2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
5 # Copyright (c) 2012 Steve McIntyre <93sam@@debian.org>
6 # This code is hereby licensed for public consumption under either the
7 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
9 # You should have received a copy of the GNU General Public License along
10 # with this program; if not, write to the Free Software Foundation, Inc.,
11 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13 # Copyright for this work is to expire January 1, 2010, after which it
14 # shall be public domain.
16 VERSION='2.6.1-UNRELEASED'
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"
30 echo " Specify a configuration file (overrides system and user config files)"
32 echo " Specify discid to resume from (only needed if you no longer have the cd)"
34 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
35 echo "-D Debugging mode (equivalent to sh -x abcde)"
36 echo "-e Erase encoded track information from status file"
37 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
38 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
39 echo "-h This help information"
40 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
41 echo "-j <#> Number of encoder processes to run at once (localhost)"
42 echo "-k Keep the wav tracks for later use"
43 echo "-l Use low disk space algorithm"
44 echo "-L Use local CDDB storage directory"
45 echo "-m Modify playlist to include CRLF endings, to comply with some players"
46 #echo " WARNING: Deprecated. Use \"cue\" action"
47 #echo "-M Create a CUE file"
48 echo "-n No lookup. Don't query CDDB, just create and use template"
49 echo "-N Noninteractive. Never prompt for anything"
50 echo "-o <type1[,type2]...>"
51 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,wv,ape). 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"
57 echo " Show fields from the CDDB info (year,genre)"
58 echo "-S <#> Set the CD speed"
59 echo "-t <#> Start the track numbering at a given number"
60 echo "-T <#> Same as -t but modifies tag numbering"
61 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
62 echo "-v Show version number and exit"
63 echo "-V Be a bit more verbose about what is happening behind the scenes"
64 echo "-x Eject CD after all tracks are read"
66 echo " Add a comment to the CD tracks"
67 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
68 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
70 echo "Tracks is a space-delimited list of tracks to grab."
71 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
73 #echo "Double hyphens are used to concatenate tracks"
78 echo "$@" >> "$ABCDETEMPDIR/status"
81 # log [level] [message]
83 # log outputs the right message in a common format
89 error) echo "[ERROR] abcde: $@" >&2 ;;
90 warning) echo "[WARNING] $@" >&2 ;;
91 info) echo "[INFO] $@" ;;
95 # Functions to replace the need of seq, which is too distribution dependent.
99 while [ $i -ne `expr $2 + 1` ]
109 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
110 while [ $i -ne `expr $2 + 1` ]
117 log error "syntax error while processing track numbers ($i)"
122 # Functions to replace the need of awk {print $1} and {print $NF}
125 if [ X"$1" = "X" ]; then
126 for first in `cat`; do
137 if [ X"$1" = "X" ]; then
138 for stdin in `cat`; do
142 for last in $@ ; do :; done
147 # checkstatus [blurb]
148 # Returns "0" if the blurb was found, returns 1 if it wasn't
149 # Puts the blurb content, if available, on stdout.
150 # Otherwise, returns "".
153 # Take the last line in the status file if there's multiple matches
155 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
157 if [ -z "$BLURB" ]; then
162 # See if there's a = in it
163 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
164 echo "$(echo $BLURB | cut -f2- -d=)"
170 # checkwarnings [blurb]
171 # Returns "0" if the blurb was found (meaning there was an warning),
172 # returns 1 if it wasn't (yes this is a little backwards).
173 # Does not print the blurb on stdout.
174 # Otherwise, returns "".
177 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
180 # Take the last line in the status file if there's multiple matches
182 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
184 if [ -z "$BLURB" ]; then
185 # negative, we did not have a negative...
188 # affirmative, we had a negative...
193 # checkerrors [blurb]
194 # Returns "0" if the blurb was found (meaning there was an error),
195 # returns 1 if it wasn't (yes this is a little backwards).
196 # Does not print the blurb on stdout.
197 # Otherwise, returns "".
200 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
203 # Take the last line in the status file if there's multiple matches
205 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
207 if [ -z "$BLURB" ]; then
208 # negative, we did not have a negative...
211 # affirmative, we had a negative...
217 # Finds the right pager in the system to display a file
221 # Use the debian sensible-pager wrapper to pick the pager
222 # user has requested via their $PAGER environment variable
223 if [ -x "/usr/bin/sensible-pager" ]; then
224 /usr/bin/sensible-pager "$PAGEFILE"
225 elif [ -x "$PAGER" ]; then
226 # That failed, try to load the preferred editor, starting
227 # with their PAGER variable
229 # If that fails, check for less
230 elif [ -x /usr/bin/less ]; then
231 /usr/bin/less -f "$PAGEFILE"
232 # more should be on all UNIX systems
233 elif [ -x /bin/more ]; then
234 /bin/more "$PAGEFILE"
236 # No bananas, just cat the thing
241 # run_command [blurb] [command...]
242 # Runs a command, silently if necessary, and updates the status file
248 # See if this is supposed to be silent
249 if [ "$(checkstatus encode-output)" = "loud" ]; then
253 # Special case for SMP, since
254 # encoder output is never displayed, don't mute echos
255 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
264 normalize|normalize-audio)
265 if [ "$RETURN" = "2" ]; then
266 # File was already normalized.
271 if [ "$RETURN" != "0" ]; then
272 # Put an error in the errors file. For various reasons we
273 # can't capture a copy of the program's output but we can
274 # log what we attempted to execute and the error code
275 # returned by the program.
276 if [ "$BLURB" ]; then
279 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
280 return $RETURN # Do not pass go, do not update the status file
282 if [ "$BLURB" ]; then
283 echo $BLURB >> "$ABCDETEMPDIR/status"
287 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
288 # distributed under the terms of the GNU GPL v2 or later, at your option
290 # Function to determine if a word contains a slash.
299 # Function to give the relative path from one file to another.
300 # Usage: relpath fromfile tofile
301 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
302 # (the result would be Album/Song.mp3)
303 # Output is relative path to $2 from $1 on stdout
305 # This code has the following restrictions:
306 # Multiple ////s are not collapsed into single /s, with strange effects.
307 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
308 # If FR is a directory it must have a trailing /
316 /*) ;; # No processing is needed for absolute paths
318 # Loop through common prefixes, ignoring them.
319 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
321 FR="$(echo "$FR" | cut -d/ -f2-)"
322 TO="$(echo "$TO" | cut -d/ -f2-)"
324 # Loop through directory portions left in FR, adding appropriate ../s.
327 FR="$(echo "$FR" | cut -d/ -f2-)"
338 if [ ! "$@" = "" ]; then
339 # Cut off any command-line option we added in
340 X=$(echo $@ | cut -d' ' -f2)
341 if [ "$(which $X)" = "" ]; then
343 elif [ ! -x $(which $X) ]; then
352 if [ ! "$@" = "" ]; then
353 # Cut off any command-line option we added in
354 X=$(echo $@ | cut -d' ' -f2)
355 # Test for built-in abcde.function
356 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
357 if [ "$(which $X)" = "" ]; then
358 log error "$X is not in your path." >&2
359 log info "Define the full path to the executable if it exists on your system." >&2
360 if [ -e /etc/debian_release ] ; then
362 oggenc) MISSING_PACKAGE=vorbis-tools ;;
363 lame|flac) MISSING_PACKAGE=$X ;;
365 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
368 elif [ ! -x "$(which $X)" ]; then
369 log error "$X is not executable." >&2
375 # diffentries <filename> <max_value> <entry1>,<entry2>
376 # max_value: the range of entries goes from 1 to <max_value>
381 local CDDBDIFFCHOICES=$1
383 local CDDBDIFFCHOICE="$@"
384 if [ ! X"$DIFF" = "X" ]; then
385 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
386 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
387 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
388 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
389 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
390 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
392 # We parse the 2 choices to diff, store them in temporary files and diff them.
393 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
394 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
396 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
397 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
398 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
399 page "$ABCDETEMPDIR/$FILENAME.diff"
401 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
405 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
410 # Finds an specific field from cddbinfo
415 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
418 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
421 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
427 # Get the track number we are going to use for different actions
430 if [ -n "$STARTTRACKNUMBER" ] ; then
431 # Get the trackpadding from the current track, also trim whitespace for MacOSX
432 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
433 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
435 TRACKNUM=${UTRACKNUM}
441 # Calculate cddb disc ids without requiring specialized helper programs.
442 # largely copied from cd-discid and musicbrainz examples. some of the steps
443 # don't make sense, but they're necessary to match the ids generated by other
446 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
447 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
448 # 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
449 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
450 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
451 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
453 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
456 if [ X"$LEADOUT" = "X" ]; then
457 log warning "Error trying to calculate disc ids without lead-out information."
461 # default to a two second lead-in
463 LEADIN=${LEADIN:=150}
465 # number of cdframes per second
468 # reset cddb checksum for cddb disc-id calululation
472 for OFFSET in $(echo $OFFSETS)
474 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
476 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
477 while [ $OFFSETTIME -gt 0 ]; do
478 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
479 OFFSETTIME=$(($OFFSETTIME / 10))
484 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
486 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
487 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
489 case "$CDDBMETHOD" in
491 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
494 # FIXME: don't assume the first track is 1
495 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
496 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
500 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
505 if checkstatus replaygain; then :; else
506 run_command "" echo "Adding replaygain information..."
507 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
511 OUTPUT=$OGGOUTPUTCONTAINER
514 OUTPUT=$OPUSOUTPUTCONTAINER
517 OUTPUT=$FLACOUTPUTCONTAINER
525 for UTRACKNUM in $TRACKQUEUE
527 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
528 getcddbinfo TRACKNAME
530 TRACKFILE="$(mungefilename "$TRACKNAME")"
531 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
532 ALBUMFILE="$(mungefilename "$DALBUM")"
533 GENRE="$(mungegenre "$GENRE")"
534 YEAR=${CDYEAR:-$CDYEAR}
536 if [ "$ONETRACK" = "y" ]; then
537 if [ "$VARIOUSARTISTS" = "y" ]; then
538 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
540 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
543 if [ "$VARIOUSARTISTS" = "y" ]; then
544 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
546 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
549 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
550 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
554 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
555 #run_command replaygain-flac true
558 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
561 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
564 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
567 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
572 if checkerrors "replaygain-.{3,6}"; then :; else
573 run_command replaygain true
578 # This code splits the a Various Artist track name from one of the following
581 # forward: Artist / Track
582 # forward-dash: Artist - Track
583 # reverse: Track / Artist
584 # reverse-dash: Track - Artist
585 # colon: Artist: Track
586 # trailing-paren: Artist (Track)
589 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
592 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
593 case "$VARIOUSARTISTSTYLE" in
595 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
596 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
597 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
600 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
601 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
602 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
605 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
606 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
607 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
610 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
611 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
612 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
615 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
616 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
617 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
620 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
621 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
622 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
625 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
626 TRACKARTIST="Various"
628 TRACKARTIST="$DARTIST"
633 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
637 "classic rock") id=1 ;;
655 "industrial") id=19 ;;
656 "alternative") id=20 ;;
658 "death metal") id=22 ;;
660 "soundtrack") id=24 ;;
661 "euro-techno") id=25 ;;
665 "jazz+funk") id=29 ;;
668 "classical") id=32 ;;
669 "instrumental") id=33 ;;
673 "sound clip") id=37 ;;
676 "alt. rock") id=40 ;;
681 "meditative") id=45 ;;
682 "instrum. pop") id=46 ;;
683 "instrum. rock") id=47 ;;
687 "techno-indust.") id=51 ;;
688 "electronic") id=52 ;;
690 "eurodance") id=54 ;;
692 "southern rock") id=56 ;;
697 "christian rap") id=61 ;;
698 "pop/funk"|"pop / funk") id=62 ;;
700 "native american") id=64 ;;
703 "psychadelic") id=67 ;;
705 "showtunes") id=69 ;;
709 "acid punk") id=73 ;;
710 "acid jazz") id=74 ;;
714 "rock & roll") id=78 ;;
715 "hard rock") id=79 ;;
717 "folk/rock") id=81 ;;
718 "national folk") id=82 ;;
725 "bluegrass") id=89 ;;
726 "avantgarde") id=90 ;;
727 "gothic rock") id=91 ;;
728 "progress. rock") id=92 ;;
729 "psychadel. rock") id=93 ;;
730 "symphonic rock") id=94 ;;
731 "slow rock") id=95 ;;
734 "easy listening") id=98 ;;
740 "chamber music") id=104 ;;
742 "symphony") id=106 ;;
743 "booty bass") id=107 ;;
745 "porn groove") id=109 ;;
747 "slow jam") id=111 ;;
751 "folklore") id=115 ;;
753 "power ballad") id=117 ;;
754 "rhythmic soul") id=118 ;;
755 "freestyle") id=119 ;;
757 "punk rock") id=121 ;;
758 "drum solo") id=122 ;;
759 "a capella") id=123 ;;
760 "euro-house") id=124 ;;
761 "dance hall") id=125 ;;
763 "drum & bass") id=127 ;;
764 "club-house") id=128 ;;
765 "hardcore") id=129 ;;
769 "negerpunk") id=133 ;;
770 "polsk punk") id=134 ;;
772 "christian gangsta rap") id=136 ;;
773 "heavy metal") id=137 ;;
774 "black metal") id=138 ;;
775 "crossover") id=139 ;;
776 "contemporary christian")id=140 ;;
777 "christian rock") id=141 ;;
778 "merengue") id=142 ;;
780 "thrash metal") id=144 ;;
783 "synthpop") id=147 ;;
784 "rock/pop"|"rock / pop") id=148 ;;
791 # do_tag [tracknumber]
792 # id3 tags a filename
794 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
795 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
798 COMMENTOUTPUT="$(eval echo ${COMMENT})"
799 if [ -z "$COMMENTOUTPUT" ]; then
800 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
802 if [ "$CDDBMETHOD" = "cddb" ]; then
803 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
805 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
806 # If we want to start the tracks with a given number, we need to modify the
807 # TRACKNUM value before evaluation
808 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
811 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
815 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
816 GENREID=$(do_getgenreid "${CDGENRE}")
817 # Set TPE2 in case we have a Various Artists rip.
819 if [ "$VARIOUSARTISTS" = "y" ]; then
826 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
827 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
828 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
829 -y "$CDYEAR" -g "$GENREID" \
830 -T "${TRACKNUM:-$1}" \
831 "$ABCDETEMPDIR/track$1.$OUTPUT"
834 # FIXME # track numbers in mp3 come with 1/10, so we cannot
835 # happily substitute them with $TRACKNUM
836 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
837 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
838 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
839 -y "$CDYEAR" -g "$GENREID" \
840 -T "${TRACKNUM:-$1}/$TRACKS" \
841 ${TPE2:+--TPE2 "$TPE2"} \
842 "$ABCDETEMPDIR/track$1.$OUTPUT"
845 # FIXME # track numbers in mp3 come with 1/10, so we cannot
846 # happily substitute them with $TRACKNUM
848 eyed3_06) addopts=( \
849 ${ENCODING:+--set-encoding="$ENCODING"} \
850 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
851 # We set 'recording-date' so the date tag will show
852 # in Audacious, vlc and friends... Andrew.
853 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
854 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
857 ${ENCODING:+--encoding="$ENCODING"} \
858 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
859 # We set 'recording-date' so the date tag will show
860 # in Audacious, vlc and friends... Andrew.
861 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
862 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
865 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
867 -a "$TRACKARTIST" -t "$TRACKNAME" \
868 -G "$GENREID" -n "${TRACKNUM:-$1}" \
869 ${TRACKNUM:+-N "$TRACKS"} \
871 "$ABCDETEMPDIR/track$1.$OUTPUT"
874 log error "Internal error: ID3SYNTAX has an illegal value"
880 case "$OGGENCODERSYNTAX" in
882 # vorbiscomment can't do in-place modification, mv the file first
883 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
884 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
888 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
890 echo ARTIST="$TRACKARTIST"
892 echo TITLE="$TRACKNAME"
893 if [ -n "$CDYEAR" ]; then
896 if [ -n "$CDGENRE" ]; then
897 echo GENRE="$CDGENRE"
899 echo TRACKNUMBER=${TRACKNUM:-$1}
900 if [ -n "$DISCNUMBER" ]; then
901 echo DISCNUMBER="$DISCNUMBER"
903 echo CDDB=$CDDBDISCID
904 if [ "$(eval echo ${COMMENT})" != "" ]; then
905 case "$COMMENTOUTPUT" in
906 *=*) echo "$COMMENTOUTPUT";;
907 *) echo COMMENT="$COMMENTOUTPUT";;
910 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
911 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
912 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
913 # Doublecheck that the commented file was created
914 # successfully before wiping the original
915 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
916 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
918 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
924 run_command tagtrack-$OUTPUT-$1 true
929 echo ARTIST="$TRACKARTIST"
931 echo TITLE="$TRACKNAME"
932 if [ -n "$CDYEAR" ]; then
935 if [ -n "$CDGENRE" ]; then
936 echo GENRE="$CDGENRE"
938 echo TRACKNUMBER="${TRACKNUM:-$1}"
939 if [ -n "$DISCNUMBER" ]; then
940 echo DISCNUMBER="$DISCNUMBER"
942 echo CDDB="$CDDBDISCID"
943 if [ "$(eval echo ${COMMENT})" != "" ]; then
944 case "$COMMENTOUTPUT" in
945 *=*) echo "$COMMENTOUTPUT";;
946 *) echo COMMENT="$COMMENTOUTPUT";;
949 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
952 run_command tagtrack-$OUTPUT-$1 true
955 run_command tagtrack-$OUTPUT-$1 true
958 run_command tagtrack-$OUTPUT-$1 true
960 ape) # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
961 # Console port (mac) used for encoding does not have the ability to tag. Andrew.
962 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
963 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
964 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
967 run_command tagtrack-$OUTPUT-$1 true
970 case "$AACENCODERSYNTAX" in
971 fdkaac) # We will use inline tagging...
972 run_command tagtrack-$OUTPUT-$1 true
974 neroAacEnc) # Tag post encode with neroAacTag...
975 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
976 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
977 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
980 run_command tagtrack-$OUTPUT-$1 true
985 run_command tagtrack-$OUTPUT-$1 true
989 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
990 run_command tagtrack-$1 true
997 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1000 # The commands here don't go through run_command because they're never
1001 # supposed to be silenced
1002 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1003 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1007 case "$MP3ENCODERSYNTAX" in
1012 for UTRACKNUM in $TRACKQUEUE
1014 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1016 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1018 if [ "$RETURN" != "0" ]; then
1019 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1021 for UTRACKNUM in $TRACKQUEUE
1023 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1024 #run_command encodetrack-$UTRACKNUM true
1033 if checkerrors "nogap-encode"; then :; else
1034 if [ ! "$KEEPWAVS" = "y" ] ; then
1035 if [ ! "$KEEPWAVS" = "move" ] ; then
1040 # Other encoders fall through to normal encoding as the tracks have not
1041 # been entered in the status file.
1044 # do_encode [tracknumber] [hostname]
1045 # If no hostname is specified, encode locally
1047 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1050 if [ "$USEPIPES" = "y" ]; then
1053 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1056 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1059 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1062 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1065 TEMPARG="PIPE_$SPEEXENCODER"
1068 TEMPARG="PIPE_$MPCENCODER"
1071 TEMPARG="PIPE_$WVCENCODERSYNTAX"
1074 TEMPARG="PIPE_$APENCODERSYNTAX"
1077 TEMPARG="PIPE_$AACENCODERSYNTAX"
1080 TEMPARG="PIPE_$AACENCODERSYNTAX"
1083 IN="$( eval echo "\$$TEMPARG" )"
1085 IN="$ABCDETEMPDIR/track$1.wav"
1088 case "$MP3ENCODERSYNTAX" in
1089 # FIXME # check if mp3enc needs -if for pipes
1090 # FIXME # I have not been able to find a working mp3enc binary
1104 # We need IN to proceed, if we are not using pipes.
1105 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1106 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1108 case "$TMPOUTPUT" in
1110 OUTPUT=$OGGOUTPUTCONTAINER
1113 OUTPUT=$OPUSOUTPUTCONTAINER
1116 OUTPUT=$FLACOUTPUTCONTAINER
1122 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1123 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1126 if [ X"$USEPIPES" = "Xy" ]; then
1128 # We need a way to store the creation of the files when using PIPES
1129 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1130 # When pipping it does not make sense to have a higher nice for
1131 # reading than for encoding, since it will be hold by the
1132 # encoding process. Setting an effective nice, to calm down a
1133 # bit the reading process.
1134 EFFECTIVE_NICE=$READNICE
1136 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1137 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1138 EFFECTIVE_NICE=$ENCNICE
1144 case "$MP3ENCODERSYNTAX" in
1145 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1146 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1147 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1148 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1149 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1153 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1160 case "$OGGENCODERSYNTAX" in
1161 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1162 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1166 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1173 case "$OPUSENCODERSYNTAX" in
1175 # Tag the file at encode time, as it can't be done after encoding.
1176 if [ "$DOTAG" = "y" ]; then
1177 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
1178 --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1180 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1186 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1193 case "$FLACENCODERSYNTAX" in
1194 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1199 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1200 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1205 if [ "$(eval echo ${COMMENT})" != "" ]; then
1208 *) COMMENT="COMMENT=$COMMENT" ;;
1211 # Tag the file at encode time, as it can't be done after encoding.
1212 if [ "$DOTAG" = "y" ]; then
1213 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1215 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1219 # Tag the file inline at encode time.
1220 if [ "$DOTAG" = "y" ]; then
1221 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
1222 --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1224 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1228 if [ "$DOTAG" = "y" ]; then
1229 # wavpack tagging is done inline using Apev2 tags:
1230 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" -w Title="$TRACKNAME" \
1231 -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" -w Comment="$COMMENT" "$IN" -o "$OUT"
1233 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1237 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1240 # aac container is only used to catch faac encoded files where faac
1241 # is compiled without mp4 support (with libmp4v2). Andrew.
1242 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1245 case "$AACENCODERSYNTAX" in
1247 if [ "$DOTAG" = "y" ]; then
1248 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" \
1249 --album "$DALBUM" --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" \
1250 --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1252 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1256 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1259 if [ "$DOTAG" = "y" ]; then
1260 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1261 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1263 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1269 # In case of wav output we need nothing. Just keep the wavs.
1270 # But we need the following to allow full logging and subsequent
1271 # successful cleaning of $ABCDETEMPDIR. Andrew.
1272 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1277 # Only remove .wav if the encoding succeeded
1278 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1279 run_command encodetrack-$1 true
1280 if [ ! "$KEEPWAVS" = "y" ] ; then
1281 if [ ! "$KEEPWAVS" = "move" ] ; then
1287 run_command "" echo "HEH! The file we were about to encode disappeared:"
1288 run_command "" echo ">> $IN"
1289 run_command encodetrack-$1 false
1293 # do_preprocess [tracknumber]
1295 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1298 # IN="$ABCDETEMPDIR/track$1.wav"
1299 # # We need IN to proceed.
1300 # if [ -s "$IN" ] ; then
1301 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1303 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1304 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1305 # case "$POSTPROCESSFORMAT" in
1307 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1309 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1311 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1313 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1315 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1318 # # Only remove .wav if the encoding succeeded
1319 # if checkerrors "preprocess-(.{3,4})-$1"; then
1320 # run_command preprocess-$1 false
1322 # run_command preprocess-$1 true
1325 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1326 # echo "HEH! The file we were about to pre-process disappeared:"
1329 # run_command preprocess-$1 false
1334 # do_postprocess [tracknumber]
1336 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1339 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1341 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1342 # # We need IN to proceed.
1343 # if [ -s "$IN" ] ; then
1344 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1345 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1346 # case "$POSTPROCESSFORMAT" in
1348 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1350 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1352 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1354 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1356 # # Only remove .wav if the encoding succeeded
1357 # if checkerrors "postprocess-(.{3,4})-$1"; then
1358 # run_command postprocess-$1 false
1360 # run_command postprocess-$1 true
1363 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1364 # echo "HEH! The file we were about to post-process disappeared:"
1367 # run_command postprocess-$1 false
1382 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1386 # The commands here don't go through run_command because they're never supposed to be silenced
1387 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1392 for UTRACKNUM in $TRACKQUEUE
1394 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1396 # FIXME # Hard-coded batch option!
1397 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1399 if [ "$RETURN" != "0" ]; then
1400 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1402 for UTRACKNUM in $TRACKQUEUE
1404 echo normalizetrack-$UTRACKNUM >> status
1410 # do_batch_normalize
1412 # NORMALIZER, NORMALIZEROPTS
1413 do_batch_normalize ()
1415 # The commands here don't go through run_command because they're never supposed to be silenced
1416 echo "Batch normalizing tracks: $TRACKQUEUE"
1421 for UTRACKNUM in $TRACKQUEUE
1423 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1425 # XXX: Hard-coded batch option!
1426 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1428 if [ "$RETURN" != "0" ]; then
1429 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1431 for UTRACKNUM in $TRACKQUEUE
1433 echo normalizetrack-$UTRACKNUM >> status
1439 # do_normalize [tracknumber]
1441 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1444 IN="$ABCDETEMPDIR/track$1.wav"
1445 if [ -e "$IN" ] ; then
1446 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1447 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1449 if [ "$(checkstatus encode-output)" = "loud" ]; then
1450 echo "HEH! The file we were about to normalize disappeared:"
1453 run_command normalizetrack-$1 false "File $IN was not found"
1457 # do_move [tracknumber]
1458 # Deduces the outfile from environment variables
1459 # Creates directory if necessary
1461 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1464 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1466 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1467 # defined the OUTPUTFILE:
1470 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1471 # Munge filenames as follows:
1476 # Eat control characters
1477 ALBUMFILE="$(mungefilename "$DALBUM")"
1478 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1479 TRACKFILE="$(mungefilename "$TRACKNAME")"
1480 GENRE="$(mungegenre "$GENRE")"
1481 YEAR=${CDYEAR:-$CDYEAR}
1482 # If we want to start the tracks with a given number, we need to modify
1483 # the TRACKNUM value before evaluation
1485 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1486 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1487 if [ "$ONETRACK" = "y" ]; then
1488 if [ "$VARIOUSARTISTS" = "y" ]; then
1489 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1491 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1494 if [ "$VARIOUSARTISTS" = "y" ]; then
1495 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1497 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1500 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1501 # Once we know the specific output was successful, we can change
1502 # the OUTPUT to the value containing the container
1505 OUTPUT=$OGGOUTPUTCONTAINER
1508 OUTPUT=$OPUSOUTPUTCONTAINER
1511 OUTPUT=$FLACOUTPUTCONTAINER
1517 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1518 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1521 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1522 # FIXME # introduce warnings?
1525 # mkdir -p shouldn't return an error if the directory already exists
1526 mkdir -p "$OUTPUTFILEDIR"
1527 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1528 if checkstatus movetrack-output-$OUTPUT; then :; else
1529 run_command movetrack-output-$OUTPUT true
1534 # mkdir -p shouldn't return an error if the directory already exists
1535 mkdir -p "$OUTPUTFILEDIR"
1536 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1537 if checkstatus movetrack-output-$OUTPUT; then :; else
1538 run_command movetrack-output-$OUTPUT true
1542 # Lets move the cue file
1543 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1544 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1545 if checkstatus movecue-$OUTPUT; then :; else
1546 # Silence the Copying output since it overlaps with encoding processes...
1547 #run_command '' vecho "Copying cue file to its destination directory..."
1548 if checkstatus onetrack >/dev/null ; then
1551 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1552 # We dont have the dir, since it was not created before.
1555 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1558 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1559 # http://brianvictor.tripod.com/mp3cue.htm#details
1560 [a-z0-9][a-z0-9][a-z0-9])
1561 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1564 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1568 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1570 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1579 # Create the playlist if wanted
1581 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1582 # VARIOUSARTISTS, OUTPUTDIR
1585 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1589 OUTPUT=$OGGOUTPUTCONTAINER
1592 OUTPUT=$OPUSOUTPUTCONTAINER
1595 OUTPUT=$FLACOUTPUTCONTAINER
1601 # Create a playlist file for the playlist data to go into.
1602 # We used to wipe it out if it existed. Now we request permission if interactive.
1603 for LASTTRACK in $TRACKQUEUE; do :; done
1604 ALBUMFILE="$(mungefilename "$DALBUM")"
1605 ARTISTFILE="$(mungefilename "$DARTIST")"
1606 GENRE="$(mungegenre "$GENRE")"
1607 YEAR=${CDYEAR:-$CDYEAR}
1608 if [ "$VARIOUSARTISTS" = "y" ] ; then
1609 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1611 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1613 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1614 mkdir -p "$FINALPLAYLISTDIR"
1615 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1616 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1617 if [ "$INTERACTIVE" = "y" ]; then
1618 while [ "$DONE" != "y" ]; do
1620 case $ERASEPLAYLIST in
1621 e|E|a|A|k|K) DONE=y ;;
1622 "") ERASEPLAYLIST=e ; DONE=y ;;
1630 # Once we erase the playlist, we use append to create the new one.
1631 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1633 # The playlist does not exist, so we can safelly use append to create the new list
1636 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1637 touch "$OUTPUTDIR/$PLAYLISTFILE"
1638 for UTRACKNUM in $TRACKQUEUE
1640 # Shares some code with do_move since the filenames have to match
1641 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1642 getcddbinfo TRACKNAME
1644 TRACKFILE="$(mungefilename "$TRACKNAME")"
1645 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1646 ALBUMFILE="$(mungefilename "$DALBUM")"
1647 # If we want to start the tracks with a given number, we need to modify the
1648 # TRACKNUM value before evaluation
1650 if [ "$VARIOUSARTISTS" = "y" ]; then
1651 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1653 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1655 if [ "$VARIOUSARTISTS" = "y" ]; then
1656 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1657 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1659 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1662 if [ "$PLAYLISTDATAPREFIX" ]; then
1663 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1665 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1670 ## this will convert the playlist to have CRLF line-endings, if specified
1671 ## (some hardware players insist on CRLF endings)
1672 if [ "$DOSPLAYLIST" = "y" ]; then
1673 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1674 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1675 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1677 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1682 # This function reads a cuefile on stdin and writes an extended
1683 # cddb query on stdout. Any PREGAP for track 1 is properly
1684 # handled, although cue files embedded in FLAC files do not
1685 # appear to properly store the PREGAP setting. :(
1686 abcde.cue2discid () {
1691 while [ $val -gt 0 ] ; do
1692 ret=$(( $ret + ( $val % 10) ))
1693 val=$(( $val / 10 ))
1703 local first second third
1704 first=$(expr ${1} + 0 )
1705 second=$(expr ${2} + 0 )
1706 third=$(expr ${3} + 0 )
1708 echo $(( ((($first * 60) + $second) * 75) + $third ))
1718 while read line ; do
1721 TRACK) i=$(( i + 1 ))
1723 INDEX) if [ "$2" -eq 1 ] ; then
1725 START=$(( $LBA + $PREGAP + $OFFSET ))
1727 X=$(cddb_sum $(( $START / 75 )) )
1731 PREGAP) PREGAP=$(msf2lba $2)
1735 LEADOUT=$(( $4 / 588 ))
1738 LEADIN=$(( $3 / 588 ))
1747 LEADOUT=$(( $LEADOUT + $LEADIN ))
1749 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1750 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1751 printf "%08x %i" $DISCID $TRACKS
1754 while [ $j -le $TRACKS ] ; do
1755 eval echo -n "\" \$TRACK$j\""
1758 echo " $(( $LEADOUT / 75 ))"
1762 # abcde.mkcue [--wholedisk]
1763 # This creates a cuefile directly from the extended discid information
1764 # The --wholedisk option controls whether we're ripping data from the
1765 # start of track one or from the start of the disk (usually, but not
1766 # always the same thing!)
1768 # Track one leadin/pregap (if any) handeling:
1769 # --wholedisk specified:
1772 # INDEX 01 <pregap value>
1773 # Remaining track index values unchanged from disc TOC
1775 # --wholedisk not specified
1777 # PREGAP <pregap value>
1779 # Remaining track index values offset by <pregap value>
1786 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1789 local MODE DISCID TRACKS
1793 if [ "$1" = --wholedisc ] ; then
1799 vecho "One track is $ONETRACK"
1800 TRACKFILE="$(mungefilename "$TRACKNAME")"
1801 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1802 ALBUMFILE="$(mungefilename "$DALBUM")"
1803 if [ "$ONETRACK" = "y" ]; then
1804 if [ "$VARIOUSARTISTS" = "y" ]; then
1805 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1807 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1809 vecho "Cue wav file is $CUEWAVFILE"
1811 CUEWAVFILE="dummy.wav"
1820 echo REM DISCID $DISCID
1821 echo FILE \""$CUEWAVFILE"\" WAVE
1823 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1830 while [ $i -le "$TRACKS" ] ; do
1831 LBA=$(( $1 - $OFFSET ))
1832 printf " TRACK %02i AUDIO\n" $i
1833 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1834 if [ $MODE = PREGAP ] ; then
1835 echomsf " PREGAP " $(($OFFSET-150))
1837 echo " INDEX 00 00:00:00"
1840 echomsf " INDEX 01 " $LBA
1847 # This essentially the start of things
1850 # Query the CD to get the track info, unless the user specified -C
1851 # or we are using some actions which do not need the CDDB data at all
1852 #if [ ! X"$EXPACTIONS" = "X" ]; then
1854 #elif [ -z "$DISCID" ]; then
1855 if [ -z "$DISCID" ]; then
1856 vecho -n "Getting CD track info... "
1857 # In OSX, unmount the disc before a query
1858 if [ "$OSFLAVOUR" = "OSX" ]; then
1859 diskutil unmount ${CDROM#/dev/}
1861 case "$CDROMREADERSYNTAX" in
1863 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1864 case "$CUE2DISCID" in
1865 # FIXME # right now we have 2 cue2discid internal
1866 # implementations: builtin and abcde.cue2discid. Test
1867 # both of them and decide which one we want to use.
1869 #vecho "Using builtin cue2discid implementation..."
1870 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1872 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1874 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1875 TRACKS=${#OFFSETTIMES[@]}
1877 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1878 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1879 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1880 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1883 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1884 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1888 #vecho "Using external python cue2discid implementation..."
1889 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1893 log error "the input flac file does not contain a cuesheet."
1898 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1900 # if [ ! "$RET" = "0" ];then
1901 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1904 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1905 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1907 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1908 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1912 case "$CDDBMETHOD" in
1913 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1914 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1918 # Make sure there's a CD in there by checking cd-discid's return code
1919 if [ ! "$?" = "0" ]; then
1920 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1921 log error "cuesheet information from the flac file could not be read."
1922 log error "Perhaps the flac file does not contain a cuesheet?."
1925 log error "CD could not be read. Perhaps there's no CD in the drive?"
1929 # In OSX, remount the disc again
1930 if [ "$OSFLAVOUR" = "OSX" ]; then
1931 diskutil mount ${CDROM#/dev/}
1934 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1936 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1939 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1940 # This needs to be done now because a section of the resuming code will need
1943 # get the number of digits to pad TRACKNUM with - we'll use this later
1944 # a CD can only hold 99 tracks, but since we support a feature for starting
1945 # numbering the tracks from a given number, we might need to set it as a
1946 # variable for the user to define... or obtain it somehow.
1947 if [ "$PADTRACKS" = "y" ] ; then
1951 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1952 if [ -z "$TRACKQUEUE" ]; then
1953 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1954 case "$CDROMREADERSYNTAX" in
1956 if [ "$WEHAVEACD" = "y" ]; then
1957 vecho "Querying the CD for audio tracks..."
1958 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1960 if [ ! "$RET" = "0" ];then
1961 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1963 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1964 CDPARANOIAAUDIOTRACKS="$TRACKS"
1966 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1967 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1968 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1969 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1971 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1972 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1976 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1979 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1981 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1982 log info "The disc does not contain any tracks. Giving up..."
1985 echo -n "Grabbing entire CD - tracks: "
1986 if [ ! "$PADTRACKS" = "y" ] ; then
1987 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1989 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1991 while [ "$X" -ne "$TRACKS" ]
1993 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1994 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1998 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1999 # User-supplied track queue.
2000 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2001 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2002 # Once cleaned, obtain the highest value in the trackqueue for number padding
2003 for LASTTRACK in $TRACKQUEUE; do :; done
2004 if [ ! "$PADTRACKS" = "y" ] ; then
2005 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2007 # Now we normalize the trackqueue
2008 for TRACK in $TRACKQUEUE ; do
2009 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2010 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2012 TRACKQUEUE=$PADTRACKQUEUE
2013 echo Grabbing tracks: "$TRACKQUEUE"
2016 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2018 # We have the discid, create a temp directory after it to store all the temp
2021 if [ -e "$ABCDETEMPDIR" ]; then
2022 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2023 # It already exists, see if it's a directory
2024 if [ ! -d "$ABCDETEMPDIR" ]; then
2025 # This is a file/socket/fifo/device/etc, not a directory
2028 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2029 echo "Please investigate, remove it, and rerun abcde." >&2
2033 # It's a directory, let's see if it's writable by us
2034 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2035 # Nope, complain and exit
2037 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2038 echo "Please investigate, remove it, and rerun abcde." >&2
2042 # See if it's populated
2043 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2044 # Wipe and start fresh
2045 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2046 echo -n "this directory to continue. Continue [y/N]? " >&2
2047 if [ "$INTERACTIVE" = "y" ]; then
2053 if [ "$ANSWER" != "y" ]; then
2056 rm -rf "$ABCDETEMPDIR" || exit 1
2057 mkdir -p "$ABCDETEMPDIR"
2058 if [ "$?" -gt "0" ]; then
2059 # Directory already exists or could not be created
2060 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2064 # Everything is fine. Check for ^encodetracklocation-
2065 # and encode-output entries in the status file and
2066 # remove them. These are not relevant across sessions.
2067 if [ -f "$ABCDETEMPDIR/status" ]; then
2068 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2069 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2070 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2072 # Remove old error messages
2073 if [ -f "$ABCDETEMPDIR/errors" ]; then
2074 rm -f "$ABCDETEMPDIR/errors"
2078 # We are starting from scratch
2079 mkdir -p "$ABCDETEMPDIR"
2080 if [ "$?" -gt "0" ]; then
2081 # Directory already exists or could not be created
2082 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2085 cat /dev/null > "$ABCDETEMPDIR/status"
2086 # Store the abcde version in the status file.
2087 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2089 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2090 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2091 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2092 vecho "Creating cue file..."
2093 case $CDROMREADERSYNTAX in
2095 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2096 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2098 log warning "the input flac file does not contain a cuesheet."
2102 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2103 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2105 log warning "reading the CUE sheet is still considered experimental"
2106 log warning "and there was a problem with the CD reading. abcde will continue,"
2107 log warning "but consider reporting the problem to the abcde author"
2113 # If we got the CDPARANOIA status and it is not recorded, save it now
2114 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2115 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2116 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2120 # Create the discid file
2121 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2122 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2123 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2128 # Create a proper CUE file based on the CUE file we created before.
2131 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2132 CUEFILE_OUT=$CUEFILE_IN.out
2133 ### FIXME ### checkstatus cddb
2134 if [ -e "$CDDBDATA" ]; then
2135 vecho "Adding metadata to the cue file..."
2136 # FIXME It doesn't preserve spaces! Why?
2137 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2139 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2140 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2141 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2145 cat "$CUEFILE_IN" | while read line
2147 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2148 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2149 # echo "$line" >> "$CUEFILE_OUT"
2150 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2151 eval track="\$TRACK$n"
2153 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2154 # When making a single-track rip, put the
2155 # actual file name into the file declaration
2156 # in the cue file so that it is usable by
2157 # music players and the like
2158 elif [ "$ONETRACK" = "y" ] &&
2159 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2161 TRACKFILE="$(mungefilename "$TRACKNAME")"
2162 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2163 ALBUMFILE="$(mungefilename "$DALBUM")"
2165 if [ "$VARIOUSARTISTS" = "y" ]; then
2166 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2168 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2171 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2174 # FIXME # If the lines above are uncommented, remove the line below.
2175 echo "$line" >> "$CUEFILE_OUT"
2178 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2179 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2185 # Parses a CDDB file and outputs the title and the track names.
2186 # Variables: CDDBFILE
2190 # List out disc title/author and contents
2191 if [ "$ONETRACK" = "y" ]; then
2192 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2194 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2195 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2196 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2197 if [ ! X"$PARSEDYEAR" = "X" ]; then
2198 echo "Year: $PARSEDYEAR"
2201 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2202 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2203 if [ ! X"$PARSEDGENRE" = "X" ]; then
2204 echo "Genre: $PARSEDGENRE"
2207 if [ ! "$ONETRACK" = "y" ]; then
2208 for TRACK in $(f_seq_row 1 $TRACKS)
2210 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2216 # Check for a local CDDB file, and report success
2219 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2221 CDDBLOCALSTATUS="notfound"
2222 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2225 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2226 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2227 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2228 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2229 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2230 CDDBLOCALMATCH=single
2231 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2232 CDDBLOCALMATCH=multiple
2237 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2238 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2239 CDDBLOCALMATCH=single
2244 # If the user has selected to check a local CDDB repo, we proceed with it
2245 case $CDDBLOCALMATCH in
2247 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2249 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2251 # List out disc title/author and contents
2252 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2253 cat "$RESULT" > "${CDDBLOCALREAD}"
2256 do_cddbparse "${CDDBLOCALREAD}"
2258 ##FIXME## QUICK HACK !!!!
2259 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2260 } >> "$ABCDETEMPDIR/cddblocalchoices"
2262 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2263 page "$ABCDETEMPDIR/cddblocalchoices"
2265 # It's all going to fit in one page, cat it
2266 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2268 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2269 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2270 CDDBLOCALCHOICENUM=-1
2271 if [ "$INTERACTIVE" = "y" ]; then
2272 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2273 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2274 read CDDBLOCALCHOICE
2275 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2276 # FIXME # Introduce diff's
2277 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2278 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2279 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2280 # Make sure we get a valid choice
2281 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2282 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2283 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2289 #echo "Selected ..."
2291 CDDBLOCALCHOICENUM=1
2293 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2294 #echo "Using local copy of CDDB data"
2295 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2296 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2297 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2298 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2299 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2300 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2301 CDDBLOCALSTATUS="found"
2303 #echo "Not using local copy of CDDB data"
2304 CDDBLOCALSTATUS="notfound"
2308 # List out disc title/author and contents
2309 do_cddbparse "${CDDBLOCALFILE}"
2310 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2311 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2313 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2315 if [ "$INTERACTIVE" = "y" ]; then
2317 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2318 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2321 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2325 if [ "$USELOCALRESP" = "y" ]; then
2326 #echo "Using local copy of CDDB data"
2327 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2328 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2329 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2330 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2331 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2332 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2333 CDDBLOCALSTATUS="single"
2335 #echo "Not using local copy of CDDB data"
2336 CDDBLOCALSTATUS="notfound"
2340 CDDBLOCALSTATUS="notfound"
2347 # Try to read CD-Text from the drive using icedax / cdda2wav
2350 if new_checkexec icedax; then
2351 CDTEXT_READER=icedax
2352 elif new_checkexec cdda2wav; then
2353 CDTEXT_READER=cdda2wav
2355 # Didn't find either, bail
2359 if [ "$OSFLAVOUR" = "OSX" ] ; then
2360 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2361 diskutil unmount ${CDROM#/dev/}
2362 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2363 CDDA2WAVCDROM="IODVDServices"
2364 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2365 CDDA2WAVCDROM="$CDROMID"
2367 if [ "$CDROMID" = "" ]; then
2368 CDDA2WAVCDROM="$CDROM"
2370 CDDA2WAVCDROM="$CDROMID"
2374 # Do we have CD-Text on the disc (and can the drive read it?)
2375 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2376 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2378 if [ $ERRORCODE -ne 0 ]; then
2379 # No CD-Text found, bail
2383 rm -f "$ABCDETEMPDIR/cddbchoices"
2385 # Make an empty template
2386 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2387 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2388 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2389 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2390 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2391 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2392 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2393 # List out disc title/author and contents
2394 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2395 for TRACK in $(f_seq_row 1 $TRACKS)
2397 TRACKM1=$(($TRACK - 1))
2398 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2399 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2400 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2401 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2403 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2404 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2405 echo >> "$ABCDETEMPDIR/cddbchoices"
2406 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2410 # Work with the musicbrainz WS API, then transform the results here so
2411 # they look (very) like the results from CDDB. Maybe not the best way
2412 # to go, but it Works For Me (TM)
2416 if checkstatus musicbrainz-readcomplete; then :; else
2417 vecho "Obtaining Musicbrainz results..."
2418 # If MB is to be used, interpret the query results and read all
2419 # the available entries.
2420 rm -f "$ABCDETEMPDIR/cddbchoices"
2421 CDDBCHOICES=1 # Overridden by multiple matches
2422 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2423 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2425 # The helper script will write disc matches out to
2426 # cddbread.*. Count how many we have
2427 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2428 # No matches. Use the normal cddb template for the user to
2430 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2431 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2432 # List out disc title/author and contents of template
2433 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2435 for TRACK in $(f_seq_row 1 $TRACKS)
2437 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2439 echo >> "$ABCDETEMPDIR/cddbchoices"
2440 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2441 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2442 echo 503 > "$ABCDETEMPDIR/cddbquery"
2444 # We have some matches
2445 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2446 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2448 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2449 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2450 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2451 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2452 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2453 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2454 # List out disc title/author and contents
2455 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2456 for TRACK in $(f_seq_row 1 $TRACKS)
2458 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2460 echo >> "$ABCDETEMPDIR/cddbchoices"
2462 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2463 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2464 for file in "$ABCDETEMPDIR"/cddbread.*
2466 X=$(echo $file | sed 's/^.*cddbread\.//g')
2467 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2468 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2469 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2470 # List out disc title/author and contents
2471 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2472 for TRACK in $(f_seq_row 1 $TRACKS)
2474 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2476 echo >> "$ABCDETEMPDIR/cddbchoices"
2478 echo "." >> "$ABCDETEMPDIR/cddbquery"
2481 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2488 # Perform CDDB protocol version check if it hasn't already been done
2489 if checkstatus cddb-statcomplete; then :; else
2490 if [ "$CDDBAVAIL" = "n" ]; then
2492 echo 503 > "$ABCDETEMPDIR/cddbstat"
2495 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2496 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2497 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2498 vecho "Checking CDDB server status..."
2499 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2500 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2501 case "$RESPONSECODE" in
2502 210) # 210 OK, status information follows (until terminating `.')
2505 501) # 501 Illegal CDDB protocol level: <n>.
2506 CDDBPROTO=`expr $CDDBPROTO - 1`
2508 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2509 # FreeDB TESTCD disc-id is used for query
2510 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2511 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2512 case "$RESPONSECODE" in
2513 2??) # Server responded, everything seems OK
2523 if test $rc -eq 1; then
2527 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2535 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2536 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2538 # Perform CDDB query if it hasn't already been done
2539 if checkstatus cddb-querycomplete; then :; else
2540 if [ "$CDDBAVAIL" = "n" ]; then
2542 echo 503 > "$ABCDETEMPDIR/cddbquery"
2543 # The default CDDBLOCALSTATUS is "notfound"
2544 # This part will be triggered if the user CDDB repo does not
2545 # contain the entry, or if we are not trying to use the repo.
2547 vecho "Querying the CDDB server..."
2548 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2549 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2550 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2556 # no match found in database,
2557 # wget/fetch error, or user requested not to use CDDB
2558 # Make up an error code (503) that abcde
2559 # will recognize in do_cddbread
2560 # and compensate by making a template
2561 echo 503 > "$ABCDETEMPDIR/cddbquery"
2563 *) # strange and unknown error
2564 echo ERRORCODE=$ERRORCODE
2565 echo "abcde: $CDDBTOOL returned unknown error code"
2569 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2576 # If it's not to be used, generate a template.
2577 # Then, display it (or them) and let the user choose/edit it
2578 if checkstatus cddb-readcomplete; then :; else
2579 vecho "Obtaining CDDB results..."
2580 # If CDDB is to be used, interpret the query results and read all
2581 # the available entries.
2582 rm -f "$ABCDETEMPDIR/cddbchoices"
2583 CDDBCHOICES=1 # Overridden by multiple matches
2584 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2585 case "$RESPONSECODE" in
2587 # One exact match, retrieve it
2588 # 200 [section] [discid] [artist] / [title]
2589 if checkstatus cddb-read-1-complete; then :; else
2590 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2591 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2592 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2593 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2594 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2596 # List out disc title/author and contents
2597 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2598 for TRACK in $(f_seq_row 1 $TRACKS)
2600 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2602 echo >> "$ABCDETEMPDIR/cddbchoices"
2606 case "$RESPONSECODE" in
2607 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2608 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2609 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2611 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2612 # List out disc title/author and contents of template
2613 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2615 for TRACK in $(f_seq_row 1 $TRACKS)
2617 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2619 echo >> "$ABCDETEMPDIR/cddbchoices"
2620 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2621 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2624 # Multiple exact, (possibly multiple) inexact matches
2626 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2627 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2628 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2629 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2630 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2632 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2634 vecho -n "Retrieving multiple matches... "
2635 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2636 read DISCINFO # eat top line
2640 if checkstatus cddb-read-$X-complete; then :; else
2641 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2642 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2644 # List out disc title/author and contents
2645 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2646 for TRACK in $(f_seq_row 1 $TRACKS)
2648 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2650 echo >> "$ABCDETEMPDIR/cddbchoices"
2653 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2657 for TRACK in $(f_seq_row 1 $TRACKS)
2659 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2661 echo >> "$ABCDETEMPDIR/cddbchoices"
2662 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2663 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2666 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2673 if checkstatus cddb-edit >/dev/null; then
2674 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2675 VARIOUSARTISTS="$(checkstatus variousartists)"
2676 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2679 if [ "$INTERACTIVE" = "y" ]; then
2680 # We should show the CDDB results both when we are not using the local CDDB repo
2681 # or when we are using it but we could not find a proper match
2682 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2683 # Display the $ABCDETEMPDIR/cddbchoices file created above
2684 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2685 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2686 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2687 CHOICE=$(checkstatus cddb-choice)
2688 if [ -n "$CHOICE" ] ; then
2689 case $CDDBCHOICES in
2690 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2691 log error "CDDB query failed!"
2694 cat "$ABCDETEMPDIR/cddbchoices"
2697 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2699 echo "Selected: #$CHOICE"
2700 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2704 # The user has a choice to make, display the info in a pager if necessary
2705 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2706 page "$ABCDETEMPDIR/cddbchoices"
2708 # It's all going to fit in one page, cat it
2709 cat "$ABCDETEMPDIR/cddbchoices" >&2
2713 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2715 # I'll take CDDB read #3 for $400, Alex
2716 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2717 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2719 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2720 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2721 if [ ! X"$DIFF" = "X" ]; then
2722 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2723 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2724 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2725 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2726 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2727 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2729 # We parse the 2 choices to diff, store them in temporary files and diff them.
2730 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2731 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2733 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2734 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2735 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2736 page "$ABCDETEMPDIR/cddbread.diff"
2738 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2742 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2744 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2745 # Make sure we get a valid choice
2746 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2747 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2748 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2752 if [ "$CDCHOICENUM" = "0" ]; then
2753 vecho "Creating empty CDDB template..."
2755 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2757 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2758 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2760 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2764 # We need some code to show the selected option when local repository is selected and we have found a match
2765 vecho "Using cached CDDB match..." >&2
2766 # Display the $ABCDETEMPDIR/cddbchoices file created above
2767 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2768 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2769 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2770 CHOICE=$(checkstatus cddb-choice)
2771 if [ "$USELOCALRESP" = "y" ]; then :; else
2772 if [ -n "$CHOICE" ] ; then
2773 case $CDDBCHOICES in
2776 echo "Selected template."
2778 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2780 echo "Selected: #$CHOICE"
2781 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2789 # We're noninteractive - pick the first choice.
2790 # But in case we run a previous instance and selected a choice, use it.
2791 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2792 # Show the choice if we are not using the locally stored one
2793 # or when the local search failed to find a match.
2794 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2795 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2796 #if [ "$PREVIOUSCHOICE" ]; then
2797 cat "$ABCDETEMPDIR/cddbchoices"
2800 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2801 CDCHOICENUM=$PREVIOUSCHOICE
2804 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2806 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2811 if checkstatus cddb-choice >/dev/null; then :; else
2812 echo "abcde: internal error: cddb-choice not recorded." >&2
2815 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2816 echo -n "Edit selected CDDB data " >&2
2817 if [ "$INTERACTIVE" = "y" ]; then
2818 if [ "$UNKNOWNDISK" = "y" ]; then
2819 echo -n "[Y/n]? " >&2
2821 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2823 echo -n "[y/N]? " >&2
2830 if [ "$EDITCDDB" = "y" ]; then
2831 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2833 # Use the debian sensible-editor wrapper to pick the editor that the
2834 # user has requested via their $EDITOR environment variable
2835 if [ -x "/usr/bin/sensible-editor" ]; then
2836 /usr/bin/sensible-editor "$CDDBDATA"
2837 elif [ -n "$EDITOR" ]; then
2838 if [ -x $(which "${EDITOR%%\ *}") ]; then
2839 # That failed, try to load the preferred editor, starting
2840 # with their EDITOR variable
2841 eval $(echo "$EDITOR") \"$CDDBDATA\"
2843 # If that fails, check for a vi
2844 elif which vi >/dev/null 2>&1; then
2846 elif [ -x /usr/bin/vim ]; then
2847 /usr/bin/vim "$CDDBDATA"
2848 elif [ -x /usr/bin/vi ]; then
2849 /usr/bin/vi "$CDDBDATA"
2850 elif [ -x /bin/vi ]; then
2852 # nano should be on all (modern, i.e., sarge) debian systems
2853 elif which nano >/dev/null 2>&1 ; then
2855 elif [ -x /usr/bin/nano ]; then
2856 /usr/bin/nano "$CDDBDATA"
2857 # mg should be on all OpenBSD systems
2858 elif which mg >/dev/null 2>&1 ; then
2860 elif [ -x /usr/bin/mg ]; then
2861 /usr/bin/mg "$CDDBDATA"
2864 log warning "no editor available. Check your EDITOR environment variable."
2866 # delete editor backup file if it exists
2867 if [ -w "$CDDBDATA~" ]; then
2872 # Some heuristics first. Look at Disc Title, and if it starts with
2873 # "Various", then we'll assume Various Artists
2874 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2875 echo "Looks like a Multi-Artist CD" >&2
2878 echo -n "Is the CD multi-artist [y/N]? " >&2
2879 if [ "$INTERACTIVE" = "y" ]; then
2886 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2889 # Need NUMTRACKS before cddb-tool will return it:
2890 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2891 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2892 # More than 1/2 tracks contain a "/", so guess forward
2894 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2895 # More than 1/2 contain a "-", so guess forward-dash
2897 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2898 # More than 1/2 contain something in parens, so guess trailing-paren
2902 echo "1) Artist / Title" >&2
2903 echo "2) Artist - Title" >&2
2904 echo "3) Title / Artist" >&2
2905 echo "4) Title - Artist" >&2
2906 echo "5) Artist: Title" >&2
2907 echo "6) Title (Artist)" >&2
2908 echo "7) This is a single-artist CD" >&2
2909 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2910 if [ "$INTERACTIVE" = "y" ]; then
2911 read VARIOUSARTISTSTYLE
2913 echo $DEFAULTSTYLE >&2
2914 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2916 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2917 # If they press Enter, then the default style (0) was chosen
2918 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2919 echo "Invalid selection. Please choose a number between 1 and 7."
2920 echo -n "Selection [1-7]: "
2921 read VARIOUSARTISTSTYLE
2922 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2924 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2925 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2927 vecho "Selected: $VARIOUSARTISTSTYLE"
2928 case "$VARIOUSARTISTSTYLE" in
2930 VARIOUSARTISTSTYLE=forward
2933 VARIOUSARTISTSTYLE=forward-dash
2936 VARIOUSARTISTSTYLE=reverse
2939 VARIOUSARTISTSTYLE=reverse-dash
2942 VARIOUSARTISTSTYLE=colon
2945 VARIOUSARTISTSTYLE=trailing-paren
2953 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2954 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2956 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2957 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2958 # This works but does not have the necessary error checking
2959 # yet. If you are familiar with the CDDB spec
2960 # (see http://www.freedb.org/src/latest/DBFORMAT)
2961 # and can create an error-free entry on your own, then put
2962 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2963 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2964 # your abcde.conf to change the email address submissions are
2967 # submit the modified file, if they want
2968 if [ "$NOSUBMIT" != "y" ]; then
2969 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2971 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2972 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2974 echo -n 'Invalid selection. Please answer "y" or "n": '
2977 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2978 echo -n "Sending..."
2979 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2986 # User CDDBLOCALPOLICY to find out if we store the file or not...
2987 # Cache edited CDDB entry in the user's cddb dir
2988 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2989 # Make sure the cache directory exists
2990 mkdir -p $CDDBLOCALDIR
2991 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2994 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2997 # do_cdread [tracknumber]
2998 # do_cdread onetrack [firsttrack] [lasttrack]
3002 # The commands here don't go through run_command because they're never supposed to be silenced
3003 # return codes need to be doublechecked anyway, however
3004 if [ "$1" = "onetrack" ]; then
3005 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3006 # FIXME # Until then, we grab the whole CD in one track, no matter what
3008 # We need the first and last track for cdda2wav/icedax
3010 LASTTRACK=$(expr $3 + 0)
3011 UTRACKNUM=$FIRSTTRACK
3012 case "$CDROMREADERSYNTAX" in
3013 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
3016 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
3017 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
3018 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3019 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3020 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3026 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3027 if [ "$USEPIPES" = "y" ]; then
3028 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3029 FILEARG="$( eval echo "\$$TEMPARG" )"
3031 PIPE_MESSAGE="and encoding "
3033 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3034 case "$CDROMREADERSYNTAX" in
3035 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
3037 FILEARG="--output-name=$WAVDATA"
3040 FILEARG="-f $WAVDATA"
3048 if [ "$1" = "onetrack" ]; then
3049 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3051 if [ -r "$CDDBDATA" ]; then
3052 getcddbinfo TRACKNAME
3053 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3055 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3058 case "$CDROMREADERSYNTAX" in
3059 ### FIXME ### use an exception for flac, since it uses -o
3060 ### FIXME ### Shall we just use -o $FILEARG ??
3062 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
3063 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3064 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3066 if [ "$REDIR" = "y" ]; then
3067 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3069 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3073 if [ "$OSFLAVOUR" = "OSX" ] ; then
3074 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3075 diskutil unmount ${CDROM#/dev/}
3076 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3077 CDDA2WAVCDROM="IODVDServices"
3078 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3079 CDDA2WAVCDROM="$CDROMID"
3081 if [ "$CDROMID" = "" ]; then
3082 CDDA2WAVCDROM="$CDROM"
3084 CDDA2WAVCDROM="$CDROMID"
3087 if [ "$REDIR" = "y" ]; then
3088 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3090 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3092 ## FIXME ## We have an exception for dagrab, since it uses -f
3093 ## FIXME ## Shall we just use -f $FILEARG ??
3095 if [ "$REDIR" = "y" ]; then
3096 nice $READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG" >&2
3098 nice $READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG"
3101 if [ "$REDIR" = "y" ]; then
3102 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3104 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3107 # Find the track's mounted path
3108 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3109 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3110 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3111 # If the file exists, copy it
3112 if [ -e "$FILEPATH" ] ; then
3113 if [ "$REDIR" = "y" ]; then
3114 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3116 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3122 if [ "$REDIR" = "y" ]; then
3123 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
3125 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3129 # If we get some error or we get some missing wav
3130 # (as long as we dont use pipes)
3131 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3132 # Thank goodness errors is only machine-parseable up to the
3133 # first colon, otherwise this woulda sucked
3134 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3135 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3137 if [ "$USEPIPES" = "y" ]; then
3138 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3140 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3144 if [ "$USEPIPES" = "y" ]; then
3145 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3147 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3149 if [ "$1" = "onetrack" ]; then
3150 echo onetrack >> "$ABCDETEMPDIR/status"
3156 # No values accepted, only uses env variables
3159 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3160 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3162 echo "abcde: unable to set the device speed" >&2
3168 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3171 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3173 warning) shift ; log warning "$@" ;;
3181 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3184 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3186 warning) shift ; log warning "$@" ;;
3194 # decho outputs a debug message if DEBUG is selected
3197 if [ x"$DEBUG" != "x" ]; then
3198 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3199 DEBUGECHO=$(echo "$@" | tr -d '[]')
3200 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3207 # User-redefinable functions
3208 # Custom filename munging:
3211 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
3212 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
3215 # Custom genre munging:
3218 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3222 # Empty pre_read function, to be defined in the configuration file.
3229 # Empty post_read function, to be defined in the configuration file.
3236 # Empty post_encode function, to be defined in the configuration file.
3242 ###############################################################################
3245 # Start of execution
3246 ###############################################################################
3251 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3253 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3254 CDDBSUBMIT=freedb-submit@freedb.org
3256 HELLOINFO="$(whoami)@$(hostname)"
3258 CDDBLOCALPOLICY="always"
3259 CDDBLOCALRECURSIVE="y"
3260 CDDBLOCALDIR="$HOME/.cddb"
3263 # List of fields we parse and show during the CDDB parsing...
3264 SHOWCDDBFIELDS="year,genre"
3267 #CDROMREADERSYNTAX=cdparanoia
3268 ENCODERSYNTAX=default
3270 MP3ENCODERSYNTAX=default
3271 OGGENCODERSYNTAX=default
3272 OPUSENCODERSYNTAX=default
3273 FLACENCODERSYNTAX=default
3274 SPEEXENCODERSYNTAX=default
3275 MPCENCODERSYNTAX=default
3276 WVENCODERSYNTAX=default
3277 APENCODERSYNTAX=default
3278 AACENCODERSYNTAX=default
3279 NORMALIZERSYNTAX=default
3280 CUEREADERSYNTAX=default
3282 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3283 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3284 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3285 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3286 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3287 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3288 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3289 PLAYLISTDATAPREFIX=''
3290 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3291 VAPLAYLISTDATAPREFIX=''
3299 VARIOUSARTISTSTYLE=forward
3306 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3307 # i.e. CDROMID="1,0,0"
3309 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3310 # If we are using the ide-scsi emulation layer, we need to define a "g"
3311 CDPARANOIACDROMBUS="d"
3313 # program paths - defaults to checking your $PATH
3320 XINGMP3ENC=xingmp3enc
3344 VORBISCOMMENT=vorbiscomment
3347 NEROAACTAG=neroAacTag
3350 CDPARANOIA=cdparanoia
3357 MUSICBRAINZ=abcde-musicbrainz-tool
3361 NORMALIZE=normalize-audio
3363 VORBISGAIN=vorbisgain
3367 # For Wavpack replay gain we set both the default of 'track gain'
3368 # as well as this option for 'album gain'. Better media players
3369 # such as vlc can select either or neither. Andrew.
3376 # Options for programs called from abcde
3389 VORBISGAINOPTS="--album"
3393 # The flac option is a workaround for an error where flac fails
3394 # to encode with error 'floating point exception'. This is flac
3395 # error in get_console_width(), corrected in flac 1.3.1
3397 FLACGAINOPTS="--add-replay-gain"
3405 # Monkey's Audio Console (mac) chokes without a mode setting
3406 # so we set one here. Andrew.
3425 VORBISCOMMENTOPTS="-R"
3426 METAFLACOPTS="--no-utf8-convert"
3429 # Default to one process if -j isn't specified
3432 # List of actions to perform - by default, run to completion
3433 ACTIONS=cddb,read,encode,tag,move,clean
3435 # This option is basically for Debian package dependencies:
3436 # List of preferred outputs - by default, run with whatever we have in the path
3437 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
3439 # List of preferred cdromreaders - by default, run whichever we have in the path
3440 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav pird"
3442 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3443 # Linux/OpenBSD. ftp is user for NetBSD.
3444 # Let's use these checkings to determine the OS flavour, which will be used
3446 if [ X$(uname) = "XFreeBSD" ] ; then
3451 elif [ X$(uname) = "XDarwin" ] ; then
3454 # We should have diskutil in OSX, but let's be sure...
3456 CDROMREADERSYNTAX=cddafs
3457 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3459 elif [ X$(uname) = "XOpenBSD" ] ; then
3463 elif [ X$(uname) = "XNetBSD" ] ; then
3467 elif [ X$(uname) = "SunOS" ] ; then
3475 # If CDDBAVAIL is set to n, no CDDB read is done
3479 # But before we get into business, let us chop off any GREP environmental
3484 if [ -z "$OUTPUTDIR" ]; then
3488 if [ -z "$WAVOUTPUTDIR" ]; then
3489 WAVOUTPUTDIR="$OUTPUTDIR"
3492 # Load system defaults
3493 if [ -r /etc/abcde.conf ]; then
3496 # Load user preference defaults
3497 if [ -r $HOME/.abcde.conf ]; then
3501 # By this time, we need some HTTPGETOPTS already defined.
3502 # If the user has defined a non-default HTTPGET method, we should not be empty.
3504 if [ "$HTTPGETOPTS" = "" ] ; then
3506 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3507 curl) HTTPGETOPTS="-f -s";;
3508 fetch)HTTPGETOPTS="-q -o -";;
3509 ftp) HTTPGETOPTS="-a -V -o - ";;
3510 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3514 # If the CDROM has not been set yet, find a suitable one.
3515 # If this is a devfs system, default to /dev/cdroms/cdrom0
3516 # instead of /dev/cdrom
3517 if [ "$CDROM" = "" ] ; then
3518 if [ -e /dev/cdroms/cdrom0 ]; then
3519 CDROM=/dev/cdroms/cdrom0
3520 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part.*(disk.)$'\n' ]]; then
3521 CDROM=/dev/${BASH_REMATCH[1]}
3522 elif [ -e /dev/cdrom ]; then
3524 elif [ -e /dev/sr0 ]; then
3526 elif [ -e /dev/cd0c ]; then
3528 elif [ -e /dev/acd0c ]; then
3530 elif [ -e /dev/disk1 ]; then
3535 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3536 # that's changed to a number to allow for more control. Deal with
3537 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3538 case "$EXTRAVERBOSE" in
3547 # Parse command line options
3548 while getopts 1a:bc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3551 a) ACTIONS="$OPTARG" ;;
3552 A) EXPACTIONS="$OPTARG" ;;
3554 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3555 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3556 d) CDROM="$OPTARG" ;;
3559 e) ERASEENCODEDSTATUS=y ;;
3560 E) ENCODING="$OPTARG" ;;
3564 j) MAXPROCS="$OPTARG" ;;
3567 L) CDDBUSELOCAL=y ;;
3572 o) OUTPUTTYPE="$OPTARG" ;;
3575 r) REMOTEHOSTS="$OPTARG" ;;
3576 R) CDDBLOCALRECURSIVE=y ;;
3577 s) SHOWCDDBFIELDS="$OPTARG" ;;
3578 S) CDSPEEDVALUE="$OPTARG" ;;
3579 t) STARTTRACKNUMBER="$OPTARG" ;;
3580 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3583 echo "This is abcde v$VERSION."
3584 echo "Usage: abcde [options] [tracks]"
3585 echo "abcde -h for extra help"
3588 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3590 X) CUE2DISCID="$OPTARG" ;;
3591 w) COMMENT="$OPTARG" ;;
3592 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3593 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
3594 STARTTRACKNUMBERTAG="y"
3595 COMMENT="CD${OPTARG}"
3596 DISCNUMBER="${OPTARG}"
3598 log error "argument of -W must be integer"
3602 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3607 shift $(($OPTIND - 1))
3609 # Here it comes the worse part of the whole thing. From here until we start
3610 # ripping, we have a mixture of sanity checks, verifications, default settigs
3611 # and other crazy stuff that interdepends, but hey, someone has to do it.
3613 # If NOCDDBQUERY is set, don't query the CDDB server.
3614 if [ "$NOCDDBQUERY" = "y" ]; then
3618 # If the user specified a flac file, then switch to special flac mode
3619 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3620 if [ ! -f "$CDROM" ]; then
3621 log error "the defined file for FLAC ripping cannot be found" >&2
3624 vecho warning "switching to flac CDROMREADERSYNTAX..."
3625 CDROMREADERSYNTAX=flac
3626 # We have a builtin version of cue2discid...
3627 case "$CUE2DISCID" in
3629 *) NEEDCUE2DISCID=y;;
3635 # If the user provided a DISCID, disable eject
3636 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3638 # Check the available cd rippers in the system, from the ones we know.
3639 if [ "$CDROMREADERSYNTAX" = "" ]; then
3640 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3641 if new_checkexec $DEFAULT_CDROMREADER; then
3642 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3646 if [ "$CDROMREADERSYNTAX" = "" ]; then
3647 log error "no cdreader found in your PATH"
3648 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3653 # Decide if we can continue.
3654 if [ "$ONETRACK" = "y" ]; then
3655 # FIXME # remove check as soon as we find out about the other readers
3656 case "$CDROMREADERSYNTAX" in
3659 cdda2wav | icedax) ;;
3661 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3664 if [ "$BATCHNORM" = "y" ]; then
3665 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3668 if [ "$NOGAP" = "y" ]; then
3669 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3672 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3673 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3674 if [ $# -gt 0 ]; then
3675 log warning "ONETRACK mode selected, grabbing all tracks..."
3678 while [ $# -gt 0 ]; do
3679 # Range parsing code courtesy of Vincent Ho
3680 # Cleaned up to use shell built-ins by Charles Steinkuehler
3681 if [ "${1#*[^0-9-]}" != "$1" ]; then
3682 log error "syntax error while processing track numbers ($1)"
3687 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3688 TRACKQUEUE="$TRACKQUEUE $RSTART"
3689 RSTART=$(( $RSTART + 1 ))
3696 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3697 # List of experimental actions: retag,transcode
3699 # Determine what actions are to be done from $ACTIONS and set the
3700 # following environment variables for them:
3712 ## FIXME ## Lets keep compatibility with -M
3713 [ "$DOCUE" != "y" ] && DOCUE=n
3715 for ACTION in $(echo $ACTIONS | tr , \ )
3718 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
3719 cue) DOCUE=y ; MAKECUEFILE=y ;;
3722 normalize) DONORMALIZE=y; DOREAD=y;;
3723 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3724 encode) DOENCODE=y; DOREAD=y;;
3725 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3726 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3727 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3728 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
3729 playlist) DOCDDB=y; DOPLAYLIST=y;;
3734 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3735 # FIXME # should we abort on error or just inform the user?
3736 log warning "selected both normalize and replaygain actions"
3739 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
3740 case $SHOWCDDBFIELD in
3741 y*|Y*) SHOWCDDBYEAR="y";;
3742 g*|G*) SHOWCDDBGENRE="y";;
3747 # At this point a CDROM has to be defined, so we check it exists.
3748 if [ X"$CDROM" != "X" ] ; then
3749 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
3750 if [ "$OSFLAVOUR" = "FBSD" ]; then
3751 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
3752 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
3753 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
3757 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
3758 log error "CDROM device cannot be found."
3761 # avoid processing if we are not going to hit the CDROM.
3762 elif [ X"$DOREAD" = "Xy" ]; then
3763 log error "CDROM has not been defined or cannot be found"
3767 # USEPIPES pre-tests, before we get into more serious stuff
3768 # Not compatible with:
3769 # - multiple outputs
3771 # - lowdisk algorithm
3773 if [ X"$USEPIPES" = "Xy" ]; then
3774 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
3775 log error "Unix pipes not compatible with multiple outputs"
3778 if [ X"$DONORMALIZE" = "Xy" ]; then
3779 log error "Unix pipes not compatible with normalizer"
3780 # FIXME # Do we need to exit or shall we just disable the mode?
3783 if [ X"$BATCHNORM" = "Xy" ]; then
3784 log error "Unix pipes not compatible with BATCHNORM encoding"
3787 if [ X"$NOGAP" = "Xy" ]; then
3788 log error "Unix pipes not compatible with NOGAP encoding"
3791 if [ X"$DOENCODE" = "Xn" ]; then
3792 vecho warning "Disabling Unix pipes since we are not encoding!"
3795 if [ X"$LOWDISK" = "Xy" ]; then
3796 log error "Unix pipes not compatible with lowdisk algorithm"
3801 # LOWDISK pre-tests, before we get into more problematic stuff
3802 # Not compatible with anything that needs all the files in the hard disc:
3805 if [ X"$LOWDISK" = "Xy" ]; then
3806 if [ X"$BATCHNORM" = "Xy" ]; then
3807 log error "Unix pipes not compatible with BATCHNORM encoding"
3810 if [ X"$NOGAP" = "Xy" ]; then
3811 log error "Unix pipes not compatible with NOGAP encoding"
3816 # BATCHNORM pre-tests, before we get into serious problems
3817 # Not compatible with
3818 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3819 vecho warning "Disabling BATCHNORM since we are not normalizing!"
3823 # Check the encoding format from the ones available in the system, if nothing has been configured.
3824 if [ X"$OUTPUTTYPE" = "X" ]; then
3825 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
3826 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3827 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3828 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
3829 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
3830 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3834 if [ X"$OUTPUTTYPE" = "X" ]; then
3835 log error "no encoder found in the PATH"
3836 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3841 # Decide which CDROM reader we're gonna use
3842 case "$CDROMREADERSYNTAX" in
3844 CDROMREADER="$CDPARANOIA"
3845 CDROMREADEROPTS="$CDPARANOIAOPTS"
3848 CDROMREADER="$CDDA2WAV"
3849 CDROMREADEROPTS="$CDDA2WAVOPTS"
3852 CDROMREADER="$DAGRAB"
3853 CDROMREADEROPTS="$DAGRABOPTS"
3857 CDROMREADEROPTS="$PIRDOPTS"
3860 CDROMREADER="$CDDAFS"
3861 CDROMREADEROPTS="$CDDAFSOPTS"
3865 CDROMREADEROPTS="$FLACOPTS"
3869 # There's only one normalize...
3870 case "$NORMALIZERSYNTAX" in
3872 NORMALIZER="$NORMALIZE"
3873 NORMALIZEROPTS="$NORMALIZEOPTS"
3877 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3878 case "$OUTPUTTYPE" in *:*)
3879 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
3880 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
3882 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3883 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3884 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3885 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3886 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3887 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3888 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3889 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3890 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3893 # Allows commandline selection of options while using multiple outputs.
3894 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
3895 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
3896 TEMPOUTPUT=${OUTPUT%%:*}
3897 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
3899 OUTPUTTYPE="$TEMPOUTPUTTYPE"
3903 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
3904 # for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as and
3905 # wavpack for wvs...
3907 # Getting ready for multiple output changes
3908 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3912 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
3913 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
3914 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
3915 OGGOUTPUTCONTAINER=ogg
3918 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
3919 OPUSOUTPUTCONTAINER=opus
3922 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
3923 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
3924 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
3927 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
3928 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
3929 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
3930 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
3933 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
3934 # [ "$DOREPLAYGAIN" = "y" ] &&
3937 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
3938 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
3941 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
3943 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVCGAIN=y
3946 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
3947 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
3950 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
3952 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
3953 # compiled without libmp4v2... Andrew.
3956 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
3957 [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
3960 if [ "$KEEPWAVS" = "y" ]; then
3961 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
3965 *) log error "Invalid OUTPUTTYPE defined"
3971 # decide which encoder
3972 case "$MP3ENCODERSYNTAX" in
3974 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
3978 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
3979 MP3ENCODER="$TOOLAME"
3982 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
3986 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
3987 MP3ENCODER="$BLADEENC"
3990 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
3994 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
3995 MP3ENCODER="$XINGMP3ENC"
3998 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
3999 MP3ENCODER="$MP3ENC"
4002 case "$OGGENCODERSYNTAX" in
4004 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4005 OGGENCODER="$VORBIZE"
4008 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4009 OGGENCODER="$OGGENC"
4012 case "$OPUSENCODERSYNTAX" in
4014 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4015 OPUSENCODER="$OPUSENC"
4018 case "$FLACENCODERSYNTAX" in
4020 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4022 if [ "$DOREPLAYGAIN" = "y" ]; then
4023 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4025 # FLAC streams can be encapsulated on a Ogg transport layer
4026 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4027 log error "FLAC on an Ogg container is not yet supported"
4028 log error "due to problem with adding comments to such files"
4030 FLACOUTPUTCONTAINER=ogg
4032 FLACOUTPUTCONTAINER=flac
4036 case "$SPEEXENCODERSYNTAX" in
4038 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4039 SPEEXENCODER="$SPEEXENC"
4042 case "$MPCENCODERSYNTAX" in
4044 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4045 MPCENCODER="$MPCENC"
4048 case "$WVENCODERSYNTAX" in
4050 WVCENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4054 case "$APENCODERSYNTAX" in
4056 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4060 case "$AACENCODERSYNTAX" in
4061 faac|neroAacEnc|fdkaac)
4062 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4063 AACENCODER="$AACENC"
4072 TAGGEROPTS="$ID3OPTS"
4077 TAGGEROPTS="$ID3V2OPTS"
4081 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4082 # trouble with CDDBPROTO=5 (which we test here) but also
4083 # with cached cddb files in latin1 (which we cannot test).
4084 if [ "$CDDBPROTO" -lt 6 ]; then
4085 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4088 # eyeD3 version 0.7 changed syntax
4089 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4090 # only if it offers the --set-encoding, assume <= 0.6.x
4092 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4094 # anything wrong, any failure, assume >= 0.7
4096 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4100 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4105 # NOGAP is specific to lame. Other encoders fail ...
4106 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4107 log warning "the NOGAP option is specific to lame. Deactivating..."
4112 case "$CUEREADERSYNTAX" in
4114 CUEREADEROPTS="${CDROM}"
4119 # which information retrieval tool are we using?
4125 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4126 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4127 log error "FLAC on an Ogg container is not yet supported"
4128 log error "due to problem with adding comments to such files"
4130 OGGOUTPUTCONTAINER=ogg.ogg
4131 FLACOUTPUTCONTAINER=flac.ogg
4132 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4135 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4137 if [ "$ENCNICE" ]; then
4138 ENCNICE="-n $ENCNICE"
4140 if [ "$READNICE" ]; then
4141 READNICE="-n $READNICE"
4143 if [ "$DISTMP3NICE" ]; then
4144 DISTMP3NICE="-n $DISTMP3NICE"
4147 # Don't check for stuff if it's not needed
4148 if [ "$REMOTEHOSTS" ]; then
4151 if [ "$DONORMALIZE" = "y" ]; then
4154 if [ "$EJECTCD" = "y" ]; then
4157 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4158 if [ "$CDDBMETHOD" = "cddb" ]; then
4160 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4164 if [ "$DOCUE" = "y" ]; then
4168 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4169 case "$CDROMREADERSYNTAX" in
4170 cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4171 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4172 ### FIXME ### translate "cue2discid" from python to bash
4173 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4178 ###USEPIPESSUPPORT###
4180 # Rippers with USEPIPE support
4181 # FIXME # Include here all the rippers we can figure out support pipes
4182 PIPERIPPER_cdparanoia="-"
4183 PIPERIPPER_debug="-"
4184 PIPERIPPER_flac="-c "
4187 # Encoders with USEPIPE support
4188 # FIXME # Include here all the encoders we can figure out support pipes
4195 # Figure out if we can use pipes with the ripper/encoder combination
4197 if [ "$USEPIPES" = "y" ]; then
4198 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4201 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4203 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4205 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4207 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4209 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
4211 PIPEENCODERSVARCHECK="PIPE_$MPCENCODER" ;;
4213 PIPEENCODERSVARCHECK="PIPE_$WVENCODER" ;;
4215 PIPEENCODERSVARCHECK="PIPE_$APENCODER" ;;
4217 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4218 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4219 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4220 log error "no support for pipes with given ripper"
4221 log error "read the USEPIPES file from the source tarball to get help."
4222 log error "On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
4225 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4226 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4227 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4228 log error "no support for pipes with given encoder"
4229 log error "read the USEPIPES file from the source tarball to help"
4230 log error "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
4235 # Make sure a buncha things exist
4236 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4237 $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4238 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER \
4239 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4240 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4241 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4242 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4243 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4244 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4245 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4246 ${NEEDCUE2DISCID+$CUE2DISCID}
4251 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4252 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4253 # these files). The resulting files are actually ADTS streams which belong in an
4254 # aac container and with some version sniffing this is all cleaned up below. If
4255 # faac is compiled with libmp4v2 inline tagging occurs with faac. Andrew.
4257 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4258 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4259 echo "WARNING: Your copy of Faac does not have mp4 support"
4260 echo "WARNING: Encoding untagged files to aac..."
4263 echo "Using Faac to Tag AAC Tracks..."
4267 # And last but not least, check if we can diff between files. We do not abort,
4268 # since diffing is not critical...
4269 if [ -x $(which $DIFF) ]; then :; else
4270 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4274 ## Now that we have metaflac, check if we need cue2discid
4275 #case $CDROMREADERSYNTAX in
4277 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4278 # if [ "$TRACKINFO" = "" ]; then
4279 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4284 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4285 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4286 HTTPGET="$HTTPGET $HTTPGETOPTS"
4288 # Here it used to say:
4289 # One thousand lines in, we can start doing stuff with things
4290 # Well, right now we are at line 3737 ;)
4292 # Export needed things so they can be read in this subshell
4293 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4294 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4296 if [ "$DOREAD" = "y" ]; then
4297 # User-definable function to set some things. Use it for
4298 # - closing the CD tray with eject -t
4299 # - set the CD speed value with eject -x
4300 vecho -n "Executing customizable pre-read function... "
4302 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4307 # Get ABCDETEMPDIR created and status file initialized
4310 if [ "$DOCDDB" = "y" ]; then
4311 # start with a sane default:
4312 CDDBLOCALSTATUS=notfound
4313 if [ $CDDBUSELOCAL = "y" ]; then
4316 if checkstatus cddb-choice > /dev/null; then
4319 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4320 case "$CDDBMETHOD" in
4331 CHOICE=$(checkstatus cddb-choice)
4332 if [ "$CHOICE" = 0 ] ; then
4333 # We don't have any information at all; try to fall back
4334 # to CD-Text for basic information
4335 vecho "No CDDB information found, trying cdtext from the CD"
4341 eval "$($CDDBTOOL parse "$CDDBDATA")"
4344 # Before reading tracks, we set the speed of the device
4346 if [ X"$CDSPEEDVALUE" != "X" ]; then
4347 case "$CDROMREADERSYNTAX" in
4348 cdparanoia|debug) ;;
4355 # Define the first and last track, since we might need them later in several places
4356 FIRSTTRACK=$( get_first $TRACKQUEUE )
4357 LASTTRACK=$( get_last $TRACKQUEUE )
4359 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4360 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4361 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4362 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4365 if checkstatus onetrack ; then ONETRACK=y ; fi
4367 if [ "$ONETRACK" = "y" ]; then
4368 # Reuse the CUEFILE in case we created it (now or in a previous run)
4369 if CUEFILE=$(checkstatus cuefile); then
4374 # Create playlist if needed (backgroundable) and start reading in tracks
4378 if [ ! "$ONETRACK" = "y" ]; then
4379 if [ "$DOPLAYLIST" = "y" ]; then
4380 echo Creating playlist... >&2
4385 # For the lowdisk option, only one program is running at once so the encoder
4386 # can be unsilenced right away.
4387 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4388 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4391 if [ "$ONETRACK" = "y" ]; then
4392 TRACKS="$FIRSTTRACK"
4393 if [ "$USEPIPES" = "y" ]; then
4394 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4395 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4398 if checkstatus readtrack-$FIRSTTRACK; then :; else
4399 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4403 for UTRACKNUM in $TRACKQUEUE
4405 if [ "$DOREAD" = "y" ]; then
4406 if [ "$USEPIPES" = "y" ]; then
4407 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4408 # Read, pipe, shut up!
4409 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4412 if checkstatus readtrack-$UTRACKNUM; then :; else
4413 do_cdread $UTRACKNUM
4415 if [ "$?" != "0" ]; then
4416 # CD read failed - don't give the goahead to
4423 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4426 # If we are not reading, set the encode output to loud already, so
4427 # that we can see the output of the first track.
4428 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4429 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4431 echo NEXTTRACK # Get the encoder machine churning again
4432 if [ "$DOREAD" = "y" ]; then
4433 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4434 until checkstatus encodetrack-$UTRACKNUM
4436 if checkerrors encodetrack-$UTRACKNUM; then
4447 # Now that we're done the encoding can be loud again -
4448 # if we're not using SMP.
4449 if [ "$MAXPROCS" = "1" ]; then
4450 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4453 # All tracks read, start encoding.
4454 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4458 # Execute the user-defined post_read function before ejecting CD
4461 # We are now finished with the cdrom - it can be safely ejected. Note that
4462 # abcde will not have completed yet.
4463 if [ "$EJECTCD" = "y" ]; then
4464 # We check if the disk we are processing is actually the disk inside the
4465 # CD tray. If not, we do not eject the CD, since it might be so that the
4466 # user ejected it manually.
4467 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4468 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4469 # More FreeBSD bits.
4470 if [ X"$(uname)" = X"FreeBSD" ] ; then
4471 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4472 # but in this script EJECT is in the envionment and names the program
4475 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4476 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4477 $eject $EJECTOPTS $cd
4478 elif [ X"$(uname)" = X"Darwin" ] ; then
4479 diskutil eject ${CDROM#/dev/} 0
4480 elif [ -x $(which $EJECT) ]; then
4481 $EJECT $EJECTOPTS "$CDROM"
4488 ## Do we need to pre-process
4489 #if [ x"$PREPROCESS" = "x" ] ; then
4492 # for PRETRACKNUM in $TRACKQUEUE
4495 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4497 # until [ $PREPROCEED ]
4499 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4500 # # all locations are working, wait and try again later
4501 # if [ ! $PREPROCEED ]; then sleep 3; fi
4503 # ( do_preprocess $PRETRACKNUM
4511 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4513 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4514 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4515 if [ "$GOAHEAD" = "NO" ]; then break; fi
4516 for LASTTRACK in $TRACKQUEUE; do :; done
4517 if checkstatus readtrack-$LASTTRACK; then
4518 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4519 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4520 if checkerrors batch-normalize; then exit 1; fi
4522 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4523 if [ "$DONORMALIZE" = "y" ]; then
4524 for UTRACKNUM in $TRACKQUEUE
4526 if checkstatus readtrack-$UTRACKNUM; then
4527 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4531 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4532 if checkerrors nogap-encode; then exit 1; fi
4537 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4538 if [ "$ONETRACK" = "y" ] ; then
4539 TRACKQUEUE="$FIRSTTRACK"
4540 TRACKS="$FIRSTTRACK"
4543 # Do the encoding, including parallelization of remote encoding
4544 # Figure out where each track is going to be encoded
4545 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4546 if [ "$MAXPROCS" != "0" ]; then
4547 for NUM in $(f_seq_row 1 "$MAXPROCS")
4549 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
4553 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
4554 for UTRACKNUM in $TRACKQUEUE
4557 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4558 if [ "$GOAHEAD" = "NO" ]; then break; fi
4559 # find out where this track is to be encoded
4560 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4561 # Make sure we have a place to encode this, if not, exit stage right
4562 if [ -z "$ENCODELOCATIONS" ]; then
4568 for LOCATION in $ENCODELOCATIONS
4570 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4571 # check first if a track has ever been assigned to this location
4572 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
4573 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4574 if checkerrors encodetrack-$PREVIOUSTRACK; then
4575 for TEMPLOCATION in $ENCODELOCATIONS
4577 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4578 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
4581 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
4586 # We're still here, this location must have been previously assigned,
4587 # and last completed without error - check if it's done with the
4588 # previous track yet
4589 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
4591 # all locations are working, wait and try again later
4592 if [ ! $PROCEED ]; then sleep 3; fi
4594 # Record the location we're about to encode the next track at
4595 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4597 # Don't proceed with the rest of the loop if we can't encode
4598 if [ "$ABORT" ]; then continue; fi
4599 ## FIXME ## Add here
4600 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4601 # Set TRACKNUM, TRACKNAME
4602 if [ -e "$CDDBDATA" ]; then
4603 if [ "$ONETRACK" = "y" ]; then
4605 TRACKNUM="$FIRSTTRACK"
4609 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
4610 getcddbinfo TRACKNAME
4614 # You can't encode a file which needs to be normalized before finishing
4615 # You can't tag a file before it's finished encoding -
4616 # thus all of this is backgrounded together
4618 if [ "$DONORMALIZE" = "y" ]; then
4619 if checkstatus readtrack-$UTRACKNUM; then
4620 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4623 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4624 if checkstatus readtrack-$UTRACKNUM; then
4625 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4626 if [ "$DONORMALIZE" = "y" ]; then
4627 if checkstatus normalizetrack-$UTRACKNUM; then
4628 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4631 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4635 if [ "$DOTAG" = "y" ]; then
4636 if checkstatus encodetrack-$UTRACKNUM; then
4637 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
4639 # Lets tag the cue file
4640 if checkstatus cleancuefile >/dev/null; then :; else
4641 if checkstatus cuefile >/dev/null ; then
4646 if [ "$DOMOVE" = "y" ]; then
4647 if checkstatus tagtrack-$UTRACKNUM; then
4648 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
4655 # Go through it again and make sure there's no distmp3 stragglers, otherwise
4656 # we'll delete the files they're working on
4657 # Do NOT play ball if there is no ball to play (so ABORT if needed)
4658 ## FIXME ## Check also for files which are encoded using PIPEs.
4659 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
4664 for LOCATION in $ENCODELOCATIONS
4666 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4667 # "How can he give us a status update, if he's DEAD?"
4668 if checkstatus encodetrack-$CHECKTRACK; then
4671 # Nothing to see here please go quietly back to your homes
4672 if [ -z "$CHECKTRACK" ]; then continue; fi
4673 # You're still here? Maybe there is something...
4674 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
4677 if [ ! $PROCEED ]; then sleep 5; fi
4680 # If the above didn't catch the stragglers, this will
4682 if [ "$DOREPLAYGAIN" = "y" ]; then
4686 # Execute the user-defined post_encode function before cleaning up
4689 # Check to see if run_command logged any errors
4690 if [ -f "$ABCDETEMPDIR/errors" ]; then
4691 log error "The following commands failed to run:"
4692 cat "$ABCDETEMPDIR/errors"
4696 if [ "$KEEPWAVS" = "y" ];then
4700 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
4701 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
4702 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
4703 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
4704 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
4705 log warning "The encoded formats does not match with the moved ones"
4706 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
4707 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
4708 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
4712 if [ "$DOCLEAN" = "y" ]; then
4713 # Wipe all the evidence
4714 # Gimme gimme gimme some more time!
4716 rm -rf "$ABCDETEMPDIR"
4719 echo "Finished. Not cleaning $ABCDETEMPDIR."