Changed update so it doesn't retry to fast
Refactored code
This commit is contained in:
2
.cache
2
.cache
@@ -1 +1 @@
|
||||
{"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"}
|
||||
{"access_token": "BQB1g4gwPqYVjNK4nO_yo-cpklfGJr3UxL5hIveI0mJjE5SppjfNnpNbvAwC2He9r1SdAPmWfDnNER1XjgNb_RlNDZVYpXTE-D46mfoLc-f-rnR7vagnY5OL7KULnDoYQkp1iOZwDUmOAWxtBKVQSzRG9coPbh7NfB75Iz42zJYu6IneT4E-R0FOJSW3bkTKjbenqn4zMsnoPyKwQmOi", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "AQC5BsmRqj_PhCL7Xj32C6Pz4UeFF09ZufzWv0NU1lGwZCUGaWAQP8F4twJf3Rx5EfKyAg4DIEnHZIFd6e5L4bPQXhPUny2t7A1AA5hCwfFI_LjXWWPij8oKX_0YDr6CXK0", "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1678338237}
|
||||
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Current File",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
}
|
||||
]
|
||||
}
|
||||
6
handler.py
Normal file
6
handler.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def handler():
|
||||
try:
|
||||
exec(open('spotifycontroller.py').read())
|
||||
except:
|
||||
print("An error has ocurred, reestablishing the application now.")
|
||||
exec(open('spotifycontroller.py').read())
|
||||
@@ -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,38 +396,7 @@ 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)
|
||||
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"])
|
||||
|
||||
6
todo.txt
6
todo.txt
@@ -70,3 +70,9 @@ if newer version is in json file, follow link in json file to download, otherwis
|
||||
|
||||
03/04/2023:
|
||||
redo background color algo. PROMINENT COLOR not average like it is now.
|
||||
|
||||
03/04/2023:
|
||||
add shuffle and repeat buttons
|
||||
|
||||
03/07/2023:
|
||||
make it so the displays turns off automatically after some time (maybe depending on time, ie. late at night)
|
||||
14
update.py
14
update.py
@@ -2,24 +2,30 @@ import urllib
|
||||
from urllib.request import urlopen
|
||||
from zipfile import ZipFile
|
||||
from io import BytesIO
|
||||
from spotipy import exceptions as SpotipyExceptions
|
||||
from requests import exceptions as RequestsExceptions
|
||||
from time import sleep
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
urlopen('http://bbrunson.com', timeout=1)
|
||||
print("Connection to server established.")
|
||||
break
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
print("Checking for updates...")
|
||||
with ZipFile(BytesIO((urlopen('http://files.bbrunson.com/spotify-gui/update.zip')).read())) as zipObj:
|
||||
zipObj.extractall()
|
||||
print("Update successfully installed.")
|
||||
except urllib.error.HTTPError:
|
||||
print("No update available.")
|
||||
pass
|
||||
|
||||
try:
|
||||
exec(open('spotifycontroller.py').read())
|
||||
except (RequestsExceptions.HTTPError, SpotipyExceptions.SpotifyException):
|
||||
print("An error has ocurred, saving and reestablishing application now.")
|
||||
except:
|
||||
print("An error has ocurred, reestablishing the application in 10 seconds.")
|
||||
sleep(10)
|
||||
exec(open('spotifycontroller.py').read())
|
||||
Reference in New Issue
Block a user