Icecast repository on Ubuntu 14.04 LTS

The version of icecast available in the 14.04 default repositories isn’t the most up to date. Rather than downloading the .deb package you can simply add their repository to your installation:

sudo sh -c "echo deb http://download.opensuse.org/repositories/multimedia:/xiph/xUbuntu_14.04/ ./ >>/etc/apt/sources.list.d/icecast.list"
wget -qO - http://icecast.org/multimedia-obs.key | sudo apt-key add -

Sources:

Shoutcast Streaming from the Command Line

One of the challenges I’ve had as the systems administrator for Still Stream is to automate the playback of a recorded show at a particular time. This probably sounds like a straight forward task but most of the current ShoutCast tools seem to be developed around a DJ broadcasting a live show, or the server playing playlists on repeat.

After giving this problem some thought I pinned down some requirements for a basic project:

  • Must be compatible with a ShoutCast v1 streaming server
  • Runnable on my Ubuntu Linux server
  • Streams one mp3 file and then quits
  • The mp3 file is to be specified at the command line
  • Task can be scheduled via cron or at

Researching these utilities wasn’t straight forward so I had to try sc_trans, icegenerator, and ezstream before I settled on liquidsoap. It’s a great all round tool which is highly configurable. Plus it’s included in the Ubuntu package collection.

To get a working set up I started by focusing on an XML file (stillstream.liq) to give liquidsoap its configuration details:

source = playlist.once("/home/innerteapot/Music/stillstream.m3u",                                              on_done={shutdown()} )

output.shoutcast(%mp3, host="yourserver.com",
        port=8765,
        password="supersecret",
        genre="Ambient",
        url="http://stillstream.fm/",
        name="Still Stream All Ambient",
        fallible=true,
        source)

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

The second part of the setup is a simple shell script to generate the playlist, stop the autodj, stream the file, and start the autodj again:

#!/bin/bash                                                                          
if [ "$#" -ne 1 ]                                                                    
then                                                                                 
    echo "usage: stillstream_broadcast "                               
    exit 1                                                                           
fi                                                                                   
echo "===> Preparing playlist"                                                      
echo `readlink -m "$1"` > /home/innerteapot/Music/stillstream.m3u                    
echo >> /home/innerteapot/Music/stillstream.m3u                                       
echo "===> Streaming"                                                                
date                                                                                 
curl "http://yourserver.com/api/?key=secretkey1234567890&action=stop" && \ 
echo && \                                                                            
liquidsoap /home/innerteapot/etc/stillstream.liq                                      
curl "http://yourserver.com /api/?key=secretkey1234567890&action=start" && \
echo                                                                                 
date    

I’m using the readlink command to get the full path to the file. I’ve also thrown in some && operators to ensure that the dj stop command is successfully triggered before liquidsoap attempts to run. The corresponding echo commands are there to improve the output formatting a little. Makes the resulting emails from the at scheduler easier to read.

Invoking using the at command goes something like this:

$ at 10pm                                            
warning: commands will be executed using /bin/sh                                     
at> stillstream_broadcast Music/AWE20141122-Nevermore02-128k.mp3                     
at>                                                                             

So there you have it. Streaming from the command line.

Now I can finally schedule Adventures in Sound 🙂