From 95b5f39381a328085f1803c6fc6f25de63df60d9 Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Sat, 31 Jul 2021 13:25:37 +0200 Subject: [PATCH] Improved spotify resume/pause intent --- .../skills/entertainement/spotify/__init__.py | 18 +++++++++++++++--- .../skills/entertainement/spotify/spotify.py | 4 ++++ .../spotify/vocab/fr-fr/pause_music.intent | 9 +-------- .../spotify/vocab/fr-fr/resume_music.intent | 1 + 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 jarvis/skills/entertainement/spotify/vocab/fr-fr/resume_music.intent diff --git a/jarvis/skills/entertainement/spotify/__init__.py b/jarvis/skills/entertainement/spotify/__init__.py index a948980..46ce159 100644 --- a/jarvis/skills/entertainement/spotify/__init__.py +++ b/jarvis/skills/entertainement/spotify/__init__.py @@ -22,14 +22,26 @@ class SpotifySkill(Skill, metaclass=SkillRegistering): spotify.get_spotify().add_to_queue(uri=song_lists_matching[0]['uri']) spotify.get_spotify().next_track() - # spotify.get_spotify().start_playback(context_uri=song_lists_matching[0]['uri']) else: print("Nothing found for :" + str(data)) @intent_file_handler("pause_music.intent", "PauseSpotifyIntent") def pause_music(self, data): - spotify.get_spotify().pause_playback() - print("[INFO INTENT] - Paused music for Spotify") + if spotify.is_music_playing(): + spotify.get_spotify().pause_playback() + print("[INFO INTENT] - Paused music for Spotify") + else: + # TODO: speak : nothing is playing on spotify + pass + + @intent_file_handler("resume_music.intent", "ResumeSpotifyIntent") + def resume_music(self, data): + if not spotify.is_music_playing(): + spotify.get_spotify().start_playback() + print("[INFO INTENT] - Resumed music for Spotify") + else: + # TODO: speak : already playing song on spotify + pass @intent_file_handler("current_song.intent", "CurrentSongSpotifyIntent") def current_song(self, data): diff --git a/jarvis/skills/entertainement/spotify/spotify.py b/jarvis/skills/entertainement/spotify/spotify.py index 20e6ba2..292967e 100644 --- a/jarvis/skills/entertainement/spotify/spotify.py +++ b/jarvis/skills/entertainement/spotify/spotify.py @@ -58,6 +58,10 @@ def query_song(song=None, artist=None): return data +def is_music_playing(): + return sp.current_user_playing_track()['is_playing'] + + def best_confidence(title, query): """Find best match for a title against a query. Some titles include ( Remastered 2016 ) and similar info. This method diff --git a/jarvis/skills/entertainement/spotify/vocab/fr-fr/pause_music.intent b/jarvis/skills/entertainement/spotify/vocab/fr-fr/pause_music.intent index 31208a9..18cfddd 100644 --- a/jarvis/skills/entertainement/spotify/vocab/fr-fr/pause_music.intent +++ b/jarvis/skills/entertainement/spotify/vocab/fr-fr/pause_music.intent @@ -1,8 +1 @@ -mets la musique sur pause -arrĂȘte la musique -coupe la musique -mets sur pause -mets spotify en pause -mets spotify sur pause -pause -mets la musique en pause \ No newline at end of file +(mets|arrĂȘte|coupe) (moi voir|) (le|la|) (musique|son|spotify) ((sur|en) pause|) diff --git a/jarvis/skills/entertainement/spotify/vocab/fr-fr/resume_music.intent b/jarvis/skills/entertainement/spotify/vocab/fr-fr/resume_music.intent new file mode 100644 index 0000000..8cf2020 --- /dev/null +++ b/jarvis/skills/entertainement/spotify/vocab/fr-fr/resume_music.intent @@ -0,0 +1 @@ +(remets|relance|mets) (moi voir|) (la|le) (musique|son) \ No newline at end of file