diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-08-30 17:23:59 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-08-30 18:13:37 +0530 |
commit | d81ba7d491bf2c89246d8817438db48a5a4e4ae9 (patch) | |
tree | a530e370d90289d3e23107328cb66a48b4ebb92c /yt_dlp/jsinterp.py | |
parent | 5135ed3d4a87b3c03902aec68b60b40855b12863 (diff) | |
download | hypervideo-pre-d81ba7d491bf2c89246d8817438db48a5a4e4ae9.tar.lz hypervideo-pre-d81ba7d491bf2c89246d8817438db48a5a4e4ae9.tar.xz hypervideo-pre-d81ba7d491bf2c89246d8817438db48a5a4e4ae9.zip |
[jsinterp, extractor/youtube] Minor fixes
Diffstat (limited to 'yt_dlp/jsinterp.py')
-rw-r--r-- | yt_dlp/jsinterp.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py index cadb013a3..99bdca927 100644 --- a/yt_dlp/jsinterp.py +++ b/yt_dlp/jsinterp.py @@ -172,7 +172,14 @@ class Debugger: def interpret_statement(self, stmt, local_vars, allow_recursion, *args, **kwargs): if cls.ENABLED and stmt.strip(): cls.write(stmt, level=allow_recursion) - ret, should_ret = f(self, stmt, local_vars, allow_recursion, *args, **kwargs) + try: + ret, should_ret = f(self, stmt, local_vars, allow_recursion, *args, **kwargs) + except Exception as e: + if cls.ENABLED: + if isinstance(e, ExtractorError): + e = e.orig_msg + cls.write('=> Raises:', e, '<-|', stmt, level=allow_recursion) + raise if cls.ENABLED and stmt.strip(): cls.write(['->', '=>'][should_ret], repr(ret), '<-|', stmt, level=allow_recursion) return ret, should_ret @@ -226,7 +233,7 @@ class JSInterpreter: @staticmethod def _separate(expr, delim=',', max_split=None): - OP_CHARS = '+-*/%&|^=<>!,;{}()[]:' + OP_CHARS = '+-*/%&|^=<>!,;{}:' if not expr: return counters = {k: 0 for k in _MATCHING_PARENS.values()} @@ -504,7 +511,7 @@ class JSInterpreter: (?P<op>{"|".join(map(re.escape, set(_OPERATORS) - _COMP_OPERATORS))})? =(?!=)(?P<expr>.*)$ )|(?P<return> - (?!if|return|true|false|null|undefined)(?P<name>{_NAME_RE})$ + (?!if|return|true|false|null|undefined|NaN)(?P<name>{_NAME_RE})$ )|(?P<indexing> (?P<in>{_NAME_RE})\[(?P<idx>.+)\]$ )|(?P<attribute> @@ -539,6 +546,8 @@ class JSInterpreter: raise JS_Continue() elif expr == 'undefined': return JS_Undefined, should_return + elif expr == 'NaN': + return float('NaN'), should_return elif m and m.group('return'): return local_vars.get(m.group('name'), JS_Undefined), should_return @@ -784,7 +793,7 @@ class JSInterpreter: global_stack[0].update(itertools.zip_longest(argnames, args, fillvalue=None)) global_stack[0].update(kwargs) var_stack = LocalNameSpace(*global_stack) - ret, should_abort = self.interpret_statement(code.replace('\n', ''), var_stack, allow_recursion - 1) + ret, should_abort = self.interpret_statement(code.replace('\n', ' '), var_stack, allow_recursion - 1) if should_abort: return ret return resf |