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...
165 # Finds the right pager in the system to display a file
169 # Use the debian sensible-pager wrapper to pick the pager
170 # user has requested via their $PAGER environment variable
171 if [ -x "/usr/bin/sensible-pager" ]; then
172 /usr
/bin
/sensible-pager
"$PAGEFILE"
173 elif [ -x "$PAGER" ]; then
174 # That failed, try to load the preferred editor, starting
175 # with their PAGER variable
177 # If that fails, check for less
178 elif [ -x /usr
/bin
/less ]; then
179 /usr
/bin
/less -f "$PAGEFILE"
180 # more should be on all UNIX systems
181 elif [ -x /bin
/more ]; then
182 /bin
/more "$PAGEFILE"
184 # No bananas, just cat the thing
189 # run_command [blurb] [command...]
190 # Runs a command, silently if necessary, and updates the status file
195 # See if this is supposed to be silent
196 if [ "$(checkstatus encode-output)" = "loud" ]; then
200 # Special case for SMP, since
201 # encoder output is never displayed, don't mute echos
202 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
212 if [ "$RETURN" = "2" ]; then
213 # File was already normalized.
218 if [ "$RETURN" != "0" ]; then
219 # Put an error in the errors file. For various reasons we
220 # can't capture a copy of the program's output but we can
221 # log what we attempted to execute and the error code
222 # returned by the program.
223 if [ "$BLURB" ]; then
226 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
227 return $RETURN # Do not pass go, do not update the status file
229 if [ "$BLURB" ]; then
230 echo $BLURB >> "$ABCDETEMPDIR/status"
234 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
235 # distributed under the terms of the GNU GPL v2 or later, at your option
237 # Function to determine if a word contains a slash.
246 # Function to give the relative path from one file to another.
247 # Usage: relpath fromfile tofile
248 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
249 # (the result would be Album/Song.mp3)
250 # Output is relative path to $2 from $1 on stdout
252 # This code has the following restrictions:
253 # Multiple ////s are not collapsed into single /s, with strange effects.
254 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
255 # If FR is a directory it must have a trailing /
263 /*) ;; # No processing is needed for absolute paths
265 # Loop through common prefixes, ignoring them.
266 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
268 FR
="$(echo "$FR" | cut -d/ -f2-)"
269 TO
="$(echo "$TO" | cut -d/ -f2-)"
271 # Loop through directory portions left in FR, adding appropriate ../s.
274 FR
="$(echo "$FR" | cut -d/ -f2-)"
283 # This code splits the a Various Artist track name from one of the following
286 # forward: Artist / Track
287 # forward-dash: Artist - Track
288 # reverse: Track / Artist
289 # reverse-dash: Track - Artist
290 # colon: Artist: Track
291 # trailing-paren: Artist (Track)
294 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
297 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
298 case "$VARIOUSARTISTSTYLE" in
300 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's- / -~-g')
301 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
302 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
305 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's, - ,~,g')
306 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
307 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
310 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's- / -~-g')
311 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
312 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
315 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's, - ,~,g')
316 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
317 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
320 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's-: -~-g')
321 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
322 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
325 DTITLEARTIST
=$
(echo "$TRACKNAME" |
sed 's,^\(.*\) (\(.*\)),\1~\2,')
326 TRACKARTIST
=$
(echo "$DTITLEARTIST" | cut
-f2 -d~
)
327 TRACKNAME
=$
(echo "$DTITLEARTIST" | cut
-f1 -d~
)
330 elif [ "$ONETRACK" = "y" ]; then
331 TRACKARTIST
="Various"
333 TRACKARTIST
="$DARTIST"
338 local genre
=$
(echo "${@}" |
tr '[A-Z]' '[a-z]')
342 "classic rock") id
=1 ;;
360 "industrial") id
=19 ;;
361 "alternative") id
=20 ;;
363 "death metal") id
=22 ;;
365 "soundtrack") id
=24 ;;
366 "euro-techno") id
=25 ;;
370 "jazz+funk") id
=29 ;;
373 "classical") id
=32 ;;
374 "instrumental") id
=33 ;;
378 "sound clip") id
=37 ;;
381 "alt. rock") id
=40 ;;
386 "meditative") id
=45 ;;
387 "instrum. pop") id
=46 ;;
388 "instrum. rock") id
=47 ;;
392 "techno-indust.") id
=51 ;;
393 "electronic") id
=52 ;;
395 "eurodance") id
=54 ;;
397 "southern rock") id
=56 ;;
402 "christian rap") id
=61 ;;
405 "native american") id
=64 ;;
408 "psychadelic") id
=67 ;;
410 "showtunes") id
=69 ;;
414 "acid punk") id
=73 ;;
415 "acid jazz") id
=74 ;;
419 "rock & roll") id
=78 ;;
420 "hard rock") id
=79 ;;
422 "folk/rock") id
=81 ;;
423 "national folk") id
=82 ;;
430 "bluegrass") id
=89 ;;
431 "avantgarde") id
=90 ;;
432 "gothic rock") id
=91 ;;
433 "progress. rock") id
=92 ;;
434 "psychadel. rock") id
=93 ;;
435 "symphonic rock") id
=94 ;;
436 "slow rock") id
=95 ;;
439 "easy listening") id
=98 ;;
445 "chamber music") id
=104 ;;
447 "symphony") id
=106 ;;
448 "booty bass") id
=107 ;;
450 "porn groove") id
=109 ;;
452 "slow jam") id
=111 ;;
456 "folklore") id
=115 ;;
458 "power ballad") id
=117 ;;
459 "rhythmic soul") id
=118 ;;
460 "freestyle") id
=119 ;;
462 "punk rock") id
=121 ;;
463 "drum solo") id
=122 ;;
464 "a capella") id
=123 ;;
465 "euro-house") id
=124 ;;
466 "dance hall") id
=125 ;;
468 "drum & bass") id
=127 ;;
469 "club-house") id
=128 ;;
470 "hardcore") id
=129 ;;
474 "negerpunk") id
=133 ;;
475 "polsk punk") id
=134 ;;
477 "christian gangsta rap") id
=136 ;;
478 "heavy metal") id
=137 ;;
479 "black metal") id
=138 ;;
480 "crossover") id
=139 ;;
481 "contemporary christian")id
=140 ;;
482 "christian rock") id
=141 ;;
483 "merengue") id
=142 ;;
485 "thrash metal") id
=144 ;;
488 "synthpop") id
=147 ;;
495 # do_tag [tracknumber]
496 # id3 tags a filename
498 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
499 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
502 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
503 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
504 # If we want to start the tracks with a given number, we need to modify the
505 # TRACKNUM value before evaluation
506 if [ -n "$STARTTRACKNUMBER" -a -n "$STARTTRACKNUMBERTAG" ] ; then
507 # Get the trackpadding from the current track
508 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
509 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
511 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
515 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
516 GENREID
=$
(do_getgenreid
"${CDGENRE}")
518 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
519 run_command tagtrack-
$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
520 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
521 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
522 "$ABCDETEMPDIR/track$1.$OUTPUT"
525 case "$OGGENCODERSYNTAX" in
527 # vorbiscomment can't do in-place modification, mv the file first
528 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
529 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
532 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
533 echo ARTIST
="$TRACKARTIST"
535 echo TITLE
="$TRACKNAME"
536 if [ -n "$CDYEAR" ]; then
539 if [ -n "$CDGENRE" ]; then
540 echo GENRE
="$CDGENRE"
542 echo TRACKNUMBER
=${TRACKNUM:-$1}
543 echo CDDB
=$CDDBDISCID
544 if [ "$(eval echo ${COMMENT})" != "" ]; then
545 case "$COMMENTOUTPUT" in
546 *=*) echo "$COMMENTOUTPUT";;
547 *) echo COMMENT
="$COMMENTOUTPUT";;
550 ) | run_command tagtrack-
$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
551 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
552 # Doublecheck that the commented file was created successfully before wiping the original
553 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
554 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
556 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
563 echo ARTIST
="$TRACKARTIST"
565 echo TITLE
="$TRACKNAME"
566 if [ -n "$CDYEAR" ]; then
569 if [ -n "$CDGENRE" ]; then
570 echo GENRE
="$CDGENRE"
572 echo TRACKNUMBER
=${TRACKNUM:-$1}
573 echo CDDB
=$CDDBDISCID
574 if [ "$(eval echo ${COMMENT})" != "" ]; then
575 case "$COMMENTOUTPUT" in
576 *=*) echo "$COMMENTOUTPUT";;
577 *) echo COMMENT
="$COMMENTOUTPUT";;
580 ) | run_command tagtrack-
$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
583 run_command tagtrack-
$1 true
586 run_command tagtrack-
$1 true
594 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
597 # The commands here don't go through run_command because they're never supposed to be silenced
598 echo "Batch encoding tracks: $TRACKQUEUE"
599 OUTPUT
=$
(echo $OUTPUTTYPE |
grep "mp3" )
602 case "$MP3ENCODERSYNTAX" in
607 for UTRACKNUM
in $TRACKQUEUE
609 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
611 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
613 if [ "$RETURN" != "0" ]; then
614 echo "batch-encode: $ENCODER returned code $RETURN" >> errors
616 for UTRACKNUM
in $TRACKQUEUE
618 echo encodetrack-
$UTRACKNUM >> status
626 # Other encoders fall through to normal encoding as the tracks
627 # have not been entered in the status file.
630 # do_encode [tracknumber] [hostname]
631 # If no hostname is specified, encode locally
633 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
636 if [ "$USEPIPES" = "y" ]; then
639 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
642 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
645 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
648 TEMPARG
="PIPE_$SPEEXENCODER"
651 TEMPARG
="PIPE_$MPPENCODER"
656 IN
="$ABCDETEMPDIR/track$1.wav"
659 case "$MP3ENCODERSYNTAX" in
660 # FIXME # check if mp3enc needs -if for pipes
674 # We need IN to proceed, if we are not using pipes.
675 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
676 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
680 OUT
="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
683 OUT
="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
686 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
689 if [ X
"$USEPIPES" = "Xy" ]; then
692 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
693 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
699 case "$MP3ENCODERSYNTAX" in
700 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
701 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
702 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
703 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
704 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
708 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
715 case "$OGGENCODERSYNTAX" in
716 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
717 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
721 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
728 case "$FLACENCODERSYNTAX" in
729 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
735 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
736 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
741 if [ "$(eval echo ${COMMENT})" != "" ]; then
744 *) COMMENT
="COMMENT=$COMMENT" ;;
746 COMMENT
="--comment \"$COMMENT\""
748 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
749 if [ ! "$DOTAG" = "y" ]; then
750 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
752 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
756 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
758 # I tried compiling the mppenc from corecodecs.org and got some
759 # errors, so I have not tried it myself.
760 ## FIXME ## Needs some cleanup to determine if an empty tag sent
761 ## FIXME ## to the encoder ends up empty.
762 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
766 # Only remove .wav if the encoding succeeded
767 if checkerrors
"encodetrack-(.{3,4})-$1"; then
768 run_command encodetrack-
$1 false
770 run_command encodetrack-
$1 true
771 if [ ! "$KEEPWAVS" = "y" ] ; then
776 if [ "$(checkstatus encode-output)" = "loud" ]; then
777 echo "HEH! The file we were about to encode disappeared:"
780 run_command encodetrack-
$1 false
784 # do_preprocess [tracknumber]
786 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
789 # IN="$ABCDETEMPDIR/track$1.wav"
790 # # We need IN to proceed.
791 # if [ -s "$IN" ] ; then
792 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
794 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
795 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
796 # case "$POSTPROCESSFORMAT" in
798 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
800 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
802 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
804 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
806 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
809 # # Only remove .wav if the encoding succeeded
810 # if checkerrors "preprocess-(.{3,4})-$1"; then
811 # run_command preprocess-$1 false
813 # run_command preprocess-$1 true
816 # if [ "$(checkstatus encode-output)" = "loud" ]; then
817 # echo "HEH! The file we were about to pre-process disappeared:"
820 # run_command preprocess-$1 false
825 # do_postprocess [tracknumber]
827 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
830 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
832 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
833 # # We need IN to proceed.
834 # if [ -s "$IN" ] ; then
835 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
836 # run_command '' echo "Post-processing track $1 of $TRACKS..."
837 # case "$POSTPROCESSFORMAT" in
839 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
841 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
843 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
845 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
847 # # Only remove .wav if the encoding succeeded
848 # if checkerrors "postprocess-(.{3,4})-$1"; then
849 # run_command postprocess-$1 false
851 # run_command postprocess-$1 true
854 # if [ "$(checkstatus encode-output)" = "loud" ]; then
855 # echo "HEH! The file we were about to post-process disappeared:"
858 # run_command postprocess-$1 false
873 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
877 # The commands here don't go through run_command because they're never supposed to be silenced
878 echo "Batch analizing gain in tracks: $TRACKQUEUE"
883 for UTRACKNUM
in $TRACKQUEUE
885 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
887 # XXX: Hard-coded batch option!
888 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
890 if [ "$RETURN" != "0" ]; then
891 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
893 for UTRACKNUM
in $TRACKQUEUE
895 echo normalizetrack-
$UTRACKNUM >> status
903 # NORMALIZER, NORMALIZEROPTS
904 do_batch_normalize
()
906 # The commands here don't go through run_command because they're never supposed to be silenced
907 echo "Batch normalizing tracks: $TRACKQUEUE"
912 for UTRACKNUM
in $TRACKQUEUE
914 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
916 # XXX: Hard-coded batch option!
917 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
919 if [ "$RETURN" != "0" ]; then
920 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
922 for UTRACKNUM
in $TRACKQUEUE
924 echo normalizetrack-
$UTRACKNUM >> status
930 # do_normalize [tracknumber]
932 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
935 IN
="$ABCDETEMPDIR/track$1.wav"
936 if [ -e "$IN" ] ; then
937 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
938 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
940 if [ "$(checkstatus encode-output)" = "loud" ]; then
941 echo "HEH! The file we were about to normalize disappeared:"
944 run_command normalizetrack-
$1 false
"File $IN was not found"
948 # do_move [tracknumber]
949 # Deduces the outfile from environment variables
950 # Creates directory if necessary
952 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
955 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
959 OUTPUT
=$OGGOUTPUTCONTAINER
962 OUTPUT
=$FLACOUTPUTCONTAINER
965 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
966 # Munge filenames as follows:
971 # Eat control characters
972 ALBUMFILE
=$
(mungefilename
"$DALBUM")
973 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
974 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
975 GENRE
=$
(mungegenre
"$GENRE")
977 # If we want to start the tracks with a given number, we need to modify the
978 # TRACKNUM value before evaluation
979 if [ -n "$STARTTRACKNUMBER" ] ; then
980 # Get the trackpadding from the current track
981 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
982 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
984 TRACKNUM
=${UTRACKNUM}
986 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
987 # TRACKFILE, and TRACKNUM.
988 if [ "$VARIOUSARTISTS" = "y" ]; then
989 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
991 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
993 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
994 OUTPUTFILEDIR
=$
(dirname "$OUTPUTDIR/$OUTPUTFILE")
995 # mkdir -p shouldn't return an error if the directory already exists
996 mkdir
-p "$OUTPUTFILEDIR"
997 # Silence the Moving output since it overlaps with encoding processes...
998 #run_command '' vecho "Moving track$1.$OUTPUT to $OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
999 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1000 # Lets move the cue file
1001 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1002 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1003 if checkstatus movecue-
$OUTPUT; then :; else
1004 # Silence the Copying output since it overlaps with encoding processes...
1005 #run_command '' vecho "Copying cue file to its destination directory..."
1006 if checkstatus onetrack
>/dev
/null
; then
1008 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1009 # http://brianvictor.tripod.com/mp3cue.htm#details
1010 [a-z0-9
][a-z0-9
][a-z0-9
])
1011 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1014 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1018 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1020 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1028 # Create the playlist if wanted
1030 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1031 # VARIOUSARTISTS, OUTPUTDIR
1034 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1036 # Create a playlist file for the playlist data to go into.
1037 # We used to wipe it out if it existed. Now we request permision if interactive.
1038 for LASTTRACK
in $TRACKQUEUE; do :; done
1039 ALBUMFILE
=$
(mungefilename
"$DALBUM")
1040 ARTISTFILE
=$
(mungefilename
"$DARTIST")
1041 GENRE
=$
(mungegenre
"$GENRE")
1042 YEAR
=${CDYEAR:-$CDYEAR}
1043 if [ "$VARIOUSARTISTS" = "y" ] ; then
1044 PLAYLISTFILE
=$
(eval echo $VAPLAYLISTFORMAT)
1046 PLAYLISTFILE
=$
(eval echo $PLAYLISTFORMAT)
1048 FINALPLAYLISTDIR
=$
(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1049 mkdir
-p "$FINALPLAYLISTDIR"
1050 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1051 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1052 if [ "$INTERACTIVE" = "y" ]; then
1053 while [ "$DONE" != "y" ]; do
1055 case $ERASEPLAYLIST in
1056 e|E|a|A|k|K
) DONE
=y
;;
1064 # Once we erase the playlist, we use append to create the new one.
1065 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1067 # The playlist does not exist, so we can safelly use append to create the new list
1070 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1071 touch "$OUTPUTDIR/$PLAYLISTFILE"
1072 for UTRACKNUM
in $TRACKQUEUE
1074 # Shares some code with do_move since the filenames have to match
1075 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1076 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2 -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\ \+$//')
1078 TRACKFILE
=$
(mungefilename
"$TRACKNAME")
1079 ARTISTFILE
=$
(mungefilename
"$TRACKARTIST")
1080 # If we want to start the tracks with a given number, we need to modify the
1081 # TRACKNUM value before evaluation
1082 if [ -n "$STARTTRACKNUMBER" ] ; then
1083 # Get the trackpadding from the current track
1084 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
1085 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
1087 TRACKNUM
=${UTRACKNUM}
1089 if [ "$VARIOUSARTISTS" = "y" ]; then
1090 OUTPUTFILE
=$
(eval echo $VAOUTPUTFORMAT)
1092 OUTPUTFILE
=$
(eval echo $OUTPUTFORMAT)
1094 if [ "$VARIOUSARTISTS" = "y" ]; then
1095 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1096 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1098 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1101 if [ "$PLAYLISTDATAPREFIX" ]; then
1102 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1104 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1109 ## this will convert the playlist to have CRLF line-endings, if specified
1110 ## (some hardware players insist on CRLF endings)
1111 if [ "$DOSPLAYLIST" = "y" ]; then
1112 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1113 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1114 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1116 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1121 # This essentially the start of things
1124 # Query the CD to get the track info, unless the user specified -C
1125 # or we are using some actions which do not need the CDDB data at all
1126 #if [ ! X"$EXPACTIONS" = "X" ]; then
1128 #elif [ -z "$DISCID" ]; then
1129 if [ -z "$DISCID" ]; then
1130 vecho
-n "Getting CD track info... "
1131 # In OSX, unmount the disc before a query
1132 if [ "$OSFLAVOUR" = "OSX" ]; then
1133 disktool
-u ${CDROM#/dev/}
1135 TRACKINFO
=$
($CDDISCID $CDROM)
1136 # Make sure there's a CD in there by checking cd-discid's return code
1137 if [ "$?" = "1" ]; then
1138 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1141 # In OSX, remount the disc again
1142 if [ "$OSFLAVOUR" = "OSX" ]; then
1143 disktool
-m ${CDROM#/dev/}
1147 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1150 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1151 # This needs to be done now because a section of the resuming code will need
1154 # get the number of digits to pad TRACKNUM with - we'll use this later
1155 # a CD can only hold 99 tracks, but since we support a feature for starting
1156 # numbering the tracks from a given number, we might need to set it as a
1157 # variable for the user to define... or obtain it somehow.
1158 if [ "$PADTRACKS" = "y" ] ; then
1162 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1163 if [ -z "$TRACKQUEUE" ]; then
1164 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1165 case "$CDROMREADERSYNTAX" in
1167 if [ "$WEHAVEACD" = "y" ]; then
1168 vecho
"Querying the CD for audio tracks..."
1169 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1171 if [ ! "$RET" = "0" ];then
1172 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1174 TRACKS
="$( echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ' )"
1175 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1177 if [ -f "$ABCDETEMPDIR/status" ] && checkstatus cdparanoia-audio-tracks
; then
1178 TRACKS
=$
( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" )
1180 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1184 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1187 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1189 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1190 echo "The disc does not contain any tracks. Giving up..."
1193 echo -n "Grabbing entire CD - tracks: "
1194 if [ ! "$PADTRACKS" = "y" ] ; then
1195 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1197 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1199 while [ "$X" -ne "$TRACKS" ]
1201 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1202 TRACKQUEUE
=$
(echo "$TRACKQUEUE" $X)
1206 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1207 # User-supplied track queue.
1208 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1209 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1210 # Once cleaned, obtain the highest value in the trackqueue for number padding
1211 for LASTTRACK
in $TRACKQUEUE; do :; done
1212 if [ ! "$PADTRACKS" = "y" ] ; then
1213 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1215 # Now we normalize the trackqueue
1216 for TRACK
in $TRACKQUEUE ; do
1217 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1218 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1220 TRACKQUEUE
=$PADTRACKQUEUE
1221 echo Grabbing tracks
: "$TRACKQUEUE"
1224 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1226 # We have the discid, create a temp directory after it to store all the temp
1229 if [ -e "$ABCDETEMPDIR" ]; then
1230 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1231 # It already exists, see if it's a directory
1232 if [ ! -d "$ABCDETEMPDIR" ]; then
1233 # This is a file/socket/fifo/device/etc, not a directory
1236 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1237 echo "Please investigate, remove it, and rerun abcde." >&2
1241 # It's a directory, let's see if it's owned by us
1242 if [ ! -O "$ABCDETEMPDIR" ]; then
1243 # Nope, complain and exit
1245 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1246 echo "Please investigate, remove it, and rerun abcde." >&2
1250 # See if it's populated
1251 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1252 # Wipe and start fresh
1253 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1254 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1255 if [ "$INTERACTIVE" = "y" ]; then
1261 if [ "$ANSWER" != "y" ]; then
1264 rm -rf "$ABCDETEMPDIR" ||
exit 1
1265 mkdir
"$ABCDETEMPDIR"
1266 if [ "$?" -gt "0" ]; then
1267 # Directory already exists or could not be created
1268 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1272 # Everything is fine. Check for ^encodetracklocation-
1273 # and encode-output entries in the status file and
1274 # remove them. These are not relevant across sessions.
1275 if [ -f "$ABCDETEMPDIR/status" ]; then
1276 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1277 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1278 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1280 # Remove old error messages
1281 if [ -f "$ABCDETEMPDIR/errors" ]; then
1282 rm -f "$ABCDETEMPDIR/errors"
1286 # We are starting from scratch
1287 mkdir
"$ABCDETEMPDIR"
1288 if [ "$?" -gt "0" ]; then
1289 # Directory already exists or could not be created
1290 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1293 cat /dev
/null
> "$ABCDETEMPDIR/status"
1295 if [ X
"$MAKECUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1296 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1297 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1298 vecho
"Creating cue file..."
1299 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1300 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1302 echo "abcde: reading the CUE sheet with mkcue is still considered experimental"
1303 echo "abcde: and there was a problem with the CD reading. abcde will continue,"
1304 echo "abcde: but consider reporting the problem to the abcde author"
1308 # If we got the CDPARANOIA status and it is not recorded, save it now
1309 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1310 if checkstatus cdparanoia-audio-tracks
; then :; else
1311 if echo "$CDPARANOIAAUDIOTRACKS" >> "$ABCDETEMPDIR/cdparanoia-audio-tracks"; then
1312 echo "cdparanoia-audio-tracks" >> "$ABCDETEMPDIR/status"
1317 # Create the discid file
1318 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1322 # Create a proper CUE file based on the CUE file we created before.
1325 # FIXME # we can get the name of the cuefile from the status file
1326 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1327 CUEFILE_OUT
=$CUEFILE_IN.out
1328 ### FIXME ### checkstatus cddb
1329 if [ -e "$CDDBDATA" ]; then
1330 vecho
"Adding metadata to the cue file..."
1331 # FIXME It doesn't preserve spaces! Why?
1332 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1334 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1335 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1336 cat "$CUEFILE_IN" |
while read line
1338 if echo "$line" |
grep -q "INDEX"
1340 eval track
="\$TRACK$n"
1342 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1344 echo "$line" >> "$CUEFILE_OUT"
1346 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1347 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1353 # Parses a CDDB file and outputs the title and the track names.
1354 # Variables: CDDBFILE
1358 # List out disc title/author and contents
1359 if [ "$ONETRACK" = "y" ]; then
1360 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1362 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1363 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1364 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1365 if [ ! X
"$PARSEDYEAR" = "X" ]; then
1366 echo "Year: $PARSEDYEAR"
1369 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1370 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1371 if [ ! X
"$PARSEDGENRE" = "X" ]; then
1372 echo "Genre: $PARSEDGENRE"
1375 if [ ! "$ONETRACK" = "y" ]; then
1376 for TRACK
in $
(f_seq_row
1 $TRACKS)
1378 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1384 # Check for a local CDDB file, and report success
1387 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1389 CDDBLOCALSUCCESS
="n"
1390 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1391 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1394 # If the user has selected to check a local CDDB repo, we proceed with it
1395 if [ -r "${CDDBLOCALFILE}" ]; then
1396 # List out disc title/author and contents
1397 do_cddbparse
"${CDDBLOCALFILE}"
1398 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1399 if [ "$INTERACTIVE" = "y" ]; then
1401 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1402 echo -n 'Invalid selection. Please answer "y" or "n": '
1405 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1409 if [ "$USELOCALRESP" = "y" ]; then
1410 #echo "Using local copy of CDDB data"
1411 cp "${CDDBLOCALFILE}" "$ABCDETEMPDIR/cddbread.1"
1412 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1413 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1414 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1415 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1416 CDDBLOCALSUCCESS
="y"
1418 #echo "Not using local copy of CDDB data"
1419 CDDBLOCALSUCCESS
="n"
1422 CDDBLOCALSUCCESS
="n"
1430 # Perform CDDB protocol version check if it hasn't already been done
1431 if checkstatus cddb-statcomplete
; then :; else
1432 if [ "$CDDBAVAIL" = "n" ]; then
1434 echo 503 > "$ABCDETEMPDIR/cddbstat"
1437 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1438 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1439 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1440 vecho
"Checking CDDB server status..."
1441 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1442 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1443 case "$RESPONSECODE" in
1444 210) # 210 OK, status information follows (until terminating `.')
1447 501|
*) # 501 Illegal CDDB protocol level: <n>.
1448 CDDBPROTO
=`expr $CDDBPROTO - 1`
1452 if test $rc -eq 1; then
1456 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
1464 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1465 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1467 # Perform CDDB query if it hasn't already been done
1468 if checkstatus cddb-querycomplete
; then :; else
1469 if [ "$CDDBAVAIL" = "n" ]; then
1471 echo 503 > "$ABCDETEMPDIR/cddbquery"
1472 # The default CDDBLOCALSUCCESS is "n"
1473 # This part will be triggered if the user CDDB repo does not
1474 # contain the entry, or if we are not trying to use the repo.
1476 vecho
"Querying the CDDB server..."
1477 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1478 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1479 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1485 # no match found in database,
1486 # wget/fetch error, or user requested not to use CDDB
1487 # Make up an error code (503) that abcde
1488 # will recognize in do_cddbread
1489 # and compensate by making a template
1490 echo 503 > "$ABCDETEMPDIR/cddbquery"
1492 *) # strange and unknown error
1493 echo ERRORCODE
=$ERRORCODE
1494 echo "abcde: $CDDBTOOL returned unknown error code"
1498 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
1505 # If it's not to be used, generate a template.
1506 # Then, display it (or them) and let the user choose/edit it
1507 if checkstatus cddb-readcomplete
; then :; else
1508 vecho
"Obtaining CDDB results..."
1509 # If CDDB is to be used, interpret the query results and read all
1510 # the available entries.
1511 rm -f "$ABCDETEMPDIR/cddbchoices"
1512 CDDBCHOICES
=1 # Overridden by multiple matches
1513 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
1514 case "$RESPONSECODE" in
1516 # One exact match, retrieve it
1517 # 200 [section] [discid] [artist] / [title]
1518 if checkstatus cddb-read-1-complete
; then :; else
1519 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1520 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1521 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1522 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1523 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1525 # List out disc title/author and contents
1526 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1527 for TRACK
in $
(f_seq_row
1 $TRACKS)
1529 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1531 echo >> "$ABCDETEMPDIR/cddbchoices"
1535 case "$RESPONSECODE" in
1536 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1537 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1538 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1540 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1541 # List out disc title/author and contents of template
1542 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
1544 for TRACK
in $
(f_seq_row
1 $TRACKS)
1546 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1548 echo >> "$ABCDETEMPDIR/cddbchoices"
1549 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
1550 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
1553 # Multiple exact, (possibly multiple) inexact matches
1555 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
1556 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
1557 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1558 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1559 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1561 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1563 vecho
-n "Retrieving multiple matches... "
1564 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
1565 read DISCINFO
# eat top line
1569 if checkstatus cddb-read-
$X-complete; then :; else
1570 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1571 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
1573 # List out disc title/author and contents
1574 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1575 for TRACK
in $
(f_seq_row
1 $TRACKS)
1577 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1579 echo >> "$ABCDETEMPDIR/cddbchoices"
1582 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1586 for TRACK
in $
(f_seq_row
1 $TRACKS)
1588 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1590 echo >> "$ABCDETEMPDIR/cddbchoices"
1591 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
1592 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1595 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1602 if checkstatus cddb-edit
>/dev
/null
; then
1603 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1604 VARIOUSARTISTS
="$(checkstatus variousartists)"
1605 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
1608 if [ "$INTERACTIVE" = "y" ]; then
1609 # We should show the CDDB results both when we are not using the local CDDB repo
1610 # or when we are using it but we could not find a proper match
1611 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1612 # Display the $ABCDETEMPDIR/cddbchoices file created above
1613 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1614 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1615 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1616 CHOICE
=$
(checkstatus cddb-choice
)
1617 if [ -n "$CHOICE" ] ; then
1618 case $CDDBCHOICES in
1619 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1621 echo "Selected: #$CHOICE"
1622 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1626 # The user has a choice to make, display the info in a pager if necessary
1627 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
1628 page
"$ABCDETEMPDIR/cddbchoices"
1630 # It's all going to fit in one page, cat it
1631 cat "$ABCDETEMPDIR/cddbchoices" >&2
1635 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1637 # I'll take CDDB read #3 for $400, Alex
1638 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1639 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
1641 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
1642 if echo $CDDBCHOICE |
egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1643 if [ ! X
"$DIFF" = "X" ]; then
1644 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1)
1645 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2)
1646 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1647 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1648 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1649 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1652 # We parse the 2 choices to diff, store them in temporary files and diff them.
1653 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
1654 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1656 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1657 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1658 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
1659 page
"$ABCDETEMPDIR/cddbread.diff"
1661 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1665 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1668 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1669 # Make sure we get a valid choice
1670 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
1671 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1675 if [ "$CDCHOICENUM" = "0" ]; then
1676 vecho
"Creating empty CDDB template..."
1678 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1680 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1681 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1683 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1687 # We need some code to show the selected option when local repository is selected and we have found a match
1688 vecho
"Using cached CDDB match..." >&2
1689 # Display the $ABCDETEMPDIR/cddbchoices file created above
1690 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1691 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1692 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
1693 CHOICE
=$
(checkstatus cddb-choice
)
1694 if [ "$USELOCALRESP" = "y" ]; then :; else
1695 if [ -n "$CHOICE" ] ; then
1696 case $CDDBCHOICES in
1699 echo "Selected template."
1701 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1703 echo "Selected: #$CHOICE"
1704 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
1712 # We're noninteractive - pick the first choice.
1713 # But in case we run a previous instance and selected a choice, use it.
1714 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1715 # Show the choice if we are not using the locally stored one
1716 # or when the local search failed to find a match.
1717 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
1718 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
1719 #if [ "$PREVIOUSCHOICE" ]; then
1720 cat "$ABCDETEMPDIR/cddbchoices"
1723 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1724 CDCHOICENUM
=$PREVIOUSCHOICE
1727 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1729 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
1734 if checkstatus cddb-choice
>/dev
/null
; then :; else
1735 echo "abcde: internal error: cddb-choice not recorded." >&2
1738 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1739 echo -n "Edit selected CDDB data? [y/n] (" >&2
1740 if [ "$INTERACTIVE" = "y" ]; then
1741 if [ "$UNKNOWNDISK" = "y" ]; then
1744 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
1753 if [ "$EDITCDDB" = "y" ]; then
1754 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
1756 # Use the debian sensible-editor wrapper to pick the editor that the
1757 # user has requested via their $EDITOR environment variable
1758 if [ -x "/usr/bin/sensible-editor" ]; then
1759 /usr
/bin
/sensible-editor
"$CDDBDATA"
1760 elif [ -n "$EDITOR" ]; then
1761 if [ -x $
(which "${EDITOR%%\ *}") ]; then
1762 # That failed, try to load the preferred editor, starting
1763 # with their EDITOR variable
1764 eval $
(echo "$EDITOR") \"$CDDBDATA\"
1766 # If that fails, check for a vi
1767 elif which vi
>/dev
/null
2>&1; then
1769 elif [ -x /usr
/bin
/vim
]; then
1770 /usr
/bin
/vim
"$CDDBDATA"
1771 elif [ -x /usr
/bin
/vi
]; then
1772 /usr
/bin
/vi
"$CDDBDATA"
1773 elif [ -x /bin
/vi
]; then
1775 # nano should be on all (modern, i.e., sarge) debian systems
1776 elif which nano
>/dev
/null
2>&1 ; then
1778 elif [ -x /usr
/bin
/nano
]; then
1779 /usr
/bin
/nano
"$CDDBDATA"
1780 # mg should be on all OpenBSD systems
1781 elif which mg
>/dev
/null
2>&1 ; then
1783 elif [ -x /usr
/bin
/mg
]; then
1784 /usr
/bin
/mg
"$CDDBDATA"
1787 echo "No editor available. Check your EDITOR environment variable." >&2
1789 # delete editor backup file if it exists
1790 if [ -w "$CDDBDATA~" ]; then
1795 # Some heuristics first. Look at Disc Title, and if it starts with
1796 # "Various", then we'll assume Various Artists
1797 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
1798 echo "Looks like a Multi-Artist CD" >&2
1801 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1802 if [ "$INTERACTIVE" = "y" ]; then
1809 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1812 # Need NUMTRACKS before cddb-tool will return it:
1813 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
1814 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1815 # More than 1/2 tracks contain a "/", so guess forward
1817 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1818 # More than 1/2 contain a "-", so guess forward-dash
1820 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1821 # More than 1/2 contain something in parens, so guess trailing-paren
1825 echo "1) Artist / Title" >&2
1826 echo "2) Artist - Title" >&2
1827 echo "3) Title / Artist" >&2
1828 echo "4) Title - Artist" >&2
1829 echo "5) Artist: Title" >&2
1830 echo "6) Title (Artist)" >&2
1831 echo "7) This is a single-artist CD" >&2
1832 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
1833 if [ "$INTERACTIVE" = "y" ]; then
1834 read VARIOUSARTISTSTYLE
1836 echo $DEFAULTSTYLE >&2
1837 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1839 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1840 # If they press Enter, then the default style (0) was chosen
1841 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
1842 echo "Invalid selection. Please choose a number between 1 and 7."
1843 echo -n "Selection [1-7]: "
1844 read VARIOUSARTISTSTYLE
1845 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
1847 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
1848 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
1850 vecho
"Selected: $VARIOUSARTISTSTYLE"
1851 case "$VARIOUSARTISTSTYLE" in
1853 VARIOUSARTISTSTYLE
=forward
1856 VARIOUSARTISTSTYLE
=forward-dash
1859 VARIOUSARTISTSTYLE
=reverse
1862 VARIOUSARTISTSTYLE
=reverse-dash
1865 VARIOUSARTISTSTYLE
=colon
1868 VARIOUSARTISTSTYLE
=trailing-paren
1876 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
1877 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
1879 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
1880 if [ $CDDBDATAMD5SUM != "" ] && [ $CDDBDATAMD5SUM != $
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1) ]; then
1881 # This works but does not have the necessary error checking
1882 # yet. If you are familiar with the CDDB spec
1883 # (see http://www.freedb.org/src/latest/DBFORMAT)
1884 # and can create an error-free entry on your own, then put
1885 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
1886 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
1887 # your abcde.conf to change the email address submissions are
1890 # submit the modified file, if they want
1891 if [ "$NOSUBMIT" != "y" ]; then
1892 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
1894 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
1895 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
1897 echo -n 'Invalid selection. Please answer "y" or "n": '
1900 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
1901 echo -n "Sending..."
1902 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
1908 # Make sure the cache directory exists
1909 mkdir
-p $CDDBLOCALDIR
1910 # Cache edited CDDB entry in the user's cddb dir
1911 if [ "$CDDBCOPYLOCAL" = "y" ] ||
[ "$COPYCDDBLOCAL" = "Y" ]; then
1912 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
1915 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
1918 # do_cdread [tracknumber]
1919 # do_cdread onetrack [firsttrack] [lasttrack]
1923 # The commands here don't go through run_command because they're never supposed to be silenced
1924 # return codes need to be doublechecked anyway, however
1925 if [ "$1" = "onetrack" ]; then
1926 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
1927 # FIXME # Until then, we grab the whole CD in one track, no matter what
1929 # We need the first and last track for cdda2wav
1932 UTRACKNUM
=$FIRSTTRACK
1933 case "$CDROMREADERSYNTAX" in
1934 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
1935 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTRACK" ;;
1936 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
1942 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1943 if [ "$USEPIPES" = "y" ]; then
1944 TEMPARG
="PIPE_$CDROMREADERSYNTAX"
1945 FILEARG
="${!TEMPARG}"
1947 PIPE_MESSAGE
="and encoding "
1949 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
1950 case "$CDROMREADERSYNTAX" in
1951 ## FIXME ## Find the case for dagrab, to avoid exceptions
1953 FILEARG
="-f $WAVDATA"
1961 if [ "$1" = "onetrack" ]; then
1962 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
1964 if [ -r "$CDDBDATA" ]; then
1965 TRACKNAME
=$
(grep ^TTITLE
$CDDBTRACKNUM= "$CDDBDATA" |
head -n 1 | cut
-f2 -d= |
tr -d \
[:cntrl
:\
])
1966 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
1968 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
1971 case "$CDROMREADERSYNTAX" in
1973 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
1975 if [ "$OSFLAVOUR" = "OSX" ] ; then
1976 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
1977 disktool
-u ${CDROM#/dev/} 0
1978 # Also, in OSX the cdrom device for cdda2wav changes...
1979 CDDA2WAVCDROM
="IODVDServices"
1980 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
1981 CDDA2WAVCDROM
="$CDROMID"
1983 if [ "$CDROMID" = "" ]; then
1984 CDDA2WAVCDROM
="$CDROM"
1986 CDDA2WAVCDROM
="$CDROMID"
1989 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
1991 ## FIXME ## We have an exception for dagrab, since it uses -f
1992 ## FIXME ## Shall we just use -f $FILEARG ??
1993 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
1996 # Find the track's mounted path
1997 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
1998 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
1999 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2000 # If the file exists, copy it
2001 if [ -e "$FILEPATH" ] ; then
2002 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2006 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2010 # If we get some error or we get some missing wav
2011 # (as long as we dont use pipes)
2012 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2013 # Thank goodness errors is only machine-parseable up to the
2014 # first colon, otherwise this woulda sucked
2015 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2016 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2018 if [ "$USEPIPES" = "y" ]; then
2019 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2021 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2025 if [ "$USEPIPES" = "y" ]; then
2026 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2028 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2029 if [ "$1" = "onetrack" ]; then
2030 echo onetrack
>> "$ABCDETEMPDIR/status"
2037 # No values accepted, only uses env variables
2040 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2041 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2043 echo "abcde: unable to set the device speed" >&2
2049 # vecho outputs a message if EXTRAVERBOSE is selected
2052 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2057 # User-redefinable functions
2058 # Custom filename munging:
2061 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2062 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2065 # Custom genre munging:
2068 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2072 # Empty pre_read function, to be defined in the configuration file.
2079 # Empty post_read function, to be defined in the configuration file.
2085 ###############################################################################
2088 # Start of execution
2089 ###############################################################################
2092 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2093 CDDBSUBMIT
=freedb-submit@freedb.org
2095 HELLOINFO
="$(whoami)@$(hostname)"
2097 CDDBLOCALDIR
="$HOME/.cddb"
2100 # List of fields we parse and show during the CDDB parsing...
2101 SHOWCDDBFIELDS
="year,genre"
2104 CDROMREADERSYNTAX
=cdparanoia
2105 ENCODERSYNTAX
=default
2107 MP3ENCODERSYNTAX
=default
2108 OGGENCODERSYNTAX
=default
2109 FLACENCODERSYNTAX
=default
2110 SPEEXENCODERSYNTAX
=default
2111 MPPENCODERSYNTAX
=default
2112 NORMALIZERSYNTAX
=default
2113 CUEREADERSYNTAX
=default
2115 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2116 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2117 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2118 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2119 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2120 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2121 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2122 PLAYLISTDATAPREFIX
=''
2123 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2124 VAPLAYLISTDATAPREFIX
=''
2132 VARIOUSARTISTSTYLE
=forward
2136 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2137 # i.e. CDROMID="1,0,0"
2139 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2140 # If we are using the ide-scsi emulation layer, we need to define a "g"
2141 CDPARANOIACDROMBUS
="d"
2143 # program paths - defaults to checking your $PATH
2149 XINGMP3ENC
=xingmp3enc
2163 CDPARANOIA
=cdparanoia
2172 VORBISCOMMENT
=vorbiscomment
2174 NORMALIZE
=normalize-audio
2176 VORBISGAIN
=vorbisgain
2181 # Options for programs called from abcde
2213 VORBISCOMMENTOPTS
="-R"
2214 METAFLACOPTS
="--no-utf8-convert"
2216 # Default to one process if -j isn't specified
2219 # List of actions to perform - by default, run to completion
2220 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2222 # List of prefered outputs - by default, run with whatever we have in the path
2223 # This option is basicaly for Debian package dependencies
2224 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
2226 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2227 # Let's use these checkings to determine the OS flavour, which will be used later
2228 if [ X$
(uname
) = "XFreeBSD" ] ; then
2232 elif [ X$
(uname
) = "XDarwin" ] ; then
2235 # We should have disktool in OSX, but let's be sure...
2237 CDROMREADERSYNTAX
=cddafs
2238 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2245 # If CDDBAVAIL is set to n, no CDDB read is done
2246 # If USEID3 is set to n, no ID3 tagging is done
2251 if [ -z "$OUTPUTDIR" ]; then
2255 if [ -z "$WAVOUTPUTDIR" ]; then
2256 WAVOUTPUTDIR
="$OUTPUTDIR"
2259 # Load system defaults
2260 if [ -r /etc
/abcde.conf
]; then
2263 # Load user preference defaults
2264 if [ -r $HOME/.abcde.conf
]; then
2268 # By this time, we need some HTTPGETOPTS already defined.
2269 # If the user has defined a non-default HTTPGET method, we should not be empty.
2271 if [ "$HTTPGETOPTS" = "" ] ; then
2273 wget
) HTTPGETOPTS
="-q -O -";;
2274 curl
) HTTPGETOPTS
="-f -s";;
2275 fetch
)HTTPGETOPTS
="-q -o -";;
2276 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2280 # If the CDROM has not been set yet, find a suitable one.
2281 # If this is a devfs system, default to /dev/cdroms/cdrom0
2282 # instead of /dev/cdrom
2283 if [ "$CDROM" = "" ] ; then
2284 if [ -e /dev
/cdroms
/cdrom0
]; then
2285 CDROM
=/dev
/cdroms
/cdrom0
2286 elif [ -e /dev
/cdrom
]; then
2288 elif [ -e /dev
/cd0c
]; then
2290 elif [ -e /dev
/acd0c
]; then
2292 elif [ -e /dev
/disk1
]; then
2297 # Parse command line options
2298 #while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2299 while getopts 1a
:bc:C
:d
:Dehj
:klLmMnNo
:pPr
:Rs
:S
:t
:T
:vVxw
:W
: opt
; do
2302 a
) ACTIONS
="$OPTARG" ;;
2303 A
) EXPACTIONS
="$OPTARG";;
2305 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2306 C
) DISCID
="${OPTARG#abcde.}" ;;
2307 d
) CDROM
="$OPTARG" ;;
2309 e
) ERASEENCODEDSTATUS
=y
;;
2311 e
) ERASEENCODEDSTATUS
=y
;;
2312 # f) FORCECDDBUSELOCAL=y ;;
2314 j
) MAXPROCS
="$OPTARG" ;;
2317 L
) CDDBUSELOCAL
=y
;;
2322 o
) OUTPUTTYPE
="$OPTARG" ;;
2325 r
) REMOTEHOSTS
="$OPTARG" ;;
2327 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2328 S
) CDSPEEDVALUE
="$OPTARG" ;;
2329 # t) PREPROCESSFORMATS="$OPTARG"
2331 # T) POSTPROCESSFORMATS="$OPTARG" ;;
2332 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2333 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2335 echo "This is abcde v$VERSION."
2336 echo "Usage: abcde [options] [tracks]"
2337 echo "abcde -h for extra help"
2340 V
) EXTRAVERBOSE
="y" ;;
2342 w
) COMMENT
="$OPTARG" ;;
2343 W
) if echo $OPTARG |
grep -q "[[:digit:]]" ; then
2344 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2346 echo "abcde error: argument of -W must be integer"
2354 shift $
(($OPTIND - 1))
2356 # Decide if we can continue.
2357 if [ "$ONETRACK" = "y" ]; then
2358 # FIXME # remove check as soon as we find out about the other readers
2359 case "$CDROMREADERSYNTAX" in
2362 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2365 if [ "$BATCH" = "y" ]; then
2366 echo "abcde error: BATCH mode is not compatible with ONETRACK mode"
2369 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2370 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2371 if [ $# -gt 0 ]; then
2372 vecho
"abcde warning: ONETRACK mode selected, grabbing all tracks..."
2375 while [ $# -gt 0 ]; do
2376 # Range parsing code courtesy of Vincent Ho
2377 RSTART
=$
(echo $1 | cut
-f1 -d-)
2378 REND
=$
(echo $1 | cut
-f2 -d-)
2379 if [ "$RSTART" = "$REND" ]; then
2382 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
2384 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
2389 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2390 # List of experimental actions: retag,transcode
2392 # Determine what actions are to be done from $ACTIONS and set the
2393 # following environment variables for them:
2405 for ACTION
in $
(echo $ACTIONS |
tr , \
)
2410 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
2411 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2412 encode
) DOENCODE
=y
; DOREAD
=y
;;
2413 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2414 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2415 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
2416 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
2421 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
2422 case $SHOWCDDBFIELD in
2423 y
*|Y
*) SHOWCDDBYEAR
="y";;
2424 g
*|G
*) SHOWCDDBGENRE
="y";;
2431 # At this point a CDROM has to be defined, so we check it exists.
2432 if [ X
"$CDROM" != "X" ] ; then
2433 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2434 if [ "$OSFLAVOUR" = "FBSD" ]; then
2435 if ! echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then
2436 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2437 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2441 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
2442 echo "abcde error: CDROM device cannot be found." >&2
2445 # avoid processing if we are not going to hit the CDROM.
2446 elif [ X
"$DOREAD" = "Xy" ]; then
2447 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2451 # USEPIPES pre-tests, before we get into more serious stuff
2452 # Not compatible with:
2453 # - multiple outputs
2455 # - lowdisk algorithm
2457 if [ X
"$USEPIPES" = "Xy" ]; then
2458 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
2459 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
2462 if [ X
"$DONORMALIZE" = "Xy" ]; then
2463 echo "abcde error: Unix pipes not compatible with normalizer"
2464 # FIXME # Do we need to exit or shall we just disable the mode?
2467 if [ X
"$DOENCODE" = "Xn" ]; then
2468 vecho
"Disabling Unix pipes since we are not encoding!"
2471 if [ X
"$LOWDISK" = "Xy" ]; then
2472 vecho
"abcde error: Unix pipes not compatible with lowdisk algorithm"
2477 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2478 if [ X
"$OUTPUTTYPE" = "X" ]; then
2479 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
2480 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2481 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2482 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
2483 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
2484 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2488 if [ X
"$OUTPUTTYPE" = "X" ]; then
2489 echo "abcde error: no encoder found in the PATH" >&2
2490 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2495 # Decide which CDROM reader we're gonna use
2496 case "$CDROMREADERSYNTAX" in
2498 CDROMREADER
="$CDPARANOIA"
2499 CDROMREADEROPTS
="$CDPARANOIAOPTS"
2502 CDROMREADER
="$CDDA2WAV"
2503 CDROMREADEROPTS
="$CDDA2WAVOPTS"
2506 CDROMREADER
="$DAGRAB"
2507 CDROMREADEROPTS
="$DAGRABOPTS"
2510 CDROMREADER
="$CDDAFS"
2511 CDROMREADEROPTS
="$CDDAFSOPTS"
2515 # There's only one normalize...
2516 case "$NORMALIZERSYNTAX" in
2518 NORMALIZER
="$NORMALIZE"
2519 NORMALIZEROPTS
="$NORMALIZEOPTS"
2523 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
2524 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
2525 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
); do
2527 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2528 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2529 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2530 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2531 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
2534 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
); do
2535 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
2536 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2538 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
2541 # 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
2543 # Getting ready for multiple output changes
2544 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
2548 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
2549 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
2550 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
2551 OGGOUTPUTCONTAINER
=ogg
2554 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
2555 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
2558 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
2559 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
2562 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
2565 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
2567 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2573 # decide which encoder
2574 case "$MP3ENCODERSYNTAX" in
2576 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
2580 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
2584 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
2585 MP3ENCODER
="$BLADEENC"
2588 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
2592 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
2593 MP3ENCODER
="$XINGMP3ENC"
2596 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
2597 MP3ENCODER
="$MP3ENC"
2600 case "$OGGENCODERSYNTAX" in
2602 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
2603 OGGENCODER
="$VORBIZE"
2606 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
2607 OGGENCODER
="$OGGENC"
2610 case "$FLACENCODERSYNTAX" in
2612 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
2614 # FLAC streams can be encapsulated on a Ogg transport layer
2615 if echo "$FLACENCODEROPTS" |
egrep -q -- "(^| )--ogg($| )" ;then
2616 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2617 echo " due to problem with adding comments to such files" >&2
2619 FLACOUTPUTCONTAINER
=ogg
2621 FLACOUTPUTCONTAINER
=flac
2625 case "$SPEEXENCODERSYNTAX" in
2627 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
2628 SPEEXENCODER
="$SPEEXENC"
2631 case "$MPPENCODERSYNTAX" in
2633 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
2634 MPPENCODER
="$MPPENC"
2640 if [ "$ID3TAGV" = "1" ]; then
2642 TAGGEROPTS
="$ID3OPTS"
2645 TAGGEROPTS
="$ID3V2OPTS"
2649 case "$CUEREADERSYNTAX" in
2651 CUEREADEROPTS
="${CDROM}"
2656 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2657 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2658 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2659 echo " due to problem with adding comments to such files" >&2
2661 OGGOUTPUTCONTAINER
=ogg.ogg
2662 FLACOUTPUTCONTAINER
=flac.ogg
2663 vecho
"abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2666 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2668 if [ "$ENCNICE" ]; then
2669 ENCNICE
="-n $ENCNICE"
2671 if [ "$READNICE" ]; then
2672 READNICE
="-n $READNICE"
2674 if [ "$DISTMP3NICE" ]; then
2675 DISTMP3NICE
="-n $DISTMP3NICE"
2678 # Don't check for stuff if it's not needed
2679 if [ "$REMOTEHOSTS" ]; then
2682 if [ "$DONORMALIZE" = "y" ]; then
2685 if [ "$EJECTCD" = "y" ]; then
2688 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2691 if [ "$MAKECUEFILE" = "y" ]; then
2695 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2696 case "$CDROMREADERSYNTAX" in
2697 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
2702 # Rippers with USEPIPE support
2703 # FIXME # Include here all the rippers we can figure out support pipes
2706 # Encoders with USEPIPE support
2707 # FIXME # Include here all the encoders we can figure out support pipes
2712 # Figure out if we can use pipes with the ripper/encoder combination
2714 if [ "$USEPIPES" = "y" ]; then
2715 PIPERIPPERSVARCHECK
="PIPE_${CDROMREADER}"
2718 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
2720 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
2722 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
2724 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
2726 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
2728 if [ ! -n "${!PIPERIPPERSVARCHECK}" ] ; then
2729 echo "abcde error: no support for pipes with given ripper" >&2
2730 echo "read the USEPIPES file from the source tarball to help" >&2
2731 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2734 if [ ! -n "${!PIPEENCODERSVARCHECK}" ] ; then
2735 echo "abcde error: no support for pipes with given encoder" >&2
2736 echo "read the USEPIPES file from the source tarball to help" >&2
2737 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
2742 # Make sure a buncha things exist
2743 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
2744 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
2745 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
2746 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
2747 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
2748 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
2749 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDCUEREADER+$CUEREADER}
2751 # Cut off the command-line options we just added in
2752 X
=$
(echo $X | cut
-d' ' -f2)
2753 if [ "$(which $X)" = "" ]; then
2754 echo "abcde error: $X is not in your path." >&2
2756 elif [ ! -x $
(which $X) ]; then
2757 echo "abcde error: $X is not executable." >&2
2762 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
2763 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
2764 HTTPGET
="$HTTPGET $HTTPGETOPTS"
2766 # And last but not least, check if we can diff between files
2767 if [ -x $
(which $DIFF) ]; then :; else
2768 vecho
"[WAR] Disabling diff since we cannot find it in the \$PATH..."
2772 # Here it used to say:
2773 # One thousand lines in, we can start doing stuff with things
2774 # Well, right now we are at line 2736 ;)
2776 # Export needed things so they can be read in this subshell
2777 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
2778 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
2780 # User-definable function to set some things. Use it for
2781 # - closing the CD tray with eject -t
2782 # - set the CD speed value with eject -x
2783 vecho
-n "Executing customizable pre-read function... "
2785 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
2789 do_discid
# Get ABCDETEMPDIR created and status file initialized
2791 if [ "$DOCDDB" = "y" ]; then
2792 if [ $CDDBUSELOCAL = "y" ]; then
2795 if checkstatus cddb-choice
> /dev
/null
; then
2798 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
2806 eval $
($CDDBTOOL parse
"$CDDBDATA")
2809 # Before reading tracks, we set the speed of the device
2811 if [ X
"$CDSPEEDVALUE" != "X" ]; then
2812 case "$CDROMREADERSYNTAX" in
2813 cdparanoia|debug
) : ;;
2818 # Define the first and last track, since we might need them later in several places
2819 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
2820 LASTTRACK
=$
( get_last
$TRACKQUEUE )
2822 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
2823 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2824 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
2825 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
2828 # Create playlist if needed (backgroundable) and start reading in tracks
2832 if [ ! "$ONETRACK" = "y" ]; then
2833 if [ "$DOPLAYLIST" = "y" ]; then
2834 echo Creating playlist...
>&2
2839 # For the lowdisk option, only one program is running at once so the encoder
2840 # can be unsilenced right away.
2841 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2842 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2845 if [ "$ONETRACK" = "y" ]; then
2846 TRACKS
="$FIRSTTRACK"
2847 if checkstatus readtrack-
$FIRSTTRACK; then :; else
2848 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
2851 for UTRACKNUM
in $TRACKQUEUE
2853 if [ "$DOREAD" = "y" ]; then
2854 if [ "$USEPIPES" = "y" ]; then
2855 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
2856 # Read, pipe, shut up!
2857 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
2860 if checkstatus readtrack-
$UTRACKNUM; then :; else
2861 do_cdread
$UTRACKNUM
2863 if [ "$?" != "0" ]; then
2864 # CD read failed - don't give the goahead to
2871 if [ "$BATCH" = "y" ]; then
2874 echo NEXTTRACK
# Get the encoder machine churning again
2875 if [ "$DOREAD" = "y" ]; then
2876 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
2877 until checkstatus encodetrack-
$UTRACKNUM
2879 if checkerrors encodetrack-
$UTRACKNUM; then
2890 # Now that we're done the encoding can be loud again -
2891 # if we're not using SMP.
2892 if [ "$MAXPROCS" = "1" ]; then
2893 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
2896 # All tracks read, start encoding.
2897 if [ "$BATCH" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
2901 # Execute the user-defined post_read funtion before ejecting CD
2904 # We are now finished with the cdrom - it can be safely ejected. Note that
2905 # abcde will not have completed yet.
2906 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
2907 # We check if the disk we are processing is actually the disk inside the
2908 # CD tray. If not, we do not eject the CD, since it might be so that the
2909 # user ejected it manually.
2910 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
2911 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
2912 # More FreeBSD bits.
2913 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
2914 # FreeBSD eject uses the EJECT environment variable to name the CDROM
2915 # but in this script EJECT is in the envionment and names the program
2918 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
2919 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
2920 $eject $EJECTOPTS $cd
2921 elif [ X
"$(uname)" = X
"Darwin" ] ; then
2922 disktool
-e ${CDROM#/dev/} 0
2924 $EJECT $EJECTOPTS $CDROM
2931 ## Do we need to pre-process
2932 #if [ x"$PREPROCESS" = "x" ] ; then
2935 # for PRETRACKNUM in $TRACKQUEUE
2938 # if [ "$GOAHEAD" = "NO" ]; then break; fi
2940 # until [ $PREPROCEED ]
2942 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
2943 # # all locations are working, wait and try again later
2944 # if [ ! $PREPROCEED ]; then sleep 3; fi
2946 # ( do_preprocess $PRETRACKNUM
2954 # In batch mode, we want all tracks to be read first.
2955 if [ "$BATCH" = "y" ]; then
2956 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2957 if [ "$GOAHEAD" = "NO" ]; then break; fi
2958 for LASTTRACK
in $TRACKQUEUE; do :; done
2959 if checkstatus readtrack-
$LASTTRACK; then
2960 if [ "$DONORMALIZE" = "y" ]; then
2961 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
2962 if checkerrors batch-normalize
; then exit; fi
2964 if [ "$DOENCODE" = "y" ]; then
2965 if checkstatus encodetrack-
$LASTTRACK; then :; else do_batch_encode
; fi
2966 if checkerrors batch-encode
; then exit; fi
2971 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
2972 if [ "$ONETRACK" = "y" ] ; then
2973 TRACKQUEUE
="$FIRSTTRACK"
2974 TRACKS
="$FIRSTTRACK"
2977 # Do the encoding, including parallelization of remote encoding
2978 # Figure out where each track is going to be encoded
2979 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
2980 if [ "$MAXPROCS" != "0" ]; then
2981 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
2983 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
2987 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
2988 for UTRACKNUM
in $TRACKQUEUE
2991 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
2992 if [ "$GOAHEAD" = "NO" ]; then break; fi
2993 # find out where this track is to be encoded
2994 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
2995 # Make sure we have a place to encode this, if not, exit stage right
2996 if [ -z "$ENCODELOCATIONS" ]; then
3002 for LOCATION
in $ENCODELOCATIONS
3004 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3005 # check first if a track has ever been assigned to this location
3006 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
3007 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3008 if checkerrors encodetrack-
$PREVIOUSTRACK; then
3009 for TEMPLOCATION
in $ENCODELOCATIONS
3011 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3012 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
3015 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
3020 # We're still here, this location must have been previously assigned,
3021 # and last completed without error - check if it's done with the
3022 # previous track yet
3023 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
3025 # all locations are working, wait and try again later
3026 if [ ! $PROCEED ]; then sleep 3; fi
3028 # Record the location we're about to encode the next track at
3029 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3031 # Don't proceed with the rest of the loop if we can't encode
3032 if [ "$ABORT" ]; then continue; fi
3033 # Set TRACKNUM, TRACKNAME
3034 if [ -e "$CDDBDATA" ]; then
3035 if [ "$ONETRACK" = "y" ]; then
3037 TRACKNUM
="$FIRSTTRACK"
3040 # TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
3042 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3043 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
3047 # You can't encode a file which needs to be normalized before finishing
3048 # You can't tag a file before it's finished encoding -
3049 # thus all of this is backgrounded together
3051 if [ "$DONORMALIZE" = "y" ]; then
3052 if checkstatus readtrack-
$UTRACKNUM; then
3053 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3056 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3057 if checkstatus readtrack-
$UTRACKNUM; then
3058 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3059 if [ "$DONORMALIZE" = "y" ]; then
3060 if checkstatus normalizetrack-
$UTRACKNUM; then
3061 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3064 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3068 if [ "$DOTAG" = "y" ]; then
3069 if checkstatus encodetrack-
$UTRACKNUM; then
3070 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3072 # Lets tag the cue file
3073 if checkstatus cleancuefile
>/dev
/null
; then :; else
3074 if checkstatus cuefile
>/dev
/null
; then
3079 if [ "$DOMOVE" = "y" ]; then
3080 if checkstatus tagtrack-
$UTRACKNUM; then
3081 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3088 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3089 # we'll delete the files they're working on
3090 ## FIXME ## Check also for files which are encoded using PIPEs.
3091 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3096 for LOCATION
in $ENCODELOCATIONS
3098 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3099 # "How can he give us a status update, if he's DEAD?"
3100 if checkstatus encodetrack-
$CHECKTRACK; then
3103 # Nothing to see here please go quietly back to your homes
3104 if [ -z "$CHECKTRACK" ]; then continue; fi
3105 # You're still here? Maybe there is something...
3106 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3109 if [ ! $PROCEED ]; then sleep 5; fi
3112 # If the above didn't catch the stragglers, this will
3114 # Check to see if run_command logged any errors
3115 if [ -f "$ABCDETEMPDIR/errors" ]; then
3116 echo "The following commands failed to run:"
3117 cat "$ABCDETEMPDIR/errors"
3121 if [ "$KEEPWAVS" = "y" ];then
3125 if [ "$DOCLEAN" = "y" ]; then
3126 # Wipe all the evidence
3127 # Gimme gimme gimme some more time!
3129 rm -rf "$ABCDETEMPDIR"
3132 echo "Finished. Not cleaning $ABCDETEMPDIR."