diff --git a/.cache b/.cache index 278f4d5..2825e3c 100644 --- a/.cache +++ b/.cache @@ -1 +1 @@ -{"access_token": "BQC05wxeoZyHXRQVuQgm4-1Zqp2Uv8hf7Hg-wMyp0R7IIQMHwzLVINH31DaxsxO3aU_fCt9a3a4hihcgqZbVACu4IZLGU1TtN_P4mBpKbftuIxiDH7UMaOIGuwhvDKKkr0Zm_jqflBuJ0wdcaAD2CkYBzevBfMsXjtO87iD8ZoWwCh5mzWicZKnHho-tAlDaDI0FY-cgU_Xe_fU0S1Hf", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "AQCCSkV9mWV-ysqv_bMMERsUGgz7baaOfBGhqm2-6_3I-lpd2CKy8bs3GS_kNZy2D1YG6Z2dhKVUNTCE7MC0qcKypWZAvRw6nRlsM8816mTP6hpK67WWAuwq_qfnLVia1Oo", "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1677969435} \ No newline at end of file +{"access_token": "BQDMY3TJbe_zGpD0_Hbhitu8zVPEwuXwPDv-KkVhqZ_itVTbYbUdwoqkUl0xFTpReD9_Hgix6RRsM7HyeWpr6r02dlVG8EzbVf9CDNclFSDH56lplmN_H8wbyZrz1DGqow-uVUZJpfDYrPizY2GclbsJLNj3pxguVNPwfbkLXjiOBK9LO1M4A-eoA8YzTCFxhdL5CC-tW2lucUDEaEpd", "token_type": "Bearer", "expires_in": 3600, "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1677981348, "refresh_token": "AQDMo7jMg-YY6MpV64feNjby-v67EjBDVFxHtJM4Uax4geoYYKU_bYmu8Mpz-7h6XjTurxvaoUZSIyxr1b4dnLgnOwfvCtS2ozFGXifAXl7R4wMjCY79BvGesxGogf24j58"} \ No newline at end of file diff --git a/icons/pause-heart-black.png b/icons/pause-heart-black.png new file mode 100644 index 0000000..f79fb07 Binary files /dev/null and b/icons/pause-heart-black.png differ diff --git a/icons/pause-heart.png b/icons/pause-heart.png new file mode 100644 index 0000000..8ddef91 Binary files /dev/null and b/icons/pause-heart.png differ diff --git a/icons/play-heart-black.png b/icons/play-heart-black.png new file mode 100644 index 0000000..e104556 Binary files /dev/null and b/icons/play-heart-black.png differ diff --git a/icons/play-heart.png b/icons/play-heart.png new file mode 100644 index 0000000..0b2c6f5 Binary files /dev/null and b/icons/play-heart.png differ diff --git a/spotifycontroller.py b/spotifycontroller.py index 0b30694..094f507 100644 --- a/spotifycontroller.py +++ b/spotifycontroller.py @@ -97,8 +97,20 @@ def controlPrevious(): def likeSong(): if spotify.current_user_saved_tracks_contains(tracks=[(spotify.current_playback()["item"]["id"])])[0] is False: spotify.current_user_saved_tracks_add(tracks=[(spotify.current_playback()["item"]["id"])]) + if is_bright is True: + play_button.config(image=play_heart_img_black) + pause_button.config(image=pause_heart_img_black) + else: + play_button.config(image=play_heart_img) + pause_button.config(image=pause_heart_img) else: spotify.current_user_saved_tracks_delete(tracks=[(spotify.current_playback()["item"]["id"])]) + if is_bright is True: + play_button.config(image=play_img_black) + pause_button.config(image=pause_img_black) + else: + play_button.config(image=play_img) + pause_button.config(image=pause_img) def start_playback_on_device(): # global count @@ -229,17 +241,21 @@ def getLyrics(artist_name, track_name): play_img = ttk.PhotoImage(file="icons/play.png") pause_img = ttk.PhotoImage(file="icons/pause.png") +play_heart_img = ttk.PhotoImage(file="icons/play-heart.png") +pause_heart_img = ttk.PhotoImage(file="icons/pause-heart.png") next_img = ttk.PhotoImage(file="icons/next.png") previous_img = ttk.PhotoImage(file="icons/previous.png") play_img_black = ttk.PhotoImage(file="icons/play-black.png") pause_img_black = ttk.PhotoImage(file="icons/pause-black.png") +play_heart_img_black = ttk.PhotoImage(file="icons/play-heart-black.png") +pause_heart_img_black = ttk.PhotoImage(file="icons/pause-heart-black.png") next_img_black = ttk.PhotoImage(file="icons/next-black.png") previous_img_black = ttk.PhotoImage(file="icons/previous-black.png") album_art_img = "" frame_artist_song = ttk.Frame(root, width=(1280/3), height=400, bg=bg_color) -album_art_frame = ttk.Frame(root, bg=bg_color) +album_art_frame = ttk.Frame(root) lyrics_label_frame = ttk.Frame(root, width=(1280/3), height=400, bg=bg_color) lyrics_label_frame.grid_propagate(0) @@ -270,20 +286,19 @@ device_name_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 12)) lyrics_label = tk.Label(lyrics_label_frame, text="", font=("Helvetica", 32), wraplength=(1280/3), justify=ttk.CENTER, background=bg_color) album_art_label = tk.Label(album_art_frame, image=album_art_img) -play_button.configure() - play_button.bind("", lambda e:controlPlay()) pause_button.bind("", lambda e:controlPause()) next_button.bind("", lambda e:controlNext()) previous_button.bind("", lambda e:controlPrevious()) -album_art_label.bind("", lambda e:likeSong()) +album_art_label.bind("", lambda e:likeSong()) # devices_list.bind("", lambda e:wakeup()) import json # Function to update the song label with the current track's name def update_song_label(): global lrc global album_art_img + global is_bright # Get the current playback information current_playback = spotify.current_playback() # If there is no current playback, set the text of the song label to "No playback" @@ -294,26 +309,14 @@ def update_song_label(): else: if current_playback.get("item"): 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"] playing_status = current_playback["is_playing"] - device_name = current_playback["device"]["name"] - album_art_url = current_playback["item"]["album"]["images"][0]["url"] track_progress_min = track_progress//(1000*60)%60 track_progress_sec = (track_progress//1000)%60 else: track_name = "Loading..." - artist_name = "" - track_duration = 1 - playing_status = True - device_name = "" - album_art_url = "" - track_progress_min = 0 - track_progress_sec = 1 if track_name == song_label.cget("text"): track_progress_formatted = ("{}:{:02d}".format(track_progress_min, track_progress_sec)) - progress_bar.config(maximum=track_duration) progress_bar.config(value=track_progress) for line in str(lrc).splitlines(): if track_progress_formatted in line: @@ -321,10 +324,16 @@ def update_song_label(): lyrics_label.config(text=lyric) root.after(800, update_song_label) else: + artist_name = current_playback["item"]["artists"][0]["name"] threading.Thread(target=getLyrics, args=(artist_name, track_name)).start() + track_id = current_playback["item"]["id"] + track_duration = current_playback["item"]["duration_ms"] + device_name = current_playback["device"]["name"] + album_art_url = current_playback["item"]["album"]["images"][0]["url"] device_name_label.config(text=device_name) song_label.config(text=track_name) artist_label.config(text=artist_name) + progress_bar.config(maximum=track_duration) lyrics_label.config(text="") album_art_img_data = requests.get(album_art_url).content album_art_img_open = Image.open(BytesIO(album_art_img_data)) @@ -348,22 +357,36 @@ def update_song_label(): previous_button.config(background=bg_color) lyrics_label_frame.config(background=bg_color) lyrics_label.config(background=bg_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: + is_bright = True + if liked_song is True: + play_button.config(image=play_heart_img_black) + pause_button.config(image=pause_heart_img_black) + else: + play_button.config(image=play_img_black) + pause_button.config(image=pause_img_black) 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: + is_bright = False + if liked_song is True: + play_button.config(image=play_heart_img) + pause_button.config(image=pause_heart_img) + else: + play_button.config(image=play_img) + pause_button.config(image=pause_img) 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) # print(oauth.get_cached_token()["access_token"]) @@ -378,7 +401,6 @@ def update_song_label(): elif playing_status == False: pause_button.grid_forget() play_button.grid(row=3, column=1, pady=(100,0)) - else: pass