-
Notifications
You must be signed in to change notification settings - Fork 2
/
scanner.py
61 lines (50 loc) · 1.75 KB
/
scanner.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
from beets.library import Library
from constants import DEFAULT_PATH_FOR_JSON_FILE
import json
import sys
import utils
from constants import *
with open(SCANNER_TAGS_FILE) as json_file:
TAGS_MODEL = json.load(json_file)
# TODO: Stop using this hard-coded shit
def prompt_tags(db_file, query):
library = Library(db_file)
for track in library.items(query=query):
try:
scan_version = int(float(track.scan_version))
except Exception:
scan_version = 0
if scan_version < VERSION:
_prompt_for_track(track, TAGS_MODEL)
track.scan_version = VERSION
track.store()
def _prompt_for_track(track, tags):
print("\n====================== \n - Title: %s\n"
"- Artist: %s\n"
"- Album %s\n =================\n"
% (track.title, track.artist, track.album))
for tag, values in tags.items():
if tag.startswith("_"):
continue
loop = True
while loop:
user_input = input("Tag %s ? Values: %s" % (tag, values))
if user_input == "" or user_input is None:
loop = False
if user_input.lower() == "skip":
return
identified_value = utils.identify_compressed_value(user_input, values)
if identified_value is not None:
print(identified_value)
loop = False
setattr(track, tag, identified_value)
if __name__ == "__main__":
if len(sys.argv) < 2:
query = None
else:
query = sys.argv[1]
print('Query: "%s"' % query)
with open(DEFAULT_PATH_FOR_JSON_FILE) as json_file:
config = json.load(json_file)
beets_db = config.get("beetsLibrary")
prompt_tags(beets_db, query)