Commit 47207f09 authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

uprcl: misc changes in db building:

 - Use Group instead of Contentgroup for grouping, like Minimserver
   does. Contentgroup is more of a Genre thing.
 - Fix date handling
 - Use cover art from any subfolder for the parent folders. Yields art for
   higher level folders in the tree, which is nice.
parent 28c5c08f
......@@ -14,7 +14,7 @@ performer = XYTPP
tracknumber = XYTRK
[stored]
# Vorbis tags, output by rclaudio. Note that
# Vorbis tags, output by rclaudio.
album=
albumartist=
albumartistsort=
......@@ -34,6 +34,7 @@ discnumber=
discsubtitle=
encodedby=
genre=
group=
isrc=
label=
language=
......
......@@ -24,9 +24,9 @@
#
# The _dirvec list has one entry for each directory. Directories are
# created as needed by splitting the paths/urls from _rcldocs (and
# possibly adding some for contentgroups). Directories have no
# direct relation with the index objects, they are identified by their
# _dirvec index
# possibly adding some for groupings defined by the Group
# tag). Directories have no direct relation with the index objects,
# they are identified by their _dirvec index
#
# Obect ids inside the section:
# Container: $d<diridx> where <diridx> indexes into _dirvec
......@@ -44,7 +44,7 @@
# - There is no _rcldocs entry, which could possibly happen if
# there is no result for an intermediary element in a path,
# because of some recoll issue, or because this is a synthetic
# 'contentgroup' entry.
# 'Group' entry.
# - Or, while we build the structure, temporarily, if the doc was
# not yet seen. The value will then be updated when we see it.
#
......@@ -103,16 +103,10 @@ import uprclinit
#
# + possibly 'xdocid' if/when needed?
#
# tagaliases: because the storage is frozen after storing, there is no
# way to modify the records after storing, even if the field names are
# provisionned. Either we add the function to recoll and pyrecoll
# resultstore, or we need to apply the aliases at the point of doc
# field use, probably by replacing at least some doc['somefield']
# accesses with a function taking the aliases into account.
_otherneededfields = [
'albumartist', 'allartists', 'comment', 'composer', 'conductor',
'contentgroup', 'date', 'discnumber', 'embdimg', 'filename',
'genre', 'label', 'lyricist', 'orchestra', 'performer',
'contentgroup', 'date', 'dmtime', 'discnumber', 'embdimg', 'filename',
'genre', 'group', 'label', 'lyricist', 'orchestra', 'performer',
]
class Folders(object):
......@@ -243,13 +237,13 @@ class Folders(object):
if len(url1) == 0:
return None,None
# If there is a contentgroup field, just add it as a virtual
# If there is a Group field, just add it as a virtual
# directory in the path. This only affects the visible tree,
# not the 'real' URLs of course.
if doc["contentgroup"]:
if doc["group"]:
a = os.path.dirname(url1)
b = os.path.basename(url1)
url1 = os.path.join(a, doc["contentgroup"], b)
url1 = os.path.join(a, doc["group"], b)
# Split path. The caller will walk the list (possibly creating
# directory entries as needed, or doing something else).
......@@ -370,7 +364,7 @@ class Folders(object):
fields = [r[1] for r in uprclutils.upnp2rclfields.items()]
fields += _otherneededfields
fields = list(set(fields))
#uplog("_fetchalldocs: store fields: %s" % fields)
self._rcldocs = qresultstore.QResultStore()
self._rcldocs.storeQuery(rclq, fieldspec=fields, isinc = True)
else:
......@@ -441,19 +435,29 @@ class Folders(object):
# Look all non-directory docs inside directory, and return the
# 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.
# 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.
# TBD In the case where this is a Group directory, we'd
# need to go look into the file system for a group.xxx 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. And also:
# currently, we won't look at possible art for a folder with no
# music (e.g. top folder of a multi-cd). We'd need to look at the
# fs directory, but we don't have the path at this point. We'd
# need a '.' entry with a doc record containing the
# path. Currently this works if one of the subdirs has an audio
# file with an external cover.
def _arturifordir(self, diridx):
for nm,ids in self._dirvec[diridx].items():
docidx = ids[1]
if docidx >= 0 and docidx < len(self._rcldocs):
doc = self._rcldocs[docidx]
if doc["mtype"] != 'inode/directory':
# We used to only look for art for direct children
# tracks, but we now also look at subdirs. This will
# yield an image from the first subdir which has an
# image file in it, so somewhat random, but nice
# anyway. The condition is kept around to show how to
# change our minds or make it optional.
if True or doc["mtype"] != 'inode/directory':
arturi = uprclutils.docarturi(
doc, self._httphp, self._pprefix)
if arturi:
......
......@@ -49,7 +49,7 @@ _alltagtotable = {
'Conductor' : 'conductor',
'Date' : 'date',
'Genre' : 'genre',
'Group' : 'contentgroup',
'Group' : 'cgroup', # can't have a table named group
'Label' : 'label',
'Lyricist' : 'lyricist',
'Orchestra' : 'orchestra',
......@@ -69,6 +69,22 @@ g_tagtotable = {}
def _clid(table):
return table + '_id'
# Partly duplicated from rclaudio, see comments about date formats
# there. The date field is a bit of a mess because up to some point
# recoll had an alias from date to dmtime, which resulted in no date
# field and a calendar date (instead of uxtime) in dmtime. So we take
# the date value from 'date' if set, else 'dmtime', and then process
# it here. All reasonable date formats begin with YYYY[-MM[-DD]] and
# this is the part we keep.
def parsedate(dt):
if len(dt) > 10:
dt = dt[0:10]
l = dt.split('-')
if len(l) > 3 or len(l) == 2 or len(l[0]) != 4 or l[0] == '0000':
return None
#uplog("parsedate: -> %s" % dt)
return dt
# Create an empty db.
#
# There is then one table for each tag (Artist, Genre, Date,
......@@ -217,7 +233,7 @@ def _maybecreatealbum(conn, doc, trackartid):
c = conn.cursor()
folder = docfolder(doc).decode('utf-8', errors = 'replace')
album = getattr(doc, 'album', None)
album = doc["album"]
if not album:
album = uprclutils.basename(folder)
#uplog("Using %s for alb MIME %s title %s" % (album,doc["mtype"],doc["url"]))
......@@ -446,6 +462,7 @@ def recolltosql(conn, rcldocs):
_createsqdb(conn)
tabtorclfield = _prepareTags()
#uplog("Tagscreate: tabtorclfield: %s"%tabtorclfield)
maxcnt = 0
totcnt = 0
......@@ -488,7 +505,14 @@ def recolltosql(conn, rcldocs):
for tb, rclfld in tabtorclfield:
if tb == 'artist': # already done
continue
value = getattr(doc, rclfld, None)
value = doc[rclfld]
# See comment in parsedate
if rclfld == 'date':
if not value:
value = doc['dmtime']
if value:
value = parsedate(value)
if not value:
continue
rowid = _auxtableinsert(conn, tb, value)
......
......@@ -293,7 +293,8 @@ def docarturi(doc, httphp, pathprefix):
bpp = pathprefix.encode('utf-8')
objpath = docpath(doc)
#uplog("docarturi, looking for cover for %s" % objpath)
# Check for an image specific to the track file
base,ext = os.path.splitext(objpath)
for artpath in _artnamegen(base):
......@@ -308,9 +309,9 @@ def docarturi(doc, httphp, pathprefix):
return arturi
# won't work for the virtual group directory itself: it has no doc
if doc["contentgroup"]:
if doc["group"]:
base = os.path.join(os.path.dirname(objpath),
tag2fn(doc["contentgroup"]))
tag2fn(doc["group"]))
for artpath in _artnamegen(base):
#uplog("docarturi: testing %s" % artpath)
if os.path.exists(artpath):
......
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