def __init__(self, spotify_refresh_token=None, speaker_index=None, locale=None): # find the device devices = soco.discover() if devices is None or len(list(devices)) == 0: time.sleep(1) devices = soco.discover() if devices is None or len(list(devices)) == 0: return try: speaker_index = int(speaker_index) except Exception: speaker_index = 0 if speaker_index >= len(list(devices)): speaker_index = 0 self.device = list(devices)[speaker_index] try: self.tunein_service = MusicService('TuneIn') except Exception: self.tunein_service = None try: self.spotify_service = MusicService('Spotify') except Exception: self.spotify_service = None self.max_volume = MAX_VOLUME if spotify_refresh_token is not None: self.spotify = SpotifyClient(spotify_refresh_token) self.previous_volume = None
def __init__(self, spotify_refresh_token=None): try: self.spotify_service = MusicService('Spotify') except Exception: self.spotify_service = None if spotify_refresh_token is not None: self.spotify = SpotifyClient(spotify_refresh_token) else: self.spotify = None
def __init__(self, soco, username, service_type): super(DeezerSocoPlugin, self).__init__(soco) account = Account() account.username = username account.service_type = service_type self.__ms = MusicService('Deezer', account=account) self.__dz = deezer.Client()
def play_spotify_album(player, uri): # need to convert from x-rincon-cpcontainer:1004206cspotify%3aalbum%3a2pbkqNS3aQJfEgm20nUe5P # to spotify:album:2pbkqNS3aQJfEgm20nUe5P print('playing spotify album') spotify = MusicService('Spotify') spotid = urllib.parse.unquote(uri[21::]) start = spotid.find('spotify:') spotid = spotid[start::] # x.stop() x.clear_queue() spotify_add_album.spotify_add_album(x, spotify, spotid) x.play_from_queue(0)
def play_radio_station(player, uri): """Plays the selected radio station. The URI must be in the format as it is currently returned from soco: x-sonosapi-stream:s25111?sid=254&flags=32 """ verbose_output("Switching to radio station {0}".format(uri)) service = MusicService('TuneIn') didl = DidlItem(title="DUMMY", parent_id="DUMMY", item_id="DUMMY", desc=service.desc) meta = to_didl_string(didl) player.avTransport.SetAVTransportURI([('InstanceID', 0), ('CurrentURI', uri), ('CurrentURIMetaData', meta)]) player.play()
# -*- 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)
def __init__(self): try: self.tunein_service = MusicService('TuneIn') except Exception: self.tunein_service = None
#speaker.play_uri("x-rincon-cpcontainer:spotify%3auser%3aspotifydiscover%3aplaylist%3a2fNlVzK3IlghhG87HZqpCA?sid=9&flags=8224&sn=9") #speaker.add_to_queue("x-sonos-spotify:spotify%3auser%3aspotifydiscover%3aplaylist%3a2fNlVzK3IlghhG87HZqpCA?sid=9&flags=8224&sn=9") if __name__ == "__main__": LOG_LEVEL = logging.FATAL # FATAl, DEBUG, INFO logging.basicConfig(format="%(asctime)s [%(levelname)s]: %(message)s", level=LOG_LEVEL) #logging.getLogger("soco").setLevel(logging.FATAL) logging.info("Start program") # list_players() player = get_device("Mobil") player = SoCo('192.168.1.36') print("Plaver is: '{}'".format(player.ip_address)) albums = player.music_library.get_albums(search_term='White') for album in albums: print('Added:', album.creator, "-", album.title) spotify = MusicService('Spotify') print(spotify.available_search_categories) print(spotify.search("artists", "The Cure")) #s = get_device("Küche") #q = s.get_queue() #s.add_to_queue("spotify:track:7HFaTkpIeG0pXINEm7EEG4") #play_weekly_discover_in_room(player) logging.info("End program")
#!/usr/bin/env python # -*- coding: utf-8 -*- """Demo to add a music service track or album to a queue.""" 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.105") # <------- Your IP here service = MusicService("Spotify") # <------ Your Music Service here album_id = "spotify:album:5qo7iEWkMEaSXEZ7fuPvC3" # <------ an album track_id = "spotify:track:2qs5ZcLByNTctJKbhAZ9JE" # <------ a track 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.