User Scripts
Here are various example scripts and their descriptions to help you get started. Please feel free to contribute your own here to help others out.
Radio Station for a UK hospital
Automated radio station - in use by a UK hospital via their Patientline system -- contributed by AndyBrown?
#!/usr/local/bin/liquidsoap
# Define the logfile and disable output to console as this program runs as a daemon/background process
set("log.file.path","/home/audio/liquidsoap.log")
set("log.stdout", false)
# day is our folder full of normal music tracks
# jingles is our folder with a few jingles and audio fillers with the station identifiers
# security is an ogg file to play if we have serious problems and just need to output something
day = playlist("/home/audio/music")
jingles = playlist("/home/audio/jingles")
security = single("/home/audio/stream_failure.ogg")
# Load the variable radio with the day playlist folder
radio = day
# Add in the jingles using a random with a 1:1 weight and set the delay to 1. which means we should never get two consecutive jingles
radio = random(weights = [1, 1], [delay(1.,jingles), radio])
# Set the fallback audio to the security audio file
radio = fallback(track_sensitive = false, [radio, security])
# Use the smart crossfader to transition between tracks using fade in and out of 0.5 seconds
radio=smart_crossfade(fade_out=0.5,fade_in=0.5,radio)
# When blank/silence is detected of -28dB for more than 3 seconds then skip track/advance to next track
radio = skip_blank(threshold=-28.,length=3.,radio)
# Normalise and compress the audio stream -- NOTE: this causes pops and over-loudness, needs fixed!
radio = nrj(radio)
# Rewrite/force the meta data to the following two parameters - i.e. doesn't show current song data in the metadata at all
radio=rewrite_metadata([("artist", "Hospital Radio"),
("title","Hospital Radio")],radio)
# Now output the stream to the local icecast server in mp3 and ogg format (Debian needed a recompile to allow vorbis and mp3 encoding)
output.icecast.mp3(host="localhost",port=8000,password="mypass",mount="hospital-mp3",bitrate=64,radio)
output.icecast.vorbis(host="localhost",port=8000,password="mypass",mount="hospital.ogg",radio)
Radio Clave
http://radioclave.se sends salsa music live daily between 15:00 and 21:00 GMT+1. Contributed by Karim Ryde
#!/usr/bin/liquidsoap
# Use the telnet server for requests
#set( "server.telnet", true )
# Log dir
set( "log.file.path", "/var/log/liquidsoap/radioclave.log" )
set( "log.level", 5 )
# Server settings for live source
set( "harbor.bind_addr", "0.0.0.0" )
set( "harbor.port", 8080 )
set( "harbor.password", "xxxx" )
# Accept incoming live source from Winamp or Oddcast
# When live is up trigger website scripts
def live_start()
system( "/home/radioclave2/scripts/live_start.py &" )
end
def live_stop()
system( "/home/radioclave2/scripts/live_stop.py &" )
end
live = input.harbor( on_connect = live_start, on_disconnect = live_stop, "Live" )
# Some more music in mp3 and mp4 (aac)
intro = single( "/home/radioclave2/salsa/intro/intro.mp3" )
normal = mksafe( playlist( "/home/radioclave2/playlists/sam.m3u" ) )
djlist_shuffle = playlist( "/home/radioclave2/playlists/djlist_shuffle.m3u" )
djlist_noshuffle = playlist( mode = "normal", "/home/radioclave2/playlists/djlist_noshuffle.m3u" )
# Load the current playlist
radio = fallback( track_sensitive = false, [djlist_shuffle, djlist_noshuffle, normal] )
# Normalize volume
#radio = normalize( radio )
# Crossfade songs 15 seconds
radio = smart_crossfade( fade_out = 15.0, fade_in = 15.0, start_next = 15.0, radio )
# Create the stream info
# When all available, show "artist - album (year) - title"
# When missing year, show "artist - album - title"
# When missing artist, show "album - title"
# When missing album, show "title"
# When missing title, show "filename"
def map( m )
# Get filename from file path
dollar = string.extract(pattern="([^/]*)\..*$", m["filename"])
filename = dollar["1"]
log( label="radioclave", level=5, "artist="^m["artist"] )
log( label="radioclave", level=5, "album="^m["album"] )
log( label="radioclave", level=5, "title="^m["title"] )
log( label="radioclave", level=5, "filename="^filename )
# Construct stream metadata from available id3 tags
if ( m["title"] == "" ) then
[ ("artist", "New"), ("title", filename) ]
else
if ( m["album"] != "" ) then
if ( m["artist"] != "" ) then
if int_of_string( m["year"], default = 0 ) > 0 then
[ ("title", m["album"]^" ("^m["year"]^") - "^m["title"] ) ]
else
[ ("title", m["album"]^" - "^m["title"] ) ]
end
else
[ ("artist", "New"), ("title", m["album"]^" - "^m["title"] ) ]
end
else
[ ("title", m["title"] ) ]
end
end
end
radio = map_metadata( map, radio )
# Send live source when active
# After 5 sec of blank the microphone stream is ignored,
# which causes the stream to fallback to radio.
# As soon as noise comes back to the microphone the stream comes back to the live
radio = fallback( track_sensitive = false, [ strip_blank( length=5., live ), radio ] )
# Send feedback to frontend system
def extern_feedback( m )
log( label="radioclave", level=5, "artist="^m["artist"] )
log( label="radioclave", level=5, "album="^m["album"] )
log( label="radioclave", level=5, "title="^m["title"] )
system( "/home/radioclave2/scripts/feedback.py "^ quote( m["artist"] ^" - "^ m["title"] ) ^" &" )
end
radio = on_metadata( extern_feedback, radio )
# Stream it out to Icecast2 server
output.icecast.mp3(
host = "localhost", port = 8005, password = "xxxx",
bitrate = 96, samplerate = 44100,
mount = "Radioclave", genre = "Salsa",
url = "http://radioclave.se", description = "Radio Clave",
radio )
# Save live transmission
output.file.mp3( "/home/radioclave2/live/live.mp3", live )
