Skip to main content

Python YouTube Downloader with Pytube

 

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 in their devices and watch them offline.

Youtube Video Downloader Python Project

The Youtube downloader project is a python project. The object of this project is to download any type of video in a fast and easy way from youtube in your device.

In this python project, the user has to copy the youtube video URL that they want to download and simply paste that URL in the ‘paste link here’ section and click on the download button, it will start downloading the video. When video downloading finishes, it shows a message ‘downloaded’ popup on the window below the download button.

Steps to Develop Python YouTube Downloader

Project Prerequisites

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

  • Tkinter is a standard GUI library and it is one of the easiest ways to build a GUI application.
  • pytube used for downloading videos from youtube

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

pip install tkinter
Pip install pytube

Download Youtube Downloader Python Code

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

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

1. Import Libraries

Start the project by importing the required modules.

PIP command-pip install pytube

from tkinter import *
from pytube import YouTube

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

2. Create Display Window

root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("DataFlair-youtube video downloader")
  • Tk() used to initialize Tkinter to create a 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 the window
Label(root,text = 'Youtube Video Downloader', font ='arial 20 bold').pack()
  • 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)
    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)
  • 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()

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 presentation 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 Output

python youtube downloader output

Summary

With this project in python, we have successfully developed the youtube video downloader project using python. We used the popular Tkinter library that used for rendering graphics. We use the pytube library to download videos from youtube.






Comments

Popular posts from this blog

How to check if the given number is Even or odd-

1. How to check if the given number is Even or odd- We can determine whether a number is even or odd. This can be tested using different methods. The test can be done using simple methods such as testing the number’s divisibility by 2. If the remainder is zero, the number is even. If the remainder is not zero, then the number is odd. The following algorithm describes how a C program can test if a number is even or odd. CODE:- #include <stdio.h> int   main () { int num;//variable declaration printf("Enter any num: ");// take input from user  scanf("%d",&num);// declare input if(num%2==0) { printf("The num %d is even",num); } else { printf("The num %d is odd",num); } return 0; }     ALGORITHM:- Step 1.   Start Step 2 .   Enter a number. Step 3.   If...

Program to find Smallest element in an array using C

  Program to find Smallest element in an array using C We will find the smallest or minimum element in an array using the C concept. We apply an algorithm that assumes the first element as the smallest element and then compares it with other elements if an element is smaller than it then, it becomes the new smallest element, and this process is repeated till the complete array is scanned. ALGORITHMS:-  STEP 1:-    Initialize the required variables. STEP 2:-  Take the input from the user. STEP 3:-   Assume the smallest element is present at the first position. STEP 4:-    Scan each element with the help of for a loop. STEP 5: -    Check if the element Scanned is new smaller than small. STEP 6:-    If it is smallest than small, change the value of small. STEP 7:-    Print small as it stores the smallest element of the array. CODE:- #include <stdio.h> int  main() {      int  a[ 50 ],p,...

Write a C program to find number is Abundant number or not

  Write a C program to find the number is an Abundant number or not:- In this program to find a number is an Abundant number or not. A number n is said to be an Abundant Number to follow these condition the sum of its proper di visors is greater than the number itself. And the difference between these two values is called abundance. Ex:-  Abundant number  12 having a proper divisor is 1,2,3,4,6 the sum of these factors is 16 it is greater than 12 so it is an Abundant number. Some other abundant numbers     18, 20, 24, 30, 36, 66, 70, 72, 78, 80, 84, 88, 90, 96, 100, 102, 104, 108, 112, 114, 120.. ALGORITHMS:- Step 1 - Enter the number, to find the Abundant number. Step 2 - Initialize the loop with c=1 to c<=number and follow the following calculation      (i) check if whether the number is divisible with c and c got a result zero.      (ii) now sum=sum+c, add a digit into a sum and store it in the sum. Step 3 . then the...