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