[extractor] Show video id in error messages if possible

This commit is contained in:
pukkandan 2021-08-19 07:19:23 +05:30
parent 88acdbc269
commit 1151c4079a
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698
3 changed files with 36 additions and 26 deletions

View File

@ -833,11 +833,13 @@ def report_file_delete(self, file_name):
except UnicodeEncodeError: except UnicodeEncodeError:
self.to_screen('Deleting existing file') self.to_screen('Deleting existing file')
def raise_no_formats(self, has_drm=False, forced=False): def raise_no_formats(self, info, forced=False):
has_drm = info.get('__has_drm')
msg = 'This video is DRM protected' if has_drm else 'No video formats found!' msg = 'This video is DRM protected' if has_drm else 'No video formats found!'
expected = self.params.get('ignore_no_formats_error') expected = self.params.get('ignore_no_formats_error')
if forced or not expected: if forced or not expected:
raise ExtractorError(msg, expected=has_drm or expected) raise ExtractorError(msg, video_id=info['id'], ie=info['extractor'],
expected=has_drm or expected)
else: else:
self.report_warning(msg) self.report_warning(msg)
@ -1191,12 +1193,7 @@ def extract_info(self, url, download=True, ie_key=None, extra_info={},
self.report_warning('The program functionality for this site has been marked as broken, ' self.report_warning('The program functionality for this site has been marked as broken, '
'and will probably not work.') 'and will probably not work.')
try: temp_id = ie.get_temp_id(url)
temp_id = str_or_none(
ie.extract_id(url) if callable(getattr(ie, 'extract_id', None))
else ie._match_id(url))
except (AssertionError, IndexError, AttributeError):
temp_id = None
if temp_id is not None and self.in_download_archive({'id': temp_id, 'ie_key': ie_key}): if temp_id is not None and self.in_download_archive({'id': temp_id, 'ie_key': ie_key}):
self.to_screen("[%s] %s: has already been recorded in archive" % ( self.to_screen("[%s] %s: has already been recorded in archive" % (
ie_key, temp_id)) ie_key, temp_id))
@ -2064,7 +2061,8 @@ def process_video_result(self, info_dict, download=True):
if 'id' not in info_dict: if 'id' not in info_dict:
raise ExtractorError('Missing "id" field in extractor result') raise ExtractorError('Missing "id" field in extractor result')
if 'title' not in info_dict: if 'title' not in info_dict:
raise ExtractorError('Missing "title" field in extractor result') raise ExtractorError('Missing "title" field in extractor result',
video_id=info_dict['id'], ie=info_dict['extractor'])
def report_force_conversion(field, field_not, conversion): def report_force_conversion(field, field_not, conversion):
self.report_warning( self.report_warning(
@ -2170,7 +2168,7 @@ def sanitize_numeric_fields(info):
info_dict['__has_drm'] = len(info_dict.get('formats') or ['']) > len(formats) info_dict['__has_drm'] = len(info_dict.get('formats') or ['']) > len(formats)
if not formats: if not formats:
self.raise_no_formats(info_dict.get('__has_drm')) self.raise_no_formats(info_dict)
def is_wellformed(f): def is_wellformed(f):
url = f.get('url') url = f.get('url')
@ -2297,7 +2295,8 @@ def is_wellformed(f):
formats_to_download = list(format_selector(ctx)) formats_to_download = list(format_selector(ctx))
if not formats_to_download: if not formats_to_download:
if not self.params.get('ignore_no_formats_error'): if not self.params.get('ignore_no_formats_error'):
raise ExtractorError('Requested format is not available', expected=True) raise ExtractorError('Requested format is not available', expected=True,
video_id=info_dict['id'], ie=info_dict['extractor'])
else: else:
self.report_warning('Requested format is not available') self.report_warning('Requested format is not available')
# Process what we can, even without any available formats. # Process what we can, even without any available formats.
@ -2427,7 +2426,7 @@ def print_optional(field):
def dl(self, name, info, subtitle=False, test=False): def dl(self, name, info, subtitle=False, test=False):
if not info.get('url'): if not info.get('url'):
self.raise_no_formats(info.get('__has_drm'), forced=True) self.raise_no_formats(info, True)
if test: if test:
verbose = self.params.get('verbose') verbose = self.params.get('verbose')

View File

@ -467,6 +467,13 @@ def suitable(cls, url):
def _match_id(cls, url): def _match_id(cls, url):
return cls._match_valid_url(url).group('id') return cls._match_valid_url(url).group('id')
@classmethod
def get_temp_id(cls, url):
try:
return cls._match_id(url)
except (IndexError, AttributeError):
return None
@classmethod @classmethod
def working(cls): def working(cls):
"""Getter method for _WORKING.""" """Getter method for _WORKING."""
@ -588,12 +595,14 @@ def extract(self, url):
if self.__maybe_fake_ip_and_retry(e.countries): if self.__maybe_fake_ip_and_retry(e.countries):
continue continue
raise raise
except ExtractorError: except ExtractorError as e:
raise video_id = e.video_id or self.get_temp_id(url)
raise ExtractorError(
e.msg, video_id=video_id, ie=self.IE_NAME, tb=e.traceback, expected=e.expected, cause=e.cause)
except compat_http_client.IncompleteRead as e: except compat_http_client.IncompleteRead as e:
raise ExtractorError('A network error has occurred.', cause=e, expected=True) raise ExtractorError('A network error has occurred.', cause=e, expected=True, video_id=self.get_temp_id(url))
except (KeyError, StopIteration) as e: except (KeyError, StopIteration) as e:
raise ExtractorError('An extractor error has occurred.', cause=e) raise ExtractorError('An extractor error has occurred.', cause=e, video_id=self.get_temp_id(url))
def __maybe_fake_ip_and_retry(self, countries): def __maybe_fake_ip_and_retry(self, countries):
if (not self.get_param('geo_bypass_country', None) if (not self.get_param('geo_bypass_country', None)

View File

@ -2399,25 +2399,27 @@ class YoutubeDLError(Exception):
class ExtractorError(YoutubeDLError): class ExtractorError(YoutubeDLError):
"""Error during info extraction.""" """Error during info extraction."""
def __init__(self, msg, tb=None, expected=False, cause=None, video_id=None): def __init__(self, msg, tb=None, expected=False, cause=None, video_id=None, ie=None):
""" tb, if given, is the original traceback (so that it can be printed out). """ tb, if given, is the original traceback (so that it can be printed out).
If expected is set, this is a normal error message and most likely not a bug in yt-dlp. If expected is set, this is a normal error message and most likely not a bug in yt-dlp.
""" """
if sys.exc_info()[0] in network_exceptions: if sys.exc_info()[0] in network_exceptions:
expected = True expected = True
if video_id is not None:
msg = video_id + ': ' + msg
if cause:
msg += ' (caused by %r)' % cause
if not expected:
msg += bug_reports_message()
super(ExtractorError, self).__init__(msg)
self.msg = msg
self.traceback = tb self.traceback = tb
self.exc_info = sys.exc_info() # preserve original exception self.expected = expected
self.cause = cause self.cause = cause
self.video_id = video_id self.video_id = video_id
self.ie = ie
self.exc_info = sys.exc_info() # preserve original exception
super(ExtractorError, self).__init__(''.join((
format_field(ie, template='[%s] '),
format_field(video_id, template='%s: '),
msg,
format_field(cause, template=' (caused by %r)'),
'' if expected else bug_reports_message())))
def format_traceback(self): def format_traceback(self):
if self.traceback is None: if self.traceback is None: