Sunday, July 28, 2013

Real-time meta data from Icecast using LiquidSoap

One of the annoying things about trying to pull metadata from Icecast is that it's a "pull". This is typically cron'd and can be as much as a minute "late". The following LiquidSoap script fixes this issue, allowing for a metadata "push".

The following listens to an Icecast stream and only extracts the metadata. It does not forward any audio. The below becomes valuable when you want to post "Now Playing" data to digital signage, IRC, or Jabber channels.







set("log.file",false)
set("log.stdout",false)
set("log.level",3)

def apply_metadata(m) =
title = m["title"]
print("Now playing: #{title}")
# system("~/Desktop/mytest.bash '#{title}'")
end

radio = input.http(
user_agent="joats/kludged-up-script",
timeout=30.,
poll_delay=.5,
new_track_on_metadata=true,
force_mime="audio/mpeg",
buffer=.5,
id="original",
"http://music.joat:8000/airtime_128"
)

radio = on_metadata(apply_metadata,radio)
output.dummy(fallible=true,radio)

Note that there's one line commented out in the above. It's there as an example, for when you want to pass the variable to an external script. About the only other line you'd need to change is the one containing "music.joat". Point that at your Icecast server.

Note: "output.dummy" is needed, to keep LiquidSoap from complaining that there's no output defined.