This commit is contained in:
Alfie King 2024-09-01 18:27:56 +01:00
parent 88271a4b56
commit 14ee7ef987

View File

@ -37,16 +37,6 @@ def get_auth():
})
redirect = requests.get(f"https://accounts.spotify.com/authorize?{query}")
print(redirect.url)
code = input('Enter code: ')
data = requests.post('https://accounts.spotify.com/api/token', data={
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': os.getenv('REDIRECT_URI'),
}, headers={
'content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + base64.b64encode(f"{os.getenv('CLIENT_ID')}:{os.getenv('CLIENT_SECRET')}".encode()).decode()
}).json()
save_cache(data)
return True
def update_token():
@ -64,6 +54,20 @@ def update_token():
# Routes
@app.route('/api/auth', methods=['GET'])
def auth():
code = request.args.get('code')
data = requests.post('https://accounts.spotify.com/api/token', data={
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': os.getenv('REDIRECT_URI'),
}, headers={
'content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + base64.b64encode(f"{os.getenv('CLIENT_ID')}:{os.getenv('CLIENT_SECRET')}".encode()).decode()
}).json()
save_cache(data)
return "Authenticated"
@app.route('/api/nowplaying', methods=['GET'])
def nowplaying():
cache = get_cache()