Skip to content

Commit

Permalink
[youtube] fix s_to_sig
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed Aug 25, 2022
1 parent 4119a14 commit 5e25e1b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/you_get/extractors/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def s_to_sig(js, s):
# - 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/3b5d5649/player_ias.vflset/sv_SE/base.js
# - https://www.youtube.com/s/player/dc0c6770/player_ias.vflset/sv_SE/base.js
def tr_js(code):
code = re.sub(r'function', r'def', code)
# add prefix '_sig_' to prevent namespace pollution
Expand Down Expand Up @@ -114,14 +115,10 @@ def tr_js(code):
else:
f2def = re.search(r'[^$\w]%s:function\((\w+)\)(\{[^\{\}]+\})' % f2e, js)
f2def = 'function {}({},b){}'.format(f2e, f2def.group(1), f2def.group(2))
f2 = re.sub(r'(as|if|in|is|or)', r'_\1', f2)
f2 = re.sub(r'\$', '_dollar', f2)
f2 = re.sub(r'\$', '_dollar', f2) # replace dollar sign
code = code + 'global _sig_%s\n' % f2 + tr_js(f2def)

# 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) # replace dollar sign
code = code + '_sig=_sig_%s(s)' % f1
exec(code, globals(), locals())
return locals()['_sig']
Expand Down

0 comments on commit 5e25e1b

Please # to comment.