# -*- coding: utf-8 -*- from __future__ import unicode_literals from soco import SoCo from soco.data_structures import DidlItem, DidlResource from soco.music_services import MusicService from soco.compat import quote_url device = SoCo("192.168.1.80") # <------- Your IP here service = MusicService("Deezer") # <------ Your Music Service here track_id = service.get_metadata(item_id='radio-37635')['mediaMetadata']['id'] def add_from_service(item_id, service, device, is_track=True): # The DIDL item_id is made of the track_id (url escaped), but with an 8 # (hex) digit prefix. It is not clear what this is for, but it doesn't # seem to matter (too much) what it is. We can use junk (thought the # first digit must be 0 or 1), and the player seems to do the right # thing. Real DIDL items sent to a player also have a title and a # parent_id (usually the id of the relevant album), but they are not # necessary. The flow charts at http://musicpartners.sonos.com/node/421 # and http://musicpartners.sonos.com/node/422 suggest that it is the job # of the player, not the controller, to call get_metadata with a track # id, so this might explain why no metadata is needed at this stage. # NB: quote_url will break if given unicode on Py2.6, and early 2.7. So # we need to encode.
# -*- coding: utf-8 -*- from __future__ import unicode_literals from soco import SoCo from soco.data_structures import DidlItem, DidlResource from soco.music_services import MusicService from soco.compat import quote_url device = SoCo("192.168.1.80") # <------- Your IP here service = MusicService("Deezer") # <------ Your Music Service here track_id = service.get_metadata(item_id='radio-37635')['mediaMetadata']['id'] def add_from_service(item_id, service, device, is_track=True): # The DIDL item_id is made of the track_id (url escaped), but with an 8 # (hex) digit prefix. It is not clear what this is for, but it doesn't # seem to matter (too much) what it is. We can use junk (thought the # first digit must be 0 or 1), and the player seems to do the right # thing. Real DIDL items sent to a player also have a title and a # parent_id (usually the id of the relevant album), but they are not # necessary. The flow charts at http://musicpartners.sonos.com/node/421 # and http://musicpartners.sonos.com/node/422 suggest that it is the job # of the player, not the controller, to call get_metadata with a track # id, so this might explain why no metadata is needed at this stage. # NB: quote_url will break if given unicode on Py2.6, and early 2.7. So # we need to encode. item_id = quote_url(item_id.encode('utf-8')) didl_item_id = "0fffffff{0}".format(item_id)
from soco.music_services import MusicService zone_list = list(soco.discover()) sonos = zone_list[0] print(MusicService.get_subscribed_services_names()) spotify = MusicService('Spotify') print(spotify.available_search_categories) search_term = 'Corinne Bailey Rae' result = spotify.search(category='artists', term=search_term) print result for search_result in result['mediaCollection']: if search_result['title'] == search_term: print search_result json_pprint(spotify.get_metadata(search_result['id'])) b_resultlist = spotify.get_metadata(search_result['id']) for b_result in b_resultlist['mediaCollection']: if b_result['title'] == 'Top Tracks': #json_pprint(spotify.get_metadata(b_result['id'])) c_resultlist = spotify.get_metadata(b_result['id']) #print result['mediaCollection']#[search_result] #sonos.add_uri_to_queue(c_resultlist['mediaMetadata'][0]['id']) st = SpotifyTrack(c_resultlist['mediaMetadata'][0]['id']) print(st.didl_metadata) #spotify_plugin = Spotify(soco) #spotify_plugin.add_track_to_queue(st)