-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_config.py
65 lines (54 loc) · 2.34 KB
/
validate_config.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
import sys
class ConfigError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
def check_config_data_valid(data: dict) -> None:
try:
if data["username"] is None or data["username"].strip() == "":
raise ConfigError("'username' in config.yaml is required")
elif isinstance(data["username"], str) is False:
raise ConfigError("'username' in config.yaml must be a string")
elif len(data["username"]) != 25:
raise ConfigError("'username' in config.yaml should be 25 characters long")
if data["root_folder"] is None or data["root_folder"].strip() == "":
raise ConfigError("'root_folder' in config.yaml is required")
elif isinstance(data["root_folder"], str) is False:
raise ConfigError("'root_folder' in config.yaml must be a string")
if data["output_format"] is None or data["output_format"].strip() == "":
raise ConfigError("'output_format' in config.yaml is required")
elif data["output_format"].lower() not in [
"mp3",
"m4a",
"flac",
"opus",
"ogg",
"wav",
]:
raise ConfigError(
"'output_format' in config.yaml must be of the following (mp3/m4a/flac/opus/ogg/wav)"
)
if data["download_threads"] is None or data["search_threads"] is None:
raise ConfigError(
"'download_threads'/'search_threads' in config.yaml is required"
)
elif (
isinstance(data["download_threads"], int) is False
or isinstance(data["search_threads"], int) is False
):
raise ConfigError(
"'download_threads'/'search_threads' in config.yaml must be an integer"
)
elif data["download_threads"] <= 0 or data["search_threads"] <= 0:
raise ConfigError(
"'download_threads'/'search_threads' in config.yaml must be greater than 0"
)
if data["lyrics_provider"] not in ["genius", "musixmatch"]:
raise ConfigError(
"'lyrics_provider' in config.yaml must be 'genius' or 'musixmatch'"
)
except ConfigError as e:
print(e)
input("press ENTER to exit...")
sys.exit()