YouTube Downloader With Python

Sourav Saha
2 min readAug 15, 2021

--

Python YouTube Video Downloader is a program that allows you to download YouTube videos. This allows users to download and watch videos on their devices when they are not connected to the internet.

Python project to download YouTube video:

The goal of this project is to quickly and easily download any type of video from YouTube to your device.

The user must copy the YouTube video URL that they want to download and paste it in the ‘paste link here’ section before clicking the download button, which will begin downloading the video. When the video has finished downloading, a message ‘downloaded’ appears in the window below the download button.

Project Prerequisites:

We used the basic concepts of python, tkinter, and the pytube library to implement this project.

  • Tkinter is a standard GUI library and one of the most straightforward ways to create a GUI application.
  • pytube used for downloading videos from youtube

Run the pip installer command on the command line to install the required modules:

pip install tkinter
Pip install pytube

Step 1: Import Libraries

from tkinter import *
from pytube import YouTube

Step 2: Create Display Window

root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("YouTube video downloader")
  • Tk() is used to initialize tkinter library
  • geometry() used to set the window’s width and height respectively
  • resizble(1,1) indicates that window can be resized according to users intention
  • title() it will give the title of the window
Label(root,text = 'Youtube Video Downloader', font ='arial 20 bold').pack()
  • Label() widget use to display text that user can’t change or modified
  • root represents the name of the window
  • pack() organized widget in block

Step 3: Create Link Field

link = StringVar()
Label(root, text = 'Paste Link Here:', font = 'arial 15 bold').place(x= 150 , y = 60)
link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 90)
  • link is a string variable which stores the user’s entered Video link
  • Entry() widget is used to create an input text field
  • place() use to place the widget at a specific position

Step 4: Create Downloader Function

def Downloader():     
url =YouTube(str(link.get()))
video = url.streams.first()
video.download()
Label(root, text = 'DOWNLOADED', font = 'arial 15').place(x= 180 , y = 210)

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

root.mainloop()
  • Button() used to display button on window
  • command is used to call the function
  • root.mainloop() is a method that executes when we run the program

Output:

Source Code:

Happy Coding !!

--

--

Sourav Saha
Sourav Saha

Written by Sourav Saha

Python Programmer || ML and DL Entusiast

No responses yet