Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP use reopen_when with output.file #11

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions liquidsoap/radio.liq
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ last_dj_disconnected = ref ""
current_dj_connected_at = ref 0.0
last_dj_disconnected_at = ref 0.0
current_dump_filename = ref ""
next_dump_filename = ref ""

stop_dump_f = ref (fun () -> ())

Expand Down Expand Up @@ -141,30 +142,42 @@ end

def on_connect(headers) =
log("on_connect")
log("current_dj: #{!current_dj}")
list.iter(fun(header)-> log("#{fst(header)}: #{snd(header)}"), headers)
# if they disconnected over 60 seconds ago, use new filename
log("current_dj_connected_at: #{!current_dj_connected_at}")
log("last_dj_disconnected_at: #{!last_dj_disconnected_at}")
if (!last_dj_disconnected_at == 0.0) then
log("*****************************************CREATING NEW DUMP, last_dj_disconnected_at is null***************************************************")
current_dump_filename := "#{!current_dj}-#{localtime(!current_dj_connected_at, format_time)}"
next_dump_filename := "#{!current_dj}-#{localtime(!current_dj_connected_at, format_time)}"
log("sending live notification")
ret = get_process_lines("./live_notification.sh 'LIVE - #{!current_dj}'")
ret = list.hd(default="",ret)
log(ret)
elsif (((!current_dj_connected_at - !last_dj_disconnected_at) > 60.0) or (!current_dj != !last_dj_disconnected)) then
log("*****************************************CREATING NEW DUMP***************************************************")
current_dump_filename := "#{!current_dj}-#{localtime(!current_dj_connected_at, format_time)}"
next_dump_filename := "#{!current_dj}-#{localtime(!current_dj_connected_at, format_time)}"
log("sending live notification")
ret = get_process_lines("./live_notification.sh 'LIVE - #{!current_dj}'")
ret = list.hd(default="",ret)
log(ret)
else
log("*****************************************APPENDING TO PREVIOUS DUMP***************************************************")
# else append to the old file (dont change the current_dump_filename)
end
log("current_dump_filename: #{!current_dump_filename}")
log("next_dump_filename: #{!next_dump_filename}")
end

def reopen_when() =
if !current_dump_filename != !next_dump_filename then
log("current_dump_filename != next_dump_filename !! reassigning current to next...")
current_dump_filename := !next_dump_filename
log("current_dump_filename was assigned: #{!current_dump_filename}")
true
else
false
end
# else append to the old file (dont change the current_dump_filename)
s = output.file(%mp3, "/home/liquidsoap/recordings/#{radio_name}-#{!current_dump_filename}.mp3", !live_dj, fallible=true, append=true)
stop_dump_f := fun () -> source.shutdown(s)
end

def on_disconnect() =
Expand All @@ -174,9 +187,7 @@ def on_disconnect() =
title_prefix := ""
last_dj_disconnected := !current_dj
current_dj := ""
sleep(60.0)
f = !stop_dump_f
f ()
next_dump_filename := ""
end

if crossfade_enabled == "true" then
Expand Down Expand Up @@ -228,6 +239,13 @@ source = on_track(pub_metadata, source)

source = server.insert_metadata(id="fallback", source)

def current_dump_filename_getter() =
log("in current_dump_filename_getter: #{!current_dump_filename}")
"/home/liquidsoap/recordings/#{radio_name}-#{!current_dump_filename}.mp3"
end

output.file(%mp3, current_dump_filename_getter, !live_dj, fallible=true, reopen_when=reopen_when, reopen_delay=0.0, append=true)

clock.assign_new(id="vorbis_icecast", [output.icecast(%vorbis,id="icecast",
mount="#{radio_name}.ogg",
host=icecast_host, port=int_of_string(icecast_port), password="hackme",
Expand Down