Changed update so it doesn't retry to fast
Refactored code
This commit is contained in:
@@ -19,7 +19,7 @@ import queue
|
||||
if os.name == 'posix':
|
||||
os.system("xset -display :0 s 21600")
|
||||
if os.path.isfile("updated.cfg"):
|
||||
print("A new update was downloaded and installed. Starting in 5 seconds...")
|
||||
print("NEW VER")
|
||||
os.remove("updated.cfg")
|
||||
sleep(5)
|
||||
|
||||
@@ -28,10 +28,13 @@ q = queue.Queue()
|
||||
# import canvas
|
||||
|
||||
# Set the Spotify app's client ID and client secret
|
||||
client_id = "69b82a34d0fb40be80b020eae8e80f25"
|
||||
client_secret = "455575b0e3db44acbbfaa0c419bc3c10"
|
||||
# client_id = "69b82a34d0fb40be80b020eae8e80f25"
|
||||
# client_secret = "455575b0e3db44acbbfaa0c419bc3c10"
|
||||
redirect_uri = "http://127.0.0.1:8888/callback"
|
||||
|
||||
client_id = "df61ecadf09941eb87e693d37f3ad178"
|
||||
client_secret = "ba97992d614e48d6b0d023998b2957cb"
|
||||
|
||||
# Set the user's Spotify username
|
||||
username = "thebrandon45"
|
||||
password = "Mariposa2502$"
|
||||
@@ -94,7 +97,7 @@ def controlNext():
|
||||
def controlPrevious():
|
||||
spotify.previous_track()
|
||||
|
||||
def likeSong():
|
||||
def likeSong(is_bright):
|
||||
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:
|
||||
@@ -112,6 +115,41 @@ def likeSong():
|
||||
play_button.config(image=play_img)
|
||||
pause_button.config(image=pause_img)
|
||||
|
||||
def colorUI(track_id, album_art_img_open):
|
||||
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")
|
||||
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")
|
||||
next_button.config(image=next_img)
|
||||
previous_button.config(image=previous_img)
|
||||
return is_bright
|
||||
|
||||
def start_playback_on_device():
|
||||
# global count
|
||||
# global wait_time
|
||||
@@ -293,12 +331,13 @@ next_button.bind("<Button-1>", lambda e:controlNext())
|
||||
previous_button.bind("<Button-1>", lambda e:controlPrevious())
|
||||
album_art_label.bind("<Button-1>", lambda e:likeSong())
|
||||
# devices_list.bind("<Button-1>", 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"
|
||||
@@ -357,42 +396,11 @@ 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")
|
||||
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")
|
||||
next_button.config(image=next_img)
|
||||
previous_button.config(image=previous_img)
|
||||
# print(oauth.get_cached_token()["access_token"])
|
||||
# print(current_playback["item"]["id"])
|
||||
# canvas_url = canvas.get_canvas_for_track(access_token=oauth.get_cached_token()["access_token"], track_id=current_playback["item"]["id"])
|
||||
# print(canvas_url)
|
||||
colorUI(track_id, album_art_img_open)
|
||||
# print(oauth.get_cached_token()["access_token"])
|
||||
# print(current_playback["item"]["id"])
|
||||
# canvas_url = canvas.get_canvas_for_track(access_token=oauth.get_cached_token()["access_token"], track_id=current_playback["item"]["id"])
|
||||
# print(canvas_url)
|
||||
lrc = q.get()
|
||||
root.after(500, update_song_label)
|
||||
if playing_status == True:
|
||||
|
||||
Reference in New Issue
Block a user