mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-08-28 01:56:29 +02:00
[youtube] Fix _extract_alerts
* Sometimes one warning is split between multiple runs * Also simplified code
This commit is contained in:
parent
f1823403b0
commit
3ffc7c89b0
@ -3222,25 +3222,26 @@ def _real_extract_alerts():
|
|||||||
alert_type = alert.get('type')
|
alert_type = alert.get('type')
|
||||||
if not alert_type:
|
if not alert_type:
|
||||||
continue
|
continue
|
||||||
message = try_get(alert, lambda x: x['text']['simpleText'], compat_str)
|
message = try_get(alert, lambda x: x['text']['simpleText'], compat_str) or ''
|
||||||
if message:
|
if message:
|
||||||
yield alert_type, message
|
yield alert_type, message
|
||||||
for run in try_get(alert, lambda x: x['text']['runs'], list) or []:
|
for run in try_get(alert, lambda x: x['text']['runs'], list) or []:
|
||||||
message = try_get(run, lambda x: x['text'], compat_str)
|
message += try_get(run, lambda x: x['text'], compat_str)
|
||||||
if message:
|
if message:
|
||||||
yield alert_type, message
|
yield alert_type, message
|
||||||
|
|
||||||
err_msg = None
|
errors = []
|
||||||
|
warnings = []
|
||||||
for alert_type, alert_message in _real_extract_alerts():
|
for alert_type, alert_message in _real_extract_alerts():
|
||||||
if alert_type.lower() == 'error':
|
if alert_type.lower() == 'error':
|
||||||
if err_msg:
|
errors.append([alert_type, alert_message])
|
||||||
self._downloader.report_warning('YouTube said: %s - %s' % ('ERROR', err_msg))
|
|
||||||
err_msg = alert_message
|
|
||||||
else:
|
else:
|
||||||
self._downloader.report_warning('YouTube said: %s - %s' % (alert_type, alert_message))
|
warnings.append([alert_type, alert_message])
|
||||||
|
|
||||||
if err_msg:
|
for alert_type, alert_message in (warnings + errors[:-1]):
|
||||||
raise ExtractorError('YouTube said: %s' % err_msg, expected=expected)
|
self._downloader.report_warning('YouTube said: %s - %s' % (alert_type, alert_message))
|
||||||
|
if errors:
|
||||||
|
raise ExtractorError('YouTube said: %s' % errors[-1][1], expected=expected)
|
||||||
|
|
||||||
def _extract_webpage(self, url, item_id):
|
def _extract_webpage(self, url, item_id):
|
||||||
retries = self._downloader.params.get('extractor_retries', 3)
|
retries = self._downloader.params.get('extractor_retries', 3)
|
||||||
|
Loading…
Reference in New Issue
Block a user