master
Lukas Schulz 2020-12-20 14:31:20 +01:00
parent 420853bec3
commit d2a0c8e926
1 changed files with 22 additions and 20 deletions

42
main.py
View File

@ -53,6 +53,27 @@ font = ImageFont.load_default()
print('before get_track()')
def get_access_token():
global token
sp_oauth = spotipy.SpotifyOAuth(
client_id,
client_secret,
redirect_uri,
scope=scope,
#cache_path=cache_path,
username=username,
open_browser=False
)
token_info = sp_oauth.get_cached_token()
if not token_info:
code = sp_oauth.get_auth_response()
token = sp_oauth.get_access_token(code, as_dict=False)
else:
if sp_oauth.is_token_expired(token_info):
token_info = refresh_access_token(token_info)
token = token_info["access_token"]
def get_track():
print('getting current song info')
sp = spotipy.Spotify(auth=token)
@ -116,7 +137,7 @@ def drawCanvas():
if not (last_song == song_name):
print('text')
#last_cover_art = cover_art
last_cover_art = cover_art
if(was_playing and not is_playing):
is_scrolling_art = True
scroll = threading.Thread(target=scrollDownSongInfo)
@ -206,26 +227,7 @@ def scrolling_text(text,offset_x=0,offset_y=0):
def main():
get_access_token()
def get_access_token():
global token
sp_oauth = spotipy.SpotifyOAuth(
client_id,
client_secret,
redirect_uri,
scope=scope,
#cache_path=cache_path,
username=username,
open_browser=False
)
token_info = sp_oauth.get_cached_token()
if not token_info:
code = sp_oauth.get_auth_response()
token = sp_oauth.get_access_token(code, as_dict=False)
else:
if sp_oauth.is_token_expired(token_info):
token_info = refresh_access_token(token_info)
token = token_info["access_token"]
if __name__ == "__main__":