JuanBindez / pytubefix

Python3 library for downloading YouTube Videos.
http://pytubefix.rtfd.io/
MIT License
674 stars 95 forks source link

pytubefix.jsinterp.JSInterpreter.Exception: slice must be applied on a list in: a.slice(0,0) #158

Closed zzunny97 closed 3 months ago

zzunny97 commented 3 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

import io
import time

from pytubefix import YouTube

start = time.time()
video_id = "kc291DqL0do"

yt = YouTube(f"https://www.youtube.com/watch?v={video_id}", client="WEB")

a = yt.streams.filter(only_audio=True).order_by("abr").desc().all()

buffers = io.BytesIO()
a[0].stream_to_buffer(buffers)

a = buffers.getvalue()

end = time.time()
print(f"Elapsed time: {end - start} sec")

Exception occurs

  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/ivan/groot-backend/playground/pytube.py", line 11, in <module>
    a = yt.streams.filter(only_audio=True).order_by("abr").desc().all()
        ^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/__main__.py", line 553, in streams
    return StreamQuery(self.fmt_streams)
                       ^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/__main__.py", line 254, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js, self.js_url)
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/extract.py", line 474, in apply_signature
    discovered_n[initial_n] = cipher.get_throttling(initial_n)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/cipher.py", line 39, in get_throttling
    return self.js_interpreter.call_function(self.throttling_function_name, n)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 1090, in call_function
    return self.extract_function(funcname)(args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 261, in __call__
    return self.func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 1100, in resf
    ret, should_abort = self.interpret_statement(code.replace('\n', ' '), var_stack, allow_recursion - 1)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 573, in interpret_statement
    ret, should_return = self.interpret_statement(sub_stmt, local_vars, allow_recursion)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 767, in interpret_statement
    ret, should_abort = self.interpret_statement(sub_expr, local_vars, allow_recursion)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 808, in interpret_statement
    local_vars[m.group('out')] = self._operator(
                                 ^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 537, in _operator
    right_val = self.interpret_expression(right_expr, local_vars, allow_recursion)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 1023, in interpret_expression
    ret, should_return = self.interpret_statement(expr, local_vars, allow_recursion)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 1007, in interpret_statement
    return eval_method(), should_return
           ^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 901, in eval_method
    argvals = [
              ^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 902, in <listcomp>
    self.interpret_expression(v, local_vars, allow_recursion)
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 1023, in interpret_expression
    ret, should_return = self.interpret_statement(expr, local_vars, allow_recursion)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 1007, in interpret_statement
    return eval_method(), should_return
           ^^^^^^^^^^^^^
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 945, in eval_method
    assertion(isinstance(obj, list), 'must be applied on a list')
  File "/home/ivan/miniconda3/envs/groot-backend/lib/python3.11/site-packages/pytubefix/jsinterp.py", line 874, in assertion
    raise self.Exception(f'{member} {msg}', expr)
pytubefix.jsinterp.JSInterpreter.Exception: slice must be applied on a list in: a.slice(0,0)

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

JuanBindez commented 3 months ago

use 6.9.2