Another Youtube Video Downloader for Python.
Project description
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) :
Existing Features
- Convert to mp3 or mp4 (Requires Moviepy - pip install moviepy)
- Fetch Comments
- 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.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.subscribers # Returns no. of subscribers
>>> yt.meta # Returns the metadata about video (Songs specifically)
>>> yt.channelUrl # Returns url of the channel
>>> yt.channelThumb # Thumbnail of channel
>>> yt.channelName # Returns name 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 # Return long description
>>> yt.keywords # Returns list of keywords if available
>>> yt.is_live # Return True if format is a live stream
>>> yt.thumbnail # Returns thumbnail URL
>>> yt.category # Category of the video
>>> yt.dashUrl # Return dashStreamingUrl (if it is a live video)
>>> yt.hlsUrl # Return hlsStreamingUrl (if it is a live video)
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)
- convert takes a string as an argument. It converts the video into the extension you want. Ex: 'webm' -> 'mp3'. [mp4 coming soon]
- 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)
- path takes full path where you want to save file
- 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:
- Get list of all the Videos
- Create Continuation URL if len(videos)>100
- 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tube_dl-4.1.1.tar.gz
.
File metadata
- Download URL: tube_dl-4.1.1.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d1a2d90d2d4dbe94085f65f728e731df04dc5d6df8c2a26e4d4177e3be2203c |
|
MD5 | 6ba9e3a798f12e83488d4b407895765e |
|
BLAKE2b-256 | 5105cf74608693cf6dfd58843b17c862c3babfc63d6aa5fd60297cc1bbc440e5 |
File details
Details for the file tube_dl-4.1.1-py3-none-any.whl
.
File metadata
- Download URL: tube_dl-4.1.1-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 866973d0f61729d681f6f41266172a3c5b432b0940272de82f26f58d2702e6f5 |
|
MD5 | 38e00b258aad13acad7cc34934ed0aac |
|
BLAKE2b-256 | aad9a6cf7fc38a6fd0534f8ca35883590fb68b9662a954a3a9fb631ed97a7838 |