增加重试逻辑

This commit is contained in:
yezian 2024-08-13 13:19:12 +08:00
parent 2db825b352
commit 8ae878587b
1 changed files with 11 additions and 3 deletions

View File

@ -16,10 +16,19 @@ def endecode_and_proxy_url(original_url):
class Video:
def douyin(self, url):
# Extract ID from URL
id_match = self.extract_id(url)
if not id_match:
for attempt_1 in range(10):
id_match = self.extract_id(url)
if id_match:
break
else:
time.sleep(0.5)
else:
return {"code": 400, "msg": "Unable to parse video ID"}
# id_match = self.extract_id(url)
# if not id_match:
# return {"code": 400, "msg": "Unable to parse video ID"}
video_id = id_match
# Construct request headers
@ -46,7 +55,6 @@ class Video:
matches = re.search(pattern, response.text, re.DOTALL)
if matches:
print(attempt)
break
else:
time.sleep(0.5)