Skip to content

Instantly share code, notes, and snippets.

@hiredman
Created August 23, 2014 02:17
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 hiredman/4439981298c9ac71fd7b to your computer and use it in GitHub Desktop.
Save hiredman/4439981298c9ac71fd7b to your computer and use it in GitHub Desktop.
#/bin/sh
if which jot; then
# osx, bsd
PORT=`jot -r 1 60000 65000`
else
# linux
PORT=`shuf -i 60000-65000 -n 1`
fi
playlist_url=$1
url_base="http://"`hostname`":$PORT"
DIR=`mktemp -d /tmp/homesXXX`
cleanup() {
echo "dying"
kill -9 `cat $DIR/twistd.pid`
rm -rf $DIR
exit
}
trap cleanup SIGHUP SIGINT SIGTERM
cd $DIR
# 140 is m4a, but not all videos will have it, so this should really check
youtube-dl -i -f140 --output '%(autonumber)s.%(ext)s' "$playlist_url"
ls *.m4a > audio.txt
# SimpleHTTPServer would fail to serve the whole song for some reason
twistd web --path=. -p $PORT
for i in `cat audio.txt`; do
echo "adding " $url_base/$i
mpc add $url_base/$i
done
# wait until the urls we've queued up are no longer in the mpd
# playlist
while mpc playlist|grep -q "$url_base"
do sleep 60
done
cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment