mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-11-04 08:35:12 +00:00 
			
		
		
		
	[extractor/youtube] Make signature extraction non-fatal
and reduce verbosity of it's warning Closes #3882
This commit is contained in:
		@@ -2530,22 +2530,16 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def _decrypt_signature(self, s, video_id, player_url):
 | 
					    def _decrypt_signature(self, s, video_id, player_url):
 | 
				
			||||||
        """Turn the encrypted s field into a working signature"""
 | 
					        """Turn the encrypted s field into a working signature"""
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if player_url is None:
 | 
					 | 
				
			||||||
            raise ExtractorError('Cannot decrypt signature without player_url')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            player_id = (player_url, self._signature_cache_id(s))
 | 
					            player_id = (player_url, self._signature_cache_id(s))
 | 
				
			||||||
            if player_id not in self._player_cache:
 | 
					            if player_id not in self._player_cache:
 | 
				
			||||||
                func = self._extract_signature_function(
 | 
					                func = self._extract_signature_function(video_id, player_url, s)
 | 
				
			||||||
                    video_id, player_url, s
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
                self._player_cache[player_id] = func
 | 
					                self._player_cache[player_id] = func
 | 
				
			||||||
            func = self._player_cache[player_id]
 | 
					            func = self._player_cache[player_id]
 | 
				
			||||||
            self._print_sig_code(func, s)
 | 
					            self._print_sig_code(func, s)
 | 
				
			||||||
            return func(s)
 | 
					            return func(s)
 | 
				
			||||||
        except Exception as e:
 | 
					        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):
 | 
					    def _decrypt_nsig(self, s, video_id, player_url):
 | 
				
			||||||
        """Turn the encrypted n field into a working signature"""
 | 
					        """Turn the encrypted n field into a working signature"""
 | 
				
			||||||
@@ -3147,13 +3141,17 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
 | 
				
			|||||||
                sc = compat_parse_qs(fmt.get('signatureCipher'))
 | 
					                sc = compat_parse_qs(fmt.get('signatureCipher'))
 | 
				
			||||||
                fmt_url = url_or_none(try_get(sc, lambda x: x['url'][0]))
 | 
					                fmt_url = url_or_none(try_get(sc, lambda x: x['url'][0]))
 | 
				
			||||||
                encrypted_sig = try_get(sc, lambda x: x['s'][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
 | 
					                    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
 | 
					                    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)
 | 
					            query = parse_qs(fmt_url)
 | 
				
			||||||
            throttled = False
 | 
					            throttled = False
 | 
				
			||||||
@@ -3164,7 +3162,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
 | 
				
			|||||||
                except ExtractorError as e:
 | 
					                except ExtractorError as e:
 | 
				
			||||||
                    self.report_warning(
 | 
					                    self.report_warning(
 | 
				
			||||||
                        'nsig extraction failed: You may experience throttling for some formats\n'
 | 
					                        '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
 | 
					                    throttled = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if itag:
 | 
					            if itag:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user