updated background dominant color calculation

reworked updater to work as handler, will restart if exception
This commit is contained in:
Brandon4466
2023-03-27 00:13:26 -07:00
parent ef4d0fee66
commit cf6f02acd1
7 changed files with 58 additions and 17 deletions

2
.cache
View File

@@ -1 +1 @@
{"access_token": "BQAwNuSTPsxO_L1DyV-7sSX_5ymdMsBTCQl1K7JBu0S2dTa6sHzUbgwKECv3zMdlKwiopbW7a7tz1yVllgKqGAMZxgFeitoAenswfmYaT2buecmrYiA28bWh14PW26Ypdg_bJWz3x40bT9QP4dF-8vu23d_-FOVUTT0EcO7t6zI95GtB2Awp2z98VAQ_MdUFWohptYtD5HXg7qK2nnvi", "token_type": "Bearer", "expires_in": 3600, "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1679465977, "refresh_token": "AQC5BsmRqj_PhCL7Xj32C6Pz4UeFF09ZufzWv0NU1lGwZCUGaWAQP8F4twJf3Rx5EfKyAg4DIEnHZIFd6e5L4bPQXhPUny2t7A1AA5hCwfFI_LjXWWPij8oKX_0YDr6CXK0"}
{"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"}

View File

@@ -1,7 +1,7 @@
librespot
Pillow
PyAutoGUI
requests
spotipy
sv_ttk
syncedlyrics
numpy

BIN
spotifycontroller.prof Normal file

Binary file not shown.

View File

@@ -12,6 +12,7 @@ import math
from time import sleep
import threading
import queue
import numpy
# SpotifyGUI - Made by Brandon Brunson
@@ -251,24 +252,58 @@ def addCorners(im, rad):
# return back
def get_colors(image_file, numcolors=1, resize=150):
# def get_colors(image_file, resize=150):
# # Resize image to speed up processing
# image_file.thumbnail((resize, resize))
# max_count_index = numpy.argmax(numpy.unique(numpy.array(image_file).reshape(-1, numpy.array(image_file).shape[-1]), axis=0, return_counts=True)[1])
# # colors = list()
# # for i in range(numcolors):
# # palette_index = color_counts[i][1]
# # dominant_color = palette[palette_index*3:palette_index*3+3]
# # colors.append(tuple(dominant_color))
# return tuple(numpy.unique(numpy.array(image_file).reshape(-1, numpy.array(image_file).shape[-1]), axis=0, return_counts=True)[0][max_count_index])
def get_colors(image_file, resize=150):
# Resize image to speed up processing
image_file.thumbnail((resize, resize))
# Reduce to palette
paletted = image_file.convert('P', palette=Image.ADAPTIVE, colors=numcolors)
numpy_array = numpy.array(image_file)
pixels = numpy_array.reshape(-1, numpy_array.shape[-1])
color_counts = numpy.unique(pixels, axis=0, return_counts=True)
max_count_index = numpy.argmax(color_counts[1])
# Find dominant colors
palette = paletted.getpalette()
# color_counts = sorted(paletted.getcolors(), reverse=True)
dominant_color = (palette[0], palette[1], palette[2])
# colors = list()
# for i in range(numcolors):
# palette_index = color_counts[i][1]
# dominant_color = palette[palette_index*3:palette_index*3+3]
# colors.append(tuple(dominant_color))
return dominant_color
return tuple(color_counts[0][max_count_index])
# def get_colors(image_file, numcolors=1, resize=150):
# # Resize image to speed up processing
# image_file.thumbnail((resize, resize))
# # Reduce to palette
# paletted = image_file.convert('P', palette=Image.ADAPTIVE, colors=numcolors)
# # Find dominant colors
# palette = paletted.getpalette()
# # color_counts = sorted(paletted.getcolors(), reverse=True)
# dominant_color = (palette[0], palette[1], palette[2])
# # colors = list()
# # for i in range(numcolors):
# # palette_index = color_counts[i][1]
# # dominant_color = palette[palette_index*3:palette_index*3+3]
# # colors.append(tuple(dominant_color))
# return dominant_color
def getLyrics(artist_name, track_name):
lrc = syncedlyrics.search("[" + track_name + "] [" + artist_name + "]")
@@ -489,8 +524,11 @@ def unloadSearching_Devices():
# Start updating the song label
# setup()
# Run the GUI
loadNow_playing()
update_song_label()
# Run the GUI
root.mainloop()

Binary file not shown.

Binary file not shown.

View File

@@ -3,6 +3,7 @@ from urllib.request import urlopen
from zipfile import ZipFile
from io import BytesIO
from time import sleep
import subprocess
while True:
@@ -23,9 +24,11 @@ except urllib.error.HTTPError:
print("No update available.")
pass
try:
exec(open('spotifycontroller.py').read())
except:
while True:
try:
subprocess.check_call(['python', 'spotifycontroller.py'])
except:
print("An error has ocurred, reestablishing the application in 10 seconds.")
sleep(10)
exec(open('spotifycontroller.py').read())
continue