I recently needed to convert a bunch of (DRM-free) WMA files to MP3 format on Ubuntu, and there’s no good tool out there to do it. There are plenty of tutorials that tell you how to convert from WMA to WAV with Lame, then from WAV to MP3 with mplayer, but none of these tutorial talk about how that will cause you to lose all the WMA artist/album/title data. I needed a tool that would keep the tagged data; so, I made one. It requires mplayer, lame, and mutagen-inspect, all of which are available from aptitude.

So, here’s my script: wma2mp3



Usage: wma2mp3 in-wma out-mp3

#!/bin/bash IN = $1 O = ${2-${IN%\.wma} } OUT = ${O%\.mp3} .mp3 TEMP = ` mktemp / tmp / convert.XXXXX.wav ` echo Converting \" $IN \" to \" $TEMP \" mplayer -vc null -vo null -ao pcm:waveheader:fast: file = %` expr length " $TEMP " `% " $TEMP " " $IN " echo Converting $TEMP to $OUT lame " $TEMP " " $OUT " rm $TEMP echo Fixing ID3 tags ARTIST = ` mutagen-inspect " $IN " | grep WM / AlbumArtist | grep -E --only-matching "[^=]+$" ` ALBUM = ` mutagen-inspect " $IN " | grep WM / AlbumTitle | grep -E --only-matching "[^=]+$" ` NUM = ` mutagen-inspect " $IN " | grep WM / TrackNumber | grep -E --only-matching "[^=]+$" ` TITLE = ` mutagen-inspect " $IN " | grep -E "^Title=" | grep -E --only-matching "[^=]+$" ` echo Artist = \" $ARTIST \" echo Album = \" $ALBUM \" echo Track Number = \" $NUM \" echo Title = \" $TITLE \" mp3info -a " $ARTIST " -l " $ALBUM " -n " $NUM " -t " $TITLE " " $OUT " echo Done !

Edit: Thanks to a post over on reddit, here’s an update that makes better use of shell scripting:

#!/bin/sh in = $1 out = ${in%.[Ww][Mm][Aa]} .mp3 mutagen-inspect " $in " | { while IFS = read -r tag; do case $tag in WM / AlbumArtist * ) ARTIST = ${tag#*=} ;; WM / AlbumTitle * ) ALBUM = ${tag#*=} ;; WM / TrackNumber * ) NUM = ${tag#*=} ;; Title = * ) TITLE = ${tag#*=} ;; esac done mplayer -vc null -vo null -ao pcm:waveheader:fast: file = / dev / stdout | lame --tt " $TITLE " --ta " $ARTIST " --tl " $ALBUM " --tn " $NUM " - " $out " }

Like this: Like Loading...

Related