Skip to content

Instantly share code, notes, and snippets.

@singpolyma
Created December 14, 2011 04:23
Show Gist options
  • Save singpolyma/1475252 to your computer and use it in GitHub Desktop.
Save singpolyma/1475252 to your computer and use it in GitHub Desktop.
Convert WAV and TOC to FLAC
#!/bin/sh
# Copyright 2011, Stephen Paul Weber <singpolyma.net>
# You may use this code under the terms of an ISC License
# This script assumes a cdrdao TOC file with CD-TEXT in it named cd.toc
# It also assumes the front cover art is called cover.jpg
# It assumes track{TRACKNUMBER}.cdda.wav files (as generated by cdparanoia)
# The WAV files are encoded to FLAC with the TITLE, ARTIST, ALBUM, TRACKNUMBER, and ISRC set
# based on the CD-TEXT and ISRCs found on disc, and with front cover art set.
maybeget() {
tr '\n' '\v' < cd.toc | sed -e 's/\v\v/\n/g' | grep 'TRACK AUDIO' | sed -n $1p | tr '\v' '\n' | grep $2 | cut -d'"' -f2
}
ALBUM="`grep TITLE cd.toc | sed -n 1p | cut -d'"' -f2`"
for track in track*.cdda.wav; do
TRACKNUMBER="`echo "$track" | grep -o '[0-9]*'`"
TITLE="`maybeget $TRACKNUMBER TITLE`"
ARTIST="`maybeget $TRACKNUMBER PERFORMER`"
ISRC="`maybeget $TRACKNUMBER ISRC`"
flac --best --replay-gain --picture='4|image/jpeg|||cover.jpg' -T "TITLE=$TITLE" -T "ARTIST=$ARTIST" -T "ALBUM=$ALBUM" -T "TRACKNUMBER=$TRACKNUMBER" -T "ISRC=$ISRC" -o "$TRACKNUMBER - $TITLE.flac" "$track"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment