mem leak fix

new icons! higher qual
miscelanous code cleanup
This commit is contained in:
Brandon4466
2023-03-04 01:58:18 -08:00
parent c18594855e
commit c66ee19a25
13 changed files with 99 additions and 51 deletions

View File

@@ -16,11 +16,12 @@ import queue
# SpotifyGUI - Made by Brandon Brunson
# import speech_recognition as sr
if os.path.isfile("updated.cfg"):
print("A new update was downloaded and installed. Starting in 5 seconds...")
os.remove("updated.cfg")
sleep(5)
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...")
os.remove("updated.cfg")
sleep(5)
q = queue.Queue()
@@ -65,12 +66,11 @@ spotify = spotipy.Spotify(auth_manager=oauth)
# print(SpotifyOAuth.refresh_access_token(refresh_token=access_token))
bg_color = "#000000"
count = 0
wait_time = 6500
# count = 0
# wait_time = 6500
# hotword = "magical"
if os.name == 'posix':
os.system("xset -display :0 s 21600")
# Create the tkinter window
root = ttk.Tk()
@@ -94,9 +94,15 @@ def controlNext():
def controlPrevious():
spotify.previous_track()
def likeSong():
print(spotify.current_playback()["item"]["id"])
spotify.current_user_saved_tracks_add(tracks=(spotify.current_playback()["item"]["id"]))
def start_playback_on_device():
wakeup()
# global count
# global wait_time
# count = 0
# wait_time = 6500
device_selections = devices_list.curselection()
list_of_devices = spotify.devices()
list_of_devices = spotify.devices()
@@ -104,17 +110,13 @@ def start_playback_on_device():
spotify.transfer_playback(device_id=device_id)
def get_devices():
global count
global wait_time
count +=1
if count < 69:
wait_time = 6500
elif count >= 69:
wait_time = 300000
elif count >= 138:
wait_time = 600000
elif count >= 277:
wait_time = 3600000
# global count
# global wait_time
# count +=1
# if count < 69:
# wait_time = 6500
# elif count >= 69:
# wait_time = 3600000
list_of_devices = spotify.devices()
unloadNow_playing()
if list_of_devices == "{'devices': []}":
@@ -122,12 +124,11 @@ def get_devices():
loadSearching_Devices()
root.after(1000, get_devices)
else:
current_playback = spotify.current_playback()
if current_playback != None:
if spotify.current_playback() != None:
unloadSearching_Devices()
unloadDevices_list()
loadNow_playing()
update_song_label()
return
else:
unloadSearching_Devices()
loadDevices_list()
@@ -135,13 +136,13 @@ def get_devices():
list_of_devices = spotify.devices()
for num_of_device, garbage in enumerate(list_of_devices["devices"]):
devices_list.insert(num_of_device, list_of_devices["devices"][num_of_device]["name"])
root.after(wait_time, get_devices)
root.after(6500, get_devices)
def wakeup():
global count
global wait_time
count = 0
wait_time = 6500
# def wakeup():
# global count
# global wait_time
# count = 0
# wait_time = 6500
def addCorners(im, rad):
circle = Image.new('L', (rad * 2, rad * 2), 0)
@@ -224,14 +225,14 @@ def getLyrics(artist_name, track_name):
# def rgb_to_hex(r, g, b):
# return ('{:X}{:X}{:X}').format(r, g, b)
play_img = ttk.PhotoImage(file="icons/play-circle-x2.png")
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")
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")
play_img = ttk.PhotoImage(file="icons/play.png")
pause_img = ttk.PhotoImage(file="icons/pause.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")
next_img_black = ttk.PhotoImage(file="icons/next-black.png")
previous_img_black = ttk.PhotoImage(file="icons/previous-black.png")
album_art_img = ""
@@ -267,13 +268,16 @@ 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("<Button-1>", lambda e:controlPlay())
pause_button.bind("<Button-1>", lambda e:controlPause())
next_button.bind("<Button-1>", lambda e:controlNext())
previous_button.bind("<Button-1>", lambda e:controlPrevious())
devices_list.bind("<Button-1>", lambda e:wakeup())
album_art_label.bind("<Double-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
@@ -283,17 +287,25 @@ def update_song_label():
# If there is no current playback, set the text of the song label to "No playback"
if current_playback is None:
get_devices()
root.after(100, update_song_label)
# Update the song label every 1 second
else:
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
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 = "Loading..."
track_duration = 1
track_progress = 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)
@@ -361,6 +373,7 @@ def update_song_label():
elif playing_status == False:
pause_button.grid_forget()
play_button.grid(row=3, column=1, pady=(100,0))
else:
pass