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
14 VERSION='2.7.2-UNRELEASED'
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,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 # http://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: http://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
941 echo ARTIST="$TRACKARTIST"
943 echo TITLE="$TRACKNAME"
944 if [ -n "$CDYEAR" ]; then
947 if [ -n "$CDGENRE" ]; then
948 echo GENRE="$CDGENRE"
950 echo TRACKNUMBER="${TRACKNUM:-$1}"
951 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
952 # xiph.org: http://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
953 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
954 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
955 echo TRACKTOTAL="${TRACKS}"
956 if [ -n "$DISCNUMBER" ]; then
957 echo DISCNUMBER="$DISCNUMBER"
959 echo CDDB="$CDDBDISCID"
960 if [ "$(eval echo ${COMMENT})" != "" ]; then
961 case "$COMMENTOUTPUT" in
962 *=*) echo "$COMMENTOUTPUT";;
963 *) echo COMMENT="$COMMENTOUTPUT";;
966 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
967 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
970 run_command tagtrack-$OUTPUT-$1 true
973 run_command tagtrack-$OUTPUT-$1 true
976 run_command tagtrack-$OUTPUT-$1 true
979 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
980 # Console port (mac) used for encoding does not have the ability to tag.
981 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
982 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
983 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
986 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
987 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
988 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
989 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
990 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
991 "$ABCDETEMPDIR/track$1.mp2"
994 run_command tagtrack-$OUTPUT-$1 true
997 case "$AACENCODERSYNTAX" in
999 # We will use inline tagging...
1000 run_command tagtrack-$OUTPUT-$1 true
1003 # Tag post encode with neroAacTag...
1004 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
1005 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
1006 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1009 run_command tagtrack-$OUTPUT-$1 true
1012 run_command tagtrack-$OUTPUT-$1 true
1015 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1016 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1017 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$ATOMICPARSLEY" "$ABCDETEMPDIR/track$1.m4a" \
1018 --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum=${TRACKNUM:-$1} \
1019 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
1022 run_command tagtrack-$OUTPUT-$1 true
1027 # We use mid3v2 tagging for True Audio:
1028 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1029 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1030 "$ABCDETEMPDIR/track$1.tta"
1033 run_command tagtrack-$OUTPUT-$1 true
1037 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1038 run_command tagtrack-$1 true
1044 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1047 # The commands here don't go through run_command because they're never
1048 # supposed to be silenced
1049 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1050 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1054 case "$MP3ENCODERSYNTAX" in
1059 for UTRACKNUM in $TRACKQUEUE
1061 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1063 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1065 if [ "$RETURN" != "0" ]; then
1066 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1068 for UTRACKNUM in $TRACKQUEUE
1070 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1071 #run_command encodetrack-$UTRACKNUM true
1080 if checkerrors "nogap-encode"; then :; else
1081 if [ ! "$KEEPWAVS" = "y" ] ; then
1082 if [ ! "$KEEPWAVS" = "move" ] ; then
1087 # Other encoders fall through to normal encoding as the tracks have not
1088 # been entered in the status file.
1091 # do_encode [tracknumber] [hostname]
1092 # If no hostname is specified, encode locally
1094 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1095 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1098 if [ "$USEPIPES" = "y" ]; then
1101 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1104 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1107 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1110 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1113 TEMPARG="PIPE_$SPEEXENCODER"
1116 TEMPARG="PIPE_$MPCENCODER"
1119 TEMPARG="PIPE_$WVENCODERSYNTAX"
1122 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1125 TEMPARG="PIPE_$AACENCODERSYNTAX"
1128 TEMPARG="PIPE_$AACENCODERSYNTAX"
1131 IN="$( eval echo "\$$TEMPARG" )"
1133 IN="$ABCDETEMPDIR/track$1.wav"
1135 # We need IN to proceed, if we are not using pipes.
1136 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1137 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1139 case "$TMPOUTPUT" in
1141 OUTPUT=$OGGOUTPUTCONTAINER
1144 OUTPUT=$OPUSOUTPUTCONTAINER
1147 OUTPUT=$FLACOUTPUTCONTAINER
1153 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1154 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1157 if [ X"$USEPIPES" = "Xy" ]; then
1159 # We need a way to store the creation of the files when using PIPES
1160 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1161 # When piping it does not make sense to have a higher nice for
1162 # reading than for encoding, since it will be hold by the
1163 # encoding process. Setting an effective nice, to calm down a
1164 # bit the reading process.
1165 EFFECTIVE_NICE=$READNICE
1167 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1168 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1169 EFFECTIVE_NICE=$ENCNICE
1175 case "$MP3ENCODERSYNTAX" in
1176 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1177 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1178 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1179 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1183 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1190 case "$OGGENCODERSYNTAX" in
1191 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1192 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1196 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1203 case "$OPUSENCODERSYNTAX" in
1205 # Tag the file at encode time, as it can't be done after encoding.
1206 if [ "$DOTAG" = "y" ]; then
1207 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1208 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1209 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1211 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1217 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1224 case "$FLACENCODERSYNTAX" in
1225 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1230 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1231 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1236 if [ "$(eval echo ${COMMENT})" != "" ]; then
1239 *) COMMENT="COMMENT=$COMMENT" ;;
1242 # Tag the file at encode time, as it can't be done after encoding.
1243 if [ "$DOTAG" = "y" ]; then
1244 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1245 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1247 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1251 # Tag the file inline at encode time.
1252 if [ "$DOTAG" = "y" ]; then
1253 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1254 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1256 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1260 case "$TTAENCODERSYNTAX" in
1261 # tta is the newer version with a small syntax change...
1263 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1266 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1271 case "$WVENCODERSYNTAX" in
1273 if [ "$DOTAG" = "y" ]; then
1274 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1275 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1277 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1281 if [ "$DOTAG" = "y" ]; then
1282 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1283 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1284 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1286 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1292 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1295 case "$MP2ENCODERSYNTAX" in
1297 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1300 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1305 # aac container is only used to catch faac encoded files where faac
1306 # is compiled without mp4 support (with libmp4v2).
1307 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1310 case "$AACENCODERSYNTAX" in
1312 if [ "$DOTAG" = "y" ]; then
1313 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1314 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1316 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1320 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1323 if [ "$DOTAG" = "y" ]; then
1324 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1325 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1327 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1331 if [ "$DOTAG" = "y" ]; then
1332 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1333 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1335 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1339 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1342 if [ "$DOTAG" = "y" ]; then
1343 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1344 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1345 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1347 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1353 # In case of wav output we need nothing. Just keep the wavs.
1354 # But we need the following to allow full logging and subsequent
1355 # successful cleaning of $ABCDETEMPDIR.
1356 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1361 # Only remove .wav if the encoding succeeded
1362 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1363 run_command encodetrack-$1 true
1364 if [ ! "$KEEPWAVS" = "y" ] ; then
1365 if [ ! "$KEEPWAVS" = "move" ] ; then
1371 run_command "" echo "HEH! The file we were about to encode disappeared:"
1372 run_command "" echo ">> $IN"
1373 run_command encodetrack-$1 false
1377 # do_preprocess [tracknumber]
1379 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1382 # IN="$ABCDETEMPDIR/track$1.wav"
1383 # # We need IN to proceed.
1384 # if [ -s "$IN" ] ; then
1385 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1387 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1388 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1389 # case "$POSTPROCESSFORMAT" in
1391 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1393 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1395 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1397 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1399 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1402 # # Only remove .wav if the encoding succeeded
1403 # if checkerrors "preprocess-(.{3,4})-$1"; then
1404 # run_command preprocess-$1 false
1406 # run_command preprocess-$1 true
1409 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1410 # echo "HEH! The file we were about to pre-process disappeared:"
1413 # run_command preprocess-$1 false
1418 # do_postprocess [tracknumber]
1420 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1423 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1425 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1426 # # We need IN to proceed.
1427 # if [ -s "$IN" ] ; then
1428 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1429 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1430 # case "$POSTPROCESSFORMAT" in
1432 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1434 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1436 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1438 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1440 # # Only remove .wav if the encoding succeeded
1441 # if checkerrors "postprocess-(.{3,4})-$1"; then
1442 # run_command postprocess-$1 false
1444 # run_command postprocess-$1 true
1447 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1448 # echo "HEH! The file we were about to post-process disappeared:"
1451 # run_command postprocess-$1 false
1466 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1470 # The commands here don't go through run_command because they're never supposed to be silenced
1471 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1476 for UTRACKNUM in $TRACKQUEUE
1478 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1480 # FIXME # Hard-coded batch option!
1481 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1483 if [ "$RETURN" != "0" ]; then
1484 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1486 for UTRACKNUM in $TRACKQUEUE
1488 echo normalizetrack-$UTRACKNUM >> status
1494 # do_batch_normalize
1496 # NORMALIZER, NORMALIZEROPTS
1497 do_batch_normalize ()
1499 # The commands here don't go through run_command because they're never supposed to be silenced
1500 echo "Batch normalizing tracks: $TRACKQUEUE"
1505 for UTRACKNUM in $TRACKQUEUE
1507 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1509 # XXX: Hard-coded batch option!
1510 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1512 if [ "$RETURN" != "0" ]; then
1513 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1515 for UTRACKNUM in $TRACKQUEUE
1517 echo normalizetrack-$UTRACKNUM >> status
1523 # do_normalize [tracknumber]
1525 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1528 IN="$ABCDETEMPDIR/track$1.wav"
1529 if [ -e "$IN" ] ; then
1530 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1531 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1533 if [ "$(checkstatus encode-output)" = "loud" ]; then
1534 echo "HEH! The file we were about to normalize disappeared:"
1537 run_command normalizetrack-$1 false "File $IN was not found"
1541 # do_move [tracknumber]
1542 # Deduces the outfile from environment variables
1543 # Creates directory if necessary
1545 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1548 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1550 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1551 # defined the OUTPUTFILE:
1554 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1555 ALBUMFILE="$(mungefilename "$DALBUM")"
1556 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1557 TRACKFILE="$(mungefilename "$TRACKNAME")"
1558 GENRE="$(mungegenre "$GENRE")"
1559 YEAR=${CDYEAR:-$CDYEAR}
1560 # If we want to start the tracks with a given number, we need to modify
1561 # the TRACKNUM value before evaluation
1563 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1564 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1565 if [ "$ONETRACK" = "y" ]; then
1566 if [ "$VARIOUSARTISTS" = "y" ]; then
1567 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1569 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1572 if [ "$VARIOUSARTISTS" = "y" ]; then
1573 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1575 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1578 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1579 # Once we know the specific output was successful, we can change
1580 # the OUTPUT to the value containing the container
1583 OUTPUT=$OGGOUTPUTCONTAINER
1586 OUTPUT=$OPUSOUTPUTCONTAINER
1589 OUTPUT=$FLACOUTPUTCONTAINER
1595 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1596 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1599 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1600 # FIXME # introduce warnings?
1603 # mkdir -p shouldn't return an error if the directory already exists
1604 mkdir -p "$OUTPUTFILEDIR"
1605 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1606 if checkstatus movetrack-output-$OUTPUT; then :; else
1607 run_command movetrack-output-$OUTPUT true
1612 # mkdir -p shouldn't return an error if the directory already exists
1613 mkdir -p "$OUTPUTFILEDIR"
1614 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1615 if checkstatus movetrack-output-$OUTPUT; then :; else
1616 run_command movetrack-output-$OUTPUT true
1620 # Lets move the cue file
1621 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1622 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1623 if checkstatus movecue-$OUTPUT; then :; else
1624 # Silence the Copying output since it overlaps with encoding processes...
1625 #run_command '' vecho "Copying cue file to its destination directory..."
1626 if checkstatus onetrack >/dev/null ; then
1629 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1630 # We dont have the dir, since it was not created before.
1633 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1636 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1637 # http://brianvictor.tripod.com/mp3cue.htm#details
1638 [a-z0-9][a-z0-9][a-z0-9])
1639 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1642 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1646 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1648 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1657 # Create the playlist if wanted
1659 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1660 # VARIOUSARTISTS, OUTPUTDIR
1663 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1667 OUTPUT=$OGGOUTPUTCONTAINER
1670 OUTPUT=$OPUSOUTPUTCONTAINER
1673 OUTPUT=$FLACOUTPUTCONTAINER
1679 # Create a playlist file for the playlist data to go into.
1680 # We used to wipe it out if it existed. Now we request permission if interactive.
1681 for LASTTRACK in $TRACKQUEUE; do :; done
1682 ALBUMFILE="$(mungefilename "$DALBUM")"
1683 ARTISTFILE="$(mungefilename "$DARTIST")"
1684 GENRE="$(mungegenre "$GENRE")"
1685 YEAR=${CDYEAR:-$CDYEAR}
1686 if [ "$VARIOUSARTISTS" = "y" ] ; then
1687 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1689 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1691 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1692 mkdir -p "$FINALPLAYLISTDIR"
1693 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1694 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1695 if [ "$INTERACTIVE" = "y" ]; then
1696 while [ "$DONE" != "y" ]; do
1698 case $ERASEPLAYLIST in
1699 e|E|a|A|k|K) DONE=y ;;
1700 "") ERASEPLAYLIST=e ; DONE=y ;;
1708 # Once we erase the playlist, we use append to create the new one.
1709 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1711 # The playlist does not exist, so we can safelly use append to create the new list
1714 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1715 touch "$OUTPUTDIR/$PLAYLISTFILE"
1716 for UTRACKNUM in $TRACKQUEUE
1718 # Shares some code with do_move since the filenames have to match
1719 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1720 getcddbinfo TRACKNAME
1722 TRACKFILE="$(mungefilename "$TRACKNAME")"
1723 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1724 ALBUMFILE="$(mungefilename "$DALBUM")"
1725 # If we want to start the tracks with a given number, we need to modify the
1726 # TRACKNUM value before evaluation
1728 if [ "$VARIOUSARTISTS" = "y" ]; then
1729 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1731 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1733 if [ "$VARIOUSARTISTS" = "y" ]; then
1734 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1735 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1737 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1740 if [ "$PLAYLISTDATAPREFIX" ]; then
1741 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1743 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1748 ## this will convert the playlist to have CRLF line-endings, if specified
1749 ## (some hardware players insist on CRLF endings)
1750 if [ "$DOSPLAYLIST" = "y" ]; then
1751 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1752 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1753 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1755 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1760 # This function reads a cuefile on stdin and writes an extended
1761 # cddb query on stdout. Any PREGAP for track 1 is properly
1762 # handled, although cue files embedded in FLAC files do not
1763 # appear to properly store the PREGAP setting. :(
1764 abcde.cue2discid () {
1769 while [ $val -gt 0 ] ; do
1770 ret=$(( $ret + ( $val % 10) ))
1771 val=$(( $val / 10 ))
1781 local first second third
1782 first=$(expr ${1} + 0 )
1783 second=$(expr ${2} + 0 )
1784 third=$(expr ${3} + 0 )
1786 echo $(( ((($first * 60) + $second) * 75) + $third ))
1796 while read line ; do
1799 TRACK) i=$(( i + 1 ))
1801 INDEX) if [ "$2" -eq 1 ] ; then
1803 START=$(( $LBA + $PREGAP + $OFFSET ))
1805 X=$(cddb_sum $(( $START / 75 )) )
1809 PREGAP) PREGAP=$(msf2lba $2)
1813 LEADOUT=$(( $4 / 588 ))
1816 LEADIN=$(( $3 / 588 ))
1825 LEADOUT=$(( $LEADOUT + $LEADIN ))
1827 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1828 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1829 printf "%08x %i" $DISCID $TRACKS
1832 while [ $j -le $TRACKS ] ; do
1833 eval echo -n "\" \$TRACK$j\""
1836 echo " $(( $LEADOUT / 75 ))"
1840 # abcde.mkcue [--wholedisk]
1841 # This creates a cuefile directly from the extended discid information
1842 # The --wholedisk option controls whether we're ripping data from the
1843 # start of track one or from the start of the disk (usually, but not
1844 # always the same thing!)
1846 # Track one leadin/pregap (if any) handeling:
1847 # --wholedisk specified:
1850 # INDEX 01 <pregap value>
1851 # Remaining track index values unchanged from disc TOC
1853 # --wholedisk not specified
1855 # PREGAP <pregap value>
1857 # Remaining track index values offset by <pregap value>
1864 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1867 local MODE DISCID TRACKS
1871 if [ "$1" = --wholedisc ] ; then
1877 vecho "One track is $ONETRACK"
1878 TRACKFILE="$(mungefilename "$TRACKNAME")"
1879 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1880 ALBUMFILE="$(mungefilename "$DALBUM")"
1881 if [ "$ONETRACK" = "y" ]; then
1882 if [ "$VARIOUSARTISTS" = "y" ]; then
1883 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1885 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1887 vecho "Cue wav file is $CUEWAVFILE"
1889 CUEWAVFILE="dummy.wav"
1898 echo REM DISCID $DISCID
1899 echo FILE \""$CUEWAVFILE"\" WAVE
1901 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1908 while [ $i -le "$TRACKS" ] ; do
1909 LBA=$(( $1 - $OFFSET ))
1910 printf " TRACK %02i AUDIO\n" $i
1911 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1912 if [ $MODE = PREGAP ] ; then
1913 echomsf " PREGAP " $(($OFFSET-150))
1915 echo " INDEX 00 00:00:00"
1918 echomsf " INDEX 01 " $LBA
1925 # This essentially the start of things
1928 # Query the CD to get the track info, unless the user specified -C
1929 # or we are using some actions which do not need the CDDB data at all
1930 #if [ ! X"$EXPACTIONS" = "X" ]; then
1932 #elif [ -z "$DISCID" ]; then
1933 if [ -z "$DISCID" ]; then
1934 vecho -n "Getting CD track info... "
1935 # In OSX, unmount the disc before a query
1936 if [ "$OSFLAVOUR" = "OSX" ]; then
1937 diskutil unmount ${CDROM#/dev/}
1939 case "$CDROMREADERSYNTAX" in
1941 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1942 case "$CUE2DISCID" in
1943 # FIXME # right now we have 2 cue2discid internal
1944 # implementations: builtin and abcde.cue2discid. Test
1945 # both of them and decide which one we want to use.
1947 #vecho "Using builtin cue2discid implementation..."
1948 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1950 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1952 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1953 TRACKS=${#OFFSETTIMES[@]}
1955 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1956 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1957 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1958 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1961 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1962 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1966 #vecho "Using external python cue2discid implementation..."
1967 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1971 log error "the input flac file does not contain a cuesheet."
1976 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1978 # if [ ! "$RET" = "0" ];then
1979 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1982 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1983 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1985 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1986 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1990 case "$CDDBMETHOD" in
1991 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1992 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1996 # Make sure there's a CD in there by checking cd-discid's return code
1997 if [ ! "$?" = "0" ]; then
1998 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1999 log error "cuesheet information from the flac file could not be read."
2000 log error "Perhaps the flac file does not contain a cuesheet?."
2003 log error "CD could not be read. Perhaps there's no CD in the drive?"
2007 # In OSX, remount the disc again
2008 if [ "$OSFLAVOUR" = "OSX" ]; then
2009 diskutil mount ${CDROM#/dev/}
2012 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
2014 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
2017 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2018 # This needs to be done now because a section of the resuming code will need
2021 # get the number of digits to pad TRACKNUM with - we'll use this later
2022 # a CD can only hold 99 tracks, but since we support a feature for starting
2023 # numbering the tracks from a given number, we might need to set it as a
2024 # variable for the user to define... or obtain it somehow.
2025 if [ "$PADTRACKS" = "y" ] ; then
2029 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
2030 if [ -z "$TRACKQUEUE" ]; then
2031 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2032 case "$CDROMREADERSYNTAX" in
2033 cdparanoia|libcdio|debug)
2034 if [ "$WEHAVEACD" = "y" ]; then
2035 vecho "Querying the CD for audio tracks..."
2036 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2038 if [ ! "$RET" = "0" ];then
2039 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2041 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2042 CDPARANOIAAUDIOTRACKS="$TRACKS"
2044 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2045 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
2046 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
2047 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
2049 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2050 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2054 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
2057 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2059 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2060 log info "The disc does not contain any tracks. Giving up..."
2063 echo -n "Grabbing entire CD - tracks: "
2064 if [ ! "$PADTRACKS" = "y" ] ; then
2065 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2067 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2069 while [ "$X" -ne "$TRACKS" ]
2071 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2072 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2076 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2077 # User-supplied track queue.
2078 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2079 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2080 # Once cleaned, obtain the highest value in the trackqueue for number padding
2081 for LASTTRACK in $TRACKQUEUE; do :; done
2082 if [ ! "$PADTRACKS" = "y" ] ; then
2083 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2085 # Now we normalize the trackqueue
2086 for TRACK in $TRACKQUEUE ; do
2087 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2088 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2090 TRACKQUEUE=$PADTRACKQUEUE
2091 echo Grabbing tracks: "$TRACKQUEUE"
2094 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2096 # We have the discid, create a temp directory after it to store all the temp
2099 if [ -e "$ABCDETEMPDIR" ]; then
2100 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2101 # It already exists, see if it's a directory
2102 if [ ! -d "$ABCDETEMPDIR" ]; then
2103 # This is a file/socket/fifo/device/etc, not a directory
2106 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2107 echo "Please investigate, remove it, and rerun abcde." >&2
2111 # It's a directory, let's see if it's writable by us
2112 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2113 # Nope, complain and exit
2115 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2116 echo "Please investigate, remove it, and rerun abcde." >&2
2120 # See if it's populated
2121 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2122 # Wipe and start fresh
2123 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2124 echo -n "this directory to continue. Continue [y/N]? " >&2
2125 if [ "$INTERACTIVE" = "y" ]; then
2131 if [ "$ANSWER" != "y" ]; then
2134 rm -rf "$ABCDETEMPDIR" || exit 1
2135 mkdir -p "$ABCDETEMPDIR"
2136 if [ "$?" -gt "0" ]; then
2137 # Directory already exists or could not be created
2138 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2142 # Everything is fine. Check for ^encodetracklocation-
2143 # and encode-output entries in the status file and
2144 # remove them. These are not relevant across sessions.
2145 if [ -f "$ABCDETEMPDIR/status" ]; then
2146 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2147 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2148 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2150 # Remove old error messages
2151 if [ -f "$ABCDETEMPDIR/errors" ]; then
2152 rm -f "$ABCDETEMPDIR/errors"
2156 # We are starting from scratch
2157 mkdir -p "$ABCDETEMPDIR"
2158 if [ "$?" -gt "0" ]; then
2159 # Directory already exists or could not be created
2160 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2163 cat /dev/null > "$ABCDETEMPDIR/status"
2164 # Store the abcde version in the status file.
2165 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2167 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2168 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2169 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2170 vecho "Creating cue file..."
2171 case $CDROMREADERSYNTAX in
2173 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2174 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2176 log warning "the input flac file does not contain a cuesheet."
2180 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2181 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2183 log warning "reading the CUE sheet is still considered experimental"
2184 log warning "and there was a problem with the CD reading. abcde will continue,"
2185 log warning "but consider reporting the problem to the abcde author"
2191 # If we got the CDPARANOIA status and it is not recorded, save it now
2192 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2193 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2194 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2198 # Create the discid file
2199 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2200 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2201 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2206 # Create a proper CUE file based on the CUE file we created before.
2209 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2210 CUEFILE_OUT=$CUEFILE_IN.out
2211 ### FIXME ### checkstatus cddb
2212 if [ -e "$CDDBDATA" ]; then
2213 vecho "Adding metadata to the cue file..."
2214 # FIXME It doesn't preserve spaces! Why?
2215 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2217 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2218 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2219 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2223 cat "$CUEFILE_IN" | while read line
2225 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2226 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2227 # echo "$line" >> "$CUEFILE_OUT"
2228 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2229 eval track="\$TRACK$n"
2231 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2232 # When making a single-track rip, put the
2233 # actual file name into the file declaration
2234 # in the cue file so that it is usable by
2235 # music players and the like
2236 elif [ "$ONETRACK" = "y" ] &&
2237 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2239 TRACKFILE="$(mungefilename "$TRACKNAME")"
2240 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2241 ALBUMFILE="$(mungefilename "$DALBUM")"
2243 if [ "$VARIOUSARTISTS" = "y" ]; then
2244 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2246 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2249 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2252 # FIXME # If the lines above are uncommented, remove the line below.
2253 echo "$line" >> "$CUEFILE_OUT"
2256 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2257 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2263 # Parses a CDDB file and outputs the title and the track names.
2264 # Variables: CDDBFILE
2268 # List out disc title/author and contents
2269 if [ "$ONETRACK" = "y" ]; then
2270 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2272 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2273 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2274 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2275 if [ ! X"$PARSEDYEAR" = "X" ]; then
2276 echo "Year: $PARSEDYEAR"
2279 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2280 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2281 if [ ! X"$PARSEDGENRE" = "X" ]; then
2282 echo "Genre: $PARSEDGENRE"
2285 if [ ! "$ONETRACK" = "y" ]; then
2286 for TRACK in $(f_seq_row 1 $TRACKS)
2288 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2294 # Check for a local CDDB file, and report success
2297 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2299 CDDBLOCALSTATUS="notfound"
2300 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2303 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2304 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2305 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2306 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2307 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2308 CDDBLOCALMATCH=single
2309 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2310 CDDBLOCALMATCH=multiple
2315 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2316 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2317 CDDBLOCALMATCH=single
2322 # If the user has selected to check a local CDDB repo, we proceed with it
2323 case $CDDBLOCALMATCH in
2325 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2327 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2329 # List out disc title/author and contents
2330 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2331 cat "$RESULT" > "${CDDBLOCALREAD}"
2334 do_cddbparse "${CDDBLOCALREAD}"
2336 ##FIXME## QUICK HACK !!!!
2337 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2338 } >> "$ABCDETEMPDIR/cddblocalchoices"
2340 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2341 page "$ABCDETEMPDIR/cddblocalchoices"
2343 # It's all going to fit in one page, cat it
2344 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2346 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2347 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2348 CDDBLOCALCHOICENUM=-1
2349 if [ "$INTERACTIVE" = "y" ]; then
2350 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2351 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2352 read CDDBLOCALCHOICE
2353 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2354 # FIXME # Introduce diff's
2355 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2356 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2357 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2358 # Make sure we get a valid choice
2359 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2360 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2361 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2367 #echo "Selected ..."
2369 CDDBLOCALCHOICENUM=1
2371 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2372 #echo "Using local copy of CDDB data"
2373 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2374 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2375 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2376 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2377 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2378 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2379 CDDBLOCALSTATUS="found"
2381 #echo "Not using local copy of CDDB data"
2382 CDDBLOCALSTATUS="notfound"
2386 # List out disc title/author and contents
2387 do_cddbparse "${CDDBLOCALFILE}"
2388 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2389 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2391 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2393 if [ "$INTERACTIVE" = "y" ]; then
2395 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2396 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2399 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2403 if [ "$USELOCALRESP" = "y" ]; then
2404 #echo "Using local copy of CDDB data"
2405 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2406 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2407 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2408 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2409 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2410 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2411 CDDBLOCALSTATUS="single"
2413 #echo "Not using local copy of CDDB data"
2414 CDDBLOCALSTATUS="notfound"
2418 CDDBLOCALSTATUS="notfound"
2425 # Try to read CD-Text from the drive using icedax / cdda2wav
2428 if new_checkexec icedax; then
2429 CDTEXT_READER=icedax
2430 elif new_checkexec cdda2wav; then
2431 CDTEXT_READER=cdda2wav
2433 # Didn't find either, bail
2437 if [ "$OSFLAVOUR" = "OSX" ] ; then
2438 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2439 diskutil unmount ${CDROM#/dev/}
2440 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2441 CDDA2WAVCDROM="IODVDServices"
2442 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2443 CDDA2WAVCDROM="$CDROMID"
2445 if [ "$CDROMID" = "" ]; then
2446 CDDA2WAVCDROM="$CDROM"
2448 CDDA2WAVCDROM="$CDROMID"
2452 # Do we have CD-Text on the disc (and can the drive read it?)
2453 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2454 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2456 if [ $ERRORCODE -ne 0 ]; then
2457 # No CD-Text found, bail
2461 rm -f "$ABCDETEMPDIR/cddbchoices"
2463 # Make an empty template
2464 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2465 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2466 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2467 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2468 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2469 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2470 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2471 # List out disc title/author and contents
2472 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2473 for TRACK in $(f_seq_row 1 $TRACKS)
2475 TRACKM1=$(($TRACK - 1))
2476 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2477 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2478 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2479 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2481 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2482 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2483 echo >> "$ABCDETEMPDIR/cddbchoices"
2484 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2488 # Work with the musicbrainz WS API, then transform the results here so
2489 # they look (very) like the results from CDDB. Maybe not the best way
2490 # to go, but it Works For Me (TM)
2494 if checkstatus musicbrainz-readcomplete; then :; else
2495 vecho "Obtaining Musicbrainz results..."
2496 # If MB is to be used, interpret the query results and read all
2497 # the available entries.
2498 rm -f "$ABCDETEMPDIR/cddbchoices"
2499 CDDBCHOICES=1 # Overridden by multiple matches
2500 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2501 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2503 # The helper script will write disc matches out to
2504 # cddbread.*. Count how many we have
2505 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2506 # No matches. Use the normal cddb template for the user to
2508 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2509 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2510 # List out disc title/author and contents of template
2511 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2513 for TRACK in $(f_seq_row 1 $TRACKS)
2515 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2517 echo >> "$ABCDETEMPDIR/cddbchoices"
2518 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2519 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2520 echo 503 > "$ABCDETEMPDIR/cddbquery"
2522 # We have some matches
2523 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2524 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2526 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2527 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2528 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2529 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2530 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2531 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2532 # List out disc title/author and contents
2533 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2534 for TRACK in $(f_seq_row 1 $TRACKS)
2536 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2538 echo >> "$ABCDETEMPDIR/cddbchoices"
2540 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2541 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2542 for file in "$ABCDETEMPDIR"/cddbread.*
2544 X=$(echo $file | sed 's/^.*cddbread\.//g')
2545 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2546 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2547 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2548 # List out disc title/author and contents
2549 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2550 for TRACK in $(f_seq_row 1 $TRACKS)
2552 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2554 echo >> "$ABCDETEMPDIR/cddbchoices"
2556 echo "." >> "$ABCDETEMPDIR/cddbquery"
2559 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2566 # Perform CDDB protocol version check if it hasn't already been done
2567 if checkstatus cddb-statcomplete; then :; else
2568 if [ "$CDDBAVAIL" = "n" ]; then
2570 echo 503 > "$ABCDETEMPDIR/cddbstat"
2573 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2574 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2575 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2576 vecho "Checking CDDB server status..."
2577 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2578 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2579 case "$RESPONSECODE" in
2580 210) # 210 OK, status information follows (until terminating `.')
2583 501) # 501 Illegal CDDB protocol level: <n>.
2584 CDDBPROTO=`expr $CDDBPROTO - 1`
2586 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2587 # FreeDB TESTCD disc-id is used for query
2588 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2589 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2590 case "$RESPONSECODE" in
2591 2??) # Server responded, everything seems OK
2601 if test $rc -eq 1; then
2605 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2613 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2614 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2616 # Perform CDDB query if it hasn't already been done
2617 if checkstatus cddb-querycomplete; then :; else
2618 if [ "$CDDBAVAIL" = "n" ]; then
2620 echo 503 > "$ABCDETEMPDIR/cddbquery"
2621 # The default CDDBLOCALSTATUS is "notfound"
2622 # This part will be triggered if the user CDDB repo does not
2623 # contain the entry, or if we are not trying to use the repo.
2625 vecho "Querying the CDDB server..."
2626 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2627 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2628 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2634 # no match found in database,
2635 # wget/fetch error, or user requested not to use CDDB
2636 # Make up an error code (503) that abcde
2637 # will recognize in do_cddbread
2638 # and compensate by making a template
2639 echo 503 > "$ABCDETEMPDIR/cddbquery"
2641 *) # strange and unknown error
2642 echo ERRORCODE=$ERRORCODE
2643 echo "abcde: $CDDBTOOL returned unknown error code"
2647 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2654 # If it's not to be used, generate a template.
2655 # Then, display it (or them) and let the user choose/edit it
2656 if checkstatus cddb-readcomplete; then :; else
2657 vecho "Obtaining CDDB results..."
2658 # If CDDB is to be used, interpret the query results and read all
2659 # the available entries.
2660 rm -f "$ABCDETEMPDIR/cddbchoices"
2661 CDDBCHOICES=1 # Overridden by multiple matches
2662 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2663 case "$RESPONSECODE" in
2665 # One exact match, retrieve it
2666 # 200 [section] [discid] [artist] / [title]
2667 if checkstatus cddb-read-1-complete; then :; else
2668 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2669 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2670 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2671 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2672 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2674 # List out disc title/author and contents
2675 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2676 for TRACK in $(f_seq_row 1 $TRACKS)
2678 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2680 echo >> "$ABCDETEMPDIR/cddbchoices"
2682 202|403|409|500|503)
2683 # TODO: Explain these error codes a little more accurately:
2684 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2685 # No match response:
2686 case "$RESPONSECODE" in
2687 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2688 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2689 500|503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2691 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2692 # List out disc title/author and contents of template
2693 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2695 for TRACK in $(f_seq_row 1 $TRACKS)
2697 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2699 echo >> "$ABCDETEMPDIR/cddbchoices"
2700 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2701 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2704 # Multiple exact, (possibly multiple) inexact matches
2706 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2707 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2708 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2709 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2710 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2712 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2714 vecho -n "Retrieving multiple matches... "
2715 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2716 read DISCINFO # eat top line
2720 if checkstatus cddb-read-$X-complete; then :; else
2721 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2722 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2724 # List out disc title/author and contents
2725 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2726 for TRACK in $(f_seq_row 1 $TRACKS)
2728 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2730 echo >> "$ABCDETEMPDIR/cddbchoices"
2733 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2737 for TRACK in $(f_seq_row 1 $TRACKS)
2739 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2741 echo >> "$ABCDETEMPDIR/cddbchoices"
2742 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2743 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2746 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2753 if checkstatus cddb-edit >/dev/null; then
2754 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2755 VARIOUSARTISTS="$(checkstatus variousartists)"
2756 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2759 if [ "$INTERACTIVE" = "y" ]; then
2760 # We should show the CDDB results both when we are not using the local CDDB repo
2761 # or when we are using it but we could not find a proper match
2762 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2763 # Display the $ABCDETEMPDIR/cddbchoices file created above
2764 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2765 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2766 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2767 CHOICE=$(checkstatus cddb-choice)
2768 if [ -n "$CHOICE" ] ; then
2769 case $CDDBCHOICES in
2770 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2771 log error "CDDB query failed!"
2774 cat "$ABCDETEMPDIR/cddbchoices"
2777 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2779 echo "Selected: #$CHOICE"
2780 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2784 # The user has a choice to make, display the info in a pager if necessary
2785 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2786 page "$ABCDETEMPDIR/cddbchoices"
2788 # It's all going to fit in one page, cat it
2789 cat "$ABCDETEMPDIR/cddbchoices" >&2
2793 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2795 # I'll take CDDB read #3 for $400, Alex
2796 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2797 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2799 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2800 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2801 if [ ! X"$DIFF" = "X" ]; then
2802 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2803 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2804 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2805 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2806 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2807 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2809 # We parse the 2 choices to diff, store them in temporary files and diff them.
2810 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2811 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2813 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2814 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2815 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2816 page "$ABCDETEMPDIR/cddbread.diff"
2818 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2822 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2824 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2825 # Make sure we get a valid choice
2826 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2827 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2828 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2832 if [ "$CDCHOICENUM" = "0" ]; then
2833 vecho "Creating empty CDDB template..."
2835 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2837 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2838 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2840 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2844 # We need some code to show the selected option when local repository is selected and we have found a match
2845 vecho "Using cached CDDB match..." >&2
2846 # Display the $ABCDETEMPDIR/cddbchoices file created above
2847 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2848 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2849 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2850 CHOICE=$(checkstatus cddb-choice)
2851 if [ "$USELOCALRESP" = "y" ]; then :; else
2852 if [ -n "$CHOICE" ] ; then
2853 case $CDDBCHOICES in
2856 echo "Selected template."
2858 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2860 echo "Selected: #$CHOICE"
2861 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2869 # We're noninteractive - pick the first choice.
2870 # But in case we run a previous instance and selected a choice, use it.
2871 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2872 # Show the choice if we are not using the locally stored one
2873 # or when the local search failed to find a match.
2874 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2875 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2876 #if [ "$PREVIOUSCHOICE" ]; then
2877 cat "$ABCDETEMPDIR/cddbchoices"
2880 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2881 CDCHOICENUM=$PREVIOUSCHOICE
2884 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2886 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2891 if checkstatus cddb-choice >/dev/null; then :; else
2892 echo "abcde: internal error: cddb-choice not recorded." >&2
2895 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2896 echo -n "Edit selected CDDB data " >&2
2897 if [ "$INTERACTIVE" = "y" ]; then
2898 if [ "$UNKNOWNDISK" = "y" ]; then
2899 echo -n "[Y/n]? " >&2
2901 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2903 echo -n "[y/N]? " >&2
2910 if [ "$EDITCDDB" = "y" ]; then
2911 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2913 # Use the debian sensible-editor wrapper to pick the editor that the
2914 # user has requested via their $EDITOR environment variable
2915 if [ -x "/usr/bin/sensible-editor" ]; then
2916 /usr/bin/sensible-editor "$CDDBDATA"
2917 elif [ -n "$EDITOR" ]; then
2918 if [ -x $(which "${EDITOR%%\ *}") ]; then
2919 # That failed, try to load the preferred editor, starting
2920 # with their EDITOR variable
2921 eval $(echo "$EDITOR") \"$CDDBDATA\"
2923 # If that fails, check for a vi
2924 elif which vi >/dev/null 2>&1; then
2926 elif [ -x /usr/bin/vim ]; then
2927 /usr/bin/vim "$CDDBDATA"
2928 elif [ -x /usr/bin/vi ]; then
2929 /usr/bin/vi "$CDDBDATA"
2930 elif [ -x /bin/vi ]; then
2932 # nano should be on all (modern, i.e., sarge) debian systems
2933 elif which nano >/dev/null 2>&1 ; then
2935 elif [ -x /usr/bin/nano ]; then
2936 /usr/bin/nano "$CDDBDATA"
2937 # mg should be on all OpenBSD systems
2938 elif which mg >/dev/null 2>&1 ; then
2940 elif [ -x /usr/bin/mg ]; then
2941 /usr/bin/mg "$CDDBDATA"
2944 log warning "no editor available. Check your EDITOR environment variable."
2946 # delete editor backup file if it exists
2947 if [ -w "$CDDBDATA~" ]; then
2952 # Some heuristics first. Look at Disc Title, and if it starts with
2953 # "Various", then we'll assume Various Artists
2954 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2955 echo "Looks like a Multi-Artist CD" >&2
2958 echo -n "Is the CD multi-artist [y/N]? " >&2
2959 if [ "$INTERACTIVE" = "y" ]; then
2966 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2969 # Need NUMTRACKS before cddb-tool will return it:
2970 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2971 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2972 # More than 1/2 tracks contain a "/", so guess forward
2974 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2975 # More than 1/2 contain a "-", so guess forward-dash
2977 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2978 # More than 1/2 contain something in parens, so guess trailing-paren
2982 echo "1) Artist / Title" >&2
2983 echo "2) Artist - Title" >&2
2984 echo "3) Title / Artist" >&2
2985 echo "4) Title - Artist" >&2
2986 echo "5) Artist: Title" >&2
2987 echo "6) Title (Artist)" >&2
2988 echo "7) This is a single-artist CD" >&2
2989 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2990 if [ "$INTERACTIVE" = "y" ]; then
2991 read VARIOUSARTISTSTYLE
2993 echo $DEFAULTSTYLE >&2
2994 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2996 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2997 # If they press Enter, then the default style (0) was chosen
2998 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2999 echo "Invalid selection. Please choose a number between 1 and 7."
3000 echo -n "Selection [1-7]: "
3001 read VARIOUSARTISTSTYLE
3002 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3004 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3005 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3007 vecho "Selected: $VARIOUSARTISTSTYLE"
3008 case "$VARIOUSARTISTSTYLE" in
3010 VARIOUSARTISTSTYLE=forward
3013 VARIOUSARTISTSTYLE=forward-dash
3016 VARIOUSARTISTSTYLE=reverse
3019 VARIOUSARTISTSTYLE=reverse-dash
3022 VARIOUSARTISTSTYLE=colon
3025 VARIOUSARTISTSTYLE=trailing-paren
3033 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
3034 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
3036 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3037 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3038 # This works but does not have the necessary error checking
3039 # yet. If you are familiar with the CDDB spec
3040 # (see http://www.freedb.org/src/latest/DBFORMAT)
3041 # and can create an error-free entry on your own, then put
3042 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3043 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3044 # your abcde.conf to change the email address submissions are
3047 # submit the modified file, if they want
3048 if [ "$NOSUBMIT" != "y" ]; then
3049 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3051 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3052 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3054 echo -n 'Invalid selection. Please answer "y" or "n": '
3057 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3058 echo -n "Sending..."
3059 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
3066 # User CDDBLOCALPOLICY to find out if we store the file or not...
3067 # Cache edited CDDB entry in the user's cddb dir
3068 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3069 # Make sure the cache directory exists
3070 mkdir -p $CDDBLOCALDIR
3071 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
3074 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
3078 # try to download CD cover
3082 ALBUMFILE="$(mungefilename "$DALBUM")"
3083 ARTISTFILE="$(mungefilename "$DARTIST")"
3084 GENRE="$(mungegenre "$GENRE")"
3085 YEAR=${CDYEAR:-$CDYEAR}
3086 # have we got a musicbrainz mbid or amazon asin?
3087 case "$CDDBMETHOD" in
3089 # try musicbrainz mbid
3090 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
3091 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
3092 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3093 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3094 vecho "cover URL: $ALBUMARTURL" >&2
3095 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3096 if [ $? -ne 0 ]; then
3097 vecho "could not download cover from musicbrainz" >&2
3099 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3100 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3101 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3102 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3103 vecho "cover URL: $ALBUMARTURL" >&2
3104 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3105 if [ $? -ne 0 ]; then
3106 vecho "could not download cover from amazon" >&2
3108 # Check that size is reasonable; sometimes when there is no cover image
3109 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3110 FILESIZE=$(wc -c < "$ABCDETEMPDIR/$ALBUMARTFILE")
3111 if [ "$FILESIZE" -lt 1024 ]; then
3112 rm "$ABCDETEMPDIR/$ALBUMARTFILE"
3113 vecho "could not download cover from amazon" >&2
3117 vecho "no amazon ID found" >&2
3121 vecho "no musicbrainz ID found" >&2
3126 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3127 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3128 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3129 if [ $? -ne 0 ]; then
3130 vecho "could not download cover with glyrc" >&2
3135 if [ "$INTERACTIVE" = "y" ]; then
3136 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3137 # display properties of coverart when identify is available
3138 if new_checkexec $IDENTIFY; then
3139 $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
3141 # display coverart when DISPLAY is set and display command is available
3142 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3143 $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
3146 # nothing downloaded yet
3147 vecho "automatic album art downloading failed" >&2
3149 # see if the user can find a better album art manually
3150 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3152 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3153 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3155 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3158 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3159 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3161 if [ ! -z "$ALBUMARTURL" ]; then
3162 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3163 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3164 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3165 vecho "unable to download $ALBUMARTURL" >&2
3167 else # it's a local path
3168 cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
3169 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3170 vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
3176 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3177 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3178 ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
3179 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3180 if new_checkexec $CONVERT; then
3181 mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3182 $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
3183 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3185 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3186 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3190 # copy to target directories
3191 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3192 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3194 # put cover in the same place as the album
3195 if [ "$ONETRACK" = "y" ] ; then
3196 if [ "$VARIOUSARTISTS" = "y" ] ; then
3197 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3199 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3202 if [ "$VARIOUSARTISTS" = "y" ] ; then
3203 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3205 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3208 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3209 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3210 mkdir -p "$FINALALBUMARTDIR"
3211 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3213 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3214 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3216 log warning "could not get cover"
3217 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3221 # do_cdread [tracknumber]
3222 # do_cdread onetrack [firsttrack] [lasttrack]
3226 # The commands here don't go through run_command because they're never supposed to be silenced
3227 # return codes need to be doublechecked anyway, however
3228 if [ "$1" = "onetrack" ]; then
3229 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3230 # FIXME # Until then, we grab the whole CD in one track, no matter what
3232 # We need the first and last track for cdda2wav/icedax
3234 LASTTRACK=$(expr $3 + 0)
3235 UTRACKNUM=$FIRSTTRACK
3236 case "$CDROMREADERSYNTAX" in
3237 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
3240 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
3241 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
3242 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3243 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3244 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3250 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3251 if [ "$USEPIPES" = "y" ]; then
3252 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3253 FILEARG="$( eval echo "\$$TEMPARG" )"
3254 PIPE_MESSAGE="and encoding "
3256 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3257 case "$CDROMREADERSYNTAX" in
3258 ## FIXME ## Find the cases for flac, to avoid exceptions
3260 FILEARG="--output-name=$WAVDATA"
3267 if [ "$1" = "onetrack" ]; then
3268 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3270 if [ -r "$CDDBDATA" ]; then
3271 getcddbinfo TRACKNAME
3272 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3274 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3277 case "$CDROMREADERSYNTAX" in
3278 ### FIXME ### use an exception for flac, since it uses -o
3279 ### FIXME ### Shall we just use -o $FILEARG ??
3281 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3282 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3283 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3285 if [ "$USEPIPES" = "y" ]; then
3286 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3288 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3292 if [ "$OSFLAVOUR" = "OSX" ] ; then
3293 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3294 diskutil unmount ${CDROM#/dev/}
3295 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3296 CDDA2WAVCDROM="IODVDServices"
3297 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3298 CDDA2WAVCDROM="$CDROMID"
3300 if [ "$CDROMID" = "" ]; then
3301 CDDA2WAVCDROM="$CDROM"
3303 CDDA2WAVCDROM="$CDROMID"
3306 if [ "$USEPIPES" = "y" ]; then
3307 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3309 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3313 # I cannot get USEPIPES to work with dagrab so just this:
3314 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2
3317 if [ "$USEPIPES" = "y" ]; then
3318 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3320 # Write ripped audio data to stdout and redirect to $FILEARG.
3321 # Progress is written to stderr by default and thus >&2 is not required.
3322 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3326 # Find the track's mounted path
3327 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3328 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3329 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3330 # If the file exists, copy it
3331 if [ -e "$FILEPATH" ] ; then
3332 if [ "$USEPIPES" = "y" ]; then
3333 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3335 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3341 if [ "$USEPIPES" = "y" ]; then
3342 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3344 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
3349 # If we get some error or we get some missing wav
3350 # (as long as we dont use pipes)
3351 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3352 # Thank goodness errors is only machine-parseable up to the
3353 # first colon, otherwise this woulda sucked
3354 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3355 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3357 if [ "$USEPIPES" = "y" ]; then
3358 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3360 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3364 if [ "$USEPIPES" = "y" ]; then
3365 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3367 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3369 if [ "$1" = "onetrack" ]; then
3370 echo onetrack >> "$ABCDETEMPDIR/status"
3376 # No values accepted, only uses env variables
3379 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3380 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3382 echo "abcde: unable to set the device speed" >&2
3388 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3391 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3393 warning) shift ; log warning "$@" ;;
3401 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3404 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3406 warning) shift ; log warning "$@" ;;
3414 # decho outputs a debug message if DEBUG is selected
3417 if [ x"$DEBUG" != "x" ]; then
3418 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3419 DEBUGECHO=$(echo "$@" | tr -d '[]')
3420 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3422 echo >&4 "[DEBUG] $1"
3427 # User-redefinable functions
3428 # Custom filename munging:
3431 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3434 # Custom genre munging:
3437 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3441 # Empty pre_read function, to be defined in the configuration file.
3448 # Empty post_read function, to be defined in the configuration file.
3455 # Empty post_encode function, to be defined in the configuration file.
3461 ###############################################################################
3464 # Start of execution
3465 ###############################################################################
3470 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3472 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3473 CDDBSUBMIT=freedb-submit@freedb.org
3475 HELLOINFO="$(whoami)@$(hostname)"
3477 CDDBLOCALPOLICY="always"
3478 CDDBLOCALRECURSIVE="y"
3479 CDDBLOCALDIR="$HOME/.cddb"
3482 # List of fields we parse and show during the CDDB parsing...
3483 SHOWCDDBFIELDS="year,genre"
3486 #CDROMREADERSYNTAX=cdparanoia
3487 ENCODERSYNTAX=default
3489 MP3ENCODERSYNTAX=default
3490 OGGENCODERSYNTAX=default
3491 OPUSENCODERSYNTAX=default
3492 FLACENCODERSYNTAX=default
3493 SPEEXENCODERSYNTAX=default
3494 MPCENCODERSYNTAX=default
3495 WVENCODERSYNTAX=default
3496 TTAENCODERSYNTAX=default
3497 APENCODERSYNTAX=default
3498 MP2ENCODERSYNTAX=default
3499 AACENCODERSYNTAX=default
3500 NORMALIZERSYNTAX=default
3501 CUEREADERSYNTAX=default
3503 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3504 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3505 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3506 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3507 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3508 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3509 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3510 PLAYLISTDATAPREFIX=''
3511 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3512 VAPLAYLISTDATAPREFIX=''
3520 VARIOUSARTISTSTYLE=forward
3527 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3528 # i.e. CDROMID="1,0,0"
3530 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3531 # If we are using the ide-scsi emulation layer, we need to define a "g"
3532 CDPARANOIACDROMBUS="d"
3534 # program paths - defaults to checking your $PATH
3540 XINGMP3ENC=xingmp3enc
3554 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3558 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3568 NEROAACENC=neroAacEnc
3570 # Note that the qaac PATH will almost always require adjustment
3571 # as it is a Windows application being run through Wine. More
3572 # detailed notes in the sample abcde.conf file in the abcde tarball.
3575 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3583 VORBISCOMMENT=vorbiscomment
3585 NEROAACTAG=neroAacTag
3586 ATOMICPARSLEY=AtomicParsley
3589 CDPARANOIA=cdparanoia
3590 CD_PARANOIA=cd-paranoia
3597 MUSICBRAINZ=abcde-musicbrainz-tool
3601 NORMALIZE=normalize-audio
3603 VORBISGAIN=vorbisgain
3607 # For Wavpack replay gain we set both the default of 'track gain'
3608 # as well as this option for 'album gain'. Better media players
3609 # such as vlc can select either or neither. Andrew.
3620 # Options for programs called from abcde
3632 VORBISGAINOPTS="--album"
3636 # The flac option is a workaround for an error where flac fails
3637 # to encode with error 'floating point exception'. This is flac
3638 # error in get_console_width(), corrected in flac 1.3.1
3640 FLACGAINOPTS="--add-replay-gain"
3647 # True Audio has no useful options but it is here anyway :)
3650 # Monkey's Audio Console (mac) chokes without a mode setting
3651 # so we set one here.
3658 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3659 # we set bitrate here.
3660 FDKAACENCOPTS='--bitrate 192k'
3682 VORBISCOMMENTOPTS="-R"
3683 METAFLACOPTS="--no-utf8-convert"
3688 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3690 # Defaults for album art downloads
3691 ALBUMARTFILE="cover.jpg"
3693 ALBUMARTALWAYSCONVERT="n"
3695 # Default to one process if -j isn't specified
3698 # List of actions to perform - by default, run to completion
3699 ACTIONS=cddb,read,encode,tag,move,clean
3701 # This option is basically for Debian package dependencies:
3702 # List of preferred outputs - by default, run with whatever we have in the path
3703 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
3705 # List of preferred cdromreaders - by default, run whichever we have in the path
3706 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3708 # fd for when `vecho` and `log info` called with redirected stdout
3711 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3712 # Linux/OpenBSD. ftp is user for NetBSD.
3713 # Let's use these checkings to determine the OS flavour, which will be used
3715 if [ X$(uname) = "XFreeBSD" ] ; then
3720 elif [ X$(uname) = "XDarwin" ] ; then
3723 # We should have diskutil in OSX, but let's be sure...
3725 CDROMREADERSYNTAX=cddafs
3726 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3728 elif [ X$(uname) = "XOpenBSD" ] ; then
3732 elif [ X$(uname) = "XNetBSD" ] ; then
3736 elif [ X$(uname) = "SunOS" ] ; then
3744 # If CDDBAVAIL is set to n, no CDDB read is done
3748 # But before we get into business, let us chop off any GREP environmental
3753 if [ -z "$OUTPUTDIR" ]; then
3757 if [ -z "$WAVOUTPUTDIR" ]; then
3758 WAVOUTPUTDIR="$OUTPUTDIR"
3761 # Load system defaults
3762 if [ -r /etc/abcde.conf ]; then
3765 # Load user preference defaults
3766 if [ -r $HOME/.abcde.conf ]; then
3770 # By this time, we need some HTTPGETOPTS already defined.
3771 # If the user has defined a non-default HTTPGET method, we should not be empty.
3773 if [ "$HTTPGETOPTS" = "" ] ; then
3775 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3776 curl) HTTPGETOPTS="-f -s";;
3777 fetch)HTTPGETOPTS="-q -o -";;
3778 ftp) HTTPGETOPTS="-a -V -o - ";;
3779 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3783 # If the CDROM has not been set yet, find a suitable one.
3784 # If this is a devfs system, default to /dev/cdroms/cdrom0
3785 # instead of /dev/cdrom
3786 if [ "$CDROM" = "" ] ; then
3787 if [ -e /dev/cdroms/cdrom0 ]; then
3788 CDROM=/dev/cdroms/cdrom0
3789 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3790 CDROM=/dev/${BASH_REMATCH[1]}
3791 elif [ -e /dev/cdrom ]; then
3793 elif [ -e /dev/sr0 ]; then
3795 elif [ -e /dev/cd0c ]; then
3797 elif [ -e /dev/acd0c ]; then
3799 elif [ -e /dev/disk1 ]; then
3804 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3805 # that's changed to a number to allow for more control. Deal with
3806 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3807 case "$EXTRAVERBOSE" in
3816 # Parse command line options
3817 while getopts 1a:bc:C:d:DefgGhj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3820 a) ACTIONS="$OPTARG" ;;
3821 A) EXPACTIONS="$OPTARG" ;;
3823 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3824 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3825 d) CDROM="$OPTARG" ;;
3828 e) ERASEENCODEDSTATUS=y ;;
3829 E) ENCODING="$OPTARG" ;;
3834 j) MAXPROCS="$OPTARG" ;;
3837 L) CDDBUSELOCAL=y ;;
3842 o) OUTPUTTYPE="$OPTARG" ;;
3845 r) REMOTEHOSTS="$OPTARG" ;;
3846 R) CDDBLOCALRECURSIVE=y ;;
3847 s) SHOWCDDBFIELDS="$OPTARG" ;;
3848 S) CDSPEEDVALUE="$OPTARG" ;;
3849 t) STARTTRACKNUMBER="$OPTARG" ;;
3850 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3853 echo "This is abcde v$VERSION."
3854 echo "Usage: abcde [options] [tracks]"
3855 echo "abcde -h for extra help"
3858 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3860 X) CUE2DISCID="$OPTARG" ;;
3861 w) COMMENT="$OPTARG" ;;
3862 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3863 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
3864 STARTTRACKNUMBERTAG="y"
3865 COMMENT="CD${OPTARG}"
3866 DISCNUMBER="${OPTARG}"
3868 log error "argument of -W must be integer"
3872 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3877 shift $(($OPTIND - 1))
3879 # Here it comes the worse part of the whole thing. From here until we start
3880 # ripping, we have a mixture of sanity checks, verifications, default settigs
3881 # and other crazy stuff that interdepends, but hey, someone has to do it.
3883 # If NOCDDBQUERY is set, don't query the CDDB server.
3884 if [ "$NOCDDBQUERY" = "y" ]; then
3888 # If the user specified a flac file, then switch to special flac mode
3889 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3890 if [ ! -f "$CDROM" ]; then
3891 log error "the defined file for FLAC ripping cannot be found" >&2
3894 vecho warning "switching to flac CDROMREADERSYNTAX..."
3895 CDROMREADERSYNTAX=flac
3896 # We have a builtin version of cue2discid...
3897 case "$CUE2DISCID" in
3899 *) NEEDCUE2DISCID=y;;
3905 # If the user provided a DISCID, disable eject
3906 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3908 # Check the available cd rippers in the system, from the ones we know.
3909 if [ "$CDROMREADERSYNTAX" = "" ]; then
3910 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3911 if new_checkexec $DEFAULT_CDROMREADER; then
3912 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3916 if [ "$CDROMREADERSYNTAX" = "" ]; then
3917 log error "no cdreader found in your PATH"
3918 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3923 # Decide if we can continue.
3924 if [ "$ONETRACK" = "y" ]; then
3925 # FIXME # remove check as soon as we find out about the other readers
3926 case "$CDROMREADERSYNTAX" in
3928 cdparanoia | libcdio) ;;
3929 cdda2wav | icedax) ;;
3931 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3934 if [ "$BATCHNORM" = "y" ]; then
3935 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3938 if [ "$NOGAP" = "y" ]; then
3939 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3942 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3943 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3944 if [ $# -gt 0 ]; then
3945 log warning "ONETRACK mode selected, grabbing all tracks..."
3948 while [ $# -gt 0 ]; do
3949 # Range parsing code courtesy of Vincent Ho
3950 # Cleaned up to use shell built-ins by Charles Steinkuehler
3951 if [ "${1#*[^0-9-]}" != "$1" ]; then
3952 log error "syntax error while processing track numbers ($1)"
3957 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3958 TRACKQUEUE="$TRACKQUEUE $RSTART"
3959 RSTART=$(( $RSTART + 1 ))
3966 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3967 # List of experimental actions: retag,transcode
3969 # Determine what actions are to be done from $ACTIONS and set the
3970 # following environment variables for them:
3982 ## FIXME ## Lets keep compatibility with -M
3983 [ "$DOCUE" != "y" ] && DOCUE=n
3985 for ACTION in $(echo $ACTIONS | tr , \ )
3988 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
3989 cue) DOCUE=y ; MAKECUEFILE=y ;;
3992 normalize) DONORMALIZE=y; DOREAD=y;;
3993 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3994 encode) DOENCODE=y; DOREAD=y;;
3995 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3996 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3997 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3998 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
3999 playlist) DOCDDB=y; DOPLAYLIST=y;;
4001 getalbumart) GETALBUMART=y;;
4005 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4006 # FIXME # should we abort on error or just inform the user?
4007 log warning "selected both normalize and replaygain actions"
4010 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
4011 case $SHOWCDDBFIELD in
4012 y*|Y*) SHOWCDDBYEAR="y";;
4013 g*|G*) SHOWCDDBGENRE="y";;
4018 # At this point a CDROM has to be defined, so we check it exists.
4019 if [ X"$CDROM" != "X" ] ; then
4020 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
4021 if [ "$OSFLAVOUR" = "FBSD" ]; then
4022 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
4023 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4024 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4028 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
4029 log error "CDROM device cannot be found."
4032 # avoid processing if we are not going to hit the CDROM.
4033 elif [ X"$DOREAD" = "Xy" ]; then
4034 log error "CDROM has not been defined or cannot be found"
4038 # USEPIPES pre-tests, before we get into more serious stuff
4039 # Not compatible with:
4040 # - multiple outputs
4042 # - lowdisk algorithm
4044 if [ X"$USEPIPES" = "Xy" ]; then
4045 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
4046 log error "Unix pipes not compatible with multiple outputs"
4049 if [ X"$DONORMALIZE" = "Xy" ]; then
4050 log error "Unix pipes not compatible with normalizer"
4051 # FIXME # Do we need to exit or shall we just disable the mode?
4054 if [ X"$BATCHNORM" = "Xy" ]; then
4055 log error "Unix pipes not compatible with BATCHNORM encoding"
4058 if [ X"$NOGAP" = "Xy" ]; then
4059 log error "Unix pipes not compatible with NOGAP encoding"
4062 if [ X"$DOENCODE" = "Xn" ]; then
4063 vecho warning "Disabling Unix pipes since we are not encoding!"
4066 if [ X"$LOWDISK" = "Xy" ]; then
4067 log error "Unix pipes not compatible with lowdisk algorithm"
4072 # LOWDISK pre-tests, before we get into more problematic stuff
4073 # Not compatible with anything that needs all the files in the hard disc:
4076 if [ X"$LOWDISK" = "Xy" ]; then
4077 if [ X"$BATCHNORM" = "Xy" ]; then
4078 log error "Unix pipes not compatible with BATCHNORM encoding"
4081 if [ X"$NOGAP" = "Xy" ]; then
4082 log error "Unix pipes not compatible with NOGAP encoding"
4087 # BATCHNORM pre-tests, before we get into serious problems
4088 # Not compatible with
4089 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4090 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4094 # Check the encoding format from the ones available in the system, if nothing has been configured.
4095 if [ X"$OUTPUTTYPE" = "X" ]; then
4096 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4097 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
4098 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
4099 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
4100 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4101 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4105 if [ X"$OUTPUTTYPE" = "X" ]; then
4106 log error "no encoder found in the PATH"
4107 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4112 # Decide which CDROM reader we're gonna use
4113 case "$CDROMREADERSYNTAX" in
4115 CDROMREADER="$CDPARANOIA"
4116 CDROMREADEROPTS="$CDPARANOIAOPTS"
4119 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4120 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4121 CDROMREADER="$CD_PARANOIA"
4122 CDROMREADEROPTS="$CDPARANOIAOPTS"
4125 CDROMREADER="$CDDA2WAV"
4126 CDROMREADEROPTS="$CDDA2WAVOPTS"
4129 CDROMREADER="$DAGRAB"
4130 CDROMREADEROPTS="$DAGRABOPTS"
4134 CDROMREADEROPTS="$PIRDOPTS"
4137 CDROMREADER="$CDDAFS"
4138 CDROMREADEROPTS="$CDDAFSOPTS"
4142 CDROMREADEROPTS="$FLACOPTS"
4146 # There's only one normalize...
4147 case "$NORMALIZERSYNTAX" in
4149 NORMALIZER="$NORMALIZE"
4150 NORMALIZEROPTS="$NORMALIZEOPTS"
4154 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4155 case "$OUTPUTTYPE" in *:*)
4156 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4157 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4159 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4160 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4161 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4162 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4163 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4164 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4165 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4166 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4167 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4168 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4169 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4172 # Allows commandline selection of options while using multiple outputs.
4173 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4174 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4175 TEMPOUTPUT=${OUTPUT%%:*}
4176 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4178 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4182 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4183 # for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as and
4184 # wavpack for wvs...
4186 # Getting ready for multiple output changes
4187 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4191 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4192 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4193 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4194 OGGOUTPUTCONTAINER=ogg
4197 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4198 OPUSOUTPUTCONTAINER=opus
4201 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4202 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4203 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4206 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4207 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4208 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4209 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4212 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4213 # [ "$DOREPLAYGAIN" = "y" ] &&
4216 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4217 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4220 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4222 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4223 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4226 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4227 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4230 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4231 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4232 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4235 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4236 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4237 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4240 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4242 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4243 # compiled without libmp4v2... Andrew.
4246 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4247 [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4248 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4249 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4250 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4251 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4254 if [ "$KEEPWAVS" = "y" ]; then
4255 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4259 *) log error "Invalid OUTPUTTYPE defined"
4265 # decide which encoder
4266 case "$MP3ENCODERSYNTAX" in
4268 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4272 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4276 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4277 MP3ENCODER="$BLADEENC"
4280 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4284 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4285 MP3ENCODER="$XINGMP3ENC"
4288 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4289 MP3ENCODER="$MP3ENC"
4292 case "$OGGENCODERSYNTAX" in
4294 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4295 OGGENCODER="$VORBIZE"
4298 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4299 OGGENCODER="$OGGENC"
4302 case "$OPUSENCODERSYNTAX" in
4304 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4305 OPUSENCODER="$OPUSENC"
4308 case "$FLACENCODERSYNTAX" in
4310 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4312 if [ "$DOREPLAYGAIN" = "y" ]; then
4313 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4315 # FLAC streams can be encapsulated on a Ogg transport layer
4316 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4317 log error "FLAC on an Ogg container is not yet supported"
4318 log error "due to problem with adding comments to such files"
4320 FLACOUTPUTCONTAINER=ogg
4322 FLACOUTPUTCONTAINER=flac
4326 case "$SPEEXENCODERSYNTAX" in
4328 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4329 SPEEXENCODER="$SPEEXENC"
4332 case "$MPCENCODERSYNTAX" in
4334 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4335 MPCENCODER="$MPCENC"
4338 case "$WVENCODERSYNTAX" in
4340 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4341 # and in the interests of backward compatibility:
4342 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4343 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4344 WVENCODER="$WAVPACK"
4346 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4347 WVENCODER="$WAVPACK"
4351 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4355 case "$TTAENCODERSYNTAX" in
4357 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4361 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4362 TTAENCODER="$TTAENC"
4365 case "$APENCODERSYNTAX" in
4367 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4371 case "$MP2ENCODERSYNTAX" in
4373 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4374 MP2ENCODER="$TWOLAME"
4377 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4378 MP2ENCODER="$FFMPEG"
4381 case "$AACENCODERSYNTAX" in
4382 # Some elaborate 'if' work to keep backward compatibility for those
4383 # who don't realise that AACENCOPTS does not work with abcde from
4384 # version 2.7 onwards.
4386 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4387 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4390 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4395 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4396 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4397 AACENCODER="$NEROAACENC"
4399 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4400 AACENCODER="$NEROAACENC"
4404 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4405 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4406 AACENCODER="$FDKAAC"
4408 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4409 AACENCODER="$FDKAAC"
4413 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4414 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4417 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4422 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4423 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4424 AACENCODER="$FHGAACENC"
4426 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4427 AACENCODER="$FHGAACENC"
4431 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4432 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4433 AACENCODER="$FFMPEG"
4435 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4436 AACENCODER="$FFMPEG"
4446 TAGGEROPTS="$ID3OPTS"
4451 TAGGEROPTS="$ID3V2OPTS"
4456 TAGGEROPTS="$ID3TAGOPTS"
4460 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4461 # trouble with CDDBPROTO=5 (which we test here) but also
4462 # with cached cddb files in latin1 (which we cannot test).
4463 if [ "$CDDBPROTO" -lt 6 ]; then
4464 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4467 # eyeD3 version 0.7 changed syntax
4468 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4469 # only if it offers the --set-encoding, assume <= 0.6.x
4471 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4473 # anything wrong, any failure, assume >= 0.7
4475 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4479 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4484 # NOGAP is specific to lame. Other encoders fail ...
4485 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4486 log warning "the NOGAP option is specific to lame. Deactivating..."
4491 case "$CUEREADERSYNTAX" in
4493 CUEREADEROPTS="${CDROM}"
4498 # which information retrieval tool are we using?
4504 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4505 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4506 log error "FLAC on an Ogg container is not yet supported"
4507 log error "due to problem with adding comments to such files"
4509 OGGOUTPUTCONTAINER=ogg.ogg
4510 FLACOUTPUTCONTAINER=flac.ogg
4511 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4514 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4516 if [ "$ENCNICE" ]; then
4517 ENCNICE="-n $ENCNICE"
4519 if [ "$READNICE" ]; then
4520 READNICE="-n $READNICE"
4522 if [ "$DISTMP3NICE" ]; then
4523 DISTMP3NICE="-n $DISTMP3NICE"
4526 # Don't check for stuff if it's not needed
4527 if [ "$REMOTEHOSTS" ]; then
4530 if [ "$DONORMALIZE" = "y" ]; then
4533 if [ "$EJECTCD" = "y" ]; then
4536 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4537 if [ "$CDDBMETHOD" = "cddb" ]; then
4539 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4543 if [ "$DOCUE" = "y" ]; then
4547 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4548 case "$CDROMREADERSYNTAX" in
4549 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4550 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4551 ### FIXME ### translate "cue2discid" from python to bash
4552 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4557 if [ "$GETALBUMART" = "y" ]; then
4562 ###USEPIPESSUPPORT###
4564 # Rippers with USEPIPE support
4565 PIPERIPPER_cdparanoia="-"
4566 PIPERIPPER_libcdio="-"
4567 # Note that by default in abcde cdda2wav redirects to icedax.
4568 PIPERIPPER_cdda2wav="-"
4569 PIPERIPPER_debug="-"
4570 PIPERIPPER_flac="-c "
4573 # Encoders with USEPIPE support
4576 PIPE_bladeenc="stdin"
4589 # Both neroAacEnc and fdkaac seem to manage without the addition of
4590 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4591 # in this manner. Andrew.
4595 # Figure out if we can use pipes with the ripper/encoder combination
4597 if [ "$USEPIPES" = "y" ]; then
4598 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4601 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4603 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4605 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4607 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4609 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4611 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4613 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4615 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4617 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4619 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4621 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4622 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4623 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4624 log error "no support for pipes with given ripper"
4625 log error "read the FAQ file from the source tarball to get help."
4628 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4629 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4630 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4631 log error "no support for pipes with given encoder"
4632 log error "read the FAQ file from the source tarball to get help"
4637 # Make sure a buncha things exist
4638 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4639 $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4640 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER \
4641 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4642 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4643 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4644 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4645 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4646 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4647 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4648 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4649 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4650 ${NEEDMID3V2+$MID3V2}
4655 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4656 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4657 # these files). The resulting files are actually ADTS streams which belong in an
4658 # aac container and with some version sniffing this is all cleaned up below. If
4659 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4661 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4662 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4663 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4664 echo "WARNING: Your copy of Faac does not have mp4 support"
4665 echo "WARNING: Encoding untagged files to aac..."
4668 echo "Using Faac to Tag AAC Tracks..."
4672 # And last but not least, check if we can diff between files. We do not abort,
4673 # since diffing is not critical...
4674 if [ -x $(which $DIFF) ]; then :; else
4675 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4679 ## Now that we have metaflac, check if we need cue2discid
4680 #case $CDROMREADERSYNTAX in
4682 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4683 # if [ "$TRACKINFO" = "" ]; then
4684 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4689 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4690 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4691 HTTPGET="$HTTPGET $HTTPGETOPTS"
4693 # Here it used to say:
4694 # One thousand lines in, we can start doing stuff with things
4695 # Well, right now we are at line 3737 ;)
4697 # Export needed things so they can be read in this subshell
4698 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4699 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4701 if [ "$DOREAD" = "y" ]; then
4702 # User-definable function to set some things. Use it for
4703 # - closing the CD tray with eject -t
4704 # - set the CD speed value with eject -x
4705 vecho -n "Executing customizable pre-read function... "
4707 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4712 # Get ABCDETEMPDIR created and status file initialized
4715 if [ "$DOCDDB" = "y" ]; then
4716 # start with a sane default:
4717 CDDBLOCALSTATUS=notfound
4718 if [ $CDDBUSELOCAL = "y" ]; then
4721 if checkstatus cddb-choice > /dev/null; then
4724 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4725 case "$CDDBMETHOD" in
4736 CHOICE=$(checkstatus cddb-choice)
4737 if [ "$CHOICE" = 0 ] ; then
4738 # We don't have any information at all; try to fall back
4739 # to CD-Text for basic information
4740 vecho "No CDDB information found, trying cdtext from the CD"
4746 eval "$($CDDBTOOL parse "$CDDBDATA")"
4749 # Before reading tracks, we set the speed of the device
4751 if [ X"$CDSPEEDVALUE" != "X" ]; then
4752 case "$CDROMREADERSYNTAX" in
4753 cdparanoia|libcdio|debug) ;;
4760 # Define the first and last track, since we might need them later in several places
4761 FIRSTTRACK=$( get_first $TRACKQUEUE )
4762 LASTTRACK=$( get_last $TRACKQUEUE )
4764 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4765 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4766 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4767 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4770 if checkstatus onetrack ; then ONETRACK=y ; fi
4772 if [ "$ONETRACK" = "y" ]; then
4773 # Reuse the CUEFILE in case we created it (now or in a previous run)
4774 if CUEFILE=$(checkstatus cuefile); then
4779 # Create playlist if needed (backgroundable) and start reading in tracks
4783 if [ ! "$ONETRACK" = "y" ]; then
4784 if [ "$DOPLAYLIST" = "y" ]; then
4785 echo Creating playlist... >&2
4790 if [ "$GETALBUMART" = "y" ]; then
4794 # For the lowdisk option, only one program is running at once so the encoder
4795 # can be unsilenced right away.
4796 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4797 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4800 if [ "$ONETRACK" = "y" ]; then
4801 TRACKS="$FIRSTTRACK"
4802 if [ "$USEPIPES" = "y" ]; then
4803 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4804 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4807 if checkstatus readtrack-$FIRSTTRACK; then :; else
4808 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4812 for UTRACKNUM in $TRACKQUEUE
4814 if [ "$DOREAD" = "y" ]; then
4815 if [ "$USEPIPES" = "y" ]; then
4816 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4817 # Read, pipe, shut up!
4818 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4821 if checkstatus readtrack-$UTRACKNUM; then :; else
4822 do_cdread $UTRACKNUM
4824 if [ "$?" != "0" ]; then
4825 # CD read failed - don't give the goahead to
4832 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4835 # If we are not reading, set the encode output to loud already, so
4836 # that we can see the output of the first track.
4837 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4838 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4840 echo NEXTTRACK # Get the encoder machine churning again
4841 if [ "$DOREAD" = "y" ]; then
4842 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4843 until checkstatus encodetrack-$UTRACKNUM
4845 if checkerrors encodetrack-$UTRACKNUM; then
4856 # Now that we're done the encoding can be loud again -
4857 # if we're not using SMP.
4858 if [ "$MAXPROCS" = "1" ]; then
4859 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4862 # All tracks read, start encoding.
4863 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4867 # Execute the user-defined post_read function before ejecting CD
4870 # We are now finished with the cdrom - it can be safely ejected. Note that
4871 # abcde will not have completed yet.
4872 if [ "$EJECTCD" = "y" ]; then
4873 # We check if the disk we are processing is actually the disk inside the
4874 # CD tray. If not, we do not eject the CD, since it might be so that the
4875 # user ejected it manually.
4876 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4877 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4878 # More FreeBSD bits.
4879 if [ X"$(uname)" = X"FreeBSD" ] ; then
4880 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4881 # but in this script EJECT is in the envionment and names the program
4884 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4885 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4886 $eject $EJECTOPTS $cd
4887 elif [ X"$(uname)" = X"Darwin" ] ; then
4888 diskutil eject ${CDROM#/dev/} 0
4889 elif [ -x $(which $EJECT) ]; then
4890 $EJECT $EJECTOPTS "$CDROM"
4897 ## Do we need to pre-process
4898 #if [ x"$PREPROCESS" = "x" ] ; then
4901 # for PRETRACKNUM in $TRACKQUEUE
4904 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4906 # until [ $PREPROCEED ]
4908 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4909 # # all locations are working, wait and try again later
4910 # if [ ! $PREPROCEED ]; then sleep 3; fi
4912 # ( do_preprocess $PRETRACKNUM
4920 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4922 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4923 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4924 if [ "$GOAHEAD" != "NO" ]; then
4925 for LASTTRACK in $TRACKQUEUE; do :; done
4926 if checkstatus readtrack-$LASTTRACK; then
4927 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4928 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4929 if checkerrors batch-normalize; then exit 1; fi
4931 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4932 if [ "$DONORMALIZE" = "y" ]; then
4933 for UTRACKNUM in $TRACKQUEUE
4935 if checkstatus readtrack-$UTRACKNUM; then
4936 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4940 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4941 if checkerrors nogap-encode; then exit 1; fi
4947 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4948 if [ "$ONETRACK" = "y" ] ; then
4949 TRACKQUEUE="$FIRSTTRACK"
4950 TRACKS="$FIRSTTRACK"
4953 # Do the encoding, including parallelization of remote encoding
4954 # Figure out where each track is going to be encoded
4955 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4956 if [ "$MAXPROCS" != "0" ]; then
4957 for NUM in $(f_seq_row 1 "$MAXPROCS")
4959 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
4963 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
4964 for UTRACKNUM in $TRACKQUEUE
4967 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4968 if [ "$GOAHEAD" = "NO" ]; then break; fi
4969 # find out where this track is to be encoded
4970 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4971 # Make sure we have a place to encode this, if not, exit stage right
4972 if [ -z "$ENCODELOCATIONS" ]; then
4978 for LOCATION in $ENCODELOCATIONS
4980 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4981 # check first if a track has ever been assigned to this location
4982 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
4983 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4984 if checkerrors encodetrack-$PREVIOUSTRACK; then
4985 for TEMPLOCATION in $ENCODELOCATIONS
4987 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4988 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
4991 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
4996 # We're still here, this location must have been previously assigned,
4997 # and last completed without error - check if it's done with the
4998 # previous track yet
4999 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
5001 # all locations are working, wait and try again later
5002 if [ ! $PROCEED ]; then sleep 3; fi
5004 # Record the location we're about to encode the next track at
5005 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
5007 # Don't proceed with the rest of the loop if we can't encode
5008 if [ "$ABORT" ]; then continue; fi
5009 ## FIXME ## Add here
5010 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
5011 # Set TRACKNUM, TRACKNAME
5012 if [ -e "$CDDBDATA" ]; then
5013 if [ "$ONETRACK" = "y" ]; then
5015 TRACKNUM="$FIRSTTRACK"
5019 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
5020 getcddbinfo TRACKNAME
5024 # You can't encode a file which needs to be normalized before finishing
5025 # You can't tag a file before it's finished encoding -
5026 # thus all of this is backgrounded together
5028 if [ "$DONORMALIZE" = "y" ]; then
5029 if checkstatus readtrack-$UTRACKNUM; then
5030 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5033 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5034 if checkstatus readtrack-$UTRACKNUM; then
5035 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
5036 if [ "$DONORMALIZE" = "y" ]; then
5037 if checkstatus normalizetrack-$UTRACKNUM; then
5038 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5041 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5045 if [ "$DOTAG" = "y" ]; then
5046 if checkstatus encodetrack-$UTRACKNUM; then
5047 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
5049 # Lets tag the cue file
5050 if checkstatus cleancuefile >/dev/null; then :; else
5051 if checkstatus cuefile >/dev/null ; then
5056 if [ "$DOMOVE" = "y" ]; then
5057 if checkstatus tagtrack-$UTRACKNUM; then
5058 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
5065 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5066 # we'll delete the files they're working on
5067 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5068 ## FIXME ## Check also for files which are encoded using PIPEs.
5069 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5074 for LOCATION in $ENCODELOCATIONS
5076 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5077 # "How can he give us a status update, if he's DEAD?"
5078 if checkstatus encodetrack-$CHECKTRACK; then
5081 # Nothing to see here please go quietly back to your homes
5082 if [ -z "$CHECKTRACK" ]; then continue; fi
5083 # You're still here? Maybe there is something...
5084 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
5087 if [ ! $PROCEED ]; then sleep 5; fi
5090 # If the above didn't catch the stragglers, this will
5092 if [ "$DOREPLAYGAIN" = "y" ]; then
5096 # Execute the user-defined post_encode function before cleaning up
5099 # Check to see if run_command logged any errors
5100 if [ -f "$ABCDETEMPDIR/errors" ]; then
5101 log error "The following commands failed to run:"
5102 cat "$ABCDETEMPDIR/errors"
5106 if [ "$KEEPWAVS" = "y" ];then
5110 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5111 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5112 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5113 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5114 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5115 log warning "The encoded formats does not match with the moved ones"
5116 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
5117 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
5118 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
5122 if [ "$DOCLEAN" = "y" ]; then
5123 # Wipe all the evidence
5124 # Gimme gimme gimme some more time!
5126 rm -rf "$ABCDETEMPDIR"
5129 echo "Finished. Not cleaning $ABCDETEMPDIR."