mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-07-30 14:00:18 +00:00
Moved util module into main package
This commit is contained in:
@@ -6,7 +6,7 @@ import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.oauth2 as oauth2
|
||||
import util
|
||||
import spotipy.util as util
|
||||
|
||||
scope = 'user-library-modify'
|
||||
|
||||
|
@@ -6,7 +6,7 @@ import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.oauth2 as oauth2
|
||||
import util
|
||||
import spotipy.util as util
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
username = sys.argv[1]
|
||||
|
@@ -7,8 +7,8 @@ import subprocess
|
||||
|
||||
import spotipy
|
||||
|
||||
import util
|
||||
import spotipy.oauth2 as oauth2
|
||||
import spotipy.util as util
|
||||
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
|
@@ -5,7 +5,7 @@ import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.oauth2 as oauth2
|
||||
import util
|
||||
import spotipy.util as util
|
||||
|
||||
scope = 'user-library-modify'
|
||||
|
||||
|
@@ -6,7 +6,7 @@ import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.oauth2 as oauth2
|
||||
import util
|
||||
import spotipy.util as util
|
||||
|
||||
scope = 'user-library-read'
|
||||
|
||||
|
@@ -7,9 +7,8 @@ import subprocess
|
||||
|
||||
import spotipy
|
||||
|
||||
import util
|
||||
import spotipy.oauth2 as oauth2
|
||||
|
||||
import spotipy.util as util
|
||||
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
|
@@ -6,9 +6,8 @@ import os
|
||||
import subprocess
|
||||
|
||||
import spotipy
|
||||
|
||||
import util
|
||||
import spotipy.oauth2 as oauth2
|
||||
import spotipy.util as util
|
||||
|
||||
|
||||
def show_tracks(results):
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
import sys
|
||||
import spotipy
|
||||
import util
|
||||
import spotipy.util as util
|
||||
import spotipy.oauth2 as oauth2
|
||||
|
||||
|
||||
|
@@ -1,56 +0,0 @@
|
||||
|
||||
# shows a user's playlists (need to be authenticated via oauth)
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import spotipy.oauth2 as oauth2
|
||||
|
||||
def prompt_for_user_token(username, scope=None):
|
||||
''' prompts the user to login if necessary and returns
|
||||
the user token suitable for use with the spotipy.Spotify
|
||||
constructor
|
||||
'''
|
||||
|
||||
client_id = os.getenv('CLIENT_ID', 'YOUR_CLIENT_ID')
|
||||
client_secret = os.getenv('CLIENT_SECRET', 'YOUR_CLIENT_SECRET')
|
||||
redirect_uri = os.getenv('REDIRECT_URI', 'YOUR_REDIRECT_URI')
|
||||
|
||||
|
||||
if client_id == 'YOUR_CLIENT_ID':
|
||||
print '''
|
||||
You need to set your Spotify API credentials. You can do this by
|
||||
setting environment variables like so:
|
||||
|
||||
export CLIENT_ID='your-spotify-client-id'
|
||||
export CLIENT_SECRET='your-spotify-client-secret'
|
||||
export REDIRECT_URI='your-app-redirect-url'
|
||||
|
||||
Get your credentials at https://developer.spotify.com/my-applications
|
||||
'''
|
||||
sys.exit(1)
|
||||
|
||||
sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri,
|
||||
scope=scope, cache_path=username)
|
||||
|
||||
# try to get a valid token for this user, from the cache,
|
||||
# if not in the cache, the create a new (this will send
|
||||
# the user to a web page where they can authorize this app)
|
||||
|
||||
token_info = sp_oauth.get_cached_token()
|
||||
|
||||
if not token_info:
|
||||
auth_url = sp_oauth.get_authorize_url()
|
||||
try:
|
||||
subprocess.call(["open", auth_url])
|
||||
print "Opening %s in your browser" % auth_url
|
||||
except:
|
||||
print "Please navigate here: %s" % auth_url
|
||||
response = raw_input("Enter the URL you were redirected to: ")
|
||||
code = sp_oauth.parse_response_code(response)
|
||||
token_info = sp_oauth.get_access_token(code)
|
||||
# Auth'ed API request
|
||||
if token_info:
|
||||
return token_info['access_token']
|
||||
else:
|
||||
return None
|
Reference in New Issue
Block a user