-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (62 loc) · 2.22 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import pytube
from pytube import YouTube
import tkinter as tk
from tkinter import messagebox, filedialog
def vdo_info() :
url = entry_url.get()
try :
video= pytube.YouTube(url)
views = video.views
title = video.title
label_title.config(text ="Title :" + title)
label_views.config(text="Views :"+ str(views))
return video
except pytube.exceptions.PytubeError as e:
messagebox.showerror("Error" ,str(e))
def choose_dir() :
download_dir = filedialog.askdirectory()
entry_dir.delete(0,tk.END)
entry_dir.insert(0,download_dir)
def vdo_download() :
video = vdo_info()
if video :
try:
stream = video.streams.get_highest_resolution()
download_dir = entry_dir.get()
stream.download(download_dir)
messagebox.showinfo("Success","video downloaded successfully")
except pytube.exceptions.PytubeError as e:
messagebox.showerror("Error",str(e))
def audio_download() :
video = vdo_info()
if video:
try:
stream = video.streams.get_audio_only()
download_dir = entry_dir.get()
stream.download(download_dir)
messagebox.showinfo("Success", "Audio downlaoded successfully!")
except pytube.exceptions.PytubeError as e:
messagebox.showerror("Error",str(e))
window = tk.Tk()
window.title("YouTube Video & Audio downloader")
label_url = tk.Label(window, text="Enter the video URl : ")
label_url.pack()
entry_url = tk.Entry(window, width=50)
entry_url.pack()
label_directory = tk.Label(window,text = "Choose Download Directory")
label_directory.pack()
entry_dir=tk.Entry(window,width=50)
entry_dir.pack()
button_dir = tk.Button(window,text="Select Directory",command = choose_dir )
button_dir.pack()
button_info = tk.Button(window,text= "Get Video Info.", command=vdo_info)
button_info.pack()
button_vdo = tk.Button(window,text="Download Video",command = vdo_download)
button_vdo.pack()
button_audio = tk.Button(window,text="Download Audio",command = audio_download)
button_audio.pack()
label_title = tk.Label(window,text="Title : ")
label_title.pack()
label_views = tk.Label(window,text="Views : ")
label_views.pack()
window.mainloop()