|
|
|
|
@ -175,6 +175,12 @@ def pick_station_id_file():
@@ -175,6 +175,12 @@ def pick_station_id_file():
|
|
|
|
|
return None |
|
|
|
|
return os.path.join(STATION_ID_DIR, random.choice(files)) |
|
|
|
|
|
|
|
|
|
def pick_random_track(): |
|
|
|
|
"""Return a random music track (relative path) from TRACKS.""" |
|
|
|
|
if not TRACKS: |
|
|
|
|
return None |
|
|
|
|
return random.choice(list(TRACKS.keys())) |
|
|
|
|
|
|
|
|
|
def set_rds(text: str): |
|
|
|
|
global rds_pipe |
|
|
|
|
try: |
|
|
|
|
@ -602,6 +608,20 @@ def worker():
@@ -602,6 +608,20 @@ 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: |
|
|
|
|
@ -632,18 +652,6 @@ def worker():
@@ -632,18 +652,6 @@ 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: |
|
|
|
|
write_silence(0.25) |
|
|
|
|
time.sleep(0.5) |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
# Shuffle only when building the play order |
|
|
|
|
if shuffle_mode: |
|
|
|
|
with queue_lock: |
|
|
|
|
|