alexmercerind / youtube-search-python

🔎 Search for YouTube videos, channels & playlists. Get 🎞 video & 📑 playlist info using link. Get search suggestions. WITHOUT YouTube Data API v3.
MIT License
740 stars 164 forks source link

Fixes to StreamURLFetcher - Resolves #134 #142

Closed mytja closed 2 years ago

mytja commented 2 years ago

I don't have much to say here.

PyTube doesn't like our JavaScript anymore for some reason, so we have to fetch it internally using PyTube. Also uploadDate and publishDate aren't available anymore in JSON YouTube sends us in Video class. This is a problem, which I don't know at the moment how to resolve...

I'd like to hear what you think about this PR, so I'm adding you two as reviewers.

PS: One commit is already on main branch.... :sweat_smile: So make sure to look at this one too.

mytja commented 2 years ago

Hmmmm. After investigating I noticed this:

As for sync version and async version. It doesn't work for sync aswell as with async version. I will see what I can do.

mytja commented 2 years ago

Now, I found out, that ANDROID_EMBED client has same response as ANDROID client. Thus we can use ANDROID client, and now it should work for your example.

Please install latest version from streamurlfetcher branch

pip install git+https://github.com/alexmercerind/youtube-search-python@streamurlfetcher

Thanks for quick response. I wouldn't catch this without you.

dscrofts commented 2 years ago

@mytja Looks like the latest fix takes care of the problem and I've tested multiple URLs to verify. Great work!

P.S. Just need to remove the JSON console debugging 😉

mytja commented 2 years ago

@mytja Looks like the latest fix takes care of the problem and I've tested multiple URLs to verify. Great work!

P.S. Just need to remove the JSON console debugging wink

Oh, thanks. Completly forgot about logging...

raitonoberu commented 2 years ago

I'm getting an error.

>>> from youtubesearchpython import *
>>> fetcher = StreamURLFetcher()
>>> video = Video.get("https://www.youtube.com/watch?v=TxBXaMQP2Kg")
>>> url = fetcher.get(video, 251)
Traceback (most recent call last):
  File "C:\Users\raitonoberu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtubesearchpython\core\streamurlfetcher.py", line 85, in _decipher
    stream = apply_descrambler(self._player_response["streamingData"])
TypeError: apply_descrambler() missing 1 required positional argument: 'key'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\raitonoberu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtubesearchpython\streamurlfetcher.py", line 52, in get
    self._getDecipheredURLs(videoFormats)
  File "C:\Users\raitonoberu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtubesearchpython\core\streamurlfetcher.py", line 51, in _getDecipheredURLs
    self._decipher()
  File "C:\Users\raitonoberu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtubesearchpython\core\streamurlfetcher.py", line 96, in _decipher
    self._decipher(retry = True)
  File "C:\Users\raitonoberu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtubesearchpython\core\streamurlfetcher.py", line 92, in _decipher
    raise e
  File "C:\Users\raitonoberu\AppData\Local\Programs\Python\Python38\lib\site-packages\youtubesearchpython\core\streamurlfetcher.py", line 85, in _decipher
    stream = apply_descrambler(self._player_response["streamingData"])
TypeError: apply_descrambler() missing 1 required positional argument: 'key'
mytja commented 2 years ago

You probably have old version of PyTube installed. Can you try to install latest one?