#!/bin/sh # # Script - real_to_mp3.sh # # Description - Record a Real Audio stream and convert to mp3 using mplayer and lame # # Author - Alex Dyas, inspired by bedouin (http://www.macosxhints.com/article.php?story=20050130184054216) # # Version - 1.2 - Small change to mplayer command line (-ao) # 1.1 - Fixed problem with unprintable characters in some HTTP replies messing up stream URL # 1.0 - First release # # Note - Whilst every effort has been made to ensure that this script does no damage, the author takes # no responsibility whatsoever as to any damages resulting in its use. # # ----------------------------------------------------------------------------------------------------------------- TEXTFILE=real_to_mp3.tmp URL=${1} FILENAME=${2} # ----------------------------------------------------------------------------------------------------------------- usage() { echo Usage : echo "`basename ${0}` " echo "eg `basename ${0}` http://www.bbc.co.uk/radio4/history/inourtime/ram/inourtime.ram \"BBC IOT The Physics of Reality\"" echo exit } # ----------------------------------------------------------------------------------------------------------------- if [ -z "${URL}" ] then { usage } elif [ -z "${FILENAME}" ] then { usage } fi # Find the Real Audio Stream from the URL echo Figure out Read Audio Stream STREAM=`curl "${URL}" | tr -cd "[:print:]" | grep rtsp` # Download echo "Downloading stream...." mplayer -noframedrop -dumpfile "${FILENAME}.rm" -dumpstream ${STREAM} # Convert to wav and grab information text echo "rm->wav" mplayer "${FILENAME}.rm" -ao pcm:file="${FILENAME}.wav" -vc dummy -vo null > ${TEXTFILE} # Set mp3 tag information #TITLE=`grep name ${TEXTFILE} | sed 's/ name: //'` TITLE="${FILENAME}" AUTHOR=`grep author ${TEXTFILE} | sed 's/ author: //'` ALBUM="Streaming Audio" # Convert to mp3 echo "wav->mp3" lame -m m "${FILENAME}.wav" "${FILENAME}.mp3" --tt "${TITLE}" --ta "${AUTHOR}" --tl "${ALBUM}" # Tidy up echo Deleting working files... if [ -f "${FILENAME}.rm" ]; then rm "${FILENAME}.rm"; fi if [ -f "${FILENAME}.wav" ]; then rm "${FILENAME}.wav"; fi if [ -f "${TEXTFILE}" ]; then rm "${TEXTFILE}"; fi echo Done.