Skip to content

Instantly share code, notes, and snippets.

@jamestomasino
Last active September 30, 2020 10:14
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 jamestomasino/a5a518b98db6089659f14e6d665a381a to your computer and use it in GitHub Desktop.
Save jamestomasino/a5a518b98db6089659f14e6d665a381a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# credentials for stream
TILDE_USER=""
TILDE_PASS=""
# don't return a * if no files found in glob
shopt -s nullglob
# change to directory where script is and run everything there
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR" || exit 1
# get list of files in current directory
files=(./*.mp3)
# if there are files in the current directory, process
if [ -n "${files[*]}" ]; then
# store reference to the 1st file in directory
next="${files[0]}"
# create a new playlist of only that 1 file
printf "%s\\n" "$next" | sed 's?\./??'> "tracks.pls"
# stream that playlist, then stop stream when it's done
liquidsoap "output.icecast(%mp3(bitrate=192), \
host='radio.tildeverse.org', \
port=8005, \
user=\"${TILDE_USER}\", \
password=\"${TILDE_PASS}\", \
mount='/', \
fallible=true, \
on_stop=shutdown,audio_to_stereo(playlist.once('tracks.pls')))"
fi
# trap any exit from this program for cleanup
function finish {
# if there's a playlist, process it
if [[ -f "tracks.pls" ]]; then
# if we haven't created a "done" directory, do that now
if [ ! -d "./done" ]; then
mkdir "./done"
fi
# move our played file to the done folder
mv "$next" "./done/"
# remove playlist
rm "tracks.pls"
fi
}
trap finish EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment