forked from ISO-B/pmb-pitft
-
Notifications
You must be signed in to change notification settings - Fork 1
/
player_base.py
117 lines (104 loc) · 3.47 KB
/
player_base.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
115
116
117
# -*- coding: utf-8 -*-
import logging
class PlayerBase(object):
def __init__(self, name, config):
self.logger = logging.getLogger("PiTFT-Playerui." + name)
self.coverartThread = None
self.config = config
# Capabilities
self.capabilities = {
"name" : name,
"connected" : False,
"volume_enabled" : False,
"seek_enabled" : False,
"random_enabled" : False,
"repeat_enabled" : False,
"elapsed_enabled" : False,
"logopath" : "",
"logo" : None,
"listbuttons" : {}
}
# Things to remember
self.data = {
"status" : {},
"song" : {},
"cover" : False,
"coverartfile" : "",
"update" : {},
"list" :
{
"type" : "",
"content" : [],
"viewcontent" : [],
"click" : self.list_click,
"highlight" : -1,
"position" : 0,
"buttons" : []
},
"menu" : []
}
self.init_data()
def init_data (self):
self.data["status"] = {
"state" : "",
"elapsed" : "",
"repeat" : "",
"random" : "",
"volume" : "",
"playlistlength" : 0
}
self.data["song"] = {
"pos" : "",
"artist" : "",
"album" : "",
"date" : "",
"track" : "",
"title" : "",
"time" : "",
"cover_uri" : ""
}
self.data["cover"] = False
self.data["coverartfile"] = ""
self.data["update"] = {
"active" : False,
"state" : True,
"elapsed" : True,
"random" : True,
"repeat" : True,
"volume" : True,
"trackinfo" : True,
"coverart" : True
}
""" Get data """
def __getitem__(self, item):
return self.data[item]
""" Get capability value """
def __call__(self, item):
return self.capabilities[item]
def set_logo(self, item):
self.capabilities["logo"] = item
def set_buttonicon(self, item, icon):
self.capabilities["listbuttons"][item]["icon"] = icon
""" Refresh data from API """
def refresh(self, active=False):
pass
def updated(self, item="all"):
if item == "all":
return True in self.data["update"].values()
else:
return self.data["update"][item]
""" Force an update """
def force_update (self,item="all"):
if item == "all":
self.data["update"] = dict.fromkeys(self.data["update"], True)
else:
self.data["update"][item] = True
""" Acknowledge an update request """
def update_ack(self, item):
self.data["update"][item] = False
""" Control the player via API """
def control(self, command, parameter=-1):
pass
""" Return value: Request next view ("listview", "contextmenu", None) """
def list_click(self, item=-1, button=1):
return None