2021-07-29 12:35:07 +02:00
|
|
|
from jarvis.skills import Skill, SkillRegistering
|
2021-07-29 14:57:55 +02:00
|
|
|
from jarvis.skills.decorators import intent_file_handler
|
2021-07-29 23:04:31 +02:00
|
|
|
from jarvis.skills.entertainement.spotify import spotify
|
2021-07-29 12:35:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
class SpotifySkill(Skill, metaclass=SkillRegistering):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__("SpotifySkill")
|
|
|
|
|
2021-07-29 20:16:22 +02:00
|
|
|
@intent_file_handler("play_a_song.intent", "PlaySongWithSpotifyIntent")
|
2021-07-29 14:57:55 +02:00
|
|
|
def handle_play_a_song(self, data):
|
2021-07-30 14:10:35 +02:00
|
|
|
print(data)
|
|
|
|
|
2021-07-30 19:58:58 +02:00
|
|
|
song_lists_matching = spotify.query_song(data['song'] if 'song' in data else None,
|
|
|
|
data['artist'] if 'artist' in data else None)
|
2021-07-30 14:10:35 +02:00
|
|
|
|
|
|
|
if song_lists_matching is not None and len(song_lists_matching) >= 1:
|
|
|
|
print(
|
|
|
|
"[INFO INTENT] - Now playing : " + song_lists_matching[0]['uri'] + " / " + song_lists_matching[0][
|
|
|
|
'name'] + " / " +
|
|
|
|
song_lists_matching[0]['artists'][0]['name'])
|
|
|
|
|
|
|
|
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'])
|
2021-07-30 19:58:58 +02:00
|
|
|
else:
|
|
|
|
print("Nothing found for :" + str(data))
|
2021-07-29 23:29:42 +02:00
|
|
|
|
|
|
|
@intent_file_handler("pause_music.intent", "PauseSpotifyIntent")
|
|
|
|
def pause_music(self, data):
|
|
|
|
spotify.get_spotify().pause_playback()
|
|
|
|
print("[INFO INTENT] - Paused music for Spotify")
|
2021-07-30 10:14:18 +02:00
|
|
|
|
|
|
|
@intent_file_handler("current_song.intent", "CurrentSongSpotifyIntent")
|
|
|
|
def current_song(self, data):
|
|
|
|
current_playback = spotify.get_spotify().current_playback()
|
|
|
|
if current_playback['is_playing']:
|
|
|
|
song_name = current_playback['item']['name']
|
|
|
|
artist = current_playback['item']['artists'][0]['name']
|
|
|
|
|
2021-07-30 12:54:25 +02:00
|
|
|
print("[INFO INTENT] - Current playback : " + song_name + " from " + artist + " on Spotify")
|
|
|
|
else:
|
|
|
|
print("Nothing is playing")
|
2021-07-30 12:28:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def create_skill():
|
|
|
|
return SpotifySkill()
|