|
| 1 | +import httpx |
| 2 | +import json |
| 3 | +from user_scanner.core.result import Result |
| 4 | + |
| 5 | + |
| 6 | +async def _check(email: str) -> Result: |
| 7 | + csrf_url = "https://accounts.wondershare.com/api/v3/csrf-token" |
| 8 | + inspect_url = "https://accounts.wondershare.com/api/v3/account/inspect" |
| 9 | + show_url = "https://wondershare.com" |
| 10 | + |
| 11 | + headers = { |
| 12 | + 'User-Agent': "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Mobile Safari/537.36", |
| 13 | + 'Accept': "application/json, text/plain, */*", |
| 14 | + 'Accept-Encoding': "identity", |
| 15 | + 'sec-ch-ua-platform': '"Android"', |
| 16 | + 'x-lang': "en-us", |
| 17 | + 'sec-ch-ua': '"Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145"', |
| 18 | + 'sec-ch-ua-mobile': "?1", |
| 19 | + 'sec-fetch-site': "same-origin", |
| 20 | + 'sec-fetch-mode': "cors", |
| 21 | + 'sec-fetch-dest': "empty", |
| 22 | + 'referer': "https://accounts.wondershare.com/m/login?source=&redirect_uri=https://www.wondershare.com/?source=&site=www.wondershare.com&verify=no", |
| 23 | + 'accept-language': "en-US,en;q=0.9", |
| 24 | + 'priority': "u=1, i" |
| 25 | + } |
| 26 | + |
| 27 | + try: |
| 28 | + async with httpx.AsyncClient(timeout=15.0) as client: |
| 29 | + |
| 30 | + r_csrf = await client.get(csrf_url, headers=headers) |
| 31 | + if r_csrf.status_code != 200: |
| 32 | + return Result.error(f"Handshake failed: {r_csrf.status_code}") |
| 33 | + |
| 34 | + token = client.cookies.get("req_identity") |
| 35 | + |
| 36 | + if not token: |
| 37 | + return Result.error("req_identity cookie missing from handshake") |
| 38 | + |
| 39 | + inspect_headers = headers.copy() |
| 40 | + inspect_headers.update({ |
| 41 | + 'x-csrf-token': token, |
| 42 | + 'Content-Type': "application/json", |
| 43 | + 'origin': "https://accounts.wondershare.com", |
| 44 | + 'referer': "https://accounts.wondershare.com/m/register" |
| 45 | + }) |
| 46 | + |
| 47 | + payload = {"email": email} |
| 48 | + |
| 49 | + response = await client.put( |
| 50 | + inspect_url, |
| 51 | + content=json.dumps(payload), |
| 52 | + headers=inspect_headers |
| 53 | + ) |
| 54 | + |
| 55 | + if response.status_code == 403: |
| 56 | + return Result.error("Caught by WAF (403)") |
| 57 | + |
| 58 | + if response.status_code != 200: |
| 59 | + return Result.error(f"HTTP Error: {response.status_code}") |
| 60 | + |
| 61 | + data_final = response.json() |
| 62 | + status_obj = data_final.get("data") |
| 63 | + |
| 64 | + if not isinstance(status_obj, dict): |
| 65 | + return Result.error("Invalid response data structure") |
| 66 | + |
| 67 | + status_code = status_obj.get("exist") |
| 68 | + |
| 69 | + # 1 = Registered, 2 = Not Registered |
| 70 | + if status_code == 1: |
| 71 | + return Result.taken(url=show_url) |
| 72 | + elif status_code == 2: |
| 73 | + return Result.available(url=show_url) |
| 74 | + |
| 75 | + return Result.error(f"Unexpected exist value: {status_code}") |
| 76 | + |
| 77 | + except Exception as e: |
| 78 | + return Result.error(e) |
| 79 | + |
| 80 | + |
| 81 | +async def validate_wondershare(email: str) -> Result: |
| 82 | + return await _check(email) |
0 commit comments