|
a/src/mediaserver/cdplugins/qobuz/qobuz-app.py |
|
b/src/mediaserver/cdplugins/qobuz/qobuz-app.py |
|
... |
|
... |
34 |
# Need bogus base_url value to avoid plugin trying to call xbmc to
|
34 |
# Need bogus base_url value to avoid plugin trying to call xbmc to
|
35 |
# retrieve addon id
|
35 |
# retrieve addon id
|
36 |
plugin = Plugin('')
|
36 |
plugin = Plugin('')
|
37 |
from session import Session
|
37 |
from session import Session
|
38 |
|
38 |
|
|
|
39 |
qobidprefix = '0$qobuz$'
|
|
|
40 |
|
39 |
# Func name to method mapper
|
41 |
# Func name to method mapper
|
40 |
dispatcher = cmdtalkplugin.Dispatch()
|
42 |
dispatcher = cmdtalkplugin.Dispatch()
|
41 |
# Pipe message handler
|
43 |
# Pipe message handler
|
42 |
msgproc = cmdtalkplugin.Processor(dispatcher)
|
44 |
msgproc = cmdtalkplugin.Processor(dispatcher)
|
43 |
|
45 |
|
|
... |
|
... |
48 |
def maybelogin():
|
50 |
def maybelogin():
|
49 |
global formatid
|
51 |
global formatid
|
50 |
global httphp
|
52 |
global httphp
|
51 |
global pathprefix
|
53 |
global pathprefix
|
52 |
global is_logged_in
|
54 |
global is_logged_in
|
53 |
|
55 |
|
|
|
56 |
# Do this always
|
|
|
57 |
setidprefix(qobidprefix)
|
|
|
58 |
|
54 |
if is_logged_in:
|
59 |
if is_logged_in:
|
55 |
return True
|
60 |
return True
|
56 |
|
61 |
|
57 |
if "UPMPD_HTTPHOSTPORT" not in os.environ:
|
62 |
if "UPMPD_HTTPHOSTPORT" not in os.environ:
|
58 |
raise Exception("No UPMPD_HTTPHOSTPORT in environment")
|
63 |
raise Exception("No UPMPD_HTTPHOSTPORT in environment")
|
|
... |
|
... |
83 |
is_logged_in = session.login(username, password)
|
88 |
is_logged_in = session.login(username, password)
|
84 |
|
89 |
|
85 |
@dispatcher.record('trackuri')
|
90 |
@dispatcher.record('trackuri')
|
86 |
def trackuri(a):
|
91 |
def trackuri(a):
|
87 |
global formatid, pathprefix
|
92 |
global formatid, pathprefix
|
|
|
93 |
|
|
|
94 |
maybelogin()
|
|
|
95 |
|
88 |
msgproc.log("trackuri: [%s]" % a)
|
96 |
msgproc.log("trackuri: [%s]" % a)
|
89 |
trackid = trackid_from_urlpath(pathprefix, a)
|
97 |
trackid = trackid_from_urlpath(pathprefix, a)
|
90 |
maybelogin()
|
98 |
|
91 |
media_url = session.get_media_url(trackid, formatid)
|
99 |
media_url = session.get_media_url(trackid, formatid)
|
92 |
if not media_url:
|
100 |
if not media_url:
|
93 |
media_url = ""
|
101 |
media_url = ""
|
94 |
|
102 |
|
95 |
#msgproc.log("%s" % media_url)
|
103 |
#msgproc.log("%s" % media_url)
|
|
... |
|
... |
103 |
|
111 |
|
104 |
|
112 |
|
105 |
def add_directory(title, endpoint):
|
113 |
def add_directory(title, endpoint):
|
106 |
if callable(endpoint):
|
114 |
if callable(endpoint):
|
107 |
endpoint = plugin.url_for(endpoint)
|
115 |
endpoint = plugin.url_for(endpoint)
|
108 |
xbmcplugin.entries.append(direntry('0$qobuz$' + endpoint,
|
116 |
xbmcplugin.entries.append(direntry(qobidprefix + endpoint,
|
109 |
xbmcplugin.objid, title))
|
117 |
xbmcplugin.objid, title))
|
110 |
|
118 |
|
111 |
def urls_from_id(view_func, items):
|
119 |
def urls_from_id(view_func, items):
|
112 |
#msgproc.log("urls_from_id: items: %s" % str([item.id for item in items]))
|
120 |
#msgproc.log("urls_from_id: items: %s" % str([item.id for item in items]))
|
113 |
return [plugin.url_for(view_func, item.id)
|
121 |
return [plugin.url_for(view_func, item.id)
|
|
... |
|
... |
127 |
try:
|
135 |
try:
|
128 |
artnm = item.artist.name if item.artist.name else None
|
136 |
artnm = item.artist.name if item.artist.name else None
|
129 |
except:
|
137 |
except:
|
130 |
artnm = None
|
138 |
artnm = None
|
131 |
xbmcplugin.entries.append(
|
139 |
xbmcplugin.entries.append(
|
132 |
direntry('0$qobuz$' + url, xbmcplugin.objid, title, arturi=image,
|
140 |
direntry(qobidprefix + url, xbmcplugin.objid, title, arturi=image,
|
133 |
artist=artnm, upnpclass=upnpclass))
|
141 |
artist=artnm, upnpclass=upnpclass))
|
134 |
|
142 |
|
135 |
def track_list(tracks):
|
143 |
def track_list(tracks):
|
136 |
xbmcplugin.entries += trackentries(httphp, pathprefix,
|
144 |
xbmcplugin.entries += trackentries(httphp, pathprefix,
|
137 |
xbmcplugin.objid, tracks)
|
145 |
xbmcplugin.objid, tracks)
|
138 |
|
146 |
|
139 |
@dispatcher.record('browse')
|
147 |
@dispatcher.record('browse')
|
140 |
def browse(a):
|
148 |
def browse(a):
|
141 |
global xbmcplugin
|
149 |
global xbmcplugin
|
142 |
xbmcplugin = XbmcPlugin('0$qobuz$')
|
150 |
xbmcplugin = XbmcPlugin(qobidprefix)
|
143 |
msgproc.log("browse: [%s]" % a)
|
151 |
msgproc.log("browse: [%s]" % a)
|
144 |
if 'objid' not in a:
|
152 |
if 'objid' not in a:
|
145 |
raise Exception("No objid in args")
|
153 |
raise Exception("No objid in args")
|
146 |
objid = a['objid']
|
154 |
objid = a['objid']
|
147 |
bflg = a['flag'] if 'flag' in a else 'children'
|
155 |
bflg = a['flag'] if 'flag' in a else 'children'
|
|
... |
|
... |
149 |
if re.match('0\$qobuz\$', objid) is None:
|
157 |
if re.match('0\$qobuz\$', objid) is None:
|
150 |
raise Exception("bad objid [%s]" % objid)
|
158 |
raise Exception("bad objid [%s]" % objid)
|
151 |
maybelogin()
|
159 |
maybelogin()
|
152 |
|
160 |
|
153 |
xbmcplugin.objid = objid
|
161 |
xbmcplugin.objid = objid
|
154 |
idpath = objid.replace('0$qobuz$', '', 1)
|
162 |
idpath = objid.replace(qobidprefix, '', 1)
|
155 |
if bflg == 'meta':
|
163 |
if bflg == 'meta':
|
156 |
m = re.match('.*\$(.+)$', idpath)
|
164 |
m = re.match('.*\$(.+)$', idpath)
|
157 |
if m:
|
165 |
if m:
|
158 |
trackid = m.group(1)
|
166 |
trackid = m.group(1)
|
159 |
track = session.get_track(trackid)
|
167 |
track = session.get_track(trackid)
|
|
... |
|
... |
298 |
view(items, urls_from_id(playlist_view, items))
|
306 |
view(items, urls_from_id(playlist_view, items))
|
299 |
|
307 |
|
300 |
@dispatcher.record('search')
|
308 |
@dispatcher.record('search')
|
301 |
def search(a):
|
309 |
def search(a):
|
302 |
global xbmcplugin
|
310 |
global xbmcplugin
|
303 |
xbmcplugin = XbmcPlugin('0$qobuz$')
|
311 |
xbmcplugin = XbmcPlugin(qobidprefix)
|
304 |
msgproc.log("search: [%s]" % a)
|
312 |
msgproc.log("search: [%s]" % a)
|
305 |
objid = a['objid']
|
313 |
objid = a['objid']
|
306 |
field = a['field'] if 'field' in a else None
|
314 |
field = a['field'] if 'field' in a else None
|
307 |
value = a['value']
|
315 |
value = a['value']
|
308 |
objkind = a['objkind'] if 'objkind' in a and a['objkind'] else None
|
316 |
objkind = a['objkind'] if 'objkind' in a and a['objkind'] else None
|