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 "-e Erase encoded track information from status file"
34 echo "-h This help information"
35 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
36 echo "-j <#> Number of encoder processes to run at once (localhost)"
37 echo "-k Keep the wav tracks for later use"
38 echo "-l Use low disk space algorithm"
39 echo "-L Use local CDDB storage directory"
40 echo "-n No lookup. Don't query CDDB, just create and use template"
41 echo "-N Noninteractive. Never prompt for anything"
42 echo "-m Modify playlist to include CRLF endings, to comply with some players"
43 echo "-M Create a CUE file"
44 echo "-o <type1[,type2]...>"
45 echo " Output file type(s) (ogg,mp3,flac,spx,mpc). Defaults to ogg"
46 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
47 echo "-P Use UNIX pipes to read+encode without wav files"
48 echo "-r <host1[,host2]...>"
49 echo " Also encode on these remote hosts"
50 echo "-R Add replaygain values to the tag info (only for ogg,flac)"
51 echo "-S <#> Set the CD speed"
52 #echo "-t File types to preprocess (wav)"
53 #echo "-T Set postprocessing options"
54 echo "-t <#> Start the track numbering at a given number"
55 echo "-T <#> Same as -t but modifies tag numbering"
56 echo "-v Show version number and exit"
57 echo "-V Be a bit more verbose about what is happening behind the scenes"
58 echo "-x Eject CD after all tracks are read"
60 echo " Add a comment to the CD tracks"
61 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
63 echo "Tracks is a space-delimited list of tracks to grab."
64 echo "Ranges specified with hyphens are allowed."
65 #echo "Double hyphens are used to concatenate tracks"
68 # Funtions to replace the need of seq, which is too distribution dependant.
72 while [ $i -ne `expr $2 + 1` ]
82 while [ $i -ne `expr $2 + 1` ]
90 # Functions to replace the need of awk {print $1} and {print $NF}
93 if [ X
"$1" = "X" ]; then
94 for first
in `cat`; do
105 if [ X
"$1" = "X" ]; then
106 for stdin
in `cat`; do
110 for last
in $@
; do :; done
115 # checkstatus [blurb]
116 # Returns "0" if the blurb was found, returns 1 if it wasn't
117 # Puts the blurb content, if available, on stdout.
118 # Otherwise, returns "".
121 # Take the last line in the status file if there's multiple matches
123 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
125 if [ -z "$BLURB" ]; then
130 # See if there's a = in it
131 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
132 echo "$(echo $BLURB | cut -f2- -d=)"
138 # checkerrors [blurb]
139 # Returns "0" if the blurb was found (meaning there was an error),
140 # returns 1 if it wasn't (yes this is a little backwards).
141 # Does not print the blurb on stdout.
142 # Otherwise, returns "".
145 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
148 # Take the last line in the status file if there's multiple matches
150 BLURB
="$(egrep $PATTERN $ABCDETEMPDIR/errors | tail -n 1)"
152 if [ -z "$BLURB" ]; then
153 # negative, we did not have a negative...
156 # affirmative, we had a negative...
161 # run_command [blurb] [command...]
162 # Runs a command, silently if necessary, and updates the status file
167 # See if this is supposed to be silent
168 if [ "$(checkstatus encode-output)" = "loud" ]; then
172 # Special case for SMP, since
173 # encoder output is never displayed, don't mute echos
174 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
184 if [ "$RETURN" = "2" ]; then
185 # File was already normalized.
190 if [ "$RETURN" != "0" ]; then
191 # Put an error in the errors file. For various reasons we
192 # can't capture a copy of the program's output but we can
193 # log what we attempted to execute and the error code
194 # returned by the program.
195 if [ "$BLURB" ]; then
198 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
199 return $RETURN # Do not pass go, do not update the status file
201 if [ "$BLURB" ]; then
202 echo $BLURB >> "$ABCDETEMPDIR/status"
206 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
207 # distributed under the terms of the GNU GPL v2 or later, at your option
209 # Function to determine if a word contains a slash.
218 # Function to give the relative path from one file to another.
219 # Usage: relpath fromfile tofile
220 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
221 # (the result would be Album/Song.mp3)
222 # Output is relative path to $2 from $1 on stdout
224 # This code has the following restrictions:
225 # Multiple ////s are not collapsed into single /s, with strange effects.
226 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
227 # If FR is a directory it must have a trailing /
235 /*) ;; # No processing is needed for absolute paths
237 # Loop through common prefixes, ignoring them.
238 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
240 FR
="$(echo "$FR" | cut -d/ -f2-)"
241 TO
="$(echo "$TO" | cut -d/ -f2-)"
243 # Loop through directory portions left in FR, adding appropriate ../s.
246 FR
="$(echo "$FR" | cut -d/ -f2-)"
255 # This code splits the a Various Artist track name from one of the following
258 # forward: Artist / Track
259 # forward-dash: Artist - Track
260 # reverse: Track / Artist
261 # reverse-dash: Track - Artist
262 # colon: Artist: Track
263 # trailing-paren: Artist (Track)
266 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
269 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
270 case "$VARIOUSARTISTSTYLE" in
272 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's- / -~-g')
273 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
274 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
277 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's, - ,~,g')
278 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
279 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
282 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's- / -~-g')
283 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
284 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
287 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's, - ,~,g')
288 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
289 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
292 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's-: -~-g')
293 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
294 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
297 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's,^\(.*\) (\(.*\)),\1~\2,')
298 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
299 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
302 elif [ "$ONETRACK" = "y" ]; then
303 TRACKARTIST
="Various"
305 TRACKARTIST
="$DARTIST"
310 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
314 "classic rock") id
=1 ;;
332 "industrial") id
=19 ;;
333 "alternative") id
=20 ;;
335 "death metal") id
=22 ;;
337 "soundtrack") id
=24 ;;
338 "euro-techno") id
=25 ;;
342 "jazz+funk") id
=29 ;;
345 "classical") id
=32 ;;
346 "instrumental") id
=33 ;;
350 "sound clip") id
=37 ;;
353 "alt. rock") id
=40 ;;
358 "meditative") id
=45 ;;
359 "instrum. pop") id
=46 ;;
360 "instrum. rock") id
=47 ;;
364 "techno-indust.") id
=51 ;;
365 "electronic") id
=52 ;;
367 "eurodance") id
=54 ;;
369 "southern rock") id
=56 ;;
374 "christian rap") id
=61 ;;
377 "native american") id
=64 ;;
380 "psychadelic") id
=67 ;;
382 "showtunes") id
=69 ;;
386 "acid punk") id
=73 ;;
387 "acid jazz") id
=74 ;;
391 "rock & roll") id
=78 ;;
392 "hard rock") id
=79 ;;
394 "folk/rock") id
=81 ;;
395 "national folk") id
=82 ;;
402 "bluegrass") id
=89 ;;
403 "avantgarde") id
=90 ;;
404 "gothic rock") id
=91 ;;
405 "progress. rock") id
=92 ;;
406 "psychadel. rock") id
=93 ;;
407 "symphonic rock") id
=94 ;;
408 "slow rock") id
=95 ;;
411 "easy listening") id
=98 ;;
417 "chamber music") id
=104 ;;
419 "symphony") id
=106 ;;
420 "booty bass") id
=107 ;;
422 "porn groove") id
=109 ;;
424 "slow jam") id
=111 ;;
428 "folklore") id
=115 ;;
430 "power ballad") id
=117 ;;
431 "rhythmic soul") id
=118 ;;
432 "freestyle") id
=119 ;;
434 "punk rock") id
=121 ;;
435 "drum solo") id
=122 ;;
436 "a capella") id
=123 ;;
437 "euro-house") id
=124 ;;
438 "dance hall") id
=125 ;;
440 "drum & bass") id
=127 ;;
441 "club-house") id
=128 ;;
442 "hardcore") id
=129 ;;
446 "negerpunk") id
=133 ;;
447 "polsk punk") id
=134 ;;
449 "christian gangsta rap") id
=136 ;;
450 "heavy metal") id
=137 ;;
451 "black metal") id
=138 ;;
452 "crossover") id
=139 ;;
453 "contemporary christian")id
=140 ;;
454 "christian rock") id
=141 ;;
455 "merengue") id
=142 ;;
457 "thrash metal") id
=144 ;;
460 "synthpop") id
=147 ;;
467 # do_tag [tracknumber]
468 # id3 tags a filename
470 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
471 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
474 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
475 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
476 # If we want to start the tracks with a given number, we need to modify the
477 # TRACKNUM value before evaluation
478 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
479 # Get the trackpadding from the current track
480 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
481 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
483 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
487 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
488 GENREID
=$
(do_getgenreid
"${CDGENRE}")
490 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
491 run_command tagtrack-
$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
492 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
493 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
494 "$ABCDETEMPDIR/track$1.$OUTPUT"
497 case "$OGGENCODERSYNTAX" in
499 # vorbiscomment can't do in-place modification, mv the file first
500 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" ]; then
501 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
504 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
505 echo ARTIST
="$TRACKARTIST"
507 echo TITLE
="$TRACKNAME"
508 if [ -n "$CDYEAR" ]; then
511 if [ -n "$CDGENRE" ]; then
512 echo GENRE
="$CDGENRE"
514 echo TRACKNUMBER
=${TRACKNUM:-$1}
515 echo CDDB
=$CDDBDISCID
516 if [ "$(eval echo ${COMMENT})" != "" ]; then
517 case "$COMMENTOUTPUT" in
518 *=*) echo "$COMMENTOUTPUT";;
519 *) echo COMMENT
="$COMMENTOUTPUT";;
522 ) | run_command tagtrack-
$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
523 "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
524 # Doublecheck that the commented file was created successfully before wiping the original
525 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" ]; then
526 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
528 mv "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
534 ## FIXME ## [ "$FLACONOGG" = "y" ] && OUTPUT=ogg
536 echo ARTIST
="$TRACKARTIST"
538 echo TITLE
="$TRACKNAME"
539 if [ -n "$CDYEAR" ]; then
542 if [ -n "$CDGENRE" ]; then
543 echo GENRE
="$CDGENRE"
545 echo TRACKNUMBER
=${TRACKNUM:-$1}
546 echo CDDB
=$CDDBDISCID
547 if [ "$(eval echo ${COMMENT})" != "" ]; then
548 case "$COMMENTOUTPUT" in
549 *=*) echo "$COMMENTOUTPUT";;
550 *) echo COMMENT
="$COMMENTOUTPUT";;
553 ) | run_command tagtrack-
$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$OUTPUT"
556 run_command tagtrack-
$1 true
559 run_command tagtrack-
$1 true
567 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
570 # The commands here don't go through run_command because they're never supposed to be silenced
571 echo "Batch encoding tracks: $TRACKQUEUE"
572 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
575 case "$MP3ENCODERSYNTAX" in
580 for UTRACKNUM
in $TRACKQUEUE
582 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
584 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
586 if [ "$RETURN" != "0" ]; then
587 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
589 for UTRACKNUM
in $TRACKQUEUE
591 echo encodetrack-
$UTRACKNUM >> status
599 # Other encoders fall through to normal encoding as the tracks
600 # have not been entered in the status file.
603 # do_encode [tracknumber] [hostname]
604 # If no hostname is specified, encode locally
606 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
609 if [ "$USEPIPES" = "y" ]; then
612 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
615 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
618 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
621 TEMPARG
="PIPE_$SPEEXENCODER"
624 TEMPARG
="PIPE_$MPPENCODER"
629 IN
="$ABCDETEMPDIR/track$1.wav"
632 case "$MP3ENCODERSYNTAX" in
633 # FIXME # check if mp3enc needs -if for pipes
647 # We need IN to proceed, if we are not using pipes.
648 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
649 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
651 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
652 if [ X
"$USEPIPES" = "Xy" ]; then
655 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
656 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
662 case "$MP3ENCODERSYNTAX" in
663 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
664 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
665 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
666 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
667 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
671 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
678 case "$OGGENCODERSYNTAX" in
679 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
680 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
684 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
691 case "$FLACENCODERSYNTAX" in
692 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
698 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
699 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
704 if [ "$(eval echo ${COMMENT})" != "" ]; then
707 *) COMMENT
="COMMENT=$COMMENT" ;;
709 COMMENT
="--comment \"$COMMENT\""
711 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
712 if [ ! "$DOTAG" = "y" ]; then
713 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
715 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
719 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
721 # I tried compiling the mppenc from corecodecs.org and got some
722 # errors, so I have not tried it myself.
723 ## FIXME ## Needs some cleanup to determine if an empty tag sent
724 ## FIXME ## to the encoder ends up empty.
725 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
729 # Only remove .wav if the encoding succeeded
730 if checkerrors
"encodetrack-(.{3,4})-$1"; then
731 run_command encodetrack-
$1 false
733 run_command encodetrack-
$1 true
734 if [ ! "$KEEPWAVS" = "y" ] ; then
739 if [ "$(checkstatus encode-output)" = "loud" ]; then
740 echo "HEH! The file we were about to encode disappeared:"
743 run_command encodetrack-
$1 false
747 # do_preprocess [tracknumber]
749 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
752 # IN="$ABCDETEMPDIR/track$1.wav"
753 # # We need IN to proceed.
754 # if [ -s "$IN" ] ; then
755 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
757 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
758 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
759 # case "$POSTPROCESSFORMAT" in
761 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
763 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
765 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
767 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
769 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
772 # # Only remove .wav if the encoding succeeded
773 # if checkerrors "preprocess-(.{3,4})-$1"; then
774 # run_command preprocess-$1 false
776 # run_command preprocess-$1 true
779 # if [ "$(checkstatus encode-output)" = "loud" ]; then
780 # echo "HEH! The file we were about to pre-process disappeared:"
783 # run_command preprocess-$1 false
788 # do_postprocess [tracknumber]
790 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
793 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
795 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
796 # # We need IN to proceed.
797 # if [ -s "$IN" ] ; then
798 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
799 # run_command '' echo "Post-processing track $1 of $TRACKS..."
800 # case "$POSTPROCESSFORMAT" in
802 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
804 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
806 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
808 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
810 # # Only remove .wav if the encoding succeeded
811 # if checkerrors "postprocess-(.{3,4})-$1"; then
812 # run_command postprocess-$1 false
814 # run_command postprocess-$1 true
817 # if [ "$(checkstatus encode-output)" = "loud" ]; then
818 # echo "HEH! The file we were about to post-process disappeared:"
821 # run_command postprocess-$1 false
828 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
831 # The commands here don't go through run_command because they're never supposed to be silenced
832 echo "Batch analizing gain in tracks: $TRACKQUEUE"
837 for UTRACKNUM
in $TRACKQUEUE
839 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
841 # XXX: Hard-coded batch option!
842 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
844 if [ "$RETURN" != "0" ]; then
845 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
847 for UTRACKNUM
in $TRACKQUEUE
849 echo normalizetrack-
$UTRACKNUM >> status
857 # NORMALIZER, NORMALIZEROPTS
858 do_batch_normalize
()
860 # The commands here don't go through run_command because they're never supposed to be silenced
861 echo "Batch normalizing tracks: $TRACKQUEUE"
866 for UTRACKNUM
in $TRACKQUEUE
868 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
870 # XXX: Hard-coded batch option!
871 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
873 if [ "$RETURN" != "0" ]; then
874 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
876 for UTRACKNUM
in $TRACKQUEUE
878 echo normalizetrack-
$UTRACKNUM >> status
884 # do_normalize [tracknumber]
886 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
889 IN
="$ABCDETEMPDIR/track$1.wav"
890 if [ -e "$IN" ] ; then
891 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
892 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
894 if [ "$(checkstatus encode-output)" = "loud" ]; then
895 echo "HEH! The file we were about to normalize disappeared:"
898 run_command normalizetrack-
$1 false
"File $IN was not found"
902 # do_move [tracknumber]
903 # Deduces the outfile from environment variables
904 # Creates directory if necessary
906 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
909 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
911 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
912 # Munge filenames as follows:
917 # Eat control characters
918 ALBUMFILE
=$
(mungefilename
"$DALBUM")
919 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
920 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
921 GENRE
=$
(mungegenre
"$GENRE")
923 # If we want to start the tracks with a given number, we need to modify the
924 # TRACKNUM value before evaluation
925 if [ -n "$STARTTRACKNUMBER" ] ; then
926 # Get the trackpadding from the current track
927 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
928 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
930 TRACKNUM
=${UTRACKNUM}
932 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
933 # TRACKFILE, and TRACKNUM.
934 if [ "$VARIOUSARTISTS" = "y" ]; then
935 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
937 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
939 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
940 OUTPUTFILEDIR
=$
(dirname "$OUTPUTDIR/$OUTPUTFILE")
941 # mkdir -p shouldn't return an error if the directory already exists
942 mkdir
-p "$OUTPUTFILEDIR"
943 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
948 # Create the playlist if wanted
950 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
951 # VARIOUSARTISTS, OUTPUTDIR
954 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
956 # Create a playlist file for the playlist data to go into.
957 # We used to wipe it out if it existed. Now we request permision if interactive.
958 for LASTTRACK
in $TRACKQUEUE; do :; done
959 ALBUMFILE
=$
(mungefilename
"$DALBUM")
960 ARTISTFILE
=$
(mungefilename
"$DARTIST")
961 GENRE
=$
(mungegenre
"$GENRE")
962 if [ "$VARIOUSARTISTS" = "y" ] ; then
963 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
965 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
967 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
968 mkdir
-p "$FINALPLAYLISTDIR"
969 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
970 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
971 if [ "$INTERACTIVE" = "y" ]; then
972 while [ "$DONE" != "y" ]; do
974 case $ERASEPLAYLIST in
975 e|E|a|A|k|K
) DONE
=y
;;
983 # Once we erase the playlist, we use append to create the new one.
984 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
986 # The playlist does not exist, so we can safelly use append to create the new list
989 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
990 touch "$OUTPUTDIR/$PLAYLISTFILE"
991 for UTRACKNUM
in $TRACKQUEUE
993 # Shares some code with do_move since the filenames have to match
994 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
995 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
997 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
998 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
999 # If we want to start the tracks with a given number, we need to modify the
1000 # TRACKNUM value before evaluation
1001 if [ -n "$STARTTRACKNUMBER" ] ; then
1002 # Get the trackpadding from the current track
1003 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
1004 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1006 TRACKNUM
=${UTRACKNUM}
1008 if [ "$VARIOUSARTISTS" = "y" ]; then
1009 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1011 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1013 if [ "$VARIOUSARTISTS" = "y" ]; then
1014 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1015 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1017 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1020 if [ "$PLAYLISTDATAPREFIX" ]; then
1021 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1023 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1028 ## this will convert the playlist to have CRLF line-endings, if specified
1029 ## (some hardware players insist on CRLF endings)
1030 if [ "$DOSPLAYLIST" = "y" ]; then
1031 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1032 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1033 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1035 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1040 # This essentially the start of things
1043 # Query the CD to get the track info, unless the user specified -C
1044 # or we are using some actions which do not need the CDDB data at all
1045 #if [ ! X"$EXPACTIONS" = "X" ]; then
1047 #elif [ -z "$DISCID" ]; then
1048 if [ -z "$DISCID" ]; then
1049 vecho
-n "Getting CD track info... "
1050 if [ "$OSFLAVOUR" = "OSX" ]; then
1051 disktool
-u ${CDROM#/dev/}
1053 TRACKINFO
=$
($CDDISCID $CDROM)
1054 if [ "$OSFLAVOUR" = "OSX" ]; then
1055 disktool
-m ${CDROM#/dev/}
1057 # Make sure there's a CD in there by checking cd-discid's return code
1058 if [ "$?" = "1" ]; then
1059 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1064 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1067 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1068 # This needs to be done now because a section of the resuming code will need
1071 # get the number of digits to pad TRACKNUM with - we'll use this later
1072 # a CD can only hold 99 tracks, but since we support a feature for starting
1073 # numbering the tracks from a given number, we might need to set it as a
1074 # variable for the user to define... or obtain it somehow.
1075 if [ "$PADTRACKS" = "y" ] ; then
1079 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1080 if [ -z "$TRACKQUEUE" ]; then
1081 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1082 case "$CDROMREADERSYNTAX" in
1084 if [ "$WEHAVEACD" = "y" ]; then
1085 vecho
"Querying the CD for audio tracks..."
1086 CDPARANOIAOUTPUT
="$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )"
1088 if [ ! "$RET" = "0" ];then
1089 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1091 TRACKS
="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ' )"
1092 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1094 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks
; then
1095 TRACKS
=$
( cat $ABCDETEMPDIR/cdparanoia-audio-tracks
)
1097 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1101 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1104 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1106 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1107 echo "The disc does not contain any tracks. Giving up..."
1110 echo -n "Grabbing entire CD - tracks: "
1111 if [ ! "$PADTRACKS" = "y" ] ; then
1112 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1114 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1116 while [ "$X" -ne "$TRACKS" ]
1118 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1119 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
1123 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1124 # User-supplied track queue.
1125 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1126 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1127 # Once cleaned, obtain the highest value in the trackqueue for number padding
1128 for LASTTRACK
in $TRACKQUEUE; do :; done
1129 if [ ! "$PADTRACKS" = "y" ] ; then
1130 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1132 # Now we normalize the trackqueue
1133 for TRACK
in $TRACKQUEUE ; do
1134 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1135 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1137 TRACKQUEUE
=$PADTRACKQUEUE
1138 echo Grabbing tracks
: "$TRACKQUEUE"
1141 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1143 # We have the discid, create a temp directory after it to store all the temp
1146 if [ -e "$ABCDETEMPDIR" ]; then
1147 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1148 # It already exists, see if it's a directory
1149 if [ ! -d "$ABCDETEMPDIR" ]; then
1150 # This is a file/socket/fifo/device/etc, not a directory
1153 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1154 echo "Please investigate, remove it, and rerun abcde." >&2
1158 # It's a directory, let's see if it's owned by us
1159 if [ ! -O "$ABCDETEMPDIR" ]; then
1160 # Nope, complain and exit
1162 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1163 echo "Please investigate, remove it, and rerun abcde." >&2
1167 # See if it's populated
1168 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1169 # Wipe and start fresh
1170 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1171 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1172 if [ "$INTERACTIVE" = "y" ]; then
1178 if [ "$ANSWER" != "y" ]; then
1181 rm -rf "$ABCDETEMPDIR" ||
exit 1
1182 mkdir
"$ABCDETEMPDIR"
1183 if [ "$?" -gt "0" ]; then
1184 # Directory already exists or could not be created
1185 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1189 # Everything is fine. Check for ^encodetracklocation-
1190 # and encode-output entries in the status file and
1191 # remove them. These are not relevant across sessions.
1192 if [ -f "$ABCDETEMPDIR/status" ]; then
1193 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1194 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1195 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1197 # Remove old error messages
1198 if [ -f "$ABCDETEMPDIR/errors" ]; then
1199 rm -f "$ABCDETEMPDIR/errors"
1203 # We are starting from scratch
1204 mkdir
"$ABCDETEMPDIR"
1205 if [ "$?" -gt "0" ]; then
1206 # Directory already exists or could not be created
1207 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1210 cat /dev
/null
> "$ABCDETEMPDIR/status"
1212 if [ X
"$CUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1213 if checkstatus cuefile
>/dev
/null
; then :; else
1214 CUEFILE
=cue-$
(echo $TRACKINFO | cut
-f3 -d' ').txt
1215 $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/$CUEFILE
1216 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1219 # If we got the CDPARANOIA status and it is not recorded, save it now
1220 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1221 if checkstatus cdparanoia-audio-tracks
; then :; else
1222 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1223 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1228 # Create the discid file
1229 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1240 # Parses a CDDB file and outputs the title and the track names.
1241 # Variables: CDDBFILE
1245 # List out disc title/author and contents
1246 if [ "$ONETRACK" = "y" ]; then
1247 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1249 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1250 if [ ! "$ONETRACK" = "y" ]; then
1251 for TRACK
in $
(f_seq_row
1 $TRACKS)
1253 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1259 # Check for a local CDDB file, and report success
1262 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1264 CDDBLOCALSUCCESS
="n"
1265 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1266 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1269 # If the user has selected to check a local CDDB repo, we proceed with it
1270 if [ -r "${CDDBLOCALFILE}" ]; then
1271 # List out disc title/author and contents
1272 do_cddbparse
"${CDDBLOCALFILE}"
1273 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1274 if [ "$INTERACTIVE" = "y" ]; then
1276 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1277 echo -n 'Invalid selection. Please answer "y" or "n": '
1280 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1284 if [ "$USELOCALRESP" = "y" ]; then
1285 #echo "Using local copy of CDDB data"
1286 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1287 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1288 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1289 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1290 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1291 CDDBLOCALSUCCESS
="y"
1293 #echo "Not using local copy of CDDB data"
1294 CDDBLOCALSUCCESS
="n"
1297 CDDBLOCALSUCCESS
="n"
1305 # Perform CDDB protocol version check if it hasn't already been done
1306 if checkstatus cddb-statcomplete
; then :; else
1307 if [ "$CDDBAVAIL" = "n" ]; then
1309 echo 503 > "$ABCDETEMPDIR/cddbstat"
1312 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1313 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1314 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1315 vecho
"Checking CDDB server status..."
1316 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1317 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1318 case "$RESPONSECODE" in
1319 210) # 210 OK, status information follows (until terminating `.')
1322 501|
*) # 501 Illegal CDDB protocol level: <n>.
1323 CDDBPROTO
=`expr $CDDBPROTO - 1`
1327 if test $rc -eq 1; then
1331 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1339 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1340 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1342 # Perform CDDB query if it hasn't already been done
1343 if checkstatus cddb-querycomplete
; then :; else
1344 if [ "$CDDBAVAIL" = "n" ]; then
1346 echo 503 > "$ABCDETEMPDIR/cddbquery"
1347 # The default CDDBLOCALSUCCESS is "n"
1348 # This part will be triggered if the user CDDB repo does not
1349 # contain the entry, or if we are not trying to use the repo.
1351 vecho
"Querying the CDDB server..."
1352 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1353 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1354 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1360 # no match found in database,
1361 # wget/fetch error, or user requested not to use CDDB
1362 # Make up an error code (503) that abcde
1363 # will recognize in do_cddbread
1364 # and compensate by making a template
1365 echo 503 > "$ABCDETEMPDIR/cddbquery"
1367 *) # strange and unknown error
1368 echo ERRORCODE
=$ERRORCODE
1369 echo "abcde: $CDDBTOOL returned unknown error code"
1373 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1380 # If it's not to be used, generate a template.
1381 # Then, display it (or them) and let the user choose/edit it
1382 if checkstatus cddb-readcomplete
; then :; else
1383 vecho
"Obtaining CDDB results..."
1384 # If CDDB is to be used, interpret the query results and read all
1385 # the available entries.
1386 rm -f "$ABCDETEMPDIR/cddbchoices"
1387 CDDBCHOICES
=1 # Overridden by multiple matches
1388 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1389 case "$RESPONSECODE" in
1391 # One exact match, retrieve it
1392 # 200 [section] [discid] [artist] / [title]
1393 if checkstatus cddb-read-1-complete
; then :; else
1394 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1395 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1396 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1397 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1398 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1400 # List out disc title/author and contents
1401 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1402 for TRACK
in $
(f_seq_row
1 $TRACKS)
1404 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1406 echo >> "$ABCDETEMPDIR/cddbchoices"
1410 case "$RESPONSECODE" in
1411 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1412 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1413 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1415 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1416 # List out disc title/author and contents of template
1417 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1419 for TRACK
in $
(f_seq_row
1 $TRACKS)
1421 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1423 echo >> "$ABCDETEMPDIR/cddbchoices"
1424 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1425 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1428 # Multiple exact, (possibly multiple) inexact matches
1430 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1431 if [ "$(wc -l < $ABCDETEMPDIR/cddbquery | tr -d ' ')" -eq 3 ]; then
1432 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1433 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1434 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1436 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1438 vecho
-n "Retrieving multiple matches... "
1439 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1440 read DISCINFO
# eat top line
1444 if checkstatus cddb-read-
$X-complete; then :; else
1445 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1446 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1448 # List out disc title/author and contents
1449 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1450 for TRACK
in $
(f_seq_row
1 $TRACKS)
1452 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1454 echo >> "$ABCDETEMPDIR/cddbchoices"
1457 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1461 for TRACK
in $
(f_seq_row
1 $TRACKS)
1463 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1465 echo >> "$ABCDETEMPDIR/cddbchoices"
1466 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1467 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1470 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1477 if checkstatus cddb-edit
>/dev
/null
; then
1478 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1479 VARIOUSARTISTS
="$(checkstatus variousartists)"
1480 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1483 if [ "$INTERACTIVE" = "y" ]; then
1484 # We should show the CDDB results both when we are not using the local CDDB repo
1485 # or when we are using it but we could not find a proper match
1486 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1487 # Display the $ABCDETEMPDIR/cddbchoices file created above
1488 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1489 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1490 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1491 CHOICE
=$
(checkstatus cddb-choice
)
1492 if [ -n "$CHOICE" ] ; then
1493 case $CDDBCHOICES in
1494 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1496 echo "Selected: #$CHOICE"
1497 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1501 # The user has a choice to make, display the info in a pager if necessary
1502 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1503 # Use the debian sensible-pager wrapper to pick the pager
1504 # user has requested via their $PAGER environment variable
1505 if [ -x "/usr/bin/sensible-pager" ]; then
1506 /usr
/bin
/sensible-pager
"$ABCDETEMPDIR/cddbchoices"
1507 elif [ -x "$PAGER" ]; then
1508 # That failed, try to load the preferred editor, starting
1509 # with their PAGER variable
1510 $PAGER "$ABCDETEMPDIR/cddbchoices"
1511 # If that fails, check for less
1512 elif [ -x /usr
/bin
/less ]; then
1513 /usr
/bin
/less -f "$ABCDETEMPDIR/cddbchoices"
1514 # more should be on all UNIX systems
1515 elif [ -x /bin
/more ]; then
1516 /bin
/more "$ABCDETEMPDIR/cddbchoices"
1518 # No bananas, just cat the thing
1519 cat "$ABCDETEMPDIR/cddbchoices" >&2
1522 # It's all going to fit in one page, cat it
1523 cat "$ABCDETEMPDIR/cddbchoices" >&2
1526 # I'll take CDDB read #3 for $400, Alex
1527 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1529 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1530 # Make sure we get a valid choice
1531 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1532 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1533 echo "Invalid selection. Please choose a number between 1 and $CDDBCHOICES." >&2
1534 echo -n "Selection [0-$CDDBCHOICES]: " >&2
1536 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1538 if [ "$CDCHOICENUM" = "0" ]; then
1539 vecho
"Creating empty CDDB template..."
1541 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > $ABCDETEMPDIR/cddbread
.0
1543 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1544 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1546 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1550 # We need some code to show the selected option when local repository is selected and we have found a match
1551 vecho
"Using cached CDDB match..." >&2
1552 # Display the $ABCDETEMPDIR/cddbchoices file created above
1553 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1554 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1555 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1556 CHOICE
=$
(checkstatus cddb-choice
)
1557 if [ "$USELOCALRESP" = "y" ]; then :; else
1558 if [ -n "$CHOICE" ] ; then
1559 case $CDDBCHOICES in
1562 echo "Selected template."
1564 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1566 echo "Selected: #$CHOICE"
1567 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1575 # We're noninteractive - pick the first choice.
1576 # But in case we run a previous instance and selected a choice, use it.
1577 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1578 # Show the choice if we are not using the locally stored one
1579 # or when the local search failed to find a match.
1580 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1581 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1582 #if [ "$PREVIOUSCHOICE" ]; then
1583 cat "$ABCDETEMPDIR/cddbchoices"
1586 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1587 CDCHOICENUM
=$PREVIOUSCHOICE
1590 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1592 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1597 if checkstatus cddb-choice
>/dev
/null
; then :; else
1598 echo "abcde: internal error: cddb-choice not recorded." >&2
1601 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1602 echo -n "Edit selected CDDB data? [y/n] (" >&2
1603 if [ "$INTERACTIVE" = "y" ]; then
1604 if [ "$UNKNOWNDISK" = "y" ]; then
1607 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1616 if [ "$EDITCDDB" = "y" ]; then
1617 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1619 # Use the debian sensible-editor wrapper to pick the editor that the
1620 # user has requested via their $EDITOR environment variable
1621 if [ -x "/usr/bin/sensible-editor" ]; then
1622 /usr
/bin
/sensible-editor
"$CDDBDATA"
1623 elif [ -n "$EDITOR" ]; then
1624 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1625 # That failed, try to load the preferred editor, starting
1626 # with their EDITOR variable
1627 eval $
(echo "$EDITOR") "$CDDBDATA"
1629 # If that fails, check for a vi
1630 elif which vi
>/dev
/null
2>&1; then
1632 elif [ -x /usr
/bin
/vi
]; then
1633 /usr
/bin
/vi
"$CDDBDATA"
1634 # nano should be on all (modern, i.e., sarge) debian systems
1635 elif which nano
>/dev
/null
2>&1 ; then
1637 elif [ -x /usr
/bin
/nano
]; then
1638 /usr
/bin
/nano
"$CDDBDATA"
1639 # mg should be on all OpenBSD systems
1640 elif which mg
>/dev
/null
2>&1 ; then
1642 elif [ -x /usr
/bin
/mg
]; then
1643 /usr
/bin
/mg
"$CDDBDATA"
1646 echo "No editor available. Check your EDITOR environment variable." >&2
1648 # delete editor backup file if it exists
1649 if [ -w "$CDDBDATA~" ]; then
1654 # Some heuristics first. Look at Disc Title, and if it starts with
1655 # "Various", then we'll assume Various Artists
1656 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1657 echo "Looks like a Multi-Artist CD" >&2
1660 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1661 if [ "$INTERACTIVE" = "y" ]; then
1668 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1671 # Need NUMTRACKS before cddb-tool will return it:
1672 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1673 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1674 # More than 1/2 tracks contain a "/", so guess forward
1676 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1677 # More than 1/2 contain a "-", so guess forward-dash
1679 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1680 # More than 1/2 contain something in parens, so guess trailing-paren
1684 echo "1) Artist / Title" >&2
1685 echo "2) Artist - Title" >&2
1686 echo "3) Title / Artist" >&2
1687 echo "4) Title - Artist" >&2
1688 echo "5) Artist: Title" >&2
1689 echo "6) Title (Artist)" >&2
1690 echo "7) This is a single-artist CD" >&2
1691 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1692 if [ "$INTERACTIVE" = "y" ]; then
1693 read VARIOUSARTISTSTYLE
1695 echo $DEFAULTSTYLE >&2
1696 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1698 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1699 # If they press Enter, then the default style (0) was chosen
1700 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1701 echo "Invalid selection. Please choose a number between 1 and 7."
1702 echo -n "Selection [1-7]: "
1703 read VARIOUSARTISTSTYLE
1704 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1706 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1707 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1709 vecho
"Selected: $VARIOUSARTISTSTYLE"
1710 case "$VARIOUSARTISTSTYLE" in
1712 VARIOUSARTISTSTYLE
=forward
1715 VARIOUSARTISTSTYLE
=forward-dash
1718 VARIOUSARTISTSTYLE
=reverse
1721 VARIOUSARTISTSTYLE
=reverse-dash
1724 VARIOUSARTISTSTYLE
=colon
1727 VARIOUSARTISTSTYLE
=trailing-paren
1735 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1736 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1738 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1739 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1740 # This works but does not have the necessary error checking
1741 # yet. If you are familiar with the CDDB spec
1742 # (see http://www.freedb.org/src/latest/DBFORMAT)
1743 # and can create an error-free entry on your own, then put
1744 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1745 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1746 # your abcde.conf to change the email address submissions are
1749 # submit the modified file, if they want
1750 if [ "$NOSUBMIT" != "y" ]; then
1751 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1753 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1754 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1756 echo -n 'Invalid selection. Please answer "y" or "n": '
1759 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1760 echo -n "Sending..."
1761 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1767 # Make sure the cache directory exists
1768 mkdir
-p $CDDBLOCALDIR
1769 # Cache edited CDDB entry in the user's cddb dir
1770 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1771 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1774 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1777 # do_cdread [tracknumber]
1778 # do_cdread onetrack [firsttrack] [lasttrack]
1782 # The commands here don't go through run_command because they're never supposed to be silenced
1783 # return codes need to be doublechecked anyway, however
1784 if [ "$1" = "onetrack" ]; then
1785 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1786 # FIXME # Until then, we grab the whole CD in one track, no matter what
1788 # We need the first and last track for cdda2wav
1791 UTRACKNUM
=$FIRSTTRACK
1792 case "$CDROMREADERSYNTAX" in
1793 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
1794 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTRACK" ;;
1795 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1801 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1802 if [ "$USEPIPES" = "y" ]; then
1803 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1806 PIPE_MESSAGE
="and encoding "
1808 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1809 case "$CDROMREADERSYNTAX" in
1810 ## FIXME ## Find the case for dagrab, to avoid exceptions
1812 FILEARG
="-f $WAVDATA"
1820 if [ "$1" = "onetrack" ]; then
1821 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK ..." >&2
1823 if [ -r "$CDDBDATA" ]; then
1824 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1825 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1827 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1830 case "$CDROMREADERSYNTAX" in
1832 nice
$READNICE $CDROMREADER -d $CDROM ${READTRACKNUMS:-$UTRACKNUM} $FILEARG $REDIR ;;
1834 if [ "$OSFLAVOUR" = "OSX" ] ; then
1835 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1836 disktool
-u ${CDROM#/dev/} 0
1837 # Also, in OSX the cdrom device for cdda2wav changes...
1838 CDDA2WAVCDROM
="IODVDServices"
1839 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1840 CDDA2WAVCDROM
="$CDROMID"
1842 if [ "$CDROMID" = "" ]; then
1843 CDDA2WAVCDROM
="$CDROM"
1845 CDDA2WAVCDROM
="$CDROMID"
1848 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} $FILEARG $REDIR
1850 ## FIXME ## We have an exception for dagrab, since it uses -f
1851 ## FIXME ## Shall we just use -f $FILEARG ??
1852 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM $FILEARG $REDIR
1855 # Find the track's mounted path
1856 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1857 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1858 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
1859 # If the file exists, copy it
1860 if [ -e "$FILEPATH" ] ; then
1861 nice
$READNICE $CDROMREADER "$FILEPATH" $FILEARG $REDIR
1865 debug
) nice
$READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] $FILEARG $REDIR
1869 # If we get some error or we get some missing wav
1870 # (as long as we dont use pipes)
1871 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
1872 # Thank goodness errors is only machine-parseable up to the
1873 # first colon, otherwise this woulda sucked
1874 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1875 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
1877 if [ "$USEPIPES" = "y" ]; then
1878 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1880 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1884 if [ "$USEPIPES" = "y" ]; then
1885 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1887 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1893 # No values accepted, only uses env variables
1896 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
1897 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
1899 echo "abcde: unable to set the device speed" >&2
1905 # vecho outputs a message if EXTRAVERBOSE is selected
1908 if [ x
"$EXTRAVERBOSE" != "x" ]; then
1913 # User-redefinable functions
1914 # Custom filename munging:
1917 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
1918 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
1921 # Custom genre munging:
1924 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
1928 # Empty pre_read function, to be defined in the configuration file.
1934 ###############################################################################
1937 # Start of execution
1938 ###############################################################################
1941 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
1942 CDDBSUBMIT
=freedb-submit@freedb.org
1944 HELLOINFO
="$(whoami)@$(hostname)"
1946 CDROMREADERSYNTAX
=cdparanoia
1948 ENCODERSYNTAX
=default
1950 MP3ENCODERSYNTAX
=default
1951 OGGENCODERSYNTAX
=default
1952 FLACENCODERSYNTAX
=default
1953 SPEEXENCODERSYNTAX
=default
1954 MPPENCODERSYNTAX
=default
1955 NORMALIZERSYNTAX
=default
1957 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
1958 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
1959 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
1960 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
1961 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
1962 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
1963 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1964 PLAYLISTDATAPREFIX
=''
1965 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1966 VAPLAYLISTDATAPREFIX
=''
1974 VARIOUSARTISTSTYLE
=forward
1978 CDDBLOCALDIR
="$HOME/.cddb"
1981 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
1982 # i.e. CDROMID="1,0,0"
1985 # program paths - defaults to checking your $PATH
1991 XINGMP3ENC
=xingmp3enc
2005 CDPARANOIA
=cdparanoia
2014 VORBISCOMMENT
=vorbiscomment
2016 NORMALIZE
=normalize-audio
2018 VORBISGAIN
=vorbisgain
2021 # Options for programs called from abcde
2052 VORBISCOMMENTOPTS
="-R"
2053 METAFLACOPTS
="--no-utf8-convert"
2055 # Default to one process if -j isn't specified
2058 # List of actions to perform - by default, run to completion
2059 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2061 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2062 # Let's use these checkings to determine the OS flavour, which will be used later
2063 if [ X$
(uname
) = "XFreeBSD" ] ; then
2067 elif [ X$
(uname
) = "XDarwin" ] ; then
2070 # We should have disktool in OSX, but let's be sure...
2072 CDROMREADERSYNTAX
=cddafs
2073 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2080 # If CDDBAVAIL is set to n, no CDDB read is done
2081 # If USEID3 is set to n, no ID3 tagging is done
2086 if [ -z "$OUTPUTDIR" ]; then
2090 if [ -z "$WAVOUTPUTDIR" ]; then
2091 WAVOUTPUTDIR
="$OUTPUTDIR"
2094 # Load system defaults
2095 if [ -r /etc
/abcde.conf
]; then
2098 # Load user preference defaults
2099 if [ -r $HOME/.abcde.conf
]; then
2103 # By this time, we need some HTTPGETOPTS already defined.
2104 # If the user has defined a non-default HTTPGET method, we should not be empty.
2106 if [ "$HTTPGETOPTS" = "" ] ; then
2108 wget
) HTTPGETOPTS
="-q -O -";;
2109 curl
) HTTPGETOPTS
="-f -s";;
2110 fetch
)HTTPGETOPTS
="-q -o -";;
2111 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2115 # If the CDROM has not been set yet, find a suitable one.
2116 # If this is a devfs system, default to /dev/cdroms/cdrom0
2117 # instead of /dev/cdrom
2118 if [ "$CDROM" = "" ] ; then
2119 if [ -e /dev
/cdroms
/cdrom0
]; then
2120 CDROM
=/dev
/cdroms
/cdrom0
2121 elif [ -e /dev
/cdrom
]; then
2123 elif [ -e /dev
/cd0c
]; then
2125 elif [ -e /dev
/acd0c
]; then
2127 elif [ -e /dev
/disk1
]; then
2132 # Parse command line options
2133 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
2134 while getopts 1a
:A
:bc:C
:d
:Dehj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
2137 a
) ACTIONS
="$OPTARG" ;;
2138 A
) EXPACTIONS
="$OPTARG";;
2140 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2141 C
) DISCID
="${OPTARG#abcde.}" ;;
2142 d
) CDROM
="$OPTARG" ;;
2144 e
) ERASEENCODEDSTATUS
=y
;;
2146 e
) ERASEENCODEDSTATUS
=y
;;
2147 # f) FORCECDDBUSELOCAL=y ;;
2149 j
) MAXPROCS
="$OPTARG" ;;
2152 L
) CDDBUSELOCAL
=y
;;
2157 o
) OUTPUTTYPE
="$OPTARG" ;;
2160 r
) REMOTEHOSTS
="$OPTARG" ;;
2162 s
) STARTTRACKNUMBER
="$OPTARG" ;;
2163 S
) CDSPEEDVALUE
="$OPTARG" ;;
2164 # t) PREPROCESSFORMATS="$OPTARG"
2166 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2167 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2168 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2170 echo "This is abcde v$VERSION."
2171 echo "Usage: abcde [options] [tracks]"
2172 echo "abcde -h for extra help"
2175 V
) EXTRAVERBOSE
="y" ;;
2177 w
) COMMENT
="$OPTARG" ;;
2178 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2179 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2181 echo "abcde error: argument of -W must be integer"
2189 shift $
(($OPTIND - 1))
2191 # Decide if we can continue.
2192 if [ "$ONETRACK" = "y" ]; then
2193 # FIXME # remove check as soon as we find out about the other readers
2194 case "$CDROMREADERSYNTAX" in
2195 dagrab|cddafs|debug
) echo "abcde error: ONETRACK reading is not suported with $CDROMREADERSYNTAX yet"
2198 if [ "$BATCH" = "y" ]; then
2199 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2202 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2203 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2204 if [ $# -gt 0 ]; then
2205 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2208 while [ $# -gt 0 ]; do
2209 # Range parsing code courtesy of Vincent Ho
2210 RSTART
=$
(echo $1 | cut
-f1 -d-)
2211 REND
=$
(echo $1 | cut
-f2 -d-)
2212 if [ "$RSTART" = "$REND" ]; then
2215 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2217 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2222 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2223 # List of experimental actions: retag,transcode
2225 # Determine what actions are to be done from $ACTIONS and set the
2226 # following environment variables for them:
2238 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2243 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2244 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2245 encode
) DOENCODE
=y
; DOREAD
=y
;;
2246 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2247 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2248 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2249 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2256 # At this point a CDROM has to be defined, so we check it exists.
2257 if [ X
"$CDROM" != "X" ] ; then
2258 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2259 if [ "$OSFLAVOUR" = "FBSD" ]; then
2260 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2261 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2262 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2266 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2267 echo "abcde error: CDROM device cannot be found." >&2
2270 # avoid processing if we are not going to hit the CDROM.
2271 elif [ X
"$DOREAD" = "Xy" ]; then
2272 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2276 # USEPIPES pre-tests, before we get into more serious stuff
2277 # Not compatible with:
2278 # - multiple outputs
2280 # - lowdisk algorithm
2282 if [ X
"$USEPIPES" = "Xy" ]; then
2283 if [ $
(echo $OUTPUTTYPE |
tr , \ |
wc -w ) -gt 1 ]; then
2284 echo "abcde error: Unix pipes not compatible with multiple outputs"
2287 if [ X
"$DONORMALIZE" = "Xy" ]; then
2288 echo "abcde error: Unix pipes not compatible with normalizer"
2289 # FIXME # Do we need to exit or shall we just disable the mode?
2292 if [ X
"$DOENCODE" = "Xn" ]; then
2293 vecho
"Disabling Unix pipes since we are not encoding!"
2296 if [ X
"$LOWDISK" = "Xy" ]; then
2297 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2302 # Decide which CDROM reader we're gonna use
2303 case "$CDROMREADERSYNTAX" in
2305 CDROMREADER
="$CDPARANOIA"
2306 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2309 CDROMREADER
="$CDDA2WAV"
2310 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2313 CDROMREADER
="$DAGRAB"
2314 CDROMREADEROPTS
="$DAGRABOPTS"
2317 CDROMREADER
="$CDDAFS"
2318 CDROMREADEROPTS
="$CDDAFSOPTS"
2322 # There's only one normalize...
2323 case "$NORMALIZERSYNTAX" in
2325 NORMALIZER
="$NORMALIZE"
2326 NORMALIZEROPTS
="$NORMALIZEOPTS"
2330 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2331 if echo $OUTPUTTYPE |
grep ":" > /dev
/null
2>&1 ; then
2334 for OUTPUT
in "$OUTPUTTYPE"
2337 ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2338 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2339 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2340 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2341 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2344 for OUTPUT
in "$OUTPUTTYPE"
2346 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2347 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2349 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2353 # 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
2355 # Getting ready for multiple output changes
2356 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2359 ogg
) [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2360 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2361 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2363 mp3
) [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2364 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2366 flac
) [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2367 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2369 spx
) [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
;;
2370 mpc
) [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
;;
2371 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2377 # decide which encoder
2378 case "$MP3ENCODERSYNTAX" in
2380 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2384 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2388 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2389 MP3ENCODER
="$BLADEENC"
2392 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2396 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2397 MP3ENCODER
="$XINGMP3ENC"
2400 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2401 MP3ENCODER
="$MP3ENC"
2404 case "$OGGENCODERSYNTAX" in
2406 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2407 OGGENCODER
="$VORBIZE"
2410 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2411 OGGENCODER
="$OGGENC"
2414 case "$FLACENCODERSYNTAX" in
2416 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2418 ## FIXME ## FLAC streams can be encapsulated on a Ogg transport layer
2419 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2424 case "$SPEEXENCODERSYNTAX" in
2426 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2427 SPEEXENCODER
="$SPEEXENC"
2430 case "$MPPENCODERSYNTAX" in
2432 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2433 MPPENCODER
="$MPPENC"
2439 if [ "$ID3TAGV" = "1" ]; then
2441 TAGGEROPTS
="$ID3OPTS"
2444 TAGGEROPTS
="$ID3V2OPTS"
2447 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2449 if [ "$ENCNICE" ]; then
2450 ENCNICE
="-n $ENCNICE"
2452 if [ "$READNICE" ]; then
2453 READNICE
="-n $READNICE"
2455 if [ "$DISTMP3NICE" ]; then
2456 DISTMP3NICE
="-n $DISTMP3NICE"
2459 # Don't check for stuff if it's not needed
2460 if [ "$REMOTEHOSTS" ]; then
2463 if [ "$DONORMALIZE" = "y" ]; then
2466 if [ "$EJECTCD" = "y" ]; then
2469 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2472 if [ "$CUEFILE" = "y" ]; then
2476 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2477 case "$CDROMREADERSYNTAX" in
2478 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2483 # Rippers with USEPIPE support
2484 # FIXME # Include here all the rippers we can figure out support pipes
2487 # Encoders with USEPIPE support
2488 # FIXME # Include here all the encoders we can figure out support pipes
2493 # Figure out if we can use pipes with the ripper/encoder combination
2495 if [ "$USEPIPES" = "y" ]; then
2496 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2499 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2501 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2503 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYTNAX" ;;
2505 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2507 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2509 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2510 echo "abcde error: no support for pipes with given ripper" >&2
2511 echo "read the USEPIPES file from the source tarball to help" >&2
2512 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2515 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2516 echo "abcde error: no support for pipes with given encoder" >&2
2517 echo "read the USEPIPES file from the source tarball to help" >&2
2518 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2524 # Make sure a buncha things exist
2525 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2526 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2527 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2528 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2529 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2530 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2531 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2533 # Cut off the command-line options we just added in
2534 X
=$
(echo $X | cut
-d' ' -f2)
2535 if [ "$(which $X)" = "" ]; then
2536 echo "abcde error: $X is not in your path." >&2
2538 elif [ ! -x $
(which $X) ]; then
2539 echo "abcde error: $X is not executable." >&2
2544 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2545 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2546 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2548 # Here it used to say:
2549 # One thousand lines in, we can start doing stuff with things
2550 # Well, right now we are at line 2157 ;)
2552 # Export needed things so they can be read in this subshell
2553 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2554 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2556 # User-definable function to set some things. Use it for
2557 # - closing the CD tray with eject -t
2558 # - set the CD speed value with eject -x
2559 vecho
-n "Executing customizable pre-read function... "
2561 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2565 do_discid
# Get ABCDETEMPDIR created and status file initialized
2567 if [ "$DOCDDB" = "y" ]; then
2568 if [ $CDDBUSELOCAL = "y" ]; then
2571 if checkstatus cddb-choice
> /dev
/null
; then
2574 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2582 eval $
($CDDBTOOL parse
"$CDDBDATA")
2585 # Before reading tracks, we set the speed of the device
2587 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2588 case "$CDROMREADERSYNTAX" in
2589 cdparanoia|debug
) : ;;
2594 # Define the first and last track, since we might need them later in several places
2595 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
2596 LASTTRACK
=$
( get_last
$TRACKQUEUE )
2598 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
2599 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2600 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
2601 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
2604 # Create playlist if needed (backgroundable) and start reading in tracks
2608 if [ ! "$ONETRACK" = "y" ]; then
2609 if [ "$DOPLAYLIST" = "y" ]; then
2610 echo Creating playlist...
>&2
2615 # For the lowdisk option, only one program is running at once so the encoder
2616 # can be unsilenced right away.
2617 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2618 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2621 if [ "$ONETRACK" = "y" ]; then
2622 TRACKS
="$FIRSTTRACK"
2623 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2624 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
2627 for UTRACKNUM
in $TRACKQUEUE
2629 if [ "$DOREAD" = "y" ]; then
2630 if [ "$USEPIPES" = "y" ]; then
2631 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2632 # Read, pipe, shut up!
2633 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
2636 if checkstatus readtrack-
$UTRACKNUM; then :; else
2637 do_cdread
$UTRACKNUM
2639 if [ "$?" != "0" ]; then
2640 # CD read failed - don't give the goahead to
2647 if [ "$BATCH" = "y" ]; then
2650 echo NEXTTRACK
# Get the encoder machine churning again
2651 if [ "$DOREAD" = "y" ]; then
2652 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2653 until checkstatus encodetrack-
$UTRACKNUM
2655 if checkerrors encodetrack-
$UTRACKNUM; then
2666 # Now that we're done the encoding can be loud again -
2667 # if we're not using SMP.
2668 if [ "$MAXPROCS" = "1" ]; then
2669 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2672 # All tracks read, start encoding.
2673 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2677 # We are now finished with the cdrom - it can be safely ejected. Note that
2678 # abcde will not have completed yet.
2679 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2680 # We check if the disk we are processing is actually the disk inside the
2681 # CD tray. If not, we do not eject the CD, since it might be so that the
2682 # user ejected it manually.
2683 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2684 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2685 # More FreeBSD bits.
2686 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2687 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2688 # but in this script EJECT is in the envionment and names the program
2691 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2692 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2693 $eject $EJECTOPTS $cd
2694 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2695 disktool
-e ${CDROM#/dev/} 0
2697 $EJECT $EJECTOPTS $CDROM
2704 ## Do we need to pre-process
2705 #if [ x"$PREPROCESS" = "x" ] ; then
2708 # for PRETRACKNUM in $TRACKQUEUE
2711 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2713 # until [ $PREPROCEED ]
2715 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2716 # # all locations are working, wait and try again later
2717 # if [ ! $PREPROCEED ]; then sleep 3; fi
2719 # ( do_preprocess $PRETRACKNUM
2727 # In batch mode, we want all tracks to be read first.
2728 if [ "$BATCH" = "y" ]; then
2729 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2730 if [ "$GOAHEAD" = "NO" ]; then break; fi
2731 for LASTTRACK
in $TRACKQUEUE; do :; done
2732 if checkstatus readtrack-
$LASTTRACK; then
2733 if [ "$DONORMALIZE" = "y" ]; then
2734 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2735 if checkerrors batch-normalize
; then exit; fi
2737 if [ "$DOENCODE" = "y" ]; then
2738 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2739 if checkerrors batch-encode
; then exit; fi
2744 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2745 if [ "$ONETRACK" = "y" ] ; then
2746 TRACKQUEUE
="$FIRSTTRACK"
2747 TRACKS
="$FIRSTTRACK"
2750 # Do the encoding, including parallelization of remote encoding
2751 # Figure out where each track is going to be encoded
2752 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2753 if [ "$MAXPROCS" != "0" ]; then
2754 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2756 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2760 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2761 for UTRACKNUM
in $TRACKQUEUE
2764 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2765 if [ "$GOAHEAD" = "NO" ]; then break; fi
2766 # find out where this track is to be encoded
2767 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2768 # Make sure we have a place to encode this, if not, exit stage right
2769 if [ -z "$ENCODELOCATIONS" ]; then
2775 for LOCATION
in $ENCODELOCATIONS
2777 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2778 # check first if a track has ever been assigned to this location
2779 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
2780 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2781 if checkerrors encodetrack-
$PREVIOUSTRACK; then
2782 for TEMPLOCATION
in $ENCODELOCATIONS
2784 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2785 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
2788 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
2793 # We're still here, this location must have been previously assigned,
2794 # and last completed without error - check if it's done with the
2795 # previous track yet
2796 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
2798 # all locations are working, wait and try again later
2799 if [ ! $PROCEED ]; then sleep 3; fi
2801 # Record the location we're about to encode the next track at
2802 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2804 # Don't proceed with the rest of the loop if we can't encode
2805 if [ "$ABORT" ]; then continue; fi
2806 # Set TRACKNUM, TRACKNAME
2807 if [ -e "$CDDBDATA" ]; then
2808 if [ "$ONETRACK" = "y" ]; then
2810 TRACKNUM
="$FIRSTTRACK"
2813 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
2815 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2816 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
2820 # You can't encode a file which needs to be normalized before finishing
2821 # You can't tag a file before it's finished encoding -
2822 # thus all of this is backgrounded together
2824 if [ "$DONORMALIZE" = "y" ]; then
2825 if checkstatus readtrack-
$UTRACKNUM; then
2826 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
2829 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2830 if checkstatus readtrack-
$UTRACKNUM; then
2831 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
2832 if [ "$DONORMALIZE" = "y" ]; then
2833 if checkstatus normalizetrack-
$UTRACKNUM; then
2834 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2837 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2841 if [ "$DOTAG" = "y" ]; then
2842 if checkstatus encodetrack-
$UTRACKNUM; then
2843 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
2846 if [ "$DOMOVE" = "y" ]; then
2847 if checkstatus tagtrack-
$UTRACKNUM; then
2848 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
2853 # Lets move the cue file
2854 if checkstatus cuefile
>/dev
/null
; then
2857 # Go through it again and make sure there's no distmp3 stragglers, otherwise
2858 # we'll delete the files they're working on
2859 ## FIXME ## Check also for files which are encoded using PIPEs.
2860 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2865 for LOCATION
in $ENCODELOCATIONS
2867 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2868 # "How can he give us a status update, if he's DEAD?"
2869 if checkstatus encodetrack-
$CHECKTRACK; then
2872 # Nothing to see here please go quietly back to your homes
2873 if [ -z "$CHECKTRACK" ]; then continue; fi
2874 # You're still here? Maybe there is something...
2875 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
2878 if [ ! $PROCEED ]; then sleep 5; fi
2881 # If the above didn't catch the stragglers, this will
2883 # Check to see if run_command logged any errors
2884 if [ -f "$ABCDETEMPDIR/errors" ]; then
2885 echo "The following commands failed to run:"
2886 cat "$ABCDETEMPDIR/errors"
2890 if [ "$KEEPWAVS" = "y" ];then
2894 if [ "$DOCLEAN" = "y" ]; then
2895 # Wipe all the evidence
2896 # Gimme gimme gimme some more time!
2898 rm -rf "$ABCDETEMPDIR"
2901 echo "Finished. Not cleaning $ABCDETEMPDIR."