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.
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.
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
Now lets open ide and understand how code will work(I'm using the IDE which comes with python itself)
# 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()
On console/python shell we get title of the youtube video printed.
There is many methods and features to be explored of pytube ,you can read those on official pytube docs.
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.