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 Batch mode: enable album normalization and nogap encoding"
27 echo " Specify a configuration file (overrides system and user config files)"
29 echo " Specify discid to resume from (only needed if you no longer have the cd)"
31 echo " Specify CDROM device to grab"
32 echo "-D Debugging mode (equivalent to sh -x abcde)"
33 echo "-e Erase encoded track information from status file"
34 echo "-h This help information"
35 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
36 echo "-j <#> Number of encoder processes to run at once (localhost)"
37 echo "-k Keep the wav tracks for later use"
38 echo "-l Use low disk space algorithm"
39 echo "-L Use local CDDB storage directory"
40 echo "-n No lookup. Don't query CDDB, just create and use template"
41 echo "-N Noninteractive. Never prompt for anything"
42 echo "-m Modify playlist to include CRLF endings, to comply with some players"
43 echo "-M Create a CUE file"
44 echo "-o <type1[,type2]...>"
45 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc). Defaults to vorbis"
46 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
47 echo "-P Use UNIX pipes to read+encode without wav files"
48 echo "-r <host1[,host2]...>"
49 echo " Also encode on these remote hosts"
50 echo "-R Add replaygain values to the tag info (only for vorbis,flac)"
52 echo " Show dielfs from the CDDB info (year,genre)"
53 echo "-S <#> Set the CD speed"
54 #echo "-t File types to preprocess (wav)"
55 #echo "-T Set postprocessing options"
56 echo "-t <#> Start the track numbering at a given number"
57 echo "-T <#> Same as -t but modifies tag numbering"
58 echo "-v Show version number and exit"
59 echo "-V Be a bit more verbose about what is happening behind the scenes"
60 echo "-x Eject CD after all tracks are read"
62 echo " Add a comment to the CD tracks"
63 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
65 echo "Tracks is a space-delimited list of tracks to grab."
66 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
68 #echo "Double hyphens are used to concatenate tracks"
71 # Funtions to replace the need of seq, which is too distribution dependant.
75 while [ $i -ne `expr $2 + 1` ]
85 while [ $i -ne `expr $2 + 1` ]
93 # Functions to replace the need of awk {print $1} and {print $NF}
96 if [ X
"$1" = "X" ]; then
97 for first
in `cat`; do
108 if [ X
"$1" = "X" ]; then
109 for stdin
in `cat`; do
113 for last
in $@
; do :; done
118 # checkstatus [blurb]
119 # Returns "0" if the blurb was found, returns 1 if it wasn't
120 # Puts the blurb content, if available, on stdout.
121 # Otherwise, returns "".
124 # Take the last line in the status file if there's multiple matches
126 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
128 if [ -z "$BLURB" ]; then
133 # See if there's a = in it
134 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
135 echo "$(echo $BLURB | cut -f2- -d=)"
141 # checkerrors [blurb]
142 # Returns "0" if the blurb was found (meaning there was an error),
143 # returns 1 if it wasn't (yes this is a little backwards).
144 # Does not print the blurb on stdout.
145 # Otherwise, returns "".
148 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
151 # Take the last line in the status file if there's multiple matches
153 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
155 if [ -z "$BLURB" ]; then
156 # negative, we did not have a negative...
159 # affirmative, we had a negative...
164 # run_command [blurb] [command...]
165 # Runs a command, silently if necessary, and updates the status file
170 # See if this is supposed to be silent
171 if [ "$(checkstatus encode-output)" = "loud" ]; then
175 # Special case for SMP, since
176 # encoder output is never displayed, don't mute echos
177 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
187 if [ "$RETURN" = "2" ]; then
188 # File was already normalized.
193 if [ "$RETURN" != "0" ]; then
194 # Put an error in the errors file. For various reasons we
195 # can't capture a copy of the program's output but we can
196 # log what we attempted to execute and the error code
197 # returned by the program.
198 if [ "$BLURB" ]; then
201 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
202 return $RETURN # Do not pass go, do not update the status file
204 if [ "$BLURB" ]; then
205 echo $BLURB >> "$ABCDETEMPDIR/status"
209 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
210 # distributed under the terms of the GNU GPL v2 or later, at your option
212 # Function to determine if a word contains a slash.
221 # Function to give the relative path from one file to another.
222 # Usage: relpath fromfile tofile
223 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
224 # (the result would be Album/Song.mp3)
225 # Output is relative path to $2 from $1 on stdout
227 # This code has the following restrictions:
228 # Multiple ////s are not collapsed into single /s, with strange effects.
229 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
230 # If FR is a directory it must have a trailing /
238 /*) ;; # No processing is needed for absolute paths
240 # Loop through common prefixes, ignoring them.
241 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
243 FR
="$(echo "$FR" | cut -d/ -f2-)"
244 TO
="$(echo "$TO" | cut -d/ -f2-)"
246 # Loop through directory portions left in FR, adding appropriate ../s.
249 FR
="$(echo "$FR" | cut -d/ -f2-)"
258 # This code splits the a Various Artist track name from one of the following
261 # forward: Artist / Track
262 # forward-dash: Artist - Track
263 # reverse: Track / Artist
264 # reverse-dash: Track - Artist
265 # colon: Artist: Track
266 # trailing-paren: Artist (Track)
269 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
272 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
273 case "$VARIOUSARTISTSTYLE" in
275 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's- / -~-g')
276 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
277 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
280 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's, - ,~,g')
281 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
282 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
285 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's- / -~-g')
286 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
287 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
290 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's, - ,~,g')
291 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
292 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
295 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's-: -~-g')
296 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
297 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
300 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's,^\(.*\) (\(.*\)),\1~\2,')
301 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
302 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
305 elif [ "$ONETRACK" = "y" ]; then
306 TRACKARTIST
="Various"
308 TRACKARTIST
="$DARTIST"
313 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
317 "classic rock") id
=1 ;;
335 "industrial") id
=19 ;;
336 "alternative") id
=20 ;;
338 "death metal") id
=22 ;;
340 "soundtrack") id
=24 ;;
341 "euro-techno") id
=25 ;;
345 "jazz+funk") id
=29 ;;
348 "classical") id
=32 ;;
349 "instrumental") id
=33 ;;
353 "sound clip") id
=37 ;;
356 "alt. rock") id
=40 ;;
361 "meditative") id
=45 ;;
362 "instrum. pop") id
=46 ;;
363 "instrum. rock") id
=47 ;;
367 "techno-indust.") id
=51 ;;
368 "electronic") id
=52 ;;
370 "eurodance") id
=54 ;;
372 "southern rock") id
=56 ;;
377 "christian rap") id
=61 ;;
380 "native american") id
=64 ;;
383 "psychadelic") id
=67 ;;
385 "showtunes") id
=69 ;;
389 "acid punk") id
=73 ;;
390 "acid jazz") id
=74 ;;
394 "rock & roll") id
=78 ;;
395 "hard rock") id
=79 ;;
397 "folk/rock") id
=81 ;;
398 "national folk") id
=82 ;;
405 "bluegrass") id
=89 ;;
406 "avantgarde") id
=90 ;;
407 "gothic rock") id
=91 ;;
408 "progress. rock") id
=92 ;;
409 "psychadel. rock") id
=93 ;;
410 "symphonic rock") id
=94 ;;
411 "slow rock") id
=95 ;;
414 "easy listening") id
=98 ;;
420 "chamber music") id
=104 ;;
422 "symphony") id
=106 ;;
423 "booty bass") id
=107 ;;
425 "porn groove") id
=109 ;;
427 "slow jam") id
=111 ;;
431 "folklore") id
=115 ;;
433 "power ballad") id
=117 ;;
434 "rhythmic soul") id
=118 ;;
435 "freestyle") id
=119 ;;
437 "punk rock") id
=121 ;;
438 "drum solo") id
=122 ;;
439 "a capella") id
=123 ;;
440 "euro-house") id
=124 ;;
441 "dance hall") id
=125 ;;
443 "drum & bass") id
=127 ;;
444 "club-house") id
=128 ;;
445 "hardcore") id
=129 ;;
449 "negerpunk") id
=133 ;;
450 "polsk punk") id
=134 ;;
452 "christian gangsta rap") id
=136 ;;
453 "heavy metal") id
=137 ;;
454 "black metal") id
=138 ;;
455 "crossover") id
=139 ;;
456 "contemporary christian")id
=140 ;;
457 "christian rock") id
=141 ;;
458 "merengue") id
=142 ;;
460 "thrash metal") id
=144 ;;
463 "synthpop") id
=147 ;;
470 # do_tag [tracknumber]
471 # id3 tags a filename
473 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
474 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
477 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
478 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
479 # If we want to start the tracks with a given number, we need to modify the
480 # TRACKNUM value before evaluation
481 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
482 # Get the trackpadding from the current track
483 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
484 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
486 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
490 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
491 GENREID
=$
(do_getgenreid
"${CDGENRE}")
493 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
494 run_command tagtrack-
$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
495 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
496 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
497 "$ABCDETEMPDIR/track$1.$OUTPUT"
500 case "$OGGENCODERSYNTAX" in
502 # vorbiscomment can't do in-place modification, mv the file first
503 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
504 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
507 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
508 echo ARTIST
="$TRACKARTIST"
510 echo TITLE
="$TRACKNAME"
511 if [ -n "$CDYEAR" ]; then
514 if [ -n "$CDGENRE" ]; then
515 echo GENRE
="$CDGENRE"
517 echo TRACKNUMBER
=${TRACKNUM:-$1}
518 echo CDDB
=$CDDBDISCID
519 if [ "$(eval echo ${COMMENT})" != "" ]; then
520 case "$COMMENTOUTPUT" in
521 *=*) echo "$COMMENTOUTPUT";;
522 *) echo COMMENT
="$COMMENTOUTPUT";;
525 ) | run_command tagtrack-
$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
526 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
527 # Doublecheck that the commented file was created successfully before wiping the original
528 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
529 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
531 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
538 echo ARTIST
="$TRACKARTIST"
540 echo TITLE
="$TRACKNAME"
541 if [ -n "$CDYEAR" ]; then
544 if [ -n "$CDGENRE" ]; then
545 echo GENRE
="$CDGENRE"
547 echo TRACKNUMBER
=${TRACKNUM:-$1}
548 echo CDDB
=$CDDBDISCID
549 if [ "$(eval echo ${COMMENT})" != "" ]; then
550 case "$COMMENTOUTPUT" in
551 *=*) echo "$COMMENTOUTPUT";;
552 *) echo COMMENT
="$COMMENTOUTPUT";;
555 ) | run_command tagtrack-
$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
558 run_command tagtrack-
$1 true
561 run_command tagtrack-
$1 true
569 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
572 # The commands here don't go through run_command because they're never supposed to be silenced
573 echo "Batch encoding tracks: $TRACKQUEUE"
574 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
577 case "$MP3ENCODERSYNTAX" in
582 for UTRACKNUM
in $TRACKQUEUE
584 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
586 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
588 if [ "$RETURN" != "0" ]; then
589 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
591 for UTRACKNUM
in $TRACKQUEUE
593 echo encodetrack-
$UTRACKNUM >> status
601 # Other encoders fall through to normal encoding as the tracks
602 # have not been entered in the status file.
605 # do_encode [tracknumber] [hostname]
606 # If no hostname is specified, encode locally
608 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
611 if [ "$USEPIPES" = "y" ]; then
614 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
617 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
620 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
623 TEMPARG
="PIPE_$SPEEXENCODER"
626 TEMPARG
="PIPE_$MPPENCODER"
631 IN
="$ABCDETEMPDIR/track$1.wav"
634 case "$MP3ENCODERSYNTAX" in
635 # FIXME # check if mp3enc needs -if for pipes
649 # We need IN to proceed, if we are not using pipes.
650 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
651 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
655 OUT
="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
658 OUT
="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
661 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
664 if [ X
"$USEPIPES" = "Xy" ]; then
667 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
668 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
674 case "$MP3ENCODERSYNTAX" in
675 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
676 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
677 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
678 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
679 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
683 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
690 case "$OGGENCODERSYNTAX" in
691 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
692 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
696 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
703 case "$FLACENCODERSYNTAX" in
704 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
710 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
711 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
716 if [ "$(eval echo ${COMMENT})" != "" ]; then
719 *) COMMENT
="COMMENT=$COMMENT" ;;
721 COMMENT
="--comment \"$COMMENT\""
723 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
724 if [ ! "$DOTAG" = "y" ]; then
725 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
727 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
731 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
733 # I tried compiling the mppenc from corecodecs.org and got some
734 # errors, so I have not tried it myself.
735 ## FIXME ## Needs some cleanup to determine if an empty tag sent
736 ## FIXME ## to the encoder ends up empty.
737 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
741 # Only remove .wav if the encoding succeeded
742 if checkerrors
"encodetrack-(.{3,4})-$1"; then
743 run_command encodetrack-
$1 false
745 run_command encodetrack-
$1 true
746 if [ ! "$KEEPWAVS" = "y" ] ; then
751 if [ "$(checkstatus encode-output)" = "loud" ]; then
752 echo "HEH! The file we were about to encode disappeared:"
755 run_command encodetrack-
$1 false
759 # do_preprocess [tracknumber]
761 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
764 # IN="$ABCDETEMPDIR/track$1.wav"
765 # # We need IN to proceed.
766 # if [ -s "$IN" ] ; then
767 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
769 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
770 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
771 # case "$POSTPROCESSFORMAT" in
773 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
775 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
777 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
779 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
781 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
784 # # Only remove .wav if the encoding succeeded
785 # if checkerrors "preprocess-(.{3,4})-$1"; then
786 # run_command preprocess-$1 false
788 # run_command preprocess-$1 true
791 # if [ "$(checkstatus encode-output)" = "loud" ]; then
792 # echo "HEH! The file we were about to pre-process disappeared:"
795 # run_command preprocess-$1 false
800 # do_postprocess [tracknumber]
802 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
805 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
807 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
808 # # We need IN to proceed.
809 # if [ -s "$IN" ] ; then
810 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
811 # run_command '' echo "Post-processing track $1 of $TRACKS..."
812 # case "$POSTPROCESSFORMAT" in
814 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
816 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
818 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
820 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
822 # # Only remove .wav if the encoding succeeded
823 # if checkerrors "postprocess-(.{3,4})-$1"; then
824 # run_command postprocess-$1 false
826 # run_command postprocess-$1 true
829 # if [ "$(checkstatus encode-output)" = "loud" ]; then
830 # echo "HEH! The file we were about to post-process disappeared:"
833 # run_command postprocess-$1 false
848 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
852 # The commands here don't go through run_command because they're never supposed to be silenced
853 echo "Batch analizing gain in tracks: $TRACKQUEUE"
858 for UTRACKNUM
in $TRACKQUEUE
860 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
862 # XXX: Hard-coded batch option!
863 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
865 if [ "$RETURN" != "0" ]; then
866 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
868 for UTRACKNUM
in $TRACKQUEUE
870 echo normalizetrack-
$UTRACKNUM >> status
878 # NORMALIZER, NORMALIZEROPTS
879 do_batch_normalize
()
881 # The commands here don't go through run_command because they're never supposed to be silenced
882 echo "Batch normalizing tracks: $TRACKQUEUE"
887 for UTRACKNUM
in $TRACKQUEUE
889 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
891 # XXX: Hard-coded batch option!
892 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
894 if [ "$RETURN" != "0" ]; then
895 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
897 for UTRACKNUM
in $TRACKQUEUE
899 echo normalizetrack-
$UTRACKNUM >> status
905 # do_normalize [tracknumber]
907 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
910 IN
="$ABCDETEMPDIR/track$1.wav"
911 if [ -e "$IN" ] ; then
912 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
913 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
915 if [ "$(checkstatus encode-output)" = "loud" ]; then
916 echo "HEH! The file we were about to normalize disappeared:"
919 run_command normalizetrack-
$1 false
"File $IN was not found"
923 # do_move [tracknumber]
924 # Deduces the outfile from environment variables
925 # Creates directory if necessary
927 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
930 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
934 OUTPUT
=$OGGOUTPUTCONTAINER
937 OUTPUT
=$FLACOUTPUTCONTAINER
940 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
941 # Munge filenames as follows:
946 # Eat control characters
947 ALBUMFILE
=$
(mungefilename
"$DALBUM")
948 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
949 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
950 GENRE
=$
(mungegenre
"$GENRE")
952 # If we want to start the tracks with a given number, we need to modify the
953 # TRACKNUM value before evaluation
954 if [ -n "$STARTTRACKNUMBER" ] ; then
955 # Get the trackpadding from the current track
956 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
957 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
959 TRACKNUM
=${UTRACKNUM}
961 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
962 # TRACKFILE, and TRACKNUM.
963 if [ "$VARIOUSARTISTS" = "y" ]; then
964 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
966 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
968 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
969 OUTPUTFILEDIR
=$
(dirname "$OUTPUTDIR/$OUTPUTFILE")
970 # mkdir -p shouldn't return an error if the directory already exists
971 mkdir
-p "$OUTPUTFILEDIR"
972 # Silence the Moving output since it overlaps with encoding processes...
973 #run_command '' vecho "Moving track$1.$OUTPUT to $OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
974 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
975 # Lets move the cue file
976 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
977 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
978 if checkstatus movecue-
$OUTPUT; then :; else
979 # Silence the Copying output since it overlaps with encoding processes...
980 #run_command '' vecho "Copying cue file to its destination directory..."
981 if checkstatus onetrack
>/dev
/null
; then
983 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
984 # http://brianvictor.tripod.com/mp3cue.htm#details
985 [a-z0-9
][a-z0-9
][a-z0-9
])
986 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
989 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
993 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
995 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1003 # Create the playlist if wanted
1005 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1006 # VARIOUSARTISTS, OUTPUTDIR
1009 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1011 # Create a playlist file for the playlist data to go into.
1012 # We used to wipe it out if it existed. Now we request permision if interactive.
1013 for LASTTRACK
in $TRACKQUEUE; do :; done
1014 ALBUMFILE
=$
(mungefilename
"$DALBUM")
1015 ARTISTFILE
=$
(mungefilename
"$DARTIST")
1016 GENRE
=$
(mungegenre
"$GENRE")
1017 YEAR
=${CDYEAR:-$CDYEAR}
1018 if [ "$VARIOUSARTISTS" = "y" ] ; then
1019 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
1021 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
1023 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1024 mkdir
-p "$FINALPLAYLISTDIR"
1025 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1026 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1027 if [ "$INTERACTIVE" = "y" ]; then
1028 while [ "$DONE" != "y" ]; do
1030 case $ERASEPLAYLIST in
1031 e|E|a|A|k|K
) DONE
=y
;;
1039 # Once we erase the playlist, we use append to create the new one.
1040 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1042 # The playlist does not exist, so we can safelly use append to create the new list
1045 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1046 touch "$OUTPUTDIR/$PLAYLISTFILE"
1047 for UTRACKNUM
in $TRACKQUEUE
1049 # Shares some code with do_move since the filenames have to match
1050 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1051 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
1053 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
1054 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
1055 # If we want to start the tracks with a given number, we need to modify the
1056 # TRACKNUM value before evaluation
1057 if [ -n "$STARTTRACKNUMBER" ] ; then
1058 # Get the trackpadding from the current track
1059 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
1060 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1062 TRACKNUM
=${UTRACKNUM}
1064 if [ "$VARIOUSARTISTS" = "y" ]; then
1065 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1067 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1069 if [ "$VARIOUSARTISTS" = "y" ]; then
1070 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1071 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1073 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1076 if [ "$PLAYLISTDATAPREFIX" ]; then
1077 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1079 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1084 ## this will convert the playlist to have CRLF line-endings, if specified
1085 ## (some hardware players insist on CRLF endings)
1086 if [ "$DOSPLAYLIST" = "y" ]; then
1087 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1088 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1089 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1091 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1096 # This essentially the start of things
1099 # Query the CD to get the track info, unless the user specified -C
1100 # or we are using some actions which do not need the CDDB data at all
1101 #if [ ! X"$EXPACTIONS" = "X" ]; then
1103 #elif [ -z "$DISCID" ]; then
1104 if [ -z "$DISCID" ]; then
1105 vecho
-n "Getting CD track info... "
1106 # In OSX, unmount the disc before a query
1107 if [ "$OSFLAVOUR" = "OSX" ]; then
1108 disktool
-u ${CDROM#/dev/}
1110 TRACKINFO
=$
($CDDISCID $CDROM)
1111 # Make sure there's a CD in there by checking cd-discid's return code
1112 if [ "$?" = "1" ]; then
1113 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1116 # In OSX, remount the disc again
1117 if [ "$OSFLAVOUR" = "OSX" ]; then
1118 disktool
-m ${CDROM#/dev/}
1122 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1125 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1126 # This needs to be done now because a section of the resuming code will need
1129 # get the number of digits to pad TRACKNUM with - we'll use this later
1130 # a CD can only hold 99 tracks, but since we support a feature for starting
1131 # numbering the tracks from a given number, we might need to set it as a
1132 # variable for the user to define... or obtain it somehow.
1133 if [ "$PADTRACKS" = "y" ] ; then
1137 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1138 if [ -z "$TRACKQUEUE" ]; then
1139 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1140 case "$CDROMREADERSYNTAX" in
1142 if [ "$WEHAVEACD" = "y" ]; then
1143 vecho
"Querying the CD for audio tracks..."
1144 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1146 if [ ! "$RET" = "0" ];then
1147 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1149 TRACKS
="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ' )"
1150 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1152 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks
; then
1153 TRACKS
=$
( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" )
1155 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1159 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1162 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1164 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1165 echo "The disc does not contain any tracks. Giving up..."
1168 echo -n "Grabbing entire CD - tracks: "
1169 if [ ! "$PADTRACKS" = "y" ] ; then
1170 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1172 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1174 while [ "$X" -ne "$TRACKS" ]
1176 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1177 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
1181 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1182 # User-supplied track queue.
1183 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1184 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1185 # Once cleaned, obtain the highest value in the trackqueue for number padding
1186 for LASTTRACK
in $TRACKQUEUE; do :; done
1187 if [ ! "$PADTRACKS" = "y" ] ; then
1188 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1190 # Now we normalize the trackqueue
1191 for TRACK
in $TRACKQUEUE ; do
1192 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1193 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1195 TRACKQUEUE
=$PADTRACKQUEUE
1196 echo Grabbing tracks
: "$TRACKQUEUE"
1199 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1201 # We have the discid, create a temp directory after it to store all the temp
1204 if [ -e "$ABCDETEMPDIR" ]; then
1205 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1206 # It already exists, see if it's a directory
1207 if [ ! -d "$ABCDETEMPDIR" ]; then
1208 # This is a file/socket/fifo/device/etc, not a directory
1211 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1212 echo "Please investigate, remove it, and rerun abcde." >&2
1216 # It's a directory, let's see if it's owned by us
1217 if [ ! -O "$ABCDETEMPDIR" ]; then
1218 # Nope, complain and exit
1220 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1221 echo "Please investigate, remove it, and rerun abcde." >&2
1225 # See if it's populated
1226 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1227 # Wipe and start fresh
1228 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1229 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1230 if [ "$INTERACTIVE" = "y" ]; then
1236 if [ "$ANSWER" != "y" ]; then
1239 rm -rf "$ABCDETEMPDIR" ||
exit 1
1240 mkdir
"$ABCDETEMPDIR"
1241 if [ "$?" -gt "0" ]; then
1242 # Directory already exists or could not be created
1243 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1247 # Everything is fine. Check for ^encodetracklocation-
1248 # and encode-output entries in the status file and
1249 # remove them. These are not relevant across sessions.
1250 if [ -f "$ABCDETEMPDIR/status" ]; then
1251 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1252 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1253 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1255 # Remove old error messages
1256 if [ -f "$ABCDETEMPDIR/errors" ]; then
1257 rm -f "$ABCDETEMPDIR/errors"
1261 # We are starting from scratch
1262 mkdir
"$ABCDETEMPDIR"
1263 if [ "$?" -gt "0" ]; then
1264 # Directory already exists or could not be created
1265 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1268 cat /dev
/null
> "$ABCDETEMPDIR/status"
1270 if [ X
"$MAKECUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1271 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1272 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1273 vecho
"Creating cue file..."
1274 $MKCUE $MKCUEOPTS > "$ABCDETEMPDIR/$CUEFILE"
1275 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1278 # If we got the CDPARANOIA status and it is not recorded, save it now
1279 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1280 if checkstatus cdparanoia-audio-tracks
; then :; else
1281 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1282 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1287 # Create the discid file
1288 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1292 # Create a proper CUE file based on the CUE file we created before.
1295 # FIXME # we can get the name of the cuefile from the status file
1296 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1297 CUEFILE_OUT
=$CUEFILE_IN.out
1298 ### FIXME ### checkstatus cddb
1299 if [ -e "$CDDBDATA" ]; then
1300 vecho
"Adding metadata to the cue file..."
1301 # FIXME It doesn't preserve spaces! Why?
1302 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1304 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1305 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1306 cat "$CUEFILE_IN" |
while read line
1308 if echo "$line" |
grep -q "INDEX"
1310 eval track
="\$TRACK$n"
1312 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1314 echo "$line" >> "$CUEFILE_OUT"
1316 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1317 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1323 # Parses a CDDB file and outputs the title and the track names.
1324 # Variables: CDDBFILE
1328 # List out disc title/author and contents
1329 if [ "$ONETRACK" = "y" ]; then
1330 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1332 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1333 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1334 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1335 if [ X
"$PARSEDYEAR" = "X" ]; then
1336 echo "Year: $PARSEDYEAR"
1339 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1340 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1341 if [ X
"$PARSEDGENRE" = "X" ]; then
1342 echo "Genre: $PARSEDGENRE"
1345 if [ ! "$ONETRACK" = "y" ]; then
1346 for TRACK
in $
(f_seq_row
1 $TRACKS)
1348 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1354 # Check for a local CDDB file, and report success
1357 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1359 CDDBLOCALSUCCESS
="n"
1360 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1361 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1364 # If the user has selected to check a local CDDB repo, we proceed with it
1365 if [ -r "${CDDBLOCALFILE}" ]; then
1366 # List out disc title/author and contents
1367 do_cddbparse
"${CDDBLOCALFILE}"
1368 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1369 if [ "$INTERACTIVE" = "y" ]; then
1371 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1372 echo -n 'Invalid selection. Please answer "y" or "n": '
1375 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1379 if [ "$USELOCALRESP" = "y" ]; then
1380 #echo "Using local copy of CDDB data"
1381 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1382 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1383 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1384 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1385 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1386 CDDBLOCALSUCCESS
="y"
1388 #echo "Not using local copy of CDDB data"
1389 CDDBLOCALSUCCESS
="n"
1392 CDDBLOCALSUCCESS
="n"
1400 # Perform CDDB protocol version check if it hasn't already been done
1401 if checkstatus cddb-statcomplete
; then :; else
1402 if [ "$CDDBAVAIL" = "n" ]; then
1404 echo 503 > "$ABCDETEMPDIR/cddbstat"
1407 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1408 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1409 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1410 vecho
"Checking CDDB server status..."
1411 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1412 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1413 case "$RESPONSECODE" in
1414 210) # 210 OK, status information follows (until terminating `.')
1417 501|
*) # 501 Illegal CDDB protocol level: <n>.
1418 CDDBPROTO
=`expr $CDDBPROTO - 1`
1422 if test $rc -eq 1; then
1426 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1434 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1435 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1437 # Perform CDDB query if it hasn't already been done
1438 if checkstatus cddb-querycomplete
; then :; else
1439 if [ "$CDDBAVAIL" = "n" ]; then
1441 echo 503 > "$ABCDETEMPDIR/cddbquery"
1442 # The default CDDBLOCALSUCCESS is "n"
1443 # This part will be triggered if the user CDDB repo does not
1444 # contain the entry, or if we are not trying to use the repo.
1446 vecho
"Querying the CDDB server..."
1447 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1448 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1449 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1455 # no match found in database,
1456 # wget/fetch error, or user requested not to use CDDB
1457 # Make up an error code (503) that abcde
1458 # will recognize in do_cddbread
1459 # and compensate by making a template
1460 echo 503 > "$ABCDETEMPDIR/cddbquery"
1462 *) # strange and unknown error
1463 echo ERRORCODE
=$ERRORCODE
1464 echo "abcde: $CDDBTOOL returned unknown error code"
1468 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1475 # If it's not to be used, generate a template.
1476 # Then, display it (or them) and let the user choose/edit it
1477 if checkstatus cddb-readcomplete
; then :; else
1478 vecho
"Obtaining CDDB results..."
1479 # If CDDB is to be used, interpret the query results and read all
1480 # the available entries.
1481 rm -f "$ABCDETEMPDIR/cddbchoices"
1482 CDDBCHOICES
=1 # Overridden by multiple matches
1483 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1484 case "$RESPONSECODE" in
1486 # One exact match, retrieve it
1487 # 200 [section] [discid] [artist] / [title]
1488 if checkstatus cddb-read-1-complete
; then :; else
1489 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1490 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1491 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1492 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1493 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1495 # List out disc title/author and contents
1496 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1497 for TRACK
in $
(f_seq_row
1 $TRACKS)
1499 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1501 echo >> "$ABCDETEMPDIR/cddbchoices"
1505 case "$RESPONSECODE" in
1506 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1507 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1508 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1510 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1511 # List out disc title/author and contents of template
1512 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1514 for TRACK
in $
(f_seq_row
1 $TRACKS)
1516 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1518 echo >> "$ABCDETEMPDIR/cddbchoices"
1519 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1520 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1523 # Multiple exact, (possibly multiple) inexact matches
1525 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1526 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
1527 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1528 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1529 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1531 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1533 vecho
-n "Retrieving multiple matches... "
1534 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1535 read DISCINFO
# eat top line
1539 if checkstatus cddb-read-
$X-complete; then :; else
1540 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1541 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1543 # List out disc title/author and contents
1544 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1545 for TRACK
in $
(f_seq_row
1 $TRACKS)
1547 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1549 echo >> "$ABCDETEMPDIR/cddbchoices"
1552 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1556 for TRACK
in $
(f_seq_row
1 $TRACKS)
1558 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1560 echo >> "$ABCDETEMPDIR/cddbchoices"
1561 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1562 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1565 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1572 if checkstatus cddb-edit
>/dev
/null
; then
1573 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1574 VARIOUSARTISTS
="$(checkstatus variousartists)"
1575 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1578 if [ "$INTERACTIVE" = "y" ]; then
1579 # We should show the CDDB results both when we are not using the local CDDB repo
1580 # or when we are using it but we could not find a proper match
1581 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1582 # Display the $ABCDETEMPDIR/cddbchoices file created above
1583 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1584 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1585 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1586 CHOICE
=$
(checkstatus cddb-choice
)
1587 if [ -n "$CHOICE" ] ; then
1588 case $CDDBCHOICES in
1589 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1591 echo "Selected: #$CHOICE"
1592 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1596 # The user has a choice to make, display the info in a pager if necessary
1597 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1598 # Use the debian sensible-pager wrapper to pick the pager
1599 # user has requested via their $PAGER environment variable
1600 if [ -x "/usr/bin/sensible-pager" ]; then
1601 /usr
/bin
/sensible-pager
"$ABCDETEMPDIR/cddbchoices"
1602 elif [ -x "$PAGER" ]; then
1603 # That failed, try to load the preferred editor, starting
1604 # with their PAGER variable
1605 $PAGER "$ABCDETEMPDIR/cddbchoices"
1606 # If that fails, check for less
1607 elif [ -x /usr
/bin
/less ]; then
1608 /usr
/bin
/less -f "$ABCDETEMPDIR/cddbchoices"
1609 # more should be on all UNIX systems
1610 elif [ -x /bin
/more ]; then
1611 /bin
/more "$ABCDETEMPDIR/cddbchoices"
1613 # No bananas, just cat the thing
1614 cat "$ABCDETEMPDIR/cddbchoices" >&2
1617 # It's all going to fit in one page, cat it
1618 cat "$ABCDETEMPDIR/cddbchoices" >&2
1623 # I'll take CDDB read #3 for $400, Alex
1624 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1625 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1627 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1628 if echo $CDDBCHOICE |
egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1629 if [ ! X
"$DIFF" = "X" ]; then
1630 # We parse the 2 choices to diff, store them in temporary files and diff them.
1631 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
1632 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1634 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1)
1635 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2)
1636 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..."
1637 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2"
1639 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1642 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1643 # Make sure we get a valid choice
1644 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1645 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1649 if [ "$CDCHOICENUM" = "0" ]; then
1650 vecho
"Creating empty CDDB template..."
1652 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1654 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1655 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1657 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1661 # We need some code to show the selected option when local repository is selected and we have found a match
1662 vecho
"Using cached CDDB match..." >&2
1663 # Display the $ABCDETEMPDIR/cddbchoices file created above
1664 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1665 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1666 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1667 CHOICE
=$
(checkstatus cddb-choice
)
1668 if [ "$USELOCALRESP" = "y" ]; then :; else
1669 if [ -n "$CHOICE" ] ; then
1670 case $CDDBCHOICES in
1673 echo "Selected template."
1675 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1677 echo "Selected: #$CHOICE"
1678 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1686 # We're noninteractive - pick the first choice.
1687 # But in case we run a previous instance and selected a choice, use it.
1688 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1689 # Show the choice if we are not using the locally stored one
1690 # or when the local search failed to find a match.
1691 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1692 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1693 #if [ "$PREVIOUSCHOICE" ]; then
1694 cat "$ABCDETEMPDIR/cddbchoices"
1697 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1698 CDCHOICENUM
=$PREVIOUSCHOICE
1701 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1703 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1708 if checkstatus cddb-choice
>/dev
/null
; then :; else
1709 echo "abcde: internal error: cddb-choice not recorded." >&2
1712 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1713 echo -n "Edit selected CDDB data? [y/n] (" >&2
1714 if [ "$INTERACTIVE" = "y" ]; then
1715 if [ "$UNKNOWNDISK" = "y" ]; then
1718 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1727 if [ "$EDITCDDB" = "y" ]; then
1728 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1730 # Use the debian sensible-editor wrapper to pick the editor that the
1731 # user has requested via their $EDITOR environment variable
1732 if [ -x "/usr/bin/sensible-editor" ]; then
1733 /usr
/bin
/sensible-editor
"$CDDBDATA"
1734 elif [ -n "$EDITOR" ]; then
1735 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1736 # That failed, try to load the preferred editor, starting
1737 # with their EDITOR variable
1738 eval $
(echo "$EDITOR") \"$CDDBDATA\"
1740 # If that fails, check for a vi
1741 elif which vi
>/dev
/null
2>&1; then
1743 elif [ -x /usr
/bin
/vim
]; then
1744 /usr
/bin
/vim
"$CDDBDATA"
1745 elif [ -x /usr
/bin
/vi
]; then
1746 /usr
/bin
/vi
"$CDDBDATA"
1747 elif [ -x /bin
/vi
]; then
1749 # nano should be on all (modern, i.e., sarge) debian systems
1750 elif which nano
>/dev
/null
2>&1 ; then
1752 elif [ -x /usr
/bin
/nano
]; then
1753 /usr
/bin
/nano
"$CDDBDATA"
1754 # mg should be on all OpenBSD systems
1755 elif which mg
>/dev
/null
2>&1 ; then
1757 elif [ -x /usr
/bin
/mg
]; then
1758 /usr
/bin
/mg
"$CDDBDATA"
1761 echo "No editor available. Check your EDITOR environment variable." >&2
1763 # delete editor backup file if it exists
1764 if [ -w "$CDDBDATA~" ]; then
1769 # Some heuristics first. Look at Disc Title, and if it starts with
1770 # "Various", then we'll assume Various Artists
1771 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1772 echo "Looks like a Multi-Artist CD" >&2
1775 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1776 if [ "$INTERACTIVE" = "y" ]; then
1783 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1786 # Need NUMTRACKS before cddb-tool will return it:
1787 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1788 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1789 # More than 1/2 tracks contain a "/", so guess forward
1791 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1792 # More than 1/2 contain a "-", so guess forward-dash
1794 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1795 # More than 1/2 contain something in parens, so guess trailing-paren
1799 echo "1) Artist / Title" >&2
1800 echo "2) Artist - Title" >&2
1801 echo "3) Title / Artist" >&2
1802 echo "4) Title - Artist" >&2
1803 echo "5) Artist: Title" >&2
1804 echo "6) Title (Artist)" >&2
1805 echo "7) This is a single-artist CD" >&2
1806 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1807 if [ "$INTERACTIVE" = "y" ]; then
1808 read VARIOUSARTISTSTYLE
1810 echo $DEFAULTSTYLE >&2
1811 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1813 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1814 # If they press Enter, then the default style (0) was chosen
1815 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1816 echo "Invalid selection. Please choose a number between 1 and 7."
1817 echo -n "Selection [1-7]: "
1818 read VARIOUSARTISTSTYLE
1819 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1821 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1822 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1824 vecho
"Selected: $VARIOUSARTISTSTYLE"
1825 case "$VARIOUSARTISTSTYLE" in
1827 VARIOUSARTISTSTYLE
=forward
1830 VARIOUSARTISTSTYLE
=forward-dash
1833 VARIOUSARTISTSTYLE
=reverse
1836 VARIOUSARTISTSTYLE
=reverse-dash
1839 VARIOUSARTISTSTYLE
=colon
1842 VARIOUSARTISTSTYLE
=trailing-paren
1850 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1851 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1853 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1854 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1855 # This works but does not have the necessary error checking
1856 # yet. If you are familiar with the CDDB spec
1857 # (see http://www.freedb.org/src/latest/DBFORMAT)
1858 # and can create an error-free entry on your own, then put
1859 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1860 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1861 # your abcde.conf to change the email address submissions are
1864 # submit the modified file, if they want
1865 if [ "$NOSUBMIT" != "y" ]; then
1866 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1868 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1869 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1871 echo -n 'Invalid selection. Please answer "y" or "n": '
1874 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1875 echo -n "Sending..."
1876 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1882 # Make sure the cache directory exists
1883 mkdir
-p $CDDBLOCALDIR
1884 # Cache edited CDDB entry in the user's cddb dir
1885 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1886 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1889 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1892 # do_cdread [tracknumber]
1893 # do_cdread onetrack [firsttrack] [lasttrack]
1897 # The commands here don't go through run_command because they're never supposed to be silenced
1898 # return codes need to be doublechecked anyway, however
1899 if [ "$1" = "onetrack" ]; then
1900 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1901 # FIXME # Until then, we grab the whole CD in one track, no matter what
1903 # We need the first and last track for cdda2wav
1906 UTRACKNUM
=$FIRSTTRACK
1907 case "$CDROMREADERSYNTAX" in
1908 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
1909 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTRACK" ;;
1910 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1916 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1917 if [ "$USEPIPES" = "y" ]; then
1918 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1919 FILEARG
="${!TEMPARG}"
1921 PIPE_MESSAGE
="and encoding "
1923 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1924 case "$CDROMREADERSYNTAX" in
1925 ## FIXME ## Find the case for dagrab, to avoid exceptions
1927 FILEARG
="-f $WAVDATA"
1935 if [ "$1" = "onetrack" ]; then
1936 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
1938 if [ -r "$CDDBDATA" ]; then
1939 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1940 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1942 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1945 case "$CDROMREADERSYNTAX" in
1947 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
1949 if [ "$OSFLAVOUR" = "OSX" ] ; then
1950 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1951 disktool
-u ${CDROM#/dev/} 0
1952 # Also, in OSX the cdrom device for cdda2wav changes...
1953 CDDA2WAVCDROM
="IODVDServices"
1954 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1955 CDDA2WAVCDROM
="$CDROMID"
1957 if [ "$CDROMID" = "" ]; then
1958 CDDA2WAVCDROM
="$CDROM"
1960 CDDA2WAVCDROM
="$CDROMID"
1963 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
1965 ## FIXME ## We have an exception for dagrab, since it uses -f
1966 ## FIXME ## Shall we just use -f $FILEARG ??
1967 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
1970 # Find the track's mounted path
1971 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1972 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1973 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
1974 # If the file exists, copy it
1975 if [ -e "$FILEPATH" ] ; then
1976 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
1980 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
1984 # If we get some error or we get some missing wav
1985 # (as long as we dont use pipes)
1986 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
1987 # Thank goodness errors is only machine-parseable up to the
1988 # first colon, otherwise this woulda sucked
1989 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1990 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
1992 if [ "$USEPIPES" = "y" ]; then
1993 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1995 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1999 if [ "$USEPIPES" = "y" ]; then
2000 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2002 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2003 if [ "$1" = "onetrack" ]; then
2004 echo onetrack
>> "$ABCDETEMPDIR/status"
2011 # No values accepted, only uses env variables
2014 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2015 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2017 echo "abcde: unable to set the device speed" >&2
2023 # vecho outputs a message if EXTRAVERBOSE is selected
2026 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2031 # User-redefinable functions
2032 # Custom filename munging:
2035 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2036 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2039 # Custom genre munging:
2042 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2046 # Empty pre_read function, to be defined in the configuration file.
2053 # Empty post_read function, to be defined in the configuration file.
2059 ###############################################################################
2062 # Start of execution
2063 ###############################################################################
2066 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2067 CDDBSUBMIT
=freedb-submit@freedb.org
2069 HELLOINFO
="$(whoami)@$(hostname)"
2071 CDDBLOCALDIR
="$HOME/.cddb"
2074 # List of fields we parse and show during the CDDB parsing...
2075 SHOWCDDBFIELDS
="year,genre"
2078 CDROMREADERSYNTAX
=cdparanoia
2079 ENCODERSYNTAX
=default
2081 MP3ENCODERSYNTAX
=default
2082 OGGENCODERSYNTAX
=default
2083 FLACENCODERSYNTAX
=default
2084 SPEEXENCODERSYNTAX
=default
2085 MPPENCODERSYNTAX
=default
2086 NORMALIZERSYNTAX
=default
2088 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2089 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2090 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2091 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2092 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2093 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2094 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2095 PLAYLISTDATAPREFIX
=''
2096 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2097 VAPLAYLISTDATAPREFIX
=''
2105 VARIOUSARTISTSTYLE
=forward
2109 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2110 # i.e. CDROMID="1,0,0"
2112 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2113 # If we are using the ide-scsi emulation layer, we need to define a "g"
2114 CDPARANOIACDROMBUS
="d"
2116 # program paths - defaults to checking your $PATH
2122 XINGMP3ENC
=xingmp3enc
2136 CDPARANOIA
=cdparanoia
2145 VORBISCOMMENT
=vorbiscomment
2147 NORMALIZE
=normalize-audio
2149 VORBISGAIN
=vorbisgain
2154 # Options for programs called from abcde
2186 VORBISCOMMENTOPTS
="-R"
2187 METAFLACOPTS
="--no-utf8-convert"
2189 # Default to one process if -j isn't specified
2192 # List of actions to perform - by default, run to completion
2193 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2195 # List of prefered outputs - by default, run with whatever we have in the path
2196 # This option is basicaly for Debian package dependencies
2197 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
2199 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2200 # Let's use these checkings to determine the OS flavour, which will be used later
2201 if [ X$
(uname
) = "XFreeBSD" ] ; then
2205 elif [ X$
(uname
) = "XDarwin" ] ; then
2208 # We should have disktool in OSX, but let's be sure...
2210 CDROMREADERSYNTAX
=cddafs
2211 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2218 # If CDDBAVAIL is set to n, no CDDB read is done
2219 # If USEID3 is set to n, no ID3 tagging is done
2224 if [ -z "$OUTPUTDIR" ]; then
2228 if [ -z "$WAVOUTPUTDIR" ]; then
2229 WAVOUTPUTDIR
="$OUTPUTDIR"
2232 # Load system defaults
2233 if [ -r /etc
/abcde.conf
]; then
2236 # Load user preference defaults
2237 if [ -r $HOME/.abcde.conf
]; then
2241 # By this time, we need some HTTPGETOPTS already defined.
2242 # If the user has defined a non-default HTTPGET method, we should not be empty.
2244 if [ "$HTTPGETOPTS" = "" ] ; then
2246 wget
) HTTPGETOPTS
="-q -O -";;
2247 curl
) HTTPGETOPTS
="-f -s";;
2248 fetch
)HTTPGETOPTS
="-q -o -";;
2249 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2253 # If the CDROM has not been set yet, find a suitable one.
2254 # If this is a devfs system, default to /dev/cdroms/cdrom0
2255 # instead of /dev/cdrom
2256 if [ "$CDROM" = "" ] ; then
2257 if [ -e /dev
/cdroms
/cdrom0
]; then
2258 CDROM
=/dev
/cdroms
/cdrom0
2259 elif [ -e /dev
/cdrom
]; then
2261 elif [ -e /dev
/cd0c
]; then
2263 elif [ -e /dev
/acd0c
]; then
2265 elif [ -e /dev
/disk1
]; then
2270 # Parse command line options
2271 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2272 while getopts 1a
:bc:C
:d
:Dehj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
2275 a
) ACTIONS
="$OPTARG" ;;
2276 A
) EXPACTIONS
="$OPTARG";;
2278 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2279 C
) DISCID
="${OPTARG#abcde.}" ;;
2280 d
) CDROM
="$OPTARG" ;;
2282 e
) ERASEENCODEDSTATUS
=y
;;
2284 e
) ERASEENCODEDSTATUS
=y
;;
2285 # f) FORCECDDBUSELOCAL=y ;;
2287 j
) MAXPROCS
="$OPTARG" ;;
2290 L
) CDDBUSELOCAL
=y
;;
2295 o
) OUTPUTTYPE
="$OPTARG" ;;
2298 r
) REMOTEHOSTS
="$OPTARG" ;;
2300 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2301 S
) CDSPEEDVALUE
="$OPTARG" ;;
2302 # t) PREPROCESSFORMATS="$OPTARG"
2304 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2305 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2306 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2308 echo "This is abcde v$VERSION."
2309 echo "Usage: abcde [options] [tracks]"
2310 echo "abcde -h for extra help"
2313 V
) EXTRAVERBOSE
="y" ;;
2315 w
) COMMENT
="$OPTARG" ;;
2316 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2317 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2319 echo "abcde error: argument of -W must be integer"
2327 shift $
(($OPTIND - 1))
2329 # Decide if we can continue.
2330 if [ "$ONETRACK" = "y" ]; then
2331 # FIXME # remove check as soon as we find out about the other readers
2332 case "$CDROMREADERSYNTAX" in
2335 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2338 if [ "$BATCH" = "y" ]; then
2339 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2342 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2343 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2344 if [ $# -gt 0 ]; then
2345 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2348 while [ $# -gt 0 ]; do
2349 # Range parsing code courtesy of Vincent Ho
2350 RSTART
=$
(echo $1 | cut
-f1 -d-)
2351 REND
=$
(echo $1 | cut
-f2 -d-)
2352 if [ "$RSTART" = "$REND" ]; then
2355 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2357 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2362 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2363 # List of experimental actions: retag,transcode
2365 # Determine what actions are to be done from $ACTIONS and set the
2366 # following environment variables for them:
2378 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2383 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2384 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2385 encode
) DOENCODE
=y
; DOREAD
=y
;;
2386 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2387 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2388 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2389 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2394 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
2395 case $SHOWCDDBFIELD in
2396 y
*|Y
*) SHOWCDDBYEAR
="y";;
2397 g
*|G
*) SHOWCDDBGENRE
="y";;
2404 # At this point a CDROM has to be defined, so we check it exists.
2405 if [ X
"$CDROM" != "X" ] ; then
2406 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2407 if [ "$OSFLAVOUR" = "FBSD" ]; then
2408 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2409 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2410 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2414 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2415 echo "abcde error: CDROM device cannot be found." >&2
2418 # avoid processing if we are not going to hit the CDROM.
2419 elif [ X
"$DOREAD" = "Xy" ]; then
2420 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2424 # USEPIPES pre-tests, before we get into more serious stuff
2425 # Not compatible with:
2426 # - multiple outputs
2428 # - lowdisk algorithm
2430 if [ X
"$USEPIPES" = "Xy" ]; then
2431 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
2432 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
2435 if [ X
"$DONORMALIZE" = "Xy" ]; then
2436 echo "abcde error: Unix pipes not compatible with normalizer"
2437 # FIXME # Do we need to exit or shall we just disable the mode?
2440 if [ X
"$DOENCODE" = "Xn" ]; then
2441 vecho
"Disabling Unix pipes since we are not encoding!"
2444 if [ X
"$LOWDISK" = "Xy" ]; then
2445 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2450 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2451 if [ X
"$OUTPUTTYPE" = "X" ]; then
2452 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
2453 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2454 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2455 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
2456 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
2457 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2461 if [ X
"$OUTPUTTYPE" = "X" ]; then
2462 echo "abcde error: no encoder found in the PATH" >&2
2463 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2468 # Decide which CDROM reader we're gonna use
2469 case "$CDROMREADERSYNTAX" in
2471 CDROMREADER
="$CDPARANOIA"
2472 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2475 CDROMREADER
="$CDDA2WAV"
2476 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2479 CDROMREADER
="$DAGRAB"
2480 CDROMREADEROPTS
="$DAGRABOPTS"
2483 CDROMREADER
="$CDDAFS"
2484 CDROMREADEROPTS
="$CDDAFSOPTS"
2488 # There's only one normalize...
2489 case "$NORMALIZERSYNTAX" in
2491 NORMALIZER
="$NORMALIZE"
2492 NORMALIZEROPTS
="$NORMALIZEOPTS"
2496 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2497 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
2498 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
); do
2500 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2501 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2502 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2503 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2504 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2507 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
); do
2508 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2509 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2511 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2514 # 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
2516 # Getting ready for multiple output changes
2517 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2521 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2522 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2523 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2524 OGGOUTPUTCONTAINER
=ogg
2527 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2528 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2531 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2532 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2535 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
2538 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
2540 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2546 # decide which encoder
2547 case "$MP3ENCODERSYNTAX" in
2549 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2553 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2557 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2558 MP3ENCODER
="$BLADEENC"
2561 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2565 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2566 MP3ENCODER
="$XINGMP3ENC"
2569 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2570 MP3ENCODER
="$MP3ENC"
2573 case "$OGGENCODERSYNTAX" in
2575 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2576 OGGENCODER
="$VORBIZE"
2579 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2580 OGGENCODER
="$OGGENC"
2583 case "$FLACENCODERSYNTAX" in
2585 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2587 # FLAC streams can be encapsulated on a Ogg transport layer
2588 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2589 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2590 echo " due to problem with adding comments to such files" >&2
2592 FLACOUTPUTCONTAINER
=ogg
2594 FLACOUTPUTCONTAINER
=flac
2598 case "$SPEEXENCODERSYNTAX" in
2600 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2601 SPEEXENCODER
="$SPEEXENC"
2604 case "$MPPENCODERSYNTAX" in
2606 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2607 MPPENCODER
="$MPPENC"
2613 if [ "$ID3TAGV" = "1" ]; then
2615 TAGGEROPTS
="$ID3OPTS"
2618 TAGGEROPTS
="$ID3V2OPTS"
2621 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2622 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2623 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2624 echo " due to problem with adding comments to such files" >&2
2626 OGGOUTPUTCONTAINER
=ogg.ogg
2627 FLACOUTPUTCONTAINER
=flac.ogg
2628 vecho
"abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2631 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2633 if [ "$ENCNICE" ]; then
2634 ENCNICE
="-n $ENCNICE"
2636 if [ "$READNICE" ]; then
2637 READNICE
="-n $READNICE"
2639 if [ "$DISTMP3NICE" ]; then
2640 DISTMP3NICE
="-n $DISTMP3NICE"
2643 # Don't check for stuff if it's not needed
2644 if [ "$REMOTEHOSTS" ]; then
2647 if [ "$DONORMALIZE" = "y" ]; then
2650 if [ "$EJECTCD" = "y" ]; then
2653 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2656 if [ "$CUEFILE" = "y" ]; then
2660 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2661 case "$CDROMREADERSYNTAX" in
2662 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2667 # Rippers with USEPIPE support
2668 # FIXME # Include here all the rippers we can figure out support pipes
2671 # Encoders with USEPIPE support
2672 # FIXME # Include here all the encoders we can figure out support pipes
2677 # Figure out if we can use pipes with the ripper/encoder combination
2679 if [ "$USEPIPES" = "y" ]; then
2680 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2683 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2685 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2687 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
2689 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2691 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2693 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2694 echo "abcde error: no support for pipes with given ripper" >&2
2695 echo "read the USEPIPES file from the source tarball to help" >&2
2696 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2699 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2700 echo "abcde error: no support for pipes with given encoder" >&2
2701 echo "read the USEPIPES file from the source tarball to help" >&2
2702 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2707 # Make sure a buncha things exist
2708 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2709 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2710 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2711 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2712 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2713 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2714 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2716 # Cut off the command-line options we just added in
2717 X
=$
(echo $X | cut
-d' ' -f2)
2718 if [ "$(which $X)" = "" ]; then
2719 echo "abcde error: $X is not in your path." >&2
2721 elif [ ! -x $
(which $X) ]; then
2722 echo "abcde error: $X is not executable." >&2
2727 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2728 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2729 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2731 # And last but not least, check if we can diff between files
2732 if [ -x $
(which $DIFF) ]; then :; else
2733 vecho
"[WAR] Disabling diff since we cannot find it in the \$PATH..."
2737 # Here it used to say:
2738 # One thousand lines in, we can start doing stuff with things
2739 # Well, right now we are at line 2736 ;)
2741 # Export needed things so they can be read in this subshell
2742 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2743 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2745 # User-definable function to set some things. Use it for
2746 # - closing the CD tray with eject -t
2747 # - set the CD speed value with eject -x
2748 vecho
-n "Executing customizable pre-read function... "
2750 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2754 do_discid
# Get ABCDETEMPDIR created and status file initialized
2756 if [ "$DOCDDB" = "y" ]; then
2757 if [ $CDDBUSELOCAL = "y" ]; then
2760 if checkstatus cddb-choice
> /dev
/null
; then
2763 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2771 eval $
($CDDBTOOL parse
"$CDDBDATA")
2774 # Before reading tracks, we set the speed of the device
2776 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2777 case "$CDROMREADERSYNTAX" in
2778 cdparanoia|debug
) : ;;
2783 # Define the first and last track, since we might need them later in several places
2784 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
2785 LASTTRACK
=$
( get_last
$TRACKQUEUE )
2787 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
2788 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2789 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
2790 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
2793 # Create playlist if needed (backgroundable) and start reading in tracks
2797 if [ ! "$ONETRACK" = "y" ]; then
2798 if [ "$DOPLAYLIST" = "y" ]; then
2799 echo Creating playlist...
>&2
2804 # For the lowdisk option, only one program is running at once so the encoder
2805 # can be unsilenced right away.
2806 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2807 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2810 if [ "$ONETRACK" = "y" ]; then
2811 TRACKS
="$FIRSTTRACK"
2812 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2813 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
2816 for UTRACKNUM
in $TRACKQUEUE
2818 if [ "$DOREAD" = "y" ]; then
2819 if [ "$USEPIPES" = "y" ]; then
2820 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2821 # Read, pipe, shut up!
2822 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
2825 if checkstatus readtrack-
$UTRACKNUM; then :; else
2826 do_cdread
$UTRACKNUM
2828 if [ "$?" != "0" ]; then
2829 # CD read failed - don't give the goahead to
2836 if [ "$BATCH" = "y" ]; then
2839 echo NEXTTRACK
# Get the encoder machine churning again
2840 if [ "$DOREAD" = "y" ]; then
2841 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2842 until checkstatus encodetrack-
$UTRACKNUM
2844 if checkerrors encodetrack-
$UTRACKNUM; then
2855 # Now that we're done the encoding can be loud again -
2856 # if we're not using SMP.
2857 if [ "$MAXPROCS" = "1" ]; then
2858 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2861 # All tracks read, start encoding.
2862 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2866 # Execute the user-defined post_read funtion before ejecting CD
2869 # We are now finished with the cdrom - it can be safely ejected. Note that
2870 # abcde will not have completed yet.
2871 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2872 # We check if the disk we are processing is actually the disk inside the
2873 # CD tray. If not, we do not eject the CD, since it might be so that the
2874 # user ejected it manually.
2875 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2876 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2877 # More FreeBSD bits.
2878 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2879 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2880 # but in this script EJECT is in the envionment and names the program
2883 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2884 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2885 $eject $EJECTOPTS $cd
2886 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2887 disktool
-e ${CDROM#/dev/} 0
2889 $EJECT $EJECTOPTS $CDROM
2896 ## Do we need to pre-process
2897 #if [ x"$PREPROCESS" = "x" ] ; then
2900 # for PRETRACKNUM in $TRACKQUEUE
2903 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2905 # until [ $PREPROCEED ]
2907 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2908 # # all locations are working, wait and try again later
2909 # if [ ! $PREPROCEED ]; then sleep 3; fi
2911 # ( do_preprocess $PRETRACKNUM
2919 # In batch mode, we want all tracks to be read first.
2920 if [ "$BATCH" = "y" ]; then
2921 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2922 if [ "$GOAHEAD" = "NO" ]; then break; fi
2923 for LASTTRACK
in $TRACKQUEUE; do :; done
2924 if checkstatus readtrack-
$LASTTRACK; then
2925 if [ "$DONORMALIZE" = "y" ]; then
2926 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2927 if checkerrors batch-normalize
; then exit; fi
2929 if [ "$DOENCODE" = "y" ]; then
2930 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2931 if checkerrors batch-encode
; then exit; fi
2936 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2937 if [ "$ONETRACK" = "y" ] ; then
2938 TRACKQUEUE
="$FIRSTTRACK"
2939 TRACKS
="$FIRSTTRACK"
2942 # Do the encoding, including parallelization of remote encoding
2943 # Figure out where each track is going to be encoded
2944 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2945 if [ "$MAXPROCS" != "0" ]; then
2946 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2948 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2952 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2953 for UTRACKNUM
in $TRACKQUEUE
2956 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2957 if [ "$GOAHEAD" = "NO" ]; then break; fi
2958 # find out where this track is to be encoded
2959 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2960 # Make sure we have a place to encode this, if not, exit stage right
2961 if [ -z "$ENCODELOCATIONS" ]; then
2967 for LOCATION
in $ENCODELOCATIONS
2969 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2970 # check first if a track has ever been assigned to this location
2971 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
2972 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2973 if checkerrors encodetrack-
$PREVIOUSTRACK; then
2974 for TEMPLOCATION
in $ENCODELOCATIONS
2976 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2977 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
2980 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
2985 # We're still here, this location must have been previously assigned,
2986 # and last completed without error - check if it's done with the
2987 # previous track yet
2988 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
2990 # all locations are working, wait and try again later
2991 if [ ! $PROCEED ]; then sleep 3; fi
2993 # Record the location we're about to encode the next track at
2994 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2996 # Don't proceed with the rest of the loop if we can't encode
2997 if [ "$ABORT" ]; then continue; fi
2998 # Set TRACKNUM, TRACKNAME
2999 if [ -e "$CDDBDATA" ]; then
3000 if [ "$ONETRACK" = "y" ]; then
3002 TRACKNUM
="$FIRSTTRACK"
3005 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
3007 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3008 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
3012 # You can't encode a file which needs to be normalized before finishing
3013 # You can't tag a file before it's finished encoding -
3014 # thus all of this is backgrounded together
3016 if [ "$DONORMALIZE" = "y" ]; then
3017 if checkstatus readtrack-
$UTRACKNUM; then
3018 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3021 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3022 if checkstatus readtrack-
$UTRACKNUM; then
3023 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3024 if [ "$DONORMALIZE" = "y" ]; then
3025 if checkstatus normalizetrack-
$UTRACKNUM; then
3026 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3029 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3033 if [ "$DOTAG" = "y" ]; then
3034 if checkstatus encodetrack-
$UTRACKNUM; then
3035 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3037 # Lets tag the cue file
3038 if checkstatus cleancuefile
>/dev
/null
; then :; else
3039 if checkstatus cuefile
>/dev
/null
; then
3044 if [ "$DOMOVE" = "y" ]; then
3045 if checkstatus tagtrack-
$UTRACKNUM; then
3046 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3053 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3054 # we'll delete the files they're working on
3055 ## FIXME ## Check also for files which are encoded using PIPEs.
3056 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3061 for LOCATION
in $ENCODELOCATIONS
3063 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3064 # "How can he give us a status update, if he's DEAD?"
3065 if checkstatus encodetrack-
$CHECKTRACK; then
3068 # Nothing to see here please go quietly back to your homes
3069 if [ -z "$CHECKTRACK" ]; then continue; fi
3070 # You're still here? Maybe there is something...
3071 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3074 if [ ! $PROCEED ]; then sleep 5; fi
3077 # If the above didn't catch the stragglers, this will
3079 # Check to see if run_command logged any errors
3080 if [ -f "$ABCDETEMPDIR/errors" ]; then
3081 echo "The following commands failed to run:"
3082 cat "$ABCDETEMPDIR/errors"
3086 if [ "$KEEPWAVS" = "y" ];then
3090 if [ "$DOCLEAN" = "y" ]; then
3091 # Wipe all the evidence
3092 # Gimme gimme gimme some more time!
3094 rm -rf "$ABCDETEMPDIR"
3097 echo "Finished. Not cleaning $ABCDETEMPDIR."