In this article, we are going to learn how to build a youtube video downloader using python.
YouTube is a very popular video-sharing website. Downloading a video from YouTube is quite a tough job. Download extensions to download YouTube videos or use another website to get the video. Using Python, this task is very easy. A few lines of code will download the video from YouTube for you. For this, there is a python library named ‘pytube’. pytube is a lightweight, dependency-free Python library that is used for downloading videos from the web.
- To know more about the pytube package, you can read this documentation –
Installing the required package:
Command to install pytube: pip install pytube
- After installing the required package, Create a folder named YouTubeVideoDownloder.
- Then open the python IDLE and create a new file.
First, we import the pytube module that we will be using in our project to download the YouTube videos.
After that, we will take input the URL of the YouTube video.
We are taking input so that we can copy-paste the URL of the video instead of writing it in the code manually.
link = input(‘Paste the url here : ‘)
link = input('Paste the url here : ')
We will use the YouTube() method from the pytube module to convert the URL into link and the use it to download the video.
video = pytube.YouTube(link)
video = pytube.YouTube(link)
After, we use the stream().frist().dowload() to download the video that we wanted to.
In the end, we use the print statement to just make sure that we know that our video is downloaded.
print(“Downloaded Successfully, “,link)
print("Downloaded Successfully, ",link)
After writing the code save the file with .py extension in the folder that we have created at the beginning of the project.
Here is the complete source code of the project.
# Program to download youtube vidoes # Importing the module import pytube # Taking input the link link = input('Paste the url here : ') # Using the module to download the video video = pytube.YouTube(link) video.streams.first().download() #promt to make sure that the download is complete print("Downloaded Successfully, ",link)
Now run the code, you should be getting the output in the following way:
First, we will need to paste the URL link of the video that we wanted to download.
After, that we wait for the video to download, and after the video is downloaded we will be shown a message that the video was successfully downloaded.
The video will be downloaded to the same folder as the program.
NOTE : Make sure that you have an internet connection to download the video.
If your video is not downloaded, then read the article again and try it.
If it worked congratulations you now know how to download a YouTube Video using python.
2 thoughts on “YouTube video downloader | Python”
How To Download Video In High Resolution ?
Currently, the module for downloading high-resolution videos is not working. We will update you with new article when it is available.