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.
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform (cddb,read,normalize,encode,tag,move,replaygain,playlist,clean)"
24 #echo "-A Experimental actions (retag, transcode)"
25 echo "-b Enable batch normalization"
26 #echo "-B Disable batch replaygain (do file by file)"
28 echo " Specify a configuration file (overrides system and user config files)"
30 echo " Specify discid to resume from (only needed if you no longer have the cd)"
32 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
33 echo "-D Debugging mode (equivalent to sh -x abcde)"
34 echo "-e Erase encoded track information from status file"
35 #echo "-E Set the encoding information for the tags"
36 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
37 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
38 echo "-h This help information"
39 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
40 echo "-j <#> Number of encoder processes to run at once (localhost)"
41 echo "-k Keep the wav tracks for later use"
42 echo "-l Use low disk space algorithm"
43 echo "-L Use local CDDB storage directory"
44 echo "-n No lookup. Don't query CDDB, just create and use template"
45 echo "-N Noninteractive. Never prompt for anything"
46 echo "-m Modify playlist to include CRLF endings, to comply with some players"
47 echo "-M Create a CUE file"
48 echo "-o <type1[,type2]...>"
49 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav). Defaults to vorbis"
50 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
51 echo "-P Use UNIX pipes to read+encode without wav files"
52 echo "-r <host1[,host2]...>"
53 echo " Also encode on these remote hosts"
54 #echo "-R Add replaygain values to the tag info (only for vorbis,flac,mp3)"
56 echo " Show dielfs from the CDDB info (year,genre)"
57 echo "-S <#> Set the CD speed"
58 echo "-t <#> Start the track numbering at a given number"
59 echo "-T <#> Same as -t but modifies tag numbering"
60 echo "-v Show version number and exit"
61 echo "-V Be a bit more verbose about what is happening behind the scenes"
62 echo "-x Eject CD after all tracks are read"
64 echo " Add a comment to the CD tracks"
65 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
66 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
68 echo "Tracks is a space-delimited list of tracks to grab."
69 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
71 #echo "Double hyphens are used to concatenate tracks"
76 echo "$@" >> "$ABCDETEMPDIR/status"
79 # log [level] [message]
81 # log outputs the right message in a common format
87 error
) echo "[ERR] abcde: $@" >&2 ;;
88 warning
) echo "[WAR] $@" >&2 ;;
89 info
) echo "[INF] $@" ;;
93 # Funtions to replace the need of seq, which is too distribution dependant.
97 while [ $i -ne `expr $2 + 1` ]
107 if echo i |
grep -q "[[:digit:]]" ; then
108 while [ $i -ne `expr $2 + 1` ]
115 log error
"syntax error while processing track numbers"
120 # Functions to replace the need of awk {print $1} and {print $NF}
123 if [ X
"$1" = "X" ]; then
124 for first
in `cat`; do
135 if [ X
"$1" = "X" ]; then
136 for stdin
in `cat`; do
140 for last
in $@
; do :; done
145 # checkstatus [blurb]
146 # Returns "0" if the blurb was found, returns 1 if it wasn't
147 # Puts the blurb content, if available, on stdout.
148 # Otherwise, returns "".
151 # Take the last line in the status file if there's multiple matches
153 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
155 if [ -z "$BLURB" ]; then
160 # See if there's a = in it
161 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
162 echo "$(echo $BLURB | cut -f2- -d=)"
168 # chechwarnings [blurb]
169 # Returns "0" if the blurb was found (meaning there was an warning),
170 # returns 1 if it wasn't (yes this is a little backwards).
171 # Does not print the blurb on stdout.
172 # Otherwise, returns "".
175 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
178 # Take the last line in the status file if there's multiple matches
180 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
182 if [ -z "$BLURB" ]; then
183 # negative, we did not have a negative...
186 # affirmative, we had a negative...
191 # checkerrors [blurb]
192 # Returns "0" if the blurb was found (meaning there was an error),
193 # returns 1 if it wasn't (yes this is a little backwards).
194 # Does not print the blurb on stdout.
195 # Otherwise, returns "".
198 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
201 # Take the last line in the status file if there's multiple matches
203 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
205 if [ -z "$BLURB" ]; then
206 # negative, we did not have a negative...
209 # affirmative, we had a negative...
215 # Finds the right pager in the system to display a file
219 # Use the debian sensible-pager wrapper to pick the pager
220 # user has requested via their $PAGER environment variable
221 if [ -x "/usr/bin/sensible-pager" ]; then
222 /usr
/bin
/sensible-pager
"$PAGEFILE"
223 elif [ -x "$PAGER" ]; then
224 # That failed, try to load the preferred editor, starting
225 # with their PAGER variable
227 # If that fails, check for less
228 elif [ -x /usr
/bin
/less ]; then
229 /usr
/bin
/less -f "$PAGEFILE"
230 # more should be on all UNIX systems
231 elif [ -x /bin
/more ]; then
232 /bin
/more "$PAGEFILE"
234 # No bananas, just cat the thing
239 # run_command [blurb] [command...]
240 # Runs a command, silently if necessary, and updates the status file
245 # See if this is supposed to be silent
246 if [ "$(checkstatus encode-output)" = "loud" ]; then
250 # Special case for SMP, since
251 # encoder output is never displayed, don't mute echos
252 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
261 normalize|normalize-audio
)
262 if [ "$RETURN" = "2" ]; then
263 # File was already normalized.
268 if [ "$RETURN" != "0" ]; then
269 # Put an error in the errors file. For various reasons we
270 # can't capture a copy of the program's output but we can
271 # log what we attempted to execute and the error code
272 # returned by the program.
273 if [ "$BLURB" ]; then
276 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
277 return $RETURN # Do not pass go, do not update the status file
279 if [ "$BLURB" ]; then
280 echo $BLURB >> "$ABCDETEMPDIR/status"
284 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
285 # distributed under the terms of the GNU GPL v2 or later, at your option
287 # Function to determine if a word contains a slash.
296 # Function to give the relative path from one file to another.
297 # Usage: relpath fromfile tofile
298 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
299 # (the result would be Album/Song.mp3)
300 # Output is relative path to $2 from $1 on stdout
302 # This code has the following restrictions:
303 # Multiple ////s are not collapsed into single /s, with strange effects.
304 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
305 # If FR is a directory it must have a trailing /
313 /*) ;; # No processing is needed for absolute paths
315 # Loop through common prefixes, ignoring them.
316 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
318 FR
="$(echo "$FR" | cut -d/ -f2-)"
319 TO
="$(echo "$TO" | cut -d/ -f2-)"
321 # Loop through directory portions left in FR, adding appropriate ../s.
324 FR
="$(echo "$FR" | cut -d/ -f2-)"
334 # Finds an specific field from cddbinfo
336 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
337 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
338 # TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
344 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
347 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
353 # Get the track number we are going to use for different actions
356 if [ -n "$STARTTRACKNUMBER" ] ; then
357 # Get the trackpadding from the current track
358 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
359 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
361 TRACKNUM
=${UTRACKNUM}
367 if checkstatus replaygain
; then :; else
368 run_command
"" echo "Adding replygain information..."
369 for OUTPUT
in $
( echo $OUTPUTTYPE |
tr , \
)
373 OUTPUT
=$OGGOUTPUTCONTAINER
376 OUTPUT
=$FLACOUTPUTCONTAINER
380 for UTRACKNUM
in $TRACKQUEUE
382 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
383 do_getcddbinfo TRACKNAME
385 TRACKFILE
="$(mungefilename "$TRACKNAME")"
386 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
387 ALBUMFILE
="$(mungefilename "$DALBUM")"
389 if [ "$VARIOUSARTISTS" = "y" ]; then
390 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
392 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
394 OUTPUTFILES
="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT $OUTPUTFILES"
398 run_command replaygain-flac
$METAFLAC --add-replay-gain $OUTPUTFILES
401 run_command replaygain-vorbis
$VORBISGAIN --album $OUTPUTFILES
404 run_command replaygain-mp3
$MP3GAIN -a $OUTPUTFILES
409 if checkerrors
"replaygain-.{3,6}"; then :; else
410 run_command replaygain true
415 # This code splits the a Various Artist track name from one of the following
418 # forward: Artist / Track
419 # forward-dash: Artist - Track
420 # reverse: Track / Artist
421 # reverse-dash: Track - Artist
422 # colon: Artist: Track
423 # trailing-paren: Artist (Track)
426 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
429 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
430 case "$VARIOUSARTISTSTYLE" in
432 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
433 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
434 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
437 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
438 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
439 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
442 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
443 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
444 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
447 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
448 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
449 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
452 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's-: -~-g')"
453 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
454 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
457 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
458 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
459 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
462 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
463 TRACKARTIST
="Various"
465 TRACKARTIST
="$DARTIST"
470 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
474 "classic rock") id
=1 ;;
492 "industrial") id
=19 ;;
493 "alternative") id
=20 ;;
495 "death metal") id
=22 ;;
497 "soundtrack") id
=24 ;;
498 "euro-techno") id
=25 ;;
502 "jazz+funk") id
=29 ;;
505 "classical") id
=32 ;;
506 "instrumental") id
=33 ;;
510 "sound clip") id
=37 ;;
513 "alt. rock") id
=40 ;;
518 "meditative") id
=45 ;;
519 "instrum. pop") id
=46 ;;
520 "instrum. rock") id
=47 ;;
524 "techno-indust.") id
=51 ;;
525 "electronic") id
=52 ;;
527 "eurodance") id
=54 ;;
529 "southern rock") id
=56 ;;
534 "christian rap") id
=61 ;;
535 "pop/funk"|
"pop / funk") id
=62 ;;
537 "native american") id
=64 ;;
540 "psychadelic") id
=67 ;;
542 "showtunes") id
=69 ;;
546 "acid punk") id
=73 ;;
547 "acid jazz") id
=74 ;;
551 "rock & roll") id
=78 ;;
552 "hard rock") id
=79 ;;
554 "folk/rock") id
=81 ;;
555 "national folk") id
=82 ;;
562 "bluegrass") id
=89 ;;
563 "avantgarde") id
=90 ;;
564 "gothic rock") id
=91 ;;
565 "progress. rock") id
=92 ;;
566 "psychadel. rock") id
=93 ;;
567 "symphonic rock") id
=94 ;;
568 "slow rock") id
=95 ;;
571 "easy listening") id
=98 ;;
577 "chamber music") id
=104 ;;
579 "symphony") id
=106 ;;
580 "booty bass") id
=107 ;;
582 "porn groove") id
=109 ;;
584 "slow jam") id
=111 ;;
588 "folklore") id
=115 ;;
590 "power ballad") id
=117 ;;
591 "rhythmic soul") id
=118 ;;
592 "freestyle") id
=119 ;;
594 "punk rock") id
=121 ;;
595 "drum solo") id
=122 ;;
596 "a capella") id
=123 ;;
597 "euro-house") id
=124 ;;
598 "dance hall") id
=125 ;;
600 "drum & bass") id
=127 ;;
601 "club-house") id
=128 ;;
602 "hardcore") id
=129 ;;
606 "negerpunk") id
=133 ;;
607 "polsk punk") id
=134 ;;
609 "christian gangsta rap") id
=136 ;;
610 "heavy metal") id
=137 ;;
611 "black metal") id
=138 ;;
612 "crossover") id
=139 ;;
613 "contemporary christian")id
=140 ;;
614 "christian rock") id
=141 ;;
615 "merengue") id
=142 ;;
617 "thrash metal") id
=144 ;;
620 "synthpop") id
=147 ;;
621 "rock/pop"|
"rock / pop") id
=148 ;;
628 # do_tag [tracknumber]
629 # id3 tags a filename
631 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
632 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
635 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
636 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
637 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
638 # If we want to start the tracks with a given number, we need to modify the
639 # TRACKNUM value before evaluation
640 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
643 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
647 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
648 GENREID
=$
(do_getgenreid
"${CDGENRE}")
653 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
654 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
655 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
656 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
657 "${ENCODING:+--set-encoding=$ENCODING}"
658 "$ABCDETEMPDIR/track$1.$OUTPUT"
661 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
662 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
663 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
664 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
665 "$ABCDETEMPDIR/track$1.$OUTPUT"
670 case "$OGGENCODERSYNTAX" in
672 # vorbiscomment can't do in-place modification, mv the file first
673 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
674 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
677 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
678 echo ARTIST
="$TRACKARTIST"
680 echo TITLE
="$TRACKNAME"
681 if [ -n "$CDYEAR" ]; then
684 if [ -n "$CDGENRE" ]; then
685 echo GENRE
="$CDGENRE"
687 echo TRACKNUMBER
=${TRACKNUM:-$1}
688 echo CDDB
=$CDDBDISCID
689 if [ "$(eval echo ${COMMENT})" != "" ]; then
690 case "$COMMENTOUTPUT" in
691 *=*) echo "$COMMENTOUTPUT";;
692 *) echo COMMENT
="$COMMENTOUTPUT";;
695 ) | run_command tagtrack-
$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
696 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
697 # Doublecheck that the commented file was created successfully before wiping the original
698 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
699 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
701 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
708 echo ARTIST
="$TRACKARTIST"
710 echo TITLE
="$TRACKNAME"
711 if [ -n "$CDYEAR" ]; then
714 if [ -n "$CDGENRE" ]; then
715 echo GENRE
="$CDGENRE"
717 echo TRACKNUMBER
="${TRACKNUM:-$1}"
718 echo CDDB
="$CDDBDISCID"
719 if [ "$(eval echo ${COMMENT})" != "" ]; then
720 case "$COMMENTOUTPUT" in
721 *=*) echo "$COMMENTOUTPUT";;
722 *) echo COMMENT
="$COMMENTOUTPUT";;
725 ) | run_command tagtrack-
$OUTPUT-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
728 run_command tagtrack-
$OUTPUT-$1 true
731 run_command tagtrack-
$OUTPUT-$1 true
734 run_command tagtrack-
$OUTPUT-$1 true
738 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
739 run_command tagtrack-
$1 true
746 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
749 # The commands here don't go through run_command because they're never supposed to be silenced
750 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
751 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
755 case "$MP3ENCODERSYNTAX" in
760 for UTRACKNUM
in $TRACKQUEUE
762 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
764 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
766 if [ "$RETURN" != "0" ]; then
767 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
769 for UTRACKNUM
in $TRACKQUEUE
771 run_command encodetrack-
$OUTPUT-$UTRACKNUM true
772 #run_command encodetrack-$UTRACKNUM true
781 if checkerrors
"nogap-encode"; then :; else
782 if [ ! "$KEEPWAVS" = "y" ] ; then
783 if [ ! "$KEEPWAVS" = "move" ] ; then
788 # Other encoders fall through to normal encoding as the tracks
789 # have not been entered in the status file.
792 # do_encode [tracknumber] [hostname]
793 # If no hostname is specified, encode locally
795 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
798 if [ "$USEPIPES" = "y" ]; then
801 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
804 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
807 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
810 TEMPARG
="PIPE_$SPEEXENCODER"
813 TEMPARG
="PIPE_$MPPENCODER"
816 IN
="$( eval echo "\$
$TEMPARG" )"
818 IN
="$ABCDETEMPDIR/track$1.wav"
821 case "$MP3ENCODERSYNTAX" in
822 # FIXME # check if mp3enc needs -if for pipes
823 # FIXME # I have not been able to find a working mp3enc binary
837 # We need IN to proceed, if we are not using pipes.
838 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
839 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
841 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-
$OUTPUT-$1 ; then
846 OUT
="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
849 OUT
="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
852 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
855 if [ X
"$USEPIPES" = "Xy" ]; then
858 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
859 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
865 case "$MP3ENCODERSYNTAX" in
866 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
867 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
868 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
869 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
870 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
874 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
881 case "$OGGENCODERSYNTAX" in
882 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
883 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
887 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
894 case "$FLACENCODERSYNTAX" in
895 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
900 vecho
"$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
901 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
906 if [ "$(eval echo ${COMMENT})" != "" ]; then
909 *) COMMENT
="COMMENT=$COMMENT" ;;
911 COMMENT
="--comment \"$COMMENT\""
913 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
914 if [ ! "$DOTAG" = "y" ]; then
915 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
917 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
921 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
923 # I tried compiling the mppenc from corecodecs.org and got some
924 # errors, so I have not tried it myself.
925 ## FIXME ## Needs some cleanup to determine if an empty tag sent
926 ## FIXME ## to the encoder ends up empty.
927 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
930 # In case of wav output we need nothing. Just keep the wavs.
931 run_command encodetrack-
$OUTPUT-$1 true
935 # Only remove .wav if the encoding succeeded
936 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
937 run_command encodetrack-
$1 true
938 if [ ! "$KEEPWAVS" = "y" ] ; then
939 if [ ! "$KEEPWAVS" = "move" ] ; then
945 run_command
"" echo "HEH! The file we were about to encode disappeared:"
946 run_command
"" echo ">> $IN"
947 run_command encodetrack-
$1 false
951 # do_preprocess [tracknumber]
953 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
956 # IN="$ABCDETEMPDIR/track$1.wav"
957 # # We need IN to proceed.
958 # if [ -s "$IN" ] ; then
959 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
961 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
962 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
963 # case "$POSTPROCESSFORMAT" in
965 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
967 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
969 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
971 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
973 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
976 # # Only remove .wav if the encoding succeeded
977 # if checkerrors "preprocess-(.{3,4})-$1"; then
978 # run_command preprocess-$1 false
980 # run_command preprocess-$1 true
983 # if [ "$(checkstatus encode-output)" = "loud" ]; then
984 # echo "HEH! The file we were about to pre-process disappeared:"
987 # run_command preprocess-$1 false
992 # do_postprocess [tracknumber]
994 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
997 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
999 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1000 # # We need IN to proceed.
1001 # if [ -s "$IN" ] ; then
1002 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1003 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1004 # case "$POSTPROCESSFORMAT" in
1006 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1008 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1010 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1012 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1014 # # Only remove .wav if the encoding succeeded
1015 # if checkerrors "postprocess-(.{3,4})-$1"; then
1016 # run_command postprocess-$1 false
1018 # run_command postprocess-$1 true
1021 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1022 # echo "HEH! The file we were about to post-process disappeared:"
1025 # run_command postprocess-$1 false
1040 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
1044 # The commands here don't go through run_command because they're never supposed to be silenced
1045 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1050 for UTRACKNUM
in $TRACKQUEUE
1052 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1054 # FIXME # Hard-coded batch option!
1055 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1057 if [ "$RETURN" != "0" ]; then
1058 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1060 for UTRACKNUM
in $TRACKQUEUE
1062 echo normalizetrack-
$UTRACKNUM >> status
1068 # do_batch_normalize
1070 # NORMALIZER, NORMALIZEROPTS
1071 do_batch_normalize
()
1073 # The commands here don't go through run_command because they're never supposed to be silenced
1074 echo "Batch normalizing tracks: $TRACKQUEUE"
1079 for UTRACKNUM
in $TRACKQUEUE
1081 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1083 # XXX: Hard-coded batch option!
1084 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1086 if [ "$RETURN" != "0" ]; then
1087 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1089 for UTRACKNUM
in $TRACKQUEUE
1091 echo normalizetrack-
$UTRACKNUM >> status
1097 # do_normalize [tracknumber]
1099 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1102 IN
="$ABCDETEMPDIR/track$1.wav"
1103 if [ -e "$IN" ] ; then
1104 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1105 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1107 if [ "$(checkstatus encode-output)" = "loud" ]; then
1108 echo "HEH! The file we were about to normalize disappeared:"
1111 run_command normalizetrack-
$1 false
"File $IN was not found"
1115 # do_move [tracknumber]
1116 # Deduces the outfile from environment variables
1117 # Creates directory if necessary
1119 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1122 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1124 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1125 # Munge filenames as follows:
1130 # Eat control characters
1131 ALBUMFILE
="$(mungefilename "$DALBUM")"
1132 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1133 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1134 GENRE
="$(mungegenre "$GENRE")"
1135 YEAR
="$(echo $CDYEAR)"
1136 # If we want to start the tracks with a given number, we need to modify the
1137 # TRACKNUM value before evaluation
1139 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1140 # TRACKFILE, and TRACKNUM.
1141 if [ "$VARIOUSARTISTS" = "y" ]; then
1142 OUTPUTFILE
="$(eval echo "$VAOUTPUTFORMAT")"
1144 OUTPUTFILE
="$(eval echo "$OUTPUTFORMAT")"
1146 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1147 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1150 OUTPUT
=$OGGOUTPUTCONTAINER
1153 OUTPUT
=$FLACOUTPUTCONTAINER
1156 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1157 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1160 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1161 # FIXME # introduce warnings?
1164 # mkdir -p shouldn't return an error if the directory already exists
1165 mkdir
-p "$OUTPUTFILEDIR"
1166 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1167 if checkstatus movetrack-output-
$OUTPUT; then :; else
1168 run_command movetrack-output-
$OUTPUT true
1173 # mkdir -p shouldn't return an error if the directory already exists
1174 mkdir
-p "$OUTPUTFILEDIR"
1175 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1176 if checkstatus movetrack-output-
$OUTPUT; then :; else
1177 run_command movetrack-output-
$OUTPUT true
1181 # Lets move the cue file
1182 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1183 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1184 if checkstatus movecue-
$OUTPUT; then :; else
1185 # Silence the Copying output since it overlaps with encoding processes...
1186 #run_command '' vecho "Copying cue file to its destination directory..."
1187 if checkstatus onetrack
>/dev
/null
; then
1190 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1191 # We dont have the dir, since it was not created before.
1194 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1197 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1198 # http://brianvictor.tripod.com/mp3cue.htm#details
1199 [a-z0-9
][a-z0-9
][a-z0-9
])
1200 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1203 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1207 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1209 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1218 # Create the playlist if wanted
1220 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1221 # VARIOUSARTISTS, OUTPUTDIR
1224 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1228 OUTPUT
=$OGGOUTPUTCONTAINER
1231 OUTPUT
=$FLACOUTPUTCONTAINER
1234 # Create a playlist file for the playlist data to go into.
1235 # We used to wipe it out if it existed. Now we request permision if interactive.
1236 for LASTTRACK
in $TRACKQUEUE; do :; done
1237 ALBUMFILE
="$(mungefilename "$DALBUM")"
1238 ARTISTFILE
="$(mungefilename "$DARTIST")"
1239 GENRE
=$
(mungegenre
"$GENRE")
1240 YEAR
=${CDYEAR:-$CDYEAR}
1241 if [ "$VARIOUSARTISTS" = "y" ] ; then
1242 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
1244 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
1246 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1247 mkdir
-p "$FINALPLAYLISTDIR"
1248 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1249 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1250 if [ "$INTERACTIVE" = "y" ]; then
1251 while [ "$DONE" != "y" ]; do
1253 case $ERASEPLAYLIST in
1254 e|E|a|A|k|K
) DONE
=y
;;
1262 # Once we erase the playlist, we use append to create the new one.
1263 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1265 # The playlist does not exist, so we can safelly use append to create the new list
1268 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1269 touch "$OUTPUTDIR/$PLAYLISTFILE"
1270 for UTRACKNUM
in $TRACKQUEUE
1272 # Shares some code with do_move since the filenames have to match
1273 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1274 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1275 do_getcddbinfo TRACKNAME
1277 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1278 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1279 ALBUMFILE
="$(mungefilename "$DALBUM")"
1280 # If we want to start the tracks with a given number, we need to modify the
1281 # TRACKNUM value before evaluation
1283 if [ "$VARIOUSARTISTS" = "y" ]; then
1284 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1286 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1288 if [ "$VARIOUSARTISTS" = "y" ]; then
1289 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1290 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1292 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1295 if [ "$PLAYLISTDATAPREFIX" ]; then
1296 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1298 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1303 ## this will convert the playlist to have CRLF line-endings, if specified
1304 ## (some hardware players insist on CRLF endings)
1305 if [ "$DOSPLAYLIST" = "y" ]; then
1306 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1307 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1308 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1310 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1315 # This essentially the start of things
1318 # Query the CD to get the track info, unless the user specified -C
1319 # or we are using some actions which do not need the CDDB data at all
1320 #if [ ! X"$EXPACTIONS" = "X" ]; then
1322 #elif [ -z "$DISCID" ]; then
1323 if [ -z "$DISCID" ]; then
1324 vecho
-n "Getting CD track info... "
1325 # In OSX, unmount the disc before a query
1326 if [ "$OSFLAVOUR" = "OSX" ]; then
1327 disktool
-u ${CDROM#/dev/}
1329 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1330 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM |
$CUE2DISCID)
1332 TRACKINFO
=$
($CDDISCID $CDROM)
1334 # Make sure there's a CD in there by checking cd-discid's return code
1335 if [ ! "$?" = "0" ]; then
1336 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1337 log error
"cuesheet information from the flac file could not be read."
1338 log error
"Perhaps the flac file does not contain a cuesheet?."
1341 log error
"CD could not be read. Perhaps there's no CD in the drive?"
1345 # In OSX, remount the disc again
1346 if [ "$OSFLAVOUR" = "OSX" ]; then
1347 disktool
-m ${CDROM#/dev/}
1351 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1354 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1355 # This needs to be done now because a section of the resuming code will need
1358 # get the number of digits to pad TRACKNUM with - we'll use this later
1359 # a CD can only hold 99 tracks, but since we support a feature for starting
1360 # numbering the tracks from a given number, we might need to set it as a
1361 # variable for the user to define... or obtain it somehow.
1362 if [ "$PADTRACKS" = "y" ] ; then
1366 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1367 if [ -z "$TRACKQUEUE" ]; then
1368 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1369 case "$CDROMREADERSYNTAX" in
1371 if [ "$WEHAVEACD" = "y" ]; then
1372 vecho
"Querying the CD for audio tracks..."
1373 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1375 if [ ! "$RET" = "0" ];then
1376 log warning
"something went wrong while querying the CD... Maybe a DATA CD?"
1378 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1379 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1381 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1382 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1386 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1389 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1391 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1392 log info
"The disc does not contain any tracks. Giving up..."
1395 echo -n "Grabbing entire CD - tracks: "
1396 if [ ! "$PADTRACKS" = "y" ] ; then
1397 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1399 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1401 while [ "$X" -ne "$TRACKS" ]
1403 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1404 TRACKQUEUE
=$
(echo $TRACKQUEUE $X)
1408 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1409 # User-supplied track queue.
1410 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1411 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1412 # Once cleaned, obtain the highest value in the trackqueue for number padding
1413 for LASTTRACK
in $TRACKQUEUE; do :; done
1414 if [ ! "$PADTRACKS" = "y" ] ; then
1415 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1417 # Now we normalize the trackqueue
1418 for TRACK
in $TRACKQUEUE ; do
1419 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1420 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1422 TRACKQUEUE
=$PADTRACKQUEUE
1423 echo Grabbing tracks
: "$TRACKQUEUE"
1426 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1428 # We have the discid, create a temp directory after it to store all the temp
1431 if [ -e "$ABCDETEMPDIR" ]; then
1432 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1433 # It already exists, see if it's a directory
1434 if [ ! -d "$ABCDETEMPDIR" ]; then
1435 # This is a file/socket/fifo/device/etc, not a directory
1438 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1439 echo "Please investigate, remove it, and rerun abcde." >&2
1443 # It's a directory, let's see if it's owned by us
1444 if [ ! -O "$ABCDETEMPDIR" ]; then
1445 # Nope, complain and exit
1447 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1448 echo "Please investigate, remove it, and rerun abcde." >&2
1452 # See if it's populated
1453 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1454 # Wipe and start fresh
1455 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1456 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1457 if [ "$INTERACTIVE" = "y" ]; then
1463 if [ "$ANSWER" != "y" ]; then
1466 rm -rf "$ABCDETEMPDIR" ||
exit 1
1467 mkdir
"$ABCDETEMPDIR"
1468 if [ "$?" -gt "0" ]; then
1469 # Directory already exists or could not be created
1470 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1474 # Everything is fine. Check for ^encodetracklocation-
1475 # and encode-output entries in the status file and
1476 # remove them. These are not relevant across sessions.
1477 if [ -f "$ABCDETEMPDIR/status" ]; then
1478 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1479 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1480 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1482 # Remove old error messages
1483 if [ -f "$ABCDETEMPDIR/errors" ]; then
1484 rm -f "$ABCDETEMPDIR/errors"
1488 # We are starting from scratch
1489 mkdir
"$ABCDETEMPDIR"
1490 if [ "$?" -gt "0" ]; then
1491 # Directory already exists or could not be created
1492 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1495 cat /dev
/null
> "$ABCDETEMPDIR/status"
1497 if [ X
"$MAKECUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1498 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1499 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1500 vecho
"Creating cue file..."
1501 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1502 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1504 log warning
"reading the CUE sheet with mkcue is still considered experimental"
1505 log warning
"and there was a problem with the CD reading. abcde will continue,"
1506 log warning
"but consider reporting the problem to the abcde author"
1510 # If we got the CDPARANOIA status and it is not recorded, save it now
1511 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1512 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
1513 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1517 # Create the discid file
1518 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1522 # Create a proper CUE file based on the CUE file we created before.
1525 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1526 CUEFILE_OUT
=$CUEFILE_IN.out
1527 ### FIXME ### checkstatus cddb
1528 if [ -e "$CDDBDATA" ]; then
1529 vecho
"Adding metadata to the cue file..."
1530 # FIXME It doesn't preserve spaces! Why?
1531 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1533 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1534 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1535 cat "$CUEFILE_IN" |
while read line
1537 if echo "$line" |
grep -q "INDEX"
1539 eval track
="\$TRACK$n"
1541 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1543 echo "$line" >> "$CUEFILE_OUT"
1545 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1546 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1552 # Parses a CDDB file and outputs the title and the track names.
1553 # Variables: CDDBFILE
1557 # List out disc title/author and contents
1558 if [ "$ONETRACK" = "y" ]; then
1559 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1561 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1562 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1563 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1564 if [ ! X
"$PARSEDYEAR" = "X" ]; then
1565 echo "Year: $PARSEDYEAR"
1568 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1569 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1570 if [ ! X
"$PARSEDGENRE" = "X" ]; then
1571 echo "Genre: $PARSEDGENRE"
1574 if [ ! "$ONETRACK" = "y" ]; then
1575 for TRACK
in $
(f_seq_row
1 $TRACKS)
1577 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1583 # Check for a local CDDB file, and report success
1586 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1588 CDDBLOCALSUCCESS
="n"
1589 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1590 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1593 # If the user has selected to check a local CDDB repo, we proceed with it
1594 if [ -r "${CDDBLOCALFILE}" ]; then
1595 # List out disc title/author and contents
1596 do_cddbparse
"${CDDBLOCALFILE}"
1597 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1598 if [ "$INTERACTIVE" = "y" ]; then
1600 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1601 echo -n 'Invalid selection. Please answer "y" or "n": '
1604 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1608 if [ "$USELOCALRESP" = "y" ]; then
1609 #echo "Using local copy of CDDB data"
1610 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1611 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
1612 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1613 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1614 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1615 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1616 CDDBLOCALSUCCESS
="y"
1618 #echo "Not using local copy of CDDB data"
1619 CDDBLOCALSUCCESS
="n"
1622 CDDBLOCALSUCCESS
="n"
1630 # Perform CDDB protocol version check if it hasn't already been done
1631 if checkstatus cddb-statcomplete
; then :; else
1632 if [ "$CDDBAVAIL" = "n" ]; then
1634 echo 503 > "$ABCDETEMPDIR/cddbstat"
1637 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1638 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1639 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1640 vecho
"Checking CDDB server status..."
1641 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1642 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1643 case "$RESPONSECODE" in
1644 210) # 210 OK, status information follows (until terminating `.')
1647 501|
*) # 501 Illegal CDDB protocol level: <n>.
1648 CDDBPROTO
=`expr $CDDBPROTO - 1`
1652 if test $rc -eq 1; then
1656 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1664 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1665 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1667 # Perform CDDB query if it hasn't already been done
1668 if checkstatus cddb-querycomplete
; then :; else
1669 if [ "$CDDBAVAIL" = "n" ]; then
1671 echo 503 > "$ABCDETEMPDIR/cddbquery"
1672 # The default CDDBLOCALSUCCESS is "n"
1673 # This part will be triggered if the user CDDB repo does not
1674 # contain the entry, or if we are not trying to use the repo.
1676 vecho
"Querying the CDDB server..."
1677 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1678 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1679 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1685 # no match found in database,
1686 # wget/fetch error, or user requested not to use CDDB
1687 # Make up an error code (503) that abcde
1688 # will recognize in do_cddbread
1689 # and compensate by making a template
1690 echo 503 > "$ABCDETEMPDIR/cddbquery"
1692 *) # strange and unknown error
1693 echo ERRORCODE
=$ERRORCODE
1694 echo "abcde: $CDDBTOOL returned unknown error code"
1698 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1705 # If it's not to be used, generate a template.
1706 # Then, display it (or them) and let the user choose/edit it
1707 if checkstatus cddb-readcomplete
; then :; else
1708 vecho
"Obtaining CDDB results..."
1709 # If CDDB is to be used, interpret the query results and read all
1710 # the available entries.
1711 rm -f "$ABCDETEMPDIR/cddbchoices"
1712 CDDBCHOICES
=1 # Overridden by multiple matches
1713 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1714 case "$RESPONSECODE" in
1716 # One exact match, retrieve it
1717 # 200 [section] [discid] [artist] / [title]
1718 if checkstatus cddb-read-1-complete
; then :; else
1719 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1720 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1721 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1722 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1723 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1725 # List out disc title/author and contents
1726 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1727 for TRACK
in $
(f_seq_row
1 $TRACKS)
1729 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1731 echo >> "$ABCDETEMPDIR/cddbchoices"
1735 case "$RESPONSECODE" in
1736 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1737 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1738 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1740 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1741 # List out disc title/author and contents of template
1742 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1744 for TRACK
in $
(f_seq_row
1 $TRACKS)
1746 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1748 echo >> "$ABCDETEMPDIR/cddbchoices"
1749 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1750 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1753 # Multiple exact, (possibly multiple) inexact matches
1755 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1756 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
1757 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1758 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1759 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1761 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1763 vecho
-n "Retrieving multiple matches... "
1764 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1765 read DISCINFO
# eat top line
1769 if checkstatus cddb-read-
$X-complete; then :; else
1770 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1771 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1773 # List out disc title/author and contents
1774 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1775 for TRACK
in $
(f_seq_row
1 $TRACKS)
1777 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1779 echo >> "$ABCDETEMPDIR/cddbchoices"
1782 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1786 for TRACK
in $
(f_seq_row
1 $TRACKS)
1788 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1790 echo >> "$ABCDETEMPDIR/cddbchoices"
1791 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1792 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1795 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1802 if checkstatus cddb-edit
>/dev
/null
; then
1803 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1804 VARIOUSARTISTS
="$(checkstatus variousartists)"
1805 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1808 if [ "$INTERACTIVE" = "y" ]; then
1809 # We should show the CDDB results both when we are not using the local CDDB repo
1810 # or when we are using it but we could not find a proper match
1811 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1812 # Display the $ABCDETEMPDIR/cddbchoices file created above
1813 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1814 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1815 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1816 CHOICE
=$
(checkstatus cddb-choice
)
1817 if [ -n "$CHOICE" ] ; then
1818 case $CDDBCHOICES in
1819 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1821 echo "Selected: #$CHOICE"
1822 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1826 # The user has a choice to make, display the info in a pager if necessary
1827 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1828 page
"$ABCDETEMPDIR/cddbchoices"
1830 # It's all going to fit in one page, cat it
1831 cat "$ABCDETEMPDIR/cddbchoices" >&2
1835 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1837 # I'll take CDDB read #3 for $400, Alex
1838 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1839 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1841 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1842 if echo $CDDBCHOICE |
egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1843 if [ ! X
"$DIFF" = "X" ]; then
1844 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1)
1845 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2)
1846 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1847 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1848 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1849 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1852 # We parse the 2 choices to diff, store them in temporary files and diff them.
1853 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
1854 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1856 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1857 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1858 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
1859 page
"$ABCDETEMPDIR/cddbread.diff"
1861 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1865 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1868 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1869 # Make sure we get a valid choice
1870 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1871 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1875 if [ "$CDCHOICENUM" = "0" ]; then
1876 vecho
"Creating empty CDDB template..."
1878 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1880 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1881 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1883 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1887 # We need some code to show the selected option when local repository is selected and we have found a match
1888 vecho
"Using cached CDDB match..." >&2
1889 # Display the $ABCDETEMPDIR/cddbchoices file created above
1890 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1891 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1892 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1893 CHOICE
=$
(checkstatus cddb-choice
)
1894 if [ "$USELOCALRESP" = "y" ]; then :; else
1895 if [ -n "$CHOICE" ] ; then
1896 case $CDDBCHOICES in
1899 echo "Selected template."
1901 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1903 echo "Selected: #$CHOICE"
1904 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1912 # We're noninteractive - pick the first choice.
1913 # But in case we run a previous instance and selected a choice, use it.
1914 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1915 # Show the choice if we are not using the locally stored one
1916 # or when the local search failed to find a match.
1917 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1918 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1919 #if [ "$PREVIOUSCHOICE" ]; then
1920 cat "$ABCDETEMPDIR/cddbchoices"
1923 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1924 CDCHOICENUM
=$PREVIOUSCHOICE
1927 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1929 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1934 if checkstatus cddb-choice
>/dev
/null
; then :; else
1935 echo "abcde: internal error: cddb-choice not recorded." >&2
1938 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1939 echo -n "Edit selected CDDB data? [y/n] (" >&2
1940 if [ "$INTERACTIVE" = "y" ]; then
1941 if [ "$UNKNOWNDISK" = "y" ]; then
1944 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1953 if [ "$EDITCDDB" = "y" ]; then
1954 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1956 # Use the debian sensible-editor wrapper to pick the editor that the
1957 # user has requested via their $EDITOR environment variable
1958 if [ -x "/usr/bin/sensible-editor" ]; then
1959 /usr
/bin
/sensible-editor
"$CDDBDATA"
1960 elif [ -n "$EDITOR" ]; then
1961 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1962 # That failed, try to load the preferred editor, starting
1963 # with their EDITOR variable
1964 eval $
(echo "$EDITOR") \"$CDDBDATA\"
1966 # If that fails, check for a vi
1967 elif which vi
>/dev
/null
2>&1; then
1969 elif [ -x /usr
/bin
/vim
]; then
1970 /usr
/bin
/vim
"$CDDBDATA"
1971 elif [ -x /usr
/bin
/vi
]; then
1972 /usr
/bin
/vi
"$CDDBDATA"
1973 elif [ -x /bin
/vi
]; then
1975 # nano should be on all (modern, i.e., sarge) debian systems
1976 elif which nano
>/dev
/null
2>&1 ; then
1978 elif [ -x /usr
/bin
/nano
]; then
1979 /usr
/bin
/nano
"$CDDBDATA"
1980 # mg should be on all OpenBSD systems
1981 elif which mg
>/dev
/null
2>&1 ; then
1983 elif [ -x /usr
/bin
/mg
]; then
1984 /usr
/bin
/mg
"$CDDBDATA"
1987 log warning
"no editor available. Check your EDITOR environment variable."
1989 # delete editor backup file if it exists
1990 if [ -w "$CDDBDATA~" ]; then
1995 # Some heuristics first. Look at Disc Title, and if it starts with
1996 # "Various", then we'll assume Various Artists
1997 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1998 echo "Looks like a Multi-Artist CD" >&2
2001 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2002 if [ "$INTERACTIVE" = "y" ]; then
2009 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2012 # Need NUMTRACKS before cddb-tool will return it:
2013 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
2014 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2015 # More than 1/2 tracks contain a "/", so guess forward
2017 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2018 # More than 1/2 contain a "-", so guess forward-dash
2020 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2021 # More than 1/2 contain something in parens, so guess trailing-paren
2025 echo "1) Artist / Title" >&2
2026 echo "2) Artist - Title" >&2
2027 echo "3) Title / Artist" >&2
2028 echo "4) Title - Artist" >&2
2029 echo "5) Artist: Title" >&2
2030 echo "6) Title (Artist)" >&2
2031 echo "7) This is a single-artist CD" >&2
2032 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2033 if [ "$INTERACTIVE" = "y" ]; then
2034 read VARIOUSARTISTSTYLE
2036 echo $DEFAULTSTYLE >&2
2037 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2039 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2040 # If they press Enter, then the default style (0) was chosen
2041 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2042 echo "Invalid selection. Please choose a number between 1 and 7."
2043 echo -n "Selection [1-7]: "
2044 read VARIOUSARTISTSTYLE
2045 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2047 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2048 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2050 vecho
"Selected: $VARIOUSARTISTSTYLE"
2051 case "$VARIOUSARTISTSTYLE" in
2053 VARIOUSARTISTSTYLE
=forward
2056 VARIOUSARTISTSTYLE
=forward-dash
2059 VARIOUSARTISTSTYLE
=reverse
2062 VARIOUSARTISTSTYLE
=reverse-dash
2065 VARIOUSARTISTSTYLE
=colon
2068 VARIOUSARTISTSTYLE
=trailing-paren
2076 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2077 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2079 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2080 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2081 # This works but does not have the necessary error checking
2082 # yet. If you are familiar with the CDDB spec
2083 # (see http://www.freedb.org/src/latest/DBFORMAT)
2084 # and can create an error-free entry on your own, then put
2085 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2086 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2087 # your abcde.conf to change the email address submissions are
2090 # submit the modified file, if they want
2091 if [ "$NOSUBMIT" != "y" ]; then
2092 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2094 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2095 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2097 echo -n 'Invalid selection. Please answer "y" or "n": '
2100 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2101 echo -n "Sending..."
2102 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2108 # Make sure the cache directory exists
2109 mkdir
-p $CDDBLOCALDIR
2110 # Cache edited CDDB entry in the user's cddb dir
2111 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
2112 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2115 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2118 # do_cdread [tracknumber]
2119 # do_cdread onetrack [firsttrack] [lasttrack]
2123 # The commands here don't go through run_command because they're never supposed to be silenced
2124 # return codes need to be doublechecked anyway, however
2125 if [ "$1" = "onetrack" ]; then
2126 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2127 # FIXME # Until then, we grab the whole CD in one track, no matter what
2129 # We need the first and last track for cdda2wav
2132 UTRACKNUM
=$FIRSTTRACK
2133 case "$CDROMREADERSYNTAX" in
2134 ### FIXME ### How are we calculating the tracks in flac mode?
2135 flac
) READTRACKNUMS
="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2136 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
2137 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTRACK" ;;
2138 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
2144 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2145 if [ "$USEPIPES" = "y" ]; then
2146 TEMPARG
="PIPERIPPER_$CDROMREADERSYNTAX"
2147 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2149 PIPE_MESSAGE
="and encoding "
2151 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2152 case "$CDROMREADERSYNTAX" in
2153 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2155 FILEARG
="--output-name=$WAVDATA"
2158 FILEARG
="-f $WAVDATA"
2166 if [ "$1" = "onetrack" ]; then
2167 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2169 if [ -r "$CDDBDATA" ]; then
2170 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
2171 do_getcddbinfo TRACKNAME
2172 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2174 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2177 case "$CDROMREADERSYNTAX" in
2178 ### FIXME ### use an exception for flac, since it uses -o
2179 ### FIXME ### Shall we just use -o $FILEARG ??
2181 nice
$READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2183 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2185 if [ "$OSFLAVOUR" = "OSX" ] ; then
2186 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2187 disktool
-u ${CDROM#/dev/} 0
2188 # Also, in OSX the cdrom device for cdda2wav changes...
2189 CDDA2WAVCDROM
="IODVDServices"
2190 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2191 CDDA2WAVCDROM
="$CDROMID"
2193 if [ "$CDROMID" = "" ]; then
2194 CDDA2WAVCDROM
="$CDROM"
2196 CDDA2WAVCDROM
="$CDROMID"
2199 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2201 ## FIXME ## We have an exception for dagrab, since it uses -f
2202 ## FIXME ## Shall we just use -f $FILEARG ??
2203 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2206 # Find the track's mounted path
2207 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2208 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2209 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2210 # If the file exists, copy it
2211 if [ -e "$FILEPATH" ] ; then
2212 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2216 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2220 # If we get some error or we get some missing wav
2221 # (as long as we dont use pipes)
2222 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2223 # Thank goodness errors is only machine-parseable up to the
2224 # first colon, otherwise this woulda sucked
2225 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2226 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2228 if [ "$USEPIPES" = "y" ]; then
2229 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2231 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2235 if [ "$USEPIPES" = "y" ]; then
2236 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2238 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2239 if [ "$1" = "onetrack" ]; then
2240 echo onetrack
>> "$ABCDETEMPDIR/status"
2247 # No values accepted, only uses env variables
2250 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2251 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2253 echo "abcde: unable to set the device speed" >&2
2259 # vecho outputs a message if EXTRAVERBOSE is selected
2262 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2264 warning
) log warning
"$@" ;;
2272 # decho outputs a debug message if DEBUG is selected
2275 if [ x
"$DEBUG" != "x" ]; then
2276 DEBUGECHO
=$
(echo "$@" |
tr -d '[]')
2277 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2281 # User-redefinable functions
2282 # Custom filename munging:
2285 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2286 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2289 # Custom genre munging:
2292 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2296 # Empty pre_read function, to be defined in the configuration file.
2303 # Empty post_read function, to be defined in the configuration file.
2309 ###############################################################################
2312 # Start of execution
2313 ###############################################################################
2316 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2317 CDDBSUBMIT
=freedb-submit@freedb.org
2319 HELLOINFO
="$(whoami)@$(hostname)"
2321 CDDBLOCALDIR
="$HOME/.cddb"
2324 # List of fields we parse and show during the CDDB parsing...
2325 SHOWCDDBFIELDS
="year,genre"
2328 CDROMREADERSYNTAX
=cdparanoia
2329 ENCODERSYNTAX
=default
2331 MP3ENCODERSYNTAX
=default
2332 OGGENCODERSYNTAX
=default
2333 FLACENCODERSYNTAX
=default
2334 SPEEXENCODERSYNTAX
=default
2335 MPPENCODERSYNTAX
=default
2336 NORMALIZERSYNTAX
=default
2337 CUEREADERSYNTAX
=default
2339 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2340 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2341 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2342 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2343 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2344 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2345 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2346 PLAYLISTDATAPREFIX
=''
2347 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2348 VAPLAYLISTDATAPREFIX
=''
2356 VARIOUSARTISTSTYLE
=forward
2362 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2363 # i.e. CDROMID="1,0,0"
2365 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2366 # If we are using the ide-scsi emulation layer, we need to define a "g"
2367 CDPARANOIACDROMBUS
="d"
2369 # program paths - defaults to checking your $PATH
2376 XINGMP3ENC
=xingmp3enc
2391 CDPARANOIA
=cdparanoia
2400 VORBISCOMMENT
=vorbiscomment
2402 NORMALIZE
=normalize-audio
2404 VORBISGAIN
=vorbisgain
2409 CUE2DISCID
=cue2discid
2411 # Options for programs called from abcde
2444 VORBISCOMMENTOPTS
="-R"
2445 METAFLACOPTS
="--no-utf8-convert"
2447 # Default to one process if -j isn't specified
2450 # List of actions to perform - by default, run to completion
2451 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2453 # List of prefered outputs - by default, run with whatever we have in the path
2454 # This option is basicaly for Debian package dependencies
2455 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
2457 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2458 # Let's use these checkings to determine the OS flavour, which will be used later
2459 if [ X$
(uname
) = "XFreeBSD" ] ; then
2464 elif [ X$
(uname
) = "XDarwin" ] ; then
2467 # We should have disktool in OSX, but let's be sure...
2469 CDROMREADERSYNTAX
=cddafs
2470 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2473 elif [ X$
(uname
) = "XNetBSD" ] ; then
2480 # If CDDBAVAIL is set to n, no CDDB read is done
2481 # If USEID3 is set to n, no ID3 tagging is done
2486 if [ -z "$OUTPUTDIR" ]; then
2490 if [ -z "$WAVOUTPUTDIR" ]; then
2491 WAVOUTPUTDIR
="$OUTPUTDIR"
2494 # Load system defaults
2495 if [ -r /etc
/abcde.conf
]; then
2498 # Load user preference defaults
2499 if [ -r $HOME/.abcde.conf
]; then
2503 # By this time, we need some HTTPGETOPTS already defined.
2504 # If the user has defined a non-default HTTPGET method, we should not be empty.
2506 if [ "$HTTPGETOPTS" = "" ] ; then
2508 wget
) HTTPGETOPTS
="-q -O -";;
2509 curl
) HTTPGETOPTS
="-f -s";;
2510 fetch
)HTTPGETOPTS
="-q -o -";;
2511 ftp) HTTPGETOPTS
="-q -o -";;
2512 *) log warning
"HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
2516 # If the CDROM has not been set yet, find a suitable one.
2517 # If this is a devfs system, default to /dev/cdroms/cdrom0
2518 # instead of /dev/cdrom
2519 if [ "$CDROM" = "" ] ; then
2520 if [ -e /dev
/cdroms
/cdrom0
]; then
2521 CDROM
=/dev
/cdroms
/cdrom0
2522 elif [ -e /dev
/cdrom
]; then
2524 elif [ -e /dev
/cd0c
]; then
2526 elif [ -e /dev
/acd0c
]; then
2528 elif [ -e /dev
/disk1
]; then
2533 # Parse command line options
2534 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2535 while getopts 1a
:bBc
:C
:d
:Defghj
:klLmMnNo
:pPr
:s
:S
:t
:T
:vVxw
:W
:z opt
; do
2538 a
) ACTIONS
="$OPTARG" ;;
2539 A
) EXPACTIONS
="$OPTARG" ;;
2541 B
) NOBATCHREPLAYGAIN
=y
;;
2542 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else log error
"config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
2543 C
) DISCID
="${OPTARG#abcde.}" ;;
2544 d
) CDROM
="$OPTARG" ;;
2546 e
) ERASEENCODEDSTATUS
=y
;;
2548 e
) ERASEENCODEDSTATUS
=y
;;
2549 E
) ENCODING
="$OPTARG" ;;
2553 j
) MAXPROCS
="$OPTARG" ;;
2556 L
) CDDBUSELOCAL
=y
;;
2561 o
) OUTPUTTYPE
="$OPTARG" ;;
2564 r
) REMOTEHOSTS
="$OPTARG" ;;
2565 R
) DOREPLAYGAIN
=y
;;
2566 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2567 S
) CDSPEEDVALUE
="$OPTARG" ;;
2568 # t) PREPROCESSFORMATS="$OPTARG"
2570 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2571 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2572 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2574 echo "This is abcde v$VERSION."
2575 echo "Usage: abcde [options] [tracks]"
2576 echo "abcde -h for extra help"
2579 V
) EXTRAVERBOSE
="y" ;;
2581 w
) COMMENT
="$OPTARG" ;;
2582 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2583 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2585 log error
"argument of -W must be integer"
2589 z
) DEBUG
=y
; CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
2594 shift $
(($OPTIND - 1))
2596 # If the user specified a flac file, then switch to special flac mode
2597 if echo $CDROM |
grep -i -q '.flac$'; then
2598 vecho
"abcde: switching to flac CDROMREADERSYNTAX..."
2599 CDROMREADERSYNTAX
=flac
2600 if [ "$EJECTCD" = "y" ];then
2601 vecho
"abcde: CDROM flac mode, deactivating EJECTCD..."
2606 # Decide if we can continue.
2607 if [ "$ONETRACK" = "y" ]; then
2608 # FIXME # remove check as soon as we find out about the other readers
2609 case "$CDROMREADERSYNTAX" in
2613 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
2616 if [ "$BATCHNORM" = "y" ]; then
2617 log warning
"BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
2620 if [ "$NOGAP" = "y" ]; then
2621 log warning
"NOGAP mode is not compatible with ONETRACK mode. Disabling..."
2624 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2625 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2626 if [ $# -gt 0 ]; then
2627 log warning
"ONETRACK mode selected, grabbing all tracks..."
2630 while [ $# -gt 0 ]; do
2631 # Range parsing code courtesy of Vincent Ho
2632 RSTART
=$
(echo $1 | cut
-f1 -d-)
2633 REND
=$
(echo $1 | cut
-f2 -d-)
2634 if [ "$RSTART" = "$REND" ]; then
2637 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2639 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2644 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2645 # List of experimental actions: retag,transcode
2647 # Determine what actions are to be done from $ACTIONS and set the
2648 # following environment variables for them:
2661 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2666 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2667 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2668 encode
) DOENCODE
=y
; DOREAD
=y
;;
2669 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2670 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2671 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2672 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
2673 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2678 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2679 # FIXME # should we abort on error or just inform the user?
2680 log warning
"selected both normalize and replaygain actions"
2683 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
2684 case $SHOWCDDBFIELD in
2685 y
*|Y
*) SHOWCDDBYEAR
="y";;
2686 g
*|G
*) SHOWCDDBGENRE
="y";;
2693 # At this point a CDROM has to be defined, so we check it exists.
2694 if [ X
"$CDROM" != "X" ] ; then
2695 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2696 if [ "$OSFLAVOUR" = "FBSD" ]; then
2697 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2698 log error
"CDROMID not in the right format for $CDROMREADERSYNTAX"
2699 log error
"Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2703 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2704 log error
"CDROM device cannot be found."
2707 # avoid processing if we are not going to hit the CDROM.
2708 elif [ X
"$DOREAD" = "Xy" ]; then
2709 log error
"CDROM has not been defined or cannot be found"
2713 # USEPIPES pre-tests, before we get into more serious stuff
2714 # Not compatible with:
2715 # - multiple outputs
2717 # - lowdisk algorithm
2719 if [ X
"$USEPIPES" = "Xy" ]; then
2720 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
2721 log error
"Unix pipes not compatible with multiple outputs"
2724 if [ X
"$DONORMALIZE" = "Xy" ]; then
2725 log error
"Unix pipes not compatible with normalizer"
2726 # FIXME # Do we need to exit or shall we just disable the mode?
2729 if [ X
"$BATCHNORM" = "Xy" ]; then
2730 log error
"Unix pipes not compatible with BATCHNORM encoding"
2733 if [ X
"$NOGAP" = "Xy" ]; then
2734 log error
"Unix pipes not compatible with NOGAP encoding"
2737 if [ X
"$DOENCODE" = "Xn" ]; then
2738 vecho warning
"Disabling Unix pipes since we are not encoding!"
2741 if [ X
"$LOWDISK" = "Xy" ]; then
2742 log error
"Unix pipes not compatible with lowdisk algorithm"
2747 # LOWDISK pre-tests, before we get into more problematic stuff
2748 # Not compatible with anything that needs all the files in the hard disc:
2751 if [ X
"$LOWDISK" = "Xy" ]; then
2752 if [ X
"$BATCHNORM" = "Xy" ]; then
2753 log error
"Unix pipes not compatible with BATCHNORM encoding"
2756 if [ X
"$NOGAP" = "Xy" ]; then
2757 log error
"Unix pipes not compatible with NOGAP encoding"
2762 # BATCHNORM pre-tests, before we get into serious problems
2763 # Not compatible with
2764 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
2765 vecho warning
"Disabling BATCHNORM since we are not normalizing!"
2769 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2770 if [ X
"$OUTPUTTYPE" = "X" ]; then
2771 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
2772 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2773 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2774 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
2775 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
2776 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2780 if [ X
"$OUTPUTTYPE" = "X" ]; then
2781 log error
"no encoder found in the PATH"
2782 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
2787 # Decide which CDROM reader we're gonna use
2788 case "$CDROMREADERSYNTAX" in
2790 CDROMREADER
="$CDPARANOIA"
2791 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2794 CDROMREADER
="$CDDA2WAV"
2795 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2798 CDROMREADER
="$DAGRAB"
2799 CDROMREADEROPTS
="$DAGRABOPTS"
2802 CDROMREADER
="$CDDAFS"
2803 CDROMREADEROPTS
="$CDDAFSOPTS"
2807 CDROMREADEROPTS
="$FLACOPTS"
2811 # There's only one normalize...
2812 case "$NORMALIZERSYNTAX" in
2814 NORMALIZER
="$NORMALIZE"
2815 NORMALIZEROPTS
="$NORMALIZEOPTS"
2819 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2820 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
2821 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2823 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2824 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2825 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2826 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2827 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2830 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2831 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2832 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2834 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2837 # 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
2839 # Getting ready for multiple output changes
2840 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2844 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2845 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2846 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2847 OGGOUTPUTCONTAINER
=ogg
2850 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2851 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2852 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN
=y
2855 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2856 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2857 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
2860 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
2863 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
2866 if [ "$KEEPWAVS" = "y" ]; then
2867 vecho
"Unsetting the KEEPWAVS option, since the resulting wav files were requested..."
2871 *) log error
"Invalid OUTPUTTYPE defined"
2877 # decide which encoder
2878 case "$MP3ENCODERSYNTAX" in
2880 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2884 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
2885 MP3ENCODER
="$TOOLAME"
2888 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2892 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2893 MP3ENCODER
="$BLADEENC"
2896 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2900 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2901 MP3ENCODER
="$XINGMP3ENC"
2904 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2905 MP3ENCODER
="$MP3ENC"
2908 case "$OGGENCODERSYNTAX" in
2910 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2911 OGGENCODER
="$VORBIZE"
2914 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2915 OGGENCODER
="$OGGENC"
2918 case "$FLACENCODERSYNTAX" in
2920 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2922 # FLAC streams can be encapsulated on a Ogg transport layer
2923 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2924 log error
"FLAC on an Ogg container is not yet supported"
2925 log error
"due to problem with adding comments to such files"
2927 FLACOUTPUTCONTAINER
=ogg
2929 FLACOUTPUTCONTAINER
=flac
2933 case "$SPEEXENCODERSYNTAX" in
2935 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2936 SPEEXENCODER
="$SPEEXENC"
2939 case "$MPPENCODERSYNTAX" in
2941 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2942 MPPENCODER
="$MPPENC"
2948 if [ "$ID3TAGV" = "1" ]; then
2950 TAGGEROPTS
="$ID3OPTS"
2953 TAGGEROPTS
="$ID3V2OPTS"
2956 # Specific for NOGAP is the use of lame. Another encoder fails...
2957 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
2958 log warning
"the NOGAP option is specific of lame. Deactivating..."
2963 case "$CUEREADERSYNTAX" in
2965 CUEREADEROPTS
="${CDROM}"
2970 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2971 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2972 log error
"FLAC on an Ogg container is not yet supported"
2973 log error
"due to problem with adding comments to such files"
2975 OGGOUTPUTCONTAINER
=ogg.ogg
2976 FLACOUTPUTCONTAINER
=flac.ogg
2977 vecho warning
"modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2980 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2982 if [ "$ENCNICE" ]; then
2983 ENCNICE
="-n $ENCNICE"
2985 if [ "$READNICE" ]; then
2986 READNICE
="-n $READNICE"
2988 if [ "$DISTMP3NICE" ]; then
2989 DISTMP3NICE
="-n $DISTMP3NICE"
2992 # Don't check for stuff if it's not needed
2993 if [ "$REMOTEHOSTS" ]; then
2996 if [ "$DONORMALIZE" = "y" ]; then
2999 if [ "$EJECTCD" = "y" ]; then
3002 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
3005 if [ "$MAKECUEFILE" = "y" ]; then
3009 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3010 case "$CDROMREADERSYNTAX" in
3011 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
3012 ### FIXME ### translate "cue2discid" from python to bash
3013 flac
) NEEDMETAFLAC
=y
; NEEDCUE2DISCID
=y
;;
3018 # Rippers with USEPIPE support
3019 # FIXME # Include here all the rippers we can figure out support pipes
3020 PIPERIPPER_cdparanoia
="-"
3021 PIPERIPPER_flac
="-c "
3023 # Encoders with USEPIPE support
3024 # FIXME # Include here all the encoders we can figure out support pipes
3030 # Figure out if we can use pipes with the ripper/encoder combination
3032 if [ "$USEPIPES" = "y" ]; then
3033 PIPERIPPERSVARCHECK
="PIPERIPPER_${CDROMREADERSYNTAX}"
3036 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
3038 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
3040 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
3042 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
3044 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
3046 if [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "$" ] ; then
3047 log error
"no support for pipes with given ripper"
3048 log error
"read the USEPIPES file from the source tarball to get help."
3049 log error
"On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
3052 if [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "$" ] ; then
3053 log error
"no support for pipes with given encoder"
3054 log error
"read the USEPIPES file from the source tarball to help"
3055 log error
"on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
3060 # Make sure a buncha things exist
3061 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
3062 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3063 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3064 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3065 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
3066 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
3067 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
3068 ${NEEDCUEREADER+$CUEREADER} ${NEEDCUE2DISCID+$CUE2DISCID}
3070 # Cut off the command-line options we just added in
3071 X
=$
(echo $X | cut
-d' ' -f2)
3072 if [ "$(which $X)" = "" ]; then
3073 log error
"$X is not in your path." >&2
3075 elif [ ! -x $
(which $X) ]; then
3076 log error
"$X is not executable." >&2
3081 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
3082 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
3083 HTTPGET
="$HTTPGET $HTTPGETOPTS"
3085 # And last but not least, check if we can diff between files
3086 if [ -x $
(which $DIFF) ]; then :; else
3087 vecho warning
"Disabling diff since we cannot find it in the \$PATH..."
3091 # Here it used to say:
3092 # One thousand lines in, we can start doing stuff with things
3093 # Well, right now we are at line 2736 ;)
3095 # Export needed things so they can be read in this subshell
3096 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
3097 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
3099 # User-definable function to set some things. Use it for
3100 # - closing the CD tray with eject -t
3101 # - set the CD speed value with eject -x
3102 vecho
-n "Executing customizable pre-read function... "
3104 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
3108 do_discid
# Get ABCDETEMPDIR created and status file initialized
3110 if [ "$DOCDDB" = "y" ]; then
3111 if [ $CDDBUSELOCAL = "y" ]; then
3114 if checkstatus cddb-choice
> /dev
/null
; then
3117 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
3125 eval "$($CDDBTOOL parse "$CDDBDATA")"
3128 # Before reading tracks, we set the speed of the device
3130 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3131 case "$CDROMREADERSYNTAX" in
3132 cdparanoia|debug
) ;;
3138 # Define the first and last track, since we might need them later in several places
3139 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
3140 LASTTRACK
=$
( get_last
$TRACKQUEUE )
3142 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
3143 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3144 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
3145 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
3148 # Create playlist if needed (backgroundable) and start reading in tracks
3152 if [ ! "$ONETRACK" = "y" ]; then
3153 if [ "$DOPLAYLIST" = "y" ]; then
3154 echo Creating playlist...
>&2
3159 # For the lowdisk option, only one program is running at once so the encoder
3160 # can be unsilenced right away.
3161 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3162 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3165 if [ "$ONETRACK" = "y" ]; then
3166 TRACKS
="$FIRSTTRACK"
3167 if checkstatus readtrack-
$FIRSTTRACK; then :; else
3168 if [ "$USEPIPES" = "y" ]; then
3169 do_cdread onetrack
$FIRSTTRACK $LASTTRACK | do_encode
$FIRSTTRACK %local0
% > /dev
/null
2>&1
3171 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
3175 for UTRACKNUM
in $TRACKQUEUE
3177 if [ "$DOREAD" = "y" ]; then
3178 if [ "$USEPIPES" = "y" ]; then
3179 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
3180 # Read, pipe, shut up!
3181 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
3184 if checkstatus readtrack-
$UTRACKNUM; then :; else
3185 do_cdread
$UTRACKNUM
3187 if [ "$?" != "0" ]; then
3188 # CD read failed - don't give the goahead to
3195 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ]; then
3198 echo NEXTTRACK
# Get the encoder machine churning again
3199 if [ "$DOREAD" = "y" ]; then
3200 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3201 until checkstatus encodetrack-
$UTRACKNUM
3203 if checkerrors encodetrack-
$UTRACKNUM; then
3214 # Now that we're done the encoding can be loud again -
3215 # if we're not using SMP.
3216 if [ "$MAXPROCS" = "1" ]; then
3217 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3220 # All tracks read, start encoding.
3221 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3225 # Execute the user-defined post_read funtion before ejecting CD
3228 # We are now finished with the cdrom - it can be safely ejected. Note that
3229 # abcde will not have completed yet.
3230 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
3231 # We check if the disk we are processing is actually the disk inside the
3232 # CD tray. If not, we do not eject the CD, since it might be so that the
3233 # user ejected it manually.
3234 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3235 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3236 # More FreeBSD bits.
3237 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
3238 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3239 # but in this script EJECT is in the envionment and names the program
3242 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3243 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3244 $eject $EJECTOPTS $cd
3245 elif [ X
"$(uname)" = X
"Darwin" ] ; then
3246 disktool
-e ${CDROM#/dev/} 0
3248 $EJECT $EJECTOPTS $CDROM
3255 ## Do we need to pre-process
3256 #if [ x"$PREPROCESS" = "x" ] ; then
3259 # for PRETRACKNUM in $TRACKQUEUE
3262 # if [ "$GOAHEAD" = "NO" ]; then break; fi
3264 # until [ $PREPROCEED ]
3266 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3267 # # all locations are working, wait and try again later
3268 # if [ ! $PREPROCEED ]; then sleep 3; fi
3270 # ( do_preprocess $PRETRACKNUM
3278 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
3280 if [ "$BATCHNORM" = "y" ] ||
[ "$NOGAP" = "y" ]; then
3281 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3282 if [ "$GOAHEAD" = "NO" ]; then break; fi
3283 for LASTTRACK
in $TRACKQUEUE; do :; done
3284 if checkstatus readtrack-
$LASTTRACK; then
3285 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
3286 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
3287 if checkerrors batch-normalize
; then exit 1; fi
3289 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
3290 if [ "$DONORMALIZE" = "y" ]; then
3291 for UTRACKNUM
in $TRACKQUEUE
3293 if checkstatus readtrack-
$UTRACKNUM; then
3294 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3298 if checkstatus encodetrack-
$LASTTRACK; then :; else do_nogap_encode
; fi
3299 if checkerrors nogap-encode
; then exit 1; fi
3304 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3305 if [ "$ONETRACK" = "y" ] ; then
3306 TRACKQUEUE
="$FIRSTTRACK"
3307 TRACKS
="$FIRSTTRACK"
3310 # Do the encoding, including parallelization of remote encoding
3311 # Figure out where each track is going to be encoded
3312 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
3313 if [ "$MAXPROCS" != "0" ]; then
3314 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
3316 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
3320 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
3321 for UTRACKNUM
in $TRACKQUEUE
3324 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3325 if [ "$GOAHEAD" = "NO" ]; then break; fi
3326 # find out where this track is to be encoded
3327 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3328 # Make sure we have a place to encode this, if not, exit stage right
3329 if [ -z "$ENCODELOCATIONS" ]; then
3335 for LOCATION
in $ENCODELOCATIONS
3337 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3338 # check first if a track has ever been assigned to this location
3339 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
3340 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3341 if checkerrors encodetrack-
$PREVIOUSTRACK; then
3342 for TEMPLOCATION
in $ENCODELOCATIONS
3344 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3345 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
3348 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
3353 # We're still here, this location must have been previously assigned,
3354 # and last completed without error - check if it's done with the
3355 # previous track yet
3356 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
3358 # all locations are working, wait and try again later
3359 if [ ! $PROCEED ]; then sleep 3; fi
3361 # Record the location we're about to encode the next track at
3362 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3364 # Don't proceed with the rest of the loop if we can't encode
3365 if [ "$ABORT" ]; then continue; fi
3366 # Set TRACKNUM, TRACKNAME
3367 if [ -e "$CDDBDATA" ]; then
3368 if [ "$ONETRACK" = "y" ]; then
3370 TRACKNUM
="$FIRSTTRACK"
3373 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
3375 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3376 #TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
3377 do_getcddbinfo TRACKNAME
3381 # You can't encode a file which needs to be normalized before finishing
3382 # You can't tag a file before it's finished encoding -
3383 # thus all of this is backgrounded together
3385 if [ "$DONORMALIZE" = "y" ]; then
3386 if checkstatus readtrack-
$UTRACKNUM; then
3387 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3390 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3391 if checkstatus readtrack-
$UTRACKNUM; then
3392 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3393 if [ "$DONORMALIZE" = "y" ]; then
3394 if checkstatus normalizetrack-
$UTRACKNUM; then
3395 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3398 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3402 if [ "$DOTAG" = "y" ]; then
3403 if checkstatus encodetrack-
$UTRACKNUM; then
3404 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3406 # Lets tag the cue file
3407 if checkstatus cleancuefile
>/dev
/null
; then :; else
3408 if checkstatus cuefile
>/dev
/null
; then
3413 if [ "$DOMOVE" = "y" ]; then
3414 if checkstatus tagtrack-
$UTRACKNUM; then
3415 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3422 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3423 # we'll delete the files they're working on
3424 ## FIXME ## Check also for files which are encoded using PIPEs.
3425 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3430 for LOCATION
in $ENCODELOCATIONS
3432 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3433 # "How can he give us a status update, if he's DEAD?"
3434 if checkstatus encodetrack-
$CHECKTRACK; then
3437 # Nothing to see here please go quietly back to your homes
3438 if [ -z "$CHECKTRACK" ]; then continue; fi
3439 # You're still here? Maybe there is something...
3440 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3443 if [ ! $PROCEED ]; then sleep 5; fi
3446 # If the above didn't catch the stragglers, this will
3448 if [ "$DOREPLAYGAIN" = "y" ]; then
3451 # Check to see if run_command logged any errors
3452 if [ -f "$ABCDETEMPDIR/errors" ]; then
3453 log error
"The following commands failed to run:"
3454 cat "$ABCDETEMPDIR/errors"
3458 if [ "$KEEPWAVS" = "y" ];then
3462 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
3463 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
3464 ENCODED_FORMATS
=$
(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f2 |
sort -u |
tr '\n' '|')
3465 MOVED_FORMATS
=$
(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f3 |
sort -u |
tr '\n' '|')
3466 decho
[ENCODED_FORMATS
]
3467 decho
[MOVED_FORMATS
]
3468 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
3469 log warning
"Not all encoded formats have been requested to be moved."
3470 log warning
"Use \"-a clean -f -C $DISCID\" to force the removal of the remaining data."
3474 if [ "$DOCLEAN" = "y" ]; then
3475 # Wipe all the evidence
3476 # Gimme gimme gimme some more time!
3478 rm -rf "$ABCDETEMPDIR"
3481 echo "Finished. Not cleaning $ABCDETEMPDIR."