1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 17:22:31 +01:00

[youtube] Raise appropriate error when API pages can't be downloaded

This commit is contained in:
pukkandan 2021-08-07 12:15:58 +05:30
parent 243c57cfe8
commit 379e44ed3c

View File

@ -2455,7 +2455,7 @@ def _extract_player_response(self, client, video_id, master_ytcfg, player_ytcfg,
yt_query.update(self._generate_player_context(sts)) yt_query.update(self._generate_player_context(sts))
return self._extract_response( return self._extract_response(
item_id=video_id, ep='player', query=yt_query, item_id=video_id, ep='player', query=yt_query,
ytcfg=player_ytcfg, headers=headers, fatal=False, ytcfg=player_ytcfg, headers=headers, fatal=True,
default_client=client, default_client=client,
note='Downloading %s player API JSON' % client.replace('_', ' ').strip() note='Downloading %s player API JSON' % client.replace('_', ' ').strip()
) or None ) or None
@ -2505,17 +2505,35 @@ def append_client(client_name):
if client_name in INNERTUBE_CLIENTS and client_name not in original_clients: if client_name in INNERTUBE_CLIENTS and client_name not in original_clients:
clients.append(client_name) clients.append(client_name)
# Android player_response does not have microFormats which are needed for
# extraction of some data. So we return the initial_pr with formats
# stripped out even if not requested by the user
# See: https://github.com/yt-dlp/yt-dlp/issues/501
yielded_pr = False
if initial_pr:
pr = dict(initial_pr)
pr['streamingData'] = None
yielded_pr = True
yield pr
last_error = None
while clients: while clients:
client = clients.pop() client = clients.pop()
player_ytcfg = master_ytcfg if client == 'web' else {} player_ytcfg = master_ytcfg if client == 'web' else {}
if 'configs' not in self._configuration_arg('player_skip'): if 'configs' not in self._configuration_arg('player_skip'):
player_ytcfg = self._extract_player_ytcfg(client, video_id) or player_ytcfg player_ytcfg = self._extract_player_ytcfg(client, video_id) or player_ytcfg
pr = ( try:
initial_pr if client == 'web' and initial_pr pr = initial_pr if client == 'web' and initial_pr else self._extract_player_response(
else self._extract_player_response( client, video_id, player_ytcfg or master_ytcfg, player_ytcfg, identity_token, player_url, initial_pr)
client, video_id, player_ytcfg or master_ytcfg, player_ytcfg, identity_token, player_url, initial_pr)) except ExtractorError as e:
if last_error:
self.report_warning(last_error)
last_error = e
continue
if pr: if pr:
yielded_pr = True
yield pr yield pr
# creator clients can bypass AGE_VERIFICATION_REQUIRED if logged in # creator clients can bypass AGE_VERIFICATION_REQUIRED if logged in
@ -2524,13 +2542,10 @@ def append_client(client_name):
elif self._is_agegated(pr): elif self._is_agegated(pr):
append_client(f'{client}_agegate') append_client(f'{client}_agegate')
# Android player_response does not have microFormats which are needed for if last_error:
# extraction of some data. So we return the initial_pr with formats if not yielded_pr:
# stripped out even if not requested by the user raise last_error
# See: https://github.com/yt-dlp/yt-dlp/issues/501 self.report_warning(last_error)
if initial_pr and 'web' not in original_clients:
initial_pr['streamingData'] = None
yield initial_pr
def _extract_formats(self, streaming_data, video_id, player_url, is_live): def _extract_formats(self, streaming_data, video_id, player_url, is_live):
itags, stream_ids = [], [] itags, stream_ids = [], []