mathr / blog / #

Fun With Sed

I made a simple DJ patch in Pd, using [readanysf~] with its handy speed control. The trouble is that it doesn't like some of my files, telling me some error with "sucks for you, dude" (rub it in my face...). Plus it's a nightmare going through many nested subdirs to find tunes, and decoding mp3 takes cpu time that could better be spent on fun stuff like live fx and synths and stuff. So I wrote a simple bash script that takes an .m3u playlist file and decodes all the MP3s in it to WAV format. Sed comes into play because of the way I name my files, namely "Artist - Album/## Trackname.mp3", and I want to copy all that information in the dirname to the filename. Note also that I have a .bpm file next to each .mp3, this is so my DJ patch knows the BPM of the track and makes it all in time and sounding nice, so best copy that too.

#!/bin/bash
cat $1 |
grep ".mp3" |
while read MP3FILE
do
    echo $MP3FILE
    WAVFILE=`echo $MP3FILE | sed "s/\(.*\)\/\(.*\)\/\(.*\)/\2 - \3/" | sed s/mp3$/wav/`
    lame --quiet --decode "$MP3FILE" "$WAVFILE"
    cp "$MP3FILE.bpm" "$WAVFILE.bpm"
done

Usage: "cd where-you-want-the-wavs && bash /path/to/script.sh playlist.m3u"

As a bonus, here's the script that takes the output of kbpm-dj (which analyzes audio to find the bpm, and stores it in a crappy way) and makes those .bpm files I mentioned above...

#!/bin/bash
grep tempo index/* | 
grep ": [0-9][0-9][0-9]" | 
sed "s/:tempo.*//" |
while read line
do
   BPMFILE=`grep file "$line" | sed "s/^file     : /music\//" | sed "s/.mp3/.mp3.bpm/"`
   BPM=`grep tempo "$line" | sed "s/^tempo    : //" | sed "s/$/\;/"`
   echo $BPM > "$BPMFILE"
done

Danny Kreutzfeldt - [THN024] Recore:02 - 02 - Chasm 2 (Digitalverein Remix)

geeky

motherboard 4 fan