Pytube Keyerror 'Streamdata' While Downloading a Video
I Was Writing a Code to See Available Streams of the Video by Writing Below Code from Pytube Import Playlist from Pytube Import Youtube as Yt Import Threading...
I was writing a code to see available streams of the video by writing below code
from pytube import Playlist
from pytube import YouTube as YT
import threading as th
import time
plist=input('Enter the playlist: ')
videos=list(Playlist(plist))
i=videos[0]
video=YT(i)
strm=video.streams.filter(res="720p")
print(strm)
from above code I got error like this
Traceback (most recent call last):
File "D:\Practicals\Python\ML\youtube\temp.py", line 11, in <module>
strm=video.streams.filter(res="720p")
^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\pytube\__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\pytube\__main__.py", line 176, in fmt_streams
stream_manifest = extract.apply_descrambler(self.streaming_data)
^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\pytube\__main__.py", line 161, in streaming_data
return self.vid_info['streamingData']
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'streamingData'
I had the same problem and fixed it by adding the use_oauth and allow_oauth_cache attributes to YT(i).
from pytube import Playlist
from pytube import YouTube as YT
import threading as th
import time
plist=input('Enter the playlist: ')
videos=list(Playlist(plist))
i=videos[0]
video=YT(i, use_oauth=True, allow_oauth_cache=True)
strm=video.streams.filter(res="720p")
print(strm)
This will require you to connect to youtube via your browser once, but then it will allow you to download the videos.
Got the same error while using pytube 12.1.2.
video=YT(i, use_oauth=True, allow_oauth_cache=True)
did not work for me.
After upgrading pytube (to 15.0.0), the error went away.
This should work...
from pytube import Playlist
from pytube import YouTube as YT
import threading as th
import time
DOWNLOAD_DIR = 'C:\\download\\folder'
plist=input('Enter a playlist URL: ')
videos=list(Playlist(plist))
for i in range(len(videos)):
print(i,'-',videos[i])
video = YT(videos[i], use_oauth=True, allow_oauth_cache=True)
stream = video.streams.get_by_itag(140)
stream.download(output_path=DOWNLOAD_DIR)
print('----------done---------')
Add this in the begining of the script.
This has done the job for me [even after a long time].
import os
os.system('cmd /c "pip install --upgrade pytube"')
First locate pytube library location
Click on "innertube.py" and edit the code on line 78 replacing client='ANDROID' with client='WEB'
It worked pretty well for me