#!/bin/sh VERSION="0.3" ########################################################################### # makeflac-0.3 # Jason Kaufman # 2003.08.15 # # 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" # Options to use with flac FLAC_OPTS="-V -8 --delete-input-file --replay-gain" # 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=".info" 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 ;; --cddb ) CDDB_ID=${2}; shift; shift ;; --cdindex ) CDINDEX_ID=${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 --cddb Specify a CDDB-ID, e.g. "0xc10bc80e" --cdindex Specify a CDINDEX, e.g. "3DS3cxoLgbTkdMA4UvTz7ArVuFc-" --date Release date of album, most often this is the release year --discs Number of discs in the album -h --help Display this help --mcn Specify an MCN, e.g. "0075678356728" --skip-rip Use this if you ran makeflac to rip your disc(s), but you still need to encode them -v --version Show release information EEOOFF exit 1 ;; --mcn ) MCN=${2}; shift; shift ;; --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 -n "${NUM_DISCS}"; 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 ### If already have all the WAVs, then we can skip all of this if test x"${SKIP_RIP}" != "xtrue"; then # 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} fi ### BEGIN Need the Audio CD Section ### echo -n "*** cdda2wav is retrieving info... " cdda2wav -D ${DEVICE} -g -J -N -v catalog,trackid,sectors 2>${INFOFILE} echo "done" fi ### END of Need the Audio CD section ### ### BEGIN ${INFOFILE}-specific code ### if test -f ${INFOFILE}; then # MCN detection if test -z "${MCN}"; then MCN=`grep -m 1 "catalog number" ${INFOFILE} | cut -d: -f2 | sed -e 's/ //g'` if ! test `echo ${MCN} | grep -e [0-9]`; then MCN= fi fi # CDDB detection if test -z "${CDDB_ID}"; then CDDB_ID=`grep -m 1 "CDDB" ${INFOFILE} | cut -d: -f2 | sed -e 's/ //g'` fi # CDINDEX detection if test -z "${CDINDEX_ID}"; then CDINDEX_ID=`grep -m 1 "CDINDEX" ${INFOFILE} | cut -d: -f2 | sed -e 's/ //g'` fi # LEADOUT LEADOUT=`grep -m 1 "Leadout" ${INFOFILE} | cut -d: -f2 | sed -e 's/ //g'` fi ### END ${INFOFILE}-specific code ### if test -f ${TRACKNAMES}; then NUM_TRACKS=`cat ${TRACKNAMES} | wc -l` else echo "*** Error: ${TRACKNAMES} containing tracknames does not exist"; exit 1; fi # Making WAVs if test x"${SKIP_RIP}" = "xfalse"; then echo "*** Ripping Disc ${DISCS_DONE} of ${NUM_DISCS}" 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 # BEGIN_SECTOR and ISRC for this track if test -f ${INFOFILE}; then BEGIN_SECTOR=`grep -m 1 "^T${TRACKNUMBER}" ${INFOFILE} | cut -d: -f2 | sed -e 's/ //g'` ISRC=`grep -m 1 "${COUNT} ISRC" ${INFOFILE} | cut -d: -f4 | sed -e 's/ //g' -e 's/\^M//g'` fi # Setting up some comments for encoding 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` echo "" echo "Encoding Track ${COUNT} as ${TRACKNUMBER}-${STITLE}.flac with info:" echo "ALBUM: ${ALBUM}" echo "ARTIST: ${ARTIST}" if test -n "${BEGIN_SECTOR}"; then echo "BEGIN_SECTOR: ${BEGIN_SECTOR}" BEGIN_SECTOR_OPT="--tag=BEGIN_SECTOR=\"${BEGIN_SECTOR}\"" fi if test -n "${CDINDEX_ID}"; then echo "CDINDEX: ${CDINDEX_ID}" CDINDEX_ID_OPT="--tag=CDINDEX=\"${CDINDEX_ID}\"" fi if test -n "${CDDB_ID}"; then echo "CDDB: ${CDDB_ID}" CDDB_ID_OPT="--tag=CDDB=\"${CDDB_ID}\"" fi if test -n "${DATE}"; then echo "DATE: ${DATE}" DATE_OPT="--tag=DATE=\"${DATE}\"" fi echo "DESCRIPTION: ${DESCRIPTION}" if test -n "${ISRC}"; then echo "ISRC: ${ISRC}" ISRC_OPT="--tag=ISRC=\"${ISRC}\"" fi if test -n "${LEADOUT}"; then echo "LEADOUT: ${LEADOUT}" LEADOUT_OPT="--tag=LEADOUT=\"${LEADOUT}\"" fi if test -n "${MCN}"; then echo "MCN: ${MCN}" MCN_OPT="--tag=MCN=\"${MCN}\"" fi echo "TITLE: ${TITLE}" echo "TRACKNUMBER: ${TRACKNUMBER}" if test -n "`whereis trm | cut -d: -f2 | sed -e 's/ //g'`"; then TRM=`trm -w track${TRACKNUMBER}.cdda.wav` echo "TRM: ${TRM}" TRM_OPT="--tag=TRM=\"${TRM}\"" fi flac ${FLAC_OPTS} --tag=ALBUM="${ALBUM}" --tag=ARTIST="${ARTIST}" ${BEGIN_SECTOR_OPT} ${CDINDEX_ID_OPT} ${CDDB_ID_OPT} ${DATE_OPT} --tag=DESCRIPTION="${DESCRIPTION}" ${ISRC_OPT} ${LEADOUT_OPT} ${MCN_OPT} --tag=TITLE="${TITLE}" --tag=TRACKNUMBER="${TRACKNUMBER}" ${TRM_OPT} track${TRACKNUMBER}.cdda.wav mv track${TRACKNUMBER}.cdda.flac ${TRACKNUMBER}-${STITLE}.flac unset THIS_ISRC let COUNT+=1 done 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!"