-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
147 lines (124 loc) · 5.76 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import tkinter as tk
from tkinter import ttk, messagebox
from pytube import YouTube
def download():
accepted = acceptvar.get()
if accepted == "Accepted":
link = linkinpt.get()
resolution = resinpt.get()
try:
youtube_video = YouTube(link)
video_stream = youtube_video.streams.filter(resolution="{}p".format(resolution)).first()
if video_stream is not None:
video_stream.download()
status.set("Video downloaded successfully!")
else:
status.set("No video stream found with the specified resolution. Please try another resolution.")
tk.messagebox.showwarning(title="Resolution Error", message="No video stream found with the specified resolution. Please try another resolution.")
except Exception as e:
errmsg = "Error: ", e
status.set(errmsg)
tk.messagebox.showwarning(title="Something Went Wrong", message="Can't find video. Please check again the video link. Check the status for detail.")
else:
status.set("Terms and Condition Error")
tk.messagebox.showwarning(title="Terms and Condition Check", message="Please Agree the Terms and Conditions to Download Video")
def vidinfo():
accepted = acceptvar.get()
if accepted == "Accepted":
linkget = linkinpt.get()
youtube_video = YouTube(linkget)
titleshow = youtube_video.title
viewshow = youtube_video.views
ratingshow = youtube_video.rating
authorshow = youtube_video.author
pubshow = youtube_video.publish_date
lengthshow = youtube_video.length
thumbshow = youtube_video.thumbnail_url
title.set(titleshow)
viewers.set(viewshow)
rating.set(ratingshow)
author.set(authorshow)
pub.set(pubshow)
length.set(lengthshow)
thumb.set(thumbshow)
else:
status.set("Terms and Condition Error")
tk.messagebox.showwarning(title="Terms and Condition Check", message="Please Agree the Terms and Conditions to Download Video")
root = tk.Tk()
root.title("Youtube Video Downloader")
frame = ttk.Frame(root)
frame.grid(row=0, column=0)
#Link
linkframe = ttk.LabelFrame(frame, text="Download Option")
linkframe.grid(row=0, column=0)
link = ttk.Label(linkframe, text="Video Link")
link.grid(row=0, column=0, padx=5, pady=10)
linkinpt = ttk.Entry(linkframe)
linkinpt.grid(row=0, column=1, padx=5, pady=10)
resolution = ttk.Label(linkframe, text="Video Resolution")
resinpt = ttk.Combobox(linkframe, value=["2160","1440","1080","720","480","360","240","144"])
resolution.grid(row="1", column="0", padx=5, pady=10)
resinpt.grid(row="1", column="1", padx=5, pady=10)
#Download and Check
downloadlabel = ttk.LabelFrame(frame, text="Download and Information")
downloadlabel.grid(row="1",column="0")
acceptvar = tk.StringVar(value="Not Accepted")
terms_check = ttk.Checkbutton(downloadlabel, text="I accept the terms and conditions.", variable=acceptvar, onvalue="Accepted", offvalue="Not Accepted")
terms_check.grid(row=0,column=0,padx=35)
downloadbtn = ttk.Button(downloadlabel, text="Download Video", command=download)
downloadbtn.grid(row=1,column=0,padx=10, pady=10, sticky="we")
infobtn = ttk.Button(downloadlabel, text="Get Video Information", command=vidinfo)
infobtn.grid(row=2,column=0,padx=10, pady=10, sticky="we")
for widget in frame.winfo_children():
widget.grid_configure(padx=10, pady=5)
infolabel = ttk.LabelFrame(frame, text="Video Information")
infolabel.grid(row=0, column=1, padx=10, pady=5, rowspan=2)
title = tk.StringVar()
titletext = ttk.Label(infolabel, text="Title : ")
titlelabel = ttk.Label(infolabel, textvariable=title)
titlelabel.grid(row=0,column=1, padx=5, pady=5, sticky="w")
titletext.grid(row=0,column=0, padx=5, pady=5, sticky="e")
author = tk.StringVar()
authortext = ttk.Label(infolabel, text="Author : ")
authorlabel = ttk.Label(infolabel, textvariable=author)
authorlabel.grid(row=1,column=1, padx=5, pady=5, sticky="w")
authortext.grid(row=1,column=0, padx=5, pady=5, sticky="e")
viewers = tk.StringVar()
viewtext = ttk.Label(infolabel, text="Views : ")
viewlabel = ttk.Label(infolabel, textvariable=viewers)
viewlabel.grid(row=2,column=1, padx=5, pady=5, sticky="w")
viewtext.grid(row=2,column=0, padx=5, pady=5, sticky="e")
rating = tk.StringVar()
ratingtext = ttk.Label(infolabel, text="Rating : ")
ratinglabel = ttk.Label(infolabel, textvariable=rating)
ratinglabel.grid(row=3,column=1, padx=5, pady=5, sticky="w")
ratingtext.grid(row=3,column=0, padx=5, pady=5, sticky="e")
pub = tk.StringVar()
pubtext = ttk.Label(infolabel, text="Publish Date : ")
publabel = ttk.Label(infolabel, textvariable=pub)
publabel.grid(row=4,column=1, padx=5, pady=5, sticky="w")
pubtext.grid(row=4,column=0, padx=5, pady=5, sticky="e")
length = tk.StringVar()
lengthtext = ttk.Label(infolabel, text="Video Length (s) : ")
lengthlabel = ttk.Label(infolabel, textvariable=length)
lengthlabel.grid(row=5,column=1, padx=5, pady=5, sticky="w")
lengthtext.grid(row=5,column=0, padx=5, pady=5, sticky="e")
thumb = tk.StringVar()
thumbtext = ttk.Label(infolabel, text="Thumb URL : ")
thumblabel = ttk.Label(infolabel, textvariable=thumb)
thumblabel.grid(row=6,column=1, padx=5, pady=5, sticky="w")
thumbtext.grid(row=6,column=0, padx=5, pady=5, sticky="e")
title.set("Unknown")
viewers.set("Unknown")
rating.set("Unknown")
author.set("Unknown")
pub.set("Unknown")
length.set("Unknown")
thumb.set("Unknown")
statuslabel = ttk.LabelFrame(frame, text="Status")
statuslabel.grid(row=2, column=0, padx=10, pady=5, columnspan=2)
status = tk.StringVar()
statustext = ttk.Label(statuslabel, textvariable=status)
statustext.grid(row=0,column=0, padx=10, pady=5)
status.set("Download Video to See Status")
root.mainloop()