pytube: [BUG]

Before creating an issue

Please confirm that you are on the latest version of pytube by installing from the source. You can do this by running python -m pip install git+https://github.com/pytube/pytube. Sometimes, the pypi library repository is not up to date, and your issue may have been fixed already!

Describe the bug A clear and concise description of what the bug is.

cannot download the youtube video. Worked last night no changes on PC, restarted.

To Reproduce Please provide the following information:

  • The video or playlist url that is causing the error.
  • The code where the problem is occurring.

import os from pytube import YouTube

Specify the URL of the YouTube video to download

url = input('Enter the URL of the YouTube video: ')

Destination directory for downloaded video

destination = ‘D:/youtube video/FNF’

yt = YouTube(url)

Filter the available video streams by file type and progressive download

video_streams = yt.streams.filter(progressive=True, file_extension=‘mp4’)

Get the highest resolution stream with both video and audio

video_stream = video_streams.get_highest_resolution()

Download the video stream to the specified destination directory

video_stream.download(destination)

print('The video has been downloaded to ’ + os.path.join(destination, video_stream.default_filename))

Expected behavior A clear and concise description of what you expected to happen.

Output If pytube raises an exception, please provide the full traceback for the exception.

I get this error:

File “d:\youtube video\FNF\high qulaity download.py”, line 13, in <module> video_streams = yt.streams.filter(progressive=True, file_extension=‘mp4’) ^^^^^^^^^^ File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytube_main_.py”, line 296, in streams
return StreamQuery(self.fmt_streams) ^^^^^^^^^^^^^^^^ File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytube_main_.py”, line 176, in fmt_streams
stream_manifest = extract.apply_descrambler(self.streaming_data) ^^^^^^^^^^^^^^^^^^^ File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\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 (run python --version)
  • Pytube version (run print(pytube.__version__) in python)
  • Command used to install pytube

windows 10, python 3.11, latest pytube versoin

About this issue

Most upvoted comments

Captura de tela de 2023-05-01 23-19-55 I changed the 78 line’s removing client=‘ANDROID’ and paste client=‘WEB’ and now it’s working pretty well and not even slow as mentioned for other people.

    'ANDROID_EMBED': {
        'context': {
            'client': {
                'clientName': 'ANDROID_EMBEDDED_PLAYER',
                'clientVersion': '17.31.35',
                'clientScreen': 'EMBED'
            }
        },
        'api_key': 'AIzaSyCjc_pVEDi4qsv5MtC2dMXzpIaDoRFLsxw'
    }

This works well for me now…

Also, I put ‘ANDROID_EMBED’ to (about 80 line): def __init__(self, client='ANDROID_EMBED', use_oauth=False, allow_cache=True):

What about these settings?

These settings (innertube line 41 and 60) work for me. No other changes are needed.

'ANDROID': {
    'context': {
        'client': {
            'clientName': 'ANDROID',
            'clientVersion': '17.31.35',
        }
    },
    'api_key': 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w' 
},

'ANDROID_EMBED': {
    'context': {
        'client': {
            'clientName': 'ANDROID_EMBEDDED_PLAYER',
            'clientVersion': '17.31.35',
            'clientScreen': 'EMBED'
        }
    },
    'api_key': 'AIzaSyCjc_pVEDi4qsv5MtC2dMXzpIaDoRFLsxw'
}

But another issue (for some of the video): … is age restricted, and can’t be accessed without logging in.

The download worked for me when using this key (taken from the array at the beginning of the file): AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w Works without use_oauth and client type substitution

Unfortunately, any changing of API Key leads to urllib.error.HTTPError: HTTP Error 403: Forbidden

If you install both pytube3 and pytube with pip, certain files get overwritten in unintended ways. You should be able to fix this problem if you do the following: Follow step by step

  1. Run pip uninstall pytube
  2. Run pip uninstall pytube3
  3. Run python -m pip install git+https://github.com/nficano/pytube This should uninstall the conflicting versions of pytube, and install the most recent code from this repository.