DEV Community

Cover image for Beginner Python Project (4) - YouTube Video Downloader
Hillary Nyakundi
Hillary Nyakundi

Posted on • Edited on

Beginner Python Project (4) - YouTube Video Downloader

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:
How to make a YouTube Video Downloader Using Python
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
Enter fullscreen mode Exit fullscreen mode
  • next step we will import the library together with tkinter
import tkinter as tk
from pytube import YouTube
Enter fullscreen mode Exit fullscreen mode
  • 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()
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode
  • 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()
Enter fullscreen mode Exit fullscreen mode

That's pretty much it now run the program by right clicking then select run. and a window should pop up like below:

Alt Text
Like my work:
ko-fi
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)