#! /bin/bash # A script to record BBC Listen Again programs. # Orignal by Seb James 2007 # Extended by Stuart Ward 2007 # Released under the terms of the GNU GPL. # # Usage example: # convert_real http://www.bbc.co.uk/radio/aod/shows/rpms/radio4/six_pm_news.ram # Where the argument is the content of the link on the bbc site # called "Listen using stand-alone Real Player" # # This program will take as almost as long as it takes to listen to the # program, plus as long as it takes to convert the realaudio file to a wav # file, and then to encode it as an mp3 or ogg-vorbis file. # # mplayer with realaudio support via proprietary codecs must be installed. # oggenc or lame is required. Default is mp3 format ENCODE="mp3" QUIET= STREAM= SUFFIX= PROGRAM=$0 BITRATE="-b 128" while [ $# -gt 0 ] do case $1 in --mp3 | -m) ENCODE="mp3" ;; --ogg | -o) ENCODE="ogg" ;; --quiet | -q) QUIET="-quiet" ;; --date | -d) SUFFIX=$(date +%Y%m%d) ;; --bitrate | -b) BITRATE="-b " $1 ;; -*) echo "Unrecognised option: $1" ;; *) STREAM=$1 ;; esac shift done if [ -z $STREAM ]; then echo "Usage:" echo "$PROGRAM [--mp3 | --ogg] [--quiet] http://www.bbc.co.uk/.../six_pm_news.ram" echo "Where the argument is the content of the link on the BBC's web radio player " echo "called \"Listen using stand-alone Real Player\"" exit fi # Create a folder in which to work. mkdir -p $HOME/radio # And make that the working directory. cd $HOME/radio ramfile=${STREAM##*/} outfile=${ramfile%.*}$SUFFIX if [ -z $QUIET ]; then echo "Filename: $outfile.$ENCODE" echo "Stream: $STREAM" fi # This will get the stream idenity parameters mplayer -vo null -ao null -frames 0 -nocache -identify -playlist $STREAM \ 2>/dev/null | grep "^ID" | \ sed 's/=/=\"/ ; s/$/\"/' >$HOME/radio/$outfile.id . $HOME/radio/$outfile.id if [ -z $QUIET ]; then echo "Title :" $ID_CLIP_INFO_VALUE0 echo "Artist :" $ID_CLIP_INFO_VALUE1 echo "Copyright :" $ID_CLIP_INFO_VALUE2 fi if [ ! -p $HOME/radio/$outfile.pipe ]; then mkfifo $HOME/radio/$outfile.pipe fi started=$(date) # Thanks to Mike McKay (http://www.vdomck.org/) for the named pipe method here: if [ $ENCODE = "ogg" ]; then oggenc --quiet -q 1 $BITRATE -t "$ID_CLIP_INFO_VALUE0" \ -a "$ID_CLIP_INFO_VALUE1" -o $outfile.ogg \ $HOME/radio/$outfile.pipe & \ mplayer -vc null -vo null $QUIET \ -ao pcm:fast:file=$HOME/radio/$outfile.pipe \ -playlist $STREAM # for mp3 files, use lame to encode elif [ $ENCODE = "mp3" ]; then lame --quiet --tt "$ID_CLIP_INFO_VALUE0" --ta "$ID_CLIP_INFO_VALUE1" \ -h -v $BITRATE $HOME/radio/$outfile.pipe $outfile.mp3 & \ mplayer -vc null -vo null $QUIET \ -ao pcm:fast:file=$HOME/radio/$outfile.pipe \ -playlist $STREAM fi # remove the named pipe rm -f $HOME/radio/$outfile.pipe if [ -z $QUIET ]; then echo "Started: $started Finished: $(date)" echo "Title :" $ID_CLIP_INFO_VALUE0 echo "Artist :" $ID_CLIP_INFO_VALUE1 echo "Copyright :" $ID_CLIP_INFO_VALUE2 echo "Successfully created the program. $outfile.$ENCODE" fi