From b57347b60607de2f154934a51cec56dad952d678 Mon Sep 17 00:00:00 2001 From: David Todd Date: Tue, 24 Apr 2018 16:32:08 -0500 Subject: [PATCH] authorize via an internal server instead of copy-paste --- README.md | 1 + save_now_playing.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) mode change 100644 => 100755 save_now_playing.py diff --git a/README.md b/README.md index 6f45731..68262e4 100755 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ show_all_playlist.py - Unlike the name suggests, I did not see all my playlists. * Edit "set_env.sh" to configure your API ID, Secret, and redirect using the information from your previously created app * Configure your environment by running `set_env.sh` * Run `pip install -r requirements.txt` to install the required dependencies +* Optionally `git clone https://github.com/alopexc0de/spotipy.git` into venv/lib/python2.7/site-packages/ (replacing the pip-installed spotipy) * Run any of the scripts to use them ## License: MIT diff --git a/save_now_playing.py b/save_now_playing.py old mode 100644 new mode 100755 index 0aaf4bf..5bf2a78 --- a/save_now_playing.py +++ b/save_now_playing.py @@ -10,6 +10,7 @@ import sys import time + import spotipy import spotipy.util as util from spotipy.client import SpotifyException @@ -42,10 +43,15 @@ def authorize_api(username, scope=None): print "[%.2fs] Authorizing %s with this auth scope: %s" % \ (time.time()-start_time, username, scope) - # User Auth-Token - Achieved by running a webserver on localhost (might not be needed) as we just paste the URL here + # The access token appears to expire around 2000ish seconds of use. # Rerunning this and retrieving the callback url (with new token) will allow the script to continue - token = util.prompt_for_user_token(username, scope) + + # Use HttpSimpleServer based auth if available (using c0de's spotipy for example) + if hasattr(util, 'obtain_token_localhost'): + token = util.obtain_token_localhost(username, scope) + else: + token = util.prompt_for_user_token(username, scope) if token: # Authorize with the API