[Youtube] Extract alerts from continuation (#144)
Related: #143 Authored by: colethedj
This commit is contained in:
parent
9e631877f8
commit
f3eaa8dd1c
1 changed files with 32 additions and 25 deletions
|
@ -2796,7 +2796,11 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||||
# See: https://github.com/ytdl-org/youtube-dl/issues/28194
|
# See: https://github.com/ytdl-org/youtube-dl/issues/28194
|
||||||
if response.get('continuationContents') or response.get('onResponseReceivedActions'):
|
if response.get('continuationContents') or response.get('onResponseReceivedActions'):
|
||||||
break
|
break
|
||||||
last_error = 'Incomplete data recieved'
|
|
||||||
|
# Youtube may send alerts if there was an issue with the continuation page
|
||||||
|
self._extract_alerts(response, expected=False)
|
||||||
|
|
||||||
|
last_error = 'Incomplete data received'
|
||||||
if count >= retries:
|
if count >= retries:
|
||||||
self._downloader.report_error(last_error)
|
self._downloader.report_error(last_error)
|
||||||
|
|
||||||
|
@ -2982,13 +2986,13 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||||
self._extract_mix_playlist(playlist, playlist_id),
|
self._extract_mix_playlist(playlist, playlist_id),
|
||||||
playlist_id=playlist_id, playlist_title=title)
|
playlist_id=playlist_id, playlist_title=title)
|
||||||
|
|
||||||
@staticmethod
|
def _extract_alerts(self, data, expected=False):
|
||||||
def _extract_alerts(data):
|
|
||||||
|
def _real_extract_alerts():
|
||||||
for alert_dict in try_get(data, lambda x: x['alerts'], list) or []:
|
for alert_dict in try_get(data, lambda x: x['alerts'], list) or []:
|
||||||
if not isinstance(alert_dict, dict):
|
if not isinstance(alert_dict, dict):
|
||||||
continue
|
continue
|
||||||
for renderer in alert_dict:
|
for alert in alert_dict.values():
|
||||||
alert = alert_dict[renderer]
|
|
||||||
alert_type = alert.get('type')
|
alert_type = alert.get('type')
|
||||||
if not alert_type:
|
if not alert_type:
|
||||||
continue
|
continue
|
||||||
|
@ -3000,6 +3004,18 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||||
if message:
|
if message:
|
||||||
yield alert_type, message
|
yield alert_type, message
|
||||||
|
|
||||||
|
err_msg = None
|
||||||
|
for alert_type, alert_message in _real_extract_alerts():
|
||||||
|
if alert_type.lower() == 'error':
|
||||||
|
if err_msg:
|
||||||
|
self._downloader.report_warning('YouTube said: %s - %s' % ('ERROR', err_msg))
|
||||||
|
err_msg = alert_message
|
||||||
|
else:
|
||||||
|
self._downloader.report_warning('YouTube said: %s - %s' % (alert_type, alert_message))
|
||||||
|
|
||||||
|
if err_msg:
|
||||||
|
raise ExtractorError('YouTube said: %s' % err_msg, expected=expected)
|
||||||
|
|
||||||
def _extract_identity_token(self, webpage, item_id):
|
def _extract_identity_token(self, webpage, item_id):
|
||||||
ytcfg = self._extract_ytcfg(item_id, webpage)
|
ytcfg = self._extract_ytcfg(item_id, webpage)
|
||||||
if ytcfg:
|
if ytcfg:
|
||||||
|
@ -3024,16 +3040,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||||
url, item_id,
|
url, item_id,
|
||||||
'Downloading webpage%s' % (' (retry #%d)' % count if count else ''))
|
'Downloading webpage%s' % (' (retry #%d)' % count if count else ''))
|
||||||
data = self._extract_yt_initial_data(item_id, webpage)
|
data = self._extract_yt_initial_data(item_id, webpage)
|
||||||
err_msg = None
|
self._extract_alerts(data, expected=True)
|
||||||
for alert_type, alert_message in self._extract_alerts(data):
|
|
||||||
if alert_type.lower() == 'error':
|
|
||||||
if err_msg:
|
|
||||||
self._downloader.report_warning('YouTube said: %s - %s' % ('ERROR', err_msg))
|
|
||||||
err_msg = alert_message
|
|
||||||
else:
|
|
||||||
self._downloader.report_warning('YouTube said: %s - %s' % (alert_type, alert_message))
|
|
||||||
if err_msg:
|
|
||||||
raise ExtractorError('YouTube said: %s' % err_msg, expected=True)
|
|
||||||
if data.get('contents') or data.get('currentVideoEndpoint'):
|
if data.get('contents') or data.get('currentVideoEndpoint'):
|
||||||
break
|
break
|
||||||
if count >= retries:
|
if count >= retries:
|
||||||
|
|
Loading…
Reference in a new issue