mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-11-21 23:27:29 +00:00
Detect being rate limited
This commit is contained in:
parent
951c62d1a9
commit
52b3ae07b1
@ -5,6 +5,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
|
import urllib.error
|
||||||
from tools.converters import *
|
from tools.converters import *
|
||||||
from tools.extractors import extract_yt_initial_data
|
from tools.extractors import extract_yt_initial_data
|
||||||
from math import floor
|
from math import floor
|
||||||
@ -169,11 +170,21 @@ def extract_video(id):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
except youtube_dl.DownloadError:
|
except youtube_dl.DownloadError as e:
|
||||||
return {
|
if isinstance(e.exc_info[1], urllib.error.HTTPError):
|
||||||
"error": "Video unavailable",
|
if e.exc_info[1].code == 429:
|
||||||
"identifier": "VIDEO_DOES_NOT_EXIST"
|
result = {
|
||||||
}
|
"error": "Could not extract video info. Instance is likely blocked.",
|
||||||
|
"identifier": "RATE_LIMITED_BY_YOUTUBE"
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
result = {
|
||||||
|
"error": "Received unexpected status code {}.".format(e.exc_info[1].code)
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
result = {
|
||||||
|
"error": "Unknown download error."
|
||||||
|
}
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
Loading…
Reference in New Issue
Block a user