Compare commits

..

2 Commits

  1. 39
      music-api.py

39
music-api.py

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

Loading…
Cancel
Save