-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_plugin.py
189 lines (143 loc) · 4.34 KB
/
source_plugin.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#
# Source Plugin base class
# Venema, S.R.G.
# 2018-03-28
#
# This BASE CLASS contains shared code and minimal implementation
# of a source plugin.
#
DEFAULT_CONFIG_FILE = '/etc/configuration.json'
import sys
sys.path.append('/mnt/PIHU_APP/defender-headunit/modules')
from hu_utils import *
class SourcePlugin(object):
def __init__(self):
self.name = None
self.sourceCtrl = None
self.logger = None
self.state = {}
self.state['state'] = None
self.state['random'] = None
self.state['repeat'] = None
self.empty_track = {'display':None,'rds':None,'artist':None,'composer':None,'performer':None,'album':None,'albumartist':None,'title':None,'length':None,'elapsed':None,'track':None,'disc':None,'genre':None,'date':None}
def on_init(self, plugin_name, sourceCtrl, logger):
self.name = plugin_name
self.sourceCtrl = sourceCtrl
self.logger = logger
return True
def on_add(self, sourceconfig):
return False
def on_activate(self, subindex):
return False
def on_event(self, event, event_path=[], payload=None):
return False
def add_subsource(self, **kwargs):
# not implemented
# We could implement a default behaviour in which a subsource dict is passed to be added
return False
def check_availability(self, **kwargs):
""" Check source
Returns LIST containing *all* subsources as available
"""
if 'SrcCtrl' in kwargs:
SrcCtrl = kwargs['SrcCtrl']
else:
return []
if 'index' in kwargs:
index = kwargs['index']
else:
index = SrcCtrl.index('name',self.name)
subsources = SrcCtrl.subsource_all(index)
if subsources is None:
return []
avchg = []
for i in range(len(subsources)):
avchg_subsource = {}
avchg_subsource['index'] = index
avchg_subsource['subindex'] = i
avchg_subsource['available'] = True
avchg.append(avchg_subsource)
return avchg
def configuration(self):
#if name is None:
# return None
config = {}
# return configuration (from json config file)
plugindir = "sources" #TODO
plugindir = "/mnt/PIHU_APP/defender-headunit/sources" #TOOD
configFileName = os.path.join(plugindir,self.name+'.json')
if not os.path.exists( configFileName):
printer('Configuration not found: {0}'.format(configFileName))
else:
# load source configuration file
jsConfigFile = open( configFileName )
config=json.load(jsConfigFile)
config['name'] = self.name
if 'category' not in config:
config['category'] = 'default'
if 'events' not in config:
config['events'] = []
# load main configuration
main_configuration = configuration_load('srctrl', DEFAULT_CONFIG_FILE)
#if 'subsources' in main_configuration:
#ABORT!
#TODO
if 'source_config' in main_configuration and self.name in main_configuration['source_config']:
config.update(main_configuration['source_config'][self.name])
return config
def play(self, index=None, subindex=None, **kwargs):
self.state['state'] = 'playing'
return False
def stop(self, **kwargs):
self.state['state'] = 'stopped'
return False
def next(self, **kwargs):
# not implemented
return False
def prev(self, **kwargs):
# not implemented
return False
def next_folder(self, **kwargs):
# not implemented
return False
def prev_folder(self, **kwargs):
# not implemented
return False
def pause(self, **kwargs):
#not implemented
return False
def random(self, **kwargs):
# not implemented
return False
def seekfwd(self, **kwargs):
# not implemented
return False
def seekrev(self, **kwargs):
# not implemented
return False
def update(self, **kwargs):
# not implemented
return False
def get_state(self, **kwargs ):
return self.state
def get_details(self, **kwargs):
details = {}
track = {'display':None,'rds':None,'artist':None,'composer':None,'performer':None,'album':None,'albumartist':None,'title':None,'length':None,'elapsed':None,'track':None,'disc':None,'genre':None,'date':None}
details['track'] = track
details['state'] = self.state
return details
# ------------------------
# todo:
def get_playlist():
return False
def get_folders():
return False
def source_get_media_details():
return False
def printer(self, message, level=LL_INFO, tag=None):
if tag is None:
tag = self.name
if self.logger is None:
print("[{0}] {1}".format(tag,message))
else:
self.logger.log(level, message, extra={'tag': tag})