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 (flac uses a single-track flac file)"
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 "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
36 echo "-h This help information"
37 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
38 echo "-j <#> Number of encoder processes to run at once (localhost)"
39 echo "-k Keep the wav tracks for later use"
40 echo "-l Use low disk space algorithm"
41 echo "-L Use local CDDB storage directory"
42 echo "-n No lookup. Don't query CDDB, just create and use template"
43 echo "-N Noninteractive. Never prompt for anything"
44 echo "-m Modify playlist to include CRLF endings, to comply with some players"
45 echo "-M Create a CUE file"
46 echo "-o <type1[,type2]...>"
47 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav). Defaults to vorbis"
48 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
49 echo "-P Use UNIX pipes to read+encode without wav files"
50 echo "-r <host1[,host2]...>"
51 echo " Also encode on these remote hosts"
52 echo "-R Add replaygain values to the tag info (only for vorbis,flac)"
54 echo " Show dielfs from the CDDB info (year,genre)"
55 echo "-S <#> Set the CD speed"
56 #echo "-t File types to preprocess (wav)"
57 #echo "-T Set postprocessing options"
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"
74 # Funtions to replace the need of seq, which is too distribution dependant.
78 while [ $i -ne `expr $2 + 1` ]
88 if echo i |
grep -q "[[:digit:]]" ; then
89 while [ $i -ne `expr $2 + 1` ]
96 echo "abcde: syntax error while processing track numbers" >&2
101 # Functions to replace the need of awk {print $1} and {print $NF}
104 if [ X
"$1" = "X" ]; then
105 for first
in `cat`; do
116 if [ X
"$1" = "X" ]; then
117 for stdin
in `cat`; do
121 for last
in $@
; do :; done
126 # checkstatus [blurb]
127 # Returns "0" if the blurb was found, returns 1 if it wasn't
128 # Puts the blurb content, if available, on stdout.
129 # Otherwise, returns "".
132 # Take the last line in the status file if there's multiple matches
134 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
136 if [ -z "$BLURB" ]; then
141 # See if there's a = in it
142 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
143 echo "$(echo $BLURB | cut -f2- -d=)"
149 # chechwarnings [blurb]
150 # Returns "0" if the blurb was found (meaning there was an warning),
151 # returns 1 if it wasn't (yes this is a little backwards).
152 # Does not print the blurb on stdout.
153 # Otherwise, returns "".
156 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
159 # Take the last line in the status file if there's multiple matches
161 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
163 if [ -z "$BLURB" ]; then
164 # negative, we did not have a negative...
167 # affirmative, we had a negative...
172 # checkerrors [blurb]
173 # Returns "0" if the blurb was found (meaning there was an error),
174 # returns 1 if it wasn't (yes this is a little backwards).
175 # Does not print the blurb on stdout.
176 # Otherwise, returns "".
179 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
182 # Take the last line in the status file if there's multiple matches
184 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
186 if [ -z "$BLURB" ]; then
187 # negative, we did not have a negative...
190 # affirmative, we had a negative...
196 # Finds the right pager in the system to display a file
200 # Use the debian sensible-pager wrapper to pick the pager
201 # user has requested via their $PAGER environment variable
202 if [ -x "/usr/bin/sensible-pager" ]; then
203 /usr
/bin
/sensible-pager
"$PAGEFILE"
204 elif [ -x "$PAGER" ]; then
205 # That failed, try to load the preferred editor, starting
206 # with their PAGER variable
208 # If that fails, check for less
209 elif [ -x /usr
/bin
/less ]; then
210 /usr
/bin
/less -f "$PAGEFILE"
211 # more should be on all UNIX systems
212 elif [ -x /bin
/more ]; then
213 /bin
/more "$PAGEFILE"
215 # No bananas, just cat the thing
220 # run_command [blurb] [command...]
221 # Runs a command, silently if necessary, and updates the status file
226 # See if this is supposed to be silent
227 if [ "$(checkstatus encode-output)" = "loud" ]; then
231 # Special case for SMP, since
232 # encoder output is never displayed, don't mute echos
233 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
242 normalize|normalize-audio
)
243 if [ "$RETURN" = "2" ]; then
244 # File was already normalized.
249 if [ "$RETURN" != "0" ]; then
250 # Put an error in the errors file. For various reasons we
251 # can't capture a copy of the program's output but we can
252 # log what we attempted to execute and the error code
253 # returned by the program.
254 if [ "$BLURB" ]; then
257 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
258 return $RETURN # Do not pass go, do not update the status file
260 if [ "$BLURB" ]; then
261 echo $BLURB >> "$ABCDETEMPDIR/status"
265 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
266 # distributed under the terms of the GNU GPL v2 or later, at your option
268 # Function to determine if a word contains a slash.
277 # Function to give the relative path from one file to another.
278 # Usage: relpath fromfile tofile
279 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
280 # (the result would be Album/Song.mp3)
281 # Output is relative path to $2 from $1 on stdout
283 # This code has the following restrictions:
284 # Multiple ////s are not collapsed into single /s, with strange effects.
285 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
286 # If FR is a directory it must have a trailing /
294 /*) ;; # No processing is needed for absolute paths
296 # Loop through common prefixes, ignoring them.
297 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
299 FR
="$(echo "$FR" | cut -d/ -f2-)"
300 TO
="$(echo "$TO" | cut -d/ -f2-)"
302 # Loop through directory portions left in FR, adding appropriate ../s.
305 FR
="$(echo "$FR" | cut -d/ -f2-)"
315 # Finds an specific field from cddbinfo
317 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
318 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
319 # TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
325 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
328 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
334 # Get the track number we are going to use for different actions
337 if [ -n "$STARTTRACKNUMBER" ] ; then
338 # Get the trackpadding from the current track
339 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
340 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
342 TRACKNUM
=${UTRACKNUM}
348 if checkstatus replaygain
; then :; else
349 run_command
"" echo "Adding replygain information..."
350 for OUTPUT
in $
( echo $OUTPUTTYPE |
tr , \
)
351 # THE OUTPUT NEEDS TO BE CORRECTED WITH THE CONTAINER?
355 OUTPUT
=$OGGOUTPUTCONTAINER
358 OUTPUT
=$FLACOUTPUTCONTAINER
362 for UTRACKNUM
in $TRACKQUEUE
364 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
365 do_getcddbinfo TRACKNAME
367 TRACKFILE
="$(mungefilename "$TRACKNAME")"
368 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
369 ALBUMFILE
="$(mungefilename "$DALBUM")"
371 if [ "$VARIOUSARTISTS" = "y" ]; then
372 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
374 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
376 OUTPUTFILES
="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT $OUTPUTFILES"
380 run_command replaygain-flac
$METAFLAC --add-replay-gain $OUTPUTFILES
383 run_command replaygain-vorbis
$VORBISGAIN --album $OUTPUTFILES
388 if checkerrors replaygain-.
{3,6}; then :; else
389 run_command replaygain true
394 # This code splits the a Various Artist track name from one of the following
397 # forward: Artist / Track
398 # forward-dash: Artist - Track
399 # reverse: Track / Artist
400 # reverse-dash: Track - Artist
401 # colon: Artist: Track
402 # trailing-paren: Artist (Track)
405 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
408 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
409 case "$VARIOUSARTISTSTYLE" in
411 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
412 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
413 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
416 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
417 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
418 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
421 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
422 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
423 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
426 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
427 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
428 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
431 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's-: -~-g')"
432 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
433 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
436 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
437 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
438 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
441 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
442 TRACKARTIST
="Various"
444 TRACKARTIST
="$DARTIST"
449 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
453 "classic rock") id
=1 ;;
471 "industrial") id
=19 ;;
472 "alternative") id
=20 ;;
474 "death metal") id
=22 ;;
476 "soundtrack") id
=24 ;;
477 "euro-techno") id
=25 ;;
481 "jazz+funk") id
=29 ;;
484 "classical") id
=32 ;;
485 "instrumental") id
=33 ;;
489 "sound clip") id
=37 ;;
492 "alt. rock") id
=40 ;;
497 "meditative") id
=45 ;;
498 "instrum. pop") id
=46 ;;
499 "instrum. rock") id
=47 ;;
503 "techno-indust.") id
=51 ;;
504 "electronic") id
=52 ;;
506 "eurodance") id
=54 ;;
508 "southern rock") id
=56 ;;
513 "christian rap") id
=61 ;;
514 "pop/funk"|
"pop / funk") id
=62 ;;
516 "native american") id
=64 ;;
519 "psychadelic") id
=67 ;;
521 "showtunes") id
=69 ;;
525 "acid punk") id
=73 ;;
526 "acid jazz") id
=74 ;;
530 "rock & roll") id
=78 ;;
531 "hard rock") id
=79 ;;
533 "folk/rock") id
=81 ;;
534 "national folk") id
=82 ;;
541 "bluegrass") id
=89 ;;
542 "avantgarde") id
=90 ;;
543 "gothic rock") id
=91 ;;
544 "progress. rock") id
=92 ;;
545 "psychadel. rock") id
=93 ;;
546 "symphonic rock") id
=94 ;;
547 "slow rock") id
=95 ;;
550 "easy listening") id
=98 ;;
556 "chamber music") id
=104 ;;
558 "symphony") id
=106 ;;
559 "booty bass") id
=107 ;;
561 "porn groove") id
=109 ;;
563 "slow jam") id
=111 ;;
567 "folklore") id
=115 ;;
569 "power ballad") id
=117 ;;
570 "rhythmic soul") id
=118 ;;
571 "freestyle") id
=119 ;;
573 "punk rock") id
=121 ;;
574 "drum solo") id
=122 ;;
575 "a capella") id
=123 ;;
576 "euro-house") id
=124 ;;
577 "dance hall") id
=125 ;;
579 "drum & bass") id
=127 ;;
580 "club-house") id
=128 ;;
581 "hardcore") id
=129 ;;
585 "negerpunk") id
=133 ;;
586 "polsk punk") id
=134 ;;
588 "christian gangsta rap") id
=136 ;;
589 "heavy metal") id
=137 ;;
590 "black metal") id
=138 ;;
591 "crossover") id
=139 ;;
592 "contemporary christian")id
=140 ;;
593 "christian rock") id
=141 ;;
594 "merengue") id
=142 ;;
596 "thrash metal") id
=144 ;;
599 "synthpop") id
=147 ;;
600 "rock/pop"|
"rock / pop") id
=148 ;;
607 # do_tag [tracknumber]
608 # id3 tags a filename
610 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
611 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
614 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
615 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
616 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
617 # If we want to start the tracks with a given number, we need to modify the
618 # TRACKNUM value before evaluation
619 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
622 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
626 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
627 GENREID
=$
(do_getgenreid
"${CDGENRE}")
632 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
633 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
634 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
635 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
636 "${ENCODING:+--set-encoding=$ENCODING}"
637 "$ABCDETEMPDIR/track$1.$OUTPUT"
640 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
641 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
642 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
643 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
644 "$ABCDETEMPDIR/track$1.$OUTPUT"
649 case "$OGGENCODERSYNTAX" in
651 # vorbiscomment can't do in-place modification, mv the file first
652 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
653 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
656 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
657 echo ARTIST
="$TRACKARTIST"
659 echo TITLE
="$TRACKNAME"
660 if [ -n "$CDYEAR" ]; then
663 if [ -n "$CDGENRE" ]; then
664 echo GENRE
="$CDGENRE"
666 echo TRACKNUMBER
=${TRACKNUM:-$1}
667 echo CDDB
=$CDDBDISCID
668 if [ "$(eval echo ${COMMENT})" != "" ]; then
669 case "$COMMENTOUTPUT" in
670 *=*) echo "$COMMENTOUTPUT";;
671 *) echo COMMENT
="$COMMENTOUTPUT";;
674 ) | run_command tagtrack-
$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
675 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
676 # Doublecheck that the commented file was created successfully before wiping the original
677 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
678 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
680 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
687 echo ARTIST
="$TRACKARTIST"
689 echo TITLE
="$TRACKNAME"
690 if [ -n "$CDYEAR" ]; then
693 if [ -n "$CDGENRE" ]; then
694 echo GENRE
="$CDGENRE"
696 echo TRACKNUMBER
="${TRACKNUM:-$1}"
697 echo CDDB
="$CDDBDISCID"
698 if [ "$(eval echo ${COMMENT})" != "" ]; then
699 case "$COMMENTOUTPUT" in
700 *=*) echo "$COMMENTOUTPUT";;
701 *) echo COMMENT
="$COMMENTOUTPUT";;
704 ) | run_command tagtrack-
$OUTPUT-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
707 run_command tagtrack-
$OUTPUT-$1 true
710 run_command tagtrack-
$OUTPUT-$1 true
713 run_command tagtrack-
$OUTPUT-$1 true
717 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
718 run_command tagtrack-
$1 true
725 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
728 # The commands here don't go through run_command because they're never supposed to be silenced
729 echo "Batch encoding tracks: $TRACKQUEUE"
730 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
733 case "$MP3ENCODERSYNTAX" in
738 for UTRACKNUM
in $TRACKQUEUE
740 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
742 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS `[ "$MP3ENCODER" = "lame" ] && echo "--nogap"` $TRACKFILES
744 if [ "$RETURN" != "0" ]; then
745 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
747 for UTRACKNUM
in $TRACKQUEUE
749 run_command encodetrack-
$UTRACKNUM true
757 # Other encoders fall through to normal encoding as the tracks
758 # have not been entered in the status file.
761 # do_encode [tracknumber] [hostname]
762 # If no hostname is specified, encode locally
764 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
767 if [ "$USEPIPES" = "y" ]; then
770 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
773 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
776 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
779 TEMPARG
="PIPE_$SPEEXENCODER"
782 TEMPARG
="PIPE_$MPPENCODER"
785 IN
="$( eval echo "\$
$TEMPARG" )"
787 IN
="$ABCDETEMPDIR/track$1.wav"
790 case "$MP3ENCODERSYNTAX" in
791 # FIXME # check if mp3enc needs -if for pipes
792 # FIXME # I have not been able to find a working mp3enc binary
806 # We need IN to proceed, if we are not using pipes.
807 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
808 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
812 OUT
="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
815 OUT
="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
818 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
821 if [ X
"$USEPIPES" = "Xy" ]; then
824 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
825 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
831 case "$MP3ENCODERSYNTAX" in
832 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
833 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
834 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
835 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
836 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
840 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
847 case "$OGGENCODERSYNTAX" in
848 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
849 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
853 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
860 case "$FLACENCODERSYNTAX" in
861 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
867 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
868 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
873 if [ "$(eval echo ${COMMENT})" != "" ]; then
876 *) COMMENT
="COMMENT=$COMMENT" ;;
878 COMMENT
="--comment \"$COMMENT\""
880 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
881 if [ ! "$DOTAG" = "y" ]; then
882 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
884 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
888 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
890 # I tried compiling the mppenc from corecodecs.org and got some
891 # errors, so I have not tried it myself.
892 ## FIXME ## Needs some cleanup to determine if an empty tag sent
893 ## FIXME ## to the encoder ends up empty.
894 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
897 # In case of wav output we need nothing. Just keep the wavs.
898 run_command encodetrack-
$OUTPUT-$1 true
902 # Only remove .wav if the encoding succeeded
903 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
904 run_command encodetrack-
$1 true
905 if [ ! "$KEEPWAVS" = "y" ] ; then
906 if [ ! "$KEEPWAVS" = "move" ] ; then
912 run_command
"" echo "HEH! The file we were about to encode disappeared:"
913 run_command
"" echo ">> $IN"
914 run_command encodetrack-
$1 false
918 # do_preprocess [tracknumber]
920 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
923 # IN="$ABCDETEMPDIR/track$1.wav"
924 # # We need IN to proceed.
925 # if [ -s "$IN" ] ; then
926 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
928 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
929 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
930 # case "$POSTPROCESSFORMAT" in
932 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
934 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
936 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
938 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
940 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
943 # # Only remove .wav if the encoding succeeded
944 # if checkerrors "preprocess-(.{3,4})-$1"; then
945 # run_command preprocess-$1 false
947 # run_command preprocess-$1 true
950 # if [ "$(checkstatus encode-output)" = "loud" ]; then
951 # echo "HEH! The file we were about to pre-process disappeared:"
954 # run_command preprocess-$1 false
959 # do_postprocess [tracknumber]
961 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
964 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
966 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
967 # # We need IN to proceed.
968 # if [ -s "$IN" ] ; then
969 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
970 # run_command '' echo "Post-processing track $1 of $TRACKS..."
971 # case "$POSTPROCESSFORMAT" in
973 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
975 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
977 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
979 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
981 # # Only remove .wav if the encoding succeeded
982 # if checkerrors "postprocess-(.{3,4})-$1"; then
983 # run_command postprocess-$1 false
985 # run_command postprocess-$1 true
988 # if [ "$(checkstatus encode-output)" = "loud" ]; then
989 # echo "HEH! The file we were about to post-process disappeared:"
992 # run_command postprocess-$1 false
1007 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
1011 # The commands here don't go through run_command because they're never supposed to be silenced
1012 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1017 for UTRACKNUM
in $TRACKQUEUE
1019 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1021 # FIXME # Hard-coded batch option!
1022 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1024 if [ "$RETURN" != "0" ]; then
1025 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1027 for UTRACKNUM
in $TRACKQUEUE
1029 echo normalizetrack-
$UTRACKNUM >> status
1035 # do_batch_normalize
1037 # NORMALIZER, NORMALIZEROPTS
1038 do_batch_normalize
()
1040 # The commands here don't go through run_command because they're never supposed to be silenced
1041 echo "Batch normalizing tracks: $TRACKQUEUE"
1046 for UTRACKNUM
in $TRACKQUEUE
1048 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1050 # XXX: Hard-coded batch option!
1051 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1053 if [ "$RETURN" != "0" ]; then
1054 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1056 for UTRACKNUM
in $TRACKQUEUE
1058 echo normalizetrack-
$UTRACKNUM >> status
1064 # do_normalize [tracknumber]
1066 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1069 IN
="$ABCDETEMPDIR/track$1.wav"
1070 if [ -e "$IN" ] ; then
1071 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1072 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1074 if [ "$(checkstatus encode-output)" = "loud" ]; then
1075 echo "HEH! The file we were about to normalize disappeared:"
1078 run_command normalizetrack-
$1 false
"File $IN was not found"
1082 # do_move [tracknumber]
1083 # Deduces the outfile from environment variables
1084 # Creates directory if necessary
1086 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1089 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1091 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1092 # Munge filenames as follows:
1097 # Eat control characters
1098 ALBUMFILE
="$(mungefilename "$DALBUM")"
1099 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1100 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1101 GENRE
="$(mungegenre "$GENRE")"
1102 YEAR
="$(echo $CDYEAR)"
1103 # If we want to start the tracks with a given number, we need to modify the
1104 # TRACKNUM value before evaluation
1106 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1107 # TRACKFILE, and TRACKNUM.
1108 if [ "$VARIOUSARTISTS" = "y" ]; then
1109 OUTPUTFILE
="$(eval echo "$VAOUTPUTFORMAT")"
1111 OUTPUTFILE
="$(eval echo "$OUTPUTFORMAT")"
1113 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1114 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1117 OUTPUT
=$OGGOUTPUTCONTAINER
1120 OUTPUT
=$FLACOUTPUTCONTAINER
1123 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1124 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1127 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1128 # FIXME # introduce warnings?
1131 # mkdir -p shouldn't return an error if the directory already exists
1132 mkdir
-p "$OUTPUTFILEDIR"
1133 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1134 if checkstatus movetrack-output-
$OUTPUT; then :; else
1135 run_command movetrack-output-
$OUTPUT true
1140 # mkdir -p shouldn't return an error if the directory already exists
1141 mkdir
-p "$OUTPUTFILEDIR"
1142 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1143 if checkstatus movetrack-output-
$OUTPUT; then :; else
1144 run_command movetrack-output-
$OUTPUT true
1148 # Lets move the cue file
1149 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1150 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1151 if checkstatus movecue-
$OUTPUT; then :; else
1152 # Silence the Copying output since it overlaps with encoding processes...
1153 #run_command '' vecho "Copying cue file to its destination directory..."
1154 if checkstatus onetrack
>/dev
/null
; then
1157 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1158 # We dont have the dir, since it was not created before.
1161 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1164 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1165 # http://brianvictor.tripod.com/mp3cue.htm#details
1166 [a-z0-9
][a-z0-9
][a-z0-9
])
1167 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1170 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1174 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1176 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1185 # Create the playlist if wanted
1187 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1188 # VARIOUSARTISTS, OUTPUTDIR
1191 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1195 OUTPUT
=$OGGOUTPUTCONTAINER
1198 OUTPUT
=$FLACOUTPUTCONTAINER
1201 # Create a playlist file for the playlist data to go into.
1202 # We used to wipe it out if it existed. Now we request permision if interactive.
1203 for LASTTRACK
in $TRACKQUEUE; do :; done
1204 ALBUMFILE
="$(mungefilename "$DALBUM")"
1205 ARTISTFILE
="$(mungefilename "$DARTIST")"
1206 GENRE
=$
(mungegenre
"$GENRE")
1207 YEAR
=${CDYEAR:-$CDYEAR}
1208 if [ "$VARIOUSARTISTS" = "y" ] ; then
1209 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
1211 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
1213 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1214 mkdir
-p "$FINALPLAYLISTDIR"
1215 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1216 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1217 if [ "$INTERACTIVE" = "y" ]; then
1218 while [ "$DONE" != "y" ]; do
1220 case $ERASEPLAYLIST in
1221 e|E|a|A|k|K
) DONE
=y
;;
1229 # Once we erase the playlist, we use append to create the new one.
1230 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1232 # The playlist does not exist, so we can safelly use append to create the new list
1235 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1236 touch "$OUTPUTDIR/$PLAYLISTFILE"
1237 for UTRACKNUM
in $TRACKQUEUE
1239 # Shares some code with do_move since the filenames have to match
1240 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1241 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1242 do_getcddbinfo TRACKNAME
1244 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1245 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1246 ALBUMFILE
="$(mungefilename "$DALBUM")"
1247 # If we want to start the tracks with a given number, we need to modify the
1248 # TRACKNUM value before evaluation
1250 if [ "$VARIOUSARTISTS" = "y" ]; then
1251 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1253 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1255 if [ "$VARIOUSARTISTS" = "y" ]; then
1256 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1257 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1259 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1262 if [ "$PLAYLISTDATAPREFIX" ]; then
1263 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1265 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1270 ## this will convert the playlist to have CRLF line-endings, if specified
1271 ## (some hardware players insist on CRLF endings)
1272 if [ "$DOSPLAYLIST" = "y" ]; then
1273 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1274 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1275 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1277 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1282 # This essentially the start of things
1285 # Query the CD to get the track info, unless the user specified -C
1286 # or we are using some actions which do not need the CDDB data at all
1287 #if [ ! X"$EXPACTIONS" = "X" ]; then
1289 #elif [ -z "$DISCID" ]; then
1290 if [ -z "$DISCID" ]; then
1291 vecho
-n "Getting CD track info... "
1292 # In OSX, unmount the disc before a query
1293 if [ "$OSFLAVOUR" = "OSX" ]; then
1294 disktool
-u ${CDROM#/dev/}
1296 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1297 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM |
$CUE2DISCID)
1299 TRACKINFO
=$
($CDDISCID $CDROM)
1301 # Make sure there's a CD in there by checking cd-discid's return code
1302 if [ ! "$?" = "0" ]; then
1303 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1304 echo "abcde error: cuesheet information from the flac file could not be read." >&2
1305 echo "abcde error: Perhaps the flac file does not contain a cuesheet?." >&2
1308 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1312 # In OSX, remount the disc again
1313 if [ "$OSFLAVOUR" = "OSX" ]; then
1314 disktool
-m ${CDROM#/dev/}
1318 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1321 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1322 # This needs to be done now because a section of the resuming code will need
1325 # get the number of digits to pad TRACKNUM with - we'll use this later
1326 # a CD can only hold 99 tracks, but since we support a feature for starting
1327 # numbering the tracks from a given number, we might need to set it as a
1328 # variable for the user to define... or obtain it somehow.
1329 if [ "$PADTRACKS" = "y" ] ; then
1333 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1334 if [ -z "$TRACKQUEUE" ]; then
1335 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1336 case "$CDROMREADERSYNTAX" in
1338 if [ "$WEHAVEACD" = "y" ]; then
1339 vecho
"Querying the CD for audio tracks..."
1340 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1342 if [ ! "$RET" = "0" ];then
1343 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1345 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1346 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1348 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1349 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1353 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1356 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1358 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1359 echo "The disc does not contain any tracks. Giving up..."
1362 echo -n "Grabbing entire CD - tracks: "
1363 if [ ! "$PADTRACKS" = "y" ] ; then
1364 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1366 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1368 while [ "$X" -ne "$TRACKS" ]
1370 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1371 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
1375 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1376 # User-supplied track queue.
1377 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1378 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1379 # Once cleaned, obtain the highest value in the trackqueue for number padding
1380 for LASTTRACK
in $TRACKQUEUE; do :; done
1381 if [ ! "$PADTRACKS" = "y" ] ; then
1382 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1384 # Now we normalize the trackqueue
1385 for TRACK
in $TRACKQUEUE ; do
1386 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1387 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1389 TRACKQUEUE
=$PADTRACKQUEUE
1390 echo Grabbing tracks
: "$TRACKQUEUE"
1393 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1395 # We have the discid, create a temp directory after it to store all the temp
1398 if [ -e "$ABCDETEMPDIR" ]; then
1399 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1400 # It already exists, see if it's a directory
1401 if [ ! -d "$ABCDETEMPDIR" ]; then
1402 # This is a file/socket/fifo/device/etc, not a directory
1405 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1406 echo "Please investigate, remove it, and rerun abcde." >&2
1410 # It's a directory, let's see if it's owned by us
1411 if [ ! -O "$ABCDETEMPDIR" ]; then
1412 # Nope, complain and exit
1414 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1415 echo "Please investigate, remove it, and rerun abcde." >&2
1419 # See if it's populated
1420 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1421 # Wipe and start fresh
1422 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1423 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1424 if [ "$INTERACTIVE" = "y" ]; then
1430 if [ "$ANSWER" != "y" ]; then
1433 rm -rf "$ABCDETEMPDIR" ||
exit 1
1434 mkdir
"$ABCDETEMPDIR"
1435 if [ "$?" -gt "0" ]; then
1436 # Directory already exists or could not be created
1437 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1441 # Everything is fine. Check for ^encodetracklocation-
1442 # and encode-output entries in the status file and
1443 # remove them. These are not relevant across sessions.
1444 if [ -f "$ABCDETEMPDIR/status" ]; then
1445 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1446 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1447 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1449 # Remove old error messages
1450 if [ -f "$ABCDETEMPDIR/errors" ]; then
1451 rm -f "$ABCDETEMPDIR/errors"
1455 # We are starting from scratch
1456 mkdir
"$ABCDETEMPDIR"
1457 if [ "$?" -gt "0" ]; then
1458 # Directory already exists or could not be created
1459 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1462 cat /dev
/null
> "$ABCDETEMPDIR/status"
1464 if [ X
"$MAKECUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1465 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1466 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1467 vecho
"Creating cue file..."
1468 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1469 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1471 echo "abcde: reading the CUE sheet with mkcue is still considered experimental"
1472 echo "abcde: and there was a problem with the CD reading. abcde will continue,"
1473 echo "abcde: but consider reporting the problem to the abcde author"
1477 # If we got the CDPARANOIA status and it is not recorded, save it now
1478 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1479 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
1480 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1484 # Create the discid file
1485 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1489 # Create a proper CUE file based on the CUE file we created before.
1492 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1493 CUEFILE_OUT
=$CUEFILE_IN.out
1494 ### FIXME ### checkstatus cddb
1495 if [ -e "$CDDBDATA" ]; then
1496 vecho
"Adding metadata to the cue file..."
1497 # FIXME It doesn't preserve spaces! Why?
1498 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1500 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1501 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1502 cat "$CUEFILE_IN" |
while read line
1504 if echo "$line" |
grep -q "INDEX"
1506 eval track
="\$TRACK$n"
1508 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1510 echo "$line" >> "$CUEFILE_OUT"
1512 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1513 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1519 # Parses a CDDB file and outputs the title and the track names.
1520 # Variables: CDDBFILE
1524 # List out disc title/author and contents
1525 if [ "$ONETRACK" = "y" ]; then
1526 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1528 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1529 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1530 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1531 if [ ! X
"$PARSEDYEAR" = "X" ]; then
1532 echo "Year: $PARSEDYEAR"
1535 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1536 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1537 if [ ! X
"$PARSEDGENRE" = "X" ]; then
1538 echo "Genre: $PARSEDGENRE"
1541 if [ ! "$ONETRACK" = "y" ]; then
1542 for TRACK
in $
(f_seq_row
1 $TRACKS)
1544 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1550 # Check for a local CDDB file, and report success
1553 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1555 CDDBLOCALSUCCESS
="n"
1556 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1557 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1560 # If the user has selected to check a local CDDB repo, we proceed with it
1561 if [ -r "${CDDBLOCALFILE}" ]; then
1562 # List out disc title/author and contents
1563 do_cddbparse
"${CDDBLOCALFILE}"
1564 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1565 if [ "$INTERACTIVE" = "y" ]; then
1567 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1568 echo -n 'Invalid selection. Please answer "y" or "n": '
1571 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1575 if [ "$USELOCALRESP" = "y" ]; then
1576 #echo "Using local copy of CDDB data"
1577 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1578 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1579 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1580 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1581 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1582 CDDBLOCALSUCCESS
="y"
1584 #echo "Not using local copy of CDDB data"
1585 CDDBLOCALSUCCESS
="n"
1588 CDDBLOCALSUCCESS
="n"
1596 # Perform CDDB protocol version check if it hasn't already been done
1597 if checkstatus cddb-statcomplete
; then :; else
1598 if [ "$CDDBAVAIL" = "n" ]; then
1600 echo 503 > "$ABCDETEMPDIR/cddbstat"
1603 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1604 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1605 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1606 vecho
"Checking CDDB server status..."
1607 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1608 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1609 case "$RESPONSECODE" in
1610 210) # 210 OK, status information follows (until terminating `.')
1613 501|
*) # 501 Illegal CDDB protocol level: <n>.
1614 CDDBPROTO
=`expr $CDDBPROTO - 1`
1618 if test $rc -eq 1; then
1622 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1630 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1631 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1633 # Perform CDDB query if it hasn't already been done
1634 if checkstatus cddb-querycomplete
; then :; else
1635 if [ "$CDDBAVAIL" = "n" ]; then
1637 echo 503 > "$ABCDETEMPDIR/cddbquery"
1638 # The default CDDBLOCALSUCCESS is "n"
1639 # This part will be triggered if the user CDDB repo does not
1640 # contain the entry, or if we are not trying to use the repo.
1642 vecho
"Querying the CDDB server..."
1643 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1644 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1645 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1651 # no match found in database,
1652 # wget/fetch error, or user requested not to use CDDB
1653 # Make up an error code (503) that abcde
1654 # will recognize in do_cddbread
1655 # and compensate by making a template
1656 echo 503 > "$ABCDETEMPDIR/cddbquery"
1658 *) # strange and unknown error
1659 echo ERRORCODE
=$ERRORCODE
1660 echo "abcde: $CDDBTOOL returned unknown error code"
1664 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1671 # If it's not to be used, generate a template.
1672 # Then, display it (or them) and let the user choose/edit it
1673 if checkstatus cddb-readcomplete
; then :; else
1674 vecho
"Obtaining CDDB results..."
1675 # If CDDB is to be used, interpret the query results and read all
1676 # the available entries.
1677 rm -f "$ABCDETEMPDIR/cddbchoices"
1678 CDDBCHOICES
=1 # Overridden by multiple matches
1679 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1680 case "$RESPONSECODE" in
1682 # One exact match, retrieve it
1683 # 200 [section] [discid] [artist] / [title]
1684 if checkstatus cddb-read-1-complete
; then :; else
1685 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1686 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1687 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1688 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1689 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1691 # List out disc title/author and contents
1692 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1693 for TRACK
in $
(f_seq_row
1 $TRACKS)
1695 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1697 echo >> "$ABCDETEMPDIR/cddbchoices"
1701 case "$RESPONSECODE" in
1702 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1703 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1704 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1706 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1707 # List out disc title/author and contents of template
1708 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1710 for TRACK
in $
(f_seq_row
1 $TRACKS)
1712 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1714 echo >> "$ABCDETEMPDIR/cddbchoices"
1715 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1716 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1719 # Multiple exact, (possibly multiple) inexact matches
1721 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1722 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
1723 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1724 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1725 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1727 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1729 vecho
-n "Retrieving multiple matches... "
1730 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1731 read DISCINFO
# eat top line
1735 if checkstatus cddb-read-
$X-complete; then :; else
1736 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1737 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1739 # List out disc title/author and contents
1740 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1741 for TRACK
in $
(f_seq_row
1 $TRACKS)
1743 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1745 echo >> "$ABCDETEMPDIR/cddbchoices"
1748 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1752 for TRACK
in $
(f_seq_row
1 $TRACKS)
1754 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1756 echo >> "$ABCDETEMPDIR/cddbchoices"
1757 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1758 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1761 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1768 if checkstatus cddb-edit
>/dev
/null
; then
1769 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1770 VARIOUSARTISTS
="$(checkstatus variousartists)"
1771 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1774 if [ "$INTERACTIVE" = "y" ]; then
1775 # We should show the CDDB results both when we are not using the local CDDB repo
1776 # or when we are using it but we could not find a proper match
1777 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1778 # Display the $ABCDETEMPDIR/cddbchoices file created above
1779 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1780 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1781 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1782 CHOICE
=$
(checkstatus cddb-choice
)
1783 if [ -n "$CHOICE" ] ; then
1784 case $CDDBCHOICES in
1785 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1787 echo "Selected: #$CHOICE"
1788 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1792 # The user has a choice to make, display the info in a pager if necessary
1793 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1794 page
"$ABCDETEMPDIR/cddbchoices"
1796 # It's all going to fit in one page, cat it
1797 cat "$ABCDETEMPDIR/cddbchoices" >&2
1801 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1803 # I'll take CDDB read #3 for $400, Alex
1804 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1805 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1807 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1808 if echo $CDDBCHOICE |
egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1809 if [ ! X
"$DIFF" = "X" ]; then
1810 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1)
1811 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2)
1812 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1813 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1814 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1815 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1818 # We parse the 2 choices to diff, store them in temporary files and diff them.
1819 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
1820 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1822 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1823 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1824 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
1825 page
"$ABCDETEMPDIR/cddbread.diff"
1827 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1831 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1834 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1835 # Make sure we get a valid choice
1836 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1837 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1841 if [ "$CDCHOICENUM" = "0" ]; then
1842 vecho
"Creating empty CDDB template..."
1844 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1846 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1847 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1849 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1853 # We need some code to show the selected option when local repository is selected and we have found a match
1854 vecho
"Using cached CDDB match..." >&2
1855 # Display the $ABCDETEMPDIR/cddbchoices file created above
1856 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1857 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1858 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1859 CHOICE
=$
(checkstatus cddb-choice
)
1860 if [ "$USELOCALRESP" = "y" ]; then :; else
1861 if [ -n "$CHOICE" ] ; then
1862 case $CDDBCHOICES in
1865 echo "Selected template."
1867 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1869 echo "Selected: #$CHOICE"
1870 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1878 # We're noninteractive - pick the first choice.
1879 # But in case we run a previous instance and selected a choice, use it.
1880 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1881 # Show the choice if we are not using the locally stored one
1882 # or when the local search failed to find a match.
1883 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1884 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1885 #if [ "$PREVIOUSCHOICE" ]; then
1886 cat "$ABCDETEMPDIR/cddbchoices"
1889 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1890 CDCHOICENUM
=$PREVIOUSCHOICE
1893 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1895 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1900 if checkstatus cddb-choice
>/dev
/null
; then :; else
1901 echo "abcde: internal error: cddb-choice not recorded." >&2
1904 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1905 echo -n "Edit selected CDDB data? [y/n] (" >&2
1906 if [ "$INTERACTIVE" = "y" ]; then
1907 if [ "$UNKNOWNDISK" = "y" ]; then
1910 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1919 if [ "$EDITCDDB" = "y" ]; then
1920 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1922 # Use the debian sensible-editor wrapper to pick the editor that the
1923 # user has requested via their $EDITOR environment variable
1924 if [ -x "/usr/bin/sensible-editor" ]; then
1925 /usr
/bin
/sensible-editor
"$CDDBDATA"
1926 elif [ -n "$EDITOR" ]; then
1927 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1928 # That failed, try to load the preferred editor, starting
1929 # with their EDITOR variable
1930 eval $
(echo "$EDITOR") \"$CDDBDATA\"
1932 # If that fails, check for a vi
1933 elif which vi
>/dev
/null
2>&1; then
1935 elif [ -x /usr
/bin
/vim
]; then
1936 /usr
/bin
/vim
"$CDDBDATA"
1937 elif [ -x /usr
/bin
/vi
]; then
1938 /usr
/bin
/vi
"$CDDBDATA"
1939 elif [ -x /bin
/vi
]; then
1941 # nano should be on all (modern, i.e., sarge) debian systems
1942 elif which nano
>/dev
/null
2>&1 ; then
1944 elif [ -x /usr
/bin
/nano
]; then
1945 /usr
/bin
/nano
"$CDDBDATA"
1946 # mg should be on all OpenBSD systems
1947 elif which mg
>/dev
/null
2>&1 ; then
1949 elif [ -x /usr
/bin
/mg
]; then
1950 /usr
/bin
/mg
"$CDDBDATA"
1953 echo "No editor available. Check your EDITOR environment variable." >&2
1955 # delete editor backup file if it exists
1956 if [ -w "$CDDBDATA~" ]; then
1961 # Some heuristics first. Look at Disc Title, and if it starts with
1962 # "Various", then we'll assume Various Artists
1963 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1964 echo "Looks like a Multi-Artist CD" >&2
1967 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1968 if [ "$INTERACTIVE" = "y" ]; then
1975 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1978 # Need NUMTRACKS before cddb-tool will return it:
1979 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1980 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1981 # More than 1/2 tracks contain a "/", so guess forward
1983 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1984 # More than 1/2 contain a "-", so guess forward-dash
1986 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1987 # More than 1/2 contain something in parens, so guess trailing-paren
1991 echo "1) Artist / Title" >&2
1992 echo "2) Artist - Title" >&2
1993 echo "3) Title / Artist" >&2
1994 echo "4) Title - Artist" >&2
1995 echo "5) Artist: Title" >&2
1996 echo "6) Title (Artist)" >&2
1997 echo "7) This is a single-artist CD" >&2
1998 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1999 if [ "$INTERACTIVE" = "y" ]; then
2000 read VARIOUSARTISTSTYLE
2002 echo $DEFAULTSTYLE >&2
2003 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2005 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2006 # If they press Enter, then the default style (0) was chosen
2007 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2008 echo "Invalid selection. Please choose a number between 1 and 7."
2009 echo -n "Selection [1-7]: "
2010 read VARIOUSARTISTSTYLE
2011 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2013 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2014 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2016 vecho
"Selected: $VARIOUSARTISTSTYLE"
2017 case "$VARIOUSARTISTSTYLE" in
2019 VARIOUSARTISTSTYLE
=forward
2022 VARIOUSARTISTSTYLE
=forward-dash
2025 VARIOUSARTISTSTYLE
=reverse
2028 VARIOUSARTISTSTYLE
=reverse-dash
2031 VARIOUSARTISTSTYLE
=colon
2034 VARIOUSARTISTSTYLE
=trailing-paren
2042 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2043 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2045 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2046 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2047 # This works but does not have the necessary error checking
2048 # yet. If you are familiar with the CDDB spec
2049 # (see http://www.freedb.org/src/latest/DBFORMAT)
2050 # and can create an error-free entry on your own, then put
2051 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2052 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2053 # your abcde.conf to change the email address submissions are
2056 # submit the modified file, if they want
2057 if [ "$NOSUBMIT" != "y" ]; then
2058 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2060 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2061 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2063 echo -n 'Invalid selection. Please answer "y" or "n": '
2066 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2067 echo -n "Sending..."
2068 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2074 # Make sure the cache directory exists
2075 mkdir
-p $CDDBLOCALDIR
2076 # Cache edited CDDB entry in the user's cddb dir
2077 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
2078 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2081 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2084 # do_cdread [tracknumber]
2085 # do_cdread onetrack [firsttrack] [lasttrack]
2089 # The commands here don't go through run_command because they're never supposed to be silenced
2090 # return codes need to be doublechecked anyway, however
2091 if [ "$1" = "onetrack" ]; then
2092 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2093 # FIXME # Until then, we grab the whole CD in one track, no matter what
2095 # We need the first and last track for cdda2wav
2098 UTRACKNUM
=$FIRSTTRACK
2099 case "$CDROMREADERSYNTAX" in
2100 ### FIXME ### How are we calculating the tracks in flac mode?
2101 flac
) READTRACKNUMS
="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2102 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
2103 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTRACK" ;;
2104 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2110 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2111 if [ "$USEPIPES" = "y" ]; then
2112 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
2113 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2115 PIPE_MESSAGE
="and encoding "
2117 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2118 case "$CDROMREADERSYNTAX" in
2119 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2121 FILEARG
="--output-name=$WAVDATA"
2124 FILEARG
="-f $WAVDATA"
2132 if [ "$1" = "onetrack" ]; then
2133 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2135 if [ -r "$CDDBDATA" ]; then
2136 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
2137 do_getcddbinfo TRACKNAME
2138 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2140 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2143 case "$CDROMREADERSYNTAX" in
2144 ### FIXME ### use an exception for flac, since it uses -o
2145 ### FIXME ### Shall we just use -o $FILEARG ??
2147 nice
$READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2149 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2151 if [ "$OSFLAVOUR" = "OSX" ] ; then
2152 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2153 disktool
-u ${CDROM#/dev/} 0
2154 # Also, in OSX the cdrom device for cdda2wav changes...
2155 CDDA2WAVCDROM
="IODVDServices"
2156 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2157 CDDA2WAVCDROM
="$CDROMID"
2159 if [ "$CDROMID" = "" ]; then
2160 CDDA2WAVCDROM
="$CDROM"
2162 CDDA2WAVCDROM
="$CDROMID"
2165 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2167 ## FIXME ## We have an exception for dagrab, since it uses -f
2168 ## FIXME ## Shall we just use -f $FILEARG ??
2169 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2172 # Find the track's mounted path
2173 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2174 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2175 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2176 # If the file exists, copy it
2177 if [ -e "$FILEPATH" ] ; then
2178 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2182 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2186 # If we get some error or we get some missing wav
2187 # (as long as we dont use pipes)
2188 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2189 # Thank goodness errors is only machine-parseable up to the
2190 # first colon, otherwise this woulda sucked
2191 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2192 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2194 if [ "$USEPIPES" = "y" ]; then
2195 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2197 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2201 if [ "$USEPIPES" = "y" ]; then
2202 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2204 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2205 if [ "$1" = "onetrack" ]; then
2206 echo onetrack
>> "$ABCDETEMPDIR/status"
2213 # No values accepted, only uses env variables
2216 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2217 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2219 echo "abcde: unable to set the device speed" >&2
2225 # vecho outputs a message if EXTRAVERBOSE is selected
2228 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2233 # User-redefinable functions
2234 # Custom filename munging:
2237 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2238 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2241 # Custom genre munging:
2244 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2248 # Empty pre_read function, to be defined in the configuration file.
2255 # Empty post_read function, to be defined in the configuration file.
2261 ###############################################################################
2264 # Start of execution
2265 ###############################################################################
2268 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2269 CDDBSUBMIT
=freedb-submit@freedb.org
2271 HELLOINFO
="$(whoami)@$(hostname)"
2273 CDDBLOCALDIR
="$HOME/.cddb"
2276 # List of fields we parse and show during the CDDB parsing...
2277 SHOWCDDBFIELDS
="year,genre"
2280 CDROMREADERSYNTAX
=cdparanoia
2281 ENCODERSYNTAX
=default
2283 MP3ENCODERSYNTAX
=default
2284 OGGENCODERSYNTAX
=default
2285 FLACENCODERSYNTAX
=default
2286 SPEEXENCODERSYNTAX
=default
2287 MPPENCODERSYNTAX
=default
2288 NORMALIZERSYNTAX
=default
2289 CUEREADERSYNTAX
=default
2291 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2292 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2293 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2294 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2295 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2296 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2297 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2298 PLAYLISTDATAPREFIX
=''
2299 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2300 VAPLAYLISTDATAPREFIX
=''
2308 VARIOUSARTISTSTYLE
=forward
2312 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2313 # i.e. CDROMID="1,0,0"
2315 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2316 # If we are using the ide-scsi emulation layer, we need to define a "g"
2317 CDPARANOIACDROMBUS
="d"
2319 # program paths - defaults to checking your $PATH
2325 XINGMP3ENC
=xingmp3enc
2340 CDPARANOIA
=cdparanoia
2349 VORBISCOMMENT
=vorbiscomment
2351 NORMALIZE
=normalize-audio
2353 VORBISGAIN
=vorbisgain
2357 CUE2DISCID
=cue2discid
2359 # Options for programs called from abcde
2391 VORBISCOMMENTOPTS
="-R"
2392 METAFLACOPTS
="--no-utf8-convert"
2394 # Default to one process if -j isn't specified
2397 # List of actions to perform - by default, run to completion
2398 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2400 # List of prefered outputs - by default, run with whatever we have in the path
2401 # This option is basicaly for Debian package dependencies
2402 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
2404 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2405 # Let's use these checkings to determine the OS flavour, which will be used later
2406 if [ X$
(uname
) = "XFreeBSD" ] ; then
2411 elif [ X$
(uname
) = "XDarwin" ] ; then
2414 # We should have disktool in OSX, but let's be sure...
2416 CDROMREADERSYNTAX
=cddafs
2417 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2420 elif [ X$
(uname
) = "XNetBSD" ] ; then
2427 # If CDDBAVAIL is set to n, no CDDB read is done
2428 # If USEID3 is set to n, no ID3 tagging is done
2433 if [ -z "$OUTPUTDIR" ]; then
2437 if [ -z "$WAVOUTPUTDIR" ]; then
2438 WAVOUTPUTDIR
="$OUTPUTDIR"
2441 # Load system defaults
2442 if [ -r /etc
/abcde.conf
]; then
2445 # Load user preference defaults
2446 if [ -r $HOME/.abcde.conf
]; then
2450 # By this time, we need some HTTPGETOPTS already defined.
2451 # If the user has defined a non-default HTTPGET method, we should not be empty.
2453 if [ "$HTTPGETOPTS" = "" ] ; then
2455 wget
) HTTPGETOPTS
="-q -O -";;
2456 curl
) HTTPGETOPTS
="-f -s";;
2457 fetch
)HTTPGETOPTS
="-q -o -";;
2458 ftp) HTTPGETOPTS
="-q -o -";;
2459 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2463 # If the CDROM has not been set yet, find a suitable one.
2464 # If this is a devfs system, default to /dev/cdroms/cdrom0
2465 # instead of /dev/cdrom
2466 if [ "$CDROM" = "" ] ; then
2467 if [ -e /dev
/cdroms
/cdrom0
]; then
2468 CDROM
=/dev
/cdroms
/cdrom0
2469 elif [ -e /dev
/cdrom
]; then
2471 elif [ -e /dev
/cd0c
]; then
2473 elif [ -e /dev
/acd0c
]; then
2475 elif [ -e /dev
/disk1
]; then
2480 # Parse command line options
2481 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2482 while getopts 1a
:bc:C
:d
:Defhj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
:z opt
; do
2485 a
) ACTIONS
="$OPTARG" ;;
2486 A
) EXPACTIONS
="$OPTARG" ;;
2488 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2489 C
) DISCID
="${OPTARG#abcde.}" ;;
2490 d
) CDROM
="$OPTARG" ;;
2492 e
) ERASEENCODEDSTATUS
=y
;;
2494 e
) ERASEENCODEDSTATUS
=y
;;
2495 E
) ENCODING
="$OPTARG" ;;
2498 j
) MAXPROCS
="$OPTARG" ;;
2501 L
) CDDBUSELOCAL
=y
;;
2506 o
) OUTPUTTYPE
="$OPTARG" ;;
2509 r
) REMOTEHOSTS
="$OPTARG" ;;
2511 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2512 S
) CDSPEEDVALUE
="$OPTARG" ;;
2513 # t) PREPROCESSFORMATS="$OPTARG"
2515 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2516 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2517 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2519 echo "This is abcde v$VERSION."
2520 echo "Usage: abcde [options] [tracks]"
2521 echo "abcde -h for extra help"
2524 V
) EXTRAVERBOSE
="y" ;;
2526 w
) COMMENT
="$OPTARG" ;;
2527 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2528 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2530 echo "abcde error: argument of -W must be integer"
2534 z
) CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
2539 shift $
(($OPTIND - 1))
2541 # If the user specified a flac file, then switch to special flac mode
2542 if echo $CDROM |
grep -i -q '.flac$'; then
2543 vecho
"abcde: switching to flac CDROMREADERSYNTAX..."
2544 CDROMREADERSYNTAX
=flac
2545 if [ "$EJECTCD" = "y" ];then
2546 vecho
"abcde: CDROM flac mode, deactivating EJECTCD..."
2551 # Decide if we can continue.
2552 if [ "$ONETRACK" = "y" ]; then
2553 # FIXME # remove check as soon as we find out about the other readers
2554 case "$CDROMREADERSYNTAX" in
2558 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2561 if [ "$BATCH" = "y" ]; then
2562 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2565 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2566 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2567 if [ $# -gt 0 ]; then
2568 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2571 while [ $# -gt 0 ]; do
2572 # Range parsing code courtesy of Vincent Ho
2573 RSTART
=$
(echo $1 | cut
-f1 -d-)
2574 REND
=$
(echo $1 | cut
-f2 -d-)
2575 if [ "$RSTART" = "$REND" ]; then
2578 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2580 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2585 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2586 # List of experimental actions: retag,transcode
2588 # Determine what actions are to be done from $ACTIONS and set the
2589 # following environment variables for them:
2602 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2607 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2608 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2609 encode
) DOENCODE
=y
; DOREAD
=y
;;
2610 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2611 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2612 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2613 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
2614 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2619 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2620 # FIXME # should we abort on error or just inform the user?
2624 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
2625 case $SHOWCDDBFIELD in
2626 y
*|Y
*) SHOWCDDBYEAR
="y";;
2627 g
*|G
*) SHOWCDDBGENRE
="y";;
2634 # At this point a CDROM has to be defined, so we check it exists.
2635 if [ X
"$CDROM" != "X" ] ; then
2636 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2637 if [ "$OSFLAVOUR" = "FBSD" ]; then
2638 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2639 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2640 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2644 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2645 echo "abcde error: CDROM device cannot be found." >&2
2648 # avoid processing if we are not going to hit the CDROM.
2649 elif [ X
"$DOREAD" = "Xy" ]; then
2650 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2654 # USEPIPES pre-tests, before we get into more serious stuff
2655 # Not compatible with:
2656 # - multiple outputs
2658 # - lowdisk algorithm
2660 if [ X
"$USEPIPES" = "Xy" ]; then
2661 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
2662 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
2665 if [ X
"$DONORMALIZE" = "Xy" ]; then
2666 echo "abcde error: Unix pipes not compatible with normalizer"
2667 # FIXME # Do we need to exit or shall we just disable the mode?
2670 if [ X
"$DOENCODE" = "Xn" ]; then
2671 vecho
"Disabling Unix pipes since we are not encoding!"
2674 if [ X
"$LOWDISK" = "Xy" ]; then
2675 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2680 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2681 if [ X
"$OUTPUTTYPE" = "X" ]; then
2682 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
2683 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2684 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2685 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
2686 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
2687 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2691 if [ X
"$OUTPUTTYPE" = "X" ]; then
2692 echo "abcde error: no encoder found in the PATH" >&2
2693 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2698 # Decide which CDROM reader we're gonna use
2699 case "$CDROMREADERSYNTAX" in
2701 CDROMREADER
="$CDPARANOIA"
2702 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2705 CDROMREADER
="$CDDA2WAV"
2706 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2709 CDROMREADER
="$DAGRAB"
2710 CDROMREADEROPTS
="$DAGRABOPTS"
2713 CDROMREADER
="$CDDAFS"
2714 CDROMREADEROPTS
="$CDDAFSOPTS"
2718 CDROMREADEROPTS
="$FLACOPTS"
2722 # There's only one normalize...
2723 case "$NORMALIZERSYNTAX" in
2725 NORMALIZER
="$NORMALIZE"
2726 NORMALIZEROPTS
="$NORMALIZEOPTS"
2730 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2731 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
2732 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2734 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2735 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2736 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2737 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2738 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2741 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2742 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2743 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2745 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2748 # 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
2750 # Getting ready for multiple output changes
2751 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2755 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2756 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2757 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2758 OGGOUTPUTCONTAINER
=ogg
2761 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2762 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2765 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2766 [ "$REPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
2767 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2770 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
2773 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
2776 if [ "$KEEPWAVS" = "y" ]; then
2777 vecho
"Unsetting the KEEPWAVS option, since the resulting wav files were requested..."
2781 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2787 # decide which encoder
2788 case "$MP3ENCODERSYNTAX" in
2790 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2794 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2798 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2799 MP3ENCODER
="$BLADEENC"
2802 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2806 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2807 MP3ENCODER
="$XINGMP3ENC"
2810 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2811 MP3ENCODER
="$MP3ENC"
2814 case "$OGGENCODERSYNTAX" in
2816 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2817 OGGENCODER
="$VORBIZE"
2820 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2821 OGGENCODER
="$OGGENC"
2824 case "$FLACENCODERSYNTAX" in
2826 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2828 # FLAC streams can be encapsulated on a Ogg transport layer
2829 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2830 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2831 echo " due to problem with adding comments to such files" >&2
2833 FLACOUTPUTCONTAINER
=ogg
2835 FLACOUTPUTCONTAINER
=flac
2839 case "$SPEEXENCODERSYNTAX" in
2841 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2842 SPEEXENCODER
="$SPEEXENC"
2845 case "$MPPENCODERSYNTAX" in
2847 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2848 MPPENCODER
="$MPPENC"
2854 if [ "$ID3TAGV" = "1" ]; then
2856 TAGGEROPTS
="$ID3OPTS"
2859 TAGGEROPTS
="$ID3V2OPTS"
2863 case "$CUEREADERSYNTAX" in
2865 CUEREADEROPTS
="${CDROM}"
2870 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2871 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2872 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2873 echo " due to problem with adding comments to such files" >&2
2875 OGGOUTPUTCONTAINER
=ogg.ogg
2876 FLACOUTPUTCONTAINER
=flac.ogg
2877 vecho
"abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2880 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2882 if [ "$ENCNICE" ]; then
2883 ENCNICE
="-n $ENCNICE"
2885 if [ "$READNICE" ]; then
2886 READNICE
="-n $READNICE"
2888 if [ "$DISTMP3NICE" ]; then
2889 DISTMP3NICE
="-n $DISTMP3NICE"
2892 # Don't check for stuff if it's not needed
2893 if [ "$REMOTEHOSTS" ]; then
2896 if [ "$DONORMALIZE" = "y" ]; then
2899 if [ "$EJECTCD" = "y" ]; then
2902 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2905 if [ "$MAKECUEFILE" = "y" ]; then
2909 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2910 case "$CDROMREADERSYNTAX" in
2911 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2912 ### FIXME ### translate "cue2discid" from python to bash
2913 flac
) NEEDMETAFLAC
=y
; NEEDCUE2DISCID
=y
;;
2918 # Rippers with USEPIPE support
2919 # FIXME # Include here all the rippers we can figure out support pipes
2923 # Encoders with USEPIPE support
2924 # FIXME # Include here all the encoders we can figure out support pipes
2929 # Figure out if we can use pipes with the ripper/encoder combination
2931 if [ "$USEPIPES" = "y" ]; then
2932 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2935 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2937 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2939 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
2941 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2943 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2945 if [ ! -n "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" ] ; then
2946 echo "abcde error: no support for pipes with given ripper" >&2
2947 echo "read the USEPIPES file from the source tarball to get help." >&2
2948 echo "On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz" >&2
2951 if [ ! -n "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" ] ; then
2952 echo "abcde error: no support for pipes with given encoder" >&2
2953 echo "read the USEPIPES file from the source tarball to help" >&2
2954 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2959 # Make sure a buncha things exist
2960 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2961 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2962 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2963 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2964 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2965 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2966 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDCUEREADER+$CUEREADER} \
2967 ${NEEDCUE2DISCID+$CUE2DISCID}
2969 # Cut off the command-line options we just added in
2970 X
=$
(echo $X | cut
-d' ' -f2)
2971 if [ "$(which $X)" = "" ]; then
2972 echo "abcde error: $X is not in your path." >&2
2974 elif [ ! -x $
(which $X) ]; then
2975 echo "abcde error: $X is not executable." >&2
2980 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2981 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2982 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2984 # And last but not least, check if we can diff between files
2985 if [ -x $
(which $DIFF) ]; then :; else
2986 vecho
"[WAR] Disabling diff since we cannot find it in the \$PATH..."
2990 # Here it used to say:
2991 # One thousand lines in, we can start doing stuff with things
2992 # Well, right now we are at line 2736 ;)
2994 # Export needed things so they can be read in this subshell
2995 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2996 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2998 # User-definable function to set some things. Use it for
2999 # - closing the CD tray with eject -t
3000 # - set the CD speed value with eject -x
3001 vecho
-n "Executing customizable pre-read function... "
3003 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
3007 do_discid
# Get ABCDETEMPDIR created and status file initialized
3009 if [ "$DOCDDB" = "y" ]; then
3010 if [ $CDDBUSELOCAL = "y" ]; then
3013 if checkstatus cddb-choice
> /dev
/null
; then
3016 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
3024 eval "$($CDDBTOOL parse "$CDDBDATA")"
3027 # Before reading tracks, we set the speed of the device
3029 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3030 case "$CDROMREADERSYNTAX" in
3031 cdparanoia|debug
) ;;
3037 # Define the first and last track, since we might need them later in several places
3038 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
3039 LASTTRACK
=$
( get_last
$TRACKQUEUE )
3041 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
3042 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3043 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
3044 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
3047 # Create playlist if needed (backgroundable) and start reading in tracks
3051 if [ ! "$ONETRACK" = "y" ]; then
3052 if [ "$DOPLAYLIST" = "y" ]; then
3053 echo Creating playlist...
>&2
3058 # For the lowdisk option, only one program is running at once so the encoder
3059 # can be unsilenced right away.
3060 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3061 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3064 if [ "$ONETRACK" = "y" ]; then
3065 TRACKS
="$FIRSTTRACK"
3066 if checkstatus readtrack-
$FIRSTTRACK; then :; else
3067 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
3070 for UTRACKNUM
in $TRACKQUEUE
3072 if [ "$DOREAD" = "y" ]; then
3073 if [ "$USEPIPES" = "y" ]; then
3074 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
3075 # Read, pipe, shut up!
3076 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
3079 if checkstatus readtrack-
$UTRACKNUM; then :; else
3080 do_cdread
$UTRACKNUM
3082 if [ "$?" != "0" ]; then
3083 # CD read failed - don't give the goahead to
3090 if [ "$BATCH" = "y" ]; then
3093 echo NEXTTRACK
# Get the encoder machine churning again
3094 if [ "$DOREAD" = "y" ]; then
3095 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3096 until checkstatus encodetrack-
$UTRACKNUM
3098 if checkerrors encodetrack-
$UTRACKNUM; then
3109 # Now that we're done the encoding can be loud again -
3110 # if we're not using SMP.
3111 if [ "$MAXPROCS" = "1" ]; then
3112 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3115 # All tracks read, start encoding.
3116 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3120 # Execute the user-defined post_read funtion before ejecting CD
3123 # We are now finished with the cdrom - it can be safely ejected. Note that
3124 # abcde will not have completed yet.
3125 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
3126 # We check if the disk we are processing is actually the disk inside the
3127 # CD tray. If not, we do not eject the CD, since it might be so that the
3128 # user ejected it manually.
3129 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3130 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3131 # More FreeBSD bits.
3132 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
3133 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3134 # but in this script EJECT is in the envionment and names the program
3137 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3138 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3139 $eject $EJECTOPTS $cd
3140 elif [ X
"$(uname)" = X
"Darwin" ] ; then
3141 disktool
-e ${CDROM#/dev/} 0
3143 $EJECT $EJECTOPTS $CDROM
3150 ## Do we need to pre-process
3151 #if [ x"$PREPROCESS" = "x" ] ; then
3154 # for PRETRACKNUM in $TRACKQUEUE
3157 # if [ "$GOAHEAD" = "NO" ]; then break; fi
3159 # until [ $PREPROCEED ]
3161 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3162 # # all locations are working, wait and try again later
3163 # if [ ! $PREPROCEED ]; then sleep 3; fi
3165 # ( do_preprocess $PRETRACKNUM
3173 # In batch mode, we want all tracks to be read first.
3174 if [ "$BATCH" = "y" ]; then
3175 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3176 if [ "$GOAHEAD" = "NO" ]; then break; fi
3177 for LASTTRACK
in $TRACKQUEUE; do :; done
3178 if checkstatus readtrack-
$LASTTRACK; then
3179 if [ "$DONORMALIZE" = "y" ]; then
3180 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
3181 if checkerrors batch-normalize
; then exit; fi
3183 if [ "$DOENCODE" = "y" ]; then
3184 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
3185 if checkerrors batch-encode
; then exit; fi
3190 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3191 if [ "$ONETRACK" = "y" ] ; then
3192 TRACKQUEUE
="$FIRSTTRACK"
3193 TRACKS
="$FIRSTTRACK"
3196 # Do the encoding, including parallelization of remote encoding
3197 # Figure out where each track is going to be encoded
3198 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
3199 if [ "$MAXPROCS" != "0" ]; then
3200 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
3202 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
3206 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
3207 for UTRACKNUM
in $TRACKQUEUE
3210 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3211 if [ "$GOAHEAD" = "NO" ]; then break; fi
3212 # find out where this track is to be encoded
3213 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3214 # Make sure we have a place to encode this, if not, exit stage right
3215 if [ -z "$ENCODELOCATIONS" ]; then
3221 for LOCATION
in $ENCODELOCATIONS
3223 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3224 # check first if a track has ever been assigned to this location
3225 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
3226 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3227 if checkerrors encodetrack-
$PREVIOUSTRACK; then
3228 for TEMPLOCATION
in $ENCODELOCATIONS
3230 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3231 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
3234 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
3239 # We're still here, this location must have been previously assigned,
3240 # and last completed without error - check if it's done with the
3241 # previous track yet
3242 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
3244 # all locations are working, wait and try again later
3245 if [ ! $PROCEED ]; then sleep 3; fi
3247 # Record the location we're about to encode the next track at
3248 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3250 # Don't proceed with the rest of the loop if we can't encode
3251 if [ "$ABORT" ]; then continue; fi
3252 # Set TRACKNUM, TRACKNAME
3253 if [ -e "$CDDBDATA" ]; then
3254 if [ "$ONETRACK" = "y" ]; then
3256 TRACKNUM
="$FIRSTTRACK"
3259 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
3261 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3262 #TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
3263 do_getcddbinfo TRACKNAME
3267 # You can't encode a file which needs to be normalized before finishing
3268 # You can't tag a file before it's finished encoding -
3269 # thus all of this is backgrounded together
3271 if [ "$DONORMALIZE" = "y" ]; then
3272 if checkstatus readtrack-
$UTRACKNUM; then
3273 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3276 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3277 if checkstatus readtrack-
$UTRACKNUM; then
3278 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3279 if [ "$DONORMALIZE" = "y" ]; then
3280 if checkstatus normalizetrack-
$UTRACKNUM; then
3281 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3284 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3288 if [ "$DOTAG" = "y" ]; then
3289 if checkstatus encodetrack-
$UTRACKNUM; then
3290 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3292 # Lets tag the cue file
3293 if checkstatus cleancuefile
>/dev
/null
; then :; else
3294 if checkstatus cuefile
>/dev
/null
; then
3299 if [ "$DOMOVE" = "y" ]; then
3300 if checkstatus tagtrack-
$UTRACKNUM; then
3301 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3308 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3309 # we'll delete the files they're working on
3310 ## FIXME ## Check also for files which are encoded using PIPEs.
3311 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3316 for LOCATION
in $ENCODELOCATIONS
3318 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3319 # "How can he give us a status update, if he's DEAD?"
3320 if checkstatus encodetrack-
$CHECKTRACK; then
3323 # Nothing to see here please go quietly back to your homes
3324 if [ -z "$CHECKTRACK" ]; then continue; fi
3325 # You're still here? Maybe there is something...
3326 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3329 if [ ! $PROCEED ]; then sleep 5; fi
3332 # If the above didn't catch the stragglers, this will
3334 if [ "$REPLAYGAIN" = "y" ]; then
3337 # Check to see if run_command logged any errors
3338 if [ -f "$ABCDETEMPDIR/errors" ]; then
3339 echo "The following commands failed to run:"
3340 cat "$ABCDETEMPDIR/errors"
3344 if [ "$KEEPWAVS" = "y" ];then
3348 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
3349 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
3350 ENCODED_FORMATS
=$
(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f2 |
sort -u |
tr '\n' '|')
3351 MOVED_FORMATS
=$
(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f3 |
sort -u |
tr '\n' '|')
3352 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
3353 echo "Not all encoded formats have been requested to be moved."
3354 echo "Use \"-a clean -f -C $DISCID\" to force the removal of the remaining data."
3358 if [ "$DOCLEAN" = "y" ]; then
3359 # Wipe all the evidence
3360 # Gimme gimme gimme some more time!
3362 rm -rf "$ABCDETEMPDIR"
3365 echo "Finished. Not cleaning $ABCDETEMPDIR."