]> jfr.im git - yt-dlp.git/commitdiff
[jsinterp] Improve separating regex
authorpukkandan <redacted>
Tue, 11 Oct 2022 02:29:27 +0000 (07:59 +0530)
committerpukkandan <redacted>
Tue, 11 Oct 2022 02:32:26 +0000 (08:02 +0530)
Fixes https://github.com/yt-dlp/yt-dlp/issues/4635#issuecomment-1273974909

test/test_jsinterp.py
test/test_youtube_signature.py
yt_dlp/extractor/youtube.py
yt_dlp/jsinterp.py

index 92ef532f56bba13d220cf2924c2ce3c2ea3a2bff..3c4391c4abbb3c26bd03c3d109a9d3486e507cfa 100644 (file)
@@ -392,6 +392,11 @@ def test_regex(self):
         ''')
         self.assertEqual(jsi.call_function('x').pattern, r',][}",],()}(\[)')
 
+        jsi = JSInterpreter(R'''
+        function x() { let a=[/[)\\]/]; return a[0]; }
+        ''')
+        self.assertEqual(jsi.call_function('x').pattern, r'[)\\]')
+
     def test_char_code_at(self):
         jsi = JSInterpreter('function x(i){return "test".charCodeAt(i)}')
         self.assertEqual(jsi.call_function('x', 0), 116)
index c3dcb4d68ff11c0474a1891614603265e76d58e0..6d753fbf09bdbc446e23afa5a60ba99f40fb485b 100644 (file)
         'https://www.youtube.com/s/player/5a3b6271/player_ias.vflset/en_US/base.js',
         'B2j7f_UPT4rfje85Lu_e', 'm5DmNymaGQ5RdQ',
     ),
+    (
+        'https://www.youtube.com/s/player/7a062b77/player_ias.vflset/en_US/base.js',
+        'NRcE3y3mVtm_cV-W', 'VbsCYUATvqlt5w',
+    ),
 ]
 
 
index 6f153bb3cf9cfd7d63bfd2250136ef0c76d70db1..35e41753a20615f07405b98fabd2c973bf7b41c4 100644 (file)
@@ -2832,7 +2832,7 @@ def _decrypt_nsig(self, s, video_id, player_url):
             self.report_warning(
                 f'Native nsig extraction failed: Trying with PhantomJS\n'
                 f'         n = {s} ; player = {player_url}', video_id)
-            self.write_debug(e)
+            self.write_debug(e, only_once=True)
 
             args, func_body = func_code
             ret = jsi.execute(
index 4caad6f743089b54f310ea69ab4f7e8d7ec75abf..e25997129d0ae69f4a9103c9453df9a7fdc0afba 100644 (file)
@@ -236,7 +236,7 @@ def _regex_flags(cls, expr):
 
     @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()}
@@ -246,7 +246,9 @@ def _separate(expr, delim=',', max_split=None):
             if not in_quote and char in _MATCHING_PARENS:
                 counters[_MATCHING_PARENS[char]] += 1
             elif not in_quote and char in counters:
-                counters[char] -= 1
+                # Something's wrong if we get negative, but ignore it anyway
+                if counters[char]:
+                    counters[char] -= 1
             elif not escaping:
                 if char in _QUOTES and in_quote in (char, None):
                     if in_quote or after_op or char != '/':