Posts: 89
Stuart O'mahony
Joined: 07 Mar 2010
#1
Here's a command that will convert all real audio files (.ra) at a given location to an mp3 format, to include sub directories:

Code: Select all

convert () { mplayer -cache 32 -ao pcm:file="${file[x]}".wav"${file[x]}".ra; lame -V2"${file[x]}".wav"${file[x]}".mp3; } ; find"$My_Music" -iname"*.ra" > Musiclist.txt ; y=$(sed 's@ @\\ @g' Musiclist.txt | wc -l); ((y=y+1));  typeset -i x; x=1; while ((x < y)) && path[x]=$(dirname"$(awk NR==$x Musiclist.txt)") && file[x]=$(awk -F"/" -v line=$x 'NR==line{sub(/\..*/,"",$NF);print $NF}' Musiclist.txt) &&  ln -s"${path[x]}/${file[x]}".ra"${file[x]}".ra; do ((x=x+1)); done ; x=1;  while (( x < y )) && convert; do (( x=x+1)); done;  rm -vf *.wav *.ra Musiclist.txt ; x=1; while (( x < y)) && mv -v"${file[x]}".mp3"${path[x]}"; do ((x=x+1)); done
All you need do before proceeding is set the variable $My_Music so the command knows where to look for your .ra files:

Code: Select all

export My_Music="/path/to/your/music/directory"
In addition to the newly created .mp3 files, temporary .wav and linked .ra files will be created within your working directory, later to be removed in the 'clean up': here *ALL* .wav and .ra files will be removed, so be sure your working directory is clear of any wanted files of this format. Your original .ra files will not be touched, and the new .mp3 files moved to the same location as source.
Last edited by Stuart O'mahony on 09 Nov 2010, 19:04, edited 2 times in total.
Posts: 516
oldhoghead
Site Admin
Joined: 01 Oct 2007
#2
Nice script Stuart, should be very handy.
__{{emoticon}}__

cheers,
ohh