Ejemplo n.º 1
0
    def do_queue(self, s):
        '''Show the queue and the currently playing track'''

        lst = sonos_actions.list_queue()
        if not lst:
            self.msg = "The queue is empty"
            return

        if s:
            try:
                pos = int(s)
            except ValueError:
                self.msg = "That wasn't a number"
                return

            if 0 < pos <= len(lst):
                sonos_actions.play_from_queue(pos-1)
                self.msg = f"I will play track {pos}: {lst[pos-1]}"
            else:
                self.msg = f"{s} is out of the range of the queue"
        else:
            q = list(enumerate(lst, 1))
            track_info = sonos_actions.current()
            if track_info:
                cur_pos = int(track_info['playlist_position'])
                q[cur_pos-1] = (cur_pos,self.colorize(q[cur_pos-1][1], 'green'))

            pos = self.select2(q, "Which track? ")

            if pos:
                sonos_actions.play_from_queue(pos-1)
                self.msg = self.colorize(f"I will play track {pos}: {lst[pos-1]}", 'green')
            else:
                self.msg = self.colorize("OK, I won't play anything.", 'red')
Ejemplo n.º 2
0
    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}."
Ejemplo n.º 3
0
    def do_queue(self, s):
        '''Show the queue and the currently playing track'''

        lst = sonos_actions.list_queue()
        if not lst:
            self.msg = "The queue is empty"
            return

        if s:
            try:
                pos = int(s)
            except ValueError:
                self.msg = "That wasn't a number"
                return

            if 0 < pos <= len(lst):
                sonos_actions.play_from_queue(pos-1)
                self.msg = f"I will play track {pos}: {lst[pos-1]}"
            else:
                self.msg = f"{s} is out of the range of the queue"
        else:
            q = list(enumerate(lst, 1))
            track_info = sonos_actions.current()
            if track_info:
                cur_pos = int(track_info['playlist_position'])
                q[cur_pos-1] = (cur_pos, colorize(q[cur_pos-1][1], 'green'))

            pos = self.select2(q, "Which track? ")

            if pos:
                sonos_actions.play_from_queue(pos-1)
                self.msg = colorize(f"I will play track {pos}: {lst[pos-1]}", 'green')
            else:
                self.msg = colorize("OK, I won't play anything.", 'red')
Ejemplo n.º 4
0
    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}."
Ejemplo n.º 5
0
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"
Ejemplo n.º 6
0
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"
Ejemplo n.º 7
0
 def do_add(self, s):
     '''
     Enter a phrase like 'Harvest by Neil Young' and the selected track
     will be added to the end of the queue
     '''
     if 'by' in s:
         title, artist = s.split(' by ')
     else:
         title, artist = s ,''
     response = play_track(title, artist, True)
     if response:
         lst = sonos_actions.list_queue()
         self.msg = f"I'll add {response}, which is {len(lst)} in the queue"
     else:
         self.msg = f"I couldn't find {s}."
Ejemplo n.º 8
0
 def do_add(self, s):
     '''
     Enter a phrase like 'Harvest by Neil Young' and the selected track
     will be added to the end of the queue
     '''
     if 'by' in s:
         title, artist = s.split(' by ')
     else:
         title, artist = s ,''
     response = play_track(title, artist, True)
     if response:
         lst = sonos_actions.list_queue()
         self.msg = f"I'll add {response}, which is {len(lst)} in the queue"
     else:
         self.msg = f"I couldn't find {s}."
Ejemplo n.º 9
0
def list_queue():
    msg = sonos_actions.list_queue()
    print("ListQueue return msg from zmq:", msg)
    return statement(msg)
Ejemplo n.º 10
0
def list_queue():
    msg = sonos_actions.list_queue()
    print("ListQueue return msg from zmq:", msg)
    return statement(msg)