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/\ \+$//')"
295 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
298 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
304 # Get the track number we are going to use for different actions
307 if [ -n "$STARTTRACKNUMBER" ] ; then
308 # Get the trackpadding from the current track
309 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
310 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
312 TRACKNUM=${UTRACKNUM}
318 run-command "" echo "Adding reply-gain information..."
319 for OUTPUT in $( echo $OUTPUTTYPE | tr , \ )
322 for UTRACKNUM in $TRACKQUEUE
324 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
325 do_getcddbinfo TRACKNAME
327 TRACKFILE=$(mungefilename "$TRACKNAME")
328 ARTISTFILE=$(mungefilename "$TRACKARTIST")
329 ALBUMFILE=$(mungefilename "$DALBUM")
331 if [ "$VARIOUSARTISTS" = "y" ]; then
332 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
334 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
336 OUTPUTFILES="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT $OUTPUTFILES"
343 echo vorbisgain-$OUTPUT >> "$ABCDETEMPDIR/status"
345 echo vorbisgain >> "$ABCDETEMPDIR/status"
348 # This code splits the a Various Artist track name from one of the following
351 # forward: Artist / Track
352 # forward-dash: Artist - Track
353 # reverse: Track / Artist
354 # reverse-dash: Track - Artist
355 # colon: Artist: Track
356 # trailing-paren: Artist (Track)
359 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
362 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
363 case "$VARIOUSARTISTSTYLE" in
365 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's- / -~-g')
366 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
367 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
370 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's, - ,~,g')
371 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
372 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
375 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's- / -~-g')
376 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
377 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
380 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's, - ,~,g')
381 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
382 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
385 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's-: -~-g')
386 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f1 -d~)
387 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f2 -d~)
390 DTITLEARTIST=$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')
391 TRACKARTIST=$(echo "$DTITLEARTIST" | cut -f2 -d~)
392 TRACKNAME=$(echo "$DTITLEARTIST" | cut -f1 -d~)
395 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
396 TRACKARTIST="Various"
398 TRACKARTIST="$DARTIST"
403 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
407 "classic rock") id=1 ;;
425 "industrial") id=19 ;;
426 "alternative") id=20 ;;
428 "death metal") id=22 ;;
430 "soundtrack") id=24 ;;
431 "euro-techno") id=25 ;;
435 "jazz+funk") id=29 ;;
438 "classical") id=32 ;;
439 "instrumental") id=33 ;;
443 "sound clip") id=37 ;;
446 "alt. rock") id=40 ;;
451 "meditative") id=45 ;;
452 "instrum. pop") id=46 ;;
453 "instrum. rock") id=47 ;;
457 "techno-indust.") id=51 ;;
458 "electronic") id=52 ;;
460 "eurodance") id=54 ;;
462 "southern rock") id=56 ;;
467 "christian rap") id=61 ;;
468 "pop/funk"|"pop / funk") id=62 ;;
470 "native american") id=64 ;;
473 "psychadelic") id=67 ;;
475 "showtunes") id=69 ;;
479 "acid punk") id=73 ;;
480 "acid jazz") id=74 ;;
484 "rock & roll") id=78 ;;
485 "hard rock") id=79 ;;
487 "folk/rock") id=81 ;;
488 "national folk") id=82 ;;
495 "bluegrass") id=89 ;;
496 "avantgarde") id=90 ;;
497 "gothic rock") id=91 ;;
498 "progress. rock") id=92 ;;
499 "psychadel. rock") id=93 ;;
500 "symphonic rock") id=94 ;;
501 "slow rock") id=95 ;;
504 "easy listening") id=98 ;;
510 "chamber music") id=104 ;;
512 "symphony") id=106 ;;
513 "booty bass") id=107 ;;
515 "porn groove") id=109 ;;
517 "slow jam") id=111 ;;
521 "folklore") id=115 ;;
523 "power ballad") id=117 ;;
524 "rhythmic soul") id=118 ;;
525 "freestyle") id=119 ;;
527 "punk rock") id=121 ;;
528 "drum solo") id=122 ;;
529 "a capella") id=123 ;;
530 "euro-house") id=124 ;;
531 "dance hall") id=125 ;;
533 "drum & bass") id=127 ;;
534 "club-house") id=128 ;;
535 "hardcore") id=129 ;;
539 "negerpunk") id=133 ;;
540 "polsk punk") id=134 ;;
542 "christian gangsta rap") id=136 ;;
543 "heavy metal") id=137 ;;
544 "black metal") id=138 ;;
545 "crossover") id=139 ;;
546 "contemporary christian")id=140 ;;
547 "christian rock") id=141 ;;
548 "merengue") id=142 ;;
550 "thrash metal") id=144 ;;
553 "synthpop") id=147 ;;
554 "rock/pop"|"rock / pop") id=148 ;;
561 # do_tag [tracknumber]
562 # id3 tags a filename
564 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
565 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
568 COMMENTOUTPUT="$(eval echo ${COMMENT})"
569 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
570 # If we want to start the tracks with a given number, we need to modify the
571 # TRACKNUM value before evaluation
572 # if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
573 # # Get the trackpadding from the current track
574 # CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
575 # TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
577 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
580 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
584 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
585 GENREID=$(do_getgenreid "${CDGENRE}")
590 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
591 run_command tagtrack-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
592 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
593 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
594 "${ENCODING:+--set-encoding=$ENCODING}"
595 "$ABCDETEMPDIR/track$1.$OUTPUT"
598 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
599 run_command tagtrack-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
600 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
601 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
602 "$ABCDETEMPDIR/track$1.$OUTPUT"
607 case "$OGGENCODERSYNTAX" in
609 # vorbiscomment can't do in-place modification, mv the file first
610 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
611 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
614 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
615 echo ARTIST="$TRACKARTIST"
617 echo TITLE="$TRACKNAME"
618 if [ -n "$CDYEAR" ]; then
621 if [ -n "$CDGENRE" ]; then
622 echo GENRE="$CDGENRE"
624 echo TRACKNUMBER=${TRACKNUM:-$1}
625 echo CDDB=$CDDBDISCID
626 if [ "$(eval echo ${COMMENT})" != "" ]; then
627 case "$COMMENTOUTPUT" in
628 *=*) echo "$COMMENTOUTPUT";;
629 *) echo COMMENT="$COMMENTOUTPUT";;
632 ) | run_command tagtrack-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
633 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
634 # Doublecheck that the commented file was created successfully before wiping the original
635 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
636 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
638 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
645 echo ARTIST="$TRACKARTIST"
647 echo TITLE="$TRACKNAME"
648 if [ -n "$CDYEAR" ]; then
651 if [ -n "$CDGENRE" ]; then
652 echo GENRE="$CDGENRE"
654 echo TRACKNUMBER=${TRACKNUM:-$1}
655 echo CDDB=$CDDBDISCID
656 if [ "$(eval echo ${COMMENT})" != "" ]; then
657 case "$COMMENTOUTPUT" in
658 *=*) echo "$COMMENTOUTPUT";;
659 *) echo COMMENT="$COMMENTOUTPUT";;
662 ) | run_command tagtrack-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
665 run_command tagtrack-$1 true
668 run_command tagtrack-$1 true
676 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
679 # The commands here don't go through run_command because they're never supposed to be silenced
680 echo "Batch encoding tracks: $TRACKQUEUE"
681 OUTPUT=$(echo $OUTPUTTYPE | grep "mp3" )
684 case "$MP3ENCODERSYNTAX" in
689 for UTRACKNUM in $TRACKQUEUE
691 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
693 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS `[ "$MP3ENCODER" = "lame" ] && echo "--nogap"` $TRACKFILES
695 if [ "$RETURN" != "0" ]; then
696 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
698 for UTRACKNUM in $TRACKQUEUE
700 echo encodetrack-$UTRACKNUM >> status
708 # Other encoders fall through to normal encoding as the tracks
709 # have not been entered in the status file.
712 # do_encode [tracknumber] [hostname]
713 # If no hostname is specified, encode locally
715 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
718 if [ "$USEPIPES" = "y" ]; then
721 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
724 TEMPARG="PIPE_$OGGENCODERSYNTAX"
727 TEMPARG="PIPE_$FLACENCODERSYNTAX"
730 TEMPARG="PIPE_$SPEEXENCODER"
733 TEMPARG="PIPE_$MPPENCODER"
736 IN="$( eval echo "\$$TEMPARG" )"
738 IN="$ABCDETEMPDIR/track$1.wav"
741 case "$MP3ENCODERSYNTAX" in
742 # FIXME # check if mp3enc needs -if for pipes
756 # We need IN to proceed, if we are not using pipes.
757 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
758 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
762 OUT="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
765 OUT="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
768 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
771 if [ X"$USEPIPES" = "Xy" ]; then
774 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
775 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
781 case "$MP3ENCODERSYNTAX" in
782 lame|gogo) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
783 bladeenc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
784 l3enc|xingmp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
785 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
786 mp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
790 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
797 case "$OGGENCODERSYNTAX" in
798 vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
799 oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
803 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
810 case "$FLACENCODERSYNTAX" in
811 flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
817 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
818 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
823 if [ "$(eval echo ${COMMENT})" != "" ]; then
826 *) COMMENT="COMMENT=$COMMENT" ;;
828 COMMENT="--comment \"$COMMENT\""
830 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
831 if [ ! "$DOTAG" = "y" ]; then
832 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
834 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
838 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
840 # I tried compiling the mppenc from corecodecs.org and got some
841 # errors, so I have not tried it myself.
842 ## FIXME ## Needs some cleanup to determine if an empty tag sent
843 ## FIXME ## to the encoder ends up empty.
844 $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
848 # Only remove .wav if the encoding succeeded
849 if checkerrors "encodetrack-(.{3,4})-$1"; then
850 run_command encodetrack-$1 false
852 run_command encodetrack-$1 true
853 if [ ! "$KEEPWAVS" = "y" ] ; then
858 if [ "$(checkstatus encode-output)" = "loud" ]; then
859 echo "HEH! The file we were about to encode disappeared:"
862 run_command encodetrack-$1 false
866 # do_preprocess [tracknumber]
868 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
871 # IN="$ABCDETEMPDIR/track$1.wav"
872 # # We need IN to proceed.
873 # if [ -s "$IN" ] ; then
874 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
876 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
877 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
878 # case "$POSTPROCESSFORMAT" in
880 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
882 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
884 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
886 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
888 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
891 # # Only remove .wav if the encoding succeeded
892 # if checkerrors "preprocess-(.{3,4})-$1"; then
893 # run_command preprocess-$1 false
895 # run_command preprocess-$1 true
898 # if [ "$(checkstatus encode-output)" = "loud" ]; then
899 # echo "HEH! The file we were about to pre-process disappeared:"
902 # run_command preprocess-$1 false
907 # do_postprocess [tracknumber]
909 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
912 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
914 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
915 # # We need IN to proceed.
916 # if [ -s "$IN" ] ; then
917 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
918 # run_command '' echo "Post-processing track $1 of $TRACKS..."
919 # case "$POSTPROCESSFORMAT" in
921 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
923 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
925 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
927 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
929 # # Only remove .wav if the encoding succeeded
930 # if checkerrors "postprocess-(.{3,4})-$1"; then
931 # run_command postprocess-$1 false
933 # run_command postprocess-$1 true
936 # if [ "$(checkstatus encode-output)" = "loud" ]; then
937 # echo "HEH! The file we were about to post-process disappeared:"
940 # run_command postprocess-$1 false
955 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
959 # The commands here don't go through run_command because they're never supposed to be silenced
960 echo "Batch analizing gain in tracks: $TRACKQUEUE"
965 for UTRACKNUM in $TRACKQUEUE
967 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
969 # XXX: Hard-coded batch option!
970 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
972 if [ "$RETURN" != "0" ]; then
973 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
975 for UTRACKNUM in $TRACKQUEUE
977 echo normalizetrack-$UTRACKNUM >> status
985 # NORMALIZER, NORMALIZEROPTS
986 do_batch_normalize ()
988 # The commands here don't go through run_command because they're never supposed to be silenced
989 echo "Batch normalizing tracks: $TRACKQUEUE"
994 for UTRACKNUM in $TRACKQUEUE
996 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
998 # XXX: Hard-coded batch option!
999 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1001 if [ "$RETURN" != "0" ]; then
1002 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1004 for UTRACKNUM in $TRACKQUEUE
1006 echo normalizetrack-$UTRACKNUM >> status
1012 # do_normalize [tracknumber]
1014 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1017 IN="$ABCDETEMPDIR/track$1.wav"
1018 if [ -e "$IN" ] ; then
1019 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1020 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1022 if [ "$(checkstatus encode-output)" = "loud" ]; then
1023 echo "HEH! The file we were about to normalize disappeared:"
1026 run_command normalizetrack-$1 false "File $IN was not found"
1030 # do_move [tracknumber]
1031 # Deduces the outfile from environment variables
1032 # Creates directory if necessary
1034 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1037 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1041 OUTPUT=$OGGOUTPUTCONTAINER
1044 OUTPUT=$FLACOUTPUTCONTAINER
1047 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1048 # Munge filenames as follows:
1053 # Eat control characters
1054 ALBUMFILE=$(mungefilename "$DALBUM")
1055 ARTISTFILE=$(mungefilename "$TRACKARTIST")
1056 TRACKFILE=$(mungefilename "$TRACKNAME")
1057 GENRE=$(mungegenre "$GENRE")
1058 YEAR=$(echo $CDYEAR)
1059 # If we want to start the tracks with a given number, we need to modify the
1060 # TRACKNUM value before evaluation
1061 # if [ -n "$STARTTRACKNUMBER" ] ; then
1062 # # Get the trackpadding from the current track
1063 # CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
1064 # TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1066 # TRACKNUM=${UTRACKNUM}
1069 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1070 # TRACKFILE, and TRACKNUM.
1071 if [ "$VARIOUSARTISTS" = "y" ]; then
1072 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
1074 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
1076 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1077 OUTPUTFILEDIR=$(dirname "$OUTPUTDIR/$OUTPUTFILE")
1078 # mkdir -p shouldn't return an error if the directory already exists
1079 mkdir -p "$OUTPUTFILEDIR"
1080 # Silence the Moving output since it overlaps with encoding processes...
1081 #run_command '' vecho "Moving track$1.$OUTPUT to $OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1082 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1083 # Lets move the cue file
1084 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1085 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1086 if checkstatus movecue-$OUTPUT; then :; else
1087 # Silence the Copying output since it overlaps with encoding processes...
1088 #run_command '' vecho "Copying cue file to its destination directory..."
1089 if checkstatus onetrack >/dev/null ; then
1091 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1092 # http://brianvictor.tripod.com/mp3cue.htm#details
1093 [a-z0-9][a-z0-9][a-z0-9])
1094 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1097 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1101 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1103 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1111 # Create the playlist if wanted
1113 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1114 # VARIOUSARTISTS, OUTPUTDIR
1117 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1119 # Create a playlist file for the playlist data to go into.
1120 # We used to wipe it out if it existed. Now we request permision if interactive.
1121 for LASTTRACK in $TRACKQUEUE; do :; done
1122 ALBUMFILE=$(mungefilename "$DALBUM")
1123 ARTISTFILE=$(mungefilename "$DARTIST")
1124 GENRE=$(mungegenre "$GENRE")
1125 YEAR=${CDYEAR:-$CDYEAR}
1126 if [ "$VARIOUSARTISTS" = "y" ] ; then
1127 PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
1129 PLAYLISTFILE=$(eval echo $PLAYLISTFORMAT)
1131 FINALPLAYLISTDIR=$(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1132 mkdir -p "$FINALPLAYLISTDIR"
1133 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1134 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1135 if [ "$INTERACTIVE" = "y" ]; then
1136 while [ "$DONE" != "y" ]; do
1138 case $ERASEPLAYLIST in
1139 e|E|a|A|k|K) DONE=y ;;
1147 # Once we erase the playlist, we use append to create the new one.
1148 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1150 # The playlist does not exist, so we can safelly use append to create the new list
1153 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1154 touch "$OUTPUTDIR/$PLAYLISTFILE"
1155 for UTRACKNUM in $TRACKQUEUE
1157 # Shares some code with do_move since the filenames have to match
1158 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1159 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1160 do_getcddbinfo TRACKNAME
1162 TRACKFILE=$(mungefilename "$TRACKNAME")
1163 ARTISTFILE=$(mungefilename "$TRACKARTIST")
1164 ALBUMFILE=$(mungefilename "$DALBUM")
1165 # If we want to start the tracks with a given number, we need to modify the
1166 # TRACKNUM value before evaluation
1167 # if [ -n "$STARTTRACKNUMBER" ] ; then
1168 # # Get the trackpadding from the current track
1169 # CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
1170 # TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1172 # TRACKNUM=${UTRACKNUM}
1175 if [ "$VARIOUSARTISTS" = "y" ]; then
1176 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
1178 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
1180 if [ "$VARIOUSARTISTS" = "y" ]; then
1181 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1182 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1184 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1187 if [ "$PLAYLISTDATAPREFIX" ]; then
1188 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1190 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1195 ## this will convert the playlist to have CRLF line-endings, if specified
1196 ## (some hardware players insist on CRLF endings)
1197 if [ "$DOSPLAYLIST" = "y" ]; then
1198 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1199 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1200 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1202 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1207 # This essentially the start of things
1210 # Query the CD to get the track info, unless the user specified -C
1211 # or we are using some actions which do not need the CDDB data at all
1212 #if [ ! X"$EXPACTIONS" = "X" ]; then
1214 #elif [ -z "$DISCID" ]; then
1215 if [ -z "$DISCID" ]; then
1216 vecho -n "Getting CD track info... "
1217 # In OSX, unmount the disc before a query
1218 if [ "$OSFLAVOUR" = "OSX" ]; then
1219 disktool -u ${CDROM#/dev/}
1221 TRACKINFO=$($CDDISCID $CDROM)
1222 # Make sure there's a CD in there by checking cd-discid's return code
1223 if [ "$?" = "1" ]; then
1224 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1227 # In OSX, remount the disc again
1228 if [ "$OSFLAVOUR" = "OSX" ]; then
1229 disktool -m ${CDROM#/dev/}
1233 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1236 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1237 # This needs to be done now because a section of the resuming code will need
1240 # get the number of digits to pad TRACKNUM with - we'll use this later
1241 # a CD can only hold 99 tracks, but since we support a feature for starting
1242 # numbering the tracks from a given number, we might need to set it as a
1243 # variable for the user to define... or obtain it somehow.
1244 if [ "$PADTRACKS" = "y" ] ; then
1248 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1249 if [ -z "$TRACKQUEUE" ]; then
1250 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1251 case "$CDROMREADERSYNTAX" in
1253 if [ "$WEHAVEACD" = "y" ]; then
1254 vecho "Querying the CD for audio tracks..."
1255 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1257 if [ ! "$RET" = "0" ];then
1258 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1260 TRACKS="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ' )"
1261 CDPARANOIAAUDIOTRACKS="$TRACKS"
1263 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks ; then
1264 TRACKS=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" )
1266 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1270 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1273 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1275 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1276 echo "The disc does not contain any tracks. Giving up..."
1279 echo -n "Grabbing entire CD - tracks: "
1280 if [ ! "$PADTRACKS" = "y" ] ; then
1281 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1283 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1285 while [ "$X" -ne "$TRACKS" ]
1287 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1288 TRACKQUEUE=$(echo "$TRACKQUEUE" $X)
1292 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1293 # User-supplied track queue.
1294 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1295 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1296 # Once cleaned, obtain the highest value in the trackqueue for number padding
1297 for LASTTRACK in $TRACKQUEUE; do :; done
1298 if [ ! "$PADTRACKS" = "y" ] ; then
1299 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1301 # Now we normalize the trackqueue
1302 for TRACK in $TRACKQUEUE ; do
1303 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1304 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1306 TRACKQUEUE=$PADTRACKQUEUE
1307 echo Grabbing tracks: "$TRACKQUEUE"
1310 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1312 # We have the discid, create a temp directory after it to store all the temp
1315 if [ -e "$ABCDETEMPDIR" ]; then
1316 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1317 # It already exists, see if it's a directory
1318 if [ ! -d "$ABCDETEMPDIR" ]; then
1319 # This is a file/socket/fifo/device/etc, not a directory
1322 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1323 echo "Please investigate, remove it, and rerun abcde." >&2
1327 # It's a directory, let's see if it's owned by us
1328 if [ ! -O "$ABCDETEMPDIR" ]; then
1329 # Nope, complain and exit
1331 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1332 echo "Please investigate, remove it, and rerun abcde." >&2
1336 # See if it's populated
1337 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1338 # Wipe and start fresh
1339 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1340 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1341 if [ "$INTERACTIVE" = "y" ]; then
1347 if [ "$ANSWER" != "y" ]; then
1350 rm -rf "$ABCDETEMPDIR" || exit 1
1351 mkdir "$ABCDETEMPDIR"
1352 if [ "$?" -gt "0" ]; then
1353 # Directory already exists or could not be created
1354 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1358 # Everything is fine. Check for ^encodetracklocation-
1359 # and encode-output entries in the status file and
1360 # remove them. These are not relevant across sessions.
1361 if [ -f "$ABCDETEMPDIR/status" ]; then
1362 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1363 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1364 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1366 # Remove old error messages
1367 if [ -f "$ABCDETEMPDIR/errors" ]; then
1368 rm -f "$ABCDETEMPDIR/errors"
1372 # We are starting from scratch
1373 mkdir "$ABCDETEMPDIR"
1374 if [ "$?" -gt "0" ]; then
1375 # Directory already exists or could not be created
1376 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1379 cat /dev/null > "$ABCDETEMPDIR/status"
1381 if [ X"$MAKECUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1382 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1383 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1384 vecho "Creating cue file..."
1385 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1386 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1388 echo "abcde: reading the CUE sheet with mkcue is still considered experimental"
1389 echo "abcde: and there was a problem with the CD reading. abcde will continue,"
1390 echo "abcde: but consider reporting the problem to the abcde author"
1394 # If we got the CDPARANOIA status and it is not recorded, save it now
1395 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1396 if checkstatus cdparanoia-audio-tracks; then :; else
1397 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1398 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1403 # Create the discid file
1404 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1408 # Create a proper CUE file based on the CUE file we created before.
1411 # FIXME # we can get the name of the cuefile from the status file
1412 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1413 CUEFILE_OUT=$CUEFILE_IN.out
1414 ### FIXME ### checkstatus cddb
1415 if [ -e "$CDDBDATA" ]; then
1416 vecho "Adding metadata to the cue file..."
1417 # FIXME It doesn't preserve spaces! Why?
1418 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1420 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1421 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1422 cat "$CUEFILE_IN" | while read line
1424 if echo "$line" | grep -q "INDEX"
1426 eval track="\$TRACK$n"
1428 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1430 echo "$line" >> "$CUEFILE_OUT"
1432 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1433 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1439 # Parses a CDDB file and outputs the title and the track names.
1440 # Variables: CDDBFILE
1444 # List out disc title/author and contents
1445 if [ "$ONETRACK" = "y" ]; then
1446 vecho "ONETRACK mode selected: displaying only the title of the CD..."
1448 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1449 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
1450 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1451 if [ ! X"$PARSEDYEAR" = "X" ]; then
1452 echo "Year: $PARSEDYEAR"
1455 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
1456 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1457 if [ ! X"$PARSEDGENRE" = "X" ]; then
1458 echo "Genre: $PARSEDGENRE"
1461 if [ ! "$ONETRACK" = "y" ]; then
1462 for TRACK in $(f_seq_row 1 $TRACKS)
1464 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1470 # Check for a local CDDB file, and report success
1473 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
1475 CDDBLOCALSUCCESS="n"
1476 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1477 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1480 # If the user has selected to check a local CDDB repo, we proceed with it
1481 if [ -r "${CDDBLOCALFILE}" ]; then
1482 # List out disc title/author and contents
1483 do_cddbparse "${CDDBLOCALFILE}"
1484 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1485 if [ "$INTERACTIVE" = "y" ]; then
1487 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1488 echo -n 'Invalid selection. Please answer "y" or "n": '
1491 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
1495 if [ "$USELOCALRESP" = "y" ]; then
1496 #echo "Using local copy of CDDB data"
1497 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1498 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1499 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
1500 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1501 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1502 CDDBLOCALSUCCESS="y"
1504 #echo "Not using local copy of CDDB data"
1505 CDDBLOCALSUCCESS="n"
1508 CDDBLOCALSUCCESS="n"
1516 # Perform CDDB protocol version check if it hasn't already been done
1517 if checkstatus cddb-statcomplete; then :; else
1518 if [ "$CDDBAVAIL" = "n" ]; then
1520 echo 503 > "$ABCDETEMPDIR/cddbstat"
1523 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1524 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1525 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1526 vecho "Checking CDDB server status..."
1527 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1528 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
1529 case "$RESPONSECODE" in
1530 210) # 210 OK, status information follows (until terminating `.')
1533 501|*) # 501 Illegal CDDB protocol level: <n>.
1534 CDDBPROTO=`expr $CDDBPROTO - 1`
1538 if test $rc -eq 1; then
1542 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
1550 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1551 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1553 # Perform CDDB query if it hasn't already been done
1554 if checkstatus cddb-querycomplete; then :; else
1555 if [ "$CDDBAVAIL" = "n" ]; then
1557 echo 503 > "$ABCDETEMPDIR/cddbquery"
1558 # The default CDDBLOCALSUCCESS is "n"
1559 # This part will be triggered if the user CDDB repo does not
1560 # contain the entry, or if we are not trying to use the repo.
1562 vecho "Querying the CDDB server..."
1563 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1564 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1565 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1571 # no match found in database,
1572 # wget/fetch error, or user requested not to use CDDB
1573 # Make up an error code (503) that abcde
1574 # will recognize in do_cddbread
1575 # and compensate by making a template
1576 echo 503 > "$ABCDETEMPDIR/cddbquery"
1578 *) # strange and unknown error
1579 echo ERRORCODE=$ERRORCODE
1580 echo "abcde: $CDDBTOOL returned unknown error code"
1584 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
1591 # If it's not to be used, generate a template.
1592 # Then, display it (or them) and let the user choose/edit it
1593 if checkstatus cddb-readcomplete; then :; else
1594 vecho "Obtaining CDDB results..."
1595 # If CDDB is to be used, interpret the query results and read all
1596 # the available entries.
1597 rm -f "$ABCDETEMPDIR/cddbchoices"
1598 CDDBCHOICES=1 # Overridden by multiple matches
1599 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
1600 case "$RESPONSECODE" in
1602 # One exact match, retrieve it
1603 # 200 [section] [discid] [artist] / [title]
1604 if checkstatus cddb-read-1-complete; then :; else
1605 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1606 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1607 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1608 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1609 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1611 # List out disc title/author and contents
1612 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
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"
1621 case "$RESPONSECODE" in
1622 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1623 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1624 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1626 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1627 # List out disc title/author and contents of template
1628 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
1630 for TRACK in $(f_seq_row 1 $TRACKS)
1632 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1634 echo >> "$ABCDETEMPDIR/cddbchoices"
1635 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
1636 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
1639 # Multiple exact, (possibly multiple) inexact matches
1641 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
1642 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
1643 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1644 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1645 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1647 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1649 vecho -n "Retrieving multiple matches... "
1650 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
1651 read DISCINFO # eat top line
1655 if checkstatus cddb-read-$X-complete; then :; else
1656 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1657 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
1659 # List out disc title/author and contents
1660 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1661 for TRACK in $(f_seq_row 1 $TRACKS)
1663 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1665 echo >> "$ABCDETEMPDIR/cddbchoices"
1668 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1672 for TRACK in $(f_seq_row 1 $TRACKS)
1674 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1676 echo >> "$ABCDETEMPDIR/cddbchoices"
1677 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1678 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1681 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1688 if checkstatus cddb-edit >/dev/null; then
1689 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1690 VARIOUSARTISTS="$(checkstatus variousartists)"
1691 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
1694 if [ "$INTERACTIVE" = "y" ]; then
1695 # We should show the CDDB results both when we are not using the local CDDB repo
1696 # or when we are using it but we could not find a proper match
1697 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1698 # Display the $ABCDETEMPDIR/cddbchoices file created above
1699 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1700 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1701 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1702 CHOICE=$(checkstatus cddb-choice)
1703 if [ -n "$CHOICE" ] ; then
1704 case $CDDBCHOICES in
1705 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1707 echo "Selected: #$CHOICE"
1708 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1712 # The user has a choice to make, display the info in a pager if necessary
1713 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
1714 page "$ABCDETEMPDIR/cddbchoices"
1716 # It's all going to fit in one page, cat it
1717 cat "$ABCDETEMPDIR/cddbchoices" >&2
1721 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1723 # I'll take CDDB read #3 for $400, Alex
1724 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1725 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1727 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
1728 if echo $CDDBCHOICE | egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1729 if [ ! X"$DIFF" = "X" ]; then
1730 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1)
1731 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2)
1732 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1733 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1734 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1735 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1738 # We parse the 2 choices to diff, store them in temporary files and diff them.
1739 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
1740 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1742 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1743 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1744 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
1745 page "$ABCDETEMPDIR/cddbread.diff"
1747 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1751 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1754 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1755 # Make sure we get a valid choice
1756 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
1757 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1761 if [ "$CDCHOICENUM" = "0" ]; then
1762 vecho "Creating empty CDDB template..."
1764 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1766 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1767 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1769 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1773 # We need some code to show the selected option when local repository is selected and we have found a match
1774 vecho "Using cached CDDB match..." >&2
1775 # Display the $ABCDETEMPDIR/cddbchoices file created above
1776 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1777 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1778 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1779 CHOICE=$(checkstatus cddb-choice)
1780 if [ "$USELOCALRESP" = "y" ]; then :; else
1781 if [ -n "$CHOICE" ] ; then
1782 case $CDDBCHOICES in
1785 echo "Selected template."
1787 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1789 echo "Selected: #$CHOICE"
1790 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1798 # We're noninteractive - pick the first choice.
1799 # But in case we run a previous instance and selected a choice, use it.
1800 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1801 # Show the choice if we are not using the locally stored one
1802 # or when the local search failed to find a match.
1803 PREVIOUSCHOICE=$(checkstatus cddb-choice)
1804 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1805 #if [ "$PREVIOUSCHOICE" ]; then
1806 cat "$ABCDETEMPDIR/cddbchoices"
1809 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1810 CDCHOICENUM=$PREVIOUSCHOICE
1813 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1815 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1820 if checkstatus cddb-choice >/dev/null; then :; else
1821 echo "abcde: internal error: cddb-choice not recorded." >&2
1824 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1825 echo -n "Edit selected CDDB data? [y/n] (" >&2
1826 if [ "$INTERACTIVE" = "y" ]; then
1827 if [ "$UNKNOWNDISK" = "y" ]; then
1830 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
1839 if [ "$EDITCDDB" = "y" ]; then
1840 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
1842 # Use the debian sensible-editor wrapper to pick the editor that the
1843 # user has requested via their $EDITOR environment variable
1844 if [ -x "/usr/bin/sensible-editor" ]; then
1845 /usr/bin/sensible-editor "$CDDBDATA"
1846 elif [ -n "$EDITOR" ]; then
1847 if [ -x $(which "${EDITOR%%\ *}") ]; then
1848 # That failed, try to load the preferred editor, starting
1849 # with their EDITOR variable
1850 eval $(echo "$EDITOR") \"$CDDBDATA\"
1852 # If that fails, check for a vi
1853 elif which vi >/dev/null 2>&1; then
1855 elif [ -x /usr/bin/vim ]; then
1856 /usr/bin/vim "$CDDBDATA"
1857 elif [ -x /usr/bin/vi ]; then
1858 /usr/bin/vi "$CDDBDATA"
1859 elif [ -x /bin/vi ]; then
1861 # nano should be on all (modern, i.e., sarge) debian systems
1862 elif which nano >/dev/null 2>&1 ; then
1864 elif [ -x /usr/bin/nano ]; then
1865 /usr/bin/nano "$CDDBDATA"
1866 # mg should be on all OpenBSD systems
1867 elif which mg >/dev/null 2>&1 ; then
1869 elif [ -x /usr/bin/mg ]; then
1870 /usr/bin/mg "$CDDBDATA"
1873 echo "No editor available. Check your EDITOR environment variable." >&2
1875 # delete editor backup file if it exists
1876 if [ -w "$CDDBDATA~" ]; then
1881 # Some heuristics first. Look at Disc Title, and if it starts with
1882 # "Various", then we'll assume Various Artists
1883 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1884 echo "Looks like a Multi-Artist CD" >&2
1887 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1888 if [ "$INTERACTIVE" = "y" ]; then
1895 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1898 # Need NUMTRACKS before cddb-tool will return it:
1899 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
1900 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1901 # More than 1/2 tracks contain a "/", so guess forward
1903 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1904 # More than 1/2 contain a "-", so guess forward-dash
1906 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1907 # More than 1/2 contain something in parens, so guess trailing-paren
1911 echo "1) Artist / Title" >&2
1912 echo "2) Artist - Title" >&2
1913 echo "3) Title / Artist" >&2
1914 echo "4) Title - Artist" >&2
1915 echo "5) Artist: Title" >&2
1916 echo "6) Title (Artist)" >&2
1917 echo "7) This is a single-artist CD" >&2
1918 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1919 if [ "$INTERACTIVE" = "y" ]; then
1920 read VARIOUSARTISTSTYLE
1922 echo $DEFAULTSTYLE >&2
1923 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
1925 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
1926 # If they press Enter, then the default style (0) was chosen
1927 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
1928 echo "Invalid selection. Please choose a number between 1 and 7."
1929 echo -n "Selection [1-7]: "
1930 read VARIOUSARTISTSTYLE
1931 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
1933 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1934 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
1936 vecho "Selected: $VARIOUSARTISTSTYLE"
1937 case "$VARIOUSARTISTSTYLE" in
1939 VARIOUSARTISTSTYLE=forward
1942 VARIOUSARTISTSTYLE=forward-dash
1945 VARIOUSARTISTSTYLE=reverse
1948 VARIOUSARTISTSTYLE=reverse-dash
1951 VARIOUSARTISTSTYLE=colon
1954 VARIOUSARTISTSTYLE=trailing-paren
1962 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1963 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1965 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1966 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
1967 # This works but does not have the necessary error checking
1968 # yet. If you are familiar with the CDDB spec
1969 # (see http://www.freedb.org/src/latest/DBFORMAT)
1970 # and can create an error-free entry on your own, then put
1971 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1972 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1973 # your abcde.conf to change the email address submissions are
1976 # submit the modified file, if they want
1977 if [ "$NOSUBMIT" != "y" ]; then
1978 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1980 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1981 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1983 echo -n 'Invalid selection. Please answer "y" or "n": '
1986 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
1987 echo -n "Sending..."
1988 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
1994 # Make sure the cache directory exists
1995 mkdir -p $CDDBLOCALDIR
1996 # Cache edited CDDB entry in the user's cddb dir
1997 if [ "$CDDBCOPYLOCAL" = "y" ] || [ "$COPYCDDBLOCAL" = "Y" ]; then
1998 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2001 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2004 # do_cdread [tracknumber]
2005 # do_cdread onetrack [firsttrack] [lasttrack]
2009 # The commands here don't go through run_command because they're never supposed to be silenced
2010 # return codes need to be doublechecked anyway, however
2011 if [ "$1" = "onetrack" ]; then
2012 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2013 # FIXME # Until then, we grab the whole CD in one track, no matter what
2015 # We need the first and last track for cdda2wav
2018 UTRACKNUM=$FIRSTTRACK
2019 case "$CDROMREADERSYNTAX" in
2020 cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2021 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
2022 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2028 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2029 if [ "$USEPIPES" = "y" ]; then
2030 TEMPARG="PIPE_$CDROMREADERSYNTAX"
2031 FILEARG="$( eval echo "\$$TEMPARG" )"
2033 PIPE_MESSAGE="and encoding "
2035 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2036 case "$CDROMREADERSYNTAX" in
2037 ## FIXME ## Find the case for dagrab, to avoid exceptions
2039 FILEARG="-f $WAVDATA"
2047 if [ "$1" = "onetrack" ]; then
2048 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2050 if [ -r "$CDDBDATA" ]; then
2051 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
2052 do_getcddbinfo TRACKNAME
2053 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2055 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2058 case "$CDROMREADERSYNTAX" in
2060 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2062 if [ "$OSFLAVOUR" = "OSX" ] ; then
2063 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2064 disktool -u ${CDROM#/dev/} 0
2065 # Also, in OSX the cdrom device for cdda2wav changes...
2066 CDDA2WAVCDROM="IODVDServices"
2067 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2068 CDDA2WAVCDROM="$CDROMID"
2070 if [ "$CDROMID" = "" ]; then
2071 CDDA2WAVCDROM="$CDROM"
2073 CDDA2WAVCDROM="$CDROMID"
2076 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2078 ## FIXME ## We have an exception for dagrab, since it uses -f
2079 ## FIXME ## Shall we just use -f $FILEARG ??
2080 dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2083 # Find the track's mounted path
2084 REALTRACKNUM=$(expr $UTRACKNUM + 0)
2085 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
2086 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2087 # If the file exists, copy it
2088 if [ -e "$FILEPATH" ] ; then
2089 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2093 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2097 # If we get some error or we get some missing wav
2098 # (as long as we dont use pipes)
2099 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
2100 # Thank goodness errors is only machine-parseable up to the
2101 # first colon, otherwise this woulda sucked
2102 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2103 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2105 if [ "$USEPIPES" = "y" ]; then
2106 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2108 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2112 if [ "$USEPIPES" = "y" ]; then
2113 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2115 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2116 if [ "$1" = "onetrack" ]; then
2117 echo onetrack >> "$ABCDETEMPDIR/status"
2124 # No values accepted, only uses env variables
2127 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
2128 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
2130 echo "abcde: unable to set the device speed" >&2
2136 # vecho outputs a message if EXTRAVERBOSE is selected
2139 if [ x"$EXTRAVERBOSE" != "x" ]; then
2144 # User-redefinable functions
2145 # Custom filename munging:
2148 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2149 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
2152 # Custom genre munging:
2155 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2159 # Empty pre_read function, to be defined in the configuration file.
2166 # Empty post_read function, to be defined in the configuration file.
2172 ###############################################################################
2175 # Start of execution
2176 ###############################################################################
2179 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2180 CDDBSUBMIT=freedb-submit@freedb.org
2182 HELLOINFO="$(whoami)@$(hostname)"
2184 CDDBLOCALDIR="$HOME/.cddb"
2187 # List of fields we parse and show during the CDDB parsing...
2188 SHOWCDDBFIELDS="year,genre"
2191 CDROMREADERSYNTAX=cdparanoia
2192 ENCODERSYNTAX=default
2194 MP3ENCODERSYNTAX=default
2195 OGGENCODERSYNTAX=default
2196 FLACENCODERSYNTAX=default
2197 SPEEXENCODERSYNTAX=default
2198 MPPENCODERSYNTAX=default
2199 NORMALIZERSYNTAX=default
2200 CUEREADERSYNTAX=default
2202 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2203 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2204 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2205 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2206 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2207 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2208 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2209 PLAYLISTDATAPREFIX=''
2210 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2211 VAPLAYLISTDATAPREFIX=''
2219 VARIOUSARTISTSTYLE=forward
2223 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2224 # i.e. CDROMID="1,0,0"
2226 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2227 # If we are using the ide-scsi emulation layer, we need to define a "g"
2228 CDPARANOIACDROMBUS="d"
2230 # program paths - defaults to checking your $PATH
2236 XINGMP3ENC=xingmp3enc
2251 CDPARANOIA=cdparanoia
2260 VORBISCOMMENT=vorbiscomment
2262 NORMALIZE=normalize-audio
2264 VORBISGAIN=vorbisgain
2269 # Options for programs called from abcde
2301 VORBISCOMMENTOPTS="-R"
2302 METAFLACOPTS="--no-utf8-convert"
2304 # Default to one process if -j isn't specified
2307 # List of actions to perform - by default, run to completion
2308 ACTIONS=cddb,read,encode,tag,move,clean
2310 # List of prefered outputs - by default, run with whatever we have in the path
2311 # This option is basicaly for Debian package dependencies
2312 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex
2314 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2315 # Let's use these checkings to determine the OS flavour, which will be used later
2316 if [ X$(uname) = "XFreeBSD" ] ; then
2321 elif [ X$(uname) = "XDarwin" ] ; then
2324 # We should have disktool in OSX, but let's be sure...
2326 CDROMREADERSYNTAX=cddafs
2327 elif [ X$(uname) = "XOpenBSD" ] ; then
2330 elif [ X$(uname) = "XNetBSD" ] ; then
2337 # If CDDBAVAIL is set to n, no CDDB read is done
2338 # If USEID3 is set to n, no ID3 tagging is done
2343 if [ -z "$OUTPUTDIR" ]; then
2347 if [ -z "$WAVOUTPUTDIR" ]; then
2348 WAVOUTPUTDIR="$OUTPUTDIR"
2351 # Load system defaults
2352 if [ -r /etc/abcde.conf ]; then
2355 # Load user preference defaults
2356 if [ -r $HOME/.abcde.conf ]; then
2360 # By this time, we need some HTTPGETOPTS already defined.
2361 # If the user has defined a non-default HTTPGET method, we should not be empty.
2363 if [ "$HTTPGETOPTS" = "" ] ; then
2365 wget) HTTPGETOPTS="-q -O -";;
2366 curl) HTTPGETOPTS="-f -s";;
2367 fetch)HTTPGETOPTS="-q -o -";;
2368 ftp) HTTPGETOPTS="-q -o -";;
2369 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2373 # If the CDROM has not been set yet, find a suitable one.
2374 # If this is a devfs system, default to /dev/cdroms/cdrom0
2375 # instead of /dev/cdrom
2376 if [ "$CDROM" = "" ] ; then
2377 if [ -e /dev/cdroms/cdrom0 ]; then
2378 CDROM=/dev/cdroms/cdrom0
2379 elif [ -e /dev/cdrom ]; then
2381 elif [ -e /dev/cd0c ]; then
2383 elif [ -e /dev/acd0c ]; then
2385 elif [ -e /dev/disk1 ]; then
2390 # Parse command line options
2391 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2392 while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2395 a) ACTIONS="$OPTARG" ;;
2396 A) EXPACTIONS="$OPTARG" ;;
2398 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2399 C) DISCID="${OPTARG#abcde.}" ;;
2400 d) CDROM="$OPTARG" ;;
2402 e) ERASEENCODEDSTATUS=y ;;
2404 e) ERASEENCODEDSTATUS=y ;;
2405 E) ENCODING="$OPTARG" ;;
2406 # f) FORCECDDBUSELOCAL=y ;;
2408 j) MAXPROCS="$OPTARG" ;;
2411 L) CDDBUSELOCAL=y ;;
2416 o) OUTPUTTYPE="$OPTARG" ;;
2419 r) REMOTEHOSTS="$OPTARG" ;;
2421 s) SHOWCDDBFIELDS="$OPTARG" ;;
2422 S) CDSPEEDVALUE="$OPTARG" ;;
2423 # t) PREPROCESSFORMATS="$OPTARG"
2425 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2426 t) STARTTRACKNUMBER="$OPTARG" ;;
2427 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
2429 echo "This is abcde v$VERSION."
2430 echo "Usage: abcde [options] [tracks]"
2431 echo "abcde -h for extra help"
2434 V) EXTRAVERBOSE="y" ;;
2436 w) COMMENT="$OPTARG" ;;
2437 W) if echo $OPTARG | grep -q "[[:digit:]]" ; then
2438 STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
2440 echo "abcde error: argument of -W must be integer"
2448 shift $(($OPTIND - 1))
2450 # Decide if we can continue.
2451 if [ "$ONETRACK" = "y" ]; then
2452 # FIXME # remove check as soon as we find out about the other readers
2453 case "$CDROMREADERSYNTAX" in
2456 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2459 if [ "$BATCH" = "y" ]; then
2460 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2463 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2464 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2465 if [ $# -gt 0 ]; then
2466 vecho "abcde warning: ONETRACK mode selected, grabbing all tracks..."
2469 while [ $# -gt 0 ]; do
2470 # Range parsing code courtesy of Vincent Ho
2471 RSTART=$(echo $1 | cut -f1 -d-)
2472 REND=$(echo $1 | cut -f2 -d-)
2473 if [ "$RSTART" = "$REND" ]; then
2476 NEWTRACKS=$(f_seq_line $RSTART $REND)
2478 TRACKQUEUE=$(echo "$TRACKQUEUE" "$NEWTRACKS")
2483 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2484 # List of experimental actions: retag,transcode
2486 # Determine what actions are to be done from $ACTIONS and set the
2487 # following environment variables for them:
2499 for ACTION in $(echo $ACTIONS | tr , \ )
2504 normalize) DONORMALIZE=y; DOREAD=y;;
2505 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2506 encode) DOENCODE=y; DOREAD=y;;
2507 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2508 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2509 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2510 playlist) DOCDDB=y; DOPLAYLIST=y;;
2515 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
2516 case $SHOWCDDBFIELD in
2517 y*|Y*) SHOWCDDBYEAR="y";;
2518 g*|G*) SHOWCDDBGENRE="y";;
2525 # At this point a CDROM has to be defined, so we check it exists.
2526 if [ X"$CDROM" != "X" ] ; then
2527 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2528 if [ "$OSFLAVOUR" = "FBSD" ]; then
2529 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
2530 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2531 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2535 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
2536 echo "abcde error: CDROM device cannot be found." >&2
2539 # avoid processing if we are not going to hit the CDROM.
2540 elif [ X"$DOREAD" = "Xy" ]; then
2541 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2545 # USEPIPES pre-tests, before we get into more serious stuff
2546 # Not compatible with:
2547 # - multiple outputs
2549 # - lowdisk algorithm
2551 if [ X"$USEPIPES" = "Xy" ]; then
2552 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
2553 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
2556 if [ X"$DONORMALIZE" = "Xy" ]; then
2557 echo "abcde error: Unix pipes not compatible with normalizer"
2558 # FIXME # Do we need to exit or shall we just disable the mode?
2561 if [ X"$DOENCODE" = "Xn" ]; then
2562 vecho "Disabling Unix pipes since we are not encoding!"
2565 if [ X"$LOWDISK" = "Xy" ]; then
2566 vecho "abcde error: Unix pipes not compatible with lowdisk algorithm"
2571 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2572 if [ X"$OUTPUTTYPE" = "X" ]; then
2573 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
2574 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2575 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2576 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
2577 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
2578 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2582 if [ X"$OUTPUTTYPE" = "X" ]; then
2583 echo "abcde error: no encoder found in the PATH" >&2
2584 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2589 # Decide which CDROM reader we're gonna use
2590 case "$CDROMREADERSYNTAX" in
2592 CDROMREADER="$CDPARANOIA"
2593 CDROMREADEROPTS="$CDPARANOIAOPTS"
2596 CDROMREADER="$CDDA2WAV"
2597 CDROMREADEROPTS="$CDDA2WAVOPTS"
2600 CDROMREADER="$DAGRAB"
2601 CDROMREADEROPTS="$DAGRABOPTS"
2604 CDROMREADER="$CDDAFS"
2605 CDROMREADEROPTS="$CDDAFSOPTS"
2609 # There's only one normalize...
2610 case "$NORMALIZERSYNTAX" in
2612 NORMALIZER="$NORMALIZE"
2613 NORMALIZEROPTS="$NORMALIZEOPTS"
2617 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2618 if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
2619 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ ); do
2621 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2622 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2623 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2624 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2625 mpc:*) MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2628 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ ); do
2629 TEMPOUTPUT=$( echo "$OUTPUT" | cut -d: -f1 )
2630 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2632 OUTPUTTYPE="$TEMPOUTPUTTYPE"
2635 # 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
2637 # Getting ready for multiple output changes
2638 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
2642 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
2643 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
2644 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
2645 OGGOUTPUTCONTAINER=ogg
2648 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
2649 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
2652 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
2653 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
2656 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
2659 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
2661 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2667 # decide which encoder
2668 case "$MP3ENCODERSYNTAX" in
2670 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2674 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2678 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2679 MP3ENCODER="$BLADEENC"
2682 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2686 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2687 MP3ENCODER="$XINGMP3ENC"
2690 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2691 MP3ENCODER="$MP3ENC"
2694 case "$OGGENCODERSYNTAX" in
2696 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2697 OGGENCODER="$VORBIZE"
2700 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2701 OGGENCODER="$OGGENC"
2704 case "$FLACENCODERSYNTAX" in
2706 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2708 # FLAC streams can be encapsulated on a Ogg transport layer
2709 if echo "$FLACENCODEROPTS" | egrep -q -- "(^| )--ogg($| )" ;then
2710 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2711 echo " due to problem with adding comments to such files" >&2
2713 FLACOUTPUTCONTAINER=ogg
2715 FLACOUTPUTCONTAINER=flac
2719 case "$SPEEXENCODERSYNTAX" in
2721 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2722 SPEEXENCODER="$SPEEXENC"
2725 case "$MPPENCODERSYNTAX" in
2727 MPPENCODEROPTS="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2728 MPPENCODER="$MPPENC"
2734 if [ "$ID3TAGV" = "1" ]; then
2736 TAGGEROPTS="$ID3OPTS"
2739 TAGGEROPTS="$ID3V2OPTS"
2743 case "$CUEREADERSYNTAX" in
2745 CUEREADEROPTS="${CDROM}"
2750 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2751 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2752 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2753 echo " due to problem with adding comments to such files" >&2
2755 OGGOUTPUTCONTAINER=ogg.ogg
2756 FLACOUTPUTCONTAINER=flac.ogg
2757 vecho "abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2760 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2762 if [ "$ENCNICE" ]; then
2763 ENCNICE="-n $ENCNICE"
2765 if [ "$READNICE" ]; then
2766 READNICE="-n $READNICE"
2768 if [ "$DISTMP3NICE" ]; then
2769 DISTMP3NICE="-n $DISTMP3NICE"
2772 # Don't check for stuff if it's not needed
2773 if [ "$REMOTEHOSTS" ]; then
2776 if [ "$DONORMALIZE" = "y" ]; then
2779 if [ "$EJECTCD" = "y" ]; then
2782 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2785 if [ "$MAKECUEFILE" = "y" ]; then
2789 if [ X"$CDSPEEDVALUE" != "X" ]; then
2790 case "$CDROMREADERSYNTAX" in
2791 cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2796 # Rippers with USEPIPE support
2797 # FIXME # Include here all the rippers we can figure out support pipes
2800 # Encoders with USEPIPE support
2801 # FIXME # Include here all the encoders we can figure out support pipes
2806 # Figure out if we can use pipes with the ripper/encoder combination
2808 if [ "$USEPIPES" = "y" ]; then
2809 PIPERIPPERSVARCHECK="PIPE_${CDROMREADER}"
2812 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
2814 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
2816 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
2818 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
2820 PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
2822 if [ ! -n "$( eval echo "\$$PIPERIPPERSVARCHECK" )" ] ; then
2823 echo "abcde error: no support for pipes with given ripper" >&2
2824 echo "read the USEPIPES file from the source tarball to help" >&2
2825 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2828 if [ ! -n "$( eval echo "\$$PIPEENCODERSVARCHECK" )" ] ; then
2829 echo "abcde error: no support for pipes with given encoder" >&2
2830 echo "read the USEPIPES file from the source tarball to help" >&2
2831 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2836 # Make sure a buncha things exist
2837 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2838 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2839 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2840 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2841 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2842 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2843 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDCUEREADER+$CUEREADER}
2845 # Cut off the command-line options we just added in
2846 X=$(echo $X | cut -d' ' -f2)
2847 if [ "$(which $X)" = "" ]; then
2848 echo "abcde error: $X is not in your path." >&2
2850 elif [ ! -x $(which $X) ]; then
2851 echo "abcde error: $X is not executable." >&2
2856 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
2857 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
2858 HTTPGET="$HTTPGET $HTTPGETOPTS"
2860 # And last but not least, check if we can diff between files
2861 if [ -x $(which $DIFF) ]; then :; else
2862 vecho "[WAR] Disabling diff since we cannot find it in the \$PATH..."
2866 # Here it used to say:
2867 # One thousand lines in, we can start doing stuff with things
2868 # Well, right now we are at line 2736 ;)
2870 # Export needed things so they can be read in this subshell
2871 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2872 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2874 # User-definable function to set some things. Use it for
2875 # - closing the CD tray with eject -t
2876 # - set the CD speed value with eject -x
2877 vecho -n "Executing customizable pre-read function... "
2879 pre_read # Execute the user-defined pre-read funtion. Close the CD with it.
2883 do_discid # Get ABCDETEMPDIR created and status file initialized
2885 if [ "$DOCDDB" = "y" ]; then
2886 if [ $CDDBUSELOCAL = "y" ]; then
2889 if checkstatus cddb-choice > /dev/null; then
2892 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2900 eval $($CDDBTOOL parse "$CDDBDATA")
2903 # Before reading tracks, we set the speed of the device
2905 if [ X"$CDSPEEDVALUE" != "X" ]; then
2906 case "$CDROMREADERSYNTAX" in
2907 cdparanoia|debug) : ;;
2912 # Define the first and last track, since we might need them later in several places
2913 FIRSTTRACK=$( get_first $TRACKQUEUE )
2914 LASTTRACK=$( get_last $TRACKQUEUE )
2916 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
2917 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2918 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2919 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2922 # Create playlist if needed (backgroundable) and start reading in tracks
2926 if [ ! "$ONETRACK" = "y" ]; then
2927 if [ "$DOPLAYLIST" = "y" ]; then
2928 echo Creating playlist... >&2
2933 # For the lowdisk option, only one program is running at once so the encoder
2934 # can be unsilenced right away.
2935 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
2936 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2939 if [ "$ONETRACK" = "y" ]; then
2940 TRACKS="$FIRSTTRACK"
2941 if checkstatus readtrack-$FIRSTTRACK; then :; else
2942 do_cdread onetrack $FIRSTTRACK $LASTTRACK
2945 for UTRACKNUM in $TRACKQUEUE