def on_play_artist(self, intent, session, pid=None): server = self._server try: artist = intent['slots']['Artist']['value'] print_d("Extracted artist slot: {}".format(artist)) except KeyError: print_d("Couldn't process artist from: {intent}", intent=intent) return speech_response(text=_("Couldn't process that artist. ")) else: matched_artists = server.search_for_artist(artist) print_d( "Found Matching artists on squeezebox server " "{matched_artists}", matched_artists=matched_artists) try: server.play_artist(matched_artists[0], player_id=pid) artist_name = sanitise_text(matched_artists[0]) text = _( "Playing albums by \"{artist_name}\" on squeezebox".format( artist_name=artist_name)) return self.smart_response(text=text, speech=text) except KeyError: return speech_response( text=_("Couldn't find the artist on squeezebox. ")) raise ValueError("Don't understand intent '{}'".format(intent))
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 = english_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 = english_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)
def on_play_playlist(self, intent, session, pid=None): server = self._server try: slot = intent['slots']['Playlist']['value'] print_d("Extracted playlist slot: {slot}", slot=slot) except KeyError: print_d("Couldn't process playlist from: {intent}", intent=intent) if not server.playlists: return speech_response(text=_("There are no playlists")) pl = random.choice(server.playlists) text = _("Didn't hear a playlist there. " "You could try the \"{name}\" playlist?").format(name=pl) return speech_response(text=text) else: if not server.playlists: return speech_response(text=_("No Squeezebox playlists found")) result = process.extractOne(slot, server.playlists) print_d("{guess} was the best guess for '{slot}' from {choices}", guess=str(result), slot=slot, choices=server.playlists) if result and int(result[1]) >= MinConfidences.PLAYLIST: pl = result[0] server.playlist_resume(pl, player_id=pid) name = sanitise_text(pl) return self.smart_response( speech=_("Playing \"{name}\" playlist").format(name=name), text=_("Playing \"{name}\" playlist").format(name=name)) pl = random.choice(server.playlists) template = _("Couldn't find a playlist matching \"{name}\"." "How about the \"{suggestion}\" playlist?") return speech_response(template.format(name=slot, suggestion=pl))
def on_play_playlist(self, intent, session, pid=None): server = self.get_server() try: slot = intent['slots']['Playlist']['value'] print_d("Extracted playlist slot: %s" % slot) except KeyError: print_d("Couldn't process playlist from: %s" % intent) if not server.playlists: return self.language_response('play_playlist_nh_none') return self.language_response('play_playlist_nh', [random.choice(server.playlists)]) else: if not server.playlists: return self.language_response('play_playlist_none') result = process.extractOne(slot, server.playlists) print_d("%s was the best guess for '%s' from %s" % (result, slot, server.playlists)) if result and int(result[1]) >= MinConfidences.PLAYLIST: pl = result[0] server.playlist_resume(pl, player_id=pid) name = sanitise_text(pl) return self.language_response('play_playlist', [name]) return self.language_response( 'play_playlist_nf', [slot, random.choice(server.playlists)])
def on_play_random_mix(self, intent, session, pid=None): server = self.get_server() try: slots = [ v.get('value') for k, v in intent['slots'].items() if k.endswith('Genre') ] print_d("Extracted genre slots: %s" % slots) except KeyError: print_d("Couldn't process genres from: %s" % intent) pass else: lms_genres = self._genres_from_slots(slots, server.genres) if lms_genres: server.play_genres(lms_genres, player_id=pid) gs = english_join(sanitise_text(g) for g in lms_genres) return self.language_response('play_random_mix', [gs]) else: genres_text = english_join(slots, "or") return self.language_response('play_random_mix_nf', [genres_text]) raise ValueError("Don't understand intent '%s'" % intent)
def test_playlists(self): assert sanitise_text("My bad-a$$ playlist") == 'My bad ass playlist'
def test_apostrophes(self): assert sanitise_text("10's pop") == '10s pop'
def test_punctuation(self): assert sanitise_text('Alt. Rock') == 'Alt Rock' assert sanitise_text('Alt.Rock') == 'Alt Rock' assert sanitise_text('Trip-hop') == 'Trip hop' assert sanitise_text('Pop/Funk') == 'Pop Funk'
def test_ands(self): assert sanitise_text('Drum & Bass') == 'Drum N Bass' assert sanitise_text('Drum&Bass') == 'Drum N Bass' assert sanitise_text('R&B') == 'R N B' assert sanitise_text('Jazz+Funk') == 'Jazz N Funk'
def test_nothing(self): assert sanitise_text("") == ""