def do_play(self, s): ''' Enter a phrase like 'Harvest by Neil Young' and the selected track will replace whatever was in the queue With no phrase, will resume playing ''' if s == '': sonos_actions.playback('play') self.msg = "I will resume what was playing." return if 'by' in s: title, artist = s.split(' by ') else: title, artist = s, '' # play adds to queue and doesn't erase it and doesn't actually play it # should be add to queue #return f"I couldn't find the track {title}{' by'+artist if artist else ''}." #self.msg = play_track(title, artist, True) response = play_track(title, artist, True) if response: lst = sonos_actions.list_queue() sonos_actions.play_from_queue(len(lst)-1) self.msg = f"I'll play {response}, which is {len(lst)} in the queue" else: self.msg = f"I couldn't find {s}."
def process_message(): j = request.json print("json loaded =", j) action = j['action'] print("action =", action) if action == 'list_queue': q = sonos_actions.list_queue() return json.dumps(q) elif action == 'track_pos': track_info = sonos_actions.current() p = track_info['playlist_position'] if track_info else "-1" return p elif action == 'list_artists': return json.dumps(sonos_actions.ARTISTS) elif action == 'play_pause': sonos_actions.play_pause() elif action in ('quieter','louder'): sonos_actions.turn_volume(action) elif action == 'next': sonos_actions.playback('next') elif action.startswith("station"): station = action[8:] sonos_actions.play_station(station) elif action.startswith("shuffle"): artist = action[8:] sonos_actions.shuffle(artist) elif action.startswith("play_queue"): pos = action[11:] pos = int(pos) if pos else 0 sonos_actions.play_from_queue(pos) elif action == 'mute': sonos_actions.mute(True) elif action == 'unmute': sonos_actions.mute(False) else: print("I don't recognize that action") return "OK"
def process_message(): j = request.json print("json loaded =", j) action = j['action'] print("action =", action) if action == 'list_queue': q = sonos_actions.list_queue() return json.dumps(q) elif action == 'track_pos': track_info = sonos_actions.current() p = track_info['playlist_position'] if track_info else "-1" return p elif action == 'list_artists': return json.dumps(sonos_actions.ARTISTS) elif action == 'play_pause': sonos_actions.play_pause() elif action in ('quieter', 'louder'): sonos_actions.turn_volume(action) elif action == 'next': sonos_actions.playback('next') elif action.startswith("station"): station = action[8:] sonos_actions.play_station(station) elif action.startswith("shuffle"): artist = action[8:] sonos_actions.shuffle(artist) elif action.startswith("play_queue"): pos = action[11:] pos = int(pos) if pos else 0 sonos_actions.play_from_queue(pos) elif action == 'mute': sonos_actions.mute(True) elif action == 'unmute': sonos_actions.mute(False) else: print("I don't recognize that action") return "OK"
def pause(): msg = sonos_actions.playback('pause') print("Pause return msg from zmq:", msg) return statement("I will pause what was playing.")
def on_message(client, userdata, msg): print(msg.topic+" "+str(msg.payload)) body = msg.payload print("mqtt messge body =", body) try: task = json.loads(body) except Exception as e: print("error reading the mqtt message body: ", e) return action = task.get('action', '') if action == 'play_pause': try: state = master.get_current_transport_info()['current_transport_state'] except Exception as e: print("Encountered error in state = master.get_current_transport_info(): ", e) state = 'ERROR' # check if sonos is playing music if state == 'PLAYING': master.pause() elif state!='ERROR': master.play() elif action in ('quieter','louder'): for s in sp: s.volume = s.volume - 10 if action=='quieter' else s.volume + 10 print("I tried to make the volume "+action) elif action == "volume": #{"action":"volume", "level":70} level = task.get("level", 500) level = int(round(level/10, -1)) if level < 70: for s in sp: s.volume = level print("I changed the volume to:", level) else: print("Volume was too high:", level) #elif action == "play_wnyc": # sonos_actions.play_station('wnyc') elif action == 'next': sonos_actions.playback('next') elif action.startswith("station"): station = action[8:] sonos_actions.play_station(station) elif action.startswith("shuffle"): artist = action[8:] sonos_actions.shuffle(artist) elif action == "play_queue": queue = master.get_queue() if len(queue) != 0: master.stop() master.play_from_queue(0) else: print("I have no idea what you said")
def do_resume(self, s): sonos_actions.playback('play') self.msg = "I will resume what was playing."
def do_next(self, s): sonos_actions.playback('next') self.msg = "I will skip to the next track."
def do_pause(self, s): sonos_actions.playback('pause') self.msg = "I will pause what was playing."
def next_(): msg = sonos_actions.playback('pause') print("Next return msg from zmq:", msg) return statement("I will skip to the next track.")
def resume(): msg = sonos_actions.playback('play') print("Resume return msg from zmq:", msg) return statement("I will resume what was playing.")