Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
749be97
commit 7664218
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.cache | ||
secrets.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
import configparser | ||
|
||
import cachetools | ||
import spotipy | ||
import spotipy.oauth2 | ||
|
||
|
||
CACHE_PATH = '.cache' | ||
REDIRECT_URI = 'https://localhost:5000/callback' | ||
SCOPES = ' '.join([ | ||
'user-library-modify', | ||
'user-library-read', | ||
]) | ||
|
||
|
||
@cachetools.cached(cachetools.Cache(1)) | ||
def spotify_client() -> spotipy.Spotify: | ||
config = configparser.ConfigParser() | ||
config.read('secrets.ini') | ||
client_id = config['client']['id'] | ||
client_secret = config['client']['secret'] | ||
|
||
auth_manager = spotipy.oauth2.SpotifyOAuth( | ||
client_id=client_id, | ||
client_secret=client_secret, | ||
redirect_uri=REDIRECT_URI, | ||
scope=SCOPES, | ||
cache_path=CACHE_PATH, | ||
# TODO (ayu): use open_browser=False and go browserless when spotipy is next updated | ||
) | ||
|
||
return spotipy.Spotify(auth_manager=auth_manager) |