-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
154 lines (118 loc) · 6.25 KB
/
app.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
148
149
150
151
152
153
154
from mp3_Downloader import Mp3_Downloader as YTdownloader
from tkinter import filedialog
import tkinter
import tkinter.messagebox
import customtkinter
#SET SOME PREFERENCES
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
######## APP CLASS ########
class App(customtkinter.CTk):
#### Costructor ####
def __init__(self):
super().__init__()
self.download_path = ""
# configure window
self.title("Mp3 Converter.py")
self.minsize(920,320)
self.maxsize(920,320)
self.grid_columnconfigure((2, 3), weight=0)
self.grid_rowconfigure((1, 2,3), weight=0)
# create sidebar frame with widgets
self.sidebar_frame = customtkinter.CTkFrame(self, width=250,height=1000, corner_radius=0)
self.sidebar_frame.grid(row=0, column=0, rowspan=7, sticky="nsew")
self.sidebar_frame.grid_rowconfigure(4, weight=1)
self.logo_label = customtkinter.CTkLabel(self.sidebar_frame, text="Mp3 Converter", font=customtkinter.CTkFont(size=30, weight="bold"))
self.logo_label.grid(row=0, column=0, padx=20, pady=(20, 20))
self.sidebar_button_1 = customtkinter.CTkButton(self.sidebar_frame, command=self.download_btn_event,width=200,text="Download")
self.sidebar_button_1.grid(row=4, column=0, padx=20, pady=(40,10))
self.sidebar_button_2 = customtkinter.CTkButton(self.sidebar_frame, command=self.directory_btn_event,width=200,text="Directory")
self.sidebar_button_2.grid(row=5, column=0, padx=20, pady=(0,52))
self.appearance_mode_label = customtkinter.CTkLabel(self.sidebar_frame, text="Appearance Mode:", anchor="w",width=200)
self.appearance_mode_label.grid(row=6, column=0, padx=20, pady=(10, 0))
self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame,width=200, values=["Light", "Dark", "System"],
command=self.change_appearance_mode_event)
self.appearance_mode_optionemenu.grid(row=7, column=0, padx=20, pady=(10, 10))
# entry labels
self.entry_1 = customtkinter.CTkEntry(self, placeholder_text="1)Singer-Title",height=35,width=600)
self.entry_1.grid(row=1, column=1, columnspan=1, padx=(20, 20), pady=(0, 10), sticky="nsew")
self.entry_2 = customtkinter.CTkEntry(self, placeholder_text="2)Singer-Title",height=35)
self.entry_2.grid(row=2, column=1, columnspan=2, padx=(20, 20), pady=(0, 10), sticky="nsew")
self.entry_3 = customtkinter.CTkEntry(self, placeholder_text="3)Singer-Title",height=35)
self.entry_3.grid(row=3, column=1, columnspan=2, padx=(20, 20), pady=(0, 10), sticky="nsew")
self.entry_4 = customtkinter.CTkEntry(self, placeholder_text="4)Singer-Title",height=35)
self.entry_4.grid(row=4, column=1, columnspan=2, padx=(20, 20), pady=(0, 10), sticky="nsew")
self.entry_5 = customtkinter.CTkEntry(self, placeholder_text="5)Singer-Title",height=35)
self.entry_5.grid(row=5, column=1, columnspan=2, padx=(20, 20), pady=(0, 10), sticky="nsew")
#### Event method for appearance button ####
def change_appearance_mode_event(self, new_appearance_mode: str):
customtkinter.set_appearance_mode(new_appearance_mode)
#### Event method for download button ####
def download_btn_event(self):
flags = [False]*5
threads = []
#maybe it doesn't the best way to check if the thread is started
if(self.entry_1.get() != "" ):
bot1 = YTdownloader(self.entry_1.get(),self.download_path)
threads.append(bot1)
flags[0]=True
if(self.entry_2.get() != ""):
bot2 = YTdownloader(self.entry_2.get(),self.download_path)
threads.append(bot2)
flags[1]=True
if(self.entry_3.get() != ""):
bot3 = YTdownloader(self.entry_3.get(),self.download_path)
threads.append(bot3)
flags[2]=True
if(self.entry_4.get() != ""):
bot4 = YTdownloader(self.entry_4.get(),self.download_path)
threads.append(bot4)
flags[3]=True
if(self.entry_5.get() != ""):
bot5 = YTdownloader(self.entry_5.get(),self.download_path)
threads.append(bot5)
flags[4]=True
#start the threads
[t.start() for t in threads]
#join the threads
[t.join() for t in threads]
if flags[0]==True:
if bot1.download_status():
flags[0]="DOWNLOADED"
else:
flags[0]="NO"
if flags[1]==True:
if bot2.download_status():
flags[1]="DOWNLOADED"
else:
flags[1]="NO"
if flags[2]==True:
if bot3.download_status():
flags[2]="DOWNLOADED"
else:
flags[2]="NO"
if flags[3]==True:
if bot4.download_status():
flags[3]="DOWNLOADED"
else:
flags[3]="NO"
if flags[4]==True:
if bot5.download_status():
flags[4]="DOWNLOADED"
else:
flags[4]="NO"
if self.check_all_download(flags):
tkinter.messagebox.showinfo(title="Success", message="Downloads completed")
else:
tkinter.messagebox.showerror(title="Error", message="Something went wrong")
#### Check method for download ####
def check_all_download(self,list):
for i in range(len(list)):
if list[i] == "NO":
return False
return True
#### Event method for directory button ####
def directory_btn_event(self):
folder_selected = filedialog.askdirectory()
self.download_path = folder_selected.replace('/','\\')
print(self.download_path)