Skip to content

Instantly share code, notes, and snippets.

@cube-drone
Created March 20, 2019 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cube-drone/04d6d2931bf1a4ed92ce1b59d1b696bb to your computer and use it in GitHub Desktop.
Save cube-drone/04d6d2931bf1a4ed92ce1b59d1b696bb to your computer and use it in GitHub Desktop.
icecast and soap example
#!/bin/bash
SOAPSTORM_NAME=${SOAPSTORM_NAME:-My Radio Station}
SOAPSTORM_EMAIL=${SOAPSTORM_EMAIL:-me@sample.org}
SOAPSTORM_DOMAIN=${SOAPSTORM_DOMAIN:-mydomain.com}
SOAPSTORM_STREAM=${SOAPSTORM_STREAM:-MyRadioStation}
SOAPSTORM_USER=${SOAPSTORM_USER:-horfdorfborf}
SOAPSTORM_PASS=${SOAPSTORM_PASS:-glorpglorpglorp}
ICECAST_CONTAINER_NAME=${ICECAST_CONTAINER_NAME:-soapstorm-icecast}
ICECAST_USER=${ICECAST_USER:-blimpblimpblimp}
ICECAST_SOURCE_PASSWORD=${ICECAST_PASSWORD:-hurfdurfburf}
ICECAST_RELAY_PASSWORD=${ICECAST_PASSWORD:-harfdarfbarf}
ICECAST_ADMIN=${ICECAST_USER:-butterlola}
ICECAST_ADMIN_PASSWORD=${ICECAST_PASSWORD:-chumpwellington}
ICECAST_PORT=8000
LIQUIDSOAP_CONTAINER_NAME=${LIQUIDSOAP_CONTAINER_NAME:-soapstorm-liquidsoap}
LIQUIDSOAP_PORT=9051
LIQUIDSOAP_PASSWORD=${LIQUIDSOAP_PASSWORD:-feelgoodinc}
HOST_MUSIC_DIRECTORY=${HOST_MUSIC_DIRECTORY:-/data/dropbox/Dropbox/Music}
MOUNT_MUSIC_DIRECTORY=${MOUNT_MUSIC_DIRECTORY:-/tmp/music}
OFFLINE_FILE=${OFFLINE_FILE:-$MOUNT_MUSIC_DIRECTORY/Bounce Traxx/Broken Bells - 02 - After the Disco.mp3}
GROOVE_MOUNT_POINT=${MOUNT_POINT:-groove.ogg}
sudo docker kill $ICECAST_CONTAINER_NAME
sudo docker rm $ICECAST_CONTAINER_NAME
cat >./icecast.xml <<END
<icecast>
<location>$SOAPSTORM_NAME</location>
<admin>$SOAPSTORM_EMAIL</admin>
<limits>
<clients>100</clients>
<sources>30</sources>
<threadpool>5</threadpool>
<queue-size>524288</queue-size>
<client-timeout>30</client-timeout>
<header-timeout>15</header-timeout>
<source-timeout>10</source-timeout>
<burst-size>65535</burst-size>
</limits>
<authentication>
<source-password>$ICECAST_SOURCE_PASSWORD</source-password>
<relay-password>$ICECAST_RELAY_PASSWORD</relay-password>
<admin-user>$ICECAST_ADMIN</admin-user>
<admin-password>$ICECAST_ADMIN_PASSWORD</admin-password>
</authentication>
<hostname>$SOAPSTORM_DOMAIN</hostname>
<listen-socket>
<port>$ICECAST_PORT</port>
</listen-socket>
<fileserve>1</fileserve>
<paths>
<basedir>/usr/share/icecast2</basedir>
<logdir>/var/log/icecast2</logdir>
<webroot>/usr/share/icecast2/web</webroot>
<adminroot>/usr/share/icecast2/admin</adminroot>
<alias source="/" dest="/index.html"/>
</paths>
<logging>
<accesslog>access.log</accesslog>
<errorlog>error.log</errorlog>
<loglevel>3</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
<logsize>10000</logsize> <!-- Max size of a logfile -->
</logging>
<security>
<chroot>0</chroot>
<!--
<changeowner>
<user>nobody</user>
<group>nogroup</group>
</changeowner>
-->
</security>
<mount>
<mount-name>/$GROOVE_MOUNT_POINT</mount-name>
<public>1</public>
<stream-name>Groove</stream-name>
<stream-description>Running in the 90s</stream-description>
<stream-url>http://$DOMAIN</stream-url>
</mount>
</icecast>
END
sudo docker run \
-p 127.0.0.1:$ICECAST_PORT:$ICECAST_PORT \
--name $ICECAST_CONTAINER_NAME \
-v `pwd`/icecast.xml:/etc/icecast2/icecast.xml \
-d moul/icecast
sleep 1
ICECAST_HOST=`sudo docker inspect $ICECAST_CONTAINER_NAME | jq '.[0]["NetworkSettings"]["IPAddress"]' | sed -e 's/^"//' -e 's/"$//'`
echo "Icecast Container Name: " $ICECAST_CONTAINER_NAME
echo "Icecast Host: " $ICECAST_HOST
echo "Icecast Port: " $ICECAST_PORT
sudo docker kill $LIQUIDSOAP_CONTAINER_NAME
sudo docker rm $LIQUIDSOAP_CONTAINER_NAME
cat >./liquidsoap.liq <<END
#!/usr/bin/liquidsoap
set("log.level", 3)
set("log.file", false)
set("log.stdout", true)
enable_replaygain_metadata()
offline_file = single("$OFFLINE_FILE")
high_frequency = audio_to_stereo(playlist("$MOUNT_MUSIC_DIRECTORY/high_frequency"))
mid_frequency = audio_to_stereo(playlist("$MOUNT_MUSIC_DIRECTORY/medium_frequency"))
low_frequency = audio_to_stereo(playlist("$MOUNT_MUSIC_DIRECTORY/low_frequency"))
interludes = audio_to_stereo(playlist("$MOUNT_MUSIC_DIRECTORY/interludes"))
promos = audio_to_stereo(playlist("$MOUNT_MUSIC_DIRECTORY/promos"))
pre_radio = random(weights=[3, 2, 1, 1, 1], [high_frequency, mid_frequency, low_frequency, interludes, promos])
groove_radio = fallback(track_sensitive = false, [pre_radio, offline_file])
groove_radio = amplify(1., override="replay_gain", groove_radio)
output.icecast(%vorbis,
host = "$ICECAST_HOST", port = $ICECAST_PORT,
password = "$ICECAST_SOURCE_PASSWORD", mount = "$GROOVE_MOUNT_POINT",
groove_radio)
END
sudo docker run \
-p 127.0.0.1:$LIQUIDSOAP_PORT:$LIQUIDSOAP_PORT \
--name $LIQUIDSOAP_CONTAINER_NAME \
-v `pwd`/liquidsoap.liq:/tmp/config.liq \
-v $HOST_MUSIC_DIRECTORY:$MOUNT_MUSIC_DIRECTORY \
-d moul/liquidsoap \
sudo -H -u www-data bash -c 'liquidsoap --debug --verbose /tmp/config.liq'
sleep 1
LIQUIDSOAP_HOST=`sudo docker inspect $LIQUIDSOAP_CONTAINER_NAME | jq '.[0]["NetworkSettings"]["IPAddress"]' | sed -e 's/^"//' -e 's/"$//'`
echo "Liquidsoap Container Name: " $LIQUIDSOAP_CONTAINER_NAME
echo "Liquidsoap Host: " $LIQUIDSOAP_HOST
echo "Liquidsoap Port: " $LIQUIDSOAP_PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment