Switch to unified view

a/src/cdplugins/qobuz/qobuz-app.py b/src/cdplugins/qobuz/qobuz-app.py
...
...
20
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
22
from __future__ import print_function
22
from __future__ import print_function
23
import sys
23
import sys
24
import os
24
import os
25
import posixpath
26
import json
25
import json
27
import re
26
import re
28
import conftree
27
import conftree
29
import cmdtalkplugin
28
import cmdtalkplugin
29
from upmplgutils import *
30
30
31
# Using kodi plugin routing plugin: lets use reuse a lot of code from
31
# Using kodi plugin routing plugin: lets use reuse a lot of code from
32
# the addon.
32
# the addon.
33
from routing import Plugin
33
from routing import Plugin
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
...
...
75
    if not username or not password:
75
    if not username or not password:
76
        raise Exception("qobuzuser and/or qobuzpass not set in configuration")
76
        raise Exception("qobuzuser and/or qobuzpass not set in configuration")
77
77
78
    is_logged_in = session.login(username, password)
78
    is_logged_in = session.login(username, password)
79
    
79
    
80
def trackentries(objid, tracks):
81
    entries = []
82
    for track in tracks:
83
        li = {}
84
        li['pid'] = objid
85
        li['id'] = objid + '$' + "%s" % track.id
86
        li['tt'] = track.name
87
        li['uri'] = 'http://%s' % httphp + \
88
                    posixpath.join(pathprefix,
89
                                   'track?version=1&trackId=%s' % \
90
                                   track.id)
91
        #msgproc.log("URI: [%s]" % li['uri'])
92
        li['tp'] = 'it'
93
        if track.album:
94
            li['upnp:album'] = track.album.name
95
            if track.album.image:
96
                li['upnp:albumArtURI'] = track.album.image
97
            if track.album.release_date:
98
                li['releasedate'] = track.album.release_date 
99
        li['upnp:originalTrackNumber'] =  str(track.track_num)
100
        li['upnp:artist'] = track.artist.name
101
        li['dc:title'] = track.name
102
        li['discnumber'] = str(track.disc_num)
103
        li['duration'] = track.duration
104
        entries.append(li)
105
    return entries
106
107
def direntry(id, pid, title):
108
    return {'id': id, 'pid' : pid, 'tt': title, 'tp':'ct', 'searchable' : '1'}
109
110
def direntries(objid, ttidlist):
111
    content = []
112
    for tt,id in ttidlist:
113
        content.append(direntry(objid + '$' + id, objid, tt))
114
    return content
115
116
def trackid_from_urlpath(a):
117
    if 'path' not in a:
118
        raise Exception("No path in args")
119
    path = a['path']
120
121
    # pathprefix + 'track?version=1&trackId=trackid
122
    exp = posixpath.join(pathprefix, '''track\?version=1&trackId=(.+)$''')
123
    m = re.match(exp, path)
124
    if m is None:
125
        raise Exception("trackuri: path [%s] does not match [%s]" % (path, exp))
126
    trackid = m.group(1)
127
    return trackid
128
129
@dispatcher.record('trackuri')
80
@dispatcher.record('trackuri')
130
def trackuri(a):
81
def trackuri(a):
131
    global formatid
82
    global formatid
132
    msgproc.log("trackuri: [%s]" % a)
83
    msgproc.log("trackuri: [%s]" % a)
133
    trackid = trackid_from_urlpath(a)
84
    trackid = trackid_from_urlpath(pathprefix, a)
134
    maybelogin()
85
    maybelogin()
135
    media_url = session.get_media_url(trackid, formatid)
86
    media_url = session.get_media_url(trackid, formatid)
136
    #msgproc.log("%s" % media_url)
87
    #msgproc.log("%s" % media_url)
137
    if formatid == 5:
88
    if formatid == 5:
138
        mime = "audio/mpeg"
89
        mime = "audio/mpeg"
...
...
172
    for item, url in zip(data_items, urls):
123
    for item, url in zip(data_items, urls):
173
        title = item.name
124
        title = item.name
174
        xbmcplugin.entries.append(direntry('0$qobuz$' + url, xbmcplugin.objid, title))
125
        xbmcplugin.entries.append(direntry('0$qobuz$' + url, xbmcplugin.objid, title))
175
126
176
def track_list(tracks):
127
def track_list(tracks):
177
    xbmcplugin.entries += trackentries(xbmcplugin.objid, tracks)
128
    xbmcplugin.entries += trackentries(httphp, pathprefix,
129
                                       xbmcplugin.objid, tracks)
178
130
179
@dispatcher.record('browse')
131
@dispatcher.record('browse')
180
def browse(a):
132
def browse(a):
181
    global xbmcplugin
133
    global xbmcplugin
182
    xbmcplugin = XbmcPlugin()
134
    xbmcplugin = XbmcPlugin()