[youtube] Throw error when --extractor-retries are exhausted (Closes #130)

This commit is contained in:
pukkandan 2021-03-03 02:53:19 +05:30
parent d6e51845b7
commit c705177da2
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698

View File

@ -2791,6 +2791,8 @@ def extract_entries(parent_renderer): # this needs to called again for continua
if response.get('continuationContents') or response.get('onResponseReceivedActions'): if response.get('continuationContents') or response.get('onResponseReceivedActions'):
break break
last_error = 'Incomplete data recieved' last_error = 'Incomplete data recieved'
if count >= retries:
self._downloader.report_error(last_error)
if not browse or not response: if not browse or not response:
break break
@ -3014,12 +3016,13 @@ def _real_extract(self, url):
retries = self._downloader.params.get('extractor_retries', 3) retries = self._downloader.params.get('extractor_retries', 3)
count = -1 count = -1
last_error = 'Incomplete yt initial data recieved'
while count < retries: while count < retries:
count += 1 count += 1
# Sometimes youtube returns a webpage with incomplete ytInitialData # Sometimes youtube returns a webpage with incomplete ytInitialData
# See: https://github.com/yt-dlp/yt-dlp/issues/116 # See: https://github.com/yt-dlp/yt-dlp/issues/116
if count: if count:
self.report_warning('Incomplete yt initial data recieved. Retrying ...') self.report_warning('%s. Retrying ...' % last_error)
webpage = self._download_webpage( webpage = self._download_webpage(
url, item_id, url, item_id,
'Downloading webpage%s' % ' (retry #%d)' % count if count else '') 'Downloading webpage%s' % ' (retry #%d)' % count if count else '')
@ -3037,6 +3040,8 @@ def _real_extract(self, url):
raise ExtractorError('YouTube said: %s' % err_msg, expected=True) 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:
self._downloader.report_error(last_error)
tabs = try_get( tabs = try_get(
data, lambda x: x['contents']['twoColumnBrowseResultsRenderer']['tabs'], list) data, lambda x: x['contents']['twoColumnBrowseResultsRenderer']['tabs'], list)