#!/bin/sh VERSION="0.2" ########################################################################### # makeflac-0.2 # Jason Kaufman # 2002.03.29 # # Well so far a lot of stuff is hardcoded and can't be removed. This is is # due to the fact that this started out as a quick hack to rip 50 CDs in one # day. Nowadays, it can do much more (tagging-wise) and has better (but # far from perfect) error-checking. It does almost everything I want a # ripper to do, but it probably doesn't do everything YOU want it to do. # You have been warned. # # REQUIRES: cdda2wav, cdparanoia, flac, metaflac # # BEGIN CONFIGURABLE OPTIONS # These must be properly set or makeflac will break # CD-ROM device to rip from DEVICE="/dev/sg0" # Full path to cdda2wav CDDA2WAV="/usr/bin/cdda2wav" # Full path to cdparanoia CDPARANOIA="/usr/local/bin/cdparanoia" # Full path to flac FLAC="/usr/local/bin/flac" # Options to use with flac FLAC_OPTS="-V -8 --delete-input-file --replay-gain" # Full path to metaflac METAFLAC="/usr/local/bin/metaflac" # The file in each album directory where track names are stored TRACKNAMES=".tracknames" # END CONFIGURABLE OPTIONS # Usage: cd Artist_Name/Album_Title; vim ${TRACKNAMES}; makeflac ALBUM_DATE # e.g., cd Cult,_The/Electric; vim .tracknames; makeflac --date 1987 # ELABORATION OF USAGE # #1. Artist_Name/Album_Title # # makeflac at this point assumes an underscore-delimited, non-escaped- # punctuation-containing directory structure. You must execute makeflac # from within this directory # # e.g. Cult,_The/Electric is legal. # e.g. Foobar/('My_Super-133t Mix') is probably not. # Don't cry if your illogical scheme doesn't work with makeflac # #2. vim ${TRACKNAMES} # # Place the name of each track, one to a line in this file. Do not # leave blank lines in the file. Punctuation is OK, a filter will sanitize # it when it names the flac, while retaining the original form for tagging. # NOTE: If your album has multiple discs, specify the tracks in different # ${TRACKNAMES} like ${TRACKNAMES}1 (the first disc), ${TRACKNAMES}2 # (the second disc), and so on. # #3. makeflac --date ALBUM_DATE # At this point all you need is the date of the album release. # # SUMMARY # 1. mkdir and cd to Artist_Name/Album_Title # 2. edit a ${TRACKNAMES} for each disc # 3. insert CD # 4. makeflac ALBUM_DATE # # Screwing with anything after this will probably break makeflac ############################################################################ INFOFILE="${PWD}/.info" LOGFILE="cd-discid.log" NUM_TRACKS= CDINDEX_ID= CDDB_ID= LEADOUT= ISRC="0" MCN="0" DO_TEST="false" SKIP_RIP="false" ALBUM=`basename ${PWD} | sed -e 's/_/\\ /g'` ARTIST=`basename \`eval "dirname ${PWD}"\` | sed -e 's/_/\\ /g'` # Parse arguments while test ${#} -gt 0; do case "${1}" in --album ) ALBUM=${2}; shift; shift ;; --artist ) ARTIST=${2}; shift; shift ;; --date ) DATE=${2}; shift; shift ;; --discs ) NUM_DISCS=${2}; shift; shift ;; -h | --help ) cat << EEOOFF makeflac-${VERSION} Jason Kaufman --album Specify an album name here to override the directory structure --artist Specify an artist name here to override the directory structure --date Release date of album, most often this is the release year --discs Number of discs in the album -h --help Display this help -t --test Do everything but rip and flac -v --version Show release information EEOOFF exit 1 ;; -skip-rip ) SKIP_RIP="true"; shift ;; -t | --test ) DO_TEST="true"; shift ;; -v | --version ) echo "makeflac-${VERSION}"; echo "Jason Kaufman " exit 1 ;; * ) break ;; esac done # Error-check some arguments if test x"${NUM_DISCS}" != "x"; then if test ${NUM_DISCS} -lt 1; then echo "*** ERROR: \"${NUM_DISCS}\" is an invalid number of discs" exit 0 fi else NUM_DISCS=1 fi ### Start the big loop DISCS_DONE=0 while test ${DISCS_DONE} -lt ${NUM_DISCS}; do let DISCS_DONE+=1 # We don't need a subdir if there's only one disc if test ${NUM_DISCS} -gt 1; then mkdir d${DISCS_DONE} && cd d${DISCS_DONE} cp ../${TRACKNAMES}${DISCS_DONE} ${TRACKNAMES} echo "*** Ripping Disc ${DISCS_DONE} of ${NUM_DISCS}" fi # ISRC and MCN detection echo -n "*** cdda2wav is identifying track boundaries ... " ${CDDA2WAV} -D ${DEVICE} -g -J -N -v 1 2>${LOGFILE} echo "done" echo -n "*** cdda2wav is scanning for ISRCs and an MCN ... " ${CDDA2WAV} -D ${DEVICE} -g -J -N -v 24 2>${INFOFILE} echo "done" # We can't conduct tests if we don't have an INFOFILE # Some broken CDs screw up cdda2wav's scanning if test -f ${INFOFILE}; then # MCN detection MCN=`grep "catalog number" ${INFOFILE} | cut -d: -f2 | sed -e 's/ //g'` if ! test `echo ${MCN} | grep -e [0-9]`; then MCN="0" fi # ISRC detection ISRC=`grep "ISRC" ${INFOFILE} | cut -d: -f4 | sed -e 's/ //g'` if test `echo ${ISRC} | grep "ISRC"`; then ISRC="0" fi fi # MASSIVE sed parser # Delete the first 3 lines of output # Align the number of tracks to the left # Align the CDINDEX discid to the left # Delete the 'Album', 'CD-Text', and 'CD-Extra' lines # Align frame offsets to the left # Align leadout time to the left cat ${LOGFILE} | \ sed '1,3d' |\ sed -e 's/^Tracks\://' \ -e 's/^CDINDEX discid\: //' \ -e 's/^CDDB discid\: //' \ -e '/^CD\-Text\:/d' -e '/^CD\-Extra\: /d' -e '/^Album/d' \ -e 's/^T[0-9][0-9]\: *//' \ -e 's/^Leadout\: //' \ > $$.temp && mv $$.temp ${LOGFILE} # Cleaning up cat ${LOGFILE} | \ cut -d" " -f1 \ > $$.temp && mv $$.temp ${LOGFILE} # Retrieving all the good info NUM_TRACKS=`sed -n 1p < ${LOGFILE}` CDINDEX_ID=`sed -n 2p < ${LOGFILE}` CDDB_ID=`sed -n 3p < ${LOGFILE} | sed -e 's/^0x//'` LEADOUT=`tail -1 ${LOGFILE}` if test "${DO_TEST}" = "true"; then echo "NUM_TRACKS="${NUM_TRACKS} echo "CDINDEX_ID="${CDINDEX_ID} echo "CDDB_ID="${CDDB_ID} echo "LEADOUT="${LEADOUT} echo "NUM_DISCS="${NUM_DISCS} exit 1 fi # Removing what we've stored cat ${LOGFILE} | sed 1,3d | sed '$d' > $$.temp && mv $$.temp ${LOGFILE} # Making WAVs if test "${SKIP_RIP}" = "false"; then ${CDPARANOIA} -d ${DEVICE} -z -B fi # Making flacs rm -f track00* COUNT=1 for FLACF in `ls *.wav`; do if test ${COUNT} -lt 10; then TRACKNUMBER=0${COUNT} else TRACKNUMBER=${COUNT} fi # Setting up some comments for encoding BEGIN_SECTOR=`sed -n ${COUNT}p < ${LOGFILE}` TITLE=`sed -n ${COUNT}p < ${TRACKNAMES}` STITLE=`echo ${TITLE} | sed -e 's/ /_/g' -e 's/_(.*//' -e 's/#//g' -e "s/'//g" -e 's/\!//g' -e 's%/%_-_%g' -e 's/\.//g' -e 's/\?//g'` DESCRIPTION=`date +%Y.%m.%d-%H%M` if ! test x"${ISRC}" = "x0"; then THIS_ISRC=`echo ${ISRC} | cut -d' ' -f${COUNT}` else THIS_ISRC="0" fi echo "" echo "Encoding Track ${COUNT} as ${TRACKNUMBER}-${STITLE}.flac with info:" echo "ALBUM: ${ALBUM}" echo "ARTIST: ${ARTIST}" echo "BEGIN_SECTOR: ${BEGIN_SECTOR}" echo "CDINDEX: ${CDINDEX_ID}" echo "CDDB: ${CDDB_ID}" echo "DATE: ${DATE}" echo "DESCRIPTION: ${DESCRIPTION}" if ! test x"${THIS_ISRC}" = "x0"; then echo "ISRC: ${THIS_ISRC}" fi echo "LEADOUT: ${LEADOUT}" if ! test x"${MCN}" = "x0"; then echo "MCN: ${MCN}" fi echo "TITLE: ${TITLE}" echo "TRACKNUMBER: ${TRACKNUMBER}" ${FLAC} ${FLAC_OPTS} --tag=ALBUM="${ALBUM}" --tag=ARTIST="${ARTIST}" --tag=BEGIN_SECTOR="${BEGIN_SECTOR}" --tag=CDINDEX="${CDINDEX_ID}" --tag=CDDB="${CDDB_ID}" --tag=DATE="${DATE}" --tag=DESCRIPTION="${DESCRIPTION}" --tag=ISRC="${THIS_ISRC}" --tag=LEADOUT="${LEADOUT}" --tag=MCN="${MCN}" --tag=TITLE="${TITLE}" --tag=TRACKNUMBER="${TRACKNUMBER}" track${TRACKNUMBER}.cdda.wav mv track${TRACKNUMBER}.cdda.flac ${TRACKNUMBER}-${STITLE}.flac if test x"${THIS_ISRC}" = "x0"; then ${METAFLAC} --remove-vc-field=ISRC ${TRACKNUMBER}-${STITLE}.flac fi if test x"${MCN}" = "x0"; then ${METAFLAC} --remove-vc-field=MCN ${TRACKNUMBER}-${STITLE}.flac fi unset THIS_ISRC let COUNT+=1 done rm ${LOGFILE} if test ${NUM_DISCS} -gt 1; then if test ${DISCS_DONE} -lt ${NUM_DISCS}; then cd ../ echo "Done with Disk ${DISCS_DONE}, insert the next disk" echo "and press any key to continue" read JUNK && unset ${JUNK} fi fi done echo "*** Done!"