mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-31 06:35:12 +00:00 
			
		
		
		
	[jsinterp] Fix for youtube player c81bbb4a
This commit is contained in:
		| @@ -212,6 +212,11 @@ class TestJSInterpreter(unittest.TestCase): | |||||||
|         ''') |         ''') | ||||||
|         self.assertEqual(jsi.call_function('x'), 7) |         self.assertEqual(jsi.call_function('x'), 7) | ||||||
| 
 | 
 | ||||||
|  |         jsi = JSInterpreter(''' | ||||||
|  |         function x() { return (l=[0,1,2,3], function(a, b){return a+b})((l[1], l[2]), l[3]) } | ||||||
|  |         ''') | ||||||
|  |         self.assertEqual(jsi.call_function('x'), 5) | ||||||
|  | 
 | ||||||
|     def test_void(self): |     def test_void(self): | ||||||
|         jsi = JSInterpreter(''' |         jsi = JSInterpreter(''' | ||||||
|         function x() { return void 42; } |         function x() { return void 42; } | ||||||
|   | |||||||
| @@ -102,6 +102,10 @@ _NSIG_TESTS = [ | |||||||
|         'https://www.youtube.com/s/player/4c3f79c5/player_ias.vflset/en_US/base.js', |         'https://www.youtube.com/s/player/4c3f79c5/player_ias.vflset/en_US/base.js', | ||||||
|         'TDCstCG66tEAO5pR9o', 'dbxNtZ14c-yWyw', |         'TDCstCG66tEAO5pR9o', 'dbxNtZ14c-yWyw', | ||||||
|     ), |     ), | ||||||
|  |     ( | ||||||
|  |         'https://www.youtube.com/s/player/c81bbb4a/player_ias.vflset/en_US/base.js', | ||||||
|  |         'gre3EcLurNY2vqp94', 'Z9DfGxWP115WTg', | ||||||
|  |     ), | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -33,19 +33,19 @@ _OPERATORS = {  # None => Defined in JSInterpreter._operator | |||||||
|     '==': operator.eq, |     '==': operator.eq, | ||||||
|     '!=': operator.ne, |     '!=': operator.ne, | ||||||
| 
 | 
 | ||||||
|     '<=': operator.le, |     '<=': lambda a, b: (a or 0) <= (b or 0), | ||||||
|     '>=': operator.ge, |     '>=': lambda a, b: (a or 0) >= (b or 0), | ||||||
|     '<': operator.lt, |     '<': lambda a, b: (a or 0) < (b or 0), | ||||||
|     '>': operator.gt, |     '>': lambda a, b: (a or 0) > (b or 0), | ||||||
| 
 | 
 | ||||||
|     '>>': operator.rshift, |     '>>': operator.rshift, | ||||||
|     '<<': operator.lshift, |     '<<': operator.lshift, | ||||||
| 
 | 
 | ||||||
|     '+': operator.add, |     '+': lambda a, b: (a or 0) + (b or 0), | ||||||
|     '-': operator.sub, |     '-': lambda a, b: (a or 0) - (b or 0), | ||||||
| 
 | 
 | ||||||
|     '*': operator.mul, |     '*': lambda a, b: (a or 0) * (b or 0), | ||||||
|     '/': operator.truediv, |     '/': lambda a, b: (a or 0) / b, | ||||||
|     '%': operator.mod, |     '%': operator.mod, | ||||||
| 
 | 
 | ||||||
|     '**': operator.pow, |     '**': operator.pow, | ||||||
| @@ -339,11 +339,12 @@ class JSInterpreter: | |||||||
| 
 | 
 | ||||||
|         # Comma separated statements |         # Comma separated statements | ||||||
|         sub_expressions = list(self._separate(expr)) |         sub_expressions = list(self._separate(expr)) | ||||||
|         expr = sub_expressions.pop().strip() if sub_expressions else '' |         if len(sub_expressions) > 1: | ||||||
|             for sub_expr in sub_expressions: |             for sub_expr in sub_expressions: | ||||||
|                 ret, should_abort = self.interpret_statement(sub_expr, local_vars, allow_recursion) |                 ret, should_abort = self.interpret_statement(sub_expr, local_vars, allow_recursion) | ||||||
|                 if should_abort: |                 if should_abort: | ||||||
|                     return ret, True |                     return ret, True | ||||||
|  |             return ret, False | ||||||
| 
 | 
 | ||||||
|         for m in re.finditer(rf'''(?x) |         for m in re.finditer(rf'''(?x) | ||||||
|                 (?P<pre_sign>\+\+|--)(?P<var1>{_NAME_RE})| |                 (?P<pre_sign>\+\+|--)(?P<var1>{_NAME_RE})| | ||||||
| @@ -422,8 +423,7 @@ class JSInterpreter: | |||||||
|             if not separated: |             if not separated: | ||||||
|                 continue |                 continue | ||||||
|             left_val = self.interpret_expression(op.join(separated), local_vars, allow_recursion) |             left_val = self.interpret_expression(op.join(separated), local_vars, allow_recursion) | ||||||
|             return self._operator(op, 0 if left_val is None else left_val, |             return self._operator(op, left_val, right_expr, expr, local_vars, allow_recursion), should_return | ||||||
|                                   right_expr, expr, local_vars, allow_recursion), should_return |  | ||||||
| 
 | 
 | ||||||
|         if m and m.group('attribute'): |         if m and m.group('attribute'): | ||||||
|             variable = m.group('var') |             variable = m.group('var') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 pukkandan
					pukkandan