fixed devices list not loading now playing

added exception handling for token expiration in devices list
This commit is contained in:
Brandon4466
2023-01-11 13:26:54 -08:00
parent bbd9e7a0a3
commit 9162f7194d
2 changed files with 8 additions and 1 deletions

View File

@@ -1 +1 @@
{"access_token": "BQC2e3LU31cnEU0wNqqtrcWUrhsiMvTo7uO4Ypujo-RvZ0eonbYIyb5rwEdZj5GlN60dp3OFUq0xQcsliPiFRYUbGLCEc7de2l6IE4XKq-4WZFRw29RJ4TVHaKLERPI9cGcIgS3koLKHxSAomRGRkIAOOsfAU6Nu5CSTemp793_B22-PRWIC4XR7QMd7gQ", "token_type": "Bearer", "expires_in": 3600, "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1673465722, "refresh_token": "AQDs4x9WTbYtoqePbR9tvRWCcJHs1Hh3vrXpIHBtBdkJIDJ-Mu14B-vLEqOnowqw1HzZI5H5ytOFS2y9xBCcDyDU0uMA_D0MRPtujyCUYb9sdnD-D6WC2fN7bFiGeoo-YAo"} {"access_token": "BQDIrlY_zruLGRtHdCeqZQT_R4MJ02E89oYTyzW-aUBxGkwrcuIaYhFAUaNVEZQE-aa-EU3j08rxeI99jaFRvG9WQy5-tsWzD1BsU8NMKLhsFRNXE8jjElDTYHicblA8ihubAP6jekrqvxP3nFXE9ggrX2fvZk8qmOe6pB5LSfli0XSpnKX2-Jjlr1YG3A", "token_type": "Bearer", "expires_in": 3600, "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1673474531, "refresh_token": "AQDs4x9WTbYtoqePbR9tvRWCcJHs1Hh3vrXpIHBtBdkJIDJ-Mu14B-vLEqOnowqw1HzZI5H5ytOFS2y9xBCcDyDU0uMA_D0MRPtujyCUYb9sdnD-D6WC2fN7bFiGeoo-YAo"}

View File

@@ -145,6 +145,11 @@ def search(event):
def start_playback_on_device(): def start_playback_on_device():
device_selections = devices_list.curselection() device_selections = devices_list.curselection()
try:
list_of_devices = spotify.devices()
except (spotipy.exceptions.SpotifyException, requests.exceptions.HTTPError):
createToken()
pass
list_of_devices = spotify.devices() list_of_devices = spotify.devices()
device_id = list_of_devices["devices"][device_selections[0]]["id"] device_id = list_of_devices["devices"][device_selections[0]]["id"]
spotify.transfer_playback(device_id=device_id) spotify.transfer_playback(device_id=device_id)
@@ -162,6 +167,7 @@ def get_devices():
if current_playback != None: if current_playback != None:
unloadSearching_Devices() unloadSearching_Devices()
unloadDevices_list() unloadDevices_list()
loadNow_playing()
update_song_label() update_song_label()
else: else:
unloadSearching_Devices() unloadSearching_Devices()
@@ -246,6 +252,7 @@ loadLyrics_button = ttk.Button(lyrics_button, image=lyrics_img, command=loadLyri
now_playing_button = tk.Button(root, text="Now Playing", command=unloadLyrics_pressed) now_playing_button = tk.Button(root, text="Now Playing", command=unloadLyrics_pressed)
root.bind("<Return>", search) root.bind("<Return>", search)
play_button.bind("<<ButtonSelected>>", lambda e: frame_artist_song.focus())
# Function to update the song label with the current track's name # Function to update the song label with the current track's name
def update_song_label(): def update_song_label():