Commit 09bac300 authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

1st pass at cover art

parent 7388a539
......@@ -74,7 +74,7 @@ def uprcl_init():
if rclconfdir is None:
raise Exception("uprclconfdir not in config")
g_rcldocs = uprclfolders.inittree(rclconfdir)
g_rcldocs = uprclfolders.inittree(rclconfdir, httphp, pathprefix)
uprcltags.recolltosql(g_rcldocs)
uprcluntagged.recoll2untagged(g_rcldocs)
......
......@@ -27,7 +27,7 @@ from recoll import rclconfig
g_myprefix = '0$uprcl$folders'
# Debug : limit processed recoll entries for speed
g_maxrecollcnt = 5000
g_maxrecollcnt = 0
# Internal init: create the directory tree (folders view) from the doc
# array by splitting the url in each doc.
......@@ -51,7 +51,7 @@ def _createdir(dirvec, fathidx, docidx, nm):
dirvec[-1][".."] = (fathidx, -1)
return len(dirvec) - 1
def _rcl2folders(docs, confdir):
def _rcl2folders(docs, confdir, httphp, pathprefix):
global dirvec
dirvec = []
......@@ -72,14 +72,18 @@ def _rcl2folders(docs, confdir):
# entry
for docidx in range(len(docs)):
doc = docs[docidx]
# No need to include non-audio types in the visible
# tree.
# TBD: We'll have to do some processing on image types though
# (will go before these lines)
# No need to include non-audio types in the visible tree.
if doc.mtype not in audiomtypes:
continue
if doc.mtype != 'inode/directory':
arturi = 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
url = doc.getbinurl()
url = url[7:]
try:
......@@ -122,8 +126,8 @@ def _rcl2folders(docs, confdir):
# If this is the last entry in the path, maybe update
# the doc idx (previous entries were created for
# intermediate elements without a Doc).
#uplog("NEED TO UPDATE DOC")
dirvec[fathidx][elt] = (dirvec[fathidx][elt][0], docidx)
if idx == len(path) -1:
dirvec[fathidx][elt] = (dirvec[fathidx][elt][0], docidx)
# Update fathidx for next iteration
fathidx = dirvec[fathidx][elt][0]
else:
......@@ -172,13 +176,20 @@ def _fetchalldocs(confdir):
# Initialize (read recoll data and build tree)
def inittree(confdir):
def inittree(confdir, httphp, pathprefix):
global g_alldocs, g_dirvec
g_alldocs = _fetchalldocs(confdir)
g_dirvec = _rcl2folders(g_alldocs, confdir)
g_dirvec = _rcl2folders(g_alldocs, confdir, httphp, pathprefix)
return g_alldocs
##############
# Browsing the initialized [folders] hierarchy
# Extract dirvec index from objid, according to the way we generate them.
def _objidtodiridx(pid):
if not pid.startswith(g_myprefix):
raise Exception("folders.browse: bad pid %s" % pid)
......@@ -199,9 +210,20 @@ def _objidtodiridx(pid):
return diridx
def rootentries(pid):
return [rcldirentry(pid + 'folders', pid, '[folders]'),]
# Look all docs inside directory, and return the cover art we find.
def arturifordir(diridx):
for nm,ids in g_dirvec[diridx].iteritems():
if ids[1] >= 0:
doc = g_alldocs[ids[1]]
if doc.mtype != 'inode/directory' and doc.albumarturi:
return doc.albumarturi
# Browse method
# objid is like folders$index
# flag is meta or children.
......@@ -230,7 +252,9 @@ def browse(pid, flag, httphp, pathprefix):
if len(dirvec[thisdiridx]) == 1:
continue
id = g_myprefix + '$' + 'd' + str(thisdiridx)
entries.append(rcldirentry(id, pid, os.path.basename(nm)))
arturi = arturifordir(thisdiridx)
entries.append(rcldirentry(id, pid, os.path.basename(nm),
arturi=arturi))
else:
# Not a directory. docidx had better been set
if thisdocidx == -1:
......
......@@ -31,8 +31,9 @@ sqconn = sqlite3.connect(':memory:')
# Tags for which we create auxiliary tables for facet descent.
#
# TBD: The list will come from the config file one day
# TBD: alias et al configuration
#
# TBD: All Artists, Group
# TBD: All Artists
#
# Maybe we'd actually need a 3rd value for the recoll field name, but
# it can be the same for the currently relevant fields.
......@@ -91,8 +92,7 @@ def createsqdb(conn):
# Insert new value if not existing, return rowid of new or existing row
def auxtableinsert(sqconn, tb, value):
c = sqconn.cursor()
col = colid(tb)
stmt = 'SELECT ' + col + ' FROM ' + tb + ' WHERE value = ?'
stmt = 'SELECT ' + colid(tb) + ' FROM ' + tb + ' WHERE value = ?'
c.execute(stmt, (value,))
r = c.fetchone()
if r:
......@@ -139,7 +139,8 @@ def recolltosql(docs):
album = getattr(doc, 'album', None)
if not album:
if doc.mtype != 'inode/directory':
uplog("No album: mtype %s title %s" % (doc.mtype, doc.url))
pass
#uplog("No album: mtype %s title %s" % (doc.mtype, doc.url))
album = '[no album]'
continue
......@@ -342,7 +343,7 @@ def tagsbrowse(pid, qpath, flag, httphp, pathprefix):
if i == qlen - 1:
# We want to display all unique values for the column
# artist.artist_id, artist.value
selwhat = col + '.' + col + '_id, ' + col + '.value'
selwhat = col + '.' + colid(col) + ', ' + col + '.value'
# tracks.artist_id = artist.artist_id
selwhere += 'tracks.' + colid(col) + ' = ' + col + '.' + colid(col)
else:
......
......@@ -21,6 +21,7 @@ import os
audiomtypes = frozenset([
'audio/mpeg',
'audio/flac',
'application/x-flac',
'application/ogg',
'audio/aac',
......@@ -97,12 +98,13 @@ def rcldoctoentry(id, pid, httphp, pathprefix, doc):
if val:
li[oname] = val
if 'upnp:artist' not in li and doc.albumartist:
li['upnp:artist'] = doc.albumartist
# TBD Date format ?
# !! Albumart will have to come from somewhere else !
### #if doc.albumarturi:
### #li['upnp:albumArtURI'] = track.album.image
### li['discnumber'] = str(track.disc_num)
#albumartist=
#comment=
#composer=
#conductor=
......@@ -126,10 +128,14 @@ def rcldoctoentry(id, pid, httphp, pathprefix, doc):
path = path[7:]
if 'tt' not in li:
li['tt'] = os.path.basename(path.decode('UTF-8', errors = 'replace'))
path = pathprefix + path
path = os.path.join(pathprefix, path)
li['uri'] = "http://%s%s" % (httphp, urllib.quote(path))
# The album art uri is precooked with httphp and prefix
if doc.albumarturi:
li['upnp:albumArtURI'] = doc.albumarturi
#uplog("Set upnp:albumArtURI to %s" % li['upnp:albumArtURI'])
uplog("rcldoctoentry: uri: %s" % li['uri'])
return li
......@@ -138,6 +144,38 @@ def docfolder(doc):
path = path[7:]
return os.path.dirname(path)
# Find cover art for directory. We are usually called repeatedly for
# the same dir, so we cache one result
_foldercache = {}
_artnames = ('folder.jpg', 'folder.png', 'cover.jpg', 'cover.png')
def docarturi(doc, httphp, pathprefix):
global _foldercache, _artnames
folder = docfolder(doc)
if folder not in _foldercache:
_foldercache = {}
_foldercache[folder] = None
candidates = [f for f in os.listdir(folder) if
f.lower().startswith('folder.')
or f.lower().startswith('cover.')]
artnm = None
for targ in _artnames:
for nm in candidates:
if nm == targ:
artnm = nm
break
elif nm.lower() == targ:
artnm = nm
break
if artnm:
path = urllib.quote(os.path.join(pathprefix, folder, artnm))
_foldercache[folder] = "http://%s%s" % (httphp, path)
break
return _foldercache[folder]
def cmpentries(e1, e2):
tp1 = e1['tp']
tp2 = e2['tp']
......
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