返回提交历史
Modified
g4f/Provider/Blackbox.py
+24
-8
XFEstudio/gpt4free
feat(g4f/Provider/Blackbox.py): Improve validated token retrieval mechanism
4d4190b3
代码差异
1 个文件
+24
-8
@@ -85,22 +85,38 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
85
85
}
86
86
87
87
@classmethod
88
async def fetch_validated(cls):
88
async def fetch_validated(cls):
89
89
async with aiohttp.ClientSession() as session:
90
90
try:
91
async with session.get('https://www.blackbox.ai/_next/static/chunks/2052-cdfeaea1ea292ff5.js') as response:
91
# Get the HTML of the page
92
async with session.get(cls.url) as response:
93
if response.status != 200:
94
print("Failed to load the page.")
95
return cls._last_validated_value
96
92
97
page_content = await response.text()
93
validated_match = re.search(r'w="([0-9a-fA-F-]{36})"', page_content)
94
95
if validated_match:
96
validated_value = validated_match.group(1)
97
cls._last_validated_value = validated_value
98
return validated_value
98
# Find all JavaScript file links
99
js_files = re.findall(r'static/chunks/\d{4}-[a-fA-F0-9]+\.js', page_content)
100
101
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})"')
102
103
# Check each JavaScript file for the key
104
for js_file in js_files:
105
js_url = f"{cls.url}/_next/{js_file}"
106
async with session.get(js_url) as js_response:
107
if js_response.status == 200:
108
js_content = await js_response.text()
109
match = key_pattern.search(js_content)
110
if match:
111
validated_value = match.group(1)
112
cls._last_validated_value = validated_value
113
return validated_value
99
114
except Exception as e:
100
115
print(f"Error fetching validated value: {e}")
101
116
102
117
return cls._last_validated_value
103
118
119
104
120
@staticmethod
105
121
def generate_id(length=7):
106
122
characters = string.ascii_letters + string.digits