Python YouTube Downloader with Pytube
Free Python course with 25 real-time projects Start Now!!
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, 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 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
Please download the source code of YouTube video downloader: Python YouTube Downloader
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
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 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').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 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 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 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.
Awesum project. Thanks for sharing..
my problem is when i press the “Donwload” button, nothing happens, help please
where does the downloaded video get saved
Your same project files path.
can you change the folder in which the video will get downloaded?that would be really helpful … ? if yes, how ?
The code is running well but after pressing the download, nothing is happening. Please help me through this.
Exception in Tkinter callback
Traceback (most recent call last):
File “C:\Users\rajes\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py”, line 1884, in __call__
return self.func(*args)
File “C:\Users\rajes\PycharmProjects\Echo\main.py”, line 456, in Downloader
url = YouTube(str(link.get()))
File “C:\Users\rajes\PycharmProjects\Echo\venv\lib\site-packages\pytube\__main__.py”, line 91, in __init__
self.prefetch()
File “C:\Users\rajes\PycharmProjects\Echo\venv\lib\site-packages\pytube\__main__.py”, line 183, in prefetch
self.js_url = extract.js_url(self.watch_html)
File “C:\Users\rajes\PycharmProjects\Echo\venv\lib\site-packages\pytube\extract.py”, line 143, in js_url
base_js = get_ytplayer_config(html)[“assets”][“js”]
File “C:\Users\rajes\PycharmProjects\Echo\venv\lib\site-packages\pytube\extract.py”, line 202, in get_ytplayer_config
raise RegexMatchError(caller=”get_ytplayer_config”, pattern=”config_patterns”)
pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match for config_patterns
It is giving me this error.
Actually this code isn’t working in my pc.
I write it as it is but still not working.
Actually this code isn’t working in my pc.
I write it as it is but still not working.
Can you fixed it.
I was literally cracking my head …what to do for the python project but then I saw this project and hope that it worked. But somehow worked it and the code is really easy to understand…
Thank you so much again….