[youtube] s_to_sig: no substitution for 3-char main function names

This commit is contained in:
Mort Yao 2022-04-08 23:20:38 +02:00
parent 699391135b
commit 5d41240860
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -78,6 +78,7 @@ class YouTube(VideoExtractor):
# - https://www.youtube.com/yts/jsbin/player_ias-vfl-jbnrr/da_DK/base.js # - https://www.youtube.com/yts/jsbin/player_ias-vfl-jbnrr/da_DK/base.js
# - https://www.youtube.com/s/player/0b643cd1/player_ias.vflset/sv_SE/base.js # - https://www.youtube.com/s/player/0b643cd1/player_ias.vflset/sv_SE/base.js
# - https://www.youtube.com/s/player/50e823fc/player_ias.vflset/sv_SE/base.js # - https://www.youtube.com/s/player/50e823fc/player_ias.vflset/sv_SE/base.js
# - https://www.youtube.com/s/player/3b5d5649/player_ias.vflset/sv_SE/base.js
def tr_js(code): def tr_js(code):
code = re.sub(r'function', r'def', code) code = re.sub(r'function', r'def', code)
# add prefix '_sig_' to prevent namespace pollution # add prefix '_sig_' to prevent namespace pollution
@ -117,7 +118,9 @@ class YouTube(VideoExtractor):
f2 = re.sub(r'\$', '_dollar', f2) f2 = re.sub(r'\$', '_dollar', f2)
code = code + 'global _sig_%s\n' % f2 + tr_js(f2def) code = code + 'global _sig_%s\n' % f2 + tr_js(f2def)
f1 = re.sub(r'(as|if|in|is|or)', r'_\1', f1) # if f1 contains more than 2 characters, no need to do substitution
# FIXME: we probably shouldn't do any substitution here at all?
f1 = re.sub(r'^(as|if|in|is|or)$', r'_\1', f1)
f1 = re.sub(r'\$', '_dollar', f1) f1 = re.sub(r'\$', '_dollar', f1)
code = code + '_sig=_sig_%s(s)' % f1 code = code + '_sig=_sig_%s(s)' % f1
exec(code, globals(), locals()) exec(code, globals(), locals())