aboutsummaryrefslogtreecommitdiffhomepage
path: root/youtube_dl
diff options
context:
space:
mode:
authordirkf <[email protected]>2024-07-10 18:07:20 +0100
committerdirkf <[email protected]>2024-07-11 00:50:46 +0100
commitd35ce6ce95aac9b98c5f8272824a82e4623b777a (patch)
tree69e4569f6a3ce2eb5375465f5311f14059770619 /youtube_dl
parent76ac69917ec76ba663da843795f46916831e6da9 (diff)
downloadyoutube-dl-d35ce6ce95aac9b98c5f8272824a82e4623b777a.tar.gz
youtube-dl-d35ce6ce95aac9b98c5f8272824a82e4623b777a.zip
[jsinterp] Support functionality for player `b22ef6e7`
* support `prototype` for call() and apply() (yt-dlp/yt-dlp#10392, thx Grub4k) * map JS `Array` to `list`
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/jsinterp.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/youtube_dl/jsinterp.py b/youtube_dl/jsinterp.py
index a2074a91e..949f77775 100644
--- a/youtube_dl/jsinterp.py
+++ b/youtube_dl/jsinterp.py
@@ -850,7 +850,7 @@ class JSInterpreter(object):
memb = member
raise self.Exception('{memb} {msg}'.format(**locals()), expr=expr)
- def eval_method():
+ def eval_method(variable, member):
if (variable, member) == ('console', 'debug'):
if Debugger.ENABLED:
Debugger.write(self.interpret_expression('[{}]'.format(arg_str), local_vars, allow_recursion))
@@ -858,6 +858,7 @@ class JSInterpreter(object):
types = {
'String': compat_str,
'Math': float,
+ 'Array': list,
}
obj = local_vars.get(variable)
if obj in (JS_Undefined, None):
@@ -883,6 +884,23 @@ class JSInterpreter(object):
self.interpret_expression(v, local_vars, allow_recursion)
for v in self._separate(arg_str)]
+ # Fixup prototype call
+ if isinstance(obj, type):
+ new_member, rest = member.partition('.')[0::2]
+ if new_member == 'prototype':
+ new_member, func_prototype = rest.partition('.')[0::2]
+ assertion(argvals, 'takes one or more arguments')
+ assertion(isinstance(argvals[0], obj), 'must bind to type {0}'.format(obj))
+ if func_prototype == 'call':
+ obj = argvals.pop(0)
+ elif func_prototype == 'apply':
+ assertion(len(argvals) == 2, 'takes two arguments')
+ obj, argvals = argvals
+ assertion(isinstance(argvals, list), 'second argument must be a list')
+ else:
+ raise self.Exception('Unsupported Function method ' + func_prototype, expr)
+ member = new_member
+
if obj is compat_str:
if member == 'fromCharCode':
assertion(argvals, 'takes one or more arguments')
@@ -976,11 +994,11 @@ class JSInterpreter(object):
if remaining:
ret, should_abort = self.interpret_statement(
- self._named_object(local_vars, eval_method()) + remaining,
+ self._named_object(local_vars, eval_method(variable, member)) + remaining,
local_vars, allow_recursion)
return ret, should_return or should_abort
else:
- return eval_method(), should_return
+ return eval_method(variable, member), should_return
elif md.get('function'):
fname = m.group('fname')