Ampache on Icecast

Afterster edited this page Jan 6, 2016 · 9 revisions

Ampache can easily serve an Icecast / Icecast2 server using Ices and script module.

Ices configuration

Create a regular Ices configuration file and setup the following input module parameters:

<input>
   <param name="type">script</param>
   <param name="program">/etc/ices/get_random.sh</param>
</input>

Ampache script file

get_random.sh, located in this example under /etc/ices

#!/bin/bash

########################
## Configuration Begin #
########################

ICES_TMP=/tmp                    # Temporary folder for cache
AMPACHE=http://localhost/ampache # Ampache server url
NBCACHE=3                        # Number of tracks to cache

########################
## Configuration End   #
########################


i=$(<$ICES_TMP/ampcache_index)

# For first track, do initial cache
dli=0
back=' &'
if [ $i -eq 0 ]; then
   let dli+=$NBCACHE
   back=''
fi

while [ $dli -gt -1 ]; do
   li=$i
   let li+=$NBCACHE
   let li-=$dli
   if [ $li -ge 10 ]; then
      let li-=9
   fi

   dlcmd="wget ${AMPACHE}'/play/?uid=-1&random=1&transcode_to=ogg' -o /dev/null -O ${ICES_TMP}/last_${li}.ogg${back}"
   eval $dlcmd
   let dli-=1
done

echo $ICES_TMP/ampcache_$i.ogg

((i++))
if [ $i = 10 ]; then
   i=1
fi
echo $i>$ICES_TMP/ampcache_index

Start the source

  • Create the following script start.sh
rm /tmp/ampcache_*.ogg -f
echo '0'>/tmp/ampcache_index
ices /etc/ices/ices.xml
  • chmod +x start.sh
  • ./start.sh