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,11 +1,12 @@
from jarvis.skills import Skill, SkillRegistering
from jarvis.skills.decorators import intent_file_handler
from jarvis.skills.entertainement.spotify import spotify
from jarvis.utils import config_utils
class SpotifySkill(Skill, metaclass=SkillRegistering):
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")
def handle_play_a_song(self, data):

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"
# 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"),
client_secret=config_utils.get_in_config("SPOTIFY_CLIENT_SECRET"),
redirect_uri='http://localhost:8888/callback/',
open_browser=False))
sp = None
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
@ -53,7 +58,7 @@ def query_song(song=None, artist=None):
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):