Confucius - "Only the wisest and stupidest of men never change."

the brown-dragon blog

Ripping a CD with Sed

2008-12-27

I just bought the Ministry Of Sound : Anthems (1991-2008) and I wanted to rip it into my music collection (who sticks with CD's these days?).

For ripping I use Exact Audio Copy which works really well. Unfortunately, EAC couldn't find the CD track information for any of the 3 CD's in the box set. Each CD has 17 tracks, many with funky names, and I really didn't want to sit and enter the details by hand.

Sed to the Rescue!

My music player is the excellent Media Monkey (if you've never tried it out - do! It's super). Media Monkey recognized the CD and was able to pull out all the track information. So I simply created a playlist from media monkey and used Sed to massage the information into a batch file that ran lame and viola! CD's cut into insanely high quality mp3's with all track information.

Here is the Sed script for converting the playlist (.m3u) to a batch file:

m3u2mp3-lame.sed

# We are expecting a m3u list of the CD tracks
# which consists of the EXTINF information on a line
# followed by the track path.
# After ripping, we have .wav files that correspond
# to the tracks. We need to rename them, encode them,
# and set their information.

# Ignore first line #EXTM3U
1{
/\#EXTM3U/d
s/.*/Expected "\#EXTM3U" as first line - Got "&"/
q
}

# Check for UTF8 encoding (and discard)
/.EXTINFUTF8:/d

# Line should be in format:
# #EXTINF:196,Seamus Haji - 17 Last Night A Deejay Saved My Life
#   ==>Seamus Haji
#      17
#      Last Night A Deejay Saved My Life
s/.EXTINF:[0-9]\+,\(.\+\) - \([0-9]*\) \?\(.*\)$/\1\n\2\n\3/
tgotdataline
s/.*/Expected mp3 data - Failed to parse "&"/
q
:gotdataline
N

# Track01.cda ==> 01.wav
s/\(.*\n.*\n.*\n\).*Track\([0-9]\+\).cda$/\1\2.wav/
tgottrackline
s/.*/Expected track data - Failed to parse "&"/
q
:gottrackline

# Convert to "lame --preset insane --tt "Last Nig..." --ta "Seamu..."
#                       --tl "ALBUM NAME" --ty "YEAR" --tn "17.."
#                       01.wm.. "ALBUM-17.[Seam..]-Last Nig...mp3"
s/\(.*\)\n\(.*\)\n\(.*\)\n\(.*\)/lame --preset insane --tt "\3" --ta "\1" --tl "Anthems(1998-2008)" --ty 2008 --tn "\2" "\4" "Anthems(1998-2008)-\2.\1-\3.mp3"/

Other Posts

(ordered by Tags then Date)