2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2004 Jesus Climent <jesus.climent@hispalinux.es>
4 # This code is hereby licensed for public consumption under either the
5 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software
9 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
24 #echo "-A Experimental actions (retag, transcode)"
25 echo "-b Batch mode: enable album normalization and nogap encoding"
27 echo " Specify a configuration file (overrides system and user config files)"
29 echo " Specify discid to resume from (only needed if you no longer have the cd)"
31 echo " Specify CDROM device to grab"
32 echo "-D Debugging mode (equivalent to sh -x abcde)"
33 echo "-h This help information"
34 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
35 echo "-j <#> Number of encoder processes to run at once (localhost)"
36 echo "-k Keep the wav tracks for later use"
37 echo "-l Use low disk space algorithm"
38 echo "-L Use local CDDB storage directory"
39 echo "-n No lookup. Don't query CDDB, just create and use template"
40 echo "-N Noninteractive. Never prompt for anything"
41 echo "-m Modify playlist to include CRLF endings, to comply with some players"
42 echo "-M Create a CUE file"
43 echo "-o <type1[,type2]...>"
44 echo " Output file type(s) (ogg,mp3,flac,spx,mpc). Defaults to ogg"
45 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
46 echo "-P Use UNIX pipes to read+encode without wav files"
47 echo "-r <host1[,host2]...>"
48 echo " Also encode on these remote hosts"
49 echo "-R Add replaygain values to the tag info (only for ogg,flac)"
50 echo "-S <#> Set the CD speed"
51 #echo "-t File types to preprocess (wav)"
52 #echo "-T Set postprocessing options"
53 echo "-t <#> Start the track numbering at a given number"
54 echo "-T <#> Same as -t but modifies tag numbering"
55 echo "-v Show version number and exit"
56 echo "-V Be a bit more verbose about what is happening behind the scenes"
57 echo "-x Eject CD after all tracks are read"
59 echo " Add a comment to the CD tracks"
60 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
62 echo "Tracks is a space-delimited list of tracks to grab."
63 echo "Ranges specified with hyphens are allowed."
66 # Funtions to replace the need of seq, which is too distribution dependant.
70 while [ $i -ne `expr $2 + 1` ]
80 while [ $i -ne `expr $2 + 1` ]
89 # Returns "0" if the blurb was found, returns 1 if it wasn't
90 # Puts the blurb content, if available, on stdout.
91 # Otherwise, returns "".
94 # Take the last line in the status file if there's multiple matches
96 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
98 if [ -z "$BLURB" ]; then
103 # See if there's a = in it
104 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
105 echo "$(echo $BLURB | cut -f2- -d=)"
111 # checkerrors [blurb]
112 # Returns "0" if the blurb was found (meaning there was an error),
113 # returns 1 if it wasn't (yes this is a little backwards).
114 # Does not print the blurb on stdout.
115 # Otherwise, returns "".
118 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
121 # Take the last line in the status file if there's multiple matches
123 BLURB
="$(egrep $PATTERN $ABCDETEMPDIR/errors | tail -n 1)"
125 if [ -z "$BLURB" ]; then
126 # negative, we did not have a negative...
129 # affirmative, we had a negative...
134 # run_command [blurb] [command...]
135 # Runs a command, silently if necessary, and updates the status file
140 # See if this is supposed to be silent
141 if [ "$(checkstatus encode-output)" = "loud" ]; then
145 # Special case for SMP, since
146 # encoder output is never displayed, don't mute echos
147 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
157 if [ "$RETURN" = "2" ]; then
158 # File was already normalized.
163 if [ "$RETURN" != "0" ]; then
164 # Put an error in the errors file. For various reasons we
165 # can't capture a copy of the program's output but we can
166 # log what we attempted to execute and the error code
167 # returned by the program.
168 if [ "$BLURB" ]; then
171 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
172 return $RETURN # Do not pass go, do not update the status file
174 if [ "$BLURB" ]; then
175 echo $BLURB >> "$ABCDETEMPDIR/status"
179 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
180 # distributed under the terms of the GNU GPL v2 or later, at your option
182 # Function to determine if a word contains a slash.
191 # Function to give the relative path from one file to another.
192 # Usage: relpath fromfile tofile
193 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
194 # (the result would be Album/Song.mp3)
195 # Output is relative path to $2 from $1 on stdout
197 # This code has the following restrictions:
198 # Multiple ////s are not collapsed into single /s, with strange effects.
199 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
200 # If FR is a directory it must have a trailing /
208 /*) ;; # No processing is needed for absolute paths
210 # Loop through common prefixes, ignoring them.
211 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
213 FR
="$(echo "$FR" | cut -d/ -f2-)"
214 TO
="$(echo "$TO" | cut -d/ -f2-)"
216 # Loop through directory portions left in FR, adding appropriate ../s.
219 FR
="$(echo "$FR" | cut -d/ -f2-)"
228 # This code splits the a Various Artist track name from one of the following
231 # forward: Artist / Track
232 # forward-dash: Artist - Track
233 # reverse: Track / Artist
234 # reverse-dash: Track - Artist
235 # colon: Artist: Track
236 # trailing-paren: Artist (Track)
239 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
242 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
243 case "$VARIOUSARTISTSTYLE" in
245 DTITLEARTIST
="$(echo $TRACKNAME | sed 's- / -~-g')"
246 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
247 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
250 DTITLEARTIST
="$(echo $TRACKNAME | sed 's, - ,~,g')"
251 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
252 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
255 DTITLEARTIST
="$(echo $TRACKNAME | sed 's- / -~-g')"
256 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
257 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
260 DTITLEARTIST
="$(echo $TRACKNAME | sed 's, - ,~,g')"
261 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
262 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
265 DTITLEARTIST
="$(echo $TRACKNAME | sed 's-: -~-g')"
266 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
267 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
270 DTITLEARTIST
="$(echo $TRACKNAME | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
271 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
272 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
275 elif [ "$ONETRACK" = "y" ]; then
276 TRACKARTIST
="Various"
283 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
287 "classic rock") id
=1 ;;
305 "industrial") id
=19 ;;
306 "alternative") id
=20 ;;
308 "death metal") id
=22 ;;
310 "soundtrack") id
=24 ;;
311 "euro-techno") id
=25 ;;
315 "jazz+funk") id
=29 ;;
318 "classical") id
=32 ;;
319 "instrumental") id
=33 ;;
323 "sound clip") id
=37 ;;
326 "alt. rock") id
=40 ;;
331 "meditative") id
=45 ;;
332 "instrum. pop") id
=46 ;;
333 "instrum. rock") id
=47 ;;
337 "techno-indust.") id
=51 ;;
338 "electronic") id
=52 ;;
340 "eurodance") id
=54 ;;
342 "southern rock") id
=56 ;;
347 "christian rap") id
=61 ;;
350 "native american") id
=64 ;;
353 "psychadelic") id
=67 ;;
355 "showtunes") id
=69 ;;
359 "acid punk") id
=73 ;;
360 "acid jazz") id
=74 ;;
364 "rock & roll") id
=78 ;;
365 "hard rock") id
=79 ;;
367 "folk/rock") id
=81 ;;
368 "national folk") id
=82 ;;
375 "bluegrass") id
=89 ;;
376 "avantgarde") id
=90 ;;
377 "gothic rock") id
=91 ;;
378 "progress. rock") id
=92 ;;
379 "psychadel. rock") id
=93 ;;
380 "symphonic rock") id
=94 ;;
381 "slow rock") id
=95 ;;
384 "easy listening") id
=98 ;;
390 "chamber music") id
=104 ;;
392 "symphony") id
=106 ;;
393 "booty bass") id
=107 ;;
395 "porn groove") id
=109 ;;
397 "slow jam") id
=111 ;;
401 "folklore") id
=115 ;;
403 "power ballad") id
=117 ;;
404 "rhythmic soul") id
=118 ;;
405 "freestyle") id
=119 ;;
407 "punk rock") id
=121 ;;
408 "drum solo") id
=122 ;;
409 "a capella") id
=123 ;;
410 "euro-house") id
=124 ;;
411 "dance hall") id
=125 ;;
413 "drum & bass") id
=127 ;;
414 "club-house") id
=128 ;;
415 "hardcore") id
=129 ;;
419 "negerpunk") id
=133 ;;
420 "polsk punk") id
=134 ;;
422 "christian gangsta rap") id
=136 ;;
423 "heavy metal") id
=137 ;;
424 "black metal") id
=138 ;;
425 "crossover") id
=139 ;;
426 "contemporary christian")id
=140 ;;
427 "christian rock") id
=141 ;;
428 "merengue") id
=142 ;;
430 "thrash metal") id
=144 ;;
433 "synthpop") id
=147 ;;
440 # do_tag [tracknumber]
441 # id3 tags a filename
443 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
444 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
447 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
448 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
449 # If we want to start the tracks with a given number, we need to modify the
450 # TRACKNUM value before evaluation
451 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
452 # Get the trackpadding from the current track
453 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
454 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
456 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
460 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
461 GENREID
=$
(do_getgenreid
"${CDGENRE}")
463 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
464 GENREID
=$
(do_getgenreid
"${CDGENRE}")
466 run_command tagtrack-
$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
467 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
468 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
469 "$ABCDETEMPDIR/track$1.$OUTPUT"
472 case "$OGGENCODERSYNTAX" in
474 # vorbiscomment can't do in-place modification, mv the file first
475 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" ]; then
476 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
479 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
480 echo ARTIST
=$TRACKARTIST
482 echo TITLE
=$TRACKNAME
483 if [ -n "$CDYEAR" ]; then
486 if [ -n "$CDGENRE" ]; then
487 echo GENRE
="$CDGENRE"
489 echo TRACKNUMBER
=${TRACKNUM:-$1}
490 echo CDDB
=$CDDBDISCID
491 if [ "$(eval echo ${COMMENT})" != "" ]; then
492 case "$COMMENTOUTPUT" in
493 *=*) echo "$COMMENTOUTPUT";;
494 *) echo COMMENT
="$COMMENTOUTPUT";;
497 ) | run_command tagtrack-
$1 $VORBISCOMMENT -w \
498 "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
499 # Doublecheck that the commented file was created successfully before wiping the original
500 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" ]; then
501 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
503 mv "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
510 echo ARTIST
="$TRACKARTIST"
512 echo TITLE
="$TRACKNAME"
513 if [ -n "$CDYEAR" ]; then
516 if [ -n "$CDGENRE" ]; then
517 echo GENRE
="$CDGENRE"
519 echo TRACKNUMBER
=${TRACKNUM:-$1}
520 echo CDDB
=$CDDBDISCID
521 if [ "$(eval echo ${COMMENT})" != "" ]; then
522 case "$COMMENTOUTPUT" in
523 *=*) echo "$COMMENTOUTPUT";;
524 *) echo COMMENT
="$COMMENTOUTPUT";;
527 ) | run_command tagtrack-
$1 $METAFLAC --no-utf8-convert --import-tags-from=- "$ABCDETEMPDIR/track$1.$OUTPUT"
530 run_command tagtrack-
$1 true
533 run_command tagtrack-
$1 true
541 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
544 # The commands here don't go through run_command because they're never supposed to be silenced
545 echo "Batch encoding tracks: $TRACKQUEUE"
546 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
549 case "$MP3ENCODERSYNTAX" in
554 for UTRACKNUM
in $TRACKQUEUE
556 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
558 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
560 if [ "$RETURN" != "0" ]; then
561 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
563 for UTRACKNUM
in $TRACKQUEUE
565 echo encodetrack-
$UTRACKNUM >> status
573 # Other encoders fall through to normal encoding as the tracks
574 # have not been entered in the status file.
577 # do_encode [tracknumber] [hostname]
578 # If no hostname is specified, encode locally
580 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
583 if [ "$USEPIPES" = "y" ]; then
586 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
589 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
592 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
595 TEMPARG
="PIPE_$SPEEXENCODER"
598 TEMPARG
="PIPE_$MPPENCODER"
603 IN
="$ABCDETEMPDIR/track$1.wav"
606 case "$MP3ENCODERSYNTAX" in
607 # FIXME # check if mp3enc needs -if for pipes
621 # We need IN to proceed, if we are not using pipes.
622 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
623 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
625 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
626 if [ X
"$USEPIPES" = "Xy" ]; then
629 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
630 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
636 case "$MP3ENCODERSYNTAX" in
637 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
638 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
639 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
640 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
641 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
645 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
652 case "$OGGENCODERSYNTAX" in
653 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
654 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
658 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
665 case "$FLACENCODERSYNTAX" in
666 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
672 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
673 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
678 if [ "$(eval echo ${COMMENT})" != "" ]; then
681 *) COMMENT
="COMMENT=$COMMENT" ;;
683 COMMENT
="--comment \"$COMMENT\""
685 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
686 if [ ! "$DOTAG" = "y" ]; then
687 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
689 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
693 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
695 # I tried compiling the mppenc from corecodecs.org and got some
696 # errors, so I have not tried it myself.
697 ## FIXME ## Needs some cleanup to determine if an empty tag sent
698 ## FIXME ## to the encoder ends up empty.
699 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
703 # Only remove .wav if the encoding succeeded
704 if checkerrors
"encodetrack-(.{3,4})-$1"; then
705 run_command encodetrack-
$1 false
707 run_command encodetrack-
$1 true
708 if [ ! "$KEEPWAVS" = "y" ] ; then
713 if [ "$(checkstatus encode-output)" = "loud" ]; then
714 echo "HEH! The file we were about to encode disappeared:"
717 run_command encodetrack-
$1 false
721 # do_preprocess [tracknumber]
723 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
726 # IN="$ABCDETEMPDIR/track$1.wav"
727 # # We need IN to proceed.
728 # if [ -s "$IN" ] ; then
729 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
731 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
732 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
733 # case "$POSTPROCESSFORMAT" in
735 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
737 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
739 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
741 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
743 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
746 # # Only remove .wav if the encoding succeeded
747 # if checkerrors "preprocess-(.{3,4})-$1"; then
748 # run_command preprocess-$1 false
750 # run_command preprocess-$1 true
753 # if [ "$(checkstatus encode-output)" = "loud" ]; then
754 # echo "HEH! The file we were about to pre-process disappeared:"
757 # run_command preprocess-$1 false
762 # do_postprocess [tracknumber]
764 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
767 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
769 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
770 # # We need IN to proceed.
771 # if [ -s "$IN" ] ; then
772 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
773 # run_command '' echo "Post-processing track $1 of $TRACKS..."
774 # case "$POSTPROCESSFORMAT" in
776 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
778 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
780 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
782 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
784 # # Only remove .wav if the encoding succeeded
785 # if checkerrors "postprocess-(.{3,4})-$1"; then
786 # run_command postprocess-$1 false
788 # run_command postprocess-$1 true
791 # if [ "$(checkstatus encode-output)" = "loud" ]; then
792 # echo "HEH! The file we were about to post-process disappeared:"
795 # run_command postprocess-$1 false
802 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
805 # The commands here don't go through run_command because they're never supposed to be silenced
806 echo "Batch analizing gain in tracks: $TRACKQUEUE"
811 for UTRACKNUM
in $TRACKQUEUE
813 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
815 # XXX: Hard-coded batch option!
816 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
818 if [ "$RETURN" != "0" ]; then
819 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
821 for UTRACKNUM
in $TRACKQUEUE
823 echo normalizetrack-
$UTRACKNUM >> status
831 # NORMALIZER, NORMALIZEROPTS
832 do_batch_normalize
()
834 # The commands here don't go through run_command because they're never supposed to be silenced
835 echo "Batch normalizing tracks: $TRACKQUEUE"
840 for UTRACKNUM
in $TRACKQUEUE
842 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
844 # XXX: Hard-coded batch option!
845 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
847 if [ "$RETURN" != "0" ]; then
848 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
850 for UTRACKNUM
in $TRACKQUEUE
852 echo normalizetrack-
$UTRACKNUM >> status
858 # do_normalize [tracknumber]
860 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
863 IN
="$ABCDETEMPDIR/track$1.wav"
864 if [ -e "$IN" ] ; then
865 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
866 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
868 if [ "$(checkstatus encode-output)" = "loud" ]; then
869 echo "HEH! The file we were about to normalize disappeared:"
872 run_command normalizetrack-
$1 false
"File $IN was not found"
876 # do_move [tracknumber]
877 # Deduces the outfile from environment variables
878 # Creates directory if necessary
880 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
883 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
885 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
886 # Munge filenames as follows:
891 # Eat control characters
892 ALBUMFILE
=$
(mungefilename
"$DALBUM")
893 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
894 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
895 GENRE
=$
(mungegenre
"$GENRE")
897 # If we want to start the tracks with a given number, we need to modify the
898 # TRACKNUM value before evaluation
899 if [ -n "$STARTTRACKNUMBER" ] ; then
900 # Get the trackpadding from the current track
901 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
902 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
904 TRACKNUM
=${UTRACKNUM}
906 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
907 # TRACKFILE, and TRACKNUM.
908 if [ "$VARIOUSARTISTS" = "y" ]; then
909 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
911 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
913 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
914 OUTPUTFILEDIR
=$
(dirname "$OUTPUTDIR/$OUTPUTFILE")
915 # mkdir -p shouldn't return an error if the directory already exists
916 mkdir
-p "$OUTPUTFILEDIR"
917 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
922 # Create the playlist if wanted
924 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
925 # VARIOUSARTISTS, OUTPUTDIR
928 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
930 # Create a playlist file for the playlist data to go into.
931 # We used to wipe it out if it existed. Now we request permision if interactive.
932 for LASTTRACK
in $TRACKQUEUE; do :; done
933 ALBUMFILE
=$
(mungefilename
"$DALBUM")
934 ARTISTFILE
=$
(mungefilename
"$DARTIST")
935 GENRE
=$
(mungegenre
"$GENRE")
936 if [ "$VARIOUSARTISTS" = "y" ] ; then
937 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
939 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
941 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
942 mkdir
-p "$FINALPLAYLISTDIR"
943 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
944 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
945 if [ "$INTERACTIVE" = "y" ]; then
946 while [ "$DONE" != "y" ]; do
948 case $ERASEPLAYLIST in
949 e|E|a|A|k|K
) DONE
=y
;;
957 # Once we erase the playlist, we use append to create the new one.
958 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
960 # The playlist does not exist, so we can safelly use append to create the new list
963 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
964 touch "$OUTPUTDIR/$PLAYLISTFILE"
965 for UTRACKNUM
in $TRACKQUEUE
967 # Shares some code with do_move since the filenames have to match
968 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
969 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
971 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
972 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
973 # If we want to start the tracks with a given number, we need to modify the
974 # TRACKNUM value before evaluation
975 if [ -n "$STARTTRACKNUMBER" ] ; then
976 # Get the trackpadding from the current track
977 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
978 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
980 TRACKNUM
=${UTRACKNUM}
982 if [ "$VARIOUSARTISTS" = "y" ]; then
983 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
985 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
987 if [ "$VARIOUSARTISTS" = "y" ]; then
988 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
989 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
991 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
994 if [ "$PLAYLISTDATAPREFIX" ]; then
995 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
997 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1002 ## this will convert the playlist to have CRLF line-endings, if specified
1003 ## (some hardware players insist on CRLF endings)
1004 if [ "$DOSPLAYLIST" = "y" ]; then
1005 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1006 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1007 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1009 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1014 # This essentially the start of things
1017 # Query the CD to get the track info, unless the user specified -C
1018 # or we are using some actions which do not need the CDDB data at all
1019 #if [ ! X"$EXPACTIONS" = "X" ]; then
1021 #elif [ -z "$DISCID" ]; then
1022 if [ -z "$DISCID" ]; then
1023 vecho
-n "Getting CD track info... "
1024 TRACKINFO
=$
($CDDISCID $CDROM)
1025 # Make sure there's a CD in there by checking cd-discid's return code
1026 if [ "$?" = "1" ]; then
1027 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1032 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1035 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1036 # This needs to be done now because a section of the resuming code will need
1039 # get the number of digits to pad TRACKNUM with - we'll use this later
1040 # a CD can only hold 99 tracks, but since we support a feature for starting
1041 # numbering the tracks from a given number, we might need to set it as a
1042 # variable for the user to define... or obtain it somehow.
1043 if [ "$PADTRACKS" = "y" ] ; then
1047 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1048 if [ -z "$TRACKQUEUE" ]; then
1049 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1050 case "$CDROMREADERSYNTAX" in
1052 if [ "$WEHAVEACD" = "y" ]; then
1053 vecho
"Querying the CD for audio tracks..."
1054 CDPARANOIAOUTPUT
="$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )"
1056 if [ ! "$RET" = "0" ];then
1057 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1059 TRACKS
="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | awk '{print $1}' | tr -d ".
" | tr '\n' ' ' )"
1060 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1062 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks
; then
1063 TRACKS
=$
( cat $ABCDETEMPDIR/cdparanoia-audio-tracks
)
1065 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1069 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1072 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1074 if echo "$TRACKS" |
grep [[:digit
:]] > /dev
/null
2>&1 ;then :;else
1075 echo "The disc does not contain any tracks. Giving up..."
1078 echo -n "Grabbing entire CD - tracks: "
1079 if [ ! "$PADTRACKS" = "y" ] ; then
1080 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1082 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1084 while [ "$X" -ne "$TRACKS" ]
1086 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1087 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
1091 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1092 # User-supplied track queue.
1093 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1094 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1095 # Once cleaned, obtain the highest value in the trackqueue for number padding
1096 for LASTTRACK
in $TRACKQUEUE; do :; done
1097 if [ ! "$PADTRACKS" = "y" ] ; then
1098 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1100 # Now we normalize the trackqueue
1101 for TRACK
in $TRACKQUEUE ; do
1102 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1103 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1105 TRACKQUEUE
=$PADTRACKQUEUE
1106 echo Grabbing tracks
: "$TRACKQUEUE"
1109 # for LASTTRACK in $TRACKQUEUE; do :; done
1111 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1113 # We have the discid, create a temp directory after it to store all the temp
1116 if [ -e "$ABCDETEMPDIR" ]; then
1117 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1118 # It already exists, see if it's a directory
1119 if [ ! -d "$ABCDETEMPDIR" ]; then
1120 # This is a file/socket/fifo/device/etc, not a directory
1123 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1124 echo "Please investigate, remove it, and rerun abcde." >&2
1128 # It's a directory, let's see if it's owned by us
1129 if [ ! -O "$ABCDETEMPDIR" ]; then
1130 # Nope, complain and exit
1132 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1133 echo "Please investigate, remove it, and rerun abcde." >&2
1137 # See if it's populated
1138 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1139 # Wipe and start fresh
1140 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1141 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1142 if [ "$INTERACTIVE" = "y" ]; then
1148 if [ "$ANSWER" != "y" ]; then
1151 rm -rf "$ABCDETEMPDIR" ||
exit 1
1152 mkdir
"$ABCDETEMPDIR"
1153 if [ "$?" -gt "0" ]; then
1154 # Directory already exists or could not be created
1155 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1159 # Everything is fine. Check for ^encodetracklocation-
1160 # and encode-output entries in the status file and
1161 # remove them. These are not relevant across sessions.
1162 if [ -f "$ABCDETEMPDIR/status" ]; then
1163 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1164 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1165 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1167 # Remove old error messages
1168 if [ -f "$ABCDETEMPDIR/errors" ]; then
1169 rm -f "$ABCDETEMPDIR/errors"
1173 # We are starting from scratch
1174 mkdir
"$ABCDETEMPDIR"
1175 if [ "$?" -gt "0" ]; then
1176 # Directory already exists or could not be created
1177 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1180 cat /dev
/null
> "$ABCDETEMPDIR/status"
1182 if [ X
"$CUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1183 if checkstatus cuefile
; then :; else
1184 $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/cue-$
(echo $TRACKINFO | cut
-f1 -d' ').txt
1185 echo cuefile
>> "$ABCDETEMPDIR/status"
1188 # If we got the CDPARANOIA status and it is not recorded, save it now
1189 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1190 if checkstatus cdparanoia-audio-tracks
; then :; else
1191 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1192 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1197 # Create the discid file
1198 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1202 # Parses a CDDB file and outputs the title and the track names.
1203 # Variables: CDDBFILE
1207 # List out disc title/author and contents
1208 if [ "$ONETRACK" = "y" ]; then
1209 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1211 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1212 if [ ! "$ONETRACK" = "y" ]; then
1213 for TRACK
in $
(f_seq_row
1 $TRACKS)
1215 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1221 # Check for a local CDDB file, and report success
1224 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1226 CDDBLOCALSUCCESS
="n"
1227 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1228 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1231 # If the user has selected to check a local CDDB repo, we proceed with it
1232 if [ -r "${CDDBLOCALFILE}" ]; then
1233 # List out disc title/author and contents
1234 do_cddbparse
"${CDDBLOCALFILE}"
1235 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1236 if [ "$INTERACTIVE" = "y" ]; then
1238 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1239 echo -n 'Invalid selection. Please answer "y" or "n": '
1242 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1246 if [ "$USELOCALRESP" = "y" ]; then
1247 #echo "Using local copy of CDDB data"
1248 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1249 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1250 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1251 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1252 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1253 CDDBLOCALSUCCESS
="y"
1255 #echo "Not using local copy of CDDB data"
1256 CDDBLOCALSUCCESS
="n"
1258 CDDBLOCALSUCCESS
="y"
1260 CDDBLOCALSUCCESS
="n"
1268 # Perform CDDB protocol version check if it hasn't already been done
1269 if checkstatus cddb-statcomplete
; then :; else
1270 if [ "$CDDBAVAIL" = "n" ]; then
1272 echo 503 > "$ABCDETEMPDIR/cddbstat"
1275 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1276 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1277 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1278 vecho
"Checking CDDB server status..."
1279 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1280 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1281 case "$RESPONSECODE" in
1282 210) # 210 OK, status information follows (until terminating `.')
1285 501|
*) # 501 Illegal CDDB protocol level: <n>.
1286 CDDBPROTO
=`expr $CDDBPROTO - 1`
1290 if test $rc -eq 1; then
1294 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1302 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1303 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1305 # Perform CDDB query if it hasn't already been done
1306 if checkstatus cddb-querycomplete
; then :; else
1307 if [ "$CDDBAVAIL" = "n" ]; then
1309 echo 503 > "$ABCDETEMPDIR/cddbquery"
1310 # The default CDDBLOCALSUCCESS is "n"
1311 # This part will be triggered if the user CDDB repo does not
1312 # contain the entry, or if we are not trying to use the repo.
1314 vecho
"Querying the CDDB server..."
1315 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1316 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1317 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1323 # no match found in database,
1324 # wget/fetch error, or user requested not to use CDDB
1325 # Make up an error code (503) that abcde
1326 # will recognize in do_cddbread
1327 # and compensate by making a template
1328 echo 503 > "$ABCDETEMPDIR/cddbquery"
1330 *) # strange and unknown error
1331 echo ERRORCODE
=$ERRORCODE
1332 echo "abcde: $CDDBTOOL returned unknown error code"
1336 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1343 # If it's not to be used, generate a template.
1344 # Then, display it (or them) and let the user choose/edit it
1345 if checkstatus cddb-readcomplete
; then :; else
1346 vecho
"Obtaining CDDB results..."
1347 # If CDDB is to be used, interpret the query results and read all
1348 # the available entries.
1349 rm -f "$ABCDETEMPDIR/cddbchoices"
1350 CDDBCHOICES
=1 # Overridden by multiple matches
1351 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1352 case "$RESPONSECODE" in
1354 # One exact match, retrieve it
1355 # 200 [section] [discid] [artist] / [title]
1356 if checkstatus cddb-read-1-complete
; then :; else
1357 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1358 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1359 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1360 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1361 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1363 # List out disc title/author and contents
1364 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1365 for TRACK
in $
(f_seq_row
1 $TRACKS)
1367 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1369 echo >> "$ABCDETEMPDIR/cddbchoices"
1373 case "$RESPONSECODE" in
1374 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1375 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1376 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1378 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1379 # List out disc title/author and contents of template
1380 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1382 for TRACK
in $
(f_seq_row
1 $TRACKS)
1384 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1386 echo >> "$ABCDETEMPDIR/cddbchoices"
1387 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1388 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1391 # Multiple exact, (possibly multiple) inexact matches
1393 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1394 if [ "$(wc -l < $ABCDETEMPDIR/cddbquery | tr -d ' ')" -eq 3 ]; then
1395 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1396 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1397 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1399 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1401 vecho
-n "Retrieving multiple matches... "
1402 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1403 read DISCINFO
# eat top line
1407 if checkstatus cddb-read-
$X-complete; then :; else
1408 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1409 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1411 # List out disc title/author and contents
1412 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1413 for TRACK
in $
(f_seq_row
1 $TRACKS)
1415 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1417 echo >> "$ABCDETEMPDIR/cddbchoices"
1420 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1424 for TRACK
in $
(f_seq_row
1 $TRACKS)
1426 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1428 echo >> "$ABCDETEMPDIR/cddbchoices"
1429 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1430 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1433 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1440 if checkstatus cddb-edit
>/dev
/null
; then
1441 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1442 VARIOUSARTISTS
="$(checkstatus variousartists)"
1443 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1446 if [ "$INTERACTIVE" = "y" ]; then
1447 # We should show the CDDB results both when we are not using the local CDDB repo
1448 # or when we are using it but we could not find a proper match
1449 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1450 # Display the $ABCDETEMPDIR/cddbchoices file created above
1451 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1452 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1453 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1454 CHOICE
=$
(checkstatus cddb-choice
)
1455 if [ -n "$CHOICE" ] ; then
1456 case $CDDBCHOICES in
1457 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1459 echo "Selected: #$CHOICE"
1460 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1464 # The user has a choice to make, display the info in a pager if necessary
1465 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1466 # Use the debian sensible-pager wrapper to pick the pager
1467 # user has requested via their $PAGER environment variable
1468 if [ -x "/usr/bin/sensible-pager" ]; then
1469 /usr
/bin
/sensible-pager
"$ABCDETEMPDIR/cddbchoices"
1470 elif [ -x "$PAGER" ]; then
1471 # That failed, try to load the preferred editor, starting
1472 # with their PAGER variable
1473 $PAGER "$ABCDETEMPDIR/cddbchoices"
1474 # If that fails, check for less
1475 elif [ -x /usr
/bin
/less ]; then
1476 /usr
/bin
/less -f "$ABCDETEMPDIR/cddbchoices"
1477 # more should be on all UNIX systems
1478 elif [ -x /bin
/more ]; then
1479 /bin
/more "$ABCDETEMPDIR/cddbchoices"
1481 # No bananas, just cat the thing
1482 cat "$ABCDETEMPDIR/cddbchoices" >&2
1485 # It's all going to fit in one page, cat it
1486 cat "$ABCDETEMPDIR/cddbchoices" >&2
1489 # I'll take CDDB read #3 for $400, Alex
1490 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1492 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1493 # Make sure we get a valid choice
1494 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1495 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1496 echo "Invalid selection. Please choose a number between 1 and $CDDBCHOICES." >&2
1497 echo -n "Selection [0-$CDDBCHOICES]: " >&2
1499 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1501 if [ "$CDCHOICENUM" = "0" ]; then
1502 vecho
"Creating empty CDDB template..."
1504 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > $ABCDETEMPDIR/cddbread
.0
1506 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1507 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1509 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1513 # We need some code to show the selected option when local repository is selected and we have found a match
1514 vecho
"Using cached CDDB match..." >&2
1515 # Display the $ABCDETEMPDIR/cddbchoices file created above
1516 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1517 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1518 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1519 CHOICE
=$
(checkstatus cddb-choice
)
1520 if [ "$USELOCALRESP" = "y" ]; then :; else
1521 if [ -n "$CHOICE" ] ; then
1522 case $CDDBCHOICES in
1525 echo "Selected template."
1527 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1529 echo "Selected: #$CHOICE"
1530 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1538 # We're noninteractive - pick the first choice.
1539 # But in case we run a previous instance and selected a choice, use it.
1540 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1541 # Show the choice if we are not using the locally stored one
1542 # or when the local search failed to find a match.
1543 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1544 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1545 #if [ "$PREVIOUSCHOICE" ]; then
1546 cat "$ABCDETEMPDIR/cddbchoices"
1549 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1550 CDCHOICENUM
=$PREVIOUSCHOICE
1553 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1555 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1560 if checkstatus cddb-choice
>/dev
/null
; then :; else
1561 echo "abcde: internal error: cddb-choice not recorded." >&2
1564 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1565 echo -n "Edit selected CDDB data? [y/n] (" >&2
1566 if [ "$INTERACTIVE" = "y" ]; then
1567 if [ "$UNKNOWNDISK" = "y" ]; then
1570 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1579 if [ "$EDITCDDB" = "y" ]; then
1580 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1582 # Use the debian sensible-editor wrapper to pick the editor that the
1583 # user has requested via their $EDITOR environment variable
1584 if [ -x "/usr/bin/sensible-editor" ]; then
1585 /usr
/bin
/sensible-editor
"$CDDBDATA"
1586 elif [ -n "$EDITOR" ]; then
1587 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1588 # That failed, try to load the preferred editor, starting
1589 # with their EDITOR variable
1590 eval $
(echo "$EDITOR") "$CDDBDATA"
1592 # If that fails, check for a vi
1593 elif which vi
>/dev
/null
2>&1; then
1595 elif [ -x /usr
/bin
/vi
]; then
1596 /usr
/bin
/vi
"$CDDBDATA"
1597 # nano should be on all (modern, i.e., sarge) debian systems
1598 elif which nano
>/dev
/null
2>&1 ; then
1600 elif [ -x /usr
/bin
/nano
]; then
1601 /usr
/bin
/nano
"$CDDBDATA"
1602 # mg should be on all OpenBSD systems
1603 elif which mg
>/dev
/null
2>&1 ; then
1605 elif [ -x /usr
/bin
/mg
]; then
1606 /usr
/bin
/mg
"$CDDBDATA"
1609 echo "No editor available. Check your EDITOR environment variable." >&2
1611 # delete editor backup file if it exists
1612 if [ -w "$CDDBDATA~" ]; then
1617 # Some heuristics first. Look at Disc Title, and if it starts with
1618 # "Various", then we'll assume Various Artists
1619 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2 -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1620 echo "Looks like a Multi-Artist CD" >&2
1623 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1624 if [ "$INTERACTIVE" = "y" ]; then
1631 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1634 # Need NUMTRACKS before cddb-tool will return it:
1635 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1636 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1637 # More than 1/2 tracks contain a "/", so guess forward
1639 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1640 # More than 1/2 contain a "-", so guess forward-dash
1642 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1643 # More than 1/2 contain something in parens, so guess trailing-paren
1647 echo "1) Artist / Title" >&2
1648 echo "2) Artist - Title" >&2
1649 echo "3) Title / Artist" >&2
1650 echo "4) Title - Artist" >&2
1651 echo "5) Artist: Title" >&2
1652 echo "6) Title (Artist)" >&2
1653 echo "7) This is a single-artist CD" >&2
1654 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1655 if [ "$INTERACTIVE" = "y" ]; then
1656 read VARIOUSARTISTSTYLE
1658 echo $DEFAULTSTYLE >&2
1659 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1661 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1662 # If they press Enter, then the default style (0) was chosen
1663 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1664 echo "Invalid selection. Please choose a number between 1 and 7."
1665 echo -n "Selection [1-7]: "
1666 read VARIOUSARTISTSTYLE
1667 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1669 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1670 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1672 vecho
"Selected: $VARIOUSARTISTSTYLE"
1673 case "$VARIOUSARTISTSTYLE" in
1675 VARIOUSARTISTSTYLE
=forward
1678 VARIOUSARTISTSTYLE
=forward-dash
1681 VARIOUSARTISTSTYLE
=reverse
1684 VARIOUSARTISTSTYLE
=reverse-dash
1687 VARIOUSARTISTSTYLE
=colon
1690 VARIOUSARTISTSTYLE
=trailing-paren
1698 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1699 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1701 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1702 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1703 # This works but does not have the necessary error checking
1704 # yet. If you are familiar with the CDDB spec
1705 # (see http://www.freedb.org/src/latest/DBFORMAT)
1706 # and can create an error-free entry on your own, then put
1707 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1708 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1709 # your abcde.conf to change the email address submissions are
1712 # submit the modified file, if they want
1713 if [ "$NOSUBMIT" != "y" ]; then
1714 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1716 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1717 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1719 echo -n 'Invalid selection. Please answer "y" or "n": '
1722 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1723 echo -n "Sending..."
1724 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1730 # Make sure the cache directory exists
1731 mkdir
-p $CDDBLOCALDIR
1732 # Cache edited CDDB entry in the user's cddb dir
1733 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1734 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1737 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1740 # do_cdread [tracknumber]
1741 # do_cdread onetrack [firsttrack] [lasttrack]
1745 # The commands here don't go through run_command because they're never supposed to be silenced
1746 # return codes need to be doublechecked anyway, however
1747 if [ "$1" = "onetrack" ]; then
1748 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1749 # FIXME # Until then, we grab the whole CD in one track, no matter what
1751 # We need the first and last track for cdda2wav
1754 case "$CDROMREADERSYNTAX" in
1755 cdparanoia
) UTRACKNUM
="1-" ;;
1756 cdda2wav
) UTRACKNUM
="1+$LASTRACK" ;;
1757 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1763 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1764 if [ "$USEPIPES" = "y" ]; then
1765 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1768 PIPE_MESSAGE
="and encoding "
1770 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1771 case "$CDROMREADERSYNTAX" in
1772 ## FIXME ## Find the case for dagrab, to avoid exceptions
1774 FILEARG
="-f $WAVDATA"
1782 if [ -r "$CDDBDATA" ]; then
1783 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1784 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1786 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1788 case "$CDROMREADERSYNTAX" in
1789 cdparanoia
) nice
$READNICE $CDROMREADER -d $CDROM $UTRACKNUM $FILEARG $REDIR ;;
1791 if [ "$OSFLAVOUR" = "OSX" ] ; then
1792 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1793 disktool
-u ${CDROM#/dev/} 0
1794 # Also, in OSX the cdrom device for cdda2wav changes...
1795 CDDA2WAVCDROM
="IODVDServices"
1796 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1797 CDDA2WAVCDROM
="$CDROMID"
1799 if [ "$CDROMID" = "" ]; then
1800 CDDA2WAVCDROM
="$CDROM"
1802 CDDA2WAVCDROM
="$CDROMID"
1805 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM $FILEARG $REDIR
1807 ## FIXME ## We have an exception for dagrab, since it uses -f
1808 ## FIXME ## Shall we just use -f $FILEARG ??
1809 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM $FILEARG $REDIR
1812 # Find the track's mounted path
1813 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1814 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1815 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
1816 # If the file exists, copy it
1817 if [ -e "$FILEPATH" ] ; then
1818 nice
$READNICE $CDROMREADER "$FILEPATH" $FILEARG $REDIR
1822 debug
) nice
$READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] $FILEARG $REDIR
1826 # If we get some error or we get some missing wav
1827 # (as long as we dont use pipes)
1828 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
1829 # Thank goodness errors is only machine-parseable up to the
1830 # first colon, otherwise this woulda sucked
1831 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1832 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
1834 if [ "$USEPIPES" = "y" ]; then
1835 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1837 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1841 if [ "$USEPIPES" = "y" ]; then
1842 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1844 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1850 # No values accepted, only uses env variables
1853 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
1854 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
1856 echo "abcde: unable to set the device speed" >&2
1862 # vecho outputs a message if EXTRAVERBOSE is selected
1865 if [ x
"$EXTRAVERBOSE" != "x" ]; then
1870 # User-redefinable functions
1871 # Custom filename munging:
1874 echo "$@" |
sed s
,:,\
-,g |
tr \
/\
* __
+ |
tr -d \'\"\?\
[:cntrl
:\
]
1877 # Custom genre munging:
1880 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
1884 # Empty pre_read function, to be defined in the configuration file.
1890 ###############################################################################
1893 # Start of execution
1894 ###############################################################################
1897 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
1898 CDDBSUBMIT
=freedb-submit@freedb.org
1900 HELLOINFO
="$(whoami)@$(hostname)"
1902 CDROMREADERSYNTAX
=cdparanoia
1904 ENCODERSYNTAX
=default
1906 MP3ENCODERSYNTAX
=default
1907 OGGENCODERSYNTAX
=default
1908 FLACENCODERSYNTAX
=default
1909 SPEEXENCODERSYNTAX
=default
1910 MPPENCODERSYNTAX
=default
1911 NORMALIZERSYNTAX
=default
1913 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
1914 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
1915 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
1916 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
1917 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
1918 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
1919 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1920 PLAYLISTDATAPREFIX
=''
1921 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1922 VAPLAYLISTDATAPREFIX
=''
1930 VARIOUSARTISTSTYLE
=forward
1934 CDDBLOCALDIR
="$HOME/.cddb"
1937 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
1938 # i.e. CDROMID="1,0,0"
1941 # program paths - defaults to checking your $PATH
1947 XINGMP3ENC
=xingmp3enc
1961 CDPARANOIA
=cdparanoia
1970 VORBISCOMMENT
=vorbiscomment
1972 NORMALIZE
=normalize-audio
1974 VORBISGAIN
=vorbisgain
1977 # Options for programs called from abcde
2009 # Default to one process if -j isn't specified
2012 # List of actions to perform - by default, run to completion
2013 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2015 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2016 # Let's use these checkings to determine the OS flavour, which will be used later
2017 if [ X$
(uname
) = "XFreeBSD" ] ; then
2021 elif [ X$
(uname
) = "XDarwin" ] ; then
2024 # We should have disktool in OSX, but let's be sure...
2026 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2033 # If CDDBAVAIL is set to n, no CDDB read is done
2034 # If USEID3 is set to n, no ID3 tagging is done
2039 if [ -z "$OUTPUTDIR" ]; then
2043 if [ -z "$WAVOUTPUTDIR" ]; then
2044 WAVOUTPUTDIR
="$OUTPUTDIR"
2047 # Load system defaults
2048 if [ -r /etc
/abcde.conf
]; then
2051 # Load user preference defaults
2052 if [ -r $HOME/.abcde.conf
]; then
2056 # By this time, we need some HTTPGETOPTS already defined.
2057 # If the user has defined a non-default HTTPGET method, we should not be empty.
2059 if [ "$HTTPGETOPTS" = "" ] ; then
2061 wget
) HTTPGETOPTS
="-q -O -";;
2062 curl
) HTTPGETOPTS
="-f -s";;
2063 fetch
)HTTPGETOPTS
="-q -o -";;
2064 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2068 # If the CDROM has not been set yet, find a suitable one.
2069 # If this is a devfs system, default to /dev/cdroms/cdrom0
2070 # instead of /dev/cdrom
2071 if [ "$CDROM" = "" ] ; then
2072 if [ -e /dev
/cdroms
/cdrom0
]; then
2073 CDROM
=/dev
/cdroms
/cdrom0
2074 elif [ -e /dev
/cdrom
]; then
2076 elif [ -e /dev
/cd0c
]; then
2078 elif [ -e /dev
/acd0c
]; then
2080 elif [ -e /dev
/disk1
]; then
2085 # Parse command line options
2086 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
2087 while getopts 1a
:A
:bc:C
:d
:Dhj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
2090 a
) ACTIONS
="$OPTARG" ;;
2091 A
) EXPACTIONS
="$OPTARG";;
2093 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2094 C
) DISCID
="${OPTARG#abcde.}" ;;
2095 d
) CDROM
="$OPTARG" ;;
2098 # f) FORCECDDBUSELOCAL=y ;;
2100 j
) MAXPROCS
="$OPTARG" ;;
2103 L
) CDDBUSELOCAL
=y
;;
2108 o
) OUTPUTTYPE
="$OPTARG" ;;
2111 r
) REMOTEHOSTS
="$OPTARG" ;;
2113 s
) STARTTRACKNUMBER
="$OPTARG" ;;
2114 S
) CDSPEEDVALUE
="$OPTARG" ;;
2115 # t) PREPROCESSFORMATS="$OPTARG"
2117 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2118 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2119 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2121 echo "This is abcde v$VERSION."
2122 echo "Usage: abcde [options] [tracks]"
2123 echo "abcde -h for extra help"
2126 V
) EXTRAVERBOSE
="y" ;;
2128 w
) COMMENT
="$OPTARG" ;;
2129 W
) STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}" ;;
2134 shift $
(($OPTIND - 1))
2136 # Decide if we can continue.
2137 if [ "$ONETRACK" = "y" ]; then
2138 # FIXME # remove check as soon as we find out about the other readers
2139 case "$CDROMREADERSYNTAX" in
2140 dagrab|cddafs|debug
) echo "abcde error: ONETRACK reading is not suported with "$CDROMREADERSYNTAX" yet"
2143 if [ "$BATCH" = "y" ]; then
2144 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2147 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2148 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2149 if [ $# -gt 0 ]; then
2150 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2153 while [ $# -gt 0 ]; do
2154 # Range parsing code courtesy of Vincent Ho
2155 RSTART
=$
(echo $1 | cut
-f1 -d-)
2156 REND
=$
(echo $1 | cut
-f2 -d-)
2157 if [ "$RSTART" = "$REND" ]; then
2160 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2162 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2167 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2168 # List of experimental actions: retag,transcode
2170 # Determine what actions are to be done from $ACTIONS and set the
2171 # following environment variables for them:
2183 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2188 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2189 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2190 encode
) DOENCODE
=y
; DOREAD
=y
;;
2191 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2192 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2193 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2194 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2201 # At this point a CDROM has to be defined, so we check it exists.
2202 if [ X
"$CDROM" != "X" ] ; then
2203 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2204 if [ "$OSFLAVOUR" = "FBSD" ]; then
2205 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2206 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2207 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2211 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "y" ]; then
2212 echo "abcde error: CDROM device cannot be found." >&2
2215 # avoid processing if we are not going to hit the CDROM.
2216 elif [ X
"$DOREAD" = "y" ]; then
2217 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2221 # USEPIPES pre-tests, before we get into more serious stuff
2222 # Not compatible with:
2223 # - multiple outputs
2225 # - lowdisk algorithm
2227 if [ X
"$USEPIPES" = "Xy" ]; then
2228 if [ $
(echo $OUTPUTTYPE |
tr , \ |
wc -w ) -gt 1 ]; then
2229 echo "abcde error: Unix pipes not compatible with multiple outputs"
2232 if [ X
"$DONORMALIZE" = "Xy" ]; then
2233 echo "abcde error: Unix pipes not compatible with normalizer"
2234 # FIXME # Do we need to exit or shall we just disable the mode?
2237 if [ X
"$DOENCODE" = "Xn" ]; then
2238 vecho
"Disabling Unix pipes since we are not encoding!"
2241 if [ X
"$LOWDISK" = "Xy" ]; then
2242 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2247 # Decide which CDROM reader we're gonna use
2248 case "$CDROMREADERSYNTAX" in
2250 CDROMREADER
="$CDPARANOIA"
2251 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2254 CDROMREADER
="$CDDA2WAV"
2255 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2258 CDROMREADER
="$DAGRAB"
2259 CDROMREADEROPTS
="$DAGRABOPTS"
2262 CDROMREADER
="$CDDAFS"
2263 CDROMREADEROPTS
="$CDDAFSOPTS"
2267 # There's only one normalize...
2268 case "$NORMALIZERSYNTAX" in
2270 NORMALIZER
="$NORMALIZE"
2271 NORMALIZEROPTS
="$NORMALIZEOPTS"
2275 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2276 if echo $OUTPUTTYPE |
grep ":" > /dev
/null
2>&1 ; then
2279 for OUTPUT
in "$OUTPUTTYPE"
2282 ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2283 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2284 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2285 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2286 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2289 for OUTPUT
in "$OUTPUTTYPE"
2291 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2292 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2294 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2298 # 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
2300 # Getting ready for multiple output changes
2301 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2304 ogg
) [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2305 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2306 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2308 mp3
) [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2309 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2311 flac
) [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2312 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2314 spx
) [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
;;
2315 mpc
) [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
;;
2316 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2322 # decide which encoder
2323 case "$MP3ENCODERSYNTAX" in
2325 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2329 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2333 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2334 MP3ENCODER
="$BLADEENC"
2337 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2341 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2342 MP3ENCODER
="$XINGMP3ENC"
2345 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2346 MP3ENCODER
="$MP3ENC"
2349 case "$OGGENCODERSYNTAX" in
2351 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2352 OGGENCODER
="$VORBIZE"
2355 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2356 OGGENCODER
="$OGGENC"
2359 case "$FLACENCODERSYNTAX" in
2361 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2365 case "$SPEEXENCODERSYNTAX" in
2367 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2368 SPEEXENCODER
="$SPEEXENC"
2371 case "$MPPENCODERSYNTAX" in
2373 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2374 MPPENCODER
="$MPPENC"
2380 if [ "$ID3TAGV" = "1" ]; then
2382 TAGGEROPTS
="$ID3OPTS"
2385 TAGGEROPTS
="$ID3V2OPTS"
2388 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2390 if [ "$ENCNICE" ]; then
2391 ENCNICE
="-n $ENCNICE"
2393 if [ "$READNICE" ]; then
2394 READNICE
="-n $READNICE"
2396 if [ "$DISTMP3NICE" ]; then
2397 DISTMP3NICE
="-n $DISTMP3NICE"
2400 # Don't check for stuff if it's not needed
2401 if [ "$REMOTEHOSTS" ]; then NEEDDISTMP3
=y
; fi
2402 [ "$DONORMALIZE" = "y" ] && NEEDNORMALIZER
=y
2403 [ "$EJECTCD" = "y" ] && NEEDEJECT
=y
2404 [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ] && NEEDHTTPGET
=y
2405 [ "$CUEFILE" = "y" ] && NEEDMKCUE
=y
2407 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2408 case "$CDROMREADERSYNTAX" in
2409 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2414 # Rippers with USEPIPE support
2415 # FIXME # Include here all the rippers we can figure out support pipes
2418 # Encoders with USEPIPE support
2419 # FIXME # Include here all the encoders we can figure out support pipes
2423 # Figure out if we can use pipes with the ripper/encoder combination
2425 if [ "$USEPIPES" = "y" ]; then
2426 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2429 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2431 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2433 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYTNAX" ;;
2435 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2437 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2439 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2440 echo "abcde error: no support for pipes with given ripper" >&2
2441 echo "read the USEPIPES file from the source tarball to help" >&2
2442 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2445 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2446 echo "abcde error: no support for pipes with given encoder" >&2
2447 echo "read the USEPIPES file from the source tarball to help" >&2
2448 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2454 # Make sure a buncha things exist
2455 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2456 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2457 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2458 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2459 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2460 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2461 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2463 # Cut off the command-line options we just added in
2464 X
=$
(echo $X | cut
-d' ' -f2)
2465 if [ "$(which $X)" = "" ]; then
2466 echo "abcde error: $X is not in your path." >&2
2468 elif [ ! -x $
(which $X) ]; then
2469 echo "abcde error: $X is not executable." >&2
2474 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2475 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2476 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2478 # Here it used to say:
2479 # One thousand lines in, we can start doing stuff with things
2480 # Well, right now we are at line 2157 ;)
2482 # Export needed things so they can be read in this subshell
2483 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2484 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2486 # User-definable function to set some things. Use it for
2487 # - closing the CD tray with eject -t
2488 # - set the CD speed value with eject -x
2489 vecho
-n "Executing customizable pre-read function... "
2491 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2495 do_discid
# Get ABCDETEMPDIR created and status file initialized
2497 if [ "$DOCDDB" = "y" ]; then
2498 if [ $CDDBUSELOCAL = "y" ]; then
2501 if checkstatus cddb-choice
> /dev
/null
; then
2504 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2512 eval $
($CDDBTOOL parse
"$CDDBDATA")
2515 # Before reading tracks, we set the speed of the device
2517 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2518 case "$CDROMREADERSYNTAX" in
2519 cdparanoia|debug
) : ;;
2524 # Create playlist if needed (backgroundable) and start reading in tracks
2528 if [ ! "$ONETRACK" = "y" ]; then
2529 if [ "$DOPLAYLIST" = "y" ]; then
2530 echo Creating playlist...
>&2
2535 # For the lowdisk option, only one program is running at once so the encoder
2536 # can be unsilenced right away.
2537 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2538 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2541 if [ "$ONETRACK" = "y" ]; then
2542 FIRSTTRACK
=$
( echo $TRACKQUEUE |
awk '{print $1}' )
2543 TRACKS
="$FIRSTTRACK"
2544 for UTRACKNUM
in $TRACKQUEUE; do :;done
2545 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2546 do_cdread onetrack
$FIRSTTRACK $UTRACKNUM
2549 for UTRACKNUM
in $TRACKQUEUE
2551 if [ "$DOREAD" = "y" ]; then
2552 if [ "$USEPIPES" = "y" ]; then
2553 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2554 # Read, pipe, shut up!
2555 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
2558 if checkstatus readtrack-
$UTRACKNUM; then :; else
2559 do_cdread
$UTRACKNUM
2561 if [ "$?" != "0" ]; then
2562 # CD read failed - don't give the goahead to
2569 if [ "$BATCH" = "y" ]; then
2572 echo NEXTTRACK
# Get the encoder machine churning again
2573 if [ "$DOREAD" = "y" ]; then
2574 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2575 until checkstatus encodetrack-
$UTRACKNUM
2577 if checkerrors encodetrack-
$UTRACKNUM; then
2588 # Now that we're done the encoding can be loud again -
2589 # if we're not using SMP.
2590 if [ "$MAXPROCS" = "1" ]; then
2591 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2594 # All tracks read, start encoding.
2595 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2599 # We are now finished with the cdrom - it can be safely ejected. Note that
2600 # abcde will not have completed yet.
2601 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2602 # We check if the disk we are processing is actually the disk inside the
2603 # CD tray. If not, we do not eject the CD, since it might be so that the
2604 # user ejected it manually.
2605 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2606 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2607 # More FreeBSD bits.
2608 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2609 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2610 # but in this script EJECT is in the envionment and names the program
2613 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2614 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2615 $eject $EJECTOPTS $cd
2616 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2617 disktool
-e ${CDROM#/dev/} 0
2619 $EJECT $EJECTOPTS $CDROM
2626 ## Do we need to pre-process
2627 #if [ x"$PREPROCESS" = "x" ] ; then
2630 # for PRETRACKNUM in $TRACKQUEUE
2633 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2635 # until [ $PREPROCEED ]
2637 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2638 # # all locations are working, wait and try again later
2639 # if [ ! $PREPROCEED ]; then sleep 3; fi
2641 # ( do_preprocess $PRETRACKNUM
2649 # In batch mode, we want all tracks to be read first.
2650 if [ "$BATCH" = "y" ]; then
2651 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2652 if [ "$GOAHEAD" = "NO" ]; then break; fi
2653 for LASTTRACK
in $TRACKQUEUE; do :; done
2654 if checkstatus readtrack-
$LASTTRACK; then
2655 if [ "$DONORMALIZE" = "y" ]; then
2656 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2657 if checkerrors batch-normalize
; then exit; fi
2659 if [ "$DOENCODE" = "y" ]; then
2660 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2661 if checkerrors batch-encode
; then exit; fi
2666 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2667 if [ "$ONETRACK" = "y" ] ; then
2668 FIRSTTRACK
=$
( echo $TRACKQUEUE |
awk '{print $1}')
2669 TRACKQUEUE
=$FIRSTTRACK
2670 TRACKS
="$FIRSTTRACK"
2673 # Do the encoding, including parallelization of remote encoding
2674 # Figure out where each track is going to be encoded
2675 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2676 if [ "$MAXPROCS" != "0" ]; then
2677 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2679 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2683 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2684 for UTRACKNUM
in $TRACKQUEUE
2687 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2688 if [ "$GOAHEAD" = "NO" ]; then break; fi
2689 # find out where this track is to be encoded
2690 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2691 # Make sure we have a place to encode this, if not, exit stage right
2692 if [ -z "$ENCODELOCATIONS" ]; then
2698 for LOCATION
in $ENCODELOCATIONS
2700 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2701 # check first if a track has ever been assigned to this location
2702 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
2703 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2704 if checkerrors encodetrack-
$PREVIOUSTRACK; then
2705 for TEMPLOCATION
in $ENCODELOCATIONS
2707 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2708 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
2711 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
2716 # We're still here, this location must have been previously assigned,
2717 # and last completed without error - check if it's done with the
2718 # previous track yet
2719 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
2721 # all locations are working, wait and try again later
2722 if [ ! $PROCEED ]; then sleep 3; fi
2724 # Record the location we're about to encode the next track at
2725 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2727 # Don't proceed with the rest of the loop if we can't encode
2728 if [ "$ABORT" ]; then continue; fi
2729 # Set TRACKNUM, TRACKNAME
2730 if [ -e "$CDDBDATA" ]; then
2731 if [ "$ONETRACK" = "y" ]; then
2733 TRACKNUM
="$FIRSTTRACK"
2736 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
2738 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2739 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
2743 # You can't encode a file which needs to be normalized before finishing
2744 # You can't tag a file before it's finished encoding -
2745 # thus all of this is backgrounded together
2747 if [ "$DONORMALIZE" = "y" ]; then
2748 if checkstatus readtrack-
$UTRACKNUM; then
2749 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
2752 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2753 if checkstatus readtrack-
$UTRACKNUM; then
2754 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
2755 if [ "$DONORMALIZE" = "y" ]; then
2756 if checkstatus normalizetrack-
$UTRACKNUM; then
2757 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2760 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2764 if [ "$DOTAG" = "y" ]; then
2765 if checkstatus encodetrack-
$UTRACKNUM; then
2766 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
2769 if [ "$DOMOVE" = "y" ]; then
2770 if checkstatus tagtrack-
$UTRACKNUM; then
2771 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
2776 # Go through it again and make sure there's no distmp3 stragglers, otherwise
2777 # we'll delete the files they're working on
2778 ## FIXME ## Check also for files which are encoded using PIPEs.
2779 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2784 for LOCATION
in $ENCODELOCATIONS
2786 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2787 # "How can he give us a status update, if he's DEAD?"
2788 if checkstatus encodetrack-
$CHECKTRACK; then
2791 # Nothing to see here please go quietly back to your homes
2792 if [ -z "$CHECKTRACK" ]; then continue; fi
2793 # You're still here? Maybe there is something...
2794 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
2797 if [ ! $PROCEED ]; then sleep 5; fi
2800 # If the above didn't catch the stragglers, this will
2802 # Check to see if run_command logged any errors
2803 if [ -f "$ABCDETEMPDIR/errors" ]; then
2804 echo "The following commands failed to run:"
2805 cat "$ABCDETEMPDIR/errors"
2809 if [ "$KEEPWAVS" = "y" ];then
2813 if [ "$DOCLEAN" = "y" ]; then
2814 # Wipe all the evidence
2815 # Gimme gimme gimme some more time!
2817 rm -rf "$ABCDETEMPDIR"
2820 echo "Finished. Not cleaning $ABCDETEMPDIR."