Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not sure whether that's the correct way but it seems to work. AFAICT, there is no "now_playing" field in the sqlite db - but tracks that start playing are added to the `PlaylistTracks` table. That means that if you started two tracks and then pause one or the other and restart it, no row will be added. Only adding a track from the library and then playing it will add to the PlaylistTracks list.

(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...



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: