added album art background on lyrics screen
switch back to now playing by tapping anywhere on lyrics screen added try blocks to fix HTTP and TypeError Exceptions other small code reworks
This commit is contained in:
@@ -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"}
|
{"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"}
|
||||||
BIN
album_art.jpg
BIN
album_art.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 111 KiB |
@@ -15,6 +15,8 @@ import threading
|
|||||||
import platform
|
import platform
|
||||||
import syncedlyrics
|
import syncedlyrics
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from PIL import Image, ImageTk
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
# 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"
|
||||||
@@ -203,15 +205,19 @@ 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")
|
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")
|
# album_art_img = ttk.PhotoImage(file="album_art.png")
|
||||||
|
|
||||||
# canvas = ttk.Canvas(root, width=480, height=320)
|
# canvas = ttk.Canvas(root, width=480, height=320)
|
||||||
# canvas.create_image(0, 0, image=album_art_img, anchor="nw")
|
# canvas.create_image(0, 0, image=album_art_img, anchor="nw")
|
||||||
# canvas.grid()
|
# canvas.grid()
|
||||||
|
|
||||||
|
# canvas = ttk.Canvas(root, width=480, height=320)
|
||||||
|
|
||||||
frame_artist_song = tk.Frame(root)
|
frame_artist_song = tk.Frame(root)
|
||||||
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)
|
||||||
|
|
||||||
root.grid_rowconfigure(0, weight=1)
|
root.grid_rowconfigure(0, weight=1)
|
||||||
root.grid_rowconfigure(1, 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)
|
# background_image_label = tk.Label(root, image=album_art_img)
|
||||||
lyrics_label = tk.Label(root, text="", font=("Helvetica", 32))
|
lyrics_label = tk.Label(root, text="", font=("Helvetica", 32))
|
||||||
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)
|
||||||
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("<Return>", search)
|
root.bind("<Return>", search)
|
||||||
play_button.bind("<<ButtonSelected>>", lambda e: frame_artist_song.focus())
|
lyrics_label.bind("<Button-1>", lambda e:unloadLyrics_pressed())
|
||||||
|
album_art_label.bind("<Button-1>", lambda e:unloadLyrics_pressed())
|
||||||
|
|
||||||
# Function to update the song label with the current track's name
|
# Function to update the song label with the current track's name
|
||||||
def update_song_label():
|
def update_song_label():
|
||||||
@@ -262,7 +271,7 @@ def update_song_label():
|
|||||||
current_playback = spotify.current_playback()
|
current_playback = spotify.current_playback()
|
||||||
except (spotipy.exceptions.SpotifyException, requests.exceptions.HTTPError):
|
except (spotipy.exceptions.SpotifyException, requests.exceptions.HTTPError):
|
||||||
createToken()
|
createToken()
|
||||||
pass
|
current_playback = spotify.current_playback()
|
||||||
# If there is no current playback, set the text of the song label to "No playback"
|
# If there is no current playback, set the text of the song label to "No playback"
|
||||||
if current_playback is None:
|
if current_playback is None:
|
||||||
# nothing_playing_obj = '{"item": {"artists": [{"name": "Nothing Playing"}],"duration_ms": 0,"name": "Nothing Playing"},"progress_ms": 0}'
|
# 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"]
|
track_name = current_playback["item"]["name"]
|
||||||
pass
|
pass
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
sleep(1000)
|
||||||
sleep(1)
|
|
||||||
update_song_label()
|
update_song_label()
|
||||||
track_name = current_playback["item"]["name"]
|
|
||||||
artist_name = current_playback["item"]["artists"][0]["name"]
|
artist_name = current_playback["item"]["artists"][0]["name"]
|
||||||
track_duration = current_playback["item"]["duration_ms"]
|
track_duration = current_playback["item"]["duration_ms"]
|
||||||
track_progress = current_playback["progress_ms"]
|
track_progress = current_playback["progress_ms"]
|
||||||
@@ -305,13 +312,12 @@ def update_song_label():
|
|||||||
track_progress_label.config(text=track_progress_formatted)
|
track_progress_label.config(text=track_progress_formatted)
|
||||||
progress_bar.config(maximum=track_duration)
|
progress_bar.config(maximum=track_duration)
|
||||||
progress_bar.config(value=track_progress)
|
progress_bar.config(value=track_progress)
|
||||||
print(track_progress_formatted)
|
|
||||||
for line in str(lrc).splitlines():
|
for line in str(lrc).splitlines():
|
||||||
if track_progress_formatted in line:
|
if track_progress_formatted in line:
|
||||||
lyric = line.split("]")[1]
|
lyric = line.split("]")[1]
|
||||||
wrapped_lyric = textwrap.fill(lyric, 21)
|
wrapped_lyric = textwrap.fill(lyric, 21)
|
||||||
lyrics_label.config(text=wrapped_lyric)
|
lyrics_label.config(text=wrapped_lyric)
|
||||||
root.after(850, update_song_label)
|
root.after(800, update_song_label)
|
||||||
else:
|
else:
|
||||||
# album_art_data = Image.open(requests.get(album_art_url, stream=True).raw)
|
# album_art_data = Image.open(requests.get(album_art_url, stream=True).raw)
|
||||||
# album_art_data.save("album_art.jpg")
|
# album_art_data.save("album_art.jpg")
|
||||||
@@ -322,6 +328,11 @@ def update_song_label():
|
|||||||
volumeslider_button.set(value=current_volume)
|
volumeslider_button.set(value=current_volume)
|
||||||
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 = 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)
|
root.after(500, update_song_label)
|
||||||
# if album_art_url == "12345":
|
# if album_art_url == "12345":
|
||||||
# open_url = urlopen(album_art_url)
|
# open_url = urlopen(album_art_url)
|
||||||
@@ -382,11 +393,13 @@ def unloadSearching_Devices():
|
|||||||
searching_for_devices_label.grid_forget()
|
searching_for_devices_label.grid_forget()
|
||||||
|
|
||||||
def loadLyrics():
|
def loadLyrics():
|
||||||
now_playing_button.grid(row=0, column=1)
|
album_art_frame.grid(row=0, column=1)
|
||||||
lyrics_label.grid(row=1, column=1, pady=20)
|
album_art_label.grid()
|
||||||
|
lyrics_label.grid(row=0, column=1)
|
||||||
|
|
||||||
def unloadLyrics():
|
def unloadLyrics():
|
||||||
now_playing_button.grid_forget()
|
album_art_frame.grid_forget()
|
||||||
|
album_art_label.grid_forget()
|
||||||
lyrics_label.grid_forget()
|
lyrics_label.grid_forget()
|
||||||
|
|
||||||
# Start updating the song label
|
# Start updating the song label
|
||||||
|
|||||||
Reference in New Issue
Block a user