fixed calling get_color many times unnecessarily
refactored calling get_devices to stop unneeded API calls
This commit is contained in:
2
.cache
2
.cache
@@ -1 +1 @@
|
||||
{"access_token": "BQA33plRMZf_O-Cr91vOocSFUB4RMzjSPuXvxoFjVsVYuFPahghyGXQxYtQqMgkHh_Pga_Pg5FIwGrInUDQ-Npz9Dd_oFOWjs0Grg34hKxQTUJG21SNKtybjgLaOqDP08PUWZ2ubtReWY4yS2dpSYwixrAsvu8QCPH9LmkYq4qO20vQzevFNGh0TLmDTM31zSPqa0tWOTqnO35SaQr4u", "token_type": "Bearer", "expires_in": 3600, "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1679903241, "refresh_token": "AQC5BsmRqj_PhCL7Xj32C6Pz4UeFF09ZufzWv0NU1lGwZCUGaWAQP8F4twJf3Rx5EfKyAg4DIEnHZIFd6e5L4bPQXhPUny2t7A1AA5hCwfFI_LjXWWPij8oKX_0YDr6CXK0"}
|
||||
{"access_token": "BQBXuUO_bXWOT8jstBrtDrGGP3P_4y_93_E0Ij6FAogp6c8_GFn4J7zUWA7dYq-q4xanGhVgcQCX4PO6GOQIx9W4-9J-1ldb2V_iPot0ibSg-8EmMTGLw4HNQf9-Yn-cbDvzHnxZWMIAp2_VcoYrF7K4BLOIFTi4JPtVM7wpL5jB-IRFRI2sYsLjafTb_gLf29XzTsPVsPloC_ljet1n", "token_type": "Bearer", "expires_in": 3600, "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1679993964, "refresh_token": "AQC5BsmRqj_PhCL7Xj32C6Pz4UeFF09ZufzWv0NU1lGwZCUGaWAQP8F4twJf3Rx5EfKyAg4DIEnHZIFd6e5L4bPQXhPUny2t7A1AA5hCwfFI_LjXWWPij8oKX_0YDr6CXK0"}
|
||||
@@ -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