diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-02-01 09:39:49 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2023-02-01 09:40:16 +0530 |
commit | 8b008d62544b82e24a0ba36c30e8e51855d93419 (patch) | |
tree | 8262dfc4a1f3757b2ddb55d8c22e415449ea90e3 /yt_dlp/jsinterp.py | |
parent | 83c4970e52839ce8761ec61bd19d549aed7d7920 (diff) | |
download | hypervideo-pre-8b008d62544b82e24a0ba36c30e8e51855d93419.tar.lz hypervideo-pre-8b008d62544b82e24a0ba36c30e8e51855d93419.tar.xz hypervideo-pre-8b008d62544b82e24a0ba36c30e8e51855d93419.zip |
[jsinterp] Support `if` statements
Closes #6131
Diffstat (limited to 'yt_dlp/jsinterp.py')
-rw-r--r-- | yt_dlp/jsinterp.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py index 3f7d659ac..c2d056aa1 100644 --- a/yt_dlp/jsinterp.py +++ b/yt_dlp/jsinterp.py @@ -403,10 +403,25 @@ class JSInterpreter: m = re.match(r'''(?x) (?P<try>try)\s*\{| + (?P<if>if)\s*\(| (?P<switch>switch)\s*\(| (?P<for>for)\s*\( ''', expr) md = m.groupdict() if m else {} + if md.get('if'): + cndn, expr = self._separate_at_paren(expr[m.end() - 1:]) + if_expr, expr = self._separate_at_paren(expr.lstrip()) + # TODO: "else if" is not handled + else_expr = None + m = re.match(r'else\s*{', expr) + if m: + else_expr, expr = self._separate_at_paren(expr[m.end() - 1:]) + cndn = _js_ternary(self.interpret_expression(cndn, local_vars, allow_recursion)) + ret, should_abort = self.interpret_statement( + if_expr if cndn else else_expr, local_vars, allow_recursion) + if should_abort: + return ret, True + if md.get('try'): try_expr, expr = self._separate_at_paren(expr[m.end() - 1:]) err = None |