Skip to content

Instantly share code, notes, and snippets.

@evilchili
Created August 22, 2021 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilchili/003e478876ca478c72c1930b7dc6d837 to your computer and use it in GitHub Desktop.
Save evilchili/003e478876ca478c72c1930b7dc6d837 to your computer and use it in GitHub Desktop.
dnd audio streaming command and control
set("server.telnet",true)
set("request.grace_time", 3.0)
set("init.daemon.pidfile.path", "run/liquidsoap.pid")
# deeebuggin
# set("log.file.path","<script>.log")
# set up the stream
stream = crossfade(normalize(playlist.safe(
id='stream', reload_mode='watch',
'stream.txt',
)))
# if source files don't contain metadata tags, use the filename
def apply_metadata(m) =
title = m["title"]
print("Now Playing: #{m['filename']}")
if (title == "") then
[("title", "#{path.remove_extension(path.basename(m['filename']))}")]
else
[("title", "#{title}")]
end
end
# apply the metadata parser
stream = map_metadata(apply_metadata, stream)
# define the source. ignore errors and provide no infallibale fallback. yolo.
radio = fallback(track_sensitive=false, [stream])
# transcode to icecast
output.icecast(
%mp3.vbr(quality=3),
name='Frog Hat Radio',
description='Background music for Dungeons and Dragons',
host="localhost",
port=5230,
password="********",
mount="dnd",
icy_metadata="true",
url="*********",
fallible=true,
radio
)
# The directory containing the liquidsoap config, playlists, and so on.
BASE_DIR=/dnd
# The liquidsoap executable
LIQUIDSOAP=/home/evilchili/.opam/default/bin/liquidsoap
# command-line parameters for liquidsoap
LIQUIDSOAP_ARGS="--daemon $BASE_DIR/dnd.liq"
# The filename that defines the current stream playlist
STREAM="${BASE_DIR}/stream.txt"
# The pidfile of the liquidsoap daemon
PIDFILE="${BASE_DIR}/run/liquidsoap.pid"
sources/intro/01 Desktop Destiny.mp3
# 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