aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcoletdjnz <colethedj@protonmail.com>2021-08-13 18:18:26 +1200
committerGitHub <noreply@github.com>2021-08-13 11:48:26 +0530
commit641ad5d813d03b1b5bed2e5a38376f968b7e7764 (patch)
tree83f0ce0d66f13102da56475665af645335039ea8
parent0715f7e19b4f7e7b423f1fb3a8348fbc85bb82fb (diff)
downloadhypervideo-pre-641ad5d813d03b1b5bed2e5a38376f968b7e7764.tar.lz
hypervideo-pre-641ad5d813d03b1b5bed2e5a38376f968b7e7764.tar.xz
hypervideo-pre-641ad5d813d03b1b5bed2e5a38376f968b7e7764.zip
[youtube] Extract error messages from HTTPError response (#644)
Authored by: coletdjnz
-rw-r--r--yt_dlp/extractor/youtube.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py
index e929aead3..88a7e5b5d 100644
--- a/yt_dlp/extractor/youtube.py
+++ b/yt_dlp/extractor/youtube.py
@@ -38,6 +38,7 @@ from ..utils import (
format_field,
int_or_none,
intlist_to_bytes,
+ is_html,
mimetype2ext,
network_exceptions,
orderedSet,
@@ -723,11 +724,11 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
if message:
yield alert_type, message
- def _report_alerts(self, alerts, expected=True):
+ def _report_alerts(self, alerts, expected=True, fatal=True):
errors = []
warnings = []
for alert_type, alert_message in alerts:
- if alert_type.lower() == 'error':
+ if alert_type.lower() == 'error' and fatal:
errors.append([alert_type, alert_message])
else:
warnings.append([alert_type, alert_message])
@@ -793,6 +794,13 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
note='%s%s' % (note, ' (retry #%d)' % count if count else ''))
except ExtractorError as e:
if isinstance(e.cause, network_exceptions):
+ if isinstance(e.cause, compat_HTTPError) and not is_html(e.cause.read(512)):
+ e.cause.seek(0)
+ yt_error = try_get(
+ self._parse_json(e.cause.read().decode(), item_id, fatal=False),
+ lambda x: x['error']['message'], compat_str)
+ if yt_error:
+ self._report_alerts([('ERROR', yt_error)], fatal=False)
# Downloading page may result in intermittent 5xx HTTP error
# Sometimes a 404 is also recieved. See: https://github.com/ytdl-org/youtube-dl/issues/28289
# We also want to catch all other network exceptions since errors in later pages can be troublesome