2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2005 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.
16 VERSION
='2.3.99-$Revision$'
20 echo "This is abcde v$VERSION."
21 echo "Usage: abcde [options] [tracks]"
23 echo "-1 Encode the whole CD in a single file"
24 echo "-a <action1[,action2]...>"
25 echo " Actions to perform (cddb,read,normalize,encode,tag,move,replaygain,playlist,clean)"
26 #echo "-A Experimental actions (retag, transcode)"
27 echo "-b Enable batch normalization"
28 #echo "-B Disable batch replaygain (do file by file)"
30 echo " Specify a configuration file (overrides system and user config files)"
32 echo " Specify discid to resume from (only needed if you no longer have the cd)"
34 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
35 echo "-D Debugging mode (equivalent to sh -x abcde)"
36 echo "-e Erase encoded track information from status file"
37 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
38 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
39 echo "-h This help information"
40 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
41 echo "-j <#> Number of encoder processes to run at once (localhost)"
42 echo "-k Keep the wav tracks for later use"
43 echo "-l Use low disk space algorithm"
44 echo "-L Use local CDDB storage directory"
45 echo "-n No lookup. Don't query CDDB, just create and use template"
46 echo "-N Noninteractive. Never prompt for anything"
47 echo "-m Modify playlist to include CRLF endings, to comply with some players"
48 echo "-M Create a CUE file"
49 echo "-o <type1[,type2]...>"
50 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav). Defaults to vorbis"
51 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
52 echo "-P Use UNIX pipes to read+encode without wav files"
53 echo "-r <host1[,host2]...>"
54 echo " Also encode on these remote hosts"
55 #echo "-R Add replaygain values to the tag info (only for vorbis,flac,mp3)"
57 echo " Show dielfs from the CDDB info (year,genre)"
58 echo "-S <#> Set the CD speed"
59 echo "-t <#> Start the track numbering at a given number"
60 echo "-T <#> Same as -t but modifies tag numbering"
61 echo "-u Use UNICODE tags and comments"
62 echo "-v Show version number and exit"
63 echo "-V Be a bit more verbose about what is happening behind the scenes"
64 echo "-x Eject CD after all tracks are read"
66 echo " Add a comment to the CD tracks"
67 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
68 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
70 echo "Tracks is a space-delimited list of tracks to grab."
71 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
73 #echo "Double hyphens are used to concatenate tracks"
78 echo "$@" >> "$ABCDETEMPDIR/status"
81 # log [level] [message]
83 # log outputs the right message in a common format
89 error
) echo "[ERROR] abcde: $@" >&2 ;;
90 warning
) echo "[WARNING] $@" >&2 ;;
91 info
) echo "[INFO] $@" ;;
95 # Funtions to replace the need of seq, which is too distribution dependant.
99 while [ $i -ne `expr $2 + 1` ]
109 if echo i |
grep -q "[[:digit:]]" ; then
110 while [ $i -ne `expr $2 + 1` ]
117 log error
"syntax error while processing track numbers"
122 # Functions to replace the need of awk {print $1} and {print $NF}
125 if [ X
"$1" = "X" ]; then
126 for first
in `cat`; do
137 if [ X
"$1" = "X" ]; then
138 for stdin
in `cat`; do
142 for last
in $@
; do :; done
147 # checkstatus [blurb]
148 # Returns "0" if the blurb was found, returns 1 if it wasn't
149 # Puts the blurb content, if available, on stdout.
150 # Otherwise, returns "".
153 # Take the last line in the status file if there's multiple matches
155 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
157 if [ -z "$BLURB" ]; then
162 # See if there's a = in it
163 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
164 echo "$(echo $BLURB | cut -f2- -d=)"
170 # chechwarnings [blurb]
171 # Returns "0" if the blurb was found (meaning there was an warning),
172 # returns 1 if it wasn't (yes this is a little backwards).
173 # Does not print the blurb on stdout.
174 # Otherwise, returns "".
177 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
180 # Take the last line in the status file if there's multiple matches
182 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
184 if [ -z "$BLURB" ]; then
185 # negative, we did not have a negative...
188 # affirmative, we had a negative...
193 # checkerrors [blurb]
194 # Returns "0" if the blurb was found (meaning there was an error),
195 # returns 1 if it wasn't (yes this is a little backwards).
196 # Does not print the blurb on stdout.
197 # Otherwise, returns "".
200 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
203 # Take the last line in the status file if there's multiple matches
205 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
207 if [ -z "$BLURB" ]; then
208 # negative, we did not have a negative...
211 # affirmative, we had a negative...
217 # Finds the right pager in the system to display a file
221 # Use the debian sensible-pager wrapper to pick the pager
222 # user has requested via their $PAGER environment variable
223 if [ -x "/usr/bin/sensible-pager" ]; then
224 /usr
/bin
/sensible-pager
"$PAGEFILE"
225 elif [ -x "$PAGER" ]; then
226 # That failed, try to load the preferred editor, starting
227 # with their PAGER variable
229 # If that fails, check for less
230 elif [ -x /usr
/bin
/less ]; then
231 /usr
/bin
/less -f "$PAGEFILE"
232 # more should be on all UNIX systems
233 elif [ -x /bin
/more ]; then
234 /bin
/more "$PAGEFILE"
236 # No bananas, just cat the thing
241 # run_command [blurb] [command...]
242 # Runs a command, silently if necessary, and updates the status file
247 # See if this is supposed to be silent
248 if [ "$(checkstatus encode-output)" = "loud" ]; then
252 # Special case for SMP, since
253 # encoder output is never displayed, don't mute echos
254 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
263 normalize|normalize-audio
)
264 if [ "$RETURN" = "2" ]; then
265 # File was already normalized.
270 if [ "$RETURN" != "0" ]; then
271 # Put an error in the errors file. For various reasons we
272 # can't capture a copy of the program's output but we can
273 # log what we attempted to execute and the error code
274 # returned by the program.
275 if [ "$BLURB" ]; then
278 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
279 return $RETURN # Do not pass go, do not update the status file
281 if [ "$BLURB" ]; then
282 echo $BLURB >> "$ABCDETEMPDIR/status"
286 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
287 # distributed under the terms of the GNU GPL v2 or later, at your option
289 # Function to determine if a word contains a slash.
298 # Function to give the relative path from one file to another.
299 # Usage: relpath fromfile tofile
300 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
301 # (the result would be Album/Song.mp3)
302 # Output is relative path to $2 from $1 on stdout
304 # This code has the following restrictions:
305 # Multiple ////s are not collapsed into single /s, with strange effects.
306 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
307 # If FR is a directory it must have a trailing /
315 /*) ;; # No processing is needed for absolute paths
317 # Loop through common prefixes, ignoring them.
318 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
320 FR
="$(echo "$FR" | cut -d/ -f2-)"
321 TO
="$(echo "$TO" | cut -d/ -f2-)"
323 # Loop through directory portions left in FR, adding appropriate ../s.
326 FR
="$(echo "$FR" | cut -d/ -f2-)"
336 # Finds an specific field from cddbinfo
341 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
344 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
350 # Get the track number we are going to use for different actions
353 if [ -n "$STARTTRACKNUMBER" ] ; then
354 # Get the trackpadding from the current track
355 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
356 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
358 TRACKNUM
=${UTRACKNUM}
364 if checkstatus replaygain
; then :; else
365 run_command
"" echo "Adding replygain information..."
366 for OUTPUT
in $
( echo $OUTPUTTYPE |
tr , \
)
370 OUTPUT
=$OGGOUTPUTCONTAINER
373 OUTPUT
=$FLACOUTPUTCONTAINER
378 for UTRACKNUM
in $TRACKQUEUE
380 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
381 do_getcddbinfo TRACKNAME
383 TRACKFILE
="$(mungefilename "$TRACKNAME")"
384 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
385 ALBUMFILE
="$(mungefilename "$DALBUM")"
387 if [ "$VARIOUSARTISTS" = "y" ]; then
388 OUTPUTFILE
="$(eval echo $VAOUTPUTFORMAT)"
390 OUTPUTFILE
="$(eval echo $OUTPUTFORMAT)"
392 OUTPUTFILES
[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
393 (( REPLAYINDEX
= $REPLAYINDEX + 1 ))
397 run_command replaygain-flac
$METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
400 run_command replaygain-vorbis
$VORBISGAIN --album "${OUTPUTFILES[@]}"
403 run_command replaygain-mp3
$MP3GAIN -a "${OUTPUTFILES[@]}"
406 run_command replaygain-mpc
$MPPGAIN --auto "${OUTPUTFILES[@]}"
411 if checkerrors
"replaygain-.{3,6}"; then :; else
412 run_command replaygain true
417 # This code splits the a Various Artist track name from one of the following
420 # forward: Artist / Track
421 # forward-dash: Artist - Track
422 # reverse: Track / Artist
423 # reverse-dash: Track - Artist
424 # colon: Artist: Track
425 # trailing-paren: Artist (Track)
428 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
431 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
432 case "$VARIOUSARTISTSTYLE" in
434 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
435 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
436 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
439 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
440 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
441 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
444 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
445 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
446 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
449 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
450 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
451 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
454 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's-: -~-g')"
455 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
456 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
459 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
460 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
461 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
464 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
465 TRACKARTIST
="Various"
467 TRACKARTIST
="$DARTIST"
472 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
476 "classic rock") id
=1 ;;
494 "industrial") id
=19 ;;
495 "alternative") id
=20 ;;
497 "death metal") id
=22 ;;
499 "soundtrack") id
=24 ;;
500 "euro-techno") id
=25 ;;
504 "jazz+funk") id
=29 ;;
507 "classical") id
=32 ;;
508 "instrumental") id
=33 ;;
512 "sound clip") id
=37 ;;
515 "alt. rock") id
=40 ;;
520 "meditative") id
=45 ;;
521 "instrum. pop") id
=46 ;;
522 "instrum. rock") id
=47 ;;
526 "techno-indust.") id
=51 ;;
527 "electronic") id
=52 ;;
529 "eurodance") id
=54 ;;
531 "southern rock") id
=56 ;;
536 "christian rap") id
=61 ;;
537 "pop/funk"|
"pop / funk") id
=62 ;;
539 "native american") id
=64 ;;
542 "psychadelic") id
=67 ;;
544 "showtunes") id
=69 ;;
548 "acid punk") id
=73 ;;
549 "acid jazz") id
=74 ;;
553 "rock & roll") id
=78 ;;
554 "hard rock") id
=79 ;;
556 "folk/rock") id
=81 ;;
557 "national folk") id
=82 ;;
564 "bluegrass") id
=89 ;;
565 "avantgarde") id
=90 ;;
566 "gothic rock") id
=91 ;;
567 "progress. rock") id
=92 ;;
568 "psychadel. rock") id
=93 ;;
569 "symphonic rock") id
=94 ;;
570 "slow rock") id
=95 ;;
573 "easy listening") id
=98 ;;
579 "chamber music") id
=104 ;;
581 "symphony") id
=106 ;;
582 "booty bass") id
=107 ;;
584 "porn groove") id
=109 ;;
586 "slow jam") id
=111 ;;
590 "folklore") id
=115 ;;
592 "power ballad") id
=117 ;;
593 "rhythmic soul") id
=118 ;;
594 "freestyle") id
=119 ;;
596 "punk rock") id
=121 ;;
597 "drum solo") id
=122 ;;
598 "a capella") id
=123 ;;
599 "euro-house") id
=124 ;;
600 "dance hall") id
=125 ;;
602 "drum & bass") id
=127 ;;
603 "club-house") id
=128 ;;
604 "hardcore") id
=129 ;;
608 "negerpunk") id
=133 ;;
609 "polsk punk") id
=134 ;;
611 "christian gangsta rap") id
=136 ;;
612 "heavy metal") id
=137 ;;
613 "black metal") id
=138 ;;
614 "crossover") id
=139 ;;
615 "contemporary christian")id
=140 ;;
616 "christian rock") id
=141 ;;
617 "merengue") id
=142 ;;
619 "thrash metal") id
=144 ;;
622 "synthpop") id
=147 ;;
623 "rock/pop"|
"rock / pop") id
=148 ;;
630 # do_tag [tracknumber]
631 # id3 tags a filename
633 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
634 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
637 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
638 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
639 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
640 # If we want to start the tracks with a given number, we need to modify the
641 # TRACKNUM value before evaluation
642 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
645 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
649 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
650 GENREID
=$
(do_getgenreid
"${CDGENRE}")
655 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
656 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
657 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
658 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
659 "${ENCODING:+--set-encoding=$ENCODING}"
660 "$ABCDETEMPDIR/track$1.$OUTPUT"
663 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
664 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
665 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
666 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
667 "$ABCDETEMPDIR/track$1.$OUTPUT"
672 case "$OGGENCODERSYNTAX" in
674 # vorbiscomment can't do in-place modification, mv the file first
675 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
676 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
679 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
680 echo ARTIST
="$TRACKARTIST"
682 echo TITLE
="$TRACKNAME"
683 if [ -n "$CDYEAR" ]; then
686 if [ -n "$CDGENRE" ]; then
687 echo GENRE
="$CDGENRE"
689 echo TRACKNUMBER
=${TRACKNUM:-$1}
690 echo CDDB
=$CDDBDISCID
691 if [ "$(eval echo ${COMMENT})" != "" ]; then
692 case "$COMMENTOUTPUT" in
693 *=*) echo "$COMMENTOUTPUT";;
694 *) echo COMMENT
="$COMMENTOUTPUT";;
697 ) | run_command tagtrack-
$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
698 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
699 # Doublecheck that the commented file was created successfully before wiping the original
700 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
701 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
703 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
710 echo ARTIST
="$TRACKARTIST"
712 echo TITLE
="$TRACKNAME"
713 if [ -n "$CDYEAR" ]; then
716 if [ -n "$CDGENRE" ]; then
717 echo GENRE
="$CDGENRE"
719 echo TRACKNUMBER
="${TRACKNUM:-$1}"
720 echo CDDB
="$CDDBDISCID"
721 if [ "$(eval echo ${COMMENT})" != "" ]; then
722 case "$COMMENTOUTPUT" in
723 *=*) echo "$COMMENTOUTPUT";;
724 *) echo COMMENT
="$COMMENTOUTPUT";;
727 ) | run_command tagtrack-
$OUTPUT-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
730 run_command tagtrack-
$OUTPUT-$1 true
733 run_command tagtrack-
$OUTPUT-$1 true
736 run_command tagtrack-
$OUTPUT-$1 true
740 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
741 run_command tagtrack-
$1 true
748 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
751 # The commands here don't go through run_command because they're never supposed to be silenced
752 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
753 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
757 case "$MP3ENCODERSYNTAX" in
762 for UTRACKNUM
in $TRACKQUEUE
764 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
766 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
768 if [ "$RETURN" != "0" ]; then
769 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
771 for UTRACKNUM
in $TRACKQUEUE
773 run_command encodetrack-
$OUTPUT-$UTRACKNUM true
774 #run_command encodetrack-$UTRACKNUM true
783 if checkerrors
"nogap-encode"; then :; else
784 if [ ! "$KEEPWAVS" = "y" ] ; then
785 if [ ! "$KEEPWAVS" = "move" ] ; then
790 # Other encoders fall through to normal encoding as the tracks
791 # have not been entered in the status file.
794 # do_encode [tracknumber] [hostname]
795 # If no hostname is specified, encode locally
797 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
800 if [ "$USEPIPES" = "y" ]; then
803 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
806 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
809 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
812 TEMPARG
="PIPE_$SPEEXENCODER"
815 TEMPARG
="PIPE_$MPPENCODER"
818 IN
="$( eval echo "\$
$TEMPARG" )"
820 IN
="$ABCDETEMPDIR/track$1.wav"
823 case "$MP3ENCODERSYNTAX" in
824 # FIXME # check if mp3enc needs -if for pipes
825 # FIXME # I have not been able to find a working mp3enc binary
839 # We need IN to proceed, if we are not using pipes.
840 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
841 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
845 OUT
="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
846 OUTPUT
=$OGGOUTPUTCONTAINER
849 OUT
="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
850 OUTPUT
=$FLACOUTPUTCONTAINER
853 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
856 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-
$OUTPUT-$1 ; then
859 if [ X
"$USEPIPES" = "Xy" ]; then
861 # We need a way to store the creation of the files when using PIPES
862 RUN_COMMAND_PIPES
="run_command encodetrack-$OUTPUT-$1 true"
864 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
865 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
871 case "$MP3ENCODERSYNTAX" in
872 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
873 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
874 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
875 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
876 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
880 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
887 case "$OGGENCODERSYNTAX" in
888 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
889 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
893 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
900 case "$FLACENCODERSYNTAX" in
901 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
906 vecho
"$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
907 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
912 if [ "$(eval echo ${COMMENT})" != "" ]; then
915 *) COMMENT
="COMMENT=$COMMENT" ;;
917 COMMENT
="--comment \"$COMMENT\""
919 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
920 if [ ! "$DOTAG" = "y" ]; then
921 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
923 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
927 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
929 # I tried compiling the mppenc from corecodecs.org and got some
930 # errors, so I have not tried it myself.
931 ## FIXME ## Needs some cleanup to determine if an empty tag sent
932 ## FIXME ## to the encoder ends up empty.
933 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
936 # In case of wav output we need nothing. Just keep the wavs.
941 # Only remove .wav if the encoding succeeded
942 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
943 run_command encodetrack-
$1 true
944 if [ ! "$KEEPWAVS" = "y" ] ; then
945 if [ ! "$KEEPWAVS" = "move" ] ; then
951 run_command
"" echo "HEH! The file we were about to encode disappeared:"
952 run_command
"" echo ">> $IN"
953 run_command encodetrack-
$1 false
957 # do_preprocess [tracknumber]
959 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
962 # IN="$ABCDETEMPDIR/track$1.wav"
963 # # We need IN to proceed.
964 # if [ -s "$IN" ] ; then
965 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
967 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
968 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
969 # case "$POSTPROCESSFORMAT" in
971 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
973 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
975 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
977 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
979 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
982 # # Only remove .wav if the encoding succeeded
983 # if checkerrors "preprocess-(.{3,4})-$1"; then
984 # run_command preprocess-$1 false
986 # run_command preprocess-$1 true
989 # if [ "$(checkstatus encode-output)" = "loud" ]; then
990 # echo "HEH! The file we were about to pre-process disappeared:"
993 # run_command preprocess-$1 false
998 # do_postprocess [tracknumber]
1000 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1003 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1005 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1006 # # We need IN to proceed.
1007 # if [ -s "$IN" ] ; then
1008 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1009 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1010 # case "$POSTPROCESSFORMAT" in
1012 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1014 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1016 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1018 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1020 # # Only remove .wav if the encoding succeeded
1021 # if checkerrors "postprocess-(.{3,4})-$1"; then
1022 # run_command postprocess-$1 false
1024 # run_command postprocess-$1 true
1027 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1028 # echo "HEH! The file we were about to post-process disappeared:"
1031 # run_command postprocess-$1 false
1046 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1050 # The commands here don't go through run_command because they're never supposed to be silenced
1051 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1056 for UTRACKNUM
in $TRACKQUEUE
1058 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1060 # FIXME # Hard-coded batch option!
1061 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1063 if [ "$RETURN" != "0" ]; then
1064 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1066 for UTRACKNUM
in $TRACKQUEUE
1068 echo normalizetrack-
$UTRACKNUM >> status
1074 # do_batch_normalize
1076 # NORMALIZER, NORMALIZEROPTS
1077 do_batch_normalize
()
1079 # The commands here don't go through run_command because they're never supposed to be silenced
1080 echo "Batch normalizing tracks: $TRACKQUEUE"
1085 for UTRACKNUM
in $TRACKQUEUE
1087 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1089 # XXX: Hard-coded batch option!
1090 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1092 if [ "$RETURN" != "0" ]; then
1093 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1095 for UTRACKNUM
in $TRACKQUEUE
1097 echo normalizetrack-
$UTRACKNUM >> status
1103 # do_normalize [tracknumber]
1105 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1108 IN
="$ABCDETEMPDIR/track$1.wav"
1109 if [ -e "$IN" ] ; then
1110 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1111 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1113 if [ "$(checkstatus encode-output)" = "loud" ]; then
1114 echo "HEH! The file we were about to normalize disappeared:"
1117 run_command normalizetrack-
$1 false
"File $IN was not found"
1121 # do_move [tracknumber]
1122 # Deduces the outfile from environment variables
1123 # Creates directory if necessary
1125 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1128 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1130 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1131 # Munge filenames as follows:
1136 # Eat control characters
1137 ALBUMFILE
="$(mungefilename "$DALBUM")"
1138 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1139 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1140 GENRE
="$(mungegenre "$GENRE")"
1141 YEAR
="$(echo $CDYEAR)"
1142 # If we want to start the tracks with a given number, we need to modify the
1143 # TRACKNUM value before evaluation
1145 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1146 # TRACKFILE, and TRACKNUM.
1147 if [ "$VARIOUSARTISTS" = "y" ]; then
1148 OUTPUTFILE
="$(eval echo "$VAOUTPUTFORMAT")"
1150 OUTPUTFILE
="$(eval echo "$OUTPUTFORMAT")"
1152 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1153 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1156 OUTPUT
=$OGGOUTPUTCONTAINER
1159 OUTPUT
=$FLACOUTPUTCONTAINER
1162 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1163 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1166 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1167 # FIXME # introduce warnings?
1170 # mkdir -p shouldn't return an error if the directory already exists
1171 mkdir
-p "$OUTPUTFILEDIR"
1172 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1173 if checkstatus movetrack-output-
$OUTPUT; then :; else
1174 run_command movetrack-output-
$OUTPUT true
1179 # mkdir -p shouldn't return an error if the directory already exists
1180 mkdir
-p "$OUTPUTFILEDIR"
1181 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1182 if checkstatus movetrack-output-
$OUTPUT; then :; else
1183 run_command movetrack-output-
$OUTPUT true
1187 # Lets move the cue file
1188 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1189 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1190 if checkstatus movecue-
$OUTPUT; then :; else
1191 # Silence the Copying output since it overlaps with encoding processes...
1192 #run_command '' vecho "Copying cue file to its destination directory..."
1193 if checkstatus onetrack
>/dev
/null
; then
1196 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1197 # We dont have the dir, since it was not created before.
1200 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1203 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1204 # http://brianvictor.tripod.com/mp3cue.htm#details
1205 [a-z0-9
][a-z0-9
][a-z0-9
])
1206 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1209 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1213 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1215 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1224 # Create the playlist if wanted
1226 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1227 # VARIOUSARTISTS, OUTPUTDIR
1230 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1234 OUTPUT
=$OGGOUTPUTCONTAINER
1237 OUTPUT
=$FLACOUTPUTCONTAINER
1240 # Create a playlist file for the playlist data to go into.
1241 # We used to wipe it out if it existed. Now we request permision if interactive.
1242 for LASTTRACK
in $TRACKQUEUE; do :; done
1243 ALBUMFILE
="$(mungefilename "$DALBUM")"
1244 ARTISTFILE
="$(mungefilename "$DARTIST")"
1245 GENRE
=$
(mungegenre
"$GENRE")
1246 YEAR
=${CDYEAR:-$CDYEAR}
1247 if [ "$VARIOUSARTISTS" = "y" ] ; then
1248 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
1250 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
1252 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1253 mkdir
-p "$FINALPLAYLISTDIR"
1254 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1255 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1256 if [ "$INTERACTIVE" = "y" ]; then
1257 while [ "$DONE" != "y" ]; do
1259 case $ERASEPLAYLIST in
1260 e|E|a|A|k|K
) DONE
=y
;;
1268 # Once we erase the playlist, we use append to create the new one.
1269 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1271 # The playlist does not exist, so we can safelly use append to create the new list
1274 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1275 touch "$OUTPUTDIR/$PLAYLISTFILE"
1276 for UTRACKNUM
in $TRACKQUEUE
1278 # Shares some code with do_move since the filenames have to match
1279 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1280 do_getcddbinfo TRACKNAME
1282 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1283 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1284 ALBUMFILE
="$(mungefilename "$DALBUM")"
1285 # If we want to start the tracks with a given number, we need to modify the
1286 # TRACKNUM value before evaluation
1288 if [ "$VARIOUSARTISTS" = "y" ]; then
1289 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1291 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1293 if [ "$VARIOUSARTISTS" = "y" ]; then
1294 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1295 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1297 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1300 if [ "$PLAYLISTDATAPREFIX" ]; then
1301 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1303 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1308 ## this will convert the playlist to have CRLF line-endings, if specified
1309 ## (some hardware players insist on CRLF endings)
1310 if [ "$DOSPLAYLIST" = "y" ]; then
1311 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1312 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1313 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1315 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1320 # This essentially the start of things
1323 # Query the CD to get the track info, unless the user specified -C
1324 # or we are using some actions which do not need the CDDB data at all
1325 #if [ ! X"$EXPACTIONS" = "X" ]; then
1327 #elif [ -z "$DISCID" ]; then
1328 if [ -z "$DISCID" ]; then
1329 vecho
-n "Getting CD track info... "
1330 # In OSX, unmount the disc before a query
1331 if [ "$OSFLAVOUR" = "OSX" ]; then
1332 disktool
-u ${CDROM#/dev/}
1334 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1335 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM |
$CUE2DISCID)
1337 TRACKINFO
=$
($CDDISCID $CDROM)
1339 # Make sure there's a CD in there by checking cd-discid's return code
1340 if [ ! "$?" = "0" ]; then
1341 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1342 log error
"cuesheet information from the flac file could not be read."
1343 log error
"Perhaps the flac file does not contain a cuesheet?."
1346 log error
"CD could not be read. Perhaps there's no CD in the drive?"
1350 # In OSX, remount the disc again
1351 if [ "$OSFLAVOUR" = "OSX" ]; then
1352 disktool
-m ${CDROM#/dev/}
1355 DISCID
=$
(echo $TRACKINFO | cut
-f1 -d' ')
1357 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1360 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1361 # This needs to be done now because a section of the resuming code will need
1364 # get the number of digits to pad TRACKNUM with - we'll use this later
1365 # a CD can only hold 99 tracks, but since we support a feature for starting
1366 # numbering the tracks from a given number, we might need to set it as a
1367 # variable for the user to define... or obtain it somehow.
1368 if [ "$PADTRACKS" = "y" ] ; then
1372 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1373 if [ -z "$TRACKQUEUE" ]; then
1374 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1375 case "$CDROMREADERSYNTAX" in
1377 if [ "$WEHAVEACD" = "y" ]; then
1378 vecho
"Querying the CD for audio tracks..."
1379 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1381 if [ ! "$RET" = "0" ];then
1382 log warning
"something went wrong while querying the CD... Maybe a DATA CD?"
1384 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1385 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1387 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1388 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1389 echo cdparanoia-audio-tracks
=$
( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1390 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1392 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1393 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1397 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1400 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1402 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1403 log info
"The disc does not contain any tracks. Giving up..."
1406 echo -n "Grabbing entire CD - tracks: "
1407 if [ ! "$PADTRACKS" = "y" ] ; then
1408 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1410 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1412 while [ "$X" -ne "$TRACKS" ]
1414 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1415 TRACKQUEUE
=$
(echo $TRACKQUEUE $X)
1419 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1420 # User-supplied track queue.
1421 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1422 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1423 # Once cleaned, obtain the highest value in the trackqueue for number padding
1424 for LASTTRACK
in $TRACKQUEUE; do :; done
1425 if [ ! "$PADTRACKS" = "y" ] ; then
1426 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1428 # Now we normalize the trackqueue
1429 for TRACK
in $TRACKQUEUE ; do
1430 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1431 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1433 TRACKQUEUE
=$PADTRACKQUEUE
1434 echo Grabbing tracks
: "$TRACKQUEUE"
1437 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1439 # We have the discid, create a temp directory after it to store all the temp
1442 if [ -e "$ABCDETEMPDIR" ]; then
1443 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1444 # It already exists, see if it's a directory
1445 if [ ! -d "$ABCDETEMPDIR" ]; then
1446 # This is a file/socket/fifo/device/etc, not a directory
1449 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1450 echo "Please investigate, remove it, and rerun abcde." >&2
1454 # It's a directory, let's see if it's owned by us
1455 if [ ! -O "$ABCDETEMPDIR" ]; then
1456 # Nope, complain and exit
1458 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1459 echo "Please investigate, remove it, and rerun abcde." >&2
1463 # See if it's populated
1464 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1465 # Wipe and start fresh
1466 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1467 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1468 if [ "$INTERACTIVE" = "y" ]; then
1474 if [ "$ANSWER" != "y" ]; then
1477 rm -rf "$ABCDETEMPDIR" ||
exit 1
1478 mkdir
"$ABCDETEMPDIR"
1479 if [ "$?" -gt "0" ]; then
1480 # Directory already exists or could not be created
1481 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1485 # Everything is fine. Check for ^encodetracklocation-
1486 # and encode-output entries in the status file and
1487 # remove them. These are not relevant across sessions.
1488 if [ -f "$ABCDETEMPDIR/status" ]; then
1489 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1490 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1491 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1493 # Remove old error messages
1494 if [ -f "$ABCDETEMPDIR/errors" ]; then
1495 rm -f "$ABCDETEMPDIR/errors"
1499 # We are starting from scratch
1500 mkdir
"$ABCDETEMPDIR"
1501 if [ "$?" -gt "0" ]; then
1502 # Directory already exists or could not be created
1503 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1506 cat /dev
/null
> "$ABCDETEMPDIR/status"
1507 # Store the abcde version in the status file.
1508 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1510 if [ X
"$MAKECUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1511 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1512 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1513 vecho
"Creating cue file..."
1514 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1515 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1517 log warning
"reading the CUE sheet with mkcue is still considered experimental"
1518 log warning
"and there was a problem with the CD reading. abcde will continue,"
1519 log warning
"but consider reporting the problem to the abcde author"
1523 # If we got the CDPARANOIA status and it is not recorded, save it now
1524 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1525 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
1526 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1530 # Create the discid file
1531 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1535 # Create a proper CUE file based on the CUE file we created before.
1538 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1539 CUEFILE_OUT
=$CUEFILE_IN.out
1540 ### FIXME ### checkstatus cddb
1541 if [ -e "$CDDBDATA" ]; then
1542 vecho
"Adding metadata to the cue file..."
1543 # FIXME It doesn't preserve spaces! Why?
1544 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1546 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1547 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1548 cat "$CUEFILE_IN" |
while read line
1550 if echo "$line" |
grep -q "INDEX"
1552 eval track
="\$TRACK$n"
1554 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1556 echo "$line" >> "$CUEFILE_OUT"
1558 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1559 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1565 # Parses a CDDB file and outputs the title and the track names.
1566 # Variables: CDDBFILE
1570 # List out disc title/author and contents
1571 if [ "$ONETRACK" = "y" ]; then
1572 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1574 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1575 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1576 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1577 if [ ! X
"$PARSEDYEAR" = "X" ]; then
1578 echo "Year: $PARSEDYEAR"
1581 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1582 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1583 if [ ! X
"$PARSEDGENRE" = "X" ]; then
1584 echo "Genre: $PARSEDGENRE"
1587 if [ ! "$ONETRACK" = "y" ]; then
1588 for TRACK
in $
(f_seq_row
1 $TRACKS)
1590 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1596 # Check for a local CDDB file, and report success
1599 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1601 CDDBLOCALSUCCESS
="n"
1602 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1603 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1606 # If the user has selected to check a local CDDB repo, we proceed with it
1607 if [ -r "${CDDBLOCALFILE}" ]; then
1608 # List out disc title/author and contents
1609 do_cddbparse
"${CDDBLOCALFILE}"
1610 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1611 if [ "$INTERACTIVE" = "y" ]; then
1613 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1614 echo -n 'Invalid selection. Please answer "y" or "n": '
1617 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1621 if [ "$USELOCALRESP" = "y" ]; then
1622 #echo "Using local copy of CDDB data"
1623 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1624 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
1625 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1626 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1627 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1628 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1629 CDDBLOCALSUCCESS
="y"
1631 #echo "Not using local copy of CDDB data"
1632 CDDBLOCALSUCCESS
="n"
1635 CDDBLOCALSUCCESS
="n"
1643 # Perform CDDB protocol version check if it hasn't already been done
1644 if checkstatus cddb-statcomplete
; then :; else
1645 if [ "$CDDBAVAIL" = "n" ]; then
1647 echo 503 > "$ABCDETEMPDIR/cddbstat"
1650 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1651 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1652 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1653 vecho
"Checking CDDB server status..."
1654 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1655 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1656 case "$RESPONSECODE" in
1657 210) # 210 OK, status information follows (until terminating `.')
1660 501|
*) # 501 Illegal CDDB protocol level: <n>.
1661 CDDBPROTO
=`expr $CDDBPROTO - 1`
1665 if test $rc -eq 1; then
1669 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1677 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1678 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1680 # Perform CDDB query if it hasn't already been done
1681 if checkstatus cddb-querycomplete
; then :; else
1682 if [ "$CDDBAVAIL" = "n" ]; then
1684 echo 503 > "$ABCDETEMPDIR/cddbquery"
1685 # The default CDDBLOCALSUCCESS is "n"
1686 # This part will be triggered if the user CDDB repo does not
1687 # contain the entry, or if we are not trying to use the repo.
1689 vecho
"Querying the CDDB server..."
1690 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1691 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1692 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1698 # no match found in database,
1699 # wget/fetch error, or user requested not to use CDDB
1700 # Make up an error code (503) that abcde
1701 # will recognize in do_cddbread
1702 # and compensate by making a template
1703 echo 503 > "$ABCDETEMPDIR/cddbquery"
1705 *) # strange and unknown error
1706 echo ERRORCODE
=$ERRORCODE
1707 echo "abcde: $CDDBTOOL returned unknown error code"
1711 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1718 # If it's not to be used, generate a template.
1719 # Then, display it (or them) and let the user choose/edit it
1720 if checkstatus cddb-readcomplete
; then :; else
1721 vecho
"Obtaining CDDB results..."
1722 # If CDDB is to be used, interpret the query results and read all
1723 # the available entries.
1724 rm -f "$ABCDETEMPDIR/cddbchoices"
1725 CDDBCHOICES
=1 # Overridden by multiple matches
1726 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1727 case "$RESPONSECODE" in
1729 # One exact match, retrieve it
1730 # 200 [section] [discid] [artist] / [title]
1731 if checkstatus cddb-read-1-complete
; then :; else
1732 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1733 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1734 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1735 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1736 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1738 # List out disc title/author and contents
1739 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1740 for TRACK
in $
(f_seq_row
1 $TRACKS)
1742 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1744 echo >> "$ABCDETEMPDIR/cddbchoices"
1748 case "$RESPONSECODE" in
1749 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1750 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1751 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1753 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1754 # List out disc title/author and contents of template
1755 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1757 for TRACK
in $
(f_seq_row
1 $TRACKS)
1759 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1761 echo >> "$ABCDETEMPDIR/cddbchoices"
1762 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1763 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1766 # Multiple exact, (possibly multiple) inexact matches
1768 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1769 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
1770 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1771 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1772 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1774 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1776 vecho
-n "Retrieving multiple matches... "
1777 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1778 read DISCINFO
# eat top line
1782 if checkstatus cddb-read-
$X-complete; then :; else
1783 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1784 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1786 # List out disc title/author and contents
1787 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1788 for TRACK
in $
(f_seq_row
1 $TRACKS)
1790 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1792 echo >> "$ABCDETEMPDIR/cddbchoices"
1795 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1799 for TRACK
in $
(f_seq_row
1 $TRACKS)
1801 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1803 echo >> "$ABCDETEMPDIR/cddbchoices"
1804 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1805 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1808 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1815 if checkstatus cddb-edit
>/dev
/null
; then
1816 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1817 VARIOUSARTISTS
="$(checkstatus variousartists)"
1818 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1821 if [ "$INTERACTIVE" = "y" ]; then
1822 # We should show the CDDB results both when we are not using the local CDDB repo
1823 # or when we are using it but we could not find a proper match
1824 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1825 # Display the $ABCDETEMPDIR/cddbchoices file created above
1826 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1827 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1828 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1829 CHOICE
=$
(checkstatus cddb-choice
)
1830 if [ -n "$CHOICE" ] ; then
1831 case $CDDBCHOICES in
1832 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1834 echo "Selected: #$CHOICE"
1835 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1839 # The user has a choice to make, display the info in a pager if necessary
1840 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1841 page
"$ABCDETEMPDIR/cddbchoices"
1843 # It's all going to fit in one page, cat it
1844 cat "$ABCDETEMPDIR/cddbchoices" >&2
1848 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1850 # I'll take CDDB read #3 for $400, Alex
1851 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1852 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1854 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1855 if echo $CDDBCHOICE |
egrep -q "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" ; then
1856 if [ ! X
"$DIFF" = "X" ]; then
1857 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
1858 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
1859 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1860 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1861 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1862 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1864 # We parse the 2 choices to diff, store them in temporary files and diff them.
1865 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
1866 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1868 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1869 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1870 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
1871 page
"$ABCDETEMPDIR/cddbread.diff"
1873 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1877 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1879 elif echo $CDDBCHOICE |
egrep -q "[[:space:]]*[[:digit:]]+[[:space:]]*" ; then
1880 # Make sure we get a valid choice
1881 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1882 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1883 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1887 if [ "$CDCHOICENUM" = "0" ]; then
1888 vecho
"Creating empty CDDB template..."
1890 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1892 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1893 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1895 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1899 # We need some code to show the selected option when local repository is selected and we have found a match
1900 vecho
"Using cached CDDB match..." >&2
1901 # Display the $ABCDETEMPDIR/cddbchoices file created above
1902 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1903 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1904 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1905 CHOICE
=$
(checkstatus cddb-choice
)
1906 if [ "$USELOCALRESP" = "y" ]; then :; else
1907 if [ -n "$CHOICE" ] ; then
1908 case $CDDBCHOICES in
1911 echo "Selected template."
1913 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1915 echo "Selected: #$CHOICE"
1916 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1924 # We're noninteractive - pick the first choice.
1925 # But in case we run a previous instance and selected a choice, use it.
1926 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1927 # Show the choice if we are not using the locally stored one
1928 # or when the local search failed to find a match.
1929 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1930 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1931 #if [ "$PREVIOUSCHOICE" ]; then
1932 cat "$ABCDETEMPDIR/cddbchoices"
1935 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1936 CDCHOICENUM
=$PREVIOUSCHOICE
1939 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1941 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1946 if checkstatus cddb-choice
>/dev
/null
; then :; else
1947 echo "abcde: internal error: cddb-choice not recorded." >&2
1950 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1951 echo -n "Edit selected CDDB data? [y/n] (" >&2
1952 if [ "$INTERACTIVE" = "y" ]; then
1953 if [ "$UNKNOWNDISK" = "y" ]; then
1956 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1965 if [ "$EDITCDDB" = "y" ]; then
1966 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1968 # Use the debian sensible-editor wrapper to pick the editor that the
1969 # user has requested via their $EDITOR environment variable
1970 if [ -x "/usr/bin/sensible-editor" ]; then
1971 /usr
/bin
/sensible-editor
"$CDDBDATA"
1972 elif [ -n "$EDITOR" ]; then
1973 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1974 # That failed, try to load the preferred editor, starting
1975 # with their EDITOR variable
1976 eval $
(echo "$EDITOR") \"$CDDBDATA\"
1978 # If that fails, check for a vi
1979 elif which vi
>/dev
/null
2>&1; then
1981 elif [ -x /usr
/bin
/vim
]; then
1982 /usr
/bin
/vim
"$CDDBDATA"
1983 elif [ -x /usr
/bin
/vi
]; then
1984 /usr
/bin
/vi
"$CDDBDATA"
1985 elif [ -x /bin
/vi
]; then
1987 # nano should be on all (modern, i.e., sarge) debian systems
1988 elif which nano
>/dev
/null
2>&1 ; then
1990 elif [ -x /usr
/bin
/nano
]; then
1991 /usr
/bin
/nano
"$CDDBDATA"
1992 # mg should be on all OpenBSD systems
1993 elif which mg
>/dev
/null
2>&1 ; then
1995 elif [ -x /usr
/bin
/mg
]; then
1996 /usr
/bin
/mg
"$CDDBDATA"
1999 log warning
"no editor available. Check your EDITOR environment variable."
2001 # delete editor backup file if it exists
2002 if [ -w "$CDDBDATA~" ]; then
2007 # Some heuristics first. Look at Disc Title, and if it starts with
2008 # "Various", then we'll assume Various Artists
2009 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2010 echo "Looks like a Multi-Artist CD" >&2
2013 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2014 if [ "$INTERACTIVE" = "y" ]; then
2021 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2024 # Need NUMTRACKS before cddb-tool will return it:
2025 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
2026 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2027 # More than 1/2 tracks contain a "/", so guess forward
2029 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2030 # More than 1/2 contain a "-", so guess forward-dash
2032 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2033 # More than 1/2 contain something in parens, so guess trailing-paren
2037 echo "1) Artist / Title" >&2
2038 echo "2) Artist - Title" >&2
2039 echo "3) Title / Artist" >&2
2040 echo "4) Title - Artist" >&2
2041 echo "5) Artist: Title" >&2
2042 echo "6) Title (Artist)" >&2
2043 echo "7) This is a single-artist CD" >&2
2044 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2045 if [ "$INTERACTIVE" = "y" ]; then
2046 read VARIOUSARTISTSTYLE
2048 echo $DEFAULTSTYLE >&2
2049 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2051 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2052 # If they press Enter, then the default style (0) was chosen
2053 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2054 echo "Invalid selection. Please choose a number between 1 and 7."
2055 echo -n "Selection [1-7]: "
2056 read VARIOUSARTISTSTYLE
2057 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2059 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2060 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2062 vecho
"Selected: $VARIOUSARTISTSTYLE"
2063 case "$VARIOUSARTISTSTYLE" in
2065 VARIOUSARTISTSTYLE
=forward
2068 VARIOUSARTISTSTYLE
=forward-dash
2071 VARIOUSARTISTSTYLE
=reverse
2074 VARIOUSARTISTSTYLE
=reverse-dash
2077 VARIOUSARTISTSTYLE
=colon
2080 VARIOUSARTISTSTYLE
=trailing-paren
2088 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2089 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2091 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2092 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2093 # This works but does not have the necessary error checking
2094 # yet. If you are familiar with the CDDB spec
2095 # (see http://www.freedb.org/src/latest/DBFORMAT)
2096 # and can create an error-free entry on your own, then put
2097 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2098 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2099 # your abcde.conf to change the email address submissions are
2102 # submit the modified file, if they want
2103 if [ "$NOSUBMIT" != "y" ]; then
2104 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2106 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2107 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2109 echo -n 'Invalid selection. Please answer "y" or "n": '
2112 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2113 echo -n "Sending..."
2114 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2120 # Make sure the cache directory exists
2121 mkdir
-p $CDDBLOCALDIR
2122 # Cache edited CDDB entry in the user's cddb dir
2123 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
2124 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2127 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2130 # do_cdread [tracknumber]
2131 # do_cdread onetrack [firsttrack] [lasttrack]
2135 # The commands here don't go through run_command because they're never supposed to be silenced
2136 # return codes need to be doublechecked anyway, however
2137 if [ "$1" = "onetrack" ]; then
2138 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2139 # FIXME # Until then, we grab the whole CD in one track, no matter what
2141 # We need the first and last track for cdda2wav
2144 UTRACKNUM
=$FIRSTTRACK
2148 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2149 if [ "$USEPIPES" = "y" ]; then
2150 TEMPARG
="PIPERIPPER_$CDROMREADERSYNTAX"
2151 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2153 PIPE_MESSAGE
="and encoding "
2155 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2156 case "$CDROMREADERSYNTAX" in
2157 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2159 FILEARG
="--output-name=$WAVDATA"
2162 FILEARG
="-f $WAVDATA"
2170 if [ "$1" = "onetrack" ]; then
2171 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2173 if [ -r "$CDDBDATA" ]; then
2174 do_getcddbinfo TRACKNAME
2175 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2177 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2180 case "$CDROMREADERSYNTAX" in
2181 ### FIXME ### use an exception for flac, since it uses -o
2182 ### FIXME ### Shall we just use -o $FILEARG ??
2184 nice
$READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2186 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2188 if [ "$OSFLAVOUR" = "OSX" ] ; then
2189 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2190 disktool
-u ${CDROM#/dev/} 0
2191 # Also, in OSX the cdrom device for cdda2wav changes...
2192 CDDA2WAVCDROM
="IODVDServices"
2193 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2194 CDDA2WAVCDROM
="$CDROMID"
2196 if [ "$CDROMID" = "" ]; then
2197 CDDA2WAVCDROM
="$CDROM"
2199 CDDA2WAVCDROM
="$CDROMID"
2202 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2204 ## FIXME ## We have an exception for dagrab, since it uses -f
2205 ## FIXME ## Shall we just use -f $FILEARG ??
2206 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2209 # Find the track's mounted path
2210 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2211 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2212 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2213 # If the file exists, copy it
2214 if [ -e "$FILEPATH" ] ; then
2215 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2219 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2223 # If we get some error or we get some missing wav
2224 # (as long as we dont use pipes)
2225 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2226 # Thank goodness errors is only machine-parseable up to the
2227 # first colon, otherwise this woulda sucked
2228 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2229 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2231 if [ "$USEPIPES" = "y" ]; then
2232 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2234 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2238 if [ "$USEPIPES" = "y" ]; then
2239 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2241 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2242 if [ "$1" = "onetrack" ]; then
2243 echo onetrack
>> "$ABCDETEMPDIR/status"
2250 # No values accepted, only uses env variables
2253 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2254 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2256 echo "abcde: unable to set the device speed" >&2
2262 # vecho outputs a message if EXTRAVERBOSE is selected
2265 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2267 warning
) log warning
"$@" ;;
2275 # decho outputs a debug message if DEBUG is selected
2278 if [ x
"$DEBUG" != "x" ]; then
2279 if echo $1 |
grep -q "^\[" ; then
2280 DEBUGECHO
=$
(echo "$@" |
tr -d '[]')
2281 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2288 # User-redefinable functions
2289 # Custom filename munging:
2292 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2293 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2296 # Custom genre munging:
2299 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2303 # Empty pre_read function, to be defined in the configuration file.
2310 # Empty post_read function, to be defined in the configuration file.
2316 ###############################################################################
2319 # Start of execution
2320 ###############################################################################
2323 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2324 CDDBSUBMIT
=freedb-submit@freedb.org
2326 HELLOINFO
="$(whoami)@$(hostname)"
2328 CDDBLOCALDIR
="$HOME/.cddb"
2331 # List of fields we parse and show during the CDDB parsing...
2332 SHOWCDDBFIELDS
="year,genre"
2335 CDROMREADERSYNTAX
=cdparanoia
2336 ENCODERSYNTAX
=default
2338 MP3ENCODERSYNTAX
=default
2339 OGGENCODERSYNTAX
=default
2340 FLACENCODERSYNTAX
=default
2341 SPEEXENCODERSYNTAX
=default
2342 MPPENCODERSYNTAX
=default
2343 NORMALIZERSYNTAX
=default
2344 CUEREADERSYNTAX
=default
2346 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2347 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2348 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2349 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2350 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2351 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2352 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2353 PLAYLISTDATAPREFIX
=''
2354 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2355 VAPLAYLISTDATAPREFIX
=''
2363 VARIOUSARTISTSTYLE
=forward
2369 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2370 # i.e. CDROMID="1,0,0"
2372 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2373 # If we are using the ide-scsi emulation layer, we need to define a "g"
2374 CDPARANOIACDROMBUS
="d"
2376 # program paths - defaults to checking your $PATH
2383 XINGMP3ENC
=xingmp3enc
2398 CDPARANOIA
=cdparanoia
2407 VORBISCOMMENT
=vorbiscomment
2409 NORMALIZE
=normalize-audio
2411 VORBISGAIN
=vorbisgain
2417 CUE2DISCID
=cue2discid
2419 # Options for programs called from abcde
2452 VORBISCOMMENTOPTS
="-R"
2453 METAFLACOPTS
="--no-utf8-convert"
2456 # Default to one process if -j isn't specified
2459 # List of actions to perform - by default, run to completion
2460 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2462 # List of prefered outputs - by default, run with whatever we have in the path
2463 # This option is basicaly for Debian package dependencies
2464 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
2466 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2467 # Let's use these checkings to determine the OS flavour, which will be used later
2468 if [ X$
(uname
) = "XFreeBSD" ] ; then
2473 elif [ X$
(uname
) = "XDarwin" ] ; then
2476 # We should have disktool in OSX, but let's be sure...
2478 CDROMREADERSYNTAX
=cddafs
2479 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2482 elif [ X$
(uname
) = "XNetBSD" ] ; then
2489 # If CDDBAVAIL is set to n, no CDDB read is done
2490 # If USEID3 is set to n, no ID3 tagging is done
2495 if [ -z "$OUTPUTDIR" ]; then
2499 if [ -z "$WAVOUTPUTDIR" ]; then
2500 WAVOUTPUTDIR
="$OUTPUTDIR"
2503 # Load system defaults
2504 if [ -r /etc
/abcde.conf
]; then
2507 # Load user preference defaults
2508 if [ -r $HOME/.abcde.conf
]; then
2512 # By this time, we need some HTTPGETOPTS already defined.
2513 # If the user has defined a non-default HTTPGET method, we should not be empty.
2515 if [ "$HTTPGETOPTS" = "" ] ; then
2517 wget
) HTTPGETOPTS
="-q -O -";;
2518 curl
) HTTPGETOPTS
="-f -s";;
2519 fetch
)HTTPGETOPTS
="-q -o -";;
2520 ftp) HTTPGETOPTS
="-q -o -";;
2521 *) log warning
"HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
2525 # If the CDROM has not been set yet, find a suitable one.
2526 # If this is a devfs system, default to /dev/cdroms/cdrom0
2527 # instead of /dev/cdrom
2528 if [ "$CDROM" = "" ] ; then
2529 if [ -e /dev
/cdroms
/cdrom0
]; then
2530 CDROM
=/dev
/cdroms
/cdrom0
2531 elif [ -e /dev
/cdrom
]; then
2533 elif [ -e /dev
/cd0c
]; then
2535 elif [ -e /dev
/acd0c
]; then
2537 elif [ -e /dev
/disk1
]; then
2542 # Parse command line options
2543 #while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2544 while getopts 1a
:bBc
:C
:d
:Defghj
:klLmMnNo
:pPr
:s
:S
:t
:T
:uvVxw
:W
:z opt
; do
2547 a
) ACTIONS
="$OPTARG" ;;
2548 A
) EXPACTIONS
="$OPTARG" ;;
2550 B
) NOBATCHREPLAYGAIN
=y
;;
2551 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else log error
"config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
2552 C
) DISCID
="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
2553 d
) CDROM
="$OPTARG" ;;
2555 e
) ERASEENCODEDSTATUS
=y
;;
2557 e
) ERASEENCODEDSTATUS
=y
;;
2558 E
) ENCODING
="$OPTARG" ;;
2562 j
) MAXPROCS
="$OPTARG" ;;
2565 L
) CDDBUSELOCAL
=y
;;
2570 o
) OUTPUTTYPE
="$OPTARG" ;;
2573 r
) REMOTEHOSTS
="$OPTARG" ;;
2574 R
) DOREPLAYGAIN
=y
;;
2575 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2576 S
) CDSPEEDVALUE
="$OPTARG" ;;
2577 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2578 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2581 echo "This is abcde v$VERSION."
2582 echo "Usage: abcde [options] [tracks]"
2583 echo "abcde -h for extra help"
2586 V
) EXTRAVERBOSE
="y" ;;
2588 w
) COMMENT
="$OPTARG" ;;
2589 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2590 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2592 log error
"argument of -W must be integer"
2596 z
) DEBUG
=y
; CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
2601 shift $
(($OPTIND - 1))
2603 # If the user specified a flac file, then switch to special flac mode
2604 if echo $CDROM |
grep -i -q '.flac$'; then
2605 vecho
"abcde: switching to flac CDROMREADERSYNTAX..."
2606 CDROMREADERSYNTAX
=flac
2607 if [ "$EJECTCD" = "y" ];then
2608 vecho
"abcde: CDROM flac mode, deactivating EJECTCD..."
2613 # If the user provided a DISCID, disable eject
2614 if [ -n "$DISCID" ]; then EJECTCD
=n
; fi
2616 # Decide if we can continue.
2617 if [ "$ONETRACK" = "y" ]; then
2618 # FIXME # remove check as soon as we find out about the other readers
2619 case "$CDROMREADERSYNTAX" in
2623 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
2626 if [ "$BATCHNORM" = "y" ]; then
2627 log warning
"BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
2630 if [ "$NOGAP" = "y" ]; then
2631 log warning
"NOGAP mode is not compatible with ONETRACK mode. Disabling..."
2634 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2635 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2636 if [ $# -gt 0 ]; then
2637 log warning
"ONETRACK mode selected, grabbing all tracks..."
2640 while [ $# -gt 0 ]; do
2641 # Range parsing code courtesy of Vincent Ho
2642 RSTART
=$
(echo $1 | cut
-f1 -d-)
2643 REND
=$
(echo $1 | cut
-f2 -d-)
2644 if [ "$RSTART" = "$REND" ]; then
2647 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2649 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2654 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2655 # List of experimental actions: retag,transcode
2657 # Determine what actions are to be done from $ACTIONS and set the
2658 # following environment variables for them:
2671 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2676 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2677 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2678 encode
) DOENCODE
=y
; DOREAD
=y
;;
2679 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2680 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2681 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2682 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
2683 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2688 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2689 # FIXME # should we abort on error or just inform the user?
2690 log warning
"selected both normalize and replaygain actions"
2693 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
2694 case $SHOWCDDBFIELD in
2695 y
*|Y
*) SHOWCDDBYEAR
="y";;
2696 g
*|G
*) SHOWCDDBGENRE
="y";;
2703 # At this point a CDROM has to be defined, so we check it exists.
2704 if [ X
"$CDROM" != "X" ] ; then
2705 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2706 if [ "$OSFLAVOUR" = "FBSD" ]; then
2707 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2708 log error
"CDROMID not in the right format for $CDROMREADERSYNTAX"
2709 log error
"Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2713 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2714 log error
"CDROM device cannot be found."
2717 # avoid processing if we are not going to hit the CDROM.
2718 elif [ X
"$DOREAD" = "Xy" ]; then
2719 log error
"CDROM has not been defined or cannot be found"
2723 # USEPIPES pre-tests, before we get into more serious stuff
2724 # Not compatible with:
2725 # - multiple outputs
2727 # - lowdisk algorithm
2729 if [ X
"$USEPIPES" = "Xy" ]; then
2730 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
2731 log error
"Unix pipes not compatible with multiple outputs"
2734 if [ X
"$DONORMALIZE" = "Xy" ]; then
2735 log error
"Unix pipes not compatible with normalizer"
2736 # FIXME # Do we need to exit or shall we just disable the mode?
2739 if [ X
"$BATCHNORM" = "Xy" ]; then
2740 log error
"Unix pipes not compatible with BATCHNORM encoding"
2743 if [ X
"$NOGAP" = "Xy" ]; then
2744 log error
"Unix pipes not compatible with NOGAP encoding"
2747 if [ X
"$DOENCODE" = "Xn" ]; then
2748 vecho warning
"Disabling Unix pipes since we are not encoding!"
2751 if [ X
"$LOWDISK" = "Xy" ]; then
2752 log error
"Unix pipes not compatible with lowdisk algorithm"
2757 # LOWDISK pre-tests, before we get into more problematic stuff
2758 # Not compatible with anything that needs all the files in the hard disc:
2761 if [ X
"$LOWDISK" = "Xy" ]; then
2762 if [ X
"$BATCHNORM" = "Xy" ]; then
2763 log error
"Unix pipes not compatible with BATCHNORM encoding"
2766 if [ X
"$NOGAP" = "Xy" ]; then
2767 log error
"Unix pipes not compatible with NOGAP encoding"
2772 # BATCHNORM pre-tests, before we get into serious problems
2773 # Not compatible with
2774 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
2775 vecho warning
"Disabling BATCHNORM since we are not normalizing!"
2779 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2780 if [ X
"$OUTPUTTYPE" = "X" ]; then
2781 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
2782 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2783 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2784 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
2785 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
2786 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2790 if [ X
"$OUTPUTTYPE" = "X" ]; then
2791 log error
"no encoder found in the PATH"
2792 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
2797 # Decide which CDROM reader we're gonna use
2798 case "$CDROMREADERSYNTAX" in
2800 CDROMREADER
="$CDPARANOIA"
2801 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2804 CDROMREADER
="$CDDA2WAV"
2805 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2808 CDROMREADER
="$DAGRAB"
2809 CDROMREADEROPTS
="$DAGRABOPTS"
2812 CDROMREADER
="$CDDAFS"
2813 CDROMREADEROPTS
="$CDDAFSOPTS"
2817 CDROMREADEROPTS
="$FLACOPTS"
2821 # There's only one normalize...
2822 case "$NORMALIZERSYNTAX" in
2824 NORMALIZER
="$NORMALIZE"
2825 NORMALIZEROPTS
="$NORMALIZEOPTS"
2829 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2830 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
2831 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2833 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2834 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2835 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2836 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2837 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2840 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2841 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2842 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2844 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2847 # 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
2849 # Getting ready for multiple output changes
2850 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2854 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2855 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2856 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2857 OGGOUTPUTCONTAINER
=ogg
2860 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2861 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2862 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN
=y
2865 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2866 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2867 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
2870 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
2871 # [ "$DOREPLAYGAIN" = "y" ] &&
2874 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
2875 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN
=y
2878 if [ "$KEEPWAVS" = "y" ]; then
2879 vecho
"Unsetting the KEEPWAVS option, since the resulting wav files were requested..."
2883 *) log error
"Invalid OUTPUTTYPE defined"
2889 # decide which encoder
2890 case "$MP3ENCODERSYNTAX" in
2892 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2896 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
2897 MP3ENCODER
="$TOOLAME"
2900 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2904 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2905 MP3ENCODER
="$BLADEENC"
2908 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2912 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2913 MP3ENCODER
="$XINGMP3ENC"
2916 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2917 MP3ENCODER
="$MP3ENC"
2920 case "$OGGENCODERSYNTAX" in
2922 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2923 OGGENCODER
="$VORBIZE"
2926 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2927 OGGENCODER
="$OGGENC"
2930 case "$FLACENCODERSYNTAX" in
2932 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2934 # FLAC streams can be encapsulated on a Ogg transport layer
2935 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2936 log error
"FLAC on an Ogg container is not yet supported"
2937 log error
"due to problem with adding comments to such files"
2939 FLACOUTPUTCONTAINER
=ogg
2941 FLACOUTPUTCONTAINER
=flac
2945 case "$SPEEXENCODERSYNTAX" in
2947 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2948 SPEEXENCODER
="$SPEEXENC"
2951 case "$MPPENCODERSYNTAX" in
2953 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2954 MPPENCODER
="$MPPENC"
2960 if [ "$ID3TAGV" = "1" ]; then
2962 TAGGEROPTS
="$ID3OPTS"
2965 TAGGEROPTS
="$ID3V2OPTS"
2968 # Specific for NOGAP is the use of lame. Another encoder fails...
2969 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
2970 log warning
"the NOGAP option is specific of lame. Deactivating..."
2975 case "$CUEREADERSYNTAX" in
2977 CUEREADEROPTS
="${CDROM}"
2982 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2983 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2984 log error
"FLAC on an Ogg container is not yet supported"
2985 log error
"due to problem with adding comments to such files"
2987 OGGOUTPUTCONTAINER
=ogg.ogg
2988 FLACOUTPUTCONTAINER
=flac.ogg
2989 vecho warning
"modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2992 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2994 if [ "$ENCNICE" ]; then
2995 ENCNICE
="-n $ENCNICE"
2997 if [ "$READNICE" ]; then
2998 READNICE
="-n $READNICE"
3000 if [ "$DISTMP3NICE" ]; then
3001 DISTMP3NICE
="-n $DISTMP3NICE"
3004 # Don't check for stuff if it's not needed
3005 if [ "$REMOTEHOSTS" ]; then
3008 if [ "$DONORMALIZE" = "y" ]; then
3011 if [ "$EJECTCD" = "y" ]; then
3014 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
3017 if [ "$MAKECUEFILE" = "y" ]; then
3021 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3022 case "$CDROMREADERSYNTAX" in
3023 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
3024 ### FIXME ### translate "cue2discid" from python to bash
3025 flac
) NEEDMETAFLAC
=y
; NEEDCUE2DISCID
=y
;;
3030 ###USEPIPESSUPPORT###
3032 # Rippers with USEPIPE support
3033 # FIXME # Include here all the rippers we can figure out support pipes
3034 PIPERIPPER_cdparanoia
="-"
3035 PIPERIPPER_debug
="-"
3036 PIPERIPPER_flac
="-c "
3038 # Encoders with USEPIPE support
3039 # FIXME # Include here all the encoders we can figure out support pipes
3045 # Figure out if we can use pipes with the ripper/encoder combination
3047 if [ "$USEPIPES" = "y" ]; then
3048 PIPERIPPERSVARCHECK
="PIPERIPPER_${CDROMREADERSYNTAX}"
3051 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
3053 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
3055 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
3057 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
3059 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
3061 decho
"PIPERIPPERSVARCHECK: $( eval echo "\$
$PIPERIPPERSVARCHECK" )"
3062 if [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "$" ] || \
3063 [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "" ] ; then
3064 log error
"no support for pipes with given ripper"
3065 log error
"read the USEPIPES file from the source tarball to get help."
3066 log error
"On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
3069 decho
"PIPEENCODERSVARCHECK: $( eval echo "\$
$PIPEENCODERSVARCHECK" )"
3070 if [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "$" ] || \
3071 [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "" ] ; then
3072 log error
"no support for pipes with given encoder"
3073 log error
"read the USEPIPES file from the source tarball to help"
3074 log error
"on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
3079 # Make sure a buncha things exist
3080 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
3081 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3082 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3083 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3084 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
3085 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
3086 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
3087 ${NEEDMPPGAIN+$MPPGAIN} \
3088 ${NEEDCUEREADER+$CUEREADER} ${NEEDCUE2DISCID+$CUE2DISCID}
3090 # Cut off the command-line options we just added in
3091 X
=$
(echo $X | cut
-d' ' -f2)
3092 if [ "$(which $X)" = "" ]; then
3093 log error
"$X is not in your path." >&2
3095 elif [ ! -x $
(which $X) ]; then
3096 log error
"$X is not executable." >&2
3101 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
3102 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
3103 HTTPGET
="$HTTPGET $HTTPGETOPTS"
3105 # And last but not least, check if we can diff between files
3106 if [ -x $
(which $DIFF) ]; then :; else
3107 vecho warning
"Disabling diff since we cannot find it in the \$PATH..."
3111 # Here it used to say:
3112 # One thousand lines in, we can start doing stuff with things
3113 # Well, right now we are at line 2736 ;)
3115 # Export needed things so they can be read in this subshell
3116 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
3117 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
3119 # User-definable function to set some things. Use it for
3120 # - closing the CD tray with eject -t
3121 # - set the CD speed value with eject -x
3122 vecho
-n "Executing customizable pre-read function... "
3124 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
3128 do_discid
# Get ABCDETEMPDIR created and status file initialized
3130 if [ "$DOCDDB" = "y" ]; then
3131 if [ $CDDBUSELOCAL = "y" ]; then
3134 if checkstatus cddb-choice
> /dev
/null
; then
3137 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
3145 eval "$($CDDBTOOL parse "$CDDBDATA")"
3148 # Before reading tracks, we set the speed of the device
3150 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3151 case "$CDROMREADERSYNTAX" in
3152 cdparanoia|debug
) ;;
3158 # Define the first and last track, since we might need them later in several places
3159 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
3160 LASTTRACK
=$
( get_last
$TRACKQUEUE )
3162 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
3163 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3164 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
3165 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
3168 # Create playlist if needed (backgroundable) and start reading in tracks
3172 if [ ! "$ONETRACK" = "y" ]; then
3173 if [ "$DOPLAYLIST" = "y" ]; then
3174 echo Creating playlist...
>&2
3179 # For the lowdisk option, only one program is running at once so the encoder
3180 # can be unsilenced right away.
3181 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3182 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3185 if [ "$ONETRACK" = "y" ]; then
3186 TRACKS
="$FIRSTTRACK"
3187 if checkstatus readtrack-
$FIRSTTRACK; then :; else
3188 if [ "$USEPIPES" = "y" ]; then
3189 do_cdread onetrack
$FIRSTTRACK $LASTTRACK | do_encode
$FIRSTTRACK %local0
% > /dev
/null
2>&1
3191 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
3195 for UTRACKNUM
in $TRACKQUEUE
3197 if [ "$DOREAD" = "y" ]; then
3198 if [ "$USEPIPES" = "y" ]; then
3199 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
3200 # Read, pipe, shut up!
3201 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
3204 if checkstatus readtrack-
$UTRACKNUM; then :; else
3205 do_cdread
$UTRACKNUM
3207 if [ "$?" != "0" ]; then
3208 # CD read failed - don't give the goahead to
3215 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ]; then
3218 # If we are not reading, set the encode output to loud already, so
3219 # that we can see the output of the first track.
3220 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
3221 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3223 echo NEXTTRACK
# Get the encoder machine churning again
3224 if [ "$DOREAD" = "y" ]; then
3225 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3226 until checkstatus encodetrack-
$UTRACKNUM
3228 if checkerrors encodetrack-
$UTRACKNUM; then
3239 # Now that we're done the encoding can be loud again -
3240 # if we're not using SMP.
3241 if [ "$MAXPROCS" = "1" ]; then
3242 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3245 # All tracks read, start encoding.
3246 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3250 # Execute the user-defined post_read funtion before ejecting CD
3253 # We are now finished with the cdrom - it can be safely ejected. Note that
3254 # abcde will not have completed yet.
3255 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
3256 # We check if the disk we are processing is actually the disk inside the
3257 # CD tray. If not, we do not eject the CD, since it might be so that the
3258 # user ejected it manually.
3259 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3260 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3261 # More FreeBSD bits.
3262 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
3263 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3264 # but in this script EJECT is in the envionment and names the program
3267 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3268 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3269 $eject $EJECTOPTS $cd
3270 elif [ X
"$(uname)" = X
"Darwin" ] ; then
3271 disktool
-e ${CDROM#/dev/} 0
3273 $EJECT $EJECTOPTS $CDROM
3280 ## Do we need to pre-process
3281 #if [ x"$PREPROCESS" = "x" ] ; then
3284 # for PRETRACKNUM in $TRACKQUEUE
3287 # if [ "$GOAHEAD" = "NO" ]; then break; fi
3289 # until [ $PREPROCEED ]
3291 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3292 # # all locations are working, wait and try again later
3293 # if [ ! $PREPROCEED ]; then sleep 3; fi
3295 # ( do_preprocess $PRETRACKNUM
3303 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
3305 if [ "$BATCHNORM" = "y" ] ||
[ "$NOGAP" = "y" ]; then
3306 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3307 if [ "$GOAHEAD" = "NO" ]; then break; fi
3308 for LASTTRACK
in $TRACKQUEUE; do :; done
3309 if checkstatus readtrack-
$LASTTRACK; then
3310 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
3311 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
3312 if checkerrors batch-normalize
; then exit 1; fi
3314 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
3315 if [ "$DONORMALIZE" = "y" ]; then
3316 for UTRACKNUM
in $TRACKQUEUE
3318 if checkstatus readtrack-
$UTRACKNUM; then
3319 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3323 if checkstatus encodetrack-
$LASTTRACK; then :; else do_nogap_encode
; fi
3324 if checkerrors nogap-encode
; then exit 1; fi
3329 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3330 if [ "$ONETRACK" = "y" ] ; then
3331 TRACKQUEUE
="$FIRSTTRACK"
3332 TRACKS
="$FIRSTTRACK"
3335 # Do the encoding, including parallelization of remote encoding
3336 # Figure out where each track is going to be encoded
3337 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
3338 if [ "$MAXPROCS" != "0" ]; then
3339 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
3341 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
3345 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
3346 for UTRACKNUM
in $TRACKQUEUE
3349 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3350 if [ "$GOAHEAD" = "NO" ]; then break; fi
3351 # find out where this track is to be encoded
3352 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3353 # Make sure we have a place to encode this, if not, exit stage right
3354 if [ -z "$ENCODELOCATIONS" ]; then
3360 for LOCATION
in $ENCODELOCATIONS
3362 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3363 # check first if a track has ever been assigned to this location
3364 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
3365 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3366 if checkerrors encodetrack-
$PREVIOUSTRACK; then
3367 for TEMPLOCATION
in $ENCODELOCATIONS
3369 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3370 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
3373 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
3378 # We're still here, this location must have been previously assigned,
3379 # and last completed without error - check if it's done with the
3380 # previous track yet
3381 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
3383 # all locations are working, wait and try again later
3384 if [ ! $PROCEED ]; then sleep 3; fi
3386 # Record the location we're about to encode the next track at
3387 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3389 # Don't proceed with the rest of the loop if we can't encode
3390 if [ "$ABORT" ]; then continue; fi
3391 # Set TRACKNUM, TRACKNAME
3392 if [ -e "$CDDBDATA" ]; then
3393 if [ "$ONETRACK" = "y" ]; then
3395 TRACKNUM
="$FIRSTTRACK"
3399 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3400 do_getcddbinfo TRACKNAME
3404 # You can't encode a file which needs to be normalized before finishing
3405 # You can't tag a file before it's finished encoding -
3406 # thus all of this is backgrounded together
3408 if [ "$DONORMALIZE" = "y" ]; then
3409 if checkstatus readtrack-
$UTRACKNUM; then
3410 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3413 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3414 if checkstatus readtrack-
$UTRACKNUM; then
3415 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3416 if [ "$DONORMALIZE" = "y" ]; then
3417 if checkstatus normalizetrack-
$UTRACKNUM; then
3418 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3421 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3425 if [ "$DOTAG" = "y" ]; then
3426 if checkstatus encodetrack-
$UTRACKNUM; then
3427 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3429 # Lets tag the cue file
3430 if checkstatus cleancuefile
>/dev
/null
; then :; else
3431 if checkstatus cuefile
>/dev
/null
; then
3436 if [ "$DOMOVE" = "y" ]; then
3437 if checkstatus tagtrack-
$UTRACKNUM; then
3438 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3445 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3446 # we'll delete the files they're working on
3447 ## FIXME ## Check also for files which are encoded using PIPEs.
3448 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3453 for LOCATION
in $ENCODELOCATIONS
3455 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3456 # "How can he give us a status update, if he's DEAD?"
3457 if checkstatus encodetrack-
$CHECKTRACK; then
3460 # Nothing to see here please go quietly back to your homes
3461 if [ -z "$CHECKTRACK" ]; then continue; fi
3462 # You're still here? Maybe there is something...
3463 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3466 if [ ! $PROCEED ]; then sleep 5; fi
3469 # If the above didn't catch the stragglers, this will
3471 if [ "$DOREPLAYGAIN" = "y" ]; then
3475 # Check to see if run_command logged any errors
3476 if [ -f "$ABCDETEMPDIR/errors" ]; then
3477 log error
"The following commands failed to run:"
3478 cat "$ABCDETEMPDIR/errors"
3482 if [ "$KEEPWAVS" = "y" ];then
3486 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
3487 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
3488 ENCODED_FORMATS
=$
(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f2 |
sort -u |
tr '\n' '|')
3489 MOVED_FORMATS
=$
(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f3 |
sort -u |
tr '\n' '|')
3490 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
3491 log warning
"The encoded formats does not match with the moved ones"
3492 log warning
"Formats encoded: $( echo $ENCODED_FORMATS | tr "|
" " " )"
3493 log warning
"Formats moved: $( echo $MOVED_FORMATS | tr "|
" " " )"
3494 log warning
"Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
3498 if [ "$DOCLEAN" = "y" ]; then
3499 # Wipe all the evidence
3500 # Gimme gimme gimme some more time!
3502 rm -rf "$ABCDETEMPDIR"
3505 echo "Finished. Not cleaning $ABCDETEMPDIR."