Hi Kenneth,
As the interface I'm calling is
soco.get_music_library_information(...)
soco.get_queue(...)
These
are being called on given instances of soco's, so they already have the
IP address etc. (And after all, the queue is a queue on a given
instance). So if the "rule" is, if you call it on an instance of soco
(like get_current_track_info) they should have the full URI, then
shouldn't these?
Either way, I have put together a class that extends the soco class, and tweaks the return etc.
In case it's of any use to anyone else:
class Sonos(SoCo):
# Format of the meta data (borrowed from sample code)
meta_template = '<DIDL-Lite
xmlns:dc="
http://purl.org/dc/elements/1.1/"
xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"
xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/"
xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item
id="R:0/0/0" parentID="R:0/0"
restricted="true"><dc:title>{title}</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc
id="cdudn"
nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">{service}</desc></item></DIDL-Lite>'
tunein_service = 'SA_RINCON65031_'
# Converts non complete URIs to complete URIs with IP address
def _updateAlbumArtToFullUri(self, musicInfo):
if hasattr(musicInfo, 'album_art_uri'):
# Add on the full album art link, as the URI version does not include the ipaddress
if (musicInfo.album_art_uri != None) and (musicInfo.album_art_uri != ""):
if not musicInfo.album_art_uri.startswith(('http:', 'https:')):
musicInfo.album_art_uri = 'http://' + self.ip_address + ':1400' + musicInfo.album_art_uri
# Override method so that the album art http reference can be added
def get_music_library_information(self, search_type, start=0, max_items=100):
# Call the base version
musicInfo = SoCo.get_music_library_information(self, search_type, start, max_items)
# Make sure the album art URI is the full path
self._updateAlbumArtToFullUri(musicInfo)
return musicInfo
# Override method so that the album art http reference can be added
def get_queue(self, start = 0, max_items = 100):
list = SoCo.get_queue(self, start=start, max_items=max_items)
if list != None:
for anItem in list:
# Make sure the album art URI is the full path
self._updateAlbumArtToFullUri(anItem)
return list
# For radio playing a title is required
def play_uri(self, uri='', title=None, metadata=''):
# Radio stations need to have at least a title to play
if (metadata == '') and (title != None):
title_esc = cgi.escape(title)
metadata = Sonos.meta_template.format(title=title_esc, service=Sonos.tunein_service)
# Need to replace any special characters in the URI
uri = cgi.escape(uri)
# Now play the track
SoCo.play_uri(self, uri, metadata)
# Need to override the add_to_queue method as in 0.7 it forces you to have
# metadata - that we do not have
def add_to_queue(self, uri):
queueitem = [
('InstanceID', 0),
('EnqueuedURI', uri),
('EnqueuedURIMetaData', ''),
('DesiredFirstTrackNumberEnqueued', 0),
('EnqueueAsNext', 1)
]
response = self.avTransport.AddURIToQueue(queueitem)
qnumber = response['FirstTrackNumberEnqueued']
return int(qnumber)
Thanks for you continued assistance.
Rob