2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
5 # Copyright (c) 2012- Steve McIntyre <93sam@@debian.org>
6 # Copyright (c) 2015- Andrew Strong <andrew.david.strong@gmail.com>
7 # This code is hereby licensed for public consumption under either the
8 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
10 # You should have received a copy of the GNU General Public License along
11 # with this program; if not, write to the Free Software Foundation, Inc.,
12 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14 VERSION='2.7.1-UNRELEASED'
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform:"
24 echo " cddb,read,getalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
25 #echo "-A Experimental actions (retag, transcode)"
26 echo "-b Enable batch normalization"
28 echo " Specify a configuration file (overrides system and user config files)"
30 echo " Specify discid to resume from (only needed if you no longer have the cd)"
32 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
33 echo "-D Debugging mode (equivalent to sh -x abcde)"
34 echo "-e Erase encoded track information from status file"
35 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
36 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
37 echo "-G Get album art by using the 'getalbumart' action"
38 echo "-h This help information"
39 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
40 echo "-j <#> Number of encoder processes to run at once (localhost)"
41 echo "-k Keep the wav tracks for later use"
42 echo "-l Use low disk space algorithm"
43 echo "-L Use local CDDB storage directory"
44 echo "-m Modify playlist to include CRLF endings, to comply with some players"
45 #echo " WARNING: Deprecated. Use \"cue\" action"
46 #echo "-M Create a CUE file"
47 echo "-n No lookup. Don't query CDDB, just create and use template"
48 echo "-N Noninteractive. Never prompt for anything"
49 echo "-o <type1[,type2]...>"
50 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,wv,ape). Defaults to vorbis"
51 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
52 echo "-P Use UNIX pipes to read+encode without wav files"
53 echo "-r <host1[,host2]...>"
54 echo " Also encode on these remote hosts"
56 echo " Show fields from the CDDB info (year,genre)"
57 echo "-S <#> Set the CD speed"
58 echo "-t <#> Start the track numbering at a given number"
59 echo "-T <#> Same as -t but modifies tag numbering"
60 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
61 echo "-v Show version number and exit"
62 echo "-V Be a bit more verbose about what is happening behind the scenes"
63 echo "-x Eject CD after all tracks are read"
65 echo " Add a comment to the CD tracks"
66 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
67 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
69 echo "Tracks is a space-delimited list of tracks to grab."
70 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
72 #echo "Double hyphens are used to concatenate tracks"
77 echo "$@" >> "$ABCDETEMPDIR/status"
80 # log [level] [message]
82 # log outputs the right message in a common format
88 error) >&2 echo "[ERROR] abcde: $@" >&2 ;;
89 warning) >&2 echo "[WARNING] $@" >&2 ;;
90 info) >&4 echo "[INFO] $@" ;;
94 # Functions to replace the need of seq, which is too distribution dependent.
98 while [ $i -ne `expr $2 + 1` ]
108 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
109 while [ $i -ne `expr $2 + 1` ]
116 log error "syntax error while processing track numbers ($i)"
121 # Functions to replace the need of awk {print $1} and {print $NF}
124 if [ X"$1" = "X" ]; then
125 for first in `cat`; do
136 if [ X"$1" = "X" ]; then
137 for stdin in `cat`; do
141 for last in $@ ; do :; done
146 # checkstatus [blurb]
147 # Returns "0" if the blurb was found, returns 1 if it wasn't
148 # Puts the blurb content, if available, on stdout.
149 # Otherwise, returns "".
152 # Take the last line in the status file if there's multiple matches
154 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
156 if [ -z "$BLURB" ]; then
161 # See if there's a = in it
162 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
163 echo "$(echo $BLURB | cut -f2- -d=)"
169 # checkwarnings [blurb]
170 # Returns "0" if the blurb was found (meaning there was an warning),
171 # returns 1 if it wasn't (yes this is a little backwards).
172 # Does not print the blurb on stdout.
173 # Otherwise, returns "".
176 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
179 # Take the last line in the status file if there's multiple matches
181 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
183 if [ -z "$BLURB" ]; then
184 # negative, we did not have a negative...
187 # affirmative, we had a negative...
192 # checkerrors [blurb]
193 # Returns "0" if the blurb was found (meaning there was an error),
194 # returns 1 if it wasn't (yes this is a little backwards).
195 # Does not print the blurb on stdout.
196 # Otherwise, returns "".
199 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
202 # Take the last line in the status file if there's multiple matches
204 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
206 if [ -z "$BLURB" ]; then
207 # negative, we did not have a negative...
210 # affirmative, we had a negative...
216 # Finds the right pager in the system to display a file
220 # Use the debian sensible-pager wrapper to pick the pager
221 # user has requested via their $PAGER environment variable
222 if [ -x "/usr/bin/sensible-pager" ]; then
223 /usr/bin/sensible-pager "$PAGEFILE"
224 elif [ -x "$PAGER" ]; then
225 # That failed, try to load the preferred editor, starting
226 # with their PAGER variable
228 # If that fails, check for less
229 elif [ -x /usr/bin/less ]; then
230 /usr/bin/less -f "$PAGEFILE"
231 # more should be on all UNIX systems
232 elif [ -x /bin/more ]; then
233 /bin/more "$PAGEFILE"
235 # No bananas, just cat the thing
240 # run_command [blurb] [command...]
241 # Runs a command, silently if necessary, and updates the status file
247 # See if this is supposed to be silent
248 if [ "$(checkstatus encode-output)" = "loud" ]; then
252 # Special case for SMP, since
253 # encoder output is never displayed, don't mute echos
254 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
263 normalize|normalize-audio)
264 if [ "$RETURN" = "2" ]; then
265 # File was already normalized.
270 if [ "$RETURN" != "0" ]; then
271 # Put an error in the errors file. For various reasons we
272 # can't capture a copy of the program's output but we can
273 # log what we attempted to execute and the error code
274 # returned by the program.
275 if [ "$BLURB" ]; then
278 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
279 return $RETURN # Do not pass go, do not update the status file
281 if [ "$BLURB" ]; then
282 echo $BLURB >> "$ABCDETEMPDIR/status"
286 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
287 # distributed under the terms of the GNU GPL v2 or later, at your option
289 # Function to determine if a word contains a slash.
298 # Function to give the relative path from one file to another.
299 # Usage: relpath fromfile tofile
300 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
301 # (the result would be Album/Song.mp3)
302 # Output is relative path to $2 from $1 on stdout
304 # This code has the following restrictions:
305 # Multiple ////s are not collapsed into single /s, with strange effects.
306 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
307 # If FR is a directory it must have a trailing /
315 /*) ;; # No processing is needed for absolute paths
317 # Loop through common prefixes, ignoring them.
318 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
320 FR="$(echo "$FR" | cut -d/ -f2-)"
321 TO="$(echo "$TO" | cut -d/ -f2-)"
323 # Loop through directory portions left in FR, adding appropriate ../s.
326 FR="$(echo "$FR" | cut -d/ -f2-)"
337 if [ ! "$@" = "" ]; then
338 # Cut off any command-line option we added in
339 X=$(echo $@ | cut -d' ' -f2)
340 if [ "$(which $X)" = "" ]; then
342 elif [ ! -x $(which $X) ]; then
351 if [ ! "$@" = "" ]; then
352 # Cut off any command-line option we added in
353 X=$(echo $@ | cut -d' ' -f2)
354 # Test for built-in abcde.function
355 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
356 if [ "$(which $X)" = "" ]; then
357 log error "$X is not in your path." >&2
358 log info "Define the full path to the executable if it exists on your system." >&2
359 if [ -e /etc/debian_release ] ; then
361 oggenc) MISSING_PACKAGE=vorbis-tools ;;
362 lame|flac) MISSING_PACKAGE=$X ;;
364 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
367 elif [ ! -x "$(which $X)" ]; then
368 log error "$X is not executable." >&2
374 # diffentries <filename> <max_value> <entry1>,<entry2>
375 # max_value: the range of entries goes from 1 to <max_value>
380 local CDDBDIFFCHOICES=$1
382 local CDDBDIFFCHOICE="$@"
383 if [ ! X"$DIFF" = "X" ]; then
384 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
385 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
386 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
387 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
388 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
389 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
391 # We parse the 2 choices to diff, store them in temporary files and diff them.
392 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
393 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
395 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
396 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
397 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
398 page "$ABCDETEMPDIR/$FILENAME.diff"
400 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
404 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
409 # Finds an specific field from cddbinfo
414 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
417 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
420 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
426 # Get the track number we are going to use for different actions
429 if [ -n "$STARTTRACKNUMBER" ] ; then
430 # Get the trackpadding from the current track, also trim whitespace for MacOSX
431 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
432 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
434 TRACKNUM=${UTRACKNUM}
440 # Calculate cddb disc ids without requiring specialized helper programs.
441 # largely copied from cd-discid and musicbrainz examples. some of the steps
442 # don't make sense, but they're necessary to match the ids generated by other
445 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
446 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
447 # processing offsetimes 00:00:00 04:47:10 08:20:37 11:46:46 17:45:36 21:41:57 27:32:21 32:03:73 35:39:28 38:27:33 43:50:38 44:42:34
448 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
449 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
450 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
452 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
455 if [ X"$LEADOUT" = "X" ]; then
456 log warning "Error trying to calculate disc ids without lead-out information."
460 # default to a two second lead-in
462 LEADIN=${LEADIN:=150}
464 # number of cdframes per second
467 # reset cddb checksum for cddb disc-id calululation
471 for OFFSET in $(echo $OFFSETS)
473 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
475 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
476 while [ $OFFSETTIME -gt 0 ]; do
477 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
478 OFFSETTIME=$(($OFFSETTIME / 10))
483 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
485 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
486 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
488 case "$CDDBMETHOD" in
490 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
493 # FIXME: don't assume the first track is 1
494 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
495 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
499 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
504 if checkstatus replaygain; then :; else
505 run_command "" echo "Adding replaygain information..."
506 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
510 OUTPUT=$OGGOUTPUTCONTAINER
513 OUTPUT=$OPUSOUTPUTCONTAINER
516 OUTPUT=$FLACOUTPUTCONTAINER
524 for UTRACKNUM in $TRACKQUEUE
526 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
527 getcddbinfo TRACKNAME
529 TRACKFILE="$(mungefilename "$TRACKNAME")"
530 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
531 ALBUMFILE="$(mungefilename "$DALBUM")"
532 GENRE="$(mungegenre "$GENRE")"
533 YEAR=${CDYEAR:-$CDYEAR}
535 if [ "$ONETRACK" = "y" ]; then
536 if [ "$VARIOUSARTISTS" = "y" ]; then
537 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
539 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
542 if [ "$VARIOUSARTISTS" = "y" ]; then
543 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
545 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
548 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
549 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
553 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
554 #run_command replaygain-flac true
557 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
560 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
563 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
566 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
571 if checkerrors "replaygain-.{3,6}"; then :; else
572 run_command replaygain true
577 # This code splits the a Various Artist track name from one of the following
580 # forward: Artist / Track
581 # forward-dash: Artist - Track
582 # reverse: Track / Artist
583 # reverse-dash: Track - Artist
584 # colon: Artist: Track
585 # trailing-paren: Artist (Track)
588 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
591 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
592 case "$VARIOUSARTISTSTYLE" in
594 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
595 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
596 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
599 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
600 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
601 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
604 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
605 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
606 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
609 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
610 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
611 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
614 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
615 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
616 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
619 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
620 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
621 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
624 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
625 TRACKARTIST="Various"
627 TRACKARTIST="$DARTIST"
632 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
636 "classic rock") id=1 ;;
654 "industrial") id=19 ;;
655 "alternative") id=20 ;;
657 "death metal") id=22 ;;
659 "soundtrack") id=24 ;;
660 "euro-techno") id=25 ;;
664 "jazz+funk") id=29 ;;
667 "classical") id=32 ;;
668 "instrumental") id=33 ;;
672 "sound clip") id=37 ;;
675 "alt. rock") id=40 ;;
680 "meditative") id=45 ;;
681 "instrum. pop") id=46 ;;
682 "instrum. rock") id=47 ;;
686 "techno-indust.") id=51 ;;
687 "electronic") id=52 ;;
689 "eurodance") id=54 ;;
691 "southern rock") id=56 ;;
696 "christian rap") id=61 ;;
697 "pop/funk"|"pop / funk") id=62 ;;
699 "native american") id=64 ;;
702 "psychadelic") id=67 ;;
704 "showtunes") id=69 ;;
708 "acid punk") id=73 ;;
709 "acid jazz") id=74 ;;
713 "rock & roll") id=78 ;;
714 "hard rock") id=79 ;;
716 "folk/rock") id=81 ;;
717 "national folk") id=82 ;;
724 "bluegrass") id=89 ;;
725 "avantgarde") id=90 ;;
726 "gothic rock") id=91 ;;
727 "progress. rock") id=92 ;;
728 "psychadel. rock") id=93 ;;
729 "symphonic rock") id=94 ;;
730 "slow rock") id=95 ;;
733 "easy listening") id=98 ;;
739 "chamber music") id=104 ;;
741 "symphony") id=106 ;;
742 "booty bass") id=107 ;;
744 "porn groove") id=109 ;;
746 "slow jam") id=111 ;;
750 "folklore") id=115 ;;
752 "power ballad") id=117 ;;
753 "rhythmic soul") id=118 ;;
754 "freestyle") id=119 ;;
756 "punk rock") id=121 ;;
757 "drum solo") id=122 ;;
758 "a capella") id=123 ;;
759 "euro-house") id=124 ;;
760 "dance hall") id=125 ;;
762 "drum & bass") id=127 ;;
763 "club-house") id=128 ;;
764 "hardcore") id=129 ;;
768 "negerpunk") id=133 ;;
769 "polsk punk") id=134 ;;
771 "christian gangsta rap") id=136 ;;
772 "heavy metal") id=137 ;;
773 "black metal") id=138 ;;
774 "crossover") id=139 ;;
775 "contemporary christian")id=140 ;;
776 "christian rock") id=141 ;;
777 "merengue") id=142 ;;
779 "thrash metal") id=144 ;;
782 "synthpop") id=147 ;;
783 "rock/pop"|"rock / pop") id=148 ;;
790 # do_tag [tracknumber]
791 # id3 tags a filename
793 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
794 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
797 COMMENTOUTPUT="$(eval echo ${COMMENT})"
798 if [ -z "$COMMENTOUTPUT" ]; then
799 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
801 if [ "$CDDBMETHOD" = "cddb" ]; then
802 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
804 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
805 # If we want to start the tracks with a given number, we need to modify the
806 # TRACKNUM value before evaluation
807 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
810 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
814 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
815 GENREID=$(do_getgenreid "${CDGENRE}")
816 # Set TPE2 in case we have a Various Artists rip.
818 if [ "$VARIOUSARTISTS" = "y" ]; then
824 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
825 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
826 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
827 -y "$CDYEAR" -g "$GENREID" \
828 -T "${TRACKNUM:-$1}" \
829 "$ABCDETEMPDIR/track$1.$OUTPUT"
832 # FIXME # track numbers in mp3 come with 1/10, so we cannot
833 # happily substitute them with $TRACKNUM
834 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
835 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
836 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
837 -y "$CDYEAR" -g "$GENREID" \
838 -T "${TRACKNUM:-$1}/$TRACKS" \
839 ${TPE2:+--TPE2 "$TPE2"} \
840 "$ABCDETEMPDIR/track$1.$OUTPUT"
843 # FIXME # track numbers in mp3 come with 1/10, so we cannot
844 # happily substitute them with $TRACKNUM
846 eyed3_06) addopts=( \
847 ${ENCODING:+--set-encoding="$ENCODING"} \
848 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
849 # We set 'recording-date' so the date tag will show
850 # in Audacious, vlc and friends... Andrew.
851 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
852 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
855 ${ENCODING:+--encoding="$ENCODING"} \
856 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
857 # We set 'recording-date' so the date tag will show
858 # in Audacious, vlc and friends... Andrew.
859 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
860 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
863 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
865 -a "$TRACKARTIST" -t "$TRACKNAME" \
866 -G "$GENREID" -n "${TRACKNUM:-$1}" \
867 ${TRACKNUM:+-N "$TRACKS"} \
869 "$ABCDETEMPDIR/track$1.$OUTPUT"
872 log error "Internal error: ID3SYNTAX has an illegal value"
878 case "$OGGENCODERSYNTAX" in
880 # vorbiscomment can't do in-place modification, mv the file first
881 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
882 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
886 # http://www.xiph.org/vorbis/doc/v-comment.html
888 echo ARTIST="$TRACKARTIST"
890 echo TITLE="$TRACKNAME"
891 if [ -n "$CDYEAR" ]; then
894 if [ -n "$CDGENRE" ]; then
895 echo GENRE="$CDGENRE"
897 echo TRACKNUMBER=${TRACKNUM:-$1}
898 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
899 # xiph.org: http://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
900 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
901 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
902 echo TRACKTOTAL="${TRACKS}"
903 if [ -n "$DISCNUMBER" ]; then
904 echo DISCNUMBER="$DISCNUMBER"
906 echo CDDB=$CDDBDISCID
907 if [ "$(eval echo ${COMMENT})" != "" ]; then
908 case "$COMMENTOUTPUT" in
909 *=*) echo "$COMMENTOUTPUT";;
910 *) echo COMMENT="$COMMENTOUTPUT";;
913 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
914 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
915 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
916 # Doublecheck that the commented file was created
917 # successfully before wiping the original
918 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
919 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
921 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
927 run_command tagtrack-$OUTPUT-$1 true
931 echo ARTIST="$TRACKARTIST"
933 echo TITLE="$TRACKNAME"
934 if [ -n "$CDYEAR" ]; then
937 if [ -n "$CDGENRE" ]; then
938 echo GENRE="$CDGENRE"
940 echo TRACKNUMBER="${TRACKNUM:-$1}"
941 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
942 # xiph.org: http://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
943 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
944 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
945 echo TRACKTOTAL="${TRACKS}"
946 if [ -n "$DISCNUMBER" ]; then
947 echo DISCNUMBER="$DISCNUMBER"
949 echo CDDB="$CDDBDISCID"
950 if [ "$(eval echo ${COMMENT})" != "" ]; then
951 case "$COMMENTOUTPUT" in
952 *=*) echo "$COMMENTOUTPUT";;
953 *) echo COMMENT="$COMMENTOUTPUT";;
956 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
957 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
960 run_command tagtrack-$OUTPUT-$1 true
963 run_command tagtrack-$OUTPUT-$1 true
966 run_command tagtrack-$OUTPUT-$1 true
969 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
970 # Console port (mac) used for encoding does not have the ability to tag.
971 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
972 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
973 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
976 run_command tagtrack-$OUTPUT-$1 true
979 case "$AACENCODERSYNTAX" in
981 # We will use inline tagging...
982 run_command tagtrack-$OUTPUT-$1 true
985 # Tag post encode with neroAacTag...
986 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
987 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
988 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
991 run_command tagtrack-$OUTPUT-$1 true
994 run_command tagtrack-$OUTPUT-$1 true
999 run_command tagtrack-$OUTPUT-$1 true
1003 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1004 run_command tagtrack-$1 true
1010 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1013 # The commands here don't go through run_command because they're never
1014 # supposed to be silenced
1015 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1016 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1020 case "$MP3ENCODERSYNTAX" in
1025 for UTRACKNUM in $TRACKQUEUE
1027 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1029 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1031 if [ "$RETURN" != "0" ]; then
1032 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1034 for UTRACKNUM in $TRACKQUEUE
1036 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1037 #run_command encodetrack-$UTRACKNUM true
1046 if checkerrors "nogap-encode"; then :; else
1047 if [ ! "$KEEPWAVS" = "y" ] ; then
1048 if [ ! "$KEEPWAVS" = "move" ] ; then
1053 # Other encoders fall through to normal encoding as the tracks have not
1054 # been entered in the status file.
1057 # do_encode [tracknumber] [hostname]
1058 # If no hostname is specified, encode locally
1060 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1061 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1064 if [ "$USEPIPES" = "y" ]; then
1067 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1070 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1073 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1076 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1079 TEMPARG="PIPE_$SPEEXENCODER"
1082 TEMPARG="PIPE_$MPCENCODER"
1085 TEMPARG="PIPE_$WVENCODERSYNTAX"
1088 TEMPARG="PIPE_$AACENCODERSYNTAX"
1091 TEMPARG="PIPE_$AACENCODERSYNTAX"
1094 IN="$( eval echo "\$$TEMPARG" )"
1096 IN="$ABCDETEMPDIR/track$1.wav"
1098 # We need IN to proceed, if we are not using pipes.
1099 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1100 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1102 case "$TMPOUTPUT" in
1104 OUTPUT=$OGGOUTPUTCONTAINER
1107 OUTPUT=$OPUSOUTPUTCONTAINER
1110 OUTPUT=$FLACOUTPUTCONTAINER
1116 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1117 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1120 if [ X"$USEPIPES" = "Xy" ]; then
1122 # We need a way to store the creation of the files when using PIPES
1123 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1124 # When piping it does not make sense to have a higher nice for
1125 # reading than for encoding, since it will be hold by the
1126 # encoding process. Setting an effective nice, to calm down a
1127 # bit the reading process.
1128 EFFECTIVE_NICE=$READNICE
1130 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1131 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1132 EFFECTIVE_NICE=$ENCNICE
1138 case "$MP3ENCODERSYNTAX" in
1139 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1140 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1141 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1142 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1146 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1153 case "$OGGENCODERSYNTAX" in
1154 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1155 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1159 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1166 case "$OPUSENCODERSYNTAX" in
1168 # Tag the file at encode time, as it can't be done after encoding.
1169 if [ "$DOTAG" = "y" ]; then
1170 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1171 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1172 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1174 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1180 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1187 case "$FLACENCODERSYNTAX" in
1188 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1193 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1194 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1199 if [ "$(eval echo ${COMMENT})" != "" ]; then
1202 *) COMMENT="COMMENT=$COMMENT" ;;
1205 # Tag the file at encode time, as it can't be done after encoding.
1206 if [ "$DOTAG" = "y" ]; then
1207 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1208 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1210 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1214 # Tag the file inline at encode time.
1215 if [ "$DOTAG" = "y" ]; then
1216 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1217 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1219 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1223 if [ "$DOTAG" = "y" ]; then
1224 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1225 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1227 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1231 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1234 # aac container is only used to catch faac encoded files where faac
1235 # is compiled without mp4 support (with libmp4v2).
1236 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1239 case "$AACENCODERSYNTAX" in
1241 if [ "$DOTAG" = "y" ]; then
1242 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1243 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1245 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1249 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1252 if [ "$DOTAG" = "y" ]; then
1253 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1254 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1256 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1260 if [ "$DOTAG" = "y" ]; then
1261 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1262 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1264 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1270 # In case of wav output we need nothing. Just keep the wavs.
1271 # But we need the following to allow full logging and subsequent
1272 # successful cleaning of $ABCDETEMPDIR.
1273 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1278 # Only remove .wav if the encoding succeeded
1279 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1280 run_command encodetrack-$1 true
1281 if [ ! "$KEEPWAVS" = "y" ] ; then
1282 if [ ! "$KEEPWAVS" = "move" ] ; then
1288 run_command "" echo "HEH! The file we were about to encode disappeared:"
1289 run_command "" echo ">> $IN"
1290 run_command encodetrack-$1 false
1294 # do_preprocess [tracknumber]
1296 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1299 # IN="$ABCDETEMPDIR/track$1.wav"
1300 # # We need IN to proceed.
1301 # if [ -s "$IN" ] ; then
1302 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1304 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1305 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1306 # case "$POSTPROCESSFORMAT" in
1308 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1310 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1312 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1314 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1316 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1319 # # Only remove .wav if the encoding succeeded
1320 # if checkerrors "preprocess-(.{3,4})-$1"; then
1321 # run_command preprocess-$1 false
1323 # run_command preprocess-$1 true
1326 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1327 # echo "HEH! The file we were about to pre-process disappeared:"
1330 # run_command preprocess-$1 false
1335 # do_postprocess [tracknumber]
1337 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1340 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1342 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1343 # # We need IN to proceed.
1344 # if [ -s "$IN" ] ; then
1345 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1346 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1347 # case "$POSTPROCESSFORMAT" in
1349 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1351 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1353 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1355 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1357 # # Only remove .wav if the encoding succeeded
1358 # if checkerrors "postprocess-(.{3,4})-$1"; then
1359 # run_command postprocess-$1 false
1361 # run_command postprocess-$1 true
1364 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1365 # echo "HEH! The file we were about to post-process disappeared:"
1368 # run_command postprocess-$1 false
1383 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1387 # The commands here don't go through run_command because they're never supposed to be silenced
1388 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1393 for UTRACKNUM in $TRACKQUEUE
1395 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1397 # FIXME # Hard-coded batch option!
1398 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1400 if [ "$RETURN" != "0" ]; then
1401 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1403 for UTRACKNUM in $TRACKQUEUE
1405 echo normalizetrack-$UTRACKNUM >> status
1411 # do_batch_normalize
1413 # NORMALIZER, NORMALIZEROPTS
1414 do_batch_normalize ()
1416 # The commands here don't go through run_command because they're never supposed to be silenced
1417 echo "Batch normalizing tracks: $TRACKQUEUE"
1422 for UTRACKNUM in $TRACKQUEUE
1424 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1426 # XXX: Hard-coded batch option!
1427 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1429 if [ "$RETURN" != "0" ]; then
1430 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1432 for UTRACKNUM in $TRACKQUEUE
1434 echo normalizetrack-$UTRACKNUM >> status
1440 # do_normalize [tracknumber]
1442 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1445 IN="$ABCDETEMPDIR/track$1.wav"
1446 if [ -e "$IN" ] ; then
1447 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1448 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1450 if [ "$(checkstatus encode-output)" = "loud" ]; then
1451 echo "HEH! The file we were about to normalize disappeared:"
1454 run_command normalizetrack-$1 false "File $IN was not found"
1458 # do_move [tracknumber]
1459 # Deduces the outfile from environment variables
1460 # Creates directory if necessary
1462 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1465 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1467 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1468 # defined the OUTPUTFILE:
1471 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1472 ALBUMFILE="$(mungefilename "$DALBUM")"
1473 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1474 TRACKFILE="$(mungefilename "$TRACKNAME")"
1475 GENRE="$(mungegenre "$GENRE")"
1476 YEAR=${CDYEAR:-$CDYEAR}
1477 # If we want to start the tracks with a given number, we need to modify
1478 # the TRACKNUM value before evaluation
1480 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1481 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1482 if [ "$ONETRACK" = "y" ]; then
1483 if [ "$VARIOUSARTISTS" = "y" ]; then
1484 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1486 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1489 if [ "$VARIOUSARTISTS" = "y" ]; then
1490 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1492 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1495 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1496 # Once we know the specific output was successful, we can change
1497 # the OUTPUT to the value containing the container
1500 OUTPUT=$OGGOUTPUTCONTAINER
1503 OUTPUT=$OPUSOUTPUTCONTAINER
1506 OUTPUT=$FLACOUTPUTCONTAINER
1512 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1513 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1516 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1517 # FIXME # introduce warnings?
1520 # mkdir -p shouldn't return an error if the directory already exists
1521 mkdir -p "$OUTPUTFILEDIR"
1522 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1523 if checkstatus movetrack-output-$OUTPUT; then :; else
1524 run_command movetrack-output-$OUTPUT true
1529 # mkdir -p shouldn't return an error if the directory already exists
1530 mkdir -p "$OUTPUTFILEDIR"
1531 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1532 if checkstatus movetrack-output-$OUTPUT; then :; else
1533 run_command movetrack-output-$OUTPUT true
1537 # Lets move the cue file
1538 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1539 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1540 if checkstatus movecue-$OUTPUT; then :; else
1541 # Silence the Copying output since it overlaps with encoding processes...
1542 #run_command '' vecho "Copying cue file to its destination directory..."
1543 if checkstatus onetrack >/dev/null ; then
1546 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1547 # We dont have the dir, since it was not created before.
1550 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1553 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1554 # http://brianvictor.tripod.com/mp3cue.htm#details
1555 [a-z0-9][a-z0-9][a-z0-9])
1556 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1559 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1563 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1565 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1574 # Create the playlist if wanted
1576 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1577 # VARIOUSARTISTS, OUTPUTDIR
1580 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1584 OUTPUT=$OGGOUTPUTCONTAINER
1587 OUTPUT=$OPUSOUTPUTCONTAINER
1590 OUTPUT=$FLACOUTPUTCONTAINER
1596 # Create a playlist file for the playlist data to go into.
1597 # We used to wipe it out if it existed. Now we request permission if interactive.
1598 for LASTTRACK in $TRACKQUEUE; do :; done
1599 ALBUMFILE="$(mungefilename "$DALBUM")"
1600 ARTISTFILE="$(mungefilename "$DARTIST")"
1601 GENRE="$(mungegenre "$GENRE")"
1602 YEAR=${CDYEAR:-$CDYEAR}
1603 if [ "$VARIOUSARTISTS" = "y" ] ; then
1604 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1606 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1608 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1609 mkdir -p "$FINALPLAYLISTDIR"
1610 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1611 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1612 if [ "$INTERACTIVE" = "y" ]; then
1613 while [ "$DONE" != "y" ]; do
1615 case $ERASEPLAYLIST in
1616 e|E|a|A|k|K) DONE=y ;;
1617 "") ERASEPLAYLIST=e ; DONE=y ;;
1625 # Once we erase the playlist, we use append to create the new one.
1626 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1628 # The playlist does not exist, so we can safelly use append to create the new list
1631 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1632 touch "$OUTPUTDIR/$PLAYLISTFILE"
1633 for UTRACKNUM in $TRACKQUEUE
1635 # Shares some code with do_move since the filenames have to match
1636 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1637 getcddbinfo TRACKNAME
1639 TRACKFILE="$(mungefilename "$TRACKNAME")"
1640 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1641 ALBUMFILE="$(mungefilename "$DALBUM")"
1642 # If we want to start the tracks with a given number, we need to modify the
1643 # TRACKNUM value before evaluation
1645 if [ "$VARIOUSARTISTS" = "y" ]; then
1646 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1648 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1650 if [ "$VARIOUSARTISTS" = "y" ]; then
1651 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1652 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1654 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1657 if [ "$PLAYLISTDATAPREFIX" ]; then
1658 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1660 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1665 ## this will convert the playlist to have CRLF line-endings, if specified
1666 ## (some hardware players insist on CRLF endings)
1667 if [ "$DOSPLAYLIST" = "y" ]; then
1668 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1669 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1670 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1672 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1677 # This function reads a cuefile on stdin and writes an extended
1678 # cddb query on stdout. Any PREGAP for track 1 is properly
1679 # handled, although cue files embedded in FLAC files do not
1680 # appear to properly store the PREGAP setting. :(
1681 abcde.cue2discid () {
1686 while [ $val -gt 0 ] ; do
1687 ret=$(( $ret + ( $val % 10) ))
1688 val=$(( $val / 10 ))
1698 local first second third
1699 first=$(expr ${1} + 0 )
1700 second=$(expr ${2} + 0 )
1701 third=$(expr ${3} + 0 )
1703 echo $(( ((($first * 60) + $second) * 75) + $third ))
1713 while read line ; do
1716 TRACK) i=$(( i + 1 ))
1718 INDEX) if [ "$2" -eq 1 ] ; then
1720 START=$(( $LBA + $PREGAP + $OFFSET ))
1722 X=$(cddb_sum $(( $START / 75 )) )
1726 PREGAP) PREGAP=$(msf2lba $2)
1730 LEADOUT=$(( $4 / 588 ))
1733 LEADIN=$(( $3 / 588 ))
1742 LEADOUT=$(( $LEADOUT + $LEADIN ))
1744 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1745 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1746 printf "%08x %i" $DISCID $TRACKS
1749 while [ $j -le $TRACKS ] ; do
1750 eval echo -n "\" \$TRACK$j\""
1753 echo " $(( $LEADOUT / 75 ))"
1757 # abcde.mkcue [--wholedisk]
1758 # This creates a cuefile directly from the extended discid information
1759 # The --wholedisk option controls whether we're ripping data from the
1760 # start of track one or from the start of the disk (usually, but not
1761 # always the same thing!)
1763 # Track one leadin/pregap (if any) handeling:
1764 # --wholedisk specified:
1767 # INDEX 01 <pregap value>
1768 # Remaining track index values unchanged from disc TOC
1770 # --wholedisk not specified
1772 # PREGAP <pregap value>
1774 # Remaining track index values offset by <pregap value>
1781 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1784 local MODE DISCID TRACKS
1788 if [ "$1" = --wholedisc ] ; then
1794 vecho "One track is $ONETRACK"
1795 TRACKFILE="$(mungefilename "$TRACKNAME")"
1796 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1797 ALBUMFILE="$(mungefilename "$DALBUM")"
1798 if [ "$ONETRACK" = "y" ]; then
1799 if [ "$VARIOUSARTISTS" = "y" ]; then
1800 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1802 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1804 vecho "Cue wav file is $CUEWAVFILE"
1806 CUEWAVFILE="dummy.wav"
1815 echo REM DISCID $DISCID
1816 echo FILE \""$CUEWAVFILE"\" WAVE
1818 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1825 while [ $i -le "$TRACKS" ] ; do
1826 LBA=$(( $1 - $OFFSET ))
1827 printf " TRACK %02i AUDIO\n" $i
1828 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1829 if [ $MODE = PREGAP ] ; then
1830 echomsf " PREGAP " $(($OFFSET-150))
1832 echo " INDEX 00 00:00:00"
1835 echomsf " INDEX 01 " $LBA
1842 # This essentially the start of things
1845 # Query the CD to get the track info, unless the user specified -C
1846 # or we are using some actions which do not need the CDDB data at all
1847 #if [ ! X"$EXPACTIONS" = "X" ]; then
1849 #elif [ -z "$DISCID" ]; then
1850 if [ -z "$DISCID" ]; then
1851 vecho -n "Getting CD track info... "
1852 # In OSX, unmount the disc before a query
1853 if [ "$OSFLAVOUR" = "OSX" ]; then
1854 diskutil unmount ${CDROM#/dev/}
1856 case "$CDROMREADERSYNTAX" in
1858 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1859 case "$CUE2DISCID" in
1860 # FIXME # right now we have 2 cue2discid internal
1861 # implementations: builtin and abcde.cue2discid. Test
1862 # both of them and decide which one we want to use.
1864 #vecho "Using builtin cue2discid implementation..."
1865 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1867 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1869 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1870 TRACKS=${#OFFSETTIMES[@]}
1872 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1873 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1874 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1875 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1878 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1879 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1883 #vecho "Using external python cue2discid implementation..."
1884 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1888 log error "the input flac file does not contain a cuesheet."
1893 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1895 # if [ ! "$RET" = "0" ];then
1896 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1899 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1900 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1902 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1903 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1907 case "$CDDBMETHOD" in
1908 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1909 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1913 # Make sure there's a CD in there by checking cd-discid's return code
1914 if [ ! "$?" = "0" ]; then
1915 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1916 log error "cuesheet information from the flac file could not be read."
1917 log error "Perhaps the flac file does not contain a cuesheet?."
1920 log error "CD could not be read. Perhaps there's no CD in the drive?"
1924 # In OSX, remount the disc again
1925 if [ "$OSFLAVOUR" = "OSX" ]; then
1926 diskutil mount ${CDROM#/dev/}
1929 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1931 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1934 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1935 # This needs to be done now because a section of the resuming code will need
1938 # get the number of digits to pad TRACKNUM with - we'll use this later
1939 # a CD can only hold 99 tracks, but since we support a feature for starting
1940 # numbering the tracks from a given number, we might need to set it as a
1941 # variable for the user to define... or obtain it somehow.
1942 if [ "$PADTRACKS" = "y" ] ; then
1946 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1947 if [ -z "$TRACKQUEUE" ]; then
1948 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1949 case "$CDROMREADERSYNTAX" in
1950 cdparanoia|libcdio|debug)
1951 if [ "$WEHAVEACD" = "y" ]; then
1952 vecho "Querying the CD for audio tracks..."
1953 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1955 if [ ! "$RET" = "0" ];then
1956 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1958 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1959 CDPARANOIAAUDIOTRACKS="$TRACKS"
1961 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1962 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1963 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1964 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1966 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1967 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1971 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1974 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1976 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1977 log info "The disc does not contain any tracks. Giving up..."
1980 echo -n "Grabbing entire CD - tracks: "
1981 if [ ! "$PADTRACKS" = "y" ] ; then
1982 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1984 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1986 while [ "$X" -ne "$TRACKS" ]
1988 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1989 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1993 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1994 # User-supplied track queue.
1995 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1996 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1997 # Once cleaned, obtain the highest value in the trackqueue for number padding
1998 for LASTTRACK in $TRACKQUEUE; do :; done
1999 if [ ! "$PADTRACKS" = "y" ] ; then
2000 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2002 # Now we normalize the trackqueue
2003 for TRACK in $TRACKQUEUE ; do
2004 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2005 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2007 TRACKQUEUE=$PADTRACKQUEUE
2008 echo Grabbing tracks: "$TRACKQUEUE"
2011 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2013 # We have the discid, create a temp directory after it to store all the temp
2016 if [ -e "$ABCDETEMPDIR" ]; then
2017 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2018 # It already exists, see if it's a directory
2019 if [ ! -d "$ABCDETEMPDIR" ]; then
2020 # This is a file/socket/fifo/device/etc, not a directory
2023 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2024 echo "Please investigate, remove it, and rerun abcde." >&2
2028 # It's a directory, let's see if it's writable by us
2029 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2030 # Nope, complain and exit
2032 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2033 echo "Please investigate, remove it, and rerun abcde." >&2
2037 # See if it's populated
2038 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2039 # Wipe and start fresh
2040 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2041 echo -n "this directory to continue. Continue [y/N]? " >&2
2042 if [ "$INTERACTIVE" = "y" ]; then
2048 if [ "$ANSWER" != "y" ]; then
2051 rm -rf "$ABCDETEMPDIR" || exit 1
2052 mkdir -p "$ABCDETEMPDIR"
2053 if [ "$?" -gt "0" ]; then
2054 # Directory already exists or could not be created
2055 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2059 # Everything is fine. Check for ^encodetracklocation-
2060 # and encode-output entries in the status file and
2061 # remove them. These are not relevant across sessions.
2062 if [ -f "$ABCDETEMPDIR/status" ]; then
2063 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2064 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2065 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2067 # Remove old error messages
2068 if [ -f "$ABCDETEMPDIR/errors" ]; then
2069 rm -f "$ABCDETEMPDIR/errors"
2073 # We are starting from scratch
2074 mkdir -p "$ABCDETEMPDIR"
2075 if [ "$?" -gt "0" ]; then
2076 # Directory already exists or could not be created
2077 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2080 cat /dev/null > "$ABCDETEMPDIR/status"
2081 # Store the abcde version in the status file.
2082 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2084 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2085 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2086 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2087 vecho "Creating cue file..."
2088 case $CDROMREADERSYNTAX in
2090 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2091 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2093 log warning "the input flac file does not contain a cuesheet."
2097 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2098 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2100 log warning "reading the CUE sheet is still considered experimental"
2101 log warning "and there was a problem with the CD reading. abcde will continue,"
2102 log warning "but consider reporting the problem to the abcde author"
2108 # If we got the CDPARANOIA status and it is not recorded, save it now
2109 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2110 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2111 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2115 # Create the discid file
2116 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2117 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2118 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2123 # Create a proper CUE file based on the CUE file we created before.
2126 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2127 CUEFILE_OUT=$CUEFILE_IN.out
2128 ### FIXME ### checkstatus cddb
2129 if [ -e "$CDDBDATA" ]; then
2130 vecho "Adding metadata to the cue file..."
2131 # FIXME It doesn't preserve spaces! Why?
2132 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2134 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2135 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2136 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2140 cat "$CUEFILE_IN" | while read line
2142 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2143 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2144 # echo "$line" >> "$CUEFILE_OUT"
2145 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2146 eval track="\$TRACK$n"
2148 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2149 # When making a single-track rip, put the
2150 # actual file name into the file declaration
2151 # in the cue file so that it is usable by
2152 # music players and the like
2153 elif [ "$ONETRACK" = "y" ] &&
2154 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2156 TRACKFILE="$(mungefilename "$TRACKNAME")"
2157 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2158 ALBUMFILE="$(mungefilename "$DALBUM")"
2160 if [ "$VARIOUSARTISTS" = "y" ]; then
2161 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2163 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2166 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2169 # FIXME # If the lines above are uncommented, remove the line below.
2170 echo "$line" >> "$CUEFILE_OUT"
2173 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2174 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2180 # Parses a CDDB file and outputs the title and the track names.
2181 # Variables: CDDBFILE
2185 # List out disc title/author and contents
2186 if [ "$ONETRACK" = "y" ]; then
2187 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2189 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2190 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2191 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2192 if [ ! X"$PARSEDYEAR" = "X" ]; then
2193 echo "Year: $PARSEDYEAR"
2196 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2197 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2198 if [ ! X"$PARSEDGENRE" = "X" ]; then
2199 echo "Genre: $PARSEDGENRE"
2202 if [ ! "$ONETRACK" = "y" ]; then
2203 for TRACK in $(f_seq_row 1 $TRACKS)
2205 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2211 # Check for a local CDDB file, and report success
2214 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2216 CDDBLOCALSTATUS="notfound"
2217 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2220 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2221 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2222 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2223 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2224 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2225 CDDBLOCALMATCH=single
2226 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2227 CDDBLOCALMATCH=multiple
2232 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2233 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2234 CDDBLOCALMATCH=single
2239 # If the user has selected to check a local CDDB repo, we proceed with it
2240 case $CDDBLOCALMATCH in
2242 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2244 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2246 # List out disc title/author and contents
2247 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2248 cat "$RESULT" > "${CDDBLOCALREAD}"
2251 do_cddbparse "${CDDBLOCALREAD}"
2253 ##FIXME## QUICK HACK !!!!
2254 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2255 } >> "$ABCDETEMPDIR/cddblocalchoices"
2257 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2258 page "$ABCDETEMPDIR/cddblocalchoices"
2260 # It's all going to fit in one page, cat it
2261 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2263 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2264 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2265 CDDBLOCALCHOICENUM=-1
2266 if [ "$INTERACTIVE" = "y" ]; then
2267 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2268 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2269 read CDDBLOCALCHOICE
2270 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2271 # FIXME # Introduce diff's
2272 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2273 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2274 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2275 # Make sure we get a valid choice
2276 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2277 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2278 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2284 #echo "Selected ..."
2286 CDDBLOCALCHOICENUM=1
2288 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2289 #echo "Using local copy of CDDB data"
2290 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2291 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2292 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2293 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2294 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2295 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2296 CDDBLOCALSTATUS="found"
2298 #echo "Not using local copy of CDDB data"
2299 CDDBLOCALSTATUS="notfound"
2303 # List out disc title/author and contents
2304 do_cddbparse "${CDDBLOCALFILE}"
2305 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2306 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2308 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2310 if [ "$INTERACTIVE" = "y" ]; then
2312 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2313 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2316 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2320 if [ "$USELOCALRESP" = "y" ]; then
2321 #echo "Using local copy of CDDB data"
2322 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2323 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2324 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2325 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2326 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2327 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2328 CDDBLOCALSTATUS="single"
2330 #echo "Not using local copy of CDDB data"
2331 CDDBLOCALSTATUS="notfound"
2335 CDDBLOCALSTATUS="notfound"
2342 # Try to read CD-Text from the drive using icedax / cdda2wav
2345 if new_checkexec icedax; then
2346 CDTEXT_READER=icedax
2347 elif new_checkexec cdda2wav; then
2348 CDTEXT_READER=cdda2wav
2350 # Didn't find either, bail
2354 if [ "$OSFLAVOUR" = "OSX" ] ; then
2355 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2356 diskutil unmount ${CDROM#/dev/}
2357 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2358 CDDA2WAVCDROM="IODVDServices"
2359 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2360 CDDA2WAVCDROM="$CDROMID"
2362 if [ "$CDROMID" = "" ]; then
2363 CDDA2WAVCDROM="$CDROM"
2365 CDDA2WAVCDROM="$CDROMID"
2369 # Do we have CD-Text on the disc (and can the drive read it?)
2370 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2371 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2373 if [ $ERRORCODE -ne 0 ]; then
2374 # No CD-Text found, bail
2378 rm -f "$ABCDETEMPDIR/cddbchoices"
2380 # Make an empty template
2381 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2382 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2383 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2384 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2385 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2386 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2387 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2388 # List out disc title/author and contents
2389 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2390 for TRACK in $(f_seq_row 1 $TRACKS)
2392 TRACKM1=$(($TRACK - 1))
2393 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2394 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2395 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2396 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2398 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2399 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2400 echo >> "$ABCDETEMPDIR/cddbchoices"
2401 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2405 # Work with the musicbrainz WS API, then transform the results here so
2406 # they look (very) like the results from CDDB. Maybe not the best way
2407 # to go, but it Works For Me (TM)
2411 if checkstatus musicbrainz-readcomplete; then :; else
2412 vecho "Obtaining Musicbrainz results..."
2413 # If MB is to be used, interpret the query results and read all
2414 # the available entries.
2415 rm -f "$ABCDETEMPDIR/cddbchoices"
2416 CDDBCHOICES=1 # Overridden by multiple matches
2417 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2418 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2420 # The helper script will write disc matches out to
2421 # cddbread.*. Count how many we have
2422 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2423 # No matches. Use the normal cddb template for the user to
2425 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2426 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2427 # List out disc title/author and contents of template
2428 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2430 for TRACK in $(f_seq_row 1 $TRACKS)
2432 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2434 echo >> "$ABCDETEMPDIR/cddbchoices"
2435 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2436 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2437 echo 503 > "$ABCDETEMPDIR/cddbquery"
2439 # We have some matches
2440 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2441 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2443 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2444 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2445 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2446 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2447 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2448 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2449 # List out disc title/author and contents
2450 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2451 for TRACK in $(f_seq_row 1 $TRACKS)
2453 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2455 echo >> "$ABCDETEMPDIR/cddbchoices"
2457 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2458 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2459 for file in "$ABCDETEMPDIR"/cddbread.*
2461 X=$(echo $file | sed 's/^.*cddbread\.//g')
2462 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2463 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2464 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2465 # List out disc title/author and contents
2466 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2467 for TRACK in $(f_seq_row 1 $TRACKS)
2469 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2471 echo >> "$ABCDETEMPDIR/cddbchoices"
2473 echo "." >> "$ABCDETEMPDIR/cddbquery"
2476 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2483 # Perform CDDB protocol version check if it hasn't already been done
2484 if checkstatus cddb-statcomplete; then :; else
2485 if [ "$CDDBAVAIL" = "n" ]; then
2487 echo 503 > "$ABCDETEMPDIR/cddbstat"
2490 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2491 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2492 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2493 vecho "Checking CDDB server status..."
2494 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2495 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2496 case "$RESPONSECODE" in
2497 210) # 210 OK, status information follows (until terminating `.')
2500 501) # 501 Illegal CDDB protocol level: <n>.
2501 CDDBPROTO=`expr $CDDBPROTO - 1`
2503 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2504 # FreeDB TESTCD disc-id is used for query
2505 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2506 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2507 case "$RESPONSECODE" in
2508 2??) # Server responded, everything seems OK
2518 if test $rc -eq 1; then
2522 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2530 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2531 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2533 # Perform CDDB query if it hasn't already been done
2534 if checkstatus cddb-querycomplete; then :; else
2535 if [ "$CDDBAVAIL" = "n" ]; then
2537 echo 503 > "$ABCDETEMPDIR/cddbquery"
2538 # The default CDDBLOCALSTATUS is "notfound"
2539 # This part will be triggered if the user CDDB repo does not
2540 # contain the entry, or if we are not trying to use the repo.
2542 vecho "Querying the CDDB server..."
2543 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2544 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2545 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2551 # no match found in database,
2552 # wget/fetch error, or user requested not to use CDDB
2553 # Make up an error code (503) that abcde
2554 # will recognize in do_cddbread
2555 # and compensate by making a template
2556 echo 503 > "$ABCDETEMPDIR/cddbquery"
2558 *) # strange and unknown error
2559 echo ERRORCODE=$ERRORCODE
2560 echo "abcde: $CDDBTOOL returned unknown error code"
2564 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2571 # If it's not to be used, generate a template.
2572 # Then, display it (or them) and let the user choose/edit it
2573 if checkstatus cddb-readcomplete; then :; else
2574 vecho "Obtaining CDDB results..."
2575 # If CDDB is to be used, interpret the query results and read all
2576 # the available entries.
2577 rm -f "$ABCDETEMPDIR/cddbchoices"
2578 CDDBCHOICES=1 # Overridden by multiple matches
2579 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2580 case "$RESPONSECODE" in
2582 # One exact match, retrieve it
2583 # 200 [section] [discid] [artist] / [title]
2584 if checkstatus cddb-read-1-complete; then :; else
2585 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2586 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2587 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2588 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2589 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2591 # List out disc title/author and contents
2592 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2593 for TRACK in $(f_seq_row 1 $TRACKS)
2595 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2597 echo >> "$ABCDETEMPDIR/cddbchoices"
2601 case "$RESPONSECODE" in
2602 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2603 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2604 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2606 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2607 # List out disc title/author and contents of template
2608 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2610 for TRACK in $(f_seq_row 1 $TRACKS)
2612 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2614 echo >> "$ABCDETEMPDIR/cddbchoices"
2615 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2616 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2619 # Multiple exact, (possibly multiple) inexact matches
2621 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2622 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2623 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2624 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2625 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2627 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2629 vecho -n "Retrieving multiple matches... "
2630 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2631 read DISCINFO # eat top line
2635 if checkstatus cddb-read-$X-complete; then :; else
2636 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2637 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2639 # List out disc title/author and contents
2640 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2641 for TRACK in $(f_seq_row 1 $TRACKS)
2643 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2645 echo >> "$ABCDETEMPDIR/cddbchoices"
2648 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2652 for TRACK in $(f_seq_row 1 $TRACKS)
2654 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2656 echo >> "$ABCDETEMPDIR/cddbchoices"
2657 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2658 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2661 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2668 if checkstatus cddb-edit >/dev/null; then
2669 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2670 VARIOUSARTISTS="$(checkstatus variousartists)"
2671 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2674 if [ "$INTERACTIVE" = "y" ]; then
2675 # We should show the CDDB results both when we are not using the local CDDB repo
2676 # or when we are using it but we could not find a proper match
2677 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2678 # Display the $ABCDETEMPDIR/cddbchoices file created above
2679 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2680 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2681 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2682 CHOICE=$(checkstatus cddb-choice)
2683 if [ -n "$CHOICE" ] ; then
2684 case $CDDBCHOICES in
2685 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2686 log error "CDDB query failed!"