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

Overview

pytube logo

pypi pypi

24 July 2020 Actively soliciting contributers!

Ping @ronncc if you would like to help out!

pytube

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

Installation

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

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.

Behold, a perfect balance of simplicity versus flexibility:

 >>> 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()

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

Getting started

Let's begin with showing how easy it is to download a video with pytube:

>>> from pytube import YouTube
>>> YouTube('https://youtube.com/watch?v=2lAe1cqCOXo').streams.first().download()

This example will download the highest quality progressive download stream available.

Next, let's explore how we would view what video streams are available:

>>> yt = YouTube('https://youtube.com/watch?v=2lAe1cqCOXo')
>>> yt.streams
 [<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2" progressive="True" type="video">,
 <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">,
 <Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028" progressive="False" type="video">,
 <Stream: itag="248" mime_type="video/webm" res="1080p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="399" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.08M.08" progressive="False" type="video">,
 <Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f" progressive="False" type="video">,
 <Stream: itag="247" mime_type="video/webm" res="720p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="398" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.05M.08" progressive="False" type="video">,
 <Stream: itag="135" mime_type="video/mp4" res="480p" fps="30fps" vcodec="avc1.4d401e" progressive="False" type="video">,
 <Stream: itag="244" mime_type="video/webm" res="480p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="397" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.04M.08" progressive="False" type="video">,
 <Stream: itag="134" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.4d401e" progressive="False" type="video">,
 <Stream: itag="243" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="396" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.01M.08" progressive="False" type="video">,
 <Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d4015" progressive="False" type="video">,
 <Stream: itag="242" mime_type="video/webm" res="240p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="395" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.00M.08" progressive="False" type="video">,
 <Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400c" progressive="False" type="video">,
 <Stream: itag="278" mime_type="video/webm" res="144p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="394" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.00M.08" progressive="False" type="video">,
 <Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2" progressive="False" type="audio">,
 <Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus" progressive="False" type="audio">,
 <Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus" progressive="False" type="audio">,
 <Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus" progressive="False" type="audio">]

You may notice that some streams listed have both a video codec and audio codec, while others have just video or just audio, this is a result of YouTube supporting a streaming technique called Dynamic Adaptive Streaming over HTTP (DASH).

In the context of pytube, the implications are for the highest quality streams; you now need to download both the audio and video tracks and then post-process them with software like FFmpeg to merge them.

The legacy streams that contain the audio and video in a single file (referred to as "progressive download") are still available, but only for resolutions 720p and below.

To only view these progressive download streams:

 >>> yt.streams.filter(progressive=True)
  [<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2" progressive="True" type="video">,
  <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">]

Conversely, if you only want to see the DASH streams (also referred to as "adaptive") you can do:

>>> yt.streams.filter(adaptive=True)
 [<Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028" progressive="False" type="video">,
 <Stream: itag="248" mime_type="video/webm" res="1080p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="399" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.08M.08" progressive="False" type="video">,
 <Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f" progressive="False" type="video">,
 <Stream: itag="247" mime_type="video/webm" res="720p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="398" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.05M.08" progressive="False" type="video">,
 <Stream: itag="135" mime_type="video/mp4" res="480p" fps="30fps" vcodec="avc1.4d401e" progressive="False" type="video">,
 <Stream: itag="244" mime_type="video/webm" res="480p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="397" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.04M.08" progressive="False" type="video">,
 <Stream: itag="134" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.4d401e" progressive="False" type="video">,
 <Stream: itag="243" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="396" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.01M.08" progressive="False" type="video">,
 <Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d4015" progressive="False" type="video">,
 <Stream: itag="242" mime_type="video/webm" res="240p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="395" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.00M.08" progressive="False" type="video">,
 <Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400c" progressive="False" type="video">,
 <Stream: itag="278" mime_type="video/webm" res="144p" fps="30fps" vcodec="vp9" progressive="False" type="video">,
 <Stream: itag="394" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.00M.08" progressive="False" type="video">,
 <Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2" progressive="False" type="audio">,
 <Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus" progressive="False" type="audio">,
 <Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus" progressive="False" type="audio">,
 <Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus" progressive="False" type="audio">]

You can also interact with Youtube playlists:

>>> from pytube import Playlist
>>> pl = Playlist("https://www.youtube.com/watch?v=Edpy1szoG80&list=PL153hDY-y1E00uQtCVCVC8xJ25TYX8yPU")
>>> for video in pl.videos:
>>>     video.streams.first().download()

Pytube allows you to filter on every property available (see the documentation for the complete list), let's take a look at some of the most useful ones.

To list the audio only streams:

>>> yt.streams.filter(only_audio=True)
  [<Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2" progressive="False" type="audio">,
  <Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus" progressive="False" type="audio">,
  <Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus" progressive="False" type="audio">,
  <Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus" progressive="False" type="audio">]

To list only mp4 streams:

>>> yt.streams.filter(subtype='mp4').all()
 [<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2" progressive="True" type="video">,
 <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">,
 <Stream: itag="137" mime_type="video/mp4" res="1080p" fps="30fps" vcodec="avc1.640028" progressive="False" type="video">,
 <Stream: itag="399" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.08M.08" progressive="False" type="video">,
 <Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f" progressive="False" type="video">,
 <Stream: itag="398" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.05M.08" progressive="False" type="video">,
 <Stream: itag="135" mime_type="video/mp4" res="480p" fps="30fps" vcodec="avc1.4d401e" progressive="False" type="video">,
 <Stream: itag="397" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.04M.08" progressive="False" type="video">,
 <Stream: itag="134" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.4d401e" progressive="False" type="video">,
 <Stream: itag="396" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.01M.08" progressive="False" type="video">,
 <Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d4015" progressive="False" type="video">,
 <Stream: itag="395" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.00M.08" progressive="False" type="video">,
 <Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400c" progressive="False" type="video">,
 <Stream: itag="394" mime_type="video/mp4" res="None" fps="30fps" vcodec="av01.0.00M.08" progressive="False" type="video">,
 <Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2" progressive="False" type="audio">]

Multiple filters can also be specified:

>>> yt.streams.filter(subtype='mp4', progressive=True).all()
>>> # this can also be expressed as:
>>> yt.streams.filter(subtype='mp4').filter(progressive=True).all()
  [<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2" progressive="True" type="video">,
  <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">]

You also have an interface to select streams by their itag, without needing to filter:

>>> yt.streams.get_by_itag(22)
  <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">

If you need to optimize for a specific feature, such as the "highest resolution" or "lowest average bitrate":

>>> yt.streams.filter(progressive=True).order_by('resolution').desc().all()
  [<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">,
  <Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2" progressive="True" type="video">]

Note that order_by cannot be used if your attribute is undefined in any of the Stream instances, so be sure to apply a filter to remove those before calling it.

If your application requires post-processing logic, pytube allows you to specify an "on download complete" callback function:

 >>> def convert_to_aac(stream, file_handle):
         return  # do work

 >>> yt.register_on_complete_callback(convert_to_aac)

Similarly, if your application requires on-download progress logic, pytube exposes a callback for this as well:

 >>> def show_progress_bar(stream, chunk, bytes_remaining):
         return  # do work

 >>> yt.register_on_progress_callback(show_progress_bar)

You can also download videos to a specific directory with specific filename:

>>> yt = YouTube('https://youtube.com/watch?v=2lAe1cqCOXo')
>>> yt.streams.first().download(output_path="/tmp" ,filename='output')

Command-line interface (CLI)

Pytube also ships with a tiny CLI for interacting with videos and playlists.

To download the highest resolution progressive stream:

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

To view available streams:

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

To download a specific stream, use the itag

$ pytube https://www.youtube.com/watch?v=2lAe1cqCOXo --itag=22

To get a list of all subtitles (caption codes)

$ pytube https://www.youtube.com/watch?v=2lAe1cqCOXo --list-captions

To download a specific subtitle (caption code) - in this case the english subtitles (in srt format) - use:

$ pytube https://www.youtube.com/watch?v=2lAe1cqCOXo -c en

It is also possible to just download the audio stream (default AAC/mp4):

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

Finally, if you're filing a bug report, the cli contains a switch called --build-playback-report, which bundles up the state, allowing others to easily replay your issue.

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

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

    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 I have been running PyTube at different points today with success and fast downloads, but as of about 30 minutes ago I started to get this when I would run it:

    'NoneType' object has no attribute 'span'

    To Reproduce I have tried on these two links, both of which were working earlier today: -https://www.youtube.com/watch?v=twtGL8WbllM&ab_channel=HarritonRams -https://www.youtube.com/watch?v=mA_3LkF_Cdo&ab_channel=IndianaSRN

    Here is the code sample where it is being used:

    def download_youtube_video(row, game_id): filename = game_id + ".mp4" try: YouTube(row[0]).streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename=filename) upload_successful = True except Exception as e: print(e) print("HEY, LOOK HERE") print("I'VE GOT SOME BAD NEWS, SADLY") print("YOU'RE GOING TO HAVE TO DOWNLOAD AND UPLOAD THIS ONE MANUALLY") print(row[0]) print(game_id) print("I TRIED TWO DIFFERENT YOUTUBE DOWNLOADER PACKAGES, BLAME THOSE F**** OVER AT GOOGLE FOR THIS")

    Expected behavior I expected the video to be downloaded in the same directory as my python script as it was earlier today.

    Output Traceback (most recent call last): File "test.py", line 3, in <module> YouTube("https://www.youtube.com/watch?v=mA_3LkF_Cdo&ab_channel=IndianaSRN").streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename="hello.mp4") File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/__main__.py", line 292, in streams return StreamQuery(self.fmt_streams) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/__main__.py", line 177, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/cipher.py", line 43, in __init__ self.throttling_plan = get_throttling_plan(js) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/cipher.py", line 387, in get_throttling_plan raw_code = get_throttling_function_code(js) File "/Users/hunterhawley/Library/Python/3.7/lib/python/site-packages/pytube/cipher.py", line 301, in get_throttling_function_code code_lines_list = find_object_from_startpoint(js, match.span()[1]).split('\n') AttributeError: 'NoneType' object has no attribute 'span'

    System information Please provide the following information:

    • Python version: Python 3.7.1rc1
    • Pytube version: Unsure as the provided way to find this didn't work
    • Command used to install pytube: First was python -m pip install pytube but before posting it was python -m pip install git+https://github.com/pytube/pytube
    bug 
    opened by hunterhawley 91
  • 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 57
  • 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
  • [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 48
  • "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
  • [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
  • 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
  • Module prints empty titles [BUG]

    Module prints empty titles [BUG]

    Hello and thanks for your help.

    Everything is up to date.

    I'm on mac, I created a script in PyCharm that checks the youtube urls in an Excel doc and returns the video titles in a column. It works great on my computer BUT, when I create an app and an executable script file with PyInstaller, it's not returning any titles anymore and I don't get any errors when I run them with the terminal...

    I did a test where I removed the pytube module and just printed "test" in the cells and it worked, so the issue is with the pytube module...I did another test where instead of returning the titles in my Excel doc, it would print the titles in the terminal, and it's printing blank...

    bug 
    opened by HNT1807 2
  • [BUG] Channe() not working when using the new http://youtube.com/@username url

    [BUG] Channe() not working when using the new http://youtube.com/@username url

    Before creating an issue

    Use the Channel() function with the URL set to the new channel ID urls "http://youtube.com/@username"

    Describe the bug the code will not work as expected with this type of URL and returns the following error

    You see my full code here: https://github.com/flyinggoatman/YouTube-Link-Extractor/blob/master/QualityYouTube.py

    The part of the code that is throwing errors is:

    ` if re.search ("/channel/", channelURL) or re.search ("@", channelURL) or re.search ("/user/", channelURL) or re.search ("/c/", channelURL):

                    # This code detects if the given URL is a channel. If the check comes back as True then it grabs the data using pytube.
                
                        
                    c = Channel(channelURL)
                    channel_name = c.channel_name
                    
                    channel_id =  c.channel_id
                    channel_id_link = "http://youtube.com/channel/"+channel_id
                    
                    print("Channel Name: "+channel_name)
                    print("Channel ID: "+channel_id) 
                    print("Channel Link: "+channel_id_link)`
    

    To Reproduce Please provide the following information:

    • Install Python3
    • Install Pytube
    • Get a channel URL that contains a "@" symbol
    • put that URL into code.

    Expected behavior Expected the pytube library to parse the link like it does with /user/, /channel/ and /c/ links.

    Output ←[31mTraceback (most recent call last): File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 409, in _run_event await coro(*args, **kwargs) File "c:\Users\[redacted]\test\QualityYouTube.py", line 108, in on_message channel_name = c.channel_name File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\contrib\channel.py", line 48, in channel_name return self.initial_data['metadata']['channelMetadataRenderer']['title'] File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\contrib\playlist.py", line 81, in initial_data self._initial_data = extract.initial_data(self.html) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\contrib\channel.py", line 78, in html self._html = request.get(self.videos_url) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\request.py", line 53, in get response = _execute_request(url, headers=extra_headers, timeout=timeout) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\request.py", line 37, in _execute_request return urlopen(request, timeout=timeout) # nosec File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen return opener.open(url, data, timeout) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open response = meth(req, response) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response response = self.parent.error( File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 557, in error result = self._call_chain(*args) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain result = func(*args) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 749, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open response = meth(req, response) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response response = self.parent.error( File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 557, in error result = self._call_chain(*args) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain result = func(*args) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 749, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open response = meth(req, response) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response response = self.parent.error( File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 563, in error return self._call_chain(*args) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain result = func(*args) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 643, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found←[0m PS C:\Users\[redacted]\test> c:; cd 'c:\Users\[redacted]\test'; & 'C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\python.exe' 'c:\Users\[redacted]\.vscode\extensions\ms-python.python-2022.20.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '53915' '--' 'c:\Users\[redacted]\test\QualityYouTube.py' ←[30;1m2022-12-30 02:03:22←[0m ←[34;1mINFO ←[0m ←[35mdiscord.client←[0m logging in using static token ←[30;1m2022-12-30 02:03:23←[0m ←[34;1mINFO ←[0m ←[35mdiscord.gateway←[0m Shard ID None has connected to Gateway (Session ID: 8003fa54f91ca34bdc56b56901acc63c). We have logged in as QualityYouTube Bot#2815 Using Discord channel: pending-channels The bot has now fully booted up and may be used. Please be advised this bot only supports one Discord server at a time. Future updates will allow for more than one server to be active at a time. ←[30;1m2022-12-30 02:20:50←[0m ←[31mERROR ←[0m ←[35mdiscord.client←[0m Ignoring exception in on_message ←[31mTraceback (most recent call last): File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 409, in _run_event await coro(*args, **kwargs) File "c:\Users\[redacted]\test\QualityYouTube.py", line 101, in on_message c = Channel(channelURL) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\contrib\channel.py", line 24, in __init__ self.channel_uri = extract.channel_name(url) File "C:\Users\[redacted]\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\extract.py", line 185, in channel_name raise RegexMatchError( pytube.exceptions.RegexMatchError: channel_name: could not find match for patterns←[0m

    System information Please provide the following information:

    • Python 3.10.9
    • pip install pytube
    bug 
    opened by flyinggoatman 5
  • [BUG]

    [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 Unexpected renderer encountered

    To Reproduce Please provide the following information: Getting an error with Search module While trying to search for "Youtube Rewind"

    Expected behavior pytube.main.YouTube object: videoId=YbJOTdZBX1g>, Output Unexpected renderer encountered. Renderer name: dict_keys(['reelShelfRenderer']) Search term: YouTube Rewind

    System information Please provide the following information:

    • Python version (run python --version) [3.8]
    • Pytube version (run print(pytube.__version__) in python) [12.1.2]
    • Command used to install pytube [pip install pytube] Screenshot (119)
    bug 
    opened by iamsyedmohammed 1
  • Unexpected renderer encountered.

    Unexpected renderer encountered.

    so i was testing z program that i created using pytube everything worked perfectly until i searched this term "central cee let her go" it actually worked fine and i downloaded the video but i got this output: Unexpected renderer encountered. Renderer name: dict_keys(['reelShelfRenderer']) Search term: central cee let her go Please open an issue at https://github.com/pytube/pytube/issues and provide this log output. other than this output everything worked fine pytube version 12.0.0

    bug 
    opened by nxxte 4
  • [BUG]

    [BUG]

    With Python 3.10.8 pytube 12.1.0 pip install pytube

    I've searched RegexMatchError on the web and it appears it had been fixed, but apparently it repeats itself.

    This is the code it's just a test: class MainPage(App): def build(self): c = Channel('https://www.youtube.com/@PyMike/videos') for url in c.video_urls[:3]: print(url) MainPage().run()

    With this channel "https://www.youtube.com/@PyMike/videos" I keep getting this error:

    Traceback (most recent call last): File "d:_python\yt_manage\main.py", line 36, in MainPage().run() File "d:_python\yt_manage\venv\lib\site-packages\kivy\app.py", line 954, in run self._run_prepare() File "d:_python\yt_manage\venv\lib\site-packages\kivy\app.py", line 924, in _run_prepare root = self.build() File "d:_python\yt_manage\main.py", line 29, in build c = Channel('https://www.youtube.com/@PyMike/videos') File "d:_python\yt_manage\venv\lib\site-packages\pytube\contrib\channel.py", line 24, in init self.channel_uri = extract.channel_name(url) File "d:_python\yt_manage\venv\lib\site-packages\pytube\extract.py", line 185, in channel_name

    raise RegexMatchError( pytube.exceptions.RegexMatchError: channel_name: could not find match for patterns

    With this other channel "https://www.youtube.com/c/ProgrammingKnowledge/videos" instead:

    Traceback (most recent call last): File "d:_python\yt_manage\venv\lib\site-packages\pytube\helpers.py", line 57, in getitem next_item = next(self.gen) StopIteration

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "d:_python\yt_manage\main.py", line 35, in MainPage().run() File "d:_python\yt_manage\venv\lib\site-packages\kivy\app.py", line 954, in run self._run_prepare() File "d:_python\yt_manage\venv\lib\site-packages\kivy\app.py", line 924, in _run_prepare root = self.build() File "d:_python\yt_manage\main.py", line 22, in build for url in c.video_urls[:3]: File "d:_python\yt_manage\venv\lib\site-packages\pytube\helpers.py", line 60, in getitem raise IndexError IndexError

    Can you help me? I just started learning python.

    bug 
    opened by pietrocaporale 0
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)
  • 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)
  • 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)
  • 0.3.1(Sep 6, 2015)

  • 0.3.0(Sep 6, 2015)

Command-line program to download videos from YouTube.com and other video sites

youtube-dl - download videos from youtube.com or other video platforms INSTALLATION DESCRIPTION OPTIONS CONFIGURATION OUTPUT TEMPLATE FORMAT SELECTION

youtube-dl 116.4k Jan 7, 2023
Python wrapper for Xeno-canto API 2.0. Enables downloading bird data with one command line

Python wrapper for Xeno-canto API 2.0. Enables downloading bird data with one command line. Supports multithreading

_zza 9 Dec 10, 2022
Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

Telegram VCVideoPlayBot An Telegram Bot By @ZauteKm To Stream Videos in Telegram Voice Chat. NOTE: Make sure you have started a VoiceChat in your Grou

Zaute 20 Oct 21, 2022
Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

SUBIN 449 Dec 27, 2022
📢 Video Chat Stream Telegram Bot. Can ⏳ Stream Live Videos, Radios, YouTube Videos & Telegram Video Files On Your Video Chat Of Channels & Groups !

Telegram Video Chat Bot (Beta) ?? Video Chat Stream Telegram Bot ?? Can Stream Live Videos, Radios, YouTube Videos & Telegram Video Files On Your Vide

brut✘⁶⁹ // ユスフ 15 Dec 24, 2022
Utility for downloading fanfiction in bulk from the Archive of Our Own

What is this? This is a program intended to help you download fanfiction from the Archive of Our Own in bulk. This program is primarily intended to wo

null 73 Dec 30, 2022
Script for downloading Coursera.org videos and naming them.

Coursera Downloader Coursera Downloader Introduction Features Disclaimer Installation instructions Recommended installation method for all Operating S

Coursera Downloader 9k Jan 2, 2023
Python Library to Extract youtube video Tags without Youtube API

YoutubeTags Python Library to Extract youtube video Tags without Youtube API Installation pip install YoutubeTags Example import YoutubeTags from Yout

Nuhman Pk 17 Nov 12, 2022
A youtube videos or channels tag finder python module

A youtube videos or channels tag finder python module

Fayas Noushad 4 Dec 3, 2021
Python bot for send videos of a Youtube channel to a telegram group , channel or chat

py_youtube_to_telegram Usage: If you want to install ytt and use it, run this command: sudo sh -c "$(curl -fsSL https://raw.githubusercontent.com/nima

Nima Fanniasl 8 Nov 22, 2022
Download videos from Youtube and other platforms through a Telegram Bot

ytdl-bot Download videos from YouTube and other platforms through a Telegram Bot Usage: https://t.me/benny_ytdlbot Send link from YouTube directly to

Telegram Bot Collection 289 Jan 3, 2023
Telegram bot to trim and download videos from youtube.

Inline-YouTube-Trim-Bot Telegram bot to trim and download youtube videos Deploy You can deploy this bot anywhere. Demo - YouTubeBot Required Variables

SUBIN 56 Dec 11, 2022
A Telegram Bot to Play Audio in Voice Chats With Youtube and Deezer support. Supports Live streaming from youtube Supports Mega Radio Fm Streamings

Bot To Stream Musics on PyTGcalls with Channel Support. A Telegram Bot to Play Audio in Voice Chats With Supports Live streaming from youtube and Mega

Shamil Habeeb 37 Dec 15, 2022
A Telegram bot to download youtube playlists and upload them to telegram. (may be slow becoz youtube limitations)

YTPlaylistDL ?? A Telegram bot to download youtube playlists and upload them to telegram. (may be slow becoz youtube limitations) ?? Follow me and sta

Anjana Madu 43 Dec 28, 2022
Google Drive, OneDrive and Youtube as covert-channels - Control systems remotely by uploading files to Google Drive, OneDrive, Youtube or Telegram

covert-control Control systems remotely by uploading files to Google Drive, OneDrive, Youtube or Telegram using Python to create the files and the lis

Ricardo Ruiz 52 Dec 6, 2022
Automation that uses Github Actions, Google Drive API, YouTube Data API and youtube-dl together to feed BackJam app with new music

Automation that uses Github Actions, Google Drive API, YouTube Data API and youtube-dl together to feed BackJam app with new music

Antônio Oliveira 1 Nov 21, 2021
A zero-dependency Python library for getting the Kubernetes token of a AWS EKS cluster

tokeks A zero-dependency Python library for getting the Kubernetes token of a AWS EKS cluster. No AWS CLI, third-party client or library (boto3, botoc

Chris Karageorgiou Kaneen 6 Nov 4, 2022
This is a very easy to use tool developed in python that will search for free courses from multiple sites including youtube and enroll in the ones in which it can.

Free-Course-Hunter-and-Enroller This is a very easy to use tool developed in python that will search for free courses from multiple sites including yo

Zain 12 Nov 12, 2022