(Is there a simpler solution I missed?)
import sqlite3
import time
from pathlib import Path
home = Path.home()
con = sqlite3.connect(f"{home}/.mixxx/mixxxdb.sqlite")
cur = con.cursor()
def get_track_name():
global cur
trackid = cur.execute("SELECT * FROM PlaylistTracks WHERE id=(SELECT max(id) FROM PlaylistTracks);").fetchall()[0][2]
trackname = cur.execute(f"SELECT * FROM library WHERE id={trackid};").fetchall()[0][2]
return trackname
now_playing = get_track_name()
print(now_playing)
while True:
if (np := get_track_name()) != now_playing:
now_playing = np
print(np)
time.sleep(1)
Edit: FWIW, unbox [1] uses the same approach.
Edit 2: yes, I should have cleaned up my SQL statements.[1] https://github.com/erikrichardlarson/unbox/blob/2182f227a0fc...
Someone has posted something similar, but it was literally just about 10 lines of python that read the right key in the dictionary and then posted that to a flask web page that another part of the system read to know what track was being played. I'm not a great programmer and it took me maybe 15 minutes to do, so it should be easy enough!
Also, your channel is fantastic. You’re a good teacher and your voice is excellent.
But..... If its always in a SQLite DB you should be able to use DB Browser for SQLite to inspect the DB Schema and then write a bash/python (whatever) script to pull the info out.
RESULTS=$(sqlite-utils "data.db" " SELECT song, artist, duration, FROM my_table WHERE song = 'CURRENT';")
RESULTS=$(sqlite3 data.db <<EOF SELECT song, artist, duration, FROM my_table WHERE song = 'CURRENT'; EOF )
I have no idea what the schema looks like but those are just some examples of how straightforward it might be. Run it on CRON (whatever) update as needed. https://cronitor.io/guides/python-cron-jobs
Once you have the Schema an LLM could most likely do the rest if you are not a programmer, but still need someone to get it added to the site.