YouTube Video Downloader Using Python

YouTube Video Downloader Using Python

This is just a two-line program but to convert it to GUI YouTube Video Downloader is a bit longer still, this program of GUI YouTube Video Downloader is less than 25 lines.

But still, if you want that two-line program then click here.

We have explained this program in every line to make it understand easily for you.

We have created two entry widgets, one to ask the user to enter the URL or link of a YouTube video and the other to add that link.

Then, we have called the download function using the “Download Video” button.

You can download the pytube module using"pip install pytube" but if this gives you the error then you should try "pip install pytube3" inside your terminal.

Now, let’s see the code and understand.

Code

# importing tkinter
from tkinter import *
# importing YouTube module
from pytube import YouTube
# initializing tkinter
root = Tk()
# setting the geometry of the GUI
root.geometry("400x350")
# setting the title of the GUI
root.title("Youtube video downloader application")
# defining download function
def download():
    # using try and except to execute program without errors
    try:
        myVar.set("Downloading...")
        root.update()
        YouTube(link.get()).streams.first().download()
        link.set("Video downloaded successfully")
    except Exception as e:
        myVar.set("Mistake")
        root.update()
        link.set("Enter correct link")

# created the Label widget to welcome user
Label(root, text="Welcome to youtube\nDownloader Application", font="Consolas 15 bold").pack()
# declaring StringVar type variable
myVar = StringVar()
# setting the default text to myVar
myVar.set("Enter the link below")
# created the Entry widget to ask user to enter the url
Entry(root, textvariable=myVar, width=40).pack(pady=10)
# declaring StringVar type variable
link = StringVar()
# created the Entry widget to get the link
Entry(root, textvariable=link, width=40).pack(pady=10)
# created and called the download function to download video
Button(root, text="Download video", command=download).pack()
# running the mainloop
root.mainloop()

Output

YouTube Video Downloader Using Python

Also read:

  • Imagination to Reality, Unlocking the Future: Genesis Physics Engine for 4D Simulation
    Genesis has unveiled a groundbreaking physics engine capable of generating immersive 4D dynamical and physical worlds. It sets new benchmarks in areas such as: All this comes with optimized performance, making it an essential tool for researchers, developers, and hobbyists alike. Open-Source and Free for All The Genesis physics engine is completely open-source and free….
  • Simple Code to compare Speed of Python, Java, and C++?
    Introduction There’s often a lot of debate about the speed of different programming languages, with many assuming that C++ is always the fastest and Python is the slowest. However, it’s not as straightforward as it seems. In this article, I’ll walk you through simple programs with the same logic written in Python, Java, and C++…
  • Falling Stars Animation on Python.Hub October 2024
    Hello Python enthusiasts! Check out the cool animation below, featured on our Instagram page, python.hub. You can view the latest reel, posted on October 8, 2024, showcasing this animation. View this post on Instagram A post shared by Lalit Tomar • AI & Coding Wizard (@python.hub) Want the code for this reel? Simply follow this…
  • Most Underrated Database Trick | Life-Saving SQL Command
    Hello folks! Today we are again back with a super important article on the Most underrated SQL & Database Trick to save your entire application. Maintaining the data integrity of your application is very important in this world of software development. However, even experienced engineers may encounter situations where mistakes happen in changing or updating…
  • Python List Methods
    Hello friends, in this article, we will explore various Python List methods, indispensable tools in a programmer’s toolkit for manipulating lists efficiently. List methods in Python are built-in functions designed to perform specific tasks when applied to lists. To access a method in Python, we simply use the dot notation (.), linking the method to…


Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you