Ubuntu – Convert library of WMA tracks to MP3’s

conversionmp3soundwma

I know there are options such as Sound Converter for doing them one track or directory at a time, but are there any tools that will recursively crawl through a directory's subdirectories and convert all WMA's to MP3's?

I basically would like to let it loose on my ~/Music and let it do its thing without me manually having to give it one subdirectory at a time.

Best Answer

MPlayer is likely to be installed already. Also make sure you have lame:

sudo apt-get install mplayer lame

Then there are two ways to do it, an easy to read version, and a short and dirty script to do it:

All wma's should be in your current directory. Create a file called wmamp3 in your home directory (~/) containing:

#!/bin/bash

current_directory=$( pwd )

#remove spaces
for i in *.wma; do mv "$i" `echo $i | tr ' ' '_'`; done

#remove uppercase
for i in *.[Ww][Mm][Aa]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done

#Rip with Mplayer / encode with LAME
for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -ao pcm:waveheader $i && lame -m s audiodump.wav -o $i; done

#convert file names
for i in *.wma; do mv "$i" "`basename "$i" .wma`.mp3"; done

#cleanup
rm audiodump.wav

chmod +x ~/wmamp3 to make it executable

sudo cp ~/wmamp3 /usr/bin to pop it somewhere useful on your path

Type "wmamp3" to run your conversion.


The short and dirty version (does exactly the same as above):

for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -ao pcm:waveheader "$i" && lame -m j -h --vbr-new -b 160 audiodump.wav -o "`basename "$i" .wma`.mp3"; done; rm -f audiodump.wav