Hello readers! Today, we will be building a YouTube downloader inPython3 using the PyTube3 library. The original pytube library no longer works and so we need to use the pytube3 library which only works with Python3 and not with Python2.

We will see various things we can do with our Youtube Downloader and various functionalities it offers to us. So, let’s do it step by step.

Downloading and Importing the libraries

First things first, before doing anything else, you need to download the pytube3 library in your system. To do this we will be using python3.

Type in the following command in the CLI to download and install pytube3 in your system.

pip install pytube3

This command will download and install pytube3 in your system.

Now we can start building our YouTube Downloader. Now we need to import the library in our program for using its functionalities.

So, we start our program with the following command:

from pytube import YouTube

You will notice that while we downloaded and installed pytube3 in our system but we are here importing pytube in the code.

To clear up the confusions, pytube3 is also imported by writing pytube only. We do not import it by writing as pytube3.

Accepting Input from User

Our next step would be to ask the user to provide us with the link of the youtube video which we need to download. User will then provide us with the link of the video he intends to download.

link = input(“Enter the link: “)
yt = YouTube(link)

So, we have accepted input from the user and passed on the link to our YouTube class. It will help us reveal all the information about the video and also will let us download it.

Revealing various Information about the Video

Now, we have the link, we have passed it into the YouTube class. Now, we can play with the link and reveal all sorts of information about the video like its title, number of views, ratings, description, length of the video and various other things.

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

#Number of views of video
print(“Number of views: “,yt.views)
#Length of the video
print(“Length of video: “,yt.length,”seconds”)
#Description of video
print("Description: ",yt.description)
#Rating
print("Ratings: ",yt.rating)

Now, when we will run this code, we will get to see various details about the video whose link we have fed into the program. Also, there are many more such operations that can be performed which you can find in the official documentation of pytube3.

So, for output purpose, we are not printing description (it’s large), so we are printing the rest four things.

We have used the link for the official trailer of Dark Season 3 here. You can use any link as per your choice.

#Output obtained on running the code
	Title:  Dark Season 3 | Official Trailer | Netflix
	Number of views:  2019403
	Length of video:  147 seconds
	Ratings:  4.9721289

Output showing various details of the video

So, as you can see above, we have printed various details about the show.

#programming #youtube-downloader #towards-data-science #coding #python

Build a YouTube Downloader with Python
7.10 GEEK