Compare commits

..

2 Commits

  1. 27
      music-api.py

27
music-api.py

@ -175,20 +175,11 @@ def pick_station_id_file():
return None return None
return os.path.join(STATION_ID_DIR, random.choice(files)) return os.path.join(STATION_ID_DIR, random.choice(files))
### FIXME:
def pick_random_track(): def pick_random_track():
conn = sqlite3.connect(DB_PATH) """Return a random music track (relative path) from TRACKS."""
c = conn.cursor() if not TRACKS:
c.execute(""" return None
SELECT path return random.choice(list(TRACKS.keys()))
FROM tracks
WHERE is_station_id = 0
ORDER BY RANDOM()
LIMIT 1
""")
row = c.fetchone()
conn.close()
return row[0] if row else None
def set_rds(text: str): def set_rds(text: str):
global rds_pipe global rds_pipe
@ -439,9 +430,6 @@ def restart_radio_chain():
print("[WATCHDOG] Restarting pifmadv") print("[WATCHDOG] Restarting pifmadv")
start_pifm() start_pifm()
print("[WATCHDOG] Restarting persistent WAV wrapper")
start_persistent_wav()
# Your addition: broadcast station ID # Your addition: broadcast station ID
id_file = pick_station_id_file() id_file = pick_station_id_file()
if id_file: if id_file:
@ -656,17 +644,16 @@ def worker():
empty = True empty = True
else: else:
empty = False empty = False
### FIXME:
if empty: if empty:
write_silence(0.25)
time.sleep(0.5)
# Ensure the queue is never empty
track = pick_random_track() track = pick_random_track()
if track: if track:
print(f"[WORKER] Queue empty — adding random track: {track}") print(f"[WORKER] Queue empty — adding random track: {track}")
with queue_lock:
queue.append(track) queue.append(track)
continue continue
# Shuffle only when building the play order # Shuffle only when building the play order
if shuffle_mode: if shuffle_mode:
with queue_lock: with queue_lock:

Loading…
Cancel
Save