|
| 1 | +import os |
| 2 | +import tkinter as tk |
| 3 | +from tkinter import messagebox |
| 4 | +from tkinter import filedialog |
| 5 | +import pytube |
| 6 | +# if you get an error here, run this command in terminal: pip install pytube |
| 7 | + |
| 8 | +def downloadVideo(): |
| 9 | + if(entry1.get() == "" or entry2.get() == "" or entry3.get() == "" or entry4.get() == ""): |
| 10 | + messagebox.showerror("Error", "Please fill all the fields.") |
| 11 | + return |
| 12 | + |
| 13 | + url = entry1.get() |
| 14 | + path = entry2.get() |
| 15 | + name = entry3.get() |
| 16 | + resolution = entry4.get() |
| 17 | + |
| 18 | + if(resolution != "360p" and resolution != "720p" and resolution != "1080p"): |
| 19 | + messagebox.showerror("Error", "Please enter a valid resolution.") |
| 20 | + return |
| 21 | + |
| 22 | + if(os.path.exists(path) == False): |
| 23 | + messagebox.showerror("Error", "Please enter a valid path.") |
| 24 | + return |
| 25 | + |
| 26 | + if(os.path.exists(path + "\\" + name + ".mp4") == True): |
| 27 | + messagebox.showerror("Error", "File already exists.") |
| 28 | + return |
| 29 | + |
| 30 | + try: |
| 31 | + yt = pytube.YouTube(url) |
| 32 | + video = yt.streams.filter(res=resolution).first() |
| 33 | + video.download(path, name) |
| 34 | + messagebox.showinfo("Success", "Video downloaded successfully.") |
| 35 | + except: |
| 36 | + messagebox.showerror("Error", "Please enter a valid url.") |
| 37 | + |
| 38 | +window = tk.Tk() |
| 39 | +window.title("Youtube Downloader") |
| 40 | +window.geometry("600x400") |
| 41 | +window.resizable(False, False) |
| 42 | + |
| 43 | +label1 = tk.Label(window, text="Youtube Downloader", font=("Arial", 20)) |
| 44 | +label1.pack() |
| 45 | + |
| 46 | +label2 = tk.Label(window, text="Enter the url of the video: ", font=("Arial", 10)) |
| 47 | +label2.pack() |
| 48 | + |
| 49 | +entry1 = tk.Entry(window, width=50) |
| 50 | +entry1.pack() |
| 51 | + |
| 52 | +label3 = tk.Label(window, text="Enter the path where you want to save the video: ", font=("Arial", 10)) |
| 53 | +label3.pack() |
| 54 | + |
| 55 | +entry2 = tk.Entry(window, width=50) |
| 56 | +entry2.pack() |
| 57 | + |
| 58 | +button1 = tk.Button(window, text="Browse", command=lambda: entry2.insert(0, filedialog.askdirectory())) |
| 59 | +button1.pack() |
| 60 | + |
| 61 | +label4 = tk.Label(window, text="Enter the name of the video: (with extension)", font=("Arial", 10)) |
| 62 | +label4.pack() |
| 63 | + |
| 64 | +entry3 = tk.Entry(window, width=50) |
| 65 | +entry3.pack() |
| 66 | + |
| 67 | +label5 = tk.Label(window, text="Enter the resolution of the video (360p, 720p, 1080p): ", font=("Arial", 10)) |
| 68 | +label5.pack() |
| 69 | + |
| 70 | +entry4 = tk.Entry(window, width=50) |
| 71 | +entry4.pack() |
| 72 | + |
| 73 | +button2 = tk.Button(window, text="Download", command=downloadVideo) |
| 74 | +button2.pack() |
| 75 | + |
| 76 | +window.mainloop() |
0 commit comments