Categories
Music Technology

Music management

So, you’ve encoded all of your CDs (still illegal in the UK) onto your computer, or even a storage array, and you realise that the filenames don’t always match the track title.

 

This quick bash command will list the differences:

 

find <path> -iname \*.ogg -type f | while read FILE; do
    NAME="$( basename "$FILE" )"
    NAME="${NAME/.ogg/}"
    TITLE="$( ogginfo "$FILE" | \
        grep -i "title=" | cut -d"=" -f 2 )"
    if [ "$NAME" != "$TITLE" ]; then
        echo -e "$FILE\\t$TITLE"
    fi
done | tee titles.list

 

I’ll leave it as an exercise for the reader to parse this output to actually rename the files 😉

One reply on “Music management”

Answering my own question, how about this:

LASTDIR=""
find <path> -iname \*.ogg -type f | while read FILE; do
    DIR="$( dirname "$FILE" )"
    NAME="$( basename "$FILE" )"
    NAME="${NAME/.ogg/}"
    TITLE="$( ogginfo "$FILE" | grep -i "title=" | cut -d"=" -f 2 )"
    TITLE="${TITLE/\//\\}"
    if [ -n "$TITLE" -a "$NAME" != "$TITLE" ]; then
        if [ "$LASTDIR" != "$DIR" ]; then
            echo "cd \"$DIR\" || exit 1"
            LASTDIR="$DIR"
        fi
        echo "mv '$NAME.ogg' '$TITLE.ogg'"
    fi
done | tee rename.sh && chmod 755 rename.sh && ./rename.sh

Leave a ReplyCancel reply

Exit mobile version