SoCo/SoCo — pull request #262 by lawrenceakka (2014-11-23 16:49:15+00:00)
Title: Universal Music services code

Continuing the discussion from #247 , with a PR!

This implements the MusicService class for access to all the music services known to Sonos.

It does not (yet) translate the data returned by the various services to DIDL.

Please test with the various services you have access to, and let me know what you think.

Lawrence

Examples:

Print all the services Sonos knows about

```python
>>> from soco.music_services import MusicService
>>> from pprint import ppring
>>> print (MusicService.get_all_music_services())
['Spotify',
'The Hype Machine',
'Saavn',
'Bandcamp',
'Stitcher SmartRadio',
'Concert Vault',
...
]
```
Or just those those which you are subscribed (and the relevant usernames)

```python
>>> pprint (MusicService.get_subscribed_music_services())
[('Spotify', u'XXXXXX'), ('radioPup', u''), ('Spreaker', u'')]
```
Interact with TuneIn

```python

>>> tunein = MusicService('TuneIn')
>>> print tunein

>>> pprint (tunein.get_metadata(item_id='root'))
{'count': 5,
'index': 0,
'mediaCollection': ({'albumArtURI': u'http://spotify-...',
'canEnumerate': True,
'canPlay': False,
'canScroll': False,
'id': u'playlists',
'itemType': u'favorites',
'title': u'Playlists'},
{'albumArtURI': u'http://spotify-...',
'canEnumerate': True,
'canPlay': True,
'canScroll': False,
'id': u'starred',
'itemType': u'favorites',
'title': u'Starred'},
...),
'total': 5}
# Get some metadata about a track
>>> response = spotify.get_media_metadata(
... item_id='spotify:track:6NmXV4o6bmp704aPGyTVVG')
>>> print (response)
{'mediaMetadata': [{'id': u'spotify:track:6NmXV4o6bmp704aPGyTVVG'},
{'itemType': u'track'},
{'title': u'B?n Fra Helvete (Live)'},
{'mimeType': u'audio/x-spotify'},
{'trackMetadata': {'album': u'Mann Mot Mann (Ep)',
'albumArtURI': u'http://o.s...9',
'albumId': u'spotify:album:...',
'artist': u'Kaizers Orchestra',
'artistId': u'spotify:artist...',
'canAddToFavorites': True,
'canPlay': True,
'canSkip': True,
'duration': 317}}]}
```

or even a playlist

```python

>>> response = spotify.get_metadata(
... item_id='spotify:user:spotify:playlist:0FQk6BADgIIYd3yTLCThjg')

```
or a URI

```python

>>> response = spotify.get_media_URI(
... item_id='spotify:track:6NmXV4o6bmp704aPGyTVVG')

```
Find the available search categories, and use them

```python

>>> pprint (spotify.available_search_categories)
['albums', 'tracks', 'artists']
>>> result = spotify.search(category='artists', term='miles')

```