2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2004 Jesus Climent <jesus.climent@hispalinux.es>
4 # This code is hereby licensed for public consumption under either the
5 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software
9 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
24 #echo "-A Experimental actions (retag, transcode)"
25 echo "-b Batch mode: enable album normalization and nogap encoding"
27 echo " Specify a configuration file (overrides system and user config files)"
29 echo " Specify discid to resume from (only needed if you no longer have the cd)"
31 echo " Specify CDROM device to grab"
32 echo "-D Debugging mode (equivalent to sh -x abcde)"
33 echo "-h This help information"
34 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
35 echo "-j <#> Number of encoder processes to run at once (localhost)"
36 echo "-k Keep the wav tracks for later use"
37 echo "-l Use low disk space algorithm"
38 echo "-L Use local CDDB storage directory"
39 echo "-n No lookup. Don't query CDDB, just create and use template"
40 echo "-N Noninteractive. Never prompt for anything"
41 echo "-m Modify playlist to include CRLF endings, to comply with some players"
42 echo "-M Create a CUE file"
43 echo "-o <type1[,type2]...>"
44 echo " Output file type(s) (ogg,mp3,flac,spx,mpc). Defaults to ogg"
45 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
46 echo "-P Use UNIX pipes to read+encode without wav files"
47 echo "-r <host1[,host2]...>"
48 echo " Also encode on these remote hosts"
49 echo "-R Add replaygain values to the tag info (only for ogg,flac)"
50 echo "-S <#> Set the CD speed"
51 #echo "-t File types to preprocess (wav)"
52 #echo "-T Set postprocessing options"
53 echo "-t <#> Start the track numbering at a given number"
54 echo "-T <#> Same as -t but modifies tag numbering"
55 echo "-v Show version number and exit"
56 echo "-V Be a bit more verbose about what is happening behind the scenes"
57 echo "-x Eject CD after all tracks are read"
59 echo " Add a comment to the CD tracks"
60 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
62 echo "Tracks is a space-delimited list of tracks to grab."
63 echo "Ranges specified with hyphens are allowed."
66 # Funtions to replace the need of seq, which is too distribution dependant.
70 while [ $i -ne `expr $2 + 1` ]
80 while [ $i -ne `expr $2 + 1` ]
89 # Returns "0" if the blurb was found, returns 1 if it wasn't
90 # Puts the blurb content, if available, on stdout.
91 # Otherwise, returns "".
94 # Take the last line in the status file if there's multiple matches
96 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
98 if [ -z "$BLURB" ]; then
103 # See if there's a = in it
104 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
105 echo "$(echo $BLURB | cut -f2- -d=)"
111 # checkerrors [blurb]
112 # Returns "0" if the blurb was found (meaning there was an error),
113 # returns 1 if it wasn't (yes this is a little backwards).
114 # Does not print the blurb on stdout.
115 # Otherwise, returns "".
118 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
121 # Take the last line in the status file if there's multiple matches
123 BLURB
="$(egrep $PATTERN $ABCDETEMPDIR/errors | tail -n 1)"
125 if [ -z "$BLURB" ]; then
126 # negative, we did not have a negative...
129 # affirmative, we had a negative...
134 # run_command [blurb] [command...]
135 # Runs a command, silently if necessary, and updates the status file
140 # See if this is supposed to be silent
141 if [ "$(checkstatus encode-output)" = "loud" ]; then
145 # Special case for SMP, since
146 # encoder output is never displayed, don't mute echos
147 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
157 if [ "$RETURN" = "2" ]; then
158 # File was already normalized.
163 if [ "$RETURN" != "0" ]; then
164 # Put an error in the errors file. For various reasons we
165 # can't capture a copy of the program's output but we can
166 # log what we attempted to execute and the error code
167 # returned by the program.
168 if [ "$BLURB" ]; then
171 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
172 return $RETURN # Do not pass go, do not update the status file
174 if [ "$BLURB" ]; then
175 echo $BLURB >> "$ABCDETEMPDIR/status"
179 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
180 # distributed under the terms of the GNU GPL v2 or later, at your option
182 # Function to determine if a word contains a slash.
191 # Function to give the relative path from one file to another.
192 # Usage: relpath fromfile tofile
193 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
194 # (the result would be Album/Song.mp3)
195 # Output is relative path to $2 from $1 on stdout
197 # This code has the following restrictions:
198 # Multiple ////s are not collapsed into single /s, with strange effects.
199 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
200 # If FR is a directory it must have a trailing /
208 /*) ;; # No processing is needed for absolute paths
210 # Loop through common prefixes, ignoring them.
211 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
213 FR
="$(echo "$FR" | cut -d/ -f2-)"
214 TO
="$(echo "$TO" | cut -d/ -f2-)"
216 # Loop through directory portions left in FR, adding appropriate ../s.
219 FR
="$(echo "$FR" | cut -d/ -f2-)"
228 # This code splits the a Various Artist track name from one of the following
231 # forward: Artist / Track
232 # forward-dash: Artist - Track
233 # reverse: Track / Artist
234 # reverse-dash: Track - Artist
235 # colon: Artist: Track
236 # trailing-paren: Artist (Track)
239 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
242 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
243 case "$VARIOUSARTISTSTYLE" in
245 DTITLEARTIST
="$(echo $TRACKNAME | sed 's- / -~-g')"
246 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
247 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
250 DTITLEARTIST
="$(echo $TRACKNAME | sed 's, - ,~,g')"
251 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
252 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
255 DTITLEARTIST
="$(echo $TRACKNAME | sed 's- / -~-g')"
256 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
257 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
260 DTITLEARTIST
="$(echo $TRACKNAME | sed 's, - ,~,g')"
261 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
262 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
265 DTITLEARTIST
="$(echo $TRACKNAME | sed 's-: -~-g')"
266 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
267 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
270 DTITLEARTIST
="$(echo $TRACKNAME | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
271 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
272 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
275 elif [ "$ONETRACK" = "y" ]; then
276 TRACKARTIST
="Various"
282 # do_tag [tracknumber]
283 # id3 tags a filename
285 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
286 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
289 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
290 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
291 # If we want to start the tracks with a given number, we need to modify the
292 # TRACKNUM value before evaluation
293 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
294 # Get the trackpadding from the current track
295 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
296 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
298 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
302 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
303 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
304 run_command tagtrack-
$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
305 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
306 -g "$CDGENRE" -T "${TRACKNUM:-$1/$TRACKS}" "$ABCDETEMPDIR/track$1.$OUTPUT"
309 case "$OGGENCODERSYNTAX" in
311 # vorbiscomment can't do in-place modification, mv the file first
312 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" ]; then
313 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
316 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
317 echo ARTIST
=$TRACKARTIST
319 echo TITLE
=$TRACKNAME
320 if [ -n "$CDYEAR" ]; then
323 if [ -n "$CDGENRE" ]; then
324 echo GENRE
="$CDGENRE"
326 echo TRACKNUMBER
=${TRACKNUM:-$1}
327 echo CDDB
=$CDDBDISCID
328 if [ "$(eval echo ${COMMENT})" != "" ]; then
329 case "$COMMENTOUTPUT" in
330 *=*) echo "$COMMENTOUTPUT";;
331 *) echo COMMENT
="$COMMENTOUTPUT";;
334 ) | run_command tagtrack-
$1 $VORBISCOMMENT -w \
335 "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
336 # Doublecheck that the commented file was created successfully before wiping the original
337 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" ]; then
338 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
340 mv "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
347 echo ARTIST
="$TRACKARTIST"
349 echo TITLE
="$TRACKNAME"
350 if [ -n "$CDYEAR" ]; then
353 if [ -n "$CDGENRE" ]; then
354 echo GENRE
="$CDGENRE"
356 echo TRACKNUMBER
=${TRACKNUM:-$1}
357 echo CDDB
=$CDDBDISCID
358 if [ "$(eval echo ${COMMENT})" != "" ]; then
359 case "$COMMENTOUTPUT" in
360 *=*) echo "$COMMENTOUTPUT";;
361 *) echo COMMENT
="$COMMENTOUTPUT";;
364 ) | run_command tagtrack-
$1 $METAFLAC --import-tags-from=- --no-utf8-convert "$ABCDETEMPDIR/track$1.$OUTPUT"
367 run_command tagtrack-
$1 true
370 run_command tagtrack-
$1 true
378 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
381 # The commands here don't go through run_command because they're never supposed to be silenced
382 echo "Batch encoding tracks: $TRACKQUEUE"
383 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
386 case "$MP3ENCODERSYNTAX" in
391 for UTRACKNUM
in $TRACKQUEUE
393 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
395 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
397 if [ "$RETURN" != "0" ]; then
398 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
400 for UTRACKNUM
in $TRACKQUEUE
402 echo encodetrack-
$UTRACKNUM >> status
410 # Other encoders fall through to normal encoding as the tracks
411 # have not been entered in the status file.
414 # do_encode [tracknumber] [hostname]
415 # If no hostname is specified, encode locally
417 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
420 IN
="$ABCDETEMPDIR/track$1.wav"
421 # We need IN to proceed.
422 if [ -s "$IN" ] ; then
423 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
425 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
426 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
431 case "$MP3ENCODERSYNTAX" in
432 lame|gogo
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
433 bladeenc
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
434 l3enc|xingmp3enc
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
435 mp3enc
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
439 run_command encodetrack-
$OUTPUT-$1 nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
446 case "$OGGENCODERSYNTAX" in
447 vorbize
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
448 oggenc
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
452 run_command encodetrack-
$OUTPUT-$1 nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
459 case "$FLACENCODERSYNTAX" in
460 flac
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
466 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
467 run_command encodetrack-
$OUTPUT-$1 nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
472 if [ "$(eval echo ${COMMENT})" != "" ]; then
475 *) COMMENT
="COMMENT=$COMMENT" ;;
477 COMMENT
="--comment \"$COMMENT\""
479 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
480 if [ ! "$DOTAG" = "y" ]; then
481 run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
483 run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
487 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
489 # I tried compiling the mppenc from corecodecs.org and got some
490 # errors, so I have not tried it myself.
491 ## FIXME ## Needs some cleanup to determine if an empty tag sent
492 ## FIXME ## to the encoder ends up empty.
493 run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
497 # Only remove .wav if the encoding succeeded
498 if checkerrors
"encodetrack-(.{3,4})-$1"; then
499 run_command encodetrack-
$1 false
501 run_command encodetrack-
$1 true
502 if [ ! "$KEEPWAVS" = "y" ] ; then
507 if [ "$(checkstatus encode-output)" = "loud" ]; then
508 echo "HEH! The file we were about to encode disappeared:"
511 run_command encodetrack-
$1 false
515 # do_preprocess [tracknumber]
517 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
520 # IN="$ABCDETEMPDIR/track$1.wav"
521 # # We need IN to proceed.
522 # if [ -s "$IN" ] ; then
523 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
525 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
526 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
527 # case "$POSTPROCESSFORMAT" in
529 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
531 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
533 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
535 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
537 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
540 # # Only remove .wav if the encoding succeeded
541 # if checkerrors "preprocess-(.{3,4})-$1"; then
542 # run_command preprocess-$1 false
544 # run_command preprocess-$1 true
547 # if [ "$(checkstatus encode-output)" = "loud" ]; then
548 # echo "HEH! The file we were about to pre-process disappeared:"
551 # run_command preprocess-$1 false
556 # do_postprocess [tracknumber]
558 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
561 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
563 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
564 # # We need IN to proceed.
565 # if [ -s "$IN" ] ; then
566 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
567 # run_command '' echo "Post-processing track $1 of $TRACKS..."
568 # case "$POSTPROCESSFORMAT" in
570 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
572 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
574 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
576 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
578 # # Only remove .wav if the encoding succeeded
579 # if checkerrors "postprocess-(.{3,4})-$1"; then
580 # run_command postprocess-$1 false
582 # run_command postprocess-$1 true
585 # if [ "$(checkstatus encode-output)" = "loud" ]; then
586 # echo "HEH! The file we were about to post-process disappeared:"
589 # run_command postprocess-$1 false
596 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
599 # The commands here don't go through run_command because they're never supposed to be silenced
600 echo "Batch analizing gain in tracks: $TRACKQUEUE"
605 for UTRACKNUM
in $TRACKQUEUE
607 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
609 # XXX: Hard-coded batch option!
610 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
612 if [ "$RETURN" != "0" ]; then
613 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
615 for UTRACKNUM
in $TRACKQUEUE
617 echo normalizetrack-
$UTRACKNUM >> status
625 # NORMALIZER, NORMALIZEROPTS
626 do_batch_normalize
()
628 # The commands here don't go through run_command because they're never supposed to be silenced
629 echo "Batch normalizing tracks: $TRACKQUEUE"
634 for UTRACKNUM
in $TRACKQUEUE
636 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
638 # XXX: Hard-coded batch option!
639 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
641 if [ "$RETURN" != "0" ]; then
642 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
644 for UTRACKNUM
in $TRACKQUEUE
646 echo normalizetrack-
$UTRACKNUM >> status
652 # do_normalize [tracknumber]
654 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
657 IN
="$ABCDETEMPDIR/track$1.wav"
658 if [ -e "$IN" ] ; then
659 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
660 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
662 if [ "$(checkstatus encode-output)" = "loud" ]; then
663 echo "HEH! The file we were about to normalize disappeared:"
666 run_command normalizetrack-
$1 false
"File $IN was not found"
670 # do_move [tracknumber]
671 # Deduces the outfile from environment variables
672 # Creates directory if necessary
674 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
677 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
679 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
680 # Munge filenames as follows:
685 # Eat control characters
686 ALBUMFILE
=$
(mungefilename
"$DALBUM")
687 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
688 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
689 GENRE
=$
(mungegenre
"$GENRE")
691 # If we want to start the tracks with a given number, we need to modify the
692 # TRACKNUM value before evaluation
693 if [ -n "$STARTTRACKNUMBER" ] ; then
694 # Get the trackpadding from the current track
695 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
696 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
698 TRACKNUM
=${UTRACKNUM}
700 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
701 # TRACKFILE, and TRACKNUM.
702 if [ "$VARIOUSARTISTS" = "y" ]; then
703 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
705 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
707 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
708 OUTPUTFILEDIR
=$
(dirname "$OUTPUTDIR/$OUTPUTFILE")
709 # mkdir -p shouldn't return an error if the directory already exists
710 mkdir
-p "$OUTPUTFILEDIR"
711 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
716 # Create the playlist if wanted
718 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
719 # VARIOUSARTISTS, OUTPUTDIR
722 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
724 # Create a playlist file for the playlist data to go into.
725 # We used to wipe it out if it existed. Now we request permision if interactive.
726 for LASTTRACK
in $TRACKQUEUE; do :; done
727 ALBUMFILE
=$
(mungefilename
"$DALBUM")
728 ARTISTFILE
=$
(mungefilename
"$DARTIST")
729 GENRE
=$
(mungegenre
"$GENRE")
730 if [ "$VARIOUSARTISTS" = "y" ] ; then
731 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
733 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
735 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
736 mkdir
-p "$FINALPLAYLISTDIR"
737 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
738 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
739 if [ "$INTERACTIVE" = "y" ]; then
740 while [ "$DONE" != "y" ]; do
742 case $ERASEPLAYLIST in
743 e|E|a|A|k|K
) DONE
=y
;;
751 # Once we erase the playlist, we use append to create the new one.
752 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
754 # The playlist does not exist, so we can safelly use append to create the new list
757 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
758 touch "$OUTPUTDIR/$PLAYLISTFILE"
759 for UTRACKNUM
in $TRACKQUEUE
761 # Shares some code with do_move since the filenames have to match
762 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
763 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
765 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
766 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
767 # If we want to start the tracks with a given number, we need to modify the
768 # TRACKNUM value before evaluation
769 if [ -n "$STARTTRACKNUMBER" ] ; then
770 # Get the trackpadding from the current track
771 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
772 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
774 TRACKNUM
=${UTRACKNUM}
776 if [ "$VARIOUSARTISTS" = "y" ]; then
777 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
779 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
781 if [ "$VARIOUSARTISTS" = "y" ]; then
782 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
783 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
785 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
788 if [ "$PLAYLISTDATAPREFIX" ]; then
789 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
791 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
796 ## this will convert the playlist to have CRLF line-endings, if specified
797 ## (some hardware players insist on CRLF endings)
798 if [ "$DOSPLAYLIST" = "y" ]; then
799 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
800 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
801 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
803 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
808 # This essentially the start of things
811 # Query the CD to get the track info, unless the user specified -C
812 # or we are using some actions which do not need the CDDB data at all
813 #if [ ! X"$EXPACTIONS" = "X" ]; then
815 #elif [ -z "$DISCID" ]; then
816 if [ -z "$DISCID" ]; then
817 vecho
-n "Getting CD track info... "
818 TRACKINFO
=$
($CDDISCID $CDROM)
819 # Make sure there's a CD in there by checking cd-discid's return code
820 if [ "$?" = "1" ]; then
821 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
826 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
829 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
830 # This needs to be done now because a section of the resuming code will need
833 # get the number of digits to pad TRACKNUM with - we'll use this later
834 # a CD can only hold 99 tracks, but since we support a feature for starting
835 # numbering the tracks from a given number, we might need to set it as a
836 # variable for the user to define... or obtain it somehow.
837 if [ "$PADTRACKS" = "y" ] ; then
841 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
842 if [ -z "$TRACKQUEUE" ]; then
843 if [ ! "$STRIPDATATRACKS" = "y" ]; then
844 case "$CDROMREADERSYNTAX" in
846 if [ "$WEHAVEACD" = "y" ]; then
847 vecho
"Querying the CD for audio tracks..."
848 CDPARANOIAOUTPUT
="$( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )"
850 if [ ! "$RET" = "0" ];then
851 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
853 TRACKS
="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | awk '{print $1}' | tr -d ".
" | tr '\n' ' ' )"
854 CDPARANOIAAUDIOTRACKS
="$TRACKS"
856 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks
; then
857 TRACKS
=$
( cat $ABCDETEMPDIR/cdparanoia-audio-tracks
)
859 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
863 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
866 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
868 if echo "$TRACKS" |
grep [[:digit
:]] > /dev
/null
2>&1 ;then :;else
869 echo "The disc does not contain any tracks. Giving up..."
872 echo -n "Grabbing entire CD - tracks: "
873 if [ ! "$PADTRACKS" = "y" ] ; then
874 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
876 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
878 while [ "$X" -ne "$TRACKS" ]
880 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
881 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
885 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
886 # User-supplied track queue.
887 # Weed out non-numbers, whitespace, then sort and weed out duplicates
888 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
889 # Once cleaned, obtain the highest value in the trackqueue for number padding
890 for LASTTRACK
in $TRACKQUEUE; do :; done
891 if [ ! "$PADTRACKS" = "y" ] ; then
892 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
894 # Now we normalize the trackqueue
895 for TRACK
in $TRACKQUEUE ; do
896 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
897 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
899 TRACKQUEUE
=$PADTRACKQUEUE
900 echo Grabbing tracks
: "$TRACKQUEUE"
903 # for LASTTRACK in $TRACKQUEUE; do :; done
905 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
907 # We have the discid, create a temp directory after it to store all the temp
910 if [ -e "$ABCDETEMPDIR" ]; then
911 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
912 # It already exists, see if it's a directory
913 if [ ! -d "$ABCDETEMPDIR" ]; then
914 # This is a file/socket/fifo/device/etc, not a directory
917 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
918 echo "Please investigate, remove it, and rerun abcde." >&2
922 # It's a directory, let's see if it's owned by us
923 if [ ! -O "$ABCDETEMPDIR" ]; then
924 # Nope, complain and exit
926 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
927 echo "Please investigate, remove it, and rerun abcde." >&2
931 # See if it's populated
932 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
933 # Wipe and start fresh
934 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
935 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
936 if [ "$INTERACTIVE" = "y" ]; then
942 if [ "$ANSWER" != "y" ]; then
945 rm -rf "$ABCDETEMPDIR" ||
exit 1
946 mkdir
"$ABCDETEMPDIR"
947 if [ "$?" -gt "0" ]; then
948 # Directory already exists or could not be created
949 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
953 # Everything is fine. Check for ^encodetracklocation-
954 # and encode-output entries in the status file and
955 # remove them. These are not relevant across sessions.
956 if [ -f "$ABCDETEMPDIR/status" ]; then
957 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
958 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
959 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
961 # Remove old error messages
962 if [ -f "$ABCDETEMPDIR/errors" ]; then
963 rm -f "$ABCDETEMPDIR/errors"
967 # We are starting from scratch
968 mkdir
"$ABCDETEMPDIR"
969 if [ "$?" -gt "0" ]; then
970 # Directory already exists or could not be created
971 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
974 cat /dev
/null
> "$ABCDETEMPDIR/status"
976 if [ X
"$CUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
977 if checkstatus cuefile
; then :; else
978 $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/cue-$
(echo $TRACKINFO | cut
-f1 -d' ').txt
979 echo cuefile
>> "$ABCDETEMPDIR/status"
982 # If we got the CDPARANOIA status and it is not recorded, save it now
983 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
984 if checkstatus cdparanoia-audio-tracks
; then :; else
985 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
986 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
991 # Create the discid file
992 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
996 # Parses a CDDB file and outputs the title and the track names.
997 # Variables: CDDBFILE
1001 # List out disc title/author and contents
1002 if [ "$ONETRACK" = "y" ]; then
1003 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1005 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1006 if [ ! "$ONETRACK" = "y" ]; then
1007 for TRACK
in $
(f_seq_row
1 $TRACKS)
1009 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1015 # Check for a local CDDB file, and report success
1018 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1020 CDDBLOCALSUCCESS
="n"
1021 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1022 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1025 # If the user has selected to check a local CDDB repo, we proceed with it
1026 if [ -r "${CDDBLOCALFILE}" ]; then
1027 # List out disc title/author and contents
1028 do_cddbparse
"${CDDBLOCALFILE}"
1029 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1030 if [ "$INTERACTIVE" = "y" ]; then
1032 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1033 echo -n 'Invalid selection. Please answer "y" or "n": '
1036 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1040 if [ "$USELOCALRESP" = "y" ]; then
1041 #echo "Using local copy of CDDB data"
1042 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1043 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1044 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1045 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1046 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1047 CDDBLOCALSUCCESS
="y"
1049 #echo "Not using local copy of CDDB data"
1050 CDDBLOCALSUCCESS
="n"
1052 CDDBLOCALSUCCESS
="y"
1054 CDDBLOCALSUCCESS
="n"
1062 # Perform CDDB protocol version check if it hasn't already been done
1063 if checkstatus cddb-statcomplete
; then :; else
1064 if [ "$CDDBAVAIL" = "n" ]; then
1066 echo 503 > "$ABCDETEMPDIR/cddbstat"
1069 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1070 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1071 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1072 vecho
"Checking CDDB server status..."
1073 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1074 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1075 case "$RESPONSECODE" in
1076 210) # 210 OK, status information follows (until terminating `.')
1079 501|
*) # 501 Illegal CDDB protocol level: <n>.
1080 CDDBPROTO
=`expr $CDDBPROTO - 1`
1084 if test $rc -eq 1; then
1088 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1096 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1097 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1099 # Perform CDDB query if it hasn't already been done
1100 if checkstatus cddb-querycomplete
; then :; else
1101 if [ "$CDDBAVAIL" = "n" ]; then
1103 echo 503 > "$ABCDETEMPDIR/cddbquery"
1104 # The default CDDBLOCALSUCCESS is "n"
1105 # This part will be triggered if the user CDDB repo does not
1106 # contain the entry, or if we are not trying to use the repo.
1108 vecho
"Querying the CDDB server..."
1109 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1110 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1111 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1117 # no match found in database,
1118 # wget/fetch error, or user requested not to use CDDB
1119 # Make up an error code (503) that abcde
1120 # will recognize in do_cddbread
1121 # and compensate by making a template
1122 echo 503 > "$ABCDETEMPDIR/cddbquery"
1124 *) # strange and unknown error
1125 echo ERRORCODE
=$ERRORCODE
1126 echo "abcde: $CDDBTOOL returned unknown error code"
1130 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1137 # If it's not to be used, generate a template.
1138 # Then, display it (or them) and let the user choose/edit it
1139 if checkstatus cddb-readcomplete
; then :; else
1140 vecho
"Obtaining CDDB results..."
1141 # If CDDB is to be used, interpret the query results and read all
1142 # the available entries.
1143 rm -f "$ABCDETEMPDIR/cddbchoices"
1144 CDDBCHOICES
=1 # Overridden by multiple matches
1145 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1146 case "$RESPONSECODE" in
1148 # One exact match, retrieve it
1149 # 200 [section] [discid] [artist] / [title]
1150 if checkstatus cddb-read-1-complete
; then :; else
1151 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1152 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1153 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1154 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1155 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1157 # List out disc title/author and contents
1158 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1159 for TRACK
in $
(f_seq_row
1 $TRACKS)
1161 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1163 echo >> "$ABCDETEMPDIR/cddbchoices"
1167 case "$RESPONSECODE" in
1168 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1169 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1170 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1172 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1173 # List out disc title/author and contents of template
1174 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1176 for TRACK
in $
(f_seq_row
1 $TRACKS)
1178 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1180 echo >> "$ABCDETEMPDIR/cddbchoices"
1181 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1182 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1185 # Multiple exact, (possibly multiple) inexact matches
1187 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1188 if [ "$(wc -l < $ABCDETEMPDIR/cddbquery | tr -d ' ')" -eq 3 ]; then
1189 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1190 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1191 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1193 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1195 vecho
-n "Retrieving multiple matches... "
1196 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1197 read DISCINFO
# eat top line
1201 if checkstatus cddb-read-
$X-complete; then :; else
1202 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1203 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1205 # List out disc title/author and contents
1206 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1207 for TRACK
in $
(f_seq_row
1 $TRACKS)
1209 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1211 echo >> "$ABCDETEMPDIR/cddbchoices"
1214 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1218 for TRACK
in $
(f_seq_row
1 $TRACKS)
1220 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1222 echo >> "$ABCDETEMPDIR/cddbchoices"
1223 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1224 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1227 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1234 if checkstatus cddb-edit
>/dev
/null
; then
1235 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1236 VARIOUSARTISTS
="$(checkstatus variousartists)"
1237 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1240 if [ "$INTERACTIVE" = "y" ]; then
1241 # We should show the CDDB results both when we are not using the local CDDB repo
1242 # or when we are using it but we could not find a proper match
1243 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1244 # Display the $ABCDETEMPDIR/cddbchoices file created above
1245 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1246 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1247 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1248 CHOICE
=$
(checkstatus cddb-choice
)
1249 if [ -n "$CHOICE" ] ; then
1250 case $CDDBCHOICES in
1251 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1253 echo "Selected: #$CHOICE"
1254 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1258 # The user has a choice to make, display the info in a pager if necessary
1259 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1260 # Use the debian sensible-pager wrapper to pick the pager
1261 # user has requested via their $PAGER environment variable
1262 if [ -x "/usr/bin/sensible-pager" ]; then
1263 /usr
/bin
/sensible-pager
"$ABCDETEMPDIR/cddbchoices"
1264 elif [ -x "$PAGER" ]; then
1265 # That failed, try to load the preferred editor, starting
1266 # with their PAGER variable
1267 $PAGER "$ABCDETEMPDIR/cddbchoices"
1268 # If that fails, check for less
1269 elif [ -x /usr
/bin
/less ]; then
1270 /usr
/bin
/less -f "$ABCDETEMPDIR/cddbchoices"
1271 # more should be on all UNIX systems
1272 elif [ -x /bin
/more ]; then
1273 /bin
/more "$ABCDETEMPDIR/cddbchoices"
1275 # No bananas, just cat the thing
1276 cat "$ABCDETEMPDIR/cddbchoices" >&2
1279 # It's all going to fit in one page, cat it
1280 cat "$ABCDETEMPDIR/cddbchoices" >&2
1283 # I'll take CDDB read #3 for $400, Alex
1284 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1286 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1287 # Make sure we get a valid choice
1288 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1289 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1290 echo "Invalid selection. Please choose a number between 1 and $CDDBCHOICES." >&2
1291 echo -n "Selection [0-$CDDBCHOICES]: " >&2
1293 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1295 if [ "$CDCHOICENUM" = "0" ]; then
1296 vecho
"Creating empty CDDB template..."
1298 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > $ABCDETEMPDIR/cddbread
.0
1300 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1301 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1303 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1307 # We need some code to show the selected option when local repository is selected and we have found a match
1308 vecho
"Using cached CDDB match..." >&2
1309 # Display the $ABCDETEMPDIR/cddbchoices file created above
1310 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1311 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1312 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1313 CHOICE
=$
(checkstatus cddb-choice
)
1314 if [ "$USELOCALRESP" = "y" ]; then :; else
1315 if [ -n "$CHOICE" ] ; then
1316 case $CDDBCHOICES in
1319 echo "Selected template."
1321 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1323 echo "Selected: #$CHOICE"
1324 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1332 # We're noninteractive - pick the first choice.
1333 # But in case we run a previous instance and selected a choice, use it.
1334 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1335 # Show the choice if we are not using the locally stored one
1336 # or when the local search failed to find a match.
1337 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1338 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1339 #if [ "$PREVIOUSCHOICE" ]; then
1340 cat "$ABCDETEMPDIR/cddbchoices"
1343 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1344 CDCHOICENUM
=$PREVIOUSCHOICE
1347 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1349 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1354 if checkstatus cddb-choice
>/dev
/null
; then :; else
1355 echo "abcde: internal error: cddb-choice not recorded." >&2
1358 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1359 echo -n "Edit selected CDDB data? [y/n] (" >&2
1360 if [ "$INTERACTIVE" = "y" ]; then
1361 if [ "$UNKNOWNDISK" = "y" ]; then
1364 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1373 if [ "$EDITCDDB" = "y" ]; then
1374 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1376 # Use the debian sensible-editor wrapper to pick the editor that the
1377 # user has requested via their $EDITOR environment variable
1378 if [ -x "/usr/bin/sensible-editor" ]; then
1379 /usr
/bin
/sensible-editor
"$CDDBDATA"
1380 elif [ -n "$EDITOR" ]; then
1381 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1382 # That failed, try to load the preferred editor, starting
1383 # with their EDITOR variable
1384 eval $
(echo "$EDITOR") "$CDDBDATA"
1386 # If that fails, check for a vi
1387 elif [ -x /usr
/bin
/vi
]; then
1388 /usr
/bin
/vi
"$CDDBDATA"
1389 # nano should be on all (modern, i.e., sarge) debian systems
1390 elif [ -x /usr
/bin
/nano
]; then
1391 /usr
/bin
/nano
"$CDDBDATA"
1392 # mg should be on all OpenBSD systems
1393 elif [ -x /usr
/bin
/mg
]; then
1394 /usr
/bin
/mg
"$CDDBDATA"
1397 echo "No editor available. Check your EDITOR environment variable." >&2
1399 # delete editor backup file if it exists
1400 if [ -w "$CDDBDATA~" ]; then
1405 # Some heuristics first. Look at Disc Title, and if it starts with
1406 # "Various", then we'll assume Various Artists
1407 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2 -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1408 echo "Looks like a Multi-Artist CD" >&2
1411 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1412 if [ "$INTERACTIVE" = "y" ]; then
1419 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1422 # Need NUMTRACKS before cddb-tool will return it:
1423 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1424 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1425 # More than 1/2 tracks contain a "/", so guess forward
1427 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1428 # More than 1/2 contain a "-", so guess forward-dash
1430 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1431 # More than 1/2 contain something in parens, so guess trailing-paren
1435 echo "1) Artist / Title" >&2
1436 echo "2) Artist - Title" >&2
1437 echo "3) Title / Artist" >&2
1438 echo "4) Title - Artist" >&2
1439 echo "5) Artist: Title" >&2
1440 echo "6) Title (Artist)" >&2
1441 echo "7) This is a single-artist CD" >&2
1442 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1443 if [ "$INTERACTIVE" = "y" ]; then
1444 read VARIOUSARTISTSTYLE
1446 echo $DEFAULTSTYLE >&2
1447 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1449 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1450 # If they press Enter, then the default style (0) was chosen
1451 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1452 echo "Invalid selection. Please choose a number between 1 and 7."
1453 echo -n "Selection [1-7]: "
1454 read VARIOUSARTISTSTYLE
1455 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1457 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1458 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1460 vecho
"Selected: $VARIOUSARTISTSTYLE"
1461 case "$VARIOUSARTISTSTYLE" in
1463 VARIOUSARTISTSTYLE
=forward
1466 VARIOUSARTISTSTYLE
=forward-dash
1469 VARIOUSARTISTSTYLE
=reverse
1472 VARIOUSARTISTSTYLE
=reverse-dash
1475 VARIOUSARTISTSTYLE
=colon
1478 VARIOUSARTISTSTYLE
=trailing-paren
1486 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1487 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1489 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1490 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1491 # This works but does not have the necessary error checking
1492 # yet. If you are familiar with the CDDB spec
1493 # (see http://www.freedb.org/src/latest/DBFORMAT)
1494 # and can create an error-free entry on your own, then put
1495 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1496 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1497 # your abcde.conf to change the email address submissions are
1500 # submit the modified file, if they want
1501 if [ "$NOSUBMIT" != "y" ]; then
1502 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1504 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1505 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1507 echo -n 'Invalid selection. Please answer "y" or "n": '
1510 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1511 echo -n "Sending..."
1512 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1518 # Make sure the cache directory exists
1519 mkdir
-p $CDDBLOCALDIR
1520 # Cache edited CDDB entry in the user's cddb dir
1521 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1522 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1525 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1528 # do_cdread [tracknumber]
1529 # do_cdread onetrack [firsttrack] [lasttrack]
1533 # The commands here don't go through run_command because they're never supposed to be silenced
1534 # return codes need to be doublechecked anyway, however
1535 if [ "$1" = "onetrack" ]; then
1536 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1537 # FIXME # Until then, we grab the whole CD in one track, no matter what
1539 # We need the first and last track for cdda2wav
1542 case "$CDROMREADERSYNTAX" in
1543 cdparanoia
) UTRACKNUM
="1-" ;;
1544 cdda2wav
) UTRACKNUM
="1+$LASTRACK" ;;
1545 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1551 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1552 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1553 if [ -r "$CDDBDATA" ]; then
1554 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1555 echo "Grabbing track $UTRACKNUM: $TRACKNAME..." >&2
1557 echo "Grabbing track $UTRACKNUM..." >&2
1559 if [ "$USEPIPES" = "y" ]; then
1560 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1564 case "$CDROMREADERSYNTAX" in
1565 ## FIXME ## Find the case for dagrab, to avoid exceptions
1567 FILEARG
="-f $WAVDATA"
1575 case "$CDROMREADERSYNTAX" in
1576 cdparanoia
) nice
$READNICE $CDROMREADER -d $CDROM $UTRACKNUM $FILEARG $REDIR ;;
1578 if [ "$OSFLAVOUR" = "OSX" ] ; then
1579 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1580 disktool
-u ${CDROM#/dev/} 0
1581 # Also, in OSX the cdrom device for cdda2wav changes...
1582 CDDA2WAVCDROM
="IODVDServices"
1583 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1584 CDDA2WAVCDROM
="$CDROMID"
1586 if [ "$CDROMID" = "" ]; then
1587 CDDA2WAVCDROM
="$CDROM"
1589 CDDA2WAVCDROM
="$CDROMID"
1592 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM $FILEARG $REDIR
1594 ## FIXME ## We have an exception for dagrab, since it uses -f
1595 ## FIXME ## Shall we just use -f $FILEARG ??
1596 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM $FILEARG $REDIR
1599 # Find the track's mounted path
1600 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1601 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1602 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
1603 # If the file exists, copy it
1604 if [ -e "$FILEPATH" ] ; then
1605 nice
$READNICE $CDROMREADER "$FILEPATH" $FILEARG $REDIR
1609 debug
) nice
$READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] $FILEARG $REDIR
1613 # If we get some error or we get some missing wav
1614 # (as long as we dont use pipes)
1615 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
1616 # Thank goodness errors is only machine-parseable up to the
1617 # first colon, otherwise this woulda sucked
1618 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1619 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
1621 if [ "$USEPIPES" = "y" ]; then
1622 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1624 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1628 if [ "$USEPIPES" = "y" ]; then
1629 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1631 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1637 # No values accepted, only uses env variables
1640 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
1641 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
1643 echo "abcde: unable to set the device speed" >&2
1649 # vecho outputs a message if EXTRAVERBOSE is selected
1652 if [ x
"$EXTRAVERBOSE" != "x" ]; then
1657 # User-redefinable functions
1658 # Custom filename munging:
1661 echo "$@" |
sed s
,:,\
-,g |
tr \
/\
* __
+ |
tr -d \'\"\?\
[:cntrl
:\
]
1664 # Custom genre munging:
1667 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
1671 # Empty pre_read function, to be defined in the configuration file.
1677 ###############################################################################
1680 # Start of execution
1681 ###############################################################################
1684 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
1685 CDDBSUBMIT
=freedb-submit@freedb.org
1687 HELLOINFO
="$(whoami)@$(hostname)"
1689 CDROMREADERSYNTAX
=cdparanoia
1691 ENCODERSYNTAX
=default
1693 MP3ENCODERSYNTAX
=default
1694 OGGENCODERSYNTAX
=default
1695 FLACENCODERSYNTAX
=default
1696 SPEEXENCODERSYNTAX
=default
1697 MPPENCODERSYNTAX
=default
1698 NORMALIZERSYNTAX
=default
1700 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
1701 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
1702 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
1703 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
1704 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
1705 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
1706 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1707 PLAYLISTDATAPREFIX
=''
1708 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1709 VAPLAYLISTDATAPREFIX
=''
1717 VARIOUSARTISTSTYLE
=forward
1721 CDDBLOCALDIR
="$HOME/.cddb"
1724 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
1725 # i.e. CDROMID="1,0,0"
1728 # program paths - defaults to checking your $PATH
1734 XINGMP3ENC
=xingmp3enc
1748 CDPARANOIA
=cdparanoia
1757 VORBISCOMMENT
=vorbiscomment
1759 NORMALIZE
=normalize-audio
1761 VORBISGAIN
=vorbisgain
1764 # Options for programs called from abcde
1796 # Default to one process if -j isn't specified
1799 # List of actions to perform - by default, run to completion
1800 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
1802 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
1803 # Let's use these checkings to determine the OS flavour, which will be used later
1804 if [ X$
(uname
) = "XFreeBSD" ] ; then
1808 elif [ X$
(uname
) = "XDarwin" ] ; then
1811 # We should have disktool in OSX, but let's be sure...
1813 elif [ X$
(uname
) = "XOpenBSD" ] ; then
1820 # If CDDBAVAIL is set to n, no CDDB read is done
1821 # If USEID3 is set to n, no ID3 tagging is done
1826 if [ -z "$OUTPUTDIR" ]; then
1830 if [ -z "$WAVOUTPUTDIR" ]; then
1831 WAVOUTPUTDIR
="$OUTPUTDIR"
1834 # Load system defaults
1835 if [ -r /etc
/abcde.conf
]; then
1838 # Load user preference defaults
1839 if [ -r $HOME/.abcde.conf
]; then
1843 # By this time, we need some HTTPGETOPTS already defined.
1844 # If the user has defined a non-default HTTPGET method, we should not be empty.
1846 if [ "$HTTPGETOPTS" = "" ] ; then
1848 wget
) HTTPGETOPTS
="-q -O -";;
1849 curl
) HTTPGETOPTS
="-f -s";;
1850 fetch
)HTTPGETOPTS
="-q -o -";;
1851 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
1855 # If the CDROM has not been set yet, find a suitable one.
1856 # If this is a devfs system, default to /dev/cdroms/cdrom0
1857 # instead of /dev/cdrom
1858 if [ "$CDROM" = "" ] ; then
1859 if [ -e /dev
/cdroms
/cdrom0
]; then
1860 CDROM
=/dev
/cdroms
/cdrom0
1861 elif [ -e /dev
/cdrom
]; then
1863 elif [ -e /dev
/cd0c
]; then
1865 elif [ -e /dev
/acd0c
]; then
1867 elif [ -e /dev
/disk1
]; then
1872 # Parse command line options
1873 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
1874 while getopts 1a
:A
:bc:C
:d
:Dhj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
1877 a
) ACTIONS
="$OPTARG" ;;
1878 A
) EXPACTIONS
="$OPTARG";;
1880 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
1881 C
) DISCID
="${OPTARG#abcde.}" ;;
1882 d
) CDROM
="$OPTARG" ;;
1885 # f) FORCECDDBUSELOCAL=y ;;
1887 j
) MAXPROCS
="$OPTARG" ;;
1890 L
) CDDBUSELOCAL
=y
;;
1895 o
) OUTPUTTYPE
="$OPTARG" ;;
1898 r
) REMOTEHOSTS
="$OPTARG" ;;
1900 s
) STARTTRACKNUMBER
="$OPTARG" ;;
1901 S
) CDSPEEDVALUE
="$OPTARG" ;;
1902 # t) PREPROCESSFORMATS="$OPTARG"
1904 # T) POSTPROCESSFORMATS="$OPTARG" ;;
1905 t
) STARTTRACKNUMBER
="$OPTARG" ;;
1906 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
1908 echo "This is abcde v$VERSION."
1909 echo "Usage: abcde [options] [tracks]"
1910 echo "abcde -h for extra help"
1913 V
) EXTRAVERBOSE
="y" ;;
1915 w
) COMMENT
="$OPTARG" ;;
1916 W
) STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}" ;;
1921 shift $
(($OPTIND - 1))
1923 # Decide if we can continue.
1924 if [ "$ONETRACK" = "y" ]; then
1925 # FIXME # remove check as soon as we find out about the other readers
1926 case "$CDROMREADERSYNTAX" in
1927 dagrab|cddafs|debug
) echo "abcde error: ONETRACK reading is not suported with "$CDROMREADERSYNTAX" yet"
1930 if [ "$BATCH" = "y" ]; then
1931 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
1934 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
1935 # FIXME # allow ranges of tracks to be selected for onetrack ripping
1936 if [ $# -gt 0 ]; then
1937 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
1940 while [ $# -gt 0 ]; do
1941 # Range parsing code courtesy of Vincent Ho
1942 RSTART
=$
(echo $1 | cut
-f1 -d-)
1943 REND
=$
(echo $1 | cut
-f2 -d-)
1944 if [ "$RSTART" = "$REND" ]; then
1947 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
1949 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
1954 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
1955 # List of experimental actions: retag,transcode
1957 # Determine what actions are to be done from $ACTIONS and set the
1958 # following environment variables for them:
1970 for ACTION
in $
(echo $ACTIONS |
tr , \
)
1975 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
1976 # preprocess) DOPREPROCESS=y; DOREAD=y;;
1977 encode
) DOENCODE
=y
; DOREAD
=y
;;
1978 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
1979 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
1980 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
1981 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
1988 # At this point a CDROM has to be defined, so we check it exists.
1989 if [ X
"$CDROM" != "X" ] ; then
1990 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
1991 if [ "$OSFLAVOUR" = "FBSD" ]; then
1992 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
1993 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
1994 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
1998 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "y" ]; then
1999 echo "abcde error: CDROM device cannot be found." >&2
2002 # avoid processing if we are not going to hit the CDROM.
2003 elif [ X
"$DOREAD" = "y" ]; then
2004 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2008 # USEPIPES pre-tests, before we get into more serious stuff
2009 # Not compatible with:
2010 # - multiple outputs
2012 # - lowdisk algorithm
2014 if [ X
"$USEPIPES" = "Xy" ]; then
2015 if [ $
(echo $OUTPUTTYPE |
tr , \ |
wc -w ) -gt 1 ]; then
2016 echo "abcde error: Unix pipes not compatible with multiple outputs"
2019 if [ X
"$DONORMALIZE" = "Xy" ]; then
2020 echo "abcde error: Unix pipes not compatible with normalizer"
2021 # FIXME # Do we need to exit or shall we just disable the mode?
2024 if [ X
"$DOENCODE" = "Xn" ]; then
2025 vecho
"Disabling Unix pipes since we are not encoding!"
2028 if [ X
"$LOWDISK" = "Xy" ]; then
2029 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2034 # Decide which CDROM reader we're gonna use
2035 case "$CDROMREADERSYNTAX" in
2037 CDROMREADER
="$CDPARANOIA"
2038 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2041 CDROMREADER
="$CDDA2WAV"
2042 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2045 CDROMREADER
="$DAGRAB"
2046 CDROMREADEROPTS
="$DAGRABOPTS"
2049 CDROMREADER
="$CDDAFS"
2050 CDROMREADEROPTS
="$CDDAFSOPTS"
2054 # There's only one normalize...
2055 case "$NORMALIZERSYNTAX" in
2057 NORMALIZER
="$NORMALIZE"
2058 NORMALIZEROPTS
="$NORMALIZEOPTS"
2062 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2063 if echo $OUTPUTTYPE |
grep ":" > /dev
/null
2>&1 ; then
2066 for OUTPUT
in "$OUTPUTTYPE"
2069 ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2070 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2071 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2072 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2073 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2076 for OUTPUT
in "$OUTPUTTYPE"
2078 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2079 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2081 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2085 # 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
2087 # Getting ready for multiple output changes
2088 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2091 ogg
) [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2092 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2093 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2095 mp3
) [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2096 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2098 flac
) [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2099 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2101 spx
) [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
;;
2102 mpc
) [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
;;
2103 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2109 # decide which encoder
2110 case "$MP3ENCODERSYNTAX" in
2112 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2116 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2120 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2121 MP3ENCODER
="$BLADEENC"
2124 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2128 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2129 MP3ENCODER
="$XINGMP3ENC"
2132 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2133 MP3ENCODER
="$MP3ENC"
2136 case "$OGGENCODERSYNTAX" in
2138 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2139 OGGENCODER
="$VORBIZE"
2142 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2143 OGGENCODER
="$OGGENC"
2146 case "$FLACENCODERSYNTAX" in
2148 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2152 case "$SPEEXENCODERSYNTAX" in
2154 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2155 SPEEXENCODER
="$SPEEXENC"
2158 case "$MPPENCODERSYNTAX" in
2160 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2161 MPPENCODER
="$MPPENC"
2167 if [ "$ID3TAGV" = "1" ]; then
2169 TAGGEROPTS
="$ID3OPTS"
2172 TAGGEROPTS
="$ID3V2OPTS"
2175 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2177 if [ "$ENCNICE" ]; then
2178 ENCNICE
="-n $ENCNICE"
2180 if [ "$READNICE" ]; then
2181 READNICE
="-n $READNICE"
2183 if [ "$DISTMP3NICE" ]; then
2184 DISTMP3NICE
="-n $DISTMP3NICE"
2187 # Don't check for stuff if it's not needed
2188 if [ "$REMOTEHOSTS" ]; then NEEDDISTMP3
=y
; fi
2189 [ "$DONORMALIZE" = "y" ] && NEEDNORMALIZER
=y
2190 [ "$EJECTCD" = "y" ] && NEEDEJECT
=y
2191 [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ] && NEEDHTTPGET
=y
2192 [ "$CUEFILE" = "y" ] && NEEDMKCUE
=y
2194 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2195 case "$CDROMREADERSYNTAX" in
2196 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2201 # Rippers with USEPIPE support
2202 # FIXME # Include here all the rippers we can figure out support pipes
2205 # Encoders with USEPIPE support
2206 # FIXME # Include here all the encoders we can figure out support pipes
2210 # Figure out if we can use pipes with the ripper/encoder combination
2212 if [ "$USEPIPES" = "y" ]; then
2213 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2216 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2218 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2220 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYTNAX" ;;
2222 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2224 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2226 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2227 echo "abcde error: no support for pipes with given ripper" >&2
2228 echo "read the USEPIPES file from the source tarball to help" >&2
2229 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2232 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2233 echo "abcde error: no support for pipes with given encoder" >&2
2234 echo "read the USEPIPES file from the source tarball to help" >&2
2235 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2241 # Make sure a buncha things exist
2242 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2243 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2244 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2245 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2246 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2247 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2248 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2250 # Cut off the command-line options we just added in
2251 X
=$
(echo $X | cut
-d' ' -f2)
2252 if [ "$(which $X)" = "" ]; then
2253 echo "abcde error: $X is not in your path." >&2
2255 elif [ ! -x $
(which $X) ]; then
2256 echo "abcde error: $X is not executable." >&2
2261 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2262 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2263 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2265 # Here it used to say:
2266 # One thousand lines in, we can start doing stuff with things
2267 # Well, right now we are at line 2157 ;)
2269 # Export needed things so they can be read in this subshell
2270 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2271 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2273 # User-definable function to set some things. Use it for
2274 # - closing the CD tray with eject -t
2275 # - set the CD speed value with eject -x
2276 vecho
-n "Executing customizable pre-read function... "
2278 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2282 do_discid
# Get ABCDETEMPDIR created and status file initialized
2284 if [ "$DOCDDB" = "y" ]; then
2285 if [ $CDDBUSELOCAL = "y" ]; then
2288 if checkstatus cddb-choice
> /dev
/null
; then
2291 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2299 eval $
($CDDBTOOL parse
"$CDDBDATA")
2302 # Before reading tracks, we set the speed of the device
2304 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2305 case "$CDROMREADERSYNTAX" in
2306 cdparanoia|debug
) : ;;
2311 # Create playlist if needed (backgroundable) and start reading in tracks
2315 if [ ! "$ONETRACK" = "y" ]; then
2316 if [ "$DOPLAYLIST" = "y" ]; then
2317 echo Creating playlist...
>&2
2322 # For the lowdisk option, only one program is running at once so the encoder
2323 # can be unsilenced right away.
2324 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2325 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2328 if [ "$ONETRACK" = "y" ]; then
2329 FIRSTTRACK
=$
( echo $TRACKQUEUE |
awk '{print $1}' )
2330 TRACKS
="$FIRSTTRACK"
2331 for UTRACKNUM
in $TRACKQUEUE; do :;done
2332 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2333 do_cdread onetrack
$FIRSTTRACK $UTRACKNUM
2336 for UTRACKNUM
in $TRACKQUEUE
2338 if [ "$DOREAD" = "y" ]; then
2339 if [ "$USEPIPES" = "y" ]; then
2340 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2341 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
%
2344 if checkstatus readtrack-
$UTRACKNUM; then :; else
2345 do_cdread
$UTRACKNUM
2347 if [ "$?" != "0" ]; then
2348 # CD read failed - don't give the goahead to
2355 if [ "$BATCH" = "y" ]; then
2358 echo NEXTTRACK
# Get the encoder machine churning again
2359 if [ "$DOREAD" = "y" ]; then
2360 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2361 until checkstatus encodetrack-
$UTRACKNUM
2363 if checkerrors encodetrack-
$UTRACKNUM; then
2374 # Now that we're done the encoding can be loud again -
2375 # if we're not using SMP.
2376 if [ "$MAXPROCS" = "1" ]; then
2377 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2380 # All tracks read, start encoding.
2381 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2385 # We are now finished with the cdrom - it can be safely ejected. Note that
2386 # abcde will not have completed yet.
2387 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2388 # We check if the disk we are processing is actually the disk inside the
2389 # CD tray. If not, we do not eject the CD, since it might be so that the
2390 # user ejected it manually.
2391 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2392 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2393 # More FreeBSD bits.
2394 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2395 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2396 # but in this script EJECT is in the envionment and names the program
2399 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2400 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2401 $eject $EJECTOPTS $cd
2402 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2403 disktool
-e ${CDROM#/dev/} 0
2405 $EJECT $EJECTOPTS $CDROM
2412 ## Do we need to pre-process
2413 #if [ x"$PREPROCESS" = "x" ] ; then
2416 # for PRETRACKNUM in $TRACKQUEUE
2419 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2421 # until [ $PREPROCEED ]
2423 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2424 # # all locations are working, wait and try again later
2425 # if [ ! $PREPROCEED ]; then sleep 3; fi
2427 # ( do_preprocess $PRETRACKNUM
2435 # In batch mode, we want all tracks to be read first.
2436 if [ "$BATCH" = "y" ]; then
2437 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2438 if [ "$GOAHEAD" = "NO" ]; then break; fi
2439 for LASTTRACK
in $TRACKQUEUE; do :; done
2440 if checkstatus readtrack-
$LASTTRACK; then
2441 if [ "$DONORMALIZE" = "y" ]; then
2442 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2443 if checkerrors batch-normalize
; then exit; fi
2445 if [ "$DOENCODE" = "y" ]; then
2446 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2447 if checkerrors batch-encode
; then exit; fi
2452 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2453 if [ "$ONETRACK" = "y" ] ; then
2454 FIRSTTRACK
=$
( echo $TRACKQUEUE |
awk '{print $1}')
2455 TRACKQUEUE
=$FIRSTTRACK
2456 TRACKS
="$FIRSTTRACK"
2459 # Do the encoding, including parallelization of remote encoding
2460 # Figure out where each track is going to be encoded
2461 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2462 if [ "$MAXPROCS" != "0" ]; then
2463 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2465 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2469 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2470 for UTRACKNUM
in $TRACKQUEUE
2473 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2474 if [ "$GOAHEAD" = "NO" ]; then break; fi
2475 # find out where this track is to be encoded
2476 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2477 # Make sure we have a place to encode this, if not, exit stage right
2478 if [ -z "$ENCODELOCATIONS" ]; then
2484 for LOCATION
in $ENCODELOCATIONS
2486 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2487 # check first if a track has ever been assigned to this location
2488 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
2489 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2490 if checkerrors encodetrack-
$PREVIOUSTRACK; then
2491 for TEMPLOCATION
in $ENCODELOCATIONS
2493 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2494 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
2497 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
2502 # We're still here, this location must have been previously assigned,
2503 # and last completed without error - check if it's done with the
2504 # previous track yet
2505 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
2507 # all locations are working, wait and try again later
2508 if [ ! $PROCEED ]; then sleep 3; fi
2510 # Record the location we're about to encode the next track at
2511 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2513 # Don't proceed with the rest of the loop if we can't encode
2514 if [ "$ABORT" ]; then continue; fi
2515 # Set TRACKNUM, TRACKNAME
2516 if [ -e "$CDDBDATA" ]; then
2517 if [ "$ONETRACK" = "y" ]; then
2519 TRACKNUM
="$FIRSTTRACK"
2522 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
2524 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2525 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
2529 # You can't encode a file which needs to be normalized before finishing
2530 # You can't tag a file before it's finished encoding -
2531 # thus all of this is backgrounded together
2533 if [ "$DONORMALIZE" = "y" ]; then
2534 if checkstatus readtrack-
$UTRACKNUM; then
2535 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
2538 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2539 if checkstatus readtrack-
$UTRACKNUM; then
2540 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
2541 if [ "$DONORMALIZE" = "y" ]; then
2542 if checkstatus normalizetrack-
$UTRACKNUM; then
2543 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2546 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2550 if [ "$DOTAG" = "y" ]; then
2551 if checkstatus encodetrack-
$UTRACKNUM; then
2552 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
2555 if [ "$DOMOVE" = "y" ]; then
2556 if checkstatus tagtrack-
$UTRACKNUM; then
2557 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
2562 # Go through it again and make sure there's no distmp3 stragglers, otherwise
2563 # we'll delete the files they're working on
2564 ## FIXME ## Check also for files which are encoded using PIPEs.
2565 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2570 for LOCATION
in $ENCODELOCATIONS
2572 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2573 # "How can he give us a status update, if he's DEAD?"
2574 if checkstatus encodetrack-
$CHECKTRACK; then
2577 # Nothing to see here please go quietly back to your homes
2578 if [ -z "$CHECKTRACK" ]; then continue; fi
2579 # You're still here? Maybe there is something...
2580 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
2583 if [ ! $PROCEED ]; then sleep 5; fi
2586 # If the above didn't catch the stragglers, this will
2588 # Check to see if run_command logged any errors
2589 if [ -f "$ABCDETEMPDIR/errors" ]; then
2590 echo "The following commands failed to run:"
2591 cat "$ABCDETEMPDIR/errors"
2595 if [ "$KEEPWAVS" = "y" ];then
2599 if [ "$DOCLEAN" = "y" ]; then
2600 # Wipe all the evidence
2601 # Gimme gimme gimme some more time!
2603 rm -rf "$ABCDETEMPDIR"
2606 echo "Finished. Not cleaning $ABCDETEMPDIR."