aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2020-03-08 05:09:02 +0700
committerSergey M․ <dstftw@gmail.com>2020-03-08 05:09:02 +0700
commitf93abcf1da5aa1ca122896254bdec3a3c831ac24 (patch)
tree4d54c90992da30910a1a03341765f91ba412d98d
parent0ec9d4e565c1471c1234634bb3be0c7c7662d864 (diff)
[youtube] Improve extraction in 429 error conditions (closes #24283)
-rw-r--r--youtube_dl/extractor/youtube.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index d3e18a6ad..9cbdc7ac5 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -1790,11 +1790,19 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
query['el'] = el
if sts:
query['sts'] = sts
- video_info_webpage = self._download_webpage(
- '%s://www.youtube.com/get_video_info' % proto,
- video_id, note=False,
- errnote='unable to download video info webpage',
- fatal=False, query=query)
+ try:
+ video_info_webpage = self._download_webpage(
+ '%s://www.youtube.com/get_video_info' % proto,
+ video_id, note=False,
+ errnote='unable to download video info webpage',
+ query=query)
+ except ExtractorError as e:
+ # Skip further retries if we get 429 since solving
+ # captcha only unblocks access to website but
+ # not get_video_info end point
+ if isinstance(e.cause, compat_HTTPError) and e.cause.code == 429:
+ break
+ continue
if not video_info_webpage:
continue
get_video_info = compat_parse_qs(video_info_webpage)
@@ -1833,13 +1841,16 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
if messages:
return '\n'.join(messages)
- if not video_info:
+ if not video_info and not player_response:
unavailable_message = extract_unavailable_message()
if not unavailable_message:
unavailable_message = 'Unable to extract video data'
raise ExtractorError(
'YouTube said: %s' % unavailable_message, expected=True, video_id=video_id)
+ if not isinstance(video_info, dict):
+ video_info = {}
+
video_details = try_get(
player_response, lambda x: x['videoDetails'], dict) or {}