-
-
Save lasconic/b8e2543ecf81bbf36c0a313cec2f6674 to your computer and use it in GitHub Desktop.
Get a cache file with authorization settings for spotify. Useful for the spotify kodi addon http://forum.kodi.tv/showthread.php?tid=265356&page=33
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
# $ virtualenv venv | |
# $ source venv/bin/activate | |
# $ pip install spotipy | |
# $ python spotify_auth.py YOURUSERNAME | |
# Follow the instruction, no problem with the 404 | |
# It will create a file .cache-YOURUSERNAME, copy it to .kodi/userdata/addon_data/plugin.audio.spotify as YOURUSERNAME.cache | |
# Run the spotify addon. If you have an error, make sure your Kodi time is right. | |
import sys | |
import spotipy | |
import spotipy.util as util | |
scope = "playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private user-follow-modify user-follow-read user-library-read user-library-modify user-read-private user-read-email user-read-birthdate user-top-read" | |
client_id = '4940f5cc79b149af9f71d5ef9319eff0' | |
client_secret = '779f4d60bd3b42e29984adf423f19688' | |
port = 52308 | |
redirect_uri = 'http://localhost:%s/callback' % port | |
if len(sys.argv) > 1: | |
username = sys.argv[1] | |
else: | |
print "Usage: %s username" % (sys.argv[0],) | |
sys.exit() | |
token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) | |
if token: | |
sp = spotipy.Spotify(auth=token) | |
results = sp.current_user_saved_tracks() | |
for item in results['items']: | |
track = item['track'] | |
print track['name'] + ' - ' + track['artists'][0]['name'] | |
else: | |
print "Can't get token for", username |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script! Unfortunately it's not giving me a valid token. I get the response as stated below. This is the same exception as I find in the Kodi log file after providing my credentials in the latest version of the Kodi Spotify plugin (1.0.25).