Python YouTube Downloader with Pytube

1757 views
optmiize_your_resume_1
Python YouTube Downloader with Pytube

In this article you will learn how to create Python YouTube Downloader with Pytube.

Python YouTube Video Downloader is an application to download videos from YouTube. This provides users to download videos they need on their devices and watch them offline.

To implement this project we use basic concept of python, tkinter, pytube library.

  • Tkinter is the standard GUI library for PythonPython when combined with Tkinter provides a fast and easy way to create GUI applications.
  • pytube  is a very serious, lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

To install the required modules run pip installer command on the command line:

pip install tkinter Pip install pytube
Code language: Python (python)

These are the following steps to build youtube video downloader project in python :

  • Import libraries
  • Create display window
  • Create field to enter link
  • Create function to start downloading

1. Import Libraries

Start the project by importing the required modules.

from tkinter import * from pytube import YouTube
Code language: Python (python)

In this python project, we import Tkinter and pytube modules.

Python YouTube Downloader with Pytube

2. Create Display Window

root = Tk() root.geometry('500x350') root.resizable(0,0) root.config(bg = '#000000') root.title("Techarge-YouTube Video Downloader") root.iconbitmap("youtubeicon.ico")
Code language: Python (python)

  • Tk() used to initialize tkinter to create display window
  • geometry() used to set the window’s width and height
  • resizable(0,0) set the fix size of window
  • title() used to give the title of window
Label(root,text = 'Youtube Video Downloader', font ='arial 20 bold').place(x= 60 , y = 30)
Code language: Python (python)

  • Label() widget use to display text that users can’t able to modify.
  • root is the name of the window
  • text which we display the title of the label
  • font in which our text is written
  • pack organized widget in block

3. Create Field to Enter Link

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)
Code language: Python (python)

  • link is a string type variable that stores the youtube video link that the user enters.
  • Entry() widget is used when we want to create an input text field.
  • width sets the width of entry widget
  • textvariable used to retrieve the value of current text variable to the entry widget
  • place() use to place the widget at a specific position

4. Create Function to Start Downloading

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()
Code language: Python (python)

Url variable gets the youtube link from the link variable by get() function and then str() will convert the link in string datatype.

The video is download in the first present stream of that video by stream.first() method.

Button() widget used to display button on the window.

  • text which we display on the label
  • font in which the text is written
  • bg sets the background color
  • command is used to call the function

root.mainloop() is a method that executes when we want to run the program.

Python YouTube Downloader with Pytube

Source code with comments

Python YouTube Downloader Output

Python YouTube Downloader with Pytube

So, here is our Python YouTube Downloader. Simple isn’t it?? This is how we have successfully done with the ‘Python YouTube Downloader using pytube’. I hope the ‘Tkinter and Pytube library is now more clear to you and don’t forget to try this code once!!

You can play around with the library, explore more features and even customize it further.

ThankYou Pythoner’s!!!

Check out more python projects

20%off for Ink 280 281

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More