diff options
author | dirkf <fieldhouse@gmx.net> | 2024-08-06 20:44:30 +0100 |
---|---|---|
committer | dirkf <fieldhouse@gmx.net> | 2024-08-06 20:51:38 +0100 |
commit | dbc08fba83a0e6c5215e8cec97eb4076f85eee5f (patch) | |
tree | 3bd333f665ca84cadc1f2dcc9d69ec0c6951a885 /youtube_dl | |
parent | 71223bff39551a11b6959a3de2dd9e2f070f3c4f (diff) |
[jsinterp] Improve slice implementation for player b12cc44b
Partly taken from yt-dlp/yt-dlp#10664, thx seproDev
Fixes #32896
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/jsinterp.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/youtube_dl/jsinterp.py b/youtube_dl/jsinterp.py index 949f77775..a616ad070 100644 --- a/youtube_dl/jsinterp.py +++ b/youtube_dl/jsinterp.py @@ -925,9 +925,16 @@ class JSInterpreter(object): obj.reverse() return obj elif member == 'slice': - assertion(isinstance(obj, list), 'must be applied on a list') - assertion(len(argvals) == 1, 'takes exactly one argument') - return obj[argvals[0]:] + assertion(isinstance(obj, (list, compat_str)), 'must be applied on a list or string') + # From [1]: + # .slice() - like [:] + # .slice(n) - like [n:] (not [slice(n)] + # .slice(m, n) - like [m:n] or [slice(m, n)] + # [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice + assertion(len(argvals) <= 2, 'takes between 0 and 2 arguments') + if len(argvals) < 2: + argvals += (None,) + return obj[slice(*argvals)] elif member == 'splice': assertion(isinstance(obj, list), 'must be applied on a list') assertion(argvals, 'takes one or more arguments') |