diff --git a/jarvis/skills/entertainement/spotify/__init__.py b/jarvis/skills/entertainement/spotify/__init__.py index d49a572..cab258b 100644 --- a/jarvis/skills/entertainement/spotify/__init__.py +++ b/jarvis/skills/entertainement/spotify/__init__.py @@ -11,22 +11,22 @@ class SpotifySkill(Skill, metaclass=SkillRegistering): def handle_play_a_song(self, data): print(data) - song_lists_matching = spotify.query_song(data['song'] if 'song' in data else None, + matching_song = spotify.query_song(data['song'] if 'song' in data else None, data['artist'] if 'artist' in data else None) - if song_lists_matching is not None and len(song_lists_matching) >= 1: + if matching_song is not None and len(matching_song) >= 1: # pause the music before speaking dialog if spotify.is_music_playing(): spotify.get_spotify().pause_playback() if 'artist' in data and 'song' not in data: - self.speak_dialog("play_from_artist", {'artist': song_lists_matching[0]['artists'][0]['name']}) + self.speak_dialog("play_from_artist", {'artist': matching_song['artists'][0]['name']}) else: - self.speak_dialog("play_song_from_artist", {'song': song_lists_matching[0][ - 'name'], 'artist': song_lists_matching[0]['artists'][0]['name']}) + self.speak_dialog("play_song_from_artist", {'song': matching_song[ + 'name'], 'artist': matching_song['artists'][0]['name']}) - spotify.get_spotify().add_to_queue(uri=song_lists_matching[0]['uri']) + spotify.get_spotify().add_to_queue(uri=matching_song['uri']) spotify.get_spotify().next_track() else: self.speak_dialog("nothing_found") diff --git a/jarvis/skills/entertainement/spotify/spotify.py b/jarvis/skills/entertainement/spotify/spotify.py index 3c8a233..f24b607 100644 --- a/jarvis/skills/entertainement/spotify/spotify.py +++ b/jarvis/skills/entertainement/spotify/spotify.py @@ -42,19 +42,14 @@ def query_song(song=None, artist=None): tracks = [(best_confidence(d['name'], 'None'), d) for d in data] tracks.sort(key=lambda x: x[0]) - tracks.reverse() # Place best matches first # Find pretty similar tracks to the best match - tracks = [t for t in tracks if t[0] > tracks[0][0] - 0.1] - + # tracks = [t for t in tracks if t[0] > tracks[0][0] - 0.1] # Sort remaining tracks by popularity - tracks.sort(key=lambda x: x[1]['popularity']) - # print([(t[0], t[1]['name'], t[1]['artists'][0]['name']) for t in tracks]) # DEBUG - data = [tracks[-1][1]] + # tracks.sort(key=lambda x: x[1]['popularity']) - # return tracks[-1][0], {'data': data, 'name': None, 'type': 'track'} - return data + return random.choice(tracks)[1] def is_music_playing(): diff --git a/jarvis/skills/entertainement/spotify/vocab/fr-fr/play_a_song.intent b/jarvis/skills/entertainement/spotify/vocab/fr-fr/play_a_song.intent index 59c3e69..71f2541 100644 --- a/jarvis/skills/entertainement/spotify/vocab/fr-fr/play_a_song.intent +++ b/jarvis/skills/entertainement/spotify/vocab/fr-fr/play_a_song.intent @@ -23,4 +23,5 @@ Tu peux jouer le morceau {song} Tu peux jouer le morceau {song} (de la chanteuse|du chanteur|de) {artist} Joue moi voir {song} (sur spotify|) Joue moi voir {song} de {artist} (sur spotify|) -(Joue|Mets) (moi|) (un peu de|du) {artist} (sur spotify|) \ No newline at end of file +(Joue|Mets) (moi|) (un peu de|du) {artist} (sur spotify|) +(Joue|Mets) (moi|) un peu d'{artist} (sur spotify|) \ No newline at end of file