Pytube3 – Download YouTube Videos Using Python

Filed Under: Python Modules
Pytube3 Download YouTube Videos Using Python In Seconds

You may have used many YouTube downloaders available on the web to download your favorite YouTube videos. But, how about building a YouTube downloader? Seems interesting? Let’s roll.

Download Youtube Videos Using Python Pytube3

Python offers Pytube3 – a package that helps us to fetch the information about videos on YouTube and of course we can download them. Without much intro let’s quickly build one.


1. Pytube3

Pytube3 is an awesome python library to fetch the video information and download it from YouTube.

One of the best features of Pytube3 is it supports downloading the entire playlist based on the video and audio quality.

It offers caption tracking also without any third-party dependency.

You can get the entire information about the video such as the number of views, likes, title, ratings, description, and many more.

You can download the front-end GUI here – YouTube Download.


2. Installing Pytube3

Let’s install and load the Pytube3 library in python using the pip installer.

#install pytube3

pip install pytube3

Import the library into python.

#import

from pytube import YouTube

That’s cool! Now we are good to go…


3. Accept Video Link as Input

The first step is to ask for the user input for the video link from YouTube. Upon adding the link, we will pass that to the YouTube function.

#user input

video_link = input(“Enter the link: “) #https://www.youtube.com/watch?v=51u5fnyrGj4
Y_tube= YouTube(video_link)

Now, we can fetch the details about the input video as shown below.

#details

#Title 
print(“Title: “,yt.title)

#views
print(“Number of views: “,yt.views)

#Rating of the video
print("Ratings: ",yt.rating)
Title:  Duncan Laurence - Arcade (Lyric Video) ft. FLETCHER
Number of views: 74,984,463
Length of video:  185 seconds
Ratings:  4.67

4. Streams Information

The steams parameter will give us the list of streams available for a particular video. Let’s see how many streams are available for our video.

#Strems

yt.streams.filter(only_video=True)
Pytube3

You can select the particular steam which you want to download. You can even see the Audio streams alone by passing audio_only = True.


5. Setting Up The GUI

Yes, the best part of this library is it has the Front end GUI which you can download on Windows or Mac. To download this GUI for Windows and Mac – https://github.com/YouTubeDownload/YouTubeDownload.

Pytube3
Pytube3
  • You have to load the video URL.
  • Browse the output directory to save the file.
  • Choose the streams available.
  • Click on “Download”.
  • This GUI is easy to use and have many features which is amazing.

6. Download Using Python

Now, let’s see how we can download YouTube videos using Pytube3 in python. We will continue from where we left in previous sections (code).

#download

yt.download()

or 

yt.download('download path')

Using the above download command, you can download the video. You can use the download() option to save the video in your current directory.

But, you can also specify the download path if you wish to save this in another folder.


Pytube3 – Wrapping Up

Pytube3 is one of the most simple python libraries to download YouTube videos based on streams. It offers many features along with a GUI which you can install on Windows and Mac. I hope you found this useful. That’s all for now. Happy Python!!!

More read: Python GUI

close
Generic selectors
Exact matches only
Search in title
Search in content