Compare commits

..

1 Commits

  1. 42
      music-api.py

42
music-api.py

@ -358,14 +358,6 @@ def extract_album_art(path: str, rel_path: str, timeout: int = 10): @@ -358,14 +358,6 @@ def extract_album_art(path: str, rel_path: str, timeout: int = 10):
return None
def display_title(path):
"""Convert 'dir/a/b/Song - Title.ext''Song - Title'."""
if not path:
return None
base = os.path.basename(path)
title, _ = os.path.splitext(base)
return title
# -----------------------------
# Pump helper for decoder -> wrapper
# -----------------------------
@ -616,20 +608,6 @@ def worker(): @@ -616,20 +608,6 @@ def worker():
global queue, shuffle_mode, repeat_mode
while True:
with queue_lock:
if not queue:
current_track = None
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)
stop_flag = False
try:
if stop_flag:
with queue_lock:
@ -660,6 +638,22 @@ def worker(): @@ -660,6 +638,22 @@ def worker():
# No station id files; reset timer so we don't spin
last_station_id_time = time.time()
with queue_lock:
if not queue:
current_track = None
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
# Shuffle only when building the play order
if shuffle_mode:
with queue_lock:
@ -794,7 +788,7 @@ def album_art(name): @@ -794,7 +788,7 @@ def album_art(name):
@app.get("/queue")
def get_queue():
with queue_lock:
return jsonify([display_title(item) for item in queue])
return jsonify(list(queue))
@app.post("/queue")
def add_to_queue():
@ -821,7 +815,7 @@ def now_playing(): @@ -821,7 +815,7 @@ def now_playing():
art_name = TRACKS[current_track].get("album_art")
if art_name:
art = f"/album_art/{art_name}"
return jsonify({"track": display_title(current_track), "album_art": art})
return jsonify({"track": current_track, "album_art": art})
@app.post("/shuffle")
def set_shuffle():

Loading…
Cancel
Save