|
a/src/mediaserver/cdplugins/uprcl/uprcluntagged.py |
|
b/src/mediaserver/cdplugins/uprcl/uprcluntagged.py |
|
... |
|
... |
33 |
import sys
|
33 |
import sys
|
34 |
|
34 |
|
35 |
from upmplgutils import uplog
|
35 |
from upmplgutils import uplog
|
36 |
from uprclutils import rcldoctoentry, rcldirentry
|
36 |
from uprclutils import rcldoctoentry, rcldirentry
|
37 |
|
37 |
|
|
|
38 |
class Untagged(object):
|
|
|
39 |
def __init__(self, docs, httphp, pathprefix):
|
38 |
untg_prefix = '0$uprcl$untagged'
|
40 |
self._idprefix = '0$uprcl$untagged'
|
|
|
41 |
self._httphp = httphp
|
|
|
42 |
self._pprefix = pathprefix
|
|
|
43 |
self.recoll2untagged(docs)
|
|
|
44 |
|
|
|
45 |
# Create the untagged entries static vector by filtering the global
|
|
|
46 |
# doc vector, storing the indexes of all tracks without a title
|
|
|
47 |
# field. We keep a reference to the doc vector.
|
|
|
48 |
def recoll2untagged(self, docs):
|
|
|
49 |
self.rcldocs = docs
|
|
|
50 |
# The -1 entry is because we use index 0 for our root.
|
|
|
51 |
self.utidx = [-1]
|
|
|
52 |
|
|
|
53 |
for docidx in range(len(docs)):
|
|
|
54 |
doc = docs[docidx]
|
|
|
55 |
if doc.mtype == 'inode/directory':
|
|
|
56 |
continue
|
|
|
57 |
if not doc.title:
|
|
|
58 |
self.utidx.append(docidx)
|
39 |
|
59 |
|
40 |
# Create the untagged entries static vector by filtering the global
|
60 |
# Compute index into our entries vector by 'parsing' the objid.
|
41 |
# doc vector, storing the indexes of all tracks without a title
|
61 |
def _objidtoidx(self, pid):
|
42 |
# field. We keep a reference to the doc vector.
|
62 |
if not pid.startswith(self._idprefix):
|
43 |
def recoll2untagged(docs):
|
63 |
raise Exception("untagged:browse: bad pid %s" % pid)
|
44 |
global g_utidx, g_rcldocs
|
64 |
|
45 |
g_rcldocs = docs
|
65 |
if len(self.rcldocs) == 0:
|
46 |
# The -1 entry is because we use index 0 for our root.
|
66 |
raise Exception("untagged:browse: no docs")
|
47 |
g_utidx = [-1]
|
67 |
|
|
|
68 |
idx = pid[len(self._idprefix):]
|
|
|
69 |
if not idx:
|
|
|
70 |
# Browsing the root.
|
|
|
71 |
idx = 0
|
|
|
72 |
else:
|
|
|
73 |
if idx[1] != 'u':
|
|
|
74 |
raise Exception("untagged:browse: called on bad objid %s" % pid)
|
|
|
75 |
idx = int(idx[2:])
|
48 |
|
76 |
|
49 |
for docidx in range(len(docs)):
|
77 |
if idx >= len(self.utidx):
|
50 |
doc = docs[docidx]
|
78 |
raise Exception("untagged:browse: bad pid %s" % pid)
|
51 |
if doc.mtype == 'inode/directory':
|
79 |
|
52 |
continue
|
80 |
return idx
|
53 |
if not doc.title:
|
81 |
|
54 |
g_utidx.append(docidx)
|
82 |
# Return entry to be created in the top-level directory ([untagged]).
|
|
|
83 |
def rootentries(self, pid):
|
|
|
84 |
return [rcldirentry(pid + 'untagged', pid, '[untagged]'),]
|
55 |
|
85 |
|
56 |
|
86 |
|
57 |
# Compute index into our entries vector by 'parsing' the objid.
|
87 |
# Browse method
|
58 |
def _objidtoidx(pid):
|
88 |
# objid is like untagged$u<index>
|
59 |
if not pid.startswith(untg_prefix):
|
89 |
# flag is meta or children.
|
60 |
raise Exception("untagged.browse: bad pid %s" % pid)
|
90 |
def browse(self, pid, flag):
|
|
|
91 |
idx = self._objidtoidx(pid)
|
61 |
|
92 |
|
62 |
if len(g_rcldocs) == 0:
|
|
|
63 |
raise Exception("untagged:browse: no docs")
|
|
|
64 |
|
|
|
65 |
idx = pid[len(untg_prefix):]
|
|
|
66 |
if not idx:
|
|
|
67 |
# Browsing the root.
|
|
|
68 |
idx = 0
|
|
|
69 |
else:
|
|
|
70 |
if idx[1] != 'u':
|
|
|
71 |
raise Exception("untagged:browse: called on bad objid %s" % pid)
|
|
|
72 |
idx = int(idx[2:])
|
|
|
73 |
|
|
|
74 |
if idx >= len(g_utidx):
|
|
|
75 |
raise Exception("untagged:browse: bad pid %s" % pid)
|
|
|
76 |
|
|
|
77 |
return idx
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
# Return entry to be created in the top-level directory ([untagged]).
|
|
|
81 |
def rootentries(pid):
|
|
|
82 |
return [rcldirentry(pid + 'untagged', pid, '[untagged]'),]
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
# Browse method
|
|
|
86 |
# objid is like untagged$u<index>
|
|
|
87 |
# flag is meta or children.
|
|
|
88 |
def browse(pid, flag, httphp, pathprefix):
|
|
|
89 |
idx = _objidtoidx(pid)
|
|
|
90 |
|
|
|
91 |
entries = []
|
93 |
entries = []
|
92 |
if idx == 0:
|
94 |
if idx == 0:
|
93 |
# Browsing root
|
95 |
# Browsing root
|
94 |
for i in range(len(g_utidx))[1:]:
|
96 |
for i in range(len(self.utidx))[1:]:
|
95 |
doc = g_rcldocs[g_utidx[i]]
|
97 |
doc = self.rcldocs[self.utidx[i]]
|
|
|
98 |
id = self._idprefix + '$u' + str(i)
|
|
|
99 |
e = rcldoctoentry(id, pid, self._httphp, self._pprefix, doc)
|
|
|
100 |
if e:
|
|
|
101 |
entries.append(e)
|
|
|
102 |
else:
|
|
|
103 |
# Non root: only items in there. flag needs to be 'meta'
|
|
|
104 |
doc = self.rcldocs[thisdocidx]
|
96 |
id = untg_prefix + '$u' + str(i)
|
105 |
id = self._idprefix + '$u' + str(idx)
|
97 |
e = rcldoctoentry(id, pid, httphp, pathprefix, doc)
|
106 |
e = rcldoctoentry(id, pid, self._httphp, self._pprefix, doc)
|
98 |
if e:
|
107 |
if e:
|
99 |
entries.append(e)
|
108 |
entries.append(e)
|
100 |
else:
|
|
|
101 |
# Non root: only items in there. flag needs to be 'meta'
|
|
|
102 |
doc = g_rcldocs[thisdocidx]
|
|
|
103 |
id = untg_prefix + '$u' + str(idx)
|
|
|
104 |
e = rcldoctoentry(id, pid, httphp, pathprefix, doc)
|
|
|
105 |
if e:
|
|
|
106 |
entries.append(e)
|
|
|
107 |
|
109 |
|
108 |
return sorted(entries, key=lambda entry: entry['tt'].lower())
|
110 |
return sorted(entries, key=lambda entry: entry['tt'].lower())
|