-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
114 lines (94 loc) · 3.26 KB
/
main.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
from musicbeeipc import *
from wox import Wox, WoxAPI
class MusicBee(Wox):
def __init__(self):
self.mbIPC = MusicBeeIPC()
Wox.__init__(self)
def play(self, file_path):
self.mbIPC.play_now(file_path)
WoxAPI.change_query("")
return []
def add(self, file_path):
self.mbIPC.queue_next(file_path)
WoxAPI.change_query("")
return []
def artist(self, file_path):
return self.mbIPC.library_get_file_tag(file_path, 31)
def title(self, file_path):
return self.mbIPC.library_get_file_tag(file_path, 39)
def shuffle(self):
self.mbIPC.now_playing_list_play_library_shuffled()
return []
def artwork(self, file_path):
local_art = self.mbIPC.library_get_artwork_url(file_path, 0)
mb_icon = "Images\\pic.png"
if ".tmp" not in local_art:
return self.mbIPC.library_get_artwork_url(file_path, 0)
else:
return mb_icon
def json_create(self, function, file_path):
json = {
"Title": self.artist(file_path) + " - " + self.title(file_path),
"Subtitle": file_path,
"IcoPath": self.artwork(file_path),
"JsonRPCAction": {
"method": function,
"parameters": [file_path.replace("\\", "\\\\")],
"dontHideAfterAction": False
}
}
return json
@staticmethod
def action_parse(action):
action = action.lower()
play_list = ["play"]
add_list = ["add", "queue"]
shuffle_list = ["shuffle", "random"]
if action in play_list:
return "play"
if action in add_list:
return "add"
if action in shuffle_list:
return "shuffle"
else:
return "play"
@staticmethod
def tag_parse(tag):
tag = tag.lower()
title_list = ["title", "song", "track"]
artist_list = ["artist", "band", "singer"]
album_list = ["album", "cd", "record"]
if tag in title_list:
return ["Title"]
if tag in artist_list:
return ["Artist"]
if tag in album_list:
return ["Album"]
else:
return ["Title"]
def arg_parser(self, key):
results = []
arguments = key.split(" ")
if len(arguments) > 2:
action = self.action_parse(arguments[0].lower())
tag = self.tag_parse(arguments[1].lower())
query = " ".join(arguments[2:])
for result in self.mbIPC.library_search(query, "Contains", tag):
results.append(self.json_create(action, result))
elif arguments[0] == "shuffle" or arguments[0] == "random":
shuffle_json = {
"Title": "Shuffle Library",
"Subtitle": "Clear playlist and add entire library in random order",
"IcoPath": "Images\\pic.png",
"JsonRPCAction": {
"method": "shuffle",
"parameters": [],
"dontHideAfterAction": False
}
}
results.append(shuffle_json)
return results
def query(self, key):
return self.arg_parser(key)
if __name__ == "__main__":
MusicBee()