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
825 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
826 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
827 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
828 -y "$CDYEAR" -g "$GENREID" \
829 -T "${TRACKNUM:-$1}" \
830 "$ABCDETEMPDIR/track$1.$OUTPUT"
833 # FIXME # track numbers in mp3 come with 1/10, so we cannot
834 # happily substitute them with $TRACKNUM
835 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
836 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
837 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
838 -y "$CDYEAR" -g "$GENREID" \
839 -T "${TRACKNUM:-$1}/$TRACKS" \
840 ${TPE2:+--TPE2 "$TPE2"} \
841 "$ABCDETEMPDIR/track$1.$OUTPUT"
844 # FIXME # track numbers in mp3 come with 1/10, so we cannot
845 # happily substitute them with $TRACKNUM
847 eyed3_06) addopts=( \
848 ${ENCODING:+--set-encoding="$ENCODING"} \
849 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
850 # We set 'recording-date' so the date tag will show
851 # in Audacious, vlc and friends... Andrew.
852 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
853 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
856 ${ENCODING:+--encoding="$ENCODING"} \
857 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
858 # We set 'recording-date' so the date tag will show
859 # in Audacious, vlc and friends... Andrew.
860 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
861 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
864 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
866 -a "$TRACKARTIST" -t "$TRACKNAME" \
867 -G "$GENREID" -n "${TRACKNUM:-$1}" \
868 ${TRACKNUM:+-N "$TRACKS"} \
870 "$ABCDETEMPDIR/track$1.$OUTPUT"
873 log error "Internal error: ID3SYNTAX has an illegal value"
879 case "$OGGENCODERSYNTAX" in
881 # vorbiscomment can't do in-place modification, mv the file first
882 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
883 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
887 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
889 echo ARTIST="$TRACKARTIST"
891 echo TITLE="$TRACKNAME"
892 if [ -n "$CDYEAR" ]; then
895 if [ -n "$CDGENRE" ]; then
896 echo GENRE="$CDGENRE"
898 echo TRACKNUMBER=${TRACKNUM:-$1}
899 if [ -n "$DISCNUMBER" ]; then
900 echo DISCNUMBER="$DISCNUMBER"
902 echo CDDB=$CDDBDISCID
903 if [ "$(eval echo ${COMMENT})" != "" ]; then
904 case "$COMMENTOUTPUT" in
905 *=*) echo "$COMMENTOUTPUT";;
906 *) echo COMMENT="$COMMENTOUTPUT";;
909 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
910 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
911 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
912 # Doublecheck that the commented file was created
913 # successfully before wiping the original
914 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
915 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
917 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
923 run_command tagtrack-$OUTPUT-$1 true
927 echo ARTIST="$TRACKARTIST"
929 echo TITLE="$TRACKNAME"
930 if [ -n "$CDYEAR" ]; then
933 if [ -n "$CDGENRE" ]; then
934 echo GENRE="$CDGENRE"
936 echo TRACKNUMBER="${TRACKNUM:-$1}"
937 if [ -n "$DISCNUMBER" ]; then
938 echo DISCNUMBER="$DISCNUMBER"
940 echo CDDB="$CDDBDISCID"
941 if [ "$(eval echo ${COMMENT})" != "" ]; then
942 case "$COMMENTOUTPUT" in
943 *=*) echo "$COMMENTOUTPUT";;
944 *) echo COMMENT="$COMMENTOUTPUT";;
947 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
948 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
951 run_command tagtrack-$OUTPUT-$1 true
954 run_command tagtrack-$OUTPUT-$1 true
957 run_command tagtrack-$OUTPUT-$1 true
960 # 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.
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
972 # We will use inline tagging...
973 run_command tagtrack-$OUTPUT-$1 true
976 # Tag post encode with neroAacTag...
977 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
978 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
979 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
982 run_command tagtrack-$OUTPUT-$1 true
987 run_command tagtrack-$OUTPUT-$1 true
991 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
992 run_command tagtrack-$1 true
998 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1001 # The commands here don't go through run_command because they're never
1002 # supposed to be silenced
1003 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1004 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1008 case "$MP3ENCODERSYNTAX" in
1013 for UTRACKNUM in $TRACKQUEUE
1015 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1017 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1019 if [ "$RETURN" != "0" ]; then
1020 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1022 for UTRACKNUM in $TRACKQUEUE
1024 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1025 #run_command encodetrack-$UTRACKNUM true
1034 if checkerrors "nogap-encode"; then :; else
1035 if [ ! "$KEEPWAVS" = "y" ] ; then
1036 if [ ! "$KEEPWAVS" = "move" ] ; then
1041 # Other encoders fall through to normal encoding as the tracks have not
1042 # been entered in the status file.
1045 # do_encode [tracknumber] [hostname]
1046 # If no hostname is specified, encode locally
1048 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1049 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1052 if [ "$USEPIPES" = "y" ]; then
1055 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1058 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1061 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1064 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1067 TEMPARG="PIPE_$SPEEXENCODER"
1070 TEMPARG="PIPE_$MPCENCODER"
1073 TEMPARG="PIPE_$WVENCODERSYNTAX"
1076 TEMPARG="PIPE_$AACENCODERSYNTAX"
1079 TEMPARG="PIPE_$AACENCODERSYNTAX"
1082 IN="$( eval echo "\$$TEMPARG" )"
1084 IN="$ABCDETEMPDIR/track$1.wav"
1086 # We need IN to proceed, if we are not using pipes.
1087 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1088 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1090 case "$TMPOUTPUT" in
1092 OUTPUT=$OGGOUTPUTCONTAINER
1095 OUTPUT=$OPUSOUTPUTCONTAINER
1098 OUTPUT=$FLACOUTPUTCONTAINER
1104 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1105 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1108 if [ X"$USEPIPES" = "Xy" ]; then
1110 # We need a way to store the creation of the files when using PIPES
1111 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1112 # When piping it does not make sense to have a higher nice for
1113 # reading than for encoding, since it will be hold by the
1114 # encoding process. Setting an effective nice, to calm down a
1115 # bit the reading process.
1116 EFFECTIVE_NICE=$READNICE
1118 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1119 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1120 EFFECTIVE_NICE=$ENCNICE
1126 case "$MP3ENCODERSYNTAX" in
1127 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1128 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1129 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1130 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1134 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1141 case "$OGGENCODERSYNTAX" in
1142 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1143 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1147 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1154 case "$OPUSENCODERSYNTAX" in
1156 # Tag the file at encode time, as it can't be done after encoding.
1157 if [ "$DOTAG" = "y" ]; then
1158 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1159 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1160 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1162 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1168 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1175 case "$FLACENCODERSYNTAX" in
1176 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1181 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1182 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1187 if [ "$(eval echo ${COMMENT})" != "" ]; then
1190 *) COMMENT="COMMENT=$COMMENT" ;;
1193 # Tag the file at encode time, as it can't be done after encoding.
1194 if [ "$DOTAG" = "y" ]; then
1195 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1196 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1198 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1202 # Tag the file inline at encode time.
1203 if [ "$DOTAG" = "y" ]; then
1204 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1205 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1207 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1211 if [ "$DOTAG" = "y" ]; then
1212 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1213 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1215 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1219 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1222 # aac container is only used to catch faac encoded files where faac
1223 # is compiled without mp4 support (with libmp4v2).
1224 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1227 case "$AACENCODERSYNTAX" in
1229 if [ "$DOTAG" = "y" ]; then
1230 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1231 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1233 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1237 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1240 if [ "$DOTAG" = "y" ]; then
1241 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1242 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1244 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1250 # In case of wav output we need nothing. Just keep the wavs.
1251 # But we need the following to allow full logging and subsequent
1252 # successful cleaning of $ABCDETEMPDIR.
1253 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1258 # Only remove .wav if the encoding succeeded
1259 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1260 run_command encodetrack-$1 true
1261 if [ ! "$KEEPWAVS" = "y" ] ; then
1262 if [ ! "$KEEPWAVS" = "move" ] ; then
1268 run_command "" echo "HEH! The file we were about to encode disappeared:"
1269 run_command "" echo ">> $IN"
1270 run_command encodetrack-$1 false
1274 # do_preprocess [tracknumber]
1276 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1279 # IN="$ABCDETEMPDIR/track$1.wav"
1280 # # We need IN to proceed.
1281 # if [ -s "$IN" ] ; then
1282 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1284 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1285 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1286 # case "$POSTPROCESSFORMAT" in
1288 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1290 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1292 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1294 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1296 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1299 # # Only remove .wav if the encoding succeeded
1300 # if checkerrors "preprocess-(.{3,4})-$1"; then
1301 # run_command preprocess-$1 false
1303 # run_command preprocess-$1 true
1306 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1307 # echo "HEH! The file we were about to pre-process disappeared:"
1310 # run_command preprocess-$1 false
1315 # do_postprocess [tracknumber]
1317 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1320 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1322 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1323 # # We need IN to proceed.
1324 # if [ -s "$IN" ] ; then
1325 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1326 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1327 # case "$POSTPROCESSFORMAT" in
1329 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1331 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1333 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1335 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1337 # # Only remove .wav if the encoding succeeded
1338 # if checkerrors "postprocess-(.{3,4})-$1"; then
1339 # run_command postprocess-$1 false
1341 # run_command postprocess-$1 true
1344 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1345 # echo "HEH! The file we were about to post-process disappeared:"
1348 # run_command postprocess-$1 false
1363 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1367 # The commands here don't go through run_command because they're never supposed to be silenced
1368 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1373 for UTRACKNUM in $TRACKQUEUE
1375 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1377 # FIXME # Hard-coded batch option!
1378 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1380 if [ "$RETURN" != "0" ]; then
1381 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1383 for UTRACKNUM in $TRACKQUEUE
1385 echo normalizetrack-$UTRACKNUM >> status
1391 # do_batch_normalize
1393 # NORMALIZER, NORMALIZEROPTS
1394 do_batch_normalize ()
1396 # The commands here don't go through run_command because they're never supposed to be silenced
1397 echo "Batch normalizing tracks: $TRACKQUEUE"
1402 for UTRACKNUM in $TRACKQUEUE
1404 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1406 # XXX: Hard-coded batch option!
1407 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1409 if [ "$RETURN" != "0" ]; then
1410 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1412 for UTRACKNUM in $TRACKQUEUE
1414 echo normalizetrack-$UTRACKNUM >> status
1420 # do_normalize [tracknumber]
1422 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1425 IN="$ABCDETEMPDIR/track$1.wav"
1426 if [ -e "$IN" ] ; then
1427 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1428 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1430 if [ "$(checkstatus encode-output)" = "loud" ]; then
1431 echo "HEH! The file we were about to normalize disappeared:"
1434 run_command normalizetrack-$1 false "File $IN was not found"
1438 # do_move [tracknumber]
1439 # Deduces the outfile from environment variables
1440 # Creates directory if necessary
1442 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1445 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1447 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1448 # defined the OUTPUTFILE:
1451 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1452 # Munge filenames as follows:
1457 # Eat control characters
1458 ALBUMFILE="$(mungefilename "$DALBUM")"
1459 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1460 TRACKFILE="$(mungefilename "$TRACKNAME")"
1461 GENRE="$(mungegenre "$GENRE")"
1462 YEAR=${CDYEAR:-$CDYEAR}
1463 # If we want to start the tracks with a given number, we need to modify
1464 # the TRACKNUM value before evaluation
1466 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1467 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1468 if [ "$ONETRACK" = "y" ]; then
1469 if [ "$VARIOUSARTISTS" = "y" ]; then
1470 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1472 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1475 if [ "$VARIOUSARTISTS" = "y" ]; then
1476 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1478 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1481 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1482 # Once we know the specific output was successful, we can change
1483 # the OUTPUT to the value containing the container
1486 OUTPUT=$OGGOUTPUTCONTAINER
1489 OUTPUT=$OPUSOUTPUTCONTAINER
1492 OUTPUT=$FLACOUTPUTCONTAINER
1498 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1499 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1502 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1503 # FIXME # introduce warnings?
1506 # mkdir -p shouldn't return an error if the directory already exists
1507 mkdir -p "$OUTPUTFILEDIR"
1508 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1509 if checkstatus movetrack-output-$OUTPUT; then :; else
1510 run_command movetrack-output-$OUTPUT true
1515 # mkdir -p shouldn't return an error if the directory already exists
1516 mkdir -p "$OUTPUTFILEDIR"
1517 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1518 if checkstatus movetrack-output-$OUTPUT; then :; else
1519 run_command movetrack-output-$OUTPUT true
1523 # Lets move the cue file
1524 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1525 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1526 if checkstatus movecue-$OUTPUT; then :; else
1527 # Silence the Copying output since it overlaps with encoding processes...
1528 #run_command '' vecho "Copying cue file to its destination directory..."
1529 if checkstatus onetrack >/dev/null ; then
1532 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1533 # We dont have the dir, since it was not created before.
1536 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1539 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1540 # http://brianvictor.tripod.com/mp3cue.htm#details
1541 [a-z0-9][a-z0-9][a-z0-9])
1542 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1545 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1549 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1551 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1560 # Create the playlist if wanted
1562 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1563 # VARIOUSARTISTS, OUTPUTDIR
1566 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1570 OUTPUT=$OGGOUTPUTCONTAINER
1573 OUTPUT=$OPUSOUTPUTCONTAINER
1576 OUTPUT=$FLACOUTPUTCONTAINER
1582 # Create a playlist file for the playlist data to go into.
1583 # We used to wipe it out if it existed. Now we request permission if interactive.
1584 for LASTTRACK in $TRACKQUEUE; do :; done
1585 ALBUMFILE="$(mungefilename "$DALBUM")"
1586 ARTISTFILE="$(mungefilename "$DARTIST")"
1587 GENRE="$(mungegenre "$GENRE")"
1588 YEAR=${CDYEAR:-$CDYEAR}
1589 if [ "$VARIOUSARTISTS" = "y" ] ; then
1590 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1592 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1594 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1595 mkdir -p "$FINALPLAYLISTDIR"
1596 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1597 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1598 if [ "$INTERACTIVE" = "y" ]; then
1599 while [ "$DONE" != "y" ]; do
1601 case $ERASEPLAYLIST in
1602 e|E|a|A|k|K) DONE=y ;;
1603 "") ERASEPLAYLIST=e ; DONE=y ;;
1611 # Once we erase the playlist, we use append to create the new one.
1612 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1614 # The playlist does not exist, so we can safelly use append to create the new list
1617 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1618 touch "$OUTPUTDIR/$PLAYLISTFILE"
1619 for UTRACKNUM in $TRACKQUEUE
1621 # Shares some code with do_move since the filenames have to match
1622 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1623 getcddbinfo TRACKNAME
1625 TRACKFILE="$(mungefilename "$TRACKNAME")"
1626 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1627 ALBUMFILE="$(mungefilename "$DALBUM")"
1628 # If we want to start the tracks with a given number, we need to modify the
1629 # TRACKNUM value before evaluation
1631 if [ "$VARIOUSARTISTS" = "y" ]; then
1632 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1634 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1636 if [ "$VARIOUSARTISTS" = "y" ]; then
1637 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1638 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1640 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1643 if [ "$PLAYLISTDATAPREFIX" ]; then
1644 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1646 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1651 ## this will convert the playlist to have CRLF line-endings, if specified
1652 ## (some hardware players insist on CRLF endings)
1653 if [ "$DOSPLAYLIST" = "y" ]; then
1654 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1655 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1656 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1658 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1663 # This function reads a cuefile on stdin and writes an extended
1664 # cddb query on stdout. Any PREGAP for track 1 is properly
1665 # handled, although cue files embedded in FLAC files do not
1666 # appear to properly store the PREGAP setting. :(
1667 abcde.cue2discid () {
1672 while [ $val -gt 0 ] ; do
1673 ret=$(( $ret + ( $val % 10) ))
1674 val=$(( $val / 10 ))
1684 local first second third
1685 first=$(expr ${1} + 0 )
1686 second=$(expr ${2} + 0 )
1687 third=$(expr ${3} + 0 )
1689 echo $(( ((($first * 60) + $second) * 75) + $third ))
1699 while read line ; do
1702 TRACK) i=$(( i + 1 ))
1704 INDEX) if [ "$2" -eq 1 ] ; then
1706 START=$(( $LBA + $PREGAP + $OFFSET ))
1708 X=$(cddb_sum $(( $START / 75 )) )
1712 PREGAP) PREGAP=$(msf2lba $2)
1716 LEADOUT=$(( $4 / 588 ))
1719 LEADIN=$(( $3 / 588 ))
1728 LEADOUT=$(( $LEADOUT + $LEADIN ))
1730 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1731 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1732 printf "%08x %i" $DISCID $TRACKS
1735 while [ $j -le $TRACKS ] ; do
1736 eval echo -n "\" \$TRACK$j\""
1739 echo " $(( $LEADOUT / 75 ))"
1743 # abcde.mkcue [--wholedisk]
1744 # This creates a cuefile directly from the extended discid information
1745 # The --wholedisk option controls whether we're ripping data from the
1746 # start of track one or from the start of the disk (usually, but not
1747 # always the same thing!)
1749 # Track one leadin/pregap (if any) handeling:
1750 # --wholedisk specified:
1753 # INDEX 01 <pregap value>
1754 # Remaining track index values unchanged from disc TOC
1756 # --wholedisk not specified
1758 # PREGAP <pregap value>
1760 # Remaining track index values offset by <pregap value>
1767 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1770 local MODE DISCID TRACKS
1774 if [ "$1" = --wholedisc ] ; then
1780 vecho "One track is $ONETRACK"
1781 TRACKFILE="$(mungefilename "$TRACKNAME")"
1782 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1783 ALBUMFILE="$(mungefilename "$DALBUM")"
1784 if [ "$ONETRACK" = "y" ]; then
1785 if [ "$VARIOUSARTISTS" = "y" ]; then
1786 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1788 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1790 vecho "Cue wav file is $CUEWAVFILE"
1792 CUEWAVFILE="dummy.wav"
1801 echo REM DISCID $DISCID
1802 echo FILE \""$CUEWAVFILE"\" WAVE
1804 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1811 while [ $i -le "$TRACKS" ] ; do
1812 LBA=$(( $1 - $OFFSET ))
1813 printf " TRACK %02i AUDIO\n" $i
1814 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1815 if [ $MODE = PREGAP ] ; then
1816 echomsf " PREGAP " $(($OFFSET-150))
1818 echo " INDEX 00 00:00:00"
1821 echomsf " INDEX 01 " $LBA
1828 # This essentially the start of things
1831 # Query the CD to get the track info, unless the user specified -C
1832 # or we are using some actions which do not need the CDDB data at all
1833 #if [ ! X"$EXPACTIONS" = "X" ]; then
1835 #elif [ -z "$DISCID" ]; then
1836 if [ -z "$DISCID" ]; then
1837 vecho -n "Getting CD track info... "
1838 # In OSX, unmount the disc before a query
1839 if [ "$OSFLAVOUR" = "OSX" ]; then
1840 diskutil unmount ${CDROM#/dev/}
1842 case "$CDROMREADERSYNTAX" in
1844 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1845 case "$CUE2DISCID" in
1846 # FIXME # right now we have 2 cue2discid internal
1847 # implementations: builtin and abcde.cue2discid. Test
1848 # both of them and decide which one we want to use.
1850 #vecho "Using builtin cue2discid implementation..."
1851 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1853 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1855 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1856 TRACKS=${#OFFSETTIMES[@]}
1858 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1859 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1860 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1861 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1864 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1865 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1869 #vecho "Using external python cue2discid implementation..."
1870 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1874 log error "the input flac file does not contain a cuesheet."
1879 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1881 # if [ ! "$RET" = "0" ];then
1882 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1885 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1886 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1888 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1889 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1893 case "$CDDBMETHOD" in
1894 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1895 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1899 # Make sure there's a CD in there by checking cd-discid's return code
1900 if [ ! "$?" = "0" ]; then
1901 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1902 log error "cuesheet information from the flac file could not be read."
1903 log error "Perhaps the flac file does not contain a cuesheet?."
1906 log error "CD could not be read. Perhaps there's no CD in the drive?"
1910 # In OSX, remount the disc again
1911 if [ "$OSFLAVOUR" = "OSX" ]; then
1912 diskutil mount ${CDROM#/dev/}
1915 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1917 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1920 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1921 # This needs to be done now because a section of the resuming code will need
1924 # get the number of digits to pad TRACKNUM with - we'll use this later
1925 # a CD can only hold 99 tracks, but since we support a feature for starting
1926 # numbering the tracks from a given number, we might need to set it as a
1927 # variable for the user to define... or obtain it somehow.
1928 if [ "$PADTRACKS" = "y" ] ; then
1932 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1933 if [ -z "$TRACKQUEUE" ]; then
1934 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1935 case "$CDROMREADERSYNTAX" in
1936 cdparanoia|libcdio|debug)
1937 if [ "$WEHAVEACD" = "y" ]; then
1938 vecho "Querying the CD for audio tracks..."
1939 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1941 if [ ! "$RET" = "0" ];then
1942 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1944 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1945 CDPARANOIAAUDIOTRACKS="$TRACKS"
1947 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1948 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1949 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1950 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1952 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1953 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1957 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1960 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1962 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1963 log info "The disc does not contain any tracks. Giving up..."
1966 echo -n "Grabbing entire CD - tracks: "
1967 if [ ! "$PADTRACKS" = "y" ] ; then
1968 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1970 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1972 while [ "$X" -ne "$TRACKS" ]
1974 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1975 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1979 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1980 # User-supplied track queue.
1981 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1982 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1983 # Once cleaned, obtain the highest value in the trackqueue for number padding
1984 for LASTTRACK in $TRACKQUEUE; do :; done
1985 if [ ! "$PADTRACKS" = "y" ] ; then
1986 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1988 # Now we normalize the trackqueue
1989 for TRACK in $TRACKQUEUE ; do
1990 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1991 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1993 TRACKQUEUE=$PADTRACKQUEUE
1994 echo Grabbing tracks: "$TRACKQUEUE"
1997 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1999 # We have the discid, create a temp directory after it to store all the temp
2002 if [ -e "$ABCDETEMPDIR" ]; then
2003 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2004 # It already exists, see if it's a directory
2005 if [ ! -d "$ABCDETEMPDIR" ]; then
2006 # This is a file/socket/fifo/device/etc, not a directory
2009 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2010 echo "Please investigate, remove it, and rerun abcde." >&2
2014 # It's a directory, let's see if it's writable by us
2015 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2016 # Nope, complain and exit
2018 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2019 echo "Please investigate, remove it, and rerun abcde." >&2
2023 # See if it's populated
2024 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2025 # Wipe and start fresh
2026 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2027 echo -n "this directory to continue. Continue [y/N]? " >&2
2028 if [ "$INTERACTIVE" = "y" ]; then
2034 if [ "$ANSWER" != "y" ]; then
2037 rm -rf "$ABCDETEMPDIR" || exit 1
2038 mkdir -p "$ABCDETEMPDIR"
2039 if [ "$?" -gt "0" ]; then
2040 # Directory already exists or could not be created
2041 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2045 # Everything is fine. Check for ^encodetracklocation-
2046 # and encode-output entries in the status file and
2047 # remove them. These are not relevant across sessions.
2048 if [ -f "$ABCDETEMPDIR/status" ]; then
2049 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2050 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2051 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2053 # Remove old error messages
2054 if [ -f "$ABCDETEMPDIR/errors" ]; then
2055 rm -f "$ABCDETEMPDIR/errors"
2059 # We are starting from scratch
2060 mkdir -p "$ABCDETEMPDIR"
2061 if [ "$?" -gt "0" ]; then
2062 # Directory already exists or could not be created
2063 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2066 cat /dev/null > "$ABCDETEMPDIR/status"
2067 # Store the abcde version in the status file.
2068 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2070 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2071 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2072 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2073 vecho "Creating cue file..."
2074 case $CDROMREADERSYNTAX in
2076 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2077 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2079 log warning "the input flac file does not contain a cuesheet."
2083 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2084 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2086 log warning "reading the CUE sheet is still considered experimental"
2087 log warning "and there was a problem with the CD reading. abcde will continue,"
2088 log warning "but consider reporting the problem to the abcde author"
2094 # If we got the CDPARANOIA status and it is not recorded, save it now
2095 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2096 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2097 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2101 # Create the discid file
2102 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2103 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2104 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2109 # Create a proper CUE file based on the CUE file we created before.
2112 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2113 CUEFILE_OUT=$CUEFILE_IN.out
2114 ### FIXME ### checkstatus cddb
2115 if [ -e "$CDDBDATA" ]; then
2116 vecho "Adding metadata to the cue file..."
2117 # FIXME It doesn't preserve spaces! Why?
2118 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2120 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2121 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2122 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2126 cat "$CUEFILE_IN" | while read line
2128 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2129 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2130 # echo "$line" >> "$CUEFILE_OUT"
2131 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2132 eval track="\$TRACK$n"
2134 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2135 # When making a single-track rip, put the
2136 # actual file name into the file declaration
2137 # in the cue file so that it is usable by
2138 # music players and the like
2139 elif [ "$ONETRACK" = "y" ] &&
2140 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2142 TRACKFILE="$(mungefilename "$TRACKNAME")"
2143 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2144 ALBUMFILE="$(mungefilename "$DALBUM")"
2146 if [ "$VARIOUSARTISTS" = "y" ]; then
2147 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2149 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2152 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2155 # FIXME # If the lines above are uncommented, remove the line below.
2156 echo "$line" >> "$CUEFILE_OUT"
2159 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2160 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2166 # Parses a CDDB file and outputs the title and the track names.
2167 # Variables: CDDBFILE
2171 # List out disc title/author and contents
2172 if [ "$ONETRACK" = "y" ]; then
2173 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2175 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2176 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2177 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2178 if [ ! X"$PARSEDYEAR" = "X" ]; then
2179 echo "Year: $PARSEDYEAR"
2182 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2183 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2184 if [ ! X"$PARSEDGENRE" = "X" ]; then
2185 echo "Genre: $PARSEDGENRE"
2188 if [ ! "$ONETRACK" = "y" ]; then
2189 for TRACK in $(f_seq_row 1 $TRACKS)
2191 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2197 # Check for a local CDDB file, and report success
2200 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2202 CDDBLOCALSTATUS="notfound"
2203 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2206 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2207 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2208 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2209 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2210 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2211 CDDBLOCALMATCH=single
2212 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2213 CDDBLOCALMATCH=multiple
2218 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2219 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2220 CDDBLOCALMATCH=single
2225 # If the user has selected to check a local CDDB repo, we proceed with it
2226 case $CDDBLOCALMATCH in
2228 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2230 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2232 # List out disc title/author and contents
2233 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2234 cat "$RESULT" > "${CDDBLOCALREAD}"
2237 do_cddbparse "${CDDBLOCALREAD}"
2239 ##FIXME## QUICK HACK !!!!
2240 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2241 } >> "$ABCDETEMPDIR/cddblocalchoices"
2243 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2244 page "$ABCDETEMPDIR/cddblocalchoices"
2246 # It's all going to fit in one page, cat it
2247 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2249 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2250 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2251 CDDBLOCALCHOICENUM=-1
2252 if [ "$INTERACTIVE" = "y" ]; then
2253 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2254 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2255 read CDDBLOCALCHOICE
2256 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2257 # FIXME # Introduce diff's
2258 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2259 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2260 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2261 # Make sure we get a valid choice
2262 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2263 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2264 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2270 #echo "Selected ..."
2272 CDDBLOCALCHOICENUM=1
2274 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2275 #echo "Using local copy of CDDB data"
2276 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2277 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2278 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2279 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2280 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2281 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2282 CDDBLOCALSTATUS="found"
2284 #echo "Not using local copy of CDDB data"
2285 CDDBLOCALSTATUS="notfound"
2289 # List out disc title/author and contents
2290 do_cddbparse "${CDDBLOCALFILE}"
2291 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2292 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2294 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2296 if [ "$INTERACTIVE" = "y" ]; then
2298 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2299 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2302 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2306 if [ "$USELOCALRESP" = "y" ]; then
2307 #echo "Using local copy of CDDB data"
2308 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2309 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2310 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2311 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2312 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2313 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2314 CDDBLOCALSTATUS="single"
2316 #echo "Not using local copy of CDDB data"
2317 CDDBLOCALSTATUS="notfound"
2321 CDDBLOCALSTATUS="notfound"
2328 # Try to read CD-Text from the drive using icedax / cdda2wav
2331 if new_checkexec icedax; then
2332 CDTEXT_READER=icedax
2333 elif new_checkexec cdda2wav; then
2334 CDTEXT_READER=cdda2wav
2336 # Didn't find either, bail
2340 if [ "$OSFLAVOUR" = "OSX" ] ; then
2341 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2342 diskutil unmount ${CDROM#/dev/}
2343 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2344 CDDA2WAVCDROM="IODVDServices"
2345 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2346 CDDA2WAVCDROM="$CDROMID"
2348 if [ "$CDROMID" = "" ]; then
2349 CDDA2WAVCDROM="$CDROM"
2351 CDDA2WAVCDROM="$CDROMID"
2355 # Do we have CD-Text on the disc (and can the drive read it?)
2356 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2357 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2359 if [ $ERRORCODE -ne 0 ]; then
2360 # No CD-Text found, bail
2364 rm -f "$ABCDETEMPDIR/cddbchoices"
2366 # Make an empty template
2367 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2368 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2369 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2370 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2371 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2372 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2373 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2374 # List out disc title/author and contents
2375 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2376 for TRACK in $(f_seq_row 1 $TRACKS)
2378 TRACKM1=$(($TRACK - 1))
2379 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2380 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2381 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2382 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2384 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2385 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2386 echo >> "$ABCDETEMPDIR/cddbchoices"
2387 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2391 # Work with the musicbrainz WS API, then transform the results here so
2392 # they look (very) like the results from CDDB. Maybe not the best way
2393 # to go, but it Works For Me (TM)
2397 if checkstatus musicbrainz-readcomplete; then :; else
2398 vecho "Obtaining Musicbrainz results..."
2399 # If MB is to be used, interpret the query results and read all
2400 # the available entries.
2401 rm -f "$ABCDETEMPDIR/cddbchoices"
2402 CDDBCHOICES=1 # Overridden by multiple matches
2403 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2404 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2406 # The helper script will write disc matches out to
2407 # cddbread.*. Count how many we have
2408 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2409 # No matches. Use the normal cddb template for the user to
2411 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2412 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2413 # List out disc title/author and contents of template
2414 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2416 for TRACK in $(f_seq_row 1 $TRACKS)
2418 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2420 echo >> "$ABCDETEMPDIR/cddbchoices"
2421 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2422 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2423 echo 503 > "$ABCDETEMPDIR/cddbquery"
2425 # We have some matches
2426 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2427 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2429 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2430 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2431 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2432 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2433 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2434 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2435 # List out disc title/author and contents
2436 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2437 for TRACK in $(f_seq_row 1 $TRACKS)
2439 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2441 echo >> "$ABCDETEMPDIR/cddbchoices"
2443 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2444 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2445 for file in "$ABCDETEMPDIR"/cddbread.*
2447 X=$(echo $file | sed 's/^.*cddbread\.//g')
2448 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2449 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2450 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2451 # List out disc title/author and contents
2452 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2453 for TRACK in $(f_seq_row 1 $TRACKS)
2455 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2457 echo >> "$ABCDETEMPDIR/cddbchoices"
2459 echo "." >> "$ABCDETEMPDIR/cddbquery"
2462 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2469 # Perform CDDB protocol version check if it hasn't already been done
2470 if checkstatus cddb-statcomplete; then :; else
2471 if [ "$CDDBAVAIL" = "n" ]; then
2473 echo 503 > "$ABCDETEMPDIR/cddbstat"
2476 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2477 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2478 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2479 vecho "Checking CDDB server status..."
2480 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2481 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2482 case "$RESPONSECODE" in
2483 210) # 210 OK, status information follows (until terminating `.')
2486 501) # 501 Illegal CDDB protocol level: <n>.
2487 CDDBPROTO=`expr $CDDBPROTO - 1`
2489 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2490 # FreeDB TESTCD disc-id is used for query
2491 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2492 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2493 case "$RESPONSECODE" in
2494 2??) # Server responded, everything seems OK
2504 if test $rc -eq 1; then
2508 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2516 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2517 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2519 # Perform CDDB query if it hasn't already been done
2520 if checkstatus cddb-querycomplete; then :; else
2521 if [ "$CDDBAVAIL" = "n" ]; then
2523 echo 503 > "$ABCDETEMPDIR/cddbquery"
2524 # The default CDDBLOCALSTATUS is "notfound"
2525 # This part will be triggered if the user CDDB repo does not
2526 # contain the entry, or if we are not trying to use the repo.
2528 vecho "Querying the CDDB server..."
2529 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2530 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2531 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2537 # no match found in database,
2538 # wget/fetch error, or user requested not to use CDDB
2539 # Make up an error code (503) that abcde
2540 # will recognize in do_cddbread
2541 # and compensate by making a template
2542 echo 503 > "$ABCDETEMPDIR/cddbquery"
2544 *) # strange and unknown error
2545 echo ERRORCODE=$ERRORCODE
2546 echo "abcde: $CDDBTOOL returned unknown error code"
2550 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2557 # If it's not to be used, generate a template.
2558 # Then, display it (or them) and let the user choose/edit it
2559 if checkstatus cddb-readcomplete; then :; else
2560 vecho "Obtaining CDDB results..."
2561 # If CDDB is to be used, interpret the query results and read all
2562 # the available entries.
2563 rm -f "$ABCDETEMPDIR/cddbchoices"
2564 CDDBCHOICES=1 # Overridden by multiple matches
2565 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2566 case "$RESPONSECODE" in
2568 # One exact match, retrieve it
2569 # 200 [section] [discid] [artist] / [title]
2570 if checkstatus cddb-read-1-complete; then :; else
2571 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2572 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2573 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2574 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2575 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2577 # List out disc title/author and contents
2578 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2579 for TRACK in $(f_seq_row 1 $TRACKS)
2581 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2583 echo >> "$ABCDETEMPDIR/cddbchoices"
2587 case "$RESPONSECODE" in
2588 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2589 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2590 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2592 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2593 # List out disc title/author and contents of template
2594 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2596 for TRACK in $(f_seq_row 1 $TRACKS)
2598 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2600 echo >> "$ABCDETEMPDIR/cddbchoices"
2601 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2602 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2605 # Multiple exact, (possibly multiple) inexact matches
2607 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2608 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2609 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2610 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2611 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2613 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2615 vecho -n "Retrieving multiple matches... "
2616 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2617 read DISCINFO # eat top line
2621 if checkstatus cddb-read-$X-complete; then :; else
2622 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2623 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2625 # List out disc title/author and contents
2626 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2627 for TRACK in $(f_seq_row 1 $TRACKS)
2629 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2631 echo >> "$ABCDETEMPDIR/cddbchoices"
2634 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2638 for TRACK in $(f_seq_row 1 $TRACKS)
2640 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2642 echo >> "$ABCDETEMPDIR/cddbchoices"
2643 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2644 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2647 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2654 if checkstatus cddb-edit >/dev/null; then
2655 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2656 VARIOUSARTISTS="$(checkstatus variousartists)"
2657 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2660 if [ "$INTERACTIVE" = "y" ]; then
2661 # We should show the CDDB results both when we are not using the local CDDB repo
2662 # or when we are using it but we could not find a proper match
2663 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2664 # Display the $ABCDETEMPDIR/cddbchoices file created above
2665 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2666 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2667 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2668 CHOICE=$(checkstatus cddb-choice)
2669 if [ -n "$CHOICE" ] ; then
2670 case $CDDBCHOICES in
2671 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2672 log error "CDDB query failed!"
2675 cat "$ABCDETEMPDIR/cddbchoices"
2678 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2680 echo "Selected: #$CHOICE"
2681 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2685 # The user has a choice to make, display the info in a pager if necessary
2686 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2687 page "$ABCDETEMPDIR/cddbchoices"
2689 # It's all going to fit in one page, cat it
2690 cat "$ABCDETEMPDIR/cddbchoices" >&2
2694 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2696 # I'll take CDDB read #3 for $400, Alex
2697 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2698 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2700 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2701 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2702 if [ ! X"$DIFF" = "X" ]; then
2703 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2704 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2705 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2706 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2707 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2708 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2710 # We parse the 2 choices to diff, store them in temporary files and diff them.
2711 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2712 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2714 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2715 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2716 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2717 page "$ABCDETEMPDIR/cddbread.diff"
2719 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2723 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2725 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2726 # Make sure we get a valid choice
2727 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2728 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2729 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2733 if [ "$CDCHOICENUM" = "0" ]; then
2734 vecho "Creating empty CDDB template..."
2736 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2738 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2739 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2741 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2745 # We need some code to show the selected option when local repository is selected and we have found a match
2746 vecho "Using cached CDDB match..." >&2
2747 # Display the $ABCDETEMPDIR/cddbchoices file created above
2748 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2749 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2750 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2751 CHOICE=$(checkstatus cddb-choice)
2752 if [ "$USELOCALRESP" = "y" ]; then :; else
2753 if [ -n "$CHOICE" ] ; then
2754 case $CDDBCHOICES in
2757 echo "Selected template."
2759 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2761 echo "Selected: #$CHOICE"
2762 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2770 # We're noninteractive - pick the first choice.
2771 # But in case we run a previous instance and selected a choice, use it.
2772 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2773 # Show the choice if we are not using the locally stored one
2774 # or when the local search failed to find a match.
2775 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2776 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2777 #if [ "$PREVIOUSCHOICE" ]; then
2778 cat "$ABCDETEMPDIR/cddbchoices"
2781 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2782 CDCHOICENUM=$PREVIOUSCHOICE
2785 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2787 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2792 if checkstatus cddb-choice >/dev/null; then :; else
2793 echo "abcde: internal error: cddb-choice not recorded." >&2
2796 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2797 echo -n "Edit selected CDDB data " >&2
2798 if [ "$INTERACTIVE" = "y" ]; then
2799 if [ "$UNKNOWNDISK" = "y" ]; then
2800 echo -n "[Y/n]? " >&2
2802 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2804 echo -n "[y/N]? " >&2
2811 if [ "$EDITCDDB" = "y" ]; then
2812 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2814 # Use the debian sensible-editor wrapper to pick the editor that the
2815 # user has requested via their $EDITOR environment variable
2816 if [ -x "/usr/bin/sensible-editor" ]; then
2817 /usr/bin/sensible-editor "$CDDBDATA"
2818 elif [ -n "$EDITOR" ]; then
2819 if [ -x $(which "${EDITOR%%\ *}") ]; then
2820 # That failed, try to load the preferred editor, starting
2821 # with their EDITOR variable
2822 eval $(echo "$EDITOR") \"$CDDBDATA\"
2824 # If that fails, check for a vi
2825 elif which vi >/dev/null 2>&1; then
2827 elif [ -x /usr/bin/vim ]; then
2828 /usr/bin/vim "$CDDBDATA"
2829 elif [ -x /usr/bin/vi ]; then
2830 /usr/bin/vi "$CDDBDATA"
2831 elif [ -x /bin/vi ]; then
2833 # nano should be on all (modern, i.e., sarge) debian systems
2834 elif which nano >/dev/null 2>&1 ; then
2836 elif [ -x /usr/bin/nano ]; then
2837 /usr/bin/nano "$CDDBDATA"
2838 # mg should be on all OpenBSD systems
2839 elif which mg >/dev/null 2>&1 ; then
2841 elif [ -x /usr/bin/mg ]; then
2842 /usr/bin/mg "$CDDBDATA"
2845 log warning "no editor available. Check your EDITOR environment variable."
2847 # delete editor backup file if it exists
2848 if [ -w "$CDDBDATA~" ]; then
2853 # Some heuristics first. Look at Disc Title, and if it starts with
2854 # "Various", then we'll assume Various Artists
2855 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2856 echo "Looks like a Multi-Artist CD" >&2
2859 echo -n "Is the CD multi-artist [y/N]? " >&2
2860 if [ "$INTERACTIVE" = "y" ]; then
2867 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2870 # Need NUMTRACKS before cddb-tool will return it:
2871 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2872 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2873 # More than 1/2 tracks contain a "/", so guess forward
2875 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2876 # More than 1/2 contain a "-", so guess forward-dash
2878 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2879 # More than 1/2 contain something in parens, so guess trailing-paren
2883 echo "1) Artist / Title" >&2
2884 echo "2) Artist - Title" >&2
2885 echo "3) Title / Artist" >&2
2886 echo "4) Title - Artist" >&2
2887 echo "5) Artist: Title" >&2
2888 echo "6) Title (Artist)" >&2
2889 echo "7) This is a single-artist CD" >&2
2890 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2891 if [ "$INTERACTIVE" = "y" ]; then
2892 read VARIOUSARTISTSTYLE
2894 echo $DEFAULTSTYLE >&2
2895 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2897 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2898 # If they press Enter, then the default style (0) was chosen
2899 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2900 echo "Invalid selection. Please choose a number between 1 and 7."
2901 echo -n "Selection [1-7]: "
2902 read VARIOUSARTISTSTYLE
2903 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2905 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2906 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2908 vecho "Selected: $VARIOUSARTISTSTYLE"
2909 case "$VARIOUSARTISTSTYLE" in
2911 VARIOUSARTISTSTYLE=forward
2914 VARIOUSARTISTSTYLE=forward-dash
2917 VARIOUSARTISTSTYLE=reverse
2920 VARIOUSARTISTSTYLE=reverse-dash
2923 VARIOUSARTISTSTYLE=colon
2926 VARIOUSARTISTSTYLE=trailing-paren
2934 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2935 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2937 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2938 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2939 # This works but does not have the necessary error checking
2940 # yet. If you are familiar with the CDDB spec
2941 # (see http://www.freedb.org/src/latest/DBFORMAT)
2942 # and can create an error-free entry on your own, then put
2943 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2944 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2945 # your abcde.conf to change the email address submissions are
2948 # submit the modified file, if they want
2949 if [ "$NOSUBMIT" != "y" ]; then
2950 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2952 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2953 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2955 echo -n 'Invalid selection. Please answer "y" or "n": '
2958 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2959 echo -n "Sending..."
2960 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2967 # User CDDBLOCALPOLICY to find out if we store the file or not...
2968 # Cache edited CDDB entry in the user's cddb dir
2969 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2970 # Make sure the cache directory exists
2971 mkdir -p $CDDBLOCALDIR
2972 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2975 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2979 # try to download CD cover
2983 ALBUMFILE="$(mungefilename "$DALBUM")"
2984 ARTISTFILE="$(mungefilename "$DARTIST")"
2986 if [ x"$ALBUMARTFILE" = "x" ]; then
2987 ALBUMARTFILE="cover.jpg"
2989 # have we got a musicbrainz mbid or amazon asin?
2990 case "$CDDBMETHOD" in
2992 # try musicbrainz mbid
2993 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
2994 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
2995 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
2996 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
2997 vecho "cover URL: $ALBUMARTURL" >&2
2998 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
2999 if [ $? -ne 0 ]; then
3000 vecho "could not download cover from musicbrainz" >&2
3002 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3003 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3004 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3005 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3006 vecho "cover URL: $ALBUMARTURL" >&2
3007 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3008 if [ $? -ne 0 ]; then
3009 vecho "could not download cover from amazon" >&2
3012 vecho "no amazon ID found" >&2
3016 vecho "no musicbrainz ID found" >&2
3021 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3022 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3023 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3024 if [ $? -ne 0 ]; then
3025 vecho "could not download cover with glyrc" >&2
3030 # copy to target directories
3031 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3032 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3034 # put cover in the same place as the album
3035 if [ "$VARIOUSARTISTS" = "y" ] ; then
3036 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3038 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3040 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3041 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3042 mkdir -p "$FINALALBUMARTDIR"
3043 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3045 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3046 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3048 log warning "could not get cover"
3049 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3053 # do_cdread [tracknumber]
3054 # do_cdread onetrack [firsttrack] [lasttrack]
3058 # The commands here don't go through run_command because they're never supposed to be silenced
3059 # return codes need to be doublechecked anyway, however
3060 if [ "$1" = "onetrack" ]; then
3061 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3062 # FIXME # Until then, we grab the whole CD in one track, no matter what
3064 # We need the first and last track for cdda2wav/icedax
3066 LASTTRACK=$(expr $3 + 0)
3067 UTRACKNUM=$FIRSTTRACK
3068 case "$CDROMREADERSYNTAX" in
3069 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
3072 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
3073 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
3074 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3075 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3076 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3082 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3083 if [ "$USEPIPES" = "y" ]; then
3084 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3085 FILEARG="$( eval echo "\$$TEMPARG" )"
3087 PIPE_MESSAGE="and encoding "
3089 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3090 case "$CDROMREADERSYNTAX" in
3091 ## FIXME ## Find the cases for flac, to avoid exceptions
3093 FILEARG="--output-name=$WAVDATA"
3101 if [ "$1" = "onetrack" ]; then
3102 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3104 if [ -r "$CDDBDATA" ]; then
3105 getcddbinfo TRACKNAME
3106 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3108 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3111 case "$CDROMREADERSYNTAX" in
3112 ### FIXME ### use an exception for flac, since it uses -o
3113 ### FIXME ### Shall we just use -o $FILEARG ??
3115 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3116 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3117 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3119 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3121 if [ "$OSFLAVOUR" = "OSX" ] ; then
3122 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3123 diskutil unmount ${CDROM#/dev/}
3124 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3125 CDDA2WAVCDROM="IODVDServices"
3126 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3127 CDDA2WAVCDROM="$CDROMID"
3129 if [ "$CDROMID" = "" ]; then
3130 CDDA2WAVCDROM="$CDROM"
3132 CDDA2WAVCDROM="$CDROMID"
3135 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3136 dagrab) nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2 ;;
3138 if [ "$USEPIPES" = "y" ]; then
3139 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3141 # Write ripped audio data to stdout and redirect to $FILEARG.
3142 # $REDIR can be ignored. Progress is written to stderr by default.
3143 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3147 # Find the track's mounted path
3148 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3149 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3150 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3151 # If the file exists, copy it
3152 if [ -e "$FILEPATH" ] ; then
3153 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
3157 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" $REDIR ;;
3160 # If we get some error or we get some missing wav
3161 # (as long as we dont use pipes)
3162 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3163 # Thank goodness errors is only machine-parseable up to the
3164 # first colon, otherwise this woulda sucked
3165 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3166 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3168 if [ "$USEPIPES" = "y" ]; then
3169 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3171 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3175 if [ "$USEPIPES" = "y" ]; then
3176 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3178 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3180 if [ "$1" = "onetrack" ]; then
3181 echo onetrack >> "$ABCDETEMPDIR/status"
3187 # No values accepted, only uses env variables
3190 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3191 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3193 echo "abcde: unable to set the device speed" >&2
3199 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3202 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3204 warning) shift ; log warning "$@" ;;
3212 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3215 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3217 warning) shift ; log warning "$@" ;;
3225 # decho outputs a debug message if DEBUG is selected
3228 if [ x"$DEBUG" != "x" ]; then
3229 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3230 DEBUGECHO=$(echo "$@" | tr -d '[]')
3231 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3238 # User-redefinable functions
3239 # Custom filename munging:
3242 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
3243 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
3246 # Custom genre munging:
3249 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3253 # Empty pre_read function, to be defined in the configuration file.
3260 # Empty post_read function, to be defined in the configuration file.
3267 # Empty post_encode function, to be defined in the configuration file.
3273 ###############################################################################
3276 # Start of execution
3277 ###############################################################################
3282 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3284 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3285 CDDBSUBMIT=freedb-submit@freedb.org
3287 HELLOINFO="$(whoami)@$(hostname)"
3289 CDDBLOCALPOLICY="always"
3290 CDDBLOCALRECURSIVE="y"
3291 CDDBLOCALDIR="$HOME/.cddb"
3294 # List of fields we parse and show during the CDDB parsing...
3295 SHOWCDDBFIELDS="year,genre"
3298 #CDROMREADERSYNTAX=cdparanoia
3299 ENCODERSYNTAX=default
3301 MP3ENCODERSYNTAX=default
3302 OGGENCODERSYNTAX=default
3303 OPUSENCODERSYNTAX=default
3304 FLACENCODERSYNTAX=default
3305 SPEEXENCODERSYNTAX=default
3306 MPCENCODERSYNTAX=default
3307 WVENCODERSYNTAX=default
3308 APENCODERSYNTAX=default
3309 AACENCODERSYNTAX=default
3310 NORMALIZERSYNTAX=default
3311 CUEREADERSYNTAX=default
3313 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3314 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3315 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3316 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3317 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3318 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3319 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3320 PLAYLISTDATAPREFIX=''
3321 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3322 VAPLAYLISTDATAPREFIX=''
3330 VARIOUSARTISTSTYLE=forward
3337 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3338 # i.e. CDROMID="1,0,0"
3340 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3341 # If we are using the ide-scsi emulation layer, we need to define a "g"
3342 CDPARANOIACDROMBUS="d"
3344 # program paths - defaults to checking your $PATH
3351 XINGMP3ENC=xingmp3enc
3371 NEROAACENC=neroAacEnc
3377 VORBISCOMMENT=vorbiscomment
3379 NEROAACTAG=neroAacTag
3381 CDPARANOIA=cdparanoia
3382 CD_PARANOIA=cd-paranoia
3389 MUSICBRAINZ=abcde-musicbrainz-tool
3393 NORMALIZE=normalize-audio
3395 VORBISGAIN=vorbisgain
3399 # For Wavpack replay gain we set both the default of 'track gain'
3400 # as well as this option for 'album gain'. Better media players
3401 # such as vlc can select either or neither. Andrew.
3409 # Options for programs called from abcde
3422 VORBISGAINOPTS="--album"
3426 # The flac option is a workaround for an error where flac fails
3427 # to encode with error 'floating point exception'. This is flac
3428 # error in get_console_width(), corrected in flac 1.3.1
3430 FLACGAINOPTS="--add-replay-gain"
3438 # Monkey's Audio Console (mac) chokes without a mode setting
3439 # so we set one here.
3444 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3445 # we set bitrate here.
3446 FDKAACENCOPTS='192k'
3463 VORBISCOMMENTOPTS="-R"
3464 METAFLACOPTS="--no-utf8-convert"
3466 GLYRCOPTS="--formats jpg;jpeg"
3468 # Default to one process if -j isn't specified
3471 # List of actions to perform - by default, run to completion
3472 ACTIONS=cddb,read,encode,tag,move,clean
3474 # This option is basically for Debian package dependencies:
3475 # List of preferred outputs - by default, run with whatever we have in the path
3476 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
3478 # List of preferred cdromreaders - by default, run whichever we have in the path
3479 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3481 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3482 # Linux/OpenBSD. ftp is user for NetBSD.
3483 # Let's use these checkings to determine the OS flavour, which will be used
3485 if [ X$(uname) = "XFreeBSD" ] ; then
3490 elif [ X$(uname) = "XDarwin" ] ; then
3493 # We should have diskutil in OSX, but let's be sure...
3495 CDROMREADERSYNTAX=cddafs
3496 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3498 elif [ X$(uname) = "XOpenBSD" ] ; then
3502 elif [ X$(uname) = "XNetBSD" ] ; then
3506 elif [ X$(uname) = "SunOS" ] ; then
3514 # If CDDBAVAIL is set to n, no CDDB read is done
3518 # But before we get into business, let us chop off any GREP environmental
3523 if [ -z "$OUTPUTDIR" ]; then
3527 if [ -z "$WAVOUTPUTDIR" ]; then
3528 WAVOUTPUTDIR="$OUTPUTDIR"
3531 # Load system defaults
3532 if [ -r /etc/abcde.conf ]; then
3535 # Load user preference defaults
3536 if [ -r $HOME/.abcde.conf ]; then
3540 # By this time, we need some HTTPGETOPTS already defined.
3541 # If the user has defined a non-default HTTPGET method, we should not be empty.
3543 if [ "$HTTPGETOPTS" = "" ] ; then
3545 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3546 curl) HTTPGETOPTS="-f -s";;
3547 fetch)HTTPGETOPTS="-q -o -";;
3548 ftp) HTTPGETOPTS="-a -V -o - ";;
3549 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3553 # If the CDROM has not been set yet, find a suitable one.
3554 # If this is a devfs system, default to /dev/cdroms/cdrom0
3555 # instead of /dev/cdrom
3556 if [ "$CDROM" = "" ] ; then
3557 if [ -e /dev/cdroms/cdrom0 ]; then
3558 CDROM=/dev/cdroms/cdrom0
3559 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3560 CDROM=/dev/${BASH_REMATCH[1]}
3561 elif [ -e /dev/cdrom ]; then
3563 elif [ -e /dev/sr0 ]; then
3565 elif [ -e /dev/cd0c ]; then
3567 elif [ -e /dev/acd0c ]; then
3569 elif [ -e /dev/disk1 ]; then
3574 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3575 # that's changed to a number to allow for more control. Deal with
3576 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3577 case "$EXTRAVERBOSE" in
3586 # Parse command line options
3587 while getopts 1a:bc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3590 a) ACTIONS="$OPTARG" ;;
3591 A) EXPACTIONS="$OPTARG" ;;
3593 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3594 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3595 d) CDROM="$OPTARG" ;;
3598 e) ERASEENCODEDSTATUS=y ;;
3599 E) ENCODING="$OPTARG" ;;
3603 j) MAXPROCS="$OPTARG" ;;
3606 L) CDDBUSELOCAL=y ;;
3611 o) OUTPUTTYPE="$OPTARG" ;;
3614 r) REMOTEHOSTS="$OPTARG" ;;
3615 R) CDDBLOCALRECURSIVE=y ;;
3616 s) SHOWCDDBFIELDS="$OPTARG" ;;
3617 S) CDSPEEDVALUE="$OPTARG" ;;
3618 t) STARTTRACKNUMBER="$OPTARG" ;;
3619 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3622 echo "This is abcde v$VERSION."
3623 echo "Usage: abcde [options] [tracks]"
3624 echo "abcde -h for extra help"
3627 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3629 X) CUE2DISCID="$OPTARG" ;;
3630 w) COMMENT="$OPTARG" ;;
3631 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3632 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
3633 STARTTRACKNUMBERTAG="y"
3634 COMMENT="CD${OPTARG}"
3635 DISCNUMBER="${OPTARG}"
3637 log error "argument of -W must be integer"
3641 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3646 shift $(($OPTIND - 1))
3648 # Here it comes the worse part of the whole thing. From here until we start
3649 # ripping, we have a mixture of sanity checks, verifications, default settigs
3650 # and other crazy stuff that interdepends, but hey, someone has to do it.
3652 # If NOCDDBQUERY is set, don't query the CDDB server.
3653 if [ "$NOCDDBQUERY" = "y" ]; then
3657 # If the user specified a flac file, then switch to special flac mode
3658 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3659 if [ ! -f "$CDROM" ]; then
3660 log error "the defined file for FLAC ripping cannot be found" >&2
3663 vecho warning "switching to flac CDROMREADERSYNTAX..."
3664 CDROMREADERSYNTAX=flac
3665 # We have a builtin version of cue2discid...
3666 case "$CUE2DISCID" in
3668 *) NEEDCUE2DISCID=y;;
3674 # If the user provided a DISCID, disable eject
3675 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3677 # Check the available cd rippers in the system, from the ones we know.
3678 if [ "$CDROMREADERSYNTAX" = "" ]; then
3679 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3680 if new_checkexec $DEFAULT_CDROMREADER; then
3681 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3685 if [ "$CDROMREADERSYNTAX" = "" ]; then
3686 log error "no cdreader found in your PATH"
3687 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3692 # Decide if we can continue.
3693 if [ "$ONETRACK" = "y" ]; then
3694 # FIXME # remove check as soon as we find out about the other readers
3695 case "$CDROMREADERSYNTAX" in
3697 cdparanoia | libcdio) ;;
3698 cdda2wav | icedax) ;;
3700 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3703 if [ "$BATCHNORM" = "y" ]; then
3704 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3707 if [ "$NOGAP" = "y" ]; then
3708 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3711 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3712 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3713 if [ $# -gt 0 ]; then
3714 log warning "ONETRACK mode selected, grabbing all tracks..."
3717 while [ $# -gt 0 ]; do
3718 # Range parsing code courtesy of Vincent Ho
3719 # Cleaned up to use shell built-ins by Charles Steinkuehler
3720 if [ "${1#*[^0-9-]}" != "$1" ]; then
3721 log error "syntax error while processing track numbers ($1)"
3726 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3727 TRACKQUEUE="$TRACKQUEUE $RSTART"
3728 RSTART=$(( $RSTART + 1 ))
3735 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3736 # List of experimental actions: retag,transcode
3738 # Determine what actions are to be done from $ACTIONS and set the
3739 # following environment variables for them:
3751 ## FIXME ## Lets keep compatibility with -M
3752 [ "$DOCUE" != "y" ] && DOCUE=n
3754 for ACTION in $(echo $ACTIONS | tr , \ )
3757 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
3758 cue) DOCUE=y ; MAKECUEFILE=y ;;
3761 normalize) DONORMALIZE=y; DOREAD=y;;
3762 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3763 encode) DOENCODE=y; DOREAD=y;;
3764 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3765 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3766 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3767 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
3768 playlist) DOCDDB=y; DOPLAYLIST=y;;
3770 getalbumart) GETALBUMART=y;;
3774 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3775 # FIXME # should we abort on error or just inform the user?
3776 log warning "selected both normalize and replaygain actions"
3779 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
3780 case $SHOWCDDBFIELD in
3781 y*|Y*) SHOWCDDBYEAR="y";;
3782 g*|G*) SHOWCDDBGENRE="y";;
3787 # At this point a CDROM has to be defined, so we check it exists.
3788 if [ X"$CDROM" != "X" ] ; then
3789 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
3790 if [ "$OSFLAVOUR" = "FBSD" ]; then
3791 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
3792 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
3793 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
3797 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
3798 log error "CDROM device cannot be found."
3801 # avoid processing if we are not going to hit the CDROM.
3802 elif [ X"$DOREAD" = "Xy" ]; then
3803 log error "CDROM has not been defined or cannot be found"
3807 # USEPIPES pre-tests, before we get into more serious stuff
3808 # Not compatible with:
3809 # - multiple outputs
3811 # - lowdisk algorithm
3813 if [ X"$USEPIPES" = "Xy" ]; then
3814 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
3815 log error "Unix pipes not compatible with multiple outputs"
3818 if [ X"$DONORMALIZE" = "Xy" ]; then
3819 log error "Unix pipes not compatible with normalizer"
3820 # FIXME # Do we need to exit or shall we just disable the mode?
3823 if [ X"$BATCHNORM" = "Xy" ]; then
3824 log error "Unix pipes not compatible with BATCHNORM encoding"
3827 if [ X"$NOGAP" = "Xy" ]; then
3828 log error "Unix pipes not compatible with NOGAP encoding"
3831 if [ X"$DOENCODE" = "Xn" ]; then
3832 vecho warning "Disabling Unix pipes since we are not encoding!"
3835 if [ X"$LOWDISK" = "Xy" ]; then
3836 log error "Unix pipes not compatible with lowdisk algorithm"
3841 # LOWDISK pre-tests, before we get into more problematic stuff
3842 # Not compatible with anything that needs all the files in the hard disc:
3845 if [ X"$LOWDISK" = "Xy" ]; then
3846 if [ X"$BATCHNORM" = "Xy" ]; then
3847 log error "Unix pipes not compatible with BATCHNORM encoding"
3850 if [ X"$NOGAP" = "Xy" ]; then
3851 log error "Unix pipes not compatible with NOGAP encoding"
3856 # BATCHNORM pre-tests, before we get into serious problems
3857 # Not compatible with
3858 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3859 vecho warning "Disabling BATCHNORM since we are not normalizing!"
3863 # Check the encoding format from the ones available in the system, if nothing has been configured.
3864 if [ X"$OUTPUTTYPE" = "X" ]; then
3865 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
3866 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3867 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3868 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
3869 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
3870 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3874 if [ X"$OUTPUTTYPE" = "X" ]; then
3875 log error "no encoder found in the PATH"
3876 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3881 # Decide which CDROM reader we're gonna use
3882 case "$CDROMREADERSYNTAX" in
3884 CDROMREADER="$CDPARANOIA"
3885 CDROMREADEROPTS="$CDPARANOIAOPTS"
3888 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
3889 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
3890 CDROMREADER="$CD_PARANOIA"
3891 CDROMREADEROPTS="$CDPARANOIAOPTS"
3894 CDROMREADER="$CDDA2WAV"
3895 CDROMREADEROPTS="$CDDA2WAVOPTS"
3898 CDROMREADER="$DAGRAB"
3899 CDROMREADEROPTS="$DAGRABOPTS"
3903 CDROMREADEROPTS="$PIRDOPTS"
3906 CDROMREADER="$CDDAFS"
3907 CDROMREADEROPTS="$CDDAFSOPTS"
3911 CDROMREADEROPTS="$FLACOPTS"
3915 # There's only one normalize...
3916 case "$NORMALIZERSYNTAX" in
3918 NORMALIZER="$NORMALIZE"
3919 NORMALIZEROPTS="$NORMALIZEOPTS"
3923 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3924 case "$OUTPUTTYPE" in *:*)
3925 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
3926 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
3928 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3929 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3930 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3931 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3932 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3933 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3934 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3935 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3936 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3939 # Allows commandline selection of options while using multiple outputs.
3940 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
3941 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
3942 TEMPOUTPUT=${OUTPUT%%:*}
3943 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
3945 OUTPUTTYPE="$TEMPOUTPUTTYPE"
3949 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
3950 # for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as and
3951 # wavpack for wvs...
3953 # Getting ready for multiple output changes
3954 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3958 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
3959 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
3960 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
3961 OGGOUTPUTCONTAINER=ogg
3964 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
3965 OPUSOUTPUTCONTAINER=opus
3968 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
3969 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
3970 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
3973 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
3974 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
3975 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
3976 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
3979 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
3980 # [ "$DOREPLAYGAIN" = "y" ] &&
3983 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
3984 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
3987 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
3989 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
3992 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
3993 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
3996 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
3998 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
3999 # compiled without libmp4v2... Andrew.
4002 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4003 [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4004 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4007 if [ "$KEEPWAVS" = "y" ]; then
4008 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4012 *) log error "Invalid OUTPUTTYPE defined"
4018 # decide which encoder
4019 case "$MP3ENCODERSYNTAX" in
4021 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4025 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
4026 MP3ENCODER="$TOOLAME"
4029 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4033 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4034 MP3ENCODER="$BLADEENC"
4037 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4041 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4042 MP3ENCODER="$XINGMP3ENC"
4045 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4046 MP3ENCODER="$MP3ENC"
4049 case "$OGGENCODERSYNTAX" in
4051 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4052 OGGENCODER="$VORBIZE"
4055 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4056 OGGENCODER="$OGGENC"
4059 case "$OPUSENCODERSYNTAX" in
4061 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4062 OPUSENCODER="$OPUSENC"
4065 case "$FLACENCODERSYNTAX" in
4067 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4069 if [ "$DOREPLAYGAIN" = "y" ]; then
4070 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4072 # FLAC streams can be encapsulated on a Ogg transport layer
4073 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4074 log error "FLAC on an Ogg container is not yet supported"
4075 log error "due to problem with adding comments to such files"
4077 FLACOUTPUTCONTAINER=ogg
4079 FLACOUTPUTCONTAINER=flac
4083 case "$SPEEXENCODERSYNTAX" in
4085 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4086 SPEEXENCODER="$SPEEXENC"
4089 case "$MPCENCODERSYNTAX" in
4091 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4092 MPCENCODER="$MPCENC"
4095 case "$WVENCODERSYNTAX" in
4097 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4101 case "$APENCODERSYNTAX" in
4103 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4107 case "$AACENCODERSYNTAX" in
4108 # Some elaborate 'if' work to keep backward compatability for those
4109 # who don't realise that AACENCOPTS does not work with abcde from
4110 # version 2.6.1 onwards.
4112 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4113 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4116 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4121 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4122 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4123 AACENCODER="$NEROAACENC"
4125 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4126 AACENCODER="$NEROAACENC"
4130 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4131 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4132 AACENCODER="$FDKAAC"
4134 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4135 AACENCODER="$FDKAAC"
4145 TAGGEROPTS="$ID3OPTS"
4150 TAGGEROPTS="$ID3V2OPTS"
4154 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4155 # trouble with CDDBPROTO=5 (which we test here) but also
4156 # with cached cddb files in latin1 (which we cannot test).
4157 if [ "$CDDBPROTO" -lt 6 ]; then
4158 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4161 # eyeD3 version 0.7 changed syntax
4162 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4163 # only if it offers the --set-encoding, assume <= 0.6.x
4165 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4167 # anything wrong, any failure, assume >= 0.7
4169 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4173 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4178 # NOGAP is specific to lame. Other encoders fail ...
4179 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4180 log warning "the NOGAP option is specific to lame. Deactivating..."
4185 case "$CUEREADERSYNTAX" in
4187 CUEREADEROPTS="${CDROM}"
4192 # which information retrieval tool are we using?
4198 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4199 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4200 log error "FLAC on an Ogg container is not yet supported"
4201 log error "due to problem with adding comments to such files"
4203 OGGOUTPUTCONTAINER=ogg.ogg
4204 FLACOUTPUTCONTAINER=flac.ogg
4205 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4208 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4210 if [ "$ENCNICE" ]; then
4211 ENCNICE="-n $ENCNICE"
4213 if [ "$READNICE" ]; then
4214 READNICE="-n $READNICE"
4216 if [ "$DISTMP3NICE" ]; then
4217 DISTMP3NICE="-n $DISTMP3NICE"
4220 # Don't check for stuff if it's not needed
4221 if [ "$REMOTEHOSTS" ]; then
4224 if [ "$DONORMALIZE" = "y" ]; then
4227 if [ "$EJECTCD" = "y" ]; then
4230 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4231 if [ "$CDDBMETHOD" = "cddb" ]; then
4233 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4237 if [ "$DOCUE" = "y" ]; then
4241 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4242 case "$CDROMREADERSYNTAX" in
4243 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4244 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4245 ### FIXME ### translate "cue2discid" from python to bash
4246 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4251 if [ "$GETALBUMART" = "y" ]; then
4256 ###USEPIPESSUPPORT###
4258 # Rippers with USEPIPE support
4259 PIPERIPPER_cdparanoia="-"
4260 PIPERIPPER_libcdio="-"
4261 # Note that by default in abcde cdda2wav redirects to icedax.
4262 PIPERIPPER_cdda2wav="-"
4263 PIPERIPPER_debug="-"
4264 PIPERIPPER_flac="-c "
4267 # Encoders with USEPIPE support
4270 PIPE_bladeenc="stdin"
4278 # Both neroAacEnc and fdkaac seem to manage without the addition of
4279 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4280 # in this manner. Andrew.
4284 # Figure out if we can use pipes with the ripper/encoder combination
4286 if [ "$USEPIPES" = "y" ]; then
4287 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4290 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4292 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4294 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4296 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4298 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4300 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4302 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4304 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4306 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4308 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4309 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4310 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4311 log error "no support for pipes with given ripper"
4312 log error "read the USEPIPES file from the source tarball to get help."
4313 log error "On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
4316 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4317 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4318 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4319 log error "no support for pipes with given encoder"
4320 log error "read the USEPIPES file from the source tarball to help"
4321 log error "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
4326 # Make sure a buncha things exist
4327 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4328 $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4329 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER \
4330 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4331 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4332 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4333 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4334 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4335 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4336 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4337 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4343 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4344 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4345 # these files). The resulting files are actually ADTS streams which belong in an
4346 # aac container and with some version sniffing this is all cleaned up below. If
4347 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4349 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4350 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4351 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4352 echo "WARNING: Your copy of Faac does not have mp4 support"
4353 echo "WARNING: Encoding untagged files to aac..."
4356 echo "Using Faac to Tag AAC Tracks..."
4360 # And last but not least, check if we can diff between files. We do not abort,
4361 # since diffing is not critical...
4362 if [ -x $(which $DIFF) ]; then :; else
4363 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4367 ## Now that we have metaflac, check if we need cue2discid
4368 #case $CDROMREADERSYNTAX in
4370 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4371 # if [ "$TRACKINFO" = "" ]; then
4372 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4377 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4378 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4379 HTTPGET="$HTTPGET $HTTPGETOPTS"
4381 # Here it used to say:
4382 # One thousand lines in, we can start doing stuff with things
4383 # Well, right now we are at line 3737 ;)
4385 # Export needed things so they can be read in this subshell
4386 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4387 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4389 if [ "$DOREAD" = "y" ]; then
4390 # User-definable function to set some things. Use it for
4391 # - closing the CD tray with eject -t
4392 # - set the CD speed value with eject -x
4393 vecho -n "Executing customizable pre-read function... "
4395 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4400 # Get ABCDETEMPDIR created and status file initialized
4403 if [ "$DOCDDB" = "y" ]; then
4404 # start with a sane default:
4405 CDDBLOCALSTATUS=notfound
4406 if [ $CDDBUSELOCAL = "y" ]; then
4409 if checkstatus cddb-choice > /dev/null; then
4412 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4413 case "$CDDBMETHOD" in
4424 CHOICE=$(checkstatus cddb-choice)
4425 if [ "$CHOICE" = 0 ] ; then
4426 # We don't have any information at all; try to fall back
4427 # to CD-Text for basic information
4428 vecho "No CDDB information found, trying cdtext from the CD"
4434 eval "$($CDDBTOOL parse "$CDDBDATA")"
4437 # Before reading tracks, we set the speed of the device
4439 if [ X"$CDSPEEDVALUE" != "X" ]; then
4440 case "$CDROMREADERSYNTAX" in
4441 cdparanoia|libcdio|debug) ;;
4448 # Define the first and last track, since we might need them later in several places
4449 FIRSTTRACK=$( get_first $TRACKQUEUE )
4450 LASTTRACK=$( get_last $TRACKQUEUE )
4452 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4453 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4454 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4455 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4458 if checkstatus onetrack ; then ONETRACK=y ; fi
4460 if [ "$ONETRACK" = "y" ]; then
4461 # Reuse the CUEFILE in case we created it (now or in a previous run)
4462 if CUEFILE=$(checkstatus cuefile); then
4467 # Create playlist if needed (backgroundable) and start reading in tracks
4471 if [ ! "$ONETRACK" = "y" ]; then
4472 if [ "$DOPLAYLIST" = "y" ]; then
4473 echo Creating playlist... >&2
4478 if [ "$GETALBUMART" = "y" ]; then
4482 # For the lowdisk option, only one program is running at once so the encoder
4483 # can be unsilenced right away.
4484 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4485 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4488 if [ "$ONETRACK" = "y" ]; then
4489 TRACKS="$FIRSTTRACK"
4490 if [ "$USEPIPES" = "y" ]; then
4491 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4492 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4495 if checkstatus readtrack-$FIRSTTRACK; then :; else
4496 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4500 for UTRACKNUM in $TRACKQUEUE
4502 if [ "$DOREAD" = "y" ]; then
4503 if [ "$USEPIPES" = "y" ]; then
4504 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4505 # Read, pipe, shut up!
4506 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4509 if checkstatus readtrack-$UTRACKNUM; then :; else
4510 do_cdread $UTRACKNUM
4512 if [ "$?" != "0" ]; then
4513 # CD read failed - don't give the goahead to
4520 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4523 # If we are not reading, set the encode output to loud already, so
4524 # that we can see the output of the first track.
4525 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4526 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4528 echo NEXTTRACK # Get the encoder machine churning again
4529 if [ "$DOREAD" = "y" ]; then
4530 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4531 until checkstatus encodetrack-$UTRACKNUM
4533 if checkerrors encodetrack-$UTRACKNUM; then
4544 # Now that we're done the encoding can be loud again -
4545 # if we're not using SMP.
4546 if [ "$MAXPROCS" = "1" ]; then
4547 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4550 # All tracks read, start encoding.
4551 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4555 # Execute the user-defined post_read function before ejecting CD
4558 # We are now finished with the cdrom - it can be safely ejected. Note that
4559 # abcde will not have completed yet.
4560 if [ "$EJECTCD" = "y" ]; then
4561 # We check if the disk we are processing is actually the disk inside the
4562 # CD tray. If not, we do not eject the CD, since it might be so that the
4563 # user ejected it manually.
4564 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4565 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4566 # More FreeBSD bits.
4567 if [ X"$(uname)" = X"FreeBSD" ] ; then
4568 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4569 # but in this script EJECT is in the envionment and names the program
4572 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4573 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4574 $eject $EJECTOPTS $cd
4575 elif [ X"$(uname)" = X"Darwin" ] ; then
4576 diskutil eject ${CDROM#/dev/} 0
4577 elif [ -x $(which $EJECT) ]; then
4578 $EJECT $EJECTOPTS "$CDROM"
4585 ## Do we need to pre-process
4586 #if [ x"$PREPROCESS" = "x" ] ; then
4589 # for PRETRACKNUM in $TRACKQUEUE
4592 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4594 # until [ $PREPROCEED ]
4596 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4597 # # all locations are working, wait and try again later
4598 # if [ ! $PREPROCEED ]; then sleep 3; fi
4600 # ( do_preprocess $PRETRACKNUM
4608 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4610 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4611 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4612 if [ "$GOAHEAD" = "NO" ]; then break; fi
4613 for LASTTRACK in $TRACKQUEUE; do :; done
4614 if checkstatus readtrack-$LASTTRACK; then
4615 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4616 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4617 if checkerrors batch-normalize; then exit 1; fi
4619 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4620 if [ "$DONORMALIZE" = "y" ]; then
4621 for UTRACKNUM in $TRACKQUEUE
4623 if checkstatus readtrack-$UTRACKNUM; then
4624 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4628 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4629 if checkerrors nogap-encode; then exit 1; fi
4634 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4635 if [ "$ONETRACK" = "y" ] ; then
4636 TRACKQUEUE="$FIRSTTRACK"
4637 TRACKS="$FIRSTTRACK"
4640 # Do the encoding, including parallelization of remote encoding
4641 # Figure out where each track is going to be encoded
4642 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4643 if [ "$MAXPROCS" != "0" ]; then
4644 for NUM in $(f_seq_row 1 "$MAXPROCS")
4646 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
4650 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
4651 for UTRACKNUM in $TRACKQUEUE
4654 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4655 if [ "$GOAHEAD" = "NO" ]; then break; fi
4656 # find out where this track is to be encoded
4657 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4658 # Make sure we have a place to encode this, if not, exit stage right
4659 if [ -z "$ENCODELOCATIONS" ]; then
4665 for LOCATION in $ENCODELOCATIONS
4667 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4668 # check first if a track has ever been assigned to this location
4669 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
4670 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4671 if checkerrors encodetrack-$PREVIOUSTRACK; then
4672 for TEMPLOCATION in $ENCODELOCATIONS
4674 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4675 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
4678 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
4683 # We're still here, this location must have been previously assigned,
4684 # and last completed without error - check if it's done with the
4685 # previous track yet
4686 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
4688 # all locations are working, wait and try again later
4689 if [ ! $PROCEED ]; then sleep 3; fi
4691 # Record the location we're about to encode the next track at
4692 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4694 # Don't proceed with the rest of the loop if we can't encode
4695 if [ "$ABORT" ]; then continue; fi
4696 ## FIXME ## Add here
4697 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4698 # Set TRACKNUM, TRACKNAME
4699 if [ -e "$CDDBDATA" ]; then
4700 if [ "$ONETRACK" = "y" ]; then
4702 TRACKNUM="$FIRSTTRACK"
4706 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
4707 getcddbinfo TRACKNAME
4711 # You can't encode a file which needs to be normalized before finishing
4712 # You can't tag a file before it's finished encoding -
4713 # thus all of this is backgrounded together
4715 if [ "$DONORMALIZE" = "y" ]; then
4716 if checkstatus readtrack-$UTRACKNUM; then
4717 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4720 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4721 if checkstatus readtrack-$UTRACKNUM; then
4722 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4723 if [ "$DONORMALIZE" = "y" ]; then
4724 if checkstatus normalizetrack-$UTRACKNUM; then
4725 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4728 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4732 if [ "$DOTAG" = "y" ]; then
4733 if checkstatus encodetrack-$UTRACKNUM; then
4734 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
4736 # Lets tag the cue file
4737 if checkstatus cleancuefile >/dev/null; then :; else
4738 if checkstatus cuefile >/dev/null ; then
4743 if [ "$DOMOVE" = "y" ]; then
4744 if checkstatus tagtrack-$UTRACKNUM; then
4745 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
4752 # Go through it again and make sure there's no distmp3 stragglers, otherwise
4753 # we'll delete the files they're working on
4754 # Do NOT play ball if there is no ball to play (so ABORT if needed)
4755 ## FIXME ## Check also for files which are encoded using PIPEs.
4756 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
4761 for LOCATION in $ENCODELOCATIONS
4763 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4764 # "How can he give us a status update, if he's DEAD?"
4765 if checkstatus encodetrack-$CHECKTRACK; then
4768 # Nothing to see here please go quietly back to your homes
4769 if [ -z "$CHECKTRACK" ]; then continue; fi
4770 # You're still here? Maybe there is something...
4771 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
4774 if [ ! $PROCEED ]; then sleep 5; fi
4777 # If the above didn't catch the stragglers, this will
4779 if [ "$DOREPLAYGAIN" = "y" ]; then
4783 # Execute the user-defined post_encode function before cleaning up
4786 # Check to see if run_command logged any errors
4787 if [ -f "$ABCDETEMPDIR/errors" ]; then
4788 log error "The following commands failed to run:"
4789 cat "$ABCDETEMPDIR/errors"
4793 if [ "$KEEPWAVS" = "y" ];then
4797 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
4798 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
4799 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
4800 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
4801 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
4802 log warning "The encoded formats does not match with the moved ones"
4803 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
4804 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
4805 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
4809 if [ "$DOCLEAN" = "y" ]; then
4810 # Wipe all the evidence
4811 # Gimme gimme gimme some more time!
4813 rm -rf "$ABCDETEMPDIR"
4816 echo "Finished. Not cleaning $ABCDETEMPDIR."