radiodump.sh

SH

No description

Guest

Download Edit

#!/bin/bash
# put the following (not out-commented) into your crontab:
#55 5 21 3 * /dir/radiodump.sh muelheim mplayer /dir/dumps >> /dir/radiomuelheim_mplayer.log &
#55 5 21 3 * /dir/radiodump.sh muelheim vlc /dir/dumps >> /dir/radiomuelheim_vlc.log &
#55 5 21 3 * /dir/radiodump.sh oberhausen mplayer /dir/dumps >> /dir/radiooberhausen_mplayer.log &
#55 5 21 3 * /dir/radiodump.sh oberhausen vlc /dir/dumps >> /dir/radiooberhausen_vlc.log &
#5 10 21 3 * kill `cat /tmp/radiomuelheim_mplayer.pid`
#5 10 21 3 * kill `cat /tmp/radiomuelheim_vlc.pid`
#5 10 21 3 * kill `cat /tmp/radiooberhausen_mplayer.pid`
#5 10 21 3 * kill `cat /tmp/radiooberhausen_vlc.pid`
if [[ $# -ne 3 ]]; then
echo -e "wrong number of arguments.\n" \
"Usage: $0 <station> <dump method> <out directory>\n" \
"Example: $0 oberhausen mplayer ." >&2
exit 1
fi
if [[ $1 != "muelheim" && $1 != "oberhausen" ]]; then
echo "no known radio station given... exiting now." >&2
exit 1
fi
if [[ $2 == "vlc" ]]; then
cmd="cvlc %s --sout=file://%s vlc://quit"
elif [[ $2 == "mplayer" ]]; then
cmd="mplayer -dumpstream %s -dumpfile %s"
else
echo "no dump method given... exiting now." >&2
exit 1
fi
if [[ $3 == "" ]]; then
echo "no dump directory given... exiting now." >&2
exit 1
fi
echo "current directory is $(pwd)..."
pidfile="/tmp/radio$1_$2.pid"
if [ -f $pidfile ]; then
echo "pidfile already exists. exiting..."
exit
fi
echo "my pid is $$. logging to pidfile..."
echo $$ > $pidfile
stationurl="http://edge.live.mp3.mdn.newmedia.nacamar.net/radio$1/livestream.mp3"
quit=0
trap "quit=1" SIGTERM SIGHUP SIGINT
while [ $quit -ne 1 ]; do
clocknow=`date +%Y%m%d%H%M%S`
outfile="$3/$1_$2_$clocknow.mp3"
echo "dump to $outfile..."
dumpcmd="$(printf "$cmd" $stationurl $outfile)&"
echo "\$ ${dumpcmd}"
eval ${dumpcmd}
pid=$!
wait
[ $quit -ne 1 ] && sleep 1
done
echo "kill last process $pid..."
kill $pid
echo "removing pidfile..."
rm $pidfile
echo "exiting..."