Youtube video downloader and info extractor for python.

Overview

Generic badge GitHub issues PyPI download month GitHub followers

tube_dl

Tube_dl is a Simple Youtube video downloader for Python. A Modular approach to bypass and download Youtube Videos and Playlist from Youtube using python.

>>> pip install tube_dl

Features:

What's New (v4.1.0) :

  1. Merge audio and video file.
  2. Get links for streamable file (for Live videos) --> m3u8 file

Existing Features

  1. Convert to mp3 or mp4 (Requires Moviepy - pip install moviepy)
  2. Fetch Comments
  3. Fetch Captions

Usage:

>>>from tube_dl import Youtube
>>>yt = Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k")
>>>yt.formats.first().download()

What is Formats?

formats is a class containing all the Youtube streams.

You can also see all the streams by :

>>> Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k").Formats()

** Note that Formats() and formats are different. When you use Formats(), a list of all streams of format class is returned. When you use formats, a list of all streams of list_formats class is returned.

Other Details

Printing Information about the Video:

You can print the info or use them anywhere in your code. Here are the list of Information available:

>>> yt.videoID # ID of the video
>>> yt.availableCountries #List of countries where video is playable
>>> yt.title # Returns the title of the video
>>> yt.views # Return total views
>>> yt.channelName # Returns the name of the channel
>>> yt.views # Returns total number of views
>>> yt.likes # Returns total likes
>>> yt.dislikes # Returns total dislikes
>>> yt.meta # Returns the metadata about video (Songs specifically) 
>>> yt.channelId # Returns url of the channel
>>> yt.length # Returns the total length of the Youtube Video (in seconds)
>>> yt.uploadDate # Returns the upload date of the video
>>> yt.description # Returns long description
>>> yt.keywords # Returns list of keywords if available
>>> yt.is_live # Returns True if format is a live stream
>>> yt.thumbnail # Returns thumbnail URL
>>> yt.category # Category of the video
>>> yt.dashUrl # Returns dashStreamingUrl (if it is a live video)
>>> yt.hlsUrl # Returns hlsStreamingUrl (if it is a live video) 
>>> yt.hashTags # Returns list of hashtags used in a video.
>>> yt.subscribers # Returns total number of subscribers(Aprroximate)

using filter_by option:

Returns : list(list_formats) You can filter the formats according to the itag, adaptive, progressive, fps, quality, only_audio, no_audio. Example:

>>>Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k").formats.filter_by(only_audio=True)

Other options:

>>> yt.first()
Returns the first index of list_formats
>>> yt.last()
Returns the last index of list_formats

Example:

>>> Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k").formats.filter_by(only_audio=True).first()

Downloading a format:

To download a format, .download() function is used. Params : Download takes following parameters. All are optional .download(convert,onprogress,path,file_name)

  1. convert takes a string as an argument. It converts the video into the extension you want. Ex: 'webm' -> 'mp3'. [mp4 coming soon]
  2. onprogress takes function name as an argument. The function should have three arguments: Ex: def show_progress(Chunk=None,bytes_done=None,total_bytes=None)
  3. path takes full path where you want to save file
  4. file_name takes name of the file. by default, it is .title of the video. It is then processed to safe_filename to strip any invalid character.
  • You can print final filename by using formats.safe_filename() Ex:
>>> filename = Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k").formats.safe_filename()

Working with Playlist

This Class is responsible for:

  1. Get list of all the Videos
  2. Create Continuation URL if len(videos)>100
  3. Get Continuation data and append all the video IDs to IDS variable

Parameters : url: str - URL of the PlayList start- Define start index of Videos end - Defines end index of videos.

Returns : Tuple : All the Video IDs within the Range variable( if Defined)

  >>> from tube_dl import Playlist, Youtube
  >>> pl = Playlist('https://music.youtube.com/playlist?list=PLTy__vzNAW6C6sqmp6ddhsuaLsodKDEt_').videos
  >>> for i in pl:
  >>>   yt = Youtube(f'https://youtube.com/watch?v={i}')
  >>>   yt.formats.first().download()

Captions

Now you can download captions from youtube. Here's the Sample code.

>>> from tube_dl captions import Captions
>>> caption = Captions('url',language='en') # Use Captions('url').caption_details to get list of languages
>>> caption.fetch_captions() #raw xml output of captions
>>> caption.convert_to_srt(path='c://xample_path//',file_name='captions.srt') # Default filename is youtube id and default path is os.getcwd()

Comments

Yes! It's possible. You can also download comments for a youtube video. It's still in beta but works absolutely file. Here's a simple use case of that.

>>> from tube_dl.comments import Comments
>>> comment = Comments('Your Youtube URL').process_comments(count=45) # Don't define count variable to get all the comments.
  • Fetching Replies for comments are not available yet. But will be there soon. Feel free to raise issues tickets.

Convert Formats

Converting any format to mp3 and mp4 is easy. Here's how to do it:

converting to mp3

>>> from tube_dl import Youtube, extras
>>> yt = Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k").formats.filter_by(only_audio=True)[0]
>>> b = a.download() #b variable stores the filename and meta(if available) as object of Output class.
>>> extras.Convert(b,'mp3',add_meta=True) #this will convert the format to mp3 and add meta if var add_meta is True

converting to mp4

>>> from tube_dl import Youtube, extras
>>> yt = Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k").formats.filter_by(only_audio=True)[0]
>>> b = a.download() #b variable stores the filename and meta(if available) as object of Output class.
>>> extras.Convert(b,'mp4',kepp_original=True) #this will convert the format to mp4 and add_meta is not available for mp4 files.
#if keep_original is True, previous format will be deleted i.e. the file downloaded

Merging Formats

Please note that the merge should be between an audio and a video file. Merging speed depends on file size and your system processing speed and it completely depends on CPU performance.

>>> from tube_dl import Youtube, extras
>>> yt = Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k")
>>> yt1 = Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k")
>>> video=yt.formats.filter_by(adaptive=True)[0].download()
>>> audio = yt1.formats.filter_by(only_audio=True)[0].download()
>>> extras.Merge(audio=audio,video=video,result='output.mp4',keep_original=False) 

The result variable stores the output filename and if keep_original = False, it will delete the raw files keeping only the output file.

Working with Live Streams

With live streams, few extra options are available apart from the normal functions. As live streams are not static, a streaUrl is provided by youtube in manifest format. Here's how to grab them.

>>> yt = Youtube('https://www.youtube.com/watch?v=U_XkCKlRcGQ')
>>> if yt.is_live==True:
>>> 	print(yt.hlsUrl)
>>> 	print(yt.dashUrl)

** This module is built for personal use. Please don't use this in production. I shall not be responsible for any consequences whatsoever.

Comments
  • KeyError: 'sentimentBar'

    KeyError: 'sentimentBar'

    I'm downloading a video, https://m.youtube.com/watch?v=HhV_Y8C5YKo, and get the following error:

    Traceback (most recent call last):
      File "main.py", line 52, in <module>
        download_audio(lin)
      File "main.py", line 27, in download_audio
        yt = Youtube(url).formats.filter_by(only_audio=True)[0]
      File "/Users/jeff/Documents/Projects/pytubedl/venv/lib/python3.8/site-packages/tube_dl/__main__.py", line 75, in __init__
        self.likes, self.dislikes = [i.strip() for i in extraDetails["sentimentBar"]["sentimentBarRenderer"]["tooltip"].split('/')]
    
    opened by jzohrab 4
  • Key Error 'Runs'

    Key Error 'Runs'

    Getting an Error when running the following:

    Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k").formats.filter_by(only_audio=True).first()

    File "[myPath]\env\lib\site-packages\tube_dl_main_.py", line 64, in init self.subscribers=extraDetails[1]['videoSecondaryInfoRenderer']["owner"]["videoOwnerRenderer"]["subscriberCountText"]["runs"][0] KeyError: 'runs'

    opened by RockoonTechnologies 3
  • Tube_dl library import isn't recognized!

    Tube_dl library import isn't recognized!

    Python version>> 3.10.5

    Command used for installation: "pip install tube_dl".

    The tube_dl library was installed, but at the time of import it is not recognized, I imported the same as the usage tutorial, but it is not found or recognized, the command: "from tube_dl import Youtube" I did a search for cmd with the command "pip3 list" and it really said that it was installed, but when looking for the folder in tube_dl on venv, it is not, please help me, I need this library a lot.

    opened by EsdrasUday 2
  • Fixed some causes for exception for not being able to download certain videos

    Fixed some causes for exception for not being able to download certain videos

    Formatting fixed, few extra checks added removed some tokens from song title which raises exceptions for opening a file with that name, dislikes, subscriber count etc maybe zero, hence the key may not be present in metadata

    opened by creepysta 2
  • Error while using the tool. KeyError: 'runs'

    Error while using the tool. KeyError: 'runs'

    I tried the following command:

    print(Youtube('link here'))
    

    and it returned back with the following error:

    Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.8/site-packages/tube_dl/main.py", line 64, in init self.subscribers=extraDetails[1]['videoSecondaryInfoRenderer']["owner"]["videoOwnerRenderer"]["subscriberCountText"]["runs"][0] KeyError: 'runs'

    opened by anirudhbagri 1
  • list index out of range

    list index out of range

    according to your usage

    from tube_dl import Youtube yt = Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k") yt.formats.first().download()

    Error: yt = Youtube("https://youtube.com/watch?v=R2j46bHm6zw&list=RDAMVMd4HYhxlsj5k") File "/usr/local/lib/python3.9/dist-packages/tube_dl/main.py", line 75, in init self.likes=re.findall(r"'label': '(.*?) likes'",str(i))[0].replace(',','') IndexError: list index out of range

    opened by Sekisback 1
  • path separators are os dependent

    path separators are os dependent

    Nice package! Tried under linux and I had to modify formats.py.

    final_path = f'{path}\{file_name}.{extension}' to: final_path = f'{path}' + os.path.sep + f'{file_name}.{extension}'

    I'm sure there are other places that the separator should be fixed.

    opened by tkamm 1
  • KeyError when downloading

    KeyError when downloading

    Traceback (most recent call last):
      File "C:\Users\fixin\PycharmProjects\TTS\main.py", line 58, in <module>
        save_to_file()
      File "C:\Users\fixin\PycharmProjects\TTS\main.py", line 52, in save_to_file
        Youtube(keys[key]).formats.filter_by(only_audio=True).first().download(convert="mp3")
      File "C:\Users\fixin\PycharmProjects\TTS\venv\lib\site-packages\tube_dl\__main__.py", line 73, in __init__
        self.description = ''.join([i["text"] for i in extraDetails[1]['videoSecondaryInfoRenderer']['description']["runs"]])
    KeyError: 'description'
    
    opened by Nebulizer1213 0
  • unable to get number of likes from video

    unable to get number of likes from video

    import tube_dl
    yt = tube_dl.Youtube("https://www.youtube.com/watch?v=eZYtnzODpW4")
    print(yt.likes)  
    
    File "/home/matteo/.local/lib/python3.8/site-packages/tube_dl/__main__.py", line 75, in __init__
        self.likes, self.dislikes = [i.strip() for i in extraDetails["sentimentBar"]["sentimentBarRenderer"]["tooltip"].split('/')]
    KeyError: 'sentimentBar'
    
    opened by cosimopp 0
  • DO NOT fetch full list of video in the playlist (max 200 videos)

    DO NOT fetch full list of video in the playlist (max 200 videos)

    It seems that after the first time using Token extracted from HTML, the author continues to use that token while the token already changed. To fix this problem, update to use new token to get full of playlist.

    In python file containing class Playlist

    In function:

       def fetch_continuation(self, html):
              #same code
              return data
    
    

    In function:

    def __init__(self, url: str, start: int = None, end: int = None):
            # same code
            if total_count > 100:
                start_html = html
                for i in range(0, total_count//100):
                    start_html = self.fetch_continuation(start_html)
                # same code
    
    

    Hope this help.

    opened by hahv 1
Owner
Shekhar Chander
Shekhar Chander
A python scripts that downloads doujin from nhentai without having an account

nhentai-downloader a python scripts that downloads doujin from https://nhentai.net without having an account. Usage Needs Python 3^ Linux pip3 install

Earl Sabalo 4 Jun 13, 2022
Download the resources of the Blue Archive easily!

blue-archive-bundle-downloader Download the resources of the Blue Archive easily! Known issue In Windows It works only if the console is "fullscreen"

Ryu juheon 7 Apr 08, 2022
A very fast file streaming bot used for streaming and downloading movies

FileStreamBot GIVE A STAR AND FORK ELSE NO MORE OPENSOURCE A Telegram bot to turn all media and documents files to web link . Report a Bug | Request F

Code X Mania a.k.a Adarsh Goel 190 Jan 04, 2023
Python youtube playlist downloader

Youtube-Playlist-Downloader-python ๐Ÿ‘ This program is a simple Youtube playlist downloader where you input the playlist link, and then the desired pat

Pepczenko 2 Dec 25, 2021
Python utility to download jobs at seek.com.au

Job Seeker job_seeker is an utility to download data of a job search from seek.com.au into a csv file for data analysis and exploration Install using

PyBites 3 May 14, 2022
YoutubeDownloader - Download any public Playlist from Youtube

YoutubeDownloader Download any public Youtube Channel / Playlist Features Bulk d

17 Nov 12, 2022
Gogoanime-dl - Gogoanime downloader for downloading anime.

gogoanime-dl With this script, you can download episodes of your favorite anime from Gogoanime. The current site that's developed against is https://w

1 Jan 06, 2022
Youtube video downloader and info extractor for python.

tube_dl Tube_dl is a Simple Youtube video downloader for Python. A Modular approach to bypass and download Youtube Videos and Playlist from Youtube us

Shekhar Chander 16 Jul 09, 2022
Tool To download Amazon 4k SDR HDR 1080, CDM IS Not Included

WV-AMZN-4K-RIPPER Tool To download Amazon 4k SDR HDR 1080, CDM IS Not Included For CDM You can Mail :- Denis Trunov 179 Dec 17, 2022

๐ด ๐‘ก๐‘’๐‘™๐‘’๐‘”๐‘Ÿ๐‘Ž๐‘š ๐‘๐‘œ๐‘ก ๐‘กโ„Ž๐‘Ž๐‘ก ๐‘๐‘Ž๐‘› ๐‘‘๐‘œ๐‘ค๐‘›๐‘™๐‘œ๐‘Ž๐‘‘ ๐‘ฃ๐‘–๐‘‘๐‘’๐‘œ ๐‘Ž๐‘›๐‘‘ ๐‘Ž๐‘ข๐‘‘๐‘–๐‘œ ๐‘“๐‘Ÿ๐‘œ๐‘š ๐‘ฆ๐‘œ๐‘ข๐‘ก๐‘ข๐‘๐‘’ ๐‘Ž๐‘›๐‘‘ ๐‘ฃ๐‘–๐‘‘๐‘’๐‘œ ๐‘ค๐‘’๐‘๐‘ ๐‘–๐‘ก๐‘’๐‘  ๐‘ž๐‘ข๐‘–๐‘๐‘˜๐‘™๐‘ฆ

๐ด ๐‘ก๐‘’๐‘™๐‘’๐‘”๐‘Ÿ๐‘Ž๐‘š ๐‘๐‘œ๐‘ก ๐‘กโ„Ž๐‘Ž๐‘ก ๐‘๐‘Ž๐‘› ๐‘‘๐‘œ๐‘ค๐‘›๐‘™๐‘œ๐‘Ž๐‘‘ ๐‘ฃ๐‘–๐‘‘๐‘’๐‘œ ๐‘Ž๐‘›๐‘‘ ๐‘Ž๐‘ข๐‘‘๐‘–๐‘œ ๐‘“๐‘Ÿ๐‘œ๐‘š ๐‘ฆ๐‘œ๐‘ข๐‘ก๐‘ข๐‘๐‘’ ๐‘Ž๐‘›๐‘‘ ๐‘ฃ๐‘–๐‘‘๐‘’๐‘œ ๐‘ค๐‘’๐‘๐‘ ๐‘–๐‘ก๐‘’๐‘  ๐‘ž๐‘ข๐‘–๐‘๐‘˜๐‘™๐‘ฆ

SOCIAL MECHANIC 2 Aug 04, 2022
Will load an SRC page, logged in with Firefox's cookies imported, and delete all comments from every run

SRCCommentsAutoDeleter Will load an SRC page, logged in with a support browser's cookies, and delete all comments from every run Config is all done in

3 Oct 29, 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

1.6k Apr 12, 2022
Python/Selenium script to scrape data about university courses

university-courses Python/Selenium script to scrape data about university courses. Script first extracts URLs of each courses homepage, then trawls ea

Sam Brown 1 Feb 02, 2022
Let's you download entire YT-playlists.

Youtube MP3 Playlist Downloader Let's you download entire youtube playlists as mp3 files. This application is basically a script that makes it easier

11 Dec 18, 2022
Music, Album and Playlist downloader for JioSaavn

jiosaavn-dl Music, Album and Playlist downloader for JioSaavn Features Downloads tracks, albums and playlists in maximum available quality (320kbps AA

bunny 19 Dec 12, 2022
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 23 Dec 22, 2022
lo2: Simple youtube-dl web frontend

Simple youtube-dl web frontend

Denis Volk 22 Jun 03, 2022
Automatically download and crop key information from the arxiv daily paper. (cpu version)

Automatically download and crop key information from the arxiv daily paper. (cpu version)

HeoLis 4 Jul 30, 2022
Used Insta Loader to download high quality images from instagram account

Insta Dp Downloader Project Description: In this project, I have used "Insta Loader" to download high quality images from instagram account. You only

Hassan Shahzad 3 Oct 31, 2022
YouTube-Video-Downloader - Download Youtube Videos for free.

YouTube-Video-Downloader Download Youtube Videos for free. Installing Dependencies:- Windows pip install pytube Mac/Linux pip3 install pytube Clonin

Xception Inc. 1 Jan 01, 2022