2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 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 along
8 # with this program; if not, write to the Free Software Foundation, Inc.,
9 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
16 VERSION
='2.3.99-$Revision$'
20 echo "This is abcde v$VERSION."
21 echo "Usage: abcde [options] [tracks]"
23 echo "-1 Encode the whole CD in a single file"
24 echo "-a <action1[,action2]...>"
25 echo " Actions to perform:"
26 echo " cddb,read,normalize,encode,tag,move,replaygain,playlist,clean"
27 #echo "-A Experimental actions (retag, transcode)"
28 echo "-b Enable batch normalization"
29 #echo "-B Disable batch replaygain (do file by file)"
31 echo " Specify a configuration file (overrides system and user config files)"
33 echo " Specify discid to resume from (only needed if you no longer have the cd)"
35 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
36 echo "-D Debugging mode (equivalent to sh -x abcde)"
37 echo "-e Erase encoded track information from status file"
38 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
39 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
40 echo "-h This help information"
41 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
42 echo "-j <#> Number of encoder processes to run at once (localhost)"
43 echo "-k Keep the wav tracks for later use"
44 echo "-l Use low disk space algorithm"
45 echo "-L Use local CDDB storage directory"
46 echo "-n No lookup. Don't query CDDB, just create and use template"
47 echo "-N Noninteractive. Never prompt for anything"
48 echo "-m Modify playlist to include CRLF endings, to comply with some players"
49 echo "-M Create a CUE file"
50 echo "-o <type1[,type2]...>"
51 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
52 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
53 echo "-P Use UNIX pipes to read+encode without wav files"
54 echo "-r <host1[,host2]...>"
55 echo " Also encode on these remote hosts"
56 echo "-R Use local CDDB in recursive mode"
58 echo " Show dielfs from the CDDB info (year,genre)"
59 echo "-S <#> Set the CD speed"
60 echo "-t <#> Start the track numbering at a given number"
61 echo "-T <#> Same as -t but modifies tag numbering"
62 echo "-u Use UNICODE (UTF8) tags and comments"
63 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
64 echo "-v Show version number and exit"
65 echo "-V Be a bit more verbose about what is happening behind the scenes"
66 echo "-x Eject CD after all tracks are read"
68 echo " Add a comment to the CD tracks"
69 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
70 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
72 echo "Tracks is a space-delimited list of tracks to grab."
73 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
75 #echo "Double hyphens are used to concatenate tracks"
80 echo "$@" >> "$ABCDETEMPDIR/status"
83 # log [level] [message]
85 # log outputs the right message in a common format
91 error
) echo "[ERROR] abcde: $@" >&2 ;;
92 warning
) echo "[WARNING] $@" >&2 ;;
93 info
) echo "[INFO] $@" ;;
97 # Funtions to replace the need of seq, which is too distribution dependant.
101 while [ $i -ne `expr $2 + 1` ]
111 if echo $i |
grep "[[:digit:]]" > /dev
/null
2>&1 ; then
112 while [ $i -ne `expr $2 + 1` ]
119 log error
"syntax error while processing track numbers"
124 # Functions to replace the need of awk {print $1} and {print $NF}
127 if [ X
"$1" = "X" ]; then
128 for first
in `cat`; do
139 if [ X
"$1" = "X" ]; then
140 for stdin
in `cat`; do
144 for last
in $@
; do :; done
149 # checkstatus [blurb]
150 # Returns "0" if the blurb was found, returns 1 if it wasn't
151 # Puts the blurb content, if available, on stdout.
152 # Otherwise, returns "".
155 # Take the last line in the status file if there's multiple matches
157 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
159 if [ -z "$BLURB" ]; then
164 # See if there's a = in it
165 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
166 echo "$(echo $BLURB | cut -f2- -d=)"
172 # checkwarnings [blurb]
173 # Returns "0" if the blurb was found (meaning there was an warning),
174 # returns 1 if it wasn't (yes this is a little backwards).
175 # Does not print the blurb on stdout.
176 # Otherwise, returns "".
179 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
182 # Take the last line in the status file if there's multiple matches
184 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
186 if [ -z "$BLURB" ]; then
187 # negative, we did not have a negative...
190 # affirmative, we had a negative...
195 # checkerrors [blurb]
196 # Returns "0" if the blurb was found (meaning there was an error),
197 # returns 1 if it wasn't (yes this is a little backwards).
198 # Does not print the blurb on stdout.
199 # Otherwise, returns "".
202 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
205 # Take the last line in the status file if there's multiple matches
207 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
209 if [ -z "$BLURB" ]; then
210 # negative, we did not have a negative...
213 # affirmative, we had a negative...
219 # Finds the right pager in the system to display a file
223 # Use the debian sensible-pager wrapper to pick the pager
224 # user has requested via their $PAGER environment variable
225 if [ -x "/usr/bin/sensible-pager" ]; then
226 /usr
/bin
/sensible-pager
"$PAGEFILE"
227 elif [ -x "$PAGER" ]; then
228 # That failed, try to load the preferred editor, starting
229 # with their PAGER variable
231 # If that fails, check for less
232 elif [ -x /usr
/bin
/less ]; then
233 /usr
/bin
/less -f "$PAGEFILE"
234 # more should be on all UNIX systems
235 elif [ -x /bin
/more ]; then
236 /bin
/more "$PAGEFILE"
238 # No bananas, just cat the thing
243 # run_command [blurb] [command...]
244 # Runs a command, silently if necessary, and updates the status file
249 # See if this is supposed to be silent
250 if [ "$(checkstatus encode-output)" = "loud" ]; then
254 # Special case for SMP, since
255 # encoder output is never displayed, don't mute echos
256 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
265 normalize|normalize-audio
)
266 if [ "$RETURN" = "2" ]; then
267 # File was already normalized.
272 if [ "$RETURN" != "0" ]; then
273 # Put an error in the errors file. For various reasons we
274 # can't capture a copy of the program's output but we can
275 # log what we attempted to execute and the error code
276 # returned by the program.
277 if [ "$BLURB" ]; then
280 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
281 return $RETURN # Do not pass go, do not update the status file
283 if [ "$BLURB" ]; then
284 echo $BLURB >> "$ABCDETEMPDIR/status"
288 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
289 # distributed under the terms of the GNU GPL v2 or later, at your option
291 # Function to determine if a word contains a slash.
300 # Function to give the relative path from one file to another.
301 # Usage: relpath fromfile tofile
302 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
303 # (the result would be Album/Song.mp3)
304 # Output is relative path to $2 from $1 on stdout
306 # This code has the following restrictions:
307 # Multiple ////s are not collapsed into single /s, with strange effects.
308 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
309 # If FR is a directory it must have a trailing /
317 /*) ;; # No processing is needed for absolute paths
319 # Loop through common prefixes, ignoring them.
320 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
322 FR
="$(echo "$FR" | cut -d/ -f2-)"
323 TO
="$(echo "$TO" | cut -d/ -f2-)"
325 # Loop through directory portions left in FR, adding appropriate ../s.
328 FR
="$(echo "$FR" | cut -d/ -f2-)"
339 if [ ! "$@" = "" ]; then
340 # Cut off any command-line option we added in
341 X
=$
(echo $@ | cut
-d' ' -f2)
342 if [ "$(which $X)" = "" ]; then
344 elif [ ! -x $
(which $X) ]; then
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X
=$
(echo $@ | cut
-d' ' -f2)
356 if [ "$(which $X)" = "" ]; then
357 log error
"$X is not in your path." >&2
358 log info
"Define the full path to the executable if it exists on your system." >&2
360 elif [ ! -x "$(which $X)" ]; then
361 log error
"$X is not executable." >&2
367 # diffentries <filename> <max_value> <entry1>,<entry2>
368 # max_value: the range of entries goes from 1 to <max_value>
373 local CDDBDIFFCHOICES
=$1
375 local CDDBDIFFCHOICE
="$@"
376 if [ ! X
"$DIFF" = "X" ]; then
377 PARSECHOICE1
=$
(echo $CDDBDIFFCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
378 PARSECHOICE2
=$
(echo $CDDBDIFFCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
379 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
380 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
381 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
382 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
384 # We parse the 2 choices to diff, store them in temporary files and diff them.
385 for PARSECHOICE
in $
(echo $CDDBDIFFCHOICE |
tr , \
); do
386 do_cddbparse
"$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
388 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
389 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
390 if [ $
(cat "$ABCDETEMPDIR/$FILENAME.diff" |
wc -l) -ge 24 ]; then
391 page
"$ABCDETEMPDIR/$FILENAME.diff"
393 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
397 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
402 # Finds an specific field from cddbinfo
407 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
410 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
416 # Get the track number we are going to use for different actions
419 if [ -n "$STARTTRACKNUMBER" ] ; then
420 # Get the trackpadding from the current track
421 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
422 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
424 TRACKNUM
=${UTRACKNUM}
430 # Calculate cddb disc ids without requiring specialized helper programs.
431 # largely copied from cd-discid and musicbrainz examples. some of the steps
432 # don't make sense, but they're necessary to match the ids generated by other
435 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
436 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
437 # processing offsetimes 00:00:00 04:47:10 08:20:37 11:46:46 17:45:36 21:41:57 27:32:21 32:03:73 35:39:28 38:27:33 43:50:38 44:42:34
438 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
439 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
440 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
442 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
445 if [ X
"$LEADOUT" = "X" ]; then
446 log warning
"Error trying to calculate disc ids without lead-out information."
450 # default to a two second lead-in
452 LEADIN
=${LEADIN:=150}
454 # number of cdframes per second
457 # reset cddb checksum for cddb disc-id calululation
461 for OFFSET
in $
(echo $OFFSETS)
463 COOKEDOFFSETS
="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
465 OFFSETTIME
=$
(( ($OFFSET + $LEADIN) / $CDFRAMES ))
466 while [ $OFFSETTIME -gt 0 ]; do
467 CDDBCKSUM
=$
(($CDDBCKSUM + $OFFSETTIME % 10))
468 OFFSETTIME
=$
(($OFFSETTIME / 10))
473 COOKEDOFFSETS
="${COOKEDOFFSETS:1}" # eat the leading space
475 PREGAP
=$
(($
(echo $OFFSETS | cut
-f1 -d' ')))
476 TOTALTIME
=$
(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
478 printf -v HEXSUM
"%08lx" $
(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
479 TRACKINFO="${HEXSUM} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
484 if checkstatus replaygain; then :; else
485 run_command "" echo "Adding replygain information..."
486 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
490 OUTPUT=$OGGOUTPUTCONTAINER
493 OUTPUT=$FLACOUTPUTCONTAINER
501 for UTRACKNUM in $TRACKQUEUE
503 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
504 getcddbinfo TRACKNAME
506 TRACKFILE="$(mungefilename "$TRACKNAME")"
507 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
508 ALBUMFILE="$(mungefilename "$DALBUM")"
510 if [ "$ONETRACK" = "y" ]; then
511 if [ "$VARIOUSARTISTS" = "y" ]; then
512 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
514 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
517 if [ "$VARIOUSARTISTS" = "y" ]; then
518 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
520 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
523 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
524 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
528 run_command replaygain-flac $METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
531 run_command replaygain-vorbis $VORBISGAIN --album "${OUTPUTFILES[@]}"
534 run_command replaygain-mp3 $MP3GAIN -a "${OUTPUTFILES[@]}"
537 run_command replaygain-mpc $MPPGAIN --auto "${OUTPUTFILES[@]}"
542 if checkerrors "replaygain-.{3,6}"; then :; else
543 run_command replaygain true
548 # This code splits the a Various Artist track name from one of the following
551 # forward: Artist / Track
552 # forward-dash: Artist - Track
553 # reverse: Track / Artist
554 # reverse-dash: Track - Artist
555 # colon: Artist: Track
556 # trailing-paren: Artist (Track)
559 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
562 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
563 case "$VARIOUSARTISTSTYLE" in
565 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
566 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
567 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
570 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
571 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
572 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
575 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
576 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
577 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
580 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
581 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
582 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
585 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
586 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
587 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
590 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
591 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
592 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
595 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
596 TRACKARTIST="Various"
598 TRACKARTIST="$DARTIST"
603 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
607 "classic rock") id=1 ;;
625 "industrial") id=19 ;;
626 "alternative") id=20 ;;
628 "death metal") id=22 ;;
630 "soundtrack") id=24 ;;
631 "euro-techno") id
=25 ;;
635 "jazz+funk") id
=29 ;;
638 "classical") id
=32 ;;
639 "instrumental") id
=33 ;;
643 "sound clip") id
=37 ;;
646 "alt. rock") id
=40 ;;
651 "meditative") id
=45 ;;
652 "instrum. pop") id
=46 ;;
653 "instrum. rock") id
=47 ;;
657 "techno-indust.") id
=51 ;;
658 "electronic") id
=52 ;;
660 "eurodance") id
=54 ;;
662 "southern rock") id
=56 ;;
667 "christian rap") id
=61 ;;
668 "pop/funk"|
"pop / funk") id
=62 ;;
670 "native american") id
=64 ;;
673 "psychadelic") id
=67 ;;
675 "showtunes") id
=69 ;;
679 "acid punk") id
=73 ;;
680 "acid jazz") id
=74 ;;
684 "rock & roll") id
=78 ;;
685 "hard rock") id
=79 ;;
687 "folk/rock") id
=81 ;;
688 "national folk") id
=82 ;;
695 "bluegrass") id
=89 ;;
696 "avantgarde") id
=90 ;;
697 "gothic rock") id
=91 ;;
698 "progress. rock") id
=92 ;;
699 "psychadel. rock") id
=93 ;;
700 "symphonic rock") id
=94 ;;
701 "slow rock") id
=95 ;;
704 "easy listening") id
=98 ;;
710 "chamber music") id
=104 ;;
712 "symphony") id
=106 ;;
713 "booty bass") id
=107 ;;
715 "porn groove") id
=109 ;;
717 "slow jam") id
=111 ;;
721 "folklore") id
=115 ;;
723 "power ballad") id
=117 ;;
724 "rhythmic soul") id
=118 ;;
725 "freestyle") id
=119 ;;
727 "punk rock") id
=121 ;;
728 "drum solo") id
=122 ;;
729 "a capella") id
=123 ;;
730 "euro-house") id
=124 ;;
731 "dance hall") id
=125 ;;
733 "drum & bass") id
=127 ;;
734 "club-house") id
=128 ;;
735 "hardcore") id
=129 ;;
739 "negerpunk") id
=133 ;;
740 "polsk punk") id
=134 ;;
742 "christian gangsta rap") id
=136 ;;
743 "heavy metal") id
=137 ;;
744 "black metal") id
=138 ;;
745 "crossover") id
=139 ;;
746 "contemporary christian")id
=140 ;;
747 "christian rock") id
=141 ;;
748 "merengue") id
=142 ;;
750 "thrash metal") id
=144 ;;
753 "synthpop") id
=147 ;;
754 "rock/pop"|
"rock / pop") id
=148 ;;
761 # do_tag [tracknumber]
762 # id3 tags a filename
764 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
765 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
768 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
769 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
770 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
771 # If we want to start the tracks with a given number, we need to modify the
772 # TRACKNUM value before evaluation
773 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
776 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
780 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
781 GENREID
=$
(do_getgenreid
"${CDGENRE}")
786 # FIXME # track numbers in mp3 come with 1/10, so we cannot
787 # happily substitute them with $TRACKNUM
788 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS \
789 --comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
790 -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
791 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
792 "${ENCODING:+--set-encoding=$ENCODING}" \
793 "$ABCDETEMPDIR/track$1.$OUTPUT"
795 # FIXME # Still not activated...
797 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
798 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" -y "$CDYEAR" \
799 -g "$GENREID" -k "${TRACKNUM:-$1}" \
800 "$ABCDETEMPDIR/track$1.$OUTPUT"
803 # FIXME # track numbers in mp3 come with 1/10, so we cannot
804 # happily substitute them with $TRACKNUM
805 run_command tagtrack-
$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
806 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
807 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
808 "$ABCDETEMPDIR/track$1.$OUTPUT"
813 case "$OGGENCODERSYNTAX" in
815 # vorbiscomment can't do in-place modification, mv the file first
816 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
817 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
820 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
821 echo ARTIST
="$TRACKARTIST"
823 echo TITLE
="$TRACKNAME"
824 if [ -n "$CDYEAR" ]; then
827 if [ -n "$CDGENRE" ]; then
828 echo GENRE
="$CDGENRE"
830 echo TRACKNUMBER
=${TRACKNUM:-$1}
831 echo CDDB
=$CDDBDISCID
832 if [ "$(eval echo ${COMMENT})" != "" ]; then
833 case "$COMMENTOUTPUT" in
834 *=*) echo "$COMMENTOUTPUT";;
835 *) echo COMMENT
="$COMMENTOUTPUT";;
838 ) | run_command tagtrack-
$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
839 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
840 # Doublecheck that the commented file was created successfully before wiping the original
841 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
842 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
844 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
851 echo ARTIST
="$TRACKARTIST"
853 echo TITLE
="$TRACKNAME"
854 if [ -n "$CDYEAR" ]; then
857 if [ -n "$CDGENRE" ]; then
858 echo GENRE
="$CDGENRE"
860 echo TRACKNUMBER
="${TRACKNUM:-$1}"
861 echo CDDB
="$CDDBDISCID"
862 if [ "$(eval echo ${COMMENT})" != "" ]; then
863 case "$COMMENTOUTPUT" in
864 *=*) echo "$COMMENTOUTPUT";;
865 *) echo COMMENT
="$COMMENTOUTPUT";;
868 ) | run_command tagtrack-
$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
871 run_command tagtrack-
$OUTPUT-$1 true
874 run_command tagtrack-
$OUTPUT-$1 true
877 run_command tagtrack-
$OUTPUT-$1 true
880 run_command tagtrack-
$OUTPUT-$1 true
884 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
885 run_command tagtrack-
$1 true
892 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
895 # The commands here don't go through run_command because they're never supposed to be silenced
896 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
897 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
901 case "$MP3ENCODERSYNTAX" in
906 for UTRACKNUM
in $TRACKQUEUE
908 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
910 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
912 if [ "$RETURN" != "0" ]; then
913 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
915 for UTRACKNUM
in $TRACKQUEUE
917 run_command encodetrack-
$OUTPUT-$UTRACKNUM true
918 #run_command encodetrack-$UTRACKNUM true
927 if checkerrors
"nogap-encode"; then :; else
928 if [ ! "$KEEPWAVS" = "y" ] ; then
929 if [ ! "$KEEPWAVS" = "move" ] ; then
934 # Other encoders fall through to normal encoding as the tracks
935 # have not been entered in the status file.
938 # do_encode [tracknumber] [hostname]
939 # If no hostname is specified, encode locally
941 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
944 if [ "$USEPIPES" = "y" ]; then
947 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
950 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
953 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
956 TEMPARG
="PIPE_$SPEEXENCODER"
959 TEMPARG
="PIPE_$MPPENCODER"
962 TEMPARG
="PIPE_$MPPENCODER"
965 IN
="$( eval echo "\$
$TEMPARG" )"
967 IN
="$ABCDETEMPDIR/track$1.wav"
970 case "$MP3ENCODERSYNTAX" in
971 # FIXME # check if mp3enc needs -if for pipes
972 # FIXME # I have not been able to find a working mp3enc binary
986 # We need IN to proceed, if we are not using pipes.
987 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
988 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
992 OUTPUT
=$OGGOUTPUTCONTAINER
995 OUTPUT
=$FLACOUTPUTCONTAINER
1001 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
1002 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-
$OUTPUT-$1 ; then
1005 if [ X
"$USEPIPES" = "Xy" ]; then
1007 # We need a way to store the creation of the files when using PIPES
1008 RUN_COMMAND_PIPES
="run_command encodetrack-$OUTPUT-$1 true"
1010 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1011 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
1017 case "$MP3ENCODERSYNTAX" in
1018 lame|gogo
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1019 bladeenc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1020 l3enc|xingmp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1021 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1022 mp3enc
) $RUN_COMMAND nice
$ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1026 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
1033 case "$OGGENCODERSYNTAX" in
1034 vorbize
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1035 oggenc
) $RUN_COMMAND nice
$ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1039 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
1046 case "$FLACENCODERSYNTAX" in
1047 flac
) $RUN_COMMAND nice
$ENCNICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1052 vecho
"$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1053 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
1058 if [ "$(eval echo ${COMMENT})" != "" ]; then
1061 *) COMMENT
="COMMENT=$COMMENT" ;;
1063 COMMENT
="--comment \"$COMMENT\""
1065 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1066 if [ ! "$DOTAG" = "y" ]; then
1067 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
1069 $RUN_COMMAND nice
$ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1073 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1075 # I tried compiling the mppenc from corecodecs.org and got some
1076 # errors, so I have not tried it myself.
1077 ## FIXME ## Needs some cleanup to determine if an empty tag sent
1078 ## FIXME ## to the encoder ends up empty.
1079 $RUN_COMMAND nice
$ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
1082 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1083 if [ ! "$DOTAG" = "y" ]; then
1084 $RUN_COMMAND nice
$ENCNICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
1087 $RUN_COMMAND nice
$ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1091 # In case of wav output we need nothing. Just keep the wavs.
1096 # Only remove .wav if the encoding succeeded
1097 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
1098 run_command encodetrack-
$1 true
1099 if [ ! "$KEEPWAVS" = "y" ] ; then
1100 if [ ! "$KEEPWAVS" = "move" ] ; then
1106 run_command
"" echo "HEH! The file we were about to encode disappeared:"
1107 run_command
"" echo ">> $IN"
1108 run_command encodetrack-
$1 false
1112 # do_preprocess [tracknumber]
1114 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1117 # IN="$ABCDETEMPDIR/track$1.wav"
1118 # # We need IN to proceed.
1119 # if [ -s "$IN" ] ; then
1120 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1122 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1123 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1124 # case "$POSTPROCESSFORMAT" in
1126 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1128 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1130 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1132 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1134 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1137 # # Only remove .wav if the encoding succeeded
1138 # if checkerrors "preprocess-(.{3,4})-$1"; then
1139 # run_command preprocess-$1 false
1141 # run_command preprocess-$1 true
1144 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1145 # echo "HEH! The file we were about to pre-process disappeared:"
1148 # run_command preprocess-$1 false
1153 # do_postprocess [tracknumber]
1155 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1158 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1160 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1161 # # We need IN to proceed.
1162 # if [ -s "$IN" ] ; then
1163 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1164 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1165 # case "$POSTPROCESSFORMAT" in
1167 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1169 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1171 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1173 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1175 # # Only remove .wav if the encoding succeeded
1176 # if checkerrors "postprocess-(.{3,4})-$1"; then
1177 # run_command postprocess-$1 false
1179 # run_command postprocess-$1 true
1182 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1183 # echo "HEH! The file we were about to post-process disappeared:"
1186 # run_command postprocess-$1 false
1201 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1205 # The commands here don't go through run_command because they're never supposed to be silenced
1206 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1211 for UTRACKNUM
in $TRACKQUEUE
1213 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1215 # FIXME # Hard-coded batch option!
1216 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1218 if [ "$RETURN" != "0" ]; then
1219 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1221 for UTRACKNUM
in $TRACKQUEUE
1223 echo normalizetrack-
$UTRACKNUM >> status
1229 # do_batch_normalize
1231 # NORMALIZER, NORMALIZEROPTS
1232 do_batch_normalize
()
1234 # The commands here don't go through run_command because they're never supposed to be silenced
1235 echo "Batch normalizing tracks: $TRACKQUEUE"
1240 for UTRACKNUM
in $TRACKQUEUE
1242 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1244 # XXX: Hard-coded batch option!
1245 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1247 if [ "$RETURN" != "0" ]; then
1248 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1250 for UTRACKNUM
in $TRACKQUEUE
1252 echo normalizetrack-
$UTRACKNUM >> status
1258 # do_normalize [tracknumber]
1260 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1263 IN
="$ABCDETEMPDIR/track$1.wav"
1264 if [ -e "$IN" ] ; then
1265 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1266 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1268 if [ "$(checkstatus encode-output)" = "loud" ]; then
1269 echo "HEH! The file we were about to normalize disappeared:"
1272 run_command normalizetrack-
$1 false
"File $IN was not found"
1276 # do_move [tracknumber]
1277 # Deduces the outfile from environment variables
1278 # Creates directory if necessary
1280 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1283 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1285 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1286 # defined the OUTPUTFILE:
1289 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1290 # Munge filenames as follows:
1295 # Eat control characters
1296 ALBUMFILE
="$(mungefilename "$DALBUM")"
1297 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1298 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1299 GENRE
="$(mungegenre "$GENRE")"
1300 YEAR
=${CDYEAR:-$CDYEAR}
1301 # If we want to start the tracks with a given number, we need to modify
1302 # the TRACKNUM value before evaluation
1304 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1305 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1306 if [ "$ONETRACK" = "y" ]; then
1307 if [ "$VARIOUSARTISTS" = "y" ]; then
1308 OUTPUTFILE
="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1310 OUTPUTFILE
="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1313 if [ "$VARIOUSARTISTS" = "y" ]; then
1314 OUTPUTFILE
="$(eval echo \""$VAOUTPUTFORMAT"\")"
1316 OUTPUTFILE
="$(eval echo \""$OUTPUTFORMAT"\")"
1319 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1320 # Once we know the specific output was successful, we can change
1321 # the OUTPUT to the value containing the container
1324 OUTPUT
=$OGGOUTPUTCONTAINER
1327 OUTPUT
=$FLACOUTPUTCONTAINER
1333 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1334 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1337 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1338 # FIXME # introduce warnings?
1341 # mkdir -p shouldn't return an error if the directory already exists
1342 mkdir
-p "$OUTPUTFILEDIR"
1343 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1344 if checkstatus movetrack-output-
$OUTPUT; then :; else
1345 run_command movetrack-output-
$OUTPUT true
1350 # mkdir -p shouldn't return an error if the directory already exists
1351 mkdir
-p "$OUTPUTFILEDIR"
1352 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1353 if checkstatus movetrack-output-
$OUTPUT; then :; else
1354 run_command movetrack-output-
$OUTPUT true
1358 # Lets move the cue file
1359 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1360 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1361 if checkstatus movecue-
$OUTPUT; then :; else
1362 # Silence the Copying output since it overlaps with encoding processes...
1363 #run_command '' vecho "Copying cue file to its destination directory..."
1364 if checkstatus onetrack
>/dev
/null
; then
1367 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1368 # We dont have the dir, since it was not created before.
1371 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1374 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1375 # http://brianvictor.tripod.com/mp3cue.htm#details
1376 [a-z0-9
][a-z0-9
][a-z0-9
])
1377 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1380 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1384 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1386 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1395 # Create the playlist if wanted
1397 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1398 # VARIOUSARTISTS, OUTPUTDIR
1401 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1405 OUTPUT
=$OGGOUTPUTCONTAINER
1408 OUTPUT
=$FLACOUTPUTCONTAINER
1414 # Create a playlist file for the playlist data to go into.
1415 # We used to wipe it out if it existed. Now we request permision if interactive.
1416 for LASTTRACK
in $TRACKQUEUE; do :; done
1417 ALBUMFILE
="$(mungefilename "$DALBUM")"
1418 ARTISTFILE
="$(mungefilename "$DARTIST")"
1419 GENRE
="$(mungegenre "$GENRE")"
1420 YEAR
=${CDYEAR:-$CDYEAR}
1421 if [ "$VARIOUSARTISTS" = "y" ] ; then
1422 PLAYLISTFILE
="$(eval echo "$VAPLAYLISTFORMAT")"
1424 PLAYLISTFILE
="$(eval echo "$PLAYLISTFORMAT")"
1426 FINALPLAYLISTDIR
="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1427 mkdir
-p "$FINALPLAYLISTDIR"
1428 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1429 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1430 if [ "$INTERACTIVE" = "y" ]; then
1431 while [ "$DONE" != "y" ]; do
1433 case $ERASEPLAYLIST in
1434 e|E|a|A|k|K
) DONE
=y
;;
1442 # Once we erase the playlist, we use append to create the new one.
1443 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1445 # The playlist does not exist, so we can safelly use append to create the new list
1448 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1449 touch "$OUTPUTDIR/$PLAYLISTFILE"
1450 for UTRACKNUM
in $TRACKQUEUE
1452 # Shares some code with do_move since the filenames have to match
1453 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1454 getcddbinfo TRACKNAME
1456 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1457 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1458 ALBUMFILE
="$(mungefilename "$DALBUM")"
1459 # If we want to start the tracks with a given number, we need to modify the
1460 # TRACKNUM value before evaluation
1462 if [ "$VARIOUSARTISTS" = "y" ]; then
1463 OUTPUTFILE
="$(eval echo \""$VAOUTPUTFORMAT\"")"
1465 OUTPUTFILE
="$(eval echo \""$OUTPUTFORMAT\"")"
1467 if [ "$VARIOUSARTISTS" = "y" ]; then
1468 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1469 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1471 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1474 if [ "$PLAYLISTDATAPREFIX" ]; then
1475 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1477 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1482 ## this will convert the playlist to have CRLF line-endings, if specified
1483 ## (some hardware players insist on CRLF endings)
1484 if [ "$DOSPLAYLIST" = "y" ]; then
1485 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1486 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1487 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1489 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1494 # This essentially the start of things
1497 # Query the CD to get the track info, unless the user specified -C
1498 # or we are using some actions which do not need the CDDB data at all
1499 #if [ ! X"$EXPACTIONS" = "X" ]; then
1501 #elif [ -z "$DISCID" ]; then
1502 if [ -z "$DISCID" ]; then
1503 vecho
-n "Getting CD track info... "
1504 # In OSX, unmount the disc before a query
1505 if [ "$OSFLAVOUR" = "OSX" ]; then
1506 disktool
-u ${CDROM#/dev/}
1508 case "$CDROMREADERSYNTAX" in
1510 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev
/null
2>&1 ; then
1511 case "$CUE2DISCID" in
1513 CUESHEET
="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1515 #TRACKS=$(echo $CUESHEET | egrep "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1517 OFFSETTIMES
=( $
(echo "$CUESHEET" |
sed -n -e's/\ *INDEX 01\ \+//p' ) )
1518 TRACKS
=${#OFFSETTIMES[@]}
1520 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1521 for OFFSETTIME
in ${OFFSETTIMES[@]}; do
1522 OFFSETS
="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1523 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1526 LEADOUT
=$
(( $
(echo "$CUESHEET" |
grep lead-out | get_last
) / 44100 * 75 ))
1527 LEADIN
=$
(( $
(echo "$CUESHEET" |
grep lead-in | get_last
) / 44100 * 75 ))
1531 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" |
$CUE2DISCID)
1535 log error
"the input flac file does not contain a cuesheet."
1540 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1542 # if [ ! "$RET" = "0" ];then
1543 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1546 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1547 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1549 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | egrep -o '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1550 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1554 case "$CDDBMETHOD" in
1555 cddb
) TRACKINFO
=$
($CDDISCID $CDROM) ;;
1556 # FIXME # musicbrainz needs a cleanup
1557 musicbrainz
) TRACKINFO
=$
($MUSICBRAINZ -c $CDROM ) ;;
1561 # Make sure there's a CD in there by checking cd-discid's return code
1562 if [ ! "$?" = "0" ]; then
1563 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1564 log error
"cuesheet information from the flac file could not be read."
1565 log error
"Perhaps the flac file does not contain a cuesheet?."
1568 log error
"CD could not be read. Perhaps there's no CD in the drive?"
1572 # In OSX, remount the disc again
1573 if [ "$OSFLAVOUR" = "OSX" ]; then
1574 disktool
-m ${CDROM#/dev/}
1577 DISCID
=$
(echo $TRACKINFO | cut
-f1 -d' ')
1579 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1582 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1583 # This needs to be done now because a section of the resuming code will need
1586 # get the number of digits to pad TRACKNUM with - we'll use this later
1587 # a CD can only hold 99 tracks, but since we support a feature for starting
1588 # numbering the tracks from a given number, we might need to set it as a
1589 # variable for the user to define... or obtain it somehow.
1590 if [ "$PADTRACKS" = "y" ] ; then
1594 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1595 if [ -z "$TRACKQUEUE" ]; then
1596 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1597 case "$CDROMREADERSYNTAX" in
1599 if [ "$WEHAVEACD" = "y" ]; then
1600 vecho
"Querying the CD for audio tracks..."
1601 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1603 if [ ! "$RET" = "0" ];then
1604 log warning
"something went wrong while querying the CD... Maybe a DATA CD?"
1606 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1607 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1609 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1610 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1611 echo cdparanoia-audio-tracks
=$
( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1612 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1614 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1615 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1619 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1622 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1624 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1625 log info
"The disc does not contain any tracks. Giving up..."
1628 echo -n "Grabbing entire CD - tracks: "
1629 if [ ! "$PADTRACKS" = "y" ] ; then
1630 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1632 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1634 while [ "$X" -ne "$TRACKS" ]
1636 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1637 TRACKQUEUE
=$
(echo $TRACKQUEUE $X)
1641 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1642 # User-supplied track queue.
1643 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1644 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1645 # Once cleaned, obtain the highest value in the trackqueue for number padding
1646 for LASTTRACK
in $TRACKQUEUE; do :; done
1647 if [ ! "$PADTRACKS" = "y" ] ; then
1648 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1650 # Now we normalize the trackqueue
1651 for TRACK
in $TRACKQUEUE ; do
1652 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1653 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1655 TRACKQUEUE
=$PADTRACKQUEUE
1656 echo Grabbing tracks
: "$TRACKQUEUE"
1659 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1661 # We have the discid, create a temp directory after it to store all the temp
1664 if [ -e "$ABCDETEMPDIR" ]; then
1665 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1666 # It already exists, see if it's a directory
1667 if [ ! -d "$ABCDETEMPDIR" ]; then
1668 # This is a file/socket/fifo/device/etc, not a directory
1671 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1672 echo "Please investigate, remove it, and rerun abcde." >&2
1676 # It's a directory, let's see if it's owned by us
1677 if [ ! -O "$ABCDETEMPDIR" ]; then
1678 # Nope, complain and exit
1680 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1681 echo "Please investigate, remove it, and rerun abcde." >&2
1685 # See if it's populated
1686 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1687 # Wipe and start fresh
1688 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1689 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1690 if [ "$INTERACTIVE" = "y" ]; then
1696 if [ "$ANSWER" != "y" ]; then
1699 rm -rf "$ABCDETEMPDIR" ||
exit 1
1700 mkdir
-p "$ABCDETEMPDIR"
1701 if [ "$?" -gt "0" ]; then
1702 # Directory already exists or could not be created
1703 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1707 # Everything is fine. Check for ^encodetracklocation-
1708 # and encode-output entries in the status file and
1709 # remove them. These are not relevant across sessions.
1710 if [ -f "$ABCDETEMPDIR/status" ]; then
1711 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1712 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1713 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1715 # Remove old error messages
1716 if [ -f "$ABCDETEMPDIR/errors" ]; then
1717 rm -f "$ABCDETEMPDIR/errors"
1721 # We are starting from scratch
1722 mkdir
-p "$ABCDETEMPDIR"
1723 if [ "$?" -gt "0" ]; then
1724 # Directory already exists or could not be created
1725 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1728 cat /dev
/null
> "$ABCDETEMPDIR/status"
1729 # Store the abcde version in the status file.
1730 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1732 if [ X
"$MAKECUEFILE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1733 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1734 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1735 vecho
"Creating cue file..."
1736 case $CDROMREADERSYNTAX in
1738 if $METAFLAC --export-cuesheet-to=- $CDROM > "$ABCDETEMPDIR/$CUEFILE"; then :; else
1739 log warning
"the input flac file does not contain a cuesheet."
1743 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1744 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1746 log warning
"reading the CUE sheet is still considered experimental"
1747 log warning
"and there was a problem with the CD reading. abcde will continue,"
1748 log warning
"but consider reporting the problem to the abcde author"
1754 # If we got the CDPARANOIA status and it is not recorded, save it now
1755 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1756 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
1757 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1761 # Create the discid file
1762 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1763 if checkstatus cddbmethod
> /dev
/null
2>&1 ; then :; else
1764 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
1769 # Create a proper CUE file based on the CUE file we created before.
1772 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1773 CUEFILE_OUT
=$CUEFILE_IN.out
1774 ### FIXME ### checkstatus cddb
1775 if [ -e "$CDDBDATA" ]; then
1776 vecho
"Adding metadata to the cue file..."
1777 # FIXME It doesn't preserve spaces! Why?
1778 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1780 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1781 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1782 cat "$CUEFILE_IN" |
while read line
1784 if echo "$line" |
grep "INDEX 01" > /dev
/null
2>&1 ; then
1785 eval track
="\$TRACK$n"
1787 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1789 echo "$line" >> "$CUEFILE_OUT"
1791 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1792 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1798 # Parses a CDDB file and outputs the title and the track names.
1799 # Variables: CDDBFILE
1803 # List out disc title/author and contents
1804 if [ "$ONETRACK" = "y" ]; then
1805 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1807 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1808 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1809 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1810 if [ ! X
"$PARSEDYEAR" = "X" ]; then
1811 echo "Year: $PARSEDYEAR"
1814 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1815 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1816 if [ ! X
"$PARSEDGENRE" = "X" ]; then
1817 echo "Genre: $PARSEDGENRE"
1820 if [ ! "$ONETRACK" = "y" ]; then
1821 for TRACK
in $
(f_seq_row
1 $TRACKS)
1823 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1829 # Check for a local CDDB file, and report success
1832 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
1834 CDDBLOCALSTATUS
="notfound"
1835 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
1838 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
1839 CDDBLOCALRESULTS
="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
1840 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
1841 if (( $
(echo "${CDDBLOCALRESULTS}" |
wc -l) == 1 )); then
1842 CDDBLOCALFILE
="${CDDBLOCALRESULTS}"
1843 CDDBLOCALMATCH
=single
1844 elif (( $
(echo "${CDDBLOCALRESULTS}" |
wc -l) > 1 )); then
1845 CDDBLOCALMATCH
=multiple
1850 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
1851 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
1852 CDDBLOCALMATCH
=single
1857 # If the user has selected to check a local CDDB repo, we proceed with it
1858 case $CDDBLOCALMATCH in
1860 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
1862 echo "$CDDBLOCALRESULTS" |
while read RESULT
; do
1864 # List out disc title/author and contents
1865 CDDBLOCALREAD
="$ABCDETEMPDIR/cddblocalread.$X"
1866 cat "$RESULT" > "${CDDBLOCALREAD}"
1869 do_cddbparse
"${CDDBLOCALREAD}"
1871 ##FIXME## QUICK HACK !!!!
1872 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
1873 } >> "$ABCDETEMPDIR/cddblocalchoices"
1875 if [ $
(cat "$ABCDETEMPDIR/cddblocalchoices" |
wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
1876 page
"$ABCDETEMPDIR/cddblocalchoices"
1878 # It's all going to fit in one page, cat it
1879 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
1881 CDDBLOCALCHOICES
=$
( echo "$CDDBLOCALRESULTS" |
wc -l )
1882 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1883 CDDBLOCALCHOICENUM
=-1
1884 if [ "$INTERACTIVE" = "y" ]; then
1885 while [ $CDDBLOCALCHOICENUM -lt 0 ] ||
[ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
1886 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
1887 read CDDBLOCALCHOICE
1888 [ x
"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE
="1"
1889 # FIXME # Introduce diff's
1890 if echo $CDDBLOCALCHOICE |
egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
1891 diffentries cddblocalread
"$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
1892 elif echo $CDDBLOCALCHOICE |
egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
1893 # Make sure we get a valid choice
1894 CDDBLOCALCHOICENUM
=$
(echo $CDDBLOCALCHOICE |
xargs printf %d
2>/dev
/null
)
1895 if [ $CDDBLOCALCHOICENUM -lt 0 ] ||
[ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
1896 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
1902 #echo "Selected ..."
1904 CDDBLOCALCHOICENUM
=1
1906 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
1907 #echo "Using local copy of CDDB data"
1908 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1909 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
1910 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1911 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1912 do_cddbparse
"$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
1913 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1914 CDDBLOCALSTATUS
="found"
1916 #echo "Not using local copy of CDDB data"
1917 CDDBLOCALSTATUS
="notfound"
1921 # List out disc title/author and contents
1922 do_cddbparse
"${CDDBLOCALFILE}"
1923 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1924 # echo -n "Embedded cuesheet entry found, use it? [y/n] (y): " >&2
1926 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
1928 if [ "$INTERACTIVE" = "y" ]; then
1930 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1931 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
1934 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
1938 if [ "$USELOCALRESP" = "y" ]; then
1939 #echo "Using local copy of CDDB data"
1940 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1941 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
1942 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1943 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
1944 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1945 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
1946 CDDBLOCALSTATUS
="single"
1948 #echo "Not using local copy of CDDB data"
1949 CDDBLOCALSTATUS
="notfound"
1953 CDDBLOCALSTATUS
="notfound"
1959 do_musicbrainzstat
()
1972 # Perform CDDB protocol version check if it hasn't already been done
1973 if checkstatus cddb-statcomplete
; then :; else
1974 if [ "$CDDBAVAIL" = "n" ]; then
1976 echo 503 > "$ABCDETEMPDIR/cddbstat"
1979 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
1980 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
1981 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1982 vecho
"Checking CDDB server status..."
1983 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1984 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
1985 case "$RESPONSECODE" in
1986 210) # 210 OK, status information follows (until terminating `.')
1989 501|
*) # 501 Illegal CDDB protocol level: <n>.
1990 CDDBPROTO
=`expr $CDDBPROTO - 1`
1994 if test $rc -eq 1; then
1998 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
2006 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
2007 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
2009 # Perform CDDB query if it hasn't already been done
2010 if checkstatus cddb-querycomplete
; then :; else
2011 if [ "$CDDBAVAIL" = "n" ]; then
2013 echo 503 > "$ABCDETEMPDIR/cddbquery"
2014 # The default CDDBLOCALSTATUS is "notfound"
2015 # This part will be triggered if the user CDDB repo does not
2016 # contain the entry, or if we are not trying to use the repo.
2018 vecho
"Querying the CDDB server..."
2019 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
2020 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
2021 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2027 # no match found in database,
2028 # wget/fetch error, or user requested not to use CDDB
2029 # Make up an error code (503) that abcde
2030 # will recognize in do_cddbread
2031 # and compensate by making a template
2032 echo 503 > "$ABCDETEMPDIR/cddbquery"
2034 *) # strange and unknown error
2035 echo ERRORCODE
=$ERRORCODE
2036 echo "abcde: $CDDBTOOL returned unknown error code"
2040 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
2047 # If it's not to be used, generate a template.
2048 # Then, display it (or them) and let the user choose/edit it
2049 if checkstatus cddb-readcomplete
; then :; else
2050 vecho
"Obtaining CDDB results..."
2051 # If CDDB is to be used, interpret the query results and read all
2052 # the available entries.
2053 rm -f "$ABCDETEMPDIR/cddbchoices"
2054 CDDBCHOICES
=1 # Overridden by multiple matches
2055 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
2056 case "$RESPONSECODE" in
2058 # One exact match, retrieve it
2059 # 200 [section] [discid] [artist] / [title]
2060 if checkstatus cddb-read-1-complete
; then :; else
2061 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2062 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2063 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2064 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2065 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2067 # List out disc title/author and contents
2068 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2069 for TRACK
in $
(f_seq_row
1 $TRACKS)
2071 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2073 echo >> "$ABCDETEMPDIR/cddbchoices"
2077 case "$RESPONSECODE" in
2078 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2079 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2080 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2082 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2083 # List out disc title/author and contents of template
2084 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
2086 for TRACK
in $
(f_seq_row
1 $TRACKS)
2088 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2090 echo >> "$ABCDETEMPDIR/cddbchoices"
2091 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
2092 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
2095 # Multiple exact, (possibly multiple) inexact matches
2097 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
2098 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
2099 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2100 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2101 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2103 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2105 vecho
-n "Retrieving multiple matches... "
2106 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
2107 read DISCINFO
# eat top line
2111 if checkstatus cddb-read-
$X-complete; then :; else
2112 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2113 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
2115 # List out disc title/author and contents
2116 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2117 for TRACK
in $
(f_seq_row
1 $TRACKS)
2119 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2121 echo >> "$ABCDETEMPDIR/cddbchoices"
2124 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2128 for TRACK
in $
(f_seq_row
1 $TRACKS)
2130 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2132 echo >> "$ABCDETEMPDIR/cddbchoices"
2133 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2134 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2137 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2144 if checkstatus cddb-edit
>/dev
/null
; then
2145 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2146 VARIOUSARTISTS
="$(checkstatus variousartists)"
2147 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
2150 if [ "$INTERACTIVE" = "y" ]; then
2151 # We should show the CDDB results both when we are not using the local CDDB repo
2152 # or when we are using it but we could not find a proper match
2153 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
2154 # Display the $ABCDETEMPDIR/cddbchoices file created above
2155 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2156 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2157 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2158 CHOICE
=$
(checkstatus cddb-choice
)
2159 if [ -n "$CHOICE" ] ; then
2160 case $CDDBCHOICES in
2161 -1) if head -1 "$ABCDETEMPDIR/cddbquery" |
grep "^$" > /dev
/null
2>&1 ; then
2162 log error
"CDDB query failed!"
2165 cat "$ABCDETEMPDIR/cddbchoices"
2168 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2170 echo "Selected: #$CHOICE"
2171 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
2175 # The user has a choice to make, display the info in a pager if necessary
2176 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
2177 page
"$ABCDETEMPDIR/cddbchoices"
2179 # It's all going to fit in one page, cat it
2180 cat "$ABCDETEMPDIR/cddbchoices" >&2
2184 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2186 # I'll take CDDB read #3 for $400, Alex
2187 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2188 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2190 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
2191 if echo $CDDBCHOICE |
egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2192 if [ ! X
"$DIFF" = "X" ]; then
2193 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
2194 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
2195 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2196 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2197 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2198 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
2200 # We parse the 2 choices to diff, store them in temporary files and diff them.
2201 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
2202 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2204 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2205 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2206 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
2207 page
"$ABCDETEMPDIR/cddbread.diff"
2209 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2213 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2215 elif echo $CDDBCHOICE |
egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2216 # Make sure we get a valid choice
2217 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
2218 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2219 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2223 if [ "$CDCHOICENUM" = "0" ]; then
2224 vecho
"Creating empty CDDB template..."
2226 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2228 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2229 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2231 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2235 # We need some code to show the selected option when local repository is selected and we have found a match
2236 vecho
"Using cached CDDB match..." >&2
2237 # Display the $ABCDETEMPDIR/cddbchoices file created above
2238 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2239 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2240 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2241 CHOICE
=$
(checkstatus cddb-choice
)
2242 if [ "$USELOCALRESP" = "y" ]; then :; else
2243 if [ -n "$CHOICE" ] ; then
2244 case $CDDBCHOICES in
2247 echo "Selected template."
2249 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2251 echo "Selected: #$CHOICE"
2252 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
2260 # We're noninteractive - pick the first choice.
2261 # But in case we run a previous instance and selected a choice, use it.
2262 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2263 # Show the choice if we are not using the locally stored one
2264 # or when the local search failed to find a match.
2265 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
2266 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
2267 #if [ "$PREVIOUSCHOICE" ]; then
2268 cat "$ABCDETEMPDIR/cddbchoices"
2271 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2272 CDCHOICENUM
=$PREVIOUSCHOICE
2275 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2277 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2282 if checkstatus cddb-choice
>/dev
/null
; then :; else
2283 echo "abcde: internal error: cddb-choice not recorded." >&2
2286 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2287 echo -n "Edit selected CDDB data? [y/n] (" >&2
2288 if [ "$INTERACTIVE" = "y" ]; then
2289 if [ "$UNKNOWNDISK" = "y" ]; then
2292 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
2301 if [ "$EDITCDDB" = "y" ]; then
2302 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
2304 # Use the debian sensible-editor wrapper to pick the editor that the
2305 # user has requested via their $EDITOR environment variable
2306 if [ -x "/usr/bin/sensible-editor" ]; then
2307 /usr
/bin
/sensible-editor
"$CDDBDATA"
2308 elif [ -n "$EDITOR" ]; then
2309 if [ -x $
(which "${EDITOR%%\ *}") ]; then
2310 # That failed, try to load the preferred editor, starting
2311 # with their EDITOR variable
2312 eval $
(echo "$EDITOR") \"$CDDBDATA\"
2314 # If that fails, check for a vi
2315 elif which vi
>/dev
/null
2>&1; then
2317 elif [ -x /usr
/bin
/vim
]; then
2318 /usr
/bin
/vim
"$CDDBDATA"
2319 elif [ -x /usr
/bin
/vi
]; then
2320 /usr
/bin
/vi
"$CDDBDATA"
2321 elif [ -x /bin
/vi
]; then
2323 # nano should be on all (modern, i.e., sarge) debian systems
2324 elif which nano
>/dev
/null
2>&1 ; then
2326 elif [ -x /usr
/bin
/nano
]; then
2327 /usr
/bin
/nano
"$CDDBDATA"
2328 # mg should be on all OpenBSD systems
2329 elif which mg
>/dev
/null
2>&1 ; then
2331 elif [ -x /usr
/bin
/mg
]; then
2332 /usr
/bin
/mg
"$CDDBDATA"
2335 log warning
"no editor available. Check your EDITOR environment variable."
2337 # delete editor backup file if it exists
2338 if [ -w "$CDDBDATA~" ]; then
2343 # Some heuristics first. Look at Disc Title, and if it starts with
2344 # "Various", then we'll assume Various Artists
2345 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2346 echo "Looks like a Multi-Artist CD" >&2
2349 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2350 if [ "$INTERACTIVE" = "y" ]; then
2357 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2360 # Need NUMTRACKS before cddb-tool will return it:
2361 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
2362 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2363 # More than 1/2 tracks contain a "/", so guess forward
2365 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2366 # More than 1/2 contain a "-", so guess forward-dash
2368 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2369 # More than 1/2 contain something in parens, so guess trailing-paren
2373 echo "1) Artist / Title" >&2
2374 echo "2) Artist - Title" >&2
2375 echo "3) Title / Artist" >&2
2376 echo "4) Title - Artist" >&2
2377 echo "5) Artist: Title" >&2
2378 echo "6) Title (Artist)" >&2
2379 echo "7) This is a single-artist CD" >&2
2380 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2381 if [ "$INTERACTIVE" = "y" ]; then
2382 read VARIOUSARTISTSTYLE
2384 echo $DEFAULTSTYLE >&2
2385 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2387 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2388 # If they press Enter, then the default style (0) was chosen
2389 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2390 echo "Invalid selection. Please choose a number between 1 and 7."
2391 echo -n "Selection [1-7]: "
2392 read VARIOUSARTISTSTYLE
2393 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2395 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2396 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2398 vecho
"Selected: $VARIOUSARTISTSTYLE"
2399 case "$VARIOUSARTISTSTYLE" in
2401 VARIOUSARTISTSTYLE
=forward
2404 VARIOUSARTISTSTYLE
=forward-dash
2407 VARIOUSARTISTSTYLE
=reverse
2410 VARIOUSARTISTSTYLE
=reverse-dash
2413 VARIOUSARTISTSTYLE
=colon
2416 VARIOUSARTISTSTYLE
=trailing-paren
2424 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2425 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2427 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2428 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2429 # This works but does not have the necessary error checking
2430 # yet. If you are familiar with the CDDB spec
2431 # (see http://www.freedb.org/src/latest/DBFORMAT)
2432 # and can create an error-free entry on your own, then put
2433 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2434 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2435 # your abcde.conf to change the email address submissions are
2438 # submit the modified file, if they want
2439 if [ "$NOSUBMIT" != "y" ]; then
2440 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2442 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2443 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2445 echo -n 'Invalid selection. Please answer "y" or "n": '
2448 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2449 echo -n "Sending..."
2450 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2457 # User CDDBLOCALPOLICY to find out if we store the file or not...
2458 # Cache edited CDDB entry in the user's cddb dir
2459 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2460 # Make sure the cache directory exists
2461 mkdir
-p $CDDBLOCALDIR
2462 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2465 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2468 # do_cdread [tracknumber]
2469 # do_cdread onetrack [firsttrack] [lasttrack]
2473 # The commands here don't go through run_command because they're never supposed to be silenced
2474 # return codes need to be doublechecked anyway, however
2475 if [ "$1" = "onetrack" ]; then
2476 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2477 # FIXME # Until then, we grab the whole CD in one track, no matter what
2479 # We need the first and last track for cdda2wav
2481 LASTTRACK
=$
(expr $3 + 0)
2482 UTRACKNUM
=$FIRSTTRACK
2483 case "$CDROMREADERSYNTAX" in
2484 flac
) READTRACKNUMS
="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2485 cdparanoia
) READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
2486 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTTRACK" ;;
2487 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2493 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2494 if [ "$USEPIPES" = "y" ]; then
2495 TEMPARG
="PIPERIPPER_$CDROMREADERSYNTAX"
2496 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2498 PIPE_MESSAGE
="and encoding "
2500 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2501 case "$CDROMREADERSYNTAX" in
2502 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2504 FILEARG
="--output-name=$WAVDATA"
2507 FILEARG
="-f $WAVDATA"
2515 if [ "$1" = "onetrack" ]; then
2516 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2518 if [ -r "$CDDBDATA" ]; then
2519 getcddbinfo TRACKNAME
2520 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2522 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2525 case "$CDROMREADERSYNTAX" in
2526 ### FIXME ### use an exception for flac, since it uses -o
2527 ### FIXME ### Shall we just use -o $FILEARG ??
2529 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2530 STRIPTRACKNUM
=$
(expr $UTRACKNUM + 0)
2531 nice
$READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2533 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2535 if [ "$OSFLAVOUR" = "OSX" ] ; then
2536 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2537 disktool
-u ${CDROM#/dev/} 0
2538 # Also, in OSX the cdrom device for cdda2wav changes...
2539 CDDA2WAVCDROM
="IODVDServices"
2540 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2541 CDDA2WAVCDROM
="$CDROMID"
2543 if [ "$CDROMID" = "" ]; then
2544 CDDA2WAVCDROM
="$CDROM"
2546 CDDA2WAVCDROM
="$CDROMID"
2549 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2551 ## FIXME ## We have an exception for dagrab, since it uses -f
2552 ## FIXME ## Shall we just use -f $FILEARG ??
2553 dagrab
) nice
$READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2556 # Find the track's mounted path
2557 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2558 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2559 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2560 # If the file exists, copy it
2561 if [ -e "$FILEPATH" ] ; then
2562 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2566 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2570 # If we get some error or we get some missing wav
2571 # (as long as we dont use pipes)
2572 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2573 # Thank goodness errors is only machine-parseable up to the
2574 # first colon, otherwise this woulda sucked
2575 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2576 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2578 if [ "$USEPIPES" = "y" ]; then
2579 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2581 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2585 if [ "$USEPIPES" = "y" ]; then
2586 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2588 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2590 if [ "$1" = "onetrack" ]; then
2591 echo onetrack
>> "$ABCDETEMPDIR/status"
2597 # No values accepted, only uses env variables
2600 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2601 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2603 echo "abcde: unable to set the device speed" >&2
2609 # vecho outputs a message if EXTRAVERBOSE is selected
2612 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2614 warning
) shift ; log warning
"$@" ;;
2622 # decho outputs a debug message if DEBUG is selected
2625 if [ x
"$DEBUG" != "x" ]; then
2626 if echo $1 |
grep "^\[" > /dev
/null
2>&1 ; then
2627 DEBUGECHO
=$
(echo "$@" |
tr -d '[]')
2628 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2635 # User-redefinable functions
2636 # Custom filename munging:
2639 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2640 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2643 # Custom genre munging:
2646 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2650 # Empty pre_read function, to be defined in the configuration file.
2657 # Empty post_read function, to be defined in the configuration file.
2663 ###############################################################################
2666 # Start of execution
2667 ###############################################################################
2672 # Defaults to FreeDB, but a python musicbrainz can be used
2674 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2675 CDDBSUBMIT
=freedb-submit@freedb.org
2677 HELLOINFO
="$(whoami)@$(hostname)"
2679 CDDBLOCALPOLICY
="always"
2680 CDDBLOCALRECURSIVE
="y"
2681 CDDBLOCALDIR
="$HOME/.cddb"
2684 # List of fields we parse and show during the CDDB parsing...
2685 SHOWCDDBFIELDS
="year,genre"
2688 #CDROMREADERSYNTAX=cdparanoia
2689 ENCODERSYNTAX
=default
2691 MP3ENCODERSYNTAX
=default
2692 OGGENCODERSYNTAX
=default
2693 FLACENCODERSYNTAX
=default
2694 SPEEXENCODERSYNTAX
=default
2695 MPPENCODERSYNTAX
=default
2696 AACENCODERSYNTAX
=default
2697 NORMALIZERSYNTAX
=default
2698 CUEREADERSYNTAX
=default
2700 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2701 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2702 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2703 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2704 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2705 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2706 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2707 PLAYLISTDATAPREFIX
=''
2708 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2709 VAPLAYLISTDATAPREFIX
=''
2717 VARIOUSARTISTSTYLE
=forward
2723 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2724 # i.e. CDROMID="1,0,0"
2726 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2727 # If we are using the ide-scsi emulation layer, we need to define a "g"
2728 CDPARANOIACDROMBUS
="d"
2730 # program paths - defaults to checking your $PATH
2737 XINGMP3ENC
=xingmp3enc
2754 CDPARANOIA
=cdparanoia
2760 MUSICBRAINZ
=musicbrainz-get-tracks
2764 VORBISCOMMENT
=vorbiscomment
2766 NORMALIZE
=normalize-audio
2768 VORBISGAIN
=vorbisgain
2774 CUE2DISCID
=cue2discid
2776 # Options for programs called from abcde
2811 VORBISCOMMENTOPTS
="-R"
2812 METAFLACOPTS
="--no-utf8-convert"
2815 # Default to one process if -j isn't specified
2818 # List of actions to perform - by default, run to completion
2819 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2821 # This option is basicaly for Debian package dependencies:
2822 # List of prefered outputs - by default, run with whatever we have in the path
2823 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
,m4a
:faac
2825 # List of prefered cdromreaders - by default, run whichever we have in the path
2826 DEFAULT_CDROMREADERS
="cdparanoia cdda2wav"
2828 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
2829 # Linux/OpenBSD. ftp is user for NetBSD.
2830 # Let's use these checkings to determine the OS flavour, which will be used
2832 if [ X$
(uname
) = "XFreeBSD" ] ; then
2837 elif [ X$
(uname
) = "XDarwin" ] ; then
2840 # We should have disktool in OSX, but let's be sure...
2842 CDROMREADERSYNTAX
=cddafs
2843 elif [ X$
(uname
) = "XOpenBSD" ] ; then
2847 elif [ X$
(uname
) = "XNetBSD" ] ; then
2851 elif [ X$
(uname
) = "SunOS" ] ; then
2859 # If CDDBAVAIL is set to n, no CDDB read is done
2860 # If USEID3 is set to n, no ID3 tagging is done
2865 if [ -z "$OUTPUTDIR" ]; then
2869 if [ -z "$WAVOUTPUTDIR" ]; then
2870 WAVOUTPUTDIR
="$OUTPUTDIR"
2873 # Load system defaults
2874 if [ -r /etc
/abcde.conf
]; then
2877 # Load user preference defaults
2878 if [ -r $HOME/.abcde.conf
]; then
2882 # By this time, we need some HTTPGETOPTS already defined.
2883 # If the user has defined a non-default HTTPGET method, we should not be empty.
2885 if [ "$HTTPGETOPTS" = "" ] ; then
2887 wget
) HTTPGETOPTS
="-q -O -";;
2888 curl
) HTTPGETOPTS
="-f -s";;
2889 fetch
)HTTPGETOPTS
="-q -o -";;
2890 ftp) HTTPGETOPTS
="-a -V -o - ";;
2891 *) log warning
"HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
2895 # If the CDROM has not been set yet, find a suitable one.
2896 # If this is a devfs system, default to /dev/cdroms/cdrom0
2897 # instead of /dev/cdrom
2898 if [ "$CDROM" = "" ] ; then
2899 if [ -e /dev
/cdroms
/cdrom0
]; then
2900 CDROM
=/dev
/cdroms
/cdrom0
2901 elif [ -e /dev
/cdrom
]; then
2903 elif [ -e /dev
/cd0c
]; then
2905 elif [ -e /dev
/acd0c
]; then
2907 elif [ -e /dev
/disk1
]; then
2912 # Parse command line options
2913 #while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2914 while getopts 1a
:bBc
:C
:d
:Defghj
:klLmMnNo
:pPr
:s
:S
:t
:T
:uvVxw
:W
:z opt
; do
2917 a
) ACTIONS
="$OPTARG" ;;
2918 A
) EXPACTIONS
="$OPTARG" ;;
2920 B
) NOBATCHREPLAYGAIN
=y
;;
2921 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else log error
"config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
2922 C
) DISCID
="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
2923 d
) CDROM
="$OPTARG" ;;
2926 e
) ERASEENCODEDSTATUS
=y
;;
2927 E
) ENCODING
="$OPTARG" ;;
2931 j
) MAXPROCS
="$OPTARG" ;;
2934 L
) CDDBUSELOCAL
=y
;;
2939 o
) OUTPUTTYPE
="$OPTARG" ;;
2942 r
) REMOTEHOSTS
="$OPTARG" ;;
2943 R
) CDDBLOCALRECURSIVE
=y
;;
2944 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
2945 S
) CDSPEEDVALUE
="$OPTARG" ;;
2946 t
) STARTTRACKNUMBER
="$OPTARG" ;;
2947 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
2951 echo "This is abcde v$VERSION."
2952 echo "Usage: abcde [options] [tracks]"
2953 echo "abcde -h for extra help"
2956 V
) EXTRAVERBOSE
="y" ;;
2958 w
) COMMENT
="$OPTARG" ;;
2959 W
) if echo $OPTARG |
grep "[[:digit:]]" > /dev
/null
2>&1 ; then
2960 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
2962 log error
"argument of -W must be integer"
2966 z
) DEBUG
=y
; CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
2967 Z
) CUE2DISCID
=builtin;;
2972 shift $
(($OPTIND - 1))
2974 # Here it comes the worse part of the whole thing. From here until we start
2975 # ripping, we have a mixture of sanity checks, verifications, default settigs
2976 # and other crazy stuff that interdepends, but hey, someone has to do it.
2978 # If the user specified a flac file, then switch to special flac mode
2979 if echo "$CDROM" |
grep -i '.flac$' > /dev
/null
2>&1 ; then
2980 if [ ! -f "$CDROM" ]; then
2981 log error
"the defined file for FLAC ripping cannot be found" >&2
2984 vecho warning
"switching to flac CDROMREADERSYNTAX..."
2985 CDROMREADERSYNTAX
=flac
2986 # We have a builtin version of cue2discid...
2987 case "$CUE2DISCID" in
2989 *) NEEDCUE2DISCID
=y
;;
2995 # If the user provided a DISCID, disable eject
2996 if [ -n "$DISCID" ] ||
[ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD
=n
; fi
2998 # Check the available cd rippers in the system, from the ones we know.
2999 if [ "$CDROMREADERSYNTAX" = "" ]; then
3000 for DEFAULT_CDROMREADER
in $DEFAULT_CDROMREADERS; do
3001 if new_checkexec
$DEFAULT_CDROMREADER; then
3002 CDROMREADERSYNTAX
=$DEFAULT_CDROMREADER
3006 if [ "$CDROMREADERSYNTAX" = "" ]; then
3007 log error
"no cdreader found in your PATH"
3008 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
3013 # Decide if we can continue.
3014 if [ "$ONETRACK" = "y" ]; then
3015 # FIXME # remove check as soon as we find out about the other readers
3016 case "$CDROMREADERSYNTAX" in
3020 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
3023 if [ "$BATCHNORM" = "y" ]; then
3024 log warning
"BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3027 if [ "$NOGAP" = "y" ]; then
3028 log warning
"NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3031 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3032 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3033 if [ $# -gt 0 ]; then
3034 log warning
"ONETRACK mode selected, grabbing all tracks..."
3037 while [ $# -gt 0 ]; do
3038 # Range parsing code courtesy of Vincent Ho
3039 RSTART
=$
(echo $1 | cut
-f1 -d-)
3040 REND
=$
(echo $1 | cut
-f2 -d-)
3041 if [ "$RSTART" = "$REND" ]; then
3044 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
3046 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
3051 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3052 # List of experimental actions: retag,transcode
3054 # Determine what actions are to be done from $ACTIONS and set the
3055 # following environment variables for them:
3068 for ACTION
in $
(echo $ACTIONS |
tr , \
)
3071 default
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOCLEAN
=y
;;
3074 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
3075 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3076 encode
) DOENCODE
=y
; DOREAD
=y
;;
3077 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3078 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
3079 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
3080 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
3081 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
3086 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3087 # FIXME # should we abort on error or just inform the user?
3088 log warning
"selected both normalize and replaygain actions"
3091 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
3092 case $SHOWCDDBFIELD in
3093 y
*|Y
*) SHOWCDDBYEAR
="y";;
3094 g
*|G
*) SHOWCDDBGENRE
="y";;
3099 # At this point a CDROM has to be defined, so we check it exists.
3100 if [ X
"$CDROM" != "X" ] ; then
3101 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
3102 if [ "$OSFLAVOUR" = "FBSD" ]; then
3103 if echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then :; else
3104 log error
"CDROMID not in the right format for $CDROMREADERSYNTAX"
3105 log error
"Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
3109 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
3110 log error
"CDROM device cannot be found."
3113 # avoid processing if we are not going to hit the CDROM.
3114 elif [ X
"$DOREAD" = "Xy" ]; then
3115 log error
"CDROM has not been defined or cannot be found"
3119 # USEPIPES pre-tests, before we get into more serious stuff
3120 # Not compatible with:
3121 # - multiple outputs
3123 # - lowdisk algorithm
3125 if [ X
"$USEPIPES" = "Xy" ]; then
3126 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
3127 log error
"Unix pipes not compatible with multiple outputs"
3130 if [ X
"$DONORMALIZE" = "Xy" ]; then
3131 log error
"Unix pipes not compatible with normalizer"
3132 # FIXME # Do we need to exit or shall we just disable the mode?
3135 if [ X
"$BATCHNORM" = "Xy" ]; then
3136 log error
"Unix pipes not compatible with BATCHNORM encoding"
3139 if [ X
"$NOGAP" = "Xy" ]; then
3140 log error
"Unix pipes not compatible with NOGAP encoding"
3143 if [ X
"$DOENCODE" = "Xn" ]; then
3144 vecho warning
"Disabling Unix pipes since we are not encoding!"
3147 if [ X
"$LOWDISK" = "Xy" ]; then
3148 log error
"Unix pipes not compatible with lowdisk algorithm"
3153 # LOWDISK pre-tests, before we get into more problematic stuff
3154 # Not compatible with anything that needs all the files in the hard disc:
3157 if [ X
"$LOWDISK" = "Xy" ]; then
3158 if [ X
"$BATCHNORM" = "Xy" ]; then
3159 log error
"Unix pipes not compatible with BATCHNORM encoding"
3162 if [ X
"$NOGAP" = "Xy" ]; then
3163 log error
"Unix pipes not compatible with NOGAP encoding"
3168 # BATCHNORM pre-tests, before we get into serious problems
3169 # Not compatible with
3170 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3171 vecho warning
"Disabling BATCHNORM since we are not normalizing!"
3175 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
3176 if [ X
"$OUTPUTTYPE" = "X" ]; then
3177 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
3178 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3179 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3180 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
3181 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
3182 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3186 if [ X
"$OUTPUTTYPE" = "X" ]; then
3187 log error
"no encoder found in the PATH"
3188 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
3193 # Decide which CDROM reader we're gonna use
3194 case "$CDROMREADERSYNTAX" in
3196 CDROMREADER
="$CDPARANOIA"
3197 CDROMREADEROPTS
="$CDPARANOIAOPTS"
3200 CDROMREADER
="$CDDA2WAV"
3201 CDROMREADEROPTS
="$CDDA2WAVOPTS"
3204 CDROMREADER
="$DAGRAB"
3205 CDROMREADEROPTS
="$DAGRABOPTS"
3208 CDROMREADER
="$CDDAFS"
3209 CDROMREADEROPTS
="$CDDAFSOPTS"
3213 CDROMREADEROPTS
="$FLACOPTS"
3217 # There's only one normalize...
3218 case "$NORMALIZERSYNTAX" in
3220 NORMALIZER
="$NORMALIZE"
3221 NORMALIZEROPTS
="$NORMALIZEOPTS"
3225 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3226 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
3227 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr \ \|| tr , \ | tr \| \ )"; do
3229 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3230 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3231 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3232 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3233 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3234 m4a
:*) AACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3237 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
3238 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
3239 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
3241 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
3244 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
3245 # for flacs and speexenc for speex and mppenc for mpps and faac for m4as
3247 # Getting ready for multiple output changes
3248 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
3252 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
3253 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
3254 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
3255 OGGOUTPUTCONTAINER
=ogg
3258 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
3259 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
3260 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN
=y
3263 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
3264 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
3265 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
3266 [ "$ONETRACK" = "y" ] && [ "$MAKECUEFILE" = "y" ] && NEEDMETAFLAC
=y
3269 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
3270 # [ "$DOREPLAYGAIN" = "y" ] &&
3273 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
3274 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN
=y
3277 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX
=faac
3280 if [ "$KEEPWAVS" = "y" ]; then
3281 vecho
"Setting the KEEPWAVS option, since the resulting wav files were requested..."
3285 *) log error
"Invalid OUTPUTTYPE defined"
3291 # decide which encoder
3292 case "$MP3ENCODERSYNTAX" in
3294 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
3298 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
3299 MP3ENCODER
="$TOOLAME"
3302 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
3306 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
3307 MP3ENCODER
="$BLADEENC"
3310 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
3314 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
3315 MP3ENCODER
="$XINGMP3ENC"
3318 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
3319 MP3ENCODER
="$MP3ENC"
3322 case "$OGGENCODERSYNTAX" in
3324 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
3325 OGGENCODER
="$VORBIZE"
3328 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
3329 OGGENCODER
="$OGGENC"
3332 case "$FLACENCODERSYNTAX" in
3334 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
3336 # FLAC streams can be encapsulated on a Ogg transport layer
3337 if echo "$FLACENCODEROPTS" |
egrep -- "(^| )--ogg($| )" > /dev
/null
2>&1 ;then
3338 log error
"FLAC on an Ogg container is not yet supported"
3339 log error
"due to problem with adding comments to such files"
3341 FLACOUTPUTCONTAINER
=ogg
3343 FLACOUTPUTCONTAINER
=flac
3347 case "$SPEEXENCODERSYNTAX" in
3349 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
3350 SPEEXENCODER
="$SPEEXENC"
3353 case "$MPPENCODERSYNTAX" in
3355 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
3356 MPPENCODER
="$MPPENC"
3359 case "$AACENCODERSYNTAX" in
3361 AACENCODEROPTS
="${AACENCODEROPTSCLI:-$AACENCOPTS}"
3362 AACENCODER
="$AACENC"
3367 if [ "$ID3TAGV" = "1" ]; then
3369 TAGGEROPTS
="$ID3OPTS"
3372 TAGGEROPTS
="$ID3V2OPTS"
3375 # Specific for NOGAP is the use of lame. Another encoder fails...
3376 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
3377 log warning
"the NOGAP option is specific of lame. Deactivating..."
3382 case "$CUEREADERSYNTAX" in
3384 CUEREADEROPTS
="${CDROM}"
3389 # which information retrieval tool are we using?
3395 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
3396 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
3397 log error
"FLAC on an Ogg container is not yet supported"
3398 log error
"due to problem with adding comments to such files"
3400 OGGOUTPUTCONTAINER
=ogg.ogg
3401 FLACOUTPUTCONTAINER
=flac.ogg
3402 vecho warning
"modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
3405 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
3407 if [ "$ENCNICE" ]; then
3408 ENCNICE
="-n $ENCNICE"
3410 if [ "$READNICE" ]; then
3411 READNICE
="-n $READNICE"
3413 if [ "$DISTMP3NICE" ]; then
3414 DISTMP3NICE
="-n $DISTMP3NICE"
3417 # Don't check for stuff if it's not needed
3418 if [ "$REMOTEHOSTS" ]; then
3421 if [ "$DONORMALIZE" = "y" ]; then
3424 if [ "$EJECTCD" = "y" ]; then
3427 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
3428 if [ "$CDDBMETHOD" = "cddb" ]; then
3430 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
3434 if [ "$MAKECUEFILE" = "y" ]; then
3438 if [ X
"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
3439 case "$CDROMREADERSYNTAX" in
3440 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
3441 ### FIXME ### translate "cue2discid" from python to bash
3442 flac
) NEEDMETAFLAC
=y
; NEEDCUE2DISCID
=y
; CDSPEEDVALUE
="" ;;
3447 ###USEPIPESSUPPORT###
3449 # Rippers with USEPIPE support
3450 # FIXME # Include here all the rippers we can figure out support pipes
3451 PIPERIPPER_cdparanoia
="-"
3452 PIPERIPPER_debug
="-"
3453 PIPERIPPER_flac
="-c "
3455 # Encoders with USEPIPE support
3456 # FIXME # Include here all the encoders we can figure out support pipes
3462 # Figure out if we can use pipes with the ripper/encoder combination
3464 if [ "$USEPIPES" = "y" ]; then
3465 PIPERIPPERSVARCHECK
="PIPERIPPER_${CDROMREADERSYNTAX}"
3468 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
3470 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
3472 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
3474 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
3476 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
3478 decho
"PIPERIPPERSVARCHECK: $( eval echo "\$
$PIPERIPPERSVARCHECK" )"
3479 if [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "$" ] || \
3480 [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "" ] ; then
3481 log error
"no support for pipes with given ripper"
3482 log error
"read the USEPIPES file from the source tarball to get help."
3483 log error
"On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
3486 decho
"PIPEENCODERSVARCHECK: $( eval echo "\$
$PIPEENCODERSVARCHECK" )"
3487 if [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "$" ] || \
3488 [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "" ] ; then
3489 log error
"no support for pipes with given encoder"
3490 log error
"read the USEPIPES file from the source tarball to help"
3491 log error
"on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
3496 # Make sure a buncha things exist
3497 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
3498 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3500 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3501 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3502 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
3503 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
3504 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
3505 ${NEEDMPPGAIN+$MPPGAIN} ${NEEDCUEREADER+$CUEREADER} \
3506 ${NEEDCUE2DISCID+$CUE2DISCID}
3511 # And last but not least, check if we can diff between files. We do not abort,
3512 # since diffing is not critical...
3513 if [ -x $
(which $DIFF) ]; then :; else
3514 vecho warning
"Disabling diff since we cannot find it in the \$PATH..."
3518 ## Now that we have metaflac, check if we need cue2discid
3519 #case $CDROMREADERSYNTAX in
3521 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | egrep "[a-f0-9]{8}")
3522 # if [ "$TRACKINFO" = "" ]; then
3523 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
3528 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
3529 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
3530 HTTPGET
="$HTTPGET $HTTPGETOPTS"
3532 # Here it used to say:
3533 # One thousand lines in, we can start doing stuff with things
3534 # Well, right now we are at line 3306 ;)
3536 # Export needed things so they can be read in this subshell
3537 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
3538 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
3540 if [ "$DOREAD" = "y" ]; then
3541 # User-definable function to set some things. Use it for
3542 # - closing the CD tray with eject -t
3543 # - set the CD speed value with eject -x
3544 vecho
-n "Executing customizable pre-read function... "
3546 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
3551 case "$CDDBMETHOD" in
3553 do_discid
# Get ABCDETEMPDIR created and status file initialized
3560 if [ "$DOCDDB" = "y" ]; then
3561 # start with a sane default:
3562 CDDBLOCALSTATUS
=notfound
3563 if [ $CDDBUSELOCAL = "y" ]; then
3566 if checkstatus cddb-choice
> /dev
/null
; then
3569 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
3570 case "$CDDBMETHOD" in
3584 eval "$($CDDBTOOL parse "$CDDBDATA")"
3587 # Before reading tracks, we set the speed of the device
3589 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3590 case "$CDROMREADERSYNTAX" in
3591 cdparanoia|debug
) ;;
3597 # Define the first and last track, since we might need them later in several places
3598 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
3599 LASTTRACK
=$
( get_last
$TRACKQUEUE )
3601 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
3602 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3603 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
3604 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
3607 if checkstatus onetrack
; then ONETRACK
=y
; fi
3609 if [ "$ONETRACK" = "y" ]; then
3610 # Reuse the CUEFILE in case we created it (now or in a previous run)
3611 if CUEFILE
=$
(checkstatus cuefile
); then
3616 # Create playlist if needed (backgroundable) and start reading in tracks
3620 if [ ! "$ONETRACK" = "y" ]; then
3621 if [ "$DOPLAYLIST" = "y" ]; then
3622 echo Creating playlist...
>&2
3627 # For the lowdisk option, only one program is running at once so the encoder
3628 # can be unsilenced right away.
3629 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3630 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3633 if [ "$ONETRACK" = "y" ]; then
3634 TRACKS
="$FIRSTTRACK"
3635 if [ "$USEPIPES" = "y" ]; then
3636 if checkstatus readencodetrack-
$FIRSTTRACK; then :; else
3637 do_cdread onetrack
$FIRSTTRACK $LASTTRACK | do_encode
$FIRSTTRACK %local0
% > /dev
/null
2>&1
3640 if checkstatus readtrack-
$FIRSTTRACK; then :; else
3641 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
3645 for UTRACKNUM
in $TRACKQUEUE
3647 if [ "$DOREAD" = "y" ]; then
3648 if [ "$USEPIPES" = "y" ]; then
3649 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
3650 # Read, pipe, shut up!
3651 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
3654 if checkstatus readtrack-
$UTRACKNUM; then :; else
3655 do_cdread
$UTRACKNUM
3657 if [ "$?" != "0" ]; then
3658 # CD read failed - don't give the goahead to
3665 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ]; then
3668 # If we are not reading, set the encode output to loud already, so
3669 # that we can see the output of the first track.
3670 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
3671 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3673 echo NEXTTRACK
# Get the encoder machine churning again
3674 if [ "$DOREAD" = "y" ]; then
3675 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3676 until checkstatus encodetrack-
$UTRACKNUM
3678 if checkerrors encodetrack-
$UTRACKNUM; then
3689 # Now that we're done the encoding can be loud again -
3690 # if we're not using SMP.
3691 if [ "$MAXPROCS" = "1" ]; then
3692 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3695 # All tracks read, start encoding.
3696 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3700 # Execute the user-defined post_read funtion before ejecting CD
3703 # We are now finished with the cdrom - it can be safely ejected. Note that
3704 # abcde will not have completed yet.
3705 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
3706 # We check if the disk we are processing is actually the disk inside the
3707 # CD tray. If not, we do not eject the CD, since it might be so that the
3708 # user ejected it manually.
3709 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3710 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3711 # More FreeBSD bits.
3712 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
3713 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3714 # but in this script EJECT is in the envionment and names the program
3717 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3718 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3719 $eject $EJECTOPTS $cd
3720 elif [ X
"$(uname)" = X
"Darwin" ] ; then
3721 disktool
-e ${CDROM#/dev/} 0
3723 $EJECT $EJECTOPTS $CDROM
3730 ## Do we need to pre-process
3731 #if [ x"$PREPROCESS" = "x" ] ; then
3734 # for PRETRACKNUM in $TRACKQUEUE
3737 # if [ "$GOAHEAD" = "NO" ]; then break; fi
3739 # until [ $PREPROCEED ]
3741 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3742 # # all locations are working, wait and try again later
3743 # if [ ! $PREPROCEED ]; then sleep 3; fi
3745 # ( do_preprocess $PRETRACKNUM
3753 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
3755 if [ "$BATCHNORM" = "y" ] ||
[ "$NOGAP" = "y" ]; then
3756 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3757 if [ "$GOAHEAD" = "NO" ]; then break; fi
3758 for LASTTRACK
in $TRACKQUEUE; do :; done
3759 if checkstatus readtrack-
$LASTTRACK; then
3760 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
3761 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
3762 if checkerrors batch-normalize
; then exit 1; fi
3764 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
3765 if [ "$DONORMALIZE" = "y" ]; then
3766 for UTRACKNUM
in $TRACKQUEUE
3768 if checkstatus readtrack-
$UTRACKNUM; then
3769 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3773 if checkstatus encodetrack-
$LASTTRACK; then :; else do_nogap_encode
; fi
3774 if checkerrors nogap-encode
; then exit 1; fi
3779 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3780 if [ "$ONETRACK" = "y" ] ; then
3781 TRACKQUEUE
="$FIRSTTRACK"
3782 TRACKS
="$FIRSTTRACK"
3785 # Do the encoding, including parallelization of remote encoding
3786 # Figure out where each track is going to be encoded
3787 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
3788 if [ "$MAXPROCS" != "0" ]; then
3789 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
3791 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
3795 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
3796 for UTRACKNUM
in $TRACKQUEUE
3799 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3800 if [ "$GOAHEAD" = "NO" ]; then break; fi
3801 # find out where this track is to be encoded
3802 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3803 # Make sure we have a place to encode this, if not, exit stage right
3804 if [ -z "$ENCODELOCATIONS" ]; then
3810 for LOCATION
in $ENCODELOCATIONS
3812 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3813 # check first if a track has ever been assigned to this location
3814 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
3815 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3816 if checkerrors encodetrack-
$PREVIOUSTRACK; then
3817 for TEMPLOCATION
in $ENCODELOCATIONS
3819 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3820 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
3823 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
3828 # We're still here, this location must have been previously assigned,
3829 # and last completed without error - check if it's done with the
3830 # previous track yet
3831 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
3833 # all locations are working, wait and try again later
3834 if [ ! $PROCEED ]; then sleep 3; fi
3836 # Record the location we're about to encode the next track at
3837 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3839 # Don't proceed with the rest of the loop if we can't encode
3840 if [ "$ABORT" ]; then continue; fi
3841 ## FIXME ## Add here
3842 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
3843 # Set TRACKNUM, TRACKNAME
3844 if [ -e "$CDDBDATA" ]; then
3845 if [ "$ONETRACK" = "y" ]; then
3847 TRACKNUM
="$FIRSTTRACK"
3851 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
3852 getcddbinfo TRACKNAME
3856 # You can't encode a file which needs to be normalized before finishing
3857 # You can't tag a file before it's finished encoding -
3858 # thus all of this is backgrounded together
3860 if [ "$DONORMALIZE" = "y" ]; then
3861 if checkstatus readtrack-
$UTRACKNUM; then
3862 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3865 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3866 if checkstatus readtrack-
$UTRACKNUM; then
3867 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3868 if [ "$DONORMALIZE" = "y" ]; then
3869 if checkstatus normalizetrack-
$UTRACKNUM; then
3870 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3873 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
3877 if [ "$DOTAG" = "y" ]; then
3878 if checkstatus encodetrack-
$UTRACKNUM; then
3879 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
3881 # Lets tag the cue file
3882 if checkstatus cleancuefile
>/dev
/null
; then :; else
3883 if checkstatus cuefile
>/dev
/null
; then
3888 if [ "$DOMOVE" = "y" ]; then
3889 if checkstatus tagtrack-
$UTRACKNUM; then
3890 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
3897 # Go through it again and make sure there's no distmp3 stragglers, otherwise
3898 # we'll delete the files they're working on
3899 # Do NOT play ball if there is no ball to play (so ABORT if needed)
3900 ## FIXME ## Check also for files which are encoded using PIPEs.
3901 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
3906 for LOCATION
in $ENCODELOCATIONS
3908 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3909 # "How can he give us a status update, if he's DEAD?"
3910 if checkstatus encodetrack-
$CHECKTRACK; then
3913 # Nothing to see here please go quietly back to your homes
3914 if [ -z "$CHECKTRACK" ]; then continue; fi
3915 # You're still here? Maybe there is something...
3916 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
3919 if [ ! $PROCEED ]; then sleep 5; fi
3922 # If the above didn't catch the stragglers, this will
3924 if [ "$DOREPLAYGAIN" = "y" ]; then
3928 # Check to see if run_command logged any errors
3929 if [ -f "$ABCDETEMPDIR/errors" ]; then
3930 log error
"The following commands failed to run:"
3931 cat "$ABCDETEMPDIR/errors"
3935 if [ "$KEEPWAVS" = "y" ];then
3939 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
3940 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
3941 ENCODED_FORMATS
=$
(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f2 |
sort -u |
tr '\n' '|')
3942 MOVED_FORMATS
=$
(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f3 |
sort -u |
tr '\n' '|')
3943 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
3944 log warning
"The encoded formats does not match with the moved ones"
3945 log warning
"Formats encoded: $( echo $ENCODED_FORMATS | tr "|
" " " )"
3946 log warning
"Formats moved: $( echo $MOVED_FORMATS | tr "|
" " " )"
3947 log warning
"Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
3951 if [ "$DOCLEAN" = "y" ]; then
3952 # Wipe all the evidence
3953 # Gimme gimme gimme some more time!
3955 rm -rf "$ABCDETEMPDIR"
3958 echo "Finished. Not cleaning $ABCDETEMPDIR."