Skip to content

Commit

Permalink
Add spotify client
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yu committed Sep 15, 2020
1 parent 749be97 commit 7664218
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 2 deletions.
1 change: 1 addition & 0 deletions spotify/.gitignore
@@ -1 +1,2 @@
.cache
secrets.ini
3 changes: 3 additions & 0 deletions spotify/Pipfile
Expand Up @@ -4,9 +4,12 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"
pycodestyle = "*"

[packages]
spotipy = "*"
cachetools = "*"

[requires]
python_version = "3.8"
115 changes: 113 additions & 2 deletions spotify/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions spotify/client.py
@@ -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)

0 comments on commit 7664218

Please sign in to comment.