pytube
pytube copied to clipboard
[BUG] KeyError: 'streamingData' when trying to filter DASH streams.
Describe the bug
I have youtube video that I'm trying to download. I'm trying to filter out only streams with is_dash
set to True
. Most of the times it works but occasionally I get KeyError: 'streamingData'
exception. I noticed bug when running pytest in CI/CD pipeline and was able to reproduce it locally.
To Reproduce
url = "https://www.youtube.com/watch?v=NcBjx_eyvxc"
video = YouTube(url)
streams = video.streams.filter(is_dash=True).desc()
Expected behavior
filter()
returns streams
as an iterable object of all adaptive streams.
Output Exception that is raised (trace from pytest):
.venv/lib/python3.10/site-packages/pytube/__main__.py:296: in streams
return StreamQuery(self.fmt_streams)
.venv/lib/python3.10/site-packages/pytube/__main__.py:176: in fmt_streams
stream_manifest = extract.apply_descrambler(self.streaming_data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pytube.__main__.YouTube object: videoId=NcBjx_eyvxc>
@property
def streaming_data(self):
"""Return streamingData from video info."""
if 'streamingData' in self.vid_info:
return self.vid_info['streamingData']
else:
self.bypass_age_gate()
> return self.vid_info['streamingData']
E KeyError: 'streamingData'
.venv/lib/python3.10/site-packages/pytube/__main__.py:161: KeyError
System information Please provide the following information:
- Python 3.10.11
- pytube.version --> '12.1.3'
- Command used to install pytube:
poetry add pytube
Unfortunately, streamingData is missing in many different cases, and it's safe to say that when it's missing, there won't be any stream descriptors.
I am also facing the same problem
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 but the problem is downloading video or audio is slow
No longer experiencing bug on version 15.0.0
. Closing issue.