Skip to content

Commit

Permalink
[youtube] Improve extraction in 429 error conditions (closes #24283)
Browse files Browse the repository at this point in the history
(cherry picked from commit f93abcf)
  • Loading branch information
dstftw authored and direc85 committed Jun 11, 2020
1 parent 2ba1750 commit a59cd5d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1790,11 +1790,19 @@ def extract_player_response(player_response, video_id):
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)
Expand Down Expand Up @@ -1833,13 +1841,16 @@ def extract_unavailable_message():
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 {}

Expand Down

0 comments on commit a59cd5d

Please sign in to comment.