create a youtube downloader with python code example
Example 1: download youtube video in python
import YouTube from pytube
yt = YouTube(url)
t = yt.streams.filter(only_audio=True)
t[0].download(/path)
Example 2: build a youtube downloader with python gui
from tkinter import *
from pytube import YouTube
root = Tk()
root.geometry("400x350")
root.title("Youtube video downloader application")
def download():
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")
Label(root, text="Welcome to youtube\nDownloader Application", font="Consolas 15 bold").pack()
myVar = StringVar()
myVar.set("Enter the link below")
Entry(root, textvariable=myVar, width=40).pack(pady=10)
link = StringVar()
Entry(root, textvariable=link, width=40).pack(pady=10)
Button(root, text="Download video", command=download).pack()
root.mainloop()