|
a/src/mediaserver/cdplugins/uprcl/uprclfolders.py |
|
b/src/mediaserver/cdplugins/uprcl/uprclfolders.py |
|
... |
|
... |
142 |
|
142 |
|
143 |
g_alldocs = _fetchalldocs(confdir)
|
143 |
g_alldocs = _fetchalldocs(confdir)
|
144 |
g_dirvec = _rcl2folders(g_alldocs, confdir)
|
144 |
g_dirvec = _rcl2folders(g_alldocs, confdir)
|
145 |
|
145 |
|
146 |
|
146 |
|
147 |
def _cmpentries(e1, e2):
|
|
|
148 |
tp1 = e1['tp']
|
|
|
149 |
tp2 = e2['tp']
|
|
|
150 |
isct1 = tp1 == 'ct'
|
|
|
151 |
isct2 = tp2 == 'ct'
|
|
|
152 |
# Containers come before items, and are sorted in alphabetic order
|
|
|
153 |
if isct1 and not isct2:
|
|
|
154 |
return 1
|
|
|
155 |
elif not isct1 and isct2:
|
|
|
156 |
return -1
|
|
|
157 |
elif isct1 and isct2:
|
|
|
158 |
tt1 = e1['tt']
|
|
|
159 |
tt2 = e2['tt']
|
|
|
160 |
if tt1 < tt2:
|
|
|
161 |
return -1
|
|
|
162 |
elif tt1 > tt2:
|
|
|
163 |
return 1
|
|
|
164 |
else:
|
|
|
165 |
return 0
|
|
|
166 |
# 2 tracks. Sort by album then track number
|
|
|
167 |
k = 'upnp:album'
|
|
|
168 |
a1 = e1[k] if k in e1 else ""
|
|
|
169 |
a2 = e2[k] if k in e2 else ""
|
|
|
170 |
if a1 < a2:
|
|
|
171 |
return -1
|
|
|
172 |
elif a1 > a2:
|
|
|
173 |
return 1
|
|
|
174 |
|
|
|
175 |
k = 'upnp:originalTrackNumber'
|
|
|
176 |
a1 = e1[k] if k in e1 else "0"
|
|
|
177 |
a2 = e2[k] if k in e2 else "0"
|
|
|
178 |
return int(a1) - int(a2)
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
def _objidtodiridx(pid):
|
147 |
def _objidtodiridx(pid):
|
182 |
if not pid.startswith(g_myprefix):
|
148 |
if not pid.startswith(g_myprefix):
|
183 |
raise Exception("folders.browse: bad pid %s" % pid)
|
149 |
raise Exception("folders.browse: bad pid %s" % pid)
|
184 |
|
150 |
|
185 |
if len(g_alldocs) == 0:
|
151 |
if len(g_alldocs) == 0:
|
|
... |
|
... |
228 |
id = g_myprefix + '$' + 'i' + str(thisdocidx)
|
194 |
id = g_myprefix + '$' + 'i' + str(thisdocidx)
|
229 |
e = rcldoctoentry(id, pid, httphp, pathprefix, doc)
|
195 |
e = rcldoctoentry(id, pid, httphp, pathprefix, doc)
|
230 |
if e:
|
196 |
if e:
|
231 |
entries.append(e)
|
197 |
entries.append(e)
|
232 |
|
198 |
|
233 |
return sorted(entries, cmp=_cmpentries)
|
199 |
return sorted(entries, cmp=cmpentries)
|
234 |
|
200 |
|
235 |
# return path for objid, which has to be a container. This is good old pwd
|
201 |
# return path for objid, which has to be a container. This is good old pwd
|
236 |
def dirpath(objid):
|
202 |
def dirpath(objid):
|
237 |
|
203 |
|
|
|
204 |
# We may get called from search, on the top dir (above [folders]). Return
|
|
|
205 |
# empty in this case
|
|
|
206 |
try:
|
238 |
diridx = _objidtodiridx(objid)
|
207 |
diridx = _objidtodiridx(objid)
|
|
|
208 |
except:
|
|
|
209 |
return ""
|
239 |
|
210 |
|
|
|
211 |
if diridx == 0:
|
|
|
212 |
return "/"
|
|
|
213 |
|
240 |
lpath = []
|
214 |
lpath = []
|
241 |
while True:
|
215 |
while True:
|
242 |
fathidx = g_dirvec[diridx][".."][0]
|
216 |
fathidx = g_dirvec[diridx][".."][0]
|
243 |
for nm, ids in g_dirvec[fathidx].iteritems():
|
217 |
for nm, ids in g_dirvec[fathidx].iteritems():
|
244 |
if ids[0] == diridx:
|
218 |
if ids[0] == diridx:
|