Compare commits

..

2 Commits

  1. 39
      music-api.py

39
music-api.py

@ -175,11 +175,20 @@ 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():
"""Return a random music track (relative path) from TRACKS.""" conn = sqlite3.connect(DB_PATH)
if not TRACKS: c = conn.cursor()
return None c.execute("""
return random.choice(list(TRACKS.keys())) 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): def set_rds(text: str):
global rds_pipe global rds_pipe
@ -430,6 +439,9 @@ 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:
@ -644,15 +656,16 @@ def worker():
empty = True empty = True
else: else:
empty = False empty = False
### FIXME:
if empty: if empty:
track = pick_random_track() write_silence(0.25)
if track: time.sleep(0.5)
print(f"[WORKER] Queue empty — adding random track: {track}") # Ensure the queue is never empty
with queue_lock: track = pick_random_track()
queue.append(track) if track:
continue print(f"[WORKER] Queue empty — adding random track: {track}")
queue.append(track)
continue
# Shuffle only when building the play order # Shuffle only when building the play order
if shuffle_mode: if shuffle_mode:

Loading…
Cancel
Save