1

I made a YouTube Downloader with a GUI but I kept getting streamingData KeyError for no reason. So I tried it out like this and keep getting the same error.

import pytube

link = "(any YouTube link)"

yt = pytube.YouTube(link)
yt.streams.get_highest_resolution().download()
print("downloaded", link)

The error:

Traceback (most recent call last):
  File "c:\Users\YTDownloader\script.py", line 6, in <module>
    yt.streams.get_highest_resolution().download()
    ^^^^^^^^^^
  File "C:\Users\AppData\Roaming\Python\Python311\site-packages\pytube\__main__.py", line 296, in streams
    return StreamQuery(self.fmt_streams)
                       ^^^^^^^^^^^^^^^^
  File "C:\Users\AppData\Roaming\Python\Python311\site-packages\pytube\__main__.py", line 176, in fmt_streams
    stream_manifest = extract.apply_descrambler(self.streaming_data)
                                                ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AppData\Roaming\Python\Python311\site-packages\pytube\__main__.py", line 161, in streaming_data
    return self.vid_info['streamingData']
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'streamingData'

3 Answers3

0

Try to downgrade pytube or you can use yt_dlp pip install yt_dlp

import yt_dlp
link   = "(any YouTube link)"

ydl_opts = {
    'format': 'best', 
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    ydl.download([link])

print("downloaded", link)
I_Al-thamary
  • 3,385
  • 2
  • 24
  • 37
0

This is what worked for me:

# change the following line:
yt = pytube.YouTube(link)
# with this line:
yt = pytube.YouTube(videolink, use_oauth=True, allow_oauth_cache=True)
#you'll be required to sign in into your account, but only for the first time

In case you're interested, with the current version of pytube I'm only able to download videos up to 720p, which might be the case for you too. If you want 4k, try downgrading pytube to version 12.0.0 and applying the previous fix, as that did it for me.

Glacialyx
  • 11
  • 3
0

Upgrading the version of pytube to 15.0.0 worked for me.

pip install pytube==15.0.0

Full credit goes to @user1019903. I stumbled across https://stackoverflow.com/a/76268388/12713495 which is where I got the inspiration to give upgrading a go.