def play_sonos(junk): logging.info('pause button pressed, start playing') self.force_refresh = True self.nav_array[1] = BoxButton('pause', 2, is_sprite=True, on_press=play_sonos, user_data=None) #self.nav_grid = urwid.GridFlow(self.nav_array,cell_width=50,h_sep=0,v_sep=0,align='center') self.dead_alarm = self.loop.set_alarm_in(.01, self.refresh) #commented out for testing at hotel play_room = (str(pod_dict['Rooms']['Living'])) self.poor_man_refresh() try: sonos = SoCo(play_room) look_at_queue = sonos.get_queue() if len(look_at_queue) > 0: sonos.group.coordinator.play() else: print("the queue is empty") except soco.exceptions.SoCoUPnPException as e: logging.warning("Exception caught. Not expecting trace", exc_info=False, stack_info=False) print("the queue is empty")
def bttn_stop(): # connect to the Sonos sonos = SoCo(SONOS_IP) # connect to Philips Hue Bridge hue = Bridge(ip=HUE_IP, username=HUE_USERNAME) # stop the Sonos and reset to sensible defaults queue = sonos.get_queue() sonos.clear_queue() sonos.volume = STOP_VOLUME sonos.play_mode = 'NORMAL' sonos.stop() # set the lights back to a sensible default command = { 'transitiontime': (STOP_DIMMER_SECONDS * 10), 'on': True, 'bri': STOP_DIMMER_BRIGHTNESS } hue.set_light(STOP_LIGHTS, command) return jsonify(status="success")
def play_sonos(junk): logging.info('play button pressed') self.force_refresh = True self.nav_array[int(right(junk.label, 1)) - 1] = BoxButton( 'pause', 2, is_sprite=True, theme=nav_theme, on_press=pause_sonos, user_data=None) #self.nav_grid = urwid.GridFlow(self.nav_array,cell_width=50,h_sep=0,v_sep=0,align='center') self.dead_alarm = self.loop.set_alarm_in(.01, self.refresh) #commented out for testing at hotel play_room = (str(pod_dict['Rooms']['Living'])) try: sonos = SoCo(play_room) look_at_queue = sonos.get_queue() if len(look_at_queue) > 0: sonos.group.coordinator.play() #else: # print("the queue is empty") except: #this doesn't work for some reason. try just looking for stop states. logging.warning("Exception caught. Not expecting trace", exc_info=False, stack_info=False) print("the queue is empty")
def bttn_stop(): # connect to the Sonos sonos = SoCo(SONOS_IP) # connect to Philips Hue Bridge hue = Bridge(ip=HUE_IP, username=HUE_USERNAME) # stop the Sonos and reset to sensible defaults queue = sonos.get_queue() sonos.clear_queue() sonos.volume = 45 sonos.play_mode = 'NORMAL' sonos.stop() # set the lights back to approximately 80% over 3 seconds command = { 'transitiontime': 30, 'on': True, 'bri': 203 } hue.set_light(1, command) return jsonify(status="success")
class Sonos(AbstractJob): def __init__(self, conf): self.interval = conf['interval'] self.sonos = SoCo(conf['ip']) def get(self): zone_name = self.sonos.get_speaker_info()['zone_name'] np = self.sonos.get_current_track_info() current_track = np if np['playlist_position'] != '0' else None queue = self.sonos.get_queue(int(np['playlist_position']), 1) next_item = queue.pop() if len(queue) > 0 else None next_track = {} if next_item is not None: next_track = { 'artist': next_item.creator, 'title': next_item.title, 'album': next_item.album } state = self.sonos.get_current_transport_info()[ 'current_transport_state'] return { 'room': zone_name, 'state': state, 'current': current_track, 'next': next_track }
class SonosQ: def __init__(self, address): self.ipAddress = address self.zone = SoCo(self.ipAddress) self.__replaceStringFlag = False def write_Q_as_m3u(self, filePath, ignoredFilePath=""): playlistFile = open(filePath, "w") if ignoredFilePath <> None: ignoredFile = open(ignoredFilePath, "w") i = 0 myQ = self.zone.get_queue(start=i) while i < myQ.total_matches: myQ = self.zone.get_queue(start=i) for item in myQ: i += 1 try: strippedURI = self.uri2filepath(item.resources[0].uri) except: print("Unknown Item: " + str(item.__dict__)) else: if strippedURI <> None: # print(strippedURI) encoded_URI = strippedURI #.decode('utf-8').encode('latin-1', 'replace') if self.__replaceStringFlag: encoded_URI = encoded_URI.replace( self.mainString, self.replacementString) playlistFile.write(encoded_URI + "\n") else: # print("No match found: " + str(item.__dict__)) if ignoredFilePath <> None: ignoredFile.write(str(item.__dict__) + "\n") def enableStringReplace(self, mainString, replacementString): self.mainString = mainString self.replacementString = replacementString self.__replaceStringFlag = True def uri2filepath(self, uri): split_uri = uri.split(':') if split_uri[0] == "x-file-cifs": #We have a Local Library Item. myURI = split_uri[1] myURI = urllib.unquote(myURI) return myURI
def sexy_time(): # connect to the Sonos sonos = SoCo(SONOS_IP) # connect to Philips Hue Bridge hue = Bridge(ip=HUE_IP, username=HUE_USERNAME) # get queue queue = sonos.get_queue() # if we: # * already have a queue # * music is playing # * we are already playing a queue that begins with "Let's Get It On" # ...then skip to the next track if len(queue) > 0 and \ sonos.get_current_transport_info()['current_transport_state'] == "PLAYING" and \ queue[0].title == SEXY_TIME_FIRST_TRACK: sonos.next() # else, intitiate a fresh Sexy Time else: # clear Sonos queue sonos.clear_queue() # turn off shuffle and repeat sonos.play_mode = 'NORMAL' # set volume sonos.volume = 45 # play Sexy Time playlist playlist = get_sonos_playlist(sonos, SEXY_TIME_PLAYLIST_NAME) if playlist: sonos.add_to_queue(playlist) sonos.play() # dim the lights (bri out of 254) over the pre-defined amount of time command = { 'transitiontime': (SEXY_TIME_DIMMER_SECONDS * 10), 'on': True, 'bri': SEXY_TIME_DIMMER_BRIGHTNESS } hue.set_light(1, command) return jsonify(status="success")
def sonos_play_from_queue(self): """sonos_play_from_queue, speelt queue af """ # pagina laden voor als antwoord terug aan de server h = queuebeheer_temp.sonos_play_from_queue() # queue afspelen als deze niet leeg is sonos = SoCo(COORDINATOR) if len(sonos.get_queue()) > 0: sonos.play_from_queue(0) return h
def sonos_clear_queue(self): """sonos_clear_queue, maak sonos afspeellijst leeg """ # pagina laden voor als antwoord terug aan de server h = queuebeheer_temp.sonos_clear_queue() ## queue leegmaken als er wat in zit sonos = SoCo(COORDINATOR) # als de sonos queue niet leeg is if len(sonos.get_queue()) > 0: ## sonos queue leegmaken sonos.clear_queue() query = """ delete from queue """ self._db.dbExecute(query) return h
def party(): # connect to the Sonos sonos = SoCo(SONOS_IP) # get queue queue = sonos.get_queue() # if we: # * already have a queue # * music is playing # ...then skip to the next track if len(queue) > 0 and sonos.get_current_transport_info()['current_transport_state'] == "PLAYING": sonos.next() # else, intitiate a fresh Party Time else: # clear Sonos queue sonos.clear_queue() # turn on shuffle, turn off repeat sonos.play_mode = 'SHUFFLE_NOREPEAT' # set volume sonos.volume = 45 # play Party playlist playlist = get_sonos_playlist(sonos, PARTY_TIME_PLAYLIST_NAME) if playlist: sonos.add_to_queue(playlist) sonos.play() return jsonify(status="success")