jean-cloud-services/services/mux.radiokipik.org/liquidsoap.liq

85 lines
2.1 KiB
Plaintext
Raw Permalink Normal View History

2024-10-16 09:41:44 +00:00
#!/usr/bin/liquidsoap
# Extract timestamp from pige path
def ts_from_filepath (filepath)
splitpath = string.split(separator='/', filepath)
# Keep only filename
filename = list.nth(splitpath,list.length(splitpath)-1)
int_of_string(list.hd(string.split(separator='\\.', filename)))
end
# Remove pige from now-1month
def rm_pige(ts)
filepath = "/soundbase/pige/#{ts}.ogg"
if file.exists("#{filepath}") then
process.run("rm #{filepath}")
end
end
# Check that the timestamp starts exactly on a minute
def integrity_check(ts)
if ts mod 60 != 0 then
print("#{ts} is to fix")
end
end
# Routine integrity check for each files
def clean_and_check (filepath)
ts = ts_from_filepath (filepath)
# Remove if old
if ( ts < int_of_float(time()) - 2678400 ) then
rm_pige(ts)
end
integrity_check (ts)
end
def clean_and_check_latest (filepath)
ts = ts_from_filepath (filepath)
rm_pige(ts - 2678400) # ts of one month sooner
integrity_check (ts)
end
# Exaustive integrity check
def clean_and_check_all ()
list.iter(clean_and_check, file.ls("/soundbase/pige/"))
end
# Mux
#input1 = mksafe(input.harbor("direct.ogg",port=8000,password=getenv("ICECAST_SOURCE_PASSWORD")))
input1 = mksafe(input.http("http://icecast:8000/direct.ogg"))
# Direct mp3
# TODO faire du 44100 pour éviter les trous ?
output.icecast(
%mp3(bitrate=128, samplerate=22050, stereo=false),
mount="/direct.mp3",
#host="icecast", port=8000, password=getenv("ICECAST_SOURCE_PASSWORD"),
host="icecast", port=8000, password="JsCabjWJUZXrrrKCaaRZma5wD4YKj5LQLXv6f",
input1)
# Radioking
#output.icecast(
# %mp3(bitrate=128, samplerate=22050, stereo=false),
# mount="/test355",
# host="live.radioking.com", port=80, user="", password="",
# input)
# Direct ogg
#output.icecast(
# %vorbis(samplerate=44100, channels=1, quality=0.2),
# mount="/direct.ogg",
# host="icecast", port=8000, password=getenv("ICECAST_SOURCE_PASSWORD"),
# input1)
# Pige
output.file(%vorbis(samplerate=44100, channels=1, quality=0.2), {"/soundbase/pige/#{int_of_float(time())}.ogg"}, input1, reopen_when={0s}, reopen_delay=1.0, on_close=clean_and_check_latest)
# Integrity checks
clean_and_check_all()