|
| 1 | +import httpx |
| 2 | +import re |
| 3 | +from user_scanner.core.result import Result |
| 4 | + |
| 5 | +async def _check(email: str) -> Result: |
| 6 | + show_url = "https://www.deviantart.com" |
| 7 | + join_page = "https://www.deviantart.com/join/" |
| 8 | + verify_url = "https://www.deviantart.com/_sisu/do/signup2" |
| 9 | + |
| 10 | + headers = { |
| 11 | + 'User-Agent': "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Mobile Safari/537.36", |
| 12 | + 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8", |
| 13 | + 'Accept-Encoding': "identity", |
| 14 | + 'sec-ch-ua-platform': '"Android"', |
| 15 | + 'upgrade-insecure-requests': "1" |
| 16 | + } |
| 17 | + |
| 18 | + try: |
| 19 | + async with httpx.AsyncClient(timeout=10.0, follow_redirects=True) as client: |
| 20 | + r_home = await client.get(show_url, headers=headers) |
| 21 | + if r_home.status_code == 403: |
| 22 | + return Result.error("Caught by WAF or IP Block (403) during Handshake 1") |
| 23 | + |
| 24 | + r_join = await client.get(join_page, headers=headers) |
| 25 | + if r_join.status_code == 403: |
| 26 | + return Result.error("Caught by WAF or IP Block (403) during Handshake 2") |
| 27 | + |
| 28 | + csrf_match = re.search(r"window\.__CSRF_TOKEN__\s*=\s*'([^']+)'", r_join.text) |
| 29 | + if not csrf_match: |
| 30 | + return Result.error("Failed to extract CSRF token from window variable") |
| 31 | + |
| 32 | + csrf_token = csrf_match.group(1) |
| 33 | + |
| 34 | + payload = { |
| 35 | + 'referer': "https://www.deviantart.com/", |
| 36 | + 'referer_type': "", |
| 37 | + 'csrf_token': csrf_token, |
| 38 | + 'join_mode': "email", |
| 39 | + 'oauth': "0", |
| 40 | + 'email': email, |
| 41 | + 'password': "", |
| 42 | + 'username': "scanner_test_99", |
| 43 | + 'dobMonth': "6", |
| 44 | + 'dobDay': "6", |
| 45 | + 'dobYear': "1998" |
| 46 | + } |
| 47 | + |
| 48 | + headers.update({ |
| 49 | + 'origin': "https://www.deviantart.com", |
| 50 | + 'referer': "https://www.deviantart.com/join/" |
| 51 | + }) |
| 52 | + |
| 53 | + response = await client.post(verify_url, data=payload, headers=headers) |
| 54 | + status = response.status_code |
| 55 | + |
| 56 | + if status == 403: |
| 57 | + return Result.error("Caught by WAF or IP Block (403) during Validation") |
| 58 | + |
| 59 | + resp_text = response.text |
| 60 | + |
| 61 | + if 'id="email-error">That email address is already in use.' in resp_text: |
| 62 | + return Result.taken(url=show_url) |
| 63 | + |
| 64 | + if 'id="email-error"' not in resp_text: |
| 65 | + return Result.available(url=show_url) |
| 66 | + |
| 67 | + if status == 429: |
| 68 | + return Result.error("Rate limited by DeviantArt") |
| 69 | + |
| 70 | + return Result.error(f"Unexpected response content or status: {status}") |
| 71 | + |
| 72 | + except httpx.ConnectTimeout: |
| 73 | + return Result.error("Connection timed out! maybe region blocks") |
| 74 | + except Exception as e: |
| 75 | + return Result.error(e) |
| 76 | + |
| 77 | +async def validate_deviantart(email: str) -> Result: |
| 78 | + return await _check(email) |
0 commit comments