denpa-radio/config/liquidsoap.liq

85 lines
2.3 KiB
Text

# denpa-radio liquidsoap script
# adding a station: copy a station block, rename, restart liquidsoap.
settings.log.stdout.set(true)
settings.log.level.set(3)
source_pw = environment.get(default="", "SOURCE_PW")
def emit_now_playing(station, m) =
filename = m["filename"]
if filename != "" then
payload = json()
payload.add("station", station)
payload.add("artist", m["artist"])
payload.add("title", m["title"])
payload.add("album", m["album"])
payload.add("filename", filename)
payload.add("duration", m["duration"])
payload.add("started_at", string(int_of_float(time())))
file.write(data=payload.stringify(), atomic=true, temp_dir="/now-playing", "/now-playing/#{station}.json")
end
end
def append_history(station, m) =
filename = m["filename"]
if filename != "" then
history_path = "/now-playing/#{station}.history.json"
existing =
if file.exists(history_path) then
file.contents(history_path)
else
"[]"
end
arr =
try
json.parse(default=([] : [json]), existing)
catch _ do
([] : [json])
end
entry = json()
entry.add("title", m["title"])
entry.add("artist", m["artist"])
entry.add("album", m["album"])
entry.add("filename", filename)
entry.add("started_at", string(int_of_float(time())))
new_arr = list.add(entry, list.prefix(50, arr))
out_str = json.stringify(new_arr)
file.write(data=out_str, atomic=true, temp_dir="/now-playing", history_path)
end
end
# === station: minecraft ===
minecraft = playlist(
reload_mode="watch",
mode="randomize",
"/library/minecraft/tracks"
)
minecraft.on_track(fun (m) -> begin
emit_now_playing("minecraft", m)
append_history("minecraft", m)
end)
minecraft = crossfade(minecraft)
minecraft = mksafe(minecraft)
output.icecast(
%mp3(bitrate=192, stereo=true),
host="icecast", port=8000, password=source_pw,
mount="/minecraft.mp3",
name="Denpa — Minecraft",
description="Minecraft soundtracks",
genre="game-ost",
url="https://denpa.femboy.page",
minecraft
)
output.icecast(
%opus(bitrate=96, vbr="constrained", samplerate=48000, channels=2),
host="icecast", port=8000, password=source_pw,
mount="/minecraft.opus",
name="Denpa — Minecraft",
description="Minecraft soundtracks",
genre="game-ost",
url="https://denpa.femboy.page",
minecraft
)