YouTube Video Downloader with Python (TUTORIAL).



Hi,

Welcome to another interesting tutorial on creating a YouTube Video Downloader with python.

This is super easy and fun project for Beginners as well as Intermediate's.

Let's get started...

1. First Let us import the required modules needed for the project:

We will use Tkinter for GUI and pytube module for connecting with YouTube in this project. 

Here is the code to import:

from tkinter import *
from pytube import YouTube

Next, we will create a border and give a title for our app. Here we will use "Tkinter's" geometry, title method to achieve it.

Code:

root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("YouTube Video Downloader By PyTechTip")

2. Create a  string variable named link to store the desired download video link.

Code:

link = StringVar()

Then we will create the "Paste Link Here: " text and the "Link entering area" with Tkinter's Label and Entry method.

Code:

Label(root, text = 'Paste Link Here:', font = 'arial 15 bold').place(x= 160 , y = 60)
link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 90)

Now, we will create the function which will help o=us to download the video:

The usage of pytube begins here.

  1. Create a function.
  2. Create a variable url and provide the link given by user.

Code:

def Downloader():    
    url = YouTube(str(link.get()))

Next line of code will load the video to download it in the next step.

Code:

    video = url.streams.first()

Now, we will download the video using download method from pytube.

Code:

    video.download()

  • We will print ("Video Downloaded") text in console after the download is completed.

Now, create a button to call the downloader function.

Code:

Button(root,text = 'DOWNLOAD', font = 'arial 15 bold' ,bg = 'pale violet red', padx = 2, command = Downloader).place(x=180 ,y = 150)

Last, we will loop the process by single line of code.

Code:

root.mainloop()

You've now created a YouTube Video Downloader using Python. 

Instead of simply copying and pasting the code, practice coding on your own and try adding more parameters, such as resolution options, to enhance its functionality.

Reference Links:

Tkinter Label Function.

Tkinter Entry Function.

PyTube Documentation.

Goodbye👋. Let's meet in next tutorial.

COMPLETE CODE OF THE PROJECT:

from tkinter import *
from pytube import YouTube

root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("YouTube Video Downloader By PyTechTip")

link = StringVar()

Label(root, text = 'Paste Link Here:', font = 'arial 15 bold').place(x= 160 , y = 60)
link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 90)

def Downloader():    
    url = YouTube(str(link.get()))
    video = url.streams.first()
    video.download()

Button(
    root,text = 'DOWNLOAD', font = 'arial 15 bold' ,bg = 'pale violet red', padx = 2, command = Downloader
    ).place(x=180 ,y = 150)
root.mainloop()