Adapted spotify skill for using new required config fields system
This commit is contained in:
parent
66b2c411aa
commit
14da3bc8f2
@ -1,11 +1,12 @@
|
|||||||
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):
|
||||||
|
@ -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):
|
||||||
|
Reference in New Issue
Block a user