Example #1
0
 def on_play_random_mix(self, intent, session, pid=None):
     server = self._server
     try:
         slots = [
             v.get('value') for k, v in intent['slots'].items()
             if k.endswith('Genre')
         ]
         print_d("Extracted genre slots: {slots}", slots=slots)
     except KeyError:
         print_d("Couldn't process genres from: {intent}", intent=intent)
     else:
         lms_genres = self._genres_from_slots(slots, server.genres)
         if lms_genres:
             server.play_genres(lms_genres, player_id=pid)
             gs = human_join(sanitise_text(g) for g in lms_genres)
             text = _("Playing mix of {genres}").format(genres=gs)
             return self.smart_response(text=text, speech=text)
         else:
             genres_text = human_join(slots, _("or"))
             text = _("Don't understand requested genres {genres}").format(
                 genres=genres_text)
             speech = _("Can't find genres: {genres}").format(
                 genres=genres_text)
             return self.smart_response(text=text, speech=speech)
     err_text = "Don't understand intent '{intent}'".format(intent=intent)
     raise ValueError(err_text)
Example #2
0
    def on_select_player(self, intent, session, pid=None):
        srv = self._server
        srv.refresh_status()

        # Do it again, yes, but not defaulting this time.
        pid = self.player_id_from(intent, defaulting=False)
        if pid:
            player = srv.players[pid]
            srv.cur_player_id = player.id
            text = _("Selected {player}").format(player=player.name)
            title = _("Selected player {player}").format(player=player)
            return speech_response(title=title,
                                   speech=text,
                                   store={"player_id": pid})
        speech = (_("I only found these players: {players}. "
                    "Could you try again?").format(
                        players=human_join(srv.player_names)))
        reprompt = (_("You can select a player by saying \"{utterance}\" "
                      "and then the player name.").format(
                          utterance=Utterances.SELECT_PLAYER))
        try:
            player = intent['slots']['Player']['value']
            title = (_("No player called \"{name}\"").format(name=player))
        except KeyError:
            title = "Didn't recognise a player name"
        return speech_response(title,
                               speech,
                               reprompt_text=reprompt,
                               end=False)
Example #3
0
 def now_playing(self, intent, session, pid=None):
     details = self._server.get_track_details(player_id=pid)
     title = details.get('title', [None])[0]
     artists = people_from(details)
     if title:
         desc = _("Currently playing: \"{title}\"").format(title=title)
         if artists:
             desc += _(", by {artists}.").format(
                 artists=human_join(artists))
         heading = _("Now playing: \"{title}\"").format(title=title)
     else:
         desc = _("Nothing playing.")
         heading = None
     return self.smart_response(text=heading, speech=desc)
Example #4
0
 def test_nothing(self):
     assert human_join(None) == ''
Example #5
0
 def test_skips_falsey(self):
     assert human_join(['foo', None, 'bar', '']) == 'foo and bar'
Example #6
0
 def test_tuples_ok(self):
     assert human_join(('foo', 'bar'), 'or') == 'foo or bar'
Example #7
0
 def test_alternate_join_works(self):
     assert human_join(['foo', 'bar'], 'or') == 'foo or bar'
Example #8
0
 def test_basics(self):
     assert human_join([]) == ''
     assert human_join(['foo']) == 'foo'
     assert human_join(['foo', 'bar']) == 'foo and bar'
     assert human_join(LOTS[:-1]) == 'foo, bar and baz'
     assert human_join(LOTS) == 'foo, bar, baz and quux'