|
|
@ -9,6 +9,7 @@ import re
|
|
|
|
from .utils import (
|
|
|
|
from .utils import (
|
|
|
|
NO_DEFAULT,
|
|
|
|
NO_DEFAULT,
|
|
|
|
ExtractorError,
|
|
|
|
ExtractorError,
|
|
|
|
|
|
|
|
function_with_repr,
|
|
|
|
js_to_json,
|
|
|
|
js_to_json,
|
|
|
|
remove_quotes,
|
|
|
|
remove_quotes,
|
|
|
|
truncate_string,
|
|
|
|
truncate_string,
|
|
|
@ -184,6 +185,7 @@ class Debugger:
|
|
|
|
cls.write('=> Raises:', e, '<-|', stmt, level=allow_recursion)
|
|
|
|
cls.write('=> Raises:', e, '<-|', stmt, level=allow_recursion)
|
|
|
|
raise
|
|
|
|
raise
|
|
|
|
if cls.ENABLED and stmt.strip():
|
|
|
|
if cls.ENABLED and stmt.strip():
|
|
|
|
|
|
|
|
if should_ret or not repr(ret) == stmt:
|
|
|
|
cls.write(['->', '=>'][should_ret], repr(ret), '<-|', stmt, level=allow_recursion)
|
|
|
|
cls.write(['->', '=>'][should_ret], repr(ret), '<-|', stmt, level=allow_recursion)
|
|
|
|
return ret, should_ret
|
|
|
|
return ret, should_ret
|
|
|
|
return interpret_statement
|
|
|
|
return interpret_statement
|
|
|
@ -205,8 +207,6 @@ class JSInterpreter:
|
|
|
|
'y': 4096, # Perform a "sticky" search that matches starting at the current position in the target string
|
|
|
|
'y': 4096, # Perform a "sticky" search that matches starting at the current position in the target string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_EXC_NAME = '__yt_dlp_exception__'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, code, objects=None):
|
|
|
|
def __init__(self, code, objects=None):
|
|
|
|
self.code, self._functions = code, {}
|
|
|
|
self.code, self._functions = code, {}
|
|
|
|
self._objects = {} if objects is None else objects
|
|
|
|
self._objects = {} if objects is None else objects
|
|
|
@ -220,6 +220,8 @@ class JSInterpreter:
|
|
|
|
def _named_object(self, namespace, obj):
|
|
|
|
def _named_object(self, namespace, obj):
|
|
|
|
self.__named_object_counter += 1
|
|
|
|
self.__named_object_counter += 1
|
|
|
|
name = f'__yt_dlp_jsinterp_obj{self.__named_object_counter}'
|
|
|
|
name = f'__yt_dlp_jsinterp_obj{self.__named_object_counter}'
|
|
|
|
|
|
|
|
if callable(obj) and not isinstance(obj, function_with_repr):
|
|
|
|
|
|
|
|
obj = function_with_repr(obj, f'F<{self.__named_object_counter}>')
|
|
|
|
namespace[name] = obj
|
|
|
|
namespace[name] = obj
|
|
|
|
return name
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
|
@ -784,7 +786,8 @@ class JSInterpreter:
|
|
|
|
fields)
|
|
|
|
fields)
|
|
|
|
for f in fields_m:
|
|
|
|
for f in fields_m:
|
|
|
|
argnames = f.group('args').split(',')
|
|
|
|
argnames = f.group('args').split(',')
|
|
|
|
obj[remove_quotes(f.group('key'))] = self.build_function(argnames, f.group('code'))
|
|
|
|
name = remove_quotes(f.group('key'))
|
|
|
|
|
|
|
|
obj[name] = function_with_repr(self.build_function(argnames, f.group('code')), f'F<{name}>')
|
|
|
|
|
|
|
|
|
|
|
|
return obj
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
@ -806,7 +809,9 @@ class JSInterpreter:
|
|
|
|
return [x.strip() for x in func_m.group('args').split(',')], code
|
|
|
|
return [x.strip() for x in func_m.group('args').split(',')], code
|
|
|
|
|
|
|
|
|
|
|
|
def extract_function(self, funcname):
|
|
|
|
def extract_function(self, funcname):
|
|
|
|
return self.extract_function_from_code(*self.extract_function_code(funcname))
|
|
|
|
return function_with_repr(
|
|
|
|
|
|
|
|
self.extract_function_from_code(*self.extract_function_code(funcname)),
|
|
|
|
|
|
|
|
f'F<{funcname}>')
|
|
|
|
|
|
|
|
|
|
|
|
def extract_function_from_code(self, argnames, code, *global_stack):
|
|
|
|
def extract_function_from_code(self, argnames, code, *global_stack):
|
|
|
|
local_vars = {}
|
|
|
|
local_vars = {}
|
|
|
|