diff --git a/user_scanner/user_scan/music/beatstars.py b/user_scanner/user_scan/music/beatstars.py new file mode 100644 index 00000000..850cdbd5 --- /dev/null +++ b/user_scanner/user_scan/music/beatstars.py @@ -0,0 +1,50 @@ +from user_scanner.core.orchestrator import generic_validate, Result + + +def validate_beatstars(user): + url = "https://core.prod.beatstars.net/auth/graphql" + show_url = f"https://www.beatstars.com/{user}" + + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0', + 'Accept-Language': 'en,en-US;q=0.9' + } + + payload = { + 'operationName': 'identifierAvailable', + 'variables': { + 'identifier': f'{user}', + }, + 'query': 'query identifierAvailable($identifier: String!) {\n identifierAvailable(identifier: $identifier) {\n ...AccountBasicInfo\n __typename\n }\n}\n\nfragment AccountBasicInfo on IsIdentifierAvailableResponse {\n available\n profileDetails {\n email\n username\n artwork {\n url\n fitInUrl\n __typename\n }\n __typename\n }\n __typename\n}', + } + + def process(response): + try: + res_json = response.json() + + if "errors" in res_json and res_json["errors"]: + raw_err = res_json["errors"][0].get("message", "") + + if "ITEM_NOT_FOUND" in raw_err: + return Result.available("Username too short or invalid length") + + if "valid email or username" in raw_err: + return Result.available("Invalid username format") + + return Result.error(f"API Error: {raw_err}") + + data = res_json.get("data", {}) + identifier_data = data.get("identifierAvailable") + + if not identifier_data: + return Result.error("Could not parse identifier data") + + if identifier_data.get("available") is True: + return Result.available() + + return Result.taken() + + except (AttributeError, ValueError, KeyError): + return Result.error("Failed to decode server response, report it via GitHub issues") + + return generic_validate(url, process, show_url=show_url, method="POST", headers=headers, json=payload) diff --git a/user_scanner/user_scan/social/vk.py b/user_scanner/user_scan/social/vk.py new file mode 100644 index 00000000..e1e18563 --- /dev/null +++ b/user_scanner/user_scan/social/vk.py @@ -0,0 +1,16 @@ +from user_scanner.core.orchestrator import generic_validate, Result + + +def validate_vk(user): + url = f"https://vk.com/{user}" + show_url = f"https://vk.com/{user}" + + def process(response): + if response.status_code == 404: + return Result.available() + elif response.status_code == 200: + return Result.taken() + + return Result.error("Unexpected response body, report it via GitHub issues.") + + return generic_validate(url, process, show_url=show_url)