-
Notifications
You must be signed in to change notification settings - Fork 0
/
yt-Mp3dl-GUI.py
93 lines (77 loc) · 3.74 KB
/
yt-Mp3dl-GUI.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
########################
# #
# yt-Mp3dl-GUI #
# #
########################
from downloader import Downloader
from cases import Cases
from pathlib import Path
import PySimpleGUI as sg
def main_app(win: sg.Window):
downloader = Downloader()
while True:
event, values = win.read()
if event in [sg.WIN_CLOSED, 'Exit_Program', KeyboardInterrupt]:
del downloader
break
if event == 'Download_Button':
urls_temp = [value for index, value in values.items()]
if urls_temp == ['']:
sg.popup_ok('No input found!')
else:
print(urls_temp)
urls = [x.split(",") for x in urls_temp][0]
print(urls)
downloader.download(urls)
downloader.WriteJson()
# urls = list(itertools.chain(*values[1]))
# print(urls)
if event == 'File_Import':
print('file import')
file = sg.popup_get_file("Select a txt, json or yaml file.", file_types = (("Text files", "*.txt *.json *.yaml",),))
if file is not None:
file = Path(file)
print(file.name)
print(file.suffix)
print(file.name[:-len(file.suffix)])
# if file.name[:-len(file.suffix)] in ['urls', 'urls_template']: # easy switch between templates and new files
if file.name[:-len(file.suffix)] == 'urls':
print('pp')
print(file.name[:-len(file.suffix)])
match file.suffix:
case ".txt":
urls = Cases.caseTxt(file)
print(f'txt urls {urls}')
download = sg.popup_ok_cancel(f"Found these links: {Cases.popup_linksTxt(urls)}")
if download == "OK":
downloader.download(urls)
downloader.WriteJson()
case ".json":
urls = Cases.caseJson(file)
print(f'json urls {urls}')
download = sg.popup_ok_cancel(f"Found these links: {Cases.popup_linksJson(urls)}")
if download == "OK":
downloader.download(urls)
downloader.WriteJson()
case ".yaml":
urls = Cases.caseYaml(file)
print(f'yaml urls {urls}')
download = sg.popup_ok_cancel(f"Found these links: {Cases.popup_linksTxt(urls)}")
if download == "OK":
downloader.download(urls)
downloader.WriteJson()
else:
sg.popup_ok('The file you entered is not a valid file or is empty.'
'\nPlease try again with a valid file.')
win.close()
if __name__ == "__main__":
layout = [
[sg.Text('YT-Mp3dl', font = 'roman 40', justification = 'c', expand_x = True)],
[sg.Text('Insert a search here or import multiple searches from a file', font = "_ 15", justification = 'c', expand_x = True)],
[sg.InputText(default_text = '', size = 45, expand_x = True)],
[sg.Button(button_text = 'Download', key = 'Download_Button'),
sg.Button(button_text = 'Import from file', key = 'File_Import')],
[sg.Button(button_text = 'Exit', key = 'Exit_Program')]
]
window = sg.Window('YT-Mp3dl', layout, size = (600, 250), resizable=True, grab_anywhere_using_control=True, finalize=False)
main_app(window)