pytube icon indicating copy to clipboard operation
pytube copied to clipboard

[BUG] KeyError: 'streamingData' when trying to filter DASH streams.

Open deepaerial opened this issue 1 year ago • 3 comments

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

deepaerial avatar Apr 10 '23 23:04 deepaerial

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.

glubsy avatar Apr 11 '23 18:04 glubsy

I am also facing the same problem

vetapalem avatar Apr 27 '23 06:04 vetapalem

First locate pytube library location

Screenshot 2023-04-28 195628

Click on "innertube.py" and edit the code on line 78 replacing client='ANDROID' with client='WEB'

image

It worked pretty well for me but the problem is downloading video or audio is slow

sumanthrao-maraboina avatar Apr 29 '23 01:04 sumanthrao-maraboina

No longer experiencing bug on version 15.0.0. Closing issue.

deepaerial avatar Jun 23 '23 01:06 deepaerial