Skip to content

Instantly share code, notes, and snippets.

@francosolerio
Created November 28, 2014 15:34
Show Gist options
  • Select an option

  • Save francosolerio/e624ba55c2a663ac6b1d to your computer and use it in GitHub Desktop.

Select an option

Save francosolerio/e624ba55c2a663ac6b1d to your computer and use it in GitHub Desktop.
Digitalia liquidsoap Script
set("server.telnet",true)
set("server.timeout",300.)
# A function applied to each metadata chunk
def append_title(m) =
# Grab the current title
title = m["title"]
# Return a new title metadata
[("title","#{title} - puntata registrata")]
end
# A function applied to each metadata chunk
def replace_artist(m) =
# Return a new artist metadata
[("artist","Digitalia.fm")]
end
# This functions outputs current playing song to the log and to the s3 bucket
def log_now_playing(m) =
title = m["title"]
artist = m["artist"]
metadatastring=
if artist=="" then
log("Now playing: #{title}")
"#{title}"
else
log("Now playing: #{title} by #{artist}")
"#{artist} - #{title}"
end
system("echo '#{metadatastring}' > /tmp/song.html")
system("/etc/liquidsoap/upload_to_s3.sh")
end
# This function adds the replay_gain metadata to a source
# using the liquidsoap script extract-replaygain
def add_replaygain(m) =
# Get the source
# The replaygain script is located there
script = "#{configure.libdir}/extract-replaygain"
# The file name is contained in this value
filename = m["filename"]
info = list.hd(get_process_lines("#{script} '#{filename}'"))
[("replay_gain",info)]
end
# Our custom crossfade that
# only crossfade between tracks
def my_crossfade(s) =
# Our transition function
def f(_,_, old_m, new_m, old, new) =
# If none of old and new have "type" metadata
# with value "jingles", we crossfade the source:
log ("Old song: " ^ old_m["source"] ^ " - " ^ old_m["title"])
log ("New song: " ^ new_m["source"] ^ " - " ^ new_m["title"])
if old_m["source"] != "jingles" and new_m["source"] != "jingles" and old_m["source"] != "" and new_m["source"] != "" then
log("fading")
add (normalize=false, [fade.initial(new), fade.final(old)])
else
log ("sequencing")
sequence([old,new])
end
end
# Now, we apply smart_cross with this function:
smart_cross(f,s)
end
# Define a transition that fades out the
# old source and plays the new source
#def to_live(old,new) =
# # Fade out old source
# old = fade.final(old)
# # Superpose the jingle
# add([new,old])
#end
# A transition when switching back to files:
def to_file(old,new) =
# We skip the file
# currently in new
# in order to being with
# a fresh file
source.skip(new)
sequence([old,new])
end
# Define a transition that fades out the
# old source, adds a single, and then
# plays the new source
def to_live(jingle,old,new) =
# Fade out old source
old = fade.final(old)
# Superpose the jingle
s = add (normalize=false, [jingle,old])
# Compose this in sequence with
# the new source
sequence([s,new])
end
#smalls - playlist of very short songs for debugging rotation
#notpodsafe = playlist("/home/franco/liquidsoap/smalls/normsmall/")
#podsafe = playlist("/home/franco/liquidsoap/smalls/podsmall/")
notpodsafe = playlist(conservative=true, "/home/franco/liquidsoap/songs/")
podsafe = playlist(conservative=true, "/home/franco/liquidsoap/podsafe/")
jingles = playlist(conservative=true, mode = "randomize", "/home/franco/liquidsoap/jingles/")
#podcastfeed = playlist(mime_type = "application/rss+xml", "http://digitalia.fm/digitalia.xml")
fuoriondafeed = playlist(mime_type = "application/rss+xml", "http://digitalia.fm/fuorionda.xml")
security = single("/home/franco/liquidsoap/potw.mp3")
# Apply map_metadata to s using append_title
fuoriondafeed = map_metadata(replace_artist, fuoriondafeed)
set("harbor.bind_addr","0.0.0.0")
live = input.harbor("live",port=7999,password="THEPASSWORD", max = 30.0, buffer = 10.0)
output.dummy(fallible=true, live)
radio = random(weights=[10,1], [podsafe, notpodsafe])
radio_with_replays = random(weights=[10,1], [radio, fuoriondafeed])
radio = switch( [ ({ 23h30m-20h00m },radio_with_replays), ({ 20h00m-23h30m }, radio)])
radio = rotate(weights=[1,3], [jingles, radio])
radio = my_crossfade(radio)
jingle = single(conservative=true, "/home/franco/liquidsoap/jingles/Jingle Digitalia Acappella.mp3")
to_live_with_jingle = to_live(jingle)
radio = fallback(track_sensitive=false, transitions=[to_live_with_jingle, to_file], [live, radio])
radio = map_metadata(add_replaygain,radio)
radio = amplify(override="replay_gain",1.,radio)
radio = on_metadata(log_now_playing, radio)
radio = fallback(track_sensitive = false, [radio, security])
# Icecast outputs
usual = %mp3(bitrate=64, samplerate=44100, stereo=true)
output.icecast(usual, name="Digitalia.fm", description="Main streaming channel", genre="tech-talk", host="localhost", url="http://digitalia.fm", port = 8000, password = "PASSWORD", mount = "mp3", radio)
half = %mp3(bitrate=32, samplerate=44100, stereo=false)
output.icecast(half, name="Digitalia.fm - LoFi", description="Low bandwidth channel", genre="tech-talk", host="localhost", url="http://digitalia.fm", port = 8000, password = "PASSWORD", mount = "lofi", mean(radio))
ogg = %vorbis(samplerate=44100, channels=2)
output.icecast(ogg, name="Digitalia.fm - OggVorbis", description="OggVorbis channel", genre="tech-talk", url="http://digitalia.fm", host="localhost", port = 8000, password = "PASSWORD", mount = "ogg", radio)
ogglofi = %vorbis(samplerate=44100, channels=2, quality=0.1)
output.icecast(ogglofi, name="Digitalia.fm - Ogg LoFi", description="OggVorbis low bandwidth channel", genre="tech-talk", url="http://digitalia.fm", host="localhost", port = 8000, password = "PASSWORD", mount = "ogglofi", radio)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment