diff --git a/.cache-thebrandon45 b/.cache-thebrandon45 index d850a98..bf2b729 100644 --- a/.cache-thebrandon45 +++ b/.cache-thebrandon45 @@ -1 +1 @@ -{"access_token": "BQBGV5PUSSn8OwdTKnIxZEz2785sMhLXI-A2uPZ8h8ELDgwUtfEf1I_2XFmarFwbJZQ5hqHzIVXXMUDELuUOiDxMv2Nme0_NcSE4Pc9IC7E56PAS_KZdaEGFu3PB7sv_pD5nzbKxh8Tkt98m_g_pgA5mtxZ1obked94wk63Q-ddBdmgmhjc0Mnx1Ritb7g", "token_type": "Bearer", "expires_in": 3600, "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1673491582, "refresh_token": "AQDs4x9WTbYtoqePbR9tvRWCcJHs1Hh3vrXpIHBtBdkJIDJ-Mu14B-vLEqOnowqw1HzZI5H5ytOFS2y9xBCcDyDU0uMA_D0MRPtujyCUYb9sdnD-D6WC2fN7bFiGeoo-YAo"} \ No newline at end of file +{"access_token": "BQBShlgGHV4Kk8pB4G4OFGraJAIJBVMllGBJkq8TKM7dkQ8tI2pnPy8hHq3rEU7J4b0J0DsQpXox28AzzsF73dB5vItgGWaBDkc8fhRnVTooK08fe9u05qYAHZ4ln0TMy-nNJKAk9txxcijo7k5W8RtBEGU9dADSnJ8wmp9aB2BPs4m3-6-ug7IB1rdqEw", "token_type": "Bearer", "expires_in": 3600, "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1673591865, "refresh_token": "AQDs4x9WTbYtoqePbR9tvRWCcJHs1Hh3vrXpIHBtBdkJIDJ-Mu14B-vLEqOnowqw1HzZI5H5ytOFS2y9xBCcDyDU0uMA_D0MRPtujyCUYb9sdnD-D6WC2fN7bFiGeoo-YAo"} \ No newline at end of file diff --git a/album_art.jpg b/album_art.jpg index 5a1337f..f31bf4f 100644 Binary files a/album_art.jpg and b/album_art.jpg differ diff --git a/program-embedded.py b/program-embedded.py index bc6d105..e8288ee 100644 --- a/program-embedded.py +++ b/program-embedded.py @@ -15,6 +15,8 @@ import threading import platform import syncedlyrics import textwrap +from PIL import Image, ImageTk +from io import BytesIO # Set the Spotify app's client ID and client secret client_id = "69b82a34d0fb40be80b020eae8e80f25" @@ -203,15 +205,19 @@ pause_img = ttk.PhotoImage(file="icons/pause-circle-x2.png") next_img = ttk.PhotoImage(file="icons/skip-next-x2.png") previous_img = ttk.PhotoImage(file="icons/skip-previous-x2.png") lyrics_img = ttk.PhotoImage(file="icons/lyrics.png") +album_art_img = ImageTk.PhotoImage(Image.open("album_art.jpg")) # album_art_img = ttk.PhotoImage(file="album_art.png") # canvas = ttk.Canvas(root, width=480, height=320) # canvas.create_image(0, 0, image=album_art_img, anchor="nw") # canvas.grid() +# canvas = ttk.Canvas(root, width=480, height=320) + frame_artist_song = tk.Frame(root) frame_controls = tk.Frame(root) lyrics_button = tk.Frame(root) +album_art_frame = tk.Frame(root) root.grid_rowconfigure(0, weight=1) root.grid_rowconfigure(1, weight=1) @@ -249,10 +255,13 @@ device_name_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 12)) # background_image_label = tk.Label(root, image=album_art_img) lyrics_label = tk.Label(root, text="", font=("Helvetica", 32)) loadLyrics_button = ttk.Button(lyrics_button, image=lyrics_img, command=loadLyrics_pressed, borderwidth=0) -now_playing_button = tk.Button(root, text="Now Playing", command=unloadLyrics_pressed) +# album_art_canvas = ttk.Canvas(root) +# 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) root.bind("", search) -play_button.bind("<>", lambda e: frame_artist_song.focus()) +lyrics_label.bind("", lambda e:unloadLyrics_pressed()) +album_art_label.bind("", lambda e:unloadLyrics_pressed()) # Function to update the song label with the current track's name def update_song_label(): @@ -262,7 +271,7 @@ def update_song_label(): current_playback = spotify.current_playback() except (spotipy.exceptions.SpotifyException, requests.exceptions.HTTPError): createToken() - pass + 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: # nothing_playing_obj = '{"item": {"artists": [{"name": "Nothing Playing"}],"duration_ms": 0,"name": "Nothing Playing"},"progress_ms": 0}' @@ -274,10 +283,8 @@ def update_song_label(): track_name = current_playback["item"]["name"] pass except TypeError: - - sleep(1) + sleep(1000) update_song_label() - track_name = current_playback["item"]["name"] artist_name = current_playback["item"]["artists"][0]["name"] track_duration = current_playback["item"]["duration_ms"] track_progress = current_playback["progress_ms"] @@ -305,13 +312,12 @@ def update_song_label(): track_progress_label.config(text=track_progress_formatted) progress_bar.config(maximum=track_duration) progress_bar.config(value=track_progress) - print(track_progress_formatted) for line in str(lrc).splitlines(): if track_progress_formatted in line: lyric = line.split("]")[1] wrapped_lyric = textwrap.fill(lyric, 21) lyrics_label.config(text=wrapped_lyric) - root.after(850, update_song_label) + root.after(800, update_song_label) else: # album_art_data = Image.open(requests.get(album_art_url, stream=True).raw) # album_art_data.save("album_art.jpg") @@ -322,6 +328,11 @@ def update_song_label(): volumeslider_button.set(value=current_volume) lyrics_label.config(text="") lrc = syncedlyrics.search("[" + track_name + "] [" + artist_name + "]") + album_art_img_data = requests.get(album_art_url).content + album_art_img = ImageTk.PhotoImage(Image.open(BytesIO(album_art_img_data)).resize((480,480))) + album_art_label.config(image=album_art_img) + # album_art_label.grid_forget() + # album_art_label.grid() root.after(500, update_song_label) # if album_art_url == "12345": # open_url = urlopen(album_art_url) @@ -382,11 +393,13 @@ def unloadSearching_Devices(): searching_for_devices_label.grid_forget() def loadLyrics(): - now_playing_button.grid(row=0, column=1) - lyrics_label.grid(row=1, column=1, pady=20) + album_art_frame.grid(row=0, column=1) + album_art_label.grid() + lyrics_label.grid(row=0, column=1) def unloadLyrics(): - now_playing_button.grid_forget() + album_art_frame.grid_forget() + album_art_label.grid_forget() lyrics_label.grid_forget() # Start updating the song label