|
a/src/mediaserver/cdplugins/tidal/tidal-app.py |
|
b/src/mediaserver/cdplugins/tidal/tidal-app.py |
|
... |
|
... |
46 |
# Pipe message handler
|
46 |
# Pipe message handler
|
47 |
msgproc = cmdtalkplugin.Processor(dispatcher)
|
47 |
msgproc = cmdtalkplugin.Processor(dispatcher)
|
48 |
|
48 |
|
49 |
is_logged_in = False
|
49 |
is_logged_in = False
|
50 |
|
50 |
|
|
|
51 |
tidalidprefix = '0$tidal$'
|
|
|
52 |
|
51 |
def maybelogin():
|
53 |
def maybelogin():
|
52 |
global session
|
54 |
global session
|
53 |
global quality
|
55 |
global quality
|
54 |
global httphp
|
56 |
global httphp
|
55 |
global pathprefix
|
57 |
global pathprefix
|
56 |
global is_logged_in
|
58 |
global is_logged_in
|
57 |
|
59 |
|
|
|
60 |
# Do this always
|
|
|
61 |
setidprefix(tidalidprefix)
|
|
|
62 |
|
58 |
if is_logged_in:
|
63 |
if is_logged_in:
|
59 |
return True
|
64 |
return True
|
60 |
|
65 |
|
61 |
if "UPMPD_HTTPHOSTPORT" not in os.environ:
|
66 |
if "UPMPD_HTTPHOSTPORT" not in os.environ:
|
62 |
raise Exception("No UPMPD_HTTPHOSTPORT in environment")
|
67 |
raise Exception("No UPMPD_HTTPHOSTPORT in environment")
|
|
... |
|
... |
103 |
else:
|
108 |
else:
|
104 |
return ('audio/mpeg', str(96))
|
109 |
return ('audio/mpeg', str(96))
|
105 |
|
110 |
|
106 |
@dispatcher.record('trackuri')
|
111 |
@dispatcher.record('trackuri')
|
107 |
def trackuri(a):
|
112 |
def trackuri(a):
|
|
|
113 |
maybelogin()
|
108 |
msgproc.log("trackuri: [%s]" % a)
|
114 |
msgproc.log("trackuri: [%s]" % a)
|
109 |
trackid = trackid_from_urlpath(pathprefix, a)
|
115 |
trackid = trackid_from_urlpath(pathprefix, a)
|
110 |
|
116 |
|
111 |
maybelogin()
|
|
|
112 |
media_url = session.get_media_url(trackid)
|
117 |
media_url = session.get_media_url(trackid)
|
113 |
msgproc.log("%s" % media_url)
|
118 |
msgproc.log("%s" % media_url)
|
114 |
if not media_url.startswith('http://') and not \
|
119 |
if not media_url.startswith('http://') and not \
|
115 |
media_url.startswith('https://'):
|
120 |
media_url.startswith('https://'):
|
116 |
host, tail = media_url.split('/', 1)
|
121 |
host, tail = media_url.split('/', 1)
|
|
... |
|
... |
121 |
|
126 |
|
122 |
|
127 |
|
123 |
def add_directory(title, endpoint):
|
128 |
def add_directory(title, endpoint):
|
124 |
if callable(endpoint):
|
129 |
if callable(endpoint):
|
125 |
endpoint = plugin.url_for(endpoint)
|
130 |
endpoint = plugin.url_for(endpoint)
|
126 |
xbmcplugin.entries.append(direntry('0$tidal$' + endpoint,
|
131 |
xbmcplugin.entries.append(direntry(tidalidprefix + endpoint,
|
127 |
xbmcplugin.objid, title))
|
132 |
xbmcplugin.objid, title))
|
128 |
|
133 |
|
129 |
def urls_from_id(view_func, items):
|
134 |
def urls_from_id(view_func, items):
|
130 |
return [plugin.url_for(view_func, item.id)
|
135 |
return [plugin.url_for(view_func, item.id)
|
131 |
for item in items if str(item.id).find('http') != 0]
|
136 |
for item in items if str(item.id).find('http') != 0]
|
|
... |
|
... |
144 |
try:
|
149 |
try:
|
145 |
artnm = item.artist.name if item.artist.name else None
|
150 |
artnm = item.artist.name if item.artist.name else None
|
146 |
except:
|
151 |
except:
|
147 |
artnm = None
|
152 |
artnm = None
|
148 |
xbmcplugin.entries.append(
|
153 |
xbmcplugin.entries.append(
|
149 |
direntry('0$tidal$' + url, xbmcplugin.objid, title, arturi=image,
|
154 |
direntry(tidalidprefix + url, xbmcplugin.objid, title, arturi=image,
|
150 |
artist=artnm, upnpclass=upnpclass))
|
155 |
artist=artnm, upnpclass=upnpclass))
|
151 |
|
156 |
|
152 |
def track_list(tracks):
|
157 |
def track_list(tracks):
|
153 |
xbmcplugin.entries += trackentries(httphp, pathprefix,
|
158 |
xbmcplugin.entries += trackentries(httphp, pathprefix,
|
154 |
xbmcplugin.objid, tracks)
|
159 |
xbmcplugin.objid, tracks)
|
155 |
|
160 |
|
156 |
@dispatcher.record('browse')
|
161 |
@dispatcher.record('browse')
|
157 |
def browse(a):
|
162 |
def browse(a):
|
158 |
global xbmcplugin
|
163 |
global xbmcplugin
|
159 |
xbmcplugin = XbmcPlugin('0$tidal$')
|
164 |
xbmcplugin = XbmcPlugin(tidalidprefix)
|
160 |
msgproc.log("browse: [%s]" % a)
|
165 |
msgproc.log("browse: [%s]" % a)
|
161 |
if 'objid' not in a:
|
166 |
if 'objid' not in a:
|
162 |
raise Exception("No objid in args")
|
167 |
raise Exception("No objid in args")
|
163 |
objid = a['objid']
|
168 |
objid = a['objid']
|
164 |
bflg = a['flag'] if 'flag' in a else 'children'
|
169 |
bflg = a['flag'] if 'flag' in a else 'children'
|
|
... |
|
... |
166 |
if re.match('0\$tidal\$', objid) is None:
|
171 |
if re.match('0\$tidal\$', objid) is None:
|
167 |
raise Exception("bad objid [%s]" % objid)
|
172 |
raise Exception("bad objid [%s]" % objid)
|
168 |
maybelogin()
|
173 |
maybelogin()
|
169 |
|
174 |
|
170 |
xbmcplugin.objid = objid
|
175 |
xbmcplugin.objid = objid
|
171 |
idpath = objid.replace('0$tidal$', '', 1)
|
176 |
idpath = objid.replace(tidalidprefix, '', 1)
|
172 |
if bflg == 'meta':
|
177 |
if bflg == 'meta':
|
173 |
m = re.match('.*\$(.+)$', idpath)
|
178 |
m = re.match('.*\$(.+)$', idpath)
|
174 |
if m:
|
179 |
if m:
|
175 |
trackid = m.group(1)
|
180 |
trackid = m.group(1)
|
176 |
track = session.get_track(trackid)
|
181 |
track = session.get_track(trackid)
|
|
... |
|
... |
374 |
|
379 |
|
375 |
|
380 |
|
376 |
@dispatcher.record('search')
|
381 |
@dispatcher.record('search')
|
377 |
def search(a):
|
382 |
def search(a):
|
378 |
global xbmcplugin
|
383 |
global xbmcplugin
|
379 |
xbmcplugin = XbmcPlugin('0$tidal$')
|
384 |
xbmcplugin = XbmcPlugin(tidalidprefix)
|
380 |
msgproc.log("search: [%s]" % a)
|
385 |
msgproc.log("search: [%s]" % a)
|
381 |
objid = a['objid']
|
386 |
objid = a['objid']
|
382 |
field = a['field'] if 'field' in a else None
|
387 |
field = a['field'] if 'field' in a else None
|
383 |
objkind = a['objkind'] if 'objkind' in a else None
|
388 |
objkind = a['objkind'] if 'objkind' in a else None
|
384 |
|
389 |
|