[clug] Ripping CDs

Hal Ashburner hal at ashburner.info
Wed Nov 23 17:48:59 MST 2011


On 24/Nov/2011, at 11:22 AM, Ian Munsie wrote:

> 
> And I suppose since you indicated you want flac you would do something like:
> jack -q -E flac (or whatever the flac encoder is called... I'm happy
> encoding to ogg since my lossless backup is... the CD ;)

And you can have all the fun of re-ripping that lossless backup when ogg is no longer the format of choice or when you want to play the music on a device that doesn't support ogg.

I rip to flac. Then create a mirror directory in whatever other format is required (usually for handheld devices), when they change format as they will, sooner or later I can re-generate in the new format by altering a script rather than having to fish out all the cds and feed them through the computer again.


This is not the kind of script that takes much time to write. I'll ross in mine below, you can see it's pretty hacky and has grown organically. One day I'll re-write its collective wisdom in python, but for now, much too lazy. ;-)

Making it spit out ogg, aac or whatever shouldn't be much of an update. I'd recommend a total re-write in your scripting language of choice, obviously.




#This code is Licensed: Public domain. Don't claim you wrote it, but then again if you did, you'd probably deserve the reputation that follows. ;)

#!/bin/sh
    COPY_DIR=/path/to/mirror/
    cd /path/to/music/toplevel/
    find . -iname '*.flac' | while read mp3file; do
        this_mp3_dir=$(dirname "$mp3file")
        copy_mp3_dir="$COPY_DIR/$this_mp3_dir"
        mp3_file_base=$(basename "$mp3file" ".flac")
        if [ -d "$copy_mp3_dir" ]; then
            #echo "$copy_mp3_dir exists"
            echo -n ""
        else
            echo "$copy_mp3_dir does not exist - creating"
            mkdir -p "$copy_mp3_dir"
        fi

        if [ -e "$copy_mp3_dir/$mp3_file_base.mp3" ]
        then
            echo -n "$copy_mp3_dir/$mp3_file_base.mp3 already exists - doing nothing"
        else
            echo -n "transcoding $mp3file"
            touch "$copy_mp3_dir"/"$mp3_file_base".mp3
            flac -d "$mp3file" -o /tmp/"$mp3_file_base.wav"

            TAGS=$(mutagen-inspect "$mp3file")
            TITLE=$(echo "$TAGS" | grep -e '^title=')
            TITLE=${TITLE#title=}
            ARTIST=$(echo "$TAGS" | grep -e '^artist=')
            ARTIST=${ARTIST#artist=}
            ALBUM=$(echo "$TAGS" | grep -e '^album=')
            ALBUM=${ALBUM#album=}
            DATE=$(echo "$TAGS" | grep -e '^date=')
            DATE=${DATE#date=}
            GENRE=$(echo "$TAGS" | grep -e '^genre=')
            GENRE=${GENRE#genre=}
            TRACKNUMBER=$(echo "$TAGS" | grep -e '^tracknumber=')
            TRACKNUMBER=${TRACKNUMBER#tracknumber=}



            lame --tt "$TITLE" --ta "$ARTIST" --tl "$ALBUM" --ty "$DATE" --tn "$TRACKNUMBER" --tg "$GENRE" --ignore-tag-errors /tmp/"$mp3_file_base.wav" "$copy_mp3_dir"/"$mp3_file_base".mp3
            rm /tmp/"$mp3_file_base.wav"
        fi
    done




More information about the linux mailing list