View Single Post
Old 21st February 2015, 10:24   #2
dopelabs
Major Dude
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 534
Send a message via AIM to dopelabs
DL’s Streaming Toolbox: How to Liquidsoap

http://www.dlnetworks.net/tools/stre...ox-liquidsoap/

install liquidsoap

the following commands were tested on a fresh/default install of ubuntu server 14.04 lts, and is expected you already have an ice/shoutcast server running, and know your way around the linux command line.

you can find a list of the available liquidsoap packages for install by searching the apt list:

code:
$ sudo apt-cache search liquidsoap


i take the easy route and just go ahead and also install all the supported streaming plugins as well.

code:
$ sudo apt-get install liquidsoap liquidsoap-plugin-all


once installed you are ready to write a script.

this example will have the following functions/capabilities:

the script runs in the background (deamon mode)
plays local mp3’s listed in a playlist file (txt)
immediately switch to live dj (and back) on connect/disconnect
play a local backup file of any of the above fails for any reason
manually set title via url GET request (http://127.0.0.1:8080/setmeta?title=SongTitleGoesHere)
output the stream to multiple instances of shoutcast at different bit rates and formats (transcoding)

to execute simply
code:
$ ./whateveryouwant.liq


create a file containing the following and name it whateveryouwant.liq and edit values as needed
code:
#!/usr/bin/liquidsoap

# run this script in the background
set("init.daemon",true)

# do not create a pid file
set("init.daemon.pidfile",false)

# set the path and permissions for the logfile
set("log.file.path","/home/user/log/liquidsoap.log")
set("log.file.perms",755)
set("log.unix_timestamps",true)

# local ip address to bind and listen for input (dj or metadata)
set("harbor.bind_addr","127.0.0.1")

# port and pass for live djs to connect to (shoutcast protocol)
live = input.harbor(icy=true,"/",port=8888,password="PASS")

# path to playlist file which contains a list of local mp3's (/home/user/mp3/song.mp3)
playlist = playlist("/home/user/mp3/playlist.txt")

# path to failover song if all above fails
emergency = single("/home/user/mp3/backup.mp3")

# do not monitor for silence and specify the fallback/priority order
radio = fallback(track_sensitive=false,[live,playlist,emergency])

# function to manually change song title
title = insert_metadata(radio)
insert = fst(title)
radio = snd(title)

def set_meta(~protocol,~data,~headers,uri) =
title = url.split(uri)
meta = metadata.export(snd(title))
ret = if meta != [] then insert(meta) "OK!" else "No metadata to add!" end
http_response(protocol=protocol,code=200,headers=[("Content-Type","text/html")],data="#{ret}") end

# port to register metadata updates via http
harbor.http.register(port=8080,method="GET","/setmeta",set_meta)

# shoutcast servers to broadcast to
output.shoutcast(%mp3(bitrate=256,samplerate=44100,stereo=true),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 8000,password = "PASS",radio)
output.shoutcast(%mp3(bitrate=128,samplerate=44100,stereo=true),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 8002,password = "PASS",radio)
output.shoutcast(%mp3(bitrate=64,samplerate=44100,stereo=true),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 8004,password = "PASS",radio)
output.shoutcast(%mp3(bitrate=24,samplerate=22050,stereo=true),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 8006,password = "PASS",radio)
output.shoutcast(%aac(bitrate=256),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 9000,password = "PASS",radio)
output.shoutcast(%aac(bitrate=128),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 9002,password = "PASS",radio)
output.shoutcast(%aac(bitrate=64),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 9004,password = "PASS",radio)
output.shoutcast(%aac(bitrate=24),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 9006,password = "PASS",radio)



another example, relay a shoutcast stream

relay.liq
code:
#!/usr/bin/liquidsoap

# set the path and permissions for the logfile
set("log.file.path","/home/user/log/liquidsoap.log")
set("log.file.perms",755)
set("log.unix_timestamps",true)

# stream url to relay (source)
url = "http://127.0.0.1:9000"
relay = mksafe(input.http(url))
radio = fallback(track_sensitive=false,[relay])

# shoutcast server to broadcast to
output.shoutcast(%mp3(bitrate=256,samplerate=44100,stereo=true),name="RADIO NAME",genre="GENRE",host="127.0.0.1",port = 8000,password = "PASS",radio)



other samples can be found on the liquidsoap website http://liquidsoap.fm/doc-svn/scripts
dopelabs is offline   Reply With Quote