2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2004 Jesus Climent <jesus.climent@hispalinux.es>
4 # This code is hereby licensed for public consumption under either the
5 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software
9 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
24 #echo "-A Experimental actions (retag, transcode)"
25 echo "-b Batch mode: enable album normalization and nogap encoding"
27 echo " Specify a configuration file (overrides system and user config files)"
29 echo " Specify discid to resume from (only needed if you no longer have the cd)"
31 echo " Specify CDROM device to grab"
32 echo "-D Debugging mode (equivalent to sh -x abcde)"
33 echo "-e Erase encoded track information from status file"
34 echo "-h This help information"
35 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
36 echo "-j <#> Number of encoder processes to run at once (localhost)"
37 echo "-k Keep the wav tracks for later use"
38 echo "-l Use low disk space algorithm"
39 echo "-L Use local CDDB storage directory"
40 echo "-n No lookup. Don't query CDDB, just create and use template"
41 echo "-N Noninteractive. Never prompt for anything"
42 echo "-m Modify playlist to include CRLF endings, to comply with some players"
43 echo "-M Create a CUE file"
44 echo "-o <type1[,type2]...>"
45 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc). Defaults to vorbis"
46 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
47 echo "-P Use UNIX pipes to read+encode without wav files"
48 echo "-r <host1[,host2]...>"
49 echo " Also encode on these remote hosts"
50 echo "-R Add replaygain values to the tag info (only for vorbis,flac)"
51 echo "-S <#> Set the CD speed"
52 #echo "-t File types to preprocess (wav)"
53 #echo "-T Set postprocessing options"
54 echo "-t <#> Start the track numbering at a given number"
55 echo "-T <#> Same as -t but modifies tag numbering"
56 echo "-v Show version number and exit"
57 echo "-V Be a bit more verbose about what is happening behind the scenes"
58 echo "-x Eject CD after all tracks are read"
60 echo " Add a comment to the CD tracks"
61 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
63 echo "Tracks is a space-delimited list of tracks to grab."
64 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
66 #echo "Double hyphens are used to concatenate tracks"
69 # Funtions to replace the need of seq, which is too distribution dependant.
73 while [ $i -ne `expr $2 + 1` ]
83 while [ $i -ne `expr $2 + 1` ]
91 # Functions to replace the need of awk {print $1} and {print $NF}
94 if [ X"$1" = "X" ]; then
95 for first in `cat`; do
106 if [ X"$1" = "X" ]; then
107 for stdin in `cat`; do
111 for last in $@ ; do :; done
116 # checkstatus [blurb]
117 # Returns "0" if the blurb was found, returns 1 if it wasn't
118 # Puts the blurb content, if available, on stdout.
119 # Otherwise, returns "".
122 # Take the last line in the status file if there's multiple matches
124 BLURB=$(egrep $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
126 if [ -z "$BLURB" ]; then
131 # See if there's a = in it
132 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
133 echo "$(echo $BLURB | cut -f2- -d=)"
139 # checkerrors [blurb]
140 # Returns "0" if the blurb was found (meaning there was an error),
141 # returns 1 if it wasn't (yes this is a little backwards).
142 # Does not print the blurb on stdout.
143 # Otherwise, returns "".
146 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
149 # Take the last line in the status file if there's multiple matches
151 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
153 if [ -z "$BLURB" ]; then
154 # negative, we did not have a negative...
157 # affirmative, we had a negative...
162 # run_command [blurb] [command...]
163 # Runs a command, silently if necessary, and updates the status file
168 # See if this is supposed to be silent
169 if [ "$(checkstatus encode-output)" = "loud" ]; then
173 # Special case for SMP, since
174 # encoder output is never displayed, don't mute echos
175 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
185 if [ "$RETURN" = "2" ]; then
186 # File was already normalized.
191 if [ "$RETURN" != "0" ]; then
192 # Put an error in the errors file. For various reasons we
193 # can't capture a copy of the program's output but we can
194 # log what we attempted to execute and the error code
195 # returned by the program.
196 if [ "$BLURB" ]; then
199 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
200 return $RETURN # Do not pass go, do not update the status file
202 if [ "$BLURB" ]; then
203 echo $BLURB >> "$ABCDETEMPDIR/status"
207 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
208 # distributed under the terms of the GNU GPL v2 or later, at your option
210 # Function to determine if a word contains a slash.
219 # Function to give the relative path from one file to another.
220 # Usage: relpath fromfile tofile
221 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
222 # (the result would be Album/Song.mp3)
223 # Output is relative path to $2 from $1 on stdout
225 # This code has the following restrictions:
226 # Multiple ////s are not collapsed into single /s, with strange effects.
227 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
228 # If FR is a directory it must have a trailing /
236 /*) ;; # No processing is needed for absolute paths
238 # Loop through common prefixes, ignoring them.
239 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
241 FR="$(echo "$FR" | cut -d/ -f2-)"
242 TO="$(echo "$TO" | cut -d/ -f2-)"
244 # Loop through directory portions left in FR, adding appropriate ../s.
247 FR="$(echo "$FR" | cut -d/ -f2-)"
256 # This code splits the a Various Artist track name from one of the following
259 # forward: Artist / Track
260 # forward-dash: Artist - Track
261 # reverse: Track / Artist
262 # reverse-dash: Track - Artist
263 # colon: Artist: Track
264 # trailing-paren: Artist (Track)
267 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
270 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
271 case "$VARIOUSARTISTSTYLE" in
273 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's- / -~-g')
274 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
275 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
278 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's, - ,~,g')
279 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
280 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
283 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's- / -~-g')
284 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
285 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
288 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's, - ,~,g')
289 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
290 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
293 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's-: -~-g')
294 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
295 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
298 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')
299 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
300 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
303 elif [ "$ONETRACK" = "y" ]; then
304 TRACKARTIST="Various"
306 TRACKARTIST="$DARTIST"
311 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
315 "classic rock") id=1 ;;
333 "industrial") id=19 ;;
334 "alternative") id=20 ;;
336 "death metal") id=22 ;;
338 "soundtrack") id=24 ;;
339 "euro-techno") id=25 ;;
343 "jazz+funk") id=29 ;;
346 "classical") id=32 ;;
347 "instrumental") id=33 ;;
351 "sound clip") id=37 ;;
354 "alt. rock") id=40 ;;
359 "meditative") id=45 ;;
360 "instrum. pop") id=46 ;;
361 "instrum. rock") id=47 ;;
365 "techno-indust.") id=51 ;;
366 "electronic") id=52 ;;
368 "eurodance") id=54 ;;
370 "southern rock") id=56 ;;
375 "christian rap") id=61 ;;
378 "native american") id=64 ;;
381 "psychadelic") id=67 ;;
383 "showtunes") id=69 ;;
387 "acid punk") id=73 ;;
388 "acid jazz") id=74 ;;
392 "rock & roll") id=78 ;;
393 "hard rock") id=79 ;;
395 "folk/rock") id=81 ;;
396 "national folk") id=82 ;;
403 "bluegrass") id=89 ;;
404 "avantgarde") id=90 ;;
405 "gothic rock") id=91 ;;
406 "progress. rock") id=92 ;;
407 "psychadel. rock") id=93 ;;
408 "symphonic rock") id=94 ;;
409 "slow rock") id=95 ;;
412 "easy listening") id=98 ;;
418 "chamber music") id=104 ;;
420 "symphony") id=106 ;;
421 "booty bass") id=107 ;;
423 "porn groove") id=109 ;;
425 "slow jam") id=111 ;;
429 "folklore") id=115 ;;
431 "power ballad") id=117 ;;
432 "rhythmic soul") id=118 ;;
433 "freestyle") id=119 ;;
435 "punk rock") id=121 ;;
436 "drum solo") id=122 ;;
437 "a capella") id=123 ;;
438 "euro-house") id=124 ;;
439 "dance hall") id=125 ;;
441 "drum & bass") id=127 ;;
442 "club-house") id=128 ;;
443 "hardcore") id=129 ;;
447 "negerpunk") id=133 ;;
448 "polsk punk") id=134 ;;
450 "christian gangsta rap") id=136 ;;
451 "heavy metal") id=137 ;;
452 "black metal") id=138 ;;
453 "crossover") id=139 ;;
454 "contemporary christian")id=140 ;;
455 "christian rock") id=141 ;;
456 "merengue") id=142 ;;
458 "thrash metal") id=144 ;;
461 "synthpop") id=147 ;;
468 # do_tag [tracknumber]
469 # id3 tags a filename
471 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
472 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
475 COMMENTOUTPUT="$(eval echo ${COMMENT})"
476 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
477 # If we want to start the tracks with a given number, we need to modify the
478 # TRACKNUM value before evaluation
479 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
480 # Get the trackpadding from the current track
481 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
482 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
484 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
488 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
489 GENREID=$(do_getgenreid "${CDGENRE}")
491 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
492 run_command tagtrack-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
493 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
494 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
495 "$ABCDETEMPDIR/track$1.$OUTPUT"
498 case "$OGGENCODERSYNTAX" in
500 # vorbiscomment can't do in-place modification, mv the file first
501 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
502 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
505 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
506 echo ARTIST="$TRACKARTIST"
508 echo TITLE="$TRACKNAME"
509 if [ -n "$CDYEAR" ]; then
512 if [ -n "$CDGENRE" ]; then
513 echo GENRE="$CDGENRE"
515 echo TRACKNUMBER=${TRACKNUM:-$1}
516 echo CDDB=$CDDBDISCID
517 if [ "$(eval echo ${COMMENT})" != "" ]; then
518 case "$COMMENTOUTPUT" in
519 *=*) echo "$COMMENTOUTPUT";;
520 *) echo COMMENT="$COMMENTOUTPUT";;
523 ) | run_command tagtrack-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
524 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
525 # Doublecheck that the commented file was created successfully before wiping the original
526 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
527 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
529 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
536 echo ARTIST="$TRACKARTIST"
538 echo TITLE="$TRACKNAME"
539 if [ -n "$CDYEAR" ]; then
542 if [ -n "$CDGENRE" ]; then
543 echo GENRE="$CDGENRE"
545 echo TRACKNUMBER=${TRACKNUM:-$1}
546 echo CDDB=$CDDBDISCID
547 if [ "$(eval echo ${COMMENT})" != "" ]; then
548 case "$COMMENTOUTPUT" in
549 *=*) echo "$COMMENTOUTPUT";;
550 *) echo COMMENT="$COMMENTOUTPUT";;
553 ) | run_command tagtrack-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
556 run_command tagtrack-$1 true
559 run_command tagtrack-$1 true
567 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
570 # The commands here don't go through run_command because they're never supposed to be silenced
571 echo "Batch encoding tracks: $TRACKQUEUE"
572 OUTPUT=$(echo $OUTPUTTYPE | grep "mp3" )
575 case "$MP3ENCODERSYNTAX" in
580 for UTRACKNUM in $TRACKQUEUE
582 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
584 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
586 if [ "$RETURN" != "0" ]; then
587 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
589 for UTRACKNUM in $TRACKQUEUE
591 echo encodetrack-$UTRACKNUM >> status
599 # Other encoders fall through to normal encoding as the tracks
600 # have not been entered in the status file.
603 # do_encode [tracknumber] [hostname]
604 # If no hostname is specified, encode locally
606 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
609 if [ "$USEPIPES" = "y" ]; then
612 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
615 TEMPARG="PIPE_$OGGENCODERSYNTAX"
618 TEMPARG="PIPE_$FLACENCODERSYNTAX"
621 TEMPARG="PIPE_$SPEEXENCODER"
624 TEMPARG="PIPE_$MPPENCODER"
629 IN="$ABCDETEMPDIR/track$1.wav"
632 case "$MP3ENCODERSYNTAX" in
633 # FIXME # check if mp3enc needs -if for pipes
647 # We need IN to proceed, if we are not using pipes.
648 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
649 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
653 OUT="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
656 OUT="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
659 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
662 if [ X"$USEPIPES" = "Xy" ]; then
665 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
666 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
672 case "$MP3ENCODERSYNTAX" in
673 lame|gogo) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
674 bladeenc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
675 l3enc|xingmp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
676 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
677 mp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
681 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
688 case "$OGGENCODERSYNTAX" in
689 vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
690 oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
694 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
701 case "$FLACENCODERSYNTAX" in
702 flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
708 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
709 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
714 if [ "$(eval echo ${COMMENT})" != "" ]; then
717 *) COMMENT="COMMENT=$COMMENT" ;;
719 COMMENT="--comment \"$COMMENT\""
721 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
722 if [ ! "$DOTAG" = "y" ]; then
723 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
725 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
729 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
731 # I tried compiling the mppenc from corecodecs.org and got some
732 # errors, so I have not tried it myself.
733 ## FIXME ## Needs some cleanup to determine if an empty tag sent
734 ## FIXME ## to the encoder ends up empty.
735 $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
739 # Only remove .wav if the encoding succeeded
740 if checkerrors "encodetrack-(.{3,4})-$1"; then
741 run_command encodetrack-$1 false
743 run_command encodetrack-$1 true
744 if [ ! "$KEEPWAVS" = "y" ] ; then
749 if [ "$(checkstatus encode-output)" = "loud" ]; then
750 echo "HEH! The file we were about to encode disappeared:"
753 run_command encodetrack-$1 false
757 # do_preprocess [tracknumber]
759 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
762 # IN="$ABCDETEMPDIR/track$1.wav"
763 # # We need IN to proceed.
764 # if [ -s "$IN" ] ; then
765 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
767 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
768 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
769 # case "$POSTPROCESSFORMAT" in
771 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
773 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
775 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
777 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
779 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
782 # # Only remove .wav if the encoding succeeded
783 # if checkerrors "preprocess-(.{3,4})-$1"; then
784 # run_command preprocess-$1 false
786 # run_command preprocess-$1 true
789 # if [ "$(checkstatus encode-output)" = "loud" ]; then
790 # echo "HEH! The file we were about to pre-process disappeared:"
793 # run_command preprocess-$1 false
798 # do_postprocess [tracknumber]
800 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
803 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
805 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
806 # # We need IN to proceed.
807 # if [ -s "$IN" ] ; then
808 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
809 # run_command '' echo "Post-processing track $1 of $TRACKS..."
810 # case "$POSTPROCESSFORMAT" in
812 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
814 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
816 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
818 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
820 # # Only remove .wav if the encoding succeeded
821 # if checkerrors "postprocess-(.{3,4})-$1"; then
822 # run_command postprocess-$1 false
824 # run_command postprocess-$1 true
827 # if [ "$(checkstatus encode-output)" = "loud" ]; then
828 # echo "HEH! The file we were about to post-process disappeared:"
831 # run_command postprocess-$1 false
846 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
850 # The commands here don't go through run_command because they're never supposed to be silenced
851 echo "Batch analizing gain in tracks: $TRACKQUEUE"
856 for UTRACKNUM in $TRACKQUEUE
858 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
860 # XXX: Hard-coded batch option!
861 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
863 if [ "$RETURN" != "0" ]; then
864 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
866 for UTRACKNUM in $TRACKQUEUE
868 echo normalizetrack-$UTRACKNUM >> status
876 # NORMALIZER, NORMALIZEROPTS
877 do_batch_normalize ()
879 # The commands here don't go through run_command because they're never supposed to be silenced
880 echo "Batch normalizing tracks: $TRACKQUEUE"
885 for UTRACKNUM in $TRACKQUEUE
887 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
889 # XXX: Hard-coded batch option!
890 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
892 if [ "$RETURN" != "0" ]; then
893 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
895 for UTRACKNUM in $TRACKQUEUE
897 echo normalizetrack-$UTRACKNUM >> status
903 # do_normalize [tracknumber]
905 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
908 IN="$ABCDETEMPDIR/track$1.wav"
909 if [ -e "$IN" ] ; then
910 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
911 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
913 if [ "$(checkstatus encode-output)" = "loud" ]; then
914 echo "HEH! The file we were about to normalize disappeared:"
917 run_command normalizetrack-$1 false "File $IN was not found"
921 # do_move [tracknumber]
922 # Deduces the outfile from environment variables
923 # Creates directory if necessary
925 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
928 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
932 OUTPUT=$OGGOUTPUTCONTAINER
935 OUTPUT=$FLACOUTPUTCONTAINER
938 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
939 # Munge filenames as follows:
944 # Eat control characters
945 ALBUMFILE=$(mungefilename "$DALBUM")
946 ARTISTFILE=$(mungefilename "$TRACKARTIST")
947 TRACKFILE=$(mungefilename "$TRACKNAME")
948 GENRE=$(mungegenre "$GENRE")
950 # If we want to start the tracks with a given number, we need to modify the
951 # TRACKNUM value before evaluation
952 if [ -n "$STARTTRACKNUMBER" ] ; then
953 # Get the trackpadding from the current track
954 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
955 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
957 TRACKNUM=${UTRACKNUM}
959 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
960 # TRACKFILE, and TRACKNUM.
961 if [ "$VARIOUSARTISTS" = "y" ]; then
962 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
964 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
966 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
967 OUTPUTFILEDIR=$(dirname "$OUTPUTDIR/$OUTPUTFILE")
968 # mkdir -p shouldn't return an error if the directory already exists
969 mkdir -p "$OUTPUTFILEDIR"
970 vecho "Moving $ABCDETEMPDIR/track$1.$OUTPUT to $OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
971 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
972 # Lets move the cue file
973 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
974 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
975 if checkstatus movecue-$OUTPUT; then :; else
976 vecho "Copying cue file to its destination directory..."
977 if checkstatus onetrack >/dev/null ; then
979 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
980 # http://brianvictor.tripod.com/mp3cue.htm#details
981 [a-z0-9][a-z0-9][a-z0-9])
982 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
985 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
989 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
991 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
999 # Create the playlist if wanted
1001 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1002 # VARIOUSARTISTS, OUTPUTDIR
1005 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1007 # Create a playlist file for the playlist data to go into.
1008 # We used to wipe it out if it existed. Now we request permision if interactive.
1009 for LASTTRACK in $TRACKQUEUE; do :; done
1010 ALBUMFILE=$(mungefilename "$DALBUM")
1011 ARTISTFILE=$(mungefilename "$DARTIST")
1012 GENRE=$(mungegenre "$GENRE")
1013 YEAR=${CDYEAR:-$CDYEAR}
1014 if [ "$VARIOUSARTISTS" = "y" ] ; then
1015 PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
1017 PLAYLISTFILE=$(eval echo $PLAYLISTFORMAT)
1019 FINALPLAYLISTDIR=$(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1020 mkdir -p "$FINALPLAYLISTDIR"
1021 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1022 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1023 if [ "$INTERACTIVE" = "y" ]; then
1024 while [ "$DONE" != "y" ]; do
1026 case $ERASEPLAYLIST in
1027 e|E|a|A|k|K) DONE=y ;;
1035 # Once we erase the playlist, we use append to create the new one.
1036 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1038 # The playlist does not exist, so we can safelly use append to create the new list
1041 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1042 touch "$OUTPUTDIR/$PLAYLISTFILE"
1043 for UTRACKNUM in $TRACKQUEUE
1045 # Shares some code with do_move since the filenames have to match
1046 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1047 TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1049 TRACKFILE=$(mungefilename "$TRACKNAME")
1050 ARTISTFILE=$(mungefilename "$TRACKARTIST")
1051 # If we want to start the tracks with a given number, we need to modify the
1052 # TRACKNUM value before evaluation
1053 if [ -n "$STARTTRACKNUMBER" ] ; then
1054 # Get the trackpadding from the current track
1055 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
1056 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1058 TRACKNUM=${UTRACKNUM}
1060 if [ "$VARIOUSARTISTS" = "y" ]; then
1061 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
1063 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
1065 if [ "$VARIOUSARTISTS" = "y" ]; then
1066 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1067 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1069 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1072 if [ "$PLAYLISTDATAPREFIX" ]; then
1073 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1075 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1080 ## this will convert the playlist to have CRLF line-endings, if specified
1081 ## (some hardware players insist on CRLF endings)
1082 if [ "$DOSPLAYLIST" = "y" ]; then
1083 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1084 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1085 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1087 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1092 # This essentially the start of things
1095 # Query the CD to get the track info, unless the user specified -C
1096 # or we are using some actions which do not need the CDDB data at all
1097 #if [ ! X"$EXPACTIONS" = "X" ]; then
1099 #elif [ -z "$DISCID" ]; then
1100 if [ -z "$DISCID" ]; then
1101 vecho -n "Getting CD track info... "
1102 # In OSX, unmount the disc before a query
1103 if [ "$OSFLAVOUR" = "OSX" ]; then
1104 disktool -u ${CDROM#/dev/}
1106 TRACKINFO=$($CDDISCID $CDROM)
1107 # Make sure there's a CD in there by checking cd-discid's return code
1108 if [ "$?" = "1" ]; then
1109 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1112 # In OSX, remount the disc again
1113 if [ "$OSFLAVOUR" = "OSX" ]; then
1114 disktool -m ${CDROM#/dev/}
1118 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1121 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1122 # This needs to be done now because a section of the resuming code will need
1125 # get the number of digits to pad TRACKNUM with - we'll use this later
1126 # a CD can only hold 99 tracks, but since we support a feature for starting
1127 # numbering the tracks from a given number, we might need to set it as a
1128 # variable for the user to define... or obtain it somehow.
1129 if [ "$PADTRACKS" = "y" ] ; then
1133 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1134 if [ -z "$TRACKQUEUE" ]; then
1135 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1136 case "$CDROMREADERSYNTAX" in
1138 if [ "$WEHAVEACD" = "y" ]; then
1139 vecho "Querying the CD for audio tracks..."
1140 CDPARANOIAOUTPUT="$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )"
1142 if [ ! "$RET" = "0" ];then
1143 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1145 TRACKS="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ' )"
1146 CDPARANOIAAUDIOTRACKS="$TRACKS"
1148 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks ; then
1149 TRACKS=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" )
1151 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1155 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1158 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1160 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1161 echo "The disc does not contain any tracks. Giving up..."
1164 echo -n "Grabbing entire CD - tracks: "
1165 if [ ! "$PADTRACKS" = "y" ] ; then
1166 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1168 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1170 while [ "$X" -ne "$TRACKS" ]
1172 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1173 TRACKQUEUE=$(echo "$TRACKQUEUE" $X)
1177 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1178 # User-supplied track queue.
1179 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1180 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1181 # Once cleaned, obtain the highest value in the trackqueue for number padding
1182 for LASTTRACK in $TRACKQUEUE; do :; done
1183 if [ ! "$PADTRACKS" = "y" ] ; then
1184 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1186 # Now we normalize the trackqueue
1187 for TRACK in $TRACKQUEUE ; do
1188 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1189 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1191 TRACKQUEUE=$PADTRACKQUEUE
1192 echo Grabbing tracks: "$TRACKQUEUE"
1195 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1197 # We have the discid, create a temp directory after it to store all the temp
1200 if [ -e "$ABCDETEMPDIR" ]; then
1201 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1202 # It already exists, see if it's a directory
1203 if [ ! -d "$ABCDETEMPDIR" ]; then
1204 # This is a file/socket/fifo/device/etc, not a directory
1207 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1208 echo "Please investigate, remove it, and rerun abcde." >&2
1212 # It's a directory, let's see if it's owned by us
1213 if [ ! -O "$ABCDETEMPDIR" ]; then
1214 # Nope, complain and exit
1216 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1217 echo "Please investigate, remove it, and rerun abcde." >&2
1221 # See if it's populated
1222 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1223 # Wipe and start fresh
1224 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1225 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1226 if [ "$INTERACTIVE" = "y" ]; then
1232 if [ "$ANSWER" != "y" ]; then
1235 rm -rf "$ABCDETEMPDIR" || exit 1
1236 mkdir "$ABCDETEMPDIR"
1237 if [ "$?" -gt "0" ]; then
1238 # Directory already exists or could not be created
1239 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1243 # Everything is fine. Check for ^encodetracklocation-
1244 # and encode-output entries in the status file and
1245 # remove them. These are not relevant across sessions.
1246 if [ -f "$ABCDETEMPDIR/status" ]; then
1247 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1248 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1249 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1251 # Remove old error messages
1252 if [ -f "$ABCDETEMPDIR/errors" ]; then
1253 rm -f "$ABCDETEMPDIR/errors"
1257 # We are starting from scratch
1258 mkdir "$ABCDETEMPDIR"
1259 if [ "$?" -gt "0" ]; then
1260 # Directory already exists or could not be created
1261 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1264 cat /dev/null > "$ABCDETEMPDIR/status"
1266 if [ X"$MAKECUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1267 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1268 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1269 vecho "Creating cue file..."
1270 $MKCUE $MKCUEOPTS > "$ABCDETEMPDIR/$CUEFILE"
1271 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1274 # If we got the CDPARANOIA status and it is not recorded, save it now
1275 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1276 if checkstatus cdparanoia-audio-tracks; then :; else
1277 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1278 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1283 # Create the discid file
1284 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1288 # Create a proper CUE file based on the CUE file we created before.
1291 # FIXME # we can get the name of the cuefile from the status file
1292 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1293 CUEFILE_OUT=$CUEFILE_IN.out
1294 ### FIXME ### checkstatus cddb
1295 if [ -e "$CDDBDATA" ]; then
1296 vecho "Adding metadata to the cue file..."
1297 # FIXME It doesn't preserve spaces! Why?
1298 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1300 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1301 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1302 cat "$CUEFILE_IN" | while read line
1304 if echo "$line" | grep -q "INDEX"
1306 eval track="\$TRACK$n"
1308 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1310 echo "$line" >> "$CUEFILE_OUT"
1312 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1313 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1319 # Parses a CDDB file and outputs the title and the track names.
1320 # Variables: CDDBFILE
1324 # List out disc title/author and contents
1325 if [ "$ONETRACK" = "y" ]; then
1326 vecho "ONETRACK mode selected: displaying only the title of the CD..."
1328 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1329 if [ ! "$ONETRACK" = "y" ]; then
1330 for TRACK in $(f_seq_row 1 $TRACKS)
1332 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1338 # Check for a local CDDB file, and report success
1341 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
1343 CDDBLOCALSUCCESS="n"
1344 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1345 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1348 # If the user has selected to check a local CDDB repo, we proceed with it
1349 if [ -r "${CDDBLOCALFILE}" ]; then
1350 # List out disc title/author and contents
1351 do_cddbparse "${CDDBLOCALFILE}"
1352 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1353 if [ "$INTERACTIVE" = "y" ]; then
1355 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1356 echo -n 'Invalid selection. Please answer "y" or "n": '
1359 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
1363 if [ "$USELOCALRESP" = "y" ]; then
1364 #echo "Using local copy of CDDB data"
1365 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1366 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1367 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
1368 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1369 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1370 CDDBLOCALSUCCESS="y"
1372 #echo "Not using local copy of CDDB data"
1373 CDDBLOCALSUCCESS="n"
1376 CDDBLOCALSUCCESS="n"
1384 # Perform CDDB protocol version check if it hasn't already been done
1385 if checkstatus cddb-statcomplete; then :; else
1386 if [ "$CDDBAVAIL" = "n" ]; then
1388 echo 503 > "$ABCDETEMPDIR/cddbstat"
1391 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1392 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1393 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1394 vecho "Checking CDDB server status..."
1395 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1396 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
1397 case "$RESPONSECODE" in
1398 210) # 210 OK, status information follows (until terminating `.')
1401 501|*) # 501 Illegal CDDB protocol level: <n>.
1402 CDDBPROTO=`expr $CDDBPROTO - 1`
1406 if test $rc -eq 1; then
1410 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
1418 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1419 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1421 # Perform CDDB query if it hasn't already been done
1422 if checkstatus cddb-querycomplete; then :; else
1423 if [ "$CDDBAVAIL" = "n" ]; then
1425 echo 503 > "$ABCDETEMPDIR/cddbquery"
1426 # The default CDDBLOCALSUCCESS is "n"
1427 # This part will be triggered if the user CDDB repo does not
1428 # contain the entry, or if we are not trying to use the repo.
1430 vecho "Querying the CDDB server..."
1431 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1432 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1433 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1439 # no match found in database,
1440 # wget/fetch error, or user requested not to use CDDB
1441 # Make up an error code (503) that abcde
1442 # will recognize in do_cddbread
1443 # and compensate by making a template
1444 echo 503 > "$ABCDETEMPDIR/cddbquery"
1446 *) # strange and unknown error
1447 echo ERRORCODE=$ERRORCODE
1448 echo "abcde: $CDDBTOOL returned unknown error code"
1452 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
1459 # If it's not to be used, generate a template.
1460 # Then, display it (or them) and let the user choose/edit it
1461 if checkstatus cddb-readcomplete; then :; else
1462 vecho "Obtaining CDDB results..."
1463 # If CDDB is to be used, interpret the query results and read all
1464 # the available entries.
1465 rm -f "$ABCDETEMPDIR/cddbchoices"
1466 CDDBCHOICES=1 # Overridden by multiple matches
1467 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
1468 case "$RESPONSECODE" in
1470 # One exact match, retrieve it
1471 # 200 [section] [discid] [artist] / [title]
1472 if checkstatus cddb-read-1-complete; then :; else
1473 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1474 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1475 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1476 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1477 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1479 # List out disc title/author and contents
1480 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1481 for TRACK in $(f_seq_row 1 $TRACKS)
1483 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1485 echo >> "$ABCDETEMPDIR/cddbchoices"
1489 case "$RESPONSECODE" in
1490 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1491 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1492 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1494 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1495 # List out disc title/author and contents of template
1496 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
1498 for TRACK in $(f_seq_row 1 $TRACKS)
1500 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1502 echo >> "$ABCDETEMPDIR/cddbchoices"
1503 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
1504 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
1507 # Multiple exact, (possibly multiple) inexact matches
1509 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
1510 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
1511 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1512 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1513 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1515 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1517 vecho -n "Retrieving multiple matches... "
1518 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
1519 read DISCINFO # eat top line
1523 if checkstatus cddb-read-$X-complete; then :; else
1524 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1525 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
1527 # List out disc title/author and contents
1528 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1529 for TRACK in $(f_seq_row 1 $TRACKS)
1531 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1533 echo >> "$ABCDETEMPDIR/cddbchoices"
1536 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1540 for TRACK in $(f_seq_row 1 $TRACKS)
1542 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1544 echo >> "$ABCDETEMPDIR/cddbchoices"
1545 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1546 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1549 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1556 if checkstatus cddb-edit >/dev/null; then
1557 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1558 VARIOUSARTISTS="$(checkstatus variousartists)"
1559 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
1562 if [ "$INTERACTIVE" = "y" ]; then
1563 # We should show the CDDB results both when we are not using the local CDDB repo
1564 # or when we are using it but we could not find a proper match
1565 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1566 # Display the $ABCDETEMPDIR/cddbchoices file created above
1567 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1568 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1569 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1570 CHOICE=$(checkstatus cddb-choice)
1571 if [ -n "$CHOICE" ] ; then
1572 case $CDDBCHOICES in
1573 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1575 echo "Selected: #$CHOICE"
1576 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1580 # The user has a choice to make, display the info in a pager if necessary
1581 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
1582 # Use the debian sensible-pager wrapper to pick the pager
1583 # user has requested via their $PAGER environment variable
1584 if [ -x "/usr/bin/sensible-pager" ]; then
1585 /usr/bin/sensible-pager "$ABCDETEMPDIR/cddbchoices"
1586 elif [ -x "$PAGER" ]; then
1587 # That failed, try to load the preferred editor, starting
1588 # with their PAGER variable
1589 $PAGER "$ABCDETEMPDIR/cddbchoices"
1590 # If that fails, check for less
1591 elif [ -x /usr/bin/less ]; then
1592 /usr/bin/less -f "$ABCDETEMPDIR/cddbchoices"
1593 # more should be on all UNIX systems
1594 elif [ -x /bin/more ]; then
1595 /bin/more "$ABCDETEMPDIR/cddbchoices"
1597 # No bananas, just cat the thing
1598 cat "$ABCDETEMPDIR/cddbchoices" >&2
1601 # It's all going to fit in one page, cat it
1602 cat "$ABCDETEMPDIR/cddbchoices" >&2
1605 # I'll take CDDB read #3 for $400, Alex
1606 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1608 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
1609 # Make sure we get a valid choice
1610 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
1611 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1612 echo "Invalid selection. Please choose a number between 1 and $CDDBCHOICES." >&2
1613 echo -n "Selection [0-$CDDBCHOICES]: " >&2
1615 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
1617 if [ "$CDCHOICENUM" = "0" ]; then
1618 vecho "Creating empty CDDB template..."
1620 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1622 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1623 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1625 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1629 # We need some code to show the selected option when local repository is selected and we have found a match
1630 vecho "Using cached CDDB match..." >&2
1631 # Display the $ABCDETEMPDIR/cddbchoices file created above
1632 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1633 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1634 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1635 CHOICE=$(checkstatus cddb-choice)
1636 if [ "$USELOCALRESP" = "y" ]; then :; else
1637 if [ -n "$CHOICE" ] ; then
1638 case $CDDBCHOICES in
1641 echo "Selected template."
1643 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1645 echo "Selected: #$CHOICE"
1646 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1654 # We're noninteractive - pick the first choice.
1655 # But in case we run a previous instance and selected a choice, use it.
1656 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1657 # Show the choice if we are not using the locally stored one
1658 # or when the local search failed to find a match.
1659 PREVIOUSCHOICE=$(checkstatus cddb-choice)
1660 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1661 #if [ "$PREVIOUSCHOICE" ]; then
1662 cat "$ABCDETEMPDIR/cddbchoices"
1665 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1666 CDCHOICENUM=$PREVIOUSCHOICE
1669 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1671 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1676 if checkstatus cddb-choice >/dev/null; then :; else
1677 echo "abcde: internal error: cddb-choice not recorded." >&2
1680 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1681 echo -n "Edit selected CDDB data? [y/n] (" >&2
1682 if [ "$INTERACTIVE" = "y" ]; then
1683 if [ "$UNKNOWNDISK" = "y" ]; then
1686 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
1695 if [ "$EDITCDDB" = "y" ]; then
1696 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
1698 # Use the debian sensible-editor wrapper to pick the editor that the
1699 # user has requested via their $EDITOR environment variable
1700 if [ -x "/usr/bin/sensible-editor" ]; then
1701 /usr/bin/sensible-editor "$CDDBDATA"
1702 elif [ -n "$EDITOR" ]; then
1703 if [ -x $(which "${EDITOR%%\ *}") ]; then
1704 # That failed, try to load the preferred editor, starting
1705 # with their EDITOR variable
1706 eval $(echo "$EDITOR") \"$CDDBDATA\"
1708 # If that fails, check for a vi
1709 elif which vi >/dev/null 2>&1; then
1711 elif [ -x /usr/bin/vi ]; then
1712 /usr/bin/vi "$CDDBDATA"
1713 # nano should be on all (modern, i.e., sarge) debian systems
1714 elif which nano >/dev/null 2>&1 ; then
1716 elif [ -x /usr/bin/nano ]; then
1717 /usr/bin/nano "$CDDBDATA"
1718 # mg should be on all OpenBSD systems
1719 elif which mg >/dev/null 2>&1 ; then
1721 elif [ -x /usr/bin/mg ]; then
1722 /usr/bin/mg "$CDDBDATA"
1725 echo "No editor available. Check your EDITOR environment variable." >&2
1727 # delete editor backup file if it exists
1728 if [ -w "$CDDBDATA~" ]; then
1733 # Some heuristics first. Look at Disc Title, and if it starts with
1734 # "Various", then we'll assume Various Artists
1735 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1736 echo "Looks like a Multi-Artist CD" >&2
1739 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1740 if [ "$INTERACTIVE" = "y" ]; then
1747 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1750 # Need NUMTRACKS before cddb-tool will return it:
1751 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
1752 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1753 # More than 1/2 tracks contain a "/", so guess forward
1755 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1756 # More than 1/2 contain a "-", so guess forward-dash
1758 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1759 # More than 1/2 contain something in parens, so guess trailing-paren
1763 echo "1) Artist / Title" >&2
1764 echo "2) Artist - Title" >&2
1765 echo "3) Title / Artist" >&2
1766 echo "4) Title - Artist" >&2
1767 echo "5) Artist: Title" >&2
1768 echo "6) Title (Artist)" >&2
1769 echo "7) This is a single-artist CD" >&2
1770 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1771 if [ "$INTERACTIVE" = "y" ]; then
1772 read VARIOUSARTISTSTYLE
1774 echo $DEFAULTSTYLE >&2
1775 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
1777 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
1778 # If they press Enter, then the default style (0) was chosen
1779 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
1780 echo "Invalid selection. Please choose a number between 1 and 7."
1781 echo -n "Selection [1-7]: "
1782 read VARIOUSARTISTSTYLE
1783 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
1785 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1786 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
1788 vecho "Selected: $VARIOUSARTISTSTYLE"
1789 case "$VARIOUSARTISTSTYLE" in
1791 VARIOUSARTISTSTYLE=forward
1794 VARIOUSARTISTSTYLE=forward-dash
1797 VARIOUSARTISTSTYLE=reverse
1800 VARIOUSARTISTSTYLE=reverse-dash
1803 VARIOUSARTISTSTYLE=colon
1806 VARIOUSARTISTSTYLE=trailing-paren
1814 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1815 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1817 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1818 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $($MD5SUM "$CDDBDATA" | cut -d " " -f 1) ]; then
1819 # This works but does not have the necessary error checking
1820 # yet. If you are familiar with the CDDB spec
1821 # (see http://www.freedb.org/src/latest/DBFORMAT)
1822 # and can create an error-free entry on your own, then put
1823 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1824 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1825 # your abcde.conf to change the email address submissions are
1828 # submit the modified file, if they want
1829 if [ "$NOSUBMIT" != "y" ]; then
1830 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1832 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1833 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1835 echo -n 'Invalid selection. Please answer "y" or "n": '
1838 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
1839 echo -n "Sending..."
1840 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
1846 # Make sure the cache directory exists
1847 mkdir -p $CDDBLOCALDIR
1848 # Cache edited CDDB entry in the user's cddb dir
1849 if [ "$CDDBCOPYLOCAL" = "y" ] || [ "$COPYCDDBLOCAL" = "Y" ]; then
1850 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
1853 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1856 # do_cdread [tracknumber]
1857 # do_cdread onetrack [firsttrack] [lasttrack]
1861 # The commands here don't go through run_command because they're never supposed to be silenced
1862 # return codes need to be doublechecked anyway, however
1863 if [ "$1" = "onetrack" ]; then
1864 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1865 # FIXME # Until then, we grab the whole CD in one track, no matter what
1867 # We need the first and last track for cdda2wav
1870 UTRACKNUM=$FIRSTTRACK
1871 case "$CDROMREADERSYNTAX" in
1872 cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
1873 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
1874 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1880 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1881 if [ "$USEPIPES" = "y" ]; then
1882 TEMPARG="PIPE_$CDROMREADERSYNTAX"
1883 FILEARG="${!TEMPARG}"
1885 PIPE_MESSAGE="and encoding "
1887 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1888 case "$CDROMREADERSYNTAX" in
1889 ## FIXME ## Find the case for dagrab, to avoid exceptions
1891 FILEARG="-f $WAVDATA"
1899 if [ "$1" = "onetrack" ]; then
1900 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
1902 if [ -r "$CDDBDATA" ]; then
1903 TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
1904 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1906 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1909 case "$CDROMREADERSYNTAX" in
1911 nice $READNICE $CDROMREADER -d $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
1913 if [ "$OSFLAVOUR" = "OSX" ] ; then
1914 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1915 disktool -u ${CDROM#/dev/} 0
1916 # Also, in OSX the cdrom device for cdda2wav changes...
1917 CDDA2WAVCDROM="IODVDServices"
1918 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1919 CDDA2WAVCDROM="$CDROMID"
1921 if [ "$CDROMID" = "" ]; then
1922 CDDA2WAVCDROM="$CDROM"
1924 CDDA2WAVCDROM="$CDROMID"
1927 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
1929 ## FIXME ## We have an exception for dagrab, since it uses -f
1930 ## FIXME ## Shall we just use -f $FILEARG ??
1931 dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
1934 # Find the track's mounted path
1935 REALTRACKNUM=$(expr $UTRACKNUM + 0)
1936 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
1937 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
1938 # If the file exists, copy it
1939 if [ -e "$FILEPATH" ] ; then
1940 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
1944 debug) nice $READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
1948 # If we get some error or we get some missing wav
1949 # (as long as we dont use pipes)
1950 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
1951 # Thank goodness errors is only machine-parseable up to the
1952 # first colon, otherwise this woulda sucked
1953 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1954 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
1956 if [ "$USEPIPES" = "y" ]; then
1957 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1959 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1963 if [ "$USEPIPES" = "y" ]; then
1964 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
1966 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
1967 if [ "$1" = "onetrack" ]; then
1968 echo onetrack >> "$ABCDETEMPDIR/status"
1975 # No values accepted, only uses env variables
1978 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
1979 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
1981 echo "abcde: unable to set the device speed" >&2
1987 # vecho outputs a message if EXTRAVERBOSE is selected
1990 if [ x"$EXTRAVERBOSE" != "x" ]; then
1995 # User-redefinable functions
1996 # Custom filename munging:
1999 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2000 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
2003 # Custom genre munging:
2006 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2010 # Empty pre_read function, to be defined in the configuration file.
2016 ###############################################################################
2019 # Start of execution
2020 ###############################################################################
2023 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2024 CDDBSUBMIT=freedb-submit@freedb.org
2026 HELLOINFO="$(whoami)@$(hostname)"
2028 CDROMREADERSYNTAX=cdparanoia
2029 ENCODERSYNTAX=default
2031 MP3ENCODERSYNTAX=default
2032 OGGENCODERSYNTAX=default
2033 FLACENCODERSYNTAX=default
2034 SPEEXENCODERSYNTAX=default
2035 MPPENCODERSYNTAX=default
2036 NORMALIZERSYNTAX=default
2038 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2039 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2040 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2041 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2042 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2043 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2044 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2045 PLAYLISTDATAPREFIX=''
2046 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2047 VAPLAYLISTDATAPREFIX=''
2055 VARIOUSARTISTSTYLE=forward
2059 CDDBLOCALDIR="$HOME/.cddb"
2062 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2063 # i.e. CDROMID="1,0,0"
2066 # program paths - defaults to checking your $PATH
2072 XINGMP3ENC=xingmp3enc
2086 CDPARANOIA=cdparanoia
2095 VORBISCOMMENT=vorbiscomment
2097 NORMALIZE=normalize-audio
2099 VORBISGAIN=vorbisgain
2102 # Options for programs called from abcde
2133 VORBISCOMMENTOPTS="-R"
2134 METAFLACOPTS="--no-utf8-convert"
2136 # Default to one process if -j isn't specified
2139 # List of actions to perform - by default, run to completion
2140 ACTIONS=cddb,read,encode,tag,move,clean
2142 # List of prefered outputs - by default, run with whatever we have in the path
2143 # This option is basicaly for Debian package dependencies
2144 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex
2146 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2147 # Let's use these checkings to determine the OS flavour, which will be used later
2148 if [ X$(uname) = "XFreeBSD" ] ; then
2152 elif [ X$(uname) = "XDarwin" ] ; then
2155 # We should have disktool in OSX, but let's be sure...
2157 CDROMREADERSYNTAX=cddafs
2158 elif [ X$(uname) = "XOpenBSD" ] ; then
2165 # If CDDBAVAIL is set to n, no CDDB read is done
2166 # If USEID3 is set to n, no ID3 tagging is done
2171 if [ -z "$OUTPUTDIR" ]; then
2175 if [ -z "$WAVOUTPUTDIR" ]; then
2176 WAVOUTPUTDIR="$OUTPUTDIR"
2179 # Load system defaults
2180 if [ -r /etc/abcde.conf ]; then
2183 # Load user preference defaults
2184 if [ -r $HOME/.abcde.conf ]; then
2188 # By this time, we need some HTTPGETOPTS already defined.
2189 # If the user has defined a non-default HTTPGET method, we should not be empty.
2191 if [ "$HTTPGETOPTS" = "" ] ; then
2193 wget) HTTPGETOPTS="-q -O -";;
2194 curl) HTTPGETOPTS="-f -s";;
2195 fetch)HTTPGETOPTS="-q -o -";;
2196 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2200 # If the CDROM has not been set yet, find a suitable one.
2201 # If this is a devfs system, default to /dev/cdroms/cdrom0
2202 # instead of /dev/cdrom
2203 if [ "$CDROM" = "" ] ; then
2204 if [ -e /dev/cdroms/cdrom0 ]; then
2205 CDROM=/dev/cdroms/cdrom0
2206 elif [ -e /dev/cdrom ]; then
2208 elif [ -e /dev/cd0c ]; then
2210 elif [ -e /dev/acd0c ]; then
2212 elif [ -e /dev/disk1 ]; then
2217 # Parse command line options
2218 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
2219 while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2222 a) ACTIONS="$OPTARG" ;;
2223 A) EXPACTIONS="$OPTARG";;
2225 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2226 C) DISCID="${OPTARG#abcde.}" ;;
2227 d) CDROM="$OPTARG" ;;
2229 e) ERASEENCODEDSTATUS=y ;;
2231 e) ERASEENCODEDSTATUS=y ;;
2232 # f) FORCECDDBUSELOCAL=y ;;
2234 j) MAXPROCS="$OPTARG" ;;
2237 L) CDDBUSELOCAL=y ;;
2242 o) OUTPUTTYPE="$OPTARG" ;;
2245 r) REMOTEHOSTS="$OPTARG" ;;
2247 s) STARTTRACKNUMBER="$OPTARG" ;;
2248 S) CDSPEEDVALUE="$OPTARG" ;;
2249 # t) PREPROCESSFORMATS="$OPTARG"
2251 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2252 t) STARTTRACKNUMBER="$OPTARG" ;;
2253 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
2255 echo "This is abcde v$VERSION."
2256 echo "Usage: abcde [options] [tracks]"
2257 echo "abcde -h for extra help"
2260 V) EXTRAVERBOSE="y" ;;
2262 w) COMMENT="$OPTARG" ;;
2263 W) if echo $OPTARG | grep -q "[[:digit:]]" ; then
2264 STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
2266 echo "abcde error: argument of -W must be integer"
2274 shift $(($OPTIND - 1))
2276 # Decide if we can continue.
2277 if [ "$ONETRACK" = "y" ]; then
2278 # FIXME # remove check as soon as we find out about the other readers
2279 case "$CDROMREADERSYNTAX" in
2282 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2285 if [ "$BATCH" = "y" ]; then
2286 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2289 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2290 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2291 if [ $# -gt 0 ]; then
2292 vecho "abcde warning: ONETRACK mode selected, grabbing all tracks..."
2295 while [ $# -gt 0 ]; do
2296 # Range parsing code courtesy of Vincent Ho
2297 RSTART=$(echo $1 | cut -f1 -d-)
2298 REND=$(echo $1 | cut -f2 -d-)
2299 if [ "$RSTART" = "$REND" ]; then
2302 NEWTRACKS=$(f_seq_line $RSTART $REND)
2304 TRACKQUEUE=$(echo "$TRACKQUEUE" "$NEWTRACKS")
2309 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2310 # List of experimental actions: retag,transcode
2312 # Determine what actions are to be done from $ACTIONS and set the
2313 # following environment variables for them:
2325 for ACTION in $(echo $ACTIONS | tr , \ )
2330 normalize) DONORMALIZE=y; DOREAD=y;;
2331 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2332 encode) DOENCODE=y; DOREAD=y;;
2333 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2334 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2335 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2336 playlist) DOCDDB=y; DOPLAYLIST=y;;
2343 # Check the encoding format, if nothing has been configured in the system, from the ones available in the system
2344 if [ X"$OUTPUTTYPE" = "X" ]; then
2345 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
2346 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2347 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2348 if which $DEFAULT_OUTPUT_BINARY > /dev/null 2>&1 ; then
2349 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
2350 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2354 if [ X"$OUTPUTTYPE" = "X" ]; then
2355 echo "abcde error: no encoder found in the PATH" >&2
2356 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2361 # At this point a CDROM has to be defined, so we check it exists.
2362 if [ X"$CDROM" != "X" ] ; then
2363 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2364 if [ "$OSFLAVOUR" = "FBSD" ]; then
2365 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
2366 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2367 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2371 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
2372 echo "abcde error: CDROM device cannot be found." >&2
2375 # avoid processing if we are not going to hit the CDROM.
2376 elif [ X"$DOREAD" = "Xy" ]; then
2377 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2381 # USEPIPES pre-tests, before we get into more serious stuff
2382 # Not compatible with:
2383 # - multiple outputs
2385 # - lowdisk algorithm
2387 if [ X"$USEPIPES" = "Xy" ]; then
2388 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
2389 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
2392 if [ X"$DONORMALIZE" = "Xy" ]; then
2393 echo "abcde error: Unix pipes not compatible with normalizer"
2394 # FIXME # Do we need to exit or shall we just disable the mode?
2397 if [ X"$DOENCODE" = "Xn" ]; then
2398 vecho "Disabling Unix pipes since we are not encoding!"
2401 if [ X"$LOWDISK" = "Xy" ]; then
2402 vecho "abcde error: Unix pipes not compatible with lowdisk algorithm"
2407 # Decide which CDROM reader we're gonna use
2408 case "$CDROMREADERSYNTAX" in
2410 CDROMREADER="$CDPARANOIA"
2411 CDROMREADEROPTS="$CDPARANOIAOPTS"
2414 CDROMREADER="$CDDA2WAV"
2415 CDROMREADEROPTS="$CDDA2WAVOPTS"
2418 CDROMREADER="$DAGRAB"
2419 CDROMREADEROPTS="$DAGRABOPTS"
2422 CDROMREADER="$CDDAFS"
2423 CDROMREADEROPTS="$CDDAFSOPTS"
2427 # There's only one normalize...
2428 case "$NORMALIZERSYNTAX" in
2430 NORMALIZER="$NORMALIZE"
2431 NORMALIZEROPTS="$NORMALIZEOPTS"
2435 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2436 if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
2437 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ ); do
2439 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2440 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2441 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2442 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2443 mpc:*) MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2446 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ ); do
2447 TEMPOUTPUT=$( echo "$OUTPUT" | cut -d: -f1 )
2448 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2450 OUTPUTTYPE="$TEMPOUTPUTTYPE"
2453 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac for flacs and speexenc for speex and mppenc for mpps
2455 # Getting ready for multiple output changes
2456 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
2460 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
2461 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
2462 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
2463 OGGOUTPUTCONTAINER=ogg
2466 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
2467 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
2470 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
2471 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
2474 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
2477 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
2479 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2485 # decide which encoder
2486 case "$MP3ENCODERSYNTAX" in
2488 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2492 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2496 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2497 MP3ENCODER="$BLADEENC"
2500 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2504 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2505 MP3ENCODER="$XINGMP3ENC"
2508 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2509 MP3ENCODER="$MP3ENC"
2512 case "$OGGENCODERSYNTAX" in
2514 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2515 OGGENCODER="$VORBIZE"
2518 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2519 OGGENCODER="$OGGENC"
2522 case "$FLACENCODERSYNTAX" in
2524 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2526 # FLAC streams can be encapsulated on a Ogg transport layer
2527 if echo "$FLACENCODEROPTS" | egrep -q -- "(^| )--ogg($| )" ;then
2528 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2529 echo " due to problem with adding comments to such files" >&2
2531 FLACOUTPUTCONTAINER=ogg
2533 FLACOUTPUTCONTAINER=flac
2537 case "$SPEEXENCODERSYNTAX" in
2539 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2540 SPEEXENCODER="$SPEEXENC"
2543 case "$MPPENCODERSYNTAX" in
2545 MPPENCODEROPTS="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2546 MPPENCODER="$MPPENC"
2552 if [ "$ID3TAGV" = "1" ]; then
2554 TAGGEROPTS="$ID3OPTS"
2557 TAGGEROPTS="$ID3V2OPTS"
2560 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2561 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2562 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2563 echo " due to problem with adding comments to such files" >&2
2565 OGGOUTPUTCONTAINER=ogg.ogg
2566 FLACOUTPUTCONTAINER=flac.ogg
2567 vecho "abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2570 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2572 if [ "$ENCNICE" ]; then
2573 ENCNICE="-n $ENCNICE"
2575 if [ "$READNICE" ]; then
2576 READNICE="-n $READNICE"
2578 if [ "$DISTMP3NICE" ]; then
2579 DISTMP3NICE="-n $DISTMP3NICE"
2582 # Don't check for stuff if it's not needed
2583 if [ "$REMOTEHOSTS" ]; then
2586 if [ "$DONORMALIZE" = "y" ]; then
2589 if [ "$EJECTCD" = "y" ]; then
2592 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2595 if [ "$CUEFILE" = "y" ]; then
2599 if [ X"$CDSPEEDVALUE" != "X" ]; then
2600 case "$CDROMREADERSYNTAX" in
2601 cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2606 # Rippers with USEPIPE support
2607 # FIXME # Include here all the rippers we can figure out support pipes
2610 # Encoders with USEPIPE support
2611 # FIXME # Include here all the encoders we can figure out support pipes
2616 # Figure out if we can use pipes with the ripper/encoder combination
2618 if [ "$USEPIPES" = "y" ]; then
2619 PIPERIPPERSVARCHECK="PIPE_${CDROMREADER}"
2622 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
2624 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
2626 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
2628 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
2630 PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
2632 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2633 echo "abcde error: no support for pipes with given ripper" >&2
2634 echo "read the USEPIPES file from the source tarball to help" >&2
2635 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2638 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2639 echo "abcde error: no support for pipes with given encoder" >&2
2640 echo "read the USEPIPES file from the source tarball to help" >&2
2641 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2646 # Make sure a buncha things exist
2647 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2648 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2649 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2650 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2651 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2652 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2653 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2655 # Cut off the command-line options we just added in
2656 X=$(echo $X | cut -d' ' -f2)
2657 if [ "$(which $X)" = "" ]; then
2658 echo "abcde error: $X is not in your path." >&2
2660 elif [ ! -x $(which $X) ]; then
2661 echo "abcde error: $X is not executable." >&2
2666 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
2667 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
2668 HTTPGET="$HTTPGET $HTTPGETOPTS"
2670 # Here it used to say:
2671 # One thousand lines in, we can start doing stuff with things
2672 # Well, right now we are at line 2157 ;)
2674 # Export needed things so they can be read in this subshell
2675 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2676 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2678 # User-definable function to set some things. Use it for
2679 # - closing the CD tray with eject -t
2680 # - set the CD speed value with eject -x
2681 vecho -n "Executing customizable pre-read function... "
2683 pre_read # Execute the user-defined pre-read funtion. Close the CD with it.
2687 do_discid # Get ABCDETEMPDIR created and status file initialized
2689 if [ "$DOCDDB" = "y" ]; then
2690 if [ $CDDBUSELOCAL = "y" ]; then
2693 if checkstatus cddb-choice > /dev/null; then
2696 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2704 eval $($CDDBTOOL parse "$CDDBDATA")
2707 # Before reading tracks, we set the speed of the device
2709 if [ X"$CDSPEEDVALUE" != "X" ]; then
2710 case "$CDROMREADERSYNTAX" in
2711 cdparanoia|debug) : ;;
2716 # Define the first and last track, since we might need them later in several places
2717 FIRSTTRACK=$( get_first $TRACKQUEUE )
2718 LASTTRACK=$( get_last $TRACKQUEUE )
2720 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
2721 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2722 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2723 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2726 # Create playlist if needed (backgroundable) and start reading in tracks
2730 if [ ! "$ONETRACK" = "y" ]; then
2731 if [ "$DOPLAYLIST" = "y" ]; then
2732 echo Creating playlist... >&2
2737 # For the lowdisk option, only one program is running at once so the encoder
2738 # can be unsilenced right away.
2739 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
2740 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2743 if [ "$ONETRACK" = "y" ]; then
2744 TRACKS="$FIRSTTRACK"
2745 if checkstatus readtrack-$FIRSTTRACK; then :; else
2746 do_cdread onetrack $FIRSTTRACK $LASTTRACK
2749 for UTRACKNUM in $TRACKQUEUE
2751 if [ "$DOREAD" = "y" ]; then
2752 if [ "$USEPIPES" = "y" ]; then
2753 if checkstatus readencodetrack-$UTRACKNUM; then :; else
2754 # Read, pipe, shut up!
2755 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
2758 if checkstatus readtrack-$UTRACKNUM; then :; else
2759 do_cdread $UTRACKNUM
2761 if [ "$?" != "0" ]; then
2762 # CD read failed - don't give the goahead to
2769 if [ "$BATCH" = "y" ]; then
2772 echo NEXTTRACK # Get the encoder machine churning again
2773 if [ "$DOREAD" = "y" ]; then
2774 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2775 until checkstatus encodetrack-$UTRACKNUM
2777 if checkerrors encodetrack-$UTRACKNUM; then
2788 # Now that we're done the encoding can be loud again -
2789 # if we're not using SMP.
2790 if [ "$MAXPROCS" = "1" ]; then
2791 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2794 # All tracks read, start encoding.
2795 if [ "$BATCH" = "y" ] || [ "$ONETRACK" = "y" ]; then
2799 # We are now finished with the cdrom - it can be safely ejected. Note that
2800 # abcde will not have completed yet.
2801 if [ "$EJECTCD" = "y" ] && [ -x $(which $EJECT) ]; then
2802 # We check if the disk we are processing is actually the disk inside the
2803 # CD tray. If not, we do not eject the CD, since it might be so that the
2804 # user ejected it manually.
2805 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2806 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2807 # More FreeBSD bits.
2808 if [ X"$(uname)" = X"FreeBSD" ] ; then
2809 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2810 # but in this script EJECT is in the envionment and names the program
2813 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2814 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2815 $eject $EJECTOPTS $cd
2816 elif [ X"$(uname)" = X"Darwin" ] ; then
2817 disktool -e ${CDROM#/dev/} 0
2819 $EJECT $EJECTOPTS $CDROM
2826 ## Do we need to pre-process
2827 #if [ x"$PREPROCESS" = "x" ] ; then
2830 # for PRETRACKNUM in $TRACKQUEUE
2833 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2835 # until [ $PREPROCEED ]
2837 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2838 # # all locations are working, wait and try again later
2839 # if [ ! $PREPROCEED ]; then sleep 3; fi
2841 # ( do_preprocess $PRETRACKNUM
2849 # In batch mode, we want all tracks to be read first.
2850 if [ "$BATCH" = "y" ]; then
2851 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
2852 if [ "$GOAHEAD" = "NO" ]; then break; fi
2853 for LASTTRACK in $TRACKQUEUE; do :; done
2854 if checkstatus readtrack-$LASTTRACK; then
2855 if [ "$DONORMALIZE" = "y" ]; then
2856 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
2857 if checkerrors batch-normalize; then exit; fi
2859 if [ "$DOENCODE" = "y" ]; then
2860 if checkstatus encodetrack-$LASTTRACK; then :; else do_batch_encode; fi
2861 if checkerrors batch-encode; then exit; fi
2866 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2867 if [ "$ONETRACK" = "y" ] ; then
2868 TRACKQUEUE="$FIRSTTRACK"
2869 TRACKS="$FIRSTTRACK"
2872 # Do the encoding, including parallelization of remote encoding
2873 # Figure out where each track is going to be encoded
2874 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
2875 if [ "$MAXPROCS" != "0" ]; then
2876 for NUM in $(f_seq_row 1 "$MAXPROCS")
2878 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
2882 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
2883 for UTRACKNUM in $TRACKQUEUE
2886 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
2887 if [ "$GOAHEAD" = "NO" ]; then break; fi
2888 # find out where this track is to be encoded
2889 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2890 # Make sure we have a place to encode this, if not, exit stage right
2891 if [ -z "$ENCODELOCATIONS" ]; then
2897 for LOCATION in $ENCODELOCATIONS
2899 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
2900 # check first if a track has ever been assigned to this location
2901 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
2902 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2903 if checkerrors encodetrack-$PREVIOUSTRACK; then
2904 for TEMPLOCATION in $ENCODELOCATIONS
2906 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2907 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
2910 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
2915 # We're still here, this location must have been previously assigned,
2916 # and last completed without error - check if it's done with the
2917 # previous track yet
2918 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
2920 # all locations are working, wait and try again later
2921 if [ ! $PROCEED ]; then sleep 3; fi
2923 # Record the location we're about to encode the next track at
2924 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2926 # Don't proceed with the rest of the loop if we can't encode
2927 if [ "$ABORT" ]; then continue; fi
2928 # Set TRACKNUM, TRACKNAME
2929 if [ -e "$CDDBDATA" ]; then
2930 if [ "$ONETRACK" = "y" ]; then
2932 TRACKNUM="$FIRSTTRACK"
2935 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
2937 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2938 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
2942 # You can't encode a file which needs to be normalized before finishing
2943 # You can't tag a file before it's finished encoding -
2944 # thus all of this is backgrounded together
2946 if [ "$DONORMALIZE" = "y" ]; then
2947 if checkstatus readtrack-$UTRACKNUM; then
2948 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
2951 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2952 if checkstatus readtrack-$UTRACKNUM; then
2953 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
2954 if [ "$DONORMALIZE" = "y" ]; then
2955 if checkstatus normalizetrack-$UTRACKNUM; then
2956 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
2959 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
2963 if [ "$DOTAG" = "y" ]; then
2964 if checkstatus encodetrack-$UTRACKNUM; then
2965 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
2967 # Lets tag the cue file
2968 if checkstatus cleancuefile >/dev/null; then :; else
2969 if checkstatus cuefile >/dev/null ; then
2974 if [ "$DOMOVE" = "y" ]; then
2975 if checkstatus tagtrack-$UTRACKNUM; then
2976 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
2983 # Go through it again and make sure there's no distmp3 stragglers, otherwise
2984 # we'll delete the files they're working on
2985 ## FIXME ## Check also for files which are encoded using PIPEs.
2986 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2991 for LOCATION in $ENCODELOCATIONS
2993 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
2994 # "How can he give us a status update, if he's DEAD?"
2995 if checkstatus encodetrack-$CHECKTRACK; then
2998 # Nothing to see here please go quietly back to your homes
2999 if [ -z "$CHECKTRACK" ]; then continue; fi
3000 # You're still here? Maybe there is something...
3001 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
3004 if [ ! $PROCEED ]; then sleep 5; fi
3007 # If the above didn't catch the stragglers, this will
3009 # Check to see if run_command logged any errors
3010 if [ -f "$ABCDETEMPDIR/errors" ]; then
3011 echo "The following commands failed to run:"
3012 cat "$ABCDETEMPDIR/errors"
3016 if [ "$KEEPWAVS" = "y" ];then
3020 if [ "$DOCLEAN" = "y" ]; then
3021 # Wipe all the evidence
3022 # Gimme gimme gimme some more time!
3024 rm -rf "$ABCDETEMPDIR"
3027 echo "Finished. Not cleaning $ABCDETEMPDIR."