fix(liquidsoap): deck filters audio, guards empty, avoids cross-deck repeat

This commit is contained in:
devilreef 2026-04-30 14:59:17 +06:00
parent fcb783ffca
commit 68a02ff250
Signed by: devilreef
SSH key fingerprint: SHA256:UZisRr4iuXx+IhkbZnR655L2RWAT6o2rgbGv5F/6m3Y

View file

@ -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)