-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.py
61 lines (48 loc) · 2.35 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
async def run(**kwargs):
from fastapi import FastAPI, Request, HTTPException
from loguru import logger
app = FastAPI()
@app.get('/')
async def root():
return 'Midjourney Captcha Bot'
@app.api_route('/captcha/solve', methods=['POST', 'GET'])
async def solve_captcha(request: Request):
if request.method == 'GET':
url = request.query_params.get('url')
else:
url = (await request.json()).get('url')
if not url:
raise HTTPException(status_code=400, detail='url is required')
from urllib.parse import urlparse
if not urlparse(url).scheme:
raise HTTPException(status_code=400, detail='invalid url')
from utils import BrowserCaptchaSolver
solver = BrowserCaptchaSolver(logger, **kwargs)
result = await solver.solve_turnstile(url)
if not result:
raise HTTPException(status_code=500, detail='failed to solve')
return {'code': 200, 'message': 'success'}
import uvicorn
config = uvicorn.Config(app, host=kwargs['host'], port=kwargs['port'])
server = uvicorn.Server(config)
await server.serve()
async def main():
import argparse
parser = argparse.ArgumentParser(description='Midjourney Captcha Bot')
parser.add_argument('--host', type=str, default='0.0.0.0')
parser.add_argument('--port', type=int, default=8000)
parser.add_argument('--proxy', type=str, default=None, help='Proxy')
parser.add_argument('--browser_path', type=str, default=None, help='Browser path')
parser.add_argument('--browser_headless', type=str, choices=['true', 'false'], default='true',
help='Browser headless')
parser.add_argument('--browser_timeout', type=int, default=10, help='Browser timeout')
parser.add_argument('--browser_user_data_path', type=str, default=None, help='Browser User data path')
parser.add_argument('--browser_screencast_save_path', type=str, default=None, help='Browser Screencast save path')
parser.add_argument('--browser_yescaptcha_path', type=str, default='yescaptcha-assistant',
help='Browser YesCaptcha path')
args = parser.parse_args()
args.browser_headless = True if args.browser_headless == 'true' else False
await run(**vars(args))
if __name__ == '__main__':
import asyncio
asyncio.run(main())