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-)"
227 # This code splits the a Various Artist track name from one of the following
230 # forward: Artist / Track
231 # forward-dash: Artist - Track
232 # reverse: Track / Artist
233 # reverse-dash: Track - Artist
234 # colon: Artist: Track
235 # trailing-paren: Artist (Track)
238 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
241 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
242 case "$VARIOUSARTISTSTYLE" in
244 DTITLEARTIST
="$(echo $TRACKNAME | sed 's- / -~-g')"
245 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
246 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
249 DTITLEARTIST
="$(echo $TRACKNAME | sed 's, - ,~,g')"
250 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
251 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
254 DTITLEARTIST
="$(echo $TRACKNAME | sed 's- / -~-g')"
255 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
256 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
259 DTITLEARTIST
="$(echo $TRACKNAME | sed 's, - ,~,g')"
260 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
261 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
264 DTITLEARTIST
="$(echo $TRACKNAME | sed 's-: -~-g')"
265 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f1 -d~)"
266 TRACKNAME
="$(echo $DTITLEARTIST | cut -f2 -d~)"
269 DTITLEARTIST
="$(echo $TRACKNAME | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
270 TRACKARTIST
="$(echo $DTITLEARTIST | cut -f2 -d~)"
271 TRACKNAME
="$(echo $DTITLEARTIST | cut -f1 -d~)"
274 elif [ "$ONETRACK" = "y" ]; then
275 TRACKARTIST
="Various"
281 # do_tag [tracknumber]
282 # id3 tags a filename
284 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
285 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
288 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
289 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
290 # If we want to start the tracks with a given number, we need to modify the
291 # TRACKNUM value before evaluation
292 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
293 # Get the trackpadding from the current track
294 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
295 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
297 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
301 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
302 run_command tagtrack-
$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
303 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
304 -g "$CDGENRE" -T "$1/$TRACKS" "$ABCDETEMPDIR/track$1.$OUTPUT"
307 case "$OGGENCODERSYNTAX" in
309 # vorbiscomment can't do in-place modification, mv the file first
310 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" ]; then
311 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
314 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
315 echo ARTIST
=$TRACKARTIST
317 echo TITLE
=$TRACKNAME
318 if [ -n "$CDYEAR" ]; then
321 if [ -n "$CDGENRE" ]; then
322 echo GENRE
="$CDGENRE"
325 echo CDDB
=$CDDBDISCID
326 if [ "$(eval echo ${COMMENT})" != "" ]; then
327 case "$COMMENTOUTPUT" in
328 *=*) echo "$COMMENTOUTPUT";;
329 *) echo COMMENT
="$COMMENTOUTPUT";;
332 ) | run_command tagtrack-
$1 $VORBISCOMMENT -w \
333 "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
334 # Doublecheck that the commented file was created successfully before wiping the original
335 if [ -f "$ABCDETEMPDIR/track$1.$OUTPUT" ]; then
336 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT"
338 mv "$ABCDETEMPDIR/track$1.uncommented.$OUTPUT" "$ABCDETEMPDIR/track$1.$OUTPUT"
345 echo ARTIST
="$TRACKARTIST"
347 echo TITLE
="$TRACKNAME"
348 if [ -n "$CDYEAR" ]; then
351 if [ -n "$CDGENRE" ]; then
352 echo GENRE
="$CDGENRE"
354 echo TRACKNUMBER
=${TRACKNUM:-$1}
355 echo CDDB
=$CDDBDISCID
356 if [ "$(eval echo ${COMMENT})" != "" ]; then
357 case "$COMMENTOUTPUT" in
358 *=*) echo "$COMMENTOUTPUT";;
359 *) echo COMMENT
="$COMMENTOUTPUT";;
362 ) | run_command tagtrack-
$1 $METAFLAC --import-tags-from=- --no-utf8-convert "$ABCDETEMPDIR/track$1.$OUTPUT"
365 run_command tagtrack-
$1 true
368 run_command tagtrack-
$1 true
376 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
379 # The commands here don't go through run_command because they're never supposed to be silenced
380 echo "Batch encoding tracks: $TRACKQUEUE"
381 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
384 case "$MP3ENCODERSYNTAX" in
389 for UTRACKNUM
in $TRACKQUEUE
391 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
393 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
395 if [ "$RETURN" != "0" ]; then
396 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
398 for UTRACKNUM
in $TRACKQUEUE
400 echo encodetrack-
$UTRACKNUM >> status
408 # Other encoders fall through to normal encoding as the tracks
409 # have not been entered in the status file.
412 # do_encode [tracknumber] [hostname]
413 # If no hostname is specified, encode locally
415 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
418 IN
="$ABCDETEMPDIR/track$1.wav"
419 # We need IN to proceed.
420 if [ -s "$IN" ] ; then
421 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
423 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
424 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
429 case "$MP3ENCODERSYNTAX" in
430 lame|gogo
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
431 bladeenc
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
432 l3enc|xingmp3enc
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
433 mp3enc
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
437 run_command encodetrack-
$OUTPUT-$1 nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
444 case "$OGGENCODERSYNTAX" in
445 vorbize
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
446 oggenc
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
450 run_command encodetrack-
$OUTPUT-$1 nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
457 case "$FLACENCODERSYNTAX" in
458 flac
) run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
464 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
465 run_command encodetrack-
$OUTPUT-$1 nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
470 if [ "$(eval echo ${COMMENT})" != "" ]; then
473 *) COMMENT
="COMMENT=$COMMENT" ;;
475 COMMENT
="--comment \"$COMMENT\""
477 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
478 if [ ! "$DOTAG" = "y" ]; then
479 run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
481 run_command encodetrack-
$OUTPUT-$1 nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
485 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
487 # I tried compiling the mppenc from corecodecs.org and got some
488 # errors, so I have not tried it myself.
489 ## FIXME ## Needs some cleanup to determine if an empty tag sent
490 ## FIXME ## to the encoder ends up empty.
491 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"
495 # Only remove .wav if the encoding succeeded
496 if checkerrors
"encodetrack-(.{3,4})-$1"; then
497 run_command encodetrack-
$1 false
499 run_command encodetrack-
$1 true
500 if [ ! "$KEEPWAVS" = "y" ] ; then
505 if [ "$(checkstatus encode-output)" = "loud" ]; then
506 echo "HEH! The file we were about to encode disappeared:"
509 run_command encodetrack-
$1 false
513 # do_preprocess [tracknumber]
515 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
518 # IN="$ABCDETEMPDIR/track$1.wav"
519 # # We need IN to proceed.
520 # if [ -s "$IN" ] ; then
521 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
523 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
524 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
525 # case "$POSTPROCESSFORMAT" in
527 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
529 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
531 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
533 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
535 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
538 # # Only remove .wav if the encoding succeeded
539 # if checkerrors "preprocess-(.{3,4})-$1"; then
540 # run_command preprocess-$1 false
542 # run_command preprocess-$1 true
545 # if [ "$(checkstatus encode-output)" = "loud" ]; then
546 # echo "HEH! The file we were about to pre-process disappeared:"
549 # run_command preprocess-$1 false
554 # do_postprocess [tracknumber]
556 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
559 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
561 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
562 # # We need IN to proceed.
563 # if [ -s "$IN" ] ; then
564 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
565 # run_command '' echo "Post-processing track $1 of $TRACKS..."
566 # case "$POSTPROCESSFORMAT" in
568 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
570 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
572 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
574 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
576 # # Only remove .wav if the encoding succeeded
577 # if checkerrors "postprocess-(.{3,4})-$1"; then
578 # run_command postprocess-$1 false
580 # run_command postprocess-$1 true
583 # if [ "$(checkstatus encode-output)" = "loud" ]; then
584 # echo "HEH! The file we were about to post-process disappeared:"
587 # run_command postprocess-$1 false
594 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
597 # The commands here don't go through run_command because they're never supposed to be silenced
598 echo "Batch analizing gain in tracks: $TRACKQUEUE"
603 for UTRACKNUM
in $TRACKQUEUE
605 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
607 # XXX: Hard-coded batch option!
608 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
610 if [ "$RETURN" != "0" ]; then
611 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
613 for UTRACKNUM
in $TRACKQUEUE
615 echo normalizetrack-
$UTRACKNUM >> status
623 # NORMALIZER, NORMALIZEROPTS
624 do_batch_normalize
()
626 # The commands here don't go through run_command because they're never supposed to be silenced
627 echo "Batch normalizing tracks: $TRACKQUEUE"
632 for UTRACKNUM
in $TRACKQUEUE
634 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
636 # XXX: Hard-coded batch option!
637 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
639 if [ "$RETURN" != "0" ]; then
640 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
642 for UTRACKNUM
in $TRACKQUEUE
644 echo normalizetrack-
$UTRACKNUM >> status
650 # do_normalize [tracknumber]
652 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
655 IN
="$ABCDETEMPDIR/track$1.wav"
656 if [ -e "$IN" ] ; then
657 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
658 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
660 if [ "$(checkstatus encode-output)" = "loud" ]; then
661 echo "HEH! The file we were about to normalize disappeared:"
664 run_command normalizetrack-
$1 false
"File $IN was not found"
668 # do_move [tracknumber]
669 # Deduces the outfile from environment variables
670 # Creates directory if necessary
672 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
675 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
677 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
678 # Munge filenames as follows:
683 # Eat control characters
684 ALBUMFILE
=$
(mungefilename
"$DALBUM")
685 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
686 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
687 GENRE
=$
(mungegenre
"$GENRE")
689 # If we want to start the tracks with a given number, we need to modify the
690 # TRACKNUM value before evaluation
691 if [ -n "$STARTTRACKNUMBER" ] ; then
692 # Get the trackpadding from the current track
693 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
694 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
696 TRACKNUM
=${UTRACKNUM}
698 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
699 # TRACKFILE, and TRACKNUM.
700 if [ "$VARIOUSARTISTS" = "y" ]; then
701 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
703 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
705 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
706 OUTPUTFILEDIR
=$
(dirname "$OUTPUTDIR/$OUTPUTFILE")
707 # mkdir -p shouldn't return an error if the directory already exists
708 mkdir
-p "$OUTPUTFILEDIR"
709 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
714 # Create the playlist if wanted
716 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
717 # VARIOUSARTISTS, OUTPUTDIR
720 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
722 # Create a playlist file for the playlist data to go into.
723 # We used to wipe it out if it existed. Now we request permision if interactive.
724 for LASTTRACK
in $TRACKQUEUE; do :; done
725 ALBUMFILE
=$
(mungefilename
"$DALBUM")
726 ARTISTFILE
=$
(mungefilename
"$DARTIST")
727 GENRE
=$
(mungegenre
"$GENRE")
728 if [ "$VARIOUSARTISTS" = "y" ] ; then
729 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
731 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
733 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
734 mkdir
-p "$FINALPLAYLISTDIR"
735 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
736 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
737 if [ "$INTERACTIVE" = "y" ]; then
738 while [ "$DONE" != "y" ]; do
740 case $ERASEPLAYLIST in
741 e|E|a|A|k|K
) DONE
=y
;;
749 # Once we erase the playlist, we use append to create the new one.
750 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
752 # The playlist does not exist, so we can safelly use append to create the new list
755 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
756 touch "$OUTPUTDIR/$PLAYLISTFILE"
757 for UTRACKNUM
in $TRACKQUEUE
759 # Shares some code with do_move since the filenames have to match
760 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
761 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
763 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
764 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
765 # If we want to start the tracks with a given number, we need to modify the
766 # TRACKNUM value before evaluation
767 if [ -n "$STARTTRACKNUMBER" ] ; then
768 # Get the trackpadding from the current track
769 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
770 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - 1 ))
772 TRACKNUM
=${UTRACKNUM}
774 if [ "$VARIOUSARTISTS" = "y" ]; then
775 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
777 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
779 if [ "$VARIOUSARTISTS" = "y" ]; then
780 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
781 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
783 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
786 if [ "$PLAYLISTDATAPREFIX" ]; then
787 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
789 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
794 ## this will convert the playlist to have CRLF line-endings, if specified
795 ## (some hardware players insist on CRLF endings)
796 if [ "$DOSPLAYLIST" = "y" ]; then
797 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
798 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
799 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
801 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
806 # This essentially the start of things
809 # Query the CD to get the track info, unless the user specified -C
810 # or we are using some actions which do not need the CDDB data at all
811 #if [ ! X"$EXPACTIONS" = "X" ]; then
813 #elif [ -z "$DISCID" ]; then
814 if [ -z "$DISCID" ]; then
815 vecho
-n "Getting CD track info... "
816 TRACKINFO
=$
($CDDISCID $CDROM)
817 # Make sure there's a CD in there by checking cd-discid's return code
818 if [ "$?" = "1" ]; then
819 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
824 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
827 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
828 # This needs to be done now because a section of the resuming code will need
831 # get the number of digits to pad TRACKNUM with - we'll use this later
832 # a CD can only hold 99 tracks, but since we support a feature for starting
833 # numbering the tracks from a given number, we might need to set it as a
834 # variable for the user to define... or obtain it somehow.
835 if [ "$PADTRACKS" = "y" ] ; then
839 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
840 if [ -z "$TRACKQUEUE" ]; then
841 if [ ! "$STRIPDATATRACKS" = "y" ]; then
842 case "$CDROMREADERSYNTAX" in
844 if [ "$WEHAVEACD" = "y" ]; then
845 vecho
"Querying the CD for audio tracks..."
846 CDPARANOIAOUTPUT
=$
( $CDROMREADER -d $CDROM -Q --verbose 2>&1 )
848 if [ ! "$RET" = "0" ];then
849 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
851 TRACKS
=$
( echo $CDPARANOIAOUTPUT |
egrep '^[[:space:]]+[[:digit:]]' |
tail -n 1 |
awk '{print $1}' |
tr -d "." |
tr '\n' ' ' )
852 CDPARANOIAAUDIOTRACKS
="$TRACKS"
854 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks
; then
855 TRACKS
=$
( cat $ABCDETEMPDIR/cdparanoia-audio-tracks
)
857 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
861 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
864 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
866 if echo "$TRACKS" |
grep [[:digit
:]] > /dev
/null
2>&1 ;then :;else
867 echo "The disc does not contain any tracks. Giving up..."
870 echo -n "Grabbing entire CD - tracks: "
871 if [ ! "$PADTRACKS" = "y" ] ; then
872 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
874 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
876 while [ "$X" -ne "$TRACKS" ]
878 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
879 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
883 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
884 # User-supplied track queue.
885 # Weed out non-numbers, whitespace, then sort and weed out duplicates
886 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
887 # Once cleaned, obtain the highest value in the trackqueue for number padding
888 for LASTTRACK
in $TRACKQUEUE; do :; done
889 if [ ! "$PADTRACKS" = "y" ] ; then
890 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
892 # Now we normalize the trackqueue
893 for TRACK
in $TRACKQUEUE ; do
894 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
895 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
897 TRACKQUEUE
=$PADTRACKQUEUE
898 echo Grabbing tracks
: "$TRACKQUEUE"
901 # for LASTTRACK in $TRACKQUEUE; do :; done
903 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
905 # We have the discid, create a temp directory after it to store all the temp
908 if [ -e "$ABCDETEMPDIR" ]; then
909 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
910 # It already exists, see if it's a directory
911 if [ ! -d "$ABCDETEMPDIR" ]; then
912 # This is a file/socket/fifo/device/etc, not a directory
915 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
916 echo "Please investigate, remove it, and rerun abcde." >&2
920 # It's a directory, let's see if it's owned by us
921 if [ ! -O "$ABCDETEMPDIR" ]; then
922 # Nope, complain and exit
924 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
925 echo "Please investigate, remove it, and rerun abcde." >&2
929 # See if it's populated
930 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
931 # Wipe and start fresh
932 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
933 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
934 if [ "$INTERACTIVE" = "y" ]; then
940 if [ "$ANSWER" != "y" ]; then
943 rm -rf "$ABCDETEMPDIR" ||
exit 1
944 mkdir
"$ABCDETEMPDIR"
945 if [ "$?" -gt "0" ]; then
946 # Directory already exists or could not be created
947 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
951 # Everything is fine. Check for ^encodetracklocation-
952 # and encode-output entries in the status file and
953 # remove them. These are not relevant across sessions.
954 if [ -f "$ABCDETEMPDIR/status" ]; then
955 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
956 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
957 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
959 # Remove old error messages
960 if [ -f "$ABCDETEMPDIR/errors" ]; then
961 rm -f "$ABCDETEMPDIR/errors"
965 # We are starting from scratch
966 mkdir
"$ABCDETEMPDIR"
967 if [ "$?" -gt "0" ]; then
968 # Directory already exists or could not be created
969 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
972 cat /dev
/null
> "$ABCDETEMPDIR/status"
974 if [ X
"$CUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
975 if checkstatus cuefile
; then :; else
976 $MKCUE $MKCUEOPTS > $ABCDETEMPDIR/cue-$
(echo $TRACKINFO | cut
-f1 -d' ').txt
977 echo cuefile
>> "$ABCDETEMPDIR/status"
980 # If we got the CDPARANOIA status and it is not recorded, save it now
981 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
982 if checkstatus cdparanoia-audio-tracks
; then :; else
983 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
984 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
989 # Create the discid file
990 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
994 # Parses a CDDB file and outputs the title and the track names.
995 # Variables: CDDBFILE
999 # List out disc title/author and contents
1000 if [ "$ONETRACK" = "y" ]; then
1001 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1003 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1004 if [ ! "$ONETRACK" = "y" ]; then
1005 for TRACK
in $
(f_seq_row
1 $TRACKS)
1007 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1013 # Check for a local CDDB file, and report success
1016 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1018 CDDBLOCALSUCCESS
="n"
1019 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1020 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1023 # If the user has selected to check a local CDDB repo, we proceed with it
1024 if [ -r "${CDDBLOCALFILE}" ]; then
1025 # List out disc title/author and contents
1026 do_cddbparse
"${CDDBLOCALFILE}"
1027 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1028 if [ "$INTERACTIVE" = "y" ]; then
1030 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1031 echo -n 'Invalid selection. Please answer "y" or "n": '
1034 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1038 if [ "$USELOCALRESP" = "y" ]; then
1039 #echo "Using local copy of CDDB data"
1040 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1041 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1042 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1043 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1044 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1045 CDDBLOCALSUCCESS
="y"
1047 #echo "Not using local copy of CDDB data"
1048 CDDBLOCALSUCCESS
="n"
1050 CDDBLOCALSUCCESS
="y"
1052 CDDBLOCALSUCCESS
="n"
1060 # Perform CDDB protocol version check if it hasn't already been done
1061 if checkstatus cddb-statcomplete
; then :; else
1062 if [ "$CDDBAVAIL" = "n" ]; then
1064 echo 503 > "$ABCDETEMPDIR/cddbstat"
1067 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1068 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1069 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1070 vecho
"Checking CDDB server status..."
1071 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1072 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1073 case "$RESPONSECODE" in
1074 210) # 210 OK, status information follows (until terminating `.')
1077 501|
*) # 501 Illegal CDDB protocol level: <n>.
1078 CDDBPROTO
=`expr $CDDBPROTO - 1`
1082 if test $rc -eq 1; then
1086 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1094 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1095 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1097 # Perform CDDB query if it hasn't already been done
1098 if checkstatus cddb-querycomplete
; then :; else
1099 if [ "$CDDBAVAIL" = "n" ]; then
1101 echo 503 > "$ABCDETEMPDIR/cddbquery"
1102 # The default CDDBLOCALSUCCESS is "n"
1103 # This part will be triggered if the user CDDB repo does not
1104 # contain the entry, or if we are not trying to use the repo.
1106 vecho
"Querying the CDDB server..."
1107 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1108 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1109 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1115 # no match found in database,
1116 # wget/fetch error, or user requested not to use CDDB
1117 # Make up an error code (503) that abcde
1118 # will recognize in do_cddbread
1119 # and compensate by making a template
1120 echo 503 > "$ABCDETEMPDIR/cddbquery"
1122 *) # strange and unknown error
1123 echo ERRORCODE
=$ERRORCODE
1124 echo "abcde: $CDDBTOOL returned unknown error code"
1128 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1135 # If it's not to be used, generate a template.
1136 # Then, display it (or them) and let the user choose/edit it
1137 if checkstatus cddb-readcomplete
; then :; else
1138 vecho
"Obtaining CDDB results..."
1139 # If CDDB is to be used, interpret the query results and read all
1140 # the available entries.
1141 rm -f "$ABCDETEMPDIR/cddbchoices"
1142 CDDBCHOICES
=1 # Overridden by multiple matches
1143 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1144 case "$RESPONSECODE" in
1146 # One exact match, retrieve it
1147 # 200 [section] [discid] [artist] / [title]
1148 if checkstatus cddb-read-1-complete
; then :; else
1149 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1150 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1151 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1152 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1153 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1155 # List out disc title/author and contents
1156 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1157 for TRACK
in $
(f_seq_row
1 $TRACKS)
1159 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1161 echo >> "$ABCDETEMPDIR/cddbchoices"
1165 case "$RESPONSECODE" in
1166 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1167 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1168 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1170 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1171 # List out disc title/author and contents of template
1172 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1174 for TRACK
in $
(f_seq_row
1 $TRACKS)
1176 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1178 echo >> "$ABCDETEMPDIR/cddbchoices"
1179 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1180 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1183 # Multiple exact, (possibly multiple) inexact matches
1185 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1186 if [ "$(wc -l < $ABCDETEMPDIR/cddbquery | tr -d ' ')" -eq 3 ]; then
1187 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1188 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1189 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1191 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1193 vecho
-n "Retrieving multiple matches... "
1194 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1195 read DISCINFO
# eat top line
1199 if checkstatus cddb-read-
$X-complete; then :; else
1200 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1201 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1203 # List out disc title/author and contents
1204 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1205 for TRACK
in $
(f_seq_row
1 $TRACKS)
1207 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1209 echo >> "$ABCDETEMPDIR/cddbchoices"
1212 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1216 for TRACK
in $
(f_seq_row
1 $TRACKS)
1218 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1220 echo >> "$ABCDETEMPDIR/cddbchoices"
1221 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1222 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1225 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1232 if checkstatus cddb-edit
>/dev
/null
; then
1233 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1234 VARIOUSARTISTS
="$(checkstatus variousartists)"
1235 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1238 if [ "$INTERACTIVE" = "y" ]; then
1239 # We should show the CDDB results both when we are not using the local CDDB repo
1240 # or when we are using it but we could not find a proper match
1241 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1242 # Display the $ABCDETEMPDIR/cddbchoices file created above
1243 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1244 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1245 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1246 CHOICE
=$
(checkstatus cddb-choice
)
1247 if [ -n "$CHOICE" ] ; then
1248 case $CDDBCHOICES in
1249 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1251 echo "Selected: #$CHOICE"
1252 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1256 # The user has a choice to make, display the info in a pager if necessary
1257 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1258 # Use the debian sensible-pager wrapper to pick the pager
1259 # user has requested via their $PAGER environment variable
1260 if [ -x "/usr/bin/sensible-pager" ]; then
1261 /usr
/bin
/sensible-pager
"$ABCDETEMPDIR/cddbchoices"
1262 elif [ -x "$PAGER" ]; then
1263 # That failed, try to load the preferred editor, starting
1264 # with their PAGER variable
1265 $PAGER "$ABCDETEMPDIR/cddbchoices"
1266 # If that fails, check for less
1267 elif [ -x /usr
/bin
/less ]; then
1268 /usr
/bin
/less -f "$ABCDETEMPDIR/cddbchoices"
1269 # more should be on all UNIX systems
1270 elif [ -x /bin
/more ]; then
1271 /bin
/more "$ABCDETEMPDIR/cddbchoices"
1273 # No bananas, just cat the thing
1274 cat "$ABCDETEMPDIR/cddbchoices" >&2
1277 # It's all going to fit in one page, cat it
1278 cat "$ABCDETEMPDIR/cddbchoices" >&2
1281 # I'll take CDDB read #3 for $400, Alex
1282 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1284 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1285 # Make sure we get a valid choice
1286 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1287 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1288 echo "Invalid selection. Please choose a number between 1 and $CDDBCHOICES." >&2
1289 echo -n "Selection [0-$CDDBCHOICES]: " >&2
1291 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1293 if [ "$CDCHOICENUM" = "0" ]; then
1294 vecho
"Creating empty CDDB template..."
1296 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > $ABCDETEMPDIR/cddbread
.0
1298 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1299 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1301 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1305 # We need some code to show the selected option when local repository is selected and we have found a match
1306 vecho
"Using cached CDDB match..." >&2
1307 # Display the $ABCDETEMPDIR/cddbchoices file created above
1308 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1309 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1310 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1311 CHOICE
=$
(checkstatus cddb-choice
)
1312 if [ "$USELOCALRESP" = "y" ]; then :; else
1313 if [ -n "$CHOICE" ] ; then
1314 case $CDDBCHOICES in
1317 echo "Selected template."
1319 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1321 echo "Selected: #$CHOICE"
1322 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1330 # We're noninteractive - pick the first choice.
1331 # But in case we run a previous instance and selected a choice, use it.
1332 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1333 # Show the choice if we are not using the locally stored one
1334 # or when the local search failed to find a match.
1335 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1336 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1337 #if [ "$PREVIOUSCHOICE" ]; then
1338 cat "$ABCDETEMPDIR/cddbchoices"
1341 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1342 CDCHOICENUM
=$PREVIOUSCHOICE
1345 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1347 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= $ABCDETEMPDIR/cddbread.$CDCHOICENUM | cut -f2- -d= | tr -d \\r\\n))" >&2
1352 if checkstatus cddb-choice
>/dev
/null
; then :; else
1353 echo "abcde: internal error: cddb-choice not recorded." >&2
1356 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1357 echo -n "Edit selected CDDB data? [y/n] (" >&2
1358 if [ "$INTERACTIVE" = "y" ]; then
1359 if [ "$UNKNOWNDISK" = "y" ]; then
1362 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1371 if [ "$EDITCDDB" = "y" ]; then
1372 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1374 # Use the debian sensible-editor wrapper to pick the editor that the
1375 # user has requested via their $EDITOR environment variable
1376 if [ -x "/usr/bin/sensible-editor" ]; then
1377 /usr
/bin
/sensible-editor
"$CDDBDATA"
1378 elif [ -n "$EDITOR" ]; then
1379 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1380 # That failed, try to load the preferred editor, starting
1381 # with their EDITOR variable
1382 eval $
(echo "$EDITOR") "$CDDBDATA"
1384 # If that fails, check for a vi
1385 elif [ -x /usr
/bin
/vi
]; then
1386 /usr
/bin
/vi
"$CDDBDATA"
1387 # nano should be on all (modern, i.e., sarge) debian systems
1388 elif [ -x /usr
/bin
/nano
]; then
1389 /usr
/bin
/nano
"$CDDBDATA"
1390 # mg should be on all OpenBSD systems
1391 elif [ -x /usr
/bin
/mg
]; then
1392 /usr
/bin
/mg
"$CDDBDATA"
1395 echo "No editor available. Check your EDITOR environment variable." >&2
1397 # delete editor backup file if it exists
1398 if [ -w "$CDDBDATA~" ]; then
1403 # Some heuristics first. Look at Disc Title, and if it starts with
1404 # "Various", then we'll assume Various Artists
1405 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2 -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1406 echo "Looks like a Multi-Artist CD" >&2
1409 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1410 if [ "$INTERACTIVE" = "y" ]; then
1417 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1420 # Need NUMTRACKS before cddb-tool will return it:
1421 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1422 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1423 # More than 1/2 tracks contain a "/", so guess forward
1425 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1426 # More than 1/2 contain a "-", so guess forward-dash
1428 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1429 # More than 1/2 contain something in parens, so guess trailing-paren
1433 echo "1) Artist / Title" >&2
1434 echo "2) Artist - Title" >&2
1435 echo "3) Title / Artist" >&2
1436 echo "4) Title - Artist" >&2
1437 echo "5) Artist: Title" >&2
1438 echo "6) Title (Artist)" >&2
1439 echo "7) This is a single-artist CD" >&2
1440 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1441 if [ "$INTERACTIVE" = "y" ]; then
1442 read VARIOUSARTISTSTYLE
1444 echo $DEFAULTSTYLE >&2
1445 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1447 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1448 # If they press Enter, then the default style (0) was chosen
1449 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1450 echo "Invalid selection. Please choose a number between 1 and 7."
1451 echo -n "Selection [1-7]: "
1452 read VARIOUSARTISTSTYLE
1453 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1455 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1456 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1458 vecho
"Selected: $VARIOUSARTISTSTYLE"
1459 case "$VARIOUSARTISTSTYLE" in
1461 VARIOUSARTISTSTYLE
=forward
1464 VARIOUSARTISTSTYLE
=forward-dash
1467 VARIOUSARTISTSTYLE
=reverse
1470 VARIOUSARTISTSTYLE
=reverse-dash
1473 VARIOUSARTISTSTYLE
=colon
1476 VARIOUSARTISTSTYLE
=trailing-paren
1484 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1485 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1487 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1488 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1489 # This works but does not have the necessary error checking
1490 # yet. If you are familiar with the CDDB spec
1491 # (see http://www.freedb.org/src/latest/DBFORMAT)
1492 # and can create an error-free entry on your own, then put
1493 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1494 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1495 # your abcde.conf to change the email address submissions are
1498 # submit the modified file, if they want
1499 if [ "$NOSUBMIT" != "y" ]; then
1500 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1502 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1503 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1505 echo -n 'Invalid selection. Please answer "y" or "n": '
1508 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1509 echo -n "Sending..."
1510 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1516 # Make sure the cache directory exists
1517 mkdir
-p $CDDBLOCALDIR
1518 # Cache edited CDDB entry in the user's cddb dir
1519 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1520 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1523 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1526 # do_cdread [tracknumber]
1527 # do_cdread onetrack [firsttrack] [lasttrack]
1531 # The commands here don't go through run_command because they're never supposed to be silenced
1532 # return codes need to be doublechecked anyway, however
1533 if [ "$1" = "onetrack" ]; then
1534 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1535 # FIXME # Until then, we grab the whole CD in one track, no matter what
1537 # We need the first and last track for cdda2wav
1540 case "$CDROMREADERSYNTAX" in
1541 cdparanoia
) UTRACKNUM
="1-" ;;
1542 cdda2wav
) UTRACKNUM
="1+$LASTRACK" ;;
1543 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1549 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1550 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1551 if [ -r "$CDDBDATA" ]; then
1552 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1553 echo "Grabbing track $UTRACKNUM: $TRACKNAME..." >&2
1555 echo "Grabbing track $UTRACKNUM..." >&2
1557 if [ "$USEPIPES" = "y" ]; then
1558 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1562 case "$CDROMREADERSYNTAX" in
1563 ## FIXME ## Find the case for dagrab, to avoid exceptions
1565 FILEARG
="-f $WAVDATA"
1573 case "$CDROMREADERSYNTAX" in
1574 cdparanoia
) nice
$READNICE $CDROMREADER -d $CDROM $UTRACKNUM $FILEARG $REDIR ;;
1576 if [ "$OSFLAVOUR" = "OSX" ] ; then
1577 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1578 disktool
-u ${CDROM#/dev/} 0
1579 # Also, in OSX the cdrom device for cdda2wav changes...
1580 CDDA2WAVCDROM
="IODVDServices"
1581 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1582 CDDA2WAVCDROM
="$CDROMID"
1584 if [ "$CDROMID" = "" ]; then
1585 CDDA2WAVCDROM
="$CDROM"
1587 CDDA2WAVCDROM
="$CDROMID"
1590 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t $UTRACKNUM $FILEARG $REDIR
1592 ## FIXME ## We have an exception for dagrab, since it uses -f
1593 ## FIXME ## Shall we just use -f $FILEARG ??
1594 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM $FILEARG $REDIR
1597 # Find the track's mounted path
1598 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1599 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1600 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
1601 # If the file exists, copy it
1602 if [ -e "$FILEPATH" ] ; then
1603 nice
$READNICE $CDROMREADER "$FILEPATH" $FILEARG $REDIR
1607 debug
) nice
$READNICE $CDROMREADER -d $CDROM -w $UTRACKNUM-[:1] $FILEARG $REDIR
1611 # If we get some error or we get some missing wav
1612 # (as long as we dont use pipes)
1613 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
1614 # Thank goodness errors is only machine-parseable up to the
1615 # first colon, otherwise this woulda sucked
1616 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1617 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
1619 if [ "$USEPIPES" = "y" ]; then
1620 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1622 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1626 if [ "$USEPIPES" = "y" ]; then
1627 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1629 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
1635 # No values accepted, only uses env variables
1638 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
1639 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
1641 echo "abcde: unable to set the device speed" >&2
1647 # vecho outputs a message if EXTRAVERBOSE is selected
1650 if [ x
"$EXTRAVERBOSE" != "x" ]; then
1655 # User-redefinable functions
1656 # Custom filename munging:
1659 echo "$@" |
sed s
,:,\
-,g |
tr \
/\
* __
+ |
tr -d \'\"\?\
[:cntrl
:\
]
1662 # Custom genre munging:
1665 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
1669 # Empty pre_read function, to be defined in the configuration file.
1675 ###############################################################################
1678 # Start of execution
1679 ###############################################################################
1682 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
1683 CDDBSUBMIT
=freedb-submit@freedb.org
1685 HELLOINFO
="$(whoami)@$(hostname)"
1687 CDROMREADERSYNTAX
=cdparanoia
1689 ENCODERSYNTAX
=default
1691 MP3ENCODERSYNTAX
=default
1692 OGGENCODERSYNTAX
=default
1693 FLACENCODERSYNTAX
=default
1694 SPEEXENCODERSYNTAX
=default
1695 MPPENCODERSYNTAX
=default
1696 NORMALIZERSYNTAX
=default
1698 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
1699 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
1700 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
1701 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
1702 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
1703 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
1704 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1705 PLAYLISTDATAPREFIX
=''
1706 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
1707 VAPLAYLISTDATAPREFIX
=''
1715 VARIOUSARTISTSTYLE
=forward
1719 CDDBLOCALDIR
="$HOME/.cddb"
1722 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
1723 # i.e. CDROMID="1,0,0"
1726 # program paths - defaults to checking your $PATH
1732 XINGMP3ENC
=xingmp3enc
1746 CDPARANOIA
=cdparanoia
1755 VORBISCOMMENT
=vorbiscomment
1757 NORMALIZE
=normalize-audio
1759 VORBISGAIN
=vorbisgain
1762 # Options for programs called from abcde
1794 # Default to one process if -j isn't specified
1797 # List of actions to perform - by default, run to completion
1798 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
1800 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
1801 # Let's use these checkings to determine the OS flavour, which will be used later
1802 if [ X$
(uname
) = "XFreeBSD" ] ; then
1806 elif [ X$
(uname
) = "XDarwin" ] ; then
1809 # We should have disktool in OSX, but let's be sure...
1811 elif [ X$
(uname
) = "XOpenBSD" ] ; then
1818 # If CDDBAVAIL is set to n, no CDDB read is done
1819 # If USEID3 is set to n, no ID3 tagging is done
1824 if [ -z "$OUTPUTDIR" ]; then
1828 if [ -z "$WAVOUTPUTDIR" ]; then
1829 WAVOUTPUTDIR
="$OUTPUTDIR"
1832 # Load system defaults
1833 if [ -r /etc
/abcde.conf
]; then
1836 # Load user preference defaults
1837 if [ -r $HOME/.abcde.conf
]; then
1841 # By this time, we need some HTTPGETOPTS already defined.
1842 # If the user has defined a non-default HTTPGET method, we should not be empty.
1844 if [ "$HTTPGETOPTS" = "" ] ; then
1846 wget
) HTTPGETOPTS
="-q -O -";;
1847 curl
) HTTPGETOPTS
="-f -s";;
1848 fetch
)HTTPGETOPTS
="-q -o -";;
1849 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
1853 # If the CDROM has not been set yet, find a suitable one.
1854 # If this is a devfs system, default to /dev/cdroms/cdrom0
1855 # instead of /dev/cdrom
1856 if [ "$CDROM" = "" ] ; then
1857 if [ -e /dev
/cdroms
/cdrom0
]; then
1858 CDROM
=/dev
/cdroms
/cdrom0
1859 elif [ -e /dev
/cdrom
]; then
1861 elif [ -e /dev
/cd0c
]; then
1863 elif [ -e /dev
/acd0c
]; then
1865 elif [ -e /dev
/disk1
]; then
1870 # Parse command line options
1871 #while getopts 1a:bc:C:d:Dhj:klLnNo:pr:S:t:T:vVx opt ; do
1872 while getopts 1a
:A
:bc:C
:d
:Dhj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
1875 a
) ACTIONS
="$OPTARG" ;;
1876 A
) EXPACTIONS
="$OPTARG";;
1878 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
1879 C
) DISCID
="${OPTARG#abcde.}" ;;
1880 d
) CDROM
="$OPTARG" ;;
1883 # f) FORCECDDBUSELOCAL=y ;;
1885 j
) MAXPROCS
="$OPTARG" ;;
1888 L
) CDDBUSELOCAL
=y
;;
1893 o
) OUTPUTTYPE
="$OPTARG" ;;
1896 r
) REMOTEHOSTS
="$OPTARG" ;;
1898 s
) STARTTRACKNUMBER
="$OPTARG" ;;
1899 S
) CDSPEEDVALUE
="$OPTARG" ;;
1900 # t) PREPROCESSFORMATS="$OPTARG"
1902 # T) POSTPROCESSFORMATS="$OPTARG" ;;
1903 t
) STARTTRACKNUMBER
="$OPTARG" ;;
1904 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
1906 echo "This is abcde v$VERSION."
1907 echo "Usage: abcde [options] [tracks]"
1908 echo "abcde -h for extra help"
1911 V
) EXTRAVERBOSE
="y" ;;
1913 w
) COMMENT
="$OPTARG" ;;
1914 W
) STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}" ;;
1919 shift $
(($OPTIND - 1))
1921 # Decide if we can continue.
1922 if [ "$ONETRACK" = "y" ]; then
1923 # FIXME # remove check as soon as we find out about the other readers
1924 case "$CDROMREADERSYNTAX" in
1925 dagrab|cddafs|debug
) echo "abcde error: ONETRACK reading is not suported with "$CDROMREADERSYNTAX" yet"
1928 if [ "$BATCH" = "y" ]; then
1929 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
1932 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
1933 # FIXME # allow ranges of tracks to be selected for onetrack ripping
1934 if [ $# -gt 0 ]; then
1935 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
1938 while [ $# -gt 0 ]; do
1939 # Range parsing code courtesy of Vincent Ho
1940 RSTART
=$
(echo $1 | cut
-f1 -d-)
1941 REND
=$
(echo $1 | cut
-f2 -d-)
1942 if [ "$RSTART" = "$REND" ]; then
1945 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
1947 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
1952 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
1953 # List of experimental actions: retag,transcode
1955 # Determine what actions are to be done from $ACTIONS and set the
1956 # following environment variables for them:
1968 for ACTION
in $
(echo $ACTIONS |
tr , \
)
1973 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
1974 # preprocess) DOPREPROCESS=y; DOREAD=y;;
1975 encode
) DOENCODE
=y
; DOREAD
=y
;;
1976 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
1977 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
1978 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
1979 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
1986 # At this point a CDROM has to be defined, so we check it exists.
1987 if [ "$CDROM" != "" ] ; then
1988 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
1989 if [ "$OSFLAVOUR" = "FBSD" ]; then
1990 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
1991 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
1992 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
1996 elif [ ! -e $CDROM ] ; then
1997 echo "abcde error: CDROM device cannot be found." >&2
2001 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2005 # USEPIPES pre-tests, before we get into more serious stuff
2006 # Not compatible with:
2007 # - multiple outputs
2009 # - lowdisk algorithm
2011 if [ X
"$USEPIPES" = "Xy" ]; then
2012 if [ $
(echo $OUTPUTTYPE |
tr , \ |
wc -w ) -gt 1 ]; then
2013 echo "abcde error: Unix pipes not compatible with multiple outputs"
2016 if [ X
"$DONORMALIZE" = "Xy" ]; then
2017 echo "abcde error: Unix pipes not compatible with normalizer"
2018 # FIXME # Do we need to exit or shall we just disable the mode?
2021 if [ X
"$DOENCODE" = "Xn" ]; then
2022 vecho
"Disabling Unix pipes since we are not encoding!"
2025 if [ X
"$LOWDISK" = "Xy" ]; then
2026 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2031 # Decide which CDROM reader we're gonna use
2032 case "$CDROMREADERSYNTAX" in
2034 CDROMREADER
="$CDPARANOIA"
2035 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2038 CDROMREADER
="$CDDA2WAV"
2039 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2042 CDROMREADER
="$DAGRAB"
2043 CDROMREADEROPTS
="$DAGRABOPTS"
2046 CDROMREADER
="$CDDAFS"
2047 CDROMREADEROPTS
="$CDDAFSOPTS"
2051 # There's only one normalize...
2052 case "$NORMALIZERSYNTAX" in
2054 NORMALIZER
="$NORMALIZE"
2055 NORMALIZEROPTS
="$NORMALIZEOPTS"
2059 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2060 if echo $OUTPUTTYPE |
grep ":" > /dev
/null
2>&1 ; then
2063 for OUTPUT
in "$OUTPUTTYPE"
2066 ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2067 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2068 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2069 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2070 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2073 for OUTPUT
in "$OUTPUTTYPE"
2075 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2076 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2078 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2082 # 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
2084 # Getting ready for multiple output changes
2085 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2088 ogg
) [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2089 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2090 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2092 mp3
) [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2093 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2095 flac
) [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2096 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2098 spx
) [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
;;
2099 mpc
) [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
;;
2100 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2106 # decide which encoder
2107 case "$MP3ENCODERSYNTAX" in
2109 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2113 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2117 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2118 MP3ENCODER
="$BLADEENC"
2121 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2125 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2126 MP3ENCODER
="$XINGMP3ENC"
2129 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2130 MP3ENCODER
="$MP3ENC"
2133 case "$OGGENCODERSYNTAX" in
2135 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2136 OGGENCODER
="$VORBIZE"
2139 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2140 OGGENCODER
="$OGGENC"
2143 case "$FLACENCODERSYNTAX" in
2145 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2149 case "$SPEEXENCODERSYNTAX" in
2151 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2152 SPEEXENCODER
="$SPEEXENC"
2155 case "$MPPENCODERSYNTAX" in
2157 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2158 MPPENCODER
="$MPPENC"
2164 if [ "$ID3TAGV" = "1" ]; then
2166 TAGGEROPTS
="$ID3OPTS"
2169 TAGGEROPTS
="$ID3V2OPTS"
2172 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2174 if [ "$ENCNICE" ]; then
2175 ENCNICE
="-n $ENCNICE"
2177 if [ "$READNICE" ]; then
2178 READNICE
="-n $READNICE"
2180 if [ "$DISTMP3NICE" ]; then
2181 DISTMP3NICE
="-n $DISTMP3NICE"
2184 # Don't check for stuff if it's not needed
2185 if [ "$REMOTEHOSTS" ]; then NEEDDISTMP3
=y
; fi
2186 [ "$DONORMALIZE" = "y" ] && NEEDNORMALIZER
=y
2187 [ "$EJECTCD" = "y" ] && NEEDEJECT
=y
2188 [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ] && NEEDHTTPGET
=y
2189 [ "$CUEFILE" = "y" ] && NEEDMKCUE
=y
2191 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2192 case "$CDROMREADERSYNTAX" in
2193 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2198 # Rippers with USEPIPE support
2199 # FIXME # Include here all the rippers we can figure out support pipes
2202 # Encoders with USEPIPE support
2203 # FIXME # Include here all the encoders we can figure out support pipes
2207 # Figure out if we can use pipes with the ripper/encoder combination
2209 if [ "$USEPIPES" = "y" ]; then
2210 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2213 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2215 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2217 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYTNAX" ;;
2219 IPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2221 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2223 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2224 echo "abcde error: no support for pipes with given ripper" >&2
2225 echo "read the USEPIPES file from the source tarball to help" >&2
2226 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2229 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2230 echo "abcde error: no support for pipes with given encoder" >&2
2231 echo "read the USEPIPES file from the source tarball to help" >&2
2232 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2238 # Make sure a buncha things exist
2239 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2240 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2241 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2242 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2243 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2244 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2245 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2247 # Cut off the command-line options we just added in
2248 X
=$
(echo $X | cut
-d' ' -f2)
2249 if [ "$(which $X)" = "" ]; then
2250 echo "abcde error: $X is not in your path." >&2
2252 elif [ ! -x $
(which $X) ]; then
2253 echo "abcde error: $X is not executable." >&2
2258 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2259 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2260 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2262 # Here it used to say:
2263 # One thousand lines in, we can start doing stuff with things
2264 # Well, right now we are at line 2157 ;)
2266 # Export needed things so they can be read in this subshell
2267 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2268 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2270 # User-definable function to set some things. Use it for
2271 # - closing the CD tray with eject -t
2272 # - set the CD speed value with eject -x
2273 vecho
-n "Executing customizable pre-read function... "
2275 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2279 do_discid
# Get ABCDETEMPDIR created and status file initialized
2281 if [ "$DOCDDB" = "y" ]; then
2282 if [ $CDDBUSELOCAL = "y" ]; then
2285 if checkstatus cddb-choice
> /dev
/null
; then
2288 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2296 eval $
($CDDBTOOL parse
"$CDDBDATA")
2299 # Before reading tracks, we set the speed of the device
2301 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2302 case "$CDROMREADERSYNTAX" in
2303 cdparanoia|debug
) : ;;
2308 # Create playlist if needed (backgroundable) and start reading in tracks
2312 if [ ! "$ONETRACK" = "y" ]; then
2313 if [ "$DOPLAYLIST" = "y" ]; then
2314 echo Creating playlist...
>&2
2319 # For the lowdisk option, only one program is running at once so the encoder
2320 # can be unsilenced right away.
2321 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2322 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2325 if [ "$ONETRACK" = "y" ]; then
2326 FIRSTTRACK
=$
( echo $TRACKQUEUE |
awk '{print $1}' )
2327 TRACKS
="$FIRSTTRACK"
2328 for UTRACKNUM
in $TRACKQUEUE; do :;done
2329 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2330 do_cdread onetrack
$FIRSTTRACK $UTRACKNUM
2333 for UTRACKNUM
in $TRACKQUEUE
2335 if [ "$DOREAD" = "y" ]; then
2336 if [ "$USEPIPES" = "y" ]; then
2337 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2338 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
%
2341 if checkstatus readtrack-
$UTRACKNUM; then :; else
2342 do_cdread
$UTRACKNUM
2344 if [ "$?" != "0" ]; then
2345 # CD read failed - don't give the goahead to
2352 if [ "$BATCH" = "y" ]; then
2355 echo NEXTTRACK
# Get the encoder machine churning again
2356 if [ "$DOREAD" = "y" ]; then
2357 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2358 until checkstatus encodetrack-
$UTRACKNUM
2360 if checkerrors encodetrack-
$UTRACKNUM; then
2371 # Now that we're done the encoding can be loud again -
2372 # if we're not using SMP.
2373 if [ "$MAXPROCS" = "1" ]; then
2374 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2377 # All tracks read, start encoding.
2378 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2382 # We are now finished with the cdrom - it can be safely ejected. Note that
2383 # abcde will not have completed yet.
2384 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2385 # We check if the disk we are processing is actually the disk inside the
2386 # CD tray. If not, we do not eject the CD, since it might be so that the
2387 # user ejected it manually.
2388 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2389 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2390 # More FreeBSD bits.
2391 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2392 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2393 # but in this script EJECT is in the envionment and names the program
2396 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2397 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2398 $eject $EJECTOPTS $cd
2399 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2400 disktool
-e ${CDROM#/dev/} 0
2402 $EJECT $EJECTOPTS $CDROM
2409 ## Do we need to pre-process
2410 #if [ x"$PREPROCESS" = "x" ] ; then
2413 # for PRETRACKNUM in $TRACKQUEUE
2416 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2418 # until [ $PREPROCEED ]
2420 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2421 # # all locations are working, wait and try again later
2422 # if [ ! $PREPROCEED ]; then sleep 3; fi
2424 # ( do_preprocess $PRETRACKNUM
2432 # In batch mode, we want all tracks to be read first.
2433 if [ "$BATCH" = "y" ]; then
2434 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2435 if [ "$GOAHEAD" = "NO" ]; then break; fi
2436 for LASTTRACK
in $TRACKQUEUE; do :; done
2437 if checkstatus readtrack-
$LASTTRACK; then
2438 if [ "$DONORMALIZE" = "y" ]; then
2439 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2440 if checkerrors batch-normalize
; then exit; fi
2442 if [ "$DOENCODE" = "y" ]; then
2443 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2444 if checkerrors batch-encode
; then exit; fi
2449 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2450 if [ "$ONETRACK" = "y" ] ; then
2451 FIRSTTRACK
=$
( echo $TRACKQUEUE |
awk '{print $1}')
2452 TRACKQUEUE
=$FIRSTTRACK
2453 TRACKS
="$FIRSTTRACK"
2456 # Do the encoding, including parallelization of remote encoding
2457 # Figure out where each track is going to be encoded
2458 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2459 if [ "$MAXPROCS" != "0" ]; then
2460 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2462 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2466 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2467 for UTRACKNUM
in $TRACKQUEUE
2470 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2471 if [ "$GOAHEAD" = "NO" ]; then break; fi
2472 # find out where this track is to be encoded
2473 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2474 # Make sure we have a place to encode this, if not, exit stage right
2475 if [ -z "$ENCODELOCATIONS" ]; then
2481 for LOCATION
in $ENCODELOCATIONS
2483 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2484 # check first if a track has ever been assigned to this location
2485 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
2486 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2487 if checkerrors encodetrack-
$PREVIOUSTRACK; then
2488 for TEMPLOCATION
in $ENCODELOCATIONS
2490 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2491 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
2494 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
2499 # We're still here, this location must have been previously assigned,
2500 # and last completed without error - check if it's done with the
2501 # previous track yet
2502 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
2504 # all locations are working, wait and try again later
2505 if [ ! $PROCEED ]; then sleep 3; fi
2507 # Record the location we're about to encode the next track at
2508 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2510 # Don't proceed with the rest of the loop if we can't encode
2511 if [ "$ABORT" ]; then continue; fi
2512 # Set TRACKNUM, TRACKNAME
2513 if [ -e "$CDDBDATA" ]; then
2514 if [ "$ONETRACK" = "y" ]; then
2516 TRACKNUM
="$FIRSTTRACK"
2519 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
2521 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2522 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
2526 # You can't encode a file which needs to be normalized before finishing
2527 # You can't tag a file before it's finished encoding -
2528 # thus all of this is backgrounded together
2530 if [ "$DONORMALIZE" = "y" ]; then
2531 if checkstatus readtrack-
$UTRACKNUM; then
2532 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
2535 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2536 if checkstatus readtrack-
$UTRACKNUM; then
2537 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
2538 if [ "$DONORMALIZE" = "y" ]; then
2539 if checkstatus normalizetrack-
$UTRACKNUM; then
2540 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2543 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
2547 if [ "$DOTAG" = "y" ]; then
2548 if checkstatus encodetrack-
$UTRACKNUM; then
2549 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
2552 if [ "$DOMOVE" = "y" ]; then
2553 if checkstatus tagtrack-
$UTRACKNUM; then
2554 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
2559 # Go through it again and make sure there's no distmp3 stragglers, otherwise
2560 # we'll delete the files they're working on
2561 ## FIXME ## Check also for files which are encoded using PIPEs.
2562 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2567 for LOCATION
in $ENCODELOCATIONS
2569 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2570 # "How can he give us a status update, if he's DEAD?"
2571 if checkstatus encodetrack-
$CHECKTRACK; then
2574 # Nothing to see here please go quietly back to your homes
2575 if [ -z "$CHECKTRACK" ]; then continue; fi
2576 # You're still here? Maybe there is something...
2577 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
2580 if [ ! $PROCEED ]; then sleep 5; fi
2583 # If the above didn't catch the stragglers, this will
2585 # Check to see if run_command logged any errors
2586 if [ -f "$ABCDETEMPDIR/errors" ]; then
2587 echo "The following commands failed to run:"
2588 cat "$ABCDETEMPDIR/errors"
2592 if [ "$KEEPWAVS" = "y" ];then
2596 if [ "$DOCLEAN" = "y" ]; then
2597 # Wipe all the evidence
2598 # Gimme gimme gimme some more time!
2600 rm -rf "$ABCDETEMPDIR"
2603 echo "Finished. Not cleaning $ABCDETEMPDIR."