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."
67 # Funtions to replace the need of seq, which is too distribution dependant.
71 while [ $i -ne `expr $2 + 1` ]
81 while [ $i -ne `expr $2 + 1` ]
89 # Functions to replace the need of awk {print $1} and {print $NF}
92 if [ X
"$1" = "X" ]; then
93 for first
in `cat`; do
104 if [ X
"$1" = "X" ]; then
105 for stdin
in `cat`; do
109 for last
in $@
; do :; done
114 # checkstatus [blurb]
115 # Returns "0" if the blurb was found, returns 1 if it wasn't
116 # Puts the blurb content, if available, on stdout.
117 # Otherwise, returns "".
120 # Take the last line in the status file if there's multiple matches
122 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
124 if [ -z "$BLURB" ]; then
129 # See if there's a = in it
130 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
131 echo "$(echo $BLURB | cut -f2- -d=)"
137 # checkerrors [blurb]
138 # Returns "0" if the blurb was found (meaning there was an error),
139 # returns 1 if it wasn't (yes this is a little backwards).
140 # Does not print the blurb on stdout.
141 # Otherwise, returns "".
144 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
147 # Take the last line in the status file if there's multiple matches
149 BLURB
="$(egrep $PATTERN $ABCDETEMPDIR/errors | tail -n 1)"
151 if [ -z "$BLURB" ]; then
152 # negative, we did not have a negative...
155 # affirmative, we had a negative...
160 # run_command [blurb] [command...]
161 # Runs a command, silently if necessary, and updates the status file
166 # See if this is supposed to be silent
167 if [ "$(checkstatus encode-output)" = "loud" ]; then
171 # Special case for SMP, since
172 # encoder output is never displayed, don't mute echos
173 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
183 if [ "$RETURN" = "2" ]; then
184 # File was already normalized.
189 if [ "$RETURN" != "0" ]; then
190 # Put an error in the errors file. For various reasons we
191 # can't capture a copy of the program's output but we can
192 # log what we attempted to execute and the error code
193 # returned by the program.
194 if [ "$BLURB" ]; then
197 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
198 return $RETURN # Do not pass go, do not update the status file
200 if [ "$BLURB" ]; then
201 echo $BLURB >> "$ABCDETEMPDIR/status"
205 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
206 # distributed under the terms of the GNU GPL v2 or later, at your option
208 # Function to determine if a word contains a slash.
217 # Function to give the relative path from one file to another.
218 # Usage: relpath fromfile tofile
219 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
220 # (the result would be Album/Song.mp3)
221 # Output is relative path to $2 from $1 on stdout
223 # This code has the following restrictions:
224 # Multiple ////s are not collapsed into single /s, with strange effects.
225 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
226 # If FR is a directory it must have a trailing /
234 /*) ;; # No processing is needed for absolute paths
236 # Loop through common prefixes, ignoring them.
237 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
239 FR
="$(echo "$FR" | cut -d/ -f2-)"
240 TO
="$(echo "$TO" | cut -d/ -f2-)"
242 # Loop through directory portions left in FR, adding appropriate ../s.
245 FR
="$(echo "$FR" | cut -d/ -f2-)"
254 # This code splits the a Various Artist track name from one of the following
257 # forward: Artist / Track
258 # forward-dash: Artist - Track
259 # reverse: Track / Artist
260 # reverse-dash: Track - Artist
261 # colon: Artist: Track
262 # trailing-paren: Artist (Track)
265 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
268 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
269 case "$VARIOUSARTISTSTYLE" in
271 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's- / -~-g')
272 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
273 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
276 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's, - ,~,g')
277 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
278 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
281 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's- / -~-g')
282 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
283 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
286 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's, - ,~,g')
287 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
288 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
291 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's-: -~-g')
292 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
293 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
296 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's,^\(.*\) (\(.*\)),\1~\2,')
297 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
298 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
301 elif [ "$ONETRACK" = "y" ]; then
302 TRACKARTIST
="Various"
304 TRACKARTIST
="$DARTIST"
309 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
313 "classic rock") id
=1 ;;
331 "industrial") id
=19 ;;
332 "alternative") id
=20 ;;
334 "death metal") id
=22 ;;
336 "soundtrack") id
=24 ;;
337 "euro-techno") id
=25 ;;
341 "jazz+funk") id
=29 ;;
344 "classical") id
=32 ;;
345 "instrumental") id
=33 ;;
349 "sound clip") id
=37 ;;
352 "alt. rock") id
=40 ;;
357 "meditative") id
=45 ;;
358 "instrum. pop") id
=46 ;;
359 "instrum. rock") id
=47 ;;
363 "techno-indust.") id
=51 ;;
364 "electronic") id
=52 ;;
366 "eurodance") id
=54 ;;
368 "southern rock") id
=56 ;;
373 "christian rap") id
=61 ;;
376 "native american") id
=64 ;;
379 "psychadelic") id
=67 ;;
381 "showtunes") id
=69 ;;
385 "acid punk") id
=73 ;;
386 "acid jazz") id
=74 ;;
390 "rock & roll") id
=78 ;;
391 "hard rock") id
=79 ;;
393 "folk/rock") id
=81 ;;
394 "national folk") id
=82 ;;
401 "bluegrass") id
=89 ;;
402 "avantgarde") id
=90 ;;
403 "gothic rock") id
=91 ;;
404 "progress. rock") id
=92 ;;
405 "psychadel. rock") id
=93 ;;
406 "symphonic rock") id
=94 ;;
407 "slow rock") id
=95 ;;
410 "easy listening") id
=98 ;;
416 "chamber music") id
=104 ;;
418 "symphony") id
=106 ;;
419 "booty bass") id
=107 ;;
421 "porn groove") id
=109 ;;
423 "slow jam") id
=111 ;;
427 "folklore") id
=115 ;;
429 "power ballad") id
=117 ;;
430 "rhythmic soul") id
=118 ;;
431 "freestyle") id
=119 ;;
433 "punk rock") id
=121 ;;
434 "drum solo") id
=122 ;;
435 "a capella") id
=123 ;;
436 "euro-house") id
=124 ;;
437 "dance hall") id
=125 ;;
439 "drum & bass") id
=127 ;;
440 "club-house") id
=128 ;;
441 "hardcore") id
=129 ;;
445 "negerpunk") id
=133 ;;
446 "polsk punk") id
=134 ;;
448 "christian gangsta rap") id
=136 ;;
449 "heavy metal") id
=137 ;;
450 "black metal") id
=138 ;;
451 "crossover") id
=139 ;;
452 "contemporary christian")id
=140 ;;
453 "christian rock") id
=141 ;;
454 "merengue") id
=142 ;;
456 "thrash metal") id
=144 ;;
459 "synthpop") id
=147 ;;
466 # do_tag [tracknumber]
467 # id3 tags a filename
469 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
470 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
473 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
474 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
475 # If we want to start the tracks with a given number, we need to modify the
476 # TRACKNUM value before evaluation
477 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
478 # Get the trackpadding from the current track
479 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
480 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
482 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
486 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
487 GENREID
=$
(do_getgenreid
"${CDGENRE}")
489 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
490 run_command tagtrack-
$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
491 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
492 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
493 "$ABCDETEMPDIR/track$1.$OUTPUT"
496 case "$OGGENCODERSYNTAX" in
498 # vorbiscomment can't do in-place modification, mv the file first
499 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" ]; then
500 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
503 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
504 echo ARTIST
="$TRACKARTIST"
506 echo TITLE
="$TRACKNAME"
507 if [ -n "$CDYEAR" ]; then
510 if [ -n "$CDGENRE" ]; then
511 echo GENRE
="$CDGENRE"
513 echo TRACKNUMBER
=${TRACKNUM:-$1}
514 echo CDDB
=$CDDBDISCID
515 if [ "$(eval echo ${COMMENT})" != "" ]; then
516 case "$COMMENTOUTPUT" in
517 *=*) echo "$COMMENTOUTPUT";;
518 *) echo COMMENT
="$COMMENTOUTPUT";;
521 ) | run_command tagtrack-
$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
522 "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
523 # Doublecheck that the commented file was created successfully before wiping the original
524 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" ]; then
525 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
527 mv "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
533 ## FIXME ## [ "$FLACONOGG" = "y" ] && OUTPUT=ogg
535 echo ARTIST
="$TRACKARTIST"
537 echo TITLE
="$TRACKNAME"
538 if [ -n "$CDYEAR" ]; then
541 if [ -n "$CDGENRE" ]; then
542 echo GENRE
="$CDGENRE"
544 echo TRACKNUMBER
=${TRACKNUM:-$1}
545 echo CDDB
=$CDDBDISCID
546 if [ "$(eval echo ${COMMENT})" != "" ]; then
547 case "$COMMENTOUTPUT" in
548 *=*) echo "$COMMENTOUTPUT";;
549 *) echo COMMENT
="$COMMENTOUTPUT";;
552 ) | run_command tagtrack-
$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$OUTPUT"
555 run_command tagtrack-
$1 true
558 run_command tagtrack-
$1 true
566 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
569 # The commands here don't go through run_command because they're never supposed to be silenced
570 echo "Batch encoding tracks: $TRACKQUEUE"
571 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
574 case "$MP3ENCODERSYNTAX" in
579 for UTRACKNUM
in $TRACKQUEUE
581 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
583 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
585 if [ "$RETURN" != "0" ]; then
586 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
588 for UTRACKNUM
in $TRACKQUEUE
590 echo encodetrack-
$UTRACKNUM >> status
598 # Other encoders fall through to normal encoding as the tracks
599 # have not been entered in the status file.
602 # do_encode [tracknumber] [hostname]
603 # If no hostname is specified, encode locally
605 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
608 if [ "$USEPIPES" = "y" ]; then
611 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
614 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
617 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
620 TEMPARG
="PIPE_$SPEEXENCODER"
623 TEMPARG
="PIPE_$MPPENCODER"
628 IN
="$ABCDETEMPDIR/track$1.wav"
631 case "$MP3ENCODERSYNTAX" in
632 # FIXME # check if mp3enc needs -if for pipes
646 # We need IN to proceed, if we are not using pipes.
647 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
648 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
650 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
651 if [ X
"$USEPIPES" = "Xy" ]; then
654 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
655 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
661 case "$MP3ENCODERSYNTAX" in
662 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
663 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
664 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
665 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
666 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
670 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
677 case "$OGGENCODERSYNTAX" in
678 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
679 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
683 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
690 case "$FLACENCODERSYNTAX" in
691 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
697 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
698 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
703 if [ "$(eval echo ${COMMENT})" != "" ]; then
706 *) COMMENT
="COMMENT=$COMMENT" ;;
708 COMMENT
="--comment \"$COMMENT\""
710 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
711 if [ ! "$DOTAG" = "y" ]; then
712 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
714 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
718 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
720 # I tried compiling the mppenc from corecodecs.org and got some
721 # errors, so I have not tried it myself.
722 ## FIXME ## Needs some cleanup to determine if an empty tag sent
723 ## FIXME ## to the encoder ends up empty.
724 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
728 # Only remove .wav if the encoding succeeded
729 if checkerrors
"encodetrack-(.{3,4})-$1"; then
730 run_command encodetrack-
$1 false
732 run_command encodetrack-
$1 true
733 if [ ! "$KEEPWAVS" = "y" ] ; then
738 if [ "$(checkstatus encode-output)" = "loud" ]; then
739 echo "HEH! The file we were about to encode disappeared:"
742 run_command encodetrack-
$1 false
746 # do_preprocess [tracknumber]
748 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
751 # IN="$ABCDETEMPDIR/track$1.wav"
752 # # We need IN to proceed.
753 # if [ -s "$IN" ] ; then
754 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
756 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
757 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
758 # case "$POSTPROCESSFORMAT" in
760 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
762 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
764 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
766 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
768 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
771 # # Only remove .wav if the encoding succeeded
772 # if checkerrors "preprocess-(.{3,4})-$1"; then
773 # run_command preprocess-$1 false
775 # run_command preprocess-$1 true
778 # if [ "$(checkstatus encode-output)" = "loud" ]; then
779 # echo "HEH! The file we were about to pre-process disappeared:"
782 # run_command preprocess-$1 false
787 # do_postprocess [tracknumber]
789 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
792 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
794 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
795 # # We need IN to proceed.
796 # if [ -s "$IN" ] ; then
797 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
798 # run_command '' echo "Post-processing track $1 of $TRACKS..."
799 # case "$POSTPROCESSFORMAT" in
801 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
803 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
805 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
807 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
809 # # Only remove .wav if the encoding succeeded
810 # if checkerrors "postprocess-(.{3,4})-$1"; then
811 # run_command postprocess-$1 false
813 # run_command postprocess-$1 true
816 # if [ "$(checkstatus encode-output)" = "loud" ]; then
817 # echo "HEH! The file we were about to post-process disappeared:"
820 # run_command postprocess-$1 false
827 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
830 # The commands here don't go through run_command because they're never supposed to be silenced
831 echo "Batch analizing gain in tracks: $TRACKQUEUE"
836 for UTRACKNUM
in $TRACKQUEUE
838 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
840 # XXX: Hard-coded batch option!
841 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
843 if [ "$RETURN" != "0" ]; then
844 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
846 for UTRACKNUM
in $TRACKQUEUE
848 echo normalizetrack-
$UTRACKNUM >> status
856 # NORMALIZER, NORMALIZEROPTS
857 do_batch_normalize
()
859 # The commands here don't go through run_command because they're never supposed to be silenced
860 echo "Batch normalizing tracks: $TRACKQUEUE"
865 for UTRACKNUM
in $TRACKQUEUE
867 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
869 # XXX: Hard-coded batch option!
870 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
872 if [ "$RETURN" != "0" ]; then
873 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
875 for UTRACKNUM
in $TRACKQUEUE
877 echo normalizetrack-
$UTRACKNUM >> status
883 # do_normalize [tracknumber]
885 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
888 IN
="$ABCDETEMPDIR/track$1.wav"
889 if [ -e "$IN" ] ; then
890 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
891 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
893 if [ "$(checkstatus encode-output)" = "loud" ]; then
894 echo "HEH! The file we were about to normalize disappeared:"
897 run_command normalizetrack-
$1 false
"File $IN was not found"
901 # do_move [tracknumber]
902 # Deduces the outfile from environment variables
903 # Creates directory if necessary
905 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
908 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
910 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
911 # Munge filenames as follows:
916 # Eat control characters
917 ALBUMFILE
=$
(mungefilename
"$DALBUM")
918 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
919 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
920 GENRE
=$
(mungegenre
"$GENRE")
922 # If we want to start the tracks with a given number, we need to modify the
923 # TRACKNUM value before evaluation
924 if [ -n "$STARTTRACKNUMBER" ] ; then
925 # Get the trackpadding from the current track
926 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
927 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
929 TRACKNUM
=${UTRACKNUM}
931 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
932 # TRACKFILE, and TRACKNUM.
933 if [ "$VARIOUSARTISTS" = "y" ]; then
934 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
936 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
938 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
939 OUTPUTFILEDIR
=$
(dirname "$OUTPUTDIR/$OUTPUTFILE")
940 # mkdir -p shouldn't return an error if the directory already exists
941 mkdir
-p "$OUTPUTFILEDIR"
942 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
947 # Create the playlist if wanted
949 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
950 # VARIOUSARTISTS, OUTPUTDIR
953 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
955 # Create a playlist file for the playlist data to go into.
956 # We used to wipe it out if it existed. Now we request permision if interactive.
957 for LASTTRACK
in $TRACKQUEUE; do :; done
958 ALBUMFILE
=$
(mungefilename
"$DALBUM")
959 ARTISTFILE
=$
(mungefilename
"$DARTIST")
960 GENRE
=$
(mungegenre
"$GENRE")
961 if [ "$VARIOUSARTISTS" = "y" ] ; then
962 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
964 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
966 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
967 mkdir
-p "$FINALPLAYLISTDIR"
968 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
969 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
970 if [ "$INTERACTIVE" = "y" ]; then
971 while [ "$DONE" != "y" ]; do
973 case $ERASEPLAYLIST in
974 e|E|a|A|k|K
) DONE
=y
;;
982 # Once we erase the playlist, we use append to create the new one.
983 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
985 # The playlist does not exist, so we can safelly use append to create the new list
988 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
989 touch "$OUTPUTDIR/$PLAYLISTFILE"
990 for UTRACKNUM
in $TRACKQUEUE
992 # Shares some code with do_move since the filenames have to match
993 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
994 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
996 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
997 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
998 # If we want to start the tracks with a given number, we need to modify the
999 # TRACKNUM value before evaluation
1000 if [ -n "$STARTTRACKNUMBER" ] ; then
1001 # Get the trackpadding from the current track
1002 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
1003 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1005 TRACKNUM
=${UTRACKNUM}
1007 if [ "$VARIOUSARTISTS" = "y" ]; then
1008 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1010 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1012 if [ "$VARIOUSARTISTS" = "y" ]; then
1013 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1014 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1016 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1019 if [ "$PLAYLISTDATAPREFIX" ]; then
1020 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1022 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1027 ## this will convert the playlist to have CRLF line-endings, if specified
1028 ## (some hardware players insist on CRLF endings)
1029 if [ "$DOSPLAYLIST" = "y" ]; then
1030 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1031 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1032 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1034 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1039 # This essentially the start of things
1042 # Query the CD to get the track info, unless the user specified -C
1043 # or we are using some actions which do not need the CDDB data at all
1044 #if [ ! X"$EXPACTIONS" = "X" ]; then
1046 #elif [ -z "$DISCID" ]; then
1047 if [ -z "$DISCID" ]; then
1048 vecho
-n "Getting CD track info... "
1049 TRACKINFO
=$
($CDDISCID $CDROM)
1050 # Make sure there's a CD in there by checking cd-discid's return code
1051 if [ "$?" = "1" ]; then
1052 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1057 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1060 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1061 # This needs to be done now because a section of the resuming code will need
1064 # get the number of digits to pad TRACKNUM with - we'll use this later
1065 # a CD can only hold 99 tracks, but since we support a feature for starting
1066 # numbering the tracks from a given number, we might need to set it as a
1067 # variable for the user to define... or obtain it somehow.
1068 if [ "$PADTRACKS" = "y" ] ; then
1072 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1073 if [ -z "$TRACKQUEUE" ]; then
1074 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1075 case "$CDROMREADERSYNTAX" in
1077 if [ "$WEHAVEACD" = "y" ]; then
1078 vecho
"Querying the CD for audio tracks..."
1079 CDPARANOIAOUTPUT
="$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )"
1081 if [ ! "$RET" = "0" ];then
1082 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1084 TRACKS
="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ' )"
1085 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1087 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks
; then
1088 TRACKS
=$
( cat $ABCDETEMPDIR/cdparanoia-audio-tracks
)
1090 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1094 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1097 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1099 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1100 echo "The disc does not contain any tracks. Giving up..."
1103 echo -n "Grabbing entire CD - tracks: "
1104 if [ ! "$PADTRACKS" = "y" ] ; then
1105 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1107 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1109 while [ "$X" -ne "$TRACKS" ]
1111 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1112 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
1116 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1117 # User-supplied track queue.
1118 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1119 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1120 # Once cleaned, obtain the highest value in the trackqueue for number padding
1121 for LASTTRACK
in $TRACKQUEUE; do :; done
1122 if [ ! "$PADTRACKS" = "y" ] ; then
1123 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1125 # Now we normalize the trackqueue
1126 for TRACK
in $TRACKQUEUE ; do
1127 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1128 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1130 TRACKQUEUE
=$PADTRACKQUEUE
1131 echo Grabbing tracks
: "$TRACKQUEUE"
1134 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1136 # We have the discid, create a temp directory after it to store all the temp
1139 if [ -e "$ABCDETEMPDIR" ]; then
1140 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1141 # It already exists, see if it's a directory
1142 if [ ! -d "$ABCDETEMPDIR" ]; then
1143 # This is a file/socket/fifo/device/etc, not a directory
1146 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1147 echo "Please investigate, remove it, and rerun abcde." >&2
1151 # It's a directory, let's see if it's owned by us
1152 if [ ! -O "$ABCDETEMPDIR" ]; then
1153 # Nope, complain and exit
1155 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1156 echo "Please investigate, remove it, and rerun abcde." >&2
1160 # See if it's populated
1161 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1162 # Wipe and start fresh
1163 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1164 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1165 if [ "$INTERACTIVE" = "y" ]; then
1171 if [ "$ANSWER" != "y" ]; then
1174 rm -rf "$ABCDETEMPDIR" ||
exit 1
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
1182 # Everything is fine. Check for ^encodetracklocation-
1183 # and encode-output entries in the status file and
1184 # remove them. These are not relevant across sessions.
1185 if [ -f "$ABCDETEMPDIR/status" ]; then
1186 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1187 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1188 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1190 # Remove old error messages
1191 if [ -f "$ABCDETEMPDIR/errors" ]; then
1192 rm -f "$ABCDETEMPDIR/errors"
1196 # We are starting from scratch
1197 mkdir
"$ABCDETEMPDIR"
1198 if [ "$?" -gt "0" ]; then
1199 # Directory already exists or could not be created
1200 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1203 cat /dev
/null
> "$ABCDETEMPDIR/status"
1205 if [ X
"$CUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1206 if checkstatus cuefile
; then :; else
1207 $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/cue-$
(echo $TRACKINFO | cut
-f1 -d' ').txt
1208 echo cuefile
>> "$ABCDETEMPDIR/status"
1211 # If we got the CDPARANOIA status and it is not recorded, save it now
1212 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1213 if checkstatus cdparanoia-audio-tracks
; then :; else
1214 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1215 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1220 # Create the discid file
1221 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1225 # Parses a CDDB file and outputs the title and the track names.
1226 # Variables: CDDBFILE
1230 # List out disc title/author and contents
1231 if [ "$ONETRACK" = "y" ]; then
1232 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1234 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1235 if [ ! "$ONETRACK" = "y" ]; then
1236 for TRACK
in $
(f_seq_row
1 $TRACKS)
1238 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1244 # Check for a local CDDB file, and report success
1247 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1249 CDDBLOCALSUCCESS
="n"
1250 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1251 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1254 # If the user has selected to check a local CDDB repo, we proceed with it
1255 if [ -r "${CDDBLOCALFILE}" ]; then
1256 # List out disc title/author and contents
1257 do_cddbparse
"${CDDBLOCALFILE}"
1258 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1259 if [ "$INTERACTIVE" = "y" ]; then
1261 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1262 echo -n 'Invalid selection. Please answer "y" or "n": '
1265 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1269 if [ "$USELOCALRESP" = "y" ]; then
1270 #echo "Using local copy of CDDB data"
1271 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1272 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1273 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1274 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1275 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1276 CDDBLOCALSUCCESS
="y"
1278 #echo "Not using local copy of CDDB data"
1279 CDDBLOCALSUCCESS
="n"
1281 CDDBLOCALSUCCESS
="y"
1283 CDDBLOCALSUCCESS
="n"
1291 # Perform CDDB protocol version check if it hasn't already been done
1292 if checkstatus cddb-statcomplete
; then :; else
1293 if [ "$CDDBAVAIL" = "n" ]; then
1295 echo 503 > "$ABCDETEMPDIR/cddbstat"
1298 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1299 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1300 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1301 vecho
"Checking CDDB server status..."
1302 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1303 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1304 case "$RESPONSECODE" in
1305 210) # 210 OK, status information follows (until terminating `.')
1308 501|
*) # 501 Illegal CDDB protocol level: <n>.
1309 CDDBPROTO
=`expr $CDDBPROTO - 1`
1313 if test $rc -eq 1; then
1317 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1325 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1326 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1328 # Perform CDDB query if it hasn't already been done
1329 if checkstatus cddb-querycomplete
; then :; else
1330 if [ "$CDDBAVAIL" = "n" ]; then
1332 echo 503 > "$ABCDETEMPDIR/cddbquery"
1333 # The default CDDBLOCALSUCCESS is "n"
1334 # This part will be triggered if the user CDDB repo does not
1335 # contain the entry, or if we are not trying to use the repo.
1337 vecho
"Querying the CDDB server..."
1338 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1339 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1340 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1346 # no match found in database,
1347 # wget/fetch error, or user requested not to use CDDB
1348 # Make up an error code (503) that abcde
1349 # will recognize in do_cddbread
1350 # and compensate by making a template
1351 echo 503 > "$ABCDETEMPDIR/cddbquery"
1353 *) # strange and unknown error
1354 echo ERRORCODE
=$ERRORCODE
1355 echo "abcde: $CDDBTOOL returned unknown error code"
1359 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1366 # If it's not to be used, generate a template.
1367 # Then, display it (or them) and let the user choose/edit it
1368 if checkstatus cddb-readcomplete
; then :; else
1369 vecho
"Obtaining CDDB results..."
1370 # If CDDB is to be used, interpret the query results and read all
1371 # the available entries.
1372 rm -f "$ABCDETEMPDIR/cddbchoices"
1373 CDDBCHOICES
=1 # Overridden by multiple matches
1374 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1375 case "$RESPONSECODE" in
1377 # One exact match, retrieve it
1378 # 200 [section] [discid] [artist] / [title]
1379 if checkstatus cddb-read-1-complete
; then :; else
1380 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1381 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1382 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1383 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1384 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1386 # List out disc title/author and contents
1387 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1388 for TRACK
in $
(f_seq_row
1 $TRACKS)
1390 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1392 echo >> "$ABCDETEMPDIR/cddbchoices"
1396 case "$RESPONSECODE" in
1397 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1398 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1399 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1401 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1402 # List out disc title/author and contents of template
1403 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1405 for TRACK
in $
(f_seq_row
1 $TRACKS)
1407 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1409 echo >> "$ABCDETEMPDIR/cddbchoices"
1410 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1411 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1414 # Multiple exact, (possibly multiple) inexact matches
1416 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1417 if [ "$(wc -l < $ABCDETEMPDIR/cddbquery | tr -d ' ')" -eq 3 ]; then
1418 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1419 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1420 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1422 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1424 vecho
-n "Retrieving multiple matches... "
1425 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1426 read DISCINFO
# eat top line
1430 if checkstatus cddb-read-
$X-complete; then :; else
1431 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1432 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1434 # List out disc title/author and contents
1435 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1436 for TRACK
in $
(f_seq_row
1 $TRACKS)
1438 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1440 echo >> "$ABCDETEMPDIR/cddbchoices"
1443 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1447 for TRACK
in $
(f_seq_row
1 $TRACKS)
1449 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1451 echo >> "$ABCDETEMPDIR/cddbchoices"
1452 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1453 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1456 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1463 if checkstatus cddb-edit
>/dev
/null
; then
1464 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1465 VARIOUSARTISTS
="$(checkstatus variousartists)"
1466 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1469 if [ "$INTERACTIVE" = "y" ]; then
1470 # We should show the CDDB results both when we are not using the local CDDB repo
1471 # or when we are using it but we could not find a proper match
1472 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1473 # Display the $ABCDETEMPDIR/cddbchoices file created above
1474 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1475 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1476 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1477 CHOICE
=$
(checkstatus cddb-choice
)
1478 if [ -n "$CHOICE" ] ; then
1479 case $CDDBCHOICES in
1480 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1482 echo "Selected: #$CHOICE"
1483 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1487 # The user has a choice to make, display the info in a pager if necessary
1488 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1489 # Use the debian sensible-pager wrapper to pick the pager
1490 # user has requested via their $PAGER environment variable
1491 if [ -x "/usr/bin/sensible-pager" ]; then
1492 /usr
/bin
/sensible-pager
"$ABCDETEMPDIR/cddbchoices"
1493 elif [ -x "$PAGER" ]; then
1494 # That failed, try to load the preferred editor, starting
1495 # with their PAGER variable
1496 $PAGER "$ABCDETEMPDIR/cddbchoices"
1497 # If that fails, check for less
1498 elif [ -x /usr
/bin
/less ]; then
1499 /usr
/bin
/less -f "$ABCDETEMPDIR/cddbchoices"
1500 # more should be on all UNIX systems
1501 elif [ -x /bin
/more ]; then
1502 /bin
/more "$ABCDETEMPDIR/cddbchoices"
1504 # No bananas, just cat the thing
1505 cat "$ABCDETEMPDIR/cddbchoices" >&2
1508 # It's all going to fit in one page, cat it
1509 cat "$ABCDETEMPDIR/cddbchoices" >&2
1512 # I'll take CDDB read #3 for $400, Alex
1513 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1515 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1516 # Make sure we get a valid choice
1517 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1518 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1519 echo "Invalid selection. Please choose a number between 1 and $CDDBCHOICES." >&2
1520 echo -n "Selection [0-$CDDBCHOICES]: " >&2
1522 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1524 if [ "$CDCHOICENUM" = "0" ]; then
1525 vecho
"Creating empty CDDB template..."
1527 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > $ABCDETEMPDIR/cddbread
.0
1529 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1530 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1532 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1536 # We need some code to show the selected option when local repository is selected and we have found a match
1537 vecho
"Using cached CDDB match..." >&2
1538 # Display the $ABCDETEMPDIR/cddbchoices file created above
1539 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1540 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1541 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1542 CHOICE
=$
(checkstatus cddb-choice
)
1543 if [ "$USELOCALRESP" = "y" ]; then :; else
1544 if [ -n "$CHOICE" ] ; then
1545 case $CDDBCHOICES in
1548 echo "Selected template."
1550 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1552 echo "Selected: #$CHOICE"
1553 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1561 # We're noninteractive - pick the first choice.
1562 # But in case we run a previous instance and selected a choice, use it.
1563 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1564 # Show the choice if we are not using the locally stored one
1565 # or when the local search failed to find a match.
1566 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1567 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1568 #if [ "$PREVIOUSCHOICE" ]; then
1569 cat "$ABCDETEMPDIR/cddbchoices"
1572 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1573 CDCHOICENUM
=$PREVIOUSCHOICE
1576 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1578 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1583 if checkstatus cddb-choice
>/dev
/null
; then :; else
1584 echo "abcde: internal error: cddb-choice not recorded." >&2
1587 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1588 echo -n "Edit selected CDDB data? [y/n] (" >&2
1589 if [ "$INTERACTIVE" = "y" ]; then
1590 if [ "$UNKNOWNDISK" = "y" ]; then
1593 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1602 if [ "$EDITCDDB" = "y" ]; then
1603 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1605 # Use the debian sensible-editor wrapper to pick the editor that the
1606 # user has requested via their $EDITOR environment variable
1607 if [ -x "/usr/bin/sensible-editor" ]; then
1608 /usr
/bin
/sensible-editor
"$CDDBDATA"
1609 elif [ -n "$EDITOR" ]; then
1610 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1611 # That failed, try to load the preferred editor, starting
1612 # with their EDITOR variable
1613 eval $
(echo "$EDITOR") "$CDDBDATA"
1615 # If that fails, check for a vi
1616 elif which vi
>/dev
/null
2>&1; then
1618 elif [ -x /usr
/bin
/vi
]; then
1619 /usr
/bin
/vi
"$CDDBDATA"
1620 # nano should be on all (modern, i.e., sarge) debian systems
1621 elif which nano
>/dev
/null
2>&1 ; then
1623 elif [ -x /usr
/bin
/nano
]; then
1624 /usr
/bin
/nano
"$CDDBDATA"
1625 # mg should be on all OpenBSD systems
1626 elif which mg
>/dev
/null
2>&1 ; then
1628 elif [ -x /usr
/bin
/mg
]; then
1629 /usr
/bin
/mg
"$CDDBDATA"
1632 echo "No editor available. Check your EDITOR environment variable." >&2
1634 # delete editor backup file if it exists
1635 if [ -w "$CDDBDATA~" ]; then
1640 # Some heuristics first. Look at Disc Title, and if it starts with
1641 # "Various", then we'll assume Various Artists
1642 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1643 echo "Looks like a Multi-Artist CD" >&2
1646 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1647 if [ "$INTERACTIVE" = "y" ]; then
1654 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1657 # Need NUMTRACKS before cddb-tool will return it:
1658 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1659 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1660 # More than 1/2 tracks contain a "/", so guess forward
1662 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1663 # More than 1/2 contain a "-", so guess forward-dash
1665 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1666 # More than 1/2 contain something in parens, so guess trailing-paren
1670 echo "1) Artist / Title" >&2
1671 echo "2) Artist - Title" >&2
1672 echo "3) Title / Artist" >&2
1673 echo "4) Title - Artist" >&2
1674 echo "5) Artist: Title" >&2
1675 echo "6) Title (Artist)" >&2
1676 echo "7) This is a single-artist CD" >&2
1677 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1678 if [ "$INTERACTIVE" = "y" ]; then
1679 read VARIOUSARTISTSTYLE
1681 echo $DEFAULTSTYLE >&2
1682 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1684 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1685 # If they press Enter, then the default style (0) was chosen
1686 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1687 echo "Invalid selection. Please choose a number between 1 and 7."
1688 echo -n "Selection [1-7]: "
1689 read VARIOUSARTISTSTYLE
1690 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1692 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1693 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1695 vecho
"Selected: $VARIOUSARTISTSTYLE"
1696 case "$VARIOUSARTISTSTYLE" in
1698 VARIOUSARTISTSTYLE
=forward
1701 VARIOUSARTISTSTYLE
=forward-dash
1704 VARIOUSARTISTSTYLE
=reverse
1707 VARIOUSARTISTSTYLE
=reverse-dash
1710 VARIOUSARTISTSTYLE
=colon
1713 VARIOUSARTISTSTYLE
=trailing-paren
1721 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1722 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1724 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1725 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1726 # This works but does not have the necessary error checking
1727 # yet. If you are familiar with the CDDB spec
1728 # (see http://www.freedb.org/src/latest/DBFORMAT)
1729 # and can create an error-free entry on your own, then put
1730 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1731 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1732 # your abcde.conf to change the email address submissions are
1735 # submit the modified file, if they want
1736 if [ "$NOSUBMIT" != "y" ]; then
1737 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1739 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1740 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1742 echo -n 'Invalid selection. Please answer "y" or "n": '
1745 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1746 echo -n "Sending..."
1747 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1753 # Make sure the cache directory exists
1754 mkdir
-p $CDDBLOCALDIR
1755 # Cache edited CDDB entry in the user's cddb dir
1756 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1757 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1760 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1763 # do_cdread [tracknumber]
1764 # do_cdread onetrack [firsttrack] [lasttrack]
1768 # The commands here don't go through run_command because they're never supposed to be silenced
1769 # return codes need to be doublechecked anyway, however
1770 if [ "$1" = "onetrack" ]; then
1771 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1772 # FIXME # Until then, we grab the whole CD in one track, no matter what
1774 # We need the first and last track for cdda2wav
1777 case "$CDROMREADERSYNTAX" in
1778 cdparanoia
) UTRACKNUM
="1-" ;;
1779 cdda2wav
) UTRACKNUM
="1+$LASTRACK" ;;
1780 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1786 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1787 if [ "$USEPIPES" = "y" ]; then
1788 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1791 PIPE_MESSAGE
="and encoding "
1793 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1794 case "$CDROMREADERSYNTAX" in
1795 ## FIXME ## Find the case for dagrab, to avoid exceptions
1797 FILEARG
="-f $WAVDATA"
1805 if [ -r "$CDDBDATA" ]; then
1806 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1807 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1809 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1811 case "$CDROMREADERSYNTAX" in
1812 cdparanoia
) nice
$READNICE $CDROMREADER -d $CDROM $UTRACKNUM $FILEARG $REDIR ;;
1814 if [ "$OSFLAVOUR" = "OSX" ] ; then
1815 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1816 disktool
-u ${CDROM#/dev/} 0
1817 # Also, in OSX the cdrom device for cdda2wav changes...
1818 CDDA2WAVCDROM
="IODVDServices"
1819 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1820 CDDA2WAVCDROM
="$CDROMID"
1822 if [ "$CDROMID" = "" ]; then
1823 CDDA2WAVCDROM
="$CDROM"
1825 CDDA2WAVCDROM
="$CDROMID"
1828 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM $FILEARG $REDIR
1830 ## FIXME ## We have an exception for dagrab, since it uses -f
1831 ## FIXME ## Shall we just use -f $FILEARG ??
1832 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM $FILEARG $REDIR
1835 # Find the track's mounted path
1836 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1837 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1838 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
1839 # If the file exists, copy it
1840 if [ -e "$FILEPATH" ] ; then
1841 nice
$READNICE $CDROMREADER "$FILEPATH" $FILEARG $REDIR
1845 debug
) nice
$READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] $FILEARG $REDIR
1849 # If we get some error or we get some missing wav
1850 # (as long as we dont use pipes)
1851 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
1852 # Thank goodness errors is only machine-parseable up to the
1853 # first colon, otherwise this woulda sucked
1854 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1855 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
1857 if [ "$USEPIPES" = "y" ]; then
1858 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1860 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1864 if [ "$USEPIPES" = "y" ]; then
1865 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1867 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1873 # No values accepted, only uses env variables
1876 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
1877 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
1879 echo "abcde: unable to set the device speed" >&2
1885 # vecho outputs a message if EXTRAVERBOSE is selected
1888 if [ x
"$EXTRAVERBOSE" != "x" ]; then
1893 # User-redefinable functions
1894 # Custom filename munging:
1897 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
1898 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
1901 # Custom genre munging:
1904 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
1908 # Empty pre_read function, to be defined in the configuration file.
1914 ###############################################################################
1917 # Start of execution
1918 ###############################################################################
1921 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
1922 CDDBSUBMIT
=freedb-submit@freedb.org
1924 HELLOINFO
="$(whoami)@$(hostname)"
1926 CDROMREADERSYNTAX
=cdparanoia
1928 ENCODERSYNTAX
=default
1930 MP3ENCODERSYNTAX
=default
1931 OGGENCODERSYNTAX
=default
1932 FLACENCODERSYNTAX
=default
1933 SPEEXENCODERSYNTAX
=default
1934 MPPENCODERSYNTAX
=default
1935 NORMALIZERSYNTAX
=default
1937 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
1938 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
1939 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
1940 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
1941 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
1942 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
1943 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1944 PLAYLISTDATAPREFIX
=''
1945 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1946 VAPLAYLISTDATAPREFIX
=''
1954 VARIOUSARTISTSTYLE
=forward
1958 CDDBLOCALDIR
="$HOME/.cddb"
1961 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
1962 # i.e. CDROMID="1,0,0"
1965 # program paths - defaults to checking your $PATH
1971 XINGMP3ENC
=xingmp3enc
1985 CDPARANOIA
=cdparanoia
1994 VORBISCOMMENT
=vorbiscomment
1996 NORMALIZE
=normalize-audio
1998 VORBISGAIN
=vorbisgain
2001 # Options for programs called from abcde
2032 VORBISCOMMENTOPTS
="-R"
2033 METAFLACOPTS
="--no-utf8-convert"
2035 # Default to one process if -j isn't specified
2038 # List of actions to perform - by default, run to completion
2039 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2041 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2042 # Let's use these checkings to determine the OS flavour, which will be used later
2043 if [ X$
(uname
) = "XFreeBSD" ] ; then
2047 elif [ X$
(uname
) = "XDarwin" ] ; then
2050 # We should have disktool in OSX, but let's be sure...
2052 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2059 # If CDDBAVAIL is set to n, no CDDB read is done
2060 # If USEID3 is set to n, no ID3 tagging is done
2065 if [ -z "$OUTPUTDIR" ]; then
2069 if [ -z "$WAVOUTPUTDIR" ]; then
2070 WAVOUTPUTDIR
="$OUTPUTDIR"
2073 # Load system defaults
2074 if [ -r /etc
/abcde.conf
]; then
2077 # Load user preference defaults
2078 if [ -r $HOME/.abcde.conf
]; then
2082 # By this time, we need some HTTPGETOPTS already defined.
2083 # If the user has defined a non-default HTTPGET method, we should not be empty.
2085 if [ "$HTTPGETOPTS" = "" ] ; then
2087 wget
) HTTPGETOPTS
="-q -O -";;
2088 curl
) HTTPGETOPTS
="-f -s";;
2089 fetch
)HTTPGETOPTS
="-q -o -";;
2090 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2094 # If the CDROM has not been set yet, find a suitable one.
2095 # If this is a devfs system, default to /dev/cdroms/cdrom0
2096 # instead of /dev/cdrom
2097 if [ "$CDROM" = "" ] ; then
2098 if [ -e /dev
/cdroms
/cdrom0
]; then
2099 CDROM
=/dev
/cdroms
/cdrom0
2100 elif [ -e /dev
/cdrom
]; then
2102 elif [ -e /dev
/cd0c
]; then
2104 elif [ -e /dev
/acd0c
]; then
2106 elif [ -e /dev
/disk1
]; then
2111 # Parse command line options
2112 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
2113 while getopts 1a
:A
:bc:C
:d
:Dehj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
2116 a
) ACTIONS
="$OPTARG" ;;
2117 A
) EXPACTIONS
="$OPTARG";;
2119 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2120 C
) DISCID
="${OPTARG#abcde.}" ;;
2121 d
) CDROM
="$OPTARG" ;;
2123 e
) ERASEENCODEDSTATUS
=y
;;
2125 e
) ERASEENCODEDSTATUS
=y
;;
2126 # f) FORCECDDBUSELOCAL=y ;;
2128 j
) MAXPROCS
="$OPTARG" ;;
2131 L
) CDDBUSELOCAL
=y
;;
2136 o
) OUTPUTTYPE
="$OPTARG" ;;
2139 r
) REMOTEHOSTS
="$OPTARG" ;;
2141 s
) STARTTRACKNUMBER
="$OPTARG" ;;
2142 S
) CDSPEEDVALUE
="$OPTARG" ;;
2143 # t) PREPROCESSFORMATS="$OPTARG"
2145 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2146 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2147 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2149 echo "This is abcde v$VERSION."
2150 echo "Usage: abcde [options] [tracks]"
2151 echo "abcde -h for extra help"
2154 V
) EXTRAVERBOSE
="y" ;;
2156 w
) COMMENT
="$OPTARG" ;;
2157 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2158 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2160 echo "abcde error: argument of -W must be integer"
2168 shift $
(($OPTIND - 1))
2170 # Decide if we can continue.
2171 if [ "$ONETRACK" = "y" ]; then
2172 # FIXME # remove check as soon as we find out about the other readers
2173 case "$CDROMREADERSYNTAX" in
2174 dagrab|cddafs|debug
) echo "abcde error: ONETRACK reading is not suported with $CDROMREADERSYNTAX yet"
2177 if [ "$BATCH" = "y" ]; then
2178 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2181 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2182 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2183 if [ $# -gt 0 ]; then
2184 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2187 while [ $# -gt 0 ]; do
2188 # Range parsing code courtesy of Vincent Ho
2189 RSTART
=$
(echo $1 | cut
-f1 -d-)
2190 REND
=$
(echo $1 | cut
-f2 -d-)
2191 if [ "$RSTART" = "$REND" ]; then
2194 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2196 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2201 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2202 # List of experimental actions: retag,transcode
2204 # Determine what actions are to be done from $ACTIONS and set the
2205 # following environment variables for them:
2217 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2222 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2223 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2224 encode
) DOENCODE
=y
; DOREAD
=y
;;
2225 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2226 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2227 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2228 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2235 # At this point a CDROM has to be defined, so we check it exists.
2236 if [ X
"$CDROM" != "X" ] ; then
2237 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2238 if [ "$OSFLAVOUR" = "FBSD" ]; then
2239 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2240 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2241 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2244 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2245 echo "abcde error: CDROM device cannot be found." >&2
2248 # avoid processing if we are not going to hit the CDROM.
2249 elif [ X
"$DOREAD" = "Xy" ]; then
2250 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2254 # USEPIPES pre-tests, before we get into more serious stuff
2255 # Not compatible with:
2256 # - multiple outputs
2258 # - lowdisk algorithm
2260 if [ X
"$USEPIPES" = "Xy" ]; then
2261 if [ $
(echo $OUTPUTTYPE |
tr , \ |
wc -w ) -gt 1 ]; then
2262 echo "abcde error: Unix pipes not compatible with multiple outputs"
2265 if [ X
"$DONORMALIZE" = "Xy" ]; then
2266 echo "abcde error: Unix pipes not compatible with normalizer"
2267 # FIXME # Do we need to exit or shall we just disable the mode?
2270 if [ X
"$DOENCODE" = "Xn" ]; then
2271 vecho
"Disabling Unix pipes since we are not encoding!"
2274 if [ X
"$LOWDISK" = "Xy" ]; then
2275 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2280 # Decide which CDROM reader we're gonna use
2281 case "$CDROMREADERSYNTAX" in
2283 CDROMREADER
="$CDPARANOIA"
2284 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2287 CDROMREADER
="$CDDA2WAV"
2288 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2291 CDROMREADER
="$DAGRAB"
2292 CDROMREADEROPTS
="$DAGRABOPTS"
2295 CDROMREADER
="$CDDAFS"
2296 CDROMREADEROPTS
="$CDDAFSOPTS"
2300 # There's only one normalize...
2301 case "$NORMALIZERSYNTAX" in
2303 NORMALIZER
="$NORMALIZE"
2304 NORMALIZEROPTS
="$NORMALIZEOPTS"
2308 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2309 if echo $OUTPUTTYPE |
grep ":" > /dev
/null
2>&1 ; then
2312 for OUTPUT
in "$OUTPUTTYPE"
2315 ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2316 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2317 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2318 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2319 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2322 for OUTPUT
in "$OUTPUTTYPE"
2324 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2325 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2327 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2331 # 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
2333 # Getting ready for multiple output changes
2334 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2337 ogg
) [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2338 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2339 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2341 mp3
) [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2342 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2344 flac
) [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2345 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2347 spx
) [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
;;
2348 mpc
) [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
;;
2349 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2355 # decide which encoder
2356 case "$MP3ENCODERSYNTAX" in
2358 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2362 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2366 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2367 MP3ENCODER
="$BLADEENC"
2370 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2374 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2375 MP3ENCODER
="$XINGMP3ENC"
2378 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2379 MP3ENCODER
="$MP3ENC"
2382 case "$OGGENCODERSYNTAX" in
2384 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2385 OGGENCODER
="$VORBIZE"
2388 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2389 OGGENCODER
="$OGGENC"
2392 case "$FLACENCODERSYNTAX" in
2394 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2396 ## FIXME ## FLAC streams can be encapsulated on a Ogg transport layer
2397 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2402 case "$SPEEXENCODERSYNTAX" in
2404 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2405 SPEEXENCODER
="$SPEEXENC"
2408 case "$MPPENCODERSYNTAX" in
2410 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2411 MPPENCODER
="$MPPENC"
2417 if [ "$ID3TAGV" = "1" ]; then
2419 TAGGEROPTS
="$ID3OPTS"
2422 TAGGEROPTS
="$ID3V2OPTS"
2425 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2427 if [ "$ENCNICE" ]; then
2428 ENCNICE
="-n $ENCNICE"
2430 if [ "$READNICE" ]; then
2431 READNICE
="-n $READNICE"
2433 if [ "$DISTMP3NICE" ]; then
2434 DISTMP3NICE
="-n $DISTMP3NICE"
2437 # Don't check for stuff if it's not needed
2438 if [ "$REMOTEHOSTS" ]; then
2441 if [ "$DONORMALIZE" = "y" ]; then
2444 if [ "$EJECTCD" = "y" ]; then
2447 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2450 if [ "$CUEFILE" = "y" ]; then
2454 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2455 case "$CDROMREADERSYNTAX" in
2456 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2461 # Rippers with USEPIPE support
2462 # FIXME # Include here all the rippers we can figure out support pipes
2465 # Encoders with USEPIPE support
2466 # FIXME # Include here all the encoders we can figure out support pipes
2471 # Figure out if we can use pipes with the ripper/encoder combination
2473 if [ "$USEPIPES" = "y" ]; then
2474 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2477 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2479 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2481 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYTNAX" ;;
2483 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2485 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2487 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2488 echo "abcde error: no support for pipes with given ripper" >&2
2489 echo "read the USEPIPES file from the source tarball to help" >&2
2490 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2493 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2494 echo "abcde error: no support for pipes with given encoder" >&2
2495 echo "read the USEPIPES file from the source tarball to help" >&2
2496 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2502 # Make sure a buncha things exist
2503 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2504 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2505 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2506 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2507 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2508 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2509 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2511 # Cut off the command-line options we just added in
2512 X
=$
(echo $X | cut
-d' ' -f2)
2513 if [ "$(which $X)" = "" ]; then
2514 echo "abcde error: $X is not in your path." >&2
2516 elif [ ! -x $
(which $X) ]; then
2517 echo "abcde error: $X is not executable." >&2
2522 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2523 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2524 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2526 # Here it used to say:
2527 # One thousand lines in, we can start doing stuff with things
2528 # Well, right now we are at line 2157 ;)
2530 # Export needed things so they can be read in this subshell
2531 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2532 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2534 # User-definable function to set some things. Use it for
2535 # - closing the CD tray with eject -t
2536 # - set the CD speed value with eject -x
2537 vecho
-n "Executing customizable pre-read function... "
2539 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2543 do_discid
# Get ABCDETEMPDIR created and status file initialized
2545 if [ "$DOCDDB" = "y" ]; then
2546 if [ $CDDBUSELOCAL = "y" ]; then
2549 if checkstatus cddb-choice
> /dev
/null
; then
2552 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2560 eval $
($CDDBTOOL parse
"$CDDBDATA")
2563 # Before reading tracks, we set the speed of the device
2565 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2566 case "$CDROMREADERSYNTAX" in
2567 cdparanoia|debug
) : ;;
2572 # Define the first and last track, since we might need them later in several places
2573 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
2574 LASTTRACK
=$
( get_last
$TRACKQUEUE )
2576 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
2577 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2578 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
2579 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
2582 # Create playlist if needed (backgroundable) and start reading in tracks
2586 if [ ! "$ONETRACK" = "y" ]; then
2587 if [ "$DOPLAYLIST" = "y" ]; then
2588 echo Creating playlist...
>&2
2593 # For the lowdisk option, only one program is running at once so the encoder
2594 # can be unsilenced right away.
2595 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2596 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2599 if [ "$ONETRACK" = "y" ]; then
2600 TRACKS
="$FIRSTTRACK"
2601 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2602 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
2605 for UTRACKNUM
in $TRACKQUEUE
2607 if [ "$DOREAD" = "y" ]; then
2608 if [ "$USEPIPES" = "y" ]; then
2609 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2610 # Read, pipe, shut up!
2611 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
2614 if checkstatus readtrack-
$UTRACKNUM; then :; else
2615 do_cdread
$UTRACKNUM
2617 if [ "$?" != "0" ]; then
2618 # CD read failed - don't give the goahead to
2625 if [ "$BATCH" = "y" ]; then
2628 echo NEXTTRACK
# Get the encoder machine churning again
2629 if [ "$DOREAD" = "y" ]; then
2630 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2631 until checkstatus encodetrack-
$UTRACKNUM
2633 if checkerrors encodetrack-
$UTRACKNUM; then
2644 # Now that we're done the encoding can be loud again -
2645 # if we're not using SMP.
2646 if [ "$MAXPROCS" = "1" ]; then
2647 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2650 # All tracks read, start encoding.
2651 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2655 # We are now finished with the cdrom - it can be safely ejected. Note that
2656 # abcde will not have completed yet.
2657 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2658 # We check if the disk we are processing is actually the disk inside the
2659 # CD tray. If not, we do not eject the CD, since it might be so that the
2660 # user ejected it manually.
2661 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2662 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2663 # More FreeBSD bits.
2664 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2665 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2666 # but in this script EJECT is in the envionment and names the program
2669 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2670 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2671 $eject $EJECTOPTS $cd
2672 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2673 disktool
-e ${CDROM#/dev/} 0
2675 $EJECT $EJECTOPTS $CDROM
2682 ## Do we need to pre-process
2683 #if [ x"$PREPROCESS" = "x" ] ; then
2686 # for PRETRACKNUM in $TRACKQUEUE
2689 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2691 # until [ $PREPROCEED ]
2693 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2694 # # all locations are working, wait and try again later
2695 # if [ ! $PREPROCEED ]; then sleep 3; fi
2697 # ( do_preprocess $PRETRACKNUM
2705 # In batch mode, we want all tracks to be read first.
2706 if [ "$BATCH" = "y" ]; then
2707 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2708 if [ "$GOAHEAD" = "NO" ]; then break; fi
2709 for LASTTRACK
in $TRACKQUEUE; do :; done
2710 if checkstatus readtrack-
$LASTTRACK; then
2711 if [ "$DONORMALIZE" = "y" ]; then
2712 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2713 if checkerrors batch-normalize
; then exit; fi
2715 if [ "$DOENCODE" = "y" ]; then
2716 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2717 if checkerrors batch-encode
; then exit; fi
2722 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2723 if [ "$ONETRACK" = "y" ] ; then
2724 TRACKQUEUE
="$FIRSTTRACK"
2725 TRACKS
="$FIRSTTRACK"
2728 # Do the encoding, including parallelization of remote encoding
2729 # Figure out where each track is going to be encoded
2730 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2731 if [ "$MAXPROCS" != "0" ]; then
2732 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2734 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2738 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2739 for UTRACKNUM
in $TRACKQUEUE
2742 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2743 if [ "$GOAHEAD" = "NO" ]; then break; fi
2744 # find out where this track is to be encoded
2745 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2746 # Make sure we have a place to encode this, if not, exit stage right
2747 if [ -z "$ENCODELOCATIONS" ]; then
2753 for LOCATION
in $ENCODELOCATIONS
2755 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2756 # check first if a track has ever been assigned to this location
2757 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
2758 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2759 if checkerrors encodetrack-
$PREVIOUSTRACK; then
2760 for TEMPLOCATION
in $ENCODELOCATIONS
2762 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2763 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
2766 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
2771 # We're still here, this location must have been previously assigned,
2772 # and last completed without error - check if it's done with the
2773 # previous track yet
2774 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
2776 # all locations are working, wait and try again later
2777 if [ ! $PROCEED ]; then sleep 3; fi
2779 # Record the location we're about to encode the next track at
2780 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2782 # Don't proceed with the rest of the loop if we can't encode
2783 if [ "$ABORT" ]; then continue; fi
2784 # Set TRACKNUM, TRACKNAME
2785 if [ -e "$CDDBDATA" ]; then
2786 if [ "$ONETRACK" = "y" ]; then
2788 TRACKNUM
="$FIRSTTRACK"
2791 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
2793 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2794 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
2798 # You can't encode a file which needs to be normalized before finishing
2799 # You can't tag a file before it's finished encoding -
2800 # thus all of this is backgrounded together
2802 if [ "$DONORMALIZE" = "y" ]; then
2803 if checkstatus readtrack-
$UTRACKNUM; then
2804 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
2807 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2808 if checkstatus readtrack-
$UTRACKNUM; then
2809 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
2810 if [ "$DONORMALIZE" = "y" ]; then
2811 if checkstatus normalizetrack-
$UTRACKNUM; then
2812 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2815 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2819 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
2822 if [ "$DOMOVE" = "y" ]; then
2823 if checkstatus tagtrack-
$UTRACKNUM; then
2824 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
2829 # Go through it again and make sure there's no distmp3 stragglers, otherwise
2830 # we'll delete the files they're working on
2831 ## FIXME ## Check also for files which are encoded using PIPEs.
2832 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2837 for LOCATION
in $ENCODELOCATIONS
2839 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2840 # "How can he give us a status update, if he's DEAD?"
2841 if checkstatus encodetrack-
$CHECKTRACK; then
2844 # Nothing to see here please go quietly back to your homes
2845 if [ -z "$CHECKTRACK" ]; then continue; fi
2846 # You're still here? Maybe there is something...
2847 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
2850 if [ ! $PROCEED ]; then sleep 5; fi
2853 # If the above didn't catch the stragglers, this will
2855 # Check to see if run_command logged any errors
2856 if [ -f "$ABCDETEMPDIR/errors" ]; then
2857 echo "The following commands failed to run:"
2858 cat "$ABCDETEMPDIR/errors"
2862 if [ "$KEEPWAVS" = "y" ];then
2866 if [ "$DOCLEAN" = "y" ]; then
2867 # Wipe all the evidence
2868 # Gimme gimme gimme some more time!
2870 rm -rf "$ABCDETEMPDIR"
2873 echo "Finished. Not cleaning $ABCDETEMPDIR."