Skip to content

Commit

Permalink
[youtube] Improve error detection (#16445)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstftw authored and pareronia committed Jun 22, 2020
1 parent 5cafca8 commit faa926e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,8 @@ def extract_player_response(player_response, video_id):

def extract_unavailable_message():
return self._html_search_regex(
r'(?s)<h1[^>]+id="unavailable-message"[^>]*>(.+?)</h1>',
(r'(?s)<div[^>]+id=["\']unavailable-submessage["\'][^>]+>(.+?)</div',
r'(?s)<h1[^>]+id=["\']unavailable-message["\'][^>]*>(.+?)</h1>'),
video_webpage, 'unavailable message', default=None)

if not video_info:
Expand Down Expand Up @@ -2098,9 +2099,14 @@ def _extract_filesize(media_url):
a_format.setdefault('http_headers', {})['Youtubedl-no-compression'] = 'True'
formats.append(a_format)
else:
error_message = clean_html(video_info.get('reason', [None])[0])
error_message = extract_unavailable_message()
if not error_message:
error_message = extract_unavailable_message()
error_message = clean_html(try_get(
player_response, lambda x: x['playabilityStatus']['reason'],
compat_str))
if not error_message:
error_message = clean_html(
try_get(video_info, lambda x: x['reason'][0], compat_str))
if error_message:
raise ExtractorError(error_message, expected=True)
raise ExtractorError('no conn, hlsvp, hlsManifestUrl or url_encoded_fmt_stream_map information found in video info')
Expand Down

0 comments on commit faa926e

Please sign in to comment.