Interesting Python Module PyTube
Tags: python, miniproject, youtube, beginners
Published: 2021-11-26 11:07:58

Hello Everyone ,
In this Interesting Python Module series I will be discussing about interesting python module you must know.
And it will be actually a fun way to learn python by making some micro projects using some interesting python module. So lets started...


In this blog I will be discussing about `PyTube`. Its an awesome python module which helps us download youtube video!!!

I know ,I know ,you will be surprised by reading this, but yes this module help us download youtube video.

> #### Problem Statement :
As we know youtube video can be downloaded and can be watched offline on mobile(iOS and Android) but on desktop its not possible . Using this python pytube module we can download youtube video on desktop.

So not just waste time and learn how we can write python code to download youtube video.

Before starting with the code part we must have python 2.7 or 3 version installed.

>Note :
When you are installing python do check the box which says something like "pip" we will required it for installing pytube module . If we dont do that we will get error during installation of pytube module.

And after python installed properly one more thing need to be installed and that is Pytube Module.
So just open command prompt and type this pip command which will install our module.

```
pip install pytube
```

We will get output for the pip command something like this

![pip install output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/srwrfrqhuggcgct9z02u.png)

And I have also created one folder which has initially one python file and in this folder I m going to download youtube video.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/313w7whvzf678hoagtf0.png)

Now lets open ide and understand how code will work(I'm using the IDE which comes with python itself)


 
 

#### Code :

```python
# importing the pytube module
from pytube import YouTube


# link of the video to be downloaded
link="https://youtu.be/z-vLtsKvp_4"

yt = YouTube(link)

# getting title of the video
head= yt.title
print(head)

#the streams is pytube class which help filter the content and download just audio or video or both

dl = yt.streams.get_by_itag(22)
#itag is the value given to different video quality stuff.
# For example here itag value 22 means video quality is 720p and we download both audio as well as video format
# Similarly itag value 18 means video quality is 360p and there are many itag value through which you can download differently like just audio or video or both with different video quality.

dl.download()
```

#### Output:

On console/python shell we get title of the youtube video printed.

![Output 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oodpt1o8tgbixvh87pek.png)

Our video gets downloaded were our python file is present automatically
![video](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/43sqr2wfrsipc1kjs661.png)


There is many methods and features to be explored of pytube ,you can read those on official pytube docs.

Pytube : [Docs](https://pytube.io/en/latest/) | [Github](https://github.com/pytube/pytube) 

> #### Idea for Mini Project using Pytube Module :
We can make one mini project using PyTube and Tkinter which will download youtube video of different video quality and create GUI which will ask input from user for "youtube link","video quality",etc.
 
I m a individual content writer and if you like my work ,do consider buying me a book your small contribution will help be to bring more awesome content.
<p align="center">
<a href="https://www.buymeacoffee.com/Atharva08" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
</p>