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,replaygain,playlist,clean)"
24 #echo "-A Experimental actions (retag, transcode)"
25 echo "-b Enable batch normalization"
26 #echo "-B Disable batch replaygain (do file by file)"
28 echo " Specify a configuration file (overrides system and user config files)"
30 echo " Specify discid to resume from (only needed if you no longer have the cd)"
32 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
33 echo "-D Debugging mode (equivalent to sh -x abcde)"
34 echo "-e Erase encoded track information from status file"
35 #echo "-E Set the encoding information for the tags"
36 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
37 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
38 echo "-h This help information"
39 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
40 echo "-j <#> Number of encoder processes to run at once (localhost)"
41 echo "-k Keep the wav tracks for later use"
42 echo "-l Use low disk space algorithm"
43 echo "-L Use local CDDB storage directory"
44 echo "-n No lookup. Don't query CDDB, just create and use template"
45 echo "-N Noninteractive. Never prompt for anything"
46 echo "-m Modify playlist to include CRLF endings, to comply with some players"
47 echo "-M Create a CUE file"
48 echo "-o <type1[,type2]...>"
49 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav). Defaults to vorbis"
50 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
51 echo "-P Use UNIX pipes to read+encode without wav files"
52 echo "-r <host1[,host2]...>"
53 echo " Also encode on these remote hosts"
54 #echo "-R Add replaygain values to the tag info (only for vorbis,flac,mp3)"
56 echo " Show dielfs from the CDDB info (year,genre)"
57 echo "-S <#> Set the CD speed"
58 echo "-t <#> Start the track numbering at a given number"
59 echo "-T <#> Same as -t but modifies tag numbering"
60 echo "-v Show version number and exit"
61 echo "-V Be a bit more verbose about what is happening behind the scenes"
62 echo "-x Eject CD after all tracks are read"
64 echo " Add a comment to the CD tracks"
65 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
66 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
68 echo "Tracks is a space-delimited list of tracks to grab."
69 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
71 #echo "Double hyphens are used to concatenate tracks"
76 echo "$@" >> "$ABCDETEMPDIR/status"
79 # log [level] [message]
81 # log outputs the right message in a common format
87 error) echo "[ERR] abcde: $@" >&2 ;;
88 warning) echo "[WAR] $@" >&2 ;;
89 info) echo "[INF] $@" ;;
93 # Funtions to replace the need of seq, which is too distribution dependant.
97 while [ $i -ne `expr $2 + 1` ]
107 if echo i | grep -q "[[:digit:]]" ; then
108 while [ $i -ne `expr $2 + 1` ]
115 log error "syntax error while processing track numbers"
120 # Functions to replace the need of awk {print $1} and {print $NF}
123 if [ X"$1" = "X" ]; then
124 for first in `cat`; do
135 if [ X"$1" = "X" ]; then
136 for stdin in `cat`; do
140 for last in $@ ; do :; done
145 # checkstatus [blurb]
146 # Returns "0" if the blurb was found, returns 1 if it wasn't
147 # Puts the blurb content, if available, on stdout.
148 # Otherwise, returns "".
151 # Take the last line in the status file if there's multiple matches
153 BLURB=$(egrep $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
155 if [ -z "$BLURB" ]; then
160 # See if there's a = in it
161 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
162 echo "$(echo $BLURB | cut -f2- -d=)"
168 # chechwarnings [blurb]
169 # Returns "0" if the blurb was found (meaning there was an warning),
170 # returns 1 if it wasn't (yes this is a little backwards).
171 # Does not print the blurb on stdout.
172 # Otherwise, returns "".
175 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
178 # Take the last line in the status file if there's multiple matches
180 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
182 if [ -z "$BLURB" ]; then
183 # negative, we did not have a negative...
186 # affirmative, we had a negative...
191 # checkerrors [blurb]
192 # Returns "0" if the blurb was found (meaning there was an error),
193 # returns 1 if it wasn't (yes this is a little backwards).
194 # Does not print the blurb on stdout.
195 # Otherwise, returns "".
198 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
201 # Take the last line in the status file if there's multiple matches
203 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
205 if [ -z "$BLURB" ]; then
206 # negative, we did not have a negative...
209 # affirmative, we had a negative...
215 # Finds the right pager in the system to display a file
219 # Use the debian sensible-pager wrapper to pick the pager
220 # user has requested via their $PAGER environment variable
221 if [ -x "/usr/bin/sensible-pager" ]; then
222 /usr/bin/sensible-pager "$PAGEFILE"
223 elif [ -x "$PAGER" ]; then
224 # That failed, try to load the preferred editor, starting
225 # with their PAGER variable
227 # If that fails, check for less
228 elif [ -x /usr/bin/less ]; then
229 /usr/bin/less -f "$PAGEFILE"
230 # more should be on all UNIX systems
231 elif [ -x /bin/more ]; then
232 /bin/more "$PAGEFILE"
234 # No bananas, just cat the thing
239 # run_command [blurb] [command...]
240 # Runs a command, silently if necessary, and updates the status file
245 # See if this is supposed to be silent
246 if [ "$(checkstatus encode-output)" = "loud" ]; then
250 # Special case for SMP, since
251 # encoder output is never displayed, don't mute echos
252 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
261 normalize|normalize-audio)
262 if [ "$RETURN" = "2" ]; then
263 # File was already normalized.
268 if [ "$RETURN" != "0" ]; then
269 # Put an error in the errors file. For various reasons we
270 # can't capture a copy of the program's output but we can
271 # log what we attempted to execute and the error code
272 # returned by the program.
273 if [ "$BLURB" ]; then
276 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
277 return $RETURN # Do not pass go, do not update the status file
279 if [ "$BLURB" ]; then
280 echo $BLURB >> "$ABCDETEMPDIR/status"
284 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
285 # distributed under the terms of the GNU GPL v2 or later, at your option
287 # Function to determine if a word contains a slash.
296 # Function to give the relative path from one file to another.
297 # Usage: relpath fromfile tofile
298 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
299 # (the result would be Album/Song.mp3)
300 # Output is relative path to $2 from $1 on stdout
302 # This code has the following restrictions:
303 # Multiple ////s are not collapsed into single /s, with strange effects.
304 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
305 # If FR is a directory it must have a trailing /
313 /*) ;; # No processing is needed for absolute paths
315 # Loop through common prefixes, ignoring them.
316 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
318 FR="$(echo "$FR" | cut -d/ -f2-)"
319 TO="$(echo "$TO" | cut -d/ -f2-)"
321 # Loop through directory portions left in FR, adding appropriate ../s.
324 FR="$(echo "$FR" | cut -d/ -f2-)"
334 # Finds an specific field from cddbinfo
336 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
337 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
338 # TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
344 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
347 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
353 # Get the track number we are going to use for different actions
356 if [ -n "$STARTTRACKNUMBER" ] ; then
357 # Get the trackpadding from the current track
358 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
359 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
361 TRACKNUM=${UTRACKNUM}
367 if checkstatus replaygain; then :; else
368 run_command "" echo "Adding replygain information..."
369 for OUTPUT in $( echo $OUTPUTTYPE | tr , \ )
373 OUTPUT=$OGGOUTPUTCONTAINER
376 OUTPUT=$FLACOUTPUTCONTAINER
380 for UTRACKNUM in $TRACKQUEUE
382 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
383 do_getcddbinfo TRACKNAME
385 TRACKFILE="$(mungefilename "$TRACKNAME")"
386 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
387 ALBUMFILE="$(mungefilename "$DALBUM")"
389 if [ "$VARIOUSARTISTS" = "y" ]; then
390 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
392 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
394 OUTPUTFILES="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT $OUTPUTFILES"
398 run_command replaygain-flac $METAFLAC --add-replay-gain $OUTPUTFILES
401 run_command replaygain-vorbis $VORBISGAIN --album $OUTPUTFILES
404 run_command replaygain-mp3 $MP3GAIN -a $OUTPUTFILES
409 if checkerrors "replaygain-.{3,6}"; then :; else
410 run_command replaygain true
415 # This code splits the a Various Artist track name from one of the following
418 # forward: Artist / Track
419 # forward-dash: Artist - Track
420 # reverse: Track / Artist
421 # reverse-dash: Track - Artist
422 # colon: Artist: Track
423 # trailing-paren: Artist (Track)
426 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
429 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
430 case "$VARIOUSARTISTSTYLE" in
432 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
433 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
434 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
437 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
438 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
439 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
442 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
443 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
444 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
447 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
448 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
449 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
452 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
453 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
454 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
457 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
458 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
459 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
462 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
463 TRACKARTIST="Various"
465 TRACKARTIST="$DARTIST"
470 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
474 "classic rock") id=1 ;;
492 "industrial") id=19 ;;
493 "alternative") id=20 ;;
495 "death metal") id=22 ;;
497 "soundtrack") id=24 ;;
498 "euro-techno") id=25 ;;
502 "jazz+funk") id=29 ;;
505 "classical") id=32 ;;
506 "instrumental") id=33 ;;
510 "sound clip") id=37 ;;
513 "alt. rock") id=40 ;;
518 "meditative") id=45 ;;
519 "instrum. pop") id=46 ;;
520 "instrum. rock") id=47 ;;
524 "techno-indust.") id=51 ;;
525 "electronic") id=52 ;;
527 "eurodance") id=54 ;;
529 "southern rock") id=56 ;;
534 "christian rap") id=61 ;;
535 "pop/funk"|"pop / funk") id=62 ;;
537 "native american") id=64 ;;
540 "psychadelic") id=67 ;;
542 "showtunes") id=69 ;;
546 "acid punk") id=73 ;;
547 "acid jazz") id=74 ;;
551 "rock & roll") id=78 ;;
552 "hard rock") id=79 ;;
554 "folk/rock") id=81 ;;
555 "national folk") id=82 ;;
562 "bluegrass") id=89 ;;
563 "avantgarde") id=90 ;;
564 "gothic rock") id=91 ;;
565 "progress. rock") id=92 ;;
566 "psychadel. rock") id=93 ;;
567 "symphonic rock") id=94 ;;
568 "slow rock") id=95 ;;
571 "easy listening") id=98 ;;
577 "chamber music") id=104 ;;
579 "symphony") id=106 ;;
580 "booty bass") id=107 ;;
582 "porn groove") id=109 ;;
584 "slow jam") id=111 ;;
588 "folklore") id=115 ;;
590 "power ballad") id=117 ;;
591 "rhythmic soul") id=118 ;;
592 "freestyle") id=119 ;;
594 "punk rock") id=121 ;;
595 "drum solo") id=122 ;;
596 "a capella") id=123 ;;
597 "euro-house") id=124 ;;
598 "dance hall") id=125 ;;
600 "drum & bass") id=127 ;;
601 "club-house") id=128 ;;
602 "hardcore") id=129 ;;
606 "negerpunk") id=133 ;;
607 "polsk punk") id=134 ;;
609 "christian gangsta rap") id=136 ;;
610 "heavy metal") id=137 ;;
611 "black metal") id=138 ;;
612 "crossover") id=139 ;;
613 "contemporary christian")id=140 ;;
614 "christian rock") id=141 ;;
615 "merengue") id=142 ;;
617 "thrash metal") id=144 ;;
620 "synthpop") id=147 ;;
621 "rock/pop"|"rock / pop") id=148 ;;
628 # do_tag [tracknumber]
629 # id3 tags a filename
631 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
632 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
635 COMMENTOUTPUT="$(eval echo ${COMMENT})"
636 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
637 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
638 # If we want to start the tracks with a given number, we need to modify the
639 # TRACKNUM value before evaluation
640 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
643 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
647 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
648 GENREID=$(do_getgenreid "${CDGENRE}")
653 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
654 run_command tagtrack-$OUTPUT-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
655 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
656 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
657 "${ENCODING:+--set-encoding=$ENCODING}"
658 "$ABCDETEMPDIR/track$1.$OUTPUT"
661 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
662 run_command tagtrack-$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
663 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
664 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
665 "$ABCDETEMPDIR/track$1.$OUTPUT"
670 case "$OGGENCODERSYNTAX" in
672 # vorbiscomment can't do in-place modification, mv the file first
673 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
674 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
677 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
678 echo ARTIST="$TRACKARTIST"
680 echo TITLE="$TRACKNAME"
681 if [ -n "$CDYEAR" ]; then
684 if [ -n "$CDGENRE" ]; then
685 echo GENRE="$CDGENRE"
687 echo TRACKNUMBER=${TRACKNUM:-$1}
688 echo CDDB=$CDDBDISCID
689 if [ "$(eval echo ${COMMENT})" != "" ]; then
690 case "$COMMENTOUTPUT" in
691 *=*) echo "$COMMENTOUTPUT";;
692 *) echo COMMENT="$COMMENTOUTPUT";;
695 ) | run_command tagtrack-$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
696 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
697 # Doublecheck that the commented file was created successfully before wiping the original
698 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
699 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
701 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
708 echo ARTIST="$TRACKARTIST"
710 echo TITLE="$TRACKNAME"
711 if [ -n "$CDYEAR" ]; then
714 if [ -n "$CDGENRE" ]; then
715 echo GENRE="$CDGENRE"
717 echo TRACKNUMBER="${TRACKNUM:-$1}"
718 echo CDDB="$CDDBDISCID"
719 if [ "$(eval echo ${COMMENT})" != "" ]; then
720 case "$COMMENTOUTPUT" in
721 *=*) echo "$COMMENTOUTPUT";;
722 *) echo COMMENT="$COMMENTOUTPUT";;
725 ) | run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
728 run_command tagtrack-$OUTPUT-$1 true
731 run_command tagtrack-$OUTPUT-$1 true
734 run_command tagtrack-$OUTPUT-$1 true
738 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
739 run_command tagtrack-$1 true
746 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
749 # The commands here don't go through run_command because they're never supposed to be silenced
750 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
751 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
755 case "$MP3ENCODERSYNTAX" in
760 for UTRACKNUM in $TRACKQUEUE
762 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
764 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
766 if [ "$RETURN" != "0" ]; then
767 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
769 for UTRACKNUM in $TRACKQUEUE
771 run_command encodetrack-$OUTPUT-$UTRACKNUM true
772 #run_command encodetrack-$UTRACKNUM true
781 if checkerrors "nogap-encode"; then :; else
782 if [ ! "$KEEPWAVS" = "y" ] ; then
783 if [ ! "$KEEPWAVS" = "move" ] ; then
788 # Other encoders fall through to normal encoding as the tracks
789 # have not been entered in the status file.
792 # do_encode [tracknumber] [hostname]
793 # If no hostname is specified, encode locally
795 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
798 if [ "$USEPIPES" = "y" ]; then
801 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
804 TEMPARG="PIPE_$OGGENCODERSYNTAX"
807 TEMPARG="PIPE_$FLACENCODERSYNTAX"
810 TEMPARG="PIPE_$SPEEXENCODER"
813 TEMPARG="PIPE_$MPPENCODER"
816 IN="$( eval echo "\$$TEMPARG" )"
818 IN="$ABCDETEMPDIR/track$1.wav"
821 case "$MP3ENCODERSYNTAX" in
822 # FIXME # check if mp3enc needs -if for pipes
823 # FIXME # I have not been able to find a working mp3enc binary
837 # We need IN to proceed, if we are not using pipes.
838 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
839 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
841 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
846 OUT="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
849 OUT="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
852 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
855 if [ X"$USEPIPES" = "Xy" ]; then
857 # We need a way to store the creation of the files when using PIPES
858 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
860 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
861 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
867 case "$MP3ENCODERSYNTAX" in
868 lame|gogo) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
869 bladeenc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
870 l3enc|xingmp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
871 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
872 mp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
876 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
883 case "$OGGENCODERSYNTAX" in
884 vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
885 oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
889 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
896 case "$FLACENCODERSYNTAX" in
897 flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
902 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
903 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
908 if [ "$(eval echo ${COMMENT})" != "" ]; then
911 *) COMMENT="COMMENT=$COMMENT" ;;
913 COMMENT="--comment \"$COMMENT\""
915 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
916 if [ ! "$DOTAG" = "y" ]; then
917 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
919 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
923 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
925 # I tried compiling the mppenc from corecodecs.org and got some
926 # errors, so I have not tried it myself.
927 ## FIXME ## Needs some cleanup to determine if an empty tag sent
928 ## FIXME ## to the encoder ends up empty.
929 $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
932 # In case of wav output we need nothing. Just keep the wavs.
937 # Only remove .wav if the encoding succeeded
938 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
939 run_command encodetrack-$1 true
940 if [ ! "$KEEPWAVS" = "y" ] ; then
941 if [ ! "$KEEPWAVS" = "move" ] ; then
947 run_command "" echo "HEH! The file we were about to encode disappeared:"
948 run_command "" echo ">> $IN"
949 run_command encodetrack-$1 false
953 # do_preprocess [tracknumber]
955 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
958 # IN="$ABCDETEMPDIR/track$1.wav"
959 # # We need IN to proceed.
960 # if [ -s "$IN" ] ; then
961 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
963 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
964 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
965 # case "$POSTPROCESSFORMAT" in
967 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
969 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
971 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
973 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
975 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
978 # # Only remove .wav if the encoding succeeded
979 # if checkerrors "preprocess-(.{3,4})-$1"; then
980 # run_command preprocess-$1 false
982 # run_command preprocess-$1 true
985 # if [ "$(checkstatus encode-output)" = "loud" ]; then
986 # echo "HEH! The file we were about to pre-process disappeared:"
989 # run_command preprocess-$1 false
994 # do_postprocess [tracknumber]
996 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
999 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1001 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1002 # # We need IN to proceed.
1003 # if [ -s "$IN" ] ; then
1004 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1005 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1006 # case "$POSTPROCESSFORMAT" in
1008 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1010 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1012 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1014 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1016 # # Only remove .wav if the encoding succeeded
1017 # if checkerrors "postprocess-(.{3,4})-$1"; then
1018 # run_command postprocess-$1 false
1020 # run_command postprocess-$1 true
1023 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1024 # echo "HEH! The file we were about to post-process disappeared:"
1027 # run_command postprocess-$1 false
1042 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
1046 # The commands here don't go through run_command because they're never supposed to be silenced
1047 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1052 for UTRACKNUM in $TRACKQUEUE
1054 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1056 # FIXME # Hard-coded batch option!
1057 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1059 if [ "$RETURN" != "0" ]; then
1060 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1062 for UTRACKNUM in $TRACKQUEUE
1064 echo normalizetrack-$UTRACKNUM >> status
1070 # do_batch_normalize
1072 # NORMALIZER, NORMALIZEROPTS
1073 do_batch_normalize ()
1075 # The commands here don't go through run_command because they're never supposed to be silenced
1076 echo "Batch normalizing tracks: $TRACKQUEUE"
1081 for UTRACKNUM in $TRACKQUEUE
1083 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1085 # XXX: Hard-coded batch option!
1086 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1088 if [ "$RETURN" != "0" ]; then
1089 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1091 for UTRACKNUM in $TRACKQUEUE
1093 echo normalizetrack-$UTRACKNUM >> status
1099 # do_normalize [tracknumber]
1101 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1104 IN="$ABCDETEMPDIR/track$1.wav"
1105 if [ -e "$IN" ] ; then
1106 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1107 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1109 if [ "$(checkstatus encode-output)" = "loud" ]; then
1110 echo "HEH! The file we were about to normalize disappeared:"
1113 run_command normalizetrack-$1 false "File $IN was not found"
1117 # do_move [tracknumber]
1118 # Deduces the outfile from environment variables
1119 # Creates directory if necessary
1121 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1124 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1126 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1127 # Munge filenames as follows:
1132 # Eat control characters
1133 ALBUMFILE="$(mungefilename "$DALBUM")"
1134 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1135 TRACKFILE="$(mungefilename "$TRACKNAME")"
1136 GENRE="$(mungegenre "$GENRE")"
1137 YEAR="$(echo $CDYEAR)"
1138 # If we want to start the tracks with a given number, we need to modify the
1139 # TRACKNUM value before evaluation
1141 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1142 # TRACKFILE, and TRACKNUM.
1143 if [ "$VARIOUSARTISTS" = "y" ]; then
1144 OUTPUTFILE="$(eval echo "$VAOUTPUTFORMAT")"
1146 OUTPUTFILE="$(eval echo "$OUTPUTFORMAT")"
1148 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1149 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1152 OUTPUT=$OGGOUTPUTCONTAINER
1155 OUTPUT=$FLACOUTPUTCONTAINER
1158 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1159 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1162 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1163 # FIXME # introduce warnings?
1166 # mkdir -p shouldn't return an error if the directory already exists
1167 mkdir -p "$OUTPUTFILEDIR"
1168 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1169 if checkstatus movetrack-output-$OUTPUT; then :; else
1170 run_command movetrack-output-$OUTPUT true
1175 # mkdir -p shouldn't return an error if the directory already exists
1176 mkdir -p "$OUTPUTFILEDIR"
1177 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1178 if checkstatus movetrack-output-$OUTPUT; then :; else
1179 run_command movetrack-output-$OUTPUT true
1183 # Lets move the cue file
1184 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1185 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1186 if checkstatus movecue-$OUTPUT; then :; else
1187 # Silence the Copying output since it overlaps with encoding processes...
1188 #run_command '' vecho "Copying cue file to its destination directory..."
1189 if checkstatus onetrack >/dev/null ; then
1192 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1193 # We dont have the dir, since it was not created before.
1196 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1199 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1200 # http://brianvictor.tripod.com/mp3cue.htm#details
1201 [a-z0-9][a-z0-9][a-z0-9])
1202 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1205 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1209 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1211 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1220 # Create the playlist if wanted
1222 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1223 # VARIOUSARTISTS, OUTPUTDIR
1226 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1230 OUTPUT=$OGGOUTPUTCONTAINER
1233 OUTPUT=$FLACOUTPUTCONTAINER
1236 # Create a playlist file for the playlist data to go into.
1237 # We used to wipe it out if it existed. Now we request permision if interactive.
1238 for LASTTRACK in $TRACKQUEUE; do :; done
1239 ALBUMFILE="$(mungefilename "$DALBUM")"
1240 ARTISTFILE="$(mungefilename "$DARTIST")"
1241 GENRE=$(mungegenre "$GENRE")
1242 YEAR=${CDYEAR:-$CDYEAR}
1243 if [ "$VARIOUSARTISTS" = "y" ] ; then
1244 PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
1246 PLAYLISTFILE=$(eval echo $PLAYLISTFORMAT)
1248 FINALPLAYLISTDIR=$(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1249 mkdir -p "$FINALPLAYLISTDIR"
1250 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1251 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1252 if [ "$INTERACTIVE" = "y" ]; then
1253 while [ "$DONE" != "y" ]; do
1255 case $ERASEPLAYLIST in
1256 e|E|a|A|k|K) DONE=y ;;
1264 # Once we erase the playlist, we use append to create the new one.
1265 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1267 # The playlist does not exist, so we can safelly use append to create the new list
1270 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1271 touch "$OUTPUTDIR/$PLAYLISTFILE"
1272 for UTRACKNUM in $TRACKQUEUE
1274 # Shares some code with do_move since the filenames have to match
1275 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1276 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1277 do_getcddbinfo TRACKNAME
1279 TRACKFILE="$(mungefilename "$TRACKNAME")"
1280 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1281 ALBUMFILE="$(mungefilename "$DALBUM")"
1282 # If we want to start the tracks with a given number, we need to modify the
1283 # TRACKNUM value before evaluation
1285 if [ "$VARIOUSARTISTS" = "y" ]; then
1286 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
1288 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
1290 if [ "$VARIOUSARTISTS" = "y" ]; then
1291 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1292 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1294 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1297 if [ "$PLAYLISTDATAPREFIX" ]; then
1298 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1300 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1305 ## this will convert the playlist to have CRLF line-endings, if specified
1306 ## (some hardware players insist on CRLF endings)
1307 if [ "$DOSPLAYLIST" = "y" ]; then
1308 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1309 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1310 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1312 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1317 # This essentially the start of things
1320 # Query the CD to get the track info, unless the user specified -C
1321 # or we are using some actions which do not need the CDDB data at all
1322 #if [ ! X"$EXPACTIONS" = "X" ]; then
1324 #elif [ -z "$DISCID" ]; then
1325 if [ -z "$DISCID" ]; then
1326 vecho -n "Getting CD track info... "
1327 # In OSX, unmount the disc before a query
1328 if [ "$OSFLAVOUR" = "OSX" ]; then
1329 disktool -u ${CDROM#/dev/}
1331 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1332 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM | $CUE2DISCID)
1334 TRACKINFO=$($CDDISCID $CDROM)
1336 # Make sure there's a CD in there by checking cd-discid's return code
1337 if [ ! "$?" = "0" ]; then
1338 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1339 log error "cuesheet information from the flac file could not be read."
1340 log error "Perhaps the flac file does not contain a cuesheet?."
1343 log error "CD could not be read. Perhaps there's no CD in the drive?"
1347 # In OSX, remount the disc again
1348 if [ "$OSFLAVOUR" = "OSX" ]; then
1349 disktool -m ${CDROM#/dev/}
1353 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1356 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1357 # This needs to be done now because a section of the resuming code will need
1360 # get the number of digits to pad TRACKNUM with - we'll use this later
1361 # a CD can only hold 99 tracks, but since we support a feature for starting
1362 # numbering the tracks from a given number, we might need to set it as a
1363 # variable for the user to define... or obtain it somehow.
1364 if [ "$PADTRACKS" = "y" ] ; then
1368 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1369 if [ -z "$TRACKQUEUE" ]; then
1370 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1371 case "$CDROMREADERSYNTAX" in
1373 if [ "$WEHAVEACD" = "y" ]; then
1374 vecho "Querying the CD for audio tracks..."
1375 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1377 if [ ! "$RET" = "0" ];then
1378 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1380 TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1381 CDPARANOIAAUDIOTRACKS="$TRACKS"
1383 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1384 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1388 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1391 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1393 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1394 log info "The disc does not contain any tracks. Giving up..."
1397 echo -n "Grabbing entire CD - tracks: "
1398 if [ ! "$PADTRACKS" = "y" ] ; then
1399 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1401 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1403 while [ "$X" -ne "$TRACKS" ]
1405 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1406 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1410 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1411 # User-supplied track queue.
1412 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1413 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1414 # Once cleaned, obtain the highest value in the trackqueue for number padding
1415 for LASTTRACK in $TRACKQUEUE; do :; done
1416 if [ ! "$PADTRACKS" = "y" ] ; then
1417 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1419 # Now we normalize the trackqueue
1420 for TRACK in $TRACKQUEUE ; do
1421 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1422 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1424 TRACKQUEUE=$PADTRACKQUEUE
1425 echo Grabbing tracks: "$TRACKQUEUE"
1428 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1430 # We have the discid, create a temp directory after it to store all the temp
1433 if [ -e "$ABCDETEMPDIR" ]; then
1434 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1435 # It already exists, see if it's a directory
1436 if [ ! -d "$ABCDETEMPDIR" ]; then
1437 # This is a file/socket/fifo/device/etc, not a directory
1440 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1441 echo "Please investigate, remove it, and rerun abcde." >&2
1445 # It's a directory, let's see if it's owned by us
1446 if [ ! -O "$ABCDETEMPDIR" ]; then
1447 # Nope, complain and exit
1449 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1450 echo "Please investigate, remove it, and rerun abcde." >&2
1454 # See if it's populated
1455 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1456 # Wipe and start fresh
1457 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1458 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1459 if [ "$INTERACTIVE" = "y" ]; then
1465 if [ "$ANSWER" != "y" ]; then
1468 rm -rf "$ABCDETEMPDIR" || exit 1
1469 mkdir "$ABCDETEMPDIR"
1470 if [ "$?" -gt "0" ]; then
1471 # Directory already exists or could not be created
1472 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1476 # Everything is fine. Check for ^encodetracklocation-
1477 # and encode-output entries in the status file and
1478 # remove them. These are not relevant across sessions.
1479 if [ -f "$ABCDETEMPDIR/status" ]; then
1480 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1481 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1482 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1484 # Remove old error messages
1485 if [ -f "$ABCDETEMPDIR/errors" ]; then
1486 rm -f "$ABCDETEMPDIR/errors"
1490 # We are starting from scratch
1491 mkdir "$ABCDETEMPDIR"
1492 if [ "$?" -gt "0" ]; then
1493 # Directory already exists or could not be created
1494 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1497 cat /dev/null > "$ABCDETEMPDIR/status"
1499 if [ X"$MAKECUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1500 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1501 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1502 vecho "Creating cue file..."
1503 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1504 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1506 log warning "reading the CUE sheet with mkcue is still considered experimental"
1507 log warning "and there was a problem with the CD reading. abcde will continue,"
1508 log warning "but consider reporting the problem to the abcde author"
1512 # If we got the CDPARANOIA status and it is not recorded, save it now
1513 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1514 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
1515 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1519 # Create the discid file
1520 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1524 # Create a proper CUE file based on the CUE file we created before.
1527 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1528 CUEFILE_OUT=$CUEFILE_IN.out
1529 ### FIXME ### checkstatus cddb
1530 if [ -e "$CDDBDATA" ]; then
1531 vecho "Adding metadata to the cue file..."
1532 # FIXME It doesn't preserve spaces! Why?
1533 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1535 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1536 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1537 cat "$CUEFILE_IN" | while read line
1539 if echo "$line" | grep -q "INDEX"
1541 eval track="\$TRACK$n"
1543 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1545 echo "$line" >> "$CUEFILE_OUT"
1547 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1548 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1554 # Parses a CDDB file and outputs the title and the track names.
1555 # Variables: CDDBFILE
1559 # List out disc title/author and contents
1560 if [ "$ONETRACK" = "y" ]; then
1561 vecho "ONETRACK mode selected: displaying only the title of the CD..."
1563 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1564 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
1565 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1566 if [ ! X"$PARSEDYEAR" = "X" ]; then
1567 echo "Year: $PARSEDYEAR"
1570 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
1571 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1572 if [ ! X"$PARSEDGENRE" = "X" ]; then
1573 echo "Genre: $PARSEDGENRE"
1576 if [ ! "$ONETRACK" = "y" ]; then
1577 for TRACK in $(f_seq_row 1 $TRACKS)
1579 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1585 # Check for a local CDDB file, and report success
1588 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
1590 CDDBLOCALSUCCESS="n"
1591 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1592 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1595 # If the user has selected to check a local CDDB repo, we proceed with it
1596 if [ -r "${CDDBLOCALFILE}" ]; then
1597 # List out disc title/author and contents
1598 do_cddbparse "${CDDBLOCALFILE}"
1599 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1600 if [ "$INTERACTIVE" = "y" ]; then
1602 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1603 echo -n 'Invalid selection. Please answer "y" or "n": '
1606 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
1610 if [ "$USELOCALRESP" = "y" ]; then
1611 #echo "Using local copy of CDDB data"
1612 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1613 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
1614 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1615 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
1616 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1617 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1618 CDDBLOCALSUCCESS="y"
1620 #echo "Not using local copy of CDDB data"
1621 CDDBLOCALSUCCESS="n"
1624 CDDBLOCALSUCCESS="n"
1632 # Perform CDDB protocol version check if it hasn't already been done
1633 if checkstatus cddb-statcomplete; then :; else
1634 if [ "$CDDBAVAIL" = "n" ]; then
1636 echo 503 > "$ABCDETEMPDIR/cddbstat"
1639 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1640 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1641 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1642 vecho "Checking CDDB server status..."
1643 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1644 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
1645 case "$RESPONSECODE" in
1646 210) # 210 OK, status information follows (until terminating `.')
1649 501|*) # 501 Illegal CDDB protocol level: <n>.
1650 CDDBPROTO=`expr $CDDBPROTO - 1`
1654 if test $rc -eq 1; then
1658 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
1666 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1667 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1669 # Perform CDDB query if it hasn't already been done
1670 if checkstatus cddb-querycomplete; then :; else
1671 if [ "$CDDBAVAIL" = "n" ]; then
1673 echo 503 > "$ABCDETEMPDIR/cddbquery"
1674 # The default CDDBLOCALSUCCESS is "n"
1675 # This part will be triggered if the user CDDB repo does not
1676 # contain the entry, or if we are not trying to use the repo.
1678 vecho "Querying the CDDB server..."
1679 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1680 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1681 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1687 # no match found in database,
1688 # wget/fetch error, or user requested not to use CDDB
1689 # Make up an error code (503) that abcde
1690 # will recognize in do_cddbread
1691 # and compensate by making a template
1692 echo 503 > "$ABCDETEMPDIR/cddbquery"
1694 *) # strange and unknown error
1695 echo ERRORCODE=$ERRORCODE
1696 echo "abcde: $CDDBTOOL returned unknown error code"
1700 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
1707 # If it's not to be used, generate a template.
1708 # Then, display it (or them) and let the user choose/edit it
1709 if checkstatus cddb-readcomplete; then :; else
1710 vecho "Obtaining CDDB results..."
1711 # If CDDB is to be used, interpret the query results and read all
1712 # the available entries.
1713 rm -f "$ABCDETEMPDIR/cddbchoices"
1714 CDDBCHOICES=1 # Overridden by multiple matches
1715 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
1716 case "$RESPONSECODE" in
1718 # One exact match, retrieve it
1719 # 200 [section] [discid] [artist] / [title]
1720 if checkstatus cddb-read-1-complete; then :; else
1721 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1722 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1723 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1724 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1725 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1727 # List out disc title/author and contents
1728 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1729 for TRACK in $(f_seq_row 1 $TRACKS)
1731 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1733 echo >> "$ABCDETEMPDIR/cddbchoices"
1737 case "$RESPONSECODE" in
1738 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1739 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1740 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1742 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1743 # List out disc title/author and contents of template
1744 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
1746 for TRACK in $(f_seq_row 1 $TRACKS)
1748 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1750 echo >> "$ABCDETEMPDIR/cddbchoices"
1751 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
1752 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
1755 # Multiple exact, (possibly multiple) inexact matches
1757 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
1758 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
1759 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1760 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1761 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1763 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1765 vecho -n "Retrieving multiple matches... "
1766 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
1767 read DISCINFO # eat top line
1771 if checkstatus cddb-read-$X-complete; then :; else
1772 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1773 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
1775 # List out disc title/author and contents
1776 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1777 for TRACK in $(f_seq_row 1 $TRACKS)
1779 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1781 echo >> "$ABCDETEMPDIR/cddbchoices"
1784 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1788 for TRACK in $(f_seq_row 1 $TRACKS)
1790 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1792 echo >> "$ABCDETEMPDIR/cddbchoices"
1793 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1794 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1797 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1804 if checkstatus cddb-edit >/dev/null; then
1805 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1806 VARIOUSARTISTS="$(checkstatus variousartists)"
1807 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
1810 if [ "$INTERACTIVE" = "y" ]; then
1811 # We should show the CDDB results both when we are not using the local CDDB repo
1812 # or when we are using it but we could not find a proper match
1813 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1814 # Display the $ABCDETEMPDIR/cddbchoices file created above
1815 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1816 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1817 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1818 CHOICE=$(checkstatus cddb-choice)
1819 if [ -n "$CHOICE" ] ; then
1820 case $CDDBCHOICES in
1821 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1823 echo "Selected: #$CHOICE"
1824 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1828 # The user has a choice to make, display the info in a pager if necessary
1829 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
1830 page "$ABCDETEMPDIR/cddbchoices"
1832 # It's all going to fit in one page, cat it
1833 cat "$ABCDETEMPDIR/cddbchoices" >&2
1837 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1839 # I'll take CDDB read #3 for $400, Alex
1840 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1841 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1843 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
1844 if echo $CDDBCHOICE | egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1845 if [ ! X"$DIFF" = "X" ]; then
1846 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1)
1847 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2)
1848 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1849 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1850 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1851 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1854 # We parse the 2 choices to diff, store them in temporary files and diff them.
1855 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
1856 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1858 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1859 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1860 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
1861 page "$ABCDETEMPDIR/cddbread.diff"
1863 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1867 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1870 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1871 # Make sure we get a valid choice
1872 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
1873 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1877 if [ "$CDCHOICENUM" = "0" ]; then
1878 vecho "Creating empty CDDB template..."
1880 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1882 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1883 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1885 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1889 # We need some code to show the selected option when local repository is selected and we have found a match
1890 vecho "Using cached CDDB match..." >&2
1891 # Display the $ABCDETEMPDIR/cddbchoices file created above
1892 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1893 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1894 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1895 CHOICE=$(checkstatus cddb-choice)
1896 if [ "$USELOCALRESP" = "y" ]; then :; else
1897 if [ -n "$CHOICE" ] ; then
1898 case $CDDBCHOICES in
1901 echo "Selected template."
1903 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1905 echo "Selected: #$CHOICE"
1906 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1914 # We're noninteractive - pick the first choice.
1915 # But in case we run a previous instance and selected a choice, use it.
1916 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1917 # Show the choice if we are not using the locally stored one
1918 # or when the local search failed to find a match.
1919 PREVIOUSCHOICE=$(checkstatus cddb-choice)
1920 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1921 #if [ "$PREVIOUSCHOICE" ]; then
1922 cat "$ABCDETEMPDIR/cddbchoices"
1925 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1926 CDCHOICENUM=$PREVIOUSCHOICE
1929 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1931 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1936 if checkstatus cddb-choice >/dev/null; then :; else
1937 echo "abcde: internal error: cddb-choice not recorded." >&2
1940 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1941 echo -n "Edit selected CDDB data? [y/n] (" >&2
1942 if [ "$INTERACTIVE" = "y" ]; then
1943 if [ "$UNKNOWNDISK" = "y" ]; then
1946 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
1955 if [ "$EDITCDDB" = "y" ]; then
1956 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
1958 # Use the debian sensible-editor wrapper to pick the editor that the
1959 # user has requested via their $EDITOR environment variable
1960 if [ -x "/usr/bin/sensible-editor" ]; then
1961 /usr/bin/sensible-editor "$CDDBDATA"
1962 elif [ -n "$EDITOR" ]; then
1963 if [ -x $(which "${EDITOR%%\ *}") ]; then
1964 # That failed, try to load the preferred editor, starting
1965 # with their EDITOR variable
1966 eval $(echo "$EDITOR") \"$CDDBDATA\"
1968 # If that fails, check for a vi
1969 elif which vi >/dev/null 2>&1; then
1971 elif [ -x /usr/bin/vim ]; then
1972 /usr/bin/vim "$CDDBDATA"
1973 elif [ -x /usr/bin/vi ]; then
1974 /usr/bin/vi "$CDDBDATA"
1975 elif [ -x /bin/vi ]; then
1977 # nano should be on all (modern, i.e., sarge) debian systems
1978 elif which nano >/dev/null 2>&1 ; then
1980 elif [ -x /usr/bin/nano ]; then
1981 /usr/bin/nano "$CDDBDATA"
1982 # mg should be on all OpenBSD systems
1983 elif which mg >/dev/null 2>&1 ; then
1985 elif [ -x /usr/bin/mg ]; then
1986 /usr/bin/mg "$CDDBDATA"
1989 log warning "no editor available. Check your EDITOR environment variable."
1991 # delete editor backup file if it exists
1992 if [ -w "$CDDBDATA~" ]; then
1997 # Some heuristics first. Look at Disc Title, and if it starts with
1998 # "Various", then we'll assume Various Artists
1999 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2000 echo "Looks like a Multi-Artist CD" >&2
2003 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2004 if [ "$INTERACTIVE" = "y" ]; then
2011 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2014 # Need NUMTRACKS before cddb-tool will return it:
2015 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2016 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2017 # More than 1/2 tracks contain a "/", so guess forward
2019 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2020 # More than 1/2 contain a "-", so guess forward-dash
2022 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2023 # More than 1/2 contain something in parens, so guess trailing-paren
2027 echo "1) Artist / Title" >&2
2028 echo "2) Artist - Title" >&2
2029 echo "3) Title / Artist" >&2
2030 echo "4) Title - Artist" >&2
2031 echo "5) Artist: Title" >&2
2032 echo "6) Title (Artist)" >&2
2033 echo "7) This is a single-artist CD" >&2
2034 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2035 if [ "$INTERACTIVE" = "y" ]; then
2036 read VARIOUSARTISTSTYLE
2038 echo $DEFAULTSTYLE >&2
2039 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2041 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2042 # If they press Enter, then the default style (0) was chosen
2043 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2044 echo "Invalid selection. Please choose a number between 1 and 7."
2045 echo -n "Selection [1-7]: "
2046 read VARIOUSARTISTSTYLE
2047 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2049 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2050 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2052 vecho "Selected: $VARIOUSARTISTSTYLE"
2053 case "$VARIOUSARTISTSTYLE" in
2055 VARIOUSARTISTSTYLE=forward
2058 VARIOUSARTISTSTYLE=forward-dash
2061 VARIOUSARTISTSTYLE=reverse
2064 VARIOUSARTISTSTYLE=reverse-dash
2067 VARIOUSARTISTSTYLE=colon
2070 VARIOUSARTISTSTYLE=trailing-paren
2078 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2079 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2081 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2082 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2083 # This works but does not have the necessary error checking
2084 # yet. If you are familiar with the CDDB spec
2085 # (see http://www.freedb.org/src/latest/DBFORMAT)
2086 # and can create an error-free entry on your own, then put
2087 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2088 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2089 # your abcde.conf to change the email address submissions are
2092 # submit the modified file, if they want
2093 if [ "$NOSUBMIT" != "y" ]; then
2094 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2096 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2097 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2099 echo -n 'Invalid selection. Please answer "y" or "n": '
2102 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2103 echo -n "Sending..."
2104 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2110 # Make sure the cache directory exists
2111 mkdir -p $CDDBLOCALDIR
2112 # Cache edited CDDB entry in the user's cddb dir
2113 if [ "$CDDBCOPYLOCAL" = "y" ] || [ "$COPYCDDBLOCAL" = "Y" ]; then
2114 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2117 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2120 # do_cdread [tracknumber]
2121 # do_cdread onetrack [firsttrack] [lasttrack]
2125 # The commands here don't go through run_command because they're never supposed to be silenced
2126 # return codes need to be doublechecked anyway, however
2127 if [ "$1" = "onetrack" ]; then
2128 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2129 # FIXME # Until then, we grab the whole CD in one track, no matter what
2131 # We need the first and last track for cdda2wav
2134 UTRACKNUM=$FIRSTTRACK
2135 case "$CDROMREADERSYNTAX" in
2136 ### FIXME ### How are we calculating the tracks in flac mode?
2137 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2138 cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2139 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
2140 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
2146 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2147 if [ "$USEPIPES" = "y" ]; then
2148 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
2149 FILEARG="$( eval echo "\$$TEMPARG" )"
2151 PIPE_MESSAGE="and encoding "
2153 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2154 case "$CDROMREADERSYNTAX" in
2155 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2157 FILEARG="--output-name=$WAVDATA"
2160 FILEARG="-f $WAVDATA"
2168 if [ "$1" = "onetrack" ]; then
2169 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2171 if [ -r "$CDDBDATA" ]; then
2172 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
2173 do_getcddbinfo TRACKNAME
2174 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2176 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2179 case "$CDROMREADERSYNTAX" in
2180 ### FIXME ### use an exception for flac, since it uses -o
2181 ### FIXME ### Shall we just use -o $FILEARG ??
2183 nice $READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2185 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2187 if [ "$OSFLAVOUR" = "OSX" ] ; then
2188 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2189 disktool -u ${CDROM#/dev/} 0
2190 # Also, in OSX the cdrom device for cdda2wav changes...
2191 CDDA2WAVCDROM="IODVDServices"
2192 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2193 CDDA2WAVCDROM="$CDROMID"
2195 if [ "$CDROMID" = "" ]; then
2196 CDDA2WAVCDROM="$CDROM"
2198 CDDA2WAVCDROM="$CDROMID"
2201 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2203 ## FIXME ## We have an exception for dagrab, since it uses -f
2204 ## FIXME ## Shall we just use -f $FILEARG ??
2205 dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2208 # Find the track's mounted path
2209 REALTRACKNUM=$(expr $UTRACKNUM + 0)
2210 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
2211 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2212 # If the file exists, copy it
2213 if [ -e "$FILEPATH" ] ; then
2214 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2218 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2222 # If we get some error or we get some missing wav
2223 # (as long as we dont use pipes)
2224 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
2225 # Thank goodness errors is only machine-parseable up to the
2226 # first colon, otherwise this woulda sucked
2227 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2228 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2230 if [ "$USEPIPES" = "y" ]; then
2231 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2233 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2237 if [ "$USEPIPES" = "y" ]; then
2238 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2240 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2241 if [ "$1" = "onetrack" ]; then
2242 echo onetrack >> "$ABCDETEMPDIR/status"
2249 # No values accepted, only uses env variables
2252 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
2253 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
2255 echo "abcde: unable to set the device speed" >&2
2261 # vecho outputs a message if EXTRAVERBOSE is selected
2264 if [ x"$EXTRAVERBOSE" != "x" ]; then
2266 warning) log warning "$@" ;;
2274 # decho outputs a debug message if DEBUG is selected
2277 if [ x"$DEBUG" != "x" ]; then
2278 DEBUGECHO=$(echo "$@" | tr -d '[]')
2279 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2283 # User-redefinable functions
2284 # Custom filename munging:
2287 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2288 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
2291 # Custom genre munging:
2294 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2298 # Empty pre_read function, to be defined in the configuration file.
2305 # Empty post_read function, to be defined in the configuration file.
2311 ###############################################################################
2314 # Start of execution
2315 ###############################################################################
2318 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2319 CDDBSUBMIT=freedb-submit@freedb.org
2321 HELLOINFO="$(whoami)@$(hostname)"
2323 CDDBLOCALDIR="$HOME/.cddb"
2326 # List of fields we parse and show during the CDDB parsing...
2327 SHOWCDDBFIELDS="year,genre"
2330 CDROMREADERSYNTAX=cdparanoia
2331 ENCODERSYNTAX=default
2333 MP3ENCODERSYNTAX=default
2334 OGGENCODERSYNTAX=default
2335 FLACENCODERSYNTAX=default
2336 SPEEXENCODERSYNTAX=default
2337 MPPENCODERSYNTAX=default
2338 NORMALIZERSYNTAX=default
2339 CUEREADERSYNTAX=default
2341 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2342 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2343 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2344 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2345 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2346 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2347 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2348 PLAYLISTDATAPREFIX=''
2349 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2350 VAPLAYLISTDATAPREFIX=''
2358 VARIOUSARTISTSTYLE=forward
2364 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2365 # i.e. CDROMID="1,0,0"
2367 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2368 # If we are using the ide-scsi emulation layer, we need to define a "g"
2369 CDPARANOIACDROMBUS="d"
2371 # program paths - defaults to checking your $PATH
2378 XINGMP3ENC=xingmp3enc
2393 CDPARANOIA=cdparanoia
2402 VORBISCOMMENT=vorbiscomment
2404 NORMALIZE=normalize-audio
2406 VORBISGAIN=vorbisgain
2411 CUE2DISCID=cue2discid
2413 # Options for programs called from abcde
2446 VORBISCOMMENTOPTS="-R"
2447 METAFLACOPTS="--no-utf8-convert"
2449 # Default to one process if -j isn't specified
2452 # List of actions to perform - by default, run to completion
2453 ACTIONS=cddb,read,encode,tag,move,clean
2455 # List of prefered outputs - by default, run with whatever we have in the path
2456 # This option is basicaly for Debian package dependencies
2457 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex
2459 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2460 # Let's use these checkings to determine the OS flavour, which will be used later
2461 if [ X$(uname) = "XFreeBSD" ] ; then
2466 elif [ X$(uname) = "XDarwin" ] ; then
2469 # We should have disktool in OSX, but let's be sure...
2471 CDROMREADERSYNTAX=cddafs
2472 elif [ X$(uname) = "XOpenBSD" ] ; then
2475 elif [ X$(uname) = "XNetBSD" ] ; then
2482 # If CDDBAVAIL is set to n, no CDDB read is done
2483 # If USEID3 is set to n, no ID3 tagging is done
2488 if [ -z "$OUTPUTDIR" ]; then
2492 if [ -z "$WAVOUTPUTDIR" ]; then
2493 WAVOUTPUTDIR="$OUTPUTDIR"
2496 # Load system defaults
2497 if [ -r /etc/abcde.conf ]; then
2500 # Load user preference defaults
2501 if [ -r $HOME/.abcde.conf ]; then
2505 # By this time, we need some HTTPGETOPTS already defined.
2506 # If the user has defined a non-default HTTPGET method, we should not be empty.
2508 if [ "$HTTPGETOPTS" = "" ] ; then
2510 wget) HTTPGETOPTS="-q -O -";;
2511 curl) HTTPGETOPTS="-f -s";;
2512 fetch)HTTPGETOPTS="-q -o -";;
2513 ftp) HTTPGETOPTS="-q -o -";;
2514 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
2518 # If the CDROM has not been set yet, find a suitable one.
2519 # If this is a devfs system, default to /dev/cdroms/cdrom0
2520 # instead of /dev/cdrom
2521 if [ "$CDROM" = "" ] ; then
2522 if [ -e /dev/cdroms/cdrom0 ]; then
2523 CDROM=/dev/cdroms/cdrom0
2524 elif [ -e /dev/cdrom ]; then
2526 elif [ -e /dev/cd0c ]; then
2528 elif [ -e /dev/acd0c ]; then
2530 elif [ -e /dev/disk1 ]; then
2535 # Parse command line options
2536 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2537 while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:vVxw:W:z opt ; do
2540 a) ACTIONS="$OPTARG" ;;
2541 A) EXPACTIONS="$OPTARG" ;;
2543 B) NOBATCHREPLAYGAIN=y ;;
2544 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
2545 C) DISCID="${OPTARG#abcde.}" ;;
2546 d) CDROM="$OPTARG" ;;
2548 e) ERASEENCODEDSTATUS=y ;;
2550 e) ERASEENCODEDSTATUS=y ;;
2551 E) ENCODING="$OPTARG" ;;
2555 j) MAXPROCS="$OPTARG" ;;
2558 L) CDDBUSELOCAL=y ;;
2563 o) OUTPUTTYPE="$OPTARG" ;;
2566 r) REMOTEHOSTS="$OPTARG" ;;
2567 R) DOREPLAYGAIN=y ;;
2568 s) SHOWCDDBFIELDS="$OPTARG" ;;
2569 S) CDSPEEDVALUE="$OPTARG" ;;
2570 # t) PREPROCESSFORMATS="$OPTARG"
2572 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2573 t) STARTTRACKNUMBER="$OPTARG" ;;
2574 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
2576 echo "This is abcde v$VERSION."
2577 echo "Usage: abcde [options] [tracks]"
2578 echo "abcde -h for extra help"
2581 V) EXTRAVERBOSE="y" ;;
2583 w) COMMENT="$OPTARG" ;;
2584 W) if echo $OPTARG | grep -q "[[:digit:]]" ; then
2585 STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
2587 log error "argument of -W must be integer"
2591 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
2596 shift $(($OPTIND - 1))
2598 # If the user specified a flac file, then switch to special flac mode
2599 if echo $CDROM | grep -i -q '.flac$'; then
2600 vecho "abcde: switching to flac CDROMREADERSYNTAX..."
2601 CDROMREADERSYNTAX=flac
2602 if [ "$EJECTCD" = "y" ];then
2603 vecho "abcde: CDROM flac mode, deactivating EJECTCD..."
2608 # Decide if we can continue.
2609 if [ "$ONETRACK" = "y" ]; then
2610 # FIXME # remove check as soon as we find out about the other readers
2611 case "$CDROMREADERSYNTAX" in
2615 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
2618 if [ "$BATCHNORM" = "y" ]; then
2619 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
2622 if [ "$NOGAP" = "y" ]; then
2623 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
2626 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2627 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2628 if [ $# -gt 0 ]; then
2629 log warning "ONETRACK mode selected, grabbing all tracks..."
2632 while [ $# -gt 0 ]; do
2633 # Range parsing code courtesy of Vincent Ho
2634 RSTART=$(echo $1 | cut -f1 -d-)
2635 REND=$(echo $1 | cut -f2 -d-)
2636 if [ "$RSTART" = "$REND" ]; then
2639 NEWTRACKS=$(f_seq_line $RSTART $REND)
2641 TRACKQUEUE=$(echo "$TRACKQUEUE" "$NEWTRACKS")
2646 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2647 # List of experimental actions: retag,transcode
2649 # Determine what actions are to be done from $ACTIONS and set the
2650 # following environment variables for them:
2663 for ACTION in $(echo $ACTIONS | tr , \ )
2668 normalize) DONORMALIZE=y; DOREAD=y;;
2669 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2670 encode) DOENCODE=y; DOREAD=y;;
2671 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2672 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2673 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2674 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
2675 playlist) DOCDDB=y; DOPLAYLIST=y;;
2680 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2681 # FIXME # should we abort on error or just inform the user?
2682 log warning "selected both normalize and replaygain actions"
2685 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
2686 case $SHOWCDDBFIELD in
2687 y*|Y*) SHOWCDDBYEAR="y";;
2688 g*|G*) SHOWCDDBGENRE="y";;
2695 # At this point a CDROM has to be defined, so we check it exists.
2696 if [ X"$CDROM" != "X" ] ; then
2697 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2698 if [ "$OSFLAVOUR" = "FBSD" ]; then
2699 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
2700 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
2701 log error "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2705 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
2706 log error "CDROM device cannot be found."
2709 # avoid processing if we are not going to hit the CDROM.
2710 elif [ X"$DOREAD" = "Xy" ]; then
2711 log error "CDROM has not been defined or cannot be found"
2715 # USEPIPES pre-tests, before we get into more serious stuff
2716 # Not compatible with:
2717 # - multiple outputs
2719 # - lowdisk algorithm
2721 if [ X"$USEPIPES" = "Xy" ]; then
2722 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
2723 log error "Unix pipes not compatible with multiple outputs"
2726 if [ X"$DONORMALIZE" = "Xy" ]; then
2727 log error "Unix pipes not compatible with normalizer"
2728 # FIXME # Do we need to exit or shall we just disable the mode?
2731 if [ X"$BATCHNORM" = "Xy" ]; then
2732 log error "Unix pipes not compatible with BATCHNORM encoding"
2735 if [ X"$NOGAP" = "Xy" ]; then
2736 log error "Unix pipes not compatible with NOGAP encoding"
2739 if [ X"$DOENCODE" = "Xn" ]; then
2740 vecho warning "Disabling Unix pipes since we are not encoding!"
2743 if [ X"$LOWDISK" = "Xy" ]; then
2744 log error "Unix pipes not compatible with lowdisk algorithm"
2749 # LOWDISK pre-tests, before we get into more problematic stuff
2750 # Not compatible with anything that needs all the files in the hard disc:
2753 if [ X"$LOWDISK" = "Xy" ]; then
2754 if [ X"$BATCHNORM" = "Xy" ]; then
2755 log error "Unix pipes not compatible with BATCHNORM encoding"
2758 if [ X"$NOGAP" = "Xy" ]; then
2759 log error "Unix pipes not compatible with NOGAP encoding"
2764 # BATCHNORM pre-tests, before we get into serious problems
2765 # Not compatible with
2766 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
2767 vecho warning "Disabling BATCHNORM since we are not normalizing!"
2771 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2772 if [ X"$OUTPUTTYPE" = "X" ]; then
2773 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
2774 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2775 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2776 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
2777 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
2778 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2782 if [ X"$OUTPUTTYPE" = "X" ]; then
2783 log error "no encoder found in the PATH"
2784 log error "hints: are all dependencies installed? has the \$PATH been modified?"
2789 # Decide which CDROM reader we're gonna use
2790 case "$CDROMREADERSYNTAX" in
2792 CDROMREADER="$CDPARANOIA"
2793 CDROMREADEROPTS="$CDPARANOIAOPTS"
2796 CDROMREADER="$CDDA2WAV"
2797 CDROMREADEROPTS="$CDDA2WAVOPTS"
2800 CDROMREADER="$DAGRAB"
2801 CDROMREADEROPTS="$DAGRABOPTS"
2804 CDROMREADER="$CDDAFS"
2805 CDROMREADEROPTS="$CDDAFSOPTS"
2809 CDROMREADEROPTS="$FLACOPTS"
2813 # There's only one normalize...
2814 case "$NORMALIZERSYNTAX" in
2816 NORMALIZER="$NORMALIZE"
2817 NORMALIZEROPTS="$NORMALIZEOPTS"
2821 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2822 if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
2823 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2825 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2826 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2827 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2828 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2829 mpc:*) MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2832 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2833 TEMPOUTPUT=$( echo "$OUTPUT" | cut -d: -f1 )
2834 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2836 OUTPUTTYPE="$TEMPOUTPUTTYPE"
2839 # 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
2841 # Getting ready for multiple output changes
2842 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
2846 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
2847 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
2848 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
2849 OGGOUTPUTCONTAINER=ogg
2852 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
2853 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
2854 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
2857 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
2858 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
2859 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
2862 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
2865 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc