mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Refactored refresh token (#408)
* Outputs error details when track download fails from list file * Refactored Spotipy token refreshing * Reverted to old refreshing method Kept refresh_token() in spotify_tools.py
This commit is contained in:
committed by
Ritiek Malhotra
parent
680525ea3d
commit
94dc27a77b
@@ -97,8 +97,7 @@ def download_list(tracks_file, skip_file=None, write_successful_file=None):
|
||||
except spotipy.client.SpotifyException:
|
||||
# refresh token when it expires
|
||||
log.debug("Token expired, generating new one and authorizing")
|
||||
new_token = spotify_tools.generate_token()
|
||||
spotify_tools.spotify = spotipy.Spotify(auth=new_token)
|
||||
spotify_tools.refresh_token()
|
||||
download_single(raw_song, number=number)
|
||||
# detect network problems
|
||||
except (urllib.request.URLError, TypeError, IOError) as e:
|
||||
|
||||
@@ -10,6 +10,7 @@ from titlecase import titlecase
|
||||
import pprint
|
||||
import sys
|
||||
|
||||
|
||||
def generate_token():
|
||||
""" Generate the token. Please respect these credentials :) """
|
||||
credentials = oauth2.SpotifyClientCredentials(
|
||||
@@ -20,6 +21,12 @@ def generate_token():
|
||||
return token
|
||||
|
||||
|
||||
def refresh_token():
|
||||
""" Refresh expired token"""
|
||||
global spotify
|
||||
new_token = generate_token()
|
||||
spotify = spotipy.Spotify(auth=new_token)
|
||||
|
||||
# token is mandatory when using Spotify's API
|
||||
# https://developer.spotify.com/news-stories/2017/01/27/removing-unauthenticated-calls-to-the-web-api/
|
||||
token = generate_token()
|
||||
|
||||
Reference in New Issue
Block a user