2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
5 # Copyright (c) 2012 Steve McIntyre <93sam@@debian.org>
6 # This code is hereby licensed for public consumption under either the
7 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
9 # You should have received a copy of the GNU General Public License along
10 # with this program; if not, write to the Free Software Foundation, Inc.,
11 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13 # Copyright for this work is to expire January 1, 2010, after which it
14 # shall be public domain.
16 VERSION='2.6.1-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"
30 echo " Specify a configuration file (overrides system and user config files)"
32 echo " Specify discid to resume from (only needed if you no longer have the cd)"
34 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
35 echo "-D Debugging mode (equivalent to sh -x abcde)"
36 echo "-e Erase encoded track information from status file"
37 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
38 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
39 echo "-h This help information"
40 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
41 echo "-j <#> Number of encoder processes to run at once (localhost)"
42 echo "-k Keep the wav tracks for later use"
43 echo "-l Use low disk space algorithm"
44 echo "-L Use local CDDB storage directory"
45 echo "-m Modify playlist to include CRLF endings, to comply with some players"
46 #echo " WARNING: Deprecated. Use \"cue\" action"
47 #echo "-M Create a CUE file"
48 echo "-n No lookup. Don't query CDDB, just create and use template"
49 echo "-N Noninteractive. Never prompt for anything"
50 echo "-o <type1[,type2]...>"
51 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,wv,ape). Defaults to vorbis"
52 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
53 echo "-P Use UNIX pipes to read+encode without wav files"
54 echo "-r <host1[,host2]...>"
55 echo " Also encode on these remote hosts"
57 echo " Show fields from the CDDB info (year,genre)"
58 echo "-S <#> Set the CD speed"
59 echo "-t <#> Start the track numbering at a given number"
60 echo "-T <#> Same as -t but modifies tag numbering"
61 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
62 echo "-v Show version number and exit"
63 echo "-V Be a bit more verbose about what is happening behind the scenes"
64 echo "-x Eject CD after all tracks are read"
66 echo " Add a comment to the CD tracks"
67 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
68 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
70 echo "Tracks is a space-delimited list of tracks to grab."
71 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
73 #echo "Double hyphens are used to concatenate tracks"
78 echo "$@" >> "$ABCDETEMPDIR/status"
81 # log [level] [message]
83 # log outputs the right message in a common format
89 error) echo "[ERROR] abcde: $@" >&2 ;;
90 warning) echo "[WARNING] $@" >&2 ;;
91 info) echo "[INFO] $@" ;;
95 # Functions to replace the need of seq, which is too distribution dependent.
99 while [ $i -ne `expr $2 + 1` ]
109 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
110 while [ $i -ne `expr $2 + 1` ]
117 log error "syntax error while processing track numbers ($i)"
122 # Functions to replace the need of awk {print $1} and {print $NF}
125 if [ X"$1" = "X" ]; then
126 for first in `cat`; do
137 if [ X"$1" = "X" ]; then
138 for stdin in `cat`; do
142 for last in $@ ; do :; done
147 # checkstatus [blurb]
148 # Returns "0" if the blurb was found, returns 1 if it wasn't
149 # Puts the blurb content, if available, on stdout.
150 # Otherwise, returns "".
153 # Take the last line in the status file if there's multiple matches
155 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
157 if [ -z "$BLURB" ]; then
162 # See if there's a = in it
163 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
164 echo "$(echo $BLURB | cut -f2- -d=)"
170 # checkwarnings [blurb]
171 # Returns "0" if the blurb was found (meaning there was an warning),
172 # returns 1 if it wasn't (yes this is a little backwards).
173 # Does not print the blurb on stdout.
174 # Otherwise, returns "".
177 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
180 # Take the last line in the status file if there's multiple matches
182 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
184 if [ -z "$BLURB" ]; then
185 # negative, we did not have a negative...
188 # affirmative, we had a negative...
193 # checkerrors [blurb]
194 # Returns "0" if the blurb was found (meaning there was an error),
195 # returns 1 if it wasn't (yes this is a little backwards).
196 # Does not print the blurb on stdout.
197 # Otherwise, returns "".
200 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
203 # Take the last line in the status file if there's multiple matches
205 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
207 if [ -z "$BLURB" ]; then
208 # negative, we did not have a negative...
211 # affirmative, we had a negative...
217 # Finds the right pager in the system to display a file
221 # Use the debian sensible-pager wrapper to pick the pager
222 # user has requested via their $PAGER environment variable
223 if [ -x "/usr/bin/sensible-pager" ]; then
224 /usr/bin/sensible-pager "$PAGEFILE"
225 elif [ -x "$PAGER" ]; then
226 # That failed, try to load the preferred editor, starting
227 # with their PAGER variable
229 # If that fails, check for less
230 elif [ -x /usr/bin/less ]; then
231 /usr/bin/less -f "$PAGEFILE"
232 # more should be on all UNIX systems
233 elif [ -x /bin/more ]; then
234 /bin/more "$PAGEFILE"
236 # No bananas, just cat the thing
241 # run_command [blurb] [command...]
242 # Runs a command, silently if necessary, and updates the status file
248 # See if this is supposed to be silent
249 if [ "$(checkstatus encode-output)" = "loud" ]; then
253 # Special case for SMP, since
254 # encoder output is never displayed, don't mute echos
255 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
264 normalize|normalize-audio)
265 if [ "$RETURN" = "2" ]; then
266 # File was already normalized.
271 if [ "$RETURN" != "0" ]; then
272 # Put an error in the errors file. For various reasons we
273 # can't capture a copy of the program's output but we can
274 # log what we attempted to execute and the error code
275 # returned by the program.
276 if [ "$BLURB" ]; then
279 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
280 return $RETURN # Do not pass go, do not update the status file
282 if [ "$BLURB" ]; then
283 echo $BLURB >> "$ABCDETEMPDIR/status"
287 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
288 # distributed under the terms of the GNU GPL v2 or later, at your option
290 # Function to determine if a word contains a slash.
299 # Function to give the relative path from one file to another.
300 # Usage: relpath fromfile tofile
301 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
302 # (the result would be Album/Song.mp3)
303 # Output is relative path to $2 from $1 on stdout
305 # This code has the following restrictions:
306 # Multiple ////s are not collapsed into single /s, with strange effects.
307 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
308 # If FR is a directory it must have a trailing /
316 /*) ;; # No processing is needed for absolute paths
318 # Loop through common prefixes, ignoring them.
319 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
321 FR="$(echo "$FR" | cut -d/ -f2-)"
322 TO="$(echo "$TO" | cut -d/ -f2-)"
324 # Loop through directory portions left in FR, adding appropriate ../s.
327 FR="$(echo "$FR" | cut -d/ -f2-)"
338 if [ ! "$@" = "" ]; then
339 # Cut off any command-line option we added in
340 X=$(echo $@ | cut -d' ' -f2)
341 if [ "$(which $X)" = "" ]; then
343 elif [ ! -x $(which $X) ]; then
352 if [ ! "$@" = "" ]; then
353 # Cut off any command-line option we added in
354 X=$(echo $@ | cut -d' ' -f2)
355 # Test for built-in abcde.function
356 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
357 if [ "$(which $X)" = "" ]; then
358 log error "$X is not in your path." >&2
359 log info "Define the full path to the executable if it exists on your system." >&2
360 if [ -e /etc/debian_release ] ; then
362 oggenc) MISSING_PACKAGE=vorbis-tools ;;
363 lame|flac) MISSING_PACKAGE=$X ;;
365 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
368 elif [ ! -x "$(which $X)" ]; then
369 log error "$X is not executable." >&2
375 # diffentries <filename> <max_value> <entry1>,<entry2>
376 # max_value: the range of entries goes from 1 to <max_value>
381 local CDDBDIFFCHOICES=$1
383 local CDDBDIFFCHOICE="$@"
384 if [ ! X"$DIFF" = "X" ]; then
385 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
386 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
387 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
388 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
389 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
390 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
392 # We parse the 2 choices to diff, store them in temporary files and diff them.
393 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
394 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
396 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
397 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
398 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
399 page "$ABCDETEMPDIR/$FILENAME.diff"
401 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
405 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
410 # Finds an specific field from cddbinfo
415 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
418 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
421 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
427 # Get the track number we are going to use for different actions
430 if [ -n "$STARTTRACKNUMBER" ] ; then
431 # Get the trackpadding from the current track, also trim whitespace for MacOSX
432 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
433 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
435 TRACKNUM=${UTRACKNUM}
441 # Calculate cddb disc ids without requiring specialized helper programs.
442 # largely copied from cd-discid and musicbrainz examples. some of the steps
443 # don't make sense, but they're necessary to match the ids generated by other
446 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
447 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
448 # 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
449 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
450 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
451 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
453 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
456 if [ X"$LEADOUT" = "X" ]; then
457 log warning "Error trying to calculate disc ids without lead-out information."
461 # default to a two second lead-in
463 LEADIN=${LEADIN:=150}
465 # number of cdframes per second
468 # reset cddb checksum for cddb disc-id calululation
472 for OFFSET in $(echo $OFFSETS)
474 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
476 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
477 while [ $OFFSETTIME -gt 0 ]; do
478 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
479 OFFSETTIME=$(($OFFSETTIME / 10))
484 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
486 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
487 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
489 case "$CDDBMETHOD" in
491 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
494 # FIXME: don't assume the first track is 1
495 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
496 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
500 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
505 if checkstatus replaygain; then :; else
506 run_command "" echo "Adding replaygain information..."
507 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
511 OUTPUT=$OGGOUTPUTCONTAINER
514 OUTPUT=$OPUSOUTPUTCONTAINER
517 OUTPUT=$FLACOUTPUTCONTAINER
525 for UTRACKNUM in $TRACKQUEUE
527 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
528 getcddbinfo TRACKNAME
530 TRACKFILE="$(mungefilename "$TRACKNAME")"
531 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
532 ALBUMFILE="$(mungefilename "$DALBUM")"
533 GENRE="$(mungegenre "$GENRE")"
534 YEAR=${CDYEAR:-$CDYEAR}
536 if [ "$ONETRACK" = "y" ]; then
537 if [ "$VARIOUSARTISTS" = "y" ]; then
538 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
540 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
543 if [ "$VARIOUSARTISTS" = "y" ]; then
544 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
546 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
549 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
550 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
554 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
555 #run_command replaygain-flac true
558 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
561 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
564 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
567 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
572 if checkerrors "replaygain-.{3,6}"; then :; else
573 run_command replaygain true
578 # This code splits the a Various Artist track name from one of the following
581 # forward: Artist / Track
582 # forward-dash: Artist - Track
583 # reverse: Track / Artist
584 # reverse-dash: Track - Artist
585 # colon: Artist: Track
586 # trailing-paren: Artist (Track)
589 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
592 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
593 case "$VARIOUSARTISTSTYLE" in
595 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
596 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
597 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
600 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
601 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
602 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
605 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
606 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
607 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
610 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
611 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
612 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
615 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
616 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
617 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
620 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
621 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
622 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
625 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
626 TRACKARTIST="Various"
628 TRACKARTIST="$DARTIST"
633 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
637 "classic rock") id=1 ;;
655 "industrial") id=19 ;;
656 "alternative") id=20 ;;
658 "death metal") id=22 ;;
660 "soundtrack") id=24 ;;
661 "euro-techno") id=25 ;;
665 "jazz+funk") id=29 ;;
668 "classical") id=32 ;;
669 "instrumental") id=33 ;;
673 "sound clip") id=37 ;;
676 "alt. rock") id=40 ;;
681 "meditative") id=45 ;;
682 "instrum. pop") id=46 ;;
683 "instrum. rock") id=47 ;;
687 "techno-indust.") id=51 ;;
688 "electronic") id=52 ;;
690 "eurodance") id=54 ;;
692 "southern rock") id=56 ;;
697 "christian rap") id=61 ;;
698 "pop/funk"|"pop / funk") id=62 ;;
700 "native american") id=64 ;;
703 "psychadelic") id=67 ;;
705 "showtunes") id=69 ;;
709 "acid punk") id=73 ;;
710 "acid jazz") id=74 ;;
714 "rock & roll") id=78 ;;
715 "hard rock") id=79 ;;
717 "folk/rock") id=81 ;;
718 "national folk") id=82 ;;
725 "bluegrass") id=89 ;;
726 "avantgarde") id=90 ;;
727 "gothic rock") id=91 ;;
728 "progress. rock") id=92 ;;
729 "psychadel. rock") id=93 ;;
730 "symphonic rock") id=94 ;;
731 "slow rock") id=95 ;;
734 "easy listening") id=98 ;;
740 "chamber music") id=104 ;;
742 "symphony") id=106 ;;
743 "booty bass") id=107 ;;
745 "porn groove") id=109 ;;
747 "slow jam") id=111 ;;
751 "folklore") id=115 ;;
753 "power ballad") id=117 ;;
754 "rhythmic soul") id=118 ;;
755 "freestyle") id=119 ;;
757 "punk rock") id=121 ;;
758 "drum solo") id=122 ;;
759 "a capella") id=123 ;;
760 "euro-house") id=124 ;;
761 "dance hall") id=125 ;;
763 "drum & bass") id=127 ;;
764 "club-house") id=128 ;;
765 "hardcore") id=129 ;;
769 "negerpunk") id=133 ;;
770 "polsk punk") id=134 ;;
772 "christian gangsta rap") id=136 ;;
773 "heavy metal") id=137 ;;
774 "black metal") id=138 ;;
775 "crossover") id=139 ;;
776 "contemporary christian")id=140 ;;
777 "christian rock") id=141 ;;
778 "merengue") id=142 ;;
780 "thrash metal") id=144 ;;
783 "synthpop") id=147 ;;
784 "rock/pop"|"rock / pop") id=148 ;;
791 # do_tag [tracknumber]
792 # id3 tags a filename
794 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
795 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
798 COMMENTOUTPUT="$(eval echo ${COMMENT})"
799 if [ -z "$COMMENTOUTPUT" ]; then
800 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
802 if [ "$CDDBMETHOD" = "cddb" ]; then
803 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
805 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
806 # If we want to start the tracks with a given number, we need to modify the
807 # TRACKNUM value before evaluation
808 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
811 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
815 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
816 GENREID=$(do_getgenreid "${CDGENRE}")
817 # Set TPE2 in case we have a Various Artists rip.
819 if [ "$VARIOUSARTISTS" = "y" ]; then
826 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
827 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
828 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
829 -y "$CDYEAR" -g "$GENREID" \
830 -T "${TRACKNUM:-$1}" \
831 "$ABCDETEMPDIR/track$1.$OUTPUT"
834 # FIXME # track numbers in mp3 come with 1/10, so we cannot
835 # happily substitute them with $TRACKNUM
836 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
837 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
838 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
839 -y "$CDYEAR" -g "$GENREID" \
840 -T "${TRACKNUM:-$1}/$TRACKS" \
841 ${TPE2:+--TPE2 "$TPE2"} \
842 "$ABCDETEMPDIR/track$1.$OUTPUT"
845 # FIXME # track numbers in mp3 come with 1/10, so we cannot
846 # happily substitute them with $TRACKNUM
848 eyed3_06) addopts=( \
849 ${ENCODING:+--set-encoding="$ENCODING"} \
850 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
851 # We set 'recording-date' so the date tag will show
852 # in Audacious, vlc and friends... Andrew.
853 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
854 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
857 ${ENCODING:+--encoding="$ENCODING"} \
858 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
859 # We set 'recording-date' so the date tag will show
860 # in Audacious, vlc and friends... Andrew.
861 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
862 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
865 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
867 -a "$TRACKARTIST" -t "$TRACKNAME" \
868 -G "$GENREID" -n "${TRACKNUM:-$1}" \
869 ${TRACKNUM:+-N "$TRACKS"} \
871 "$ABCDETEMPDIR/track$1.$OUTPUT"
874 log error "Internal error: ID3SYNTAX has an illegal value"
880 case "$OGGENCODERSYNTAX" in
882 # vorbiscomment can't do in-place modification, mv the file first
883 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
884 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
888 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
890 echo ARTIST="$TRACKARTIST"
892 echo TITLE="$TRACKNAME"
893 if [ -n "$CDYEAR" ]; then
896 if [ -n "$CDGENRE" ]; then
897 echo GENRE="$CDGENRE"
899 echo TRACKNUMBER=${TRACKNUM:-$1}
900 if [ -n "$DISCNUMBER" ]; then
901 echo DISCNUMBER="$DISCNUMBER"
903 echo CDDB=$CDDBDISCID
904 if [ "$(eval echo ${COMMENT})" != "" ]; then
905 case "$COMMENTOUTPUT" in
906 *=*) echo "$COMMENTOUTPUT";;
907 *) echo COMMENT="$COMMENTOUTPUT";;
910 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
911 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
912 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
913 # Doublecheck that the commented file was created
914 # successfully before wiping the original
915 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
916 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
918 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
924 run_command tagtrack-$OUTPUT-$1 true
929 echo ARTIST="$TRACKARTIST"
931 echo TITLE="$TRACKNAME"
932 if [ -n "$CDYEAR" ]; then
935 if [ -n "$CDGENRE" ]; then
936 echo GENRE="$CDGENRE"
938 echo TRACKNUMBER="${TRACKNUM:-$1}"
939 if [ -n "$DISCNUMBER" ]; then
940 echo DISCNUMBER="$DISCNUMBER"
942 echo CDDB="$CDDBDISCID"
943 if [ "$(eval echo ${COMMENT})" != "" ]; then
944 case "$COMMENTOUTPUT" in
945 *=*) echo "$COMMENTOUTPUT";;
946 *) echo COMMENT="$COMMENTOUTPUT";;
949 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
952 run_command tagtrack-$OUTPUT-$1 true
955 run_command tagtrack-$OUTPUT-$1 true
958 run_command tagtrack-$OUTPUT-$1 true
960 ape) # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
961 # Console port (mac) used for encoding does not have the ability to tag. Andrew.
962 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
963 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
964 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
967 run_command tagtrack-$OUTPUT-$1 true
970 case "$AACENCODERSYNTAX" in
971 fdkaac) # We will use inline tagging...
972 run_command tagtrack-$OUTPUT-$1 true
974 neroAacEnc) # Tag post encode with neroAacTag...
975 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
976 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
977 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
980 run_command tagtrack-$OUTPUT-$1 true
985 run_command tagtrack-$OUTPUT-$1 true
989 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
990 run_command tagtrack-$1 true
997 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1000 # The commands here don't go through run_command because they're never
1001 # supposed to be silenced
1002 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1003 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1007 case "$MP3ENCODERSYNTAX" in
1012 for UTRACKNUM in $TRACKQUEUE
1014 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1016 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1018 if [ "$RETURN" != "0" ]; then
1019 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1021 for UTRACKNUM in $TRACKQUEUE
1023 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1024 #run_command encodetrack-$UTRACKNUM true
1033 if checkerrors "nogap-encode"; then :; else
1034 if [ ! "$KEEPWAVS" = "y" ] ; then
1035 if [ ! "$KEEPWAVS" = "move" ] ; then
1040 # Other encoders fall through to normal encoding as the tracks have not
1041 # been entered in the status file.
1044 # do_encode [tracknumber] [hostname]
1045 # If no hostname is specified, encode locally
1047 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1050 if [ "$USEPIPES" = "y" ]; then
1053 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1056 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1059 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1062 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1065 TEMPARG="PIPE_$SPEEXENCODER"
1068 TEMPARG="PIPE_$MPCENCODER"
1071 TEMPARG="PIPE_$WVENCODERSYNTAX"
1074 TEMPARG="PIPE_$AACENCODERSYNTAX"
1077 TEMPARG="PIPE_$AACENCODERSYNTAX"
1080 IN="$( eval echo "\$$TEMPARG" )"
1082 IN="$ABCDETEMPDIR/track$1.wav"
1084 # We need IN to proceed, if we are not using pipes.
1085 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1086 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1088 case "$TMPOUTPUT" in
1090 OUTPUT=$OGGOUTPUTCONTAINER
1093 OUTPUT=$OPUSOUTPUTCONTAINER
1096 OUTPUT=$FLACOUTPUTCONTAINER
1102 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1103 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1106 if [ X"$USEPIPES" = "Xy" ]; then
1108 # We need a way to store the creation of the files when using PIPES
1109 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1110 # When pipping it does not make sense to have a higher nice for
1111 # reading than for encoding, since it will be hold by the
1112 # encoding process. Setting an effective nice, to calm down a
1113 # bit the reading process.
1114 EFFECTIVE_NICE=$READNICE
1116 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1117 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1118 EFFECTIVE_NICE=$ENCNICE
1124 case "$MP3ENCODERSYNTAX" in
1125 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1126 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1127 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1128 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1132 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1139 case "$OGGENCODERSYNTAX" in
1140 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1141 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1145 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1152 case "$OPUSENCODERSYNTAX" in
1154 # Tag the file at encode time, as it can't be done after encoding.
1155 if [ "$DOTAG" = "y" ]; then
1156 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
1157 --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1159 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1165 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1172 case "$FLACENCODERSYNTAX" in
1173 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1178 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1179 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1184 if [ "$(eval echo ${COMMENT})" != "" ]; then
1187 *) COMMENT="COMMENT=$COMMENT" ;;
1190 # Tag the file at encode time, as it can't be done after encoding.
1191 if [ "$DOTAG" = "y" ]; then
1192 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1194 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1198 # Tag the file inline at encode time.
1199 if [ "$DOTAG" = "y" ]; then
1200 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
1201 --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1203 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1207 if [ "$DOTAG" = "y" ]; then
1208 # wavpack tagging is done inline using Apev2 tags:
1209 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" -w Title="$TRACKNAME" \
1210 -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1212 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1216 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1219 # aac container is only used to catch faac encoded files where faac
1220 # is compiled without mp4 support (with libmp4v2). Andrew.
1221 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1224 case "$AACENCODERSYNTAX" in
1226 if [ "$DOTAG" = "y" ]; then
1227 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" \
1228 --album "$DALBUM" --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" \
1229 --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1231 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1235 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1238 if [ "$DOTAG" = "y" ]; then
1239 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1240 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1242 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1248 # In case of wav output we need nothing. Just keep the wavs.
1249 # But we need the following to allow full logging and subsequent
1250 # successful cleaning of $ABCDETEMPDIR. Andrew.
1251 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1256 # Only remove .wav if the encoding succeeded
1257 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1258 run_command encodetrack-$1 true
1259 if [ ! "$KEEPWAVS" = "y" ] ; then
1260 if [ ! "$KEEPWAVS" = "move" ] ; then
1266 run_command "" echo "HEH! The file we were about to encode disappeared:"
1267 run_command "" echo ">> $IN"
1268 run_command encodetrack-$1 false
1272 # do_preprocess [tracknumber]
1274 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1277 # IN="$ABCDETEMPDIR/track$1.wav"
1278 # # We need IN to proceed.
1279 # if [ -s "$IN" ] ; then
1280 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1282 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1283 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1284 # case "$POSTPROCESSFORMAT" in
1286 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1288 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1290 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1292 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1294 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1297 # # Only remove .wav if the encoding succeeded
1298 # if checkerrors "preprocess-(.{3,4})-$1"; then
1299 # run_command preprocess-$1 false
1301 # run_command preprocess-$1 true
1304 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1305 # echo "HEH! The file we were about to pre-process disappeared:"
1308 # run_command preprocess-$1 false
1313 # do_postprocess [tracknumber]
1315 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1318 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1320 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1321 # # We need IN to proceed.
1322 # if [ -s "$IN" ] ; then
1323 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1324 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1325 # case "$POSTPROCESSFORMAT" in
1327 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1329 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1331 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1333 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1335 # # Only remove .wav if the encoding succeeded
1336 # if checkerrors "postprocess-(.{3,4})-$1"; then
1337 # run_command postprocess-$1 false
1339 # run_command postprocess-$1 true
1342 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1343 # echo "HEH! The file we were about to post-process disappeared:"
1346 # run_command postprocess-$1 false
1361 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1365 # The commands here don't go through run_command because they're never supposed to be silenced
1366 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1371 for UTRACKNUM in $TRACKQUEUE
1373 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1375 # FIXME # Hard-coded batch option!
1376 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1378 if [ "$RETURN" != "0" ]; then
1379 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1381 for UTRACKNUM in $TRACKQUEUE
1383 echo normalizetrack-$UTRACKNUM >> status
1389 # do_batch_normalize
1391 # NORMALIZER, NORMALIZEROPTS
1392 do_batch_normalize ()
1394 # The commands here don't go through run_command because they're never supposed to be silenced
1395 echo "Batch normalizing tracks: $TRACKQUEUE"
1400 for UTRACKNUM in $TRACKQUEUE
1402 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1404 # XXX: Hard-coded batch option!
1405 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1407 if [ "$RETURN" != "0" ]; then
1408 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1410 for UTRACKNUM in $TRACKQUEUE
1412 echo normalizetrack-$UTRACKNUM >> status
1418 # do_normalize [tracknumber]
1420 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1423 IN="$ABCDETEMPDIR/track$1.wav"
1424 if [ -e "$IN" ] ; then
1425 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1426 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1428 if [ "$(checkstatus encode-output)" = "loud" ]; then
1429 echo "HEH! The file we were about to normalize disappeared:"
1432 run_command normalizetrack-$1 false "File $IN was not found"
1436 # do_move [tracknumber]
1437 # Deduces the outfile from environment variables
1438 # Creates directory if necessary
1440 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1443 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1445 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1446 # defined the OUTPUTFILE:
1449 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1450 # Munge filenames as follows:
1455 # Eat control characters
1456 ALBUMFILE="$(mungefilename "$DALBUM")"
1457 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1458 TRACKFILE="$(mungefilename "$TRACKNAME")"
1459 GENRE="$(mungegenre "$GENRE")"
1460 YEAR=${CDYEAR:-$CDYEAR}
1461 # If we want to start the tracks with a given number, we need to modify
1462 # the TRACKNUM value before evaluation
1464 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1465 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1466 if [ "$ONETRACK" = "y" ]; then
1467 if [ "$VARIOUSARTISTS" = "y" ]; then
1468 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1470 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1473 if [ "$VARIOUSARTISTS" = "y" ]; then
1474 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1476 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1479 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1480 # Once we know the specific output was successful, we can change
1481 # the OUTPUT to the value containing the container
1484 OUTPUT=$OGGOUTPUTCONTAINER
1487 OUTPUT=$OPUSOUTPUTCONTAINER
1490 OUTPUT=$FLACOUTPUTCONTAINER
1496 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1497 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1500 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1501 # FIXME # introduce warnings?
1504 # mkdir -p shouldn't return an error if the directory already exists
1505 mkdir -p "$OUTPUTFILEDIR"
1506 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1507 if checkstatus movetrack-output-$OUTPUT; then :; else
1508 run_command movetrack-output-$OUTPUT true
1513 # mkdir -p shouldn't return an error if the directory already exists
1514 mkdir -p "$OUTPUTFILEDIR"
1515 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1516 if checkstatus movetrack-output-$OUTPUT; then :; else
1517 run_command movetrack-output-$OUTPUT true
1521 # Lets move the cue file
1522 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1523 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1524 if checkstatus movecue-$OUTPUT; then :; else
1525 # Silence the Copying output since it overlaps with encoding processes...
1526 #run_command '' vecho "Copying cue file to its destination directory..."
1527 if checkstatus onetrack >/dev/null ; then
1530 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1531 # We dont have the dir, since it was not created before.
1534 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1537 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1538 # http://brianvictor.tripod.com/mp3cue.htm#details
1539 [a-z0-9][a-z0-9][a-z0-9])
1540 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1543 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1547 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1549 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1558 # Create the playlist if wanted
1560 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1561 # VARIOUSARTISTS, OUTPUTDIR
1564 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1568 OUTPUT=$OGGOUTPUTCONTAINER
1571 OUTPUT=$OPUSOUTPUTCONTAINER
1574 OUTPUT=$FLACOUTPUTCONTAINER
1580 # Create a playlist file for the playlist data to go into.
1581 # We used to wipe it out if it existed. Now we request permission if interactive.
1582 for LASTTRACK in $TRACKQUEUE; do :; done
1583 ALBUMFILE="$(mungefilename "$DALBUM")"
1584 ARTISTFILE="$(mungefilename "$DARTIST")"
1585 GENRE="$(mungegenre "$GENRE")"
1586 YEAR=${CDYEAR:-$CDYEAR}
1587 if [ "$VARIOUSARTISTS" = "y" ] ; then
1588 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1590 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1592 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1593 mkdir -p "$FINALPLAYLISTDIR"
1594 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1595 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1596 if [ "$INTERACTIVE" = "y" ]; then
1597 while [ "$DONE" != "y" ]; do
1599 case $ERASEPLAYLIST in
1600 e|E|a|A|k|K) DONE=y ;;
1601 "") ERASEPLAYLIST=e ; DONE=y ;;
1609 # Once we erase the playlist, we use append to create the new one.
1610 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1612 # The playlist does not exist, so we can safelly use append to create the new list
1615 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1616 touch "$OUTPUTDIR/$PLAYLISTFILE"
1617 for UTRACKNUM in $TRACKQUEUE
1619 # Shares some code with do_move since the filenames have to match
1620 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1621 getcddbinfo TRACKNAME
1623 TRACKFILE="$(mungefilename "$TRACKNAME")"
1624 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1625 ALBUMFILE="$(mungefilename "$DALBUM")"
1626 # If we want to start the tracks with a given number, we need to modify the
1627 # TRACKNUM value before evaluation
1629 if [ "$VARIOUSARTISTS" = "y" ]; then
1630 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1632 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1634 if [ "$VARIOUSARTISTS" = "y" ]; then
1635 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1636 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1638 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1641 if [ "$PLAYLISTDATAPREFIX" ]; then
1642 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1644 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1649 ## this will convert the playlist to have CRLF line-endings, if specified
1650 ## (some hardware players insist on CRLF endings)
1651 if [ "$DOSPLAYLIST" = "y" ]; then
1652 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1653 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1654 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1656 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1661 # This function reads a cuefile on stdin and writes an extended
1662 # cddb query on stdout. Any PREGAP for track 1 is properly
1663 # handled, although cue files embedded in FLAC files do not
1664 # appear to properly store the PREGAP setting. :(
1665 abcde.cue2discid () {
1670 while [ $val -gt 0 ] ; do
1671 ret=$(( $ret + ( $val % 10) ))
1672 val=$(( $val / 10 ))
1682 local first second third
1683 first=$(expr ${1} + 0 )
1684 second=$(expr ${2} + 0 )
1685 third=$(expr ${3} + 0 )
1687 echo $(( ((($first * 60) + $second) * 75) + $third ))
1697 while read line ; do
1700 TRACK) i=$(( i + 1 ))
1702 INDEX) if [ "$2" -eq 1 ] ; then
1704 START=$(( $LBA + $PREGAP + $OFFSET ))
1706 X=$(cddb_sum $(( $START / 75 )) )
1710 PREGAP) PREGAP=$(msf2lba $2)
1714 LEADOUT=$(( $4 / 588 ))
1717 LEADIN=$(( $3 / 588 ))
1726 LEADOUT=$(( $LEADOUT + $LEADIN ))
1728 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1729 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1730 printf "%08x %i" $DISCID $TRACKS
1733 while [ $j -le $TRACKS ] ; do
1734 eval echo -n "\" \$TRACK$j\""
1737 echo " $(( $LEADOUT / 75 ))"
1741 # abcde.mkcue [--wholedisk]
1742 # This creates a cuefile directly from the extended discid information
1743 # The --wholedisk option controls whether we're ripping data from the
1744 # start of track one or from the start of the disk (usually, but not
1745 # always the same thing!)
1747 # Track one leadin/pregap (if any) handeling:
1748 # --wholedisk specified:
1751 # INDEX 01 <pregap value>
1752 # Remaining track index values unchanged from disc TOC
1754 # --wholedisk not specified
1756 # PREGAP <pregap value>
1758 # Remaining track index values offset by <pregap value>
1765 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1768 local MODE DISCID TRACKS
1772 if [ "$1" = --wholedisc ] ; then
1778 vecho "One track is $ONETRACK"
1779 TRACKFILE="$(mungefilename "$TRACKNAME")"
1780 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1781 ALBUMFILE="$(mungefilename "$DALBUM")"
1782 if [ "$ONETRACK" = "y" ]; then
1783 if [ "$VARIOUSARTISTS" = "y" ]; then
1784 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1786 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1788 vecho "Cue wav file is $CUEWAVFILE"
1790 CUEWAVFILE="dummy.wav"
1799 echo REM DISCID $DISCID
1800 echo FILE \""$CUEWAVFILE"\" WAVE
1802 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1809 while [ $i -le "$TRACKS" ] ; do
1810 LBA=$(( $1 - $OFFSET ))
1811 printf " TRACK %02i AUDIO\n" $i
1812 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1813 if [ $MODE = PREGAP ] ; then
1814 echomsf " PREGAP " $(($OFFSET-150))
1816 echo " INDEX 00 00:00:00"
1819 echomsf " INDEX 01 " $LBA
1826 # This essentially the start of things
1829 # Query the CD to get the track info, unless the user specified -C
1830 # or we are using some actions which do not need the CDDB data at all
1831 #if [ ! X"$EXPACTIONS" = "X" ]; then
1833 #elif [ -z "$DISCID" ]; then
1834 if [ -z "$DISCID" ]; then
1835 vecho -n "Getting CD track info... "
1836 # In OSX, unmount the disc before a query
1837 if [ "$OSFLAVOUR" = "OSX" ]; then
1838 diskutil unmount ${CDROM#/dev/}
1840 case "$CDROMREADERSYNTAX" in
1842 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1843 case "$CUE2DISCID" in
1844 # FIXME # right now we have 2 cue2discid internal
1845 # implementations: builtin and abcde.cue2discid. Test
1846 # both of them and decide which one we want to use.
1848 #vecho "Using builtin cue2discid implementation..."
1849 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1851 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1853 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1854 TRACKS=${#OFFSETTIMES[@]}
1856 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1857 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1858 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1859 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1862 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1863 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1867 #vecho "Using external python cue2discid implementation..."
1868 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1872 log error "the input flac file does not contain a cuesheet."
1877 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1879 # if [ ! "$RET" = "0" ];then
1880 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1883 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1884 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1886 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1887 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1891 case "$CDDBMETHOD" in
1892 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1893 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1897 # Make sure there's a CD in there by checking cd-discid's return code
1898 if [ ! "$?" = "0" ]; then
1899 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1900 log error "cuesheet information from the flac file could not be read."
1901 log error "Perhaps the flac file does not contain a cuesheet?."
1904 log error "CD could not be read. Perhaps there's no CD in the drive?"
1908 # In OSX, remount the disc again
1909 if [ "$OSFLAVOUR" = "OSX" ]; then
1910 diskutil mount ${CDROM#/dev/}
1913 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1915 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1918 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1919 # This needs to be done now because a section of the resuming code will need
1922 # get the number of digits to pad TRACKNUM with - we'll use this later
1923 # a CD can only hold 99 tracks, but since we support a feature for starting
1924 # numbering the tracks from a given number, we might need to set it as a
1925 # variable for the user to define... or obtain it somehow.
1926 if [ "$PADTRACKS" = "y" ] ; then
1930 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1931 if [ -z "$TRACKQUEUE" ]; then
1932 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1933 case "$CDROMREADERSYNTAX" in
1935 if [ "$WEHAVEACD" = "y" ]; then
1936 vecho "Querying the CD for audio tracks..."
1937 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1939 if [ ! "$RET" = "0" ];then
1940 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1942 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1943 CDPARANOIAAUDIOTRACKS="$TRACKS"
1945 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1946 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1947 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1948 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1950 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1951 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1955 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1958 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1960 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1961 log info "The disc does not contain any tracks. Giving up..."
1964 echo -n "Grabbing entire CD - tracks: "
1965 if [ ! "$PADTRACKS" = "y" ] ; then
1966 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1968 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1970 while [ "$X" -ne "$TRACKS" ]
1972 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1973 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1977 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1978 # User-supplied track queue.
1979 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1980 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1981 # Once cleaned, obtain the highest value in the trackqueue for number padding
1982 for LASTTRACK in $TRACKQUEUE; do :; done
1983 if [ ! "$PADTRACKS" = "y" ] ; then
1984 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1986 # Now we normalize the trackqueue
1987 for TRACK in $TRACKQUEUE ; do
1988 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1989 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1991 TRACKQUEUE=$PADTRACKQUEUE
1992 echo Grabbing tracks: "$TRACKQUEUE"
1995 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1997 # We have the discid, create a temp directory after it to store all the temp
2000 if [ -e "$ABCDETEMPDIR" ]; then
2001 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2002 # It already exists, see if it's a directory
2003 if [ ! -d "$ABCDETEMPDIR" ]; then
2004 # This is a file/socket/fifo/device/etc, not a directory
2007 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2008 echo "Please investigate, remove it, and rerun abcde." >&2
2012 # It's a directory, let's see if it's writable by us
2013 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2014 # Nope, complain and exit
2016 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2017 echo "Please investigate, remove it, and rerun abcde." >&2
2021 # See if it's populated
2022 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2023 # Wipe and start fresh
2024 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2025 echo -n "this directory to continue. Continue [y/N]? " >&2
2026 if [ "$INTERACTIVE" = "y" ]; then
2032 if [ "$ANSWER" != "y" ]; then
2035 rm -rf "$ABCDETEMPDIR" || exit 1
2036 mkdir -p "$ABCDETEMPDIR"
2037 if [ "$?" -gt "0" ]; then
2038 # Directory already exists or could not be created
2039 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2043 # Everything is fine. Check for ^encodetracklocation-
2044 # and encode-output entries in the status file and
2045 # remove them. These are not relevant across sessions.
2046 if [ -f "$ABCDETEMPDIR/status" ]; then
2047 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2048 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2049 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2051 # Remove old error messages
2052 if [ -f "$ABCDETEMPDIR/errors" ]; then
2053 rm -f "$ABCDETEMPDIR/errors"
2057 # We are starting from scratch
2058 mkdir -p "$ABCDETEMPDIR"
2059 if [ "$?" -gt "0" ]; then
2060 # Directory already exists or could not be created
2061 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2064 cat /dev/null > "$ABCDETEMPDIR/status"
2065 # Store the abcde version in the status file.
2066 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2068 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2069 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2070 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2071 vecho "Creating cue file..."
2072 case $CDROMREADERSYNTAX in
2074 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2075 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2077 log warning "the input flac file does not contain a cuesheet."
2081 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2082 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2084 log warning "reading the CUE sheet is still considered experimental"
2085 log warning "and there was a problem with the CD reading. abcde will continue,"
2086 log warning "but consider reporting the problem to the abcde author"
2092 # If we got the CDPARANOIA status and it is not recorded, save it now
2093 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2094 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2095 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2099 # Create the discid file
2100 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2101 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2102 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2107 # Create a proper CUE file based on the CUE file we created before.
2110 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2111 CUEFILE_OUT=$CUEFILE_IN.out
2112 ### FIXME ### checkstatus cddb
2113 if [ -e "$CDDBDATA" ]; then
2114 vecho "Adding metadata to the cue file..."
2115 # FIXME It doesn't preserve spaces! Why?
2116 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2118 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2119 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2120 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2124 cat "$CUEFILE_IN" | while read line
2126 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2127 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2128 # echo "$line" >> "$CUEFILE_OUT"
2129 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2130 eval track="\$TRACK$n"
2132 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2133 # When making a single-track rip, put the
2134 # actual file name into the file declaration
2135 # in the cue file so that it is usable by
2136 # music players and the like
2137 elif [ "$ONETRACK" = "y" ] &&
2138 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2140 TRACKFILE="$(mungefilename "$TRACKNAME")"
2141 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2142 ALBUMFILE="$(mungefilename "$DALBUM")"
2144 if [ "$VARIOUSARTISTS" = "y" ]; then
2145 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2147 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2150 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2153 # FIXME # If the lines above are uncommented, remove the line below.
2154 echo "$line" >> "$CUEFILE_OUT"
2157 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2158 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2164 # Parses a CDDB file and outputs the title and the track names.
2165 # Variables: CDDBFILE
2169 # List out disc title/author and contents
2170 if [ "$ONETRACK" = "y" ]; then
2171 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2173 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2174 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2175 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2176 if [ ! X"$PARSEDYEAR" = "X" ]; then
2177 echo "Year: $PARSEDYEAR"
2180 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2181 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2182 if [ ! X"$PARSEDGENRE" = "X" ]; then
2183 echo "Genre: $PARSEDGENRE"
2186 if [ ! "$ONETRACK" = "y" ]; then
2187 for TRACK in $(f_seq_row 1 $TRACKS)
2189 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2195 # Check for a local CDDB file, and report success
2198 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2200 CDDBLOCALSTATUS="notfound"
2201 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2204 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2205 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2206 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2207 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2208 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2209 CDDBLOCALMATCH=single
2210 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2211 CDDBLOCALMATCH=multiple
2216 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2217 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2218 CDDBLOCALMATCH=single
2223 # If the user has selected to check a local CDDB repo, we proceed with it
2224 case $CDDBLOCALMATCH in
2226 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2228 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2230 # List out disc title/author and contents
2231 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2232 cat "$RESULT" > "${CDDBLOCALREAD}"
2235 do_cddbparse "${CDDBLOCALREAD}"
2237 ##FIXME## QUICK HACK !!!!
2238 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2239 } >> "$ABCDETEMPDIR/cddblocalchoices"
2241 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2242 page "$ABCDETEMPDIR/cddblocalchoices"
2244 # It's all going to fit in one page, cat it
2245 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2247 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2248 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2249 CDDBLOCALCHOICENUM=-1
2250 if [ "$INTERACTIVE" = "y" ]; then
2251 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2252 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2253 read CDDBLOCALCHOICE
2254 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2255 # FIXME # Introduce diff's
2256 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2257 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2258 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2259 # Make sure we get a valid choice
2260 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2261 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2262 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2268 #echo "Selected ..."
2270 CDDBLOCALCHOICENUM=1
2272 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2273 #echo "Using local copy of CDDB data"
2274 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2275 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2276 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2277 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2278 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2279 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2280 CDDBLOCALSTATUS="found"
2282 #echo "Not using local copy of CDDB data"
2283 CDDBLOCALSTATUS="notfound"
2287 # List out disc title/author and contents
2288 do_cddbparse "${CDDBLOCALFILE}"
2289 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2290 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2292 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2294 if [ "$INTERACTIVE" = "y" ]; then
2296 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2297 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2300 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2304 if [ "$USELOCALRESP" = "y" ]; then
2305 #echo "Using local copy of CDDB data"
2306 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2307 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2308 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2309 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2310 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2311 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2312 CDDBLOCALSTATUS="single"
2314 #echo "Not using local copy of CDDB data"
2315 CDDBLOCALSTATUS="notfound"
2319 CDDBLOCALSTATUS="notfound"
2326 # Try to read CD-Text from the drive using icedax / cdda2wav
2329 if new_checkexec icedax; then
2330 CDTEXT_READER=icedax
2331 elif new_checkexec cdda2wav; then
2332 CDTEXT_READER=cdda2wav
2334 # Didn't find either, bail
2338 if [ "$OSFLAVOUR" = "OSX" ] ; then
2339 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2340 diskutil unmount ${CDROM#/dev/}
2341 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2342 CDDA2WAVCDROM="IODVDServices"
2343 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2344 CDDA2WAVCDROM="$CDROMID"
2346 if [ "$CDROMID" = "" ]; then
2347 CDDA2WAVCDROM="$CDROM"
2349 CDDA2WAVCDROM="$CDROMID"
2353 # Do we have CD-Text on the disc (and can the drive read it?)
2354 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2355 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2357 if [ $ERRORCODE -ne 0 ]; then
2358 # No CD-Text found, bail
2362 rm -f "$ABCDETEMPDIR/cddbchoices"
2364 # Make an empty template
2365 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2366 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2367 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2368 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2369 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2370 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2371 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2372 # List out disc title/author and contents
2373 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2374 for TRACK in $(f_seq_row 1 $TRACKS)
2376 TRACKM1=$(($TRACK - 1))
2377 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2378 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2379 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2380 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2382 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2383 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2384 echo >> "$ABCDETEMPDIR/cddbchoices"
2385 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2389 # Work with the musicbrainz WS API, then transform the results here so
2390 # they look (very) like the results from CDDB. Maybe not the best way
2391 # to go, but it Works For Me (TM)
2395 if checkstatus musicbrainz-readcomplete; then :; else
2396 vecho "Obtaining Musicbrainz results..."
2397 # If MB is to be used, interpret the query results and read all
2398 # the available entries.
2399 rm -f "$ABCDETEMPDIR/cddbchoices"
2400 CDDBCHOICES=1 # Overridden by multiple matches
2401 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2402 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2404 # The helper script will write disc matches out to
2405 # cddbread.*. Count how many we have
2406 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2407 # No matches. Use the normal cddb template for the user to
2409 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2410 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2411 # List out disc title/author and contents of template
2412 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2414 for TRACK in $(f_seq_row 1 $TRACKS)
2416 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2418 echo >> "$ABCDETEMPDIR/cddbchoices"
2419 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2420 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2421 echo 503 > "$ABCDETEMPDIR/cddbquery"
2423 # We have some matches
2424 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2425 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2427 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2428 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2429 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2430 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2431 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2432 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2433 # List out disc title/author and contents
2434 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2435 for TRACK in $(f_seq_row 1 $TRACKS)
2437 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2439 echo >> "$ABCDETEMPDIR/cddbchoices"
2441 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2442 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2443 for file in "$ABCDETEMPDIR"/cddbread.*
2445 X=$(echo $file | sed 's/^.*cddbread\.//g')
2446 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2447 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2448 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2449 # List out disc title/author and contents
2450 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2451 for TRACK in $(f_seq_row 1 $TRACKS)
2453 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2455 echo >> "$ABCDETEMPDIR/cddbchoices"
2457 echo "." >> "$ABCDETEMPDIR/cddbquery"
2460 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2467 # Perform CDDB protocol version check if it hasn't already been done
2468 if checkstatus cddb-statcomplete; then :; else
2469 if [ "$CDDBAVAIL" = "n" ]; then
2471 echo 503 > "$ABCDETEMPDIR/cddbstat"
2474 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2475 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2476 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2477 vecho "Checking CDDB server status..."
2478 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2479 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2480 case "$RESPONSECODE" in
2481 210) # 210 OK, status information follows (until terminating `.')
2484 501) # 501 Illegal CDDB protocol level: <n>.
2485 CDDBPROTO=`expr $CDDBPROTO - 1`
2487 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2488 # FreeDB TESTCD disc-id is used for query
2489 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2490 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2491 case "$RESPONSECODE" in
2492 2??) # Server responded, everything seems OK
2502 if test $rc -eq 1; then
2506 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2514 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2515 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2517 # Perform CDDB query if it hasn't already been done
2518 if checkstatus cddb-querycomplete; then :; else
2519 if [ "$CDDBAVAIL" = "n" ]; then
2521 echo 503 > "$ABCDETEMPDIR/cddbquery"
2522 # The default CDDBLOCALSTATUS is "notfound"
2523 # This part will be triggered if the user CDDB repo does not
2524 # contain the entry, or if we are not trying to use the repo.
2526 vecho "Querying the CDDB server..."
2527 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2528 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2529 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2535 # no match found in database,
2536 # wget/fetch error, or user requested not to use CDDB
2537 # Make up an error code (503) that abcde
2538 # will recognize in do_cddbread
2539 # and compensate by making a template
2540 echo 503 > "$ABCDETEMPDIR/cddbquery"
2542 *) # strange and unknown error
2543 echo ERRORCODE=$ERRORCODE
2544 echo "abcde: $CDDBTOOL returned unknown error code"
2548 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2555 # If it's not to be used, generate a template.
2556 # Then, display it (or them) and let the user choose/edit it
2557 if checkstatus cddb-readcomplete; then :; else
2558 vecho "Obtaining CDDB results..."
2559 # If CDDB is to be used, interpret the query results and read all
2560 # the available entries.
2561 rm -f "$ABCDETEMPDIR/cddbchoices"
2562 CDDBCHOICES=1 # Overridden by multiple matches
2563 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2564 case "$RESPONSECODE" in
2566 # One exact match, retrieve it
2567 # 200 [section] [discid] [artist] / [title]
2568 if checkstatus cddb-read-1-complete; then :; else
2569 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2570 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2571 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2572 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2573 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2575 # List out disc title/author and contents
2576 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2577 for TRACK in $(f_seq_row 1 $TRACKS)
2579 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2581 echo >> "$ABCDETEMPDIR/cddbchoices"
2585 case "$RESPONSECODE" in
2586 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2587 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2588 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2590 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2591 # List out disc title/author and contents of template
2592 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2594 for TRACK in $(f_seq_row 1 $TRACKS)
2596 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2598 echo >> "$ABCDETEMPDIR/cddbchoices"
2599 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2600 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2603 # Multiple exact, (possibly multiple) inexact matches
2605 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2606 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2607 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2608 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2609 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2611 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2613 vecho -n "Retrieving multiple matches... "
2614 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2615 read DISCINFO # eat top line
2619 if checkstatus cddb-read-$X-complete; then :; else
2620 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2621 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2623 # List out disc title/author and contents
2624 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2625 for TRACK in $(f_seq_row 1 $TRACKS)
2627 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2629 echo >> "$ABCDETEMPDIR/cddbchoices"
2632 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2636 for TRACK in $(f_seq_row 1 $TRACKS)
2638 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2640 echo >> "$ABCDETEMPDIR/cddbchoices"
2641 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2642 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2645 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2652 if checkstatus cddb-edit >/dev/null; then
2653 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2654 VARIOUSARTISTS="$(checkstatus variousartists)"
2655 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2658 if [ "$INTERACTIVE" = "y" ]; then
2659 # We should show the CDDB results both when we are not using the local CDDB repo
2660 # or when we are using it but we could not find a proper match
2661 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2662 # Display the $ABCDETEMPDIR/cddbchoices file created above
2663 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2664 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2665 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2666 CHOICE=$(checkstatus cddb-choice)
2667 if [ -n "$CHOICE" ] ; then
2668 case $CDDBCHOICES in
2669 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2670 log error "CDDB query failed!"
2673 cat "$ABCDETEMPDIR/cddbchoices"
2676 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2678 echo "Selected: #$CHOICE"
2679 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2683 # The user has a choice to make, display the info in a pager if necessary
2684 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2685 page "$ABCDETEMPDIR/cddbchoices"
2687 # It's all going to fit in one page, cat it
2688 cat "$ABCDETEMPDIR/cddbchoices" >&2
2692 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2694 # I'll take CDDB read #3 for $400, Alex
2695 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2696 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2698 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2699 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2700 if [ ! X"$DIFF" = "X" ]; then