--- a/src/cdplugins/pycommon/upmplgutils.py
+++ b/src/cdplugins/pycommon/upmplgutils.py
@@ -1,16 +1,51 @@
-# # de shared by the tidal, qobuz and gmusic plugins. This assumes a
-# certain formats for track, albums, and artist objects (as defined in
-# practise in models.py, but if it quacks...), and also for permanent
-# URLs, and implements utility functions for translating to what our
-# parent expects or sends on the pipe.
+# Copyright (C) 2016 J.F.Dockes
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the
+# Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+#
+# Shared code for the tidal, qobuz and gmusic plugins (at this
+# point). This assumes: - The interface for the entity objects (track,
+# album...) concretely defined in models.py, but duck-typed. - The
+# format for the permanent URLs # e module implements utility
+# functions for translating to/from what our parent expects or sends
+# on the pipe.
from __future__ import print_function, unicode_literals
import posixpath
import re
-# Transform a Track array into an array of dicts suitable for
-# returning as a track list
def trackentries(httphp, pathprefix, objid, tracks):
+ """
+ Transform a list of Track objects to the format expected by the parent
+
+ Args:
+ objid (str): objid for the browsed object (the parent container)
+ tracks is the array of Track objects to be translated
+ tracks: a list of Track objects.
+
+ Returns:
+ A list of dicts, each representing an UPnP item, with the
+ keys as expected in the plgwithslave.cxx resultToEntries() function.
+
+ The permanent URIs, are of the following form, based on the
+ configured host:port and pathprefix arguments and track Id:
+
+ http://host:port/pathprefix/track?version=1&trackId=<trackid>
+
+ """
+
entries = []
for track in tracks:
if not track.available:
@@ -21,9 +56,7 @@
li['tt'] = track.name
li['uri'] = 'http://%s' % httphp + \
posixpath.join(pathprefix,
- 'track?version=1&trackId=%s' % \
- track.id)
- #msgproc.log("URI: [%s]" % li['uri'])
+ 'track?version=1&trackId=%s' % track.id)
li['tp'] = 'it'
if track.album:
li['upnp:album'] = track.album.name
@@ -39,22 +72,22 @@
entries.append(li)
return entries
-# Container entry
-def direntry(id, pid, title):
- return {'id': id, 'pid' : pid, 'tt': title, 'tp':'ct', 'searchable' : '1'}
+def trackid_from_urlpath(pathprefix, a):
+ """
+ Extract track id from a permanent URL path part.
-# Directory entries from list of (name,id) pairs
-def direntries(objid, ttidlist):
- content = []
- for tt,id in ttidlist:
- content.append(direntry(objid + '$' + id, objid, tt))
- return content
+ This supposes that the input URL has the format produced by the
+ trackentries() method: <pathprefix>/track?version=1&trackId=<trackid>
-# Extract trackid from URL. Supposes that our permanent URLs look like
-# track?version=1&trackId=<trackid>
-def trackid_from_urlpath(pathprefix, a):
+ Args:
+ pathprefix (str): our configured path prefix (e.g. /qobuz/)
+ a (dict): the argument dict out of cmdtalk with a 'path' key
+ Returns:
+ str: the track Id.
+ """
+
if 'path' not in a:
- raise Exception("No path in args")
+ raise Exception("trackuri: no 'path' in args")
path = a['path']
# pathprefix + 'track?version=1&trackId=trackid
@@ -65,3 +98,21 @@
trackid = m.group(1)
return trackid
+
+def direntry(id, pid, title, arturi=None, artist=None):
+ """ Create container entry in format expected by parent """
+ ret = {'id':id, 'pid':pid, 'tt':title, 'tp':'ct', 'searchable':'1'}
+ if arturi:
+ ret['upnp:albumArtURI'] = arturi
+ if artist:
+ ret['upnp:artist'] = artist
+ return ret
+
+
+def direntries(objid, ttidlist):
+ """ Create a list of directory entries """
+ content = []
+ for tt,id in ttidlist:
+ content.append(direntry(objid + '$' + id, objid, tt))
+ return content
+