2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2005 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 "-E Set the encoding information for the tags"
35 echo "-h This help information"
36 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
37 echo "-j <#> Number of encoder processes to run at once (localhost)"
38 echo "-k Keep the wav tracks for later use"
39 echo "-l Use low disk space algorithm"
40 echo "-L Use local CDDB storage directory"
41 echo "-n No lookup. Don't query CDDB, just create and use template"
42 echo "-N Noninteractive. Never prompt for anything"
43 echo "-m Modify playlist to include CRLF endings, to comply with some players"
44 echo "-M Create a CUE file"
45 echo "-o <type1[,type2]...>"
46 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc). Defaults to vorbis"
47 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
48 echo "-P Use UNIX pipes to read+encode without wav files"
49 echo "-r <host1[,host2]...>"
50 echo " Also encode on these remote hosts"
51 echo "-R Add replaygain values to the tag info (only for vorbis,flac)"
53 echo " Show dielfs from the CDDB info (year,genre)"
54 echo "-S <#> Set the CD speed"
55 #echo "-t File types to preprocess (wav)"
56 #echo "-T Set postprocessing options"
57 echo "-t <#> Start the track numbering at a given number"
58 echo "-T <#> Same as -t but modifies tag numbering"
59 echo "-v Show version number and exit"
60 echo "-V Be a bit more verbose about what is happening behind the scenes"
61 echo "-x Eject CD after all tracks are read"
63 echo " Add a comment to the CD tracks"
64 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
66 echo "Tracks is a space-delimited list of tracks to grab."
67 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
69 #echo "Double hyphens are used to concatenate tracks"
72 # Funtions to replace the need of seq, which is too distribution dependant.
76 while [ $i -ne `expr $2 + 1` ]
86 while [ $i -ne `expr $2 + 1` ]
94 # Functions to replace the need of awk {print $1} and {print $NF}
97 if [ X"$1" = "X" ]; then
98 for first in `cat`; do
109 if [ X"$1" = "X" ]; then
110 for stdin in `cat`; do
114 for last in $@ ; do :; done
119 # checkstatus [blurb]
120 # Returns "0" if the blurb was found, returns 1 if it wasn't
121 # Puts the blurb content, if available, on stdout.
122 # Otherwise, returns "".
125 # Take the last line in the status file if there's multiple matches
127 BLURB=$(egrep $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
129 if [ -z "$BLURB" ]; then
134 # See if there's a = in it
135 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
136 echo "$(echo $BLURB | cut -f2- -d=)"
142 # checkerrors [blurb]
143 # Returns "0" if the blurb was found (meaning there was an error),
144 # returns 1 if it wasn't (yes this is a little backwards).
145 # Does not print the blurb on stdout.
146 # Otherwise, returns "".
149 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
152 # Take the last line in the status file if there's multiple matches
154 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
156 if [ -z "$BLURB" ]; then
157 # negative, we did not have a negative...
160 # affirmative, we had a negative...
166 # Finds the right pager in the system to display a file
170 # Use the debian sensible-pager wrapper to pick the pager
171 # user has requested via their $PAGER environment variable
172 if [ -x "/usr/bin/sensible-pager" ]; then
173 /usr/bin/sensible-pager "$PAGEFILE"
174 elif [ -x "$PAGER" ]; then
175 # That failed, try to load the preferred editor, starting
176 # with their PAGER variable
178 # If that fails, check for less
179 elif [ -x /usr/bin/less ]; then
180 /usr/bin/less -f "$PAGEFILE"
181 # more should be on all UNIX systems
182 elif [ -x /bin/more ]; then
183 /bin/more "$PAGEFILE"
185 # No bananas, just cat the thing
190 # run_command [blurb] [command...]
191 # Runs a command, silently if necessary, and updates the status file
196 # See if this is supposed to be silent
197 if [ "$(checkstatus encode-output)" = "loud" ]; then
201 # Special case for SMP, since
202 # encoder output is never displayed, don't mute echos
203 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
213 if [ "$RETURN" = "2" ]; then
214 # File was already normalized.
219 if [ "$RETURN" != "0" ]; then
220 # Put an error in the errors file. For various reasons we
221 # can't capture a copy of the program's output but we can
222 # log what we attempted to execute and the error code
223 # returned by the program.
224 if [ "$BLURB" ]; then
227 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
228 return $RETURN # Do not pass go, do not update the status file
230 if [ "$BLURB" ]; then
231 echo $BLURB >> "$ABCDETEMPDIR/status"
235 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
236 # distributed under the terms of the GNU GPL v2 or later, at your option
238 # Function to determine if a word contains a slash.
247 # Function to give the relative path from one file to another.
248 # Usage: relpath fromfile tofile
249 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
250 # (the result would be Album/Song.mp3)
251 # Output is relative path to $2 from $1 on stdout
253 # This code has the following restrictions:
254 # Multiple ////s are not collapsed into single /s, with strange effects.
255 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
256 # If FR is a directory it must have a trailing /
264 /*) ;; # No processing is needed for absolute paths
266 # Loop through common prefixes, ignoring them.
267 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
269 FR="$(echo "$FR" | cut -d/ -f2-)"
270 TO="$(echo "$TO" | cut -d/ -f2-)"
272 # Loop through directory portions left in FR, adding appropriate ../s.
275 FR="$(echo "$FR" | cut -d/ -f2-)"
285 # Finds an specific field from cddbinfo
287 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
288 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
289 # TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
296 # This code splits the a Various Artist track name from one of the following
299 # forward: Artist / Track
300 # forward-dash: Artist - Track
301 # reverse: Track / Artist
302 # reverse-dash: Track - Artist
303 # colon: Artist: Track
304 # trailing-paren: Artist (Track)
307 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
310 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
311 case "$VARIOUSARTISTSTYLE" in
313 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's- / -~-g')
314 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
315 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
318 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's, - ,~,g')
319 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
320 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
323 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's- / -~-g')
324 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
325 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
328 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's, - ,~,g')
329 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
330 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
333 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's-: -~-g')
334 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
335 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
338 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')
339 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
340 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
343 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
344 TRACKARTIST="Various"
346 TRACKARTIST="$DARTIST"
351 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
355 "classic rock") id=1 ;;
373 "industrial") id=19 ;;
374 "alternative") id=20 ;;
376 "death metal") id=22 ;;
378 "soundtrack") id=24 ;;
379 "euro-techno") id=25 ;;
383 "jazz+funk") id=29 ;;
386 "classical") id=32 ;;
387 "instrumental") id=33 ;;
391 "sound clip") id=37 ;;
394 "alt. rock") id=40 ;;
399 "meditative") id=45 ;;
400 "instrum. pop") id=46 ;;
401 "instrum. rock") id=47 ;;
405 "techno-indust.") id=51 ;;
406 "electronic") id=52 ;;
408 "eurodance") id=54 ;;
410 "southern rock") id=56 ;;
415 "christian rap") id=61 ;;
416 "pop/funk"|"pop / funk") id=62 ;;
418 "native american") id=64 ;;
421 "psychadelic") id=67 ;;
423 "showtunes") id=69 ;;
427 "acid punk") id=73 ;;
428 "acid jazz") id=74 ;;
432 "rock & roll") id=78 ;;
433 "hard rock") id=79 ;;
435 "folk/rock") id=81 ;;
436 "national folk") id=82 ;;
443 "bluegrass") id=89 ;;
444 "avantgarde") id=90 ;;
445 "gothic rock") id=91 ;;
446 "progress. rock") id=92 ;;
447 "psychadel. rock") id=93 ;;
448 "symphonic rock") id=94 ;;
449 "slow rock") id=95 ;;
452 "easy listening") id=98 ;;
458 "chamber music") id=104 ;;
460 "symphony") id=106 ;;
461 "booty bass") id=107 ;;
463 "porn groove") id=109 ;;
465 "slow jam") id=111 ;;
469 "folklore") id=115 ;;
471 "power ballad") id=117 ;;
472 "rhythmic soul") id=118 ;;
473 "freestyle") id=119 ;;
475 "punk rock") id=121 ;;
476 "drum solo") id=122 ;;
477 "a capella") id=123 ;;
478 "euro-house") id=124 ;;
479 "dance hall") id=125 ;;
481 "drum & bass") id=127 ;;
482 "club-house") id=128 ;;
483 "hardcore") id=129 ;;
487 "negerpunk") id=133 ;;
488 "polsk punk") id=134 ;;
490 "christian gangsta rap") id=136 ;;
491 "heavy metal") id=137 ;;
492 "black metal") id=138 ;;
493 "crossover") id=139 ;;
494 "contemporary christian")id=140 ;;
495 "christian rock") id=141 ;;
496 "merengue") id=142 ;;
498 "thrash metal") id=144 ;;
501 "synthpop") id=147 ;;
502 "rock/pop"|"rock / pop") id=148 ;;
509 # do_tag [tracknumber]
510 # id3 tags a filename
512 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
513 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
516 COMMENTOUTPUT="$(eval echo ${COMMENT})"
517 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
518 # If we want to start the tracks with a given number, we need to modify the
519 # TRACKNUM value before evaluation
520 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
521 # Get the trackpadding from the current track
522 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
523 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
525 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
529 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
530 GENREID=$(do_getgenreid "${CDGENRE}")
535 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
536 run_command tagtrack-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
537 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
538 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
539 "${ENCODING:+--set-encoding=$ENCODING}"
540 "$ABCDETEMPDIR/track$1.$OUTPUT"
543 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
544 run_command tagtrack-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
545 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
546 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
547 "$ABCDETEMPDIR/track$1.$OUTPUT"
552 case "$OGGENCODERSYNTAX" in
554 # vorbiscomment can't do in-place modification, mv the file first
555 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
556 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
559 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
560 echo ARTIST="$TRACKARTIST"
562 echo TITLE="$TRACKNAME"
563 if [ -n "$CDYEAR" ]; then
566 if [ -n "$CDGENRE" ]; then
567 echo GENRE="$CDGENRE"
569 echo TRACKNUMBER=${TRACKNUM:-$1}
570 echo CDDB=$CDDBDISCID
571 if [ "$(eval echo ${COMMENT})" != "" ]; then
572 case "$COMMENTOUTPUT" in
573 *=*) echo "$COMMENTOUTPUT";;
574 *) echo COMMENT="$COMMENTOUTPUT";;
577 ) | run_command tagtrack-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
578 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
579 # Doublecheck that the commented file was created successfully before wiping the original
580 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
581 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
583 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
590 echo ARTIST="$TRACKARTIST"
592 echo TITLE="$TRACKNAME"
593 if [ -n "$CDYEAR" ]; then
596 if [ -n "$CDGENRE" ]; then
597 echo GENRE="$CDGENRE"
599 echo TRACKNUMBER=${TRACKNUM:-$1}
600 echo CDDB=$CDDBDISCID
601 if [ "$(eval echo ${COMMENT})" != "" ]; then
602 case "$COMMENTOUTPUT" in
603 *=*) echo "$COMMENTOUTPUT";;
604 *) echo COMMENT="$COMMENTOUTPUT";;
607 ) | run_command tagtrack-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
610 run_command tagtrack-$1 true
613 run_command tagtrack-$1 true
621 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
624 # The commands here don't go through run_command because they're never supposed to be silenced
625 echo "Batch encoding tracks: $TRACKQUEUE"
626 OUTPUT=$(echo $OUTPUTTYPE | grep "mp3" )
629 case "$MP3ENCODERSYNTAX" in
634 for UTRACKNUM in $TRACKQUEUE
636 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
638 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
640 if [ "$RETURN" != "0" ]; then
641 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
643 for UTRACKNUM in $TRACKQUEUE
645 echo encodetrack-$UTRACKNUM >> status
653 # Other encoders fall through to normal encoding as the tracks
654 # have not been entered in the status file.
657 # do_encode [tracknumber] [hostname]
658 # If no hostname is specified, encode locally
660 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
663 if [ "$USEPIPES" = "y" ]; then
666 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
669 TEMPARG="PIPE_$OGGENCODERSYNTAX"
672 TEMPARG="PIPE_$FLACENCODERSYNTAX"
675 TEMPARG="PIPE_$SPEEXENCODER"
678 TEMPARG="PIPE_$MPPENCODER"
681 IN="$( eval echo "\$$TEMPARG" )"
683 IN="$ABCDETEMPDIR/track$1.wav"
686 case "$MP3ENCODERSYNTAX" in
687 # FIXME # check if mp3enc needs -if for pipes
701 # We need IN to proceed, if we are not using pipes.
702 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
703 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
707 OUT="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
710 OUT="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
713 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
716 if [ X"$USEPIPES" = "Xy" ]; then
719 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
720 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
726 case "$MP3ENCODERSYNTAX" in
727 lame|gogo) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
728 bladeenc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
729 l3enc|xingmp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
730 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
731 mp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
735 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
742 case "$OGGENCODERSYNTAX" in
743 vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
744 oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
748 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
755 case "$FLACENCODERSYNTAX" in
756 flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
762 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
763 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
768 if [ "$(eval echo ${COMMENT})" != "" ]; then
771 *) COMMENT="COMMENT=$COMMENT" ;;
773 COMMENT="--comment \"$COMMENT\""
775 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
776 if [ ! "$DOTAG" = "y" ]; then
777 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
779 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
783 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
785 # I tried compiling the mppenc from corecodecs.org and got some
786 # errors, so I have not tried it myself.
787 ## FIXME ## Needs some cleanup to determine if an empty tag sent
788 ## FIXME ## to the encoder ends up empty.
789 $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
793 # Only remove .wav if the encoding succeeded
794 if checkerrors "encodetrack-(.{3,4})-$1"; then
795 run_command encodetrack-$1 false
797 run_command encodetrack-$1 true
798 if [ ! "$KEEPWAVS" = "y" ] ; then
803 if [ "$(checkstatus encode-output)" = "loud" ]; then
804 echo "HEH! The file we were about to encode disappeared:"
807 run_command encodetrack-$1 false
811 # do_preprocess [tracknumber]
813 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
816 # IN="$ABCDETEMPDIR/track$1.wav"
817 # # We need IN to proceed.
818 # if [ -s "$IN" ] ; then
819 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
821 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
822 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
823 # case "$POSTPROCESSFORMAT" in
825 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
827 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
829 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
831 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
833 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
836 # # Only remove .wav if the encoding succeeded
837 # if checkerrors "preprocess-(.{3,4})-$1"; then
838 # run_command preprocess-$1 false
840 # run_command preprocess-$1 true
843 # if [ "$(checkstatus encode-output)" = "loud" ]; then
844 # echo "HEH! The file we were about to pre-process disappeared:"
847 # run_command preprocess-$1 false
852 # do_postprocess [tracknumber]
854 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
857 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
859 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
860 # # We need IN to proceed.
861 # if [ -s "$IN" ] ; then
862 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
863 # run_command '' echo "Post-processing track $1 of $TRACKS..."
864 # case "$POSTPROCESSFORMAT" in
866 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
868 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
870 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
872 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
874 # # Only remove .wav if the encoding succeeded
875 # if checkerrors "postprocess-(.{3,4})-$1"; then
876 # run_command postprocess-$1 false
878 # run_command postprocess-$1 true
881 # if [ "$(checkstatus encode-output)" = "loud" ]; then
882 # echo "HEH! The file we were about to post-process disappeared:"
885 # run_command postprocess-$1 false
900 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
904 # The commands here don't go through run_command because they're never supposed to be silenced
905 echo "Batch analizing gain in tracks: $TRACKQUEUE"
910 for UTRACKNUM in $TRACKQUEUE
912 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
914 # XXX: Hard-coded batch option!
915 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
917 if [ "$RETURN" != "0" ]; then
918 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
920 for UTRACKNUM in $TRACKQUEUE
922 echo normalizetrack-$UTRACKNUM >> status
930 # NORMALIZER, NORMALIZEROPTS
931 do_batch_normalize ()
933 # The commands here don't go through run_command because they're never supposed to be silenced
934 echo "Batch normalizing tracks: $TRACKQUEUE"
939 for UTRACKNUM in $TRACKQUEUE
941 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
943 # XXX: Hard-coded batch option!
944 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
946 if [ "$RETURN" != "0" ]; then
947 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
949 for UTRACKNUM in $TRACKQUEUE
951 echo normalizetrack-$UTRACKNUM >> status
957 # do_normalize [tracknumber]
959 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
962 IN="$ABCDETEMPDIR/track$1.wav"
963 if [ -e "$IN" ] ; then
964 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
965 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
967 if [ "$(checkstatus encode-output)" = "loud" ]; then
968 echo "HEH! The file we were about to normalize disappeared:"
971 run_command normalizetrack-$1 false "File $IN was not found"
975 # do_move [tracknumber]
976 # Deduces the outfile from environment variables
977 # Creates directory if necessary
979 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
982 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
986 OUTPUT=$OGGOUTPUTCONTAINER
989 OUTPUT=$FLACOUTPUTCONTAINER
992 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
993 # Munge filenames as follows:
998 # Eat control characters
999 ALBUMFILE=$(mungefilename "$DALBUM")
1000 ARTISTFILE=$(mungefilename "$TRACKARTIST")
1001 TRACKFILE=$(mungefilename "$TRACKNAME")
1002 GENRE=$(mungegenre "$GENRE")
1003 YEAR=$(echo $CDYEAR)
1004 # If we want to start the tracks with a given number, we need to modify the
1005 # TRACKNUM value before evaluation
1006 if [ -n "$STARTTRACKNUMBER" ] ; then
1007 # Get the trackpadding from the current track
1008 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
1009 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1011 TRACKNUM=${UTRACKNUM}
1013 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1014 # TRACKFILE, and TRACKNUM.
1015 if [ "$VARIOUSARTISTS" = "y" ]; then
1016 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
1018 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
1020 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1021 OUTPUTFILEDIR=$(dirname "$OUTPUTDIR/$OUTPUTFILE")
1022 # mkdir -p shouldn't return an error if the directory already exists
1023 mkdir -p "$OUTPUTFILEDIR"
1024 # Silence the Moving output since it overlaps with encoding processes...
1025 #run_command '' vecho "Moving track$1.$OUTPUT to $OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1026 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1027 # Lets move the cue file
1028 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1029 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1030 if checkstatus movecue-$OUTPUT; then :; else
1031 # Silence the Copying output since it overlaps with encoding processes...
1032 #run_command '' vecho "Copying cue file to its destination directory..."
1033 if checkstatus onetrack >/dev/null ; then
1035 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1036 # http://brianvictor.tripod.com/mp3cue.htm#details
1037 [a-z0-9][a-z0-9][a-z0-9])
1038 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1041 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1045 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1047 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1055 # Create the playlist if wanted
1057 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1058 # VARIOUSARTISTS, OUTPUTDIR
1061 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1063 # Create a playlist file for the playlist data to go into.
1064 # We used to wipe it out if it existed. Now we request permision if interactive.
1065 for LASTTRACK in $TRACKQUEUE; do :; done
1066 ALBUMFILE=$(mungefilename "$DALBUM")
1067 ARTISTFILE=$(mungefilename "$DARTIST")
1068 GENRE=$(mungegenre "$GENRE")
1069 YEAR=${CDYEAR:-$CDYEAR}
1070 if [ "$VARIOUSARTISTS" = "y" ] ; then
1071 PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
1073 PLAYLISTFILE=$(eval echo $PLAYLISTFORMAT)
1075 FINALPLAYLISTDIR=$(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1076 mkdir -p "$FINALPLAYLISTDIR"
1077 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1078 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1079 if [ "$INTERACTIVE" = "y" ]; then
1080 while [ "$DONE" != "y" ]; do
1082 case $ERASEPLAYLIST in
1083 e|E|a|A|k|K) DONE=y ;;
1091 # Once we erase the playlist, we use append to create the new one.
1092 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1094 # The playlist does not exist, so we can safelly use append to create the new list
1097 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1098 touch "$OUTPUTDIR/$PLAYLISTFILE"
1099 for UTRACKNUM in $TRACKQUEUE
1101 # Shares some code with do_move since the filenames have to match
1102 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1103 TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1105 TRACKFILE=$(mungefilename "$TRACKNAME")
1106 ARTISTFILE=$(mungefilename "$TRACKARTIST")
1107 # If we want to start the tracks with a given number, we need to modify the
1108 # TRACKNUM value before evaluation
1109 if [ -n "$STARTTRACKNUMBER" ] ; then
1110 # Get the trackpadding from the current track
1111 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
1112 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1114 TRACKNUM=${UTRACKNUM}
1116 if [ "$VARIOUSARTISTS" = "y" ]; then
1117 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
1119 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
1121 if [ "$VARIOUSARTISTS" = "y" ]; then
1122 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1123 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1125 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1128 if [ "$PLAYLISTDATAPREFIX" ]; then
1129 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1131 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1136 ## this will convert the playlist to have CRLF line-endings, if specified
1137 ## (some hardware players insist on CRLF endings)
1138 if [ "$DOSPLAYLIST" = "y" ]; then
1139 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1140 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1141 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1143 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1148 # This essentially the start of things
1151 # Query the CD to get the track info, unless the user specified -C
1152 # or we are using some actions which do not need the CDDB data at all
1153 #if [ ! X"$EXPACTIONS" = "X" ]; then
1155 #elif [ -z "$DISCID" ]; then
1156 if [ -z "$DISCID" ]; then
1157 vecho -n "Getting CD track info... "
1158 # In OSX, unmount the disc before a query
1159 if [ "$OSFLAVOUR" = "OSX" ]; then
1160 disktool -u ${CDROM#/dev/}
1162 TRACKINFO=$($CDDISCID $CDROM)
1163 # Make sure there's a CD in there by checking cd-discid's return code
1164 if [ "$?" = "1" ]; then
1165 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1168 # In OSX, remount the disc again
1169 if [ "$OSFLAVOUR" = "OSX" ]; then
1170 disktool -m ${CDROM#/dev/}
1174 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1177 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1178 # This needs to be done now because a section of the resuming code will need
1181 # get the number of digits to pad TRACKNUM with - we'll use this later
1182 # a CD can only hold 99 tracks, but since we support a feature for starting
1183 # numbering the tracks from a given number, we might need to set it as a
1184 # variable for the user to define... or obtain it somehow.
1185 if [ "$PADTRACKS" = "y" ] ; then
1189 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1190 if [ -z "$TRACKQUEUE" ]; then
1191 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1192 case "$CDROMREADERSYNTAX" in
1194 if [ "$WEHAVEACD" = "y" ]; then
1195 vecho "Querying the CD for audio tracks..."
1196 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1198 if [ ! "$RET" = "0" ];then
1199 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1201 TRACKS="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ' )"
1202 CDPARANOIAAUDIOTRACKS="$TRACKS"
1204 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks ; then
1205 TRACKS=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" )
1207 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1211 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1214 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1216 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1217 echo "The disc does not contain any tracks. Giving up..."
1220 echo -n "Grabbing entire CD - tracks: "
1221 if [ ! "$PADTRACKS" = "y" ] ; then
1222 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1224 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1226 while [ "$X" -ne "$TRACKS" ]
1228 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1229 TRACKQUEUE=$(echo "$TRACKQUEUE" $X)
1233 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1234 # User-supplied track queue.
1235 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1236 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1237 # Once cleaned, obtain the highest value in the trackqueue for number padding
1238 for LASTTRACK in $TRACKQUEUE; do :; done
1239 if [ ! "$PADTRACKS" = "y" ] ; then
1240 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1242 # Now we normalize the trackqueue
1243 for TRACK in $TRACKQUEUE ; do
1244 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1245 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1247 TRACKQUEUE=$PADTRACKQUEUE
1248 echo Grabbing tracks: "$TRACKQUEUE"
1251 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1253 # We have the discid, create a temp directory after it to store all the temp
1256 if [ -e "$ABCDETEMPDIR" ]; then
1257 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1258 # It already exists, see if it's a directory
1259 if [ ! -d "$ABCDETEMPDIR" ]; then
1260 # This is a file/socket/fifo/device/etc, not a directory
1263 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1264 echo "Please investigate, remove it, and rerun abcde." >&2
1268 # It's a directory, let's see if it's owned by us
1269 if [ ! -O "$ABCDETEMPDIR" ]; then
1270 # Nope, complain and exit
1272 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1273 echo "Please investigate, remove it, and rerun abcde." >&2
1277 # See if it's populated
1278 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1279 # Wipe and start fresh
1280 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1281 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1282 if [ "$INTERACTIVE" = "y" ]; then
1288 if [ "$ANSWER" != "y" ]; then
1291 rm -rf "$ABCDETEMPDIR" || exit 1
1292 mkdir "$ABCDETEMPDIR"
1293 if [ "$?" -gt "0" ]; then
1294 # Directory already exists or could not be created
1295 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1299 # Everything is fine. Check for ^encodetracklocation-
1300 # and encode-output entries in the status file and
1301 # remove them. These are not relevant across sessions.
1302 if [ -f "$ABCDETEMPDIR/status" ]; then
1303 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1304 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1305 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1307 # Remove old error messages
1308 if [ -f "$ABCDETEMPDIR/errors" ]; then
1309 rm -f "$ABCDETEMPDIR/errors"
1313 # We are starting from scratch
1314 mkdir "$ABCDETEMPDIR"
1315 if [ "$?" -gt "0" ]; then
1316 # Directory already exists or could not be created
1317 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1320 cat /dev/null > "$ABCDETEMPDIR/status"
1322 if [ X"$MAKECUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1323 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1324 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1325 vecho "Creating cue file..."
1326 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1327 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1329 echo "abcde: reading the CUE sheet with mkcue is still considered experimental"
1330 echo "abcde: and there was a problem with the CD reading. abcde will continue,"
1331 echo "abcde: but consider reporting the problem to the abcde author"
1335 # If we got the CDPARANOIA status and it is not recorded, save it now
1336 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1337 if checkstatus cdparanoia-audio-tracks; then :; else
1338 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1339 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1344 # Create the discid file
1345 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1349 # Create a proper CUE file based on the CUE file we created before.
1352 # FIXME # we can get the name of the cuefile from the status file
1353 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1354 CUEFILE_OUT=$CUEFILE_IN.out
1355 ### FIXME ### checkstatus cddb
1356 if [ -e "$CDDBDATA" ]; then
1357 vecho "Adding metadata to the cue file..."
1358 # FIXME It doesn't preserve spaces! Why?
1359 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1361 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1362 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1363 cat "$CUEFILE_IN" | while read line
1365 if echo "$line" | grep -q "INDEX"
1367 eval track="\$TRACK$n"
1369 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1371 echo "$line" >> "$CUEFILE_OUT"
1373 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1374 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1380 # Parses a CDDB file and outputs the title and the track names.
1381 # Variables: CDDBFILE
1385 # List out disc title/author and contents
1386 if [ "$ONETRACK" = "y" ]; then
1387 vecho "ONETRACK mode selected: displaying only the title of the CD..."
1389 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1390 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
1391 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1392 if [ ! X"$PARSEDYEAR" = "X" ]; then
1393 echo "Year: $PARSEDYEAR"
1396 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
1397 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1398 if [ ! X"$PARSEDGENRE" = "X" ]; then
1399 echo "Genre: $PARSEDGENRE"
1402 if [ ! "$ONETRACK" = "y" ]; then
1403 for TRACK in $(f_seq_row 1 $TRACKS)
1405 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1411 # Check for a local CDDB file, and report success
1414 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
1416 CDDBLOCALSUCCESS="n"
1417 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1418 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1421 # If the user has selected to check a local CDDB repo, we proceed with it
1422 if [ -r "${CDDBLOCALFILE}" ]; then
1423 # List out disc title/author and contents
1424 do_cddbparse "${CDDBLOCALFILE}"
1425 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1426 if [ "$INTERACTIVE" = "y" ]; then
1428 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1429 echo -n 'Invalid selection. Please answer "y" or "n": '
1432 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
1436 if [ "$USELOCALRESP" = "y" ]; then
1437 #echo "Using local copy of CDDB data"
1438 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1439 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1440 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
1441 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1442 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1443 CDDBLOCALSUCCESS="y"
1445 #echo "Not using local copy of CDDB data"
1446 CDDBLOCALSUCCESS="n"
1449 CDDBLOCALSUCCESS="n"
1457 # Perform CDDB protocol version check if it hasn't already been done
1458 if checkstatus cddb-statcomplete; then :; else
1459 if [ "$CDDBAVAIL" = "n" ]; then
1461 echo 503 > "$ABCDETEMPDIR/cddbstat"
1464 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1465 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1466 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1467 vecho "Checking CDDB server status..."
1468 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1469 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
1470 case "$RESPONSECODE" in
1471 210) # 210 OK, status information follows (until terminating `.')
1474 501|*) # 501 Illegal CDDB protocol level: <n>.
1475 CDDBPROTO=`expr $CDDBPROTO - 1`
1479 if test $rc -eq 1; then
1483 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
1491 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1492 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1494 # Perform CDDB query if it hasn't already been done
1495 if checkstatus cddb-querycomplete; then :; else
1496 if [ "$CDDBAVAIL" = "n" ]; then
1498 echo 503 > "$ABCDETEMPDIR/cddbquery"
1499 # The default CDDBLOCALSUCCESS is "n"
1500 # This part will be triggered if the user CDDB repo does not
1501 # contain the entry, or if we are not trying to use the repo.
1503 vecho "Querying the CDDB server..."
1504 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1505 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1506 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1512 # no match found in database,
1513 # wget/fetch error, or user requested not to use CDDB
1514 # Make up an error code (503) that abcde
1515 # will recognize in do_cddbread
1516 # and compensate by making a template
1517 echo 503 > "$ABCDETEMPDIR/cddbquery"
1519 *) # strange and unknown error
1520 echo ERRORCODE=$ERRORCODE
1521 echo "abcde: $CDDBTOOL returned unknown error code"
1525 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
1532 # If it's not to be used, generate a template.
1533 # Then, display it (or them) and let the user choose/edit it
1534 if checkstatus cddb-readcomplete; then :; else
1535 vecho "Obtaining CDDB results..."
1536 # If CDDB is to be used, interpret the query results and read all
1537 # the available entries.
1538 rm -f "$ABCDETEMPDIR/cddbchoices"
1539 CDDBCHOICES=1 # Overridden by multiple matches
1540 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
1541 case "$RESPONSECODE" in
1543 # One exact match, retrieve it
1544 # 200 [section] [discid] [artist] / [title]
1545 if checkstatus cddb-read-1-complete; then :; else
1546 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1547 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1548 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1549 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1550 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1552 # List out disc title/author and contents
1553 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1554 for TRACK in $(f_seq_row 1 $TRACKS)
1556 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1558 echo >> "$ABCDETEMPDIR/cddbchoices"
1562 case "$RESPONSECODE" in
1563 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1564 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1565 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1567 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1568 # List out disc title/author and contents of template
1569 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
1571 for TRACK in $(f_seq_row 1 $TRACKS)
1573 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1575 echo >> "$ABCDETEMPDIR/cddbchoices"
1576 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
1577 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
1580 # Multiple exact, (possibly multiple) inexact matches
1582 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
1583 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
1584 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1585 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1586 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1588 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1590 vecho -n "Retrieving multiple matches... "
1591 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
1592 read DISCINFO # eat top line
1596 if checkstatus cddb-read-$X-complete; then :; else
1597 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1598 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
1600 # List out disc title/author and contents
1601 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1602 for TRACK in $(f_seq_row 1 $TRACKS)
1604 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1606 echo >> "$ABCDETEMPDIR/cddbchoices"
1609 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1613 for TRACK in $(f_seq_row 1 $TRACKS)
1615 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1617 echo >> "$ABCDETEMPDIR/cddbchoices"
1618 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1619 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1622 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1629 if checkstatus cddb-edit >/dev/null; then
1630 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1631 VARIOUSARTISTS="$(checkstatus variousartists)"
1632 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
1635 if [ "$INTERACTIVE" = "y" ]; then
1636 # We should show the CDDB results both when we are not using the local CDDB repo
1637 # or when we are using it but we could not find a proper match
1638 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1639 # Display the $ABCDETEMPDIR/cddbchoices file created above
1640 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1641 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1642 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1643 CHOICE=$(checkstatus cddb-choice)
1644 if [ -n "$CHOICE" ] ; then
1645 case $CDDBCHOICES in
1646 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1648 echo "Selected: #$CHOICE"
1649 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1653 # The user has a choice to make, display the info in a pager if necessary
1654 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
1655 page "$ABCDETEMPDIR/cddbchoices"
1657 # It's all going to fit in one page, cat it
1658 cat "$ABCDETEMPDIR/cddbchoices" >&2
1662 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1664 # I'll take CDDB read #3 for $400, Alex
1665 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1666 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1668 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
1669 if echo $CDDBCHOICE | egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1670 if [ ! X"$DIFF" = "X" ]; then
1671 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1)
1672 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2)
1673 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1674 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1675 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1676 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1679 # We parse the 2 choices to diff, store them in temporary files and diff them.
1680 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
1681 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1683 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1684 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1685 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
1686 page "$ABCDETEMPDIR/cddbread.diff"
1688 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1692 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1695 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1696 # Make sure we get a valid choice
1697 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
1698 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1702 if [ "$CDCHOICENUM" = "0" ]; then
1703 vecho "Creating empty CDDB template..."
1705 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1707 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1708 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1710 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1714 # We need some code to show the selected option when local repository is selected and we have found a match
1715 vecho "Using cached CDDB match..." >&2
1716 # Display the $ABCDETEMPDIR/cddbchoices file created above
1717 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1718 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1719 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1720 CHOICE=$(checkstatus cddb-choice)
1721 if [ "$USELOCALRESP" = "y" ]; then :; else
1722 if [ -n "$CHOICE" ] ; then
1723 case $CDDBCHOICES in
1726 echo "Selected template."
1728 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1730 echo "Selected: #$CHOICE"
1731 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1739 # We're noninteractive - pick the first choice.
1740 # But in case we run a previous instance and selected a choice, use it.
1741 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1742 # Show the choice if we are not using the locally stored one
1743 # or when the local search failed to find a match.
1744 PREVIOUSCHOICE=$(checkstatus cddb-choice)
1745 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1746 #if [ "$PREVIOUSCHOICE" ]; then
1747 cat "$ABCDETEMPDIR/cddbchoices"
1750 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1751 CDCHOICENUM=$PREVIOUSCHOICE
1754 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1756 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1761 if checkstatus cddb-choice >/dev/null; then :; else
1762 echo "abcde: internal error: cddb-choice not recorded." >&2
1765 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1766 echo -n "Edit selected CDDB data? [y/n] (" >&2
1767 if [ "$INTERACTIVE" = "y" ]; then
1768 if [ "$UNKNOWNDISK" = "y" ]; then
1771 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
1780 if [ "$EDITCDDB" = "y" ]; then
1781 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
1783 # Use the debian sensible-editor wrapper to pick the editor that the
1784 # user has requested via their $EDITOR environment variable
1785 if [ -x "/usr/bin/sensible-editor" ]; then
1786 /usr/bin/sensible-editor "$CDDBDATA"
1787 elif [ -n "$EDITOR" ]; then
1788 if [ -x $(which "${EDITOR%%\ *}") ]; then
1789 # That failed, try to load the preferred editor, starting
1790 # with their EDITOR variable
1791 eval $(echo "$EDITOR") \"$CDDBDATA\"
1793 # If that fails, check for a vi
1794 elif which vi >/dev/null 2>&1; then
1796 elif [ -x /usr/bin/vim ]; then
1797 /usr/bin/vim "$CDDBDATA"
1798 elif [ -x /usr/bin/vi ]; then
1799 /usr/bin/vi "$CDDBDATA"
1800 elif [ -x /bin/vi ]; then
1802 # nano should be on all (modern, i.e., sarge) debian systems
1803 elif which nano >/dev/null 2>&1 ; then
1805 elif [ -x /usr/bin/nano ]; then
1806 /usr/bin/nano "$CDDBDATA"
1807 # mg should be on all OpenBSD systems
1808 elif which mg >/dev/null 2>&1 ; then
1810 elif [ -x /usr/bin/mg ]; then
1811 /usr/bin/mg "$CDDBDATA"
1814 echo "No editor available. Check your EDITOR environment variable." >&2
1816 # delete editor backup file if it exists
1817 if [ -w "$CDDBDATA~" ]; then
1822 # Some heuristics first. Look at Disc Title, and if it starts with
1823 # "Various", then we'll assume Various Artists
1824 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1825 echo "Looks like a Multi-Artist CD" >&2
1828 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1829 if [ "$INTERACTIVE" = "y" ]; then
1836 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1839 # Need NUMTRACKS before cddb-tool will return it:
1840 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
1841 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1842 # More than 1/2 tracks contain a "/", so guess forward
1844 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1845 # More than 1/2 contain a "-", so guess forward-dash
1847 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1848 # More than 1/2 contain something in parens, so guess trailing-paren
1852 echo "1) Artist / Title" >&2
1853 echo "2) Artist - Title" >&2
1854 echo "3) Title / Artist" >&2
1855 echo "4) Title - Artist" >&2
1856 echo "5) Artist: Title" >&2
1857 echo "6) Title (Artist)" >&2
1858 echo "7) This is a single-artist CD" >&2
1859 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1860 if [ "$INTERACTIVE" = "y" ]; then
1861 read VARIOUSARTISTSTYLE
1863 echo $DEFAULTSTYLE >&2
1864 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
1866 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
1867 # If they press Enter, then the default style (0) was chosen
1868 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
1869 echo "Invalid selection. Please choose a number between 1 and 7."
1870 echo -n "Selection [1-7]: "
1871 read VARIOUSARTISTSTYLE
1872 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
1874 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1875 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
1877 vecho "Selected: $VARIOUSARTISTSTYLE"
1878 case "$VARIOUSARTISTSTYLE" in
1880 VARIOUSARTISTSTYLE=forward
1883 VARIOUSARTISTSTYLE=forward-dash
1886 VARIOUSARTISTSTYLE=reverse
1889 VARIOUSARTISTSTYLE=reverse-dash
1892 VARIOUSARTISTSTYLE=colon
1895 VARIOUSARTISTSTYLE=trailing-paren
1903 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1904 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1906 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1907 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
1908 # This works but does not have the necessary error checking
1909 # yet. If you are familiar with the CDDB spec
1910 # (see http://www.freedb.org/src/latest/DBFORMAT)
1911 # and can create an error-free entry on your own, then put
1912 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1913 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1914 # your abcde.conf to change the email address submissions are
1917 # submit the modified file, if they want
1918 if [ "$NOSUBMIT" != "y" ]; then
1919 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1921 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1922 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1924 echo -n 'Invalid selection. Please answer "y" or "n": '
1927 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
1928 echo -n "Sending..."
1929 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
1935 # Make sure the cache directory exists
1936 mkdir -p $CDDBLOCALDIR
1937 # Cache edited CDDB entry in the user's cddb dir
1938 if [ "$CDDBCOPYLOCAL" = "y" ] || [ "$COPYCDDBLOCAL" = "Y" ]; then
1939 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
1942 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1945 # do_cdread [tracknumber]
1946 # do_cdread onetrack [firsttrack] [lasttrack]
1950 # The commands here don't go through run_command because they're never supposed to be silenced
1951 # return codes need to be doublechecked anyway, however
1952 if [ "$1" = "onetrack" ]; then
1953 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1954 # FIXME # Until then, we grab the whole CD in one track, no matter what
1956 # We need the first and last track for cdda2wav
1959 UTRACKNUM=$FIRSTTRACK
1960 case "$CDROMREADERSYNTAX" in
1961 cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
1962 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
1963 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1969 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1970 if [ "$USEPIPES" = "y" ]; then
1971 TEMPARG="PIPE_$CDROMREADERSYNTAX"
1972 FILEARG="$( eval echo "\$$TEMPARG" )"
1974 PIPE_MESSAGE="and encoding "
1976 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1977 case "$CDROMREADERSYNTAX" in
1978 ## FIXME ## Find the case for dagrab, to avoid exceptions
1980 FILEARG="-f $WAVDATA"
1988 if [ "$1" = "onetrack" ]; then
1989 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
1991 if [ -r "$CDDBDATA" ]; then
1992 TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
1993 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1995 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1998 case "$CDROMREADERSYNTAX" in
2000 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2002 if [ "$OSFLAVOUR" = "OSX" ] ; then
2003 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2004 disktool -u ${CDROM#/dev/} 0
2005 # Also, in OSX the cdrom device for cdda2wav changes...
2006 CDDA2WAVCDROM="IODVDServices"
2007 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2008 CDDA2WAVCDROM="$CDROMID"
2010 if [ "$CDROMID" = "" ]; then
2011 CDDA2WAVCDROM="$CDROM"
2013 CDDA2WAVCDROM="$CDROMID"
2016 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2018 ## FIXME ## We have an exception for dagrab, since it uses -f
2019 ## FIXME ## Shall we just use -f $FILEARG ??
2020 dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2023 # Find the track's mounted path
2024 REALTRACKNUM=$(expr $UTRACKNUM + 0)
2025 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
2026 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2027 # If the file exists, copy it
2028 if [ -e "$FILEPATH" ] ; then
2029 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2033 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2037 # If we get some error or we get some missing wav
2038 # (as long as we dont use pipes)
2039 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
2040 # Thank goodness errors is only machine-parseable up to the
2041 # first colon, otherwise this woulda sucked
2042 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2043 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2045 if [ "$USEPIPES" = "y" ]; then
2046 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2048 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2052 if [ "$USEPIPES" = "y" ]; then
2053 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2055 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2056 if [ "$1" = "onetrack" ]; then
2057 echo onetrack >> "$ABCDETEMPDIR/status"
2064 # No values accepted, only uses env variables
2067 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
2068 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
2070 echo "abcde: unable to set the device speed" >&2
2076 # vecho outputs a message if EXTRAVERBOSE is selected
2079 if [ x"$EXTRAVERBOSE" != "x" ]; then
2084 # User-redefinable functions
2085 # Custom filename munging:
2088 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2089 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
2092 # Custom genre munging:
2095 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2099 # Empty pre_read function, to be defined in the configuration file.
2106 # Empty post_read function, to be defined in the configuration file.
2112 ###############################################################################
2115 # Start of execution
2116 ###############################################################################
2119 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2120 CDDBSUBMIT=freedb-submit@freedb.org
2122 HELLOINFO="$(whoami)@$(hostname)"
2124 CDDBLOCALDIR="$HOME/.cddb"
2127 # List of fields we parse and show during the CDDB parsing...
2128 SHOWCDDBFIELDS="year,genre"
2131 CDROMREADERSYNTAX=cdparanoia
2132 ENCODERSYNTAX=default
2134 MP3ENCODERSYNTAX=default
2135 OGGENCODERSYNTAX=default
2136 FLACENCODERSYNTAX=default
2137 SPEEXENCODERSYNTAX=default
2138 MPPENCODERSYNTAX=default
2139 NORMALIZERSYNTAX=default
2140 CUEREADERSYNTAX=default
2142 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2143 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2144 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2145 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2146 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2147 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2148 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2149 PLAYLISTDATAPREFIX=''
2150 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2151 VAPLAYLISTDATAPREFIX=''
2159 VARIOUSARTISTSTYLE=forward
2163 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2164 # i.e. CDROMID="1,0,0"
2166 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2167 # If we are using the ide-scsi emulation layer, we need to define a "g"
2168 CDPARANOIACDROMBUS="d"
2170 # program paths - defaults to checking your $PATH
2176 XINGMP3ENC=xingmp3enc
2191 CDPARANOIA=cdparanoia
2200 VORBISCOMMENT=vorbiscomment
2202 NORMALIZE=normalize-audio
2204 VORBISGAIN=vorbisgain
2209 # Options for programs called from abcde
2241 VORBISCOMMENTOPTS="-R"
2242 METAFLACOPTS="--no-utf8-convert"
2244 # Default to one process if -j isn't specified
2247 # List of actions to perform - by default, run to completion
2248 ACTIONS=cddb,read,encode,tag,move,clean
2250 # List of prefered outputs - by default, run with whatever we have in the path
2251 # This option is basicaly for Debian package dependencies
2252 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex
2254 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2255 # Let's use these checkings to determine the OS flavour, which will be used later
2256 if [ X$(uname) = "XFreeBSD" ] ; then
2261 elif [ X$(uname) = "XDarwin" ] ; then
2264 # We should have disktool in OSX, but let's be sure...
2266 CDROMREADERSYNTAX=cddafs
2267 elif [ X$(uname) = "XOpenBSD" ] ; then
2270 elif [ X$(uname) = "XNetBSD" ] ; then
2277 # If CDDBAVAIL is set to n, no CDDB read is done
2278 # If USEID3 is set to n, no ID3 tagging is done
2283 if [ -z "$OUTPUTDIR" ]; then
2287 if [ -z "$WAVOUTPUTDIR" ]; then
2288 WAVOUTPUTDIR="$OUTPUTDIR"
2291 # Load system defaults
2292 if [ -r /etc/abcde.conf ]; then
2295 # Load user preference defaults
2296 if [ -r $HOME/.abcde.conf ]; then
2300 # By this time, we need some HTTPGETOPTS already defined.
2301 # If the user has defined a non-default HTTPGET method, we should not be empty.
2303 if [ "$HTTPGETOPTS" = "" ] ; then
2305 wget) HTTPGETOPTS="-q -O -";;
2306 curl) HTTPGETOPTS="-f -s";;
2307 fetch)HTTPGETOPTS="-q -o -";;
2308 ftp) HTTPGETOPTS="-q -o -";;
2309 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2313 # If the CDROM has not been set yet, find a suitable one.
2314 # If this is a devfs system, default to /dev/cdroms/cdrom0
2315 # instead of /dev/cdrom
2316 if [ "$CDROM" = "" ] ; then
2317 if [ -e /dev/cdroms/cdrom0 ]; then
2318 CDROM=/dev/cdroms/cdrom0
2319 elif [ -e /dev/cdrom ]; then
2321 elif [ -e /dev/cd0c ]; then
2323 elif [ -e /dev/acd0c ]; then
2325 elif [ -e /dev/disk1 ]; then
2330 # Parse command line options
2331 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2332 while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2335 a) ACTIONS="$OPTARG" ;;
2336 A) EXPACTIONS="$OPTARG" ;;
2338 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2339 C) DISCID="${OPTARG#abcde.}" ;;
2340 d) CDROM="$OPTARG" ;;
2342 e) ERASEENCODEDSTATUS=y ;;
2344 e) ERASEENCODEDSTATUS=y ;;
2345 E) ENCODING="$OPTARG" ;;
2346 # f) FORCECDDBUSELOCAL=y ;;
2348 j) MAXPROCS="$OPTARG" ;;
2351 L) CDDBUSELOCAL=y ;;
2356 o) OUTPUTTYPE="$OPTARG" ;;
2359 r) REMOTEHOSTS="$OPTARG" ;;
2361 s) SHOWCDDBFIELDS="$OPTARG" ;;
2362 S) CDSPEEDVALUE="$OPTARG" ;;
2363 # t) PREPROCESSFORMATS="$OPTARG"
2365 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2366 t) STARTTRACKNUMBER="$OPTARG" ;;
2367 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
2369 echo "This is abcde v$VERSION."
2370 echo "Usage: abcde [options] [tracks]"
2371 echo "abcde -h for extra help"
2374 V) EXTRAVERBOSE="y" ;;
2376 w) COMMENT="$OPTARG" ;;
2377 W) if echo $OPTARG | grep -q "[[:digit:]]" ; then
2378 STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
2380 echo "abcde error: argument of -W must be integer"
2388 shift $(($OPTIND - 1))
2390 # Decide if we can continue.
2391 if [ "$ONETRACK" = "y" ]; then
2392 # FIXME # remove check as soon as we find out about the other readers
2393 case "$CDROMREADERSYNTAX" in
2396 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2399 if [ "$BATCH" = "y" ]; then
2400 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2403 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2404 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2405 if [ $# -gt 0 ]; then
2406 vecho "abcde warning: ONETRACK mode selected, grabbing all tracks..."
2409 while [ $# -gt 0 ]; do
2410 # Range parsing code courtesy of Vincent Ho
2411 RSTART=$(echo $1 | cut -f1 -d-)
2412 REND=$(echo $1 | cut -f2 -d-)
2413 if [ "$RSTART" = "$REND" ]; then
2416 NEWTRACKS=$(f_seq_line $RSTART $REND)
2418 TRACKQUEUE=$(echo "$TRACKQUEUE" "$NEWTRACKS")
2423 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2424 # List of experimental actions: retag,transcode
2426 # Determine what actions are to be done from $ACTIONS and set the
2427 # following environment variables for them:
2439 for ACTION in $(echo $ACTIONS | tr , \ )
2444 normalize) DONORMALIZE=y; DOREAD=y;;
2445 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2446 encode) DOENCODE=y; DOREAD=y;;
2447 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2448 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2449 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2450 playlist) DOCDDB=y; DOPLAYLIST=y;;
2455 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
2456 case $SHOWCDDBFIELD in
2457 y*|Y*) SHOWCDDBYEAR="y";;
2458 g*|G*) SHOWCDDBGENRE="y";;
2465 # At this point a CDROM has to be defined, so we check it exists.
2466 if [ X"$CDROM" != "X" ] ; then
2467 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2468 if [ "$OSFLAVOUR" = "FBSD" ]; then
2469 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
2470 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2471 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2475 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
2476 echo "abcde error: CDROM device cannot be found." >&2
2479 # avoid processing if we are not going to hit the CDROM.
2480 elif [ X"$DOREAD" = "Xy" ]; then
2481 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2485 # USEPIPES pre-tests, before we get into more serious stuff
2486 # Not compatible with:
2487 # - multiple outputs
2489 # - lowdisk algorithm
2491 if [ X"$USEPIPES" = "Xy" ]; then
2492 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
2493 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
2496 if [ X"$DONORMALIZE" = "Xy" ]; then
2497 echo "abcde error: Unix pipes not compatible with normalizer"
2498 # FIXME # Do we need to exit or shall we just disable the mode?
2501 if [ X"$DOENCODE" = "Xn" ]; then
2502 vecho "Disabling Unix pipes since we are not encoding!"
2505 if [ X"$LOWDISK" = "Xy" ]; then
2506 vecho "abcde error: Unix pipes not compatible with lowdisk algorithm"
2511 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2512 if [ X"$OUTPUTTYPE" = "X" ]; then
2513 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
2514 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2515 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2516 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
2517 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
2518 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2522 if [ X"$OUTPUTTYPE" = "X" ]; then
2523 echo "abcde error: no encoder found in the PATH" >&2
2524 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2529 # Decide which CDROM reader we're gonna use
2530 case "$CDROMREADERSYNTAX" in
2532 CDROMREADER="$CDPARANOIA"
2533 CDROMREADEROPTS="$CDPARANOIAOPTS"
2536 CDROMREADER="$CDDA2WAV"
2537 CDROMREADEROPTS="$CDDA2WAVOPTS"
2540 CDROMREADER="$DAGRAB"
2541 CDROMREADEROPTS="$DAGRABOPTS"
2544 CDROMREADER="$CDDAFS"
2545 CDROMREADEROPTS="$CDDAFSOPTS"
2549 # There's only one normalize...
2550 case "$NORMALIZERSYNTAX" in
2552 NORMALIZER="$NORMALIZE"
2553 NORMALIZEROPTS="$NORMALIZEOPTS"
2557 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2558 if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
2559 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ ); do
2561 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2562 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2563 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2564 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2565 mpc:*) MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2568 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ ); do
2569 TEMPOUTPUT=$( echo "$OUTPUT" | cut -d: -f1 )
2570 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2572 OUTPUTTYPE="$TEMPOUTPUTTYPE"
2575 # 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
2577 # Getting ready for multiple output changes
2578 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
2582 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
2583 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
2584 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
2585 OGGOUTPUTCONTAINER=ogg
2588 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
2589 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
2592 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
2593 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
2596 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
2599 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
2601 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2607 # decide which encoder
2608 case "$MP3ENCODERSYNTAX" in
2610 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2614 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2618 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2619 MP3ENCODER="$BLADEENC"
2622 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2626 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2627 MP3ENCODER="$XINGMP3ENC"
2630 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2631 MP3ENCODER="$MP3ENC"
2634 case "$OGGENCODERSYNTAX" in
2636 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2637 OGGENCODER="$VORBIZE"
2640 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2641 OGGENCODER="$OGGENC"
2644 case "$FLACENCODERSYNTAX" in
2646 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2648 # FLAC streams can be encapsulated on a Ogg transport layer
2649 if echo "$FLACENCODEROPTS" | egrep -q -- "(^| )--ogg($| )" ;then
2650 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2651 echo " due to problem with adding comments to such files" >&2
2653 FLACOUTPUTCONTAINER=ogg
2655 FLACOUTPUTCONTAINER=flac
2659 case "$SPEEXENCODERSYNTAX" in
2661 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2662 SPEEXENCODER="$SPEEXENC"
2665 case "$MPPENCODERSYNTAX" in
2667 MPPENCODEROPTS="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2668 MPPENCODER="$MPPENC"
2674 if [ "$ID3TAGV" = "1" ]; then
2676 TAGGEROPTS="$ID3OPTS"
2679 TAGGEROPTS="$ID3V2OPTS"
2683 case "$CUEREADERSYNTAX" in
2685 CUEREADEROPTS="${CDROM}"
2690 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2691 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2692 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2693 echo " due to problem with adding comments to such files" >&2
2695 OGGOUTPUTCONTAINER=ogg.ogg
2696 FLACOUTPUTCONTAINER=flac.ogg
2697 vecho "abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2700 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2702 if [ "$ENCNICE" ]; then
2703 ENCNICE="-n $ENCNICE"
2705 if [ "$READNICE" ]; then
2706 READNICE="-n $READNICE"
2708 if [ "$DISTMP3NICE" ]; then
2709 DISTMP3NICE="-n $DISTMP3NICE"
2712 # Don't check for stuff if it's not needed
2713 if [ "$REMOTEHOSTS" ]; then
2716 if [ "$DONORMALIZE" = "y" ]; then
2719 if [ "$EJECTCD" = "y" ]; then
2722 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2725 if [ "$MAKECUEFILE" = "y" ]; then
2729 if [ X"$CDSPEEDVALUE" != "X" ]; then
2730 case "$CDROMREADERSYNTAX" in
2731 cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2736 # Rippers with USEPIPE support
2737 # FIXME # Include here all the rippers we can figure out support pipes
2740 # Encoders with USEPIPE support
2741 # FIXME # Include here all the encoders we can figure out support pipes
2746 # Figure out if we can use pipes with the ripper/encoder combination
2748 if [ "$USEPIPES" = "y" ]; then
2749 PIPERIPPERSVARCHECK="PIPE_${CDROMREADER}"
2752 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
2754 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
2756 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
2758 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
2760 PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
2762 if [ ! -n "$( eval echo "\$$PIPERIPPERSVARCHECK" )" ] ; then
2763 echo "abcde error: no support for pipes with given ripper" >&2
2764 echo "read the USEPIPES file from the source tarball to help" >&2
2765 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2768 if [ ! -n "$( eval echo "\$$PIPEENCODERSVARCHECK" )" ] ; then
2769 echo "abcde error: no support for pipes with given encoder" >&2
2770 echo "read the USEPIPES file from the source tarball to help" >&2
2771 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2776 # Make sure a buncha things exist
2777 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2778 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2779 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2780 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2781 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2782 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2783 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDCUEREADER+$CUEREADER}
2785 # Cut off the command-line options we just added in
2786 X=$(echo $X | cut -d' ' -f2)
2787 if [ "$(which $X)" = "" ]; then
2788 echo "abcde error: $X is not in your path." >&2
2790 elif [ ! -x $(which $X) ]; then
2791 echo "abcde error: $X is not executable." >&2
2796 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
2797 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
2798 HTTPGET="$HTTPGET $HTTPGETOPTS"
2800 # And last but not least, check if we can diff between files
2801 if [ -x $(which $DIFF) ]; then :; else
2802 vecho "[WAR] Disabling diff since we cannot find it in the \$PATH..."
2806 # Here it used to say:
2807 # One thousand lines in, we can start doing stuff with things
2808 # Well, right now we are at line 2736 ;)
2810 # Export needed things so they can be read in this subshell
2811 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2812 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2814 # User-definable function to set some things. Use it for
2815 # - closing the CD tray with eject -t
2816 # - set the CD speed value with eject -x
2817 vecho -n "Executing customizable pre-read function... "
2819 pre_read # Execute the user-defined pre-read funtion. Close the CD with it.
2823 do_discid # Get ABCDETEMPDIR created and status file initialized
2825 if [ "$DOCDDB" = "y" ]; then
2826 if [ $CDDBUSELOCAL = "y" ]; then
2829 if checkstatus cddb-choice > /dev/null; then
2832 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2840 eval $($CDDBTOOL parse "$CDDBDATA")
2843 # Before reading tracks, we set the speed of the device
2845 if [ X"$CDSPEEDVALUE" != "X" ]; then
2846 case "$CDROMREADERSYNTAX" in
2847 cdparanoia|debug) : ;;
2852 # Define the first and last track, since we might need them later in several places
2853 FIRSTTRACK=$( get_first $TRACKQUEUE )
2854 LASTTRACK=$( get_last $TRACKQUEUE )
2856 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
2857 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2858 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2859 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2862 # Create playlist if needed (backgroundable) and start reading in tracks
2866 if [ ! "$ONETRACK" = "y" ]; then
2867 if [ "$DOPLAYLIST" = "y" ]; then
2868 echo Creating playlist... >&2
2873 # For the lowdisk option, only one program is running at once so the encoder
2874 # can be unsilenced right away.
2875 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
2876 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2879 if [ "$ONETRACK" = "y" ]; then
2880 TRACKS="$FIRSTTRACK"
2881 if checkstatus readtrack-$FIRSTTRACK; then :; else
2882 do_cdread onetrack $FIRSTTRACK $LASTTRACK
2885 for UTRACKNUM in $TRACKQUEUE
2887 if [ "$DOREAD" = "y" ]; then
2888 if [ "$USEPIPES" = "y" ]; then
2889 if checkstatus readencodetrack-$UTRACKNUM; then :; else
2890 # Read, pipe, shut up!
2891 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
2894 if checkstatus readtrack-$UTRACKNUM; then :; else
2895 do_cdread $UTRACKNUM
2897 if [ "$?" != "0" ]; then
2898 # CD read failed - don't give the goahead to
2905 if [ "$BATCH" = "y" ]; then
2908 echo NEXTTRACK # Get the encoder machine churning again
2909 if [ "$DOREAD" = "y" ]; then
2910 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2911 until checkstatus encodetrack-$UTRACKNUM
2913 if checkerrors encodetrack-$UTRACKNUM; then
2924 # Now that we're done the encoding can be loud again -
2925 # if we're not using SMP.
2926 if [ "$MAXPROCS" = "1" ]; then
2927 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2930 # All tracks read, start encoding.
2931 if [ "$BATCH" = "y" ] || [ "$ONETRACK" = "y" ]; then
2935 # Execute the user-defined post_read funtion before ejecting CD
2938 # We are now finished with the cdrom - it can be safely ejected. Note that
2939 # abcde will not have completed yet.