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-2016 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.8.2-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,embedalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
25 #echo "-A Experimental actions (retag, transcode)"
26 echo "-b Enable batch normalization"
27 echo "-B Embed albumart (this also activates getalbumart)"
29 echo " Specify a configuration file (overrides system and user config files)"
31 echo " Specify discid to resume from (only needed if you no longer have the cd)"
33 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
34 echo "-D Debugging mode (equivalent to sh -x abcde)"
35 echo "-e Erase encoded track information from status file"
36 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
37 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
38 echo "-G Get album art by using the 'getalbumart' action"
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,mka,wv,ape,mp2,tta,aiff). 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 "-Q Select CDDBMETHOD from the command line. Choice is cddb or musicbrainz".
55 echo "-r <host1[,host2]...>"
56 echo " Also encode on these remote hosts"
58 echo " Show fields from the CDDB info (year,genre)"
59 echo "-S <#> Set the CD speed"
60 echo "-t <#> Start the track numbering at a given number"
61 echo "-T <#> Same as -t but modifies tag numbering"
62 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
63 echo "-v Show version number and exit"
64 echo "-V Be a bit more verbose about what is happening behind the scenes"
65 echo "-x Eject CD after all tracks are read"
67 echo " Add a comment to the CD tracks"
68 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
69 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
71 echo "Tracks is a space-delimited list of tracks to grab."
72 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
74 #echo "Double hyphens are used to concatenate tracks"
79 echo "$@" >> "$ABCDETEMPDIR/status"
82 # log [level] [message]
84 # log outputs the right message in a common format
90 error) >&2 echo "[ERROR] abcde: $@" >&2 ;;
91 warning) >&2 echo "[WARNING] $@" >&2 ;;
92 info) >&4 echo "[INFO] $@" ;;
96 # Functions to replace the need of seq, which is too distribution dependent.
100 while [ $i -ne `expr $2 + 1` ]
110 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
111 while [ $i -ne `expr $2 + 1` ]
118 log error "syntax error while processing track numbers ($i)"
123 # Functions to replace the need of awk {print $1} and {print $NF}
126 if [ X"$1" = "X" ]; then
127 for first in `cat`; do
138 if [ X"$1" = "X" ]; then
139 for stdin in `cat`; do
143 for last in $@ ; do :; done
148 # checkstatus [blurb]
149 # Returns "0" if the blurb was found, returns 1 if it wasn't
150 # Puts the blurb content, if available, on stdout.
151 # Otherwise, returns "".
154 # Take the last line in the status file if there's multiple matches
156 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
158 if [ -z "$BLURB" ]; then
163 # See if there's a = in it
164 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
165 echo "$(echo $BLURB | cut -f2- -d=)"
171 # checkwarnings [blurb]
172 # Returns "0" if the blurb was found (meaning there was an warning),
173 # returns 1 if it wasn't (yes this is a little backwards).
174 # Does not print the blurb on stdout.
175 # Otherwise, returns "".
178 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
181 # Take the last line in the status file if there's multiple matches
183 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
185 if [ -z "$BLURB" ]; then
186 # negative, we did not have a negative...
189 # affirmative, we had a negative...
194 # checkerrors [blurb]
195 # Returns "0" if the blurb was found (meaning there was an error),
196 # returns 1 if it wasn't (yes this is a little backwards).
197 # Does not print the blurb on stdout.
198 # Otherwise, returns "".
201 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
204 # Take the last line in the status file if there's multiple matches
206 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
208 if [ -z "$BLURB" ]; then
209 # negative, we did not have a negative...
212 # affirmative, we had a negative...
218 # Finds the right pager in the system to display a file
222 # Use the debian sensible-pager wrapper to pick the pager
223 # user has requested via their $PAGER environment variable
224 if [ -x "/usr/bin/sensible-pager" ]; then
225 /usr/bin/sensible-pager "$PAGEFILE"
226 elif [ -x "$PAGER" ]; then
227 # That failed, try to load the preferred editor, starting
228 # with their PAGER variable
230 # If that fails, check for less
231 elif [ -x /usr/bin/less ]; then
232 /usr/bin/less -f "$PAGEFILE"
233 # more should be on all UNIX systems
234 elif [ -x /bin/more ]; then
235 /bin/more "$PAGEFILE"
237 # No bananas, just cat the thing
242 # run_command [blurb] [command...]
243 # Runs a command, silently if necessary, and updates the status file
249 # See if this is supposed to be silent
250 if [ "$(checkstatus encode-output)" = "loud" ]; then
254 # Special case for SMP, since
255 # encoder output is never displayed, don't mute echos
256 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
265 normalize|normalize-audio)
266 if [ "$RETURN" = "2" ]; then
267 # File was already normalized.
272 if [ "$RETURN" != "0" ]; then
273 # Put an error in the errors file. For various reasons we
274 # can't capture a copy of the program's output but we can
275 # log what we attempted to execute and the error code
276 # returned by the program.
277 if [ "$BLURB" ]; then
280 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
281 return $RETURN # Do not pass go, do not update the status file
283 if [ "$BLURB" ]; then
284 echo $BLURB >> "$ABCDETEMPDIR/status"
288 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
289 # distributed under the terms of the GNU GPL v2 or later, at your option
291 # Function to determine if a word contains a slash.
300 # Function to give the relative path from one file to another.
301 # Usage: relpath fromfile tofile
302 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
303 # (the result would be Album/Song.mp3)
304 # Output is relative path to $2 from $1 on stdout
306 # This code has the following restrictions:
307 # Multiple ////s are not collapsed into single /s, with strange effects.
308 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
309 # If FR is a directory it must have a trailing /
317 /*) ;; # No processing is needed for absolute paths
319 # Loop through common prefixes, ignoring them.
320 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
322 FR="$(echo "$FR" | cut -d/ -f2-)"
323 TO="$(echo "$TO" | cut -d/ -f2-)"
325 # Loop through directory portions left in FR, adding appropriate ../s.
328 FR="$(echo "$FR" | cut -d/ -f2-)"
339 if [ ! "$@" = "" ]; then
340 # Cut off any command-line option we added in
341 X=$(echo $@ | cut -d' ' -f2)
342 if [ "$(which $X)" = "" ]; then
344 elif [ ! -x $(which $X) ]; then
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X=$(echo $@ | cut -d' ' -f2)
356 # Test for built-in abcde.function
357 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
358 if [ "$(which $X)" = "" ]; then
359 log error "$X is not in your path." >&2
360 log info "Define the full path to the executable if it exists on your system." >&2
361 if [ -e /etc/debian_* ] ; then
363 oggenc) MISSING_PACKAGE=vorbis-tools ;;
364 lame|flac) MISSING_PACKAGE=$X ;;
366 log info "Hint: sudo apt-get install $MISSING_PACKAGE" >&2
369 elif [ ! -x "$(which $X)" ]; then
370 log error "$X is not executable." >&2
376 # diffentries <filename> <max_value> <entry1>,<entry2>
377 # max_value: the range of entries goes from 1 to <max_value>
382 local CDDBDIFFCHOICES=$1
384 local CDDBDIFFCHOICE="$@"
385 if [ ! X"$DIFF" = "X" ]; then
386 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
387 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
388 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
389 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
390 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
391 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
393 # We parse the 2 choices to diff, store them in temporary files and diff them.
394 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
395 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
397 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
398 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
399 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
400 page "$ABCDETEMPDIR/$FILENAME.diff"
402 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
406 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
411 # Finds an specific field from cddbinfo
416 TRACKNAME="$(grep -a ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
419 TRACKNAME="$(grep -a ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
422 grep -a ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
428 # Get the track number we are going to use for different actions
431 if [ -n "$STARTTRACKNUMBER" ] ; then
432 # Get the trackpadding from the current track, also trim whitespace for MacOSX
433 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
434 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
436 TRACKNUM=${UTRACKNUM}
442 # Calculate cddb disc ids without requiring specialized helper programs.
443 # largely copied from cd-discid and musicbrainz examples. some of the steps
444 # don't make sense, but they're necessary to match the ids generated by other
447 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
448 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
449 # 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
450 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
451 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
452 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
454 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
457 if [ X"$LEADOUT" = "X" ]; then
458 log warning "Error trying to calculate disc ids without lead-out information."
462 # default to a two second lead-in
464 LEADIN=${LEADIN:=150}
466 # number of cdframes per second
469 # reset cddb checksum for cddb disc-id calululation
473 for OFFSET in $(echo $OFFSETS)
475 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
477 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
478 while [ $OFFSETTIME -gt 0 ]; do
479 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
480 OFFSETTIME=$(($OFFSETTIME / 10))
485 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
487 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
488 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
490 case "$CDDBMETHOD" in
492 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
495 # FIXME: don't assume the first track is 1
496 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
497 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
501 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
506 if checkstatus replaygain; then :; else
507 run_command "" echo "Adding replaygain information..."
508 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
512 OUTPUT=$OGGOUTPUTCONTAINER
515 OUTPUT=$OPUSOUTPUTCONTAINER
518 OUTPUT=$FLACOUTPUTCONTAINER
526 for UTRACKNUM in $TRACKQUEUE
528 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
529 getcddbinfo TRACKNAME
531 TRACKFILE="$(mungetrackname "$TRACKNAME")"
532 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
533 ALBUMFILE="$(mungealbumname "$DALBUM")"
534 GENRE="$(mungegenre "$GENRE")"
535 YEAR=${CDYEAR:-$CDYEAR}
537 if [ "$ONETRACK" = "y" ]; then
538 if [ "$VARIOUSARTISTS" = "y" ]; then
539 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
541 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
544 if [ "$VARIOUSARTISTS" = "y" ]; then
545 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
547 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
550 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
551 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
555 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
556 #run_command replaygain-flac true
559 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
562 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
565 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
568 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
573 if checkerrors "replaygain-.{3,6}"; then :; else
574 run_command replaygain true
579 # This code splits the a Various Artist track name from one of the following
582 # forward: Artist / Track
583 # forward-dash: Artist - Track
584 # reverse: Track / Artist
585 # reverse-dash: Track - Artist
586 # colon: Artist: Track
587 # trailing-paren: Artist (Track)
590 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
593 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
594 case "$VARIOUSARTISTSTYLE" in
596 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
597 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
598 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
601 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
602 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
603 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
606 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
607 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
608 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
611 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
612 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
613 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
616 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
617 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
618 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
621 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
622 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
623 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
626 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
627 TRACKARTIST="Various"
629 TRACKARTIST="$DARTIST"
634 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
638 "classic rock") id=1 ;;
656 "industrial") id=19 ;;
657 "alternative") id=20 ;;
659 "death metal") id=22 ;;
661 "soundtrack") id=24 ;;
662 "euro-techno") id=25 ;;
666 "jazz+funk") id=29 ;;
669 "classical") id=32 ;;
670 "instrumental") id=33 ;;
674 "sound clip") id=37 ;;
677 "alt. rock") id=40 ;;
682 "meditative") id=45 ;;
683 "instrum. pop") id=46 ;;
684 "instrum. rock") id=47 ;;
688 "techno-indust.") id=51 ;;
689 "electronic") id=52 ;;
691 "eurodance") id=54 ;;
693 "southern rock") id=56 ;;
698 "christian rap") id=61 ;;
699 "pop/funk"|"pop / funk") id=62 ;;
701 "native american") id=64 ;;
704 "psychadelic") id=67 ;;
706 "showtunes") id=69 ;;
710 "acid punk") id=73 ;;
711 "acid jazz") id=74 ;;
715 "rock & roll") id=78 ;;
716 "hard rock") id=79 ;;
718 "folk/rock") id=81 ;;
719 "national folk") id=82 ;;
726 "bluegrass") id=89 ;;
727 "avantgarde") id=90 ;;
728 "gothic rock") id=91 ;;
729 "progress. rock") id=92 ;;
730 "psychadel. rock") id=93 ;;
731 "symphonic rock") id=94 ;;
732 "slow rock") id=95 ;;
735 "easy listening") id=98 ;;
741 "chamber music") id=104 ;;
743 "symphony") id=106 ;;
744 "booty bass") id=107 ;;
746 "porn groove") id=109 ;;
748 "slow jam") id=111 ;;
752 "folklore") id=115 ;;
754 "power ballad") id=117 ;;
755 "rhythmic soul") id=118 ;;
756 "freestyle") id=119 ;;
758 "punk rock") id=121 ;;
759 "drum solo") id=122 ;;
760 "a capella") id=123 ;;
761 "euro-house") id=124 ;;
762 "dance hall") id=125 ;;
764 "drum & bass") id=127 ;;
765 "club-house") id=128 ;;
766 "hardcore") id=129 ;;
770 "negerpunk") id=133 ;;
771 "polsk punk") id=134 ;;
773 "christian gangsta rap") id=136 ;;
774 "heavy metal") id=137 ;;
775 "black metal") id=138 ;;
776 "crossover") id=139 ;;
777 "contemporary christian")id=140 ;;
778 "christian rock") id=141 ;;
779 "merengue") id=142 ;;
781 "thrash metal") id=144 ;;
784 "synthpop") id=147 ;;
785 "rock/pop"|"rock / pop") id=148 ;;
792 # do_tag [tracknumber]
793 # id3 tags a filename
795 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
796 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
799 COMMENTOUTPUT="$(eval echo ${COMMENT})"
800 if [ -z "$COMMENTOUTPUT" ]; then
801 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
803 if [ "$CDDBMETHOD" = "cddb" ]; then
804 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
806 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
807 # If we want to start the tracks with a given number, we need to modify the
808 # TRACKNUM value before evaluation
809 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
812 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
816 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
817 GENREID=$(do_getgenreid "${CDGENRE}")
818 # Set TPE2 in case we have a Various Artists rip.
820 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
847 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
848 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
849 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
850 -y "$CDYEAR" -g "$GENREID" \
851 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
852 "$ABCDETEMPDIR/track$1.$OUTPUT"
855 # FIXME # track numbers in mp3 come with 1/10, so we cannot
856 # happily substitute them with $TRACKNUM
858 eyed3_06) addopts=( \
859 ${ENCODING:+--set-encoding="$ENCODING"} \
860 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
861 # We set 'recording-date' so the date tag will show
862 # in Audacious, vlc and friends... Andrew.
863 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
864 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
867 ${ENCODING:+--encoding="$ENCODING"} \
868 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
869 # We set 'recording-date' so the date tag will show
870 # in Audacious, vlc and friends... Andrew.
871 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
872 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
875 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
877 -a "$TRACKARTIST" -t "$TRACKNAME" \
878 -G "$GENREID" -n "${TRACKNUM:-$1}" \
879 ${TRACKNUM:+-N "$TRACKS"} \
881 "$ABCDETEMPDIR/track$1.$OUTPUT"
884 log error "Internal error: ID3SYNTAX has an illegal value"
890 case "$OGGENCODERSYNTAX" in
892 # vorbiscomment can't do in-place modification, mv the file first
893 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
894 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
898 # https://www.xiph.org/vorbis/doc/v-comment.html
900 echo ARTIST="$TRACKARTIST"
902 echo TITLE="$TRACKNAME"
903 if [ -n "$CDYEAR" ]; then
906 if [ -n "$CDGENRE" ]; then
907 echo GENRE="$CDGENRE"
909 echo TRACKNUMBER=${TRACKNUM:-$1}
910 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
911 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
912 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
913 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
914 echo TRACKTOTAL="${TRACKS}"
915 if [ -n "$DISCNUMBER" ]; then
916 echo DISCNUMBER="$DISCNUMBER"
918 echo CDDB=$CDDBDISCID
919 if [ "$(eval echo ${COMMENT})" != "" ]; then
920 case "$COMMENTOUTPUT" in
921 *=*) echo "$COMMENTOUTPUT";;
922 *) echo COMMENT="$COMMENTOUTPUT";;
925 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
926 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
927 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
928 # Doublecheck that the commented file was created
929 # successfully before wiping the original
930 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
931 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
933 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
939 run_command tagtrack-$OUTPUT-$1 true
942 run_command tagtrack-$OUTPUT-$1 true
945 run_command tagtrack-$OUTPUT-$1 true
949 echo ARTIST="$TRACKARTIST"
951 echo TITLE="$TRACKNAME"
952 if [ -n "$CDYEAR" ]; then
955 if [ -n "$CDGENRE" ]; then
956 echo GENRE="$CDGENRE"
958 echo TRACKNUMBER="${TRACKNUM:-$1}"
959 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
960 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
961 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
962 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
963 echo TRACKTOTAL="${TRACKS}"
964 if [ -n "$DISCNUMBER" ]; then
965 echo DISCNUMBER="$DISCNUMBER"
967 echo CDDB="$CDDBDISCID"
968 if [ "$(eval echo ${COMMENT})" != "" ]; then
969 case "$COMMENTOUTPUT" in
970 *=*) echo "$COMMENTOUTPUT";;
971 *) echo COMMENT="$COMMENTOUTPUT";;
974 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
975 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
978 run_command tagtrack-$OUTPUT-$1 true
981 run_command tagtrack-$OUTPUT-$1 true
984 run_command tagtrack-$OUTPUT-$1 true
987 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
988 # Console port (mac) used for encoding does not have the ability to tag.
989 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
990 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
991 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
994 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
995 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
996 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
997 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
998 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
999 "$ABCDETEMPDIR/track$1.mp2"
1002 run_command tagtrack-$OUTPUT-$1 true
1005 case "$AACENCODERSYNTAX" in
1007 # We will use inline tagging...
1008 run_command tagtrack-$OUTPUT-$1 true
1011 # Tag post encode with neroAacTag...
1012 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
1013 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
1014 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1017 run_command tagtrack-$OUTPUT-$1 true
1020 run_command tagtrack-$OUTPUT-$1 true
1023 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1024 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1025 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$ATOMICPARSLEY" "$ABCDETEMPDIR/track$1.m4a" \
1026 --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum=${TRACKNUM:-$1} \
1027 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
1030 run_command tagtrack-$OUTPUT-$1 true
1035 # We use mid3v2 tagging for True Audio:
1036 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1037 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1038 "$ABCDETEMPDIR/track$1.tta"
1041 run_command tagtrack-$OUTPUT-$1 true
1045 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1046 run_command tagtrack-$1 true
1052 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1055 # The commands here don't go through run_command because they're never
1056 # supposed to be silenced
1057 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1058 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1062 case "$MP3ENCODERSYNTAX" in
1067 for UTRACKNUM in $TRACKQUEUE
1069 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1071 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1073 if [ "$RETURN" != "0" ]; then
1074 echo "nogap-encode: $ENCODER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1076 for UTRACKNUM in $TRACKQUEUE
1078 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1079 #run_command encodetrack-$UTRACKNUM true
1088 if checkerrors "nogap-encode"; then :; else
1089 if [ ! "$KEEPWAVS" = "y" ] ; then
1090 if [ ! "$KEEPWAVS" = "move" ] ; then
1095 # Other encoders fall through to normal encoding as the tracks have not
1096 # been entered in the status file.
1099 # do_encode [tracknumber] [hostname]
1100 # If no hostname is specified, encode locally
1102 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1103 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1106 if [ "$USEPIPES" = "y" ]; then
1109 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1112 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1115 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1118 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1121 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1124 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1127 TEMPARG="PIPE_$SPEEXENCODER"
1130 TEMPARG="PIPE_$MPCENCODER"
1133 TEMPARG="PIPE_$WVENCODERSYNTAX"
1136 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1139 TEMPARG="PIPE_$AACENCODERSYNTAX"
1142 TEMPARG="PIPE_$AACENCODERSYNTAX"
1145 IN="$( eval echo "\$$TEMPARG" )"
1147 IN="$ABCDETEMPDIR/track$1.wav"
1149 # We need IN to proceed, if we are not using pipes.
1150 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1151 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1153 case "$TMPOUTPUT" in
1155 OUTPUT=$OGGOUTPUTCONTAINER
1158 OUTPUT=$OPUSOUTPUTCONTAINER
1161 OUTPUT=$MKAOUTPUTCONTAINER
1164 OUTPUT=$AIFFOUTPUTCONTAINER
1167 OUTPUT=$FLACOUTPUTCONTAINER
1173 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1174 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1177 if [ X"$USEPIPES" = "Xy" ]; then
1179 # We need a way to store the creation of the files when using PIPES
1180 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1181 # When piping it does not make sense to have a higher nice for
1182 # reading than for encoding, since it will be hold by the
1183 # encoding process. Setting an effective nice, to calm down a
1184 # bit the reading process.
1185 EFFECTIVE_NICE=$READNICE
1187 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1188 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1189 EFFECTIVE_NICE=$ENCNICE
1195 case "$MP3ENCODERSYNTAX" in
1196 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1197 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1198 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1199 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1203 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1210 case "$OGGENCODERSYNTAX" in
1211 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1212 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1216 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1223 case "$OPUSENCODERSYNTAX" in
1225 # Tag the file at encode time, as it can't be done after encoding.
1226 if [ "$DOTAG" = "y" ]; then
1227 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1228 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1229 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1231 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1237 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1242 case "$MKAENCODERSYNTAX" in
1244 if [ "$DOTAG" = "y" ]; then
1245 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS -metadata artist="$TRACKARTIST" \
1246 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1247 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1249 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1255 case "$AIFFENCODERSYNTAX" in
1257 if [ "$DOTAG" = "y" ]; then
1258 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS -metadata artist="$TRACKARTIST" \
1259 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1260 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1262 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1270 case "$FLACENCODERSYNTAX" in
1271 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1276 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1277 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1282 if [ "$(eval echo ${COMMENT})" != "" ]; then
1285 *) COMMENT="COMMENT=$COMMENT" ;;
1288 # Tag the file at encode time, as it can't be done after encoding.
1289 if [ "$DOTAG" = "y" ]; then
1290 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1291 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1293 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1297 # Tag the file inline at encode time.
1298 if [ "$DOTAG" = "y" ]; then
1299 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1300 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1302 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1306 case "$TTAENCODERSYNTAX" in
1307 # tta is the newer version with a small syntax change...
1309 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1312 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1317 case "$WVENCODERSYNTAX" in
1319 if [ "$DOTAG" = "y" ]; then
1320 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1321 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1323 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1327 if [ "$DOTAG" = "y" ]; then
1328 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1329 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1330 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1332 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1338 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1341 case "$MP2ENCODERSYNTAX" in
1343 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1346 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1351 # aac container is only used to catch faac encoded files where faac
1352 # is compiled without mp4 support (with libmp4v2).
1353 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1356 case "$AACENCODERSYNTAX" in
1358 if [ "$DOTAG" = "y" ]; then
1359 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1360 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1362 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1366 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1369 if [ "$DOTAG" = "y" ]; then
1370 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1371 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1373 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1377 if [ "$DOTAG" = "y" ]; then
1378 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1379 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1381 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1385 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1388 if [ "$DOTAG" = "y" ]; then
1389 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1390 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1391 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1393 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1399 # In case of wav output we need nothing. Just keep the wavs.
1400 # But we need the following to allow full logging and subsequent
1401 # successful cleaning of $ABCDETEMPDIR.
1402 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1407 # Only remove .wav if the encoding succeeded
1408 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1409 run_command encodetrack-$1 true
1410 if [ ! "$KEEPWAVS" = "y" ] ; then
1411 if [ ! "$KEEPWAVS" = "move" ] ; then
1417 run_command "" echo "HEH! The file we were about to encode disappeared:"
1418 run_command "" echo ">> $IN"
1419 run_command encodetrack-$1 false
1423 # do_preprocess [tracknumber]
1425 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1428 # IN="$ABCDETEMPDIR/track$1.wav"
1429 # # We need IN to proceed.
1430 # if [ -s "$IN" ] ; then
1431 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1433 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1434 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1435 # case "$POSTPROCESSFORMAT" in
1437 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1439 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1441 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1443 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1445 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1448 # # Only remove .wav if the encoding succeeded
1449 # if checkerrors "preprocess-(.{3,4})-$1"; then
1450 # run_command preprocess-$1 false
1452 # run_command preprocess-$1 true
1455 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1456 # echo "HEH! The file we were about to pre-process disappeared:"
1459 # run_command preprocess-$1 false
1464 # do_postprocess [tracknumber]
1466 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1469 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1471 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1472 # # We need IN to proceed.
1473 # if [ -s "$IN" ] ; then
1474 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1475 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1476 # case "$POSTPROCESSFORMAT" in
1478 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1480 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1482 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1484 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1486 # # Only remove .wav if the encoding succeeded
1487 # if checkerrors "postprocess-(.{3,4})-$1"; then
1488 # run_command postprocess-$1 false
1490 # run_command postprocess-$1 true
1493 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1494 # echo "HEH! The file we were about to post-process disappeared:"
1497 # run_command postprocess-$1 false
1512 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1516 # The commands here don't go through run_command because they're never supposed to be silenced
1517 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1522 for UTRACKNUM in $TRACKQUEUE
1524 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1526 # FIXME # Hard-coded batch option!
1527 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1529 if [ "$RETURN" != "0" ]; then
1530 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1532 for UTRACKNUM in $TRACKQUEUE
1534 echo "normalizetrack-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1540 # do_batch_normalize
1542 # NORMALIZER, NORMALIZEROPTS
1543 do_batch_normalize ()
1545 # The commands here don't go through run_command because they're never supposed to be silenced
1546 echo "Batch normalizing tracks: $TRACKQUEUE"
1551 for UTRACKNUM in $TRACKQUEUE
1553 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1555 # XXX: Hard-coded batch option!
1556 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1558 if [ "$RETURN" != "0" ]; then
1559 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1561 for UTRACKNUM in $TRACKQUEUE
1563 echo "normalizetrack-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1569 # do_normalize [tracknumber]
1571 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1574 IN="$ABCDETEMPDIR/track$1.wav"
1575 if [ -e "$IN" ] ; then
1576 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1577 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1579 if [ "$(checkstatus encode-output)" = "loud" ]; then
1580 echo "HEH! The file we were about to normalize disappeared:"
1583 run_command normalizetrack-$1 false "File $IN was not found"
1587 # do_move [tracknumber]
1588 # Deduces the outfile from environment variables
1589 # Creates directory if necessary
1591 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1594 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1596 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1597 # defined the OUTPUTFILE:
1600 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1601 ALBUMFILE="$(mungealbumname "$DALBUM")"
1602 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1603 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1604 GENRE="$(mungegenre "$GENRE")"
1605 YEAR=${CDYEAR:-$CDYEAR}
1606 # If we want to start the tracks with a given number, we need to modify
1607 # the TRACKNUM value before evaluation
1609 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1610 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1611 if [ "$ONETRACK" = "y" ]; then
1612 if [ "$VARIOUSARTISTS" = "y" ]; then
1613 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1615 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1618 if [ "$VARIOUSARTISTS" = "y" ]; then
1619 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1621 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1624 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1625 # Once we know the specific output was successful, we can change
1626 # the OUTPUT to the value containing the container
1629 OUTPUT=$OGGOUTPUTCONTAINER
1632 OUTPUT=$OPUSOUTPUTCONTAINER
1635 OUTPUT=$MKAOUTPUTCONTAINER
1638 OUTPUT=$AIFFOUTPUTCONTAINER
1641 OUTPUT=$FLACOUTPUTCONTAINER
1647 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1648 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1651 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1652 # FIXME # introduce warnings?
1655 # mkdir -p shouldn't return an error if the directory already exists
1656 mkdir -p "$OUTPUTFILEDIR"
1657 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1658 if checkstatus movetrack-output-$OUTPUT; then :; else
1659 run_command movetrack-output-$OUTPUT true
1664 # mkdir -p shouldn't return an error if the directory already exists
1665 mkdir -p "$OUTPUTFILEDIR"
1666 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1667 if checkstatus movetrack-output-$OUTPUT; then :; else
1668 run_command movetrack-output-$OUTPUT true
1672 # Lets move the cue file
1673 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1674 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1675 if checkstatus movecue-$OUTPUT; then :; else
1676 # Silence the Copying output since it overlaps with encoding processes...
1677 #run_command '' vecho "Copying cue file to its destination directory..."
1678 if checkstatus onetrack >/dev/null ; then
1681 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1682 # We dont have the dir, since it was not created before.
1685 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1688 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1689 # http://brianvictor.tripod.com/mp3cue.htm#details
1690 [a-z0-9][a-z0-9][a-z0-9])
1691 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1694 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1698 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1700 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1709 # Create the playlist if wanted
1711 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1712 # VARIOUSARTISTS, OUTPUTDIR
1715 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1719 OUTPUT=$OGGOUTPUTCONTAINER
1722 OUTPUT=$OPUSOUTPUTCONTAINER
1725 OUTPUT=$MKAOUTPUTCONTAINER
1728 OUTPUT=$AIFFOUTPUTCONTAINER
1731 OUTPUT=$FLACOUTPUTCONTAINER
1737 # Create a playlist file for the playlist data to go into.
1738 # We used to wipe it out if it existed. Now we request permission if interactive.
1739 for LASTTRACK in $TRACKQUEUE; do :; done
1740 ALBUMFILE="$(mungealbumname "$DALBUM")"
1741 ARTISTFILE="$(mungeartistname "$DARTIST")"
1742 GENRE="$(mungegenre "$GENRE")"
1743 YEAR=${CDYEAR:-$CDYEAR}
1744 if [ "$VARIOUSARTISTS" = "y" ] ; then
1745 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1747 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1749 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1750 mkdir -p "$FINALPLAYLISTDIR"
1751 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1752 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1753 if [ "$INTERACTIVE" = "y" ]; then
1754 while [ "$DONE" != "y" ]; do
1756 case $ERASEPLAYLIST in
1757 e|E|a|A|k|K) DONE=y ;;
1758 "") ERASEPLAYLIST=e ; DONE=y ;;
1766 # Once we erase the playlist, we use append to create the new one.
1767 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1769 # The playlist does not exist, so we can safelly use append to create the new list
1772 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1773 touch "$OUTPUTDIR/$PLAYLISTFILE"
1774 for UTRACKNUM in $TRACKQUEUE
1776 # Shares some code with do_move since the filenames have to match
1777 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1778 getcddbinfo TRACKNAME
1780 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1781 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1782 ALBUMFILE="$(mungealbumname "$DALBUM")"
1783 # If we want to start the tracks with a given number, we need to modify the
1784 # TRACKNUM value before evaluation
1786 if [ "$VARIOUSARTISTS" = "y" ]; then
1787 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1789 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1791 if [ "$VARIOUSARTISTS" = "y" ]; then
1792 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1793 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1795 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1798 if [ "$PLAYLISTDATAPREFIX" ]; then
1799 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1801 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1806 ## this will convert the playlist to have CRLF line-endings, if specified
1807 ## (some hardware players insist on CRLF endings)
1808 if [ "$DOSPLAYLIST" = "y" ]; then
1809 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1810 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1811 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1813 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1818 # This function reads a cuefile on stdin and writes an extended
1819 # cddb query on stdout. Any PREGAP for track 1 is properly
1820 # handled, although cue files embedded in FLAC files do not
1821 # appear to properly store the PREGAP setting. :(
1822 abcde.cue2discid () {
1827 while [ $val -gt 0 ] ; do
1828 ret=$(( $ret + ( $val % 10) ))
1829 val=$(( $val / 10 ))
1839 local first second third
1840 first=$(expr ${1} + 0 )
1841 second=$(expr ${2} + 0 )
1842 third=$(expr ${3} + 0 )
1844 echo $(( ((($first * 60) + $second) * 75) + $third ))
1854 while read line ; do
1857 TRACK) i=$(( i + 1 ))
1859 INDEX) if [ "$2" -eq 1 ] ; then
1861 START=$(( $LBA + $PREGAP + $OFFSET ))
1863 X=$(cddb_sum $(( $START / 75 )) )
1867 PREGAP) PREGAP=$(msf2lba $2)
1871 LEADOUT=$(( $4 / 588 ))
1874 LEADIN=$(( $3 / 588 ))
1883 LEADOUT=$(( $LEADOUT + $LEADIN ))
1885 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1886 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1887 printf "%08x %i" $DISCID $TRACKS
1890 while [ $j -le $TRACKS ] ; do
1891 eval echo -n "\" \$TRACK$j\""
1894 echo " $(( $LEADOUT / 75 ))"
1898 # abcde.mkcue [--wholedisk]
1899 # This creates a cuefile directly from the extended discid information
1900 # The --wholedisk option controls whether we're ripping data from the
1901 # start of track one or from the start of the disk (usually, but not
1902 # always the same thing!)
1904 # Track one leadin/pregap (if any) handeling:
1905 # --wholedisk specified:
1908 # INDEX 01 <pregap value>
1909 # Remaining track index values unchanged from disc TOC
1911 # --wholedisk not specified
1913 # PREGAP <pregap value>
1915 # Remaining track index values offset by <pregap value>
1922 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1925 local MODE DISCID TRACKS
1929 if [ "$1" = --wholedisc ] ; then
1935 vecho "One track is $ONETRACK"
1936 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1937 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1938 ALBUMFILE="$(mungealbumname "$DALBUM")"
1939 if [ "$ONETRACK" = "y" ]; then
1940 if [ "$VARIOUSARTISTS" = "y" ]; then
1941 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1943 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1945 vecho "Cue wav file is $CUEWAVFILE"
1947 CUEWAVFILE="dummy.wav"
1956 echo REM DISCID $DISCID
1957 echo FILE \""$CUEWAVFILE"\" WAVE
1959 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1966 while [ $i -le "$TRACKS" ] ; do
1967 LBA=$(( $1 - $OFFSET ))
1968 printf " TRACK %02i AUDIO\n" $i
1969 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1970 if [ $MODE = PREGAP ] ; then
1971 echomsf " PREGAP " $(($OFFSET-150))
1973 echo " INDEX 00 00:00:00"
1976 echomsf " INDEX 01 " $LBA
1983 # This essentially the start of things
1986 # Query the CD to get the track info, unless the user specified -C
1987 # or we are using some actions which do not need the CDDB data at all
1988 #if [ ! X"$EXPACTIONS" = "X" ]; then
1990 #elif [ -z "$DISCID" ]; then
1991 if [ -z "$DISCID" ]; then
1992 vecho -n "Getting CD track info... "
1993 # In OSX, unmount the disc before a query
1994 if [ "$OSFLAVOUR" = "OSX" ]; then
1995 diskutil unmount ${CDROM#/dev/}
1997 case "$CDROMREADERSYNTAX" in
1999 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
2000 case "$CUE2DISCID" in
2001 # FIXME # right now we have 2 cue2discid internal
2002 # implementations: builtin and abcde.cue2discid. Test
2003 # both of them and decide which one we want to use.
2005 #vecho "Using builtin cue2discid implementation..."
2006 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2008 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2010 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2011 TRACKS=${#OFFSETTIMES[@]}
2013 #echo "processing offsetimes ${OFFSETTIMES[@]}"
2014 for OFFSETTIME in ${OFFSETTIMES[@]}; do
2015 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2016 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
2019 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2020 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2024 #vecho "Using external python cue2discid implementation..."
2025 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2029 log error "the input flac file does not contain a cuesheet."
2034 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2036 if [ ! "$RET" = "0" ];then
2037 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2040 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2041 CDPARANOIAAUDIOTRACKS="$TRACKS"
2043 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2044 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2048 case "$CDDBMETHOD" in
2049 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
2050 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
2054 # Make sure there's a CD in there by checking cd-discid's return code
2055 if [ ! "$?" = "0" ]; then
2056 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2057 log error "cuesheet information from the flac file could not be read."
2058 log error "Perhaps the flac file does not contain a cuesheet?."
2061 log error "CD could not be read. Perhaps there's no CD in the drive?"
2065 # In OSX, remount the disc again
2066 if [ "$OSFLAVOUR" = "OSX" ]; then
2067 diskutil mount ${CDROM#/dev/}
2070 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
2072 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
2075 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2076 # This needs to be done now because a section of the resuming code will need
2079 # get the number of digits to pad TRACKNUM with - we'll use this later
2080 # a CD can only hold 99 tracks, but since we support a feature for starting
2081 # numbering the tracks from a given number, we might need to set it as a
2082 # variable for the user to define... or obtain it somehow.
2083 if [ "$PADTRACKS" = "y" ] ; then
2087 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
2088 if [ -z "$TRACKQUEUE" ]; then
2089 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2090 case "$CDROMREADERSYNTAX" in
2091 cdparanoia|libcdio|debug)
2092 if [ "$WEHAVEACD" = "y" ]; then
2093 vecho "Querying the CD for audio tracks..."
2094 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2096 if [ ! "$RET" = "0" ];then
2097 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2099 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2100 CDPARANOIAAUDIOTRACKS="$TRACKS"
2102 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2103 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
2104 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
2105 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
2107 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2108 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2112 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
2115 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2117 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2118 log info "The disc does not contain any tracks. Giving up..."
2121 echo -n "Grabbing entire CD - tracks: "
2122 if [ ! "$PADTRACKS" = "y" ] ; then
2123 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2125 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2127 while [ "$X" -ne "$TRACKS" ]
2129 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2130 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2134 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2135 # User-supplied track queue.
2136 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2137 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2138 # Once cleaned, obtain the highest value in the trackqueue for number padding
2139 for LASTTRACK in $TRACKQUEUE; do :; done
2140 if [ ! "$PADTRACKS" = "y" ] ; then
2141 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2143 # Now we normalize the trackqueue
2144 for TRACK in $TRACKQUEUE ; do
2145 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2146 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2148 TRACKQUEUE=$PADTRACKQUEUE
2149 echo Grabbing tracks: "$TRACKQUEUE"
2152 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2154 # We have the discid, create a temp directory after it to store all the temp
2157 if [ -e "$ABCDETEMPDIR" ]; then
2158 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2159 # It already exists, see if it's a directory
2160 if [ ! -d "$ABCDETEMPDIR" ]; then
2161 # This is a file/socket/fifo/device/etc, not a directory
2164 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2165 echo "Please investigate, remove it, and rerun abcde." >&2
2169 # It's a directory, let's see if it's writable by us
2170 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2171 # Nope, complain and exit
2173 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2174 echo "Please investigate, remove it, and rerun abcde." >&2
2178 # See if it's populated
2179 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2180 # Wipe and start fresh
2181 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2182 echo -n "this directory to continue. Continue [y/N]? " >&2
2183 if [ "$INTERACTIVE" = "y" ]; then
2189 if [ "$ANSWER" != "y" ]; then
2192 rm -rf "$ABCDETEMPDIR" || exit 1
2193 mkdir -p "$ABCDETEMPDIR"
2194 if [ "$?" -gt "0" ]; then
2195 # Directory already exists or could not be created
2196 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2200 # Everything is fine. Check for ^encodetracklocation-
2201 # and encode-output entries in the status file and
2202 # remove them. These are not relevant across sessions.
2203 if [ -f "$ABCDETEMPDIR/status" ]; then
2204 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2205 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2206 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2208 # Remove old error messages
2209 if [ -f "$ABCDETEMPDIR/errors" ]; then
2210 rm -f "$ABCDETEMPDIR/errors"
2214 # We are starting from scratch
2215 mkdir -p "$ABCDETEMPDIR"
2216 if [ "$?" -gt "0" ]; then
2217 # Directory already exists or could not be created
2218 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2221 cat /dev/null > "$ABCDETEMPDIR/status"
2222 # Store the abcde version in the status file.
2223 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2225 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2226 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2227 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2228 vecho "Creating cue file..."
2229 case $CDROMREADERSYNTAX in
2231 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2232 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2234 log warning "the input flac file does not contain a cuesheet."
2238 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2239 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2241 log warning "reading the CUE sheet is still considered experimental"
2242 log warning "and there was a problem with the CD reading. abcde will continue,"
2243 log warning "but consider reporting the problem to the abcde author"
2249 # If we got the CDPARANOIA status and it is not recorded, save it now
2250 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2251 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2252 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2256 # Create the discid file
2257 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2258 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2259 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2264 # Create a proper CUE file based on the CUE file we created before.
2267 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2268 CUEFILE_OUT=$CUEFILE_IN.out
2269 ### FIXME ### checkstatus cddb
2270 if [ -e "$CDDBDATA" ]; then
2271 vecho "Adding metadata to the cue file..."
2272 # FIXME It doesn't preserve spaces! Why?
2273 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2275 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2276 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2277 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2281 cat "$CUEFILE_IN" | while read line
2283 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2284 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2285 # echo "$line" >> "$CUEFILE_OUT"
2286 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2287 eval track="\$TRACK$n"
2289 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2290 # When making a single-track rip, put the
2291 # actual file name into the file declaration
2292 # in the cue file so that it is usable by
2293 # music players and the like
2294 elif [ "$ONETRACK" = "y" ] &&
2295 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2297 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2298 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2299 ALBUMFILE="$(mungealbumname "$DALBUM")"
2301 if [ "$VARIOUSARTISTS" = "y" ]; then
2302 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2304 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2307 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2310 # FIXME # If the lines above are uncommented, remove the line below.
2311 echo "$line" >> "$CUEFILE_OUT"
2314 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2315 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2321 # Parses a CDDB file and outputs the title and the track names.
2322 # Variables: CDDBFILE
2326 # List out disc title/author and contents
2327 if [ "$ONETRACK" = "y" ]; then
2328 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2330 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2331 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2332 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2333 if [ ! X"$PARSEDYEAR" = "X" ]; then
2334 echo "Year: $PARSEDYEAR"
2337 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2338 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2339 if [ ! X"$PARSEDGENRE" = "X" ]; then
2340 echo "Genre: $PARSEDGENRE"
2343 if [ ! "$ONETRACK" = "y" ]; then
2344 for TRACK in $(f_seq_row 1 $TRACKS)
2346 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2352 # Check for a local CDDB file, and report success
2355 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2357 CDDBLOCALSTATUS="notfound"
2358 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2361 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2362 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2363 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2364 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2365 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2366 CDDBLOCALMATCH=single
2367 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2368 CDDBLOCALMATCH=multiple
2373 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2374 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2375 CDDBLOCALMATCH=single
2380 # If the user has selected to check a local CDDB repo, we proceed with it
2381 case $CDDBLOCALMATCH in
2383 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2385 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2387 # List out disc title/author and contents
2388 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2389 cat "$RESULT" > "${CDDBLOCALREAD}"
2392 do_cddbparse "${CDDBLOCALREAD}"
2394 ##FIXME## QUICK HACK !!!!
2395 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2396 } >> "$ABCDETEMPDIR/cddblocalchoices"
2398 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2399 page "$ABCDETEMPDIR/cddblocalchoices"
2401 # It's all going to fit in one page, cat it
2402 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2404 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2405 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2406 CDDBLOCALCHOICENUM=-1
2407 if [ "$INTERACTIVE" = "y" ]; then
2408 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2409 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2410 read CDDBLOCALCHOICE
2411 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2412 # FIXME # Introduce diff's
2413 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2414 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2415 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2416 # Make sure we get a valid choice
2417 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2418 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2419 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2425 #echo "Selected ..."
2427 CDDBLOCALCHOICENUM=1
2429 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2430 #echo "Using local copy of CDDB data"
2431 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2432 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2433 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2434 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2435 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2436 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2437 CDDBLOCALSTATUS="found"
2439 #echo "Not using local copy of CDDB data"
2440 CDDBLOCALSTATUS="notfound"
2444 # List out disc title/author and contents
2445 do_cddbparse "${CDDBLOCALFILE}"
2446 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2447 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2449 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2451 if [ "$INTERACTIVE" = "y" ]; then
2453 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2454 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2457 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2461 if [ "$USELOCALRESP" = "y" ]; then
2462 #echo "Using local copy of CDDB data"
2463 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2464 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2465 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2466 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2467 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2468 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2469 CDDBLOCALSTATUS="single"
2471 #echo "Not using local copy of CDDB data"
2472 CDDBLOCALSTATUS="notfound"
2476 CDDBLOCALSTATUS="notfound"
2483 # Try to read CD-Text from the drive using icedax / cdda2wav
2486 if new_checkexec icedax; then
2487 CDTEXT_READER=icedax
2488 elif new_checkexec cdda2wav; then
2489 CDTEXT_READER=cdda2wav
2491 # Didn't find either, bail
2495 if [ "$OSFLAVOUR" = "OSX" ] ; then
2496 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2497 diskutil unmount ${CDROM#/dev/}
2498 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2499 CDDA2WAVCDROM="IODVDServices"
2500 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2501 CDDA2WAVCDROM="$CDROMID"
2503 if [ "$CDROMID" = "" ]; then
2504 CDDA2WAVCDROM="$CDROM"
2506 CDDA2WAVCDROM="$CDROMID"
2510 # Do we have CD-Text on the disc (and can the drive read it?)
2512 cd "$ABCDETEMPDIR" && rm -f audio.* audio_*
2513 ${CDTEXT_READER} -J -v titles -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2515 grep -a -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2517 if [ $ERRORCODE -ne 0 ]; then
2518 # No CD-Text found, bail
2522 rm -f "$ABCDETEMPDIR/cddbchoices"
2524 # Make an empty template
2525 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2526 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2527 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2528 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2529 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2530 #ATITLE=$(grep -ae '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- | sed "s~'\(.*\)'.*\[from \(.*\)]$~\2 / \1~")
2531 ATITLE=$(grep -ae '^DTITLE=' "${ABCDETEMPDIR}/audio.cddb" | cut -c8-)
2532 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2533 # List out disc title/author and contents
2534 echo "---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2535 sed -n 's~^Track \(..:\) .\(.*\).$~\1 \2~gp;' "$ABCDETEMPDIR/cd-text" >>"$ABCDETEMPDIR/cddbchoices"
2536 rm -f "$ABCDETEMPDIR/cddbread.1"
2537 # XXX FIXME - this is a hack and should be replaced by proper
2538 # character set tracking for the CDDB data we have.
2539 if test "$CDDBPROTO" -ge 6 ; then
2540 # convert to Unicode
2541 iconv -f iso-8859-1 -t utf-8 <"$ABCDETEMPDIR/audio.cddb" >"$ABCDETEMPDIR/cddbread.1"
2543 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2544 # apparently icedax/cdda2wav have no support for 16-bit
2545 # characters yet, either
2546 cp -p "$ABCDETEMPDIR/audio.cddb" "$ABCDETEMPDIR/cddbread.1"
2548 ( cd "$ABCDETEMPDIR" && rm -f audio_* audio.* )
2549 echo >> "$ABCDETEMPDIR/cddbchoices"
2550 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2554 # Work with the musicbrainz WS API, then transform the results here so
2555 # they look (very) like the results from CDDB. Maybe not the best way
2556 # to go, but it Works For Me (TM)
2560 if checkstatus musicbrainz-readcomplete; then :; else
2561 vecho "Obtaining Musicbrainz results..."
2562 # If MB is to be used, interpret the query results and read all
2563 # the available entries.
2564 rm -f "$ABCDETEMPDIR/cddbchoices"
2565 CDDBCHOICES=1 # Overridden by multiple matches
2566 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2567 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2569 # The helper script will write disc matches out to
2570 # cddbread.*. Count how many we have
2571 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2572 if [ $CDDBLASTMETHOD = "y" ]
2574 # We're the end of the line.
2576 # No matches. Use the normal cddb template for the user to
2578 vecho "Unable to find a match with ${CDDBMETHCHOICE}, generating CDDB template."
2579 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2580 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2581 # List out disc title/author and contents of template
2582 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2584 for TRACK in $(f_seq_row 1 $TRACKS)
2586 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2588 echo >> "$ABCDETEMPDIR/cddbchoices"
2589 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2590 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2591 echo 503 > "$ABCDETEMPDIR/cddbquery"
2593 # Neat, we'll let the next guy take care of this CDDB
2595 vecho "Unable to find a match with ${CDDBMETHCHOICE}, moving on to the next option."
2598 # We have some matches
2599 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2600 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2602 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2603 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2604 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2605 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2606 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2607 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2608 # List out disc title/author and contents
2609 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2610 for TRACK in $(f_seq_row 1 $TRACKS)
2612 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2614 echo >> "$ABCDETEMPDIR/cddbchoices"
2616 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2617 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2618 for file in "$ABCDETEMPDIR"/cddbread.*
2620 X=$(echo $file | sed 's/^.*cddbread\.//g')
2621 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2622 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2623 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2624 # List out disc title/author and contents
2625 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2626 for TRACK in $(f_seq_row 1 $TRACKS)
2628 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2630 echo >> "$ABCDETEMPDIR/cddbchoices"
2632 echo "." >> "$ABCDETEMPDIR/cddbquery"
2635 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2642 # Perform CDDB protocol version check if it hasn't already been done
2643 if checkstatus cddb-statcomplete; then :; else
2644 if [ "$CDDBAVAIL" = "n" ]; then
2646 echo 503 > "$ABCDETEMPDIR/cddbstat"
2649 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2650 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2651 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2652 vecho "Checking CDDB server status..."
2653 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2654 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2655 case "$RESPONSECODE" in
2656 210) # 210 OK, status information follows (until terminating `.')
2659 501) # 501 Illegal CDDB protocol level: <n>.
2660 CDDBPROTO=`expr $CDDBPROTO - 1`
2662 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2663 # FreeDB TESTCD disc-id is used for query
2664 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2665 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')