diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-11-13 15:16:44 +0100 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-11-13 15:16:44 +0100 |
commit | 4d4190b3c47df69920971da244a6a798b4c91307 (patch) | |
tree | 0c695d9b4646be1f1dccbf9668bfc07006bd9997 | |
parent | Update (g4f/models.py) (diff) | |
download | gpt4free-4d4190b3c47df69920971da244a6a798b4c91307.tar gpt4free-4d4190b3c47df69920971da244a6a798b4c91307.tar.gz gpt4free-4d4190b3c47df69920971da244a6a798b4c91307.tar.bz2 gpt4free-4d4190b3c47df69920971da244a6a798b4c91307.tar.lz gpt4free-4d4190b3c47df69920971da244a6a798b4c91307.tar.xz gpt4free-4d4190b3c47df69920971da244a6a798b4c91307.tar.zst gpt4free-4d4190b3c47df69920971da244a6a798b4c91307.zip |
-rw-r--r-- | g4f/Provider/Blackbox.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/g4f/Provider/Blackbox.py b/g4f/Provider/Blackbox.py index 952507ff..3dc4236f 100644 --- a/g4f/Provider/Blackbox.py +++ b/g4f/Provider/Blackbox.py @@ -85,22 +85,38 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): } @classmethod - async def fetch_validated(cls): + async def fetch_validated(cls): async with aiohttp.ClientSession() as session: try: - async with session.get('https://www.blackbox.ai/_next/static/chunks/2052-cdfeaea1ea292ff5.js') as response: + # Get the HTML of the page + async with session.get(cls.url) as response: + if response.status != 200: + print("Failed to load the page.") + return cls._last_validated_value + page_content = await response.text() - validated_match = re.search(r'w="([0-9a-fA-F-]{36})"', page_content) - - if validated_match: - validated_value = validated_match.group(1) - cls._last_validated_value = validated_value - return validated_value + # Find all JavaScript file links + js_files = re.findall(r'static/chunks/\d{4}-[a-fA-F0-9]+\.js', page_content) + + key_pattern = re.compile(r'w="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"') + + # Check each JavaScript file for the key + for js_file in js_files: + js_url = f"{cls.url}/_next/{js_file}" + async with session.get(js_url) as js_response: + if js_response.status == 200: + js_content = await js_response.text() + match = key_pattern.search(js_content) + if match: + validated_value = match.group(1) + cls._last_validated_value = validated_value + return validated_value except Exception as e: print(f"Error fetching validated value: {e}") return cls._last_validated_value + @staticmethod def generate_id(length=7): characters = string.ascii_letters + string.digits |