Skip to content

Commit

Permalink
[YouTube] Fix KeyError QV in signature extraction failed
Browse files Browse the repository at this point in the history
* temporarily force missing global definition into sig JS
* improve test: thanks yt-dlp/yt-dlp#7327 (comment)
* resolves #32314
  • Loading branch information
dirkf committed Jun 17, 2023
1 parent d6433cb commit ae8ba2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion test/test_youtube_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
'https://s.ytimg.com/yts/jsbin/html5player-en_US-vflKjOTVq/html5player.js',
'312AA52209E3623129A412D56A40F11CB0AF14AE.3EE09501CB14E3BCDC3B2AE808BF3F1D14E7FBF12',
'112AA5220913623229A412D56A40F11CB0AF14AE.3EE0950FCB14EEBCDC3B2AE808BF331D14E7FBF3',
),
(
'https://www.youtube.com/s/player/6ed0d907/player_ias.vflset/en_US/base.js',
'2aq0aqSyOoJXtK73m-uME_jv7-pT15gOFC02RFkGMqWpzEICs69VdbwQ0LDp1v7j8xx92efCJlYFYb1sUkkBSPOlPmXgIARw8JQ0qOAOAA',
'AOq0QJ8wRAIgXmPlOPSBkkUs1bYFYlJCfe29xx8j7v1pDL2QwbdV96sCIEzpWqMGkFR20CFOg51Tp-7vj_EMu-m37KtXJoOySqa0',
)
]

Expand Down Expand Up @@ -231,7 +236,7 @@ def n_sig(jscode, sig_input):


make_sig_test = t_factory(
'signature', signature, re.compile(r'.*-(?P<id>[a-zA-Z0-9_-]+)(?:/watch_as3|/html5player)?\.[a-z]+$'))
'signature', signature, re.compile(r'(?s).*(?:-|/player/)(?P<id>[a-zA-Z0-9_-]+)(?:/.+\.js|(?:/watch_as3|/html5player)?\.[a-z]+)$'))
for test_spec in _SIG_TESTS:
make_sig_test(*test_spec)

Expand Down
6 changes: 5 additions & 1 deletion youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,12 @@ def _parse_sig_js(self, jscode):
r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('),
jscode, 'Initial JS player signature function name', group='sig')

jsi = JSInterpreter(jscode)
# temporary (please) hack for player 6ed0d907 #32314
ah = 'var AH={LR:function(a,b){var c=a[0];a[0]=a[b%a.length];a[b%a.length]=c},QV:function(a){a.reverse()},pO:function(a,b){a.splice(0,b)}};'
jsi = JSInterpreter(ah + jscode)

initial_function = jsi.extract_function(funcname)

return lambda s: initial_function([s])

def _decrypt_signature(self, s, video_id, player_url):
Expand Down

0 comments on commit ae8ba2c

Please sign in to comment.