generated from nathanwoodburn/python-webserver-template
feat: Add a ton of features to make it better
All checks were successful
Build Docker / BuildImage (push) Successful in 2m15s
All checks were successful
Build Docker / BuildImage (push) Successful in 2m15s
This commit is contained in:
44
song-hook.py
Executable file
44
song-hook.py
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
from datetime import datetime
|
||||
# "PLAYER_EVENT": "Player Event",
|
||||
# "TRACK_ID": "Track ID",
|
||||
# "TRACK_COVER": "Track Cover",
|
||||
# "endoftrack": "End of Track",
|
||||
ENVLOGS = {
|
||||
"CLIENT_NAME": "Device Connected",
|
||||
"VOLUME": "Volume Level",
|
||||
"AUTOPLAY": "Autoplay Status",
|
||||
"SHUFFLE": "Shuffle Status",
|
||||
"REPEAT": "Repeat Status",
|
||||
"TRACK_NAME": "Song Name",
|
||||
}
|
||||
PLAYER_EVENTS = {
|
||||
"start": "Playing Song",
|
||||
"change": "Changing Song",
|
||||
}
|
||||
|
||||
LOG_FILE = "/home/nathan/Git/spotifyd-webui/server.log"
|
||||
|
||||
def main():
|
||||
with open(LOG_FILE, "a") as f:
|
||||
# Get PLAYER_EVENT from environment variables
|
||||
player_event = os.getenv("PLAYER_EVENT", "Unknown Event")
|
||||
player_event = PLAYER_EVENTS.get(player_event, None)
|
||||
if player_event:
|
||||
f.write(player_event + "\n")
|
||||
for key, value in os.environ.items():
|
||||
# Only log specific environment variables using format {ENVLOGS[key]}: value
|
||||
if key in ENVLOGS:
|
||||
f.write(f"{ENVLOGS[key]}: {value}\n")
|
||||
|
||||
# Save current name and cover
|
||||
track_name = os.getenv("TRACK_NAME", None)
|
||||
track_cover = os.getenv("TRACK_COVER", None)
|
||||
if track_name and track_cover:
|
||||
with open("current_track.json", "w") as f:
|
||||
f.write(f'{{"name": "{track_name}", "cover": "{track_cover}"}}\n')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user