soco.ms_data_structures module¶
This module contains all the data structures for music service plugins.
-
soco.ms_data_structures.
get_ms_item
(xml, service, parent_id)[source]¶ Return the music service item that corresponds to xml.
The class is identified by getting the type from the ‘itemType’ tag
Return a list of tags that contain text retrieved recursively from an XML tree.
-
class
soco.ms_data_structures.
MusicServiceItem
(**kwargs)[source]¶ Class that represents a music service item.
-
classmethod
from_xml
(xml, service, parent_id)[source]¶ Return a Music Service item generated from xml.
Parameters: - xml (
xml.etree.ElementTree.Element
) – Object XML. All items containing text are added to the content of the item. The class variablevalid_fields
of each of the classes list the valid fields (after translating the camel case to underscore notation). Required fields are listed in the class variable by that name (where ‘id’ has been renamed to ‘item_id’). - service (Instance of sub-class of
soco.plugins.SoCoPlugin
) – The music service (plugin) instance that retrieved the element. This service must containid_to_extended_id
andform_uri
methods anddescription
andservice_id
attributes. - parent_id (str) – The parent ID of the item, will either be the extended ID of another MusicServiceItem or of a search
For a track the XML can e.g. be on the following form:
<mediaMetadata xmlns="http://www.sonos.com/Services/1.1"> <id>trackid_141359</id> <itemType>track</itemType> <mimeType>audio/aac</mimeType> <title>Teacher</title> <trackMetadata> <artistId>artistid_10597</artistId> <artist>Jethro Tull</artist> <composerId>artistid_10597</composerId> <composer>Jethro Tull</composer> <albumId>albumid_141358</albumId> <album>MU - The Best Of Jethro Tull</album> <albumArtistId>artistid_10597</albumArtistId> <albumArtist>Jethro Tull</albumArtist> <duration>229</duration> <albumArtURI>http://varnish01.music.aspiro.com/sca/ imscale?h=90&w=90&img=/content/music10/prod/wmg/ 1383757201/094639008452_20131105025504431/resources/094639008452. jpg</albumArtURI> <canPlay>true</canPlay> <canSkip>true</canSkip> <canAddToFavorites>true</canAddToFavorites> </trackMetadata> </mediaMetadata>
- xml (
-
classmethod
from_dict
(dict_in)[source]¶ Initialize the class from a dict.
Parameters: dict_in (dict) – The dictionary that contains the item content. Required fields are listed class variable by that name
-
__repr__
()[source]¶ Return the repr value for the item.
The repr is on the form:
<class_name 'middle_part[0:40]' at id_in_hex>
where middle_part is either the title item in content, if it is set, or
str(content)
. The output is also cleared of non-ascii characters.
-
__str__
()[source]¶ Return the str value for the item:
<class_name 'middle_part[0:40]' at id_in_hex>
where middle_part is either the title item in content, if it is set, or
str(content)
. The output is also cleared of non-ascii characters.
-
to_dict
¶ Return a copy of the content dict.
-
didl_metadata
¶ Return the DIDL metadata for a Music Service Track.
The metadata is on the form:
<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="...self.extended_id..." parentID="...self.parent_id..." restricted="true"> <dc:title>...self.title...</dc:title> <upnp:class>...self.item_class...</upnp:class> <desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/"> self.content['description'] </desc> </item> </DIDL-Lite>
-
item_id
¶ Return the item id.
-
extended_id
¶ Return the extended id.
-
title
¶ Return the title.
-
service_id
¶ Return the service ID.
-
can_play
¶ Return a boolean for whether the item can be played.
-
parent_id
¶ Return the extended parent_id, if set, otherwise return None.
-
album_art_uri
¶ Return the album art URI if set, otherwise return None.
-
classmethod
-
class
soco.ms_data_structures.
MSTrack
(title, item_id, extended_id, uri, description, service_id, **kwargs)[source]¶ Class that represents a music service track.
Initialize MSTrack item.
-
album
¶ Return the album title if set, otherwise return None.
-
artist
¶ Return the artist if set, otherwise return None.
-
duration
¶ Return the duration if set, otherwise return None.
-
uri
¶ Return the URI.
-
-
class
soco.ms_data_structures.
MSAlbum
(title, item_id, extended_id, uri, description, service_id, **kwargs)[source]¶ Class that represents a Music Service Album.
-
artist
¶ Return the artist if set, otherwise return None.
-
uri
¶ Return the URI.
-
-
class
soco.ms_data_structures.
MSAlbumList
(title, item_id, extended_id, uri, description, service_id, **kwargs)[source]¶ Class that represents a Music Service Album List.
-
uri
¶ Return the URI.
-
-
class
soco.ms_data_structures.
MSPlaylist
(title, item_id, extended_id, uri, description, service_id, **kwargs)[source]¶ Class that represents a Music Service Play List.
-
uri
¶ Return the URI.
-
-
class
soco.ms_data_structures.
MSArtistTracklist
(title, item_id, extended_id, uri, description, service_id, **kwargs)[source]¶ Class that represents a Music Service Artist Track List.
-
uri
¶ Return the URI.
-
-
class
soco.ms_data_structures.
MSArtist
(title, item_id, extended_id, service_id, **kwargs)[source]¶ Class that represents a Music Service Artist.