A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

Overview

pytube logo

pypi

Actively soliciting contributers!

Have ideas for how pytube can be improved? Feel free to open an issue or a pull request!

pytube

pytube is a very serious, lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

Documentation

Detailed documentation about how to use the library can be found on pytube.io. This is recommended for most use cases. If you just want to quickly download a single video, the quickstart guide below might be what you're looking for.

Description

YouTube is the most popular video-sharing platform in the world and as a hacker you may encounter a situation where you want to script something to download videos. For this I present to you pytube.

pytube is a lightweight library written in Python. It has no third party dependencies and aims to be highly reliable.

pytube also makes pipelining easy, allowing you to specify callback functions for different download events, such as on progress or on complete.

Finally pytube also includes a command-line utility, allowing you to quickly download videos right from terminal.

Features

  • Support for both progressive & DASH streams
  • Support for downloading complete playlist
  • Easily register on_download_progress & on_download_complete callbacks
  • Command-line interfaced included
  • Caption track support
  • Outputs caption tracks to .srt format (SubRip Subtitle)
  • Ability to capture thumbnail URL
  • Extensively documented source code
  • No third-party dependencies

Quickstart

This guide is only meant to cover the most basic usage of the library. For more detailed information, please refer to pytube.io.

Installation

Pytube requires an installation of python 3.6 or greater, as well as pip. Pip is typically bundled with python installations, and you can find options for how to install python at https://python.org.

To install from pypi with pip:

$ python -m pip install pytube

Sometime, the pypi release becomes slightly outdated. To install from the source with pip:

$ python -m pip install git+https://github.com/pytube/pytube

Using pytube in a python script

To download a video using the library in a script, you'll need to first import the YouTube class from the library, and pass it an argument of the video url. From there, you can access the streams and download them.

 >>> from pytube import YouTube
 >>> YouTube('https://youtu.be/2lAe1cqCOXo').streams.first().download()
 >>> yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')
 >>> yt.streams
  ... .filter(progressive=True, file_extension='mp4')
  ... .order_by('resolution')
  ... .desc()
  ... .first()
  ... .download()

Using the command-line interface

Using the CLI is extremely straightforward as well. To download a video at the highest progressive quality, you can use the following command:

$ pytube https://youtube.com/watch?v=2lAe1cqCOXo

You can also do the same for a playlist:

$ pytube https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n
Issues
  • Already-signed videos can also use the `sig=` attribute

    Already-signed videos can also use the `sig=` attribute

    @coveralls is extremely chatty. Please @mention me to comment

    opened by stdedos 150
  • HTTP Error 404: Not Found when trying get stream

    HTTP Error 404: Not Found when trying get stream

    Describe the bug I need to get URL to upload the video on AWS. The code is simplest as possible

    yt = YouTube(video_url)
    streams = yt.streams
    

    The video that I want to download: http://youtube.com/watch?v=2lAe1cqCOXo On the line where we get streams, it returns the error urllib.error.HTTPError: HTTP Error 404: Not Found It's happening not always around once at 2-3 requests.

    Full error list:

    Internal Server Error: /api/external-video-upload/
    Traceback (most recent call last):
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
        response = get_response(request)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/core/handlers/base.py", line 179, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/sentry_sdk/integrations/django/views.py", line 67, in sentry_wrapped_callback
        return callback(request, *args, **kwargs)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
        return view_func(*args, **kwargs)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
        return self.dispatch(request, *args, **kwargs)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
        response = self.handle_exception(exc)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
        self.raise_uncaught_exception(exc)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
        raise exc
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
        response = handler(request, *args, **kwargs)
      File "/home/alex/Developer/blossom-backend/blossom/recordings/views.py", line 819, in get
        youtube_video_upload(video_url, recording)
      File "/home/alex/Developer/blossom-backend/blossom/recordings/utils.py", line 791, in youtube_video_upload
        streams = yt.streams
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 321, in streams
        return StreamQuery(self.fmt_streams)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 214, in fmt_streams
        if "adaptive_fmts" in self.player_config_args:
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 188, in player_config_args
        self._player_config_args = self.vid_info
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 291, in vid_info
        return dict(parse_qsl(self.vid_info_raw))
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 109, in vid_info_raw
        self._vid_info_raw = request.get(self.vid_info_url)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/request.py", line 53, in get
        response = _execute_request(url, headers=extra_headers, timeout=timeout)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/request.py", line 37, in _execute_request
        return urlopen(request, timeout=timeout)  # nosec
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 214, in urlopen
        return opener.open(url, data, timeout)
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 523, in open
        response = meth(req, response)
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 632, in http_response
        response = self.parent.error(
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 561, in error
        return self._call_chain(*args)
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 494, in _call_chain
        result = func(*args)
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 641, in http_error_default
        raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 404: Not Found
    Internal Server Error: /api/external-video-upload/
    Traceback (most recent call last):
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
        response = get_response(request)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/core/handlers/base.py", line 179, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/sentry_sdk/integrations/django/views.py", line 67, in sentry_wrapped_callback
        return callback(request, *args, **kwargs)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
        return view_func(*args, **kwargs)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
        return self.dispatch(request, *args, **kwargs)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
        response = self.handle_exception(exc)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
        self.raise_uncaught_exception(exc)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
        raise exc
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
        response = handler(request, *args, **kwargs)
      File "/home/alex/Developer/blossom-backend/blossom/recordings/views.py", line 819, in get
        youtube_video_upload(video_url, recording)
      File "/home/alex/Developer/blossom-backend/blossom/recordings/utils.py", line 791, in youtube_video_upload
        streams = yt.streams
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 321, in streams
        return StreamQuery(self.fmt_streams)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 214, in fmt_streams
        if "adaptive_fmts" in self.player_config_args:
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 188, in player_config_args
        self._player_config_args = self.vid_info
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 291, in vid_info
        return dict(parse_qsl(self.vid_info_raw))
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 109, in vid_info_raw
        self._vid_info_raw = request.get(self.vid_info_url)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/request.py", line 53, in get
        response = _execute_request(url, headers=extra_headers, timeout=timeout)
      File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/request.py", line 37, in _execute_request
        return urlopen(request, timeout=timeout)  # nosec
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 214, in urlopen
        return opener.open(url, data, timeout)
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 523, in open
        response = meth(req, response)
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 632, in http_response
        response = self.parent.error(
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 561, in error
        return self._call_chain(*args)
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 494, in _call_chain
        result = func(*args)
      File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 641, in http_error_default
        raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 404: Not Found
    

    System information

    • Python version 3.9
    • Pytube version 10.9.3
    bug 
    opened by oleksandr-shvab 82
  • urllib.error.HTTPError: HTTP Error 403: Forbidden

    urllib.error.HTTPError: HTTP Error 403: Forbidden

    Hi all,

    I'm aware that there are some older issues with the same error, howevery I thought I would just give it a try. For some videos (like this one: https://www.youtube.com/watch?v=393C3pr2ioY ) I get a 403 error...others work fine though. Do you know of any workaround for that? I saw this thread in the older issue https://stackoverflow.com/questions/16627227/http-error-403-in-python-3-web-scraping but I'm not good enough in Python to find the right spot to implement it. Any help would be appreciated.

    PS: I already updated to the most current version (9.5.0).

    stat: stale 
    opened by NeverAskWhy 63
  • KeyError: 'url_encoded_fmt_stream_map'

    KeyError: 'url_encoded_fmt_stream_map'

    Seems like starting from today every video will cause this error when initialize a YouTube instance. Is there a quick way to fix this? I was using the same code yesterday and everything works fine.

    python version 3.6 I've tried various pytube version such as 8.0.0, 9.5.0 and 9.5.2. None of them works and all lead to this error.

    yt = YouTube('https://www.youtube.com/watch?v=p1X5A9Nmsy4') Traceback (most recent call last): File "", line 1, in File "/home/bshen/anaconda3/envs/videodata/lib/python3.6/site-packages/pytube/main.py", line 88, in init self.prefetch_init() File "/home/bshen/anaconda3/envs/videodata/lib/python3.6/site-packages/pytube/main.py", line 97, in prefetch_init self.init() File "/home/bshen/anaconda3/envs/videodata/lib/python3.6/site-packages/pytube/main.py", line 130, in init mixins.apply_descrambler(self.player_config_args, fmt) File "/home/bshen/anaconda3/envs/videodata/lib/python3.6/site-packages/pytube/mixins.py", line 89, in apply_descrambler for i in stream_data[key].split(',') KeyError: 'url_encoded_fmt_stream_map'

    opened by haroldfry 58
  • KeyError: 'cipher'

    KeyError: 'cipher'

    from pytube import YouTube
    yt = YouTube('https://www.youtube.com/watch?v=3AtDnEC4zak')
    
    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    ~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/extract.py in apply_descrambler(stream_data, key)
        296                 }
    --> 297                 for format_item in formats
        298             ]
    
    ~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/extract.py in <listcomp>(.0)
        296                 }
    --> 297                 for format_item in formats
        298             ]
    
    KeyError: 'url'
    
    During handling of the above exception, another exception occurred:
    
    KeyError                                  Traceback (most recent call last)
    <ipython-input-3-bc6543d387ce> in <module>
    ----> 1 yt = YouTube('https://www.youtube.com/watch?v=3AtDnEC4zak')
    
    ~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/__main__.py in __init__(self, url, defer_prefetch_init, on_progress_callback, on_complete_callback, proxies)
         90         if not defer_prefetch_init:
         91             self.prefetch()
    ---> 92             self.descramble()
         93 
         94     def descramble(self) -> None:
    
    ~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/__main__.py in descramble(self)
        130             if not self.age_restricted and fmt in self.vid_info:
        131                 apply_descrambler(self.vid_info, fmt)
    --> 132             apply_descrambler(self.player_config_args, fmt)
        133 
        134             if not self.js:
    
    ~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/extract.py in apply_descrambler(stream_data, key)
        299         except KeyError:
        300             cipher_url = [
    --> 301                 parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
        302             ]
        303             stream_data[key] = [
    
    ~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/extract.py in <listcomp>(.0)
        299         except KeyError:
        300             cipher_url = [
    --> 301                 parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
        302             ]
        303             stream_data[key] = [
    
    KeyError: 'cipher'
    
    
    opened by twwwy 54
  • [BUG] Download speed getting slower and slower when downloading many videos

    [BUG] Download speed getting slower and slower when downloading many videos

    When downloading multiple videos continuously, the download speed will become slower and slower.

    image image

    System information Please provide the following information:

    • Python version (run python --version) Python 3.8.0
    • Pytube version (run print(pytube.__version__) in python) 10.8.5
    • Command used to install pytube python3.8 -m pip install pytube
    bug YouTube change 
    opened by joon612 51
  • "urllib.error.HTTPError: HTTP Error 404: Not Found" when downloading using pytube

    I've been getting this error ever since I downloaded pytube, which was only two weeks ago, but it keeps getting worse. At least 1 in 30 downloads will give me the error "urllib.error.HTTPError: HTTP Error 404: Not Found"

    When I run the loop using the same YouTube link and Download location:

    import pytube
    
    for i in range(50):
        out_file = pytube.YouTube("https://www.youtube.com/watch?v=yHwGIA4VeOc").streams.first().download("D:\Music")
        print("Done")
    

    I get the error "urllib.error.HTTPError: HTTP Error 404: Not Found" at least once during the loop. Sometimes it will give the error on the 5th download, sometimes on the 43rd. It is random. If I'm lucky it will download them all successfully, but that almost never happens.

    I've tried putting a delay between downloads and looping through a list of links instead of using the same link for each download, but neither worked.

    There is an old issue from 2019, where people have left comments having the same issue within the last two weeks, so I'm not the only one.

    Information:

    • Python 3.9.5
    • Pytube 10.8.1
    • I used "python -m pip install git+https://github.com/pytube/pytube" to download pytube
    bug YouTube change 
    opened by FlubOtic 48
  • RegexMatchError:  (\W[\'

    RegexMatchError: (\W[\'"]?t[\'"]?: ?[\'"](.+?)[\'"]) had zero matches

    Tried adding the pattern into cipher.py to no effect... help please?

    pytube==9.4.0, Python 3.7.1

    Traceback (most recent call last):
      File "filename.py", line 13, in <module>
        yt = YouTube(link, on_progress_callback=progress_function)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/__main__.py", line 88, in __init__
        self.prefetch_init()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/__main__.py", line 96, in prefetch_init
        self.prefetch()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/__main__.py", line 170, in prefetch
        age_restricted=self.age_restricted,
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/extract.py", line 121, in video_info_url
        group=0,
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/helpers.py", line 65, in regex_search
        .format(pattern=pattern),
    pytube.exceptions.RegexMatchError: regex pattern (\W[\'"]?t[\'"]?: ?[\'"](.+?)[\'"]) had zero matches
    
    
    opened by walpolsh 44
  • ValueError: too many values to unpack (expected 2)

    ValueError: too many values to unpack (expected 2)

    Ran into this error in my main file i was using.

    So i made the most basic version i could and still got that error. Running in python 3.8 64 bit

    from pytube import YouTube yt = YouTube('https://www.youtube.com/watch?v=jNQXAC9IVRw')

    Error thrown: Traceback (most recent call last): File "c:\Users\user\Documents\My scripting projects\yt download testr\test.py", line 4, in <module> yt = YouTube('https://www.youtube.com/watch?v=jNQXAC9IVRw') File "C:\Python38\lib\site-packages\pytube\__main__.py", line 92, in __init__ self.descramble() File "C:\Python38\lib\site-packages\pytube\__main__.py", line 140, in descramble apply_signature(self.player_config_args, fmt, self.js) File "C:\Python38\lib\site-packages\pytube\extract.py", line 225, in apply_signature cipher = Cipher(js=js) File "C:\Python38\lib\site-packages\pytube\cipher.py", line 31, in __init__ var, _ = self.transform_plan[0].split(".") ValueError: too many values to unpack (expected 2)

    Is it just me or are you guys getting this error also?

    opened by ZippyDoodah123 41
  • [BUG] urllib.error.HTTPError: HTTP Error 404: Not Found

    [BUG] urllib.error.HTTPError: HTTP Error 404: Not Found

    Describe the bug urllib.error.HTTPError: HTTP Error 404: Not Found cannot download video or list out streams (sometimes the download did work but most of the time it throws the same error)

    To Reproduce Using Command CLI: pytube https://www.youtube.com/watch?v=1MmQUT3TjtI --list

    Expected behavior A list of streams is printed

    Output

    Traceback (most recent call last):
      File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "c:\program files\python39\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\Program Files\Python39\Scripts\pytube.exe\__main__.py", line 7, in <module>
      File "c:\program files\python39\lib\site-packages\pytube\cli.py", line 50, in main
        _perform_args_on_youtube(youtube, args)
      File "c:\program files\python39\lib\site-packages\pytube\cli.py", line 63, in _perform_args_on_youtube
        display_streams(youtube)
      File "c:\program files\python39\lib\site-packages\pytube\cli.py", line 489, in display_streams
        for stream in youtube.streams:
      File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 310, in streams
        return StreamQuery(self.fmt_streams)
      File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 213, in fmt_streams
        if "adaptive_fmts" in self.player_config_args:
      File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 187, in player_config_args
        self._player_config_args = self.vid_info
      File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 280, in vid_info
        return dict(parse_qsl(self.vid_info_raw))
      File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 108, in vid_info_raw
        self._vid_info_raw = request.get(self.vid_info_url)
      File "c:\program files\python39\lib\site-packages\pytube\request.py", line 52, in get
        response = _execute_request(url, headers=extra_headers, timeout=timeout)
      File "c:\program files\python39\lib\site-packages\pytube\request.py", line 36, in _execute_request
        return urlopen(request, timeout=timeout)  # nosec
      File "c:\program files\python39\lib\urllib\request.py", line 214, in urlopen
        return opener.open(url, data, timeout)
      File "c:\program files\python39\lib\urllib\request.py", line 523, in open
        response = meth(req, response)
      File "c:\program files\python39\lib\urllib\request.py", line 632, in http_response
        response = self.parent.error(
      File "c:\program files\python39\lib\urllib\request.py", line 561, in error
        return self._call_chain(*args)
      File "c:\program files\python39\lib\urllib\request.py", line 494, in _call_chain
        result = func(*args)
      File "c:\program files\python39\lib\urllib\request.py", line 641, in http_error_default
        raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 404: Not Found
    

    System information

    • Python version 3.9.5
    • Pytube version 10.8.4
    • Command used to install pytube: pip install git+https://github.com/pytube/pytube
    bug YouTube change 
    opened by SooOverpowered 41
  • fix bug regex

    fix bug regex

    null

    opened by mhi-iranmanesh 1
  • AttributeError: 'NoneType' object has no attribute 'span'

    AttributeError: 'NoneType' object has no attribute 'span'

    (venv) ➜ pytube pytube https://www.youtube.com/watch?v=5Q2Pc-e-8Qc Loading video... Traceback (most recent call last): File "/Users/32uni/PycharmProjects/pytube/venv/bin/pytube", line 8, in sys.exit(main()) File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/cli.py", line 53, in main _perform_args_on_youtube(youtube, args) File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/cli.py", line 60, in _perform_args_on_youtube download_highest_resolution_progressive( File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/cli.py", line 474, in download_highest_resolution_progressive stream = youtube.streams.get_highest_resolution() File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/main.py", line 292, in streams return StreamQuery(self.fmt_streams) File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/main.py", line 177, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/cipher.py", line 44, in init self.throttling_array = get_throttling_function_array(js) File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/cipher.py", line 323, in get_throttling_function_array str_array = throttling_array_split(array_raw) File "/Users/32uni/PycharmProjects/pytube/venv/lib/python3.8/site-packages/pytube/parser.py", line 158, in throttling_array_split match_start, match_end = match.span() AttributeError: 'NoneType' object has no attribute 'span' (venv) ➜ pytube

    opened by bubersome 4
  • raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 410: Gone

    raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 410: Gone

     line 5, in <module>
        vdo = yt.streams.first()
    
    
    raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 410: Gone
    

    How to fix this ? This was working , 5 months back .. : (

    bug 
    opened by httpanand 2
  • Fix for parsing throttling array function

    Fix for parsing throttling array function

    As I already mentioned in #1163, it seems that YouTube has added functions without parameters, e.g.:

    function(){for(var d=64,e=[];++d-e.length-32;){switch(d){case 58:d-=14;case 91:case 92:case 93:continue;case 123:d=47;case 94:case 95:case 96:continue;case 46:d=95}e.push(String.fromCharCode(d))}return e}
    

    So in my opinion the best fix would be to allow the regex to accept these too. That is, change the regex function\([^)]+\) to function\([^)]*\). The * allows the function to have no parameters.

    opened by alexeichhorn 0
  • [BUG] yt.streams  Error

    [BUG] yt.streams Error

    match_start, match_end = match.span() AttributeError: 'NoneType' object has no attribute 'span'

    Found this issue

    in C:\Python38\lib\site-packages\pytube\parser.py

    Change this line:

    152: func_regex = re.compile(r"function([^)]+)")

    to this:

    152: func_regex = re.compile(r"function([^)]?)")

    The issue is that the regex expects a function with an argument, but I guess youtube added some src that includes non-paramterized functions.

    bug 
    opened by senanoguz 6
  • ERROR 'NoneType' object has no attribute 'span' [BUG]

    ERROR 'NoneType' object has no attribute 'span' [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.

    To Reproduce Please provide the following information:

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

    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.

    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
    bug 
    opened by DiyRex 3
  • hotfix parses the throttling array javascript error nontype

    hotfix parses the throttling array javascript error nontype

    Fix error 'NoneType' object has no attribute 'span'

    opened by thinhpm 2
  • ERROR 'NoneType' object has no attribute 'span'

    ERROR 'NoneType' object has no attribute 'span'

    line 292, in streams return StreamQuery(self.fmt_streams) File "...\Python39\lib\site-packages\pytube_main_.py", line 177, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "...\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "...\Python39\lib\site-packages\pytube\cipher.py", line 44, in init self.throttling_array = get_throttling_function_array(js) File "...\Python39\lib\site-packages\pytube\cipher.py", line 323, in get_throttling_function_array str_array = throttling_array_split(array_raw) File "...\Python39\lib\site-packages\pytube\parser.py", line 158, in throttling_array_split match_start, match_end = match.span() AttributeError: 'NoneType' object has no attribute 'span'

    Pytube version: 11.0.1 Python 3.9.7

    bug 
    opened by rishabh3354 3
  • [BUG] 'NoneType' object has no attribute 'span'

    [BUG] 'NoneType' object has no attribute 'span'

    arr = yt.streams.filter(only_video=True, file_extension='mp4')
    
    line 292, in streams
        return StreamQuery(self.fmt_streams)
      File "...\Python39\lib\site-packages\pytube\__main__.py", line 177, in fmt_streams
        extract.apply_signature(stream_manifest, self.vid_info, self.js)
      File "...\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature
        cipher = Cipher(js=js)
      File "...\Python39\lib\site-packages\pytube\cipher.py", line 44, in __init__
        self.throttling_array = get_throttling_function_array(js)
      File "...\Python39\lib\site-packages\pytube\cipher.py", line 323, in get_throttling_function_array
        str_array = throttling_array_split(array_raw)
    
      File "...\Python39\lib\site-packages\pytube\parser.py", line 158, in throttling_array_split
        match_start, match_end = match.span()
    AttributeError: 'NoneType' object has no attribute 'span'
    

    Pytube version: 11.0.1 Python 3.9.7

    bug 
    opened by SuperZombi 26
  • [BUG]Unexpected renderer encountered,Renderer name: dict_keys(['showingResultsForRenderer'])

    [BUG]Unexpected renderer encountered,Renderer name: dict_keys(['showingResultsForRenderer'])

    Pytube version : 11.0.1-1 OS : ArchLinux (Archcraft, basically uses the official repos of Arch)

    Describe the bug I was learning pytube for the first time, I made a simple script that search and give top 20 results, I observed that for a particular search string, pytube is throwing me a warning and asked me to open an issue here, hence I am.

    Code

    from pytube import Search
    
    search_term = input("Enter search keyword : ")
    
    s = Search(search_term)
    
    print("top 20 results")
    
    if(len(s.results) < 20):
            s.get_next_results()
    
    for i in range(0,20):
            print(str(i+1) + "." + str(s.results[i].title)+"\n")
    
    

    For a particular search string lie you do it tells me,

    Enter search keyword : lie you do
    top 20 results
    Unexpected renderer encountered.
    Renderer name: dict_keys(['showingResultsForRenderer'])
    Search term: lie you do
    Please open an issue at https://github.com/pytube/pytube/issues and provide this log output.
    1.Ellie Goulding - Love Me Like You Do (Official Video)
    
    2.Joji - Like You Do
    
    3.Ellie Goulding - Love Me Like You Do (Official Audio)
    
    4.Ellie Goulding - Love Me Like You Do (Lyrics)
    .
    .
    .
    
    

    I don't know what it means I tried the string many times, it repeats the warning. I thought it might be of use to you guys.

    bug 
    opened by SisyphusIsntHappy 1
Releases(v11.0.1)
  • v11.0.1(Aug 27, 2021)

    • Fixes RegexMatchError in n cipher
    • Added documentation for some new functionality
    • last_updated will now return the raw text if it can't parse a datetime (e.g. "X days ago")
    • change default innertube client for Search objects to WEB
    Source code(tar.gz)
    Source code(zip)
  • v11.0.0(Aug 3, 2021)

    • User InnerTube in place of get_video_info url

    • Added some additional base parameters for innertube requests.

    • Added Oauth support for innertube client

    • Add exception for age-restricted videos which can no longer be accessed without using auth.

    • Carved out and simplified code where possible due to API changes.

    • Added renderer catch -- fixes #1068

    • Additional channel name support for URL-encoded names.

    • Updated test mocks, removed region-locked test because that functionality no longer works.

    Due to significant changes in how video info is accessed, certain YouTube object attributes no longer exist, which could cause breaking changes in code bases that rely on those attributes, hence the major version release.

    Source code(tar.gz)
    Source code(zip)
  • v10.9.3(Jul 21, 2021)

    • Add catch for suggested search results; accounts for edge case of no views on result.

    • Added exception handling for incorrect cached js files.

    • Now allows you to actually set filenames, instead of doing partial overrides to create safe filenames.

    • Innertube improvements, and skeleton code for future innertube work

    Source code(tar.gz)
    Source code(zip)
  • v10.9.2(Jul 7, 2021)

  • v10.9.1(Jul 6, 2021)

    • Removed special character from author attribute.

    • Changed -v CLI arg to have a single setting, rather than multiple.

    • Add retry functionality for IncompleteRead errors.

    • Extract contentLength from info where possible.

    • Mock open in final streams test to prevent file from being written.

    • Exception handling for accessing titles of private videos.

    Source code(tar.gz)
    Source code(zip)
  • v10.9.0(Jul 6, 2021)

    • Emulates the js player to calulate the value of n to prevent download slowdowns

    • Adds some additional debugging to HTMLParseErrors

    • Adds a helper for generating new html json files

    • Parser improvement

    Source code(tar.gz)
    Source code(zip)
  • v10.8.5(Jun 19, 2021)

    • Improved support for additional channel URLs
    • Improved metadata for channels
    • Improved channel documentation
    • Change to get_video_info call to fix 404 issue
    Source code(tar.gz)
    Source code(zip)
  • v10.8.4(Jun 2, 2021)

  • v10.8.3(May 30, 2021)

    • Implements an actual check for whether a video is a livestream, and raises an exception if it is.
    • Fixes channel url matching for channels without canonical names.
    Source code(tar.gz)
    Source code(zip)
  • v10.8.2(May 20, 2021)

    • Fixes the 404 issue by adding html5=1 as an additional query parameter to the get_video_info endpoint

    • Prepends the URL used with www. to avoid the redirect that occurs.

    Source code(tar.gz)
    Source code(zip)
  • v10.8.1(May 9, 2021)

    • Added channel id and channel url properties to YouTube object.

    • Added some metadata to playlist object:

      • owner
      • owner_id
      • owner_url
      • description
      • length
      • views
    Source code(tar.gz)
    Source code(zip)
  • v10.8.0(May 9, 2021)

    • Removes file write chunk size to improve performance.

    • Implements a Channel object for downloading videos from a YouTube channel.

    • Minor changes to the playlist class to make it more compatible to be subclassed.

    • .videos and .video_urls now behave just like iterable lists, but defer web requests.

    • Implements DeferredGeneratorList which converts generators to lazy list-like objects.

    Source code(tar.gz)
    Source code(zip)
  • v10.7.2(Apr 20, 2021)

  • v10.7.1(Apr 5, 2021)

    • Defaults to a duration of 0.0s when 'dur' key is missing from XML subtitles.

    • Consolidates some import lines to reduce clutter at top of files.

    Source code(tar.gz)
    Source code(zip)
  • v10.7.0(Apr 4, 2021)

  • v10.6.1(Mar 28, 2021)

  • v10.6.0(Mar 19, 2021)

    • Defers web requests until they're actually necessary to fetch information

    • Adjusts tests to reflect changes to how web requests are made

    • Removes "defer_prefetch_init" arg from YouTube object initialization

    • Converted most attributes into caching properties to facilitate request deferring.

    • Added some documentation to uniqueify to explain its purpose.

    • Prefetching added to conftest to improve test speed

    • Added some setters for YouTube properties.

    • Some cosmetic README changes

    Source code(tar.gz)
    Source code(zip)
  • v10.5.2(Mar 6, 2021)

    • Fix for the new youtube playlist requests

    • Implements pytube.request.post in order to fetch continuations

    • Implements ytcfg extraction

    • Slight refactor of object parser

    • Extends request_execute_request to take a data argument for post requests

    • Adjusted tests to reflect changes

    Source code(tar.gz)
    Source code(zip)
  • v10.5.1(Feb 23, 2021)

  • v10.5.0(Jan 31, 2021)

    • Improves the CLI by adding a --list-captions tag, and adding a default download quality instead of silently failing.

    • Got rid of incorrect hard-coded fps values in favor of determining from the stream metadata.

    • Fixed an issue where Playlist objects could not iterate over videos if the playlist was part of a series.

    Source code(tar.gz)
    Source code(zip)
  • v10.4.0(Dec 28, 2020)

  • v10.2.0(Dec 28, 2020)

  • v10.1.1(Dec 28, 2020)

    All exceptions relating to failure to load a video, such as RecordingUnavailable, VideoPrivate, LivestreamError, etc., now inherit from the base VideoUnavailable exception. This allows users to more easily catch all exceptions where a video is unavailable.

    Additionally, more handling has been added to improve our ability to detect unavailable videos.

    Source code(tar.gz)
    Source code(zip)
  • v9.7.2(Dec 11, 2020)

    Enhancements:

    • Video publish date
    • Improved unavailable video handling
    • Playlist.download_all() now returns list of file paths
    • Unit test revamp
    • Improved caption selection for videos with auto-generated and user-generated captions

    Bugfixes:

    • Updated playlist extraction to reflect YouTube changes
    • Regex optimizations
    • 404 error on adaptive downloads
    • KeyError with adaptive formats
    Source code(tar.gz)
    Source code(zip)
  • v10.1.0(Dec 10, 2020)

    Improvements:

    • More accurate itags
    • More precise exceptions for unavailable videos
    • More robust parsing of video information
    • Reduction in overall number of network calls for longer-running applications

    Bugfixes:

    • Empty StreamQuery object
    • Playlists not loading correctly
    Source code(tar.gz)
    Source code(zip)
  • v10.0.0(Dec 10, 2020)

    This release removes a number of functions that were previously part of the Playlist object, but were considered deprecated, and brought some of the components built for interacting with playlists in line with the coding style of the rest of the library.

    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Sep 6, 2015)

  • 0.2.1(Sep 6, 2015)

    • Cleanup. [Nick Ficano]
      • pep8
      • removed \n from exceptions
      • normalized docstring parameters
      • fix bug causing exception to be raised if no download path is provided.
      • changed FileExistsError to OSError for 2.7.x compat.
    • Clean up docstrings. [Nick Ficano]
    • Cleanup!! [Nick Ficano]
      • added from_url method.
      • added set_filename method.
      • added deprecation warnings to setters.
      • fixed typos.
      • pep8.
      • removed old comments.
      • removed unnecessary TODOs.
      • removed unused _fetch. method.
    • Vevovideonotworking : 1. Getting rid of default static function 2. downloading from assets js always 3. Using jsinterp instead of tinyjs since it was not working 4. vevo and everyother video with encrypted signature downloads in similar way. [vidyuthd]
    • Vevo video download not working due to changed algo. [vidyuthd]
    • Default to cwd for path arg. [Enrique Fernandez]
    • Fix division by zero. [Enrique Fernandez]
    • Refs #2: - added posibility to provide full path to file. [Eloar]
    • Refs #1: - added argument to force file overwrite - changed exit to rise exception on file name conflict. [Eloar]
    • Refs #4: - changed all exit usages to raise exceptions. [Eloar]
      • added info about 3.4 support to README and setup.py. [Eloar]
      • added future import to example in README. [Eloar]
      • added import print_function from future for backward compatibility to 2.6. [Janusz Paszyński]
      • ported example in README to 3.4.1. [Janusz Paszyński]
      • ported to 3.4.1 with backward compatibility. [Janusz Paszyński]
      • added requirements information to README file. [Janusz Paszyński]
    Source code(tar.gz)
    Source code(zip)
Making the process of downloading youtube videos faster and more convinient.

Easy-YT Making the process of downloading youtube videos faster and more convinient. What can it do? This python script can be used to download youtub

Meynam 39 Nov 15, 2021
This script fully automates of downloading tiktok videos, editing them,compiling them and finally uploading them to youtube.

This script fully automates of downloading tiktok videos, editing them,compiling them and finally uploading them to youtube. If you wanted to create a tiktok video compiilation youtubbe channel this script is here to help you :D

Supriyo Sarkar 3 Nov 13, 2021
Command-line program to download videos from YouTube.com and other video sites

youtube-dl - download videos from youtube.com or other video platforms

youtube-dl 102.8k Dec 1, 2021
Jocomol 12 Jul 24, 2021
Youtube Downloader by PyTube é uma ferramenta simples com interface gráfica e escrito em python para baixar vídeos e playlists do youtube...

YouTube Downloader by PyTube O que é o YouTube Downloader by PyTube? YouTube Downloader by PyTube é um software simples para baixar vídeos no YouTube

Elizeu Barbosa Abreu 5 Nov 26, 2021
A discord bot for downloading youtube video and audio files

disctube disctube is a discord bot for downloading video and audio files from youtube using python pytube. disclaimer i am not the best python program

razor420 2 Nov 17, 2021
📼Command line tool based on youtube-dl to easily download selected channels from your subscriptions.

youtube-cdl Command line tool based on youtube-dl to easily download selected channels from your subscriptions. This tool is very handy if you want to

Anatoly 66 Nov 8, 2021
FireDM is a python open source (Internet Download Manager) with multi-connections, high speed engine, it downloads general files and videos from youtube and tons of other streaming websites .

python open source (Internet Download Manager) with multi-connections, high speed engine, based on python, LibCurl, and youtube_dl https://github.com/firedm/FireDM

null 1.3k Dec 2, 2021
Youtube videos and channels scraper python wrapper!

YouTubeCrawle Wrapper for python Why This wrapper? This is wrapper is not limited to videos only it can scrape both channel and videos seperately ;D

Kei 16 Nov 17, 2021
Download Youtube videos in mp4 format in a fast, easy, convenient way made with Python!

yt_downloader Download Youtube videos in mp4 format in a fast, easy, convenient way made with Python! Required Modules pytube os time colorama Errors

null 2 Nov 1, 2021
Using Youtube downloader is the fast and easy way to download and save any YouTube video.

Youtube video downloader using Django Using Django as a backend along with pytube module to create Youtbue Video Downloader. https://yt-videos-downloa

Suman Raj Khanal 9 Nov 24, 2021
A Udemy downloader that can download DRM protected videos and non-DRM protected videos.

Udemy Downloader with DRM support NOTE This program is WIP, the code is provided as-is and i am not held resposible for any legal repercussions result

Puyodead1 172 Nov 30, 2021
A CLI that searches and download Youtube videos in mp3 format.

A CLI that searches and download Youtube videos in mp3 format.

Finhawk 2 Nov 15, 2021
A script that downloads YouTube videos/audio

YouTube-Downloader A script that downloads YouTube videos/audio from youtube. Usage Download the script by executing the following in your terminal :

Debayan Sarkar 2 Nov 15, 2021
Um projeto modesto para baixar vídeos do youtube usando tkinter como gui

Youtube Downloader Um projeto modesto para baixar vídeos do youtube usando tkinter como gui Instalação dos requirements: python3 setup.py ou python se

Sunlyx 2 Nov 25, 2021
🔥 A Bot To Telegram For Download High Qulity Videos & Songs From Youtube

?? A Bot To Telegram For Download High Qulity Videos & Songs From Youtube ?? Fast And Free Bot No Need To Pay ✅ By SL-Alpha-X-Team ⚡

Official Alpha-X-Team Account 1 Nov 27, 2021
DYA ( Ditch YouTube API ) is a package created to power the user with YouTube Data API functionality without any API Key

Ditch YouTubeAPI (BETA) DYA ( Ditch YouTube API ) is a package created to power the user with YouTube Data API functionality without any API Key Detai

Sougata Jana 11 Nov 28, 2021
Youtube Downloader is a Graphic User Interface(GUI) that lets users download a Youtube Video or Audio through a URL

Youtube Downloader This Python and Tkinter based GUI allows users to directly download the Best Resolution Videos and Audios from Youtube. Pa-fy Insta

Samarth Kumar 1 Oct 2, 2021
ImageScraper is a cross-platform tool for downloading a specified count from xkcd, Astronomy Picture of the Day and Existential Comics

ImageScraper The ImageScraper is a cross-platform tool for downloading a specified count from xkcd, Astronomy Picture of the Day and Existential Comic

1amnobody 0 Sep 18, 2021