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 # Copyright (c) 2015- Andrew Strong <andrew.david.strong@gmail.com>
7 # This code is hereby licensed for public consumption under either the
8 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
10 # You should have received a copy of the GNU General Public License along
11 # with this program; if not, write to the Free Software Foundation, Inc.,
12 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform:"
24 echo " cddb,read,getalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
25 #echo "-A Experimental actions (retag, transcode)"
26 echo "-b Enable batch normalization"
28 echo " Specify a configuration file (overrides system and user config files)"
30 echo " Specify discid to resume from (only needed if you no longer have the cd)"
32 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
33 echo "-D Debugging mode (equivalent to sh -x abcde)"
34 echo "-e Erase encoded track information from status file"
35 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
36 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
37 echo "-G Get album art by using the 'getalbumart' action"
38 echo "-h This help information"
39 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
40 echo "-j <#> Number of encoder processes to run at once (localhost)"
41 echo "-k Keep the wav tracks for later use"
42 echo "-l Use low disk space algorithm"
43 echo "-L Use local CDDB storage directory"
44 echo "-m Modify playlist to include CRLF endings, to comply with some players"
45 #echo " WARNING: Deprecated. Use \"cue\" action"
46 #echo "-M Create a CUE file"
47 echo "-n No lookup. Don't query CDDB, just create and use template"
48 echo "-N Noninteractive. Never prompt for anything"
49 echo "-o <type1[,type2]...>"
50 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,mka,wv,ape,mp2,tta). Defaults to vorbis"
51 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
52 echo "-P Use UNIX pipes to read+encode without wav files"
53 echo "-r <host1[,host2]...>"
54 echo " Also encode on these remote hosts"
56 echo " Show fields from the CDDB info (year,genre)"
57 echo "-S <#> Set the CD speed"
58 echo "-t <#> Start the track numbering at a given number"
59 echo "-T <#> Same as -t but modifies tag numbering"
60 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
61 echo "-v Show version number and exit"
62 echo "-V Be a bit more verbose about what is happening behind the scenes"
63 echo "-x Eject CD after all tracks are read"
65 echo " Add a comment to the CD tracks"
66 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
67 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
69 echo "Tracks is a space-delimited list of tracks to grab."
70 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
72 #echo "Double hyphens are used to concatenate tracks"
77 echo "$@" >> "$ABCDETEMPDIR/status"
80 # log [level] [message]
82 # log outputs the right message in a common format
88 error) >&2 echo "[ERROR] abcde: $@" >&2 ;;
89 warning) >&2 echo "[WARNING] $@" >&2 ;;
90 info) >&4 echo "[INFO] $@" ;;
94 # Functions to replace the need of seq, which is too distribution dependent.
98 while [ $i -ne `expr $2 + 1` ]
108 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
109 while [ $i -ne `expr $2 + 1` ]
116 log error "syntax error while processing track numbers ($i)"
121 # Functions to replace the need of awk {print $1} and {print $NF}
124 if [ X"$1" = "X" ]; then
125 for first in `cat`; do
136 if [ X"$1" = "X" ]; then
137 for stdin in `cat`; do
141 for last in $@ ; do :; done
146 # checkstatus [blurb]
147 # Returns "0" if the blurb was found, returns 1 if it wasn't
148 # Puts the blurb content, if available, on stdout.
149 # Otherwise, returns "".
152 # Take the last line in the status file if there's multiple matches
154 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
156 if [ -z "$BLURB" ]; then
161 # See if there's a = in it
162 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
163 echo "$(echo $BLURB | cut -f2- -d=)"
169 # checkwarnings [blurb]
170 # Returns "0" if the blurb was found (meaning there was an warning),
171 # returns 1 if it wasn't (yes this is a little backwards).
172 # Does not print the blurb on stdout.
173 # Otherwise, returns "".
176 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
179 # Take the last line in the status file if there's multiple matches
181 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
183 if [ -z "$BLURB" ]; then
184 # negative, we did not have a negative...
187 # affirmative, we had a negative...
192 # checkerrors [blurb]
193 # Returns "0" if the blurb was found (meaning there was an error),
194 # returns 1 if it wasn't (yes this is a little backwards).
195 # Does not print the blurb on stdout.
196 # Otherwise, returns "".
199 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
202 # Take the last line in the status file if there's multiple matches
204 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
206 if [ -z "$BLURB" ]; then
207 # negative, we did not have a negative...
210 # affirmative, we had a negative...
216 # Finds the right pager in the system to display a file
220 # Use the debian sensible-pager wrapper to pick the pager
221 # user has requested via their $PAGER environment variable
222 if [ -x "/usr/bin/sensible-pager" ]; then
223 /usr/bin/sensible-pager "$PAGEFILE"
224 elif [ -x "$PAGER" ]; then
225 # That failed, try to load the preferred editor, starting
226 # with their PAGER variable
228 # If that fails, check for less
229 elif [ -x /usr/bin/less ]; then
230 /usr/bin/less -f "$PAGEFILE"
231 # more should be on all UNIX systems
232 elif [ -x /bin/more ]; then
233 /bin/more "$PAGEFILE"
235 # No bananas, just cat the thing
240 # run_command [blurb] [command...]
241 # Runs a command, silently if necessary, and updates the status file
247 # See if this is supposed to be silent
248 if [ "$(checkstatus encode-output)" = "loud" ]; then
252 # Special case for SMP, since
253 # encoder output is never displayed, don't mute echos
254 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
263 normalize|normalize-audio)
264 if [ "$RETURN" = "2" ]; then
265 # File was already normalized.
270 if [ "$RETURN" != "0" ]; then
271 # Put an error in the errors file. For various reasons we
272 # can't capture a copy of the program's output but we can
273 # log what we attempted to execute and the error code
274 # returned by the program.
275 if [ "$BLURB" ]; then
278 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
279 return $RETURN # Do not pass go, do not update the status file
281 if [ "$BLURB" ]; then
282 echo $BLURB >> "$ABCDETEMPDIR/status"
286 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
287 # distributed under the terms of the GNU GPL v2 or later, at your option
289 # Function to determine if a word contains a slash.
298 # Function to give the relative path from one file to another.
299 # Usage: relpath fromfile tofile
300 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
301 # (the result would be Album/Song.mp3)
302 # Output is relative path to $2 from $1 on stdout
304 # This code has the following restrictions:
305 # Multiple ////s are not collapsed into single /s, with strange effects.
306 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
307 # If FR is a directory it must have a trailing /
315 /*) ;; # No processing is needed for absolute paths
317 # Loop through common prefixes, ignoring them.
318 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
320 FR="$(echo "$FR" | cut -d/ -f2-)"
321 TO="$(echo "$TO" | cut -d/ -f2-)"
323 # Loop through directory portions left in FR, adding appropriate ../s.
326 FR="$(echo "$FR" | cut -d/ -f2-)"
337 if [ ! "$@" = "" ]; then
338 # Cut off any command-line option we added in
339 X=$(echo $@ | cut -d' ' -f2)
340 if [ "$(which $X)" = "" ]; then
342 elif [ ! -x $(which $X) ]; then
351 if [ ! "$@" = "" ]; then
352 # Cut off any command-line option we added in
353 X=$(echo $@ | cut -d' ' -f2)
354 # Test for built-in abcde.function
355 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
356 if [ "$(which $X)" = "" ]; then
357 log error "$X is not in your path." >&2
358 log info "Define the full path to the executable if it exists on your system." >&2
359 if [ -e /etc/debian_* ] ; then
361 oggenc) MISSING_PACKAGE=vorbis-tools ;;
362 lame|flac) MISSING_PACKAGE=$X ;;
364 log info "Hint: sudo apt-get install $MISSING_PACKAGE" >&2
367 elif [ ! -x "$(which $X)" ]; then
368 log error "$X is not executable." >&2
374 # diffentries <filename> <max_value> <entry1>,<entry2>
375 # max_value: the range of entries goes from 1 to <max_value>
380 local CDDBDIFFCHOICES=$1
382 local CDDBDIFFCHOICE="$@"
383 if [ ! X"$DIFF" = "X" ]; then
384 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
385 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
386 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
387 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
388 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
389 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
391 # We parse the 2 choices to diff, store them in temporary files and diff them.
392 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
393 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
395 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
396 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
397 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
398 page "$ABCDETEMPDIR/$FILENAME.diff"
400 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
404 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
409 # Finds an specific field from cddbinfo
414 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
417 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
420 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
426 # Get the track number we are going to use for different actions
429 if [ -n "$STARTTRACKNUMBER" ] ; then
430 # Get the trackpadding from the current track, also trim whitespace for MacOSX
431 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
432 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
434 TRACKNUM=${UTRACKNUM}
440 # Calculate cddb disc ids without requiring specialized helper programs.
441 # largely copied from cd-discid and musicbrainz examples. some of the steps
442 # don't make sense, but they're necessary to match the ids generated by other
445 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
446 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
447 # 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
448 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
449 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
450 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
452 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
455 if [ X"$LEADOUT" = "X" ]; then
456 log warning "Error trying to calculate disc ids without lead-out information."
460 # default to a two second lead-in
462 LEADIN=${LEADIN:=150}
464 # number of cdframes per second
467 # reset cddb checksum for cddb disc-id calululation
471 for OFFSET in $(echo $OFFSETS)
473 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
475 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
476 while [ $OFFSETTIME -gt 0 ]; do
477 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
478 OFFSETTIME=$(($OFFSETTIME / 10))
483 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
485 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
486 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
488 case "$CDDBMETHOD" in
490 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
493 # FIXME: don't assume the first track is 1
494 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
495 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
499 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
504 if checkstatus replaygain; then :; else
505 run_command "" echo "Adding replaygain information..."
506 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
510 OUTPUT=$OGGOUTPUTCONTAINER
513 OUTPUT=$OPUSOUTPUTCONTAINER
516 OUTPUT=$FLACOUTPUTCONTAINER
524 for UTRACKNUM in $TRACKQUEUE
526 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
527 getcddbinfo TRACKNAME
529 TRACKFILE="$(mungefilename "$TRACKNAME")"
530 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
531 ALBUMFILE="$(mungefilename "$DALBUM")"
532 GENRE="$(mungegenre "$GENRE")"
533 YEAR=${CDYEAR:-$CDYEAR}
535 if [ "$ONETRACK" = "y" ]; then
536 if [ "$VARIOUSARTISTS" = "y" ]; then
537 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
539 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
542 if [ "$VARIOUSARTISTS" = "y" ]; then
543 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
545 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
548 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
549 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
553 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
554 #run_command replaygain-flac true
557 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
560 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
563 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
566 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
571 if checkerrors "replaygain-.{3,6}"; then :; else
572 run_command replaygain true
577 # This code splits the a Various Artist track name from one of the following
580 # forward: Artist / Track
581 # forward-dash: Artist - Track
582 # reverse: Track / Artist
583 # reverse-dash: Track - Artist
584 # colon: Artist: Track
585 # trailing-paren: Artist (Track)
588 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
591 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
592 case "$VARIOUSARTISTSTYLE" in
594 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
595 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
596 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
599 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
600 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
601 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
604 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
605 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
606 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
609 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
610 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
611 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
614 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
615 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
616 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
619 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
620 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
621 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
624 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
625 TRACKARTIST="Various"
627 TRACKARTIST="$DARTIST"
632 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
636 "classic rock") id=1 ;;
654 "industrial") id=19 ;;
655 "alternative") id=20 ;;
657 "death metal") id=22 ;;
659 "soundtrack") id=24 ;;
660 "euro-techno") id=25 ;;
664 "jazz+funk") id=29 ;;
667 "classical") id=32 ;;
668 "instrumental") id=33 ;;
672 "sound clip") id=37 ;;
675 "alt. rock") id=40 ;;
680 "meditative") id=45 ;;
681 "instrum. pop") id=46 ;;
682 "instrum. rock") id=47 ;;
686 "techno-indust.") id=51 ;;
687 "electronic") id=52 ;;
689 "eurodance") id=54 ;;
691 "southern rock") id=56 ;;
696 "christian rap") id=61 ;;
697 "pop/funk"|"pop / funk") id=62 ;;
699 "native american") id=64 ;;
702 "psychadelic") id=67 ;;
704 "showtunes") id=69 ;;
708 "acid punk") id=73 ;;
709 "acid jazz") id=74 ;;
713 "rock & roll") id=78 ;;
714 "hard rock") id=79 ;;
716 "folk/rock") id=81 ;;
717 "national folk") id=82 ;;
724 "bluegrass") id=89 ;;
725 "avantgarde") id=90 ;;
726 "gothic rock") id=91 ;;
727 "progress. rock") id=92 ;;
728 "psychadel. rock") id=93 ;;
729 "symphonic rock") id=94 ;;
730 "slow rock") id=95 ;;
733 "easy listening") id=98 ;;
739 "chamber music") id=104 ;;
741 "symphony") id=106 ;;
742 "booty bass") id=107 ;;
744 "porn groove") id=109 ;;
746 "slow jam") id=111 ;;
750 "folklore") id=115 ;;
752 "power ballad") id=117 ;;
753 "rhythmic soul") id=118 ;;
754 "freestyle") id=119 ;;
756 "punk rock") id=121 ;;
757 "drum solo") id=122 ;;
758 "a capella") id=123 ;;
759 "euro-house") id=124 ;;
760 "dance hall") id=125 ;;
762 "drum & bass") id=127 ;;
763 "club-house") id=128 ;;
764 "hardcore") id=129 ;;
768 "negerpunk") id=133 ;;
769 "polsk punk") id=134 ;;
771 "christian gangsta rap") id=136 ;;
772 "heavy metal") id=137 ;;
773 "black metal") id=138 ;;
774 "crossover") id=139 ;;
775 "contemporary christian")id=140 ;;
776 "christian rock") id=141 ;;
777 "merengue") id=142 ;;
779 "thrash metal") id=144 ;;
782 "synthpop") id=147 ;;
783 "rock/pop"|"rock / pop") id=148 ;;
790 # do_tag [tracknumber]
791 # id3 tags a filename
793 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
794 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
797 COMMENTOUTPUT="$(eval echo ${COMMENT})"
798 if [ -z "$COMMENTOUTPUT" ]; then
799 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
801 if [ "$CDDBMETHOD" = "cddb" ]; then
802 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
804 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
805 # If we want to start the tracks with a given number, we need to modify the
806 # TRACKNUM value before evaluation
807 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
810 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
814 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
815 GENREID=$(do_getgenreid "${CDGENRE}")
816 # Set TPE2 in case we have a Various Artists rip.
818 if [ "$VARIOUSARTISTS" = "y" ]; then
824 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
825 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
826 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
827 -y "$CDYEAR" -g "$GENREID" \
828 -T "${TRACKNUM:-$1}" \
829 "$ABCDETEMPDIR/track$1.$OUTPUT"
832 # FIXME # track numbers in mp3 come with 1/10, so we cannot
833 # happily substitute them with $TRACKNUM
834 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
835 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
836 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
837 -y "$CDYEAR" -g "$GENREID" \
838 -T "${TRACKNUM:-$1}/$TRACKS" \
839 ${TPE2:+--TPE2 "$TPE2"} \
840 "$ABCDETEMPDIR/track$1.$OUTPUT"
843 # FIXME # track numbers in mp3 come with 1/10, so we cannot
844 # happily substitute them with $TRACKNUM
845 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
846 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
847 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
848 -y "$CDYEAR" -g "$GENREID" \
849 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
850 "$ABCDETEMPDIR/track$1.$OUTPUT"
853 # FIXME # track numbers in mp3 come with 1/10, so we cannot
854 # happily substitute them with $TRACKNUM
856 eyed3_06) addopts=( \
857 ${ENCODING:+--set-encoding="$ENCODING"} \
858 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
859 # We set 'recording-date' so the date tag will show
860 # in Audacious, vlc and friends... Andrew.
861 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
862 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
865 ${ENCODING:+--encoding="$ENCODING"} \
866 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
867 # We set 'recording-date' so the date tag will show
868 # in Audacious, vlc and friends... Andrew.
869 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
870 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
873 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
875 -a "$TRACKARTIST" -t "$TRACKNAME" \
876 -G "$GENREID" -n "${TRACKNUM:-$1}" \
877 ${TRACKNUM:+-N "$TRACKS"} \
879 "$ABCDETEMPDIR/track$1.$OUTPUT"
882 log error "Internal error: ID3SYNTAX has an illegal value"
888 case "$OGGENCODERSYNTAX" in
890 # vorbiscomment can't do in-place modification, mv the file first
891 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
892 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
896 # https://www.xiph.org/vorbis/doc/v-comment.html
898 echo ARTIST="$TRACKARTIST"
900 echo TITLE="$TRACKNAME"
901 if [ -n "$CDYEAR" ]; then
904 if [ -n "$CDGENRE" ]; then
905 echo GENRE="$CDGENRE"
907 echo TRACKNUMBER=${TRACKNUM:-$1}
908 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
909 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
910 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
911 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
912 echo TRACKTOTAL="${TRACKS}"
913 if [ -n "$DISCNUMBER" ]; then
914 echo DISCNUMBER="$DISCNUMBER"
916 echo CDDB=$CDDBDISCID
917 if [ "$(eval echo ${COMMENT})" != "" ]; then
918 case "$COMMENTOUTPUT" in
919 *=*) echo "$COMMENTOUTPUT";;
920 *) echo COMMENT="$COMMENTOUTPUT";;
923 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
924 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
925 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
926 # Doublecheck that the commented file was created
927 # successfully before wiping the original
928 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
929 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
931 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
937 run_command tagtrack-$OUTPUT-$1 true
940 run_command tagtrack-$OUTPUT-$1 true
944 echo ARTIST="$TRACKARTIST"
946 echo TITLE="$TRACKNAME"
947 if [ -n "$CDYEAR" ]; then
950 if [ -n "$CDGENRE" ]; then
951 echo GENRE="$CDGENRE"
953 echo TRACKNUMBER="${TRACKNUM:-$1}"
954 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
955 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
956 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
957 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
958 echo TRACKTOTAL="${TRACKS}"
959 if [ -n "$DISCNUMBER" ]; then
960 echo DISCNUMBER="$DISCNUMBER"
962 echo CDDB="$CDDBDISCID"
963 if [ "$(eval echo ${COMMENT})" != "" ]; then
964 case "$COMMENTOUTPUT" in
965 *=*) echo "$COMMENTOUTPUT";;
966 *) echo COMMENT="$COMMENTOUTPUT";;
969 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
970 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
973 run_command tagtrack-$OUTPUT-$1 true
976 run_command tagtrack-$OUTPUT-$1 true
979 run_command tagtrack-$OUTPUT-$1 true
982 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
983 # Console port (mac) used for encoding does not have the ability to tag.
984 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
985 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
986 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
989 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
990 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
991 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
992 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
993 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
994 "$ABCDETEMPDIR/track$1.mp2"
997 run_command tagtrack-$OUTPUT-$1 true
1000 case "$AACENCODERSYNTAX" in
1002 # We will use inline tagging...
1003 run_command tagtrack-$OUTPUT-$1 true
1006 # Tag post encode with neroAacTag...
1007 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
1008 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
1009 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1012 run_command tagtrack-$OUTPUT-$1 true
1015 run_command tagtrack-$OUTPUT-$1 true
1018 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1019 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1020 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$ATOMICPARSLEY" "$ABCDETEMPDIR/track$1.m4a" \
1021 --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum=${TRACKNUM:-$1} \
1022 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
1025 run_command tagtrack-$OUTPUT-$1 true
1030 # We use mid3v2 tagging for True Audio:
1031 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1032 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1033 "$ABCDETEMPDIR/track$1.tta"
1036 run_command tagtrack-$OUTPUT-$1 true
1040 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1041 run_command tagtrack-$1 true
1047 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1050 # The commands here don't go through run_command because they're never
1051 # supposed to be silenced
1052 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1053 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1057 case "$MP3ENCODERSYNTAX" in
1062 for UTRACKNUM in $TRACKQUEUE
1064 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1066 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1068 if [ "$RETURN" != "0" ]; then
1069 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1071 for UTRACKNUM in $TRACKQUEUE
1073 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1074 #run_command encodetrack-$UTRACKNUM true
1083 if checkerrors "nogap-encode"; then :; else
1084 if [ ! "$KEEPWAVS" = "y" ] ; then
1085 if [ ! "$KEEPWAVS" = "move" ] ; then
1090 # Other encoders fall through to normal encoding as the tracks have not
1091 # been entered in the status file.
1094 # do_encode [tracknumber] [hostname]
1095 # If no hostname is specified, encode locally
1097 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1098 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1101 if [ "$USEPIPES" = "y" ]; then
1104 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1107 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1110 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1113 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1116 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1119 TEMPARG="PIPE_$SPEEXENCODER"
1122 TEMPARG="PIPE_$MPCENCODER"
1125 TEMPARG="PIPE_$WVENCODERSYNTAX"
1128 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1131 TEMPARG="PIPE_$AACENCODERSYNTAX"
1134 TEMPARG="PIPE_$AACENCODERSYNTAX"
1137 IN="$( eval echo "\$$TEMPARG" )"
1139 IN="$ABCDETEMPDIR/track$1.wav"
1141 # We need IN to proceed, if we are not using pipes.
1142 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1143 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1145 case "$TMPOUTPUT" in
1147 OUTPUT=$OGGOUTPUTCONTAINER
1150 OUTPUT=$OPUSOUTPUTCONTAINER
1153 OUTPUT=$MKAOUTPUTCONTAINER
1156 OUTPUT=$FLACOUTPUTCONTAINER
1162 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1163 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1166 if [ X"$USEPIPES" = "Xy" ]; then
1168 # We need a way to store the creation of the files when using PIPES
1169 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1170 # When piping it does not make sense to have a higher nice for
1171 # reading than for encoding, since it will be hold by the
1172 # encoding process. Setting an effective nice, to calm down a
1173 # bit the reading process.
1174 EFFECTIVE_NICE=$READNICE
1176 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1177 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1178 EFFECTIVE_NICE=$ENCNICE
1184 case "$MP3ENCODERSYNTAX" in
1185 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1186 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1187 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1188 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1192 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1199 case "$OGGENCODERSYNTAX" in
1200 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1201 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1205 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1212 case "$OPUSENCODERSYNTAX" in
1214 # Tag the file at encode time, as it can't be done after encoding.
1215 if [ "$DOTAG" = "y" ]; then
1216 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1217 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1218 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1220 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1226 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1231 case "$MKAENCODERSYNTAX" in
1233 if [ "$DOTAG" = "y" ]; then
1234 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS -metadata artist="$TRACKARTIST" \
1235 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1236 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1238 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1246 case "$FLACENCODERSYNTAX" in
1247 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1252 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1253 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1258 if [ "$(eval echo ${COMMENT})" != "" ]; then
1261 *) COMMENT="COMMENT=$COMMENT" ;;
1264 # Tag the file at encode time, as it can't be done after encoding.
1265 if [ "$DOTAG" = "y" ]; then
1266 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1267 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1269 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1273 # Tag the file inline at encode time.
1274 if [ "$DOTAG" = "y" ]; then
1275 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1276 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1278 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1282 case "$TTAENCODERSYNTAX" in
1283 # tta is the newer version with a small syntax change...
1285 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1288 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1293 case "$WVENCODERSYNTAX" in
1295 if [ "$DOTAG" = "y" ]; then
1296 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1297 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1299 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1303 if [ "$DOTAG" = "y" ]; then
1304 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1305 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1306 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1308 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1314 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1317 case "$MP2ENCODERSYNTAX" in
1319 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1322 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1327 # aac container is only used to catch faac encoded files where faac
1328 # is compiled without mp4 support (with libmp4v2).
1329 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1332 case "$AACENCODERSYNTAX" in
1334 if [ "$DOTAG" = "y" ]; then
1335 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1336 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1338 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1342 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1345 if [ "$DOTAG" = "y" ]; then
1346 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1347 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1349 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1353 if [ "$DOTAG" = "y" ]; then
1354 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1355 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1357 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1361 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1364 if [ "$DOTAG" = "y" ]; then
1365 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1366 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1367 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1369 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1375 # In case of wav output we need nothing. Just keep the wavs.
1376 # But we need the following to allow full logging and subsequent
1377 # successful cleaning of $ABCDETEMPDIR.
1378 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1383 # Only remove .wav if the encoding succeeded
1384 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1385 run_command encodetrack-$1 true
1386 if [ ! "$KEEPWAVS" = "y" ] ; then
1387 if [ ! "$KEEPWAVS" = "move" ] ; then
1393 run_command "" echo "HEH! The file we were about to encode disappeared:"
1394 run_command "" echo ">> $IN"
1395 run_command encodetrack-$1 false
1399 # do_preprocess [tracknumber]
1401 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1404 # IN="$ABCDETEMPDIR/track$1.wav"
1405 # # We need IN to proceed.
1406 # if [ -s "$IN" ] ; then
1407 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1409 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1410 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1411 # case "$POSTPROCESSFORMAT" in
1413 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1415 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1417 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1419 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1421 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1424 # # Only remove .wav if the encoding succeeded
1425 # if checkerrors "preprocess-(.{3,4})-$1"; then
1426 # run_command preprocess-$1 false
1428 # run_command preprocess-$1 true
1431 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1432 # echo "HEH! The file we were about to pre-process disappeared:"
1435 # run_command preprocess-$1 false
1440 # do_postprocess [tracknumber]
1442 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1445 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1447 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1448 # # We need IN to proceed.
1449 # if [ -s "$IN" ] ; then
1450 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1451 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1452 # case "$POSTPROCESSFORMAT" in
1454 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1456 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1458 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1460 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1462 # # Only remove .wav if the encoding succeeded
1463 # if checkerrors "postprocess-(.{3,4})-$1"; then
1464 # run_command postprocess-$1 false
1466 # run_command postprocess-$1 true
1469 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1470 # echo "HEH! The file we were about to post-process disappeared:"
1473 # run_command postprocess-$1 false
1488 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1492 # The commands here don't go through run_command because they're never supposed to be silenced
1493 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1498 for UTRACKNUM in $TRACKQUEUE
1500 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1502 # FIXME # Hard-coded batch option!
1503 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1505 if [ "$RETURN" != "0" ]; then
1506 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1508 for UTRACKNUM in $TRACKQUEUE
1510 echo normalizetrack-$UTRACKNUM >> status
1516 # do_batch_normalize
1518 # NORMALIZER, NORMALIZEROPTS
1519 do_batch_normalize ()
1521 # The commands here don't go through run_command because they're never supposed to be silenced
1522 echo "Batch normalizing tracks: $TRACKQUEUE"
1527 for UTRACKNUM in $TRACKQUEUE
1529 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1531 # XXX: Hard-coded batch option!
1532 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1534 if [ "$RETURN" != "0" ]; then
1535 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1537 for UTRACKNUM in $TRACKQUEUE
1539 echo normalizetrack-$UTRACKNUM >> status
1545 # do_normalize [tracknumber]
1547 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1550 IN="$ABCDETEMPDIR/track$1.wav"
1551 if [ -e "$IN" ] ; then
1552 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1553 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1555 if [ "$(checkstatus encode-output)" = "loud" ]; then
1556 echo "HEH! The file we were about to normalize disappeared:"
1559 run_command normalizetrack-$1 false "File $IN was not found"
1563 # do_move [tracknumber]
1564 # Deduces the outfile from environment variables
1565 # Creates directory if necessary
1567 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1570 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1572 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1573 # defined the OUTPUTFILE:
1576 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1577 ALBUMFILE="$(mungefilename "$DALBUM")"
1578 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1579 TRACKFILE="$(mungefilename "$TRACKNAME")"
1580 GENRE="$(mungegenre "$GENRE")"
1581 YEAR=${CDYEAR:-$CDYEAR}
1582 # If we want to start the tracks with a given number, we need to modify
1583 # the TRACKNUM value before evaluation
1585 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1586 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1587 if [ "$ONETRACK" = "y" ]; then
1588 if [ "$VARIOUSARTISTS" = "y" ]; then
1589 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1591 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1594 if [ "$VARIOUSARTISTS" = "y" ]; then
1595 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1597 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1600 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1601 # Once we know the specific output was successful, we can change
1602 # the OUTPUT to the value containing the container
1605 OUTPUT=$OGGOUTPUTCONTAINER
1608 OUTPUT=$OPUSOUTPUTCONTAINER
1611 OUTPUT=$MKAOUTPUTCONTAINER
1614 OUTPUT=$FLACOUTPUTCONTAINER
1620 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1621 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1624 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1625 # FIXME # introduce warnings?
1628 # mkdir -p shouldn't return an error if the directory already exists
1629 mkdir -p "$OUTPUTFILEDIR"
1630 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1631 if checkstatus movetrack-output-$OUTPUT; then :; else
1632 run_command movetrack-output-$OUTPUT true
1637 # mkdir -p shouldn't return an error if the directory already exists
1638 mkdir -p "$OUTPUTFILEDIR"
1639 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1640 if checkstatus movetrack-output-$OUTPUT; then :; else
1641 run_command movetrack-output-$OUTPUT true
1645 # Lets move the cue file
1646 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1647 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1648 if checkstatus movecue-$OUTPUT; then :; else
1649 # Silence the Copying output since it overlaps with encoding processes...
1650 #run_command '' vecho "Copying cue file to its destination directory..."
1651 if checkstatus onetrack >/dev/null ; then
1654 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1655 # We dont have the dir, since it was not created before.
1658 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1661 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1662 # http://brianvictor.tripod.com/mp3cue.htm#details
1663 [a-z0-9][a-z0-9][a-z0-9])
1664 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1667 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1671 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1673 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1682 # Create the playlist if wanted
1684 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1685 # VARIOUSARTISTS, OUTPUTDIR
1688 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1692 OUTPUT=$OGGOUTPUTCONTAINER
1695 OUTPUT=$OPUSOUTPUTCONTAINER
1698 OUTPUT=$MKAOUTPUTCONTAINER
1701 OUTPUT=$FLACOUTPUTCONTAINER
1707 # Create a playlist file for the playlist data to go into.
1708 # We used to wipe it out if it existed. Now we request permission if interactive.
1709 for LASTTRACK in $TRACKQUEUE; do :; done
1710 ALBUMFILE="$(mungefilename "$DALBUM")"
1711 ARTISTFILE="$(mungefilename "$DARTIST")"
1712 GENRE="$(mungegenre "$GENRE")"
1713 YEAR=${CDYEAR:-$CDYEAR}
1714 if [ "$VARIOUSARTISTS" = "y" ] ; then
1715 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1717 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1719 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1720 mkdir -p "$FINALPLAYLISTDIR"
1721 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1722 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1723 if [ "$INTERACTIVE" = "y" ]; then
1724 while [ "$DONE" != "y" ]; do
1726 case $ERASEPLAYLIST in
1727 e|E|a|A|k|K) DONE=y ;;
1728 "") ERASEPLAYLIST=e ; DONE=y ;;
1736 # Once we erase the playlist, we use append to create the new one.
1737 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1739 # The playlist does not exist, so we can safelly use append to create the new list
1742 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1743 touch "$OUTPUTDIR/$PLAYLISTFILE"
1744 for UTRACKNUM in $TRACKQUEUE
1746 # Shares some code with do_move since the filenames have to match
1747 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1748 getcddbinfo TRACKNAME
1750 TRACKFILE="$(mungefilename "$TRACKNAME")"
1751 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1752 ALBUMFILE="$(mungefilename "$DALBUM")"
1753 # If we want to start the tracks with a given number, we need to modify the
1754 # TRACKNUM value before evaluation
1756 if [ "$VARIOUSARTISTS" = "y" ]; then
1757 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1759 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1761 if [ "$VARIOUSARTISTS" = "y" ]; then
1762 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1763 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1765 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1768 if [ "$PLAYLISTDATAPREFIX" ]; then
1769 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1771 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1776 ## this will convert the playlist to have CRLF line-endings, if specified
1777 ## (some hardware players insist on CRLF endings)
1778 if [ "$DOSPLAYLIST" = "y" ]; then
1779 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1780 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1781 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1783 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1788 # This function reads a cuefile on stdin and writes an extended
1789 # cddb query on stdout. Any PREGAP for track 1 is properly
1790 # handled, although cue files embedded in FLAC files do not
1791 # appear to properly store the PREGAP setting. :(
1792 abcde.cue2discid () {
1797 while [ $val -gt 0 ] ; do
1798 ret=$(( $ret + ( $val % 10) ))
1799 val=$(( $val / 10 ))
1809 local first second third
1810 first=$(expr ${1} + 0 )
1811 second=$(expr ${2} + 0 )
1812 third=$(expr ${3} + 0 )
1814 echo $(( ((($first * 60) + $second) * 75) + $third ))
1824 while read line ; do
1827 TRACK) i=$(( i + 1 ))
1829 INDEX) if [ "$2" -eq 1 ] ; then
1831 START=$(( $LBA + $PREGAP + $OFFSET ))
1833 X=$(cddb_sum $(( $START / 75 )) )
1837 PREGAP) PREGAP=$(msf2lba $2)
1841 LEADOUT=$(( $4 / 588 ))
1844 LEADIN=$(( $3 / 588 ))
1853 LEADOUT=$(( $LEADOUT + $LEADIN ))
1855 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1856 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1857 printf "%08x %i" $DISCID $TRACKS
1860 while [ $j -le $TRACKS ] ; do
1861 eval echo -n "\" \$TRACK$j\""
1864 echo " $(( $LEADOUT / 75 ))"
1868 # abcde.mkcue [--wholedisk]
1869 # This creates a cuefile directly from the extended discid information
1870 # The --wholedisk option controls whether we're ripping data from the
1871 # start of track one or from the start of the disk (usually, but not
1872 # always the same thing!)
1874 # Track one leadin/pregap (if any) handeling:
1875 # --wholedisk specified:
1878 # INDEX 01 <pregap value>
1879 # Remaining track index values unchanged from disc TOC
1881 # --wholedisk not specified
1883 # PREGAP <pregap value>
1885 # Remaining track index values offset by <pregap value>
1892 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1895 local MODE DISCID TRACKS
1899 if [ "$1" = --wholedisc ] ; then
1905 vecho "One track is $ONETRACK"
1906 TRACKFILE="$(mungefilename "$TRACKNAME")"
1907 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1908 ALBUMFILE="$(mungefilename "$DALBUM")"
1909 if [ "$ONETRACK" = "y" ]; then
1910 if [ "$VARIOUSARTISTS" = "y" ]; then
1911 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1913 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1915 vecho "Cue wav file is $CUEWAVFILE"
1917 CUEWAVFILE="dummy.wav"
1926 echo REM DISCID $DISCID
1927 echo FILE \""$CUEWAVFILE"\" WAVE
1929 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1936 while [ $i -le "$TRACKS" ] ; do
1937 LBA=$(( $1 - $OFFSET ))
1938 printf " TRACK %02i AUDIO\n" $i
1939 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1940 if [ $MODE = PREGAP ] ; then
1941 echomsf " PREGAP " $(($OFFSET-150))
1943 echo " INDEX 00 00:00:00"
1946 echomsf " INDEX 01 " $LBA
1953 # This essentially the start of things
1956 # Query the CD to get the track info, unless the user specified -C
1957 # or we are using some actions which do not need the CDDB data at all
1958 #if [ ! X"$EXPACTIONS" = "X" ]; then
1960 #elif [ -z "$DISCID" ]; then
1961 if [ -z "$DISCID" ]; then
1962 vecho -n "Getting CD track info... "
1963 # In OSX, unmount the disc before a query
1964 if [ "$OSFLAVOUR" = "OSX" ]; then
1965 diskutil unmount ${CDROM#/dev/}
1967 case "$CDROMREADERSYNTAX" in
1969 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1970 case "$CUE2DISCID" in
1971 # FIXME # right now we have 2 cue2discid internal
1972 # implementations: builtin and abcde.cue2discid. Test
1973 # both of them and decide which one we want to use.
1975 #vecho "Using builtin cue2discid implementation..."
1976 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1978 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1980 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1981 TRACKS=${#OFFSETTIMES[@]}
1983 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1984 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1985 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1986 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1989 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1990 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1994 #vecho "Using external python cue2discid implementation..."
1995 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1999 log error "the input flac file does not contain a cuesheet."
2004 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2006 # if [ ! "$RET" = "0" ];then
2007 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2010 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2011 # CDPARANOIAAUDIOTRACKS="$TRACKS"
2013 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2014 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2018 case "$CDDBMETHOD" in
2019 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
2020 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
2024 # Make sure there's a CD in there by checking cd-discid's return code
2025 if [ ! "$?" = "0" ]; then
2026 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2027 log error "cuesheet information from the flac file could not be read."
2028 log error "Perhaps the flac file does not contain a cuesheet?."
2031 log error "CD could not be read. Perhaps there's no CD in the drive?"
2035 # In OSX, remount the disc again
2036 if [ "$OSFLAVOUR" = "OSX" ]; then
2037 diskutil mount ${CDROM#/dev/}
2040 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
2042 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
2045 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2046 # This needs to be done now because a section of the resuming code will need
2049 # get the number of digits to pad TRACKNUM with - we'll use this later
2050 # a CD can only hold 99 tracks, but since we support a feature for starting
2051 # numbering the tracks from a given number, we might need to set it as a
2052 # variable for the user to define... or obtain it somehow.
2053 if [ "$PADTRACKS" = "y" ] ; then
2057 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
2058 if [ -z "$TRACKQUEUE" ]; then
2059 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2060 case "$CDROMREADERSYNTAX" in
2061 cdparanoia|libcdio|debug)
2062 if [ "$WEHAVEACD" = "y" ]; then
2063 vecho "Querying the CD for audio tracks..."
2064 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2066 if [ ! "$RET" = "0" ];then
2067 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2069 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2070 CDPARANOIAAUDIOTRACKS="$TRACKS"
2072 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2073 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
2074 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
2075 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
2077 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2078 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2082 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
2085 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2087 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2088 log info "The disc does not contain any tracks. Giving up..."
2091 echo -n "Grabbing entire CD - tracks: "
2092 if [ ! "$PADTRACKS" = "y" ] ; then
2093 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2095 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2097 while [ "$X" -ne "$TRACKS" ]
2099 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2100 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2104 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2105 # User-supplied track queue.
2106 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2107 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2108 # Once cleaned, obtain the highest value in the trackqueue for number padding
2109 for LASTTRACK in $TRACKQUEUE; do :; done
2110 if [ ! "$PADTRACKS" = "y" ] ; then
2111 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2113 # Now we normalize the trackqueue
2114 for TRACK in $TRACKQUEUE ; do
2115 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2116 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2118 TRACKQUEUE=$PADTRACKQUEUE
2119 echo Grabbing tracks: "$TRACKQUEUE"
2122 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2124 # We have the discid, create a temp directory after it to store all the temp
2127 if [ -e "$ABCDETEMPDIR" ]; then
2128 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2129 # It already exists, see if it's a directory
2130 if [ ! -d "$ABCDETEMPDIR" ]; then
2131 # This is a file/socket/fifo/device/etc, not a directory
2134 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2135 echo "Please investigate, remove it, and rerun abcde." >&2
2139 # It's a directory, let's see if it's writable by us
2140 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2141 # Nope, complain and exit
2143 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2144 echo "Please investigate, remove it, and rerun abcde." >&2
2148 # See if it's populated
2149 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2150 # Wipe and start fresh
2151 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2152 echo -n "this directory to continue. Continue [y/N]? " >&2
2153 if [ "$INTERACTIVE" = "y" ]; then
2159 if [ "$ANSWER" != "y" ]; then
2162 rm -rf "$ABCDETEMPDIR" || exit 1
2163 mkdir -p "$ABCDETEMPDIR"
2164 if [ "$?" -gt "0" ]; then
2165 # Directory already exists or could not be created
2166 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2170 # Everything is fine. Check for ^encodetracklocation-
2171 # and encode-output entries in the status file and
2172 # remove them. These are not relevant across sessions.
2173 if [ -f "$ABCDETEMPDIR/status" ]; then
2174 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2175 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2176 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2178 # Remove old error messages
2179 if [ -f "$ABCDETEMPDIR/errors" ]; then
2180 rm -f "$ABCDETEMPDIR/errors"
2184 # We are starting from scratch
2185 mkdir -p "$ABCDETEMPDIR"
2186 if [ "$?" -gt "0" ]; then
2187 # Directory already exists or could not be created
2188 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2191 cat /dev/null > "$ABCDETEMPDIR/status"
2192 # Store the abcde version in the status file.
2193 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2195 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2196 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2197 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2198 vecho "Creating cue file..."
2199 case $CDROMREADERSYNTAX in
2201 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2202 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2204 log warning "the input flac file does not contain a cuesheet."
2208 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2209 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2211 log warning "reading the CUE sheet is still considered experimental"
2212 log warning "and there was a problem with the CD reading. abcde will continue,"
2213 log warning "but consider reporting the problem to the abcde author"
2219 # If we got the CDPARANOIA status and it is not recorded, save it now
2220 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2221 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2222 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2226 # Create the discid file
2227 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2228 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2229 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2234 # Create a proper CUE file based on the CUE file we created before.
2237 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2238 CUEFILE_OUT=$CUEFILE_IN.out
2239 ### FIXME ### checkstatus cddb
2240 if [ -e "$CDDBDATA" ]; then
2241 vecho "Adding metadata to the cue file..."
2242 # FIXME It doesn't preserve spaces! Why?
2243 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2245 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2246 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2247 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2251 cat "$CUEFILE_IN" | while read line
2253 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2254 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2255 # echo "$line" >> "$CUEFILE_OUT"
2256 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2257 eval track="\$TRACK$n"
2259 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2260 # When making a single-track rip, put the
2261 # actual file name into the file declaration
2262 # in the cue file so that it is usable by
2263 # music players and the like
2264 elif [ "$ONETRACK" = "y" ] &&
2265 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2267 TRACKFILE="$(mungefilename "$TRACKNAME")"
2268 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2269 ALBUMFILE="$(mungefilename "$DALBUM")"
2271 if [ "$VARIOUSARTISTS" = "y" ]; then
2272 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2274 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2277 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2280 # FIXME # If the lines above are uncommented, remove the line below.
2281 echo "$line" >> "$CUEFILE_OUT"
2284 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2285 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2291 # Parses a CDDB file and outputs the title and the track names.
2292 # Variables: CDDBFILE
2296 # List out disc title/author and contents
2297 if [ "$ONETRACK" = "y" ]; then
2298 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2300 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2301 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2302 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2303 if [ ! X"$PARSEDYEAR" = "X" ]; then
2304 echo "Year: $PARSEDYEAR"
2307 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2308 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2309 if [ ! X"$PARSEDGENRE" = "X" ]; then
2310 echo "Genre: $PARSEDGENRE"
2313 if [ ! "$ONETRACK" = "y" ]; then
2314 for TRACK in $(f_seq_row 1 $TRACKS)
2316 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2322 # Check for a local CDDB file, and report success
2325 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2327 CDDBLOCALSTATUS="notfound"
2328 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2331 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2332 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2333 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2334 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2335 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2336 CDDBLOCALMATCH=single
2337 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2338 CDDBLOCALMATCH=multiple
2343 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2344 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2345 CDDBLOCALMATCH=single
2350 # If the user has selected to check a local CDDB repo, we proceed with it
2351 case $CDDBLOCALMATCH in
2353 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2355 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2357 # List out disc title/author and contents
2358 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2359 cat "$RESULT" > "${CDDBLOCALREAD}"
2362 do_cddbparse "${CDDBLOCALREAD}"
2364 ##FIXME## QUICK HACK !!!!
2365 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2366 } >> "$ABCDETEMPDIR/cddblocalchoices"
2368 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2369 page "$ABCDETEMPDIR/cddblocalchoices"
2371 # It's all going to fit in one page, cat it
2372 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2374 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2375 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2376 CDDBLOCALCHOICENUM=-1
2377 if [ "$INTERACTIVE" = "y" ]; then
2378 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2379 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2380 read CDDBLOCALCHOICE
2381 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2382 # FIXME # Introduce diff's
2383 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2384 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2385 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2386 # Make sure we get a valid choice
2387 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2388 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2389 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2395 #echo "Selected ..."
2397 CDDBLOCALCHOICENUM=1
2399 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2400 #echo "Using local copy of CDDB data"
2401 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2402 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2403 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2404 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2405 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2406 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2407 CDDBLOCALSTATUS="found"
2409 #echo "Not using local copy of CDDB data"
2410 CDDBLOCALSTATUS="notfound"
2414 # List out disc title/author and contents
2415 do_cddbparse "${CDDBLOCALFILE}"
2416 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2417 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2419 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2421 if [ "$INTERACTIVE" = "y" ]; then
2423 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2424 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2427 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2431 if [ "$USELOCALRESP" = "y" ]; then
2432 #echo "Using local copy of CDDB data"
2433 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2434 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2435 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2436 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2437 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2438 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2439 CDDBLOCALSTATUS="single"
2441 #echo "Not using local copy of CDDB data"
2442 CDDBLOCALSTATUS="notfound"
2446 CDDBLOCALSTATUS="notfound"
2453 # Try to read CD-Text from the drive using icedax / cdda2wav
2456 if new_checkexec icedax; then
2457 CDTEXT_READER=icedax
2458 elif new_checkexec cdda2wav; then
2459 CDTEXT_READER=cdda2wav
2461 # Didn't find either, bail
2465 if [ "$OSFLAVOUR" = "OSX" ] ; then
2466 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2467 diskutil unmount ${CDROM#/dev/}
2468 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2469 CDDA2WAVCDROM="IODVDServices"
2470 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2471 CDDA2WAVCDROM="$CDROMID"
2473 if [ "$CDROMID" = "" ]; then
2474 CDDA2WAVCDROM="$CDROM"
2476 CDDA2WAVCDROM="$CDROMID"
2480 # Do we have CD-Text on the disc (and can the drive read it?)
2481 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2482 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2484 if [ $ERRORCODE -ne 0 ]; then
2485 # No CD-Text found, bail
2489 rm -f "$ABCDETEMPDIR/cddbchoices"
2491 # Make an empty template
2492 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2493 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2494 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2495 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2496 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2497 ATITLE=$(grep -ae '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2498 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2499 # List out disc title/author and contents
2500 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2501 for TRACK in $(f_seq_row 1 $TRACKS)
2503 TRACKM1=$(($TRACK - 1))
2504 TITLE="$(grep -aE ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2505 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2506 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new" && \
2507 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2509 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new" && \
2510 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2511 rm -f "$ABCDETEMPDIR/cddbread.new" # In case a sed error occurred
2512 echo >> "$ABCDETEMPDIR/cddbchoices"
2513 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2517 # Work with the musicbrainz WS API, then transform the results here so
2518 # they look (very) like the results from CDDB. Maybe not the best way
2519 # to go, but it Works For Me (TM)
2523 if checkstatus musicbrainz-readcomplete; then :; else
2524 vecho "Obtaining Musicbrainz results..."
2525 # If MB is to be used, interpret the query results and read all
2526 # the available entries.
2527 rm -f "$ABCDETEMPDIR/cddbchoices"
2528 CDDBCHOICES=1 # Overridden by multiple matches
2529 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2530 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2532 # The helper script will write disc matches out to
2533 # cddbread.*. Count how many we have
2534 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2535 # No matches. Use the normal cddb template for the user to
2537 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2538 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2539 # List out disc title/author and contents of template
2540 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2542 for TRACK in $(f_seq_row 1 $TRACKS)
2544 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2546 echo >> "$ABCDETEMPDIR/cddbchoices"
2547 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2548 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2549 echo 503 > "$ABCDETEMPDIR/cddbquery"
2551 # We have some matches
2552 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2553 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2555 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2556 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2557 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2558 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2559 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2560 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2561 # List out disc title/author and contents
2562 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2563 for TRACK in $(f_seq_row 1 $TRACKS)
2565 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2567 echo >> "$ABCDETEMPDIR/cddbchoices"
2569 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2570 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2571 for file in "$ABCDETEMPDIR"/cddbread.*
2573 X=$(echo $file | sed 's/^.*cddbread\.//g')
2574 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2575 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2576 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2577 # List out disc title/author and contents
2578 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2579 for TRACK in $(f_seq_row 1 $TRACKS)
2581 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2583 echo >> "$ABCDETEMPDIR/cddbchoices"
2585 echo "." >> "$ABCDETEMPDIR/cddbquery"
2588 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2595 # Perform CDDB protocol version check if it hasn't already been done
2596 if checkstatus cddb-statcomplete; then :; else
2597 if [ "$CDDBAVAIL" = "n" ]; then
2599 echo 503 > "$ABCDETEMPDIR/cddbstat"
2602 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2603 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2604 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2605 vecho "Checking CDDB server status..."
2606 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2607 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2608 case "$RESPONSECODE" in
2609 210) # 210 OK, status information follows (until terminating `.')
2612 501) # 501 Illegal CDDB protocol level: <n>.
2613 CDDBPROTO=`expr $CDDBPROTO - 1`
2615 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2616 # FreeDB TESTCD disc-id is used for query
2617 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2618 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2619 case "$RESPONSECODE" in
2620 2??) # Server responded, everything seems OK
2630 if test $rc -eq 1; then
2634 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2642 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2643 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2645 # Perform CDDB query if it hasn't already been done
2646 if checkstatus cddb-querycomplete; then :; else
2647 if [ "$CDDBAVAIL" = "n" ]; then
2649 echo 503 > "$ABCDETEMPDIR/cddbquery"
2650 # The default CDDBLOCALSTATUS is "notfound"
2651 # This part will be triggered if the user CDDB repo does not
2652 # contain the entry, or if we are not trying to use the repo.
2654 vecho "Querying the CDDB server..."
2655 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2656 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2657 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2663 # no match found in database,
2664 # wget/fetch error, or user requested not to use CDDB
2665 # Make up an error code (503) that abcde
2666 # will recognize in do_cddbread
2667 # and compensate by making a template
2668 echo 503 > "$ABCDETEMPDIR/cddbquery"
2670 *) # strange and unknown error
2671 echo ERRORCODE=$ERRORCODE
2672 echo "abcde: $CDDBTOOL returned unknown error code"
2676 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2683 # If it's not to be used, generate a template.
2684 # Then, display it (or them) and let the user choose/edit it
2685 if checkstatus cddb-readcomplete; then :; else
2686 vecho "Obtaining CDDB results..."
2687 # If CDDB is to be used, interpret the query results and read all
2688 # the available entries.
2689 rm -f "$ABCDETEMPDIR/cddbchoices"
2690 CDDBCHOICES=1 # Overridden by multiple matches
2691 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2692 case "$RESPONSECODE" in
2694 # One exact match, retrieve it
2695 # 200 [section] [discid] [artist] / [title]
2696 if checkstatus cddb-read-1-complete; then :; else
2697 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2698 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2699 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2700 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2701 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2703 # List out disc title/author and contents
2704 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2705 for TRACK in $(f_seq_row 1 $TRACKS)
2707 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2709 echo >> "$ABCDETEMPDIR/cddbchoices"
2711 202|403|409|500|503)
2712 # TODO: Explain these error codes a little more accurately:
2713 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2714 # No match response:
2715 case "$RESPONSECODE" in
2716 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2717 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2718 500|503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2720 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2721 # List out disc title/author and contents of template
2722 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2724 for TRACK in $(f_seq_row 1 $TRACKS)
2726 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2728 echo >> "$ABCDETEMPDIR/cddbchoices"
2729 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2730 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2733 # Multiple exact, (possibly multiple) inexact matches
2735 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2736 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2737 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2738 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2739 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2741 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2743 vecho -n "Retrieving multiple matches... "
2744 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2745 read DISCINFO # eat top line
2749 if checkstatus cddb-read-$X-complete; then :; else
2750 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2751 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2753 # List out disc title/author and contents
2754 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2755 for TRACK in $(f_seq_row 1 $TRACKS)
2757 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2759 echo >> "$ABCDETEMPDIR/cddbchoices"
2762 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2766 for TRACK in $(f_seq_row 1 $TRACKS)
2768 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2770 echo >> "$ABCDETEMPDIR/cddbchoices"
2771 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2772 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2775 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2782 if checkstatus cddb-edit >/dev/null; then
2783 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2784 VARIOUSARTISTS="$(checkstatus variousartists)"
2785 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2788 if [ "$INTERACTIVE" = "y" ]; then
2789 # We should show the CDDB results both when we are not using the local CDDB repo
2790 # or when we are using it but we could not find a proper match
2791 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2792 # Display the $ABCDETEMPDIR/cddbchoices file created above
2793 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2794 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2795 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2796 CHOICE=$(checkstatus cddb-choice)
2797 if [ -n "$CHOICE" ] ; then
2798 case $CDDBCHOICES in
2799 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2800 log error "CDDB query failed!"
2803 cat "$ABCDETEMPDIR/cddbchoices"
2806 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2808 echo "Selected: #$CHOICE"
2809 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2813 # The user has a choice to make, display the info in a pager if necessary
2814 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2815 page "$ABCDETEMPDIR/cddbchoices"
2817 # It's all going to fit in one page, cat it
2818 cat "$ABCDETEMPDIR/cddbchoices" >&2
2822 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2824 # I'll take CDDB read #3 for $400, Alex
2825 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2826 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2828 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2829 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2830 if [ ! X"$DIFF" = "X" ]; then
2831 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2832 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2833 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2834 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2835 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2836 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2838 # We parse the 2 choices to diff, store them in temporary files and diff them.
2839 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2840 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2842 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2843 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2844 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2845 page "$ABCDETEMPDIR/cddbread.diff"
2847 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2851 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2853 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2854 # Make sure we get a valid choice
2855 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2856 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2857 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2861 if [ "$CDCHOICENUM" = "0" ]; then
2862 vecho "Creating empty CDDB template..."
2864 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2866 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2867 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2869 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2873 # We need some code to show the selected option when local repository is selected and we have found a match
2874 vecho "Using cached CDDB match..." >&2
2875 # Display the $ABCDETEMPDIR/cddbchoices file created above
2876 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2877 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2878 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2879 CHOICE=$(checkstatus cddb-choice)
2880 if [ "$USELOCALRESP" = "y" ]; then :; else
2881 if [ -n "$CHOICE" ] ; then
2882 case $CDDBCHOICES in
2885 echo "Selected template."
2887 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2889 echo "Selected: #$CHOICE"
2890 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2898 # We're noninteractive - pick the first choice.
2899 # But in case we run a previous instance and selected a choice, use it.
2900 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2901 # Show the choice if we are not using the locally stored one
2902 # or when the local search failed to find a match.
2903 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2904 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2905 #if [ "$PREVIOUSCHOICE" ]; then
2906 cat "$ABCDETEMPDIR/cddbchoices"
2909 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2910 CDCHOICENUM=$PREVIOUSCHOICE
2913 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2915 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2920 if checkstatus cddb-choice >/dev/null; then :; else
2921 echo "abcde: internal error: cddb-choice not recorded." >&2
2924 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2925 echo -n "Edit selected CDDB data " >&2
2926 if [ "$INTERACTIVE" = "y" ]; then
2927 if [ "$UNKNOWNDISK" = "y" ]; then
2928 echo -n "[Y/n]? " >&2
2930 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2932 echo -n "[y/N]? " >&2
2939 if [ "$EDITCDDB" = "y" ]; then
2940 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2942 # Use the debian sensible-editor wrapper to pick the editor that the
2943 # user has requested via their $EDITOR environment variable
2944 if [ -x "/usr/bin/sensible-editor" ]; then
2945 /usr/bin/sensible-editor "$CDDBDATA"
2946 elif [ -n "$EDITOR" ]; then
2947 if [ -x $(which "${EDITOR%%\ *}") ]; then
2948 # That failed, try to load the preferred editor, starting
2949 # with their EDITOR variable
2950 eval $(echo "$EDITOR") \"$CDDBDATA\"
2952 # If that fails, check for a vi
2953 elif which vi >/dev/null 2>&1; then
2955 elif [ -x /usr/bin/vim ]; then
2956 /usr/bin/vim "$CDDBDATA"
2957 elif [ -x /usr/bin/vi ]; then
2958 /usr/bin/vi "$CDDBDATA"
2959 elif [ -x /bin/vi ]; then
2961 # nano should be on all (modern, i.e., sarge) debian systems
2962 elif which nano >/dev/null 2>&1 ; then
2964 elif [ -x /usr/bin/nano ]; then
2965 /usr/bin/nano "$CDDBDATA"
2966 # mg should be on all OpenBSD systems
2967 elif which mg >/dev/null 2>&1 ; then
2969 elif [ -x /usr/bin/mg ]; then
2970 /usr/bin/mg "$CDDBDATA"
2973 log warning "no editor available. Check your EDITOR environment variable."
2975 # delete editor backup file if it exists
2976 if [ -w "$CDDBDATA~" ]; then
2981 # Some heuristics first. Look at Disc Title, and if it starts with
2982 # "Various", then we'll assume Various Artists
2983 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2984 echo "Looks like a Multi-Artist CD" >&2
2987 echo -n "Is the CD multi-artist [y/N]? " >&2
2988 if [ "$INTERACTIVE" = "y" ]; then
2995 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2998 # Need NUMTRACKS before cddb-tool will return it:
2999 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
3000 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3001 # More than 1/2 tracks contain a "/", so guess forward
3003 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3004 # More than 1/2 contain a "-", so guess forward-dash
3006 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3007 # More than 1/2 contain something in parens, so guess trailing-paren
3011 echo "1) Artist / Title" >&2
3012 echo "2) Artist - Title" >&2
3013 echo "3) Title / Artist" >&2
3014 echo "4) Title - Artist" >&2
3015 echo "5) Artist: Title" >&2
3016 echo "6) Title (Artist)" >&2
3017 echo "7) This is a single-artist CD" >&2
3018 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
3019 if [ "$INTERACTIVE" = "y" ]; then
3020 read VARIOUSARTISTSTYLE
3022 echo $DEFAULTSTYLE >&2
3023 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3025 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3026 # If they press Enter, then the default style (0) was chosen
3027 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
3028 echo "Invalid selection. Please choose a number between 1 and 7."
3029 echo -n "Selection [1-7]: "
3030 read VARIOUSARTISTSTYLE
3031 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3033 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3034 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3036 vecho "Selected: $VARIOUSARTISTSTYLE"
3037 case "$VARIOUSARTISTSTYLE" in
3039 VARIOUSARTISTSTYLE=forward
3042 VARIOUSARTISTSTYLE=forward-dash
3045 VARIOUSARTISTSTYLE=reverse
3048 VARIOUSARTISTSTYLE=reverse-dash
3051 VARIOUSARTISTSTYLE=colon
3054 VARIOUSARTISTSTYLE=trailing-paren
3062 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
3063 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
3065 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3066 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3067 # This works but does not have the necessary error checking
3068 # yet. If you are familiar with the CDDB spec
3069 # (see http://www.freedb.org/src/latest/DBFORMAT)
3070 # and can create an error-free entry on your own, then put
3071 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3072 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3073 # your abcde.conf to change the email address submissions are
3076 # submit the modified file, if they want
3077 if [ "$NOSUBMIT" != "y" ]; then
3078 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3080 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3081 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3083 echo -n 'Invalid selection. Please answer "y" or "n": '
3086 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3087 echo -n "Sending..."
3088 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
3095 # User CDDBLOCALPOLICY to find out if we store the file or not...
3096 # Cache edited CDDB entry in the user's cddb dir
3097 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3098 # Make sure the cache directory exists
3099 mkdir -p $CDDBLOCALDIR
3100 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
3103 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
3107 # try to download CD cover
3111 ALBUMFILE="$(mungefilename "$DALBUM")"
3112 ARTISTFILE="$(mungefilename "$DARTIST")"
3113 GENRE="$(mungegenre "$GENRE")"
3114 YEAR=${CDYEAR:-$CDYEAR}
3115 # have we got a musicbrainz mbid or amazon asin?
3116 case "$CDDBMETHOD" in
3118 # try musicbrainz mbid
3119 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
3120 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
3121 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3122 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3123 vecho "cover URL: $ALBUMARTURL" >&2
3124 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3125 if [ $? -ne 0 ]; then
3126 vecho "could not download cover from musicbrainz" >&2
3128 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3129 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3130 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3131 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3132 vecho "cover URL: $ALBUMARTURL" >&2
3133 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3134 if [ $? -ne 0 ]; then
3135 vecho "could not download cover from amazon" >&2
3137 # Check that size is reasonable; sometimes when there is no cover image
3138 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3139 FILESIZE=$(wc -c < "$ABCDETEMPDIR/$ALBUMARTFILE")
3140 if [ "$FILESIZE" -lt 1024 ]; then
3141 rm "$ABCDETEMPDIR/$ALBUMARTFILE"
3142 vecho "could not download cover from amazon" >&2
3146 vecho "no amazon ID found" >&2
3150 vecho "no musicbrainz ID found" >&2
3155 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3156 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3157 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3158 if [ $? -ne 0 ]; then
3159 vecho "could not download cover with glyrc" >&2
3164 if [ "$INTERACTIVE" = "y" ]; then
3165 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3166 # display properties of coverart when identify is available
3167 if new_checkexec $IDENTIFY; then
3168 $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
3170 # display coverart when DISPLAY is set and display command is available
3171 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3172 $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
3175 # nothing downloaded yet
3176 vecho "automatic album art downloading failed" >&2
3178 # see if the user can find a better album art manually
3179 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3181 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3182 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3184 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3187 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3188 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3190 if [ ! -z "$ALBUMARTURL" ]; then
3191 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3192 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3193 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3194 vecho "unable to download $ALBUMARTURL" >&2
3196 else # it's a local path
3197 cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
3198 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3199 vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
3205 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3206 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3207 ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
3208 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3209 if new_checkexec $CONVERT; then
3210 mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3211 $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
3212 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3214 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3215 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3219 # copy to target directories
3220 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3221 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3223 # put cover in the same place as the album
3224 if [ "$ONETRACK" = "y" ] ; then
3225 if [ "$VARIOUSARTISTS" = "y" ] ; then
3226 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3228 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3231 if [ "$VARIOUSARTISTS" = "y" ] ; then
3232 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3234 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3237 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3238 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3239 mkdir -p "$FINALALBUMARTDIR"
3240 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3242 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3243 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3245 log warning "could not get cover"
3246 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3250 # do_cdread [tracknumber]
3251 # do_cdread onetrack [firsttrack] [lasttrack]
3255 # The commands here don't go through run_command because they're never supposed to be silenced
3256 # return codes need to be doublechecked anyway, however
3257 if [ "$1" = "onetrack" ]; then
3258 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3259 # FIXME # Until then, we grab the whole CD in one track, no matter what
3261 # We need the first and last track for cdda2wav/icedax
3263 LASTTRACK=$(expr $3 + 0)
3264 UTRACKNUM=$FIRSTTRACK
3265 case "$CDROMREADERSYNTAX" in
3266 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
3269 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
3270 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
3271 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3272 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3273 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3279 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3280 if [ "$USEPIPES" = "y" ]; then
3281 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3282 FILEARG="$( eval echo "\$$TEMPARG" )"
3283 PIPE_MESSAGE="and encoding "
3285 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3286 case "$CDROMREADERSYNTAX" in
3287 ## FIXME ## Find the cases for flac, to avoid exceptions
3289 FILEARG="--output-name=$WAVDATA"
3296 if [ "$1" = "onetrack" ]; then
3297 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3299 if [ -r "$CDDBDATA" ]; then
3300 getcddbinfo TRACKNAME
3301 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3303 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3306 case "$CDROMREADERSYNTAX" in
3307 ### FIXME ### use an exception for flac, since it uses -o
3308 ### FIXME ### Shall we just use -o $FILEARG ??
3310 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3311 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3312 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3314 if [ "$USEPIPES" = "y" ]; then
3315 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3317 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3321 if [ "$OSFLAVOUR" = "OSX" ] ; then
3322 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3323 diskutil unmount ${CDROM#/dev/}
3324 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3325 CDDA2WAVCDROM="IODVDServices"
3326 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3327 CDDA2WAVCDROM="$CDROMID"
3329 if [ "$CDROMID" = "" ]; then
3330 CDDA2WAVCDROM="$CDROM"
3332 CDDA2WAVCDROM="$CDROMID"
3335 if [ "$USEPIPES" = "y" ]; then
3336 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3338 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3342 # I cannot get USEPIPES to work with dagrab so just this:
3343 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2
3346 if [ "$USEPIPES" = "y" ]; then
3347 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3349 # Write ripped audio data to stdout and redirect to $FILEARG.
3350 # Progress is written to stderr by default and thus >&2 is not required.
3351 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3355 # Find the track's mounted path
3356 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3357 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3358 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3359 # If the file exists, copy it
3360 if [ -e "$FILEPATH" ] ; then
3361 if [ "$USEPIPES" = "y" ]; then
3362 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3364 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3370 if [ "$USEPIPES" = "y" ]; then
3371 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3373 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
3378 # If we get some error or we get some missing wav
3379 # (as long as we dont use pipes)
3380 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3381 # Thank goodness errors is only machine-parseable up to the
3382 # first colon, otherwise this woulda sucked
3383 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3384 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3386 if [ "$USEPIPES" = "y" ]; then
3387 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3389 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3393 if [ "$USEPIPES" = "y" ]; then
3394 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3396 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3398 if [ "$1" = "onetrack" ]; then
3399 echo onetrack >> "$ABCDETEMPDIR/status"
3405 # No values accepted, only uses env variables
3408 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3409 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3411 echo "abcde: unable to set the device speed" >&2
3417 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3420 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3422 warning) shift ; log warning "$@" ;;
3430 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3433 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3435 warning) shift ; log warning "$@" ;;
3443 # decho outputs a debug message if DEBUG is selected
3446 if [ x"$DEBUG" != "x" ]; then
3447 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3448 DEBUGECHO=$(echo "$@" | tr -d '[]')
3449 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3451 echo >&4 "[DEBUG] $1"
3456 # User-redefinable functions
3457 # Custom filename munging:
3460 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3463 # Custom genre munging:
3466 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3470 # Empty pre_read function, to be defined in the configuration file.
3477 # Empty post_read function, to be defined in the configuration file.
3484 # Empty post_encode function, to be defined in the configuration file.
3490 ###############################################################################
3493 # Start of execution
3494 ###############################################################################
3499 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3501 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3502 CDDBSUBMIT=freedb-submit@freedb.org
3504 HELLOINFO="$(whoami)@$(hostname)"
3506 CDDBLOCALPOLICY="always"
3507 CDDBLOCALRECURSIVE="y"
3508 CDDBLOCALDIR="$HOME/.cddb"
3511 # List of fields we parse and show during the CDDB parsing...
3512 SHOWCDDBFIELDS="year,genre"
3515 #CDROMREADERSYNTAX=cdparanoia
3516 ENCODERSYNTAX=default
3518 MP3ENCODERSYNTAX=default
3519 OGGENCODERSYNTAX=default
3520 OPUSENCODERSYNTAX=default
3521 MKAENCODERSYNTAX=default
3522 FLACENCODERSYNTAX=default
3523 SPEEXENCODERSYNTAX=default
3524 MPCENCODERSYNTAX=default
3525 WVENCODERSYNTAX=default
3526 TTAENCODERSYNTAX=default
3527 APENCODERSYNTAX=default
3528 MP2ENCODERSYNTAX=default
3529 AACENCODERSYNTAX=default
3530 NORMALIZERSYNTAX=default
3531 CUEREADERSYNTAX=default
3533 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3534 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3535 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3536 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3537 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3538 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3539 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3540 PLAYLISTDATAPREFIX=''
3541 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3542 VAPLAYLISTDATAPREFIX=''
3550 VARIOUSARTISTSTYLE=forward
3557 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3558 # i.e. CDROMID="1,0,0"
3560 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3561 # If we are using the ide-scsi emulation layer, we need to define a "g"
3562 CDPARANOIACDROMBUS="d"
3564 # program paths - defaults to checking your $PATH
3570 XINGMP3ENC=xingmp3enc
3584 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3588 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3598 NEROAACENC=neroAacEnc
3600 # Note that the qaac PATH will almost always require adjustment
3601 # as it is a Windows application being run through Wine. More
3602 # detailed notes in the sample abcde.conf file in the abcde tarball.
3605 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3613 VORBISCOMMENT=vorbiscomment
3615 NEROAACTAG=neroAacTag
3616 ATOMICPARSLEY=AtomicParsley
3619 CDPARANOIA=cdparanoia
3620 CD_PARANOIA=cd-paranoia
3627 MUSICBRAINZ=abcde-musicbrainz-tool
3631 NORMALIZE=normalize-audio
3633 VORBISGAIN=vorbisgain
3637 # For Wavpack replay gain we set both the default of 'track gain'
3638 # as well as this option for 'album gain'. Better media players
3639 # such as vlc can select either or neither. Andrew.
3650 # Options for programs called from abcde
3662 VORBISGAINOPTS="--album"
3666 # The flac option is a workaround for an error where flac fails
3667 # to encode with error 'floating point exception'. This is flac
3668 # error in get_console_width(), corrected in flac 1.3.1
3670 FLACGAINOPTS="--add-replay-gain"
3677 # True Audio has no useful options but it is here anyway :)
3680 # Monkey's Audio Console (mac) chokes without a mode setting
3681 # so we set one here.
3688 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3689 # we set bitrate here.
3690 FDKAACENCOPTS='--bitrate 192k'
3712 VORBISCOMMENTOPTS="-R"
3713 METAFLACOPTS="--no-utf8-convert"
3718 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3720 # Defaults for album art downloads
3721 ALBUMARTFILE="cover.jpg"
3723 ALBUMARTALWAYSCONVERT="n"
3725 # Default to one process if -j isn't specified
3728 # List of actions to perform - by default, run to completion
3729 ACTIONS=cddb,read,encode,tag,move,clean
3731 # This option is basically for Debian package dependencies:
3732 # List of preferred outputs - by default, run with whatever we have in the path
3733 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
3735 # List of preferred cdromreaders - by default, run whichever we have in the path
3736 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3738 # fd for when `vecho` and `log info` called with redirected stdout
3741 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3742 # Linux/OpenBSD. ftp is user for NetBSD.
3743 # Let's use these checkings to determine the OS flavour, which will be used
3745 if [ X$(uname) = "XFreeBSD" ] ; then
3750 elif [ X$(uname) = "XDarwin" ] ; then
3753 # We should have diskutil in OSX, but let's be sure...
3755 CDROMREADERSYNTAX=cddafs
3756 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3758 elif [ X$(uname) = "XOpenBSD" ] ; then
3762 elif [ X$(uname) = "XNetBSD" ] ; then
3766 elif [ X$(uname) = "SunOS" ] ; then
3774 # If CDDBAVAIL is set to n, no CDDB read is done
3778 # But before we get into business, let us chop off any GREP environmental
3783 if [ -z "$OUTPUTDIR" ]; then
3787 if [ -z "$WAVOUTPUTDIR" ]; then
3788 WAVOUTPUTDIR="$OUTPUTDIR"
3791 # Load system defaults
3792 if [ -r /etc/abcde.conf ]; then
3795 # Load user preference defaults
3796 if [ -r $HOME/.abcde.conf ]; then
3800 # By this time, we need some HTTPGETOPTS already defined.
3801 # If the user has defined a non-default HTTPGET method, we should not be empty.
3803 if [ "$HTTPGETOPTS" = "" ] ; then
3805 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3806 curl) HTTPGETOPTS="-f -s";;
3807 fetch)HTTPGETOPTS="-q -o -";;
3808 ftp) HTTPGETOPTS="-a -V -o - ";;
3809 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3813 # If the CDROM has not been set yet, find a suitable one.
3814 # If this is a devfs system, default to /dev/cdroms/cdrom0
3815 # instead of /dev/cdrom
3816 if [ "$CDROM" = "" ] ; then
3817 if [ -e /dev/cdroms/cdrom0 ]; then
3818 CDROM=/dev/cdroms/cdrom0
3819 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3820 CDROM=/dev/${BASH_REMATCH[1]}
3821 elif [ -e /dev/cdrom ]; then
3823 elif [ -e /dev/sr0 ]; then
3825 elif [ -e /dev/cd0c ]; then
3827 elif [ -e /dev/acd0c ]; then
3829 elif [ -e /dev/disk1 ]; then
3834 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3835 # that's changed to a number to allow for more control. Deal with
3836 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3837 case "$EXTRAVERBOSE" in
3846 # Parse command line options
3847 while getopts 1a:bc:C:d:DefgGhj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3850 a) ACTIONS="$OPTARG" ;;
3851 A) EXPACTIONS="$OPTARG" ;;
3853 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3854 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3855 d) CDROM="$OPTARG" ;;
3858 e) ERASEENCODEDSTATUS=y ;;
3859 E) ENCODING="$OPTARG" ;;
3864 j) MAXPROCS="$OPTARG" ;;
3867 L) CDDBUSELOCAL=y ;;
3872 o) OUTPUTTYPE="$OPTARG" ;;
3875 r) REMOTEHOSTS="$OPTARG" ;;
3876 R) CDDBLOCALRECURSIVE=y ;;
3877 s) SHOWCDDBFIELDS="$OPTARG" ;;
3878 S) CDSPEEDVALUE="$OPTARG" ;;
3879 t) STARTTRACKNUMBER="$OPTARG" ;;
3880 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3883 echo "This is abcde v$VERSION."
3884 echo "Usage: abcde [options] [tracks]"
3885 echo "abcde -h for extra help"
3888 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3890 X) CUE2DISCID="$OPTARG" ;;
3891 w) COMMENT="$OPTARG" ;;
3892 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3893 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
3894 STARTTRACKNUMBERTAG="y"
3895 COMMENT="CD${OPTARG}"
3896 DISCNUMBER="${OPTARG}"
3898 log error "argument of -W must be integer"
3902 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3907 shift $(($OPTIND - 1))
3909 # Here it comes the worse part of the whole thing. From here until we start
3910 # ripping, we have a mixture of sanity checks, verifications, default settigs
3911 # and other crazy stuff that interdepends, but hey, someone has to do it.
3913 # If NOCDDBQUERY is set, don't query the CDDB server.
3914 if [ "$NOCDDBQUERY" = "y" ]; then
3918 # If the user specified a flac file, then switch to special flac mode
3919 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3920 if [ ! -f "$CDROM" ]; then
3921 log error "the defined file for FLAC ripping cannot be found" >&2
3924 vecho warning "switching to flac CDROMREADERSYNTAX..."
3925 CDROMREADERSYNTAX=flac
3926 # We have a builtin version of cue2discid...
3927 case "$CUE2DISCID" in
3929 *) NEEDCUE2DISCID=y;;
3935 # If the user provided a DISCID, disable eject
3936 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3938 # Check the available cd rippers in the system, from the ones we know.
3939 if [ "$CDROMREADERSYNTAX" = "" ]; then
3940 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3941 if new_checkexec $DEFAULT_CDROMREADER; then
3942 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3946 if [ "$CDROMREADERSYNTAX" = "" ]; then
3947 log error "no cdreader found in your PATH"
3948 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3953 # Decide if we can continue.
3954 if [ "$ONETRACK" = "y" ]; then
3955 # FIXME # remove check as soon as we find out about the other readers
3956 case "$CDROMREADERSYNTAX" in
3958 cdparanoia | libcdio) ;;
3959 cdda2wav | icedax) ;;
3961 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3964 if [ "$BATCHNORM" = "y" ]; then
3965 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3968 if [ "$NOGAP" = "y" ]; then
3969 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3972 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3973 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3974 if [ $# -gt 0 ]; then
3975 log warning "ONETRACK mode selected, grabbing all tracks..."
3978 while [ $# -gt 0 ]; do
3979 # Range parsing code courtesy of Vincent Ho
3980 # Cleaned up to use shell built-ins by Charles Steinkuehler
3981 if [ "${1#*[^0-9-]}" != "$1" ]; then
3982 log error "syntax error while processing track numbers ($1)"
3987 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3988 TRACKQUEUE="$TRACKQUEUE $RSTART"
3989 RSTART=$(( $RSTART + 1 ))
3996 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3997 # List of experimental actions: retag,transcode
3999 # Determine what actions are to be done from $ACTIONS and set the
4000 # following environment variables for them:
4012 ## FIXME ## Lets keep compatibility with -M
4013 [ "$DOCUE" != "y" ] && DOCUE=n
4015 for ACTION in $(echo $ACTIONS | tr , \ )
4018 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4019 cue) DOCUE=y ; MAKECUEFILE=y ;;
4022 normalize) DONORMALIZE=y; DOREAD=y;;
4023 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4024 encode) DOENCODE=y; DOREAD=y;;
4025 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4026 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4027 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4028 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4029 playlist) DOCDDB=y; DOPLAYLIST=y;;
4031 getalbumart) GETALBUMART=y;;
4035 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4036 # FIXME # should we abort on error or just inform the user?
4037 log warning "selected both normalize and replaygain actions"
4040 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
4041 case $SHOWCDDBFIELD in
4042 y*|Y*) SHOWCDDBYEAR="y";;
4043 g*|G*) SHOWCDDBGENRE="y";;
4048 # At this point a CDROM has to be defined, so we check it exists.
4049 if [ X"$CDROM" != "X" ] ; then
4050 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
4051 if [ "$OSFLAVOUR" = "FBSD" ]; then
4052 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
4053 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4054 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4058 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
4059 log error "CDROM device cannot be found."
4062 # avoid processing if we are not going to hit the CDROM.
4063 elif [ X"$DOREAD" = "Xy" ]; then
4064 log error "CDROM has not been defined or cannot be found"
4068 # USEPIPES pre-tests, before we get into more serious stuff
4069 # Not compatible with:
4070 # - multiple outputs
4072 # - lowdisk algorithm
4074 if [ X"$USEPIPES" = "Xy" ]; then
4075 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
4076 log error "Unix pipes not compatible with multiple outputs"
4079 if [ X"$DONORMALIZE" = "Xy" ]; then
4080 log error "Unix pipes not compatible with normalizer"
4081 # FIXME # Do we need to exit or shall we just disable the mode?
4084 if [ X"$BATCHNORM" = "Xy" ]; then
4085 log error "Unix pipes not compatible with BATCHNORM encoding"
4088 if [ X"$NOGAP" = "Xy" ]; then
4089 log error "Unix pipes not compatible with NOGAP encoding"
4092 if [ X"$DOENCODE" = "Xn" ]; then
4093 vecho warning "Disabling Unix pipes since we are not encoding!"
4096 if [ X"$LOWDISK" = "Xy" ]; then
4097 log error "Unix pipes not compatible with lowdisk algorithm"
4102 # LOWDISK pre-tests, before we get into more problematic stuff
4103 # Not compatible with anything that needs all the files in the hard disc:
4106 if [ X"$LOWDISK" = "Xy" ]; then
4107 if [ X"$BATCHNORM" = "Xy" ]; then
4108 log error "Unix pipes not compatible with BATCHNORM encoding"
4111 if [ X"$NOGAP" = "Xy" ]; then
4112 log error "Unix pipes not compatible with NOGAP encoding"
4117 # BATCHNORM pre-tests, before we get into serious problems
4118 # Not compatible with
4119 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4120 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4124 # Check the encoding format from the ones available in the system, if nothing has been configured.
4125 if [ X"$OUTPUTTYPE" = "X" ]; then
4126 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4127 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
4128 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
4129 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
4130 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4131 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4135 if [ X"$OUTPUTTYPE" = "X" ]; then
4136 log error "no encoder found in the PATH"
4137 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4142 # Decide which CDROM reader we're gonna use
4143 case "$CDROMREADERSYNTAX" in
4145 CDROMREADER="$CDPARANOIA"
4146 CDROMREADEROPTS="$CDPARANOIAOPTS"
4149 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4150 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4151 CDROMREADER="$CD_PARANOIA"
4152 CDROMREADEROPTS="$CDPARANOIAOPTS"
4155 CDROMREADER="$CDDA2WAV"
4156 CDROMREADEROPTS="$CDDA2WAVOPTS"
4159 CDROMREADER="$DAGRAB"
4160 CDROMREADEROPTS="$DAGRABOPTS"
4164 CDROMREADEROPTS="$PIRDOPTS"
4167 CDROMREADER="$CDDAFS"
4168 CDROMREADEROPTS="$CDDAFSOPTS"
4172 CDROMREADEROPTS="$FLACOPTS"
4176 # There's only one normalize...
4177 case "$NORMALIZERSYNTAX" in
4179 NORMALIZER="$NORMALIZE"
4180 NORMALIZEROPTS="$NORMALIZEOPTS"
4184 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4185 case "$OUTPUTTYPE" in *:*)
4186 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4187 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4189 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4190 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4191 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4192 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4193 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4194 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4195 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4196 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4197 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4198 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4199 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4200 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4203 # Allows commandline selection of options while using multiple outputs.
4204 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4205 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4206 TEMPOUTPUT=${OUTPUT%%:*}
4207 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4209 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4213 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4214 # for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as and
4215 # wavpack for wvs...
4217 # Getting ready for multiple output changes
4218 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4222 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4223 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4224 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4225 OGGOUTPUTCONTAINER=ogg
4228 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4229 OPUSOUTPUTCONTAINER=opus
4232 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4233 MKAOUTPUTCONTAINER=mka
4236 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4237 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4238 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4241 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4242 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4243 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4244 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4247 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4248 # [ "$DOREPLAYGAIN" = "y" ] &&
4251 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4252 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4255 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4257 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4258 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4261 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4262 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4265 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4266 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4267 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4270 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4271 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4272 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4275 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4277 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4278 # compiled without libmp4v2... Andrew.
4281 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4282 [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4283 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4284 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4285 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4286 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4289 if [ "$KEEPWAVS" = "y" ]; then
4290 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4294 *) log error "Invalid OUTPUTTYPE defined"
4300 # decide which encoder
4301 case "$MP3ENCODERSYNTAX" in
4303 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4307 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4311 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4312 MP3ENCODER="$BLADEENC"
4315 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4319 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4320 MP3ENCODER="$XINGMP3ENC"
4323 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4324 MP3ENCODER="$MP3ENC"
4327 case "$OGGENCODERSYNTAX" in
4329 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4330 OGGENCODER="$VORBIZE"
4333 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4334 OGGENCODER="$OGGENC"
4337 case "$OPUSENCODERSYNTAX" in
4339 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4340 OPUSENCODER="$OPUSENC"
4343 case "$MKAENCODERSYNTAX" in
4345 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4346 MKAENCODER="$FFMPEG"
4349 case "$FLACENCODERSYNTAX" in
4351 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4353 if [ "$DOREPLAYGAIN" = "y" ]; then
4354 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4356 # FLAC streams can be encapsulated on a Ogg transport layer
4357 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4358 log error "FLAC on an Ogg container is not yet supported"
4359 log error "due to problem with adding comments to such files"
4361 FLACOUTPUTCONTAINER=ogg
4363 FLACOUTPUTCONTAINER=flac
4367 case "$SPEEXENCODERSYNTAX" in
4369 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4370 SPEEXENCODER="$SPEEXENC"
4373 case "$MPCENCODERSYNTAX" in
4375 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4376 MPCENCODER="$MPCENC"
4379 case "$WVENCODERSYNTAX" in
4381 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4382 # and in the interests of backward compatibility:
4383 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4384 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4385 WVENCODER="$WAVPACK"
4387 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4388 WVENCODER="$WAVPACK"
4392 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4396 case "$TTAENCODERSYNTAX" in
4398 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4402 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4403 TTAENCODER="$TTAENC"
4406 case "$APENCODERSYNTAX" in
4408 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4412 case "$MP2ENCODERSYNTAX" in
4414 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4415 MP2ENCODER="$TWOLAME"
4418 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4419 MP2ENCODER="$FFMPEG"
4422 case "$AACENCODERSYNTAX" in
4423 # Some elaborate 'if' work to keep backward compatibility for those
4424 # who don't realise that AACENCOPTS does not work with abcde from
4425 # version 2.7 onwards.
4427 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4428 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4431 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4436 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4437 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4438 AACENCODER="$NEROAACENC"
4440 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4441 AACENCODER="$NEROAACENC"
4445 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4446 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4447 AACENCODER="$FDKAAC"
4449 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4450 AACENCODER="$FDKAAC"
4454 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4455 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4458 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4463 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4464 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4465 AACENCODER="$FHGAACENC"
4467 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4468 AACENCODER="$FHGAACENC"
4472 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4473 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4474 AACENCODER="$FFMPEG"
4476 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4477 AACENCODER="$FFMPEG"
4487 TAGGEROPTS="$ID3OPTS"
4492 TAGGEROPTS="$ID3V2OPTS"
4497 TAGGEROPTS="$ID3TAGOPTS"
4501 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4502 # trouble with CDDBPROTO=5 (which we test here) but also
4503 # with cached cddb files in latin1 (which we cannot test).
4504 if [ "$CDDBPROTO" -lt 6 ]; then
4505 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4508 # eyeD3 version 0.7 changed syntax
4509 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4510 # only if it offers the --set-encoding, assume <= 0.6.x
4512 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4514 # anything wrong, any failure, assume >= 0.7
4516 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4520 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4525 # NOGAP is specific to lame. Other encoders fail ...
4526 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4527 log warning "the NOGAP option is specific to lame. Deactivating..."
4532 case "$CUEREADERSYNTAX" in
4534 CUEREADEROPTS="${CDROM}"
4539 # which information retrieval tool are we using?
4545 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4546 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4547 log error "FLAC on an Ogg container is not yet supported"
4548 log error "due to problem with adding comments to such files"
4550 OGGOUTPUTCONTAINER=ogg.ogg
4551 FLACOUTPUTCONTAINER=flac.ogg
4552 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4555 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4557 if [ "$ENCNICE" ]; then
4558 ENCNICE="-n $ENCNICE"
4560 if [ "$READNICE" ]; then
4561 READNICE="-n $READNICE"
4563 if [ "$DISTMP3NICE" ]; then
4564 DISTMP3NICE="-n $DISTMP3NICE"
4567 # Don't check for stuff if it's not needed
4568 if [ "$REMOTEHOSTS" ]; then
4571 if [ "$DONORMALIZE" = "y" ]; then
4574 if [ "$EJECTCD" = "y" ]; then
4577 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4578 if [ "$CDDBMETHOD" = "cddb" ]; then
4580 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4584 if [ "$DOCUE" = "y" ]; then
4588 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4589 case "$CDROMREADERSYNTAX" in
4590 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4591 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4592 ### FIXME ### translate "cue2discid" from python to bash
4593 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4598 if [ "$GETALBUMART" = "y" ]; then
4603 ###USEPIPESSUPPORT###
4605 # Rippers with USEPIPE support
4606 PIPERIPPER_cdparanoia="-"
4607 PIPERIPPER_libcdio="-"
4608 # Note that by default in abcde cdda2wav redirects to icedax.
4609 PIPERIPPER_cdda2wav="-"
4610 PIPERIPPER_debug="-"
4611 PIPERIPPER_flac="-c "
4614 # Encoders with USEPIPE support
4617 PIPE_bladeenc="stdin"
4630 # Both neroAacEnc and fdkaac seem to manage without the addition of
4631 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4632 # in this manner. Andrew.
4636 # Figure out if we can use pipes with the ripper/encoder combination
4638 if [ "$USEPIPES" = "y" ]; then
4639 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4642 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4644 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4646 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4648 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4650 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4652 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4654 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4656 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4658 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4660 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4662 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4664 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4665 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4666 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4667 log error "no support for pipes with given ripper"
4668 log error "read the FAQ file from the source tarball to get help."
4671 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4672 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4673 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4674 log error "no support for pipes with given encoder"
4675 log error "read the FAQ file from the source tarball to get help"
4680 # Make sure a buncha things exist
4681 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4682 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4683 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER \
4684 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4685 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4686 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4687 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4688 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4689 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4690 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4691 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4692 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4693 ${NEEDMID3V2+$MID3V2}
4698 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4699 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4700 # these files). The resulting files are actually ADTS streams which belong in an
4701 # aac container and with some version sniffing this is all cleaned up below. If
4702 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4704 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4705 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4706 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4707 echo "WARNING: Your copy of Faac does not have mp4 support"
4708 echo "WARNING: Encoding untagged files to aac..."
4711 echo "Using Faac to Tag AAC Tracks..."
4715 # And last but not least, check if we can diff between files. We do not abort,
4716 # since diffing is not critical...
4717 if [ -x $(which $DIFF) ]; then :; else
4718 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4722 ## Now that we have metaflac, check if we need cue2discid
4723 #case $CDROMREADERSYNTAX in
4725 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4726 # if [ "$TRACKINFO" = "" ]; then
4727 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4732 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4733 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4734 HTTPGET="$HTTPGET $HTTPGETOPTS"
4736 # Here it used to say:
4737 # One thousand lines in, we can start doing stuff with things
4738 # Well, right now we are at line 3737 ;)
4740 # Export needed things so they can be read in this subshell
4741 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4742 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4744 if [ "$DOREAD" = "y" ]; then
4745 # User-definable function to set some things. Use it for
4746 # - closing the CD tray with eject -t
4747 # - set the CD speed value with eject -x
4748 vecho -n "Executing customizable pre-read function... "
4750 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4755 # Get ABCDETEMPDIR created and status file initialized
4758 if [ "$DOCDDB" = "y" ]; then
4759 # start with a sane default:
4760 CDDBLOCALSTATUS=notfound
4761 if [ $CDDBUSELOCAL = "y" ]; then
4764 if checkstatus cddb-choice > /dev/null; then
4767 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4768 case "$CDDBMETHOD" in
4779 CHOICE=$(checkstatus cddb-choice)
4780 if [ "$CHOICE" = 0 ] ; then
4781 # We don't have any information at all; try to fall back
4782 # to CD-Text for basic information
4783 vecho "No CDDB information found, trying cdtext from the CD"
4789 eval "$($CDDBTOOL parse "$CDDBDATA")"
4792 # Before reading tracks, we set the speed of the device
4794 if [ X"$CDSPEEDVALUE" != "X" ]; then
4795 case "$CDROMREADERSYNTAX" in
4796 cdparanoia|libcdio|debug) ;;
4803 # Define the first and last track, since we might need them later in several places
4804 FIRSTTRACK=$( get_first $TRACKQUEUE )
4805 LASTTRACK=$( get_last $TRACKQUEUE )
4807 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4808 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4809 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4810 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4813 if checkstatus onetrack ; then ONETRACK=y ; fi
4815 if [ "$ONETRACK" = "y" ]; then
4816 # Reuse the CUEFILE in case we created it (now or in a previous run)
4817 if CUEFILE=$(checkstatus cuefile); then
4822 # Create playlist if needed (backgroundable) and start reading in tracks
4826 if [ ! "$ONETRACK" = "y" ]; then
4827 if [ "$DOPLAYLIST" = "y" ]; then
4828 echo Creating playlist... >&2
4833 if [ "$GETALBUMART" = "y" ]; then
4837 # For the lowdisk option, only one program is running at once so the encoder
4838 # can be unsilenced right away.
4839 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4840 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4843 if [ "$ONETRACK" = "y" ]; then
4844 TRACKS="$FIRSTTRACK"
4845 if [ "$USEPIPES" = "y" ]; then
4846 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4847 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4850 if checkstatus readtrack-$FIRSTTRACK; then :; else
4851 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4855 for UTRACKNUM in $TRACKQUEUE
4857 if [ "$DOREAD" = "y" ]; then
4858 if [ "$USEPIPES" = "y" ]; then
4859 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4860 # Read, pipe, shut up!
4861 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4864 if checkstatus readtrack-$UTRACKNUM; then :; else
4865 do_cdread $UTRACKNUM
4867 if [ "$?" != "0" ]; then
4868 # CD read failed - don't give the goahead to
4875 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4878 # If we are not reading, set the encode output to loud already, so
4879 # that we can see the output of the first track.
4880 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4881 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4883 echo NEXTTRACK # Get the encoder machine churning again
4884 if [ "$DOREAD" = "y" ]; then
4885 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4886 until checkstatus encodetrack-$UTRACKNUM
4888 if checkerrors encodetrack-$UTRACKNUM; then
4899 # Now that we're done the encoding can be loud again -
4900 # if we're not using SMP.
4901 if [ "$MAXPROCS" = "1" ]; then
4902 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4905 # All tracks read, start encoding.
4906 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4910 # Execute the user-defined post_read function before ejecting CD
4913 # We are now finished with the cdrom - it can be safely ejected. Note that
4914 # abcde will not have completed yet.
4915 if [ "$EJECTCD" = "y" ]; then
4916 # We check if the disk we are processing is actually the disk inside the
4917 # CD tray. If not, we do not eject the CD, since it might be so that the
4918 # user ejected it manually.
4919 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4920 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4921 # More FreeBSD bits.
4922 if [ X"$(uname)" = X"FreeBSD" ] ; then
4923 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4924 # but in this script EJECT is in the envionment and names the program
4927 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4928 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4929 $eject $EJECTOPTS $cd
4930 elif [ X"$(uname)" = X"Darwin" ] ; then
4931 diskutil eject ${CDROM#/dev/} 0
4932 elif [ -x $(which $EJECT) ]; then
4933 $EJECT $EJECTOPTS "$CDROM"
4940 ## Do we need to pre-process
4941 #if [ x"$PREPROCESS" = "x" ] ; then
4944 # for PRETRACKNUM in $TRACKQUEUE
4947 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4949 # until [ $PREPROCEED ]
4951 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4952 # # all locations are working, wait and try again later
4953 # if [ ! $PREPROCEED ]; then sleep 3; fi
4955 # ( do_preprocess $PRETRACKNUM
4963 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4965 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4966 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4967 if [ "$GOAHEAD" != "NO" ]; then
4968 for LASTTRACK in $TRACKQUEUE; do :; done
4969 if checkstatus readtrack-$LASTTRACK; then
4970 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4971 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4972 if checkerrors batch-normalize; then exit 1; fi
4974 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4975 if [ "$DONORMALIZE" = "y" ]; then
4976 for UTRACKNUM in $TRACKQUEUE
4978 if checkstatus readtrack-$UTRACKNUM; then
4979 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4983 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4984 if checkerrors nogap-encode; then exit 1; fi
4990 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4991 if [ "$ONETRACK" = "y" ] ; then
4992 TRACKQUEUE="$FIRSTTRACK"
4993 TRACKS="$FIRSTTRACK"
4996 # Do the encoding, including parallelization of remote encoding
4997 # Figure out where each track is going to be encoded
4998 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4999 if [ "$MAXPROCS" != "0" ]; then
5000 for NUM in $(f_seq_row 1 "$MAXPROCS")
5002 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5006 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5007 for UTRACKNUM in $TRACKQUEUE
5010 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5011 if [ "$GOAHEAD" = "NO" ]; then break; fi
5012 # find out where this track is to be encoded
5013 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5014 # Make sure we have a place to encode this, if not, exit stage right
5015 if [ -z "$ENCODELOCATIONS" ]; then
5021 for LOCATION in $ENCODELOCATIONS
5023 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5024 # check first if a track has ever been assigned to this location
5025 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5026 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5027 if checkerrors encodetrack-$PREVIOUSTRACK; then
5028 for TEMPLOCATION in $ENCODELOCATIONS
5030 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5031 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5034 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5039 # We're still here, this location must have been previously assigned,
5040 # and last completed without error - check if it's done with the
5041 # previous track yet
5042 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
5044 # all locations are working, wait and try again later
5045 if [ ! $PROCEED ]; then sleep 3; fi
5047 # Record the location we're about to encode the next track at
5048 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
5050 # Don't proceed with the rest of the loop if we can't encode
5051 if [ "$ABORT" ]; then continue; fi
5052 ## FIXME ## Add here
5053 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
5054 # Set TRACKNUM, TRACKNAME
5055 if [ -e "$CDDBDATA" ]; then
5056 if [ "$ONETRACK" = "y" ]; then
5058 TRACKNUM="$FIRSTTRACK"
5062 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
5063 getcddbinfo TRACKNAME
5067 # You can't encode a file which needs to be normalized before finishing
5068 # You can't tag a file before it's finished encoding -
5069 # thus all of this is backgrounded together
5071 if [ "$DONORMALIZE" = "y" ]; then
5072 if checkstatus readtrack-$UTRACKNUM; then
5073 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5076 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5077 if checkstatus readtrack-$UTRACKNUM; then
5078 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
5079 if [ "$DONORMALIZE" = "y" ]; then
5080 if checkstatus normalizetrack-$UTRACKNUM; then
5081 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5084 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5088 if [ "$DOTAG" = "y" ]; then
5089 if checkstatus encodetrack-$UTRACKNUM; then
5090 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
5092 # Lets tag the cue file
5093 if checkstatus cleancuefile >/dev/null; then :; else
5094 if checkstatus cuefile >/dev/null ; then
5099 if [ "$DOMOVE" = "y" ]; then
5100 if checkstatus tagtrack-$UTRACKNUM; then
5101 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
5108 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5109 # we'll delete the files they're working on
5110 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5111 ## FIXME ## Check also for files which are encoded using PIPEs.
5112 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5117 for LOCATION in $ENCODELOCATIONS
5119 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5120 # "How can he give us a status update, if he's DEAD?"
5121 if checkstatus encodetrack-$CHECKTRACK; then
5124 # Nothing to see here please go quietly back to your homes
5125 if [ -z "$CHECKTRACK" ]; then continue; fi
5126 # You're still here? Maybe there is something...
5127 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
5130 if [ ! $PROCEED ]; then sleep 5; fi
5133 # If the above didn't catch the stragglers, this will
5135 if [ "$DOREPLAYGAIN" = "y" ]; then
5139 # Execute the user-defined post_encode function before cleaning up
5142 # Check to see if run_command logged any errors
5143 if [ -f "$ABCDETEMPDIR/errors" ]; then
5144 log error "The following commands failed to run:"
5145 cat "$ABCDETEMPDIR/errors"
5149 if [ "$KEEPWAVS" = "y" ];then
5153 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5154 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5155 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5156 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5157 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5158 log warning "The encoded formats does not match with the moved ones"
5159 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
5160 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
5161 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
5165 if [ "$DOCLEAN" = "y" ]; then
5166 # Wipe all the evidence
5167 # Gimme gimme gimme some more time!
5169 rm -rf "$ABCDETEMPDIR"
5172 echo "Finished. Not cleaning $ABCDETEMPDIR."