Skip to content

Commit

Permalink
Merge pull request #207 from robwebset/AlbumArtUri
Browse files Browse the repository at this point in the history
Support for returning full Album Art URI's
  • Loading branch information
stefankoegl committed Aug 31, 2014
2 parents 990bca6 + d2730ec commit cfab1aa
Showing 1 changed file with 59 additions and 19 deletions.
78 changes: 59 additions & 19 deletions soco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,11 +1093,13 @@ def get_current_transport_info(self):

return playstate

def get_queue(self, start=0, max_items=100):
def get_queue(self, start=0, max_items=100, full_album_art_uri=False):
""" Get information about the queue
:param start: Starting number of returned matches
:param max_items: Maximum number of returned matches
:param full_album_art_uri: If the album art URI should include the
IP address
:returns: A list of :py:class:`~.soco.data_structures.QueueItem`.
This method is heavly based on Sam Soffes (aka soffes) ruby
Expand All @@ -1121,11 +1123,15 @@ def get_queue(self, start=0, max_items=100):
for element in result_dom.findall(
'{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}item'):
item = QueueItem.from_xml(element)
# Check if the album art URI should be fully qualified
if full_album_art_uri:
self._update_album_art_to_full_uri(item)
queue.append(item)

return queue

def get_sonos_playlists(self, start=0, max_items=100):
def get_sonos_playlists(self, start=0, max_items=100,
full_album_art_uri=False):
""" Convenience method for:
get_music_library_information('sonos_playlists')
Refer to the docstring for that method
Expand All @@ -1134,65 +1140,73 @@ def get_sonos_playlists(self, start=0, max_items=100):
out = self.get_music_library_information(
'sonos_playlists',
start,
max_items)
max_items,
full_album_art_uri)
return out

def get_artists(self, start=0, max_items=100):
def get_artists(self, start=0, max_items=100, full_album_art_uri=False):
""" Convinience method for :py:meth:`get_music_library_information`
with `search_type='artists'`. For details on remaining arguments refer
to the docstring for that method.
"""
out = self.get_music_library_information('artists', start, max_items)
out = self.get_music_library_information('artists', start, max_items,
full_album_art_uri)
return out

def get_album_artists(self, start=0, max_items=100):
def get_album_artists(self, start=0, max_items=100,
full_album_art_uri=False):
""" Convinience method for :py:meth:`get_music_library_information`
with `search_type='album_artists'`. For details on remaining arguments
refer to the docstring for that method.
"""
out = self.get_music_library_information('album_artists',
start, max_items)
start, max_items,
full_album_art_uri)
return out

def get_albums(self, start=0, max_items=100):
def get_albums(self, start=0, max_items=100, full_album_art_uri=False):
""" Convinience method for :py:meth:`get_music_library_information`
with `search_type='albums'`. For details on remaining arguments refer
to the docstring for that method.
"""
out = self.get_music_library_information('albums', start, max_items)
out = self.get_music_library_information('albums', start, max_items,
full_album_art_uri)
return out

def get_genres(self, start=0, max_items=100):
def get_genres(self, start=0, max_items=100, full_album_art_uri=False):
""" Convinience method for :py:meth:`get_music_library_information`
with `search_type='genres'`. For details on remaining arguments refer
to the docstring for that method.
"""
out = self.get_music_library_information('genres', start, max_items)
out = self.get_music_library_information('genres', start, max_items,
full_album_art_uri)
return out

def get_composers(self, start=0, max_items=100):
def get_composers(self, start=0, max_items=100, full_album_art_uri=False):
""" Convinience method for :py:meth:`get_music_library_information`
with `search_type='composers'`. For details on remaining arguments
refer to the docstring for that method.
"""
out = self.get_music_library_information('composers', start, max_items)
out = self.get_music_library_information('composers', start, max_items,
full_album_art_uri)
return out

def get_tracks(self, start=0, max_items=100):
def get_tracks(self, start=0, max_items=100, full_album_art_uri=False):
""" Convinience method for :py:meth:`get_music_library_information`
with `search_type='tracks'`. For details on remaining arguments refer
to the docstring for that method.
"""
out = self.get_music_library_information('tracks', start, max_items)
out = self.get_music_library_information('tracks', start, max_items,
full_album_art_uri)
return out

def get_playlists(self, start=0, max_items=100):
def get_playlists(self, start=0, max_items=100, full_album_art_uri=False):
""" Convinience method for :py:meth:`get_music_library_information`
with `search_type='playlists'`. For details on remaining arguments
refer to the docstring for that method.
Expand All @@ -1201,11 +1215,12 @@ def get_playlists(self, start=0, max_items=100):
imported from the music library, they are not the Sonos playlists.
"""
out = self.get_music_library_information('playlists', start, max_items)
out = self.get_music_library_information('playlists', start, max_items,
full_album_art_uri)
return out

def get_music_library_information(self, search_type, start=0,
max_items=100):
max_items=100, full_album_art_uri=False):
""" Retrieve information about the music library
:param search_type: The kind of information to retrieve. Can be one of:
Expand All @@ -1218,6 +1233,8 @@ def get_music_library_information(self, search_type, start=0,
may be restricted by the unit, presumably due to transfer
size consideration, so check the returned number against the
requested.
:param full_album_art_uri: If the album art URI should include the
IP address
:returns: A dictionary with metadata for the search, with the
keys 'number_returned', 'update_id', 'total_matches' and an
'item_list' list with the search results. The search results
Expand Down Expand Up @@ -1267,12 +1284,16 @@ def get_music_library_information(self, search_type, start=0,
item = MLShare.from_xml(container)
else:
item = get_ml_item(container)
# Check if the album art URI should be fully qualified
if full_album_art_uri:
self._update_album_art_to_full_uri(item)
# Append the item to the list
out['item_list'].append(item)

return out

def browse(self, ml_item=None, start=0, max_items=100):
def browse(self, ml_item=None, start=0, max_items=100,
full_album_art_uri=False):
"""Browse (get sub-elements) a music library item
Keyword arguments:
Expand All @@ -1281,6 +1302,8 @@ def browse(self, ml_item=None, start=0, max_items=100):
returned
start (int): The starting index of the results
max_items (int): The maximum number of items to return
full_album_art_uri(bool): If the album art URI should include the
IP address
Returns:
dict: A dictionary with metadata for the search, with the
Expand All @@ -1305,6 +1328,9 @@ def browse(self, ml_item=None, start=0, max_items=100):
dom = XML.fromstring(really_utf8(response['Result']))
for container in dom:
item = get_ml_item(container)
# Check if the album art URI should be fully qualified
if full_album_art_uri:
self._update_album_art_to_full_uri(item)
out['item_list'].append(item)

return out
Expand Down Expand Up @@ -1499,6 +1525,20 @@ def __get_radio_favorites(self, favorite_type, start=0, max_items=100):

return result

def _update_album_art_to_full_uri(self, item):
"""Updated the Album Art URI to be fully qualified
:param item: The item to update the URI for
"""
if not getattr(item, 'album_art_uri', False):
return

# Add on the full album art link, as the URI version
# does not include the ipaddress
if not item.album_art_uri.startswith(('http:', 'https:')):
item.album_art_uri = 'http://' + self.ip_address + ':1400' +\
item.album_art_uri


# definition section

Expand Down

0 comments on commit cfab1aa

Please sign in to comment.