Hello there! Today we are going to build our own YouTube Video Downloader. Interesting right?! So let’s begin!
Introduction to the Project
The YouTube Video downloader aims at downloading any type of video from YouTube in a fast, simple, and easy way.
The user has to copy the youtube video URL link which needs to be pasted into the application. Later, the user needs to click on the download button in order to download the video.
If you will use this program for bulk downloads, chances are that YouTube will block your IP. So, it’s wise to use a VPN for bulk downloading requirements and safeguard your IP from getting blocked.
1. Import Libraries/Modules
For the current project, we will be importing two modules namely Tkinter
and pytube
module where the pytube module is used to handle operations related to YouTube.
import tkinter as tk
from pytube import YouTube
2. Creating a Tkinter Window
The code below creates a blank and customized Tkinter application window. By now, you might be familiar with this basic code.
window = tk.Tk()
window.geometry("600x200")
window.config(bg="#EC7063")
window.resizable(width=False,height=False)
window.title('YouTube Video Downloader')
window.mainloop()
3. Adding Widgets to Tkinter Screen
We would add three simple widgets namely labels, buttons, and entry boxes. The code for the same is shown below with the added lines added for you.
window = tk.Tk()
window.geometry("600x200")
window.config(bg="#EC7063")
window.resizable(width=False,height=False)
window.title('YouTube Video Downloader')
link = tk.StringVar()
tk.Label(window,text = ' Youtube Video Downloader ', font ='arial 20 bold',fg="White",bg="Black").pack()
tk.Label(window, text = 'Paste Your YouTube Link Here:', font = 'arial 20 bold',fg="Black",bg="#EC7063").place(x= 5 , y = 60)
link_enter = tk.Entry(window, width = 53,textvariable = link,font = 'arial 15 bold',bg="lightgreen").place(x = 5, y = 100)
tk.Button(window,text = 'DOWNLOAD VIDEO', font = 'arial 15 bold' ,fg="white",bg = 'black', padx = 2,command=Download_Video).place(x=385 ,y = 140)
window.mainloop()
The final design of the application is displayed below.

4. Creating Function for Download Video
Button
Now for the Download button to work, we need to define a Download_Video
function and link the function with the button using command
property in the Button declaration. The code for the function is shown below:
def Download_Video():
url =YouTube(str(link.get()))
video = url.streams.first()
video.download()
tk.Label(window, text = 'Your Video is downloaded!', font = 'arial 15',fg="White",bg="#EC7063").place(x= 10 , y = 140)
Firstly with the help of get
function we would extract the link from the entry box. Then with the help of the YouTube function the url is checked on the youtube.
And finally, using the streams.first
function video is extracted from YouTube and is later downloaded using the download
function.
After the download is completed and is a success a new label is added on the screen which says Your Video is downloaded!.
Complete Code for YouTube Video Downloader in Tkinter
The complete code is shown below.
import tkinter as tk
from pytube import YouTube
def Download_Video():
url =YouTube(str(link.get()))
video = url.streams.first()
video.download()
tk.Label(window, text = 'Your Video is downloaded!', font = 'arial 15',fg="White",bg="#EC7063").place(x= 10 , y = 140)
window = tk.Tk()
window.geometry("600x200")
window.config(bg="#EC7063")
window.resizable(width=False,height=False)
window.title('YouTube Video Downloader')
link = tk.StringVar()
tk.Label(window,text = ' Youtube Video Downloader ', font ='arial 20 bold',fg="White",bg="Black").pack()
tk.Label(window, text = 'Paste Your YouTube Link Here:', font = 'arial 20 bold',fg="Black",bg="#EC7063").place(x= 5 , y = 60)
link_enter = tk.Entry(window, width = 53,textvariable = link,font = 'arial 15 bold',bg="lightgreen").place(x = 5, y = 100)
tk.Button(window,text = 'DOWNLOAD VIDEO', font = 'arial 15 bold' ,fg="white",bg = 'black', padx = 2,command=Download_Video).place(x=385 ,y = 140)
window.mainloop()
Output
The video displayed below shows the working of the application. Check it out!
Conclusion
Congratulations! Today in this tutorial, we have successfully built our own YouTube video downloader project using python. Try it out yourself!
Thank you for reading! Happy coding!