#!/bin/bash # --------------------------------------------------------------------# # mp3rm - downloads rm files, converts to mp3, and adds to itunes # # requires mplayerosx, LAME, and correctly linked realmedia codecs # # as described in the README. # # --------------------------------------------------------------------# # USER VARIABLES # hard drive name. HD_NAME="Macintosh HD" # Location of mplayer. MPLAYER="/usr/local/bin" # Location of LAME. LAME="/sw/bin" # --------------------------------------------------------------------# # No need to modify past here unless you know what you are doing. # # --------------------------------------------------------------------# # help if [ -z $1 ] then echo "use: mp3rm [title] [artist] [album]" echo " if title, artist, album not set - title will be set to filename" echo echo "if url is a ram file, the script will parse and display it, and ask for the url to the rm file" exit fi # open .ram files TEST=`echo $1 | awk '/ram$/'` if [ $TEST ] then echo "try to find the .rm url in here:" curl -s "$1" echo exit fi # get file NAME=`echo $1 | sed -e 's/.*\///' -e 's/\.rm$//'` echo "downloading $NAME.rm" /usr/bin/curl "$1" -o "$NAME.rm" echo "finished downloading $NAME.rm" # check if file is valid if [ ! -e "$NAME.rm" ] then echo "file doesn't exist, check again, aborting" exit fi FNAME="$NAME.rm" RMSIZE=`ls -s $FNAME | awk '{print $1}'` if (( "$RMSIZE" < 1000 )) then echo -e "file too small, aborting\n" mv $FNAME ~/.Trash exit fi # converts .rm to .wav echo "converting $NAME.rm to $NAME.wav" $MPLAYER/mplayer "$NAME".rm -ao pcm:file="$NAME".wav -vc dummy -vo null # converts .wav to .mp3 echo "converting $NAME.wav to $NAME.mp3" if [ $2 ] then $LAME/lame -f -b 32 --tt "$2" --ta "$3" --tl "$4" "$NAME.wav" "$NAME.mp3" else $LAME/lame -f -b 32 --tt "$NAME" "$NAME.wav" "$NAME.mp3" fi # import into iTunes FILE_LOC=`echo "$HD_NAME/$PWD/" | sed -e 's/\//:/g'` echo "importing $NAME.mp3 into iTunes" osascript -e 'tell application "iTunes"' -e 'set this_track to "'"$FILE_LOC"''$NAME'.mp3"' -e 'add this_track' -e 'end tell' # cleanup echo "moving $NAME.rm, $NAME.wav, and $NAME.mp3 to trash" mv "$NAME.rm" ~/.Trash mv "$NAME.wav" ~/.Trash mv "$NAME.mp3" ~/.Trash echo "done!"