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.1-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
846 eyed3_06) addopts=( \
847 ${ENCODING:+--set-encoding="$ENCODING"} \
848 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
849 # We set 'recording-date' so the date tag will show
850 # in Audacious, vlc and friends... Andrew.
851 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
852 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
855 ${ENCODING:+--encoding="$ENCODING"} \
856 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
857 # We set 'recording-date' so the date tag will show
858 # in Audacious, vlc and friends... Andrew.
859 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
860 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
863 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
865 -a "$TRACKARTIST" -t "$TRACKNAME" \
866 -G "$GENREID" -n "${TRACKNUM:-$1}" \
867 ${TRACKNUM:+-N "$TRACKS"} \
869 "$ABCDETEMPDIR/track$1.$OUTPUT"
872 log error "Internal error: ID3SYNTAX has an illegal value"
878 case "$OGGENCODERSYNTAX" in
880 # vorbiscomment can't do in-place modification, mv the file first
881 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
882 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
886 # http://www.xiph.org/vorbis/doc/v-comment.html
888 echo ARTIST="$TRACKARTIST"
890 echo TITLE="$TRACKNAME"
891 if [ -n "$CDYEAR" ]; then
894 if [ -n "$CDGENRE" ]; then
895 echo GENRE="$CDGENRE"
897 echo TRACKNUMBER=${TRACKNUM:-$1}
898 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
899 # xiph.org: http://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
900 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
901 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
902 echo TRACKTOTAL="${TRACKS}"
903 if [ -n "$DISCNUMBER" ]; then
904 echo DISCNUMBER="$DISCNUMBER"
906 echo CDDB=$CDDBDISCID
907 if [ "$(eval echo ${COMMENT})" != "" ]; then
908 case "$COMMENTOUTPUT" in
909 *=*) echo "$COMMENTOUTPUT";;
910 *) echo COMMENT="$COMMENTOUTPUT";;
913 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
914 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
915 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
916 # Doublecheck that the commented file was created
917 # successfully before wiping the original
918 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
919 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
921 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
927 run_command tagtrack-$OUTPUT-$1 true
931 echo ARTIST="$TRACKARTIST"
933 echo TITLE="$TRACKNAME"
934 if [ -n "$CDYEAR" ]; then
937 if [ -n "$CDGENRE" ]; then
938 echo GENRE="$CDGENRE"
940 echo TRACKNUMBER="${TRACKNUM:-$1}"
941 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
942 # xiph.org: http://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
943 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
944 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
945 echo TRACKTOTAL="${TRACKS}"
946 if [ -n "$DISCNUMBER" ]; then
947 echo DISCNUMBER="$DISCNUMBER"
949 echo CDDB="$CDDBDISCID"
950 if [ "$(eval echo ${COMMENT})" != "" ]; then
951 case "$COMMENTOUTPUT" in
952 *=*) echo "$COMMENTOUTPUT";;
953 *) echo COMMENT="$COMMENTOUTPUT";;
956 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
957 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
960 run_command tagtrack-$OUTPUT-$1 true
963 run_command tagtrack-$OUTPUT-$1 true
966 run_command tagtrack-$OUTPUT-$1 true
969 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
970 # Console port (mac) used for encoding does not have the ability to tag.
971 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
972 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
973 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
976 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
977 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
978 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
979 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
980 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
981 "$ABCDETEMPDIR/track$1.mp2"
984 run_command tagtrack-$OUTPUT-$1 true
987 case "$AACENCODERSYNTAX" in
989 # We will use inline tagging...
990 run_command tagtrack-$OUTPUT-$1 true
993 # Tag post encode with neroAacTag...
994 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
995 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
996 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
999 run_command tagtrack-$OUTPUT-$1 true
1002 run_command tagtrack-$OUTPUT-$1 true
1005 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1006 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1007 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$ATOMICPARSLEY" "$ABCDETEMPDIR/track$1.m4a" \
1008 --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum=${TRACKNUM:-$1} \
1009 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
1012 run_command tagtrack-$OUTPUT-$1 true
1017 # We use mid3v2 tagging for True Audio:
1018 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1019 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1020 "$ABCDETEMPDIR/track$1.tta"
1023 run_command tagtrack-$OUTPUT-$1 true
1027 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1028 run_command tagtrack-$1 true
1034 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1037 # The commands here don't go through run_command because they're never
1038 # supposed to be silenced
1039 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1040 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1044 case "$MP3ENCODERSYNTAX" in
1049 for UTRACKNUM in $TRACKQUEUE
1051 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1053 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1055 if [ "$RETURN" != "0" ]; then
1056 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1058 for UTRACKNUM in $TRACKQUEUE
1060 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1061 #run_command encodetrack-$UTRACKNUM true
1070 if checkerrors "nogap-encode"; then :; else
1071 if [ ! "$KEEPWAVS" = "y" ] ; then
1072 if [ ! "$KEEPWAVS" = "move" ] ; then
1077 # Other encoders fall through to normal encoding as the tracks have not
1078 # been entered in the status file.
1081 # do_encode [tracknumber] [hostname]
1082 # If no hostname is specified, encode locally
1084 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1085 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1088 if [ "$USEPIPES" = "y" ]; then
1091 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1094 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1097 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1100 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1103 TEMPARG="PIPE_$SPEEXENCODER"
1106 TEMPARG="PIPE_$MPCENCODER"
1109 TEMPARG="PIPE_$WVENCODERSYNTAX"
1112 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1115 TEMPARG="PIPE_$AACENCODERSYNTAX"
1118 TEMPARG="PIPE_$AACENCODERSYNTAX"
1121 IN="$( eval echo "\$$TEMPARG" )"
1123 IN="$ABCDETEMPDIR/track$1.wav"
1125 # We need IN to proceed, if we are not using pipes.
1126 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1127 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1129 case "$TMPOUTPUT" in
1131 OUTPUT=$OGGOUTPUTCONTAINER
1134 OUTPUT=$OPUSOUTPUTCONTAINER
1137 OUTPUT=$FLACOUTPUTCONTAINER
1143 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1144 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1147 if [ X"$USEPIPES" = "Xy" ]; then
1149 # We need a way to store the creation of the files when using PIPES
1150 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1151 # When piping it does not make sense to have a higher nice for
1152 # reading than for encoding, since it will be hold by the
1153 # encoding process. Setting an effective nice, to calm down a
1154 # bit the reading process.
1155 EFFECTIVE_NICE=$READNICE
1157 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1158 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1159 EFFECTIVE_NICE=$ENCNICE
1165 case "$MP3ENCODERSYNTAX" in
1166 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1167 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1168 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1169 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1173 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1180 case "$OGGENCODERSYNTAX" in
1181 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1182 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1186 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1193 case "$OPUSENCODERSYNTAX" in
1195 # Tag the file at encode time, as it can't be done after encoding.
1196 if [ "$DOTAG" = "y" ]; then
1197 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1198 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1199 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1201 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1207 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1214 case "$FLACENCODERSYNTAX" in
1215 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1220 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1221 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1226 if [ "$(eval echo ${COMMENT})" != "" ]; then
1229 *) COMMENT="COMMENT=$COMMENT" ;;
1232 # Tag the file at encode time, as it can't be done after encoding.
1233 if [ "$DOTAG" = "y" ]; then
1234 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1235 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1237 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1241 # Tag the file inline at encode time.
1242 if [ "$DOTAG" = "y" ]; then
1243 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1244 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1246 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1250 case "$TTAENCODERSYNTAX" in
1251 # tta is the newer version with a small syntax change...
1253 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1256 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1261 case "$WVENCODERSYNTAX" in
1263 if [ "$DOTAG" = "y" ]; then
1264 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1265 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1267 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1271 if [ "$DOTAG" = "y" ]; then
1272 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1273 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1274 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1276 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1282 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1285 case "$MP2ENCODERSYNTAX" in
1287 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1290 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1295 # aac container is only used to catch faac encoded files where faac
1296 # is compiled without mp4 support (with libmp4v2).
1297 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1300 case "$AACENCODERSYNTAX" in
1302 if [ "$DOTAG" = "y" ]; then
1303 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1304 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1306 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1310 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1313 if [ "$DOTAG" = "y" ]; then
1314 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1315 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1317 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1321 if [ "$DOTAG" = "y" ]; then
1322 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1323 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1325 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1329 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1332 if [ "$DOTAG" = "y" ]; then
1333 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1334 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1335 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1337 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1343 # In case of wav output we need nothing. Just keep the wavs.
1344 # But we need the following to allow full logging and subsequent
1345 # successful cleaning of $ABCDETEMPDIR.
1346 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1351 # Only remove .wav if the encoding succeeded
1352 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1353 run_command encodetrack-$1 true
1354 if [ ! "$KEEPWAVS" = "y" ] ; then
1355 if [ ! "$KEEPWAVS" = "move" ] ; then
1361 run_command "" echo "HEH! The file we were about to encode disappeared:"
1362 run_command "" echo ">> $IN"
1363 run_command encodetrack-$1 false
1367 # do_preprocess [tracknumber]
1369 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1372 # IN="$ABCDETEMPDIR/track$1.wav"
1373 # # We need IN to proceed.
1374 # if [ -s "$IN" ] ; then
1375 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1377 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1378 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1379 # case "$POSTPROCESSFORMAT" in
1381 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1383 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1385 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1387 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1389 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1392 # # Only remove .wav if the encoding succeeded
1393 # if checkerrors "preprocess-(.{3,4})-$1"; then
1394 # run_command preprocess-$1 false
1396 # run_command preprocess-$1 true
1399 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1400 # echo "HEH! The file we were about to pre-process disappeared:"
1403 # run_command preprocess-$1 false
1408 # do_postprocess [tracknumber]
1410 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1413 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1415 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1416 # # We need IN to proceed.
1417 # if [ -s "$IN" ] ; then
1418 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1419 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1420 # case "$POSTPROCESSFORMAT" in
1422 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1424 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1426 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1428 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1430 # # Only remove .wav if the encoding succeeded
1431 # if checkerrors "postprocess-(.{3,4})-$1"; then
1432 # run_command postprocess-$1 false
1434 # run_command postprocess-$1 true
1437 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1438 # echo "HEH! The file we were about to post-process disappeared:"
1441 # run_command postprocess-$1 false
1456 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1460 # The commands here don't go through run_command because they're never supposed to be silenced
1461 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1466 for UTRACKNUM in $TRACKQUEUE
1468 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1470 # FIXME # Hard-coded batch option!
1471 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1473 if [ "$RETURN" != "0" ]; then
1474 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1476 for UTRACKNUM in $TRACKQUEUE
1478 echo normalizetrack-$UTRACKNUM >> status
1484 # do_batch_normalize
1486 # NORMALIZER, NORMALIZEROPTS
1487 do_batch_normalize ()
1489 # The commands here don't go through run_command because they're never supposed to be silenced
1490 echo "Batch normalizing tracks: $TRACKQUEUE"
1495 for UTRACKNUM in $TRACKQUEUE
1497 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1499 # XXX: Hard-coded batch option!
1500 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1502 if [ "$RETURN" != "0" ]; then
1503 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1505 for UTRACKNUM in $TRACKQUEUE
1507 echo normalizetrack-$UTRACKNUM >> status
1513 # do_normalize [tracknumber]
1515 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1518 IN="$ABCDETEMPDIR/track$1.wav"
1519 if [ -e "$IN" ] ; then
1520 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1521 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1523 if [ "$(checkstatus encode-output)" = "loud" ]; then
1524 echo "HEH! The file we were about to normalize disappeared:"
1527 run_command normalizetrack-$1 false "File $IN was not found"
1531 # do_move [tracknumber]
1532 # Deduces the outfile from environment variables
1533 # Creates directory if necessary
1535 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1538 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1540 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1541 # defined the OUTPUTFILE:
1544 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1545 ALBUMFILE="$(mungefilename "$DALBUM")"
1546 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1547 TRACKFILE="$(mungefilename "$TRACKNAME")"
1548 GENRE="$(mungegenre "$GENRE")"
1549 YEAR=${CDYEAR:-$CDYEAR}
1550 # If we want to start the tracks with a given number, we need to modify
1551 # the TRACKNUM value before evaluation
1553 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1554 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1555 if [ "$ONETRACK" = "y" ]; then
1556 if [ "$VARIOUSARTISTS" = "y" ]; then
1557 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1559 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1562 if [ "$VARIOUSARTISTS" = "y" ]; then
1563 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1565 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1568 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1569 # Once we know the specific output was successful, we can change
1570 # the OUTPUT to the value containing the container
1573 OUTPUT=$OGGOUTPUTCONTAINER
1576 OUTPUT=$OPUSOUTPUTCONTAINER
1579 OUTPUT=$FLACOUTPUTCONTAINER
1585 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1586 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1589 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1590 # FIXME # introduce warnings?
1593 # mkdir -p shouldn't return an error if the directory already exists
1594 mkdir -p "$OUTPUTFILEDIR"
1595 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1596 if checkstatus movetrack-output-$OUTPUT; then :; else
1597 run_command movetrack-output-$OUTPUT true
1602 # mkdir -p shouldn't return an error if the directory already exists
1603 mkdir -p "$OUTPUTFILEDIR"
1604 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1605 if checkstatus movetrack-output-$OUTPUT; then :; else
1606 run_command movetrack-output-$OUTPUT true
1610 # Lets move the cue file
1611 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1612 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1613 if checkstatus movecue-$OUTPUT; then :; else
1614 # Silence the Copying output since it overlaps with encoding processes...
1615 #run_command '' vecho "Copying cue file to its destination directory..."
1616 if checkstatus onetrack >/dev/null ; then
1619 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1620 # We dont have the dir, since it was not created before.
1623 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1626 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1627 # http://brianvictor.tripod.com/mp3cue.htm#details
1628 [a-z0-9][a-z0-9][a-z0-9])
1629 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1632 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1636 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1638 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1647 # Create the playlist if wanted
1649 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1650 # VARIOUSARTISTS, OUTPUTDIR
1653 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1657 OUTPUT=$OGGOUTPUTCONTAINER
1660 OUTPUT=$OPUSOUTPUTCONTAINER
1663 OUTPUT=$FLACOUTPUTCONTAINER
1669 # Create a playlist file for the playlist data to go into.
1670 # We used to wipe it out if it existed. Now we request permission if interactive.
1671 for LASTTRACK in $TRACKQUEUE; do :; done
1672 ALBUMFILE="$(mungefilename "$DALBUM")"
1673 ARTISTFILE="$(mungefilename "$DARTIST")"
1674 GENRE="$(mungegenre "$GENRE")"
1675 YEAR=${CDYEAR:-$CDYEAR}
1676 if [ "$VARIOUSARTISTS" = "y" ] ; then
1677 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1679 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1681 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1682 mkdir -p "$FINALPLAYLISTDIR"
1683 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1684 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1685 if [ "$INTERACTIVE" = "y" ]; then
1686 while [ "$DONE" != "y" ]; do
1688 case $ERASEPLAYLIST in
1689 e|E|a|A|k|K) DONE=y ;;
1690 "") ERASEPLAYLIST=e ; DONE=y ;;
1698 # Once we erase the playlist, we use append to create the new one.
1699 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1701 # The playlist does not exist, so we can safelly use append to create the new list
1704 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1705 touch "$OUTPUTDIR/$PLAYLISTFILE"
1706 for UTRACKNUM in $TRACKQUEUE
1708 # Shares some code with do_move since the filenames have to match
1709 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1710 getcddbinfo TRACKNAME
1712 TRACKFILE="$(mungefilename "$TRACKNAME")"
1713 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1714 ALBUMFILE="$(mungefilename "$DALBUM")"
1715 # If we want to start the tracks with a given number, we need to modify the
1716 # TRACKNUM value before evaluation
1718 if [ "$VARIOUSARTISTS" = "y" ]; then
1719 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1721 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1723 if [ "$VARIOUSARTISTS" = "y" ]; then
1724 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1725 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1727 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1730 if [ "$PLAYLISTDATAPREFIX" ]; then
1731 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1733 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1738 ## this will convert the playlist to have CRLF line-endings, if specified
1739 ## (some hardware players insist on CRLF endings)
1740 if [ "$DOSPLAYLIST" = "y" ]; then
1741 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1742 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1743 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1745 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1750 # This function reads a cuefile on stdin and writes an extended
1751 # cddb query on stdout. Any PREGAP for track 1 is properly
1752 # handled, although cue files embedded in FLAC files do not
1753 # appear to properly store the PREGAP setting. :(
1754 abcde.cue2discid () {
1759 while [ $val -gt 0 ] ; do
1760 ret=$(( $ret + ( $val % 10) ))
1761 val=$(( $val / 10 ))
1771 local first second third
1772 first=$(expr ${1} + 0 )
1773 second=$(expr ${2} + 0 )
1774 third=$(expr ${3} + 0 )
1776 echo $(( ((($first * 60) + $second) * 75) + $third ))
1786 while read line ; do
1789 TRACK) i=$(( i + 1 ))
1791 INDEX) if [ "$2" -eq 1 ] ; then
1793 START=$(( $LBA + $PREGAP + $OFFSET ))
1795 X=$(cddb_sum $(( $START / 75 )) )
1799 PREGAP) PREGAP=$(msf2lba $2)
1803 LEADOUT=$(( $4 / 588 ))
1806 LEADIN=$(( $3 / 588 ))
1815 LEADOUT=$(( $LEADOUT + $LEADIN ))
1817 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1818 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1819 printf "%08x %i" $DISCID $TRACKS
1822 while [ $j -le $TRACKS ] ; do
1823 eval echo -n "\" \$TRACK$j\""
1826 echo " $(( $LEADOUT / 75 ))"
1830 # abcde.mkcue [--wholedisk]
1831 # This creates a cuefile directly from the extended discid information
1832 # The --wholedisk option controls whether we're ripping data from the
1833 # start of track one or from the start of the disk (usually, but not
1834 # always the same thing!)
1836 # Track one leadin/pregap (if any) handeling:
1837 # --wholedisk specified:
1840 # INDEX 01 <pregap value>
1841 # Remaining track index values unchanged from disc TOC
1843 # --wholedisk not specified
1845 # PREGAP <pregap value>
1847 # Remaining track index values offset by <pregap value>
1854 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1857 local MODE DISCID TRACKS
1861 if [ "$1" = --wholedisc ] ; then
1867 vecho "One track is $ONETRACK"
1868 TRACKFILE="$(mungefilename "$TRACKNAME")"
1869 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1870 ALBUMFILE="$(mungefilename "$DALBUM")"
1871 if [ "$ONETRACK" = "y" ]; then
1872 if [ "$VARIOUSARTISTS" = "y" ]; then
1873 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1875 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1877 vecho "Cue wav file is $CUEWAVFILE"
1879 CUEWAVFILE="dummy.wav"
1888 echo REM DISCID $DISCID
1889 echo FILE \""$CUEWAVFILE"\" WAVE
1891 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1898 while [ $i -le "$TRACKS" ] ; do
1899 LBA=$(( $1 - $OFFSET ))
1900 printf " TRACK %02i AUDIO\n" $i
1901 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1902 if [ $MODE = PREGAP ] ; then
1903 echomsf " PREGAP " $(($OFFSET-150))
1905 echo " INDEX 00 00:00:00"
1908 echomsf " INDEX 01 " $LBA
1915 # This essentially the start of things
1918 # Query the CD to get the track info, unless the user specified -C
1919 # or we are using some actions which do not need the CDDB data at all
1920 #if [ ! X"$EXPACTIONS" = "X" ]; then
1922 #elif [ -z "$DISCID" ]; then
1923 if [ -z "$DISCID" ]; then
1924 vecho -n "Getting CD track info... "
1925 # In OSX, unmount the disc before a query
1926 if [ "$OSFLAVOUR" = "OSX" ]; then
1927 diskutil unmount ${CDROM#/dev/}
1929 case "$CDROMREADERSYNTAX" in
1931 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1932 case "$CUE2DISCID" in
1933 # FIXME # right now we have 2 cue2discid internal
1934 # implementations: builtin and abcde.cue2discid. Test
1935 # both of them and decide which one we want to use.
1937 #vecho "Using builtin cue2discid implementation..."
1938 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1940 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1942 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1943 TRACKS=${#OFFSETTIMES[@]}
1945 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1946 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1947 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1948 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1951 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1952 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1956 #vecho "Using external python cue2discid implementation..."
1957 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1961 log error "the input flac file does not contain a cuesheet."
1966 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1968 # if [ ! "$RET" = "0" ];then
1969 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1972 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1973 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1975 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1976 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1980 case "$CDDBMETHOD" in
1981 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1982 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1986 # Make sure there's a CD in there by checking cd-discid's return code
1987 if [ ! "$?" = "0" ]; then
1988 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1989 log error "cuesheet information from the flac file could not be read."
1990 log error "Perhaps the flac file does not contain a cuesheet?."
1993 log error "CD could not be read. Perhaps there's no CD in the drive?"
1997 # In OSX, remount the disc again
1998 if [ "$OSFLAVOUR" = "OSX" ]; then
1999 diskutil mount ${CDROM#/dev/}
2002 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
2004 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
2007 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2008 # This needs to be done now because a section of the resuming code will need
2011 # get the number of digits to pad TRACKNUM with - we'll use this later
2012 # a CD can only hold 99 tracks, but since we support a feature for starting
2013 # numbering the tracks from a given number, we might need to set it as a
2014 # variable for the user to define... or obtain it somehow.
2015 if [ "$PADTRACKS" = "y" ] ; then
2019 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
2020 if [ -z "$TRACKQUEUE" ]; then
2021 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2022 case "$CDROMREADERSYNTAX" in
2023 cdparanoia|libcdio|debug)
2024 if [ "$WEHAVEACD" = "y" ]; then
2025 vecho "Querying the CD for audio tracks..."
2026 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2028 if [ ! "$RET" = "0" ];then
2029 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2031 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2032 CDPARANOIAAUDIOTRACKS="$TRACKS"
2034 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2035 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
2036 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
2037 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
2039 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2040 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2044 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
2047 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2049 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2050 log info "The disc does not contain any tracks. Giving up..."
2053 echo -n "Grabbing entire CD - tracks: "
2054 if [ ! "$PADTRACKS" = "y" ] ; then
2055 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2057 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2059 while [ "$X" -ne "$TRACKS" ]
2061 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2062 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2066 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2067 # User-supplied track queue.
2068 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2069 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2070 # Once cleaned, obtain the highest value in the trackqueue for number padding
2071 for LASTTRACK in $TRACKQUEUE; do :; done
2072 if [ ! "$PADTRACKS" = "y" ] ; then
2073 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2075 # Now we normalize the trackqueue
2076 for TRACK in $TRACKQUEUE ; do
2077 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2078 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2080 TRACKQUEUE=$PADTRACKQUEUE
2081 echo Grabbing tracks: "$TRACKQUEUE"
2084 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2086 # We have the discid, create a temp directory after it to store all the temp
2089 if [ -e "$ABCDETEMPDIR" ]; then
2090 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2091 # It already exists, see if it's a directory
2092 if [ ! -d "$ABCDETEMPDIR" ]; then
2093 # This is a file/socket/fifo/device/etc, not a directory
2096 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2097 echo "Please investigate, remove it, and rerun abcde." >&2
2101 # It's a directory, let's see if it's writable by us
2102 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2103 # Nope, complain and exit
2105 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2106 echo "Please investigate, remove it, and rerun abcde." >&2
2110 # See if it's populated
2111 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2112 # Wipe and start fresh
2113 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2114 echo -n "this directory to continue. Continue [y/N]? " >&2
2115 if [ "$INTERACTIVE" = "y" ]; then
2121 if [ "$ANSWER" != "y" ]; then
2124 rm -rf "$ABCDETEMPDIR" || exit 1
2125 mkdir -p "$ABCDETEMPDIR"
2126 if [ "$?" -gt "0" ]; then
2127 # Directory already exists or could not be created
2128 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2132 # Everything is fine. Check for ^encodetracklocation-
2133 # and encode-output entries in the status file and
2134 # remove them. These are not relevant across sessions.
2135 if [ -f "$ABCDETEMPDIR/status" ]; then
2136 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2137 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2138 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2140 # Remove old error messages
2141 if [ -f "$ABCDETEMPDIR/errors" ]; then
2142 rm -f "$ABCDETEMPDIR/errors"
2146 # We are starting from scratch
2147 mkdir -p "$ABCDETEMPDIR"
2148 if [ "$?" -gt "0" ]; then
2149 # Directory already exists or could not be created
2150 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2153 cat /dev/null > "$ABCDETEMPDIR/status"
2154 # Store the abcde version in the status file.
2155 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2157 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2158 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2159 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2160 vecho "Creating cue file..."
2161 case $CDROMREADERSYNTAX in
2163 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2164 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2166 log warning "the input flac file does not contain a cuesheet."
2170 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2171 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2173 log warning "reading the CUE sheet is still considered experimental"
2174 log warning "and there was a problem with the CD reading. abcde will continue,"
2175 log warning "but consider reporting the problem to the abcde author"
2181 # If we got the CDPARANOIA status and it is not recorded, save it now
2182 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2183 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2184 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2188 # Create the discid file
2189 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2190 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2191 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2196 # Create a proper CUE file based on the CUE file we created before.
2199 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2200 CUEFILE_OUT=$CUEFILE_IN.out
2201 ### FIXME ### checkstatus cddb
2202 if [ -e "$CDDBDATA" ]; then
2203 vecho "Adding metadata to the cue file..."
2204 # FIXME It doesn't preserve spaces! Why?
2205 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2207 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2208 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2209 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2213 cat "$CUEFILE_IN" | while read line
2215 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2216 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2217 # echo "$line" >> "$CUEFILE_OUT"
2218 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2219 eval track="\$TRACK$n"
2221 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2222 # When making a single-track rip, put the
2223 # actual file name into the file declaration
2224 # in the cue file so that it is usable by
2225 # music players and the like
2226 elif [ "$ONETRACK" = "y" ] &&
2227 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2229 TRACKFILE="$(mungefilename "$TRACKNAME")"
2230 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2231 ALBUMFILE="$(mungefilename "$DALBUM")"
2233 if [ "$VARIOUSARTISTS" = "y" ]; then
2234 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2236 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2239 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2242 # FIXME # If the lines above are uncommented, remove the line below.
2243 echo "$line" >> "$CUEFILE_OUT"
2246 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2247 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2253 # Parses a CDDB file and outputs the title and the track names.
2254 # Variables: CDDBFILE
2258 # List out disc title/author and contents
2259 if [ "$ONETRACK" = "y" ]; then
2260 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2262 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2263 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2264 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2265 if [ ! X"$PARSEDYEAR" = "X" ]; then
2266 echo "Year: $PARSEDYEAR"
2269 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2270 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2271 if [ ! X"$PARSEDGENRE" = "X" ]; then
2272 echo "Genre: $PARSEDGENRE"
2275 if [ ! "$ONETRACK" = "y" ]; then
2276 for TRACK in $(f_seq_row 1 $TRACKS)
2278 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2284 # Check for a local CDDB file, and report success
2287 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2289 CDDBLOCALSTATUS="notfound"
2290 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2293 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2294 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2295 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2296 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2297 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2298 CDDBLOCALMATCH=single
2299 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2300 CDDBLOCALMATCH=multiple
2305 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2306 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2307 CDDBLOCALMATCH=single
2312 # If the user has selected to check a local CDDB repo, we proceed with it
2313 case $CDDBLOCALMATCH in
2315 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2317 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2319 # List out disc title/author and contents
2320 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2321 cat "$RESULT" > "${CDDBLOCALREAD}"
2324 do_cddbparse "${CDDBLOCALREAD}"
2326 ##FIXME## QUICK HACK !!!!
2327 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2328 } >> "$ABCDETEMPDIR/cddblocalchoices"
2330 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2331 page "$ABCDETEMPDIR/cddblocalchoices"
2333 # It's all going to fit in one page, cat it
2334 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2336 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2337 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2338 CDDBLOCALCHOICENUM=-1
2339 if [ "$INTERACTIVE" = "y" ]; then
2340 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2341 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2342 read CDDBLOCALCHOICE
2343 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2344 # FIXME # Introduce diff's
2345 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2346 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2347 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2348 # Make sure we get a valid choice
2349 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2350 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2351 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2357 #echo "Selected ..."
2359 CDDBLOCALCHOICENUM=1
2361 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2362 #echo "Using local copy of CDDB data"
2363 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2364 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2365 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2366 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2367 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2368 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2369 CDDBLOCALSTATUS="found"
2371 #echo "Not using local copy of CDDB data"
2372 CDDBLOCALSTATUS="notfound"
2376 # List out disc title/author and contents
2377 do_cddbparse "${CDDBLOCALFILE}"
2378 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2379 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2381 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2383 if [ "$INTERACTIVE" = "y" ]; then
2385 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2386 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2389 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2393 if [ "$USELOCALRESP" = "y" ]; then
2394 #echo "Using local copy of CDDB data"
2395 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2396 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2397 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2398 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2399 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2400 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2401 CDDBLOCALSTATUS="single"
2403 #echo "Not using local copy of CDDB data"
2404 CDDBLOCALSTATUS="notfound"
2408 CDDBLOCALSTATUS="notfound"
2415 # Try to read CD-Text from the drive using icedax / cdda2wav
2418 if new_checkexec icedax; then
2419 CDTEXT_READER=icedax
2420 elif new_checkexec cdda2wav; then
2421 CDTEXT_READER=cdda2wav
2423 # Didn't find either, bail
2427 if [ "$OSFLAVOUR" = "OSX" ] ; then
2428 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2429 diskutil unmount ${CDROM#/dev/}
2430 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2431 CDDA2WAVCDROM="IODVDServices"
2432 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2433 CDDA2WAVCDROM="$CDROMID"
2435 if [ "$CDROMID" = "" ]; then
2436 CDDA2WAVCDROM="$CDROM"
2438 CDDA2WAVCDROM="$CDROMID"
2442 # Do we have CD-Text on the disc (and can the drive read it?)
2443 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2444 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2446 if [ $ERRORCODE -ne 0 ]; then
2447 # No CD-Text found, bail
2451 rm -f "$ABCDETEMPDIR/cddbchoices"
2453 # Make an empty template
2454 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2455 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2456 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2457 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2458 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2459 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2460 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2461 # List out disc title/author and contents
2462 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2463 for TRACK in $(f_seq_row 1 $TRACKS)
2465 TRACKM1=$(($TRACK - 1))
2466 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2467 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2468 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2469 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2471 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2472 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2473 echo >> "$ABCDETEMPDIR/cddbchoices"
2474 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2478 # Work with the musicbrainz WS API, then transform the results here so
2479 # they look (very) like the results from CDDB. Maybe not the best way
2480 # to go, but it Works For Me (TM)
2484 if checkstatus musicbrainz-readcomplete; then :; else
2485 vecho "Obtaining Musicbrainz results..."
2486 # If MB is to be used, interpret the query results and read all
2487 # the available entries.
2488 rm -f "$ABCDETEMPDIR/cddbchoices"
2489 CDDBCHOICES=1 # Overridden by multiple matches
2490 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2491 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2493 # The helper script will write disc matches out to
2494 # cddbread.*. Count how many we have
2495 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2496 # No matches. Use the normal cddb template for the user to
2498 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2499 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2500 # List out disc title/author and contents of template
2501 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2503 for TRACK in $(f_seq_row 1 $TRACKS)
2505 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2507 echo >> "$ABCDETEMPDIR/cddbchoices"
2508 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2509 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2510 echo 503 > "$ABCDETEMPDIR/cddbquery"
2512 # We have some matches
2513 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2514 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2516 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2517 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2518 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2519 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2520 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2521 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2522 # List out disc title/author and contents
2523 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2524 for TRACK in $(f_seq_row 1 $TRACKS)
2526 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2528 echo >> "$ABCDETEMPDIR/cddbchoices"
2530 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2531 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2532 for file in "$ABCDETEMPDIR"/cddbread.*
2534 X=$(echo $file | sed 's/^.*cddbread\.//g')
2535 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2536 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2537 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2538 # List out disc title/author and contents
2539 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2540 for TRACK in $(f_seq_row 1 $TRACKS)
2542 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2544 echo >> "$ABCDETEMPDIR/cddbchoices"
2546 echo "." >> "$ABCDETEMPDIR/cddbquery"
2549 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2556 # Perform CDDB protocol version check if it hasn't already been done
2557 if checkstatus cddb-statcomplete; then :; else
2558 if [ "$CDDBAVAIL" = "n" ]; then
2560 echo 503 > "$ABCDETEMPDIR/cddbstat"
2563 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2564 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2565 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2566 vecho "Checking CDDB server status..."
2567 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2568 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2569 case "$RESPONSECODE" in
2570 210) # 210 OK, status information follows (until terminating `.')
2573 501) # 501 Illegal CDDB protocol level: <n>.
2574 CDDBPROTO=`expr $CDDBPROTO - 1`
2576 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2577 # FreeDB TESTCD disc-id is used for query
2578 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2579 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2580 case "$RESPONSECODE" in
2581 2??) # Server responded, everything seems OK
2591 if test $rc -eq 1; then
2595 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2603 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2604 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2606 # Perform CDDB query if it hasn't already been done
2607 if checkstatus cddb-querycomplete; then :; else
2608 if [ "$CDDBAVAIL" = "n" ]; then
2610 echo 503 > "$ABCDETEMPDIR/cddbquery"
2611 # The default CDDBLOCALSTATUS is "notfound"
2612 # This part will be triggered if the user CDDB repo does not
2613 # contain the entry, or if we are not trying to use the repo.
2615 vecho "Querying the CDDB server..."
2616 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2617 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2618 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2624 # no match found in database,
2625 # wget/fetch error, or user requested not to use CDDB
2626 # Make up an error code (503) that abcde
2627 # will recognize in do_cddbread
2628 # and compensate by making a template
2629 echo 503 > "$ABCDETEMPDIR/cddbquery"
2631 *) # strange and unknown error
2632 echo ERRORCODE=$ERRORCODE
2633 echo "abcde: $CDDBTOOL returned unknown error code"
2637 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2644 # If it's not to be used, generate a template.
2645 # Then, display it (or them) and let the user choose/edit it
2646 if checkstatus cddb-readcomplete; then :; else
2647 vecho "Obtaining CDDB results..."
2648 # If CDDB is to be used, interpret the query results and read all
2649 # the available entries.
2650 rm -f "$ABCDETEMPDIR/cddbchoices"
2651 CDDBCHOICES=1 # Overridden by multiple matches
2652 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2653 case "$RESPONSECODE" in
2655 # One exact match, retrieve it
2656 # 200 [section] [discid] [artist] / [title]
2657 if checkstatus cddb-read-1-complete; then :; else
2658 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2659 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2660 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2661 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2662 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2664 # List out disc title/author and contents
2665 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2666 for TRACK in $(f_seq_row 1 $TRACKS)
2668 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2670 echo >> "$ABCDETEMPDIR/cddbchoices"
2674 case "$RESPONSECODE" in
2675 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2676 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2677 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2679 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2680 # List out disc title/author and contents of template
2681 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2683 for TRACK in $(f_seq_row 1 $TRACKS)
2685 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2687 echo >> "$ABCDETEMPDIR/cddbchoices"
2688 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2689 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2692 # Multiple exact, (possibly multiple) inexact matches
2694 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2695 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2696 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2697 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2698 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2700 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2702 vecho -n "Retrieving multiple matches... "
2703 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2704 read DISCINFO # eat top line
2708 if checkstatus cddb-read-$X-complete; then :; else
2709 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2710 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2712 # List out disc title/author and contents
2713 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2714 for TRACK in $(f_seq_row 1 $TRACKS)
2716 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2718 echo >> "$ABCDETEMPDIR/cddbchoices"
2721 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2725 for TRACK in $(f_seq_row 1 $TRACKS)
2727 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2729 echo >> "$ABCDETEMPDIR/cddbchoices"
2730 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2731 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2734 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2741 if checkstatus cddb-edit >/dev/null; then
2742 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2743 VARIOUSARTISTS="$(checkstatus variousartists)"
2744 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2747 if [ "$INTERACTIVE" = "y" ]; then
2748 # We should show the CDDB results both when we are not using the local CDDB repo
2749 # or when we are using it but we could not find a proper match
2750 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2751 # Display the $ABCDETEMPDIR/cddbchoices file created above
2752 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2753 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2754 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2755 CHOICE=$(checkstatus cddb-choice)
2756 if [ -n "$CHOICE" ] ; then
2757 case $CDDBCHOICES in
2758 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2759 log error "CDDB query failed!"
2762 cat "$ABCDETEMPDIR/cddbchoices"
2765 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2767 echo "Selected: #$CHOICE"
2768 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2772 # The user has a choice to make, display the info in a pager if necessary
2773 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2774 page "$ABCDETEMPDIR/cddbchoices"
2776 # It's all going to fit in one page, cat it
2777 cat "$ABCDETEMPDIR/cddbchoices" >&2
2781 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2783 # I'll take CDDB read #3 for $400, Alex
2784 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2785 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2787 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2788 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2789 if [ ! X"$DIFF" = "X" ]; then
2790 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2791 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2792 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2793 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2794 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2795 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2797 # We parse the 2 choices to diff, store them in temporary files and diff them.
2798 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2799 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2801 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2802 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2803 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2804 page "$ABCDETEMPDIR/cddbread.diff"
2806 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2810 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2812 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2813 # Make sure we get a valid choice
2814 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2815 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2816 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2820 if [ "$CDCHOICENUM" = "0" ]; then
2821 vecho "Creating empty CDDB template..."
2823 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2825 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2826 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2828 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2832 # We need some code to show the selected option when local repository is selected and we have found a match
2833 vecho "Using cached CDDB match..." >&2
2834 # Display the $ABCDETEMPDIR/cddbchoices file created above
2835 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2836 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2837 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2838 CHOICE=$(checkstatus cddb-choice)
2839 if [ "$USELOCALRESP" = "y" ]; then :; else
2840 if [ -n "$CHOICE" ] ; then
2841 case $CDDBCHOICES in
2844 echo "Selected template."
2846 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2848 echo "Selected: #$CHOICE"
2849 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2857 # We're noninteractive - pick the first choice.
2858 # But in case we run a previous instance and selected a choice, use it.
2859 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2860 # Show the choice if we are not using the locally stored one
2861 # or when the local search failed to find a match.
2862 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2863 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2864 #if [ "$PREVIOUSCHOICE" ]; then
2865 cat "$ABCDETEMPDIR/cddbchoices"
2868 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2869 CDCHOICENUM=$PREVIOUSCHOICE
2872 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2874 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2879 if checkstatus cddb-choice >/dev/null; then :; else
2880 echo "abcde: internal error: cddb-choice not recorded." >&2
2883 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2884 echo -n "Edit selected CDDB data " >&2
2885 if [ "$INTERACTIVE" = "y" ]; then
2886 if [ "$UNKNOWNDISK" = "y" ]; then
2887 echo -n "[Y/n]? " >&2
2889 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2891 echo -n "[y/N]? " >&2
2898 if [ "$EDITCDDB" = "y" ]; then
2899 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2901 # Use the debian sensible-editor wrapper to pick the editor that the
2902 # user has requested via their $EDITOR environment variable
2903 if [ -x "/usr/bin/sensible-editor" ]; then
2904 /usr/bin/sensible-editor "$CDDBDATA"
2905 elif [ -n "$EDITOR" ]; then
2906 if [ -x $(which "${EDITOR%%\ *}") ]; then
2907 # That failed, try to load the preferred editor, starting
2908 # with their EDITOR variable
2909 eval $(echo "$EDITOR") \"$CDDBDATA\"
2911 # If that fails, check for a vi
2912 elif which vi >/dev/null 2>&1; then
2914 elif [ -x /usr/bin/vim ]; then
2915 /usr/bin/vim "$CDDBDATA"
2916 elif [ -x /usr/bin/vi ]; then
2917 /usr/bin/vi "$CDDBDATA"
2918 elif [ -x /bin/vi ]; then
2920 # nano should be on all (modern, i.e., sarge) debian systems
2921 elif which nano >/dev/null 2>&1 ; then
2923 elif [ -x /usr/bin/nano ]; then
2924 /usr/bin/nano "$CDDBDATA"
2925 # mg should be on all OpenBSD systems
2926 elif which mg >/dev/null 2>&1 ; then
2928 elif [ -x /usr/bin/mg ]; then
2929 /usr/bin/mg "$CDDBDATA"
2932 log warning "no editor available. Check your EDITOR environment variable."
2934 # delete editor backup file if it exists
2935 if [ -w "$CDDBDATA~" ]; then
2940 # Some heuristics first. Look at Disc Title, and if it starts with
2941 # "Various", then we'll assume Various Artists
2942 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2943 echo "Looks like a Multi-Artist CD" >&2
2946 echo -n "Is the CD multi-artist [y/N]? " >&2
2947 if [ "$INTERACTIVE" = "y" ]; then
2954 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2957 # Need NUMTRACKS before cddb-tool will return it:
2958 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2959 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2960 # More than 1/2 tracks contain a "/", so guess forward
2962 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2963 # More than 1/2 contain a "-", so guess forward-dash
2965 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2966 # More than 1/2 contain something in parens, so guess trailing-paren
2970 echo "1) Artist / Title" >&2
2971 echo "2) Artist - Title" >&2
2972 echo "3) Title / Artist" >&2
2973 echo "4) Title - Artist" >&2
2974 echo "5) Artist: Title" >&2
2975 echo "6) Title (Artist)" >&2
2976 echo "7) This is a single-artist CD" >&2
2977 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2978 if [ "$INTERACTIVE" = "y" ]; then
2979 read VARIOUSARTISTSTYLE
2981 echo $DEFAULTSTYLE >&2
2982 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2984 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2985 # If they press Enter, then the default style (0) was chosen
2986 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2987 echo "Invalid selection. Please choose a number between 1 and 7."
2988 echo -n "Selection [1-7]: "
2989 read VARIOUSARTISTSTYLE
2990 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2992 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2993 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2995 vecho "Selected: $VARIOUSARTISTSTYLE"
2996 case "$VARIOUSARTISTSTYLE" in
2998 VARIOUSARTISTSTYLE=forward
3001 VARIOUSARTISTSTYLE=forward-dash
3004 VARIOUSARTISTSTYLE=reverse
3007 VARIOUSARTISTSTYLE=reverse-dash
3010 VARIOUSARTISTSTYLE=colon
3013 VARIOUSARTISTSTYLE=trailing-paren
3021 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
3022 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
3024 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3025 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3026 # This works but does not have the necessary error checking
3027 # yet. If you are familiar with the CDDB spec
3028 # (see http://www.freedb.org/src/latest/DBFORMAT)
3029 # and can create an error-free entry on your own, then put
3030 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3031 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3032 # your abcde.conf to change the email address submissions are
3035 # submit the modified file, if they want
3036 if [ "$NOSUBMIT" != "y" ]; then
3037 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3039 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3040 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3042 echo -n 'Invalid selection. Please answer "y" or "n": '
3045 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3046 echo -n "Sending..."
3047 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
3054 # User CDDBLOCALPOLICY to find out if we store the file or not...
3055 # Cache edited CDDB entry in the user's cddb dir
3056 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3057 # Make sure the cache directory exists
3058 mkdir -p $CDDBLOCALDIR
3059 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
3062 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
3066 # try to download CD cover
3070 ALBUMFILE="$(mungefilename "$DALBUM")"
3071 ARTISTFILE="$(mungefilename "$DARTIST")"
3072 # have we got a musicbrainz mbid or amazon asin?
3073 case "$CDDBMETHOD" in
3075 # try musicbrainz mbid
3076 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
3077 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
3078 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3079 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3080 vecho "cover URL: $ALBUMARTURL" >&2
3081 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3082 if [ $? -ne 0 ]; then
3083 vecho "could not download cover from musicbrainz" >&2
3085 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3086 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3087 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3088 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3089 vecho "cover URL: $ALBUMARTURL" >&2
3090 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3091 if [ $? -ne 0 ]; then
3092 vecho "could not download cover from amazon" >&2
3094 # Check that size is reasonable; sometimes when there is no cover image
3095 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3096 FILESIZE=$(wc -c < "$ABCDETEMPDIR/$ALBUMARTFILE")
3097 if [ "$FILESIZE" -lt 1024 ]; then
3098 rm "$ABCDETEMPDIR/$ALBUMARTFILE"
3099 vecho "could not download cover from amazon" >&2
3103 vecho "no amazon ID found" >&2
3107 vecho "no musicbrainz ID found" >&2
3112 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3113 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3114 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3115 if [ $? -ne 0 ]; then
3116 vecho "could not download cover with glyrc" >&2
3121 if [ "$INTERACTIVE" = "y" ]; then
3122 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3123 # display properties of coverart when identify is available
3124 if new_checkexec $IDENTIFY; then
3125 $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
3127 # display coverart when DISPLAY is set and display command is available
3128 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3129 $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
3132 # nothing downloaded yet
3133 vecho "automatic album art downloading failed" >&2
3135 # see if the user can find a better album art manually
3136 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3138 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3139 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3141 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3144 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3145 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3147 if [ ! -z "$ALBUMARTURL" ]; then
3148 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3149 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3150 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3151 vecho "unable to download $ALBUMARTURL" >&2
3153 else # it's a local path
3154 cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
3155 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3156 vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
3162 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3163 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3164 ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
3165 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3166 if new_checkexec $CONVERT; then
3167 mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3168 $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
3169 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3171 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3172 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3176 # copy to target directories
3177 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3178 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3180 # put cover in the same place as the album
3181 if [ "$VARIOUSARTISTS" = "y" ] ; then
3182 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3184 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3186 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3187 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3188 mkdir -p "$FINALALBUMARTDIR"
3189 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3191 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3192 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3194 log warning "could not get cover"
3195 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3199 # do_cdread [tracknumber]
3200 # do_cdread onetrack [firsttrack] [lasttrack]
3204 # The commands here don't go through run_command because they're never supposed to be silenced
3205 # return codes need to be doublechecked anyway, however
3206 if [ "$1" = "onetrack" ]; then
3207 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3208 # FIXME # Until then, we grab the whole CD in one track, no matter what
3210 # We need the first and last track for cdda2wav/icedax
3212 LASTTRACK=$(expr $3 + 0)
3213 UTRACKNUM=$FIRSTTRACK
3214 case "$CDROMREADERSYNTAX" in
3215 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
3218 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
3219 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
3220 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3221 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3222 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3228 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3229 if [ "$USEPIPES" = "y" ]; then
3230 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3231 FILEARG="$( eval echo "\$$TEMPARG" )"
3233 PIPE_MESSAGE="and encoding "
3235 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3236 case "$CDROMREADERSYNTAX" in
3237 ## FIXME ## Find the cases for flac, to avoid exceptions
3239 FILEARG="--output-name=$WAVDATA"
3247 if [ "$1" = "onetrack" ]; then
3248 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3250 if [ -r "$CDDBDATA" ]; then
3251 getcddbinfo TRACKNAME
3252 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3254 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3257 case "$CDROMREADERSYNTAX" in
3258 ### FIXME ### use an exception for flac, since it uses -o
3259 ### FIXME ### Shall we just use -o $FILEARG ??
3261 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3262 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3263 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3265 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3267 if [ "$OSFLAVOUR" = "OSX" ] ; then
3268 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3269 diskutil unmount ${CDROM#/dev/}
3270 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3271 CDDA2WAVCDROM="IODVDServices"
3272 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3273 CDDA2WAVCDROM="$CDROMID"
3275 if [ "$CDROMID" = "" ]; then
3276 CDDA2WAVCDROM="$CDROM"
3278 CDDA2WAVCDROM="$CDROMID"
3281 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3282 dagrab) nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2 ;;
3284 if [ "$USEPIPES" = "y" ]; then
3285 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3287 # Write ripped audio data to stdout and redirect to $FILEARG.
3288 # $REDIR can be ignored. Progress is written to stderr by default.
3289 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3293 # Find the track's mounted path
3294 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3295 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3296 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3297 # If the file exists, copy it
3298 if [ -e "$FILEPATH" ] ; then
3299 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
3303 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" $REDIR ;;
3306 # If we get some error or we get some missing wav
3307 # (as long as we dont use pipes)
3308 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3309 # Thank goodness errors is only machine-parseable up to the
3310 # first colon, otherwise this woulda sucked
3311 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3312 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3314 if [ "$USEPIPES" = "y" ]; then
3315 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3317 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3321 if [ "$USEPIPES" = "y" ]; then
3322 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3324 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3326 if [ "$1" = "onetrack" ]; then
3327 echo onetrack >> "$ABCDETEMPDIR/status"
3333 # No values accepted, only uses env variables
3336 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3337 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3339 echo "abcde: unable to set the device speed" >&2
3345 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3348 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3350 warning) shift ; log warning "$@" ;;
3358 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3361 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3363 warning) shift ; log warning "$@" ;;
3371 # decho outputs a debug message if DEBUG is selected
3374 if [ x"$DEBUG" != "x" ]; then
3375 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3376 DEBUGECHO=$(echo "$@" | tr -d '[]')
3377 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3379 echo >&4 "[DEBUG] $1"
3384 # User-redefinable functions
3385 # Custom filename munging:
3388 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3391 # Custom genre munging:
3394 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3398 # Empty pre_read function, to be defined in the configuration file.
3405 # Empty post_read function, to be defined in the configuration file.
3412 # Empty post_encode function, to be defined in the configuration file.
3418 ###############################################################################
3421 # Start of execution
3422 ###############################################################################
3427 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3429 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3430 CDDBSUBMIT=freedb-submit@freedb.org
3432 HELLOINFO="$(whoami)@$(hostname)"
3434 CDDBLOCALPOLICY="always"
3435 CDDBLOCALRECURSIVE="y"
3436 CDDBLOCALDIR="$HOME/.cddb"
3439 # List of fields we parse and show during the CDDB parsing...
3440 SHOWCDDBFIELDS="year,genre"
3443 #CDROMREADERSYNTAX=cdparanoia
3444 ENCODERSYNTAX=default
3446 MP3ENCODERSYNTAX=default
3447 OGGENCODERSYNTAX=default
3448 OPUSENCODERSYNTAX=default
3449 FLACENCODERSYNTAX=default
3450 SPEEXENCODERSYNTAX=default
3451 MPCENCODERSYNTAX=default
3452 WVENCODERSYNTAX=default
3453 TTAENCODERSYNTAX=default
3454 APENCODERSYNTAX=default
3455 MP2ENCODERSYNTAX=default
3456 AACENCODERSYNTAX=default
3457 NORMALIZERSYNTAX=default
3458 CUEREADERSYNTAX=default
3460 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3461 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3462 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3463 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3464 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3465 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3466 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3467 PLAYLISTDATAPREFIX=''
3468 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3469 VAPLAYLISTDATAPREFIX=''
3477 VARIOUSARTISTSTYLE=forward
3484 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3485 # i.e. CDROMID="1,0,0"
3487 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3488 # If we are using the ide-scsi emulation layer, we need to define a "g"
3489 CDPARANOIACDROMBUS="d"
3491 # program paths - defaults to checking your $PATH
3497 XINGMP3ENC=xingmp3enc
3511 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3515 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3525 NEROAACENC=neroAacEnc
3527 # Note that the qaac PATH will almost always require adjustment
3528 # as it is a Windows application being run through Wine. More
3529 # detailed notes in the sample abcde.conf file in the abcde tarball.
3532 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3539 VORBISCOMMENT=vorbiscomment
3541 NEROAACTAG=neroAacTag
3542 ATOMICPARSLEY=AtomicParsley
3545 CDPARANOIA=cdparanoia
3546 CD_PARANOIA=cd-paranoia
3553 MUSICBRAINZ=abcde-musicbrainz-tool
3557 NORMALIZE=normalize-audio
3559 VORBISGAIN=vorbisgain
3563 # For Wavpack replay gain we set both the default of 'track gain'
3564 # as well as this option for 'album gain'. Better media players
3565 # such as vlc can select either or neither. Andrew.
3576 # Options for programs called from abcde
3588 VORBISGAINOPTS="--album"
3592 # The flac option is a workaround for an error where flac fails
3593 # to encode with error 'floating point exception'. This is flac
3594 # error in get_console_width(), corrected in flac 1.3.1
3596 FLACGAINOPTS="--add-replay-gain"
3603 # True Audio has no useful options but it is here anyway :)
3606 # Monkey's Audio Console (mac) chokes without a mode setting
3607 # so we set one here.
3614 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3615 # we set bitrate here.
3616 FDKAACENCOPTS='--bitrate 192k'
3637 VORBISCOMMENTOPTS="-R"
3638 METAFLACOPTS="--no-utf8-convert"
3643 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3645 # Defaults for album art downloads
3646 ALBUMARTFILE="cover.jpg"
3648 ALBUMARTALWAYSCONVERT="n"
3650 # Default to one process if -j isn't specified
3653 # List of actions to perform - by default, run to completion
3654 ACTIONS=cddb,read,encode,tag,move,clean
3656 # This option is basically for Debian package dependencies:
3657 # List of preferred outputs - by default, run with whatever we have in the path
3658 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
3660 # List of preferred cdromreaders - by default, run whichever we have in the path
3661 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3663 # fd for when `vecho` and `log info` called with redirected stdout
3666 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3667 # Linux/OpenBSD. ftp is user for NetBSD.
3668 # Let's use these checkings to determine the OS flavour, which will be used
3670 if [ X$(uname) = "XFreeBSD" ] ; then
3675 elif [ X$(uname) = "XDarwin" ] ; then
3678 # We should have diskutil in OSX, but let's be sure...
3680 CDROMREADERSYNTAX=cddafs
3681 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3683 elif [ X$(uname) = "XOpenBSD" ] ; then
3687 elif [ X$(uname) = "XNetBSD" ] ; then
3691 elif [ X$(uname) = "SunOS" ] ; then
3699 # If CDDBAVAIL is set to n, no CDDB read is done
3703 # But before we get into business, let us chop off any GREP environmental
3708 if [ -z "$OUTPUTDIR" ]; then
3712 if [ -z "$WAVOUTPUTDIR" ]; then
3713 WAVOUTPUTDIR="$OUTPUTDIR"
3716 # Load system defaults
3717 if [ -r /etc/abcde.conf ]; then
3720 # Load user preference defaults
3721 if [ -r $HOME/.abcde.conf ]; then
3725 # By this time, we need some HTTPGETOPTS already defined.
3726 # If the user has defined a non-default HTTPGET method, we should not be empty.
3728 if [ "$HTTPGETOPTS" = "" ] ; then
3730 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3731 curl) HTTPGETOPTS="-f -s";;
3732 fetch)HTTPGETOPTS="-q -o -";;
3733 ftp) HTTPGETOPTS="-a -V -o - ";;
3734 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3738 # If the CDROM has not been set yet, find a suitable one.
3739 # If this is a devfs system, default to /dev/cdroms/cdrom0
3740 # instead of /dev/cdrom
3741 if [ "$CDROM" = "" ] ; then
3742 if [ -e /dev/cdroms/cdrom0 ]; then
3743 CDROM=/dev/cdroms/cdrom0
3744 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3745 CDROM=/dev/${BASH_REMATCH[1]}
3746 elif [ -e /dev/cdrom ]; then
3748 elif [ -e /dev/sr0 ]; then
3750 elif [ -e /dev/cd0c ]; then
3752 elif [ -e /dev/acd0c ]; then
3754 elif [ -e /dev/disk1 ]; then
3759 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3760 # that's changed to a number to allow for more control. Deal with
3761 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3762 case "$EXTRAVERBOSE" in
3771 # Parse command line options
3772 while getopts 1a:bc:C:d:DefgGhj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3775 a) ACTIONS="$OPTARG" ;;
3776 A) EXPACTIONS="$OPTARG" ;;
3778 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3779 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3780 d) CDROM="$OPTARG" ;;
3783 e) ERASEENCODEDSTATUS=y ;;
3784 E) ENCODING="$OPTARG" ;;
3789 j) MAXPROCS="$OPTARG" ;;
3792 L) CDDBUSELOCAL=y ;;
3797 o) OUTPUTTYPE="$OPTARG" ;;
3800 r) REMOTEHOSTS="$OPTARG" ;;
3801 R) CDDBLOCALRECURSIVE=y ;;
3802 s) SHOWCDDBFIELDS="$OPTARG" ;;
3803 S) CDSPEEDVALUE="$OPTARG" ;;
3804 t) STARTTRACKNUMBER="$OPTARG" ;;
3805 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3808 echo "This is abcde v$VERSION."
3809 echo "Usage: abcde [options] [tracks]"
3810 echo "abcde -h for extra help"
3813 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3815 X) CUE2DISCID="$OPTARG" ;;
3816 w) COMMENT="$OPTARG" ;;
3817 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3818 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
3819 STARTTRACKNUMBERTAG="y"
3820 COMMENT="CD${OPTARG}"
3821 DISCNUMBER="${OPTARG}"
3823 log error "argument of -W must be integer"
3827 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3832 shift $(($OPTIND - 1))
3834 # Here it comes the worse part of the whole thing. From here until we start
3835 # ripping, we have a mixture of sanity checks, verifications, default settigs
3836 # and other crazy stuff that interdepends, but hey, someone has to do it.
3838 # If NOCDDBQUERY is set, don't query the CDDB server.
3839 if [ "$NOCDDBQUERY" = "y" ]; then
3843 # If the user specified a flac file, then switch to special flac mode
3844 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3845 if [ ! -f "$CDROM" ]; then
3846 log error "the defined file for FLAC ripping cannot be found" >&2
3849 vecho warning "switching to flac CDROMREADERSYNTAX..."
3850 CDROMREADERSYNTAX=flac
3851 # We have a builtin version of cue2discid...
3852 case "$CUE2DISCID" in
3854 *) NEEDCUE2DISCID=y;;
3860 # If the user provided a DISCID, disable eject
3861 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3863 # Check the available cd rippers in the system, from the ones we know.
3864 if [ "$CDROMREADERSYNTAX" = "" ]; then
3865 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3866 if new_checkexec $DEFAULT_CDROMREADER; then
3867 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3871 if [ "$CDROMREADERSYNTAX" = "" ]; then
3872 log error "no cdreader found in your PATH"
3873 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3878 # Decide if we can continue.
3879 if [ "$ONETRACK" = "y" ]; then
3880 # FIXME # remove check as soon as we find out about the other readers
3881 case "$CDROMREADERSYNTAX" in
3883 cdparanoia | libcdio) ;;
3884 cdda2wav | icedax) ;;
3886 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3889 if [ "$BATCHNORM" = "y" ]; then
3890 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3893 if [ "$NOGAP" = "y" ]; then
3894 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3897 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3898 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3899 if [ $# -gt 0 ]; then
3900 log warning "ONETRACK mode selected, grabbing all tracks..."
3903 while [ $# -gt 0 ]; do
3904 # Range parsing code courtesy of Vincent Ho
3905 # Cleaned up to use shell built-ins by Charles Steinkuehler
3906 if [ "${1#*[^0-9-]}" != "$1" ]; then
3907 log error "syntax error while processing track numbers ($1)"
3912 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3913 TRACKQUEUE="$TRACKQUEUE $RSTART"
3914 RSTART=$(( $RSTART + 1 ))
3921 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3922 # List of experimental actions: retag,transcode
3924 # Determine what actions are to be done from $ACTIONS and set the
3925 # following environment variables for them:
3937 ## FIXME ## Lets keep compatibility with -M
3938 [ "$DOCUE" != "y" ] && DOCUE=n
3940 for ACTION in $(echo $ACTIONS | tr , \ )
3943 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
3944 cue) DOCUE=y ; MAKECUEFILE=y ;;
3947 normalize) DONORMALIZE=y; DOREAD=y;;
3948 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3949 encode) DOENCODE=y; DOREAD=y;;
3950 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3951 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3952 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3953 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
3954 playlist) DOCDDB=y; DOPLAYLIST=y;;
3956 getalbumart) GETALBUMART=y;;
3960 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3961 # FIXME # should we abort on error or just inform the user?
3962 log warning "selected both normalize and replaygain actions"
3965 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
3966 case $SHOWCDDBFIELD in
3967 y*|Y*) SHOWCDDBYEAR="y";;
3968 g*|G*) SHOWCDDBGENRE="y";;
3973 # At this point a CDROM has to be defined, so we check it exists.
3974 if [ X"$CDROM" != "X" ] ; then
3975 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
3976 if [ "$OSFLAVOUR" = "FBSD" ]; then
3977 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
3978 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
3979 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
3983 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
3984 log error "CDROM device cannot be found."
3987 # avoid processing if we are not going to hit the CDROM.
3988 elif [ X"$DOREAD" = "Xy" ]; then
3989 log error "CDROM has not been defined or cannot be found"
3993 # USEPIPES pre-tests, before we get into more serious stuff
3994 # Not compatible with:
3995 # - multiple outputs
3997 # - lowdisk algorithm
3999 if [ X"$USEPIPES" = "Xy" ]; then
4000 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
4001 log error "Unix pipes not compatible with multiple outputs"
4004 if [ X"$DONORMALIZE" = "Xy" ]; then
4005 log error "Unix pipes not compatible with normalizer"
4006 # FIXME # Do we need to exit or shall we just disable the mode?
4009 if [ X"$BATCHNORM" = "Xy" ]; then
4010 log error "Unix pipes not compatible with BATCHNORM encoding"
4013 if [ X"$NOGAP" = "Xy" ]; then
4014 log error "Unix pipes not compatible with NOGAP encoding"
4017 if [ X"$DOENCODE" = "Xn" ]; then
4018 vecho warning "Disabling Unix pipes since we are not encoding!"
4021 if [ X"$LOWDISK" = "Xy" ]; then
4022 log error "Unix pipes not compatible with lowdisk algorithm"
4027 # LOWDISK pre-tests, before we get into more problematic stuff
4028 # Not compatible with anything that needs all the files in the hard disc:
4031 if [ X"$LOWDISK" = "Xy" ]; then
4032 if [ X"$BATCHNORM" = "Xy" ]; then
4033 log error "Unix pipes not compatible with BATCHNORM encoding"
4036 if [ X"$NOGAP" = "Xy" ]; then
4037 log error "Unix pipes not compatible with NOGAP encoding"
4042 # BATCHNORM pre-tests, before we get into serious problems
4043 # Not compatible with
4044 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4045 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4049 # Check the encoding format from the ones available in the system, if nothing has been configured.
4050 if [ X"$OUTPUTTYPE" = "X" ]; then
4051 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4052 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
4053 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
4054 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
4055 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4056 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4060 if [ X"$OUTPUTTYPE" = "X" ]; then
4061 log error "no encoder found in the PATH"
4062 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4067 # Decide which CDROM reader we're gonna use
4068 case "$CDROMREADERSYNTAX" in
4070 CDROMREADER="$CDPARANOIA"
4071 CDROMREADEROPTS="$CDPARANOIAOPTS"
4074 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4075 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4076 CDROMREADER="$CD_PARANOIA"
4077 CDROMREADEROPTS="$CDPARANOIAOPTS"
4080 CDROMREADER="$CDDA2WAV"
4081 CDROMREADEROPTS="$CDDA2WAVOPTS"
4084 CDROMREADER="$DAGRAB"
4085 CDROMREADEROPTS="$DAGRABOPTS"
4089 CDROMREADEROPTS="$PIRDOPTS"
4092 CDROMREADER="$CDDAFS"
4093 CDROMREADEROPTS="$CDDAFSOPTS"
4097 CDROMREADEROPTS="$FLACOPTS"
4101 # There's only one normalize...
4102 case "$NORMALIZERSYNTAX" in
4104 NORMALIZER="$NORMALIZE"
4105 NORMALIZEROPTS="$NORMALIZEOPTS"
4109 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4110 case "$OUTPUTTYPE" in *:*)
4111 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4112 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4114 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4115 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4116 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4117 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4118 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4119 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4120 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4121 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4122 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4123 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4124 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4127 # Allows commandline selection of options while using multiple outputs.
4128 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4129 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4130 TEMPOUTPUT=${OUTPUT%%:*}
4131 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4133 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4137 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4138 # for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as and
4139 # wavpack for wvs...
4141 # Getting ready for multiple output changes
4142 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4146 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4147 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4148 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4149 OGGOUTPUTCONTAINER=ogg
4152 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4153 OPUSOUTPUTCONTAINER=opus
4156 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4157 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4158 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4161 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4162 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4163 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4164 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4167 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4168 # [ "$DOREPLAYGAIN" = "y" ] &&
4171 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4172 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4175 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4177 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4178 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4181 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4182 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4185 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4186 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4187 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4190 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4191 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4192 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4195 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4197 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4198 # compiled without libmp4v2... Andrew.
4201 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4202 [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4203 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4204 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4205 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4206 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4209 if [ "$KEEPWAVS" = "y" ]; then
4210 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4214 *) log error "Invalid OUTPUTTYPE defined"
4220 # decide which encoder
4221 case "$MP3ENCODERSYNTAX" in
4223 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4227 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4231 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4232 MP3ENCODER="$BLADEENC"
4235 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4239 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4240 MP3ENCODER="$XINGMP3ENC"
4243 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4244 MP3ENCODER="$MP3ENC"
4247 case "$OGGENCODERSYNTAX" in
4249 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4250 OGGENCODER="$VORBIZE"
4253 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4254 OGGENCODER="$OGGENC"
4257 case "$OPUSENCODERSYNTAX" in
4259 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4260 OPUSENCODER="$OPUSENC"
4263 case "$FLACENCODERSYNTAX" in
4265 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4267 if [ "$DOREPLAYGAIN" = "y" ]; then
4268 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4270 # FLAC streams can be encapsulated on a Ogg transport layer
4271 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4272 log error "FLAC on an Ogg container is not yet supported"
4273 log error "due to problem with adding comments to such files"
4275 FLACOUTPUTCONTAINER=ogg
4277 FLACOUTPUTCONTAINER=flac
4281 case "$SPEEXENCODERSYNTAX" in
4283 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4284 SPEEXENCODER="$SPEEXENC"
4287 case "$MPCENCODERSYNTAX" in
4289 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4290 MPCENCODER="$MPCENC"
4293 case "$WVENCODERSYNTAX" in
4295 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4296 # and in the interests of backward compatibility:
4297 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4298 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4299 WVENCODER="$WAVPACK"
4301 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4302 WVENCODER="$WAVPACK"
4306 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4310 case "$TTAENCODERSYNTAX" in
4312 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4316 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4317 TTAENCODER="$TTAENC"
4320 case "$APENCODERSYNTAX" in
4322 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4326 case "$MP2ENCODERSYNTAX" in
4328 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4329 MP2ENCODER="$TWOLAME"
4332 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4333 MP2ENCODER="$FFMPEG"
4336 case "$AACENCODERSYNTAX" in
4337 # Some elaborate 'if' work to keep backward compatibility for those
4338 # who don't realise that AACENCOPTS does not work with abcde from
4339 # version 2.7 onwards.
4341 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4342 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4345 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4350 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4351 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4352 AACENCODER="$NEROAACENC"
4354 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4355 AACENCODER="$NEROAACENC"
4359 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4360 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4361 AACENCODER="$FDKAAC"
4363 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4364 AACENCODER="$FDKAAC"
4368 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4369 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4372 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4377 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4378 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4379 AACENCODER="$FHGAACENC"
4381 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4382 AACENCODER="$FHGAACENC"
4386 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4387 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4388 AACENCODER="$FFMPEG"
4390 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4391 AACENCODER="$FFMPEG"
4401 TAGGEROPTS="$ID3OPTS"
4406 TAGGEROPTS="$ID3V2OPTS"
4410 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4411 # trouble with CDDBPROTO=5 (which we test here) but also
4412 # with cached cddb files in latin1 (which we cannot test).
4413 if [ "$CDDBPROTO" -lt 6 ]; then
4414 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4417 # eyeD3 version 0.7 changed syntax
4418 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4419 # only if it offers the --set-encoding, assume <= 0.6.x
4421 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4423 # anything wrong, any failure, assume >= 0.7
4425 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4429 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4434 # NOGAP is specific to lame. Other encoders fail ...
4435 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4436 log warning "the NOGAP option is specific to lame. Deactivating..."
4441 case "$CUEREADERSYNTAX" in
4443 CUEREADEROPTS="${CDROM}"
4448 # which information retrieval tool are we using?
4454 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4455 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4456 log error "FLAC on an Ogg container is not yet supported"
4457 log error "due to problem with adding comments to such files"
4459 OGGOUTPUTCONTAINER=ogg.ogg
4460 FLACOUTPUTCONTAINER=flac.ogg
4461 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4464 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4466 if [ "$ENCNICE" ]; then
4467 ENCNICE="-n $ENCNICE"
4469 if [ "$READNICE" ]; then
4470 READNICE="-n $READNICE"
4472 if [ "$DISTMP3NICE" ]; then
4473 DISTMP3NICE="-n $DISTMP3NICE"
4476 # Don't check for stuff if it's not needed
4477 if [ "$REMOTEHOSTS" ]; then
4480 if [ "$DONORMALIZE" = "y" ]; then
4483 if [ "$EJECTCD" = "y" ]; then
4486 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4487 if [ "$CDDBMETHOD" = "cddb" ]; then
4489 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4493 if [ "$DOCUE" = "y" ]; then
4497 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4498 case "$CDROMREADERSYNTAX" in
4499 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4500 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4501 ### FIXME ### translate "cue2discid" from python to bash
4502 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4507 if [ "$GETALBUMART" = "y" ]; then
4512 ###USEPIPESSUPPORT###
4514 # Rippers with USEPIPE support
4515 PIPERIPPER_cdparanoia="-"
4516 PIPERIPPER_libcdio="-"
4517 # Note that by default in abcde cdda2wav redirects to icedax.
4518 PIPERIPPER_cdda2wav="-"
4519 PIPERIPPER_debug="-"
4520 PIPERIPPER_flac="-c "
4523 # Encoders with USEPIPE support
4526 PIPE_bladeenc="stdin"
4539 # Both neroAacEnc and fdkaac seem to manage without the addition of
4540 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4541 # in this manner. Andrew.
4545 # Figure out if we can use pipes with the ripper/encoder combination
4547 if [ "$USEPIPES" = "y" ]; then
4548 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4551 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4553 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4555 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4557 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4559 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4561 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4563 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4565 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4567 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4569 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4571 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4572 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4573 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4574 log error "no support for pipes with given ripper"
4575 log error "read the FAQ file from the source tarball to get help."
4578 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4579 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4580 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4581 log error "no support for pipes with given encoder"
4582 log error "read the FAQ file from the source tarball to get help"
4587 # Make sure a buncha things exist
4588 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4589 $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4590 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER \
4591 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4592 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4593 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4594 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4595 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4596 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4597 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4598 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4599 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4600 ${NEEDMID3V2+$MID3V2}
4605 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4606 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4607 # these files). The resulting files are actually ADTS streams which belong in an
4608 # aac container and with some version sniffing this is all cleaned up below. If
4609 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4611 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4612 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4613 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4614 echo "WARNING: Your copy of Faac does not have mp4 support"
4615 echo "WARNING: Encoding untagged files to aac..."
4618 echo "Using Faac to Tag AAC Tracks..."
4622 # And last but not least, check if we can diff between files. We do not abort,
4623 # since diffing is not critical...
4624 if [ -x $(which $DIFF) ]; then :; else
4625 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4629 ## Now that we have metaflac, check if we need cue2discid
4630 #case $CDROMREADERSYNTAX in
4632 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4633 # if [ "$TRACKINFO" = "" ]; then
4634 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4639 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4640 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4641 HTTPGET="$HTTPGET $HTTPGETOPTS"
4643 # Here it used to say:
4644 # One thousand lines in, we can start doing stuff with things
4645 # Well, right now we are at line 3737 ;)
4647 # Export needed things so they can be read in this subshell
4648 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4649 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4651 if [ "$DOREAD" = "y" ]; then
4652 # User-definable function to set some things. Use it for
4653 # - closing the CD tray with eject -t
4654 # - set the CD speed value with eject -x
4655 vecho -n "Executing customizable pre-read function... "
4657 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4662 # Get ABCDETEMPDIR created and status file initialized
4665 if [ "$DOCDDB" = "y" ]; then
4666 # start with a sane default:
4667 CDDBLOCALSTATUS=notfound
4668 if [ $CDDBUSELOCAL = "y" ]; then
4671 if checkstatus cddb-choice > /dev/null; then
4674 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4675 case "$CDDBMETHOD" in
4686 CHOICE=$(checkstatus cddb-choice)
4687 if [ "$CHOICE" = 0 ] ; then
4688 # We don't have any information at all; try to fall back
4689 # to CD-Text for basic information
4690 vecho "No CDDB information found, trying cdtext from the CD"
4696 eval "$($CDDBTOOL parse "$CDDBDATA")"
4699 # Before reading tracks, we set the speed of the device
4701 if [ X"$CDSPEEDVALUE" != "X" ]; then
4702 case "$CDROMREADERSYNTAX" in
4703 cdparanoia|libcdio|debug) ;;
4710 # Define the first and last track, since we might need them later in several places
4711 FIRSTTRACK=$( get_first $TRACKQUEUE )
4712 LASTTRACK=$( get_last $TRACKQUEUE )
4714 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4715 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4716 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4717 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4720 if checkstatus onetrack ; then ONETRACK=y ; fi
4722 if [ "$ONETRACK" = "y" ]; then
4723 # Reuse the CUEFILE in case we created it (now or in a previous run)
4724 if CUEFILE=$(checkstatus cuefile); then
4729 # Create playlist if needed (backgroundable) and start reading in tracks
4733 if [ ! "$ONETRACK" = "y" ]; then
4734 if [ "$DOPLAYLIST" = "y" ]; then
4735 echo Creating playlist... >&2
4740 if [ "$GETALBUMART" = "y" ]; then
4744 # For the lowdisk option, only one program is running at once so the encoder
4745 # can be unsilenced right away.
4746 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4747 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4750 if [ "$ONETRACK" = "y" ]; then
4751 TRACKS="$FIRSTTRACK"
4752 if [ "$USEPIPES" = "y" ]; then
4753 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4754 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4757 if checkstatus readtrack-$FIRSTTRACK; then :; else
4758 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4762 for UTRACKNUM in $TRACKQUEUE
4764 if [ "$DOREAD" = "y" ]; then
4765 if [ "$USEPIPES" = "y" ]; then
4766 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4767 # Read, pipe, shut up!
4768 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4771 if checkstatus readtrack-$UTRACKNUM; then :; else
4772 do_cdread $UTRACKNUM
4774 if [ "$?" != "0" ]; then
4775 # CD read failed - don't give the goahead to
4782 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4785 # If we are not reading, set the encode output to loud already, so
4786 # that we can see the output of the first track.
4787 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4788 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4790 echo NEXTTRACK # Get the encoder machine churning again
4791 if [ "$DOREAD" = "y" ]; then
4792 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4793 until checkstatus encodetrack-$UTRACKNUM
4795 if checkerrors encodetrack-$UTRACKNUM; then
4806 # Now that we're done the encoding can be loud again -
4807 # if we're not using SMP.
4808 if [ "$MAXPROCS" = "1" ]; then
4809 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4812 # All tracks read, start encoding.
4813 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4817 # Execute the user-defined post_read function before ejecting CD
4820 # We are now finished with the cdrom - it can be safely ejected. Note that
4821 # abcde will not have completed yet.
4822 if [ "$EJECTCD" = "y" ]; then
4823 # We check if the disk we are processing is actually the disk inside the
4824 # CD tray. If not, we do not eject the CD, since it might be so that the
4825 # user ejected it manually.
4826 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4827 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4828 # More FreeBSD bits.
4829 if [ X"$(uname)" = X"FreeBSD" ] ; then
4830 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4831 # but in this script EJECT is in the envionment and names the program
4834 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4835 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4836 $eject $EJECTOPTS $cd
4837 elif [ X"$(uname)" = X"Darwin" ] ; then
4838 diskutil eject ${CDROM#/dev/} 0
4839 elif [ -x $(which $EJECT) ]; then
4840 $EJECT $EJECTOPTS "$CDROM"
4847 ## Do we need to pre-process
4848 #if [ x"$PREPROCESS" = "x" ] ; then
4851 # for PRETRACKNUM in $TRACKQUEUE
4854 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4856 # until [ $PREPROCEED ]
4858 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4859 # # all locations are working, wait and try again later
4860 # if [ ! $PREPROCEED ]; then sleep 3; fi
4862 # ( do_preprocess $PRETRACKNUM
4870 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4872 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4873 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4874 if [ "$GOAHEAD" = "NO" ]; then break; fi
4875 for LASTTRACK in $TRACKQUEUE; do :; done
4876 if checkstatus readtrack-$LASTTRACK; then
4877 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4878 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4879 if checkerrors batch-normalize; then exit 1; fi
4881 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4882 if [ "$DONORMALIZE" = "y" ]; then
4883 for UTRACKNUM in $TRACKQUEUE
4885 if checkstatus readtrack-$UTRACKNUM; then
4886 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4890 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4891 if checkerrors nogap-encode; then exit 1; fi
4896 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4897 if [ "$ONETRACK" = "y" ] ; then
4898 TRACKQUEUE="$FIRSTTRACK"
4899 TRACKS="$FIRSTTRACK"
4902 # Do the encoding, including parallelization of remote encoding
4903 # Figure out where each track is going to be encoded
4904 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4905 if [ "$MAXPROCS" != "0" ]; then
4906 for NUM in $(f_seq_row 1 "$MAXPROCS")
4908 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
4912 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
4913 for UTRACKNUM in $TRACKQUEUE
4916 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4917 if [ "$GOAHEAD" = "NO" ]; then break; fi
4918 # find out where this track is to be encoded
4919 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4920 # Make sure we have a place to encode this, if not, exit stage right
4921 if [ -z "$ENCODELOCATIONS" ]; then
4927 for LOCATION in $ENCODELOCATIONS
4929 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4930 # check first if a track has ever been assigned to this location
4931 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
4932 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4933 if checkerrors encodetrack-$PREVIOUSTRACK; then
4934 for TEMPLOCATION in $ENCODELOCATIONS
4936 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4937 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
4940 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
4945 # We're still here, this location must have been previously assigned,
4946 # and last completed without error - check if it's done with the
4947 # previous track yet
4948 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
4950 # all locations are working, wait and try again later
4951 if [ ! $PROCEED ]; then sleep 3; fi
4953 # Record the location we're about to encode the next track at
4954 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4956 # Don't proceed with the rest of the loop if we can't encode
4957 if [ "$ABORT" ]; then continue; fi
4958 ## FIXME ## Add here
4959 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4960 # Set TRACKNUM, TRACKNAME
4961 if [ -e "$CDDBDATA" ]; then
4962 if [ "$ONETRACK" = "y" ]; then
4964 TRACKNUM="$FIRSTTRACK"
4968 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
4969 getcddbinfo TRACKNAME
4973 # You can't encode a file which needs to be normalized before finishing
4974 # You can't tag a file before it's finished encoding -
4975 # thus all of this is backgrounded together
4977 if [ "$DONORMALIZE" = "y" ]; then
4978 if checkstatus readtrack-$UTRACKNUM; then
4979 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4982 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4983 if checkstatus readtrack-$UTRACKNUM; then
4984 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4985 if [ "$DONORMALIZE" = "y" ]; then
4986 if checkstatus normalizetrack-$UTRACKNUM; then
4987 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4990 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4994 if [ "$DOTAG" = "y" ]; then
4995 if checkstatus encodetrack-$UTRACKNUM; then
4996 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
4998 # Lets tag the cue file
4999 if checkstatus cleancuefile >/dev/null; then :; else
5000 if checkstatus cuefile >/dev/null ; then
5005 if [ "$DOMOVE" = "y" ]; then
5006 if checkstatus tagtrack-$UTRACKNUM; then
5007 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
5014 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5015 # we'll delete the files they're working on
5016 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5017 ## FIXME ## Check also for files which are encoded using PIPEs.
5018 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5023 for LOCATION in $ENCODELOCATIONS
5025 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5026 # "How can he give us a status update, if he's DEAD?"
5027 if checkstatus encodetrack-$CHECKTRACK; then
5030 # Nothing to see here please go quietly back to your homes
5031 if [ -z "$CHECKTRACK" ]; then continue; fi
5032 # You're still here? Maybe there is something...
5033 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
5036 if [ ! $PROCEED ]; then sleep 5; fi
5039 # If the above didn't catch the stragglers, this will
5041 if [ "$DOREPLAYGAIN" = "y" ]; then
5045 # Execute the user-defined post_encode function before cleaning up
5048 # Check to see if run_command logged any errors
5049 if [ -f "$ABCDETEMPDIR/errors" ]; then
5050 log error "The following commands failed to run:"
5051 cat "$ABCDETEMPDIR/errors"
5055 if [ "$KEEPWAVS" = "y" ];then
5059 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5060 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5061 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5062 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5063 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5064 log warning "The encoded formats does not match with the moved ones"
5065 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
5066 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
5067 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
5071 if [ "$DOCLEAN" = "y" ]; then
5072 # Wipe all the evidence
5073 # Gimme gimme gimme some more time!
5075 rm -rf "$ABCDETEMPDIR"
5078 echo "Finished. Not cleaning $ABCDETEMPDIR."