Commit 6c991857 authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

uprcl: replace redundant uprclutils.rcldirentry with upmplgutils.direntry

parent 2297eff4
...@@ -26,6 +26,7 @@ def sortmodellist(l): ...@@ -26,6 +26,7 @@ def sortmodellist(l):
class Model(object): class Model(object):
id = None id = None
name = None name = None
image = None
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.__dict__.update(kwargs) self.__dict__.update(kwargs)
...@@ -33,7 +34,6 @@ class Model(object): ...@@ -33,7 +34,6 @@ class Model(object):
class User(Model): class User(Model):
upnpclass = "object.container" upnpclass = "object.container"
name = "Unknown" name = "Unknown"
image = None
class Album(Model): class Album(Model):
upnpclass = "object.container.album.musicAlbum" upnpclass = "object.container.album.musicAlbum"
...@@ -43,7 +43,6 @@ class Album(Model): ...@@ -43,7 +43,6 @@ class Album(Model):
num_tracks = -1 num_tracks = -1
duration = -1 duration = -1
release_date = None release_date = None
image = None
available = True available = True
maxsamprate = "44.1" maxsamprate = "44.1"
maxbitdepth = "16" maxbitdepth = "16"
...@@ -59,7 +58,6 @@ class Playlist(Model): ...@@ -59,7 +58,6 @@ class Playlist(Model):
upnpclass = "object.container.album" upnpclass = "object.container.album"
# Using the proper playlistContainer type this confuses e.g. Kazoo # Using the proper playlistContainer type this confuses e.g. Kazoo
#upnpclass = "object.container.playlistContainer" #upnpclass = "object.container.playlistContainer"
name = None
# We create a bogus artist with the playlist owner name when available # We create a bogus artist with the playlist owner name when available
artist = None artist = None
description = None description = None
...@@ -78,23 +76,23 @@ class Track(Model): ...@@ -78,23 +76,23 @@ class Track(Model):
artist = None artist = None
artists = [] artists = []
album = None album = None
image = None
available = True available = True
maxsamprate = "44.1" maxsamprate = "44.1"
maxbitdepth = "16" maxbitdepth = "16"
maxchannels = "2" maxchannels = "2"
class Category(Model):
upnpclass = "object.container"
class Genre(Model):
upnpclass = "object.container"
class SearchResult(Model): class SearchResult(Model):
artists = [] artists = []
albums = [] albums = []
tracks = [] tracks = []
playlists = [] playlists = []
class Category(Model):
image = None
class Genre(Model):
pass
...@@ -165,15 +165,22 @@ def trackid_from_urlpath(pathprefix, a): ...@@ -165,15 +165,22 @@ def trackid_from_urlpath(pathprefix, a):
return trackid return trackid
def direntry(id, pid, title, arturi=None, artist=None, upnpclass=None): def direntry(id, pid, title, arturi=None, artist=None, upnpclass=None,
searchable='1', date=None):
""" Create container entry in format expected by parent """ """ Create container entry in format expected by parent """
ret = {'id':id, 'pid':pid, 'tt':title, 'tp':'ct', 'searchable':'1'} #uplog("rcldirentry: id %s pid %s tt %s dte %s clss %s artist %s arturi %s" %
# (id,pid,title,date,upnpclass,artist,arturi))
ret = {'id':id, 'pid':pid, 'tt':title, 'tp':'ct', 'searchable':searchable}
if arturi: if arturi:
ret['upnp:albumArtURI'] = arturi ret['upnp:albumArtURI'] = arturi
if artist: if artist:
ret['upnp:artist'] = artist ret['upnp:artist'] = artist
if date:
ret['dc:date'] = date
if upnpclass: if upnpclass:
ret['upnp:class'] = upnpclass ret['upnp:class'] = upnpclass
else:
ret['upnp:class'] = 'object.container.storageFolder'
return ret return ret
# Get user and password from service, from the main configuration # Get user and password from service, from the main configuration
......
...@@ -26,7 +26,7 @@ import uprclsearch ...@@ -26,7 +26,7 @@ import uprclsearch
import uprclindex import uprclindex
from upmplgutils import uplog, setidprefix from upmplgutils import uplog, setidprefix
from uprclutils import rcldirentry, waitentry from uprclutils import waitentry
import uprclinit import uprclinit
setidprefix("uprcl") setidprefix("uprcl")
......
...@@ -81,9 +81,8 @@ from urllib.parse import quote as urlquote ...@@ -81,9 +81,8 @@ from urllib.parse import quote as urlquote
import time import time
from timeit import default_timer as timer from timeit import default_timer as timer
from upmplgutils import uplog from upmplgutils import uplog, direntry
from uprclutils import audiomtypes, rcldirentry, \ from uprclutils import audiomtypes, rcldoctoentry, cmpentries
rcldoctoentry, cmpentries
import uprclutils import uprclutils
from recoll import recoll from recoll import recoll
try: try:
...@@ -429,7 +428,7 @@ class Folders(object): ...@@ -429,7 +428,7 @@ class Folders(object):
# Tell the top module what entries we define in the root # Tell the top module what entries we define in the root
def rootentries(self, pid): def rootentries(self, pid):
return [rcldirentry(pid + 'folders', pid, '[folders]'),] return [direntry(pid + 'folders', pid, '[folders]'),]
# Look all non-directory docs inside directory, and return the # Look all non-directory docs inside directory, and return the
...@@ -502,7 +501,7 @@ class Folders(object): ...@@ -502,7 +501,7 @@ class Folders(object):
continue continue
id = self._idprefix + '$d' + str(thisdiridx) id = self._idprefix + '$d' + str(thisdiridx)
arturi = self._arturifordir(thisdiridx) arturi = self._arturifordir(thisdiridx)
entries.append(rcldirentry(id, pid, os.path.basename(nm), entries.append(direntry(id, pid, os.path.basename(nm),
arturi=arturi)) arturi=arturi))
else: else:
# Not a directory. docidx had better been set # Not a directory. docidx had better been set
...@@ -523,7 +522,7 @@ class Folders(object): ...@@ -523,7 +522,7 @@ class Folders(object):
# Add "Browse subtree by tags" entry # Add "Browse subtree by tags" entry
if pid != self._idprefix and self._enabletags: if pid != self._idprefix and self._enabletags:
id = pid + '$tagview.0' id = pid + '$tagview.0'
entries.insert(0, rcldirentry(id, pid, ">> Tag View")) entries.insert(0, direntry(id, pid, ">> Tag View"))
return entries return entries
# Return path for objid, which has to be a container.This is good old # Return path for objid, which has to be a container.This is good old
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
import os, sys import os, sys
from upmplgutils import uplog from upmplgutils import uplog, direntry
from uprclutils import rcldoctoentry, rcldirentry, cmpentries from uprclutils import rcldoctoentry, cmpentries
import uprclutils import uprclutils
import uprclinit import uprclinit
from recoll import recoll from recoll import recoll
...@@ -70,7 +70,7 @@ class Playlists(object): ...@@ -70,7 +70,7 @@ class Playlists(object):
# Return entry to be created in the top-level directory ([playlists]). # Return entry to be created in the top-level directory ([playlists]).
def rootentries(self, pid): def rootentries(self, pid):
return [rcldirentry(pid + 'playlists', pid, return [direntry(pid + 'playlists', pid,
str(len(self.utidx) - 1) + ' playlists'),] str(len(self.utidx) - 1) + ' playlists'),]
...@@ -89,7 +89,7 @@ class Playlists(object): ...@@ -89,7 +89,7 @@ class Playlists(object):
doc = rcldocs[self.utidx[i]] doc = rcldocs[self.utidx[i]]
id = self._idprefix + '$p' + str(i) id = self._idprefix + '$p' + str(i)
title = doc["title"] if doc["title"] else doc["filename"] title = doc["title"] if doc["title"] else doc["filename"]
e = rcldirentry(id, pid, title, e = direntry(id, pid, title,
upnpclass='object.container.playlistContainer') upnpclass='object.container.playlistContainer')
if e: if e:
entries.append(e) entries.append(e)
......
...@@ -29,9 +29,9 @@ import time ...@@ -29,9 +29,9 @@ import time
import tempfile import tempfile
import time import time
from upmplgutils import uplog from upmplgutils import uplog, direntry
import uprclutils import uprclutils
from uprclutils import rcldirentry, rcldoctoentry, cmpentries from uprclutils import rcldoctoentry, cmpentries
import uprclinit import uprclinit
import uprcltagscreate import uprcltagscreate
from uprcltagscreate import _clid, recolltosql from uprcltagscreate import _clid, recolltosql
...@@ -75,7 +75,7 @@ class Tagged(object): ...@@ -75,7 +75,7 @@ class Tagged(object):
uplog("rootentries: pid %s path %s" % (pid, path)) uplog("rootentries: pid %s path %s" % (pid, path))
entries = [] entries = []
nalbs = self._albcntforfolder(path) nalbs = self._albcntforfolder(path)
entries.append(rcldirentry(pid + 'albums', pid, nalbs + ' albums')) entries.append(direntry(pid + 'albums', pid, nalbs + ' albums'))
if path: if path:
where = ' WHERE tracks.path LIKE ? ' where = ' WHERE tracks.path LIKE ? '
args = (path + '%',) args = (path + '%',)
...@@ -86,11 +86,11 @@ class Tagged(object): ...@@ -86,11 +86,11 @@ class Tagged(object):
stmt = "SELECT COUNT(*) from tracks" stmt = "SELECT COUNT(*) from tracks"
c.execute(stmt+where, args) c.execute(stmt+where, args)
nitems = str(c.fetchone()[0]) nitems = str(c.fetchone()[0])
entries.append(rcldirentry(pid + 'items', pid, nitems + ' items')) entries.append(direntry(pid + 'items', pid, nitems + ' items'))
subqs = self._subtreetags(where, args) subqs = self._subtreetags(where, args)
tagdisplaytag = uprcltagscreate.getTagDisplayTag() tagdisplaytag = uprcltagscreate.getTagDisplayTag()
for tt in subqs: for tt in subqs:
entries.append(rcldirentry(pid + '=' + tt , pid, tagdisplaytag[tt])) entries.append(direntry(pid + '=' + tt , pid, tagdisplaytag[tt]))
return entries return entries
...@@ -312,7 +312,7 @@ class Tagged(object): ...@@ -312,7 +312,7 @@ class Tagged(object):
for r in c: for r in c:
id = pid + '$' + str(r[0]) id = pid + '$' + str(r[0])
entries.append( entries.append(
rcldirentry(id, pid, r[1], arturi=r[2], date=r[3],artist=r[4], direntry(id, pid, r[1], arturi=r[2], date=r[3],artist=r[4],
upnpclass='object.container.album.musicAlbum')) upnpclass='object.container.album.musicAlbum'))
return entries return entries
...@@ -329,7 +329,7 @@ class Tagged(object): ...@@ -329,7 +329,7 @@ class Tagged(object):
for r in c: for r in c:
pid = uprclinit.getObjPrefix() + 'albums' pid = uprclinit.getObjPrefix() + 'albums'
id = pid + '$' + albid id = pid + '$' + albid
return rcldirentry(id, pid, r[1], arturi=r[2], date=r[3],artist=r[4], return direntry(id, pid, r[1], arturi=r[2], date=r[3],artist=r[4],
upnpclass='object.container.album.musicAlbum') upnpclass='object.container.album.musicAlbum')
return None return None
...@@ -368,7 +368,7 @@ class Tagged(object): ...@@ -368,7 +368,7 @@ class Tagged(object):
entries = self._trackentriesforstmt(stmt, rawalbids+docidsl, pid) entries = self._trackentriesforstmt(stmt, rawalbids+docidsl, pid)
if ntracks != len(entries): if ntracks != len(entries):
id = pid + '$' + 'showca' id = pid + '$' + 'showca'
entries = [rcldirentry(id, pid, '>> Complete Album')] + entries entries = [direntry(id, pid, '>> Complete Album')] + entries
elif i == len(qpath)-3: elif i == len(qpath)-3:
# 'Complete album' entry # 'Complete album' entry
# Note that minim has an additional level here, probably to # Note that minim has an additional level here, probably to
...@@ -403,7 +403,7 @@ class Tagged(object): ...@@ -403,7 +403,7 @@ class Tagged(object):
# Replace $items with $albums for the album entry # Replace $items with $albums for the album entry
id = pid.replace('$items', '$albums') + '$' + str(albid) + '$showca' id = pid.replace('$items', '$albums') + '$' + str(albid) + '$showca'
if len(tlist) != len(docids): if len(tlist) != len(docids):
entries.append(rcldirentry(id, pid, '>> Complete Album')) entries.append(direntry(id, pid, '>> Complete Album'))
else: else:
displaytracks = False displaytracks = False
el = self._direntriesforalbums(pid, "WHERE album_id = %s"%albid) el = self._direntriesforalbums(pid, "WHERE album_id = %s"%albid)
...@@ -487,7 +487,7 @@ class Tagged(object): ...@@ -487,7 +487,7 @@ class Tagged(object):
if len(albids) > 1: if len(albids) > 1:
id = pid + '$albums' id = pid + '$albums'
label = '%d albums' label = '%d albums'
entries.append(rcldirentry(id, pid, label % len(albids))) entries.append(direntry(id, pid, label % len(albids)))
elif len(albids) == 1 and not subqs: elif len(albids) == 1 and not subqs:
# Only display '>> Complete album' if not all tracks # Only display '>> Complete album' if not all tracks
# already there. If all tracks are there, we display # already there. If all tracks are there, we display
...@@ -496,7 +496,7 @@ class Tagged(object): ...@@ -496,7 +496,7 @@ class Tagged(object):
tlist = self._trackentriesforalbum(albid, pid) tlist = self._trackentriesforalbum(albid, pid)
id = pid + '$albums$' + str(albid) + '$showca' id = pid + '$albums$' + str(albid) + '$showca'
if len(tlist) != len(docids): if len(tlist) != len(docids):
entries.append(rcldirentry(id, pid, '>> Complete Album')) entries.append(direntry(id, pid, '>> Complete Album'))
else: else:
displaytracks = False displaytracks = False
el = self._direntriesforalbums(pid, el = self._direntriesforalbums(pid,
...@@ -507,10 +507,10 @@ class Tagged(object): ...@@ -507,10 +507,10 @@ class Tagged(object):
if subqs: if subqs:
id = pid + '$items' id = pid + '$items'
label = '%d items' label = '%d items'
entries.append(rcldirentry(id, pid, label % len(docids))) entries.append(direntry(id, pid, label % len(docids)))
for tt in subqs: for tt in subqs:
id = pid + '$=' + tt id = pid + '$=' + tt
entries.append(rcldirentry(id, pid, tagdisplaytag[tt])) entries.append(direntry(id, pid, tagdisplaytag[tt]))
elif displaytracks: elif displaytracks:
rcldocs = uprclinit.getTree('folders').rcldocs() rcldocs = uprclinit.getTree('folders').rcldocs()
for docidx in docids: for docidx in docids:
...@@ -533,7 +533,7 @@ class Tagged(object): ...@@ -533,7 +533,7 @@ class Tagged(object):
c.execute(stmt, values) c.execute(stmt, values)
for r in c: for r in c:
id = pid + '$' + str(r[0]) id = pid + '$' + str(r[0])
entries.append(rcldirentry(id, pid, r[1])) entries.append(direntry(id, pid, r[1]))
return entries return entries
...@@ -593,8 +593,8 @@ class Tagged(object): ...@@ -593,8 +593,8 @@ class Tagged(object):
# ?? # ??
return entries return entries
if len(l) == 2: if len(l) == 2:
entries.append(rcldirentry(pid + '$hchide', pid, ">> Hide Contents")) entries.append(direntry(pid + '$hchide', pid, ">> Hide Contents"))
entries.append(rcldirentry(pid + '$hctags', pid, uprclutils.basename(folder))) entries.append(direntry(pid + '$hctags', pid, uprclutils.basename(folder)))
return entries return entries
elif len(l) == 3: elif len(l) == 3:
ppid = '$'.join(pid.split('$')[:-1]) ppid = '$'.join(pid.split('$')[:-1])
......
...@@ -31,8 +31,8 @@ import os ...@@ -31,8 +31,8 @@ import os
import shlex import shlex
import sys import sys
from upmplgutils import uplog from upmplgutils import uplog, direntry
from uprclutils import rcldoctoentry, rcldirentry from uprclutils import rcldoctoentry
import uprclinit import uprclinit
class Untagged(object): class Untagged(object):
...@@ -78,7 +78,7 @@ class Untagged(object): ...@@ -78,7 +78,7 @@ class Untagged(object):
# Return entry to be created in the top-level directory ([untagged]). # Return entry to be created in the top-level directory ([untagged]).
def rootentries(self, pid): def rootentries(self, pid):
return [rcldirentry(pid + 'untagged', pid, '[untagged]'),] return [direntry(pid + 'untagged', pid, '[untagged]'),]
# Browse method # Browse method
......
...@@ -173,25 +173,6 @@ def rcldoctoentry(id, pid, httphp, pathprefix, doc): ...@@ -173,25 +173,6 @@ def rcldoctoentry(id, pid, httphp, pathprefix, doc):
return li return li
def rcldirentry(id, pid, title, arturi=None, artist=None, upnpclass=None,
searchable='1', date=None):
""" Create container entry in format expected by parent """
#uplog("rcldirentry: id %s pid %s tt %s dte %s clss %s artist %s arturi %s" %
# (id,pid,title,date,upnpclass,artist,arturi))
ret = {'id':id, 'pid':pid, 'tt':title, 'tp':'ct', 'searchable':searchable}
if arturi:
ret['upnp:albumArtURI'] = arturi
if artist:
ret['upnp:artist'] = artist
if date:
ret['dc:date'] = date
if upnpclass:
ret['upnp:class'] = upnpclass
else:
ret['upnp:class'] = 'object.container'
return ret
# Bogus entry for the top directory while the index/db is updating # Bogus entry for the top directory while the index/db is updating
def waitentry(id, pid, httphp): def waitentry(id, pid, httphp):
li = {} li = {}
......
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