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"
278 TRACKARTIST
="$DARTIST"
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"
509 ## FIXME ## [ "$FLACONOGG" = "y" ] && OUTPUT=ogg
511 echo ARTIST
="$TRACKARTIST"
513 echo TITLE
="$TRACKNAME"
514 if [ -n "$CDYEAR" ]; then
517 if [ -n "$CDGENRE" ]; then
518 echo GENRE
="$CDGENRE"
520 echo TRACKNUMBER
=${TRACKNUM:-$1}
521 echo CDDB
=$CDDBDISCID
522 if [ "$(eval echo ${COMMENT})" != "" ]; then
523 case "$COMMENTOUTPUT" in
524 *=*) echo "$COMMENTOUTPUT";;
525 *) echo COMMENT
="$COMMENTOUTPUT";;
528 ) | run_command tagtrack-
$1 $METAFLAC --no-utf8-convert --import-tags-from=- "$ABCDETEMPDIR/track$1.$OUTPUT"
531 run_command tagtrack-
$1 true
534 run_command tagtrack-
$1 true
542 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
545 # The commands here don't go through run_command because they're never supposed to be silenced
546 echo "Batch encoding tracks: $TRACKQUEUE"
547 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
550 case "$MP3ENCODERSYNTAX" in
555 for UTRACKNUM
in $TRACKQUEUE
557 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
559 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
561 if [ "$RETURN" != "0" ]; then
562 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
564 for UTRACKNUM
in $TRACKQUEUE
566 echo encodetrack-
$UTRACKNUM >> status
574 # Other encoders fall through to normal encoding as the tracks
575 # have not been entered in the status file.
578 # do_encode [tracknumber] [hostname]
579 # If no hostname is specified, encode locally
581 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
584 if [ "$USEPIPES" = "y" ]; then
587 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
590 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
593 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
596 TEMPARG
="PIPE_$SPEEXENCODER"
599 TEMPARG
="PIPE_$MPPENCODER"
604 IN
="$ABCDETEMPDIR/track$1.wav"
607 case "$MP3ENCODERSYNTAX" in
608 # FIXME # check if mp3enc needs -if for pipes
622 # We need IN to proceed, if we are not using pipes.
623 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
624 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
626 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
627 if [ X
"$USEPIPES" = "Xy" ]; then
630 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
631 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
637 case "$MP3ENCODERSYNTAX" in
638 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
639 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
640 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
641 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
642 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
646 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
653 case "$OGGENCODERSYNTAX" in
654 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
655 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
659 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
666 case "$FLACENCODERSYNTAX" in
667 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
673 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
674 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
679 if [ "$(eval echo ${COMMENT})" != "" ]; then
682 *) COMMENT
="COMMENT=$COMMENT" ;;
684 COMMENT
="--comment \"$COMMENT\""
686 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
687 if [ ! "$DOTAG" = "y" ]; then
688 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
690 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
694 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
696 # I tried compiling the mppenc from corecodecs.org and got some
697 # errors, so I have not tried it myself.
698 ## FIXME ## Needs some cleanup to determine if an empty tag sent
699 ## FIXME ## to the encoder ends up empty.
700 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
704 # Only remove .wav if the encoding succeeded
705 if checkerrors
"encodetrack-(.{3,4})-$1"; then
706 run_command encodetrack-
$1 false
708 run_command encodetrack-
$1 true
709 if [ ! "$KEEPWAVS" = "y" ] ; then
714 if [ "$(checkstatus encode-output)" = "loud" ]; then
715 echo "HEH! The file we were about to encode disappeared:"
718 run_command encodetrack-
$1 false
722 # do_preprocess [tracknumber]
724 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
727 # IN="$ABCDETEMPDIR/track$1.wav"
728 # # We need IN to proceed.
729 # if [ -s "$IN" ] ; then
730 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
732 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
733 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
734 # case "$POSTPROCESSFORMAT" in
736 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
738 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
740 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
742 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
744 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
747 # # Only remove .wav if the encoding succeeded
748 # if checkerrors "preprocess-(.{3,4})-$1"; then
749 # run_command preprocess-$1 false
751 # run_command preprocess-$1 true
754 # if [ "$(checkstatus encode-output)" = "loud" ]; then
755 # echo "HEH! The file we were about to pre-process disappeared:"
758 # run_command preprocess-$1 false
763 # do_postprocess [tracknumber]
765 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
768 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
770 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
771 # # We need IN to proceed.
772 # if [ -s "$IN" ] ; then
773 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
774 # run_command '' echo "Post-processing track $1 of $TRACKS..."
775 # case "$POSTPROCESSFORMAT" in
777 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
779 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
781 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
783 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
785 # # Only remove .wav if the encoding succeeded
786 # if checkerrors "postprocess-(.{3,4})-$1"; then
787 # run_command postprocess-$1 false
789 # run_command postprocess-$1 true
792 # if [ "$(checkstatus encode-output)" = "loud" ]; then
793 # echo "HEH! The file we were about to post-process disappeared:"
796 # run_command postprocess-$1 false
803 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
806 # The commands here don't go through run_command because they're never supposed to be silenced
807 echo "Batch analizing gain in tracks: $TRACKQUEUE"
812 for UTRACKNUM
in $TRACKQUEUE
814 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
816 # XXX: Hard-coded batch option!
817 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
819 if [ "$RETURN" != "0" ]; then
820 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
822 for UTRACKNUM
in $TRACKQUEUE
824 echo normalizetrack-
$UTRACKNUM >> status
832 # NORMALIZER, NORMALIZEROPTS
833 do_batch_normalize
()
835 # The commands here don't go through run_command because they're never supposed to be silenced
836 echo "Batch normalizing tracks: $TRACKQUEUE"
841 for UTRACKNUM
in $TRACKQUEUE
843 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
845 # XXX: Hard-coded batch option!
846 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
848 if [ "$RETURN" != "0" ]; then
849 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
851 for UTRACKNUM
in $TRACKQUEUE
853 echo normalizetrack-
$UTRACKNUM >> status
859 # do_normalize [tracknumber]
861 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
864 IN
="$ABCDETEMPDIR/track$1.wav"
865 if [ -e "$IN" ] ; then
866 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
867 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
869 if [ "$(checkstatus encode-output)" = "loud" ]; then
870 echo "HEH! The file we were about to normalize disappeared:"
873 run_command normalizetrack-
$1 false
"File $IN was not found"
877 # do_move [tracknumber]
878 # Deduces the outfile from environment variables
879 # Creates directory if necessary
881 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
884 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
886 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
887 # Munge filenames as follows:
892 # Eat control characters
893 ALBUMFILE
=$
(mungefilename
"$DALBUM")
894 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
895 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
896 GENRE
=$
(mungegenre
"$GENRE")
898 # If we want to start the tracks with a given number, we need to modify the
899 # TRACKNUM value before evaluation
900 if [ -n "$STARTTRACKNUMBER" ] ; then
901 # Get the trackpadding from the current track
902 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
903 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
905 TRACKNUM
=${UTRACKNUM}
907 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
908 # TRACKFILE, and TRACKNUM.
909 if [ "$VARIOUSARTISTS" = "y" ]; then
910 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
912 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
914 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
915 OUTPUTFILEDIR
=$
(dirname "$OUTPUTDIR/$OUTPUTFILE")
916 # mkdir -p shouldn't return an error if the directory already exists
917 mkdir
-p "$OUTPUTFILEDIR"
918 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
923 # Create the playlist if wanted
925 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
926 # VARIOUSARTISTS, OUTPUTDIR
929 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
931 # Create a playlist file for the playlist data to go into.
932 # We used to wipe it out if it existed. Now we request permision if interactive.
933 for LASTTRACK
in $TRACKQUEUE; do :; done
934 ALBUMFILE
=$
(mungefilename
"$DALBUM")
935 ARTISTFILE
=$
(mungefilename
"$DARTIST")
936 GENRE
=$
(mungegenre
"$GENRE")
937 if [ "$VARIOUSARTISTS" = "y" ] ; then
938 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
940 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
942 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
943 mkdir
-p "$FINALPLAYLISTDIR"
944 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
945 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
946 if [ "$INTERACTIVE" = "y" ]; then
947 while [ "$DONE" != "y" ]; do
949 case $ERASEPLAYLIST in
950 e|E|a|A|k|K
) DONE
=y
;;
958 # Once we erase the playlist, we use append to create the new one.
959 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
961 # The playlist does not exist, so we can safelly use append to create the new list
964 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
965 touch "$OUTPUTDIR/$PLAYLISTFILE"
966 for UTRACKNUM
in $TRACKQUEUE
968 # Shares some code with do_move since the filenames have to match
969 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
970 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
972 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
973 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
974 # If we want to start the tracks with a given number, we need to modify the
975 # TRACKNUM value before evaluation
976 if [ -n "$STARTTRACKNUMBER" ] ; then
977 # Get the trackpadding from the current track
978 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
979 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
981 TRACKNUM
=${UTRACKNUM}
983 if [ "$VARIOUSARTISTS" = "y" ]; then
984 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
986 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
988 if [ "$VARIOUSARTISTS" = "y" ]; then
989 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
990 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
992 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
995 if [ "$PLAYLISTDATAPREFIX" ]; then
996 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
998 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1003 ## this will convert the playlist to have CRLF line-endings, if specified
1004 ## (some hardware players insist on CRLF endings)
1005 if [ "$DOSPLAYLIST" = "y" ]; then
1006 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1007 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1008 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1010 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1015 # This essentially the start of things
1018 # Query the CD to get the track info, unless the user specified -C
1019 # or we are using some actions which do not need the CDDB data at all
1020 #if [ ! X"$EXPACTIONS" = "X" ]; then
1022 #elif [ -z "$DISCID" ]; then
1023 if [ -z "$DISCID" ]; then
1024 vecho
-n "Getting CD track info... "
1025 TRACKINFO
=$
($CDDISCID $CDROM)
1026 # Make sure there's a CD in there by checking cd-discid's return code
1027 if [ "$?" = "1" ]; then
1028 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1033 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1036 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1037 # This needs to be done now because a section of the resuming code will need
1040 # get the number of digits to pad TRACKNUM with - we'll use this later
1041 # a CD can only hold 99 tracks, but since we support a feature for starting
1042 # numbering the tracks from a given number, we might need to set it as a
1043 # variable for the user to define... or obtain it somehow.
1044 if [ "$PADTRACKS" = "y" ] ; then
1048 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1049 if [ -z "$TRACKQUEUE" ]; then
1050 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1051 case "$CDROMREADERSYNTAX" in
1053 if [ "$WEHAVEACD" = "y" ]; then
1054 vecho
"Querying the CD for audio tracks..."
1055 CDPARANOIAOUTPUT
="$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )"
1057 if [ ! "$RET" = "0" ];then
1058 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1060 TRACKS
="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | awk '{print $1}' | tr -d ".
" | tr '\n' ' ' )"
1061 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1063 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks
; then
1064 TRACKS
=$
( cat $ABCDETEMPDIR/cdparanoia-audio-tracks
)
1066 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1070 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1073 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1075 if echo "$TRACKS" |
grep [[:digit
:]] > /dev
/null
2>&1 ;then :;else
1076 echo "The disc does not contain any tracks. Giving up..."
1079 echo -n "Grabbing entire CD - tracks: "
1080 if [ ! "$PADTRACKS" = "y" ] ; then
1081 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1083 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1085 while [ "$X" -ne "$TRACKS" ]
1087 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1088 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
1092 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1093 # User-supplied track queue.
1094 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1095 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1096 # Once cleaned, obtain the highest value in the trackqueue for number padding
1097 for LASTTRACK
in $TRACKQUEUE; do :; done
1098 if [ ! "$PADTRACKS" = "y" ] ; then
1099 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1101 # Now we normalize the trackqueue
1102 for TRACK
in $TRACKQUEUE ; do
1103 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1104 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1106 TRACKQUEUE
=$PADTRACKQUEUE
1107 echo Grabbing tracks
: "$TRACKQUEUE"
1110 # for LASTTRACK in $TRACKQUEUE; do :; done
1112 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1114 # We have the discid, create a temp directory after it to store all the temp
1117 if [ -e "$ABCDETEMPDIR" ]; then
1118 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1119 # It already exists, see if it's a directory
1120 if [ ! -d "$ABCDETEMPDIR" ]; then
1121 # This is a file/socket/fifo/device/etc, not a directory
1124 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1125 echo "Please investigate, remove it, and rerun abcde." >&2
1129 # It's a directory, let's see if it's owned by us
1130 if [ ! -O "$ABCDETEMPDIR" ]; then
1131 # Nope, complain and exit
1133 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1134 echo "Please investigate, remove it, and rerun abcde." >&2
1138 # See if it's populated
1139 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1140 # Wipe and start fresh
1141 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1142 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1143 if [ "$INTERACTIVE" = "y" ]; then
1149 if [ "$ANSWER" != "y" ]; then
1152 rm -rf "$ABCDETEMPDIR" ||
exit 1
1153 mkdir
"$ABCDETEMPDIR"
1154 if [ "$?" -gt "0" ]; then
1155 # Directory already exists or could not be created
1156 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1160 # Everything is fine. Check for ^encodetracklocation-
1161 # and encode-output entries in the status file and
1162 # remove them. These are not relevant across sessions.
1163 if [ -f "$ABCDETEMPDIR/status" ]; then
1164 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1165 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1166 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1168 # Remove old error messages
1169 if [ -f "$ABCDETEMPDIR/errors" ]; then
1170 rm -f "$ABCDETEMPDIR/errors"
1174 # We are starting from scratch
1175 mkdir
"$ABCDETEMPDIR"
1176 if [ "$?" -gt "0" ]; then
1177 # Directory already exists or could not be created
1178 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1181 cat /dev
/null
> "$ABCDETEMPDIR/status"
1183 if [ X
"$CUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1184 if checkstatus cuefile
; then :; else
1185 $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/cue-$
(echo $TRACKINFO | cut
-f1 -d' ').txt
1186 echo cuefile
>> "$ABCDETEMPDIR/status"
1189 # If we got the CDPARANOIA status and it is not recorded, save it now
1190 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1191 if checkstatus cdparanoia-audio-tracks
; then :; else
1192 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1193 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1198 # Create the discid file
1199 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1203 # Parses a CDDB file and outputs the title and the track names.
1204 # Variables: CDDBFILE
1208 # List out disc title/author and contents
1209 if [ "$ONETRACK" = "y" ]; then
1210 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1212 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1213 if [ ! "$ONETRACK" = "y" ]; then
1214 for TRACK
in $
(f_seq_row
1 $TRACKS)
1216 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1222 # Check for a local CDDB file, and report success
1225 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1227 CDDBLOCALSUCCESS
="n"
1228 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1229 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1232 # If the user has selected to check a local CDDB repo, we proceed with it
1233 if [ -r "${CDDBLOCALFILE}" ]; then
1234 # List out disc title/author and contents
1235 do_cddbparse
"${CDDBLOCALFILE}"
1236 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1237 if [ "$INTERACTIVE" = "y" ]; then
1239 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1240 echo -n 'Invalid selection. Please answer "y" or "n": '
1243 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1247 if [ "$USELOCALRESP" = "y" ]; then
1248 #echo "Using local copy of CDDB data"
1249 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1250 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1251 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1252 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1253 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1254 CDDBLOCALSUCCESS
="y"
1256 #echo "Not using local copy of CDDB data"
1257 CDDBLOCALSUCCESS
="n"
1259 CDDBLOCALSUCCESS
="y"
1261 CDDBLOCALSUCCESS
="n"
1269 # Perform CDDB protocol version check if it hasn't already been done
1270 if checkstatus cddb-statcomplete
; then :; else
1271 if [ "$CDDBAVAIL" = "n" ]; then
1273 echo 503 > "$ABCDETEMPDIR/cddbstat"
1276 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1277 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1278 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1279 vecho
"Checking CDDB server status..."
1280 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1281 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1282 case "$RESPONSECODE" in
1283 210) # 210 OK, status information follows (until terminating `.')
1286 501|
*) # 501 Illegal CDDB protocol level: <n>.
1287 CDDBPROTO
=`expr $CDDBPROTO - 1`
1291 if test $rc -eq 1; then
1295 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1303 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1304 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1306 # Perform CDDB query if it hasn't already been done
1307 if checkstatus cddb-querycomplete
; then :; else
1308 if [ "$CDDBAVAIL" = "n" ]; then
1310 echo 503 > "$ABCDETEMPDIR/cddbquery"
1311 # The default CDDBLOCALSUCCESS is "n"
1312 # This part will be triggered if the user CDDB repo does not
1313 # contain the entry, or if we are not trying to use the repo.
1315 vecho
"Querying the CDDB server..."
1316 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1317 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1318 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1324 # no match found in database,
1325 # wget/fetch error, or user requested not to use CDDB
1326 # Make up an error code (503) that abcde
1327 # will recognize in do_cddbread
1328 # and compensate by making a template
1329 echo 503 > "$ABCDETEMPDIR/cddbquery"
1331 *) # strange and unknown error
1332 echo ERRORCODE
=$ERRORCODE
1333 echo "abcde: $CDDBTOOL returned unknown error code"
1337 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1344 # If it's not to be used, generate a template.
1345 # Then, display it (or them) and let the user choose/edit it
1346 if checkstatus cddb-readcomplete
; then :; else
1347 vecho
"Obtaining CDDB results..."
1348 # If CDDB is to be used, interpret the query results and read all
1349 # the available entries.
1350 rm -f "$ABCDETEMPDIR/cddbchoices"
1351 CDDBCHOICES
=1 # Overridden by multiple matches
1352 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1353 case "$RESPONSECODE" in
1355 # One exact match, retrieve it
1356 # 200 [section] [discid] [artist] / [title]
1357 if checkstatus cddb-read-1-complete
; then :; else
1358 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1359 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1360 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1361 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1362 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1364 # List out disc title/author and contents
1365 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1366 for TRACK
in $
(f_seq_row
1 $TRACKS)
1368 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1370 echo >> "$ABCDETEMPDIR/cddbchoices"
1374 case "$RESPONSECODE" in
1375 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1376 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1377 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1379 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1380 # List out disc title/author and contents of template
1381 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1383 for TRACK
in $
(f_seq_row
1 $TRACKS)
1385 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1387 echo >> "$ABCDETEMPDIR/cddbchoices"
1388 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1389 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1392 # Multiple exact, (possibly multiple) inexact matches
1394 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1395 if [ "$(wc -l < $ABCDETEMPDIR/cddbquery | tr -d ' ')" -eq 3 ]; then
1396 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1397 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1398 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1400 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1402 vecho
-n "Retrieving multiple matches... "
1403 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1404 read DISCINFO
# eat top line
1408 if checkstatus cddb-read-
$X-complete; then :; else
1409 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1410 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1412 # List out disc title/author and contents
1413 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1414 for TRACK
in $
(f_seq_row
1 $TRACKS)
1416 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1418 echo >> "$ABCDETEMPDIR/cddbchoices"
1421 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1425 for TRACK
in $
(f_seq_row
1 $TRACKS)
1427 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1429 echo >> "$ABCDETEMPDIR/cddbchoices"
1430 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1431 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1434 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1441 if checkstatus cddb-edit
>/dev
/null
; then
1442 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1443 VARIOUSARTISTS
="$(checkstatus variousartists)"
1444 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1447 if [ "$INTERACTIVE" = "y" ]; then
1448 # We should show the CDDB results both when we are not using the local CDDB repo
1449 # or when we are using it but we could not find a proper match
1450 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1451 # Display the $ABCDETEMPDIR/cddbchoices file created above
1452 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1453 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1454 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1455 CHOICE
=$
(checkstatus cddb-choice
)
1456 if [ -n "$CHOICE" ] ; then
1457 case $CDDBCHOICES in
1458 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1460 echo "Selected: #$CHOICE"
1461 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1465 # The user has a choice to make, display the info in a pager if necessary
1466 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1467 # Use the debian sensible-pager wrapper to pick the pager
1468 # user has requested via their $PAGER environment variable
1469 if [ -x "/usr/bin/sensible-pager" ]; then
1470 /usr
/bin
/sensible-pager
"$ABCDETEMPDIR/cddbchoices"
1471 elif [ -x "$PAGER" ]; then
1472 # That failed, try to load the preferred editor, starting
1473 # with their PAGER variable
1474 $PAGER "$ABCDETEMPDIR/cddbchoices"
1475 # If that fails, check for less
1476 elif [ -x /usr
/bin
/less ]; then
1477 /usr
/bin
/less -f "$ABCDETEMPDIR/cddbchoices"
1478 # more should be on all UNIX systems
1479 elif [ -x /bin
/more ]; then
1480 /bin
/more "$ABCDETEMPDIR/cddbchoices"
1482 # No bananas, just cat the thing
1483 cat "$ABCDETEMPDIR/cddbchoices" >&2
1486 # It's all going to fit in one page, cat it
1487 cat "$ABCDETEMPDIR/cddbchoices" >&2
1490 # I'll take CDDB read #3 for $400, Alex
1491 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1493 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1494 # Make sure we get a valid choice
1495 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1496 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1497 echo "Invalid selection. Please choose a number between 1 and $CDDBCHOICES." >&2
1498 echo -n "Selection [0-$CDDBCHOICES]: " >&2
1500 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1502 if [ "$CDCHOICENUM" = "0" ]; then
1503 vecho
"Creating empty CDDB template..."
1505 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > $ABCDETEMPDIR/cddbread
.0
1507 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1508 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1510 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1514 # We need some code to show the selected option when local repository is selected and we have found a match
1515 vecho
"Using cached CDDB match..." >&2
1516 # Display the $ABCDETEMPDIR/cddbchoices file created above
1517 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1518 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1519 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1520 CHOICE
=$
(checkstatus cddb-choice
)
1521 if [ "$USELOCALRESP" = "y" ]; then :; else
1522 if [ -n "$CHOICE" ] ; then
1523 case $CDDBCHOICES in
1526 echo "Selected template."
1528 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1530 echo "Selected: #$CHOICE"
1531 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1539 # We're noninteractive - pick the first choice.
1540 # But in case we run a previous instance and selected a choice, use it.
1541 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1542 # Show the choice if we are not using the locally stored one
1543 # or when the local search failed to find a match.
1544 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1545 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1546 #if [ "$PREVIOUSCHOICE" ]; then
1547 cat "$ABCDETEMPDIR/cddbchoices"
1550 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1551 CDCHOICENUM
=$PREVIOUSCHOICE
1554 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1556 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1561 if checkstatus cddb-choice
>/dev
/null
; then :; else
1562 echo "abcde: internal error: cddb-choice not recorded." >&2
1565 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1566 echo -n "Edit selected CDDB data? [y/n] (" >&2
1567 if [ "$INTERACTIVE" = "y" ]; then
1568 if [ "$UNKNOWNDISK" = "y" ]; then
1571 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1580 if [ "$EDITCDDB" = "y" ]; then
1581 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1583 # Use the debian sensible-editor wrapper to pick the editor that the
1584 # user has requested via their $EDITOR environment variable
1585 if [ -x "/usr/bin/sensible-editor" ]; then
1586 /usr
/bin
/sensible-editor
"$CDDBDATA"
1587 elif [ -n "$EDITOR" ]; then
1588 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1589 # That failed, try to load the preferred editor, starting
1590 # with their EDITOR variable
1591 eval $
(echo "$EDITOR") "$CDDBDATA"
1593 # If that fails, check for a vi
1594 elif which vi
>/dev
/null
2>&1; then
1596 elif [ -x /usr
/bin
/vi
]; then
1597 /usr
/bin
/vi
"$CDDBDATA"
1598 # nano should be on all (modern, i.e., sarge) debian systems
1599 elif which nano
>/dev
/null
2>&1 ; then
1601 elif [ -x /usr
/bin
/nano
]; then
1602 /usr
/bin
/nano
"$CDDBDATA"
1603 # mg should be on all OpenBSD systems
1604 elif which mg
>/dev
/null
2>&1 ; then
1606 elif [ -x /usr
/bin
/mg
]; then
1607 /usr
/bin
/mg
"$CDDBDATA"
1610 echo "No editor available. Check your EDITOR environment variable." >&2
1612 # delete editor backup file if it exists
1613 if [ -w "$CDDBDATA~" ]; then
1618 # Some heuristics first. Look at Disc Title, and if it starts with
1619 # "Various", then we'll assume Various Artists
1620 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1621 echo "Looks like a Multi-Artist CD" >&2
1624 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1625 if [ "$INTERACTIVE" = "y" ]; then
1632 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1635 # Need NUMTRACKS before cddb-tool will return it:
1636 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1637 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1638 # More than 1/2 tracks contain a "/", so guess forward
1640 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1641 # More than 1/2 contain a "-", so guess forward-dash
1643 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1644 # More than 1/2 contain something in parens, so guess trailing-paren
1648 echo "1) Artist / Title" >&2
1649 echo "2) Artist - Title" >&2
1650 echo "3) Title / Artist" >&2
1651 echo "4) Title - Artist" >&2
1652 echo "5) Artist: Title" >&2
1653 echo "6) Title (Artist)" >&2
1654 echo "7) This is a single-artist CD" >&2
1655 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1656 if [ "$INTERACTIVE" = "y" ]; then
1657 read VARIOUSARTISTSTYLE
1659 echo $DEFAULTSTYLE >&2
1660 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1662 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1663 # If they press Enter, then the default style (0) was chosen
1664 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1665 echo "Invalid selection. Please choose a number between 1 and 7."
1666 echo -n "Selection [1-7]: "
1667 read VARIOUSARTISTSTYLE
1668 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1670 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1671 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1673 vecho
"Selected: $VARIOUSARTISTSTYLE"
1674 case "$VARIOUSARTISTSTYLE" in
1676 VARIOUSARTISTSTYLE
=forward
1679 VARIOUSARTISTSTYLE
=forward-dash
1682 VARIOUSARTISTSTYLE
=reverse
1685 VARIOUSARTISTSTYLE
=reverse-dash
1688 VARIOUSARTISTSTYLE
=colon
1691 VARIOUSARTISTSTYLE
=trailing-paren
1699 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1700 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1702 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1703 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1704 # This works but does not have the necessary error checking
1705 # yet. If you are familiar with the CDDB spec
1706 # (see http://www.freedb.org/src/latest/DBFORMAT)
1707 # and can create an error-free entry on your own, then put
1708 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1709 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1710 # your abcde.conf to change the email address submissions are
1713 # submit the modified file, if they want
1714 if [ "$NOSUBMIT" != "y" ]; then
1715 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1717 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1718 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1720 echo -n 'Invalid selection. Please answer "y" or "n": '
1723 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1724 echo -n "Sending..."
1725 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1731 # Make sure the cache directory exists
1732 mkdir
-p $CDDBLOCALDIR
1733 # Cache edited CDDB entry in the user's cddb dir
1734 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1735 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1738 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1741 # do_cdread [tracknumber]
1742 # do_cdread onetrack [firsttrack] [lasttrack]
1746 # The commands here don't go through run_command because they're never supposed to be silenced
1747 # return codes need to be doublechecked anyway, however
1748 if [ "$1" = "onetrack" ]; then
1749 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1750 # FIXME # Until then, we grab the whole CD in one track, no matter what
1752 # We need the first and last track for cdda2wav
1755 case "$CDROMREADERSYNTAX" in
1756 cdparanoia
) UTRACKNUM
="1-" ;;
1757 cdda2wav
) UTRACKNUM
="1+$LASTRACK" ;;
1758 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1764 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1765 if [ "$USEPIPES" = "y" ]; then
1766 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1769 PIPE_MESSAGE
="and encoding "
1771 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1772 case "$CDROMREADERSYNTAX" in
1773 ## FIXME ## Find the case for dagrab, to avoid exceptions
1775 FILEARG
="-f $WAVDATA"
1783 if [ -r "$CDDBDATA" ]; then
1784 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1785 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1787 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1789 case "$CDROMREADERSYNTAX" in
1790 cdparanoia
) nice
$READNICE $CDROMREADER -d $CDROM $UTRACKNUM $FILEARG $REDIR ;;
1792 if [ "$OSFLAVOUR" = "OSX" ] ; then
1793 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1794 disktool
-u ${CDROM#/dev/} 0
1795 # Also, in OSX the cdrom device for cdda2wav changes...
1796 CDDA2WAVCDROM
="IODVDServices"
1797 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1798 CDDA2WAVCDROM
="$CDROMID"
1800 if [ "$CDROMID" = "" ]; then
1801 CDDA2WAVCDROM
="$CDROM"
1803 CDDA2WAVCDROM
="$CDROMID"
1806 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM $FILEARG $REDIR
1808 ## FIXME ## We have an exception for dagrab, since it uses -f
1809 ## FIXME ## Shall we just use -f $FILEARG ??
1810 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM $FILEARG $REDIR
1813 # Find the track's mounted path
1814 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1815 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1816 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
1817 # If the file exists, copy it
1818 if [ -e "$FILEPATH" ] ; then
1819 nice
$READNICE $CDROMREADER "$FILEPATH" $FILEARG $REDIR
1823 debug
) nice
$READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] $FILEARG $REDIR
1827 # If we get some error or we get some missing wav
1828 # (as long as we dont use pipes)
1829 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
1830 # Thank goodness errors is only machine-parseable up to the
1831 # first colon, otherwise this woulda sucked
1832 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1833 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
1835 if [ "$USEPIPES" = "y" ]; then
1836 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1838 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1842 if [ "$USEPIPES" = "y" ]; then
1843 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1845 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1851 # No values accepted, only uses env variables
1854 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
1855 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
1857 echo "abcde: unable to set the device speed" >&2
1863 # vecho outputs a message if EXTRAVERBOSE is selected
1866 if [ x
"$EXTRAVERBOSE" != "x" ]; then
1871 # User-redefinable functions
1872 # Custom filename munging:
1875 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
1876 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
1879 # Custom genre munging:
1882 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
1886 # Empty pre_read function, to be defined in the configuration file.
1892 ###############################################################################
1895 # Start of execution
1896 ###############################################################################
1899 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
1900 CDDBSUBMIT
=freedb-submit@freedb.org
1902 HELLOINFO
="$(whoami)@$(hostname)"
1904 CDROMREADERSYNTAX
=cdparanoia
1906 ENCODERSYNTAX
=default
1908 MP3ENCODERSYNTAX
=default
1909 OGGENCODERSYNTAX
=default
1910 FLACENCODERSYNTAX
=default
1911 SPEEXENCODERSYNTAX
=default
1912 MPPENCODERSYNTAX
=default
1913 NORMALIZERSYNTAX
=default
1915 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
1916 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
1917 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
1918 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
1919 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
1920 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
1921 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1922 PLAYLISTDATAPREFIX
=''
1923 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1924 VAPLAYLISTDATAPREFIX
=''
1932 VARIOUSARTISTSTYLE
=forward
1936 CDDBLOCALDIR
="$HOME/.cddb"
1939 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
1940 # i.e. CDROMID="1,0,0"
1943 # program paths - defaults to checking your $PATH
1949 XINGMP3ENC
=xingmp3enc
1963 CDPARANOIA
=cdparanoia
1972 VORBISCOMMENT
=vorbiscomment
1974 NORMALIZE
=normalize-audio
1976 VORBISGAIN
=vorbisgain
1979 # Options for programs called from abcde
2011 # Default to one process if -j isn't specified
2014 # List of actions to perform - by default, run to completion
2015 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2017 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2018 # Let's use these checkings to determine the OS flavour, which will be used later
2019 if [ X$
(uname
) = "XFreeBSD" ] ; then
2023 elif [ X$
(uname
) = "XDarwin" ] ; then
2026 # We should have disktool in OSX, but let's be sure...
2028 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2035 # If CDDBAVAIL is set to n, no CDDB read is done
2036 # If USEID3 is set to n, no ID3 tagging is done
2041 if [ -z "$OUTPUTDIR" ]; then
2045 if [ -z "$WAVOUTPUTDIR" ]; then
2046 WAVOUTPUTDIR
="$OUTPUTDIR"
2049 # Load system defaults
2050 if [ -r /etc
/abcde.conf
]; then
2053 # Load user preference defaults
2054 if [ -r $HOME/.abcde.conf
]; then
2058 # By this time, we need some HTTPGETOPTS already defined.
2059 # If the user has defined a non-default HTTPGET method, we should not be empty.
2061 if [ "$HTTPGETOPTS" = "" ] ; then
2063 wget
) HTTPGETOPTS
="-q -O -";;
2064 curl
) HTTPGETOPTS
="-f -s";;
2065 fetch
)HTTPGETOPTS
="-q -o -";;
2066 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2070 # If the CDROM has not been set yet, find a suitable one.
2071 # If this is a devfs system, default to /dev/cdroms/cdrom0
2072 # instead of /dev/cdrom
2073 if [ "$CDROM" = "" ] ; then
2074 if [ -e /dev
/cdroms
/cdrom0
]; then
2075 CDROM
=/dev
/cdroms
/cdrom0
2076 elif [ -e /dev
/cdrom
]; then
2078 elif [ -e /dev
/cd0c
]; then
2080 elif [ -e /dev
/acd0c
]; then
2082 elif [ -e /dev
/disk1
]; then
2087 # Parse command line options
2088 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
2089 while getopts 1a
:A
:bc:C
:d
:Dhj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
2092 a
) ACTIONS
="$OPTARG" ;;
2093 A
) EXPACTIONS
="$OPTARG";;
2095 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2096 C
) DISCID
="${OPTARG#abcde.}" ;;
2097 d
) CDROM
="$OPTARG" ;;
2100 # f) FORCECDDBUSELOCAL=y ;;
2102 j
) MAXPROCS
="$OPTARG" ;;
2105 L
) CDDBUSELOCAL
=y
;;
2110 o
) OUTPUTTYPE
="$OPTARG" ;;
2113 r
) REMOTEHOSTS
="$OPTARG" ;;
2115 s
) STARTTRACKNUMBER
="$OPTARG" ;;
2116 S
) CDSPEEDVALUE
="$OPTARG" ;;
2117 # t) PREPROCESSFORMATS="$OPTARG"
2119 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2120 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2121 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2123 echo "This is abcde v$VERSION."
2124 echo "Usage: abcde [options] [tracks]"
2125 echo "abcde -h for extra help"
2128 V
) EXTRAVERBOSE
="y" ;;
2130 w
) COMMENT
="$OPTARG" ;;
2131 W
) STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}" ;;
2136 shift $
(($OPTIND - 1))
2138 # Decide if we can continue.
2139 if [ "$ONETRACK" = "y" ]; then
2140 # FIXME # remove check as soon as we find out about the other readers
2141 case "$CDROMREADERSYNTAX" in
2142 dagrab|cddafs|debug
) echo "abcde error: ONETRACK reading is not suported with "$CDROMREADERSYNTAX" yet"
2145 if [ "$BATCH" = "y" ]; then
2146 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2149 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2150 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2151 if [ $# -gt 0 ]; then
2152 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2155 while [ $# -gt 0 ]; do
2156 # Range parsing code courtesy of Vincent Ho
2157 RSTART
=$
(echo $1 | cut
-f1 -d-)
2158 REND
=$
(echo $1 | cut
-f2 -d-)
2159 if [ "$RSTART" = "$REND" ]; then
2162 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2164 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2169 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2170 # List of experimental actions: retag,transcode
2172 # Determine what actions are to be done from $ACTIONS and set the
2173 # following environment variables for them:
2185 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2190 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2191 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2192 encode
) DOENCODE
=y
; DOREAD
=y
;;
2193 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2194 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2195 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2196 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2203 # At this point a CDROM has to be defined, so we check it exists.
2204 if [ X
"$CDROM" != "X" ] ; then
2205 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2206 if [ "$OSFLAVOUR" = "FBSD" ]; then
2207 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2208 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2209 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2213 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2214 echo "abcde error: CDROM device cannot be found." >&2
2217 # avoid processing if we are not going to hit the CDROM.
2218 elif [ X
"$DOREAD" = "Xy" ]; then
2219 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2223 # USEPIPES pre-tests, before we get into more serious stuff
2224 # Not compatible with:
2225 # - multiple outputs
2227 # - lowdisk algorithm
2229 if [ X
"$USEPIPES" = "Xy" ]; then
2230 if [ $
(echo $OUTPUTTYPE |
tr , \ |
wc -w ) -gt 1 ]; then
2231 echo "abcde error: Unix pipes not compatible with multiple outputs"
2234 if [ X
"$DONORMALIZE" = "Xy" ]; then
2235 echo "abcde error: Unix pipes not compatible with normalizer"
2236 # FIXME # Do we need to exit or shall we just disable the mode?
2239 if [ X
"$DOENCODE" = "Xn" ]; then
2240 vecho
"Disabling Unix pipes since we are not encoding!"
2243 if [ X
"$LOWDISK" = "Xy" ]; then
2244 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2249 # Decide which CDROM reader we're gonna use
2250 case "$CDROMREADERSYNTAX" in
2252 CDROMREADER
="$CDPARANOIA"
2253 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2256 CDROMREADER
="$CDDA2WAV"
2257 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2260 CDROMREADER
="$DAGRAB"
2261 CDROMREADEROPTS
="$DAGRABOPTS"
2264 CDROMREADER
="$CDDAFS"
2265 CDROMREADEROPTS
="$CDDAFSOPTS"
2269 # There's only one normalize...
2270 case "$NORMALIZERSYNTAX" in
2272 NORMALIZER
="$NORMALIZE"
2273 NORMALIZEROPTS
="$NORMALIZEOPTS"
2277 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2278 if echo $OUTPUTTYPE |
grep ":" > /dev
/null
2>&1 ; then
2281 for OUTPUT
in "$OUTPUTTYPE"
2284 ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2285 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2286 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2287 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2288 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2291 for OUTPUT
in "$OUTPUTTYPE"
2293 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2294 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2296 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2300 # 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
2302 # Getting ready for multiple output changes
2303 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2306 ogg
) [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2307 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2308 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2310 mp3
) [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2311 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2313 flac
) [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2314 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2316 spx
) [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
;;
2317 mpc
) [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
;;
2318 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2324 # decide which encoder
2325 case "$MP3ENCODERSYNTAX" in
2327 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2331 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2335 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2336 MP3ENCODER
="$BLADEENC"
2339 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2343 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2344 MP3ENCODER
="$XINGMP3ENC"
2347 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2348 MP3ENCODER
="$MP3ENC"
2351 case "$OGGENCODERSYNTAX" in
2353 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2354 OGGENCODER
="$VORBIZE"
2357 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2358 OGGENCODER
="$OGGENC"
2361 case "$FLACENCODERSYNTAX" in
2363 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2365 ## FIXME ## FLAC streams can be encapsulated on a Ogg transport layer
2366 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2371 case "$SPEEXENCODERSYNTAX" in
2373 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2374 SPEEXENCODER
="$SPEEXENC"
2377 case "$MPPENCODERSYNTAX" in
2379 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2380 MPPENCODER
="$MPPENC"
2386 if [ "$ID3TAGV" = "1" ]; then
2388 TAGGEROPTS
="$ID3OPTS"
2391 TAGGEROPTS
="$ID3V2OPTS"
2394 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2396 if [ "$ENCNICE" ]; then
2397 ENCNICE
="-n $ENCNICE"
2399 if [ "$READNICE" ]; then
2400 READNICE
="-n $READNICE"
2402 if [ "$DISTMP3NICE" ]; then
2403 DISTMP3NICE
="-n $DISTMP3NICE"
2406 # Don't check for stuff if it's not needed
2407 if [ "$REMOTEHOSTS" ]; then NEEDDISTMP3
=y
; fi
2408 [ "$DONORMALIZE" = "y" ] && NEEDNORMALIZER
=y
2409 [ "$EJECTCD" = "y" ] && NEEDEJECT
=y
2410 [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ] && NEEDHTTPGET
=y
2411 [ "$CUEFILE" = "y" ] && NEEDMKCUE
=y
2413 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2414 case "$CDROMREADERSYNTAX" in
2415 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2420 # Rippers with USEPIPE support
2421 # FIXME # Include here all the rippers we can figure out support pipes
2424 # Encoders with USEPIPE support
2425 # FIXME # Include here all the encoders we can figure out support pipes
2429 # Figure out if we can use pipes with the ripper/encoder combination
2431 if [ "$USEPIPES" = "y" ]; then
2432 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2435 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2437 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2439 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYTNAX" ;;
2441 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2443 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2445 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2446 echo "abcde error: no support for pipes with given ripper" >&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
2451 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2452 echo "abcde error: no support for pipes with given encoder" >&2
2453 echo "read the USEPIPES file from the source tarball to help" >&2
2454 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2460 # Make sure a buncha things exist
2461 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2462 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2463 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2464 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2465 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2466 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2467 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2469 # Cut off the command-line options we just added in
2470 X
=$
(echo $X | cut
-d' ' -f2)
2471 if [ "$(which $X)" = "" ]; then
2472 echo "abcde error: $X is not in your path." >&2
2474 elif [ ! -x $
(which $X) ]; then
2475 echo "abcde error: $X is not executable." >&2
2480 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2481 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2482 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2484 # Here it used to say:
2485 # One thousand lines in, we can start doing stuff with things
2486 # Well, right now we are at line 2157 ;)
2488 # Export needed things so they can be read in this subshell
2489 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2490 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2492 # User-definable function to set some things. Use it for
2493 # - closing the CD tray with eject -t
2494 # - set the CD speed value with eject -x
2495 vecho
-n "Executing customizable pre-read function... "
2497 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2501 do_discid
# Get ABCDETEMPDIR created and status file initialized
2503 if [ "$DOCDDB" = "y" ]; then
2504 if [ $CDDBUSELOCAL = "y" ]; then
2507 if checkstatus cddb-choice
> /dev
/null
; then
2510 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2518 eval $
($CDDBTOOL parse
"$CDDBDATA")
2521 # Before reading tracks, we set the speed of the device
2523 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2524 case "$CDROMREADERSYNTAX" in
2525 cdparanoia|debug
) : ;;
2530 # Create playlist if needed (backgroundable) and start reading in tracks
2534 if [ ! "$ONETRACK" = "y" ]; then
2535 if [ "$DOPLAYLIST" = "y" ]; then
2536 echo Creating playlist...
>&2
2541 # For the lowdisk option, only one program is running at once so the encoder
2542 # can be unsilenced right away.
2543 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2544 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2547 if [ "$ONETRACK" = "y" ]; then
2548 FIRSTTRACK
=$
( echo $TRACKQUEUE |
awk '{print $1}' )
2549 TRACKS
="$FIRSTTRACK"
2550 for UTRACKNUM
in $TRACKQUEUE; do :;done
2551 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2552 do_cdread onetrack
$FIRSTTRACK $UTRACKNUM
2555 for UTRACKNUM
in $TRACKQUEUE
2557 if [ "$DOREAD" = "y" ]; then
2558 if [ "$USEPIPES" = "y" ]; then
2559 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2560 # Read, pipe, shut up!
2561 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
2564 if checkstatus readtrack-
$UTRACKNUM; then :; else
2565 do_cdread
$UTRACKNUM
2567 if [ "$?" != "0" ]; then
2568 # CD read failed - don't give the goahead to
2575 if [ "$BATCH" = "y" ]; then
2578 echo NEXTTRACK
# Get the encoder machine churning again
2579 if [ "$DOREAD" = "y" ]; then
2580 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2581 until checkstatus encodetrack-
$UTRACKNUM
2583 if checkerrors encodetrack-
$UTRACKNUM; then
2594 # Now that we're done the encoding can be loud again -
2595 # if we're not using SMP.
2596 if [ "$MAXPROCS" = "1" ]; then
2597 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2600 # All tracks read, start encoding.
2601 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2605 # We are now finished with the cdrom - it can be safely ejected. Note that
2606 # abcde will not have completed yet.
2607 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2608 # We check if the disk we are processing is actually the disk inside the
2609 # CD tray. If not, we do not eject the CD, since it might be so that the
2610 # user ejected it manually.
2611 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2612 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2613 # More FreeBSD bits.
2614 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2615 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2616 # but in this script EJECT is in the envionment and names the program
2619 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2620 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2621 $eject $EJECTOPTS $cd
2622 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2623 disktool
-e ${CDROM#/dev/} 0
2625 $EJECT $EJECTOPTS $CDROM
2632 ## Do we need to pre-process
2633 #if [ x"$PREPROCESS" = "x" ] ; then
2636 # for PRETRACKNUM in $TRACKQUEUE
2639 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2641 # until [ $PREPROCEED ]
2643 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2644 # # all locations are working, wait and try again later
2645 # if [ ! $PREPROCEED ]; then sleep 3; fi
2647 # ( do_preprocess $PRETRACKNUM
2655 # In batch mode, we want all tracks to be read first.
2656 if [ "$BATCH" = "y" ]; then
2657 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2658 if [ "$GOAHEAD" = "NO" ]; then break; fi
2659 for LASTTRACK
in $TRACKQUEUE; do :; done
2660 if checkstatus readtrack-
$LASTTRACK; then
2661 if [ "$DONORMALIZE" = "y" ]; then
2662 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2663 if checkerrors batch-normalize
; then exit; fi
2665 if [ "$DOENCODE" = "y" ]; then
2666 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2667 if checkerrors batch-encode
; then exit; fi
2672 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2673 if [ "$ONETRACK" = "y" ] ; then
2674 FIRSTTRACK
=$
( echo $TRACKQUEUE |
awk '{print $1}')
2675 TRACKQUEUE
=$FIRSTTRACK
2676 TRACKS
="$FIRSTTRACK"
2679 # Do the encoding, including parallelization of remote encoding
2680 # Figure out where each track is going to be encoded
2681 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2682 if [ "$MAXPROCS" != "0" ]; then
2683 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2685 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2689 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2690 for UTRACKNUM
in $TRACKQUEUE
2693 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2694 if [ "$GOAHEAD" = "NO" ]; then break; fi
2695 # find out where this track is to be encoded
2696 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2697 # Make sure we have a place to encode this, if not, exit stage right
2698 if [ -z "$ENCODELOCATIONS" ]; then
2704 for LOCATION
in $ENCODELOCATIONS
2706 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2707 # check first if a track has ever been assigned to this location
2708 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
2709 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2710 if checkerrors encodetrack-
$PREVIOUSTRACK; then
2711 for TEMPLOCATION
in $ENCODELOCATIONS
2713 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2714 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
2717 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
2722 # We're still here, this location must have been previously assigned,
2723 # and last completed without error - check if it's done with the
2724 # previous track yet
2725 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
2727 # all locations are working, wait and try again later
2728 if [ ! $PROCEED ]; then sleep 3; fi
2730 # Record the location we're about to encode the next track at
2731 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2733 # Don't proceed with the rest of the loop if we can't encode
2734 if [ "$ABORT" ]; then continue; fi
2735 # Set TRACKNUM, TRACKNAME
2736 if [ -e "$CDDBDATA" ]; then
2737 if [ "$ONETRACK" = "y" ]; then
2739 TRACKNUM
="$FIRSTTRACK"
2742 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
2744 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2745 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
2749 # You can't encode a file which needs to be normalized before finishing
2750 # You can't tag a file before it's finished encoding -
2751 # thus all of this is backgrounded together
2753 if [ "$DONORMALIZE" = "y" ]; then
2754 if checkstatus readtrack-
$UTRACKNUM; then
2755 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
2758 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2759 if checkstatus readtrack-
$UTRACKNUM; then
2760 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
2761 if [ "$DONORMALIZE" = "y" ]; then
2762 if checkstatus normalizetrack-
$UTRACKNUM; then
2763 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2766 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2770 if [ "$DOTAG" = "y" ]; then
2771 if checkstatus encodetrack-
$UTRACKNUM; then
2772 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
2775 if [ "$DOMOVE" = "y" ]; then
2776 if checkstatus tagtrack-
$UTRACKNUM; then
2777 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
2782 # Go through it again and make sure there's no distmp3 stragglers, otherwise
2783 # we'll delete the files they're working on
2784 ## FIXME ## Check also for files which are encoded using PIPEs.
2785 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2790 for LOCATION
in $ENCODELOCATIONS
2792 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2793 # "How can he give us a status update, if he's DEAD?"
2794 if checkstatus encodetrack-
$CHECKTRACK; then
2797 # Nothing to see here please go quietly back to your homes
2798 if [ -z "$CHECKTRACK" ]; then continue; fi
2799 # You're still here? Maybe there is something...
2800 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
2803 if [ ! $PROCEED ]; then sleep 5; fi
2806 # If the above didn't catch the stragglers, this will
2808 # Check to see if run_command logged any errors
2809 if [ -f "$ABCDETEMPDIR/errors" ]; then
2810 echo "The following commands failed to run:"
2811 cat "$ABCDETEMPDIR/errors"
2815 if [ "$KEEPWAVS" = "y" ];then
2819 if [ "$DOCLEAN" = "y" ]; then
2820 # Wipe all the evidence
2821 # Gimme gimme gimme some more time!
2823 rm -rf "$ABCDETEMPDIR"
2826 echo "Finished. Not cleaning $ABCDETEMPDIR."