Skip to content

Instantly share code, notes, and snippets.

@maietta
Created October 8, 2023 20:15
Show Gist options
  • Save maietta/63b656055db1ddbd238ace20c8bdb7a7 to your computer and use it in GitHub Desktop.
Save maietta/63b656055db1ddbd238ace20c8bdb7a7 to your computer and use it in GitHub Desktop.
Shoutcast Relay with Timestamped Slicing
# Set log level
set("log.level", 4)
# Capture the remote Shoutcast stream
input_stream = input.http("http://your.shoutcast.server/stream")
# Function to add breaks every minute
def add_breaks(~duration, s) =
let duration = duration * 60. in
sequence([s, blank(duration)])
end
# Add breaks every minute to the input stream
sliced_input = add_breaks(1., input_stream)
# Function to save a slice every minute
def save_slice(m) =
timestamp = int_of_float(gettimeofday())
filename = "/path/to/save/directory/"^timestamp^".mp3"
output.file(%mp3, fallible=true, append=true, filename, m)
end
# On each "track" (every minute), save a slice
sliced_input = on_track(save_slice, sliced_input)
# Relay the stream to an Icecast server
output.icecast(
%mp3,
host = "your.icecast.server",
port = 8000,
password = "yourpassword",
mount = "relay",
input_stream
)
# Play the sliced input (this is necessary to ensure the on_track function is triggered)
output.dummy(sliced_input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment