From 68a02ff250fdcd0778c87e144e96f31949863539 Mon Sep 17 00:00:00 2001 From: devilreef Date: Thu, 30 Apr 2026 14:59:17 +0600 Subject: [PATCH] fix(liquidsoap): deck filters audio, guards empty, avoids cross-deck repeat --- config/liquidsoap.liq | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/config/liquidsoap.liq b/config/liquidsoap.liq index ebc547c..4fd08d8 100644 --- a/config/liquidsoap.liq +++ b/config/liquidsoap.liq @@ -11,17 +11,33 @@ source_pw = environment.get(default="", "SOURCE_PW") def make_deck(dir) = files = ref([]) cursor = ref(0) + last_played = ref("") def reload_and_shuffle() = - files := list.shuffle(file.ls(dir, recursive=true, absolute=true)) + all = file.ls(dir, recursive=true, absolute=true) + audio_exts = ["flac", "mp3", "opus", "m4a", "wav", "ogg"] + audio = list.filter( + fun(f) -> list.mem(string.case(lower=true, path.extension(leading_dot=false, f)), audio_exts), + all + ) + files := list.shuffle(audio) + if !last_played != "" and list.length(!files) > 1 and list.nth(default="", !files, 0) == !last_played then + files := list.append( + [list.nth(default="", !files, 1), list.nth(default="", !files, 0)], + list.tl(list.tl(!files)) + ) + end cursor := 0 end def next_file() = if !cursor >= list.length(!files) then reload_and_shuffle() end - f = list.nth(default="", !files, !cursor) - cursor := !cursor + 1 - f + if list.length(!files) == 0 then "" else + f = list.nth(default="", !files, !cursor) + cursor := !cursor + 1 + last_played := f + f + end end def next_request() = @@ -30,12 +46,6 @@ def make_deck(dir) = end def peek(n) = - needed = !cursor + n - if needed > list.length(!files) and list.length(!files) > 0 then - # would exhaust the deck during peek; not worth pre-reshuffling. - # return whatever's left, the caller pads. - () - end list.init( min(n, list.length(!files) - !cursor), fun(i) -> list.nth(default="", !files, !cursor + i)