add timeout for sponsorblock api requests, handle 503

This commit is contained in:
simon 2022-10-23 12:46:10 +07:00
parent baacd3ee39
commit f0874b2d02
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -48,9 +48,17 @@ class SponsorBlock:
url = f"{self.API}/skipSegments?videoID={youtube_id}"
headers = {"User-Agent": self.user_agent}
print(f"{youtube_id}: get sponsorblock timestamps")
response = requests.get(url, headers=headers)
try:
response = requests.get(url, headers=headers, timeout=10)
except requests.ReadTimeout:
print(f"{youtube_id}: sponsorblock API timeout")
return False
if not response.ok:
print(f"{youtube_id}: sponsorblock failed: {response.text}")
print(f"{youtube_id}: sponsorblock failed: {response.status_code}")
if response.status_code == 503:
return False
sponsor_dict = {
"last_refresh": self.last_refresh,
"is_enabled": True,