added background color changing to album art color

determines if new bg color is "dark" or "bright"
text and buttons invert color when bg color is too bright
This commit is contained in:
Brandon4466
2023-01-14 16:45:19 -08:00
parent 671ca07d4b
commit c23b8b01c2
6 changed files with 59 additions and 16 deletions

View File

@@ -1 +1 @@
{"access_token": "BQDldG8RcelC2zfeMARvA0BlLzA1_kOIW3LJyE1yATS7sj19-ysYNvcwm7CM2901s38Bt1RjNy8XfvDbvgwMei1_zf3duPpD-nV2BqNncOqO9NlTj7N5QAvEeSFN45dwGUCcdpdXv8k8vE_HD0Yf2HStRyQgQ0q3xta-s0FFLcXCt6PP48-txZ4ufNa1Xg", "token_type": "Bearer", "expires_in": 3600, "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1673739632, "refresh_token": "AQBb9zPnT-MmK7H70IzzenfZBz1VV-0eZWhD73x2br6xQPx1jctO-uuGZu38EvvXapCpdJZ8oLAk4Z4Ci2gmZGGfMsmsofMNVB402gjRrSzfV94BpkuYJtyV0fS5bSK5Nrg"} {"access_token": "BQCekaBvjmyM9f12lOetax1Wqzc6TSlwiySg4aEIc_10eH09pQPEX89ZAiZCDnXC4U94N98wg6R3DqS0SJh5EqykeuO29RIK9uVPaArOob6pYRhlNdeQuDuc_UGKzuND_JUy7Bd7XlYjAbcxiemBJjGfx44gAAJD-IDbPTSTQ_PoYZtOie7JtIF2XNQTgw", "token_type": "Bearer", "expires_in": 3600, "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1673746986, "refresh_token": "AQBb9zPnT-MmK7H70IzzenfZBz1VV-0eZWhD73x2br6xQPx1jctO-uuGZu38EvvXapCpdJZ8oLAk4Z4Ci2gmZGGfMsmsofMNVB402gjRrSzfV94BpkuYJtyV0fS5bSK5Nrg"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 832 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

View File

@@ -17,6 +17,7 @@ import syncedlyrics
import textwrap import textwrap
from PIL import Image, ImageTk from PIL import Image, ImageTk
from io import BytesIO from io import BytesIO
import math
# Set the Spotify app's client ID and client secret # Set the Spotify app's client ID and client secret
client_id = "69b82a34d0fb40be80b020eae8e80f25" client_id = "69b82a34d0fb40be80b020eae8e80f25"
@@ -90,6 +91,8 @@ def createToken():
spotify = createToken() spotify = createToken()
bg_color = "#000000"
# Create the tkinter window # Create the tkinter window
root = ttk.Tk() root = ttk.Tk()
root.title("Media Controller") root.title("Media Controller")
@@ -195,6 +198,7 @@ def unloadLyrics_pressed():
unloadLyrics() unloadLyrics()
loadNow_playing() loadNow_playing()
# def hide_devices(): # def hide_devices():
# get_devices_button.grid() # get_devices_button.grid()
# devices_list.grid_remove() # devices_list.grid_remove()
@@ -206,7 +210,11 @@ play_img = ttk.PhotoImage(file="icons/play-circle-x2.png")
pause_img = ttk.PhotoImage(file="icons/pause-circle-x2.png") pause_img = ttk.PhotoImage(file="icons/pause-circle-x2.png")
next_img = ttk.PhotoImage(file="icons/skip-next-x2.png") next_img = ttk.PhotoImage(file="icons/skip-next-x2.png")
previous_img = ttk.PhotoImage(file="icons/skip-previous-x2.png") previous_img = ttk.PhotoImage(file="icons/skip-previous-x2.png")
lyrics_img = ttk.PhotoImage(file="icons/lyrics.png") play_img_black = ttk.PhotoImage(file="icons/play-circle-x2-black.png")
pause_img_black = ttk.PhotoImage(file="icons/pause-circle-x2-black.png")
next_img_black = ttk.PhotoImage(file="icons/skip-next-x2-black.png")
previous_img_black = ttk.PhotoImage(file="icons/skip-previous-x2-black.png")
# lyrics_img = ttk.PhotoImage(file="icons/lyrics.png")
album_art_img = "" album_art_img = ""
# album_art_img = ttk.PhotoImage(file="album_art.png") # album_art_img = ttk.PhotoImage(file="album_art.png")
@@ -216,11 +224,11 @@ album_art_img = ""
canvas = ttk.Canvas(root, width=480, height=320) canvas = ttk.Canvas(root, width=480, height=320)
frame_artist_song = tk.Frame(root, width=(1280/3), height=400) frame_artist_song = ttk.Frame(root, width=(1280/3), height=400, bg=bg_color)
# frame_controls = tk.Frame(root) # frame_controls = tk.Frame(root)
lyrics_button = tk.Frame(root) # lyrics_button = tk.Frame(root)
album_art_frame = tk.Frame(root) album_art_frame = ttk.Frame(root, bg=bg_color)
lyrics_label_frame = tk.Frame(root, width=(1280/3), height=400) lyrics_label_frame = ttk.Frame(root, width=(1280/3), height=400, bg=bg_color)
lyrics_label_frame.grid_propagate(0) lyrics_label_frame.grid_propagate(0)
root.grid_rowconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1)
@@ -230,21 +238,23 @@ root.grid_columnconfigure(0, weight=1)
root.grid_columnconfigure(1, weight=1) root.grid_columnconfigure(1, weight=1)
# root.grid_columnconfigure(2, weight=1) # root.grid_columnconfigure(2, weight=1)
root.configure(background=bg_color)
lyrics_label_frame.grid_rowconfigure(0, weight=1) lyrics_label_frame.grid_rowconfigure(0, weight=1)
lyrics_label_frame.grid_columnconfigure(0, weight=1) lyrics_label_frame.grid_columnconfigure(0, weight=1)
# Create the media control buttons and a text label # Create the media control buttons and a text label
play_button = ttk.Button(frame_artist_song, image=play_img, command=play, borderwidth=0, relief=None) play_button = ttk.Button(frame_artist_song, image=play_img, command=play, borderwidth=0, relief=None, background=bg_color)
pause_button = ttk.Button(frame_artist_song, image=pause_img, command=pause, borderwidth=0) pause_button = ttk.Button(frame_artist_song, image=pause_img, command=pause, borderwidth=0, background=bg_color)
next_button = ttk.Button(frame_artist_song, image=next_img, command=next, borderwidth=0) next_button = ttk.Button(frame_artist_song, image=next_img, command=next, borderwidth=0, background=bg_color)
previous_button = ttk.Button(frame_artist_song, image=previous_img, command=previous, borderwidth=0) previous_button = ttk.Button(frame_artist_song, image=previous_img, command=previous, borderwidth=0, background=bg_color)
maxvolume_button = tk.Button(root, text="Max Volume", command=maxvolume) maxvolume_button = tk.Button(root, text="Max Volume", command=maxvolume)
minvolume_button = tk.Button(root, text="Min Volume", command=minvolume) minvolume_button = tk.Button(root, text="Min Volume", command=minvolume)
randomvolume_button = tk.Button(root, text="Random Volume", command=randomvolume) randomvolume_button = tk.Button(root, text="Random Volume", command=randomvolume)
volumeslider_button = tk.Scale(root, from_=100, to=0, orient=ttk.VERTICAL, length=240, command=volumeslider) volumeslider_button = tk.Scale(root, from_=100, to=0, orient=ttk.VERTICAL, length=240, command=volumeslider)
#doaudio_analysis = tk.Button(root, text="Audio Analysis", command=doaudioanalysis) #doaudio_analysis = tk.Button(root, text="Audio Analysis", command=doaudioanalysis)
artist_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 32), wraplength=(1280/3), justify=ttk.CENTER) artist_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 32), wraplength=(1280/3), justify=ttk.CENTER, background=bg_color)
song_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 24), wraplength=(1280/3), justify=ttk.CENTER) song_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 24), wraplength=(1280/3), justify=ttk.CENTER, background=bg_color)
track_progress_label = tk.Label(root, text="") track_progress_label = tk.Label(root, text="")
track_duration_label = tk.Label(root, text="") track_duration_label = tk.Label(root, text="")
# track_combined_label = tk.Label(root, text="") # track_combined_label = tk.Label(root, text="")
@@ -259,8 +269,8 @@ progress_bar = tk.Progressbar(root, orient=ttk.HORIZONTAL, length=1280)
searching_for_devices_label = tk.Label(root, text="Searching for Devices...", font=("Helvetica", 24)) searching_for_devices_label = tk.Label(root, text="Searching for Devices...", font=("Helvetica", 24))
device_name_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 12)) device_name_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 12))
# background_image_label = tk.Label(root, image=album_art_img) # background_image_label = tk.Label(root, image=album_art_img)
lyrics_label = tk.Label(lyrics_label_frame, text="", font=("Helvetica", 32), wraplength=(1280/3), justify=ttk.CENTER) lyrics_label = tk.Label(lyrics_label_frame, text="", font=("Helvetica", 32), wraplength=(1280/3), justify=ttk.CENTER, background=bg_color)
loadLyrics_button = ttk.Button(lyrics_button, image=lyrics_img, command=loadLyrics_pressed, borderwidth=0) # loadLyrics_button = ttk.Button(lyrics_button, image=lyrics_img, command=loadLyrics_pressed, borderwidth=0)
# album_art_canvas = ttk.Canvas(root) # album_art_canvas = ttk.Canvas(root)
# album_art_canvas_create_image = album_art_canvas.create_image(0, 0, image=album_art_img) # album_art_canvas_create_image = album_art_canvas.create_image(0, 0, image=album_art_img)
album_art_label = tk.Label(album_art_frame, image=album_art_img) album_art_label = tk.Label(album_art_frame, image=album_art_img)
@@ -336,8 +346,41 @@ def update_song_label():
lyrics_label.config(text="") lyrics_label.config(text="")
lrc = syncedlyrics.search("[" + track_name + "] [" + artist_name + "]") lrc = syncedlyrics.search("[" + track_name + "] [" + artist_name + "]")
album_art_img_data = requests.get(album_art_url).content album_art_img_data = requests.get(album_art_url).content
album_art_img = ImageTk.PhotoImage(Image.open(BytesIO(album_art_img_data)).resize((300,300))) album_art_img_open = Image.open(BytesIO(album_art_img_data))
album_art_img = ImageTk.PhotoImage(album_art_img_open.resize((300,300)))
album_art_label.config(image=album_art_img) album_art_label.config(image=album_art_img)
bg_color_img = album_art_img_open.resize((1,1), resample=0)
bg_color_img_pixel = bg_color_img.getpixel((0,0))
bg_color = "#" + '%02x%02x%02x' % (bg_color_img_pixel)
root.config(background=bg_color)
frame_artist_song.config(background=bg_color)
device_name_label.config(background=bg_color)
song_label.config(background=bg_color)
artist_label.config(background=bg_color)
play_button.config(background=bg_color)
pause_button.config(background=bg_color)
next_button.config(background=bg_color)
previous_button.config(background=bg_color)
lyrics_label_frame.config(background=bg_color)
lyrics_label.config(background=bg_color)
if math.sqrt(0.299 * (bg_color_img_pixel[0] ** 2) + 0.587 * (bg_color_img_pixel[1] ** 2) + 0.114 * (bg_color_img_pixel[2] ** 2)) > 186:
song_label.config(foreground="black")
artist_label.config(foreground="black")
device_name_label.config(foreground="black")
lyrics_label.config(foreground="black")
play_button.config(image=play_img_black)
pause_button.config(image=pause_img_black)
next_button.config(image=next_img_black)
previous_button.config(image=previous_img_black)
else:
song_label.config(foreground="white")
artist_label.config(foreground="white")
device_name_label.config(foreground="white")
lyrics_label.config(foreground="white")
play_button.config(image=play_img)
pause_button.config(image=pause_img)
next_button.config(image=next_img)
previous_button.config(image=previous_img)
# album_art_label.grid_forget() # album_art_label.grid_forget()
# album_art_label.grid() # album_art_label.grid()
root.after(500, update_song_label) root.after(500, update_song_label)
@@ -387,7 +430,7 @@ def unloadNow_playing():
play_button.grid_forget() play_button.grid_forget()
next_button.grid_forget() next_button.grid_forget()
progress_bar.grid_forget() progress_bar.grid_forget()
loadLyrics_button.grid_forget() # loadLyrics_button.grid_forget()
def loadDevices_list(): def loadDevices_list():
devices_list.grid(row=1, column=1, pady=10) devices_list.grid(row=1, column=1, pady=10)