Skip to content

Instantly share code, notes, and snippets.

@evilchili
Created November 29, 2021 21:15
Show Gist options
  • Save evilchili/db139262ca2db8a959f92a4a34f5a741 to your computer and use it in GitHub Desktop.
Save evilchili/db139262ca2db8a959f92a4a34f5a741 to your computer and use it in GitHub Desktop.
liquidsoap controller script
#!/bin/bash -e
#
# s -- stream controller
#
# Usage:
#
# s PLAYLIST -- Switch to the specified playlist file. Starts liquidsoap if it isn't running.
# s -- Skip to a random track from the current playlist.
# s stop -- Shutdown liquidsoap
#
# Load environment variables:
#
# $LIQUIDSOAP
# $BASE_DIR
# $STREAM
# PIDFILE
source ./env
PLAYLIST="${BASE_DIR}/$1"
start_liquidsoap() {
if [ -f $PIDFILE ] && ps -p $(cat $PIDFILE) &> /dev/null; then
return
fi
echo "Liquidsoap does not appear to be running. Starting it..."
$LIQUIDSOAP $LIQUIDSOAP_ARGS
sleep 1
}
rebuild_playlist() {
if [ -e $PLAYLIST ]; then
name=$(basename -- "$1")
name="${name%.*}"
echo "Switching to [${name}] music..."
unlink $STREAM
ln -s $PLAYLIST $STREAM
sleep 2
skip
else
echo "File not found: $1"
fi
}
skip() {
echo 'Frog_Hat_Radio.skip'| nc -N localhost 1234 || echo "Could not contact liquidsoap. Is it running?"
sleep 1
}
if [ "$1" = "stop" ]; then
echo "Shutting down..."
if [ -f $PIDFILE ]; then
kill $(cat $PIDFILE)
fi
else
start_liquidsoap
if [ "$1" ]; then
rebuild_playlist $1
else
skip
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment