Adapted spotify skill for using new required config fields system

This commit is contained in:
Mathieu 2021-09-13 22:10:34 +02:00
parent 66b2c411aa
commit 14da3bc8f2
2 changed files with 14 additions and 8 deletions

View File

@ -1,18 +1,19 @@
from jarvis.skills import Skill, SkillRegistering from jarvis.skills import Skill, SkillRegistering
from jarvis.skills.decorators import intent_file_handler from jarvis.skills.decorators import intent_file_handler
from jarvis.skills.entertainement.spotify import spotify from jarvis.skills.entertainement.spotify import spotify
from jarvis.utils import config_utils
class SpotifySkill(Skill, metaclass=SkillRegistering): class SpotifySkill(Skill, metaclass=SkillRegistering):
def __init__(self, data=dict): def __init__(self, data=dict):
super().__init__("SpotifySkill", data) super().__init__("SpotifySkill", data, required_config=['SPOTIFY_CLIENT_ID', 'SPOTIFY_CLIENT_SECRET'])
@intent_file_handler("play_a_song.intent", "PlaySongWithSpotifyIntent") @intent_file_handler("play_a_song.intent", "PlaySongWithSpotifyIntent")
def handle_play_a_song(self, data): def handle_play_a_song(self, data):
print(data) print(data)
matching_song = 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) data['artist'] if 'artist' in data else None)
if matching_song is not None and len(matching_song) >= 1: if matching_song is not None and len(matching_song) >= 1:

View File

@ -12,14 +12,19 @@ from jarvis.utils import config_utils
scope = "user-read-playback-state, user-modify-playback-state, user-read-currently-playing" scope = "user-read-playback-state, user-modify-playback-state, user-read-currently-playing"
# TODO: Investigate the open_browser and automatic auth renewing without user interaction # TODO: Investigate the open_browser and automatic auth renewing without user interaction
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope,
client_id=config_utils.get_in_config("SPOTIFY_CLIENT_ID"), sp = None
client_secret=config_utils.get_in_config("SPOTIFY_CLIENT_SECRET"),
redirect_uri='http://localhost:8888/callback/',
open_browser=False))
def get_spotify(): def get_spotify():
global sp
if sp is None:
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope,
client_id=config_utils.get_in_secret("SPOTIFY_CLIENT_ID"),
client_secret=config_utils.get_in_secret(
"SPOTIFY_CLIENT_SECRET"),
redirect_uri='http://localhost:8888/callback/',
open_browser=False))
return sp return sp
@ -53,7 +58,7 @@ def query_song(song=None, artist=None):
def is_music_playing(): def is_music_playing():
return sp.current_user_playing_track()['is_playing'] return get_spotify().current_user_playing_track()['is_playing']
def best_confidence(title, query): def best_confidence(title, query):