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 Enable batch normalization"
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 "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
37 echo "-h This help information"
38 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
39 echo "-j <#> Number of encoder processes to run at once (localhost)"
40 echo "-k Keep the wav tracks for later use"
41 echo "-l Use low disk space algorithm"
42 echo "-L Use local CDDB storage directory"
43 echo "-n No lookup. Don't query CDDB, just create and use template"
44 echo "-N Noninteractive. Never prompt for anything"
45 echo "-m Modify playlist to include CRLF endings, to comply with some players"
46 echo "-M Create a CUE file"
47 echo "-o <type1[,type2]...>"
48 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav). Defaults to vorbis"
49 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
50 echo "-P Use UNIX pipes to read+encode without wav files"
51 echo "-r <host1[,host2]...>"
52 echo " Also encode on these remote hosts"
53 echo "-R Add replaygain values to the tag info (only for vorbis,flac)"
55 echo " Show dielfs from the CDDB info (year,genre)"
56 echo "-S <#> Set the CD speed"
57 echo "-t <#> Start the track numbering at a given number"
58 echo "-T <#> Same as -t but modifies tag numbering"
59 echo "-v Show version number and exit"
60 echo "-V Be a bit more verbose about what is happening behind the scenes"
61 echo "-x Eject CD after all tracks are read"
63 echo " Add a comment to the CD tracks"
64 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
65 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
67 echo "Tracks is a space-delimited list of tracks to grab."
68 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
70 #echo "Double hyphens are used to concatenate tracks"
73 # Funtions to replace the need of seq, which is too distribution dependant.
77 while [ $i -ne `expr $2 + 1` ]
87 if echo i |
grep -q "[[:digit:]]" ; then
88 while [ $i -ne `expr $2 + 1` ]
95 echo "abcde: syntax error while processing track numbers" >&2
100 # Functions to replace the need of awk {print $1} and {print $NF}
103 if [ X
"$1" = "X" ]; then
104 for first
in `cat`; do
115 if [ X
"$1" = "X" ]; then
116 for stdin
in `cat`; do
120 for last
in $@
; do :; done
125 # checkstatus [blurb]
126 # Returns "0" if the blurb was found, returns 1 if it wasn't
127 # Puts the blurb content, if available, on stdout.
128 # Otherwise, returns "".
131 # Take the last line in the status file if there's multiple matches
133 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
135 if [ -z "$BLURB" ]; then
140 # See if there's a = in it
141 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
142 echo "$(echo $BLURB | cut -f2- -d=)"
148 # chechwarnings [blurb]
149 # Returns "0" if the blurb was found (meaning there was an warning),
150 # returns 1 if it wasn't (yes this is a little backwards).
151 # Does not print the blurb on stdout.
152 # Otherwise, returns "".
155 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
158 # Take the last line in the status file if there's multiple matches
160 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
162 if [ -z "$BLURB" ]; then
163 # negative, we did not have a negative...
166 # affirmative, we had a negative...
171 # checkerrors [blurb]
172 # Returns "0" if the blurb was found (meaning there was an error),
173 # returns 1 if it wasn't (yes this is a little backwards).
174 # Does not print the blurb on stdout.
175 # Otherwise, returns "".
178 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
181 # Take the last line in the status file if there's multiple matches
183 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
185 if [ -z "$BLURB" ]; then
186 # negative, we did not have a negative...
189 # affirmative, we had a negative...
195 # Finds the right pager in the system to display a file
199 # Use the debian sensible-pager wrapper to pick the pager
200 # user has requested via their $PAGER environment variable
201 if [ -x "/usr/bin/sensible-pager" ]; then
202 /usr
/bin
/sensible-pager
"$PAGEFILE"
203 elif [ -x "$PAGER" ]; then
204 # That failed, try to load the preferred editor, starting
205 # with their PAGER variable
207 # If that fails, check for less
208 elif [ -x /usr
/bin
/less ]; then
209 /usr
/bin
/less -f "$PAGEFILE"
210 # more should be on all UNIX systems
211 elif [ -x /bin
/more ]; then
212 /bin
/more "$PAGEFILE"
214 # No bananas, just cat the thing
219 # run_command [blurb] [command...]
220 # Runs a command, silently if necessary, and updates the status file
225 # See if this is supposed to be silent
226 if [ "$(checkstatus encode-output)" = "loud" ]; then
230 # Special case for SMP, since
231 # encoder output is never displayed, don't mute echos
232 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
241 normalize|normalize-audio
)
242 if [ "$RETURN" = "2" ]; then
243 # File was already normalized.
248 if [ "$RETURN" != "0" ]; then
249 # Put an error in the errors file. For various reasons we
250 # can't capture a copy of the program's output but we can
251 # log what we attempted to execute and the error code
252 # returned by the program.
253 if [ "$BLURB" ]; then
256 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
257 return $RETURN # Do not pass go, do not update the status file
259 if [ "$BLURB" ]; then
260 echo $BLURB >> "$ABCDETEMPDIR/status"
264 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
265 # distributed under the terms of the GNU GPL v2 or later, at your option
267 # Function to determine if a word contains a slash.
276 # Function to give the relative path from one file to another.
277 # Usage: relpath fromfile tofile
278 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
279 # (the result would be Album/Song.mp3)
280 # Output is relative path to $2 from $1 on stdout
282 # This code has the following restrictions:
283 # Multiple ////s are not collapsed into single /s, with strange effects.
284 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
285 # If FR is a directory it must have a trailing /
293 /*) ;; # No processing is needed for absolute paths
295 # Loop through common prefixes, ignoring them.
296 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
298 FR
="$(echo "$FR" | cut -d/ -f2-)"
299 TO
="$(echo "$TO" | cut -d/ -f2-)"
301 # Loop through directory portions left in FR, adding appropriate ../s.
304 FR
="$(echo "$FR" | cut -d/ -f2-)"
314 # Finds an specific field from cddbinfo
316 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
317 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
318 # TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
324 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
327 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
333 # Get the track number we are going to use for different actions
336 if [ -n "$STARTTRACKNUMBER" ] ; then
337 # Get the trackpadding from the current track
338 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
339 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
341 TRACKNUM
=${UTRACKNUM}
347 if checkstatus replaygain
; then :; else
348 run_command
"" echo "Adding replygain information..."
349 for OUTPUT
in $
( echo $OUTPUTTYPE |
tr , \
)
350 # THE OUTPUT NEEDS TO BE CORRECTED WITH THE CONTAINER?
354 OUTPUT
=$OGGOUTPUTCONTAINER
357 OUTPUT
=$FLACOUTPUTCONTAINER
361 for UTRACKNUM
in $TRACKQUEUE
363 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
364 do_getcddbinfo TRACKNAME
366 TRACKFILE
="$(mungefilename "$TRACKNAME")"
367 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
368 ALBUMFILE
="$(mungefilename "$DALBUM")"
370 if [ "$VARIOUSARTISTS" = "y" ]; then
371 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
373 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
375 OUTPUTFILES
="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT $OUTPUTFILES"
379 run_command replaygain-flac
$METAFLAC --add-replay-gain $OUTPUTFILES
382 run_command replaygain-vorbis
$VORBISGAIN --album $OUTPUTFILES
387 if checkerrors replaygain-.
{3,6}; then :; else
388 run_command replaygain true
393 # This code splits the a Various Artist track name from one of the following
396 # forward: Artist / Track
397 # forward-dash: Artist - Track
398 # reverse: Track / Artist
399 # reverse-dash: Track - Artist
400 # colon: Artist: Track
401 # trailing-paren: Artist (Track)
404 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
407 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
408 case "$VARIOUSARTISTSTYLE" in
410 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
411 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
412 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
415 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
416 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
417 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
420 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
421 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
422 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
425 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
426 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
427 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
430 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's-: -~-g')"
431 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
432 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
435 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
436 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
437 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
440 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
441 TRACKARTIST
="Various"
443 TRACKARTIST
="$DARTIST"
448 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
452 "classic rock") id
=1 ;;
470 "industrial") id
=19 ;;
471 "alternative") id
=20 ;;
473 "death metal") id
=22 ;;
475 "soundtrack") id
=24 ;;
476 "euro-techno") id
=25 ;;
480 "jazz+funk") id
=29 ;;
483 "classical") id
=32 ;;
484 "instrumental") id
=33 ;;
488 "sound clip") id
=37 ;;
491 "alt. rock") id
=40 ;;
496 "meditative") id
=45 ;;
497 "instrum. pop") id
=46 ;;
498 "instrum. rock") id
=47 ;;
502 "techno-indust.") id
=51 ;;
503 "electronic") id
=52 ;;
505 "eurodance") id
=54 ;;
507 "southern rock") id
=56 ;;
512 "christian rap") id
=61 ;;
513 "pop/funk"|
"pop / funk") id
=62 ;;
515 "native american") id
=64 ;;
518 "psychadelic") id
=67 ;;
520 "showtunes") id
=69 ;;
524 "acid punk") id
=73 ;;
525 "acid jazz") id
=74 ;;
529 "rock & roll") id
=78 ;;
530 "hard rock") id
=79 ;;
532 "folk/rock") id
=81 ;;
533 "national folk") id
=82 ;;
540 "bluegrass") id
=89 ;;
541 "avantgarde") id
=90 ;;
542 "gothic rock") id
=91 ;;
543 "progress. rock") id
=92 ;;
544 "psychadel. rock") id
=93 ;;
545 "symphonic rock") id
=94 ;;
546 "slow rock") id
=95 ;;
549 "easy listening") id
=98 ;;
555 "chamber music") id
=104 ;;
557 "symphony") id
=106 ;;
558 "booty bass") id
=107 ;;
560 "porn groove") id
=109 ;;
562 "slow jam") id
=111 ;;
566 "folklore") id
=115 ;;
568 "power ballad") id
=117 ;;
569 "rhythmic soul") id
=118 ;;
570 "freestyle") id
=119 ;;
572 "punk rock") id
=121 ;;
573 "drum solo") id
=122 ;;
574 "a capella") id
=123 ;;
575 "euro-house") id
=124 ;;
576 "dance hall") id
=125 ;;
578 "drum & bass") id
=127 ;;
579 "club-house") id
=128 ;;
580 "hardcore") id
=129 ;;
584 "negerpunk") id
=133 ;;
585 "polsk punk") id
=134 ;;
587 "christian gangsta rap") id
=136 ;;
588 "heavy metal") id
=137 ;;
589 "black metal") id
=138 ;;
590 "crossover") id
=139 ;;
591 "contemporary christian")id
=140 ;;
592 "christian rock") id
=141 ;;
593 "merengue") id
=142 ;;
595 "thrash metal") id
=144 ;;
598 "synthpop") id
=147 ;;
599 "rock/pop"|
"rock / pop") id
=148 ;;
606 # do_tag [tracknumber]
607 # id3 tags a filename
609 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
610 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
613 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
614 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
615 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
616 # If we want to start the tracks with a given number, we need to modify the
617 # TRACKNUM value before evaluation
618 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
621 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
625 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
626 GENREID
=$
(do_getgenreid
"${CDGENRE}")
631 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
632 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
633 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
634 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
635 "${ENCODING:+--set-encoding=$ENCODING}"
636 "$ABCDETEMPDIR/track$1.$OUTPUT"
639 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
640 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
641 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
642 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
643 "$ABCDETEMPDIR/track$1.$OUTPUT"
648 case "$OGGENCODERSYNTAX" in
650 # vorbiscomment can't do in-place modification, mv the file first
651 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
652 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
655 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
656 echo ARTIST
="$TRACKARTIST"
658 echo TITLE
="$TRACKNAME"
659 if [ -n "$CDYEAR" ]; then
662 if [ -n "$CDGENRE" ]; then
663 echo GENRE
="$CDGENRE"
665 echo TRACKNUMBER
=${TRACKNUM:-$1}
666 echo CDDB
=$CDDBDISCID
667 if [ "$(eval echo ${COMMENT})" != "" ]; then
668 case "$COMMENTOUTPUT" in
669 *=*) echo "$COMMENTOUTPUT";;
670 *) echo COMMENT
="$COMMENTOUTPUT";;
673 ) | run_command tagtrack-
$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
674 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
675 # Doublecheck that the commented file was created successfully before wiping the original
676 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
677 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
679 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
686 echo ARTIST
="$TRACKARTIST"
688 echo TITLE
="$TRACKNAME"
689 if [ -n "$CDYEAR" ]; then
692 if [ -n "$CDGENRE" ]; then
693 echo GENRE
="$CDGENRE"
695 echo TRACKNUMBER
="${TRACKNUM:-$1}"
696 echo CDDB
="$CDDBDISCID"
697 if [ "$(eval echo ${COMMENT})" != "" ]; then
698 case "$COMMENTOUTPUT" in
699 *=*) echo "$COMMENTOUTPUT";;
700 *) echo COMMENT
="$COMMENTOUTPUT";;
703 ) | run_command tagtrack-
$OUTPUT-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
706 run_command tagtrack-
$OUTPUT-$1 true
709 run_command tagtrack-
$OUTPUT-$1 true
712 run_command tagtrack-
$OUTPUT-$1 true
716 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
717 run_command tagtrack-
$1 true
724 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
727 # The commands here don't go through run_command because they're never supposed to be silenced
728 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
729 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
733 case "$MP3ENCODERSYNTAX" in
738 for UTRACKNUM
in $TRACKQUEUE
740 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
742 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
744 if [ "$RETURN" != "0" ]; then
745 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
747 for UTRACKNUM
in $TRACKQUEUE
749 run_command encodetrack-
$OUTPUT-$UTRACKNUM true
750 #run_command encodetrack-$UTRACKNUM true
759 if checkerrors
"nogap-encode"; then :; else
760 if [ ! "$KEEPWAVS" = "y" ] ; then
761 if [ ! "$KEEPWAVS" = "move" ] ; then
766 # Other encoders fall through to normal encoding as the tracks
767 # have not been entered in the status file.
770 # do_encode [tracknumber] [hostname]
771 # If no hostname is specified, encode locally
773 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
776 if [ "$USEPIPES" = "y" ]; then
779 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
782 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
785 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
788 TEMPARG
="PIPE_$SPEEXENCODER"
791 TEMPARG
="PIPE_$MPPENCODER"
794 IN
="$( eval echo "\$
$TEMPARG" )"
796 IN
="$ABCDETEMPDIR/track$1.wav"
799 case "$MP3ENCODERSYNTAX" in
800 # FIXME # check if mp3enc needs -if for pipes
801 # FIXME # I have not been able to find a working mp3enc binary
815 # We need IN to proceed, if we are not using pipes.
816 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
817 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
819 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-
$OUTPUT-$1 ; then
824 OUT
="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
827 OUT
="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
830 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
833 if [ X
"$USEPIPES" = "Xy" ]; then
836 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
837 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
843 case "$MP3ENCODERSYNTAX" in
844 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
845 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
846 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
847 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
848 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
852 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
859 case "$OGGENCODERSYNTAX" in
860 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
861 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
865 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
872 case "$FLACENCODERSYNTAX" in
873 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
879 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
880 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
885 if [ "$(eval echo ${COMMENT})" != "" ]; then
888 *) COMMENT
="COMMENT=$COMMENT" ;;
890 COMMENT
="--comment \"$COMMENT\""
892 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
893 if [ ! "$DOTAG" = "y" ]; then
894 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
896 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
900 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
902 # I tried compiling the mppenc from corecodecs.org and got some
903 # errors, so I have not tried it myself.
904 ## FIXME ## Needs some cleanup to determine if an empty tag sent
905 ## FIXME ## to the encoder ends up empty.
906 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
909 # In case of wav output we need nothing. Just keep the wavs.
910 run_command encodetrack-
$OUTPUT-$1 true
914 # Only remove .wav if the encoding succeeded
915 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
916 run_command encodetrack-
$1 true
917 if [ ! "$KEEPWAVS" = "y" ] ; then
918 if [ ! "$KEEPWAVS" = "move" ] ; then
924 run_command
"" echo "HEH! The file we were about to encode disappeared:"
925 run_command
"" echo ">> $IN"
926 run_command encodetrack-
$1 false
930 # do_preprocess [tracknumber]
932 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
935 # IN="$ABCDETEMPDIR/track$1.wav"
936 # # We need IN to proceed.
937 # if [ -s "$IN" ] ; then
938 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
940 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
941 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
942 # case "$POSTPROCESSFORMAT" in
944 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
946 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
948 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
950 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
952 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
955 # # Only remove .wav if the encoding succeeded
956 # if checkerrors "preprocess-(.{3,4})-$1"; then
957 # run_command preprocess-$1 false
959 # run_command preprocess-$1 true
962 # if [ "$(checkstatus encode-output)" = "loud" ]; then
963 # echo "HEH! The file we were about to pre-process disappeared:"
966 # run_command preprocess-$1 false
971 # do_postprocess [tracknumber]
973 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
976 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
978 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
979 # # We need IN to proceed.
980 # if [ -s "$IN" ] ; then
981 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
982 # run_command '' echo "Post-processing track $1 of $TRACKS..."
983 # case "$POSTPROCESSFORMAT" in
985 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
987 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
989 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
991 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
993 # # Only remove .wav if the encoding succeeded
994 # if checkerrors "postprocess-(.{3,4})-$1"; then
995 # run_command postprocess-$1 false
997 # run_command postprocess-$1 true
1000 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1001 # echo "HEH! The file we were about to post-process disappeared:"
1004 # run_command postprocess-$1 false
1019 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
1023 # The commands here don't go through run_command because they're never supposed to be silenced
1024 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1029 for UTRACKNUM
in $TRACKQUEUE
1031 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1033 # FIXME # Hard-coded batch option!
1034 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1036 if [ "$RETURN" != "0" ]; then
1037 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1039 for UTRACKNUM
in $TRACKQUEUE
1041 echo normalizetrack-
$UTRACKNUM >> status
1047 # do_batch_normalize
1049 # NORMALIZER, NORMALIZEROPTS
1050 do_batch_normalize
()
1052 # The commands here don't go through run_command because they're never supposed to be silenced
1053 echo "Batch normalizing tracks: $TRACKQUEUE"
1058 for UTRACKNUM
in $TRACKQUEUE
1060 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1062 # XXX: Hard-coded batch option!
1063 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1065 if [ "$RETURN" != "0" ]; then
1066 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1068 for UTRACKNUM
in $TRACKQUEUE
1070 echo normalizetrack-
$UTRACKNUM >> status
1076 # do_normalize [tracknumber]
1078 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1081 IN
="$ABCDETEMPDIR/track$1.wav"
1082 if [ -e "$IN" ] ; then
1083 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1084 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1086 if [ "$(checkstatus encode-output)" = "loud" ]; then
1087 echo "HEH! The file we were about to normalize disappeared:"
1090 run_command normalizetrack-
$1 false
"File $IN was not found"
1094 # do_move [tracknumber]
1095 # Deduces the outfile from environment variables
1096 # Creates directory if necessary
1098 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1101 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1103 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1104 # Munge filenames as follows:
1109 # Eat control characters
1110 ALBUMFILE
="$(mungefilename "$DALBUM")"
1111 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1112 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1113 GENRE
="$(mungegenre "$GENRE")"
1114 YEAR
="$(echo $CDYEAR)"
1115 # If we want to start the tracks with a given number, we need to modify the
1116 # TRACKNUM value before evaluation
1118 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1119 # TRACKFILE, and TRACKNUM.
1120 if [ "$VARIOUSARTISTS" = "y" ]; then
1121 OUTPUTFILE
="$(eval echo "$VAOUTPUTFORMAT")"
1123 OUTPUTFILE
="$(eval echo "$OUTPUTFORMAT")"
1125 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1126 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1129 OUTPUT
=$OGGOUTPUTCONTAINER
1132 OUTPUT
=$FLACOUTPUTCONTAINER
1135 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1136 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1139 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1140 # FIXME # introduce warnings?
1143 # mkdir -p shouldn't return an error if the directory already exists
1144 mkdir
-p "$OUTPUTFILEDIR"
1145 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1146 if checkstatus movetrack-output-
$OUTPUT; then :; else
1147 run_command movetrack-output-
$OUTPUT true
1152 # mkdir -p shouldn't return an error if the directory already exists
1153 mkdir
-p "$OUTPUTFILEDIR"
1154 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1155 if checkstatus movetrack-output-
$OUTPUT; then :; else
1156 run_command movetrack-output-
$OUTPUT true
1160 # Lets move the cue file
1161 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1162 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1163 if checkstatus movecue-
$OUTPUT; then :; else
1164 # Silence the Copying output since it overlaps with encoding processes...
1165 #run_command '' vecho "Copying cue file to its destination directory..."
1166 if checkstatus onetrack
>/dev
/null
; then
1169 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1170 # We dont have the dir, since it was not created before.
1173 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1176 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1177 # http://brianvictor.tripod.com/mp3cue.htm#details
1178 [a-z0-9
][a-z0-9
][a-z0-9
])
1179 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1182 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1186 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1188 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1197 # Create the playlist if wanted
1199 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1200 # VARIOUSARTISTS, OUTPUTDIR
1203 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1207 OUTPUT
=$OGGOUTPUTCONTAINER
1210 OUTPUT
=$FLACOUTPUTCONTAINER
1213 # Create a playlist file for the playlist data to go into.
1214 # We used to wipe it out if it existed. Now we request permision if interactive.
1215 for LASTTRACK
in $TRACKQUEUE; do :; done
1216 ALBUMFILE
="$(mungefilename "$DALBUM")"
1217 ARTISTFILE
="$(mungefilename "$DARTIST")"
1218 GENRE
=$
(mungegenre
"$GENRE")
1219 YEAR
=${CDYEAR:-$CDYEAR}
1220 if [ "$VARIOUSARTISTS" = "y" ] ; then
1221 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
1223 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
1225 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1226 mkdir
-p "$FINALPLAYLISTDIR"
1227 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1228 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1229 if [ "$INTERACTIVE" = "y" ]; then
1230 while [ "$DONE" != "y" ]; do
1232 case $ERASEPLAYLIST in
1233 e|E|a|A|k|K
) DONE
=y
;;
1241 # Once we erase the playlist, we use append to create the new one.
1242 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1244 # The playlist does not exist, so we can safelly use append to create the new list
1247 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1248 touch "$OUTPUTDIR/$PLAYLISTFILE"
1249 for UTRACKNUM
in $TRACKQUEUE
1251 # Shares some code with do_move since the filenames have to match
1252 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1253 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1254 do_getcddbinfo TRACKNAME
1256 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1257 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1258 ALBUMFILE
="$(mungefilename "$DALBUM")"
1259 # If we want to start the tracks with a given number, we need to modify the
1260 # TRACKNUM value before evaluation
1262 if [ "$VARIOUSARTISTS" = "y" ]; then
1263 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1265 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1267 if [ "$VARIOUSARTISTS" = "y" ]; then
1268 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1269 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1271 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1274 if [ "$PLAYLISTDATAPREFIX" ]; then
1275 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1277 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1282 ## this will convert the playlist to have CRLF line-endings, if specified
1283 ## (some hardware players insist on CRLF endings)
1284 if [ "$DOSPLAYLIST" = "y" ]; then
1285 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1286 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1287 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1289 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1294 # This essentially the start of things
1297 # Query the CD to get the track info, unless the user specified -C
1298 # or we are using some actions which do not need the CDDB data at all
1299 #if [ ! X"$EXPACTIONS" = "X" ]; then
1301 #elif [ -z "$DISCID" ]; then
1302 if [ -z "$DISCID" ]; then
1303 vecho
-n "Getting CD track info... "
1304 # In OSX, unmount the disc before a query
1305 if [ "$OSFLAVOUR" = "OSX" ]; then
1306 disktool
-u ${CDROM#/dev/}
1308 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1309 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM |
$CUE2DISCID)
1311 TRACKINFO
=$
($CDDISCID $CDROM)
1313 # Make sure there's a CD in there by checking cd-discid's return code
1314 if [ ! "$?" = "0" ]; then
1315 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1316 echo "abcde error: cuesheet information from the flac file could not be read." >&2
1317 echo "abcde error: Perhaps the flac file does not contain a cuesheet?." >&2
1320 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1324 # In OSX, remount the disc again
1325 if [ "$OSFLAVOUR" = "OSX" ]; then
1326 disktool
-m ${CDROM#/dev/}
1330 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1333 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1334 # This needs to be done now because a section of the resuming code will need
1337 # get the number of digits to pad TRACKNUM with - we'll use this later
1338 # a CD can only hold 99 tracks, but since we support a feature for starting
1339 # numbering the tracks from a given number, we might need to set it as a
1340 # variable for the user to define... or obtain it somehow.
1341 if [ "$PADTRACKS" = "y" ] ; then
1345 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1346 if [ -z "$TRACKQUEUE" ]; then
1347 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1348 case "$CDROMREADERSYNTAX" in
1350 if [ "$WEHAVEACD" = "y" ]; then
1351 vecho
"Querying the CD for audio tracks..."
1352 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1354 if [ ! "$RET" = "0" ];then
1355 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1357 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1358 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1360 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1361 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1365 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1368 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1370 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1371 echo "The disc does not contain any tracks. Giving up..."
1374 echo -n "Grabbing entire CD - tracks: "
1375 if [ ! "$PADTRACKS" = "y" ] ; then
1376 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1378 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1380 while [ "$X" -ne "$TRACKS" ]
1382 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1383 TRACKQUEUE
=$
(echo $TRACKQUEUE $X)
1387 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1388 # User-supplied track queue.
1389 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1390 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1391 # Once cleaned, obtain the highest value in the trackqueue for number padding
1392 for LASTTRACK
in $TRACKQUEUE; do :; done
1393 if [ ! "$PADTRACKS" = "y" ] ; then
1394 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1396 # Now we normalize the trackqueue
1397 for TRACK
in $TRACKQUEUE ; do
1398 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1399 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1401 TRACKQUEUE
=$PADTRACKQUEUE
1402 echo Grabbing tracks
: "$TRACKQUEUE"
1405 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1407 # We have the discid, create a temp directory after it to store all the temp
1410 if [ -e "$ABCDETEMPDIR" ]; then
1411 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1412 # It already exists, see if it's a directory
1413 if [ ! -d "$ABCDETEMPDIR" ]; then
1414 # This is a file/socket/fifo/device/etc, not a directory
1417 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1418 echo "Please investigate, remove it, and rerun abcde." >&2
1422 # It's a directory, let's see if it's owned by us
1423 if [ ! -O "$ABCDETEMPDIR" ]; then
1424 # Nope, complain and exit
1426 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1427 echo "Please investigate, remove it, and rerun abcde." >&2
1431 # See if it's populated
1432 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1433 # Wipe and start fresh
1434 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1435 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1436 if [ "$INTERACTIVE" = "y" ]; then
1442 if [ "$ANSWER" != "y" ]; then
1445 rm -rf "$ABCDETEMPDIR" ||
exit 1
1446 mkdir
"$ABCDETEMPDIR"
1447 if [ "$?" -gt "0" ]; then
1448 # Directory already exists or could not be created
1449 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1453 # Everything is fine. Check for ^encodetracklocation-
1454 # and encode-output entries in the status file and
1455 # remove them. These are not relevant across sessions.
1456 if [ -f "$ABCDETEMPDIR/status" ]; then
1457 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1458 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1459 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1461 # Remove old error messages
1462 if [ -f "$ABCDETEMPDIR/errors" ]; then
1463 rm -f "$ABCDETEMPDIR/errors"
1467 # We are starting from scratch
1468 mkdir
"$ABCDETEMPDIR"
1469 if [ "$?" -gt "0" ]; then
1470 # Directory already exists or could not be created
1471 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1474 cat /dev
/null
> "$ABCDETEMPDIR/status"
1476 if [ X
"$MAKECUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1477 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1478 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1479 vecho
"Creating cue file..."
1480 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1481 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1483 echo "abcde: reading the CUE sheet with mkcue is still considered experimental"
1484 echo "abcde: and there was a problem with the CD reading. abcde will continue,"
1485 echo "abcde: but consider reporting the problem to the abcde author"
1489 # If we got the CDPARANOIA status and it is not recorded, save it now
1490 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1491 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
1492 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1496 # Create the discid file
1497 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1501 # Create a proper CUE file based on the CUE file we created before.
1504 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1505 CUEFILE_OUT
=$CUEFILE_IN.out
1506 ### FIXME ### checkstatus cddb
1507 if [ -e "$CDDBDATA" ]; then
1508 vecho
"Adding metadata to the cue file..."
1509 # FIXME It doesn't preserve spaces! Why?
1510 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1512 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1513 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1514 cat "$CUEFILE_IN" |
while read line
1516 if echo "$line" |
grep -q "INDEX"
1518 eval track
="\$TRACK$n"
1520 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1522 echo "$line" >> "$CUEFILE_OUT"
1524 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1525 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1531 # Parses a CDDB file and outputs the title and the track names.
1532 # Variables: CDDBFILE
1536 # List out disc title/author and contents
1537 if [ "$ONETRACK" = "y" ]; then
1538 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1540 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1541 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1542 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1543 if [ ! X
"$PARSEDYEAR" = "X" ]; then
1544 echo "Year: $PARSEDYEAR"
1547 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1548 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1549 if [ ! X
"$PARSEDGENRE" = "X" ]; then
1550 echo "Genre: $PARSEDGENRE"
1553 if [ ! "$ONETRACK" = "y" ]; then
1554 for TRACK
in $
(f_seq_row
1 $TRACKS)
1556 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1562 # Check for a local CDDB file, and report success
1565 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1567 CDDBLOCALSUCCESS
="n"
1568 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1569 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1572 # If the user has selected to check a local CDDB repo, we proceed with it
1573 if [ -r "${CDDBLOCALFILE}" ]; then
1574 # List out disc title/author and contents
1575 do_cddbparse
"${CDDBLOCALFILE}"
1576 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1577 if [ "$INTERACTIVE" = "y" ]; then
1579 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1580 echo -n 'Invalid selection. Please answer "y" or "n": '
1583 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1587 if [ "$USELOCALRESP" = "y" ]; then
1588 #echo "Using local copy of CDDB data"
1589 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1590 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
1591 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1592 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1593 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1594 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1595 CDDBLOCALSUCCESS
="y"
1597 #echo "Not using local copy of CDDB data"
1598 CDDBLOCALSUCCESS
="n"
1601 CDDBLOCALSUCCESS
="n"
1609 # Perform CDDB protocol version check if it hasn't already been done
1610 if checkstatus cddb-statcomplete
; then :; else
1611 if [ "$CDDBAVAIL" = "n" ]; then
1613 echo 503 > "$ABCDETEMPDIR/cddbstat"
1616 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1617 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1618 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1619 vecho
"Checking CDDB server status..."
1620 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1621 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1622 case "$RESPONSECODE" in
1623 210) # 210 OK, status information follows (until terminating `.')
1626 501|
*) # 501 Illegal CDDB protocol level: <n>.
1627 CDDBPROTO
=`expr $CDDBPROTO - 1`
1631 if test $rc -eq 1; then
1635 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1643 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1644 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1646 # Perform CDDB query if it hasn't already been done
1647 if checkstatus cddb-querycomplete
; then :; else
1648 if [ "$CDDBAVAIL" = "n" ]; then
1650 echo 503 > "$ABCDETEMPDIR/cddbquery"
1651 # The default CDDBLOCALSUCCESS is "n"
1652 # This part will be triggered if the user CDDB repo does not
1653 # contain the entry, or if we are not trying to use the repo.
1655 vecho
"Querying the CDDB server..."
1656 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1657 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1658 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1664 # no match found in database,
1665 # wget/fetch error, or user requested not to use CDDB
1666 # Make up an error code (503) that abcde
1667 # will recognize in do_cddbread
1668 # and compensate by making a template
1669 echo 503 > "$ABCDETEMPDIR/cddbquery"
1671 *) # strange and unknown error
1672 echo ERRORCODE
=$ERRORCODE
1673 echo "abcde: $CDDBTOOL returned unknown error code"
1677 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1684 # If it's not to be used, generate a template.
1685 # Then, display it (or them) and let the user choose/edit it
1686 if checkstatus cddb-readcomplete
; then :; else
1687 vecho
"Obtaining CDDB results..."
1688 # If CDDB is to be used, interpret the query results and read all
1689 # the available entries.
1690 rm -f "$ABCDETEMPDIR/cddbchoices"
1691 CDDBCHOICES
=1 # Overridden by multiple matches
1692 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1693 case "$RESPONSECODE" in
1695 # One exact match, retrieve it
1696 # 200 [section] [discid] [artist] / [title]
1697 if checkstatus cddb-read-1-complete
; then :; else
1698 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1699 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1700 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1701 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1702 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1704 # List out disc title/author and contents
1705 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1706 for TRACK
in $
(f_seq_row
1 $TRACKS)
1708 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1710 echo >> "$ABCDETEMPDIR/cddbchoices"
1714 case "$RESPONSECODE" in
1715 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1716 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1717 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1719 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1720 # List out disc title/author and contents of template
1721 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1723 for TRACK
in $
(f_seq_row
1 $TRACKS)
1725 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1727 echo >> "$ABCDETEMPDIR/cddbchoices"
1728 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1729 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1732 # Multiple exact, (possibly multiple) inexact matches
1734 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1735 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
1736 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1737 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1738 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1740 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1742 vecho
-n "Retrieving multiple matches... "
1743 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1744 read DISCINFO
# eat top line
1748 if checkstatus cddb-read-
$X-complete; then :; else
1749 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1750 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1752 # List out disc title/author and contents
1753 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1754 for TRACK
in $
(f_seq_row
1 $TRACKS)
1756 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1758 echo >> "$ABCDETEMPDIR/cddbchoices"
1761 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1765 for TRACK
in $
(f_seq_row
1 $TRACKS)
1767 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1769 echo >> "$ABCDETEMPDIR/cddbchoices"
1770 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1771 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1774 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1781 if checkstatus cddb-edit
>/dev
/null
; then
1782 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1783 VARIOUSARTISTS
="$(checkstatus variousartists)"
1784 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1787 if [ "$INTERACTIVE" = "y" ]; then
1788 # We should show the CDDB results both when we are not using the local CDDB repo
1789 # or when we are using it but we could not find a proper match
1790 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1791 # Display the $ABCDETEMPDIR/cddbchoices file created above
1792 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1793 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1794 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1795 CHOICE
=$
(checkstatus cddb-choice
)
1796 if [ -n "$CHOICE" ] ; then
1797 case $CDDBCHOICES in
1798 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1800 echo "Selected: #$CHOICE"
1801 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1805 # The user has a choice to make, display the info in a pager if necessary
1806 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1807 page
"$ABCDETEMPDIR/cddbchoices"
1809 # It's all going to fit in one page, cat it
1810 cat "$ABCDETEMPDIR/cddbchoices" >&2
1814 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1816 # I'll take CDDB read #3 for $400, Alex
1817 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1818 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1820 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1821 if echo $CDDBCHOICE |
egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1822 if [ ! X
"$DIFF" = "X" ]; then
1823 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1)
1824 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2)
1825 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1826 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1827 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1828 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1831 # We parse the 2 choices to diff, store them in temporary files and diff them.
1832 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
1833 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1835 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1836 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1837 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
1838 page
"$ABCDETEMPDIR/cddbread.diff"
1840 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1844 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1847 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1848 # Make sure we get a valid choice
1849 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1850 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1854 if [ "$CDCHOICENUM" = "0" ]; then
1855 vecho
"Creating empty CDDB template..."
1857 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1859 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1860 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1862 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1866 # We need some code to show the selected option when local repository is selected and we have found a match
1867 vecho
"Using cached CDDB match..." >&2
1868 # Display the $ABCDETEMPDIR/cddbchoices file created above
1869 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1870 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1871 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1872 CHOICE
=$
(checkstatus cddb-choice
)
1873 if [ "$USELOCALRESP" = "y" ]; then :; else
1874 if [ -n "$CHOICE" ] ; then
1875 case $CDDBCHOICES in
1878 echo "Selected template."
1880 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1882 echo "Selected: #$CHOICE"
1883 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1891 # We're noninteractive - pick the first choice.
1892 # But in case we run a previous instance and selected a choice, use it.
1893 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1894 # Show the choice if we are not using the locally stored one
1895 # or when the local search failed to find a match.
1896 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1897 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1898 #if [ "$PREVIOUSCHOICE" ]; then
1899 cat "$ABCDETEMPDIR/cddbchoices"
1902 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1903 CDCHOICENUM
=$PREVIOUSCHOICE
1906 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1908 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1913 if checkstatus cddb-choice
>/dev
/null
; then :; else
1914 echo "abcde: internal error: cddb-choice not recorded." >&2
1917 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1918 echo -n "Edit selected CDDB data? [y/n] (" >&2
1919 if [ "$INTERACTIVE" = "y" ]; then
1920 if [ "$UNKNOWNDISK" = "y" ]; then
1923 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1932 if [ "$EDITCDDB" = "y" ]; then
1933 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1935 # Use the debian sensible-editor wrapper to pick the editor that the
1936 # user has requested via their $EDITOR environment variable
1937 if [ -x "/usr/bin/sensible-editor" ]; then
1938 /usr
/bin
/sensible-editor
"$CDDBDATA"
1939 elif [ -n "$EDITOR" ]; then
1940 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1941 # That failed, try to load the preferred editor, starting
1942 # with their EDITOR variable
1943 eval $
(echo "$EDITOR") \"$CDDBDATA\"
1945 # If that fails, check for a vi
1946 elif which vi
>/dev
/null
2>&1; then
1948 elif [ -x /usr
/bin
/vim
]; then
1949 /usr
/bin
/vim
"$CDDBDATA"
1950 elif [ -x /usr
/bin
/vi
]; then
1951 /usr
/bin
/vi
"$CDDBDATA"
1952 elif [ -x /bin
/vi
]; then
1954 # nano should be on all (modern, i.e., sarge) debian systems
1955 elif which nano
>/dev
/null
2>&1 ; then
1957 elif [ -x /usr
/bin
/nano
]; then
1958 /usr
/bin
/nano
"$CDDBDATA"
1959 # mg should be on all OpenBSD systems
1960 elif which mg
>/dev
/null
2>&1 ; then
1962 elif [ -x /usr
/bin
/mg
]; then
1963 /usr
/bin
/mg
"$CDDBDATA"
1966 echo "No editor available. Check your EDITOR environment variable." >&2
1968 # delete editor backup file if it exists
1969 if [ -w "$CDDBDATA~" ]; then
1974 # Some heuristics first. Look at Disc Title, and if it starts with
1975 # "Various", then we'll assume Various Artists
1976 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1977 echo "Looks like a Multi-Artist CD" >&2
1980 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1981 if [ "$INTERACTIVE" = "y" ]; then
1988 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1991 # Need NUMTRACKS before cddb-tool will return it:
1992 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1993 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1994 # More than 1/2 tracks contain a "/", so guess forward
1996 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1997 # More than 1/2 contain a "-", so guess forward-dash
1999 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2000 # More than 1/2 contain something in parens, so guess trailing-paren
2004 echo "1) Artist / Title" >&2
2005 echo "2) Artist - Title" >&2
2006 echo "3) Title / Artist" >&2
2007 echo "4) Title - Artist" >&2
2008 echo "5) Artist: Title" >&2
2009 echo "6) Title (Artist)" >&2
2010 echo "7) This is a single-artist CD" >&2
2011 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2012 if [ "$INTERACTIVE" = "y" ]; then
2013 read VARIOUSARTISTSTYLE
2015 echo $DEFAULTSTYLE >&2
2016 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2018 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2019 # If they press Enter, then the default style (0) was chosen
2020 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2021 echo "Invalid selection. Please choose a number between 1 and 7."
2022 echo -n "Selection [1-7]: "
2023 read VARIOUSARTISTSTYLE
2024 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2026 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2027 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2029 vecho
"Selected: $VARIOUSARTISTSTYLE"
2030 case "$VARIOUSARTISTSTYLE" in
2032 VARIOUSARTISTSTYLE
=forward
2035 VARIOUSARTISTSTYLE
=forward-dash
2038 VARIOUSARTISTSTYLE
=reverse
2041 VARIOUSARTISTSTYLE
=reverse-dash
2044 VARIOUSARTISTSTYLE
=colon
2047 VARIOUSARTISTSTYLE
=trailing-paren
2055 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2056 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2058 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2059 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2060 # This works but does not have the necessary error checking
2061 # yet. If you are familiar with the CDDB spec
2062 # (see http://www.freedb.org/src/latest/DBFORMAT)
2063 # and can create an error-free entry on your own, then put
2064 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2065 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2066 # your abcde.conf to change the email address submissions are
2069 # submit the modified file, if they want
2070 if [ "$NOSUBMIT" != "y" ]; then
2071 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2073 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2074 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2076 echo -n 'Invalid selection. Please answer "y" or "n": '
2079 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2080 echo -n "Sending..."
2081 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2087 # Make sure the cache directory exists
2088 mkdir
-p $CDDBLOCALDIR
2089 # Cache edited CDDB entry in the user's cddb dir
2090 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
2091 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2094 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2097 # do_cdread [tracknumber]
2098 # do_cdread onetrack [firsttrack] [lasttrack]
2102 # The commands here don't go through run_command because they're never supposed to be silenced
2103 # return codes need to be doublechecked anyway, however
2104 if [ "$1" = "onetrack" ]; then
2105 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2106 # FIXME # Until then, we grab the whole CD in one track, no matter what
2108 # We need the first and last track for cdda2wav
2111 UTRACKNUM
=$FIRSTTRACK
2112 case "$CDROMREADERSYNTAX" in
2113 ### FIXME ### How are we calculating the tracks in flac mode?
2114 flac
) READTRACKNUMS
="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2115 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
2116 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTRACK" ;;
2117 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2123 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2124 if [ "$USEPIPES" = "y" ]; then
2125 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
2126 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2128 PIPE_MESSAGE
="and encoding "
2130 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2131 case "$CDROMREADERSYNTAX" in
2132 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2134 FILEARG
="--output-name=$WAVDATA"
2137 FILEARG
="-f $WAVDATA"
2145 if [ "$1" = "onetrack" ]; then
2146 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2148 if [ -r "$CDDBDATA" ]; then
2149 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
2150 do_getcddbinfo TRACKNAME
2151 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2153 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2156 case "$CDROMREADERSYNTAX" in
2157 ### FIXME ### use an exception for flac, since it uses -o
2158 ### FIXME ### Shall we just use -o $FILEARG ??
2160 nice
$READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2162 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2164 if [ "$OSFLAVOUR" = "OSX" ] ; then
2165 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2166 disktool
-u ${CDROM#/dev/} 0
2167 # Also, in OSX the cdrom device for cdda2wav changes...
2168 CDDA2WAVCDROM
="IODVDServices"
2169 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2170 CDDA2WAVCDROM
="$CDROMID"
2172 if [ "$CDROMID" = "" ]; then
2173 CDDA2WAVCDROM
="$CDROM"
2175 CDDA2WAVCDROM
="$CDROMID"
2178 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2180 ## FIXME ## We have an exception for dagrab, since it uses -f
2181 ## FIXME ## Shall we just use -f $FILEARG ??
2182 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2185 # Find the track's mounted path
2186 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2187 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2188 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2189 # If the file exists, copy it
2190 if [ -e "$FILEPATH" ] ; then
2191 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2195 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2199 # If we get some error or we get some missing wav
2200 # (as long as we dont use pipes)
2201 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2202 # Thank goodness errors is only machine-parseable up to the
2203 # first colon, otherwise this woulda sucked
2204 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2205 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2207 if [ "$USEPIPES" = "y" ]; then
2208 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2210 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2214 if [ "$USEPIPES" = "y" ]; then
2215 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2217 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2218 if [ "$1" = "onetrack" ]; then
2219 echo onetrack
>> "$ABCDETEMPDIR/status"
2226 # No values accepted, only uses env variables
2229 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2230 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2232 echo "abcde: unable to set the device speed" >&2
2238 # vecho outputs a message if EXTRAVERBOSE is selected
2241 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2248 # decho outputs a debug message if DEBUG is selected
2251 if [ x
"$DEBUG" != "x" ]; then
2252 DEBUGECHO
=$
(echo "$@" |
tr -d '[]')
2253 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2257 # User-redefinable functions
2258 # Custom filename munging:
2261 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2262 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2265 # Custom genre munging:
2268 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2272 # Empty pre_read function, to be defined in the configuration file.
2279 # Empty post_read function, to be defined in the configuration file.
2285 ###############################################################################
2288 # Start of execution
2289 ###############################################################################
2292 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2293 CDDBSUBMIT
=freedb-submit@freedb.org
2295 HELLOINFO
="$(whoami)@$(hostname)"
2297 CDDBLOCALDIR
="$HOME/.cddb"
2300 # List of fields we parse and show during the CDDB parsing...
2301 SHOWCDDBFIELDS
="year,genre"
2304 CDROMREADERSYNTAX
=cdparanoia
2305 ENCODERSYNTAX
=default
2307 MP3ENCODERSYNTAX
=default
2308 OGGENCODERSYNTAX
=default
2309 FLACENCODERSYNTAX
=default
2310 SPEEXENCODERSYNTAX
=default
2311 MPPENCODERSYNTAX
=default
2312 NORMALIZERSYNTAX
=default
2313 CUEREADERSYNTAX
=default
2315 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2316 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2317 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2318 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2319 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2320 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2321 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2322 PLAYLISTDATAPREFIX
=''
2323 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2324 VAPLAYLISTDATAPREFIX
=''
2332 VARIOUSARTISTSTYLE
=forward
2338 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2339 # i.e. CDROMID="1,0,0"
2341 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2342 # If we are using the ide-scsi emulation layer, we need to define a "g"
2343 CDPARANOIACDROMBUS
="d"
2345 # program paths - defaults to checking your $PATH
2352 XINGMP3ENC
=xingmp3enc
2367 CDPARANOIA
=cdparanoia
2376 VORBISCOMMENT
=vorbiscomment
2378 NORMALIZE
=normalize-audio
2380 VORBISGAIN
=vorbisgain
2384 CUE2DISCID
=cue2discid
2386 # Options for programs called from abcde
2419 VORBISCOMMENTOPTS
="-R"
2420 METAFLACOPTS
="--no-utf8-convert"
2422 # Default to one process if -j isn't specified
2425 # List of actions to perform - by default, run to completion
2426 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2428 # List of prefered outputs - by default, run with whatever we have in the path
2429 # This option is basicaly for Debian package dependencies
2430 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
2432 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2433 # Let's use these checkings to determine the OS flavour, which will be used later
2434 if [ X$
(uname
) = "XFreeBSD" ] ; then
2439 elif [ X$
(uname
) = "XDarwin" ] ; then
2442 # We should have disktool in OSX, but let's be sure...
2444 CDROMREADERSYNTAX
=cddafs
2445 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2448 elif [ X$
(uname
) = "XNetBSD" ] ; then
2455 # If CDDBAVAIL is set to n, no CDDB read is done
2456 # If USEID3 is set to n, no ID3 tagging is done
2461 if [ -z "$OUTPUTDIR" ]; then
2465 if [ -z "$WAVOUTPUTDIR" ]; then
2466 WAVOUTPUTDIR
="$OUTPUTDIR"
2469 # Load system defaults
2470 if [ -r /etc
/abcde.conf
]; then
2473 # Load user preference defaults
2474 if [ -r $HOME/.abcde.conf
]; then
2478 # By this time, we need some HTTPGETOPTS already defined.
2479 # If the user has defined a non-default HTTPGET method, we should not be empty.
2481 if [ "$HTTPGETOPTS" = "" ] ; then
2483 wget
) HTTPGETOPTS
="-q -O -";;
2484 curl
) HTTPGETOPTS
="-f -s";;
2485 fetch
)HTTPGETOPTS
="-q -o -";;
2486 ftp) HTTPGETOPTS
="-q -o -";;
2487 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2491 # If the CDROM has not been set yet, find a suitable one.
2492 # If this is a devfs system, default to /dev/cdroms/cdrom0
2493 # instead of /dev/cdrom
2494 if [ "$CDROM" = "" ] ; then
2495 if [ -e /dev
/cdroms
/cdrom0
]; then
2496 CDROM
=/dev
/cdroms
/cdrom0
2497 elif [ -e /dev
/cdrom
]; then
2499 elif [ -e /dev
/cd0c
]; then
2501 elif [ -e /dev
/acd0c
]; then
2503 elif [ -e /dev
/disk1
]; then
2508 # Parse command line options
2509 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2510 while getopts 1a
:bc:C
:d
:Defghj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
:z opt
; do
2513 a
) ACTIONS
="$OPTARG" ;;
2514 A
) EXPACTIONS
="$OPTARG" ;;
2516 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2517 C
) DISCID
="${OPTARG#abcde.}" ;;
2518 d
) CDROM
="$OPTARG" ;;
2520 e
) ERASEENCODEDSTATUS
=y
;;
2522 e
) ERASEENCODEDSTATUS
=y
;;
2523 E
) ENCODING
="$OPTARG" ;;
2527 j
) MAXPROCS
="$OPTARG" ;;
2530 L
) CDDBUSELOCAL
=y
;;
2535 o
) OUTPUTTYPE
="$OPTARG" ;;
2538 r
) REMOTEHOSTS
="$OPTARG" ;;
2540 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2541 S
) CDSPEEDVALUE
="$OPTARG" ;;
2542 # t) PREPROCESSFORMATS="$OPTARG"
2544 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2545 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2546 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2548 echo "This is abcde v$VERSION."
2549 echo "Usage: abcde [options] [tracks]"
2550 echo "abcde -h for extra help"
2553 V
) EXTRAVERBOSE
="y" ;;
2555 w
) COMMENT
="$OPTARG" ;;
2556 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2557 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2559 echo "abcde error: argument of -W must be integer"
2563 z
) DEBUG
=y
; CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
2568 shift $
(($OPTIND - 1))
2570 # If the user specified a flac file, then switch to special flac mode
2571 if echo $CDROM |
grep -i -q '.flac$'; then
2572 vecho
"abcde: switching to flac CDROMREADERSYNTAX..."
2573 CDROMREADERSYNTAX
=flac
2574 if [ "$EJECTCD" = "y" ];then
2575 vecho
"abcde: CDROM flac mode, deactivating EJECTCD..."
2580 # Decide if we can continue.
2581 if [ "$ONETRACK" = "y" ]; then
2582 # FIXME # remove check as soon as we find out about the other readers
2583 case "$CDROMREADERSYNTAX" in
2587 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2590 if [ "$BATCHNORM" = "y" ]; then
2591 echo "abcde warning: BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
2594 if [ "$NOGAP" = "y" ]; then
2595 echo "abcde warning: NOGAP mode is not compatible with ONETRACK mode. Disabling..."
2598 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2599 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2600 if [ $# -gt 0 ]; then
2601 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2604 while [ $# -gt 0 ]; do
2605 # Range parsing code courtesy of Vincent Ho
2606 RSTART
=$
(echo $1 | cut
-f1 -d-)
2607 REND
=$
(echo $1 | cut
-f2 -d-)
2608 if [ "$RSTART" = "$REND" ]; then
2611 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2613 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2618 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2619 # List of experimental actions: retag,transcode
2621 # Determine what actions are to be done from $ACTIONS and set the
2622 # following environment variables for them:
2635 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2640 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2641 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2642 encode
) DOENCODE
=y
; DOREAD
=y
;;
2643 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2644 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2645 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2646 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
2647 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2652 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2653 # FIXME # should we abort on error or just inform the user?
2657 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
2658 case $SHOWCDDBFIELD in
2659 y
*|Y
*) SHOWCDDBYEAR
="y";;
2660 g
*|G
*) SHOWCDDBGENRE
="y";;
2667 # At this point a CDROM has to be defined, so we check it exists.
2668 if [ X
"$CDROM" != "X" ] ; then
2669 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2670 if [ "$OSFLAVOUR" = "FBSD" ]; then
2671 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2672 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2673 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2677 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2678 echo "abcde error: CDROM device cannot be found." >&2
2681 # avoid processing if we are not going to hit the CDROM.
2682 elif [ X
"$DOREAD" = "Xy" ]; then
2683 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2687 # USEPIPES pre-tests, before we get into more serious stuff
2688 # Not compatible with:
2689 # - multiple outputs
2691 # - lowdisk algorithm
2693 if [ X
"$USEPIPES" = "Xy" ]; then
2694 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
2695 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
2698 if [ X
"$DONORMALIZE" = "Xy" ]; then
2699 echo "abcde error: Unix pipes not compatible with normalizer"
2700 # FIXME # Do we need to exit or shall we just disable the mode?
2703 if [ X
"$BATCHNORM" = "Xy" ]; then
2704 echo "abcde error: Unix pipes not compatible with BATCHNORM encoding"
2707 if [ X
"$NOGAP" = "Xy" ]; then
2708 echo "abcde error: Unix pipes not compatible with NOGAP encoding"
2711 if [ X
"$DOENCODE" = "Xn" ]; then
2712 vecho
"Disabling Unix pipes since we are not encoding!"
2715 if [ X
"$LOWDISK" = "Xy" ]; then
2716 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2721 # LOWDISK pre-tests, before we get into more problematic stuff
2722 # Not compatible with anything that needs all the files in the hard disc:
2725 if [ X
"$LOWDISK" = "Xy" ]; then
2726 if [ X
"$BATCHNORM" = "Xy" ]; then
2727 echo "abcde error: Unix pipes not compatible with BATCHNORM encoding"
2730 if [ X
"$NOGAP" = "Xy" ]; then
2731 echo "abcde error: Unix pipes not compatible with NOGAP encoding"
2736 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2737 if [ X
"$OUTPUTTYPE" = "X" ]; then
2738 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
2739 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2740 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2741 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
2742 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
2743 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2747 if [ X
"$OUTPUTTYPE" = "X" ]; then
2748 echo "abcde error: no encoder found in the PATH" >&2
2749 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2754 # Decide which CDROM reader we're gonna use
2755 case "$CDROMREADERSYNTAX" in
2757 CDROMREADER
="$CDPARANOIA"
2758 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2761 CDROMREADER
="$CDDA2WAV"
2762 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2765 CDROMREADER
="$DAGRAB"
2766 CDROMREADEROPTS
="$DAGRABOPTS"
2769 CDROMREADER
="$CDDAFS"
2770 CDROMREADEROPTS
="$CDDAFSOPTS"
2774 CDROMREADEROPTS
="$FLACOPTS"
2778 # There's only one normalize...
2779 case "$NORMALIZERSYNTAX" in
2781 NORMALIZER
="$NORMALIZE"
2782 NORMALIZEROPTS
="$NORMALIZEOPTS"
2786 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2787 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
2788 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2790 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2791 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2792 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2793 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2794 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2797 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2798 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2799 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2801 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2804 # 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
2806 # Getting ready for multiple output changes
2807 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2811 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2812 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2813 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2814 OGGOUTPUTCONTAINER
=ogg
2817 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2818 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2822 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2823 [ "$REPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
2824 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2827 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
2830 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
2833 if [ "$KEEPWAVS" = "y" ]; then
2834 vecho
"Unsetting the KEEPWAVS option, since the resulting wav files were requested..."
2838 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2844 # decide which encoder
2845 case "$MP3ENCODERSYNTAX" in
2847 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2851 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
2852 MP3ENCODER
="$TOOLAME"
2855 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2859 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2860 MP3ENCODER
="$BLADEENC"
2863 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2867 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2868 MP3ENCODER
="$XINGMP3ENC"
2871 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2872 MP3ENCODER
="$MP3ENC"
2875 case "$OGGENCODERSYNTAX" in
2877 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2878 OGGENCODER
="$VORBIZE"
2881 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2882 OGGENCODER
="$OGGENC"
2885 case "$FLACENCODERSYNTAX" in
2887 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2889 # FLAC streams can be encapsulated on a Ogg transport layer
2890 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2891 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2892 echo " due to problem with adding comments to such files" >&2
2894 FLACOUTPUTCONTAINER
=ogg
2896 FLACOUTPUTCONTAINER
=flac
2900 case "$SPEEXENCODERSYNTAX" in
2902 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2903 SPEEXENCODER
="$SPEEXENC"
2906 case "$MPPENCODERSYNTAX" in
2908 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2909 MPPENCODER
="$MPPENC"
2915 if [ "$ID3TAGV" = "1" ]; then
2917 TAGGEROPTS
="$ID3OPTS"
2920 TAGGEROPTS
="$ID3V2OPTS"
2923 # Specific for NOGAP is the use of lame. Another encoder fails...
2924 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
2925 "abcde warning: the NOGAP option is specific of lame. Deactivating..."
2930 case "$CUEREADERSYNTAX" in
2932 CUEREADEROPTS
="${CDROM}"
2937 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2938 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2939 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2940 echo " due to problem with adding comments to such files" >&2
2942 OGGOUTPUTCONTAINER
=ogg.ogg
2943 FLACOUTPUTCONTAINER
=flac.ogg
2944 vecho
"abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2947 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2949 if [ "$ENCNICE" ]; then
2950 ENCNICE
="-n $ENCNICE"
2952 if [ "$READNICE" ]; then
2953 READNICE
="-n $READNICE"
2955 if [ "$DISTMP3NICE" ]; then
2956 DISTMP3NICE
="-n $DISTMP3NICE"
2959 # Don't check for stuff if it's not needed
2960 if [ "$REMOTEHOSTS" ]; then
2963 if [ "$DONORMALIZE" = "y" ]; then
2966 if [ "$EJECTCD" = "y" ]; then
2969 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2972 if [ "$MAKECUEFILE" = "y" ]; then
2976 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2977 case "$CDROMREADERSYNTAX" in
2978 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2979 ### FIXME ### translate "cue2discid" from python to bash
2980 flac
) NEEDMETAFLAC
=y
; NEEDCUE2DISCID
=y
;;
2985 # Rippers with USEPIPE support
2986 # FIXME # Include here all the rippers we can figure out support pipes
2990 # Encoders with USEPIPE support
2991 # FIXME # Include here all the encoders we can figure out support pipes
2996 # Figure out if we can use pipes with the ripper/encoder combination
2998 if [ "$USEPIPES" = "y" ]; then
2999 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
3002 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
3004 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
3006 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
3008 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
3010 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
3012 if [ ! -n "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" ] ; then
3013 echo "abcde error: no support for pipes with given ripper" >&2
3014 echo "read the USEPIPES file from the source tarball to get help." >&2
3015 echo "On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz" >&2
3018 if [ ! -n "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" ] ; then
3019 echo "abcde error: no support for pipes with given encoder" >&2
3020 echo "read the USEPIPES file from the source tarball to help" >&2
3021 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
3026 # Make sure a buncha things exist
3027 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
3028 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3029 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3030 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3031 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
3032 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
3033 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDCUEREADER+$CUEREADER} \
3034 ${NEEDCUE2DISCID+$CUE2DISCID}
3036 # Cut off the command-line options we just added in
3037 X
=$
(echo $X | cut
-d' ' -f2)
3038 if [ "$(which $X)" = "" ]; then
3039 echo "abcde error: $X is not in your path." >&2
3041 elif [ ! -x $
(which $X) ]; then
3042 echo "abcde error: $X is not executable." >&2
3047 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
3048 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
3049 HTTPGET
="$HTTPGET $HTTPGETOPTS"
3051 # And last but not least, check if we can diff between files
3052 if [ -x $
(which $DIFF) ]; then :; else
3053 vecho
"[WAR] Disabling diff since we cannot find it in the \$PATH..."
3057 # Here it used to say:
3058 # One thousand lines in, we can start doing stuff with things
3059 # Well, right now we are at line 2736 ;)
3061 # Export needed things so they can be read in this subshell
3062 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
3063 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
3065 # User-definable function to set some things. Use it for
3066 # - closing the CD tray with eject -t
3067 # - set the CD speed value with eject -x
3068 vecho
-n "Executing customizable pre-read function... "
3070 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
3074 do_discid
# Get ABCDETEMPDIR created and status file initialized
3076 if [ "$DOCDDB" = "y" ]; then
3077 if [ $CDDBUSELOCAL = "y" ]; then
3080 if checkstatus cddb-choice
> /dev
/null
; then
3083 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
3091 eval "$($CDDBTOOL parse "$CDDBDATA")"
3094 # Before reading tracks, we set the speed of the device
3096 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3097 case "$CDROMREADERSYNTAX" in
3098 cdparanoia|debug
) ;;
3104 # Define the first and last track, since we might need them later in several places
3105 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
3106 LASTTRACK
=$
( get_last
$TRACKQUEUE )
3108 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
3109 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3110 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
3111 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
3114 # Create playlist if needed (backgroundable) and start reading in tracks
3118 if [ ! "$ONETRACK" = "y" ]; then
3119 if [ "$DOPLAYLIST" = "y" ]; then
3120 echo Creating playlist...
>&2
3125 # For the lowdisk option, only one program is running at once so the encoder
3126 # can be unsilenced right away.
3127 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3128 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3131 if [ "$ONETRACK" = "y" ]; then
3132 TRACKS
="$FIRSTTRACK"
3133 if checkstatus readtrack-
$FIRSTTRACK; then :; else
3134 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
3137 for UTRACKNUM
in $TRACKQUEUE
3139 if [ "$DOREAD" = "y" ]; then
3140 if [ "$USEPIPES" = "y" ]; then
3141 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
3142 # Read, pipe, shut up!
3143 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
3146 if checkstatus readtrack-
$UTRACKNUM; then :; else
3147 do_cdread
$UTRACKNUM
3149 if [ "$?" != "0" ]; then
3150 # CD read failed - don't give the goahead to
3157 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ]; then
3160 echo NEXTTRACK
# Get the encoder machine churning again
3161 if [ "$DOREAD" = "y" ]; then
3162 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3163 until checkstatus encodetrack-
$UTRACKNUM
3165 if checkerrors encodetrack-
$UTRACKNUM; then
3176 # Now that we're done the encoding can be loud again -
3177 # if we're not using SMP.
3178 if [ "$MAXPROCS" = "1" ]; then
3179 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3182 # All tracks read, start encoding.
3183 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3187 # Execute the user-defined post_read funtion before ejecting CD
3190 # We are now finished with the cdrom - it can be safely ejected. Note that
3191 # abcde will not have completed yet.
3192 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
3193 # We check if the disk we are processing is actually the disk inside the
3194 # CD tray. If not, we do not eject the CD, since it might be so that the
3195 # user ejected it manually.
3196 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3197 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3198 # More FreeBSD bits.
3199 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
3200 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3201 # but in this script EJECT is in the envionment and names the program
3204 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3205 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3206 $eject $EJECTOPTS $cd
3207 elif [ X
"$(uname)" = X
"Darwin" ] ; then
3208 disktool
-e ${CDROM#/dev/} 0
3210 $EJECT $EJECTOPTS $CDROM
3217 ## Do we need to pre-process
3218 #if [ x"$PREPROCESS" = "x" ] ; then
3221 # for PRETRACKNUM in $TRACKQUEUE
3224 # if [ "$GOAHEAD" = "NO" ]; then break; fi
3226 # until [ $PREPROCEED ]
3228 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3229 # # all locations are working, wait and try again later
3230 # if [ ! $PREPROCEED ]; then sleep 3; fi
3232 # ( do_preprocess $PRETRACKNUM
3240 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
3242 if [ "$BATCHNORM" = "y" ] ||
[ "$NOGAP" = "y" ]; then
3243 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3244 if [ "$GOAHEAD" = "NO" ]; then break; fi
3245 for LASTTRACK
in $TRACKQUEUE; do :; done
3246 if checkstatus readtrack-
$LASTTRACK; then
3247 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
3248 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
3249 if checkerrors batch-normalize
; then exit 1; fi
3251 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
3252 if [ "$DONORMALIZE" = "y" ]; then
3253 for UTRACKNUM
in $TRACKQUEUE
3255 if checkstatus readtrack-
$UTRACKNUM; then
3256 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3260 if checkstatus encodetrack-
$LASTTRACK; then :; else do_nogap_encode
; fi
3261 if checkerrors nogap-encode
; then exit 1; fi
3267 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3268 if [ "$ONETRACK" = "y" ] ; then
3269 TRACKQUEUE
="$FIRSTTRACK"
3270 TRACKS
="$FIRSTTRACK"
3273 # Do the encoding, including parallelization of remote encoding
3274 # Figure out where each track is going to be encoded
3275 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
3276 if [ "$MAXPROCS" != "0" ]; then
3277 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
3279 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
3283 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
3284 for UTRACKNUM
in $TRACKQUEUE
3287 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3288 if [ "$GOAHEAD" = "NO" ]; then break; fi
3289 # find out where this track is to be encoded
3290 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3291 # Make sure we have a place to encode this, if not, exit stage right
3292 if [ -z "$ENCODELOCATIONS" ]; then
3298 for LOCATION
in $ENCODELOCATIONS
3300 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3301 # check first if a track has ever been assigned to this location
3302 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
3303 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3304 if checkerrors encodetrack-
$PREVIOUSTRACK; then
3305 for TEMPLOCATION
in $ENCODELOCATIONS
3307 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3308 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
3311 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
3316 # We're still here, this location must have been previously assigned,
3317 # and last completed without error - check if it's done with the
3318 # previous track yet
3319 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
3321 # all locations are working, wait and try again later
3322 if [ ! $PROCEED ]; then sleep 3; fi
3324 # Record the location we're about to encode the next track at
3325 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3327 # Don't proceed with the rest of the loop if we can't encode
3328 if [ "$ABORT" ]; then continue; fi
3329 # Set TRACKNUM, TRACKNAME
3330 if [ -e "$CDDBDATA" ]; then
3331 if [ "$ONETRACK" = "y" ]; then
3333 TRACKNUM
="$FIRSTTRACK"
3336 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
3338 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3339 #TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
3340 do_getcddbinfo TRACKNAME
3344 # You can't encode a file which needs to be normalized before finishing
3345 # You can't tag a file before it's finished encoding -
3346 # thus all of this is backgrounded together
3348 if [ "$DONORMALIZE" = "y" ]; then
3349 if checkstatus readtrack-
$UTRACKNUM; then
3350 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3353 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3354 if checkstatus readtrack-
$UTRACKNUM; then
3355 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3356 if [ "$DONORMALIZE" = "y" ]; then
3357 if checkstatus normalizetrack-
$UTRACKNUM; then
3358 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3361 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3365 if [ "$DOTAG" = "y" ]; then
3366 if checkstatus encodetrack-
$UTRACKNUM; then
3367 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3369 # Lets tag the cue file
3370 if checkstatus cleancuefile
>/dev
/null
; then :; else
3371 if checkstatus cuefile
>/dev
/null
; then
3376 if [ "$DOMOVE" = "y" ]; then
3377 if checkstatus tagtrack-
$UTRACKNUM; then
3378 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3385 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3386 # we'll delete the files they're working on
3387 ## FIXME ## Check also for files which are encoded using PIPEs.
3388 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3393 for LOCATION
in $ENCODELOCATIONS
3395 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3396 # "How can he give us a status update, if he's DEAD?"
3397 if checkstatus encodetrack-
$CHECKTRACK; then
3400 # Nothing to see here please go quietly back to your homes
3401 if [ -z "$CHECKTRACK" ]; then continue; fi
3402 # You're still here? Maybe there is something...
3403 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3406 if [ ! $PROCEED ]; then sleep 5; fi
3409 # If the above didn't catch the stragglers, this will
3411 if [ "$REPLAYGAIN" = "y" ]; then
3414 # Check to see if run_command logged any errors
3415 if [ -f "$ABCDETEMPDIR/errors" ]; then
3416 echo "The following commands failed to run:"
3417 cat "$ABCDETEMPDIR/errors"
3421 if [ "$KEEPWAVS" = "y" ];then
3425 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
3426 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
3427 ENCODED_FORMATS
=$
(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f2 |
sort -u |
tr '\n' '|')
3428 MOVED_FORMATS
=$
(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f3 |
sort -u |
tr '\n' '|')
3429 decho
[ENCODED_FORMATS
]
3430 decho
[MOVED_FORMATS
]
3431 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
3432 echo "Not all encoded formats have been requested to be moved."
3433 echo "Use \"-a clean -f -C $DISCID\" to force the removal of the remaining data."
3437 if [ "$DOCLEAN" = "y" ]; then
3438 # Wipe all the evidence
3439 # Gimme gimme gimme some more time!
3441 rm -rf "$ABCDETEMPDIR"
3444 echo "Finished. Not cleaning $ABCDETEMPDIR."