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). 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 run_command tagtrack-$OUTPUT-$1 true
1021 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1022 run_command tagtrack-$1 true
1028 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1031 # The commands here don't go through run_command because they're never
1032 # supposed to be silenced
1033 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1034 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1038 case "$MP3ENCODERSYNTAX" in
1043 for UTRACKNUM in $TRACKQUEUE
1045 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1047 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1049 if [ "$RETURN" != "0" ]; then
1050 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1052 for UTRACKNUM in $TRACKQUEUE
1054 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1055 #run_command encodetrack-$UTRACKNUM true
1064 if checkerrors "nogap-encode"; then :; else
1065 if [ ! "$KEEPWAVS" = "y" ] ; then
1066 if [ ! "$KEEPWAVS" = "move" ] ; then
1071 # Other encoders fall through to normal encoding as the tracks have not
1072 # been entered in the status file.
1075 # do_encode [tracknumber] [hostname]
1076 # If no hostname is specified, encode locally
1078 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1079 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1082 if [ "$USEPIPES" = "y" ]; then
1085 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1088 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1091 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1094 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1097 TEMPARG="PIPE_$SPEEXENCODER"
1100 TEMPARG="PIPE_$MPCENCODER"
1103 TEMPARG="PIPE_$WVENCODERSYNTAX"
1106 TEMPARG="PIPE_$AACENCODERSYNTAX"
1109 TEMPARG="PIPE_$AACENCODERSYNTAX"
1112 IN="$( eval echo "\$$TEMPARG" )"
1114 IN="$ABCDETEMPDIR/track$1.wav"
1116 # We need IN to proceed, if we are not using pipes.
1117 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1118 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1120 case "$TMPOUTPUT" in
1122 OUTPUT=$OGGOUTPUTCONTAINER
1125 OUTPUT=$OPUSOUTPUTCONTAINER
1128 OUTPUT=$FLACOUTPUTCONTAINER
1134 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1135 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1138 if [ X"$USEPIPES" = "Xy" ]; then
1140 # We need a way to store the creation of the files when using PIPES
1141 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1142 # When piping it does not make sense to have a higher nice for
1143 # reading than for encoding, since it will be hold by the
1144 # encoding process. Setting an effective nice, to calm down a
1145 # bit the reading process.
1146 EFFECTIVE_NICE=$READNICE
1148 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1149 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1150 EFFECTIVE_NICE=$ENCNICE
1156 case "$MP3ENCODERSYNTAX" in
1157 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1158 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1159 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1160 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1164 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1171 case "$OGGENCODERSYNTAX" in
1172 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1173 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1177 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1184 case "$OPUSENCODERSYNTAX" in
1186 # Tag the file at encode time, as it can't be done after encoding.
1187 if [ "$DOTAG" = "y" ]; then
1188 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1189 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1190 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1192 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1198 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1205 case "$FLACENCODERSYNTAX" in
1206 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1211 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1212 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1217 if [ "$(eval echo ${COMMENT})" != "" ]; then
1220 *) COMMENT="COMMENT=$COMMENT" ;;
1223 # Tag the file at encode time, as it can't be done after encoding.
1224 if [ "$DOTAG" = "y" ]; then
1225 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1226 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1228 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1232 # Tag the file inline at encode time.
1233 if [ "$DOTAG" = "y" ]; then
1234 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1235 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1237 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1241 case "$WVENCODERSYNTAX" in
1243 if [ "$DOTAG" = "y" ]; then
1244 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1245 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1247 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1251 if [ "$DOTAG" = "y" ]; then
1252 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1253 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1254 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1256 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1262 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1265 case "$MP2ENCODERSYNTAX" in
1267 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1270 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1275 # aac container is only used to catch faac encoded files where faac
1276 # is compiled without mp4 support (with libmp4v2).
1277 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1280 case "$AACENCODERSYNTAX" in
1282 if [ "$DOTAG" = "y" ]; then
1283 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1284 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1286 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1290 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1293 if [ "$DOTAG" = "y" ]; then
1294 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1295 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1297 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1301 if [ "$DOTAG" = "y" ]; then
1302 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1303 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1305 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1309 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1312 if [ "$DOTAG" = "y" ]; then
1313 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1314 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1315 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1317 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1323 # In case of wav output we need nothing. Just keep the wavs.
1324 # But we need the following to allow full logging and subsequent
1325 # successful cleaning of $ABCDETEMPDIR.
1326 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1331 # Only remove .wav if the encoding succeeded
1332 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1333 run_command encodetrack-$1 true
1334 if [ ! "$KEEPWAVS" = "y" ] ; then
1335 if [ ! "$KEEPWAVS" = "move" ] ; then
1341 run_command "" echo "HEH! The file we were about to encode disappeared:"
1342 run_command "" echo ">> $IN"
1343 run_command encodetrack-$1 false
1347 # do_preprocess [tracknumber]
1349 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1352 # IN="$ABCDETEMPDIR/track$1.wav"
1353 # # We need IN to proceed.
1354 # if [ -s "$IN" ] ; then
1355 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1357 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1358 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1359 # case "$POSTPROCESSFORMAT" in
1361 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1363 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1365 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1367 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1369 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1372 # # Only remove .wav if the encoding succeeded
1373 # if checkerrors "preprocess-(.{3,4})-$1"; then
1374 # run_command preprocess-$1 false
1376 # run_command preprocess-$1 true
1379 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1380 # echo "HEH! The file we were about to pre-process disappeared:"
1383 # run_command preprocess-$1 false
1388 # do_postprocess [tracknumber]
1390 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1393 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1395 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1396 # # We need IN to proceed.
1397 # if [ -s "$IN" ] ; then
1398 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1399 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1400 # case "$POSTPROCESSFORMAT" in
1402 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1404 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1406 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1408 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1410 # # Only remove .wav if the encoding succeeded
1411 # if checkerrors "postprocess-(.{3,4})-$1"; then
1412 # run_command postprocess-$1 false
1414 # run_command postprocess-$1 true
1417 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1418 # echo "HEH! The file we were about to post-process disappeared:"
1421 # run_command postprocess-$1 false
1436 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1440 # The commands here don't go through run_command because they're never supposed to be silenced
1441 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1446 for UTRACKNUM in $TRACKQUEUE
1448 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1450 # FIXME # Hard-coded batch option!
1451 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1453 if [ "$RETURN" != "0" ]; then
1454 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1456 for UTRACKNUM in $TRACKQUEUE
1458 echo normalizetrack-$UTRACKNUM >> status
1464 # do_batch_normalize
1466 # NORMALIZER, NORMALIZEROPTS
1467 do_batch_normalize ()
1469 # The commands here don't go through run_command because they're never supposed to be silenced
1470 echo "Batch normalizing tracks: $TRACKQUEUE"
1475 for UTRACKNUM in $TRACKQUEUE
1477 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1479 # XXX: Hard-coded batch option!
1480 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1482 if [ "$RETURN" != "0" ]; then
1483 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1485 for UTRACKNUM in $TRACKQUEUE
1487 echo normalizetrack-$UTRACKNUM >> status
1493 # do_normalize [tracknumber]
1495 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1498 IN="$ABCDETEMPDIR/track$1.wav"
1499 if [ -e "$IN" ] ; then
1500 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1501 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1503 if [ "$(checkstatus encode-output)" = "loud" ]; then
1504 echo "HEH! The file we were about to normalize disappeared:"
1507 run_command normalizetrack-$1 false "File $IN was not found"
1511 # do_move [tracknumber]
1512 # Deduces the outfile from environment variables
1513 # Creates directory if necessary
1515 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1518 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1520 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1521 # defined the OUTPUTFILE:
1524 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1525 ALBUMFILE="$(mungefilename "$DALBUM")"
1526 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1527 TRACKFILE="$(mungefilename "$TRACKNAME")"
1528 GENRE="$(mungegenre "$GENRE")"
1529 YEAR=${CDYEAR:-$CDYEAR}
1530 # If we want to start the tracks with a given number, we need to modify
1531 # the TRACKNUM value before evaluation
1533 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1534 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1535 if [ "$ONETRACK" = "y" ]; then
1536 if [ "$VARIOUSARTISTS" = "y" ]; then
1537 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1539 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1542 if [ "$VARIOUSARTISTS" = "y" ]; then
1543 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1545 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1548 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1549 # Once we know the specific output was successful, we can change
1550 # the OUTPUT to the value containing the container
1553 OUTPUT=$OGGOUTPUTCONTAINER
1556 OUTPUT=$OPUSOUTPUTCONTAINER
1559 OUTPUT=$FLACOUTPUTCONTAINER
1565 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1566 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1569 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1570 # FIXME # introduce warnings?
1573 # mkdir -p shouldn't return an error if the directory already exists
1574 mkdir -p "$OUTPUTFILEDIR"
1575 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1576 if checkstatus movetrack-output-$OUTPUT; then :; else
1577 run_command movetrack-output-$OUTPUT true
1582 # mkdir -p shouldn't return an error if the directory already exists
1583 mkdir -p "$OUTPUTFILEDIR"
1584 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1585 if checkstatus movetrack-output-$OUTPUT; then :; else
1586 run_command movetrack-output-$OUTPUT true
1590 # Lets move the cue file
1591 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1592 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1593 if checkstatus movecue-$OUTPUT; then :; else
1594 # Silence the Copying output since it overlaps with encoding processes...
1595 #run_command '' vecho "Copying cue file to its destination directory..."
1596 if checkstatus onetrack >/dev/null ; then
1599 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1600 # We dont have the dir, since it was not created before.
1603 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1606 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1607 # http://brianvictor.tripod.com/mp3cue.htm#details
1608 [a-z0-9][a-z0-9][a-z0-9])
1609 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1612 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1616 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1618 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1627 # Create the playlist if wanted
1629 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1630 # VARIOUSARTISTS, OUTPUTDIR
1633 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1637 OUTPUT=$OGGOUTPUTCONTAINER
1640 OUTPUT=$OPUSOUTPUTCONTAINER
1643 OUTPUT=$FLACOUTPUTCONTAINER
1649 # Create a playlist file for the playlist data to go into.
1650 # We used to wipe it out if it existed. Now we request permission if interactive.
1651 for LASTTRACK in $TRACKQUEUE; do :; done
1652 ALBUMFILE="$(mungefilename "$DALBUM")"
1653 ARTISTFILE="$(mungefilename "$DARTIST")"
1654 GENRE="$(mungegenre "$GENRE")"
1655 YEAR=${CDYEAR:-$CDYEAR}
1656 if [ "$VARIOUSARTISTS" = "y" ] ; then
1657 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1659 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1661 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1662 mkdir -p "$FINALPLAYLISTDIR"
1663 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1664 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1665 if [ "$INTERACTIVE" = "y" ]; then
1666 while [ "$DONE" != "y" ]; do
1668 case $ERASEPLAYLIST in
1669 e|E|a|A|k|K) DONE=y ;;
1670 "") ERASEPLAYLIST=e ; DONE=y ;;
1678 # Once we erase the playlist, we use append to create the new one.
1679 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1681 # The playlist does not exist, so we can safelly use append to create the new list
1684 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1685 touch "$OUTPUTDIR/$PLAYLISTFILE"
1686 for UTRACKNUM in $TRACKQUEUE
1688 # Shares some code with do_move since the filenames have to match
1689 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1690 getcddbinfo TRACKNAME
1692 TRACKFILE="$(mungefilename "$TRACKNAME")"
1693 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1694 ALBUMFILE="$(mungefilename "$DALBUM")"
1695 # If we want to start the tracks with a given number, we need to modify the
1696 # TRACKNUM value before evaluation
1698 if [ "$VARIOUSARTISTS" = "y" ]; then
1699 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1701 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1703 if [ "$VARIOUSARTISTS" = "y" ]; then
1704 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1705 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1707 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1710 if [ "$PLAYLISTDATAPREFIX" ]; then
1711 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1713 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1718 ## this will convert the playlist to have CRLF line-endings, if specified
1719 ## (some hardware players insist on CRLF endings)
1720 if [ "$DOSPLAYLIST" = "y" ]; then
1721 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1722 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1723 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1725 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1730 # This function reads a cuefile on stdin and writes an extended
1731 # cddb query on stdout. Any PREGAP for track 1 is properly
1732 # handled, although cue files embedded in FLAC files do not
1733 # appear to properly store the PREGAP setting. :(
1734 abcde.cue2discid () {
1739 while [ $val -gt 0 ] ; do
1740 ret=$(( $ret + ( $val % 10) ))
1741 val=$(( $val / 10 ))
1751 local first second third
1752 first=$(expr ${1} + 0 )
1753 second=$(expr ${2} + 0 )
1754 third=$(expr ${3} + 0 )
1756 echo $(( ((($first * 60) + $second) * 75) + $third ))
1766 while read line ; do
1769 TRACK) i=$(( i + 1 ))
1771 INDEX) if [ "$2" -eq 1 ] ; then
1773 START=$(( $LBA + $PREGAP + $OFFSET ))
1775 X=$(cddb_sum $(( $START / 75 )) )
1779 PREGAP) PREGAP=$(msf2lba $2)
1783 LEADOUT=$(( $4 / 588 ))
1786 LEADIN=$(( $3 / 588 ))
1795 LEADOUT=$(( $LEADOUT + $LEADIN ))
1797 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1798 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1799 printf "%08x %i" $DISCID $TRACKS
1802 while [ $j -le $TRACKS ] ; do
1803 eval echo -n "\" \$TRACK$j\""
1806 echo " $(( $LEADOUT / 75 ))"
1810 # abcde.mkcue [--wholedisk]
1811 # This creates a cuefile directly from the extended discid information
1812 # The --wholedisk option controls whether we're ripping data from the
1813 # start of track one or from the start of the disk (usually, but not
1814 # always the same thing!)
1816 # Track one leadin/pregap (if any) handeling:
1817 # --wholedisk specified:
1820 # INDEX 01 <pregap value>
1821 # Remaining track index values unchanged from disc TOC
1823 # --wholedisk not specified
1825 # PREGAP <pregap value>
1827 # Remaining track index values offset by <pregap value>
1834 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1837 local MODE DISCID TRACKS
1841 if [ "$1" = --wholedisc ] ; then
1847 vecho "One track is $ONETRACK"
1848 TRACKFILE="$(mungefilename "$TRACKNAME")"
1849 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1850 ALBUMFILE="$(mungefilename "$DALBUM")"
1851 if [ "$ONETRACK" = "y" ]; then
1852 if [ "$VARIOUSARTISTS" = "y" ]; then
1853 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1855 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1857 vecho "Cue wav file is $CUEWAVFILE"
1859 CUEWAVFILE="dummy.wav"
1868 echo REM DISCID $DISCID
1869 echo FILE \""$CUEWAVFILE"\" WAVE
1871 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1878 while [ $i -le "$TRACKS" ] ; do
1879 LBA=$(( $1 - $OFFSET ))
1880 printf " TRACK %02i AUDIO\n" $i
1881 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1882 if [ $MODE = PREGAP ] ; then
1883 echomsf " PREGAP " $(($OFFSET-150))
1885 echo " INDEX 00 00:00:00"
1888 echomsf " INDEX 01 " $LBA
1895 # This essentially the start of things
1898 # Query the CD to get the track info, unless the user specified -C
1899 # or we are using some actions which do not need the CDDB data at all
1900 #if [ ! X"$EXPACTIONS" = "X" ]; then
1902 #elif [ -z "$DISCID" ]; then
1903 if [ -z "$DISCID" ]; then
1904 vecho -n "Getting CD track info... "
1905 # In OSX, unmount the disc before a query
1906 if [ "$OSFLAVOUR" = "OSX" ]; then
1907 diskutil unmount ${CDROM#/dev/}
1909 case "$CDROMREADERSYNTAX" in
1911 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1912 case "$CUE2DISCID" in
1913 # FIXME # right now we have 2 cue2discid internal
1914 # implementations: builtin and abcde.cue2discid. Test
1915 # both of them and decide which one we want to use.
1917 #vecho "Using builtin cue2discid implementation..."
1918 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1920 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1922 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1923 TRACKS=${#OFFSETTIMES[@]}
1925 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1926 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1927 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1928 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1931 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1932 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1936 #vecho "Using external python cue2discid implementation..."
1937 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1941 log error "the input flac file does not contain a cuesheet."
1946 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1948 # if [ ! "$RET" = "0" ];then
1949 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1952 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1953 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1955 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1956 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1960 case "$CDDBMETHOD" in
1961 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1962 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1966 # Make sure there's a CD in there by checking cd-discid's return code
1967 if [ ! "$?" = "0" ]; then
1968 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1969 log error "cuesheet information from the flac file could not be read."
1970 log error "Perhaps the flac file does not contain a cuesheet?."
1973 log error "CD could not be read. Perhaps there's no CD in the drive?"
1977 # In OSX, remount the disc again
1978 if [ "$OSFLAVOUR" = "OSX" ]; then
1979 diskutil mount ${CDROM#/dev/}
1982 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1984 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1987 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1988 # This needs to be done now because a section of the resuming code will need
1991 # get the number of digits to pad TRACKNUM with - we'll use this later
1992 # a CD can only hold 99 tracks, but since we support a feature for starting
1993 # numbering the tracks from a given number, we might need to set it as a
1994 # variable for the user to define... or obtain it somehow.
1995 if [ "$PADTRACKS" = "y" ] ; then
1999 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
2000 if [ -z "$TRACKQUEUE" ]; then
2001 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2002 case "$CDROMREADERSYNTAX" in
2003 cdparanoia|libcdio|debug)
2004 if [ "$WEHAVEACD" = "y" ]; then
2005 vecho "Querying the CD for audio tracks..."
2006 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2008 if [ ! "$RET" = "0" ];then
2009 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2011 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2012 CDPARANOIAAUDIOTRACKS="$TRACKS"
2014 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2015 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
2016 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
2017 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
2019 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2020 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2024 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
2027 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2029 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2030 log info "The disc does not contain any tracks. Giving up..."
2033 echo -n "Grabbing entire CD - tracks: "
2034 if [ ! "$PADTRACKS" = "y" ] ; then
2035 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2037 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2039 while [ "$X" -ne "$TRACKS" ]
2041 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2042 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2046 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2047 # User-supplied track queue.
2048 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2049 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2050 # Once cleaned, obtain the highest value in the trackqueue for number padding
2051 for LASTTRACK in $TRACKQUEUE; do :; done
2052 if [ ! "$PADTRACKS" = "y" ] ; then
2053 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2055 # Now we normalize the trackqueue
2056 for TRACK in $TRACKQUEUE ; do
2057 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2058 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2060 TRACKQUEUE=$PADTRACKQUEUE
2061 echo Grabbing tracks: "$TRACKQUEUE"
2064 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2066 # We have the discid, create a temp directory after it to store all the temp
2069 if [ -e "$ABCDETEMPDIR" ]; then
2070 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2071 # It already exists, see if it's a directory
2072 if [ ! -d "$ABCDETEMPDIR" ]; then
2073 # This is a file/socket/fifo/device/etc, not a directory
2076 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2077 echo "Please investigate, remove it, and rerun abcde." >&2
2081 # It's a directory, let's see if it's writable by us
2082 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2083 # Nope, complain and exit
2085 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2086 echo "Please investigate, remove it, and rerun abcde." >&2
2090 # See if it's populated
2091 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2092 # Wipe and start fresh
2093 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2094 echo -n "this directory to continue. Continue [y/N]? " >&2
2095 if [ "$INTERACTIVE" = "y" ]; then
2101 if [ "$ANSWER" != "y" ]; then
2104 rm -rf "$ABCDETEMPDIR" || exit 1
2105 mkdir -p "$ABCDETEMPDIR"
2106 if [ "$?" -gt "0" ]; then
2107 # Directory already exists or could not be created
2108 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2112 # Everything is fine. Check for ^encodetracklocation-
2113 # and encode-output entries in the status file and
2114 # remove them. These are not relevant across sessions.
2115 if [ -f "$ABCDETEMPDIR/status" ]; then
2116 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2117 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2118 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2120 # Remove old error messages
2121 if [ -f "$ABCDETEMPDIR/errors" ]; then
2122 rm -f "$ABCDETEMPDIR/errors"
2126 # We are starting from scratch
2127 mkdir -p "$ABCDETEMPDIR"
2128 if [ "$?" -gt "0" ]; then
2129 # Directory already exists or could not be created
2130 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2133 cat /dev/null > "$ABCDETEMPDIR/status"
2134 # Store the abcde version in the status file.
2135 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2137 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2138 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2139 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2140 vecho "Creating cue file..."
2141 case $CDROMREADERSYNTAX in
2143 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2144 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2146 log warning "the input flac file does not contain a cuesheet."
2150 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2151 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2153 log warning "reading the CUE sheet is still considered experimental"
2154 log warning "and there was a problem with the CD reading. abcde will continue,"
2155 log warning "but consider reporting the problem to the abcde author"
2161 # If we got the CDPARANOIA status and it is not recorded, save it now
2162 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2163 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2164 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2168 # Create the discid file
2169 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2170 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2171 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2176 # Create a proper CUE file based on the CUE file we created before.
2179 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2180 CUEFILE_OUT=$CUEFILE_IN.out
2181 ### FIXME ### checkstatus cddb
2182 if [ -e "$CDDBDATA" ]; then
2183 vecho "Adding metadata to the cue file..."
2184 # FIXME It doesn't preserve spaces! Why?
2185 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2187 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2188 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2189 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2193 cat "$CUEFILE_IN" | while read line
2195 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2196 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2197 # echo "$line" >> "$CUEFILE_OUT"
2198 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2199 eval track="\$TRACK$n"
2201 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2202 # When making a single-track rip, put the
2203 # actual file name into the file declaration
2204 # in the cue file so that it is usable by
2205 # music players and the like
2206 elif [ "$ONETRACK" = "y" ] &&
2207 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2209 TRACKFILE="$(mungefilename "$TRACKNAME")"
2210 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2211 ALBUMFILE="$(mungefilename "$DALBUM")"
2213 if [ "$VARIOUSARTISTS" = "y" ]; then
2214 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2216 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2219 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2222 # FIXME # If the lines above are uncommented, remove the line below.
2223 echo "$line" >> "$CUEFILE_OUT"
2226 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2227 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2233 # Parses a CDDB file and outputs the title and the track names.
2234 # Variables: CDDBFILE
2238 # List out disc title/author and contents
2239 if [ "$ONETRACK" = "y" ]; then
2240 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2242 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2243 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2244 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2245 if [ ! X"$PARSEDYEAR" = "X" ]; then
2246 echo "Year: $PARSEDYEAR"
2249 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2250 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2251 if [ ! X"$PARSEDGENRE" = "X" ]; then
2252 echo "Genre: $PARSEDGENRE"
2255 if [ ! "$ONETRACK" = "y" ]; then
2256 for TRACK in $(f_seq_row 1 $TRACKS)
2258 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2264 # Check for a local CDDB file, and report success
2267 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2269 CDDBLOCALSTATUS="notfound"
2270 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2273 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2274 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2275 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2276 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2277 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2278 CDDBLOCALMATCH=single
2279 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2280 CDDBLOCALMATCH=multiple
2285 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2286 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2287 CDDBLOCALMATCH=single
2292 # If the user has selected to check a local CDDB repo, we proceed with it
2293 case $CDDBLOCALMATCH in
2295 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2297 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2299 # List out disc title/author and contents
2300 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2301 cat "$RESULT" > "${CDDBLOCALREAD}"
2304 do_cddbparse "${CDDBLOCALREAD}"
2306 ##FIXME## QUICK HACK !!!!
2307 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2308 } >> "$ABCDETEMPDIR/cddblocalchoices"
2310 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2311 page "$ABCDETEMPDIR/cddblocalchoices"
2313 # It's all going to fit in one page, cat it
2314 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2316 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2317 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2318 CDDBLOCALCHOICENUM=-1
2319 if [ "$INTERACTIVE" = "y" ]; then
2320 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2321 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2322 read CDDBLOCALCHOICE
2323 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2324 # FIXME # Introduce diff's
2325 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2326 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2327 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2328 # Make sure we get a valid choice
2329 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2330 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2331 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2337 #echo "Selected ..."
2339 CDDBLOCALCHOICENUM=1
2341 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2342 #echo "Using local copy of CDDB data"
2343 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2344 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2345 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2346 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2347 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2348 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2349 CDDBLOCALSTATUS="found"
2351 #echo "Not using local copy of CDDB data"
2352 CDDBLOCALSTATUS="notfound"
2356 # List out disc title/author and contents
2357 do_cddbparse "${CDDBLOCALFILE}"
2358 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2359 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2361 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2363 if [ "$INTERACTIVE" = "y" ]; then
2365 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2366 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2369 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2373 if [ "$USELOCALRESP" = "y" ]; then
2374 #echo "Using local copy of CDDB data"
2375 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2376 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2377 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2378 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2379 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2380 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2381 CDDBLOCALSTATUS="single"
2383 #echo "Not using local copy of CDDB data"
2384 CDDBLOCALSTATUS="notfound"
2388 CDDBLOCALSTATUS="notfound"
2395 # Try to read CD-Text from the drive using icedax / cdda2wav
2398 if new_checkexec icedax; then
2399 CDTEXT_READER=icedax
2400 elif new_checkexec cdda2wav; then
2401 CDTEXT_READER=cdda2wav
2403 # Didn't find either, bail
2407 if [ "$OSFLAVOUR" = "OSX" ] ; then
2408 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2409 diskutil unmount ${CDROM#/dev/}
2410 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2411 CDDA2WAVCDROM="IODVDServices"
2412 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2413 CDDA2WAVCDROM="$CDROMID"
2415 if [ "$CDROMID" = "" ]; then
2416 CDDA2WAVCDROM="$CDROM"
2418 CDDA2WAVCDROM="$CDROMID"
2422 # Do we have CD-Text on the disc (and can the drive read it?)
2423 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2424 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2426 if [ $ERRORCODE -ne 0 ]; then
2427 # No CD-Text found, bail
2431 rm -f "$ABCDETEMPDIR/cddbchoices"
2433 # Make an empty template
2434 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2435 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2436 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2437 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2438 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2439 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2440 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2441 # List out disc title/author and contents
2442 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2443 for TRACK in $(f_seq_row 1 $TRACKS)
2445 TRACKM1=$(($TRACK - 1))
2446 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2447 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2448 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2449 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2451 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2452 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2453 echo >> "$ABCDETEMPDIR/cddbchoices"
2454 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2458 # Work with the musicbrainz WS API, then transform the results here so
2459 # they look (very) like the results from CDDB. Maybe not the best way
2460 # to go, but it Works For Me (TM)
2464 if checkstatus musicbrainz-readcomplete; then :; else
2465 vecho "Obtaining Musicbrainz results..."
2466 # If MB is to be used, interpret the query results and read all
2467 # the available entries.
2468 rm -f "$ABCDETEMPDIR/cddbchoices"
2469 CDDBCHOICES=1 # Overridden by multiple matches
2470 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2471 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2473 # The helper script will write disc matches out to
2474 # cddbread.*. Count how many we have
2475 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2476 # No matches. Use the normal cddb template for the user to
2478 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2479 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2480 # List out disc title/author and contents of template
2481 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2483 for TRACK in $(f_seq_row 1 $TRACKS)
2485 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2487 echo >> "$ABCDETEMPDIR/cddbchoices"
2488 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2489 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2490 echo 503 > "$ABCDETEMPDIR/cddbquery"
2492 # We have some matches
2493 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2494 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2496 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2497 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2498 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2499 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2500 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2501 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2502 # List out disc title/author and contents
2503 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2504 for TRACK in $(f_seq_row 1 $TRACKS)
2506 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2508 echo >> "$ABCDETEMPDIR/cddbchoices"
2510 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2511 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2512 for file in "$ABCDETEMPDIR"/cddbread.*
2514 X=$(echo $file | sed 's/^.*cddbread\.//g')
2515 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2516 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2517 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2518 # List out disc title/author and contents
2519 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2520 for TRACK in $(f_seq_row 1 $TRACKS)
2522 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2524 echo >> "$ABCDETEMPDIR/cddbchoices"
2526 echo "." >> "$ABCDETEMPDIR/cddbquery"
2529 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2536 # Perform CDDB protocol version check if it hasn't already been done
2537 if checkstatus cddb-statcomplete; then :; else
2538 if [ "$CDDBAVAIL" = "n" ]; then
2540 echo 503 > "$ABCDETEMPDIR/cddbstat"
2543 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2544 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2545 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2546 vecho "Checking CDDB server status..."
2547 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2548 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2549 case "$RESPONSECODE" in
2550 210) # 210 OK, status information follows (until terminating `.')
2553 501) # 501 Illegal CDDB protocol level: <n>.
2554 CDDBPROTO=`expr $CDDBPROTO - 1`
2556 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2557 # FreeDB TESTCD disc-id is used for query
2558 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2559 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2560 case "$RESPONSECODE" in
2561 2??) # Server responded, everything seems OK
2571 if test $rc -eq 1; then
2575 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2583 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2584 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2586 # Perform CDDB query if it hasn't already been done
2587 if checkstatus cddb-querycomplete; then :; else
2588 if [ "$CDDBAVAIL" = "n" ]; then
2590 echo 503 > "$ABCDETEMPDIR/cddbquery"
2591 # The default CDDBLOCALSTATUS is "notfound"
2592 # This part will be triggered if the user CDDB repo does not
2593 # contain the entry, or if we are not trying to use the repo.
2595 vecho "Querying the CDDB server..."
2596 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2597 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2598 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2604 # no match found in database,
2605 # wget/fetch error, or user requested not to use CDDB
2606 # Make up an error code (503) that abcde
2607 # will recognize in do_cddbread
2608 # and compensate by making a template
2609 echo 503 > "$ABCDETEMPDIR/cddbquery"
2611 *) # strange and unknown error
2612 echo ERRORCODE=$ERRORCODE
2613 echo "abcde: $CDDBTOOL returned unknown error code"
2617 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2624 # If it's not to be used, generate a template.
2625 # Then, display it (or them) and let the user choose/edit it
2626 if checkstatus cddb-readcomplete; then :; else
2627 vecho "Obtaining CDDB results..."
2628 # If CDDB is to be used, interpret the query results and read all
2629 # the available entries.
2630 rm -f "$ABCDETEMPDIR/cddbchoices"
2631 CDDBCHOICES=1 # Overridden by multiple matches
2632 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2633 case "$RESPONSECODE" in
2635 # One exact match, retrieve it
2636 # 200 [section] [discid] [artist] / [title]
2637 if checkstatus cddb-read-1-complete; then :; else
2638 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2639 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2640 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2641 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2642 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2644 # List out disc title/author and contents
2645 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2646 for TRACK in $(f_seq_row 1 $TRACKS)
2648 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2650 echo >> "$ABCDETEMPDIR/cddbchoices"
2654 case "$RESPONSECODE" in
2655 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2656 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2657 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2659 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2660 # List out disc title/author and contents of template
2661 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2663 for TRACK in $(f_seq_row 1 $TRACKS)
2665 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2667 echo >> "$ABCDETEMPDIR/cddbchoices"
2668 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2669 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2672 # Multiple exact, (possibly multiple) inexact matches
2674 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2675 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2676 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2677 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2678 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2680 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2682 vecho -n "Retrieving multiple matches... "
2683 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2684 read DISCINFO # eat top line
2688 if checkstatus cddb-read-$X-complete; then :; else
2689 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2690 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2692 # List out disc title/author and contents
2693 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2694 for TRACK in $(f_seq_row 1 $TRACKS)
2696 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2698 echo >> "$ABCDETEMPDIR/cddbchoices"
2701 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2705 for TRACK in $(f_seq_row 1 $TRACKS)
2707 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2709 echo >> "$ABCDETEMPDIR/cddbchoices"
2710 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2711 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2714 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2721 if checkstatus cddb-edit >/dev/null; then
2722 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2723 VARIOUSARTISTS="$(checkstatus variousartists)"
2724 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2727 if [ "$INTERACTIVE" = "y" ]; then
2728 # We should show the CDDB results both when we are not using the local CDDB repo
2729 # or when we are using it but we could not find a proper match
2730 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2731 # Display the $ABCDETEMPDIR/cddbchoices file created above
2732 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2733 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2734 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2735 CHOICE=$(checkstatus cddb-choice)
2736 if [ -n "$CHOICE" ] ; then
2737 case $CDDBCHOICES in
2738 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2739 log error "CDDB query failed!"
2742 cat "$ABCDETEMPDIR/cddbchoices"
2745 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2747 echo "Selected: #$CHOICE"
2748 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2752 # The user has a choice to make, display the info in a pager if necessary
2753 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2754 page "$ABCDETEMPDIR/cddbchoices"
2756 # It's all going to fit in one page, cat it
2757 cat "$ABCDETEMPDIR/cddbchoices" >&2
2761 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2763 # I'll take CDDB read #3 for $400, Alex
2764 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2765 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2767 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2768 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2769 if [ ! X"$DIFF" = "X" ]; then
2770 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2771 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2772 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2773 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2774 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2775 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2777 # We parse the 2 choices to diff, store them in temporary files and diff them.
2778 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2779 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2781 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2782 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2783 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2784 page "$ABCDETEMPDIR/cddbread.diff"
2786 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2790 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2792 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2793 # Make sure we get a valid choice
2794 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2795 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2796 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2800 if [ "$CDCHOICENUM" = "0" ]; then
2801 vecho "Creating empty CDDB template..."
2803 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2805 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2806 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2808 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2812 # We need some code to show the selected option when local repository is selected and we have found a match
2813 vecho "Using cached CDDB match..." >&2
2814 # Display the $ABCDETEMPDIR/cddbchoices file created above
2815 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2816 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2817 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2818 CHOICE=$(checkstatus cddb-choice)
2819 if [ "$USELOCALRESP" = "y" ]; then :; else
2820 if [ -n "$CHOICE" ] ; then
2821 case $CDDBCHOICES in
2824 echo "Selected template."
2826 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2828 echo "Selected: #$CHOICE"
2829 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2837 # We're noninteractive - pick the first choice.
2838 # But in case we run a previous instance and selected a choice, use it.
2839 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2840 # Show the choice if we are not using the locally stored one
2841 # or when the local search failed to find a match.
2842 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2843 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2844 #if [ "$PREVIOUSCHOICE" ]; then
2845 cat "$ABCDETEMPDIR/cddbchoices"
2848 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2849 CDCHOICENUM=$PREVIOUSCHOICE
2852 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2854 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2859 if checkstatus cddb-choice >/dev/null; then :; else
2860 echo "abcde: internal error: cddb-choice not recorded." >&2
2863 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2864 echo -n "Edit selected CDDB data " >&2
2865 if [ "$INTERACTIVE" = "y" ]; then
2866 if [ "$UNKNOWNDISK" = "y" ]; then
2867 echo -n "[Y/n]? " >&2
2869 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2871 echo -n "[y/N]? " >&2
2878 if [ "$EDITCDDB" = "y" ]; then
2879 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2881 # Use the debian sensible-editor wrapper to pick the editor that the
2882 # user has requested via their $EDITOR environment variable
2883 if [ -x "/usr/bin/sensible-editor" ]; then
2884 /usr/bin/sensible-editor "$CDDBDATA"
2885 elif [ -n "$EDITOR" ]; then
2886 if [ -x $(which "${EDITOR%%\ *}") ]; then
2887 # That failed, try to load the preferred editor, starting
2888 # with their EDITOR variable
2889 eval $(echo "$EDITOR") \"$CDDBDATA\"
2891 # If that fails, check for a vi
2892 elif which vi >/dev/null 2>&1; then
2894 elif [ -x /usr/bin/vim ]; then
2895 /usr/bin/vim "$CDDBDATA"
2896 elif [ -x /usr/bin/vi ]; then
2897 /usr/bin/vi "$CDDBDATA"
2898 elif [ -x /bin/vi ]; then
2900 # nano should be on all (modern, i.e., sarge) debian systems
2901 elif which nano >/dev/null 2>&1 ; then
2903 elif [ -x /usr/bin/nano ]; then
2904 /usr/bin/nano "$CDDBDATA"
2905 # mg should be on all OpenBSD systems
2906 elif which mg >/dev/null 2>&1 ; then
2908 elif [ -x /usr/bin/mg ]; then
2909 /usr/bin/mg "$CDDBDATA"
2912 log warning "no editor available. Check your EDITOR environment variable."
2914 # delete editor backup file if it exists
2915 if [ -w "$CDDBDATA~" ]; then
2920 # Some heuristics first. Look at Disc Title, and if it starts with
2921 # "Various", then we'll assume Various Artists
2922 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2923 echo "Looks like a Multi-Artist CD" >&2
2926 echo -n "Is the CD multi-artist [y/N]? " >&2
2927 if [ "$INTERACTIVE" = "y" ]; then
2934 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2937 # Need NUMTRACKS before cddb-tool will return it:
2938 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2939 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2940 # More than 1/2 tracks contain a "/", so guess forward
2942 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2943 # More than 1/2 contain a "-", so guess forward-dash
2945 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2946 # More than 1/2 contain something in parens, so guess trailing-paren
2950 echo "1) Artist / Title" >&2
2951 echo "2) Artist - Title" >&2
2952 echo "3) Title / Artist" >&2
2953 echo "4) Title - Artist" >&2
2954 echo "5) Artist: Title" >&2
2955 echo "6) Title (Artist)" >&2
2956 echo "7) This is a single-artist CD" >&2
2957 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2958 if [ "$INTERACTIVE" = "y" ]; then
2959 read VARIOUSARTISTSTYLE
2961 echo $DEFAULTSTYLE >&2
2962 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2964 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2965 # If they press Enter, then the default style (0) was chosen
2966 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2967 echo "Invalid selection. Please choose a number between 1 and 7."
2968 echo -n "Selection [1-7]: "
2969 read VARIOUSARTISTSTYLE
2970 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2972 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2973 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2975 vecho "Selected: $VARIOUSARTISTSTYLE"
2976 case "$VARIOUSARTISTSTYLE" in
2978 VARIOUSARTISTSTYLE=forward
2981 VARIOUSARTISTSTYLE=forward-dash
2984 VARIOUSARTISTSTYLE=reverse
2987 VARIOUSARTISTSTYLE=reverse-dash
2990 VARIOUSARTISTSTYLE=colon
2993 VARIOUSARTISTSTYLE=trailing-paren
3001 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
3002 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
3004 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3005 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3006 # This works but does not have the necessary error checking
3007 # yet. If you are familiar with the CDDB spec
3008 # (see http://www.freedb.org/src/latest/DBFORMAT)
3009 # and can create an error-free entry on your own, then put
3010 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3011 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3012 # your abcde.conf to change the email address submissions are
3015 # submit the modified file, if they want
3016 if [ "$NOSUBMIT" != "y" ]; then
3017 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3019 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3020 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3022 echo -n 'Invalid selection. Please answer "y" or "n": '
3025 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3026 echo -n "Sending..."
3027 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
3034 # User CDDBLOCALPOLICY to find out if we store the file or not...
3035 # Cache edited CDDB entry in the user's cddb dir
3036 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3037 # Make sure the cache directory exists
3038 mkdir -p $CDDBLOCALDIR
3039 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
3042 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
3046 # try to download CD cover
3050 ALBUMFILE="$(mungefilename "$DALBUM")"
3051 ARTISTFILE="$(mungefilename "$DARTIST")"
3052 # have we got a musicbrainz mbid or amazon asin?
3053 case "$CDDBMETHOD" in
3055 # try musicbrainz mbid
3056 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
3057 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
3058 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3059 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3060 vecho "cover URL: $ALBUMARTURL" >&2
3061 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3062 if [ $? -ne 0 ]; then
3063 vecho "could not download cover from musicbrainz" >&2
3065 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3066 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3067 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3068 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3069 vecho "cover URL: $ALBUMARTURL" >&2
3070 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3071 if [ $? -ne 0 ]; then
3072 vecho "could not download cover from amazon" >&2
3074 # Check that size is reasonable; sometimes when there is no cover image
3075 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3076 FILESIZE=$(wc -c < "$ABCDETEMPDIR/$ALBUMARTFILE")
3077 if [ "$FILESIZE" -lt 1024 ]; then
3078 rm "$ABCDETEMPDIR/$ALBUMARTFILE"
3079 vecho "could not download cover from amazon" >&2
3083 vecho "no amazon ID found" >&2
3087 vecho "no musicbrainz ID found" >&2
3092 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3093 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3094 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3095 if [ $? -ne 0 ]; then
3096 vecho "could not download cover with glyrc" >&2
3101 if [ "$INTERACTIVE" = "y" ]; then
3102 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3103 # display properties of coverart when identify is available
3104 if new_checkexec $IDENTIFY; then
3105 $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
3107 # display coverart when DISPLAY is set and display command is available
3108 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3109 $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
3112 # nothing downloaded yet
3113 vecho "automatic album art downloading failed" >&2
3115 # see if the user can find a better album art manually
3116 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3118 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3119 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3121 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3124 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3125 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3127 if [ ! -z "$ALBUMARTURL" ]; then
3128 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3129 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3130 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3131 vecho "unable to download $ALBUMARTURL" >&2
3133 else # it's a local path
3134 cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
3135 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3136 vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
3142 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3143 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3144 ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
3145 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3146 if new_checkexec $CONVERT; then
3147 mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3148 $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
3149 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3151 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3152 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3156 # copy to target directories
3157 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3158 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3160 # put cover in the same place as the album
3161 if [ "$VARIOUSARTISTS" = "y" ] ; then
3162 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3164 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3166 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3167 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3168 mkdir -p "$FINALALBUMARTDIR"
3169 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3171 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3172 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3174 log warning "could not get cover"
3175 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3179 # do_cdread [tracknumber]
3180 # do_cdread onetrack [firsttrack] [lasttrack]
3184 # The commands here don't go through run_command because they're never supposed to be silenced
3185 # return codes need to be doublechecked anyway, however
3186 if [ "$1" = "onetrack" ]; then
3187 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3188 # FIXME # Until then, we grab the whole CD in one track, no matter what
3190 # We need the first and last track for cdda2wav/icedax
3192 LASTTRACK=$(expr $3 + 0)
3193 UTRACKNUM=$FIRSTTRACK
3194 case "$CDROMREADERSYNTAX" in
3195 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
3198 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
3199 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
3200 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3201 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3202 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3208 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3209 if [ "$USEPIPES" = "y" ]; then
3210 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3211 FILEARG="$( eval echo "\$$TEMPARG" )"
3213 PIPE_MESSAGE="and encoding "
3215 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3216 case "$CDROMREADERSYNTAX" in
3217 ## FIXME ## Find the cases for flac, to avoid exceptions
3219 FILEARG="--output-name=$WAVDATA"
3227 if [ "$1" = "onetrack" ]; then
3228 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3230 if [ -r "$CDDBDATA" ]; then
3231 getcddbinfo TRACKNAME
3232 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3234 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3237 case "$CDROMREADERSYNTAX" in
3238 ### FIXME ### use an exception for flac, since it uses -o
3239 ### FIXME ### Shall we just use -o $FILEARG ??
3241 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3242 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3243 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3245 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3247 if [ "$OSFLAVOUR" = "OSX" ] ; then
3248 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3249 diskutil unmount ${CDROM#/dev/}
3250 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3251 CDDA2WAVCDROM="IODVDServices"
3252 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3253 CDDA2WAVCDROM="$CDROMID"
3255 if [ "$CDROMID" = "" ]; then
3256 CDDA2WAVCDROM="$CDROM"
3258 CDDA2WAVCDROM="$CDROMID"
3261 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3262 dagrab) nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2 ;;
3264 if [ "$USEPIPES" = "y" ]; then
3265 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3267 # Write ripped audio data to stdout and redirect to $FILEARG.
3268 # $REDIR can be ignored. Progress is written to stderr by default.
3269 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3273 # Find the track's mounted path
3274 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3275 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3276 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3277 # If the file exists, copy it
3278 if [ -e "$FILEPATH" ] ; then
3279 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
3283 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" $REDIR ;;
3286 # If we get some error or we get some missing wav
3287 # (as long as we dont use pipes)
3288 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3289 # Thank goodness errors is only machine-parseable up to the
3290 # first colon, otherwise this woulda sucked
3291 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3292 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3294 if [ "$USEPIPES" = "y" ]; then
3295 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3297 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3301 if [ "$USEPIPES" = "y" ]; then
3302 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3304 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3306 if [ "$1" = "onetrack" ]; then
3307 echo onetrack >> "$ABCDETEMPDIR/status"
3313 # No values accepted, only uses env variables
3316 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3317 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3319 echo "abcde: unable to set the device speed" >&2
3325 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3328 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3330 warning) shift ; log warning "$@" ;;
3338 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3341 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3343 warning) shift ; log warning "$@" ;;
3351 # decho outputs a debug message if DEBUG is selected
3354 if [ x"$DEBUG" != "x" ]; then
3355 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3356 DEBUGECHO=$(echo "$@" | tr -d '[]')
3357 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3359 echo >&4 "[DEBUG] $1"
3364 # User-redefinable functions
3365 # Custom filename munging:
3368 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3371 # Custom genre munging:
3374 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3378 # Empty pre_read function, to be defined in the configuration file.
3385 # Empty post_read function, to be defined in the configuration file.
3392 # Empty post_encode function, to be defined in the configuration file.
3398 ###############################################################################
3401 # Start of execution
3402 ###############################################################################
3407 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3409 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3410 CDDBSUBMIT=freedb-submit@freedb.org
3412 HELLOINFO="$(whoami)@$(hostname)"
3414 CDDBLOCALPOLICY="always"
3415 CDDBLOCALRECURSIVE="y"
3416 CDDBLOCALDIR="$HOME/.cddb"
3419 # List of fields we parse and show during the CDDB parsing...
3420 SHOWCDDBFIELDS="year,genre"
3423 #CDROMREADERSYNTAX=cdparanoia
3424 ENCODERSYNTAX=default
3426 MP3ENCODERSYNTAX=default
3427 OGGENCODERSYNTAX=default
3428 OPUSENCODERSYNTAX=default
3429 FLACENCODERSYNTAX=default
3430 SPEEXENCODERSYNTAX=default
3431 MPCENCODERSYNTAX=default
3432 WVENCODERSYNTAX=default
3433 APENCODERSYNTAX=default
3434 MP2ENCODERSYNTAX=default
3435 AACENCODERSYNTAX=default
3436 NORMALIZERSYNTAX=default
3437 CUEREADERSYNTAX=default
3439 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3440 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3441 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3442 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3443 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3444 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3445 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3446 PLAYLISTDATAPREFIX=''
3447 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3448 VAPLAYLISTDATAPREFIX=''
3456 VARIOUSARTISTSTYLE=forward
3463 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3464 # i.e. CDROMID="1,0,0"
3466 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3467 # If we are using the ide-scsi emulation layer, we need to define a "g"
3468 CDPARANOIACDROMBUS="d"
3470 # program paths - defaults to checking your $PATH
3476 XINGMP3ENC=xingmp3enc
3490 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3501 NEROAACENC=neroAacEnc
3503 # Note that the qaac PATH will almost always require adjustment
3504 # as it is a Windows application being run through Wine. More
3505 # detailed notes in the sample abcde.conf file in the abcde tarball.
3508 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3515 VORBISCOMMENT=vorbiscomment
3517 NEROAACTAG=neroAacTag
3518 ATOMICPARSLEY=AtomicParsley
3521 CDPARANOIA=cdparanoia
3522 CD_PARANOIA=cd-paranoia
3529 MUSICBRAINZ=abcde-musicbrainz-tool
3533 NORMALIZE=normalize-audio
3535 VORBISGAIN=vorbisgain
3539 # For Wavpack replay gain we set both the default of 'track gain'
3540 # as well as this option for 'album gain'. Better media players
3541 # such as vlc can select either or neither. Andrew.
3552 # Options for programs called from abcde
3564 VORBISGAINOPTS="--album"
3568 # The flac option is a workaround for an error where flac fails
3569 # to encode with error 'floating point exception'. This is flac
3570 # error in get_console_width(), corrected in flac 1.3.1
3572 FLACGAINOPTS="--add-replay-gain"
3580 # Monkey's Audio Console (mac) chokes without a mode setting
3581 # so we set one here.
3588 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3589 # we set bitrate here.
3590 FDKAACENCOPTS='--bitrate 192k'
3611 VORBISCOMMENTOPTS="-R"
3612 METAFLACOPTS="--no-utf8-convert"
3617 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3619 # Defaults for album art downloads
3620 ALBUMARTFILE="cover.jpg"
3622 ALBUMARTALWAYSCONVERT="n"
3624 # Default to one process if -j isn't specified
3627 # List of actions to perform - by default, run to completion
3628 ACTIONS=cddb,read,encode,tag,move,clean
3630 # This option is basically for Debian package dependencies:
3631 # List of preferred outputs - by default, run with whatever we have in the path
3632 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
3634 # List of preferred cdromreaders - by default, run whichever we have in the path
3635 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3637 # fd for when `vecho` and `log info` called with redirected stdout
3640 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3641 # Linux/OpenBSD. ftp is user for NetBSD.
3642 # Let's use these checkings to determine the OS flavour, which will be used
3644 if [ X$(uname) = "XFreeBSD" ] ; then
3649 elif [ X$(uname) = "XDarwin" ] ; then
3652 # We should have diskutil in OSX, but let's be sure...
3654 CDROMREADERSYNTAX=cddafs
3655 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3657 elif [ X$(uname) = "XOpenBSD" ] ; then
3661 elif [ X$(uname) = "XNetBSD" ] ; then
3665 elif [ X$(uname) = "SunOS" ] ; then
3673 # If CDDBAVAIL is set to n, no CDDB read is done
3677 # But before we get into business, let us chop off any GREP environmental
3682 if [ -z "$OUTPUTDIR" ]; then
3686 if [ -z "$WAVOUTPUTDIR" ]; then
3687 WAVOUTPUTDIR="$OUTPUTDIR"
3690 # Load system defaults
3691 if [ -r /etc/abcde.conf ]; then
3694 # Load user preference defaults
3695 if [ -r $HOME/.abcde.conf ]; then
3699 # By this time, we need some HTTPGETOPTS already defined.
3700 # If the user has defined a non-default HTTPGET method, we should not be empty.
3702 if [ "$HTTPGETOPTS" = "" ] ; then
3704 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3705 curl) HTTPGETOPTS="-f -s";;
3706 fetch)HTTPGETOPTS="-q -o -";;
3707 ftp) HTTPGETOPTS="-a -V -o - ";;
3708 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3712 # If the CDROM has not been set yet, find a suitable one.
3713 # If this is a devfs system, default to /dev/cdroms/cdrom0
3714 # instead of /dev/cdrom
3715 if [ "$CDROM" = "" ] ; then
3716 if [ -e /dev/cdroms/cdrom0 ]; then
3717 CDROM=/dev/cdroms/cdrom0
3718 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3719 CDROM=/dev/${BASH_REMATCH[1]}
3720 elif [ -e /dev/cdrom ]; then
3722 elif [ -e /dev/sr0 ]; then
3724 elif [ -e /dev/cd0c ]; then
3726 elif [ -e /dev/acd0c ]; then
3728 elif [ -e /dev/disk1 ]; then
3733 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3734 # that's changed to a number to allow for more control. Deal with
3735 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3736 case "$EXTRAVERBOSE" in
3745 # Parse command line options
3746 while getopts 1a:bc:C:d:DefgGhj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3749 a) ACTIONS="$OPTARG" ;;
3750 A) EXPACTIONS="$OPTARG" ;;
3752 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3753 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3754 d) CDROM="$OPTARG" ;;
3757 e) ERASEENCODEDSTATUS=y ;;
3758 E) ENCODING="$OPTARG" ;;
3763 j) MAXPROCS="$OPTARG" ;;
3766 L) CDDBUSELOCAL=y ;;
3771 o) OUTPUTTYPE="$OPTARG" ;;
3774 r) REMOTEHOSTS="$OPTARG" ;;
3775 R) CDDBLOCALRECURSIVE=y ;;
3776 s) SHOWCDDBFIELDS="$OPTARG" ;;
3777 S) CDSPEEDVALUE="$OPTARG" ;;
3778 t) STARTTRACKNUMBER="$OPTARG" ;;
3779 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3782 echo "This is abcde v$VERSION."
3783 echo "Usage: abcde [options] [tracks]"
3784 echo "abcde -h for extra help"
3787 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3789 X) CUE2DISCID="$OPTARG" ;;
3790 w) COMMENT="$OPTARG" ;;
3791 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3792 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
3793 STARTTRACKNUMBERTAG="y"
3794 COMMENT="CD${OPTARG}"
3795 DISCNUMBER="${OPTARG}"
3797 log error "argument of -W must be integer"
3801 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3806 shift $(($OPTIND - 1))
3808 # Here it comes the worse part of the whole thing. From here until we start
3809 # ripping, we have a mixture of sanity checks, verifications, default settigs
3810 # and other crazy stuff that interdepends, but hey, someone has to do it.
3812 # If NOCDDBQUERY is set, don't query the CDDB server.
3813 if [ "$NOCDDBQUERY" = "y" ]; then
3817 # If the user specified a flac file, then switch to special flac mode
3818 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3819 if [ ! -f "$CDROM" ]; then
3820 log error "the defined file for FLAC ripping cannot be found" >&2
3823 vecho warning "switching to flac CDROMREADERSYNTAX..."
3824 CDROMREADERSYNTAX=flac
3825 # We have a builtin version of cue2discid...
3826 case "$CUE2DISCID" in
3828 *) NEEDCUE2DISCID=y;;
3834 # If the user provided a DISCID, disable eject
3835 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3837 # Check the available cd rippers in the system, from the ones we know.
3838 if [ "$CDROMREADERSYNTAX" = "" ]; then
3839 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3840 if new_checkexec $DEFAULT_CDROMREADER; then
3841 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3845 if [ "$CDROMREADERSYNTAX" = "" ]; then
3846 log error "no cdreader found in your PATH"
3847 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3852 # Decide if we can continue.
3853 if [ "$ONETRACK" = "y" ]; then
3854 # FIXME # remove check as soon as we find out about the other readers
3855 case "$CDROMREADERSYNTAX" in
3857 cdparanoia | libcdio) ;;
3858 cdda2wav | icedax) ;;
3860 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3863 if [ "$BATCHNORM" = "y" ]; then
3864 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3867 if [ "$NOGAP" = "y" ]; then
3868 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3871 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3872 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3873 if [ $# -gt 0 ]; then
3874 log warning "ONETRACK mode selected, grabbing all tracks..."
3877 while [ $# -gt 0 ]; do
3878 # Range parsing code courtesy of Vincent Ho
3879 # Cleaned up to use shell built-ins by Charles Steinkuehler
3880 if [ "${1#*[^0-9-]}" != "$1" ]; then
3881 log error "syntax error while processing track numbers ($1)"
3886 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3887 TRACKQUEUE="$TRACKQUEUE $RSTART"
3888 RSTART=$(( $RSTART + 1 ))
3895 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3896 # List of experimental actions: retag,transcode
3898 # Determine what actions are to be done from $ACTIONS and set the
3899 # following environment variables for them:
3911 ## FIXME ## Lets keep compatibility with -M
3912 [ "$DOCUE" != "y" ] && DOCUE=n
3914 for ACTION in $(echo $ACTIONS | tr , \ )
3917 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
3918 cue) DOCUE=y ; MAKECUEFILE=y ;;
3921 normalize) DONORMALIZE=y; DOREAD=y;;
3922 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3923 encode) DOENCODE=y; DOREAD=y;;
3924 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3925 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3926 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3927 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
3928 playlist) DOCDDB=y; DOPLAYLIST=y;;
3930 getalbumart) GETALBUMART=y;;
3934 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3935 # FIXME # should we abort on error or just inform the user?
3936 log warning "selected both normalize and replaygain actions"
3939 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
3940 case $SHOWCDDBFIELD in
3941 y*|Y*) SHOWCDDBYEAR="y";;
3942 g*|G*) SHOWCDDBGENRE="y";;
3947 # At this point a CDROM has to be defined, so we check it exists.
3948 if [ X"$CDROM" != "X" ] ; then
3949 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
3950 if [ "$OSFLAVOUR" = "FBSD" ]; then
3951 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
3952 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
3953 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
3957 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
3958 log error "CDROM device cannot be found."
3961 # avoid processing if we are not going to hit the CDROM.
3962 elif [ X"$DOREAD" = "Xy" ]; then
3963 log error "CDROM has not been defined or cannot be found"
3967 # USEPIPES pre-tests, before we get into more serious stuff
3968 # Not compatible with:
3969 # - multiple outputs
3971 # - lowdisk algorithm
3973 if [ X"$USEPIPES" = "Xy" ]; then
3974 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
3975 log error "Unix pipes not compatible with multiple outputs"
3978 if [ X"$DONORMALIZE" = "Xy" ]; then
3979 log error "Unix pipes not compatible with normalizer"
3980 # FIXME # Do we need to exit or shall we just disable the mode?
3983 if [ X"$BATCHNORM" = "Xy" ]; then
3984 log error "Unix pipes not compatible with BATCHNORM encoding"
3987 if [ X"$NOGAP" = "Xy" ]; then
3988 log error "Unix pipes not compatible with NOGAP encoding"
3991 if [ X"$DOENCODE" = "Xn" ]; then
3992 vecho warning "Disabling Unix pipes since we are not encoding!"
3995 if [ X"$LOWDISK" = "Xy" ]; then
3996 log error "Unix pipes not compatible with lowdisk algorithm"
4001 # LOWDISK pre-tests, before we get into more problematic stuff
4002 # Not compatible with anything that needs all the files in the hard disc:
4005 if [ X"$LOWDISK" = "Xy" ]; then
4006 if [ X"$BATCHNORM" = "Xy" ]; then
4007 log error "Unix pipes not compatible with BATCHNORM encoding"
4010 if [ X"$NOGAP" = "Xy" ]; then
4011 log error "Unix pipes not compatible with NOGAP encoding"
4016 # BATCHNORM pre-tests, before we get into serious problems
4017 # Not compatible with
4018 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4019 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4023 # Check the encoding format from the ones available in the system, if nothing has been configured.
4024 if [ X"$OUTPUTTYPE" = "X" ]; then
4025 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4026 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
4027 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
4028 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
4029 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4030 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4034 if [ X"$OUTPUTTYPE" = "X" ]; then
4035 log error "no encoder found in the PATH"
4036 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4041 # Decide which CDROM reader we're gonna use
4042 case "$CDROMREADERSYNTAX" in
4044 CDROMREADER="$CDPARANOIA"
4045 CDROMREADEROPTS="$CDPARANOIAOPTS"
4048 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4049 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4050 CDROMREADER="$CD_PARANOIA"
4051 CDROMREADEROPTS="$CDPARANOIAOPTS"
4054 CDROMREADER="$CDDA2WAV"
4055 CDROMREADEROPTS="$CDDA2WAVOPTS"
4058 CDROMREADER="$DAGRAB"
4059 CDROMREADEROPTS="$DAGRABOPTS"
4063 CDROMREADEROPTS="$PIRDOPTS"
4066 CDROMREADER="$CDDAFS"
4067 CDROMREADEROPTS="$CDDAFSOPTS"
4071 CDROMREADEROPTS="$FLACOPTS"
4075 # There's only one normalize...
4076 case "$NORMALIZERSYNTAX" in
4078 NORMALIZER="$NORMALIZE"
4079 NORMALIZEROPTS="$NORMALIZEOPTS"
4083 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4084 case "$OUTPUTTYPE" in *:*)
4085 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4086 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4088 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4089 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4090 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4091 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4092 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4093 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4094 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4095 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4096 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4097 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4100 # Allows commandline selection of options while using multiple outputs.
4101 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4102 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4103 TEMPOUTPUT=${OUTPUT%%:*}
4104 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4106 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4110 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4111 # for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as and
4112 # wavpack for wvs...
4114 # Getting ready for multiple output changes
4115 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4119 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4120 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4121 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4122 OGGOUTPUTCONTAINER=ogg
4125 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4126 OPUSOUTPUTCONTAINER=opus
4129 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4130 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4131 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4134 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4135 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4136 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4137 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4140 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4141 # [ "$DOREPLAYGAIN" = "y" ] &&
4144 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4145 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4148 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4150 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4151 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4154 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4155 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4158 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4159 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4160 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4163 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4165 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4166 # compiled without libmp4v2... Andrew.
4169 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4170 [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4171 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4172 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4173 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4174 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4177 if [ "$KEEPWAVS" = "y" ]; then
4178 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4182 *) log error "Invalid OUTPUTTYPE defined"
4188 # decide which encoder
4189 case "$MP3ENCODERSYNTAX" in
4191 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4195 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4199 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4200 MP3ENCODER="$BLADEENC"
4203 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4207 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4208 MP3ENCODER="$XINGMP3ENC"
4211 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4212 MP3ENCODER="$MP3ENC"
4215 case "$OGGENCODERSYNTAX" in
4217 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4218 OGGENCODER="$VORBIZE"
4221 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4222 OGGENCODER="$OGGENC"
4225 case "$OPUSENCODERSYNTAX" in
4227 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4228 OPUSENCODER="$OPUSENC"
4231 case "$FLACENCODERSYNTAX" in
4233 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4235 if [ "$DOREPLAYGAIN" = "y" ]; then
4236 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4238 # FLAC streams can be encapsulated on a Ogg transport layer
4239 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4240 log error "FLAC on an Ogg container is not yet supported"
4241 log error "due to problem with adding comments to such files"
4243 FLACOUTPUTCONTAINER=ogg
4245 FLACOUTPUTCONTAINER=flac
4249 case "$SPEEXENCODERSYNTAX" in
4251 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4252 SPEEXENCODER="$SPEEXENC"
4255 case "$MPCENCODERSYNTAX" in
4257 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4258 MPCENCODER="$MPCENC"
4261 case "$WVENCODERSYNTAX" in
4263 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4264 # and in the interests of backward compatibility:
4265 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4266 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4267 WVENCODER="$WAVPACK"
4269 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4270 WVENCODER="$WAVPACK"
4274 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4278 case "$APENCODERSYNTAX" in
4280 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4284 case "$MP2ENCODERSYNTAX" in
4286 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4287 MP2ENCODER="$TWOLAME"
4290 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4291 MP2ENCODER="$FFMPEG"
4294 case "$AACENCODERSYNTAX" in
4295 # Some elaborate 'if' work to keep backward compatibility for those
4296 # who don't realise that AACENCOPTS does not work with abcde from
4297 # version 2.7 onwards.
4299 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4300 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4303 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4308 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4309 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4310 AACENCODER="$NEROAACENC"
4312 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4313 AACENCODER="$NEROAACENC"
4317 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4318 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4319 AACENCODER="$FDKAAC"
4321 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4322 AACENCODER="$FDKAAC"
4326 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4327 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4330 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4335 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4336 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4337 AACENCODER="$FHGAACENC"
4339 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4340 AACENCODER="$FHGAACENC"
4344 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4345 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4346 AACENCODER="$FFMPEG"
4348 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4349 AACENCODER="$FFMPEG"
4359 TAGGEROPTS="$ID3OPTS"
4364 TAGGEROPTS="$ID3V2OPTS"
4368 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4369 # trouble with CDDBPROTO=5 (which we test here) but also
4370 # with cached cddb files in latin1 (which we cannot test).
4371 if [ "$CDDBPROTO" -lt 6 ]; then
4372 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4375 # eyeD3 version 0.7 changed syntax
4376 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4377 # only if it offers the --set-encoding, assume <= 0.6.x
4379 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4381 # anything wrong, any failure, assume >= 0.7
4383 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4387 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4392 # NOGAP is specific to lame. Other encoders fail ...
4393 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4394 log warning "the NOGAP option is specific to lame. Deactivating..."
4399 case "$CUEREADERSYNTAX" in
4401 CUEREADEROPTS="${CDROM}"
4406 # which information retrieval tool are we using?
4412 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4413 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4414 log error "FLAC on an Ogg container is not yet supported"
4415 log error "due to problem with adding comments to such files"
4417 OGGOUTPUTCONTAINER=ogg.ogg
4418 FLACOUTPUTCONTAINER=flac.ogg
4419 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4422 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4424 if [ "$ENCNICE" ]; then
4425 ENCNICE="-n $ENCNICE"
4427 if [ "$READNICE" ]; then
4428 READNICE="-n $READNICE"
4430 if [ "$DISTMP3NICE" ]; then
4431 DISTMP3NICE="-n $DISTMP3NICE"
4434 # Don't check for stuff if it's not needed
4435 if [ "$REMOTEHOSTS" ]; then
4438 if [ "$DONORMALIZE" = "y" ]; then
4441 if [ "$EJECTCD" = "y" ]; then
4444 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4445 if [ "$CDDBMETHOD" = "cddb" ]; then
4447 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4451 if [ "$DOCUE" = "y" ]; then
4455 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4456 case "$CDROMREADERSYNTAX" in
4457 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4458 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4459 ### FIXME ### translate "cue2discid" from python to bash
4460 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4465 if [ "$GETALBUMART" = "y" ]; then
4470 ###USEPIPESSUPPORT###
4472 # Rippers with USEPIPE support
4473 PIPERIPPER_cdparanoia="-"
4474 PIPERIPPER_libcdio="-"
4475 # Note that by default in abcde cdda2wav redirects to icedax.
4476 PIPERIPPER_cdda2wav="-"
4477 PIPERIPPER_debug="-"
4478 PIPERIPPER_flac="-c "
4481 # Encoders with USEPIPE support
4484 PIPE_bladeenc="stdin"
4495 # Both neroAacEnc and fdkaac seem to manage without the addition of
4496 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4497 # in this manner. Andrew.
4501 # Figure out if we can use pipes with the ripper/encoder combination
4503 if [ "$USEPIPES" = "y" ]; then
4504 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4507 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4509 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4511 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4513 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4515 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4517 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4519 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4521 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4523 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4525 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4526 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4527 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4528 log error "no support for pipes with given ripper"
4529 log error "read the FAQ file from the source tarball to get help."
4532 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4533 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4534 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4535 log error "no support for pipes with given encoder"
4536 log error "read the FAQ file from the source tarball to get help"
4541 # Make sure a buncha things exist
4542 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4543 $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4544 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER \
4545 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4546 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4547 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4548 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4549 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4550 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4551 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4552 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4553 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4554 ${NEEDMID3V2+$MID3V2}
4559 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4560 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4561 # these files). The resulting files are actually ADTS streams which belong in an
4562 # aac container and with some version sniffing this is all cleaned up below. If
4563 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4565 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4566 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4567 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4568 echo "WARNING: Your copy of Faac does not have mp4 support"
4569 echo "WARNING: Encoding untagged files to aac..."
4572 echo "Using Faac to Tag AAC Tracks..."
4576 # And last but not least, check if we can diff between files. We do not abort,
4577 # since diffing is not critical...
4578 if [ -x $(which $DIFF) ]; then :; else
4579 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4583 ## Now that we have metaflac, check if we need cue2discid
4584 #case $CDROMREADERSYNTAX in
4586 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4587 # if [ "$TRACKINFO" = "" ]; then
4588 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4593 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4594 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4595 HTTPGET="$HTTPGET $HTTPGETOPTS"
4597 # Here it used to say:
4598 # One thousand lines in, we can start doing stuff with things
4599 # Well, right now we are at line 3737 ;)
4601 # Export needed things so they can be read in this subshell
4602 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4603 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4605 if [ "$DOREAD" = "y" ]; then
4606 # User-definable function to set some things. Use it for
4607 # - closing the CD tray with eject -t
4608 # - set the CD speed value with eject -x
4609 vecho -n "Executing customizable pre-read function... "
4611 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4616 # Get ABCDETEMPDIR created and status file initialized
4619 if [ "$DOCDDB" = "y" ]; then
4620 # start with a sane default:
4621 CDDBLOCALSTATUS=notfound
4622 if [ $CDDBUSELOCAL = "y" ]; then
4625 if checkstatus cddb-choice > /dev/null; then
4628 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4629 case "$CDDBMETHOD" in
4640 CHOICE=$(checkstatus cddb-choice)
4641 if [ "$CHOICE" = 0 ] ; then
4642 # We don't have any information at all; try to fall back
4643 # to CD-Text for basic information
4644 vecho "No CDDB information found, trying cdtext from the CD"
4650 eval "$($CDDBTOOL parse "$CDDBDATA")"
4653 # Before reading tracks, we set the speed of the device
4655 if [ X"$CDSPEEDVALUE" != "X" ]; then
4656 case "$CDROMREADERSYNTAX" in
4657 cdparanoia|libcdio|debug) ;;
4664 # Define the first and last track, since we might need them later in several places
4665 FIRSTTRACK=$( get_first $TRACKQUEUE )
4666 LASTTRACK=$( get_last $TRACKQUEUE )
4668 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4669 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4670 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4671 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4674 if checkstatus onetrack ; then ONETRACK=y ; fi
4676 if [ "$ONETRACK" = "y" ]; then
4677 # Reuse the CUEFILE in case we created it (now or in a previous run)
4678 if CUEFILE=$(checkstatus cuefile); then
4683 # Create playlist if needed (backgroundable) and start reading in tracks
4687 if [ ! "$ONETRACK" = "y" ]; then
4688 if [ "$DOPLAYLIST" = "y" ]; then
4689 echo Creating playlist... >&2
4694 if [ "$GETALBUMART" = "y" ]; then
4698 # For the lowdisk option, only one program is running at once so the encoder
4699 # can be unsilenced right away.
4700 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4701 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4704 if [ "$ONETRACK" = "y" ]; then
4705 TRACKS="$FIRSTTRACK"
4706 if [ "$USEPIPES" = "y" ]; then
4707 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4708 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4711 if checkstatus readtrack-$FIRSTTRACK; then :; else
4712 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4716 for UTRACKNUM in $TRACKQUEUE
4718 if [ "$DOREAD" = "y" ]; then
4719 if [ "$USEPIPES" = "y" ]; then
4720 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4721 # Read, pipe, shut up!
4722 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4725 if checkstatus readtrack-$UTRACKNUM; then :; else
4726 do_cdread $UTRACKNUM
4728 if [ "$?" != "0" ]; then
4729 # CD read failed - don't give the goahead to
4736 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4739 # If we are not reading, set the encode output to loud already, so
4740 # that we can see the output of the first track.
4741 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4742 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4744 echo NEXTTRACK # Get the encoder machine churning again
4745 if [ "$DOREAD" = "y" ]; then
4746 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4747 until checkstatus encodetrack-$UTRACKNUM
4749 if checkerrors encodetrack-$UTRACKNUM; then
4760 # Now that we're done the encoding can be loud again -
4761 # if we're not using SMP.
4762 if [ "$MAXPROCS" = "1" ]; then
4763 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4766 # All tracks read, start encoding.
4767 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4771 # Execute the user-defined post_read function before ejecting CD
4774 # We are now finished with the cdrom - it can be safely ejected. Note that
4775 # abcde will not have completed yet.
4776 if [ "$EJECTCD" = "y" ]; then
4777 # We check if the disk we are processing is actually the disk inside the
4778 # CD tray. If not, we do not eject the CD, since it might be so that the
4779 # user ejected it manually.
4780 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4781 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4782 # More FreeBSD bits.
4783 if [ X"$(uname)" = X"FreeBSD" ] ; then
4784 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4785 # but in this script EJECT is in the envionment and names the program
4788 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4789 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4790 $eject $EJECTOPTS $cd
4791 elif [ X"$(uname)" = X"Darwin" ] ; then
4792 diskutil eject ${CDROM#/dev/} 0
4793 elif [ -x $(which $EJECT) ]; then
4794 $EJECT $EJECTOPTS "$CDROM"
4801 ## Do we need to pre-process
4802 #if [ x"$PREPROCESS" = "x" ] ; then
4805 # for PRETRACKNUM in $TRACKQUEUE
4808 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4810 # until [ $PREPROCEED ]
4812 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4813 # # all locations are working, wait and try again later
4814 # if [ ! $PREPROCEED ]; then sleep 3; fi
4816 # ( do_preprocess $PRETRACKNUM
4824 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4826 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4827 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4828 if [ "$GOAHEAD" = "NO" ]; then break; fi
4829 for LASTTRACK in $TRACKQUEUE; do :; done
4830 if checkstatus readtrack-$LASTTRACK; then
4831 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4832 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4833 if checkerrors batch-normalize; then exit 1; fi
4835 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4836 if [ "$DONORMALIZE" = "y" ]; then
4837 for UTRACKNUM in $TRACKQUEUE
4839 if checkstatus readtrack-$UTRACKNUM; then
4840 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4844 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4845 if checkerrors nogap-encode; then exit 1; fi
4850 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4851 if [ "$ONETRACK" = "y" ] ; then
4852 TRACKQUEUE="$FIRSTTRACK"
4853 TRACKS="$FIRSTTRACK"
4856 # Do the encoding, including parallelization of remote encoding
4857 # Figure out where each track is going to be encoded
4858 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4859 if [ "$MAXPROCS" != "0" ]; then
4860 for NUM in $(f_seq_row 1 "$MAXPROCS")
4862 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
4866 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
4867 for UTRACKNUM in $TRACKQUEUE
4870 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4871 if [ "$GOAHEAD" = "NO" ]; then break; fi
4872 # find out where this track is to be encoded
4873 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4874 # Make sure we have a place to encode this, if not, exit stage right
4875 if [ -z "$ENCODELOCATIONS" ]; then
4881 for LOCATION in $ENCODELOCATIONS
4883 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4884 # check first if a track has ever been assigned to this location
4885 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
4886 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4887 if checkerrors encodetrack-$PREVIOUSTRACK; then
4888 for TEMPLOCATION in $ENCODELOCATIONS
4890 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4891 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
4894 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
4899 # We're still here, this location must have been previously assigned,
4900 # and last completed without error - check if it's done with the
4901 # previous track yet
4902 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
4904 # all locations are working, wait and try again later
4905 if [ ! $PROCEED ]; then sleep 3; fi
4907 # Record the location we're about to encode the next track at
4908 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4910 # Don't proceed with the rest of the loop if we can't encode
4911 if [ "$ABORT" ]; then continue; fi
4912 ## FIXME ## Add here
4913 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4914 # Set TRACKNUM, TRACKNAME
4915 if [ -e "$CDDBDATA" ]; then
4916 if [ "$ONETRACK" = "y" ]; then
4918 TRACKNUM="$FIRSTTRACK"
4922 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
4923 getcddbinfo TRACKNAME
4927 # You can't encode a file which needs to be normalized before finishing
4928 # You can't tag a file before it's finished encoding -
4929 # thus all of this is backgrounded together
4931 if [ "$DONORMALIZE" = "y" ]; then
4932 if checkstatus readtrack-$UTRACKNUM; then
4933 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4936 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4937 if checkstatus readtrack-$UTRACKNUM; then
4938 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4939 if [ "$DONORMALIZE" = "y" ]; then
4940 if checkstatus normalizetrack-$UTRACKNUM; then
4941 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4944 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4948 if [ "$DOTAG" = "y" ]; then
4949 if checkstatus encodetrack-$UTRACKNUM; then
4950 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
4952 # Lets tag the cue file
4953 if checkstatus cleancuefile >/dev/null; then :; else
4954 if checkstatus cuefile >/dev/null ; then
4959 if [ "$DOMOVE" = "y" ]; then
4960 if checkstatus tagtrack-$UTRACKNUM; then
4961 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
4968 # Go through it again and make sure there's no distmp3 stragglers, otherwise
4969 # we'll delete the files they're working on
4970 # Do NOT play ball if there is no ball to play (so ABORT if needed)
4971 ## FIXME ## Check also for files which are encoded using PIPEs.
4972 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
4977 for LOCATION in $ENCODELOCATIONS
4979 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4980 # "How can he give us a status update, if he's DEAD?"
4981 if checkstatus encodetrack-$CHECKTRACK; then
4984 # Nothing to see here please go quietly back to your homes
4985 if [ -z "$CHECKTRACK" ]; then continue; fi
4986 # You're still here? Maybe there is something...
4987 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
4990 if [ ! $PROCEED ]; then sleep 5; fi
4993 # If the above didn't catch the stragglers, this will
4995 if [ "$DOREPLAYGAIN" = "y" ]; then
4999 # Execute the user-defined post_encode function before cleaning up
5002 # Check to see if run_command logged any errors
5003 if [ -f "$ABCDETEMPDIR/errors" ]; then
5004 log error "The following commands failed to run:"
5005 cat "$ABCDETEMPDIR/errors"
5009 if [ "$KEEPWAVS" = "y" ];then
5013 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5014 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5015 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5016 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5017 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5018 log warning "The encoded formats does not match with the moved ones"
5019 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
5020 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
5021 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
5025 if [ "$DOCLEAN" = "y" ]; then
5026 # Wipe all the evidence
5027 # Gimme gimme gimme some more time!
5029 rm -rf "$ABCDETEMPDIR"
5032 echo "Finished. Not cleaning $ABCDETEMPDIR."