Parent: [be9be8] (diff)

Download this file

spotiauthinit.py    42 lines (35 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python3
import spotipy
import sys
import json
import sys
import spotipy
import spotipy.util as util
from spotipy.oauth2 import SpotifyClientCredentials
import upmspotid
if len(sys.argv) > 1:
username = sys.argv[1]
else:
print("Whoops, need your username!")
print("usage: spotipyauth [username]")
sys.exit(1)
cachepath = "/tmp/spotipy-" + username + "-token"
token = util.prompt_for_user_token(
username, scope = upmspotid.SCOPE, client_id = upmspotid.CLIENT_ID,
client_secret = upmspotid.CLIENT_SECRET,
redirect_uri = upmspotid.REDIRECT_URI, cache_path = cachepath)
if token:
# Check
sp = spotipy.Spotify(auth=token)
data = sp.current_user_recently_played()
if not data:
print("Authentication failed");
sys.exit(1)
else:
print("Authentication ok. Please move %s to the file named " \
"/var/cache/upmpdcli/spotify/token" % cachepath)
# print("%s"% json.dumps(data,indent=True))
sys.exit(0)
else:
print("Can't get token for %s"% username)
sys.exit(1)