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,18 +11,34 @@ source_pw = environment.get(default="", "SOURCE_PW")
def make_deck(dir) = def make_deck(dir) =
files = ref([]) files = ref([])
cursor = ref(0) cursor = ref(0)
last_played = ref("")
def reload_and_shuffle() = 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 cursor := 0
end end
def next_file() = def next_file() =
if !cursor >= list.length(!files) then reload_and_shuffle() end if !cursor >= list.length(!files) then reload_and_shuffle() end
if list.length(!files) == 0 then "" else
f = list.nth(default="", !files, !cursor) f = list.nth(default="", !files, !cursor)
cursor := !cursor + 1 cursor := !cursor + 1
last_played := f
f f
end end
end
def next_request() = def next_request() =
f = next_file() f = next_file()
@ -30,12 +46,6 @@ def make_deck(dir) =
end end
def peek(n) = 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( list.init(
min(n, list.length(!files) - !cursor), min(n, list.length(!files) - !cursor),
fun(i) -> list.nth(default="", !files, !cursor + i) fun(i) -> list.nth(default="", !files, !cursor + i)