forked from norbeyandresg/hades
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hades_ui.py
110 lines (95 loc) · 3.11 KB
/
hades_ui.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
#!/usr/bin/env python3
import os
from argparse import ArgumentParser
from pyfiglet import figlet_format
from PyInquirer import Separator, prompt
from hades import Hades, download_base_path
from validators import PlaylistURIValidator
# Argparser
parser = ArgumentParser(description="Download Spotify playlist the easy way")
class HadesUI:
def __init__(self, pl_uri=None):
self.hades = Hades()
if pl_uri:
self.hades.download_tracks(pl_uri)
else:
self.reset_screen()
self.main_menu()
def reset_screen(self):
os.system("clear")
print(figlet_format("HADES", font="isometric1"))
def main_menu(self):
menu = [
{
"type": "list",
"name": "action",
"message": "Spotify downloader manager",
"choices": [
{"name": "Download from uri/url", "value": "download_playlist"},
{"name": "Manage my playlists", "value": "manage_playlists"},
{"name": "Quit", "value": "quit"},
Separator(),
{
"name": "Current download path",
"disabled": f"{download_base_path}",
},
{
"name": "You can change the download path changing",
"disabled": "hades.py > download_base_path",
},
],
},
]
answer = prompt(menu)
action = getattr(self, answer["action"])
action()
def quit(self):
pass
def download_playlist(self):
input = [
{
"type": "input",
"name": "pl_uri",
"message": "Playlist uri or url to download:",
"default": "back",
"validate": PlaylistURIValidator,
}
]
response = prompt(input)["pl_uri"]
if response == "back":
self.reset_screen()
self.main_menu()
else:
self.hades.download_tracks(response)
confirm = [
{
"type": "confirm",
"message": "Download complete. Continue downloading?",
"name": "continue",
"default": True,
}
]
response = prompt(confirm)["continue"]
if response:
self.reset_screen()
self.main_menu()
else:
self.quit()
def manage_playlists(self):
playlists = self.hades.get_user_playlists()
menu = [
{
"type": "checkbox",
"name": "response",
"message": "Select playlist to download",
"choices": playlists,
}
]
selected_playlists = prompt(menu)["response"]
for pl in selected_playlists:
self.hades.download_tracks(pl)
if __name__ == "__main__":
parser.add_argument(
"--pl_uri", metavar="playlist_uri", type=str, help="Spotify playlist uri"
)
HadesUI(parser.parse_args().pl_uri)