diff --git a/lib/api.py b/lib/api.py index 962ca25..7ba1893 100644 --- a/lib/api.py +++ b/lib/api.py @@ -1,4 +1,6 @@ import requests +import spotipy +from spotipy import SpotifyOAuth from lib.track import Track from lib.user_config import ConfigFile, AppSettings @@ -27,6 +29,11 @@ def __str__(self): return f"?api_key={self.apiKey}&method={self.method}&user={self.user}&format={self.format}" +class SpotifyParams(AppSettings): + client_id: str + client_secret: str + + class LastFM: """Class to interact with Last.fm's API.""" params: Params @@ -66,3 +73,20 @@ def username(self): return self.params.user @property def totalScrobbles(self): return self.totalScrobbles if self.totalScrobbles is not None else \ self._callApi()["recenttracks"]["@attr"]["total"] + + +class Spotify: + """Class to interact with Spotify's API.""" + sp: spotipy.Spotify + redirect_uri: str = "https://example.com" # maybe user config? + scope = "user-read-currently-playing" + + def __init__(self, params: SpotifyParams): + self.sp = spotipy.Spotify( + auth_manager=SpotifyOAuth( + client_id=params.client_id, + client_secret=params.client_secret, + redirect_uri=self.redirect_uri, + scope=self.scope, + ) + )