pytube: [BUG] non-age restricted video causing KeyError: 'streamingData'

Describe the bug Preface: I’ve read through several issues like #674 #743 #1259 #1290 #1313, but most of these are later described as age-restricted videos. The 2 videos I’ve been experiencing these with are not age restricted!

This is a 50-50 split between no issues and getting a KeyError: 'streamingData' error.

To Reproduce Please provide the following information: I’ve mainly been testing with these 2 videos, and from what I can tell (from checking in incognito/private Chrome & safari windows) they are not age restricted. https://www.youtube.com/watch?v=qCsS-6W4rOA https://www.youtube.com/watch?v=hBgEx4m-ejo

path_to_tmp_folder = 'tmp'  # local api on personal device
yt_url = request_json['yt_url']
 # remove any playlist/mix (non single video) parameters from url
      if '&' in yt_url:
          yt_url = yt_url.split('&')[0]
      # prevent shorts from being processed
      if 'shorts' in yt_url:
          return {"message": "shorts are not supported", "response_time": (time.time()-start_time)}
      yt = YouTube(yt_url)
      yt_stream = yt.streams.filter(only_audio=True).first()
      yt_stream.download(output_path=path_to_tmp_folder)
      
      yt_title = yt.title
      yt_description = yt.description
      yt_id = yt_url.split('=')[1]
      
      file_path = os.path.join(path_to_tmp_folder, yt_stream.default_filename)
      os.remove(file_path)

Expected behavior A clear and concise description of what you expected to happen. Downloads the file (which is does basically every other time)

Output 2023-04-18 16:33:49,642:INFO - 127.0.0.1 - - [18/Apr/2023 16:33:49] "POST / HTTP/1.1" 500 - Traceback (most recent call last): File "/Users/mani/Library/Python/3.9/lib/python/site-packages/flask/app.py", line 2551, in __call__ return self.wsgi_app(environ, start_response) File "/Users/mani/Library/Python/3.9/lib/python/site-packages/flask/app.py", line 2531, in wsgi_app response = self.handle_exception(e) File "/Users/mani/Library/Python/3.9/lib/python/site-packages/flask/app.py", line 2528, in wsgi_app response = self.full_dispatch_request() File "/Users/mani/Library/Python/3.9/lib/python/site-packages/flask/app.py", line 1825, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/mani/Library/Python/3.9/lib/python/site-packages/flask/app.py", line 1823, in full_dispatch_request rv = self.dispatch_request() File "/Users/mani/Library/Python/3.9/lib/python/site-packages/flask/app.py", line 1799, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) File "/Users/mani/Library/Python/3.9/lib/python/site-packages/functions_framework/__init__.py", line 130, in view_func return function(request._get_current_object()) File "/Users/mani/Library/Python/3.9/lib/python/site-packages/functions_framework/__init__.py", line 110, in wrapper return func(*args, **kwargs) File "/Users/mani/Developer/dubdubs/gcp-cloud-functions/main.py", line 33, in whisper_cap yt2 = YouTube(yt_url).streams.filter( File "/Users/mani/Library/Python/3.9/lib/python/site-packages/pytube/__main__.py", line 296, in streams return StreamQuery(self.fmt_streams) File "/Users/mani/Library/Python/3.9/lib/python/site-packages/pytube/__main__.py", line 176, in fmt_streams stream_manifest = extract.apply_descrambler(self.streaming_data) File "/Users/mani/Library/Python/3.9/lib/python/site-packages/pytube/__main__.py", line 161, in streaming_data return self.vid_info['streamingData'] KeyError: 'streamingData'

System information Please provide the following information:

  • Python version 3.9 on system, 3.11.3 (in venv)
  • Pytube version 12.1.3
  • Command used to install pytube (listed in my requirements.txt as pytube==12.1.3 then i let VS code install requirements in a venv)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 17

Most upvoted comments

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

@vcpavao @Gerald05 @andrii1 @mkandan @Thecosy ,

after a bit of trial and error, I discovered that if you retry to download the same link 3 / 4 times (depends really) maybe even more, then it downloads the video. I guess it’s a matter of luck until the issue gets resolved. I am not an expert on this, however, I suggest adding a while loop to check if the error gets thrown and retrying downloading the video link until the error goes away and the video starts downloading.

Hope this helps and let me know if it works for you.