2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2004 Jesus Climent <jesus.climent@hispalinux.es>
4 # This code is hereby licensed for public consumption under either the
5 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software
9 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
24 #echo "-A Experimental actions (retag, transcode)"
25 echo "-b Batch mode: enable album normalization and nogap encoding"
27 echo " Specify a configuration file (overrides system and user config files)"
29 echo " Specify discid to resume from (only needed if you no longer have the cd)"
31 echo " Specify CDROM device to grab"
32 echo "-D Debugging mode (equivalent to sh -x abcde)"
33 echo "-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
1622 # I'll take CDDB read #3 for $400, Alex
1623 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1624 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1626 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1627 if echo $CDDBCHOICE |
egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1628 if [ ! X
"$DIFF" = "X" ]; then
1629 # We parse the 2 choices to diff, store them in temporary files and diff them.
1630 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
1631 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1633 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1)
1634 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2)
1635 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..."
1636 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2"
1638 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1641 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1642 # Make sure we get a valid choice
1643 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1644 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1648 if [ "$CDCHOICENUM" = "0" ]; then
1649 vecho
"Creating empty CDDB template..."
1651 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1653 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1654 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1656 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1660 # We need some code to show the selected option when local repository is selected and we have found a match
1661 vecho
"Using cached CDDB match..." >&2
1662 # Display the $ABCDETEMPDIR/cddbchoices file created above
1663 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1664 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1665 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1666 CHOICE
=$
(checkstatus cddb-choice
)
1667 if [ "$USELOCALRESP" = "y" ]; then :; else
1668 if [ -n "$CHOICE" ] ; then
1669 case $CDDBCHOICES in
1672 echo "Selected template."
1674 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1676 echo "Selected: #$CHOICE"
1677 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1685 # We're noninteractive - pick the first choice.
1686 # But in case we run a previous instance and selected a choice, use it.
1687 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1688 # Show the choice if we are not using the locally stored one
1689 # or when the local search failed to find a match.
1690 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1691 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1692 #if [ "$PREVIOUSCHOICE" ]; then
1693 cat "$ABCDETEMPDIR/cddbchoices"
1696 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1697 CDCHOICENUM
=$PREVIOUSCHOICE
1700 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1702 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1707 if checkstatus cddb-choice
>/dev
/null
; then :; else
1708 echo "abcde: internal error: cddb-choice not recorded." >&2
1711 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1712 echo -n "Edit selected CDDB data? [y/n] (" >&2
1713 if [ "$INTERACTIVE" = "y" ]; then
1714 if [ "$UNKNOWNDISK" = "y" ]; then
1717 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1726 if [ "$EDITCDDB" = "y" ]; then
1727 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1729 # Use the debian sensible-editor wrapper to pick the editor that the
1730 # user has requested via their $EDITOR environment variable
1731 if [ -x "/usr/bin/sensible-editor" ]; then
1732 /usr
/bin
/sensible-editor
"$CDDBDATA"
1733 elif [ -n "$EDITOR" ]; then
1734 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1735 # That failed, try to load the preferred editor, starting
1736 # with their EDITOR variable
1737 eval $
(echo "$EDITOR") \"$CDDBDATA\"
1739 # If that fails, check for a vi
1740 elif which vi
>/dev
/null
2>&1; then
1742 elif [ -x /usr
/bin
/vim
]; then
1743 /usr
/bin
/vim
"$CDDBDATA"
1744 elif [ -x /usr
/bin
/vi
]; then
1745 /usr
/bin
/vi
"$CDDBDATA"
1746 elif [ -x /bin
/vi
]; then
1748 # nano should be on all (modern, i.e., sarge) debian systems
1749 elif which nano
>/dev
/null
2>&1 ; then
1751 elif [ -x /usr
/bin
/nano
]; then
1752 /usr
/bin
/nano
"$CDDBDATA"
1753 # mg should be on all OpenBSD systems
1754 elif which mg
>/dev
/null
2>&1 ; then
1756 elif [ -x /usr
/bin
/mg
]; then
1757 /usr
/bin
/mg
"$CDDBDATA"
1760 echo "No editor available. Check your EDITOR environment variable." >&2
1762 # delete editor backup file if it exists
1763 if [ -w "$CDDBDATA~" ]; then
1768 # Some heuristics first. Look at Disc Title, and if it starts with
1769 # "Various", then we'll assume Various Artists
1770 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1771 echo "Looks like a Multi-Artist CD" >&2
1774 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1775 if [ "$INTERACTIVE" = "y" ]; then
1782 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1785 # Need NUMTRACKS before cddb-tool will return it:
1786 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1787 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1788 # More than 1/2 tracks contain a "/", so guess forward
1790 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1791 # More than 1/2 contain a "-", so guess forward-dash
1793 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1794 # More than 1/2 contain something in parens, so guess trailing-paren
1798 echo "1) Artist / Title" >&2
1799 echo "2) Artist - Title" >&2
1800 echo "3) Title / Artist" >&2
1801 echo "4) Title - Artist" >&2
1802 echo "5) Artist: Title" >&2
1803 echo "6) Title (Artist)" >&2
1804 echo "7) This is a single-artist CD" >&2
1805 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1806 if [ "$INTERACTIVE" = "y" ]; then
1807 read VARIOUSARTISTSTYLE
1809 echo $DEFAULTSTYLE >&2
1810 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1812 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1813 # If they press Enter, then the default style (0) was chosen
1814 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1815 echo "Invalid selection. Please choose a number between 1 and 7."
1816 echo -n "Selection [1-7]: "
1817 read VARIOUSARTISTSTYLE
1818 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1820 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1821 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1823 vecho
"Selected: $VARIOUSARTISTSTYLE"
1824 case "$VARIOUSARTISTSTYLE" in
1826 VARIOUSARTISTSTYLE
=forward
1829 VARIOUSARTISTSTYLE
=forward-dash
1832 VARIOUSARTISTSTYLE
=reverse
1835 VARIOUSARTISTSTYLE
=reverse-dash
1838 VARIOUSARTISTSTYLE
=colon
1841 VARIOUSARTISTSTYLE
=trailing-paren
1849 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1850 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1852 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1853 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1854 # This works but does not have the necessary error checking
1855 # yet. If you are familiar with the CDDB spec
1856 # (see http://www.freedb.org/src/latest/DBFORMAT)
1857 # and can create an error-free entry on your own, then put
1858 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1859 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1860 # your abcde.conf to change the email address submissions are
1863 # submit the modified file, if they want
1864 if [ "$NOSUBMIT" != "y" ]; then
1865 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1867 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1868 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1870 echo -n 'Invalid selection. Please answer "y" or "n": '
1873 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1874 echo -n "Sending..."
1875 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1881 # Make sure the cache directory exists
1882 mkdir
-p $CDDBLOCALDIR
1883 # Cache edited CDDB entry in the user's cddb dir
1884 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1885 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1888 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1891 # do_cdread [tracknumber]
1892 # do_cdread onetrack [firsttrack] [lasttrack]
1896 # The commands here don't go through run_command because they're never supposed to be silenced
1897 # return codes need to be doublechecked anyway, however
1898 if [ "$1" = "onetrack" ]; then
1899 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1900 # FIXME # Until then, we grab the whole CD in one track, no matter what
1902 # We need the first and last track for cdda2wav
1905 UTRACKNUM
=$FIRSTTRACK
1906 case "$CDROMREADERSYNTAX" in
1907 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
1908 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTRACK" ;;
1909 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1915 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1916 if [ "$USEPIPES" = "y" ]; then
1917 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1918 FILEARG
="${!TEMPARG}"
1920 PIPE_MESSAGE
="and encoding "
1922 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1923 case "$CDROMREADERSYNTAX" in
1924 ## FIXME ## Find the case for dagrab, to avoid exceptions
1926 FILEARG
="-f $WAVDATA"
1934 if [ "$1" = "onetrack" ]; then
1935 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
1937 if [ -r "$CDDBDATA" ]; then
1938 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1939 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1941 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1944 case "$CDROMREADERSYNTAX" in
1946 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
1948 if [ "$OSFLAVOUR" = "OSX" ] ; then
1949 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1950 disktool
-u ${CDROM#/dev/} 0
1951 # Also, in OSX the cdrom device for cdda2wav changes...
1952 CDDA2WAVCDROM
="IODVDServices"
1953 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1954 CDDA2WAVCDROM
="$CDROMID"
1956 if [ "$CDROMID" = "" ]; then
1957 CDDA2WAVCDROM
="$CDROM"
1959 CDDA2WAVCDROM
="$CDROMID"
1962 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
1964 ## FIXME ## We have an exception for dagrab, since it uses -f
1965 ## FIXME ## Shall we just use -f $FILEARG ??
1966 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
1969 # Find the track's mounted path
1970 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1971 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1972 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
1973 # If the file exists, copy it
1974 if [ -e "$FILEPATH" ] ; then
1975 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
1979 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
1983 # If we get some error or we get some missing wav
1984 # (as long as we dont use pipes)
1985 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
1986 # Thank goodness errors is only machine-parseable up to the
1987 # first colon, otherwise this woulda sucked
1988 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
1989 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
1991 if [ "$USEPIPES" = "y" ]; then
1992 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1994 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1998 if [ "$USEPIPES" = "y" ]; then
1999 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2001 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2002 if [ "$1" = "onetrack" ]; then
2003 echo onetrack
>> "$ABCDETEMPDIR/status"
2010 # No values accepted, only uses env variables
2013 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2014 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2016 echo "abcde: unable to set the device speed" >&2
2022 # vecho outputs a message if EXTRAVERBOSE is selected
2025 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2030 # User-redefinable functions
2031 # Custom filename munging:
2034 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2035 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2038 # Custom genre munging:
2041 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2045 # Empty pre_read function, to be defined in the configuration file.
2052 # Empty post_read function, to be defined in the configuration file.
2058 ###############################################################################
2061 # Start of execution
2062 ###############################################################################
2065 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2066 CDDBSUBMIT
=freedb-submit@freedb.org
2068 HELLOINFO
="$(whoami)@$(hostname)"
2070 CDDBLOCALDIR
="$HOME/.cddb"
2073 # List of fields we parse and show during the CDDB parsing...
2074 SHOWCDDBFIELDS
="year,genre"
2077 CDROMREADERSYNTAX
=cdparanoia
2078 ENCODERSYNTAX
=default
2080 MP3ENCODERSYNTAX
=default
2081 OGGENCODERSYNTAX
=default
2082 FLACENCODERSYNTAX
=default
2083 SPEEXENCODERSYNTAX
=default
2084 MPPENCODERSYNTAX
=default
2085 NORMALIZERSYNTAX
=default
2087 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2088 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2089 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2090 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2091 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2092 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2093 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2094 PLAYLISTDATAPREFIX
=''
2095 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2096 VAPLAYLISTDATAPREFIX
=''
2104 VARIOUSARTISTSTYLE
=forward
2108 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2109 # i.e. CDROMID="1,0,0"
2111 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2112 # If we are using the ide-scsi emulation layer, we need to define a "g"
2113 CDPARANOIACDROMBUS
="d"
2115 # program paths - defaults to checking your $PATH
2121 XINGMP3ENC
=xingmp3enc
2135 CDPARANOIA
=cdparanoia
2144 VORBISCOMMENT
=vorbiscomment
2146 NORMALIZE
=normalize-audio
2148 VORBISGAIN
=vorbisgain
2153 # Options for programs called from abcde
2185 VORBISCOMMENTOPTS
="-R"
2186 METAFLACOPTS
="--no-utf8-convert"
2188 # Default to one process if -j isn't specified
2191 # List of actions to perform - by default, run to completion
2192 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2194 # List of prefered outputs - by default, run with whatever we have in the path
2195 # This option is basicaly for Debian package dependencies
2196 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
2198 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2199 # Let's use these checkings to determine the OS flavour, which will be used later
2200 if [ X$
(uname
) = "XFreeBSD" ] ; then
2204 elif [ X$
(uname
) = "XDarwin" ] ; then
2207 # We should have disktool in OSX, but let's be sure...
2209 CDROMREADERSYNTAX
=cddafs
2210 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2217 # If CDDBAVAIL is set to n, no CDDB read is done
2218 # If USEID3 is set to n, no ID3 tagging is done
2223 if [ -z "$OUTPUTDIR" ]; then
2227 if [ -z "$WAVOUTPUTDIR" ]; then
2228 WAVOUTPUTDIR
="$OUTPUTDIR"
2231 # Load system defaults
2232 if [ -r /etc
/abcde.conf
]; then
2235 # Load user preference defaults
2236 if [ -r $HOME/.abcde.conf
]; then
2240 # By this time, we need some HTTPGETOPTS already defined.
2241 # If the user has defined a non-default HTTPGET method, we should not be empty.
2243 if [ "$HTTPGETOPTS" = "" ] ; then
2245 wget
) HTTPGETOPTS
="-q -O -";;
2246 curl
) HTTPGETOPTS
="-f -s";;
2247 fetch
)HTTPGETOPTS
="-q -o -";;
2248 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2252 # If the CDROM has not been set yet, find a suitable one.
2253 # If this is a devfs system, default to /dev/cdroms/cdrom0
2254 # instead of /dev/cdrom
2255 if [ "$CDROM" = "" ] ; then
2256 if [ -e /dev
/cdroms
/cdrom0
]; then
2257 CDROM
=/dev
/cdroms
/cdrom0
2258 elif [ -e /dev
/cdrom
]; then
2260 elif [ -e /dev
/cd0c
]; then
2262 elif [ -e /dev
/acd0c
]; then
2264 elif [ -e /dev
/disk1
]; then
2269 # Parse command line options
2270 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2271 while getopts 1a
:bc:C
:d
:Dehj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
2274 a
) ACTIONS
="$OPTARG" ;;
2275 A
) EXPACTIONS
="$OPTARG";;
2277 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2278 C
) DISCID
="${OPTARG#abcde.}" ;;
2279 d
) CDROM
="$OPTARG" ;;
2281 e
) ERASEENCODEDSTATUS
=y
;;
2283 e
) ERASEENCODEDSTATUS
=y
;;
2284 # f) FORCECDDBUSELOCAL=y ;;
2286 j
) MAXPROCS
="$OPTARG" ;;
2289 L
) CDDBUSELOCAL
=y
;;
2294 o
) OUTPUTTYPE
="$OPTARG" ;;
2297 r
) REMOTEHOSTS
="$OPTARG" ;;
2299 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2300 S
) CDSPEEDVALUE
="$OPTARG" ;;
2301 # t) PREPROCESSFORMATS="$OPTARG"
2303 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2304 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2305 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2307 echo "This is abcde v$VERSION."
2308 echo "Usage: abcde [options] [tracks]"
2309 echo "abcde -h for extra help"
2312 V
) EXTRAVERBOSE
="y" ;;
2314 w
) COMMENT
="$OPTARG" ;;
2315 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2316 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2318 echo "abcde error: argument of -W must be integer"
2326 shift $
(($OPTIND - 1))
2328 # Decide if we can continue.
2329 if [ "$ONETRACK" = "y" ]; then
2330 # FIXME # remove check as soon as we find out about the other readers
2331 case "$CDROMREADERSYNTAX" in
2334 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2337 if [ "$BATCH" = "y" ]; then
2338 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2341 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2342 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2343 if [ $# -gt 0 ]; then
2344 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2347 while [ $# -gt 0 ]; do
2348 # Range parsing code courtesy of Vincent Ho
2349 RSTART
=$
(echo $1 | cut
-f1 -d-)
2350 REND
=$
(echo $1 | cut
-f2 -d-)
2351 if [ "$RSTART" = "$REND" ]; then
2354 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2356 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2361 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2362 # List of experimental actions: retag,transcode
2364 # Determine what actions are to be done from $ACTIONS and set the
2365 # following environment variables for them:
2377 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2382 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2383 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2384 encode
) DOENCODE
=y
; DOREAD
=y
;;
2385 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2386 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2387 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2388 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2393 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
2394 case $SHOWCDDBFIELD in
2395 y
*|Y
*) SHOWCDDBYEAR
="y";;
2396 g
*|G
*) SHOWCDDBGENRE
="y";;
2403 # At this point a CDROM has to be defined, so we check it exists.
2404 if [ X
"$CDROM" != "X" ] ; then
2405 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2406 if [ "$OSFLAVOUR" = "FBSD" ]; then
2407 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2408 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2409 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2413 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2414 echo "abcde error: CDROM device cannot be found." >&2
2417 # avoid processing if we are not going to hit the CDROM.
2418 elif [ X
"$DOREAD" = "Xy" ]; then
2419 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2423 # USEPIPES pre-tests, before we get into more serious stuff
2424 # Not compatible with:
2425 # - multiple outputs
2427 # - lowdisk algorithm
2429 if [ X
"$USEPIPES" = "Xy" ]; then
2430 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
2431 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
2434 if [ X
"$DONORMALIZE" = "Xy" ]; then
2435 echo "abcde error: Unix pipes not compatible with normalizer"
2436 # FIXME # Do we need to exit or shall we just disable the mode?
2439 if [ X
"$DOENCODE" = "Xn" ]; then
2440 vecho
"Disabling Unix pipes since we are not encoding!"
2443 if [ X
"$LOWDISK" = "Xy" ]; then
2444 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2449 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2450 if [ X
"$OUTPUTTYPE" = "X" ]; then
2451 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
2452 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2453 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2454 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
2455 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
2456 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2460 if [ X
"$OUTPUTTYPE" = "X" ]; then
2461 echo "abcde error: no encoder found in the PATH" >&2
2462 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2467 # Decide which CDROM reader we're gonna use
2468 case "$CDROMREADERSYNTAX" in
2470 CDROMREADER
="$CDPARANOIA"
2471 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2474 CDROMREADER
="$CDDA2WAV"
2475 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2478 CDROMREADER
="$DAGRAB"
2479 CDROMREADEROPTS
="$DAGRABOPTS"
2482 CDROMREADER
="$CDDAFS"
2483 CDROMREADEROPTS
="$CDDAFSOPTS"
2487 # There's only one normalize...
2488 case "$NORMALIZERSYNTAX" in
2490 NORMALIZER
="$NORMALIZE"
2491 NORMALIZEROPTS
="$NORMALIZEOPTS"
2495 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2496 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
2497 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
); do
2499 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2500 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2501 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2502 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2503 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2506 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
); do
2507 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2508 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2510 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2513 # 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
2515 # Getting ready for multiple output changes
2516 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2520 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2521 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2522 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2523 OGGOUTPUTCONTAINER
=ogg
2526 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2527 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2530 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2531 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2534 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
2537 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
2539 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2545 # decide which encoder
2546 case "$MP3ENCODERSYNTAX" in
2548 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2552 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2556 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2557 MP3ENCODER
="$BLADEENC"
2560 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2564 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2565 MP3ENCODER
="$XINGMP3ENC"
2568 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2569 MP3ENCODER
="$MP3ENC"
2572 case "$OGGENCODERSYNTAX" in
2574 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2575 OGGENCODER
="$VORBIZE"
2578 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2579 OGGENCODER
="$OGGENC"
2582 case "$FLACENCODERSYNTAX" in
2584 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2586 # FLAC streams can be encapsulated on a Ogg transport layer
2587 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2588 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2589 echo " due to problem with adding comments to such files" >&2
2591 FLACOUTPUTCONTAINER
=ogg
2593 FLACOUTPUTCONTAINER
=flac
2597 case "$SPEEXENCODERSYNTAX" in
2599 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2600 SPEEXENCODER
="$SPEEXENC"
2603 case "$MPPENCODERSYNTAX" in
2605 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2606 MPPENCODER
="$MPPENC"
2612 if [ "$ID3TAGV" = "1" ]; then
2614 TAGGEROPTS
="$ID3OPTS"
2617 TAGGEROPTS
="$ID3V2OPTS"
2620 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2621 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2622 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2623 echo " due to problem with adding comments to such files" >&2
2625 OGGOUTPUTCONTAINER
=ogg.ogg
2626 FLACOUTPUTCONTAINER
=flac.ogg
2627 vecho
"abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2630 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2632 if [ "$ENCNICE" ]; then
2633 ENCNICE
="-n $ENCNICE"
2635 if [ "$READNICE" ]; then
2636 READNICE
="-n $READNICE"
2638 if [ "$DISTMP3NICE" ]; then
2639 DISTMP3NICE
="-n $DISTMP3NICE"
2642 # Don't check for stuff if it's not needed
2643 if [ "$REMOTEHOSTS" ]; then
2646 if [ "$DONORMALIZE" = "y" ]; then
2649 if [ "$EJECTCD" = "y" ]; then
2652 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2655 if [ "$CUEFILE" = "y" ]; then
2659 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2660 case "$CDROMREADERSYNTAX" in
2661 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2666 # Rippers with USEPIPE support
2667 # FIXME # Include here all the rippers we can figure out support pipes
2670 # Encoders with USEPIPE support
2671 # FIXME # Include here all the encoders we can figure out support pipes
2676 # Figure out if we can use pipes with the ripper/encoder combination
2678 if [ "$USEPIPES" = "y" ]; then
2679 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2682 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2684 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2686 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
2688 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2690 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2692 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2693 echo "abcde error: no support for pipes with given ripper" >&2
2694 echo "read the USEPIPES file from the source tarball to help" >&2
2695 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2698 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2699 echo "abcde error: no support for pipes with given encoder" >&2
2700 echo "read the USEPIPES file from the source tarball to help" >&2
2701 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2706 # Make sure a buncha things exist
2707 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2708 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2709 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2710 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2711 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2712 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2713 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMKCUE+$MKCUE}
2715 # Cut off the command-line options we just added in
2716 X
=$
(echo $X | cut
-d' ' -f2)
2717 if [ "$(which $X)" = "" ]; then
2718 echo "abcde error: $X is not in your path." >&2
2720 elif [ ! -x $
(which $X) ]; then
2721 echo "abcde error: $X is not executable." >&2
2726 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2727 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2728 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2730 # And last but not least, check if we can diff between files
2731 if [ -x $
(which $DIFF) ]; then :; else
2732 vecho
"[WAR] Disabling diff since we cannot find it in the \$PATH..."
2736 # Here it used to say:
2737 # One thousand lines in, we can start doing stuff with things
2738 # Well, right now we are at line 2695 ;)
2740 # Export needed things so they can be read in this subshell
2741 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2742 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2744 # User-definable function to set some things. Use it for
2745 # - closing the CD tray with eject -t
2746 # - set the CD speed value with eject -x
2747 vecho
-n "Executing customizable pre-read function... "
2749 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2753 do_discid
# Get ABCDETEMPDIR created and status file initialized
2755 if [ "$DOCDDB" = "y" ]; then
2756 if [ $CDDBUSELOCAL = "y" ]; then
2759 if checkstatus cddb-choice
> /dev
/null
; then
2762 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2770 eval $
($CDDBTOOL parse
"$CDDBDATA")
2773 # Before reading tracks, we set the speed of the device
2775 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2776 case "$CDROMREADERSYNTAX" in
2777 cdparanoia|debug
) : ;;
2782 # Define the first and last track, since we might need them later in several places
2783 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
2784 LASTTRACK
=$
( get_last
$TRACKQUEUE )
2786 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
2787 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2788 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
2789 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
2792 # Create playlist if needed (backgroundable) and start reading in tracks
2796 if [ ! "$ONETRACK" = "y" ]; then
2797 if [ "$DOPLAYLIST" = "y" ]; then
2798 echo Creating playlist...
>&2
2803 # For the lowdisk option, only one program is running at once so the encoder
2804 # can be unsilenced right away.
2805 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2806 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2809 if [ "$ONETRACK" = "y" ]; then
2810 TRACKS
="$FIRSTTRACK"
2811 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2812 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
2815 for UTRACKNUM
in $TRACKQUEUE
2817 if [ "$DOREAD" = "y" ]; then
2818 if [ "$USEPIPES" = "y" ]; then
2819 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2820 # Read, pipe, shut up!
2821 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
2824 if checkstatus readtrack-
$UTRACKNUM; then :; else
2825 do_cdread
$UTRACKNUM
2827 if [ "$?" != "0" ]; then
2828 # CD read failed - don't give the goahead to
2835 if [ "$BATCH" = "y" ]; then
2838 echo NEXTTRACK
# Get the encoder machine churning again
2839 if [ "$DOREAD" = "y" ]; then
2840 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2841 until checkstatus encodetrack-
$UTRACKNUM
2843 if checkerrors encodetrack-
$UTRACKNUM; then
2854 # Now that we're done the encoding can be loud again -
2855 # if we're not using SMP.
2856 if [ "$MAXPROCS" = "1" ]; then
2857 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2860 # All tracks read, start encoding.
2861 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2865 # Execute the user-defined post_read funtion before ejecting CD
2868 # We are now finished with the cdrom - it can be safely ejected. Note that
2869 # abcde will not have completed yet.
2870 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2871 # We check if the disk we are processing is actually the disk inside the
2872 # CD tray. If not, we do not eject the CD, since it might be so that the
2873 # user ejected it manually.
2874 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2875 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2876 # More FreeBSD bits.
2877 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2878 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2879 # but in this script EJECT is in the envionment and names the program
2882 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2883 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2884 $eject $EJECTOPTS $cd
2885 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2886 disktool
-e ${CDROM#/dev/} 0
2888 $EJECT $EJECTOPTS $CDROM
2895 ## Do we need to pre-process
2896 #if [ x"$PREPROCESS" = "x" ] ; then
2899 # for PRETRACKNUM in $TRACKQUEUE
2902 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2904 # until [ $PREPROCEED ]
2906 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2907 # # all locations are working, wait and try again later
2908 # if [ ! $PREPROCEED ]; then sleep 3; fi
2910 # ( do_preprocess $PRETRACKNUM
2918 # In batch mode, we want all tracks to be read first.
2919 if [ "$BATCH" = "y" ]; then
2920 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2921 if [ "$GOAHEAD" = "NO" ]; then break; fi
2922 for LASTTRACK
in $TRACKQUEUE; do :; done
2923 if checkstatus readtrack-
$LASTTRACK; then
2924 if [ "$DONORMALIZE" = "y" ]; then
2925 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2926 if checkerrors batch-normalize
; then exit; fi
2928 if [ "$DOENCODE" = "y" ]; then
2929 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2930 if checkerrors batch-encode
; then exit; fi
2935 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2936 if [ "$ONETRACK" = "y" ] ; then
2937 TRACKQUEUE
="$FIRSTTRACK"
2938 TRACKS
="$FIRSTTRACK"
2941 # Do the encoding, including parallelization of remote encoding
2942 # Figure out where each track is going to be encoded
2943 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2944 if [ "$MAXPROCS" != "0" ]; then
2945 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2947 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2951 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2952 for UTRACKNUM
in $TRACKQUEUE
2955 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2956 if [ "$GOAHEAD" = "NO" ]; then break; fi
2957 # find out where this track is to be encoded
2958 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2959 # Make sure we have a place to encode this, if not, exit stage right
2960 if [ -z "$ENCODELOCATIONS" ]; then
2966 for LOCATION
in $ENCODELOCATIONS
2968 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
2969 # check first if a track has ever been assigned to this location
2970 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
2971 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
2972 if checkerrors encodetrack-
$PREVIOUSTRACK; then
2973 for TEMPLOCATION
in $ENCODELOCATIONS
2975 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
2976 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
2979 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
2984 # We're still here, this location must have been previously assigned,
2985 # and last completed without error - check if it's done with the
2986 # previous track yet
2987 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
2989 # all locations are working, wait and try again later
2990 if [ ! $PROCEED ]; then sleep 3; fi
2992 # Record the location we're about to encode the next track at
2993 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
2995 # Don't proceed with the rest of the loop if we can't encode
2996 if [ "$ABORT" ]; then continue; fi
2997 # Set TRACKNUM, TRACKNAME
2998 if [ -e "$CDDBDATA" ]; then
2999 if [ "$ONETRACK" = "y" ]; then
3001 TRACKNUM
="$FIRSTTRACK"
3004 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
3006 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3007 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
3011 # You can't encode a file which needs to be normalized before finishing
3012 # You can't tag a file before it's finished encoding -
3013 # thus all of this is backgrounded together
3015 if [ "$DONORMALIZE" = "y" ]; then
3016 if checkstatus readtrack-
$UTRACKNUM; then
3017 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3020 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3021 if checkstatus readtrack-
$UTRACKNUM; then
3022 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3023 if [ "$DONORMALIZE" = "y" ]; then
3024 if checkstatus normalizetrack-
$UTRACKNUM; then
3025 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3028 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3032 if [ "$DOTAG" = "y" ]; then
3033 if checkstatus encodetrack-
$UTRACKNUM; then
3034 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3036 # Lets tag the cue file
3037 if checkstatus cleancuefile
>/dev
/null
; then :; else
3038 if checkstatus cuefile
>/dev
/null
; then
3043 if [ "$DOMOVE" = "y" ]; then
3044 if checkstatus tagtrack-
$UTRACKNUM; then
3045 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3052 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3053 # we'll delete the files they're working on
3054 ## FIXME ## Check also for files which are encoded using PIPEs.
3055 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3060 for LOCATION
in $ENCODELOCATIONS
3062 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3063 # "How can he give us a status update, if he's DEAD?"
3064 if checkstatus encodetrack-
$CHECKTRACK; then
3067 # Nothing to see here please go quietly back to your homes
3068 if [ -z "$CHECKTRACK" ]; then continue; fi
3069 # You're still here? Maybe there is something...
3070 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3073 if [ ! $PROCEED ]; then sleep 5; fi
3076 # If the above didn't catch the stragglers, this will
3078 # Check to see if run_command logged any errors
3079 if [ -f "$ABCDETEMPDIR/errors" ]; then
3080 echo "The following commands failed to run:"
3081 cat "$ABCDETEMPDIR/errors"
3085 if [ "$KEEPWAVS" = "y" ];then
3089 if [ "$DOCLEAN" = "y" ]; then
3090 # Wipe all the evidence
3091 # Gimme gimme gimme some more time!
3093 rm -rf "$ABCDETEMPDIR"
3096 echo "Finished. Not cleaning $ABCDETEMPDIR."