---
#!/bin/bash
# copyright Wulf Coulmann <scripts at gpl.coulmann dot de>
# GNU GPL
# http://www.gnu.org/licenses/gpl.html
#
# Download me here: http://gpl.coulmann.de/radio_rip
#set -x
# Config --------------------------------------------------
TMP='/tmp/' # location of the temporery fifo buffer
RETRY=200 # how often we retry if we do'nt get a streaming port
# let's rock'n roll
case "$1" in
-h|--help)
cat | less << 'EOD'
RADIO_RIP(1) User Manuals RADIO_RIP(1)
NAME
radio_rip - dumps every audio stream you can listen with your mplayer
installation (yes, it's a possibility to record real streams) and encode
them to everything sox can manage.
Ogg Vorbis, mp3 ...
SYNOPSIS
radio_rip [ --help | RECORDING_TIME OUTPUT_FILE STREAM_URL ]
DESCRIPTION
radio_rip connect via mplayer to a audio stream send the raw output
to a named pipe. Sox reads from the named pipe and transform to a format
you refer in OUTPUT_FILE by the last 3 characters.
If there is no free streaming port available radio_rip retry that often you
define in the config section of the radio_rip script. The default is 200.
It's a god idea to use radio_rip in combination with cron or at and sometimes
http://gpl.coulmann.de/day_of_month.html is very helpful.
Of corse, you need a mplayer and a sox installation.
RECORDING_TIME
is the duration of the recording in minutes
OUTPUT_FILE
is the location of the output codec. The last 3 characters define the format
e.g. ~/favorite_radio_show.ogg will generate a ogg vorbis file
please refer to sox (1)
STREAM_URL
is the url of any audio stream your mplayer installation can handle
please refer to mplayer (1)
OPTIONS
-h print this help
EXAMPLES
main program call
radio_rip 55 ~/favorite_radio_show.ogg rtsp://stream01.rbb-online.de/broadcast/multikulti
crontab - every sunday 9:04
4 09 * * 7 radio_rip 55 ~/favorite_radio_show.ogg rtsp://stream01.rbb-online.de/broadcast/multikulti
crontab and day_of_month - every second sunday of the month
3 16 * * 7 day_of_month 2 "radio_rip 55 ~/favorite_radio_show.ogg rtsp://stream01.rbb-online.de/broadcast/multikulti"
at for single recordings
echo "radio_rip 55 ~/favorite_radio_show.ogg rtsp://stream01.rbb-online.de/broadcast/multikulti" | at 16:05
AUTHOR
Wulf Coulmann <scripts at gpl.coulmann dot de>
SEE ALSO
mplayer(1), sox(1), cron(8), at(1), http://gpl.coulmann.de/day_of_month.html
Linux Last change: September 2006
EOD
exit 0
;;
*)
DAUER=$1
ZIEL=$2
URL=$3
FIFO=$TMP`date +%s`_real_rip.wav
mkfifo $FIFO
# run mplayer in background
CMD="/usr/bin/mplayer -playlist -really-quiet -vc null -vo null -ao pcm:file=$FIFO -cache 320 $URL"
${CMD} &
MPLAYER=$!
echo ${MPLAYER}
# convert raw data to ogg
#sox $FIFO -r 48k -e signed -b 16 -t vorbis $ZIEL&
oggenc -q 6 -o ${ZIEL} ${FIFO} &
# make sure we get a port of the streaming server, if not try to reconnect
CHECK=0
RECONNECT=0
while [ $CHECK -lt 1 ] && [ $RECONNECT -lt $RETRY ]
do
sleep 1
if [ ! -n "`ps -p $MPLAYER|grep $MPLAYER`" ] ; then
echo "reconnect $RECONNECT"
#/usr/bin/mplayer -quiet -ao pcm:file=$FIFO -cache 32 $URL&
${CMD} &
MPLAYER=$!
CHECK=0
RECONNECT=$(($RECONNECT + 1))
fi
CHECK=$(($CHECK + 1))
#sleep 1
done
echo mplayer connected
# wait for requested time
sleep $(($DAUER * 60))
# stop mplayer
kill ${MPLAYER}
sleep 10
# remove fifo
rm -rf $FIFO
;;
esac
syntax highlighted by Code2HTML, v. 0.9.1