Commit 5ffa7bce authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

uprcl: ok with qresultstore except for playlists and tagaliases?

parent e5435600
......@@ -82,10 +82,10 @@ import time
from timeit import default_timer as timer
from upmplgutils import uplog
from uprclutils import docarturi, audiomtypes, rcldirentry, \
from uprclutils import audiomtypes, rcldirentry, \
rcldoctoentry, cmpentries
import uprclutils
from recoll import recoll
from recoll import recoll, qresultstore
from recoll import rclconfig
import uprclinit
......@@ -134,9 +134,6 @@ class Folders(object):
for diridx in self._playlists:
pldocidx = self._dirvec[diridx]["."][1]
pldoc = self._rcldocs[pldocidx]
arturi = uprclutils.docarturi(pldoc, self._httphp,self._pprefix)
if arturi:
pldoc["albumarturi"] = arturi
plpath = uprclutils.docpath(pldoc)
try:
m3u = uprclutils.M3u(plpath)
......@@ -256,13 +253,6 @@ class Folders(object):
# needed.
#self._xid2idx[doc["xdocid"]] = docidx
# Possibly enrich the doc entry with a cover art uri.
arturi = docarturi(doc, self._httphp, self._pprefix)
if arturi:
# The uri is quoted, so it's ascii and we can just store
# it as a doc attribute
doc["albumarturi"] = arturi
fathidx, path = self._pathbeyondtopdirs(doc)
if not fathidx:
continue
......@@ -301,7 +291,7 @@ class Folders(object):
uplog("%s" % ent)
self._initplaylists()
# self._initplaylists()
end = timer()
uplog("_rcl2folders took %.2f Seconds" % (end - start))
......@@ -324,20 +314,25 @@ class Folders(object):
if uprclinit.g_minimconfig:
tagaliases = uprclinit.g_minimconfig.gettagaliases()
self._rcldocs = []
for doc in rclq:
if tagaliases:
for orig, target, rep in tagaliases:
val = doc[orig]
#uplog("Rep %s doc[%s]=[%s] doc[%s]=[%s]"%
# (rep, orig, val, target, doc[target]))
if val and (rep or not doc[target]):
setattr(doc, target, val)
self._rcldocs.append(doc)
if self._maxrclcnt > 0 and len(self._rcldocs) >= self._maxrclcnt:
break
time.sleep(0)
self._rcldocs = qresultstore.QResultStore()
self._rcldocs.storeQuery(rclq,
fieldspec=
("author", "ipath", "rcludi", "relevancyrating",
"sig", "abstract", "caption", "filename",
"origcharset", "sig"))
# for i in range(len(self._rcldocs)):
# doc = self._rcldocs[i]
# if tagaliases:
# for orig, target, rep in tagaliases:
# val = doc[orig]
# #uplog("Rep %s doc[%s]=[%s] doc[%s]=[%s]"%
# # (rep, orig, val, target, doc[target]))
# if val and (rep or not doc[target]):
# setattr(doc, target, val)
# self._rcldocs.append(doc)
# if self._maxrclcnt > 0 and len(self._rcldocs) >= self._maxrclcnt:
# break
# time.sleep(0)
end = timer()
uplog("Retrieved %d docs in %.2f Seconds" %
(len(self._rcldocs), end - start))
......@@ -385,23 +380,24 @@ class Folders(object):
# Look all non-directory docs inside directory, and return the
# cover art we find. The doc albumarturi field has been set during
# the initial walk by call to uprclutils.docarturi()
# cover art we find.
#
# TBD In the case where this is a contentgroup directory, we'd
# need to go look into the file system for a group.xxx
# image. Actually, the best approach would probably be to create
# virtual doc records for such directories, and set their
# albumarturi during the tree setup. As it is things work if the
# tracks rely on the group pic (instead of having an embedded pic
# or track pic) Also: playlists: need to look at the physical dir
# for a e.g. playlistname.jpg.
# image.
# As it is things work if the tracks rely on the group pic
# (instead of having an embedded pic or track pic) Also:
# playlists: need to look at the physical dir for a
# e.g. playlistname.jpg.
def _arturifordir(self, diridx):
for nm,ids in self._dirvec[diridx].items():
if ids[1] >= 0:
doc = self._rcldocs[ids[1]]
if doc["mtype"] != 'inode/directory' and doc["albumarturi"]:
return doc["albumarturi"]
if doc["mtype"] != 'inode/directory':
arturi = uprclutils.docarturi(doc, self._httphp,
self._pprefix)
if arturi:
return arturi
# Folder hierarchy browse method.
......@@ -447,10 +443,7 @@ class Folders(object):
if len(self._dirvec[thisdiridx]) == 1:
continue
id = self._idprefix + '$d' + str(thisdiridx)
if doc and doc["albumarturi"]:
arturi = doc["albumarturi"]
else:
arturi = self._arturifordir(thisdiridx)
arturi = self._arturifordir(thisdiridx)
entries.append(rcldirentry(id, pid, os.path.basename(nm),
arturi=arturi))
else:
......
......@@ -250,11 +250,6 @@ def search(foldersobj, rclconfdir, objid, upnps, idprefix, httphp, pathprefix):
while True:
docs = rclq.fetchmany()
for doc in docs:
arturi = uprclutils.docarturi(doc, httphp, pathprefix)
if arturi:
# The uri is quoted, so it's ascii and we can just store
# it as a doc attribute
doc["albumarturi"] = arturi
id = foldersobj.objidfordoc(doc)
e = uprclutils.rcldoctoentry(id, objid, httphp, pathprefix, doc)
if e:
......
......@@ -285,11 +285,14 @@ def _maybecreatealbum(conn, doc, trackartid):
c.execute('''UPDATE albums SET albtartist = ?
WHERE album_id = ?''', (trackartid, album_id))
else:
arturi = uprclutils.docarturi(doc, uprclinit.g_httphp,
uprclinit.g_pathprefix)
c.execute('''INSERT INTO
albums(albtitle, albfolder, artist_id, albdate, albarturi,
albtdisc, albartok, albtartist) VALUES (?,?,?,?,?,?,?,?)''',
(album, folder, albartist_id, doc["date"],
doc["albumarturi"], discnumber, 1, trackartid))
arturi, discnumber, 1, trackartid))
album_id = c.lastrowid
#uplog("Created album %d %s disc %s artist %s folder %s" %
# (album_id, album, discnumber, albartist_id, folder))
......
......@@ -113,10 +113,15 @@ def rcldoctoentry(id, pid, httphp, pathprefix, doc):
li['upnp:class'] = 'object.item.audioItem.musicTrack'
for oname,dname in upnp2rclfields.items():
val = getattr(doc, dname)
val = doc[dname]
if val:
li[oname] = val
if 'upnp:albumArtURI' not in li:
arturi = docarturi(doc, httphp, pathprefix)
if arturi:
li['upnp:albumArtURI'] = arturi
if 'upnp:artist' not in li and doc["albumartist"]:
li['upnp:artist'] = doc["albumartist"]
......@@ -139,14 +144,14 @@ def rcldoctoentry(id, pid, httphp, pathprefix, doc):
# Compute the url. We use the URL from recoll, stripped of file://
# and with the pathprefix prepended (the pathprefix is used by our
# parent process to match urls to plugins)
path = doc.getbinurl()
ssidx = path.find(b'//')
if path.find(b'file://') == 0:
path = doc["url"]
ssidx = path.find('//')
if path.find('file://') == 0:
path = path[7:]
path = os.path.join(pathprefix.encode('ascii'), path)
path = os.path.join(pathprefix.encode('ascii'), urlunquotetobytes(path))
li['uri'] = _httpurl(httphp, path)
else:
li['uri'] = path[:ssidx+2].decode('ascii', errors='replace') +\
li['uri'] = path[:ssidx+2].decode('ascii', errors='replace') + \
urlquote(path[ssidx+1:])
#uplog("rcldoctoentry: uri: %s" % li['uri'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment