2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # This code is hereby licensed for public consumption under either the
5 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
7 # You should have received a copy of the GNU General Public License along
8 # with this program; if not, write to the Free Software Foundation, Inc.,
9 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
16 VERSION='2.5.3-UNRELEASED'
20 echo "This is abcde v$VERSION."
21 echo "Usage: abcde [options] [tracks]"
23 echo "-1 Encode the whole CD in a single file"
24 echo "-a <action1[,action2]...>"
25 echo " Actions to perform:"
26 echo " cddb,read,normalize,encode,tag,move,replaygain,playlist,clean"
27 #echo "-A Experimental actions (retag, transcode)"
28 echo "-b Enable batch normalization"
29 #echo "-B Disable batch replaygain (do file by file)"
31 echo " Specify a configuration file (overrides system and user config files)"
33 echo " Specify discid to resume from (only needed if you no longer have the cd)"
35 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
36 echo "-D Debugging mode (equivalent to sh -x abcde)"
37 echo "-e Erase encoded track information from status file"
38 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
39 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
40 echo "-h This help information"
41 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
42 echo "-j <#> Number of encoder processes to run at once (localhost)"
43 echo "-k Keep the wav tracks for later use"
44 echo "-l Use low disk space algorithm"
45 echo "-L Use local CDDB storage directory"
46 echo "-m Modify playlist to include CRLF endings, to comply with some players"
47 #echo " WARNING: Deprecated. Use \"cue\" action"
48 #echo "-M Create a CUE file"
49 echo "-n No lookup. Don't query CDDB, just create and use template"
50 echo "-N Noninteractive. Never prompt for anything"
51 echo "-o <type1[,type2]...>"
52 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
53 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
54 echo "-P Use UNIX pipes to read+encode without wav files"
56 echo " Set quality level (high,medium,low)"
57 echo "-r <host1[,host2]...>"
58 echo " Also encode on these remote hosts"
59 echo "-R Use local CDDB in recursive mode"
61 echo " Show fields from the CDDB info (year,genre)"
62 echo "-S <#> Set the CD speed"
63 echo "-t <#> Start the track numbering at a given number"
64 echo "-T <#> Same as -t but modifies tag numbering"
65 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
66 echo "-v Show version number and exit"
67 echo "-V Be a bit more verbose about what is happening behind the scenes"
68 echo "-x Eject CD after all tracks are read"
70 echo " Add a comment to the CD tracks"
71 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
72 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
74 echo "Tracks is a space-delimited list of tracks to grab."
75 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
77 #echo "Double hyphens are used to concatenate tracks"
82 echo "$@" >> "$ABCDETEMPDIR/status"
85 # log [level] [message]
87 # log outputs the right message in a common format
93 error) echo "[ERROR] abcde: $@" >&2 ;;
94 warning) echo "[WARNING] $@" >&2 ;;
95 info) echo "[INFO] $@" ;;
99 # Funtions to replace the need of seq, which is too distribution dependant.
103 while [ $i -ne `expr $2 + 1` ]
113 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
114 while [ $i -ne `expr $2 + 1` ]
121 log error "syntax error while processing track numbers ($i)"
126 # Functions to replace the need of awk {print $1} and {print $NF}
129 if [ X"$1" = "X" ]; then
130 for first in `cat`; do
141 if [ X"$1" = "X" ]; then
142 for stdin in `cat`; do
146 for last in $@ ; do :; done
151 # checkstatus [blurb]
152 # Returns "0" if the blurb was found, returns 1 if it wasn't
153 # Puts the blurb content, if available, on stdout.
154 # Otherwise, returns "".
157 # Take the last line in the status file if there's multiple matches
159 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
161 if [ -z "$BLURB" ]; then
166 # See if there's a = in it
167 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
168 echo "$(echo $BLURB | cut -f2- -d=)"
174 # checkwarnings [blurb]
175 # Returns "0" if the blurb was found (meaning there was an warning),
176 # returns 1 if it wasn't (yes this is a little backwards).
177 # Does not print the blurb on stdout.
178 # Otherwise, returns "".
181 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
184 # Take the last line in the status file if there's multiple matches
186 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
188 if [ -z "$BLURB" ]; then
189 # negative, we did not have a negative...
192 # affirmative, we had a negative...
197 # checkerrors [blurb]
198 # Returns "0" if the blurb was found (meaning there was an error),
199 # returns 1 if it wasn't (yes this is a little backwards).
200 # Does not print the blurb on stdout.
201 # Otherwise, returns "".
204 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
207 # Take the last line in the status file if there's multiple matches
209 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
211 if [ -z "$BLURB" ]; then
212 # negative, we did not have a negative...
215 # affirmative, we had a negative...
221 # Finds the right pager in the system to display a file
225 # Use the debian sensible-pager wrapper to pick the pager
226 # user has requested via their $PAGER environment variable
227 if [ -x "/usr/bin/sensible-pager" ]; then
228 /usr/bin/sensible-pager "$PAGEFILE"
229 elif [ -x "$PAGER" ]; then
230 # That failed, try to load the preferred editor, starting
231 # with their PAGER variable
233 # If that fails, check for less
234 elif [ -x /usr/bin/less ]; then
235 /usr/bin/less -f "$PAGEFILE"
236 # more should be on all UNIX systems
237 elif [ -x /bin/more ]; then
238 /bin/more "$PAGEFILE"
240 # No bananas, just cat the thing
245 # run_command [blurb] [command...]
246 # Runs a command, silently if necessary, and updates the status file
252 # See if this is supposed to be silent
253 if [ "$(checkstatus encode-output)" = "loud" ]; then
257 # Special case for SMP, since
258 # encoder output is never displayed, don't mute echos
259 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
268 normalize|normalize-audio)
269 if [ "$RETURN" = "2" ]; then
270 # File was already normalized.
275 if [ "$RETURN" != "0" ]; then
276 # Put an error in the errors file. For various reasons we
277 # can't capture a copy of the program's output but we can
278 # log what we attempted to execute and the error code
279 # returned by the program.
280 if [ "$BLURB" ]; then
283 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
284 return $RETURN # Do not pass go, do not update the status file
286 if [ "$BLURB" ]; then
287 echo $BLURB >> "$ABCDETEMPDIR/status"
291 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
292 # distributed under the terms of the GNU GPL v2 or later, at your option
294 # Function to determine if a word contains a slash.
303 # Function to give the relative path from one file to another.
304 # Usage: relpath fromfile tofile
305 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
306 # (the result would be Album/Song.mp3)
307 # Output is relative path to $2 from $1 on stdout
309 # This code has the following restrictions:
310 # Multiple ////s are not collapsed into single /s, with strange effects.
311 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
312 # If FR is a directory it must have a trailing /
320 /*) ;; # No processing is needed for absolute paths
322 # Loop through common prefixes, ignoring them.
323 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
325 FR="$(echo "$FR" | cut -d/ -f2-)"
326 TO="$(echo "$TO" | cut -d/ -f2-)"
328 # Loop through directory portions left in FR, adding appropriate ../s.
331 FR="$(echo "$FR" | cut -d/ -f2-)"
342 if [ ! "$@" = "" ]; then
343 # Cut off any command-line option we added in
344 X=$(echo $@ | cut -d' ' -f2)
345 if [ "$(which $X)" = "" ]; then
347 elif [ ! -x $(which $X) ]; then
356 if [ ! "$@" = "" ]; then
357 # Cut off any command-line option we added in
358 X=$(echo $@ | cut -d' ' -f2)
359 # Test for built-in abcde.function
360 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
361 if [ "$(which $X)" = "" ]; then
362 log error "$X is not in your path." >&2
363 log info "Define the full path to the executable if it exists on your system." >&2
364 if [ -e /etc/debian_release ] ; then
366 oggenc) MISSING_PACKAGE=vorbis-tools ;;
367 lame|flac) MISSING_PACKAGE=$X ;;
369 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
372 elif [ ! -x "$(which $X)" ]; then
373 log error "$X is not executable." >&2
379 # diffentries <filename> <max_value> <entry1>,<entry2>
380 # max_value: the range of entries goes from 1 to <max_value>
385 local CDDBDIFFCHOICES=$1
387 local CDDBDIFFCHOICE="$@"
388 if [ ! X"$DIFF" = "X" ]; then
389 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
390 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
391 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
392 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
393 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
394 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
396 # We parse the 2 choices to diff, store them in temporary files and diff them.
397 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
398 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
400 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
401 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
402 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
403 page "$ABCDETEMPDIR/$FILENAME.diff"
405 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
409 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
414 # Finds an specific field from cddbinfo
419 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
422 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
425 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
431 # Get the track number we are going to use for different actions
434 if [ -n "$STARTTRACKNUMBER" ] ; then
435 # Get the trackpadding from the current track
436 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
437 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
439 TRACKNUM=${UTRACKNUM}
445 # Calculate cddb disc ids without requiring specialized helper programs.
446 # largely copied from cd-discid and musicbrainz examples. some of the steps
447 # don't make sense, but they're necessary to match the ids generated by other
450 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
451 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
452 # 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
453 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
454 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
455 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
457 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
460 if [ X"$LEADOUT" = "X" ]; then
461 log warning "Error trying to calculate disc ids without lead-out information."
465 # default to a two second lead-in
467 LEADIN=${LEADIN:=150}
469 # number of cdframes per second
472 # reset cddb checksum for cddb disc-id calululation
476 for OFFSET in $(echo $OFFSETS)
478 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
480 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
481 while [ $OFFSETTIME -gt 0 ]; do
482 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
483 OFFSETTIME=$(($OFFSETTIME / 10))
488 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
490 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
491 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
493 case "$CDDBMETHOD" in
495 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
498 # FIXME: don't assume the first track is 1
499 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
500 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
504 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
509 if checkstatus replaygain; then :; else
510 run_command "" echo "Adding replaygain information..."
511 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
515 OUTPUT=$OGGOUTPUTCONTAINER
518 OUTPUT=$FLACOUTPUTCONTAINER
526 for UTRACKNUM in $TRACKQUEUE
528 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
529 getcddbinfo TRACKNAME
531 TRACKFILE="$(mungefilename "$TRACKNAME")"
532 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
533 ALBUMFILE="$(mungefilename "$DALBUM")"
534 GENRE="$(mungegenre "$GENRE")"
535 YEAR=${CDYEAR:-$CDYEAR}
537 if [ "$ONETRACK" = "y" ]; then
538 if [ "$VARIOUSARTISTS" = "y" ]; then
539 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
541 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
544 if [ "$VARIOUSARTISTS" = "y" ]; then
545 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
547 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
550 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
551 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
555 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
556 #run_command replaygain-flac true
559 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
562 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
565 run_command replaygain-mpc nice $ENCNICE $MPPGAIN --auto "${OUTPUTFILES[@]}"
570 if checkerrors "replaygain-.{3,6}"; then :; else
571 run_command replaygain true
576 # This code splits the a Various Artist track name from one of the following
579 # forward: Artist / Track
580 # forward-dash: Artist - Track
581 # reverse: Track / Artist
582 # reverse-dash: Track - Artist
583 # colon: Artist: Track
584 # trailing-paren: Artist (Track)
587 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
590 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
591 case "$VARIOUSARTISTSTYLE" in
593 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
594 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
595 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
598 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
599 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
600 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
603 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
604 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
605 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
608 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
609 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
610 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
613 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
614 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
615 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
618 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
619 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
620 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
623 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
624 TRACKARTIST="Various"
626 TRACKARTIST="$DARTIST"
631 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
635 "classic rock") id=1 ;;
653 "industrial") id=19 ;;
654 "alternative") id=20 ;;
656 "death metal") id=22 ;;
658 "soundtrack") id=24 ;;
659 "euro-techno") id=25 ;;
663 "jazz+funk") id=29 ;;
666 "classical") id=32 ;;
667 "instrumental") id=33 ;;
671 "sound clip") id=37 ;;
674 "alt. rock") id=40 ;;
679 "meditative") id=45 ;;
680 "instrum. pop") id=46 ;;
681 "instrum. rock") id=47 ;;
685 "techno-indust.") id=51 ;;
686 "electronic") id=52 ;;
688 "eurodance") id=54 ;;
690 "southern rock") id=56 ;;
695 "christian rap") id=61 ;;
696 "pop/funk"|"pop / funk") id=62 ;;
698 "native american") id=64 ;;
701 "psychadelic") id=67 ;;
703 "showtunes") id=69 ;;
707 "acid punk") id=73 ;;
708 "acid jazz") id=74 ;;
712 "rock & roll") id=78 ;;
713 "hard rock") id=79 ;;
715 "folk/rock") id=81 ;;
716 "national folk") id=82 ;;
723 "bluegrass") id=89 ;;
724 "avantgarde") id=90 ;;
725 "gothic rock") id=91 ;;
726 "progress. rock") id=92 ;;
727 "psychadel. rock") id=93 ;;
728 "symphonic rock") id=94 ;;
729 "slow rock") id=95 ;;
732 "easy listening") id=98 ;;
738 "chamber music") id=104 ;;
740 "symphony") id=106 ;;
741 "booty bass") id=107 ;;
743 "porn groove") id=109 ;;
745 "slow jam") id=111 ;;
749 "folklore") id=115 ;;
751 "power ballad") id=117 ;;
752 "rhythmic soul") id=118 ;;
753 "freestyle") id=119 ;;
755 "punk rock") id=121 ;;
756 "drum solo") id=122 ;;
757 "a capella") id=123 ;;
758 "euro-house") id=124 ;;
759 "dance hall") id=125 ;;
761 "drum & bass") id=127 ;;
762 "club-house") id=128 ;;
763 "hardcore") id=129 ;;
767 "negerpunk") id=133 ;;
768 "polsk punk") id=134 ;;
770 "christian gangsta rap") id=136 ;;
771 "heavy metal") id=137 ;;
772 "black metal") id=138 ;;
773 "crossover") id=139 ;;
774 "contemporary christian")id=140 ;;
775 "christian rock") id=141 ;;
776 "merengue") id=142 ;;
778 "thrash metal") id=144 ;;
781 "synthpop") id=147 ;;
782 "rock/pop"|"rock / pop") id=148 ;;
789 # do_tag [tracknumber]
790 # id3 tags a filename
792 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC, ATOMICPARSLEY
793 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
796 COMMENTOUTPUT="$(eval echo ${COMMENT})"
797 if [ -z "$COMMENTOUTPUT" ]; then
798 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
800 if [ "$CDDBMETHOD" = "cddb" ]; then
801 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
803 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
804 # If we want to start the tracks with a given number, we need to modify the
805 # TRACKNUM value before evaluation
806 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
809 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
813 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
814 GENREID=$(do_getgenreid "${CDGENRE}")
815 # Set TPE2 in case we have a Various Artists rip.
817 if [ "$VARIOUSARTISTS" = "y" ]; then
824 # FIXME # track numbers in mp3 come with 1/10, so we cannot
825 # happily substitute them with $TRACKNUM
826 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
827 --comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
828 -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
829 -G "$GENREID" -n "${TRACKNUM:-$1}" \
830 "${TRACKNUM:+-N $TRACKS}" \
831 "${ENCODING:+--set-encoding=$ENCODING}" \
832 "${TPE2:+--set-user-text-frame=TPE2:$TPE2}" \
833 "$ABCDETEMPDIR/track$1.$OUTPUT"
835 # FIXME # Still not activated...
837 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
838 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
839 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" \
840 -y "$CDYEAR" -g "$GENREID" -k "${TRACKNUM:-$1}" \
841 "$ABCDETEMPDIR/track$1.$OUTPUT"
844 # FIXME # track numbers in mp3 come with 1/10, so we cannot
845 # happily substitute them with $TRACKNUM
846 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
847 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
848 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
849 -y "$CDYEAR" -g "$GENREID" \
850 -T "${TRACKNUM:-$1}/$TRACKS" \
851 ${TPE2:+--TPE2 "$TPE2"} \
852 "$ABCDETEMPDIR/track$1.$OUTPUT"
857 case "$OGGENCODERSYNTAX" in
859 # vorbiscomment can't do in-place modification, mv the file first
860 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
861 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
865 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
867 echo ARTIST="$TRACKARTIST"
869 echo TITLE="$TRACKNAME"
870 if [ -n "$CDYEAR" ]; then
873 if [ -n "$CDGENRE" ]; then
874 echo GENRE="$CDGENRE"
876 echo TRACKNUMBER=${TRACKNUM:-$1}
877 if [ -n "$DISCNUMBER" ]; then
878 echo DISCNUMBER="$DISCNUMBER"
880 echo CDDB=$CDDBDISCID
881 if [ "$(eval echo ${COMMENT})" != "" ]; then
882 case "$COMMENTOUTPUT" in
883 *=*) echo "$COMMENTOUTPUT";;
884 *) echo COMMENT="$COMMENTOUTPUT";;
887 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
888 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
889 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
890 # Doublecheck that the commented file was created
891 # successfully before wiping the original
892 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
893 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
895 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
902 echo ARTIST="$TRACKARTIST"
904 echo TITLE="$TRACKNAME"
905 if [ -n "$CDYEAR" ]; then
908 if [ -n "$CDGENRE" ]; then
909 echo GENRE="$CDGENRE"
911 echo TRACKNUMBER="${TRACKNUM:-$1}"
912 if [ -n "$DISCNUMBER" ]; then
913 echo DISCNUMBER="$DISCNUMBER"
915 echo CDDB="$CDDBDISCID"
916 if [ "$(eval echo ${COMMENT})" != "" ]; then
917 case "$COMMENTOUTPUT" in
918 *=*) echo "$COMMENTOUTPUT";;
919 *) echo COMMENT="$COMMENTOUTPUT";;
922 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
925 run_command tagtrack-$OUTPUT-$1 true
928 run_command tagtrack-$OUTPUT-$1 true
931 # Use a temp-file of our choice. --overWrite seems to
932 # case core dumps with AtomicParsley 0.9.0
933 ATOMICTEMPFILE="$ABCDETEMPDIR/track$1.m4a-atomic"
936 if [ "$VARIOUSARTISTS" = "y" ]; then
940 #It has to be command file opts for AtomicParsley
941 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $ATOMICPARSLEY $ABCDETEMPDIR/track$1.m4a --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --tracknum ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --compilation $VARIOUSBOOL --comment "$COMMENTOUTPUT" --output $ATOMICTEMPFILE
942 if [ -f $ATOMICTEMPFILE ]; then
943 mv "$ATOMICTEMPFILE" "$ABCDETEMPDIR/track$1.m4a"
947 run_command tagtrack-$OUTPUT-$1 true
951 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
952 run_command tagtrack-$1 true
959 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
962 # The commands here don't go through run_command because they're never
963 # supposed to be silenced
964 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
965 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
969 case "$MP3ENCODERSYNTAX" in
974 for UTRACKNUM in $TRACKQUEUE
976 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
978 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
980 if [ "$RETURN" != "0" ]; then
981 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
983 for UTRACKNUM in $TRACKQUEUE
985 run_command encodetrack-$OUTPUT-$UTRACKNUM true
986 #run_command encodetrack-$UTRACKNUM true
995 if checkerrors "nogap-encode"; then :; else
996 if [ ! "$KEEPWAVS" = "y" ] ; then
997 if [ ! "$KEEPWAVS" = "move" ] ; then
1002 # Other encoders fall through to normal encoding as the tracks have not
1003 # been entered in the status file.
1006 # do_encode [tracknumber] [hostname]
1007 # If no hostname is specified, encode locally
1009 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1012 if [ "$USEPIPES" = "y" ]; then
1015 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1018 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1021 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1024 TEMPARG="PIPE_$SPEEXENCODER"
1027 TEMPARG="PIPE_$MPPENCODER"
1030 TEMPARG="PIPE_$AACENCODERSYNTAX"
1033 IN="$( eval echo "\$$TEMPARG" )"
1035 IN="$ABCDETEMPDIR/track$1.wav"
1038 case "$MP3ENCODERSYNTAX" in
1039 # FIXME # check if mp3enc needs -if for pipes
1040 # FIXME # I have not been able to find a working mp3enc binary
1054 # We need IN to proceed, if we are not using pipes.
1055 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1056 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1058 case "$TMPOUTPUT" in
1060 OUTPUT=$OGGOUTPUTCONTAINER
1063 OUTPUT=$FLACOUTPUTCONTAINER
1069 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1070 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1073 if [ X"$USEPIPES" = "Xy" ]; then
1075 # We need a way to store the creation of the files when using PIPES
1076 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1077 # When pipping it does not make sense to have a higher nice for
1078 # reading than for encoding, since it will be hold by the
1079 # encoding process. Setting an effective nice, to calm down a
1080 # bit the reading process.
1081 EFFECTIVE_NICE=$READNICE
1083 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1084 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1085 EFFECTIVE_NICE=$ENCNICE
1091 case "$MP3ENCODERSYNTAX" in
1092 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1093 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1094 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1095 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1096 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1100 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1107 case "$OGGENCODERSYNTAX" in
1108 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1109 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1113 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1120 case "$FLACENCODERSYNTAX" in
1121 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1126 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1127 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1132 if [ "$(eval echo ${COMMENT})" != "" ]; then
1135 *) COMMENT="COMMENT=$COMMENT" ;;
1138 # Tag the file at encode time, as it can't be done after encoding.
1139 if [ "$DOTAG" = "y" ]; then
1140 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1142 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1146 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1148 # I tried compiling the mppenc from corecodecs.org and got some
1149 # errors, so I have not tried it myself.
1150 ## FIXME ## Needs some cleanup to determine if an empty tag sent
1151 ## FIXME ## to the encoder ends up empty.
1152 $RUN_COMMAND nice $EFFECTIVE_NICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
1155 # Tag the file at encode time, as it can't be done after encoding.
1156 if [ "$DOTAG" = "y" ]; then
1157 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
1160 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1164 # In case of wav output we need nothing. Just keep the wavs.
1169 # Only remove .wav if the encoding succeeded
1170 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1171 run_command encodetrack-$1 true
1172 if [ ! "$KEEPWAVS" = "y" ] ; then
1173 if [ ! "$KEEPWAVS" = "move" ] ; then
1179 run_command "" echo "HEH! The file we were about to encode disappeared:"
1180 run_command "" echo ">> $IN"
1181 run_command encodetrack-$1 false
1185 # do_preprocess [tracknumber]
1187 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1190 # IN="$ABCDETEMPDIR/track$1.wav"
1191 # # We need IN to proceed.
1192 # if [ -s "$IN" ] ; then
1193 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1195 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1196 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1197 # case "$POSTPROCESSFORMAT" in
1199 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1201 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1203 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1205 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1207 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1210 # # Only remove .wav if the encoding succeeded
1211 # if checkerrors "preprocess-(.{3,4})-$1"; then
1212 # run_command preprocess-$1 false
1214 # run_command preprocess-$1 true
1217 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1218 # echo "HEH! The file we were about to pre-process disappeared:"
1221 # run_command preprocess-$1 false
1226 # do_postprocess [tracknumber]
1228 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1231 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1233 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1234 # # We need IN to proceed.
1235 # if [ -s "$IN" ] ; then
1236 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1237 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1238 # case "$POSTPROCESSFORMAT" in
1240 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1242 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1244 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1246 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1248 # # Only remove .wav if the encoding succeeded
1249 # if checkerrors "postprocess-(.{3,4})-$1"; then
1250 # run_command postprocess-$1 false
1252 # run_command postprocess-$1 true
1255 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1256 # echo "HEH! The file we were about to post-process disappeared:"
1259 # run_command postprocess-$1 false
1274 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1278 # The commands here don't go through run_command because they're never supposed to be silenced
1279 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1284 for UTRACKNUM in $TRACKQUEUE
1286 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1288 # FIXME # Hard-coded batch option!
1289 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1291 if [ "$RETURN" != "0" ]; then
1292 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1294 for UTRACKNUM in $TRACKQUEUE
1296 echo normalizetrack-$UTRACKNUM >> status
1302 # do_batch_normalize
1304 # NORMALIZER, NORMALIZEROPTS
1305 do_batch_normalize ()
1307 # The commands here don't go through run_command because they're never supposed to be silenced
1308 echo "Batch normalizing tracks: $TRACKQUEUE"
1313 for UTRACKNUM in $TRACKQUEUE
1315 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1317 # XXX: Hard-coded batch option!
1318 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1320 if [ "$RETURN" != "0" ]; then
1321 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1323 for UTRACKNUM in $TRACKQUEUE
1325 echo normalizetrack-$UTRACKNUM >> status
1331 # do_normalize [tracknumber]
1333 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1336 IN="$ABCDETEMPDIR/track$1.wav"
1337 if [ -e "$IN" ] ; then
1338 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1339 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1341 if [ "$(checkstatus encode-output)" = "loud" ]; then
1342 echo "HEH! The file we were about to normalize disappeared:"
1345 run_command normalizetrack-$1 false "File $IN was not found"
1349 # do_move [tracknumber]
1350 # Deduces the outfile from environment variables
1351 # Creates directory if necessary
1353 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1356 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1358 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1359 # defined the OUTPUTFILE:
1362 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1363 # Munge filenames as follows:
1368 # Eat control characters
1369 ALBUMFILE="$(mungefilename "$DALBUM")"
1370 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1371 TRACKFILE="$(mungefilename "$TRACKNAME")"
1372 GENRE="$(mungegenre "$GENRE")"
1373 YEAR=${CDYEAR:-$CDYEAR}
1374 # If we want to start the tracks with a given number, we need to modify
1375 # the TRACKNUM value before evaluation
1377 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1378 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1379 if [ "$ONETRACK" = "y" ]; then
1380 if [ "$VARIOUSARTISTS" = "y" ]; then
1381 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1383 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1386 if [ "$VARIOUSARTISTS" = "y" ]; then
1387 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1389 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1392 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1393 # Once we know the specific output was successful, we can change
1394 # the OUTPUT to the value containing the container
1397 OUTPUT=$OGGOUTPUTCONTAINER
1400 OUTPUT=$FLACOUTPUTCONTAINER
1406 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1407 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1410 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1411 # FIXME # introduce warnings?
1414 # mkdir -p shouldn't return an error if the directory already exists
1415 mkdir -p "$OUTPUTFILEDIR"
1416 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1417 if checkstatus movetrack-output-$OUTPUT; then :; else
1418 run_command movetrack-output-$OUTPUT true
1423 # mkdir -p shouldn't return an error if the directory already exists
1424 mkdir -p "$OUTPUTFILEDIR"
1425 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1426 if checkstatus movetrack-output-$OUTPUT; then :; else
1427 run_command movetrack-output-$OUTPUT true
1431 # Lets move the cue file
1432 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1433 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1434 if checkstatus movecue-$OUTPUT; then :; else
1435 # Silence the Copying output since it overlaps with encoding processes...
1436 #run_command '' vecho "Copying cue file to its destination directory..."
1437 if checkstatus onetrack >/dev/null ; then
1440 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1441 # We dont have the dir, since it was not created before.
1444 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1447 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1448 # http://brianvictor.tripod.com/mp3cue.htm#details
1449 [a-z0-9][a-z0-9][a-z0-9])
1450 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1453 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1457 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1459 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1468 # Create the playlist if wanted
1470 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1471 # VARIOUSARTISTS, OUTPUTDIR
1474 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1478 OUTPUT=$OGGOUTPUTCONTAINER
1481 OUTPUT=$FLACOUTPUTCONTAINER
1487 # Create a playlist file for the playlist data to go into.
1488 # We used to wipe it out if it existed. Now we request permision if interactive.
1489 for LASTTRACK in $TRACKQUEUE; do :; done
1490 ALBUMFILE="$(mungefilename "$DALBUM")"
1491 ARTISTFILE="$(mungefilename "$DARTIST")"
1492 GENRE="$(mungegenre "$GENRE")"
1493 YEAR=${CDYEAR:-$CDYEAR}
1494 if [ "$VARIOUSARTISTS" = "y" ] ; then
1495 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1497 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1499 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1500 mkdir -p "$FINALPLAYLISTDIR"
1501 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1502 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1503 if [ "$INTERACTIVE" = "y" ]; then
1504 while [ "$DONE" != "y" ]; do
1506 case $ERASEPLAYLIST in
1507 e|E|a|A|k|K) DONE=y ;;
1508 "") ERASEPLAYLIST=e ; DONE=y ;;
1516 # Once we erase the playlist, we use append to create the new one.
1517 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1519 # The playlist does not exist, so we can safelly use append to create the new list
1522 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1523 touch "$OUTPUTDIR/$PLAYLISTFILE"
1524 for UTRACKNUM in $TRACKQUEUE
1526 # Shares some code with do_move since the filenames have to match
1527 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1528 getcddbinfo TRACKNAME
1530 TRACKFILE="$(mungefilename "$TRACKNAME")"
1531 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1532 ALBUMFILE="$(mungefilename "$DALBUM")"
1533 # If we want to start the tracks with a given number, we need to modify the
1534 # TRACKNUM value before evaluation
1536 if [ "$VARIOUSARTISTS" = "y" ]; then
1537 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1539 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1541 if [ "$VARIOUSARTISTS" = "y" ]; then
1542 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1543 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1545 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1548 if [ "$PLAYLISTDATAPREFIX" ]; then
1549 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1551 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1556 ## this will convert the playlist to have CRLF line-endings, if specified
1557 ## (some hardware players insist on CRLF endings)
1558 if [ "$DOSPLAYLIST" = "y" ]; then
1559 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1560 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1561 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1563 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1568 # This function reads a cuefile on stdin and writes an extended
1569 # cddb query on stdout. Any PREGAP for track 1 is properly
1570 # handled, although cue files embedded in FLAC files do not
1571 # appear to properly store the PREGAP setting. :(
1572 abcde.cue2discid () {
1577 while [ $val -gt 0 ] ; do
1578 ret=$(( $ret + ( $val % 10) ))
1579 val=$(( $val / 10 ))
1589 local first second third
1590 first=$(expr ${1} + 0 )
1591 second=$(expr ${2} + 0 )
1592 third=$(expr ${3} + 0 )
1594 echo $(( ((($first * 60) + $second) * 75) + $third ))
1604 while read line ; do
1607 TRACK) i=$(( i + 1 ))
1609 INDEX) if [ "$2" -eq 1 ] ; then
1611 START=$(( $LBA + $PREGAP + $OFFSET ))
1613 X=$(cddb_sum $(( $START / 75 )) )
1617 PREGAP) PREGAP=$(msf2lba $2)
1621 LEADOUT=$(( $4 / 588 ))
1624 LEADIN=$(( $3 / 588 ))
1633 LEADOUT=$(( $LEADOUT + $LEADIN ))
1635 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1636 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1637 printf "%08x %i" $DISCID $TRACKS
1640 while [ $j -le $TRACKS ] ; do
1641 eval echo -n "\" \$TRACK$j\""
1644 echo " $(( $LEADOUT / 75 ))"
1648 # abcde.mkcue [--wholedisk]
1649 # This creates a cuefile directly from the extended discid information
1650 # The --wholedisk option controls whether we're ripping data from the
1651 # start of track one or from the start of the disk (usually, but not
1652 # always the same thing!)
1654 # Track one leadin/pregap (if any) handeling:
1655 # --wholedisk specified:
1658 # INDEX 01 <pregap value>
1659 # Remaining track index values unchanged from disc TOC
1661 # --wholedisk not specified
1663 # PREGAP <pregap value>
1665 # Remaining track index values offset by <pregap value>
1672 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1675 local MODE DISCID TRACKS
1679 if [ "$1" = --wholedisc ] ; then
1685 vecho "One track is $ONETRACK"
1686 TRACKFILE="$(mungefilename "$TRACKNAME")"
1687 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1688 ALBUMFILE="$(mungefilename "$DALBUM")"
1689 if [ "$ONETRACK" = "y" ]; then
1690 if [ "$VARIOUSARTISTS" = "y" ]; then
1691 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1693 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1695 vecho "Cue wav file is $CUEWAVFILE"
1697 CUEWAVFILE="dummy.wav"
1706 echo REM DISCID $DISCID
1707 echo FILE \""$CUEWAVEFILE"\" WAVE
1709 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1716 while [ $i -le "$TRACKS" ] ; do
1717 LBA=$(( $1 - $OFFSET ))
1718 printf " TRACK %02i AUDIO\n" $i
1719 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1720 if [ $MODE = PREGAP ] ; then
1721 echomsf " PREGAP " $(($OFFSET-150))
1723 echo " INDEX 00 00:00:00"
1726 echomsf " INDEX 01 " $LBA
1733 # This essentially the start of things
1736 # Query the CD to get the track info, unless the user specified -C
1737 # or we are using some actions which do not need the CDDB data at all
1738 #if [ ! X"$EXPACTIONS" = "X" ]; then
1740 #elif [ -z "$DISCID" ]; then
1741 if [ -z "$DISCID" ]; then
1742 vecho -n "Getting CD track info... "
1743 # In OSX, unmount the disc before a query
1744 if [ "$OSFLAVOUR" = "OSX" ]; then
1745 diskutil unmount ${CDROM#/dev/}
1747 case "$CDROMREADERSYNTAX" in
1749 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1750 case "$CUE2DISCID" in
1751 # FIXME # right now we have 2 cue2discid internal
1752 # implementations: builtin and abcde.cue2discid. Test
1753 # both of them and decide which one we want to use.
1755 #vecho "Using builtin cue2discid implementation..."
1756 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1758 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1760 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1761 TRACKS=${#OFFSETTIMES[@]}
1763 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1764 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1765 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1766 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1769 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1770 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1774 #vecho "Using external python cue2discid implementation..."
1775 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1779 log error "the input flac file does not contain a cuesheet."
1784 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1786 # if [ ! "$RET" = "0" ];then
1787 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1790 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1791 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1793 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1794 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1798 case "$CDDBMETHOD" in
1799 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1800 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1804 # Make sure there's a CD in there by checking cd-discid's return code
1805 if [ ! "$?" = "0" ]; then
1806 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1807 log error "cuesheet information from the flac file could not be read."
1808 log error "Perhaps the flac file does not contain a cuesheet?."
1811 log error "CD could not be read. Perhaps there's no CD in the drive?"
1815 # In OSX, remount the disc again
1816 if [ "$OSFLAVOUR" = "OSX" ]; then
1817 diskutil mount ${CDROM#/dev/}
1820 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1822 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1825 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1826 # This needs to be done now because a section of the resuming code will need
1829 # get the number of digits to pad TRACKNUM with - we'll use this later
1830 # a CD can only hold 99 tracks, but since we support a feature for starting
1831 # numbering the tracks from a given number, we might need to set it as a
1832 # variable for the user to define... or obtain it somehow.
1833 if [ "$PADTRACKS" = "y" ] ; then
1837 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1838 if [ -z "$TRACKQUEUE" ]; then
1839 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1840 case "$CDROMREADERSYNTAX" in
1842 if [ "$WEHAVEACD" = "y" ]; then
1843 vecho "Querying the CD for audio tracks..."
1844 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1846 if [ ! "$RET" = "0" ];then
1847 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1849 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1850 CDPARANOIAAUDIOTRACKS="$TRACKS"
1852 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1853 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1854 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1855 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1857 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1858 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1862 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1865 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1867 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1868 log info "The disc does not contain any tracks. Giving up..."
1871 echo -n "Grabbing entire CD - tracks: "
1872 if [ ! "$PADTRACKS" = "y" ] ; then
1873 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1875 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1877 while [ "$X" -ne "$TRACKS" ]
1879 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1880 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1884 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1885 # User-supplied track queue.
1886 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1887 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1888 # Once cleaned, obtain the highest value in the trackqueue for number padding
1889 for LASTTRACK in $TRACKQUEUE; do :; done
1890 if [ ! "$PADTRACKS" = "y" ] ; then
1891 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1893 # Now we normalize the trackqueue
1894 for TRACK in $TRACKQUEUE ; do
1895 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1896 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1898 TRACKQUEUE=$PADTRACKQUEUE
1899 echo Grabbing tracks: "$TRACKQUEUE"
1902 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1904 # We have the discid, create a temp directory after it to store all the temp
1907 if [ -e "$ABCDETEMPDIR" ]; then
1908 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1909 # It already exists, see if it's a directory
1910 if [ ! -d "$ABCDETEMPDIR" ]; then
1911 # This is a file/socket/fifo/device/etc, not a directory
1914 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1915 echo "Please investigate, remove it, and rerun abcde." >&2
1919 # It's a directory, let's see if it's writable by us
1920 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
1921 # Nope, complain and exit
1923 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
1924 echo "Please investigate, remove it, and rerun abcde." >&2
1928 # See if it's populated
1929 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1930 # Wipe and start fresh
1931 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1932 echo -n "this directory to continue. Continue [y/N]? " >&2
1933 if [ "$INTERACTIVE" = "y" ]; then
1939 if [ "$ANSWER" != "y" ]; then
1942 rm -rf "$ABCDETEMPDIR" || exit 1
1943 mkdir -p "$ABCDETEMPDIR"
1944 if [ "$?" -gt "0" ]; then
1945 # Directory already exists or could not be created
1946 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1950 # Everything is fine. Check for ^encodetracklocation-
1951 # and encode-output entries in the status file and
1952 # remove them. These are not relevant across sessions.
1953 if [ -f "$ABCDETEMPDIR/status" ]; then
1954 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1955 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1956 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1958 # Remove old error messages
1959 if [ -f "$ABCDETEMPDIR/errors" ]; then
1960 rm -f "$ABCDETEMPDIR/errors"
1964 # We are starting from scratch
1965 mkdir -p "$ABCDETEMPDIR"
1966 if [ "$?" -gt "0" ]; then
1967 # Directory already exists or could not be created
1968 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1971 cat /dev/null > "$ABCDETEMPDIR/status"
1972 # Store the abcde version in the status file.
1973 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1975 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1976 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1977 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1978 vecho "Creating cue file..."
1979 case $CDROMREADERSYNTAX in
1981 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
1982 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1984 log warning "the input flac file does not contain a cuesheet."
1988 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1989 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1991 log warning "reading the CUE sheet is still considered experimental"
1992 log warning "and there was a problem with the CD reading. abcde will continue,"
1993 log warning "but consider reporting the problem to the abcde author"
1999 # If we got the CDPARANOIA status and it is not recorded, save it now
2000 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2001 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2002 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2006 # Create the discid file
2007 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2008 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2009 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2014 # Create a proper CUE file based on the CUE file we created before.
2017 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2018 CUEFILE_OUT=$CUEFILE_IN.out
2019 ### FIXME ### checkstatus cddb
2020 if [ -e "$CDDBDATA" ]; then
2021 vecho "Adding metadata to the cue file..."
2022 # FIXME It doesn't preserve spaces! Why?
2023 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2025 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2026 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2027 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2031 cat "$CUEFILE_IN" | while read line
2033 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2034 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2035 # echo "$line" >> "$CUEFILE_OUT"
2036 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2037 eval track="\$TRACK$n"
2039 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2040 # When making a single-track rip, put the
2041 # actual file name into the file declaration
2042 # in the cue file so that it is usable by
2043 # music players and the like
2044 elif [ "$ONETRACK" = "y" ] &&
2045 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2047 TRACKFILE="$(mungefilename "$TRACKNAME")"
2048 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2049 ALBUMFILE="$(mungefilename "$DALBUM")"
2051 if [ "$VARIOUSARTISTS" = "y" ]; then
2052 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2054 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2057 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2060 # FIXME # If the lines above are uncommented, remove the line below.
2061 echo "$line" >> "$CUEFILE_OUT"
2064 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2065 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2071 # Parses a CDDB file and outputs the title and the track names.
2072 # Variables: CDDBFILE
2076 # List out disc title/author and contents
2077 if [ "$ONETRACK" = "y" ]; then
2078 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2080 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2081 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2082 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2083 if [ ! X"$PARSEDYEAR" = "X" ]; then
2084 echo "Year: $PARSEDYEAR"
2087 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2088 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2089 if [ ! X"$PARSEDGENRE" = "X" ]; then
2090 echo "Genre: $PARSEDGENRE"
2093 if [ ! "$ONETRACK" = "y" ]; then
2094 for TRACK in $(f_seq_row 1 $TRACKS)
2096 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2102 # Check for a local CDDB file, and report success
2105 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2107 CDDBLOCALSTATUS="notfound"
2108 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2111 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2112 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2113 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2114 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2115 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2116 CDDBLOCALMATCH=single
2117 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2118 CDDBLOCALMATCH=multiple
2123 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2124 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2125 CDDBLOCALMATCH=single
2130 # If the user has selected to check a local CDDB repo, we proceed with it
2131 case $CDDBLOCALMATCH in
2133 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2135 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2137 # List out disc title/author and contents
2138 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2139 cat "$RESULT" > "${CDDBLOCALREAD}"
2142 do_cddbparse "${CDDBLOCALREAD}"
2144 ##FIXME## QUICK HACK !!!!
2145 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2146 } >> "$ABCDETEMPDIR/cddblocalchoices"
2148 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2149 page "$ABCDETEMPDIR/cddblocalchoices"
2151 # It's all going to fit in one page, cat it
2152 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2154 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2155 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2156 CDDBLOCALCHOICENUM=-1
2157 if [ "$INTERACTIVE" = "y" ]; then
2158 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2159 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2160 read CDDBLOCALCHOICE
2161 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2162 # FIXME # Introduce diff's
2163 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2164 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2165 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2166 # Make sure we get a valid choice
2167 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2168 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2169 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2175 #echo "Selected ..."
2177 CDDBLOCALCHOICENUM=1
2179 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2180 #echo "Using local copy of CDDB data"
2181 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2182 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2183 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2184 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2185 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2186 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2187 CDDBLOCALSTATUS="found"
2189 #echo "Not using local copy of CDDB data"
2190 CDDBLOCALSTATUS="notfound"
2194 # List out disc title/author and contents
2195 do_cddbparse "${CDDBLOCALFILE}"
2196 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2197 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2199 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2201 if [ "$INTERACTIVE" = "y" ]; then
2203 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2204 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2207 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2211 if [ "$USELOCALRESP" = "y" ]; then
2212 #echo "Using local copy of CDDB data"
2213 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2214 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2215 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2216 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2217 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2218 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2219 CDDBLOCALSTATUS="single"
2221 #echo "Not using local copy of CDDB data"
2222 CDDBLOCALSTATUS="notfound"
2226 CDDBLOCALSTATUS="notfound"
2233 # Try to read CD-Text from the drive using icedax / cdda2wav
2236 if new_checkexec icedax; then
2237 CDTEXT_READER=icedax
2238 elif new_checkexec cdda2wav; then
2239 CDTEXT_READER=cdda2wav
2241 # Didn't find either, bail
2245 if [ "$CDROMID" = "" ]; then
2246 CDDA2WAVCDROM="$CDROM"
2248 CDDA2WAVCDROM="$CDROMID"
2251 # Do we have CD-Text on the disc (and can the drive read it?)
2252 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > $ABCDETEMPDIR/cd-text 2>&1
2253 grep -q '^CD-Text: detected' $ABCDETEMPDIR/cd-text
2255 if [ $ERRORCODE -ne 0 ]; then
2256 # No CD-Text found, bail
2260 rm -f "$ABCDETEMPDIR/cddbchoices"
2262 # Make an empty template
2263 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2264 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2265 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2266 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2267 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2268 ATITLE=$(grep -e '^Album title:' ${ABCDETEMPDIR}/cd-text | cut -c14- )
2269 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2270 # List out disc title/author and contents
2271 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2272 for TRACK in $(f_seq_row 1 $TRACKS)
2274 TRACKM1=$(($TRACK - 1))
2275 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2276 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2277 sed -i "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" $ABCDETEMPDIR/cddbread.1
2279 sed -i "s~^DTITLE=.*~DTITLE=${ATITLE}~" $ABCDETEMPDIR/cddbread.1
2280 echo >> "$ABCDETEMPDIR/cddbchoices"
2281 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2285 # Work with the musicbrainz WS API, then transform the results here so
2286 # they look (very) like the results from CDDB. Maybe not the best way
2287 # to go, but it Works For Me (TM)
2291 if checkstatus musicbrainz-readcomplete; then :; else
2292 vecho "Obtaining Musicbrainz results..."
2293 # If MB is to be used, interpret the query results and read all
2294 # the available entries.
2295 rm -f "$ABCDETEMPDIR/cddbchoices"
2296 CDDBCHOICES=1 # Overridden by multiple matches
2297 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2298 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir $ABCDETEMPDIR
2300 # The helper script will write disc matches out to
2301 # cddbread.*. Count how many we have
2302 NUM_RESPONSES=$(echo ${ABCDETEMPDIR}/cddbread.* | wc -w)
2303 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2305 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2306 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2307 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2308 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2309 ATITLE=$(grep -e '^DTITLE=' ${ABCDETEMPDIR}/cddbread.1 | cut -c8- )
2310 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2311 # List out disc title/author and contents
2312 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2313 for TRACK in $(f_seq_row 1 $TRACKS)
2315 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2317 echo >> "$ABCDETEMPDIR/cddbchoices"
2318 elif [ "$NUM_RESPONSES" -eq 0 ] ; then
2319 # No matches. Use the normal cddb template for the user to
2321 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2322 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2323 # List out disc title/author and contents of template
2324 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2326 for TRACK in $(f_seq_row 1 $TRACKS)
2328 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2330 echo >> "$ABCDETEMPDIR/cddbchoices"
2331 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2332 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2333 echo 503 > "$ABCDETEMPDIR/cddbquery"
2335 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2336 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2337 for file in $ABCDETEMPDIR/cddbread.*
2339 X=$(echo $file | sed 's/^.*cddbread\.//g')
2340 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2341 ATITLE=$(grep -e '^DTITLE=' ${ABCDETEMPDIR}/cddbread.$X | cut -c8- )
2342 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2343 # List out disc title/author and contents
2344 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2345 for TRACK in $(f_seq_row 1 $TRACKS)
2347 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2349 echo >> "$ABCDETEMPDIR/cddbchoices"
2351 echo "." >> "$ABCDETEMPDIR/cddbquery"
2353 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2360 # Perform CDDB protocol version check if it hasn't already been done
2361 if checkstatus cddb-statcomplete; then :; else
2362 if [ "$CDDBAVAIL" = "n" ]; then
2364 echo 503 > "$ABCDETEMPDIR/cddbstat"
2367 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2368 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2369 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2370 vecho "Checking CDDB server status..."
2371 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2372 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2373 case "$RESPONSECODE" in
2374 210) # 210 OK, status information follows (until terminating `.')
2377 501) # 501 Illegal CDDB protocol level: <n>.
2378 CDDBPROTO=`expr $CDDBPROTO - 1`
2380 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2381 # FreeDB TESTCD disc-id is used for query
2382 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2383 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2384 case "$RESPONSECODE" in
2385 2??) # Server responded, everything seems OK
2392 if test $rc -eq 1; then
2396 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2404 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2405 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2407 # Perform CDDB query if it hasn't already been done
2408 if checkstatus cddb-querycomplete; then :; else
2409 if [ "$CDDBAVAIL" = "n" ]; then
2411 echo 503 > "$ABCDETEMPDIR/cddbquery"
2412 # The default CDDBLOCALSTATUS is "notfound"
2413 # This part will be triggered if the user CDDB repo does not
2414 # contain the entry, or if we are not trying to use the repo.
2416 vecho "Querying the CDDB server..."
2417 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2418 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2419 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2425 # no match found in database,
2426 # wget/fetch error, or user requested not to use CDDB
2427 # Make up an error code (503) that abcde
2428 # will recognize in do_cddbread
2429 # and compensate by making a template
2430 echo 503 > "$ABCDETEMPDIR/cddbquery"
2432 *) # strange and unknown error
2433 echo ERRORCODE=$ERRORCODE
2434 echo "abcde: $CDDBTOOL returned unknown error code"
2438 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2445 # If it's not to be used, generate a template.
2446 # Then, display it (or them) and let the user choose/edit it
2447 if checkstatus cddb-readcomplete; then :; else
2448 vecho "Obtaining CDDB results..."
2449 # If CDDB is to be used, interpret the query results and read all
2450 # the available entries.
2451 rm -f "$ABCDETEMPDIR/cddbchoices"
2452 CDDBCHOICES=1 # Overridden by multiple matches
2453 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2454 case "$RESPONSECODE" in
2456 # One exact match, retrieve it
2457 # 200 [section] [discid] [artist] / [title]
2458 if checkstatus cddb-read-1-complete; then :; else
2459 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2460 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2461 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2462 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2463 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2465 # List out disc title/author and contents
2466 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2467 for TRACK in $(f_seq_row 1 $TRACKS)
2469 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2471 echo >> "$ABCDETEMPDIR/cddbchoices"
2475 case "$RESPONSECODE" in
2476 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2477 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2478 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2480 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2481 # List out disc title/author and contents of template
2482 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2484 for TRACK in $(f_seq_row 1 $TRACKS)
2486 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2488 echo >> "$ABCDETEMPDIR/cddbchoices"
2489 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2490 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2493 # Multiple exact, (possibly multiple) inexact matches
2495 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2496 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2497 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2498 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2499 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2501 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2503 vecho -n "Retrieving multiple matches... "
2504 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2505 read DISCINFO # eat top line
2509 if checkstatus cddb-read-$X-complete; then :; else
2510 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2511 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2513 # List out disc title/author and contents
2514 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2515 for TRACK in $(f_seq_row 1 $TRACKS)
2517 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2519 echo >> "$ABCDETEMPDIR/cddbchoices"
2522 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2526 for TRACK in $(f_seq_row 1 $TRACKS)
2528 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2530 echo >> "$ABCDETEMPDIR/cddbchoices"
2531 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2532 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2535 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2542 if checkstatus cddb-edit >/dev/null; then
2543 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2544 VARIOUSARTISTS="$(checkstatus variousartists)"
2545 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2548 if [ "$INTERACTIVE" = "y" ]; then
2549 # We should show the CDDB results both when we are not using the local CDDB repo
2550 # or when we are using it but we could not find a proper match
2551 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2552 # Display the $ABCDETEMPDIR/cddbchoices file created above
2553 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2554 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2555 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2556 CHOICE=$(checkstatus cddb-choice)
2557 if [ -n "$CHOICE" ] ; then
2558 case $CDDBCHOICES in
2559 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2560 log error "CDDB query failed!"
2563 cat "$ABCDETEMPDIR/cddbchoices"
2566 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2568 echo "Selected: #$CHOICE"
2569 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2573 # The user has a choice to make, display the info in a pager if necessary
2574 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2575 page "$ABCDETEMPDIR/cddbchoices"
2577 # It's all going to fit in one page, cat it
2578 cat "$ABCDETEMPDIR/cddbchoices" >&2
2582 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2584 # I'll take CDDB read #3 for $400, Alex
2585 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2586 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2588 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2589 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2590 if [ ! X"$DIFF" = "X" ]; then
2591 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2592 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2593 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2594 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2595 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2596 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2598 # We parse the 2 choices to diff, store them in temporary files and diff them.
2599 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2600 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2602 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2603 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2604 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2605 page "$ABCDETEMPDIR/cddbread.diff"
2607 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2611 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2613 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2614 # Make sure we get a valid choice
2615 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2616 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2617 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2621 if [ "$CDCHOICENUM" = "0" ]; then
2622 vecho "Creating empty CDDB template..."
2624 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2626 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2627 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2629 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2633 # We need some code to show the selected option when local repository is selected and we have found a match
2634 vecho "Using cached CDDB match..." >&2
2635 # Display the $ABCDETEMPDIR/cddbchoices file created above
2636 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2637 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2638 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2639 CHOICE=$(checkstatus cddb-choice)
2640 if [ "$USELOCALRESP" = "y" ]; then :; else
2641 if [ -n "$CHOICE" ] ; then
2642 case $CDDBCHOICES in
2645 echo "Selected template."
2647 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2649 echo "Selected: #$CHOICE"
2650 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2658 # We're noninteractive - pick the first choice.
2659 # But in case we run a previous instance and selected a choice, use it.
2660 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2661 # Show the choice if we are not using the locally stored one
2662 # or when the local search failed to find a match.
2663 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2664 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2665 #if [ "$PREVIOUSCHOICE" ]; then
2666 cat "$ABCDETEMPDIR/cddbchoices"
2669 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2670 CDCHOICENUM=$PREVIOUSCHOICE
2673 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2675 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2680 if checkstatus cddb-choice >/dev/null; then :; else
2681 echo "abcde: internal error: cddb-choice not recorded." >&2
2684 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2685 echo -n "Edit selected CDDB data? [y/n] (" >&2
2686 if [ "$INTERACTIVE" = "y" ]; then
2687 if [ "$UNKNOWNDISK" = "y" ]; then
2690 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2699 if [ "$EDITCDDB" = "y" ]; then
2700 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2702 # Use the debian sensible-editor wrapper to pick the editor that the
2703 # user has requested via their $EDITOR environment variable
2704 if [ -x "/usr/bin/sensible-editor" ]; then
2705 /usr/bin/sensible-editor "$CDDBDATA"
2706 elif [ -n "$EDITOR" ]; then
2707 if [ -x $(which "${EDITOR%%\ *}") ]; then
2708 # That failed, try to load the preferred editor, starting
2709 # with their EDITOR variable
2710 eval $(echo "$EDITOR") \"$CDDBDATA\"
2712 # If that fails, check for a vi
2713 elif which vi >/dev/null 2>&1; then
2715 elif [ -x /usr/bin/vim ]; then
2716 /usr/bin/vim "$CDDBDATA"
2717 elif [ -x /usr/bin/vi ]; then
2718 /usr/bin/vi "$CDDBDATA"
2719 elif [ -x /bin/vi ]; then
2721 # nano should be on all (modern, i.e., sarge) debian systems
2722 elif which nano >/dev/null 2>&1 ; then
2724 elif [ -x /usr/bin/nano ]; then
2725 /usr/bin/nano "$CDDBDATA"
2726 # mg should be on all OpenBSD systems
2727 elif which mg >/dev/null 2>&1 ; then
2729 elif [ -x /usr/bin/mg ]; then
2730 /usr/bin/mg "$CDDBDATA"
2733 log warning "no editor available. Check your EDITOR environment variable."
2735 # delete editor backup file if it exists
2736 if [ -w "$CDDBDATA~" ]; then
2741 # Some heuristics first. Look at Disc Title, and if it starts with
2742 # "Various", then we'll assume Various Artists
2743 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2744 echo "Looks like a Multi-Artist CD" >&2
2747 echo -n "Is the CD multi-artist [y/N]? " >&2
2748 if [ "$INTERACTIVE" = "y" ]; then
2755 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2758 # Need NUMTRACKS before cddb-tool will return it:
2759 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2760 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2761 # More than 1/2 tracks contain a "/", so guess forward
2763 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2764 # More than 1/2 contain a "-", so guess forward-dash
2766 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2767 # More than 1/2 contain something in parens, so guess trailing-paren
2771 echo "1) Artist / Title" >&2
2772 echo "2) Artist - Title" >&2
2773 echo "3) Title / Artist" >&2
2774 echo "4) Title - Artist" >&2
2775 echo "5) Artist: Title" >&2
2776 echo "6) Title (Artist)" >&2
2777 echo "7) This is a single-artist CD" >&2
2778 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2779 if [ "$INTERACTIVE" = "y" ]; then
2780 read VARIOUSARTISTSTYLE
2782 echo $DEFAULTSTYLE >&2
2783 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2785 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2786 # If they press Enter, then the default style (0) was chosen
2787 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2788 echo "Invalid selection. Please choose a number between 1 and 7."
2789 echo -n "Selection [1-7]: "
2790 read VARIOUSARTISTSTYLE
2791 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2793 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2794 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2796 vecho "Selected: $VARIOUSARTISTSTYLE"
2797 case "$VARIOUSARTISTSTYLE" in
2799 VARIOUSARTISTSTYLE=forward
2802 VARIOUSARTISTSTYLE=forward-dash
2805 VARIOUSARTISTSTYLE=reverse
2808 VARIOUSARTISTSTYLE=reverse-dash
2811 VARIOUSARTISTSTYLE=colon
2814 VARIOUSARTISTSTYLE=trailing-paren
2822 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2823 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2825 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2826 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2827 # This works but does not have the necessary error checking
2828 # yet. If you are familiar with the CDDB spec
2829 # (see http://www.freedb.org/src/latest/DBFORMAT)
2830 # and can create an error-free entry on your own, then put
2831 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2832 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2833 # your abcde.conf to change the email address submissions are
2836 # submit the modified file, if they want
2837 if [ "$NOSUBMIT" != "y" ]; then
2838 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2840 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2841 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2843 echo -n 'Invalid selection. Please answer "y" or "n": '
2846 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2847 echo -n "Sending..."
2848 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2855 # User CDDBLOCALPOLICY to find out if we store the file or not...
2856 # Cache edited CDDB entry in the user's cddb dir
2857 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2858 # Make sure the cache directory exists
2859 mkdir -p $CDDBLOCALDIR
2860 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2863 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2866 # do_cdread [tracknumber]
2867 # do_cdread onetrack [firsttrack] [lasttrack]
2871 # The commands here don't go through run_command because they're never supposed to be silenced
2872 # return codes need to be doublechecked anyway, however
2873 if [ "$1" = "onetrack" ]; then
2874 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2875 # FIXME # Until then, we grab the whole CD in one track, no matter what
2877 # We need the first and last track for cdda2wav/icedax
2879 LASTTRACK=$(expr $3 + 0)
2880 UTRACKNUM=$FIRSTTRACK
2881 case "$CDROMREADERSYNTAX" in
2882 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2885 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
2886 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2887 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
2888 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2894 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2895 if [ "$USEPIPES" = "y" ]; then
2896 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
2897 FILEARG="$( eval echo "\$$TEMPARG" )"
2899 PIPE_MESSAGE="and encoding "
2901 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2902 case "$CDROMREADERSYNTAX" in
2903 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2905 FILEARG="--output-name=$WAVDATA"
2908 FILEARG="-f $WAVDATA"
2916 if [ "$1" = "onetrack" ]; then
2917 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2919 if [ -r "$CDDBDATA" ]; then
2920 getcddbinfo TRACKNAME
2921 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2923 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2926 case "$CDROMREADERSYNTAX" in
2927 ### FIXME ### use an exception for flac, since it uses -o
2928 ### FIXME ### Shall we just use -o $FILEARG ??
2930 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2931 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
2932 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2934 if [ "$REDIR" = "y" ]; then
2935 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
2937 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
2941 if [ "$OSFLAVOUR" = "OSX" ] ; then
2942 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2943 diskutil unmount ${CDROM#/dev/} 0
2944 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2945 CDDA2WAVCDROM="IODVDServices"
2946 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2947 CDDA2WAVCDROM="$CDROMID"
2949 if [ "$CDROMID" = "" ]; then
2950 CDDA2WAVCDROM="$CDROM"
2952 CDDA2WAVCDROM="$CDROMID"
2955 if [ "$REDIR" = "y" ]; then
2956 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
2958 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
2960 ## FIXME ## We have an exception for dagrab, since it uses -f
2961 ## FIXME ## Shall we just use -f $FILEARG ??
2963 if [ "$REDIR" = "y" ]; then
2964 nice $READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG" >&2
2966 nice $READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG"
2969 # Find the track's mounted path
2970 REALTRACKNUM=$(expr $UTRACKNUM + 0)
2971 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
2972 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2973 # If the file exists, copy it
2974 if [ -e "$FILEPATH" ] ; then
2975 if [ "$REDIR" = "y" ]; then
2976 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
2978 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
2984 if [ "$REDIR" = "y" ]; then
2985 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
2987 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
2991 # If we get some error or we get some missing wav
2992 # (as long as we dont use pipes)
2993 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
2994 # Thank goodness errors is only machine-parseable up to the
2995 # first colon, otherwise this woulda sucked
2996 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2997 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2999 if [ "$USEPIPES" = "y" ]; then
3000 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3002 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3006 if [ "$USEPIPES" = "y" ]; then
3007 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3009 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3011 if [ "$1" = "onetrack" ]; then
3012 echo onetrack >> "$ABCDETEMPDIR/status"
3018 # No values accepted, only uses env variables
3021 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3022 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3024 echo "abcde: unable to set the device speed" >&2
3030 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3033 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3035 warning) shift ; log warning "$@" ;;
3043 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3046 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3048 warning) shift ; log warning "$@" ;;
3056 # decho outputs a debug message if DEBUG is selected
3059 if [ x"$DEBUG" != "x" ]; then
3060 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3061 DEBUGECHO=$(echo "$@" | tr -d '[]')
3062 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3069 # User-redefinable functions
3070 # Custom filename munging:
3073 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
3074 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
3077 # Custom genre munging:
3080 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3084 # Empty pre_read function, to be defined in the configuration file.
3091 # Empty post_read function, to be defined in the configuration file.
3098 # Empty post_encode function, to be defined in the configuration file.
3104 ###############################################################################
3107 # Start of execution
3108 ###############################################################################
3113 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3115 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3116 CDDBSUBMIT=freedb-submit@freedb.org
3118 HELLOINFO="$(whoami)@$(hostname)"
3120 CDDBLOCALPOLICY="always"
3121 CDDBLOCALRECURSIVE="y"
3122 CDDBLOCALDIR="$HOME/.cddb"
3125 # List of fields we parse and show during the CDDB parsing...
3126 SHOWCDDBFIELDS="year,genre"
3129 #CDROMREADERSYNTAX=cdparanoia
3130 ENCODERSYNTAX=default
3132 MP3ENCODERSYNTAX=default
3133 OGGENCODERSYNTAX=default
3134 FLACENCODERSYNTAX=default
3135 SPEEXENCODERSYNTAX=default
3136 MPPENCODERSYNTAX=default
3137 AACENCODERSYNTAX=default
3138 NORMALIZERSYNTAX=default
3139 CUEREADERSYNTAX=default
3141 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3142 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3143 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3144 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3145 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3146 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3147 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3148 PLAYLISTDATAPREFIX=''
3149 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3150 VAPLAYLISTDATAPREFIX=''
3158 VARIOUSARTISTSTYLE=forward
3165 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3166 # i.e. CDROMID="1,0,0"
3168 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3169 # If we are using the ide-scsi emulation layer, we need to define a "g"
3170 CDPARANOIACDROMBUS="d"
3172 # program paths - defaults to checking your $PATH
3179 XINGMP3ENC=xingmp3enc
3196 VORBISCOMMENT=vorbiscomment
3199 ATOMICPARSLEY=AtomicParsley
3201 CDPARANOIA=cdparanoia
3207 MUSICBRAINZ=abcde-musicbrainz-tool
3211 NORMALIZE=normalize-audio
3213 VORBISGAIN=vorbisgain
3221 # Options for programs called from abcde
3234 VORBISGAINOPTS="--album"
3237 FLACGAINOPTS="--add-replay-gain"
3259 VORBISCOMMENTOPTS="-R"
3260 METAFLACOPTS="--no-utf8-convert"
3263 # Default to one process if -j isn't specified
3266 # List of actions to perform - by default, run to completion
3267 ACTIONS=cddb,read,encode,tag,move,clean
3269 # This option is basicaly for Debian package dependencies:
3270 # List of prefered outputs - by default, run with whatever we have in the path
3271 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac
3273 # List of prefered cdromreaders - by default, run whichever we have in the path
3274 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav"
3276 # List of quality levels associated with the encoders:
3277 DEFAULT_QUALITY_XLO="oggenc:-q -1,lame:-q 9,speex:--quality 1,m4a:"
3278 DEFAULT_QUALITY_LO="oggenc:-q 1,lame:-q 7,speex:--quality 5,m4a:"
3279 DEFAULT_QUALITY_HI="oggenc:-q 7,lame:--preset standard,speex:--quality 9,m4a:"
3280 DEFAULT_QUALITY_XHI="oggenc:-q 10,lame:--preset extreme,speex:--quality 10,m4a:"
3282 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3283 # Linux/OpenBSD. ftp is user for NetBSD.
3284 # Let's use these checkings to determine the OS flavour, which will be used
3286 if [ X$(uname) = "XFreeBSD" ] ; then
3291 elif [ X$(uname) = "XDarwin" ] ; then
3294 # We should have diskutil in OSX, but let's be sure...
3296 CDROMREADERSYNTAX=cddafs
3297 elif [ X$(uname) = "XOpenBSD" ] ; then
3301 elif [ X$(uname) = "XNetBSD" ] ; then
3305 elif [ X$(uname) = "SunOS" ] ; then
3313 # If CDDBAVAIL is set to n, no CDDB read is done
3314 # If USEID3 is set to n, no ID3 tagging is done
3320 # But before we get into business, let us chop off any GREP environmental
3325 if [ -z "$OUTPUTDIR" ]; then
3329 if [ -z "$WAVOUTPUTDIR" ]; then
3330 WAVOUTPUTDIR="$OUTPUTDIR"
3333 # Load system defaults
3334 if [ -r /etc/abcde.conf ]; then
3337 # Load user preference defaults
3338 if [ -r $HOME/.abcde.conf ]; then
3342 # By this time, we need some HTTPGETOPTS already defined.
3343 # If the user has defined a non-default HTTPGET method, we should not be empty.
3345 if [ "$HTTPGETOPTS" = "" ] ; then
3347 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3348 curl) HTTPGETOPTS="-f -s";;
3349 fetch)HTTPGETOPTS="-q -o -";;
3350 ftp) HTTPGETOPTS="-a -V -o - ";;
3351 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3355 # If the CDROM has not been set yet, find a suitable one.
3356 # If this is a devfs system, default to /dev/cdroms/cdrom0
3357 # instead of /dev/cdrom
3358 if [ "$CDROM" = "" ] ; then
3359 if [ -e /dev/cdroms/cdrom0 ]; then
3360 CDROM=/dev/cdroms/cdrom0
3361 elif [ -e /dev/cdrom ]; then
3363 elif [ -e /dev/sr0 ]; then
3365 elif [ -e /dev/cd0c ]; then
3367 elif [ -e /dev/acd0c ]; then
3369 elif [ -e /dev/disk1 ]; then
3371 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part.*(disk.)$'\n' ]]; then
3372 CDROM=/dev/${BASH_REMATCH[1]}
3376 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3377 # that's changed to a number to allow for more control. If
3378 # EXTRAVERBOSE=y, set it to 1 for backwards compatibility.
3379 if [ "$EXTRAVERBOSE" = "y" ]; then
3382 if [ "$EXTRAVERBOSE" = "n" ]; then
3386 # Parse command line options
3387 #while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPq:r:Rs:S:t:T:vVxw:W: opt ; do
3388 while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPq:r:s:S:t:T:UvVxX:w:W:z opt ; do
3391 a) ACTIONS="$OPTARG" ;;
3392 A) EXPACTIONS="$OPTARG" ;;
3394 B) NOBATCHREPLAYGAIN=y ;;
3395 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3396 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3397 d) CDROM="$OPTARG" ;;
3400 e) ERASEENCODEDSTATUS=y ;;
3401 E) ENCODING="$OPTARG" ;;
3405 j) MAXPROCS="$OPTARG" ;;
3408 L) CDDBUSELOCAL=y ;;
3413 o) OUTPUTTYPE="$OPTARG" ;;
3416 q) QUALITYLEVEL="$OPTARG" ;;
3417 r) REMOTEHOSTS="$OPTARG" ;;
3418 R) CDDBLOCALRECURSIVE=y ;;
3419 s) SHOWCDDBFIELDS="$OPTARG" ;;
3420 S) CDSPEEDVALUE="$OPTARG" ;;
3421 t) STARTTRACKNUMBER="$OPTARG" ;;
3422 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3425 echo "This is abcde v$VERSION."
3426 echo "Usage: abcde [options] [tracks]"
3427 echo "abcde -h for extra help"
3430 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3432 X) CUE2DISCID="$OPTARG" ;;
3433 w) COMMENT="$OPTARG" ;;
3434 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3435 STARTTRACKNUMBER="${OPTARG}01"
3436 STARTTRACKNUMBERTAG="y"
3437 COMMENT="CD${OPTARG}"
3438 DISCNUMBER="${OPTARG}"
3440 log error "argument of -W must be integer"
3444 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3449 shift $(($OPTIND - 1))
3451 # Here it comes the worse part of the whole thing. From here until we start
3452 # ripping, we have a mixture of sanity checks, verifications, default settigs
3453 # and other crazy stuff that interdepends, but hey, someone has to do it.
3455 # If NOCDDBQUERY is set, don't query the CDDB server.
3456 if [ "$NOCDDBQUERY" = "y" ]; then
3460 # If the user specified a flac file, then switch to special flac mode
3461 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3462 if [ ! -f "$CDROM" ]; then
3463 log error "the defined file for FLAC ripping cannot be found" >&2
3466 vecho warning "switching to flac CDROMREADERSYNTAX..."
3467 CDROMREADERSYNTAX=flac
3468 # We have a builtin version of cue2discid...
3469 case "$CUE2DISCID" in
3471 *) NEEDCUE2DISCID=y;;
3477 # If the user provided a DISCID, disable eject
3478 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3480 # Check the available cd rippers in the system, from the ones we know.
3481 if [ "$CDROMREADERSYNTAX" = "" ]; then
3482 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3483 if new_checkexec $DEFAULT_CDROMREADER; then
3484 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3488 if [ "$CDROMREADERSYNTAX" = "" ]; then
3489 log error "no cdreader found in your PATH"
3490 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3495 # Decide if we can continue.
3496 if [ "$ONETRACK" = "y" ]; then
3497 # FIXME # remove check as soon as we find out about the other readers
3498 case "$CDROMREADERSYNTAX" in
3501 cdda2wav | icedax) ;;
3502 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3505 if [ "$BATCHNORM" = "y" ]; then
3506 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3509 if [ "$NOGAP" = "y" ]; then
3510 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3513 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3514 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3515 if [ $# -gt 0 ]; then
3516 log warning "ONETRACK mode selected, grabbing all tracks..."
3519 while [ $# -gt 0 ]; do
3520 # Range parsing code courtesy of Vincent Ho
3521 # Cleaned up to use shell built-ins by Charles Steinkuehler
3522 if [ "${1#*[^0-9-]}" != "$1" ]; then
3523 log error "syntax error while processing track numbers ($1)"
3528 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3529 TRACKQUEUE="$TRACKQUEUE $RSTART"
3530 RSTART=$(( $RSTART + 1 ))
3537 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3538 # List of experimental actions: retag,transcode
3540 # Determine what actions are to be done from $ACTIONS and set the
3541 # following environment variables for them:
3553 ## FIXME ## Lets keep compatibility with -M
3554 [ "$DOCUE" != "y" ] && DOCUE=n
3556 for ACTION in $(echo $ACTIONS | tr , \ )
3559 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
3560 cue) DOCUE=y ; MAKECUEFILE=y ;;
3563 normalize) DONORMALIZE=y; DOREAD=y;;
3564 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3565 encode) DOENCODE=y; DOREAD=y;;
3566 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3567 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3568 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3569 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
3570 playlist) DOCDDB=y; DOPLAYLIST=y;;
3575 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3576 # FIXME # should we abort on error or just inform the user?
3577 log warning "selected both normalize and replaygain actions"
3580 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
3581 case $SHOWCDDBFIELD in
3582 y*|Y*) SHOWCDDBYEAR="y";;
3583 g*|G*) SHOWCDDBGENRE="y";;
3588 # At this point a CDROM has to be defined, so we check it exists.
3589 if [ X"$CDROM" != "X" ] ; then
3590 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
3591 if [ "$OSFLAVOUR" = "FBSD" ]; then
3592 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
3593 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
3594 log error "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
3598 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
3599 log error "CDROM device cannot be found."
3602 # avoid processing if we are not going to hit the CDROM.
3603 elif [ X"$DOREAD" = "Xy" ]; then
3604 log error "CDROM has not been defined or cannot be found"
3608 # USEPIPES pre-tests, before we get into more serious stuff
3609 # Not compatible with:
3610 # - multiple outputs
3612 # - lowdisk algorithm
3614 if [ X"$USEPIPES" = "Xy" ]; then
3615 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
3616 log error "Unix pipes not compatible with multiple outputs"
3619 if [ X"$DONORMALIZE" = "Xy" ]; then
3620 log error "Unix pipes not compatible with normalizer"
3621 # FIXME # Do we need to exit or shall we just disable the mode?
3624 if [ X"$BATCHNORM" = "Xy" ]; then
3625 log error "Unix pipes not compatible with BATCHNORM encoding"
3628 if [ X"$NOGAP" = "Xy" ]; then
3629 log error "Unix pipes not compatible with NOGAP encoding"
3632 if [ X"$DOENCODE" = "Xn" ]; then
3633 vecho warning "Disabling Unix pipes since we are not encoding!"
3636 if [ X"$LOWDISK" = "Xy" ]; then
3637 log error "Unix pipes not compatible with lowdisk algorithm"
3642 # LOWDISK pre-tests, before we get into more problematic stuff
3643 # Not compatible with anything that needs all the files in the hard disc:
3646 if [ X"$LOWDISK" = "Xy" ]; then
3647 if [ X"$BATCHNORM" = "Xy" ]; then
3648 log error "Unix pipes not compatible with BATCHNORM encoding"
3651 if [ X"$NOGAP" = "Xy" ]; then
3652 log error "Unix pipes not compatible with NOGAP encoding"
3657 # BATCHNORM pre-tests, before we get into serious problems
3658 # Not compatible with
3659 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3660 vecho warning "Disabling BATCHNORM since we are not normalizing!"
3664 # Check the encoding format from the ones available in the system, if nothing has been configured.
3665 if [ X"$OUTPUTTYPE" = "X" ]; then
3666 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
3667 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3668 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3669 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
3670 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
3671 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3675 if [ X"$OUTPUTTYPE" = "X" ]; then
3676 log error "no encoder found in the PATH"
3677 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3682 # Decide which CDROM reader we're gonna use
3683 case "$CDROMREADERSYNTAX" in
3685 CDROMREADER="$CDPARANOIA"
3686 CDROMREADEROPTS="$CDPARANOIAOPTS"
3689 CDROMREADER="$CDDA2WAV"
3690 CDROMREADEROPTS="$CDDA2WAVOPTS"
3693 CDROMREADER="$DAGRAB"
3694 CDROMREADEROPTS="$DAGRABOPTS"
3697 CDROMREADER="$CDDAFS"
3698 CDROMREADEROPTS="$CDDAFSOPTS"
3702 CDROMREADEROPTS="$FLACOPTS"
3706 # There's only one normalize...
3707 case "$NORMALIZERSYNTAX" in
3709 NORMALIZER="$NORMALIZE"
3710 NORMALIZEROPTS="$NORMALIZEOPTS"
3714 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3715 if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
3716 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr \ \|| tr , \ | tr \| \ )"; do
3718 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3719 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3720 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3721 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3722 mpc:*) MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3723 m4a:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3726 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
3727 TEMPOUTPUT=$( echo "$OUTPUT" | cut -d: -f1 )
3728 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
3730 OUTPUTTYPE="$TEMPOUTPUTTYPE"
3733 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
3734 # for flacs and speexenc for speex and mppenc for mpps and faac for m4as
3736 # Getting ready for multiple output changes
3737 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3741 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
3742 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
3743 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
3744 OGGOUTPUTCONTAINER=ogg
3747 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
3748 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
3749 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
3752 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
3753 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
3754 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
3755 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
3758 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
3759 # [ "$DOREPLAYGAIN" = "y" ] &&
3762 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
3763 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN=y
3766 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
3767 [ "$DOTAG" = "y" ] && CHECKATOMICPARSLEY=y
3770 if [ "$KEEPWAVS" = "y" ]; then
3771 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
3775 *) log error "Invalid OUTPUTTYPE defined"
3781 # decide which encoder
3782 case "$MP3ENCODERSYNTAX" in
3784 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
3788 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
3789 MP3ENCODER="$TOOLAME"
3792 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
3796 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
3797 MP3ENCODER="$BLADEENC"
3800 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
3804 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
3805 MP3ENCODER="$XINGMP3ENC"
3808 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
3809 MP3ENCODER="$MP3ENC"
3812 case "$OGGENCODERSYNTAX" in
3814 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
3815 OGGENCODER="$VORBIZE"
3818 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
3819 OGGENCODER="$OGGENC"
3822 case "$FLACENCODERSYNTAX" in
3824 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
3826 if [ "$DOREPLAYGAIN" = "y" ]; then
3827 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
3829 # FLAC streams can be encapsulated on a Ogg transport layer
3830 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
3831 log error "FLAC on an Ogg container is not yet supported"
3832 log error "due to problem with adding comments to such files"
3834 FLACOUTPUTCONTAINER=ogg
3836 FLACOUTPUTCONTAINER=flac
3840 case "$SPEEXENCODERSYNTAX" in
3842 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
3843 SPEEXENCODER="$SPEEXENC"
3846 case "$MPPENCODERSYNTAX" in
3848 MPPENCODEROPTS="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
3849 MPPENCODER="$MPPENC"
3852 case "$AACENCODERSYNTAX" in
3854 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
3855 AACENCODER="$AACENC"
3860 if [ "$ID3TAGV" = "1" ]; then
3862 TAGGEROPTS="$ID3OPTS"
3865 TAGGEROPTS="$ID3V2OPTS"
3868 # NOGAP is specific to lame. Other encoders fail ...
3869 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
3870 log warning "the NOGAP option is specific to lame. Deactivating..."
3875 case "$CUEREADERSYNTAX" in
3877 CUEREADEROPTS="${CDROM}"
3882 # which information retrieval tool are we using?
3888 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
3889 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
3890 log error "FLAC on an Ogg container is not yet supported"
3891 log error "due to problem with adding comments to such files"
3893 OGGOUTPUTCONTAINER=ogg.ogg
3894 FLACOUTPUTCONTAINER=flac.ogg
3895 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
3898 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
3900 if [ "$ENCNICE" ]; then
3901 ENCNICE="-n $ENCNICE"
3903 if [ "$READNICE" ]; then
3904 READNICE="-n $READNICE"
3906 if [ "$DISTMP3NICE" ]; then
3907 DISTMP3NICE="-n $DISTMP3NICE"
3910 # Don't check for stuff if it's not needed
3911 if [ "$REMOTEHOSTS" ]; then
3914 if [ "$DONORMALIZE" = "y" ]; then
3917 if [ "$EJECTCD" = "y" ]; then
3920 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
3921 if [ "$CDDBMETHOD" = "cddb" ]; then
3923 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
3927 if [ "$DOCUE" = "y" ]; then
3931 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
3932 case "$CDROMREADERSYNTAX" in
3933 cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
3934 ### FIXME ### translate "cue2discid" from python to bash
3935 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
3940 ###USEPIPESSUPPORT###
3942 # Rippers with USEPIPE support
3943 # FIXME # Include here all the rippers we can figure out support pipes
3944 PIPERIPPER_cdparanoia="-"
3945 PIPERIPPER_debug="-"
3946 PIPERIPPER_flac="-c "
3948 # Encoders with USEPIPE support
3949 # FIXME # Include here all the encoders we can figure out support pipes
3955 # Figure out if we can use pipes with the ripper/encoder combination
3957 if [ "$USEPIPES" = "y" ]; then
3958 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
3961 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
3963 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
3965 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
3967 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
3969 PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
3971 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
3972 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
3973 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
3974 log error "no support for pipes with given ripper"
3975 log error "read the USEPIPES file from the source tarball to get help."
3976 log error "On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
3979 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
3980 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
3981 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
3982 log error "no support for pipes with given encoder"
3983 log error "read the USEPIPES file from the source tarball to help"
3984 log error "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
3989 # Make sure a buncha things exist
3990 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
3991 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3992 $AACENCODER $CDDBTOOL \
3993 ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
3994 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3995 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3996 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
3997 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
3998 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
3999 ${NEEDMPPGAIN+$MPPGAIN} ${NEEDCUEREADER+$CUEREADER} \
4000 ${NEEDCUE2DISCID+$CUE2DISCID}
4005 if [ "$CHECKATOMICPARSLEY" = "y" ]; then
4006 if ! new_checkexec "$ATOMICPARSLEY"; then
4007 echo "WARNING: $ATOMICPARSLEY Not Found Not Post-Tagging!"
4010 echo "Using $ATOMICPARSLEY To Tag AAC Tracks."
4014 # And last but not least, check if we can diff between files. We do not abort,
4015 # since diffing is not critical...
4016 if [ -x $(which $DIFF) ]; then :; else
4017 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4021 ## Now that we have metaflac, check if we need cue2discid
4022 #case $CDROMREADERSYNTAX in
4024 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4025 # if [ "$TRACKINFO" = "" ]; then
4026 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4031 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4032 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4033 HTTPGET="$HTTPGET $HTTPGETOPTS"
4035 # Here it used to say:
4036 # One thousand lines in, we can start doing stuff with things
4037 # Well, right now we are at line 3737 ;)
4039 # Export needed things so they can be read in this subshell
4040 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4041 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4043 if [ "$DOREAD" = "y" ]; then
4044 # User-definable function to set some things. Use it for
4045 # - closing the CD tray with eject -t
4046 # - set the CD speed value with eject -x
4047 vecho -n "Executing customizable pre-read function... "
4049 pre_read # Execute the user-defined pre-read funtion. Close the CD with it.
4054 # Get ABCDETEMPDIR created and status file initialized
4057 if [ "$DOCDDB" = "y" ]; then
4058 # start with a sane default:
4059 CDDBLOCALSTATUS=notfound
4060 if [ $CDDBUSELOCAL = "y" ]; then
4063 if checkstatus cddb-choice > /dev/null; then
4066 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4067 case "$CDDBMETHOD" in
4078 CHOICE=$(checkstatus cddb-choice)
4079 if [ $CHOICE = 0 ] ; then
4080 # We don't have any information at all; try to fall back
4081 # to CD-Text for basic information
4082 vecho "No CDDB information found, trying cdtext from the CD"
4088 eval "$($CDDBTOOL parse "$CDDBDATA")"
4091 # Before reading tracks, we set the speed of the device
4093 if [ X"$CDSPEEDVALUE" != "X" ]; then
4094 case "$CDROMREADERSYNTAX" in
4095 cdparanoia|debug) ;;
4101 # Define the first and last track, since we might need them later in several places
4102 FIRSTTRACK=$( get_first $TRACKQUEUE )
4103 LASTTRACK=$( get_last $TRACKQUEUE )
4105 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4106 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4107 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4108 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4111 if checkstatus onetrack ; then ONETRACK=y ; fi
4113 if [ "$ONETRACK" = "y" ]; then
4114 # Reuse the CUEFILE in case we created it (now or in a previous run)
4115 if CUEFILE=$(checkstatus cuefile); then
4120 # Create playlist if needed (backgroundable) and start reading in tracks
4124 if [ ! "$ONETRACK" = "y" ]; then
4125 if [ "$DOPLAYLIST" = "y" ]; then
4126 echo Creating playlist... >&2
4131 # For the lowdisk option, only one program is running at once so the encoder
4132 # can be unsilenced right away.
4133 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4134 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4137 if [ "$ONETRACK" = "y" ]; then
4138 TRACKS="$FIRSTTRACK"
4139 if [ "$USEPIPES" = "y" ]; then
4140 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4141 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4144 if checkstatus readtrack-$FIRSTTRACK; then :; else
4145 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4149 for UTRACKNUM in $TRACKQUEUE
4151 if [ "$DOREAD" = "y" ]; then
4152 if [ "$USEPIPES" = "y" ]; then
4153 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4154 # Read, pipe, shut up!
4155 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4158 if checkstatus readtrack-$UTRACKNUM; then :; else
4159 do_cdread $UTRACKNUM
4161 if [ "$?" != "0" ]; then
4162 # CD read failed - don't give the goahead to
4169 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4172 # If we are not reading, set the encode output to loud already, so
4173 # that we can see the output of the first track.
4174 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4175 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4177 echo NEXTTRACK # Get the encoder machine churning again
4178 if [ "$DOREAD" = "y" ]; then
4179 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4180 until checkstatus encodetrack-$UTRACKNUM
4182 if checkerrors encodetrack-$UTRACKNUM; then
4193 # Now that we're done the encoding can be loud again -
4194 # if we're not using SMP.
4195 if [ "$MAXPROCS" = "1" ]; then
4196 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4199 # All tracks read, start encoding.
4200 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4204 # Execute the user-defined post_read funtion before ejecting CD
4207 # We are now finished with the cdrom - it can be safely ejected. Note that
4208 # abcde will not have completed yet.
4209 if [ "$EJECTCD" = "y" ] && [ -x $(which $EJECT) ]; then
4210 # We check if the disk we are processing is actually the disk inside the
4211 # CD tray. If not, we do not eject the CD, since it might be so that the
4212 # user ejected it manually.
4213 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4214 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4215 # More FreeBSD bits.
4216 if [ X"$(uname)" = X"FreeBSD" ] ; then
4217 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4218 # but in this script EJECT is in the envionment and names the program
4221 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4222 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4223 $eject $EJECTOPTS $cd
4224 elif [ X"$(uname)" = X"Darwin" ] ; then
4225 diskutil eject ${CDROM#/dev/} 0
4227 $EJECT $EJECTOPTS "$CDROM"
4234 ## Do we need to pre-process
4235 #if [ x"$PREPROCESS" = "x" ] ; then
4238 # for PRETRACKNUM in $TRACKQUEUE
4241 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4243 # until [ $PREPROCEED ]
4245 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4246 # # all locations are working, wait and try again later
4247 # if [ ! $PREPROCEED ]; then sleep 3; fi
4249 # ( do_preprocess $PRETRACKNUM
4257 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4259 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4260 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4261 if [ "$GOAHEAD" = "NO" ]; then break; fi
4262 for LASTTRACK in $TRACKQUEUE; do :; done
4263 if checkstatus readtrack-$LASTTRACK; then
4264 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4265 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4266 if checkerrors batch-normalize; then exit 1; fi
4268 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4269 if [ "$DONORMALIZE" = "y" ]; then
4270 for UTRACKNUM in $TRACKQUEUE
4272 if checkstatus readtrack-$UTRACKNUM; then
4273 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4277 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4278 if checkerrors nogap-encode; then exit 1; fi
4283 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4284 if [ "$ONETRACK" = "y" ] ; then
4285 TRACKQUEUE="$FIRSTTRACK"
4286 TRACKS="$FIRSTTRACK"
4289 # Do the encoding, including parallelization of remote encoding
4290 # Figure out where each track is going to be encoded
4291 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4292 if [ "$MAXPROCS" != "0" ]; then
4293 for NUM in $(f_seq_row 1 "$MAXPROCS")
4295 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
4299 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
4300 for UTRACKNUM in $TRACKQUEUE
4303 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4304 if [ "$GOAHEAD" = "NO" ]; then break; fi
4305 # find out where this track is to be encoded
4306 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4307 # Make sure we have a place to encode this, if not, exit stage right
4308 if [ -z "$ENCODELOCATIONS" ]; then
4314 for LOCATION in $ENCODELOCATIONS
4316 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4317 # check first if a track has ever been assigned to this location
4318 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
4319 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4320 if checkerrors encodetrack-$PREVIOUSTRACK; then
4321 for TEMPLOCATION in $ENCODELOCATIONS
4323 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4324 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
4327 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
4332 # We're still here, this location must have been previously assigned,
4333 # and last completed without error - check if it's done with the
4334 # previous track yet
4335 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
4337 # all locations are working, wait and try again later
4338 if [ ! $PROCEED ]; then sleep 3; fi
4340 # Record the location we're about to encode the next track at
4341 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4343 # Don't proceed with the rest of the loop if we can't encode
4344 if [ "$ABORT" ]; then continue; fi
4345 ## FIXME ## Add here
4346 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4347 # Set TRACKNUM, TRACKNAME
4348 if [ -e "$CDDBDATA" ]; then
4349 if [ "$ONETRACK" = "y" ]; then
4351 TRACKNUM="$FIRSTTRACK"
4355 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
4356 getcddbinfo TRACKNAME
4360 # You can't encode a file which needs to be normalized before finishing
4361 # You can't tag a file before it's finished encoding -
4362 # thus all of this is backgrounded together
4364 if [ "$DONORMALIZE" = "y" ]; then
4365 if checkstatus readtrack-$UTRACKNUM; then
4366 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4369 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4370 if checkstatus readtrack-$UTRACKNUM; then
4371 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4372 if [ "$DONORMALIZE" = "y" ]; then
4373 if checkstatus normalizetrack-$UTRACKNUM; then
4374 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4377 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4381 if [ "$DOTAG" = "y" ]; then
4382 if checkstatus encodetrack-$UTRACKNUM; then
4383 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
4385 # Lets tag the cue file
4386 if checkstatus cleancuefile >/dev/null; then :; else
4387 if checkstatus cuefile >/dev/null ; then
4392 if [ "$DOMOVE" = "y" ]; then
4393 if checkstatus tagtrack-$UTRACKNUM; then
4394 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
4401 # Go through it again and make sure there's no distmp3 stragglers, otherwise
4402 # we'll delete the files they're working on
4403 # Do NOT play ball if there is no ball to play (so ABORT if needed)
4404 ## FIXME ## Check also for files which are encoded using PIPEs.
4405 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
4410 for LOCATION in $ENCODELOCATIONS
4412 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4413 # "How can he give us a status update, if he's DEAD?"
4414 if checkstatus encodetrack-$CHECKTRACK; then
4417 # Nothing to see here please go quietly back to your homes
4418 if [ -z "$CHECKTRACK" ]; then continue; fi
4419 # You're still here? Maybe there is something...
4420 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
4423 if [ ! $PROCEED ]; then sleep 5; fi
4426 # If the above didn't catch the stragglers, this will
4428 if [ "$DOREPLAYGAIN" = "y" ]; then
4432 # Execute the user-defined post_encode function before cleaning up
4435 # Check to see if run_command logged any errors
4436 if [ -f "$ABCDETEMPDIR/errors" ]; then
4437 log error "The following commands failed to run:"
4438 cat "$ABCDETEMPDIR/errors"
4442 if [ "$KEEPWAVS" = "y" ];then
4446 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
4447 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
4448 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
4449 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
4450 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
4451 log warning "The encoded formats does not match with the moved ones"
4452 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
4453 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
4454 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
4458 if [ "$DOCLEAN" = "y" ]; then
4459 # Wipe all the evidence
4460 # Gimme gimme gimme some more time!
4462 rm -rf "$ABCDETEMPDIR"
4465 echo "Finished. Not cleaning $ABCDETEMPDIR."