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,playlist,clean)"
24 #echo "-A Experimental actions (retag, transcode)"
25 echo "-b Enable batch normalization"
27 echo " Specify a configuration file (overrides system and user config files)"
29 echo " Specify discid to resume from (only needed if you no longer have the cd)"
31 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
32 echo "-D Debugging mode (equivalent to sh -x abcde)"
33 echo "-e Erase encoded track information from status file"
34 #echo "-E Set the encoding information for the tags"
35 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
36 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
37 echo "-h This help information"
38 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
39 echo "-j <#> Number of encoder processes to run at once (localhost)"
40 echo "-k Keep the wav tracks for later use"
41 echo "-l Use low disk space algorithm"
42 echo "-L Use local CDDB storage directory"
43 echo "-n No lookup. Don't query CDDB, just create and use template"
44 echo "-N Noninteractive. Never prompt for anything"
45 echo "-m Modify playlist to include CRLF endings, to comply with some players"
46 echo "-M Create a CUE file"
47 echo "-o <type1[,type2]...>"
48 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav). Defaults to vorbis"
49 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
50 echo "-P Use UNIX pipes to read+encode without wav files"
51 echo "-r <host1[,host2]...>"
52 echo " Also encode on these remote hosts"
53 echo "-R Add replaygain values to the tag info (only for vorbis,flac)"
55 echo " Show dielfs from the CDDB info (year,genre)"
56 echo "-S <#> Set the CD speed"
57 echo "-t <#> Start the track numbering at a given number"
58 echo "-T <#> Same as -t but modifies tag numbering"
59 echo "-v Show version number and exit"
60 echo "-V Be a bit more verbose about what is happening behind the scenes"
61 echo "-x Eject CD after all tracks are read"
63 echo " Add a comment to the CD tracks"
64 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
65 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
67 echo "Tracks is a space-delimited list of tracks to grab."
68 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
70 #echo "Double hyphens are used to concatenate tracks"
75 echo "$@" >> "$ABCDETEMPDIR/status"
78 # log [level] [message]
80 # log outputs the right message in a common format
86 error
) echo "[ERR] abcde: $@" >&2 ;;
87 warning
) echo "[WAR] $@" >&2 ;;
88 info
) echo "[INF] $@" ;;
92 # Funtions to replace the need of seq, which is too distribution dependant.
96 while [ $i -ne `expr $2 + 1` ]
106 if echo i |
grep -q "[[:digit:]]" ; then
107 while [ $i -ne `expr $2 + 1` ]
114 log error
"syntax error while processing track numbers"
119 # Functions to replace the need of awk {print $1} and {print $NF}
122 if [ X
"$1" = "X" ]; then
123 for first
in `cat`; do
134 if [ X
"$1" = "X" ]; then
135 for stdin
in `cat`; do
139 for last
in $@
; do :; done
144 # checkstatus [blurb]
145 # Returns "0" if the blurb was found, returns 1 if it wasn't
146 # Puts the blurb content, if available, on stdout.
147 # Otherwise, returns "".
150 # Take the last line in the status file if there's multiple matches
152 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
154 if [ -z "$BLURB" ]; then
159 # See if there's a = in it
160 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
161 echo "$(echo $BLURB | cut -f2- -d=)"
167 # chechwarnings [blurb]
168 # Returns "0" if the blurb was found (meaning there was an warning),
169 # returns 1 if it wasn't (yes this is a little backwards).
170 # Does not print the blurb on stdout.
171 # Otherwise, returns "".
174 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
177 # Take the last line in the status file if there's multiple matches
179 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
181 if [ -z "$BLURB" ]; then
182 # negative, we did not have a negative...
185 # affirmative, we had a negative...
190 # checkerrors [blurb]
191 # Returns "0" if the blurb was found (meaning there was an error),
192 # returns 1 if it wasn't (yes this is a little backwards).
193 # Does not print the blurb on stdout.
194 # Otherwise, returns "".
197 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
200 # Take the last line in the status file if there's multiple matches
202 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
204 if [ -z "$BLURB" ]; then
205 # negative, we did not have a negative...
208 # affirmative, we had a negative...
214 # Finds the right pager in the system to display a file
218 # Use the debian sensible-pager wrapper to pick the pager
219 # user has requested via their $PAGER environment variable
220 if [ -x "/usr/bin/sensible-pager" ]; then
221 /usr
/bin
/sensible-pager
"$PAGEFILE"
222 elif [ -x "$PAGER" ]; then
223 # That failed, try to load the preferred editor, starting
224 # with their PAGER variable
226 # If that fails, check for less
227 elif [ -x /usr
/bin
/less ]; then
228 /usr
/bin
/less -f "$PAGEFILE"
229 # more should be on all UNIX systems
230 elif [ -x /bin
/more ]; then
231 /bin
/more "$PAGEFILE"
233 # No bananas, just cat the thing
238 # run_command [blurb] [command...]
239 # Runs a command, silently if necessary, and updates the status file
244 # See if this is supposed to be silent
245 if [ "$(checkstatus encode-output)" = "loud" ]; then
249 # Special case for SMP, since
250 # encoder output is never displayed, don't mute echos
251 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
260 normalize|normalize-audio
)
261 if [ "$RETURN" = "2" ]; then
262 # File was already normalized.
267 if [ "$RETURN" != "0" ]; then
268 # Put an error in the errors file. For various reasons we
269 # can't capture a copy of the program's output but we can
270 # log what we attempted to execute and the error code
271 # returned by the program.
272 if [ "$BLURB" ]; then
275 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
276 return $RETURN # Do not pass go, do not update the status file
278 if [ "$BLURB" ]; then
279 echo $BLURB >> "$ABCDETEMPDIR/status"
283 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
284 # distributed under the terms of the GNU GPL v2 or later, at your option
286 # Function to determine if a word contains a slash.
295 # Function to give the relative path from one file to another.
296 # Usage: relpath fromfile tofile
297 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
298 # (the result would be Album/Song.mp3)
299 # Output is relative path to $2 from $1 on stdout
301 # This code has the following restrictions:
302 # Multiple ////s are not collapsed into single /s, with strange effects.
303 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
304 # If FR is a directory it must have a trailing /
312 /*) ;; # No processing is needed for absolute paths
314 # Loop through common prefixes, ignoring them.
315 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
317 FR
="$(echo "$FR" | cut -d/ -f2-)"
318 TO
="$(echo "$TO" | cut -d/ -f2-)"
320 # Loop through directory portions left in FR, adding appropriate ../s.
323 FR
="$(echo "$FR" | cut -d/ -f2-)"
333 # Finds an specific field from cddbinfo
335 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
336 # TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
337 # TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
343 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
346 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
352 # Get the track number we are going to use for different actions
355 if [ -n "$STARTTRACKNUMBER" ] ; then
356 # Get the trackpadding from the current track
357 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
358 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
360 TRACKNUM
=${UTRACKNUM}
366 if checkstatus replaygain
; then :; else
367 run_command
"" echo "Adding replygain information..."
368 for OUTPUT
in $
( echo $OUTPUTTYPE |
tr , \
)
369 # THE OUTPUT NEEDS TO BE CORRECTED WITH THE CONTAINER?
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
406 if checkerrors replaygain-.
{3,6}; then :; else
407 run_command replaygain true
412 # This code splits the a Various Artist track name from one of the following
415 # forward: Artist / Track
416 # forward-dash: Artist - Track
417 # reverse: Track / Artist
418 # reverse-dash: Track - Artist
419 # colon: Artist: Track
420 # trailing-paren: Artist (Track)
423 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
426 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
427 case "$VARIOUSARTISTSTYLE" in
429 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
430 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
431 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
434 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
435 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
436 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
439 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's- / -~-g')"
440 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
441 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
444 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
445 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
446 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
449 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's-: -~-g')"
450 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
451 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
454 DTITLEARTIST
="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
455 TRACKARTIST
="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
456 TRACKNAME
="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
459 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
460 TRACKARTIST
="Various"
462 TRACKARTIST
="$DARTIST"
467 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
471 "classic rock") id
=1 ;;
489 "industrial") id
=19 ;;
490 "alternative") id
=20 ;;
492 "death metal") id
=22 ;;
494 "soundtrack") id
=24 ;;
495 "euro-techno") id
=25 ;;
499 "jazz+funk") id
=29 ;;
502 "classical") id
=32 ;;
503 "instrumental") id
=33 ;;
507 "sound clip") id
=37 ;;
510 "alt. rock") id
=40 ;;
515 "meditative") id
=45 ;;
516 "instrum. pop") id
=46 ;;
517 "instrum. rock") id
=47 ;;
521 "techno-indust.") id
=51 ;;
522 "electronic") id
=52 ;;
524 "eurodance") id
=54 ;;
526 "southern rock") id
=56 ;;
531 "christian rap") id
=61 ;;
532 "pop/funk"|
"pop / funk") id
=62 ;;
534 "native american") id
=64 ;;
537 "psychadelic") id
=67 ;;
539 "showtunes") id
=69 ;;
543 "acid punk") id
=73 ;;
544 "acid jazz") id
=74 ;;
548 "rock & roll") id
=78 ;;
549 "hard rock") id
=79 ;;
551 "folk/rock") id
=81 ;;
552 "national folk") id
=82 ;;
559 "bluegrass") id
=89 ;;
560 "avantgarde") id
=90 ;;
561 "gothic rock") id
=91 ;;
562 "progress. rock") id
=92 ;;
563 "psychadel. rock") id
=93 ;;
564 "symphonic rock") id
=94 ;;
565 "slow rock") id
=95 ;;
568 "easy listening") id
=98 ;;
574 "chamber music") id
=104 ;;
576 "symphony") id
=106 ;;
577 "booty bass") id
=107 ;;
579 "porn groove") id
=109 ;;
581 "slow jam") id
=111 ;;
585 "folklore") id
=115 ;;
587 "power ballad") id
=117 ;;
588 "rhythmic soul") id
=118 ;;
589 "freestyle") id
=119 ;;
591 "punk rock") id
=121 ;;
592 "drum solo") id
=122 ;;
593 "a capella") id
=123 ;;
594 "euro-house") id
=124 ;;
595 "dance hall") id
=125 ;;
597 "drum & bass") id
=127 ;;
598 "club-house") id
=128 ;;
599 "hardcore") id
=129 ;;
603 "negerpunk") id
=133 ;;
604 "polsk punk") id
=134 ;;
606 "christian gangsta rap") id
=136 ;;
607 "heavy metal") id
=137 ;;
608 "black metal") id
=138 ;;
609 "crossover") id
=139 ;;
610 "contemporary christian")id
=140 ;;
611 "christian rock") id
=141 ;;
612 "merengue") id
=142 ;;
614 "thrash metal") id
=144 ;;
617 "synthpop") id
=147 ;;
618 "rock/pop"|
"rock / pop") id
=148 ;;
625 # do_tag [tracknumber]
626 # id3 tags a filename
628 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
629 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
632 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
633 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
634 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
635 # If we want to start the tracks with a given number, we need to modify the
636 # TRACKNUM value before evaluation
637 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
640 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
644 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
645 GENREID
=$
(do_getgenreid
"${CDGENRE}")
650 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
651 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
652 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
653 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
654 "${ENCODING:+--set-encoding=$ENCODING}"
655 "$ABCDETEMPDIR/track$1.$OUTPUT"
658 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
659 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
660 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
661 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
662 "$ABCDETEMPDIR/track$1.$OUTPUT"
667 case "$OGGENCODERSYNTAX" in
669 # vorbiscomment can't do in-place modification, mv the file first
670 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
671 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
674 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
675 echo ARTIST
="$TRACKARTIST"
677 echo TITLE
="$TRACKNAME"
678 if [ -n "$CDYEAR" ]; then
681 if [ -n "$CDGENRE" ]; then
682 echo GENRE
="$CDGENRE"
684 echo TRACKNUMBER
=${TRACKNUM:-$1}
685 echo CDDB
=$CDDBDISCID
686 if [ "$(eval echo ${COMMENT})" != "" ]; then
687 case "$COMMENTOUTPUT" in
688 *=*) echo "$COMMENTOUTPUT";;
689 *) echo COMMENT
="$COMMENTOUTPUT";;
692 ) | run_command tagtrack-
$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
693 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
694 # Doublecheck that the commented file was created successfully before wiping the original
695 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
696 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
698 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
705 echo ARTIST
="$TRACKARTIST"
707 echo TITLE
="$TRACKNAME"
708 if [ -n "$CDYEAR" ]; then
711 if [ -n "$CDGENRE" ]; then
712 echo GENRE
="$CDGENRE"
714 echo TRACKNUMBER
="${TRACKNUM:-$1}"
715 echo CDDB
="$CDDBDISCID"
716 if [ "$(eval echo ${COMMENT})" != "" ]; then
717 case "$COMMENTOUTPUT" in
718 *=*) echo "$COMMENTOUTPUT";;
719 *) echo COMMENT
="$COMMENTOUTPUT";;
722 ) | run_command tagtrack-
$OUTPUT-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
725 run_command tagtrack-
$OUTPUT-$1 true
728 run_command tagtrack-
$OUTPUT-$1 true
731 run_command tagtrack-
$OUTPUT-$1 true
735 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
736 run_command tagtrack-
$1 true
743 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
746 # The commands here don't go through run_command because they're never supposed to be silenced
747 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
748 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
752 case "$MP3ENCODERSYNTAX" in
757 for UTRACKNUM
in $TRACKQUEUE
759 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
761 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
763 if [ "$RETURN" != "0" ]; then
764 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
766 for UTRACKNUM
in $TRACKQUEUE
768 run_command encodetrack-
$OUTPUT-$UTRACKNUM true
769 #run_command encodetrack-$UTRACKNUM true
778 if checkerrors
"nogap-encode"; then :; else
779 if [ ! "$KEEPWAVS" = "y" ] ; then
780 if [ ! "$KEEPWAVS" = "move" ] ; then
785 # Other encoders fall through to normal encoding as the tracks
786 # have not been entered in the status file.
789 # do_encode [tracknumber] [hostname]
790 # If no hostname is specified, encode locally
792 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
795 if [ "$USEPIPES" = "y" ]; then
798 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
801 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
804 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
807 TEMPARG
="PIPE_$SPEEXENCODER"
810 TEMPARG
="PIPE_$MPPENCODER"
813 IN
="$( eval echo "\$
$TEMPARG" )"
815 IN
="$ABCDETEMPDIR/track$1.wav"
818 case "$MP3ENCODERSYNTAX" in
819 # FIXME # check if mp3enc needs -if for pipes
820 # FIXME # I have not been able to find a working mp3enc binary
834 # We need IN to proceed, if we are not using pipes.
835 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
836 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
838 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-
$OUTPUT-$1 ; then
843 OUT
="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
846 OUT
="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
849 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
852 if [ X
"$USEPIPES" = "Xy" ]; then
855 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
856 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
862 case "$MP3ENCODERSYNTAX" in
863 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
864 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
865 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
866 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
867 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
871 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
878 case "$OGGENCODERSYNTAX" in
879 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
880 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
884 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
891 case "$FLACENCODERSYNTAX" in
892 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
897 vecho
"$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
898 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
903 if [ "$(eval echo ${COMMENT})" != "" ]; then
906 *) COMMENT
="COMMENT=$COMMENT" ;;
908 COMMENT
="--comment \"$COMMENT\""
910 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
911 if [ ! "$DOTAG" = "y" ]; then
912 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
914 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
918 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
920 # I tried compiling the mppenc from corecodecs.org and got some
921 # errors, so I have not tried it myself.
922 ## FIXME ## Needs some cleanup to determine if an empty tag sent
923 ## FIXME ## to the encoder ends up empty.
924 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
927 # In case of wav output we need nothing. Just keep the wavs.
928 run_command encodetrack-
$OUTPUT-$1 true
932 # Only remove .wav if the encoding succeeded
933 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
934 run_command encodetrack-
$1 true
935 if [ ! "$KEEPWAVS" = "y" ] ; then
936 if [ ! "$KEEPWAVS" = "move" ] ; then
942 run_command
"" echo "HEH! The file we were about to encode disappeared:"
943 run_command
"" echo ">> $IN"
944 run_command encodetrack-
$1 false
948 # do_preprocess [tracknumber]
950 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
953 # IN="$ABCDETEMPDIR/track$1.wav"
954 # # We need IN to proceed.
955 # if [ -s "$IN" ] ; then
956 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
958 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
959 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
960 # case "$POSTPROCESSFORMAT" in
962 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
964 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
966 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
968 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
970 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
973 # # Only remove .wav if the encoding succeeded
974 # if checkerrors "preprocess-(.{3,4})-$1"; then
975 # run_command preprocess-$1 false
977 # run_command preprocess-$1 true
980 # if [ "$(checkstatus encode-output)" = "loud" ]; then
981 # echo "HEH! The file we were about to pre-process disappeared:"
984 # run_command preprocess-$1 false
989 # do_postprocess [tracknumber]
991 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
994 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
996 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
997 # # We need IN to proceed.
998 # if [ -s "$IN" ] ; then
999 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1000 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1001 # case "$POSTPROCESSFORMAT" in
1003 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1005 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1007 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1009 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1011 # # Only remove .wav if the encoding succeeded
1012 # if checkerrors "postprocess-(.{3,4})-$1"; then
1013 # run_command postprocess-$1 false
1015 # run_command postprocess-$1 true
1018 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1019 # echo "HEH! The file we were about to post-process disappeared:"
1022 # run_command postprocess-$1 false
1037 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
1041 # The commands here don't go through run_command because they're never supposed to be silenced
1042 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1047 for UTRACKNUM
in $TRACKQUEUE
1049 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1051 # FIXME # Hard-coded batch option!
1052 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1054 if [ "$RETURN" != "0" ]; then
1055 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1057 for UTRACKNUM
in $TRACKQUEUE
1059 echo normalizetrack-
$UTRACKNUM >> status
1065 # do_batch_normalize
1067 # NORMALIZER, NORMALIZEROPTS
1068 do_batch_normalize
()
1070 # The commands here don't go through run_command because they're never supposed to be silenced
1071 echo "Batch normalizing tracks: $TRACKQUEUE"
1076 for UTRACKNUM
in $TRACKQUEUE
1078 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1080 # XXX: Hard-coded batch option!
1081 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1083 if [ "$RETURN" != "0" ]; then
1084 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1086 for UTRACKNUM
in $TRACKQUEUE
1088 echo normalizetrack-
$UTRACKNUM >> status
1094 # do_normalize [tracknumber]
1096 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1099 IN
="$ABCDETEMPDIR/track$1.wav"
1100 if [ -e "$IN" ] ; then
1101 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1102 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1104 if [ "$(checkstatus encode-output)" = "loud" ]; then
1105 echo "HEH! The file we were about to normalize disappeared:"
1108 run_command normalizetrack-
$1 false
"File $IN was not found"
1112 # do_move [tracknumber]
1113 # Deduces the outfile from environment variables
1114 # Creates directory if necessary
1116 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1119 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1121 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1122 # Munge filenames as follows:
1127 # Eat control characters
1128 ALBUMFILE
="$(mungefilename "$DALBUM")"
1129 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1130 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1131 GENRE
="$(mungegenre "$GENRE")"
1132 YEAR
="$(echo $CDYEAR)"
1133 # If we want to start the tracks with a given number, we need to modify the
1134 # TRACKNUM value before evaluation
1136 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1137 # TRACKFILE, and TRACKNUM.
1138 if [ "$VARIOUSARTISTS" = "y" ]; then
1139 OUTPUTFILE
="$(eval echo "$VAOUTPUTFORMAT")"
1141 OUTPUTFILE
="$(eval echo "$OUTPUTFORMAT")"
1143 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1144 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1147 OUTPUT
=$OGGOUTPUTCONTAINER
1150 OUTPUT
=$FLACOUTPUTCONTAINER
1153 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1154 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1157 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1158 # FIXME # introduce warnings?
1161 # mkdir -p shouldn't return an error if the directory already exists
1162 mkdir
-p "$OUTPUTFILEDIR"
1163 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1164 if checkstatus movetrack-output-
$OUTPUT; then :; else
1165 run_command movetrack-output-
$OUTPUT true
1170 # mkdir -p shouldn't return an error if the directory already exists
1171 mkdir
-p "$OUTPUTFILEDIR"
1172 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1173 if checkstatus movetrack-output-
$OUTPUT; then :; else
1174 run_command movetrack-output-
$OUTPUT true
1178 # Lets move the cue file
1179 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1180 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1181 if checkstatus movecue-
$OUTPUT; then :; else
1182 # Silence the Copying output since it overlaps with encoding processes...
1183 #run_command '' vecho "Copying cue file to its destination directory..."
1184 if checkstatus onetrack
>/dev
/null
; then
1187 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1188 # We dont have the dir, since it was not created before.
1191 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1194 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1195 # http://brianvictor.tripod.com/mp3cue.htm#details
1196 [a-z0-9
][a-z0-9
][a-z0-9
])
1197 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1200 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1204 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1206 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1215 # Create the playlist if wanted
1217 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1218 # VARIOUSARTISTS, OUTPUTDIR
1221 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1225 OUTPUT
=$OGGOUTPUTCONTAINER
1228 OUTPUT
=$FLACOUTPUTCONTAINER
1231 # Create a playlist file for the playlist data to go into.
1232 # We used to wipe it out if it existed. Now we request permision if interactive.
1233 for LASTTRACK
in $TRACKQUEUE; do :; done
1234 ALBUMFILE
="$(mungefilename "$DALBUM")"
1235 ARTISTFILE
="$(mungefilename "$DARTIST")"
1236 GENRE
=$
(mungegenre
"$GENRE")
1237 YEAR
=${CDYEAR:-$CDYEAR}
1238 if [ "$VARIOUSARTISTS" = "y" ] ; then
1239 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
1241 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
1243 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1244 mkdir
-p "$FINALPLAYLISTDIR"
1245 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1246 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1247 if [ "$INTERACTIVE" = "y" ]; then
1248 while [ "$DONE" != "y" ]; do
1250 case $ERASEPLAYLIST in
1251 e|E|a|A|k|K
) DONE
=y
;;
1259 # Once we erase the playlist, we use append to create the new one.
1260 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1262 # The playlist does not exist, so we can safelly use append to create the new list
1265 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1266 touch "$OUTPUTDIR/$PLAYLISTFILE"
1267 for UTRACKNUM
in $TRACKQUEUE
1269 # Shares some code with do_move since the filenames have to match
1270 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1271 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1272 do_getcddbinfo TRACKNAME
1274 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1275 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1276 ALBUMFILE
="$(mungefilename "$DALBUM")"
1277 # If we want to start the tracks with a given number, we need to modify the
1278 # TRACKNUM value before evaluation
1280 if [ "$VARIOUSARTISTS" = "y" ]; then
1281 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1283 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1285 if [ "$VARIOUSARTISTS" = "y" ]; then
1286 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1287 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1289 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1292 if [ "$PLAYLISTDATAPREFIX" ]; then
1293 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1295 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1300 ## this will convert the playlist to have CRLF line-endings, if specified
1301 ## (some hardware players insist on CRLF endings)
1302 if [ "$DOSPLAYLIST" = "y" ]; then
1303 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1304 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1305 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1307 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1312 # This essentially the start of things
1315 # Query the CD to get the track info, unless the user specified -C
1316 # or we are using some actions which do not need the CDDB data at all
1317 #if [ ! X"$EXPACTIONS" = "X" ]; then
1319 #elif [ -z "$DISCID" ]; then
1320 if [ -z "$DISCID" ]; then
1321 vecho
-n "Getting CD track info... "
1322 # In OSX, unmount the disc before a query
1323 if [ "$OSFLAVOUR" = "OSX" ]; then
1324 disktool
-u ${CDROM#/dev/}
1326 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1327 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM |
$CUE2DISCID)
1329 TRACKINFO
=$
($CDDISCID $CDROM)
1331 # Make sure there's a CD in there by checking cd-discid's return code
1332 if [ ! "$?" = "0" ]; then
1333 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1334 log error
"cuesheet information from the flac file could not be read."
1335 log error
"Perhaps the flac file does not contain a cuesheet?."
1338 log error
"CD could not be read. Perhaps there's no CD in the drive?"
1342 # In OSX, remount the disc again
1343 if [ "$OSFLAVOUR" = "OSX" ]; then
1344 disktool
-m ${CDROM#/dev/}
1348 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1351 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1352 # This needs to be done now because a section of the resuming code will need
1355 # get the number of digits to pad TRACKNUM with - we'll use this later
1356 # a CD can only hold 99 tracks, but since we support a feature for starting
1357 # numbering the tracks from a given number, we might need to set it as a
1358 # variable for the user to define... or obtain it somehow.
1359 if [ "$PADTRACKS" = "y" ] ; then
1363 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1364 if [ -z "$TRACKQUEUE" ]; then
1365 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1366 case "$CDROMREADERSYNTAX" in
1368 if [ "$WEHAVEACD" = "y" ]; then
1369 vecho
"Querying the CD for audio tracks..."
1370 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1372 if [ ! "$RET" = "0" ];then
1373 log warning
"something went wrong while querying the CD... Maybe a DATA CD?"
1375 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1376 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1378 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1379 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1383 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1386 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1388 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1389 log info
"The disc does not contain any tracks. Giving up..."
1392 echo -n "Grabbing entire CD - tracks: "
1393 if [ ! "$PADTRACKS" = "y" ] ; then
1394 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1396 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1398 while [ "$X" -ne "$TRACKS" ]
1400 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1401 TRACKQUEUE
=$
(echo $TRACKQUEUE $X)
1405 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1406 # User-supplied track queue.
1407 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1408 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1409 # Once cleaned, obtain the highest value in the trackqueue for number padding
1410 for LASTTRACK
in $TRACKQUEUE; do :; done
1411 if [ ! "$PADTRACKS" = "y" ] ; then
1412 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1414 # Now we normalize the trackqueue
1415 for TRACK
in $TRACKQUEUE ; do
1416 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1417 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1419 TRACKQUEUE
=$PADTRACKQUEUE
1420 echo Grabbing tracks
: "$TRACKQUEUE"
1423 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1425 # We have the discid, create a temp directory after it to store all the temp
1428 if [ -e "$ABCDETEMPDIR" ]; then
1429 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1430 # It already exists, see if it's a directory
1431 if [ ! -d "$ABCDETEMPDIR" ]; then
1432 # This is a file/socket/fifo/device/etc, not a directory
1435 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1436 echo "Please investigate, remove it, and rerun abcde." >&2
1440 # It's a directory, let's see if it's owned by us
1441 if [ ! -O "$ABCDETEMPDIR" ]; then
1442 # Nope, complain and exit
1444 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1445 echo "Please investigate, remove it, and rerun abcde." >&2
1449 # See if it's populated
1450 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1451 # Wipe and start fresh
1452 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1453 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1454 if [ "$INTERACTIVE" = "y" ]; then
1460 if [ "$ANSWER" != "y" ]; then
1463 rm -rf "$ABCDETEMPDIR" ||
exit 1
1464 mkdir
"$ABCDETEMPDIR"
1465 if [ "$?" -gt "0" ]; then
1466 # Directory already exists or could not be created
1467 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1471 # Everything is fine. Check for ^encodetracklocation-
1472 # and encode-output entries in the status file and
1473 # remove them. These are not relevant across sessions.
1474 if [ -f "$ABCDETEMPDIR/status" ]; then
1475 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1476 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1477 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1479 # Remove old error messages
1480 if [ -f "$ABCDETEMPDIR/errors" ]; then
1481 rm -f "$ABCDETEMPDIR/errors"
1485 # We are starting from scratch
1486 mkdir
"$ABCDETEMPDIR"
1487 if [ "$?" -gt "0" ]; then
1488 # Directory already exists or could not be created
1489 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1492 cat /dev
/null
> "$ABCDETEMPDIR/status"
1494 if [ X
"$MAKECUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1495 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1496 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1497 vecho
"Creating cue file..."
1498 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1499 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1501 log warning
"reading the CUE sheet with mkcue is still considered experimental"
1502 log warning
"and there was a problem with the CD reading. abcde will continue,"
1503 log warning
"but consider reporting the problem to the abcde author"
1507 # If we got the CDPARANOIA status and it is not recorded, save it now
1508 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1509 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
1510 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1514 # Create the discid file
1515 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1519 # Create a proper CUE file based on the CUE file we created before.
1522 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1523 CUEFILE_OUT
=$CUEFILE_IN.out
1524 ### FIXME ### checkstatus cddb
1525 if [ -e "$CDDBDATA" ]; then
1526 vecho
"Adding metadata to the cue file..."
1527 # FIXME It doesn't preserve spaces! Why?
1528 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1530 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1531 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1532 cat "$CUEFILE_IN" |
while read line
1534 if echo "$line" |
grep -q "INDEX"
1536 eval track
="\$TRACK$n"
1538 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1540 echo "$line" >> "$CUEFILE_OUT"
1542 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1543 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1549 # Parses a CDDB file and outputs the title and the track names.
1550 # Variables: CDDBFILE
1554 # List out disc title/author and contents
1555 if [ "$ONETRACK" = "y" ]; then
1556 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1558 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1559 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1560 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1561 if [ ! X
"$PARSEDYEAR" = "X" ]; then
1562 echo "Year: $PARSEDYEAR"
1565 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1566 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1567 if [ ! X
"$PARSEDGENRE" = "X" ]; then
1568 echo "Genre: $PARSEDGENRE"
1571 if [ ! "$ONETRACK" = "y" ]; then
1572 for TRACK
in $
(f_seq_row
1 $TRACKS)
1574 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1580 # Check for a local CDDB file, and report success
1583 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1585 CDDBLOCALSUCCESS
="n"
1586 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1587 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1590 # If the user has selected to check a local CDDB repo, we proceed with it
1591 if [ -r "${CDDBLOCALFILE}" ]; then
1592 # List out disc title/author and contents
1593 do_cddbparse
"${CDDBLOCALFILE}"
1594 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1595 if [ "$INTERACTIVE" = "y" ]; then
1597 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1598 echo -n 'Invalid selection. Please answer "y" or "n": '
1601 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1605 if [ "$USELOCALRESP" = "y" ]; then
1606 #echo "Using local copy of CDDB data"
1607 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1608 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
1609 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1610 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1611 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1612 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1613 CDDBLOCALSUCCESS
="y"
1615 #echo "Not using local copy of CDDB data"
1616 CDDBLOCALSUCCESS
="n"
1619 CDDBLOCALSUCCESS
="n"
1627 # Perform CDDB protocol version check if it hasn't already been done
1628 if checkstatus cddb-statcomplete
; then :; else
1629 if [ "$CDDBAVAIL" = "n" ]; then
1631 echo 503 > "$ABCDETEMPDIR/cddbstat"
1634 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1635 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1636 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1637 vecho
"Checking CDDB server status..."
1638 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1639 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1640 case "$RESPONSECODE" in
1641 210) # 210 OK, status information follows (until terminating `.')
1644 501|
*) # 501 Illegal CDDB protocol level: <n>.
1645 CDDBPROTO
=`expr $CDDBPROTO - 1`
1649 if test $rc -eq 1; then
1653 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1661 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1662 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1664 # Perform CDDB query if it hasn't already been done
1665 if checkstatus cddb-querycomplete
; then :; else
1666 if [ "$CDDBAVAIL" = "n" ]; then
1668 echo 503 > "$ABCDETEMPDIR/cddbquery"
1669 # The default CDDBLOCALSUCCESS is "n"
1670 # This part will be triggered if the user CDDB repo does not
1671 # contain the entry, or if we are not trying to use the repo.
1673 vecho
"Querying the CDDB server..."
1674 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1675 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1676 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1682 # no match found in database,
1683 # wget/fetch error, or user requested not to use CDDB
1684 # Make up an error code (503) that abcde
1685 # will recognize in do_cddbread
1686 # and compensate by making a template
1687 echo 503 > "$ABCDETEMPDIR/cddbquery"
1689 *) # strange and unknown error
1690 echo ERRORCODE
=$ERRORCODE
1691 echo "abcde: $CDDBTOOL returned unknown error code"
1695 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1702 # If it's not to be used, generate a template.
1703 # Then, display it (or them) and let the user choose/edit it
1704 if checkstatus cddb-readcomplete
; then :; else
1705 vecho
"Obtaining CDDB results..."
1706 # If CDDB is to be used, interpret the query results and read all
1707 # the available entries.
1708 rm -f "$ABCDETEMPDIR/cddbchoices"
1709 CDDBCHOICES
=1 # Overridden by multiple matches
1710 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1711 case "$RESPONSECODE" in
1713 # One exact match, retrieve it
1714 # 200 [section] [discid] [artist] / [title]
1715 if checkstatus cddb-read-1-complete
; then :; else
1716 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1717 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1718 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1719 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1720 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1722 # List out disc title/author and contents
1723 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1724 for TRACK
in $
(f_seq_row
1 $TRACKS)
1726 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1728 echo >> "$ABCDETEMPDIR/cddbchoices"
1732 case "$RESPONSECODE" in
1733 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1734 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1735 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1737 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1738 # List out disc title/author and contents of template
1739 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1741 for TRACK
in $
(f_seq_row
1 $TRACKS)
1743 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1745 echo >> "$ABCDETEMPDIR/cddbchoices"
1746 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1747 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1750 # Multiple exact, (possibly multiple) inexact matches
1752 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1753 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
1754 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1755 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1756 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1758 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1760 vecho
-n "Retrieving multiple matches... "
1761 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1762 read DISCINFO
# eat top line
1766 if checkstatus cddb-read-
$X-complete; then :; else
1767 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1768 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1770 # List out disc title/author and contents
1771 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1772 for TRACK
in $
(f_seq_row
1 $TRACKS)
1774 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1776 echo >> "$ABCDETEMPDIR/cddbchoices"
1779 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1783 for TRACK
in $
(f_seq_row
1 $TRACKS)
1785 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1787 echo >> "$ABCDETEMPDIR/cddbchoices"
1788 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1789 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1792 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1799 if checkstatus cddb-edit
>/dev
/null
; then
1800 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1801 VARIOUSARTISTS
="$(checkstatus variousartists)"
1802 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1805 if [ "$INTERACTIVE" = "y" ]; then
1806 # We should show the CDDB results both when we are not using the local CDDB repo
1807 # or when we are using it but we could not find a proper match
1808 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1809 # Display the $ABCDETEMPDIR/cddbchoices file created above
1810 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1811 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1812 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1813 CHOICE
=$
(checkstatus cddb-choice
)
1814 if [ -n "$CHOICE" ] ; then
1815 case $CDDBCHOICES in
1816 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1818 echo "Selected: #$CHOICE"
1819 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1823 # The user has a choice to make, display the info in a pager if necessary
1824 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1825 page
"$ABCDETEMPDIR/cddbchoices"
1827 # It's all going to fit in one page, cat it
1828 cat "$ABCDETEMPDIR/cddbchoices" >&2
1832 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1834 # I'll take CDDB read #3 for $400, Alex
1835 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1836 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1838 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1839 if echo $CDDBCHOICE |
egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1840 if [ ! X
"$DIFF" = "X" ]; then
1841 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1)
1842 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2)
1843 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1844 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1845 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1846 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1849 # We parse the 2 choices to diff, store them in temporary files and diff them.
1850 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
1851 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1853 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1854 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1855 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
1856 page
"$ABCDETEMPDIR/cddbread.diff"
1858 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1862 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1865 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1866 # Make sure we get a valid choice
1867 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1868 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1872 if [ "$CDCHOICENUM" = "0" ]; then
1873 vecho
"Creating empty CDDB template..."
1875 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1877 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1878 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1880 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1884 # We need some code to show the selected option when local repository is selected and we have found a match
1885 vecho
"Using cached CDDB match..." >&2
1886 # Display the $ABCDETEMPDIR/cddbchoices file created above
1887 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1888 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1889 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1890 CHOICE
=$
(checkstatus cddb-choice
)
1891 if [ "$USELOCALRESP" = "y" ]; then :; else
1892 if [ -n "$CHOICE" ] ; then
1893 case $CDDBCHOICES in
1896 echo "Selected template."
1898 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1900 echo "Selected: #$CHOICE"
1901 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1909 # We're noninteractive - pick the first choice.
1910 # But in case we run a previous instance and selected a choice, use it.
1911 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1912 # Show the choice if we are not using the locally stored one
1913 # or when the local search failed to find a match.
1914 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1915 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1916 #if [ "$PREVIOUSCHOICE" ]; then
1917 cat "$ABCDETEMPDIR/cddbchoices"
1920 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1921 CDCHOICENUM
=$PREVIOUSCHOICE
1924 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1926 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1931 if checkstatus cddb-choice
>/dev
/null
; then :; else
1932 echo "abcde: internal error: cddb-choice not recorded." >&2
1935 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1936 echo -n "Edit selected CDDB data? [y/n] (" >&2
1937 if [ "$INTERACTIVE" = "y" ]; then
1938 if [ "$UNKNOWNDISK" = "y" ]; then
1941 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1950 if [ "$EDITCDDB" = "y" ]; then
1951 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1953 # Use the debian sensible-editor wrapper to pick the editor that the
1954 # user has requested via their $EDITOR environment variable
1955 if [ -x "/usr/bin/sensible-editor" ]; then
1956 /usr
/bin
/sensible-editor
"$CDDBDATA"
1957 elif [ -n "$EDITOR" ]; then
1958 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1959 # That failed, try to load the preferred editor, starting
1960 # with their EDITOR variable
1961 eval $
(echo "$EDITOR") \"$CDDBDATA\"
1963 # If that fails, check for a vi
1964 elif which vi
>/dev
/null
2>&1; then
1966 elif [ -x /usr
/bin
/vim
]; then
1967 /usr
/bin
/vim
"$CDDBDATA"
1968 elif [ -x /usr
/bin
/vi
]; then
1969 /usr
/bin
/vi
"$CDDBDATA"
1970 elif [ -x /bin
/vi
]; then
1972 # nano should be on all (modern, i.e., sarge) debian systems
1973 elif which nano
>/dev
/null
2>&1 ; then
1975 elif [ -x /usr
/bin
/nano
]; then
1976 /usr
/bin
/nano
"$CDDBDATA"
1977 # mg should be on all OpenBSD systems
1978 elif which mg
>/dev
/null
2>&1 ; then
1980 elif [ -x /usr
/bin
/mg
]; then
1981 /usr
/bin
/mg
"$CDDBDATA"
1984 log warning
"no editor available. Check your EDITOR environment variable."
1986 # delete editor backup file if it exists
1987 if [ -w "$CDDBDATA~" ]; then
1992 # Some heuristics first. Look at Disc Title, and if it starts with
1993 # "Various", then we'll assume Various Artists
1994 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1995 echo "Looks like a Multi-Artist CD" >&2
1998 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1999 if [ "$INTERACTIVE" = "y" ]; then
2006 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2009 # Need NUMTRACKS before cddb-tool will return it:
2010 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
2011 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2012 # More than 1/2 tracks contain a "/", so guess forward
2014 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2015 # More than 1/2 contain a "-", so guess forward-dash
2017 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2018 # More than 1/2 contain something in parens, so guess trailing-paren
2022 echo "1) Artist / Title" >&2
2023 echo "2) Artist - Title" >&2
2024 echo "3) Title / Artist" >&2
2025 echo "4) Title - Artist" >&2
2026 echo "5) Artist: Title" >&2
2027 echo "6) Title (Artist)" >&2
2028 echo "7) This is a single-artist CD" >&2
2029 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2030 if [ "$INTERACTIVE" = "y" ]; then
2031 read VARIOUSARTISTSTYLE
2033 echo $DEFAULTSTYLE >&2
2034 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2036 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2037 # If they press Enter, then the default style (0) was chosen
2038 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2039 echo "Invalid selection. Please choose a number between 1 and 7."
2040 echo -n "Selection [1-7]: "
2041 read VARIOUSARTISTSTYLE
2042 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2044 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2045 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2047 vecho
"Selected: $VARIOUSARTISTSTYLE"
2048 case "$VARIOUSARTISTSTYLE" in
2050 VARIOUSARTISTSTYLE
=forward
2053 VARIOUSARTISTSTYLE
=forward-dash
2056 VARIOUSARTISTSTYLE
=reverse
2059 VARIOUSARTISTSTYLE
=reverse-dash
2062 VARIOUSARTISTSTYLE
=colon
2065 VARIOUSARTISTSTYLE
=trailing-paren
2073 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2074 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2076 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2077 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2078 # This works but does not have the necessary error checking
2079 # yet. If you are familiar with the CDDB spec
2080 # (see http://www.freedb.org/src/latest/DBFORMAT)
2081 # and can create an error-free entry on your own, then put
2082 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2083 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2084 # your abcde.conf to change the email address submissions are
2087 # submit the modified file, if they want
2088 if [ "$NOSUBMIT" != "y" ]; then
2089 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2091 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2092 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2094 echo -n 'Invalid selection. Please answer "y" or "n": '
2097 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2098 echo -n "Sending..."
2099 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2105 # Make sure the cache directory exists
2106 mkdir
-p $CDDBLOCALDIR
2107 # Cache edited CDDB entry in the user's cddb dir
2108 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
2109 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2112 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2115 # do_cdread [tracknumber]
2116 # do_cdread onetrack [firsttrack] [lasttrack]
2120 # The commands here don't go through run_command because they're never supposed to be silenced
2121 # return codes need to be doublechecked anyway, however
2122 if [ "$1" = "onetrack" ]; then
2123 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2124 # FIXME # Until then, we grab the whole CD in one track, no matter what
2126 # We need the first and last track for cdda2wav
2129 UTRACKNUM
=$FIRSTTRACK
2130 case "$CDROMREADERSYNTAX" in
2131 ### FIXME ### How are we calculating the tracks in flac mode?
2132 flac
) READTRACKNUMS
="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2133 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
2134 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTRACK" ;;
2135 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
2141 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2142 if [ "$USEPIPES" = "y" ]; then
2143 TEMPARG
="PIPERIPPER_$CDROMREADERSYNTAX"
2144 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2146 PIPE_MESSAGE
="and encoding "
2148 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2149 case "$CDROMREADERSYNTAX" in
2150 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2152 FILEARG
="--output-name=$WAVDATA"
2155 FILEARG
="-f $WAVDATA"
2163 if [ "$1" = "onetrack" ]; then
2164 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2166 if [ -r "$CDDBDATA" ]; then
2167 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
2168 do_getcddbinfo TRACKNAME
2169 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2171 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2174 case "$CDROMREADERSYNTAX" in
2175 ### FIXME ### use an exception for flac, since it uses -o
2176 ### FIXME ### Shall we just use -o $FILEARG ??
2178 nice
$READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2180 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2182 if [ "$OSFLAVOUR" = "OSX" ] ; then
2183 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2184 disktool
-u ${CDROM#/dev/} 0
2185 # Also, in OSX the cdrom device for cdda2wav changes...
2186 CDDA2WAVCDROM
="IODVDServices"
2187 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2188 CDDA2WAVCDROM
="$CDROMID"
2190 if [ "$CDROMID" = "" ]; then
2191 CDDA2WAVCDROM
="$CDROM"
2193 CDDA2WAVCDROM
="$CDROMID"
2196 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2198 ## FIXME ## We have an exception for dagrab, since it uses -f
2199 ## FIXME ## Shall we just use -f $FILEARG ??
2200 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2203 # Find the track's mounted path
2204 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2205 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2206 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2207 # If the file exists, copy it
2208 if [ -e "$FILEPATH" ] ; then
2209 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2213 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2217 # If we get some error or we get some missing wav
2218 # (as long as we dont use pipes)
2219 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2220 # Thank goodness errors is only machine-parseable up to the
2221 # first colon, otherwise this woulda sucked
2222 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2223 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2225 if [ "$USEPIPES" = "y" ]; then
2226 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2228 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2232 if [ "$USEPIPES" = "y" ]; then
2233 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2235 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2236 if [ "$1" = "onetrack" ]; then
2237 echo onetrack
>> "$ABCDETEMPDIR/status"
2244 # No values accepted, only uses env variables
2247 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2248 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2250 echo "abcde: unable to set the device speed" >&2
2256 # vecho outputs a message if EXTRAVERBOSE is selected
2259 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2261 warning
) log warning
"$@" ;;
2269 # decho outputs a debug message if DEBUG is selected
2272 if [ x
"$DEBUG" != "x" ]; then
2273 DEBUGECHO
=$
(echo "$@" |
tr -d '[]')
2274 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2278 # User-redefinable functions
2279 # Custom filename munging:
2282 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2283 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2286 # Custom genre munging:
2289 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2293 # Empty pre_read function, to be defined in the configuration file.
2300 # Empty post_read function, to be defined in the configuration file.
2306 ###############################################################################
2309 # Start of execution
2310 ###############################################################################
2313 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2314 CDDBSUBMIT
=freedb-submit@freedb.org
2316 HELLOINFO
="$(whoami)@$(hostname)"
2318 CDDBLOCALDIR
="$HOME/.cddb"
2321 # List of fields we parse and show during the CDDB parsing...
2322 SHOWCDDBFIELDS
="year,genre"
2325 CDROMREADERSYNTAX
=cdparanoia
2326 ENCODERSYNTAX
=default
2328 MP3ENCODERSYNTAX
=default
2329 OGGENCODERSYNTAX
=default
2330 FLACENCODERSYNTAX
=default
2331 SPEEXENCODERSYNTAX
=default
2332 MPPENCODERSYNTAX
=default
2333 NORMALIZERSYNTAX
=default
2334 CUEREADERSYNTAX
=default
2336 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2337 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2338 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2339 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2340 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2341 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2342 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2343 PLAYLISTDATAPREFIX
=''
2344 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2345 VAPLAYLISTDATAPREFIX
=''
2353 VARIOUSARTISTSTYLE
=forward
2359 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2360 # i.e. CDROMID="1,0,0"
2362 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2363 # If we are using the ide-scsi emulation layer, we need to define a "g"
2364 CDPARANOIACDROMBUS
="d"
2366 # program paths - defaults to checking your $PATH
2373 XINGMP3ENC
=xingmp3enc
2388 CDPARANOIA
=cdparanoia
2397 VORBISCOMMENT
=vorbiscomment
2399 NORMALIZE
=normalize-audio
2401 VORBISGAIN
=vorbisgain
2405 CUE2DISCID
=cue2discid
2407 # Options for programs called from abcde
2440 VORBISCOMMENTOPTS
="-R"
2441 METAFLACOPTS
="--no-utf8-convert"
2443 # Default to one process if -j isn't specified
2446 # List of actions to perform - by default, run to completion
2447 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2449 # List of prefered outputs - by default, run with whatever we have in the path
2450 # This option is basicaly for Debian package dependencies
2451 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
2453 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2454 # Let's use these checkings to determine the OS flavour, which will be used later
2455 if [ X$
(uname
) = "XFreeBSD" ] ; then
2460 elif [ X$
(uname
) = "XDarwin" ] ; then
2463 # We should have disktool in OSX, but let's be sure...
2465 CDROMREADERSYNTAX
=cddafs
2466 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2469 elif [ X$
(uname
) = "XNetBSD" ] ; then
2476 # If CDDBAVAIL is set to n, no CDDB read is done
2477 # If USEID3 is set to n, no ID3 tagging is done
2482 if [ -z "$OUTPUTDIR" ]; then
2486 if [ -z "$WAVOUTPUTDIR" ]; then
2487 WAVOUTPUTDIR
="$OUTPUTDIR"
2490 # Load system defaults
2491 if [ -r /etc
/abcde.conf
]; then
2494 # Load user preference defaults
2495 if [ -r $HOME/.abcde.conf
]; then
2499 # By this time, we need some HTTPGETOPTS already defined.
2500 # If the user has defined a non-default HTTPGET method, we should not be empty.
2502 if [ "$HTTPGETOPTS" = "" ] ; then
2504 wget
) HTTPGETOPTS
="-q -O -";;
2505 curl
) HTTPGETOPTS
="-f -s";;
2506 fetch
)HTTPGETOPTS
="-q -o -";;
2507 ftp) HTTPGETOPTS
="-q -o -";;
2508 *) log warning
"HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
2512 # If the CDROM has not been set yet, find a suitable one.
2513 # If this is a devfs system, default to /dev/cdroms/cdrom0
2514 # instead of /dev/cdrom
2515 if [ "$CDROM" = "" ] ; then
2516 if [ -e /dev
/cdroms
/cdrom0
]; then
2517 CDROM
=/dev
/cdroms
/cdrom0
2518 elif [ -e /dev
/cdrom
]; then
2520 elif [ -e /dev
/cd0c
]; then
2522 elif [ -e /dev
/acd0c
]; then
2524 elif [ -e /dev
/disk1
]; then
2529 # Parse command line options
2530 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2531 while getopts 1a
:bc:C
:d
:Defghj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
:z opt
; do
2534 a
) ACTIONS
="$OPTARG" ;;
2535 A
) EXPACTIONS
="$OPTARG" ;;
2537 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else log error
"config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
2538 C
) DISCID
="${OPTARG#abcde.}" ;;
2539 d
) CDROM
="$OPTARG" ;;
2541 e
) ERASEENCODEDSTATUS
=y
;;
2543 e
) ERASEENCODEDSTATUS
=y
;;
2544 E
) ENCODING
="$OPTARG" ;;
2548 j
) MAXPROCS
="$OPTARG" ;;
2551 L
) CDDBUSELOCAL
=y
;;
2556 o
) OUTPUTTYPE
="$OPTARG" ;;
2559 r
) REMOTEHOSTS
="$OPTARG" ;;
2561 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2562 S
) CDSPEEDVALUE
="$OPTARG" ;;
2563 # t) PREPROCESSFORMATS="$OPTARG"
2565 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2566 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2567 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2569 echo "This is abcde v$VERSION."
2570 echo "Usage: abcde [options] [tracks]"
2571 echo "abcde -h for extra help"
2574 V
) EXTRAVERBOSE
="y" ;;
2576 w
) COMMENT
="$OPTARG" ;;
2577 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2578 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2580 log error
"argument of -W must be integer"
2584 z
) DEBUG
=y
; CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
2589 shift $
(($OPTIND - 1))
2591 # If the user specified a flac file, then switch to special flac mode
2592 if echo $CDROM |
grep -i -q '.flac$'; then
2593 vecho
"abcde: switching to flac CDROMREADERSYNTAX..."
2594 CDROMREADERSYNTAX
=flac
2595 if [ "$EJECTCD" = "y" ];then
2596 vecho
"abcde: CDROM flac mode, deactivating EJECTCD..."
2601 # Decide if we can continue.
2602 if [ "$ONETRACK" = "y" ]; then
2603 # FIXME # remove check as soon as we find out about the other readers
2604 case "$CDROMREADERSYNTAX" in
2608 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
2611 if [ "$BATCHNORM" = "y" ]; then
2612 log warning
"BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
2615 if [ "$NOGAP" = "y" ]; then
2616 log warning
"NOGAP mode is not compatible with ONETRACK mode. Disabling..."
2619 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2620 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2621 if [ $# -gt 0 ]; then
2622 log warning
"ONETRACK mode selected, grabbing all tracks..."
2625 while [ $# -gt 0 ]; do
2626 # Range parsing code courtesy of Vincent Ho
2627 RSTART
=$
(echo $1 | cut
-f1 -d-)
2628 REND
=$
(echo $1 | cut
-f2 -d-)
2629 if [ "$RSTART" = "$REND" ]; then
2632 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2634 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2639 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2640 # List of experimental actions: retag,transcode
2642 # Determine what actions are to be done from $ACTIONS and set the
2643 # following environment variables for them:
2656 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2661 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2662 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2663 encode
) DOENCODE
=y
; DOREAD
=y
;;
2664 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2665 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2666 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2667 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
2668 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2673 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2674 # FIXME # should we abort on error or just inform the user?
2678 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
2679 case $SHOWCDDBFIELD in
2680 y
*|Y
*) SHOWCDDBYEAR
="y";;
2681 g
*|G
*) SHOWCDDBGENRE
="y";;
2688 # At this point a CDROM has to be defined, so we check it exists.
2689 if [ X
"$CDROM" != "X" ] ; then
2690 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2691 if [ "$OSFLAVOUR" = "FBSD" ]; then
2692 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2693 log error
"CDROMID not in the right format for $CDROMREADERSYNTAX"
2694 log error
"Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2698 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2699 log error
"CDROM device cannot be found."
2702 # avoid processing if we are not going to hit the CDROM.
2703 elif [ X
"$DOREAD" = "Xy" ]; then
2704 log error
"CDROM has not been defined or cannot be found"
2708 # USEPIPES pre-tests, before we get into more serious stuff
2709 # Not compatible with:
2710 # - multiple outputs
2712 # - lowdisk algorithm
2714 if [ X
"$USEPIPES" = "Xy" ]; then
2715 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
2716 log error
"Unix pipes not compatible with multiple outputs"
2719 if [ X
"$DONORMALIZE" = "Xy" ]; then
2720 log error
"Unix pipes not compatible with normalizer"
2721 # FIXME # Do we need to exit or shall we just disable the mode?
2724 if [ X
"$BATCHNORM" = "Xy" ]; then
2725 log error
"Unix pipes not compatible with BATCHNORM encoding"
2728 if [ X
"$NOGAP" = "Xy" ]; then
2729 log error
"Unix pipes not compatible with NOGAP encoding"
2732 if [ X
"$DOENCODE" = "Xn" ]; then
2733 vecho warning
"Disabling Unix pipes since we are not encoding!"
2736 if [ X
"$LOWDISK" = "Xy" ]; then
2737 log error
"Unix pipes not compatible with lowdisk algorithm"
2742 # LOWDISK pre-tests, before we get into more problematic stuff
2743 # Not compatible with anything that needs all the files in the hard disc:
2746 if [ X
"$LOWDISK" = "Xy" ]; then
2747 if [ X
"$BATCHNORM" = "Xy" ]; then
2748 log error
"Unix pipes not compatible with BATCHNORM encoding"
2751 if [ X
"$NOGAP" = "Xy" ]; then
2752 log error
"Unix pipes not compatible with NOGAP encoding"
2757 # BATCHNORM pre-tests, before we get into serious problems
2758 # Not compatible with
2759 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
2760 vecho warning
"Disabling BATCHNORM since we are not normalizing!"
2764 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2765 if [ X
"$OUTPUTTYPE" = "X" ]; then
2766 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
2767 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2768 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2769 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
2770 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
2771 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2775 if [ X
"$OUTPUTTYPE" = "X" ]; then
2776 log error
"no encoder found in the PATH"
2777 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
2782 # Decide which CDROM reader we're gonna use
2783 case "$CDROMREADERSYNTAX" in
2785 CDROMREADER
="$CDPARANOIA"
2786 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2789 CDROMREADER
="$CDDA2WAV"
2790 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2793 CDROMREADER
="$DAGRAB"
2794 CDROMREADEROPTS
="$DAGRABOPTS"
2797 CDROMREADER
="$CDDAFS"
2798 CDROMREADEROPTS
="$CDDAFSOPTS"
2802 CDROMREADEROPTS
="$FLACOPTS"
2806 # There's only one normalize...
2807 case "$NORMALIZERSYNTAX" in
2809 NORMALIZER
="$NORMALIZE"
2810 NORMALIZEROPTS
="$NORMALIZEOPTS"
2814 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2815 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
2816 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2818 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2819 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2820 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2821 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2822 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2825 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
2826 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2827 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2829 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2832 # 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
2834 # Getting ready for multiple output changes
2835 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2839 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2840 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2841 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2842 OGGOUTPUTCONTAINER
=ogg
2845 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2846 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2849 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2850 [ "$REPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
2851 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2854 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
2857 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
2860 if [ "$KEEPWAVS" = "y" ]; then
2861 vecho
"Unsetting the KEEPWAVS option, since the resulting wav files were requested..."
2865 *) log error
"Invalid OUTPUTTYPE defined"
2871 # decide which encoder
2872 case "$MP3ENCODERSYNTAX" in
2874 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2878 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
2879 MP3ENCODER
="$TOOLAME"
2882 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2886 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2887 MP3ENCODER
="$BLADEENC"
2890 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2894 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2895 MP3ENCODER
="$XINGMP3ENC"
2898 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2899 MP3ENCODER
="$MP3ENC"
2902 case "$OGGENCODERSYNTAX" in
2904 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2905 OGGENCODER
="$VORBIZE"
2908 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2909 OGGENCODER
="$OGGENC"
2912 case "$FLACENCODERSYNTAX" in
2914 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2916 # FLAC streams can be encapsulated on a Ogg transport layer
2917 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2918 log error
"FLAC on an Ogg container is not yet supported"
2919 log error
"due to problem with adding comments to such files"
2921 FLACOUTPUTCONTAINER
=ogg
2923 FLACOUTPUTCONTAINER
=flac
2927 case "$SPEEXENCODERSYNTAX" in
2929 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2930 SPEEXENCODER
="$SPEEXENC"
2933 case "$MPPENCODERSYNTAX" in
2935 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2936 MPPENCODER
="$MPPENC"
2942 if [ "$ID3TAGV" = "1" ]; then
2944 TAGGEROPTS
="$ID3OPTS"
2947 TAGGEROPTS
="$ID3V2OPTS"
2950 # Specific for NOGAP is the use of lame. Another encoder fails...
2951 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
2952 log warning
"the NOGAP option is specific of lame. Deactivating..."
2957 case "$CUEREADERSYNTAX" in
2959 CUEREADEROPTS
="${CDROM}"
2964 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2965 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2966 log error
"FLAC on an Ogg container is not yet supported"
2967 log error
"due to problem with adding comments to such files"
2969 OGGOUTPUTCONTAINER
=ogg.ogg
2970 FLACOUTPUTCONTAINER
=flac.ogg
2971 vecho warning
"modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2974 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2976 if [ "$ENCNICE" ]; then
2977 ENCNICE
="-n $ENCNICE"
2979 if [ "$READNICE" ]; then
2980 READNICE
="-n $READNICE"
2982 if [ "$DISTMP3NICE" ]; then
2983 DISTMP3NICE
="-n $DISTMP3NICE"
2986 # Don't check for stuff if it's not needed
2987 if [ "$REMOTEHOSTS" ]; then
2990 if [ "$DONORMALIZE" = "y" ]; then
2993 if [ "$EJECTCD" = "y" ]; then
2996 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2999 if [ "$MAKECUEFILE" = "y" ]; then
3003 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3004 case "$CDROMREADERSYNTAX" in
3005 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
3006 ### FIXME ### translate "cue2discid" from python to bash
3007 flac
) NEEDMETAFLAC
=y
; NEEDCUE2DISCID
=y
;;
3012 # Rippers with USEPIPE support
3013 # FIXME # Include here all the rippers we can figure out support pipes
3014 PIPERIPPER_cdparanoia
="-"
3015 PIPERIPPER_flac
="-c "
3017 # Encoders with USEPIPE support
3018 # FIXME # Include here all the encoders we can figure out support pipes
3024 # Figure out if we can use pipes with the ripper/encoder combination
3026 if [ "$USEPIPES" = "y" ]; then
3027 PIPERIPPERSVARCHECK
="PIPERIPPER_${CDROMREADERSYNTAX}"
3030 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
3032 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
3034 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
3036 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
3038 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
3040 if [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "$" ] ; then
3041 log error
"no support for pipes with given ripper"
3042 log error
"read the USEPIPES file from the source tarball to get help."
3043 log error
"On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
3046 vecho PIPES
: "$( eval echo "\$
$PIPEENCODERSVARCHECK" )"
3047 if [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "$" ] ; then
3048 log error
"no support for pipes with given encoder"
3049 log error
"read the USEPIPES file from the source tarball to help"
3050 log error
"on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
3055 # Make sure a buncha things exist
3056 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
3057 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3058 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3059 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3060 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
3061 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
3062 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDCUEREADER+$CUEREADER} \
3063 ${NEEDCUE2DISCID+$CUE2DISCID}
3065 # Cut off the command-line options we just added in
3066 X
=$
(echo $X | cut
-d' ' -f2)
3067 if [ "$(which $X)" = "" ]; then
3068 log error
"$X is not in your path." >&2
3070 elif [ ! -x $
(which $X) ]; then
3071 log error
"$X is not executable." >&2
3076 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
3077 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
3078 HTTPGET
="$HTTPGET $HTTPGETOPTS"
3080 # And last but not least, check if we can diff between files
3081 if [ -x $
(which $DIFF) ]; then :; else
3082 vecho warning
"Disabling diff since we cannot find it in the \$PATH..."
3086 # Here it used to say:
3087 # One thousand lines in, we can start doing stuff with things
3088 # Well, right now we are at line 2736 ;)
3090 # Export needed things so they can be read in this subshell
3091 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
3092 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
3094 # User-definable function to set some things. Use it for
3095 # - closing the CD tray with eject -t
3096 # - set the CD speed value with eject -x
3097 vecho
-n "Executing customizable pre-read function... "
3099 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
3103 do_discid
# Get ABCDETEMPDIR created and status file initialized
3105 if [ "$DOCDDB" = "y" ]; then
3106 if [ $CDDBUSELOCAL = "y" ]; then
3109 if checkstatus cddb-choice
> /dev
/null
; then
3112 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
3120 eval "$($CDDBTOOL parse "$CDDBDATA")"
3123 # Before reading tracks, we set the speed of the device
3125 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3126 case "$CDROMREADERSYNTAX" in
3127 cdparanoia|debug
) ;;
3133 # Define the first and last track, since we might need them later in several places
3134 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
3135 LASTTRACK
=$
( get_last
$TRACKQUEUE )
3137 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
3138 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3139 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
3140 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
3143 # Create playlist if needed (backgroundable) and start reading in tracks
3147 if [ ! "$ONETRACK" = "y" ]; then
3148 if [ "$DOPLAYLIST" = "y" ]; then
3149 echo Creating playlist...
>&2
3154 # For the lowdisk option, only one program is running at once so the encoder
3155 # can be unsilenced right away.
3156 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3157 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3160 if [ "$ONETRACK" = "y" ]; then
3161 TRACKS
="$FIRSTTRACK"
3162 if checkstatus readtrack-
$FIRSTTRACK; then :; else
3163 if [ "$USEPIPES" = "y" ]; then
3164 do_cdread onetrack
$FIRSTTRACK $LASTTRACK | do_encode
$FIRSTTRACK %local0
% > /dev
/null
2>&1
3166 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
3170 for UTRACKNUM
in $TRACKQUEUE
3172 if [ "$DOREAD" = "y" ]; then
3173 if [ "$USEPIPES" = "y" ]; then
3174 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
3175 # Read, pipe, shut up!
3176 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
3179 if checkstatus readtrack-
$UTRACKNUM; then :; else
3180 do_cdread
$UTRACKNUM
3182 if [ "$?" != "0" ]; then
3183 # CD read failed - don't give the goahead to
3190 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ]; then
3193 echo NEXTTRACK
# Get the encoder machine churning again
3194 if [ "$DOREAD" = "y" ]; then
3195 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3196 until checkstatus encodetrack-
$UTRACKNUM
3198 if checkerrors encodetrack-
$UTRACKNUM; then
3209 # Now that we're done the encoding can be loud again -
3210 # if we're not using SMP.
3211 if [ "$MAXPROCS" = "1" ]; then
3212 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3215 # All tracks read, start encoding.
3216 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3220 # Execute the user-defined post_read funtion before ejecting CD
3223 # We are now finished with the cdrom - it can be safely ejected. Note that
3224 # abcde will not have completed yet.
3225 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
3226 # We check if the disk we are processing is actually the disk inside the
3227 # CD tray. If not, we do not eject the CD, since it might be so that the
3228 # user ejected it manually.
3229 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3230 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3231 # More FreeBSD bits.
3232 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
3233 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3234 # but in this script EJECT is in the envionment and names the program
3237 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3238 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3239 $eject $EJECTOPTS $cd
3240 elif [ X
"$(uname)" = X
"Darwin" ] ; then
3241 disktool
-e ${CDROM#/dev/} 0
3243 $EJECT $EJECTOPTS $CDROM
3250 ## Do we need to pre-process
3251 #if [ x"$PREPROCESS" = "x" ] ; then
3254 # for PRETRACKNUM in $TRACKQUEUE
3257 # if [ "$GOAHEAD" = "NO" ]; then break; fi
3259 # until [ $PREPROCEED ]
3261 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3262 # # all locations are working, wait and try again later
3263 # if [ ! $PREPROCEED ]; then sleep 3; fi
3265 # ( do_preprocess $PRETRACKNUM
3273 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
3275 if [ "$BATCHNORM" = "y" ] ||
[ "$NOGAP" = "y" ]; then
3276 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3277 if [ "$GOAHEAD" = "NO" ]; then break; fi
3278 for LASTTRACK
in $TRACKQUEUE; do :; done
3279 if checkstatus readtrack-
$LASTTRACK; then
3280 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
3281 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
3282 if checkerrors batch-normalize
; then exit 1; fi
3284 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
3285 if [ "$DONORMALIZE" = "y" ]; then
3286 for UTRACKNUM
in $TRACKQUEUE
3288 if checkstatus readtrack-
$UTRACKNUM; then
3289 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3293 if checkstatus encodetrack-
$LASTTRACK; then :; else do_nogap_encode
; fi
3294 if checkerrors nogap-encode
; then exit 1; fi
3299 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3300 if [ "$ONETRACK" = "y" ] ; then
3301 TRACKQUEUE
="$FIRSTTRACK"
3302 TRACKS
="$FIRSTTRACK"
3305 # Do the encoding, including parallelization of remote encoding
3306 # Figure out where each track is going to be encoded
3307 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
3308 if [ "$MAXPROCS" != "0" ]; then
3309 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
3311 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
3315 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
3316 for UTRACKNUM
in $TRACKQUEUE
3319 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3320 if [ "$GOAHEAD" = "NO" ]; then break; fi
3321 # find out where this track is to be encoded
3322 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3323 # Make sure we have a place to encode this, if not, exit stage right
3324 if [ -z "$ENCODELOCATIONS" ]; then
3330 for LOCATION
in $ENCODELOCATIONS
3332 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3333 # check first if a track has ever been assigned to this location
3334 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
3335 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3336 if checkerrors encodetrack-
$PREVIOUSTRACK; then
3337 for TEMPLOCATION
in $ENCODELOCATIONS
3339 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3340 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
3343 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
3348 # We're still here, this location must have been previously assigned,
3349 # and last completed without error - check if it's done with the
3350 # previous track yet
3351 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
3353 # all locations are working, wait and try again later
3354 if [ ! $PROCEED ]; then sleep 3; fi
3356 # Record the location we're about to encode the next track at
3357 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3359 # Don't proceed with the rest of the loop if we can't encode
3360 if [ "$ABORT" ]; then continue; fi
3361 # Set TRACKNUM, TRACKNAME
3362 if [ -e "$CDDBDATA" ]; then
3363 if [ "$ONETRACK" = "y" ]; then
3365 TRACKNUM
="$FIRSTTRACK"
3368 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
3370 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3371 #TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
3372 do_getcddbinfo TRACKNAME
3376 # You can't encode a file which needs to be normalized before finishing
3377 # You can't tag a file before it's finished encoding -
3378 # thus all of this is backgrounded together
3380 if [ "$DONORMALIZE" = "y" ]; then
3381 if checkstatus readtrack-
$UTRACKNUM; then
3382 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3385 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3386 if checkstatus readtrack-
$UTRACKNUM; then
3387 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3388 if [ "$DONORMALIZE" = "y" ]; then
3389 if checkstatus normalizetrack-
$UTRACKNUM; then
3390 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3393 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3397 if [ "$DOTAG" = "y" ]; then
3398 if checkstatus encodetrack-
$UTRACKNUM; then
3399 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3401 # Lets tag the cue file
3402 if checkstatus cleancuefile
>/dev
/null
; then :; else
3403 if checkstatus cuefile
>/dev
/null
; then
3408 if [ "$DOMOVE" = "y" ]; then
3409 if checkstatus tagtrack-
$UTRACKNUM; then
3410 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3417 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3418 # we'll delete the files they're working on
3419 ## FIXME ## Check also for files which are encoded using PIPEs.
3420 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3425 for LOCATION
in $ENCODELOCATIONS
3427 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3428 # "How can he give us a status update, if he's DEAD?"
3429 if checkstatus encodetrack-
$CHECKTRACK; then
3432 # Nothing to see here please go quietly back to your homes
3433 if [ -z "$CHECKTRACK" ]; then continue; fi
3434 # You're still here? Maybe there is something...
3435 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3438 if [ ! $PROCEED ]; then sleep 5; fi
3441 # If the above didn't catch the stragglers, this will
3443 if [ "$REPLAYGAIN" = "y" ]; then
3446 # Check to see if run_command logged any errors
3447 if [ -f "$ABCDETEMPDIR/errors" ]; then
3448 log error
"The following commands failed to run:"
3449 cat "$ABCDETEMPDIR/errors"
3453 if [ "$KEEPWAVS" = "y" ];then
3457 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
3458 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
3459 ENCODED_FORMATS
=$
(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f2 |
sort -u |
tr '\n' '|')
3460 MOVED_FORMATS
=$
(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f3 |
sort -u |
tr '\n' '|')
3461 decho
[ENCODED_FORMATS
]
3462 decho
[MOVED_FORMATS
]
3463 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
3464 log warning
"Not all encoded formats have been requested to be moved."
3465 log warning
"Use \"-a clean -f -C $DISCID\" to force the removal of the remaining data."
3469 if [ "$DOCLEAN" = "y" ]; then
3470 # Wipe all the evidence
3471 # Gimme gimme gimme some more time!
3473 rm -rf "$ABCDETEMPDIR"
3476 echo "Finished. Not cleaning $ABCDETEMPDIR."