Switch to unified view

a/src/mediaserver/cdplugins/uprcl/uprclutils.py b/src/mediaserver/cdplugins/uprcl/uprclutils.py
...
...
24
    'audio/flac',
24
    'audio/flac',
25
    'application/x-flac',
25
    'application/x-flac',
26
    'application/ogg',
26
    'application/ogg',
27
    'audio/aac',
27
    'audio/aac',
28
    'audio/mp4',
28
    'audio/mp4',
29
    'video/mp4',
29
    'audio/x-aiff',
30
    'audio/x-aiff',
30
    'audio/x-wav',
31
    'audio/x-wav',
31
    'inode/directory'
32
    'inode/directory'
32
    ])
33
    ])
33
34
...
...
140
    return li
141
    return li
141
142
142
def docfolder(doc):
143
def docfolder(doc):
143
    path = doc.getbinurl()
144
    path = doc.getbinurl()
144
    path = path[7:]
145
    path = path[7:]
146
    if doc.mtype == 'inode/directory':
147
        return path
148
    else:
145
    return os.path.dirname(path)
149
        return os.path.dirname(path)
146
150
147
# Find cover art for directory. We are usually called repeatedly for
151
def embdimgurl(doc, httphp, pathprefix):
148
# the same dir, so we cache one result
152
    if doc.embdimg == 'jpg':
153
        ext = '.jpg'
154
    elif doc.embdimg == '.png':
155
        ext = 'png'
156
    else:
157
        return None
158
    path = doc.getbinurl()
159
    path = path[7:]
160
    path = urllib.quote(os.path.join(pathprefix, path+ext))
161
    path +=  "?embed=1"
162
    return "http://%s%s" % (httphp, path)
163
164
def printable(s):
165
    return s.decode('utf-8', errors='replace') if s else ""
166
167
# Find cover art for doc. We return both a value for the directory
168
# cover art (if there is a cover.jpg or equiv, and a file own uri if
169
# there is embedded img data.
170
#
171
# We are usually called repeatedly for the same directory, so we cache
172
# one result
149
_foldercache = {}
173
_foldercache = {}
150
_artnames = ('folder.jpg', 'folder.png', 'cover.jpg', 'cover.png')
174
_artnames = ('folder.jpg', 'folder.png', 'cover.jpg', 'cover.png')
151
def docarturi(doc, httphp, pathprefix):
175
def docarturi(doc, httphp, pathprefix):
152
    global _foldercache, _artnames
176
    global _foldercache, _artnames
153
177
178
    if doc.embdimg:
179
        arturi = embdimgurl(doc, httphp, pathprefix)
180
        if arturi:
181
            #uplog("docarturi: embedded: %s"%printable(arturi))
182
            return arturi
183
    
154
    folder = docfolder(doc)
184
    folder = docfolder(doc)
155
185
156
    if folder not in _foldercache:
186
    if folder not in _foldercache:
157
        _foldercache = {}
187
        _foldercache = {}
158
        _foldercache[folder] = None
188
        _foldercache[folder] = None
...
...
171
            if artnm:
201
            if artnm:
172
                path = urllib.quote(os.path.join(pathprefix, folder, artnm))
202
                path = urllib.quote(os.path.join(pathprefix, folder, artnm))
173
                _foldercache[folder] = "http://%s%s" % (httphp, path)
203
                _foldercache[folder] = "http://%s%s" % (httphp, path)
174
                break
204
                break
175
205
176
    return _foldercache[folder]
206
    arturi = _foldercache[folder]
207
    if arturi:
208
        if doc.mtype == 'inode/directory':
209
            #uplog("docarturi: external: %s->%s" %
210
            #      (printable(folder), printable(arturi)))
211
            pass
212
    return arturi
177
213
178
214
179
def cmpentries(e1, e2):
215
def cmpentries(e1, e2):
180
    tp1 = e1['tp']
216
    tp1 = e1['tp']
181
    tp2 = e2['tp']
217
    tp2 = e2['tp']