fixed calling get_color many times unnecessarily
refactored calling get_devices to stop unneeded API calls
This commit is contained in:
@@ -116,12 +116,12 @@ def likeSong():
|
||||
play_button.config(image=play_img)
|
||||
pause_button.config(image=pause_img)
|
||||
|
||||
def colorUI(track_id, album_art_img_open):
|
||||
def colorUI(track_id, dominant_color):
|
||||
if spotify.current_user_saved_tracks_contains(tracks=[track_id])[0] is True:
|
||||
liked_song = True
|
||||
else:
|
||||
liked_song = False
|
||||
if math.sqrt(0.299 * (get_colors(album_art_img_open)[0] ** 2) + 0.587 * (get_colors(album_art_img_open)[1] ** 2) + 0.114 * (get_colors(album_art_img_open)[2] ** 2)) > 170:
|
||||
if math.sqrt(0.299 * (dominant_color[0] ** 2) + 0.587 * (dominant_color[1] ** 2) + 0.114 * (dominant_color[2] ** 2)) > 170:
|
||||
is_bright = True
|
||||
if liked_song is True:
|
||||
play_button.config(image=play_heart_img_black)
|
||||
@@ -171,25 +171,25 @@ def get_devices():
|
||||
# elif count >= 69:
|
||||
# wait_time = 3600000
|
||||
list_of_devices = spotify.devices()
|
||||
unloadNow_playing()
|
||||
if list_of_devices == "{'devices': []}":
|
||||
|
||||
# if list_of_devices == "{'devices': []}":
|
||||
# unloadDevices_list()
|
||||
# loadSearching_Devices()
|
||||
# root.after(1000, get_devices)
|
||||
# else:
|
||||
if spotify.current_playback() != None:
|
||||
# unloadSearching_Devices()
|
||||
unloadDevices_list()
|
||||
loadSearching_Devices()
|
||||
root.after(1000, get_devices)
|
||||
loadNow_playing()
|
||||
root.after(200, update_song_label)
|
||||
else:
|
||||
if spotify.current_playback() != None:
|
||||
unloadSearching_Devices()
|
||||
unloadDevices_list()
|
||||
loadNow_playing()
|
||||
return
|
||||
else:
|
||||
unloadSearching_Devices()
|
||||
loadDevices_list()
|
||||
devices_list.delete(0, ttk.END)
|
||||
list_of_devices = spotify.devices()
|
||||
for num_of_device, garbage in enumerate(list_of_devices["devices"]):
|
||||
devices_list.insert(num_of_device, list_of_devices["devices"][num_of_device]["name"])
|
||||
root.after(6500, get_devices)
|
||||
# unloadSearching_Devices()
|
||||
# loadDevices_list()
|
||||
devices_list.delete(0, ttk.END)
|
||||
# list_of_devices = spotify.devices()
|
||||
for num_of_device, garbage in enumerate(list_of_devices["devices"]):
|
||||
devices_list.insert(num_of_device, list_of_devices["devices"][num_of_device]["name"])
|
||||
root.after(8500, get_devices)
|
||||
|
||||
# def wakeup():
|
||||
# global count
|
||||
@@ -378,8 +378,10 @@ def update_song_label():
|
||||
current_playback = spotify.current_playback()
|
||||
# If there is no current playback, set the text of the song label to "No playback"
|
||||
if current_playback is None:
|
||||
get_devices()
|
||||
root.after(100, update_song_label)
|
||||
unloadNow_playing()
|
||||
loadDevices_list()
|
||||
|
||||
root.after(200, get_devices)
|
||||
# Update the song label every 1 second
|
||||
else:
|
||||
if current_playback.get("item"):
|
||||
@@ -415,7 +417,8 @@ def update_song_label():
|
||||
# bg_color_img = album_art_img_open.resize((1,1), resample=0)
|
||||
# bg_color_img_pixel = bg_color_img.getpixel((0,0))
|
||||
# bg_color_rgb = get_colors(album_art_img_open)
|
||||
bg_color = "#" + '%02x%02x%02x' % (get_colors(album_art_img_open))
|
||||
dominant_color = get_colors(album_art_img_open)
|
||||
bg_color = "#" + '%02x%02x%02x' % (dominant_color)
|
||||
# print(bg_color)
|
||||
album_art_img_with_corners = addCorners(album_art_img_open, 15)
|
||||
# addDropShadow(album_art_img_with_corners)
|
||||
@@ -432,7 +435,7 @@ def update_song_label():
|
||||
previous_button.config(background=bg_color)
|
||||
lyrics_label_frame.config(background=bg_color)
|
||||
lyrics_label.config(background=bg_color)
|
||||
isBright = colorUI(track_id, album_art_img_open)
|
||||
isBright = colorUI(track_id, dominant_color)
|
||||
# print(oauth.get_cached_token()["access_token"])
|
||||
# print(current_playback["item"]["id"])
|
||||
# canvas_url = canvas.get_canvas_for_track(access_token=oauth.get_cached_token()["access_token"], track_id=current_playback["item"]["id"])
|
||||
|
||||
Reference in New Issue
Block a user