mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-30 12:01:28 +00:00
[extractor/youtube] Make signature extraction non-fatal
and reduce verbosity of it's warning Closes #3882
This commit is contained in:
parent
5bbe631e04
commit
52023f1291
|
@ -2530,22 +2530,16 @@ def _parse_sig_js(self, jscode):
|
|||
|
||||
def _decrypt_signature(self, s, video_id, player_url):
|
||||
"""Turn the encrypted s field into a working signature"""
|
||||
|
||||
if player_url is None:
|
||||
raise ExtractorError('Cannot decrypt signature without player_url')
|
||||
|
||||
try:
|
||||
player_id = (player_url, self._signature_cache_id(s))
|
||||
if player_id not in self._player_cache:
|
||||
func = self._extract_signature_function(
|
||||
video_id, player_url, s
|
||||
)
|
||||
func = self._extract_signature_function(video_id, player_url, s)
|
||||
self._player_cache[player_id] = func
|
||||
func = self._player_cache[player_id]
|
||||
self._print_sig_code(func, s)
|
||||
return func(s)
|
||||
except Exception as e:
|
||||
raise ExtractorError('Signature extraction failed: ' + traceback.format_exc(), cause=e)
|
||||
raise ExtractorError(traceback.format_exc(), cause=e, video_id=video_id)
|
||||
|
||||
def _decrypt_nsig(self, s, video_id, player_url):
|
||||
"""Turn the encrypted n field into a working signature"""
|
||||
|
@ -3147,13 +3141,17 @@ def _extract_formats(self, streaming_data, video_id, player_url, is_live, durati
|
|||
sc = compat_parse_qs(fmt.get('signatureCipher'))
|
||||
fmt_url = url_or_none(try_get(sc, lambda x: x['url'][0]))
|
||||
encrypted_sig = try_get(sc, lambda x: x['s'][0])
|
||||
if not (sc and fmt_url and encrypted_sig):
|
||||
if not all((sc, fmt_url, player_url, encrypted_sig)):
|
||||
continue
|
||||
if not player_url:
|
||||
try:
|
||||
fmt_url += '&%s=%s' % (
|
||||
traverse_obj(sc, ('sp', -1)) or 'signature',
|
||||
self._decrypt_signature(encrypted_sig, video_id, player_url)
|
||||
)
|
||||
except ExtractorError as e:
|
||||
self.report_warning('Signature extraction failed: Some formats may be missing', only_once=True)
|
||||
self.write_debug(e, only_once=True)
|
||||
continue
|
||||
signature = self._decrypt_signature(sc['s'][0], video_id, player_url)
|
||||
sp = try_get(sc, lambda x: x['sp'][0]) or 'signature'
|
||||
fmt_url += '&' + sp + '=' + signature
|
||||
|
||||
query = parse_qs(fmt_url)
|
||||
throttled = False
|
||||
|
@ -3164,7 +3162,8 @@ def _extract_formats(self, streaming_data, video_id, player_url, is_live, durati
|
|||
except ExtractorError as e:
|
||||
self.report_warning(
|
||||
'nsig extraction failed: You may experience throttling for some formats\n'
|
||||
f'n = {query["n"][0]} ; player = {player_url}\n{e}', only_once=True)
|
||||
f'n = {query["n"][0]} ; player = {player_url}', only_once=True)
|
||||
self.write_debug(e, only_once=True)
|
||||
throttled = True
|
||||
|
||||
if itag:
|
||||
|
|
Loading…
Reference in a new issue