Created
November 29, 2021 21:15
-
-
Save evilchili/db139262ca2db8a959f92a4a34f5a741 to your computer and use it in GitHub Desktop.
liquidsoap controller script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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