#!/bin/sh
# Semplice script per registrare le streaming radio in rete in file mp3 o ogg.
# Digitare sh recordradio.sh -h per maggiori info.
# Esempio di uso: sh recordradio.sh -u mms://fastreal.fastweb.it/RDS -o prova -c ogg
red='\e[0;31m'
RED='\e[1;31m'
blue='\e[0;34m'
BLUE='\e[1;34m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
banner (){
echo -e $RED"**********************************"
echo -e "* Record Stream Radio *"
echo -e "* Bash Script *"
echo -e "* Coded By Matrix86 *"
echo -e "* http://www.tuxmealux.net *"
echo -e "**********************************"
}
usage=$BLUE'Usage: $0 [OPTION] [FILE] \nOptions:\n\t-h\t show this help\n\t-u\t radio url\n\t-o\t output filename\n\t-c\t use codec type (ogg,mp3) default mp3\n'
codec="mp3"
outfile="radiorec"
if [ $# -eq 0 ];then
banner
echo -e $usage
tput sgr0
exit 0
fi
while getopts ":h:u:o:c:" option
do
case $option in
h)
banner
echo -e $usage
tput sgr0 # Ripristina il colore normale della shell
exit 0
;;
u)
url=$OPTARG
;;
o)
outfile=$OPTARG
;;
c)
codec=$OPTARG
;;
*)
banner
echo -e $usage
tput sgr0
exit 0
;;
esac
done
banner
tput sgr0
mplayer $url -cache 128 -ao pcm:file=$outfile.wav >/dev/null 2>&1 &
PID=$(ps aux | grep "mplayer $url -cache 128 -ao pcm:file=$outfile.wav" | grep -v grep | cut -c10-14)
echo -e "Start Recording...\nTo Stop Recording Press a Key!"
read key
kill -3 $PID && echo -e "Stop Recording"
sleep 2
if [ -e $outfile.wav ];then
case $codec in
mp3)
lame -b 192 -vbr-new $outfile.wav $outfile_`date "+%d%m%Y_%H%M%S"`.mp3 >/dev/null 2>&1 && echo -e "Encoding to MP3...Wait a While"
;;
ogg)
oggenc $outfile.wav -o $outfile_`date "+%d%m%Y_%H%M%S"`.ogg >/dev/null 2>&1 && echo -e "Encoding to OGG...Wait a While"
;;
esac
rm $outfile.wav
echo "DONE"
else
echo $outfile".wav not found!"
fi
tput sgr0
exit 0