0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-22 02:15:12 +00:00

[youtube] Retry on incomplete ytInitialData

Related: #116
This commit is contained in:
pukkandan 2021-02-26 03:22:44 +05:30
parent b45d4e4a8e
commit 14fdfea973

View file

@ -2998,19 +2998,29 @@ def _real_extract(self, url):
return self.url_result(video_id, ie=YoutubeIE.ie_key(), video_id=video_id) return self.url_result(video_id, ie=YoutubeIE.ie_key(), video_id=video_id)
self.to_screen('Downloading playlist %s - add --no-playlist to just download video %s' % (playlist_id, video_id)) self.to_screen('Downloading playlist %s - add --no-playlist to just download video %s' % (playlist_id, video_id))
webpage = self._download_webpage(url, item_id) count = 0
identity_token = self._extract_identity_token(webpage, item_id) retries = 3
data = self._extract_yt_initial_data(item_id, webpage) while count < retries:
err_msg = None # Sometimes youtube returns a webpage with incomplete ytInitialData
for alert_type, alert_message in self._extract_alerts(data): webpage = self._download_webpage(url, item_id)
if alert_type.lower() == 'error': identity_token = self._extract_identity_token(webpage, item_id)
if err_msg: data = self._extract_yt_initial_data(item_id, webpage)
self._downloader.report_warning('YouTube said: %s - %s' % ('ERROR', err_msg)) err_msg = None
err_msg = alert_message for alert_type, alert_message in self._extract_alerts(data):
else: if alert_type.lower() == 'error':
self._downloader.report_warning('YouTube said: %s - %s' % (alert_type, alert_message)) if err_msg:
if err_msg: self._downloader.report_warning('YouTube said: %s - %s' % ('ERROR', err_msg))
raise ExtractorError('YouTube said: %s' % err_msg, expected=True) 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'):
break
count += 1
self.to_screen(
'Incomplete yt initial data recieved. Retrying (attempt %d of %d)...' % (count, retries))
tabs = try_get( tabs = try_get(
data, lambda x: x['contents']['twoColumnBrowseResultsRenderer']['tabs'], list) data, lambda x: x['contents']['twoColumnBrowseResultsRenderer']['tabs'], list)
if tabs: if tabs: