pytube / pytube

A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.
https://pytube.io
The Unlicense
12.28k stars 2.52k forks source link

[BUG]Pytube cannot access streams of some youtube videos #1054

Closed Rohanator2314 closed 3 years ago

Rohanator2314 commented 3 years ago

The bug Pytube cannot access streams of some youtube videos

To Reproduce A quick test shows this. I ran this in cmd:

yt = YouTube('https://www.youtube.com/watch?v=nb6ou_k4OzM')
print(yt.streams)

Expected behavior When running this code in the past (on the same video), a list of streams was shown

Output The error is as follows:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\*name*\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 311, in streams
    return StreamQuery(self.fmt_streams)
  File "C:\Users\*name*\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 223, in fmt_streams
    extract.apply_signature(self.player_config_args, fmt, self.js)
  File "C:\Users\*name*\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py", line 476, in apply_signature
    new_n = cipher.calculate_n(initial_n)
  File "C:\Users\*name*\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 63, in calculate_n
    raise TypeError(f'{curr_func} is not callable.')
TypeError: 302823254 is not callable.

System information Please provide the following information:

github-actions[bot] commented 3 years ago

Thank you for contributing to PyTube. Please remember to reference Contributing.md

Rohanator2314 commented 3 years ago

After some more testing, it seems that this is some sort of change on YouTubes end for videos in playlists. The same code that could download a playlist before will no longer work. Hopefully their is still a way to fix this

tfdahlin commented 3 years ago

Looking into a fix for this

tfdahlin commented 3 years ago

Well that's weird. I was able to reproduce this bug like 20 minutes ago, and now I can't any more.

Rohanator2314 commented 3 years ago

A good sign???

Rohanator2314 commented 3 years ago

It works for me aswell

tfdahlin commented 3 years ago

Could indicate one of several things:

  1. YouTube made a change and reverted it (less likely, but might explain it)
  2. I'm getting different results in my web requests than other people (possibly b/c of geofencing. This makes it extremely difficult for me to try and debug)
  3. Perhaps I need to get rid of the base.js caching, and people are experiencing this transiently because of a change to the player js while downloading multiple videos. I was afraid this may happen at some point, but wasn't sure.

If we get another issue like this in the future, I'll strip the caching code, which will cause a slight performance hit, but should permanently solve the issue if it is indeed the 3rd case.

tfdahlin commented 3 years ago

I'm adding some code that will try and fetch a newer version of the player js if it encounters this error, will try to get it merged today or tomorrow after some additional testing

tfdahlin commented 3 years ago

The code that's supposed to detect these failures and try to refresh the js cache has been pushed as part of v10.9.3

BOKUS123 commented 1 year ago

Hello, I had the same problem as described here. I dont know if it helps you here with that issue. But it helped me to use Pytube again successfully.

After I updated all outdated packes (Thats how I found them: pip list --outdated) I was able to use it again.

I updated them in power shell with that statement: "pip freeze | %{$.split('==')[0]} | %{pip install --upgrade $}" (https://www.activestate.com/resources/quick-reads/how-to-update-all-python-packages/ or https://www.youtube.com/watch?v=cJduUNbU9ao)

Greetings