Am pretty sure we have all wanted at some point to download videos from YouTube, but we end up failing because we can't, or we even end up installing third party extensions which may be harmful to our machines.
Hey, guess what, that's about to be over, I am going to show you how you can fix all that using simple python program.
Let's get started!!
You can Also Watch the Video Here:
Our goal is to create a YouTube video downloader using python, Tkinter and Pytube.
first make sure you have an IDE, preferably Pycharm installed in your computer.
Steps
- First you will start by installing pytube, open the terminal and run the following command:
pip install pytube
- next step we will import the library together with tkinter
import tkinter as tk
from pytube import YouTube
- After importing we will have to create the display window using tkinter:
#Dispaly Window
dock = tk.Tk()
dock.geometry('500x300')
dock.resizable(0,0)
dock.title("TechTips By Lary Youtube Video Downloader")
tk.Label(dock, text ="Youtube Video Downloader", font ="arial 20 bold").pack()
Here we have specified the size, and also given it a title to display at the top. We have also added some inline styling to our code.
- We will create the field that's goint to allow us to enter the video link to be downloaded:
#Enter the URL
link = tk.StringVar()
tk.Label(dock, text ="Paste Link Here:", font ="arial 15 bold").place(x=160, y=60)
link_error = tk.Entry(dock, width =70, textvariable = link).place(x =32, y=90)
- The next step is to create the main function that's going to enable us download the video and then finally adding a button.
#Function to download the video
def Downloader():
url =YouTube(str(link.get()))
video =url.streams.first()
video.download()
tk.Label(dock, text ="Successfully Downloaded", font ="arial 15").place(x =180, y =200)
#Download Button
tk.Button(dock, text ="DOWNLOAD", font ="Verdana 15 bold", bg ="orange", padx =2, command =Downloader).place(x=180, y=150)
dock.mainloop()
That's pretty much it now run the program by right clicking then select run. and a window should pop up like below:
Like my work:
Also check out my other Python Beginner Projects:
Connect With me at Twitter | Insta | YouTube | LinkedIn | GitHub
Do share your valuable opinion, I appreciate your honest feedback!
Enjoy Coding ❤
Top comments (0)