2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
5 # Copyright (c) 2012 Steve McIntyre <93sam@@debian.org>
6 # This code is hereby licensed for public consumption under either the
7 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
9 # You should have received a copy of the GNU General Public License along
10 # with this program; if not, write to the Free Software Foundation, Inc.,
11 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13 # Copyright for this work is to expire January 1, 2010, after which it
14 # shall be public domain.
16 VERSION='2.6.1-UNRELEASED'
20 echo "This is abcde v$VERSION."
21 echo "Usage: abcde [options] [tracks]"
23 echo "-1 Encode the whole CD in a single file"
24 echo "-a <action1[,action2]...>"
25 echo " Actions to perform:"
26 echo " cddb,read,normalize,encode,tag,move,replaygain,playlist,clean"
27 #echo "-A Experimental actions (retag, transcode)"
28 echo "-b Enable batch normalization"
30 echo " Specify a configuration file (overrides system and user config files)"
32 echo " Specify discid to resume from (only needed if you no longer have the cd)"
34 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
35 echo "-D Debugging mode (equivalent to sh -x abcde)"
36 echo "-e Erase encoded track information from status file"
37 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
38 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
39 echo "-h This help information"
40 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
41 echo "-j <#> Number of encoder processes to run at once (localhost)"
42 echo "-k Keep the wav tracks for later use"
43 echo "-l Use low disk space algorithm"
44 echo "-L Use local CDDB storage directory"
45 echo "-m Modify playlist to include CRLF endings, to comply with some players"
46 #echo " WARNING: Deprecated. Use \"cue\" action"
47 #echo "-M Create a CUE file"
48 echo "-n No lookup. Don't query CDDB, just create and use template"
49 echo "-N Noninteractive. Never prompt for anything"
50 echo "-o <type1[,type2]...>"
51 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus). Defaults to vorbis"
52 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
53 echo "-P Use UNIX pipes to read+encode without wav files"
54 echo "-r <host1[,host2]...>"
55 echo " Also encode on these remote hosts"
57 echo " Show fields from the CDDB info (year,genre)"
58 echo "-S <#> Set the CD speed"
59 echo "-t <#> Start the track numbering at a given number"
60 echo "-T <#> Same as -t but modifies tag numbering"
61 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
62 echo "-v Show version number and exit"
63 echo "-V Be a bit more verbose about what is happening behind the scenes"
64 echo "-x Eject CD after all tracks are read"
66 echo " Add a comment to the CD tracks"
67 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
68 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
70 echo "Tracks is a space-delimited list of tracks to grab."
71 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
73 #echo "Double hyphens are used to concatenate tracks"
78 echo "$@" >> "$ABCDETEMPDIR/status"
81 # log [level] [message]
83 # log outputs the right message in a common format
89 error) echo "[ERROR] abcde: $@" >&2 ;;
90 warning) echo "[WARNING] $@" >&2 ;;
91 info) echo "[INFO] $@" ;;
95 # Functions to replace the need of seq, which is too distribution dependent.
99 while [ $i -ne `expr $2 + 1` ]
109 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
110 while [ $i -ne `expr $2 + 1` ]
117 log error "syntax error while processing track numbers ($i)"
122 # Functions to replace the need of awk {print $1} and {print $NF}
125 if [ X"$1" = "X" ]; then
126 for first in `cat`; do
137 if [ X"$1" = "X" ]; then
138 for stdin in `cat`; do
142 for last in $@ ; do :; done
147 # checkstatus [blurb]
148 # Returns "0" if the blurb was found, returns 1 if it wasn't
149 # Puts the blurb content, if available, on stdout.
150 # Otherwise, returns "".
153 # Take the last line in the status file if there's multiple matches
155 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
157 if [ -z "$BLURB" ]; then
162 # See if there's a = in it
163 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
164 echo "$(echo $BLURB | cut -f2- -d=)"
170 # checkwarnings [blurb]
171 # Returns "0" if the blurb was found (meaning there was an warning),
172 # returns 1 if it wasn't (yes this is a little backwards).
173 # Does not print the blurb on stdout.
174 # Otherwise, returns "".
177 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
180 # Take the last line in the status file if there's multiple matches
182 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
184 if [ -z "$BLURB" ]; then
185 # negative, we did not have a negative...
188 # affirmative, we had a negative...
193 # checkerrors [blurb]
194 # Returns "0" if the blurb was found (meaning there was an error),
195 # returns 1 if it wasn't (yes this is a little backwards).
196 # Does not print the blurb on stdout.
197 # Otherwise, returns "".
200 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
203 # Take the last line in the status file if there's multiple matches
205 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
207 if [ -z "$BLURB" ]; then
208 # negative, we did not have a negative...
211 # affirmative, we had a negative...
217 # Finds the right pager in the system to display a file
221 # Use the debian sensible-pager wrapper to pick the pager
222 # user has requested via their $PAGER environment variable
223 if [ -x "/usr/bin/sensible-pager" ]; then
224 /usr/bin/sensible-pager "$PAGEFILE"
225 elif [ -x "$PAGER" ]; then
226 # That failed, try to load the preferred editor, starting
227 # with their PAGER variable
229 # If that fails, check for less
230 elif [ -x /usr/bin/less ]; then
231 /usr/bin/less -f "$PAGEFILE"
232 # more should be on all UNIX systems
233 elif [ -x /bin/more ]; then
234 /bin/more "$PAGEFILE"
236 # No bananas, just cat the thing
241 # run_command [blurb] [command...]
242 # Runs a command, silently if necessary, and updates the status file
248 # See if this is supposed to be silent
249 if [ "$(checkstatus encode-output)" = "loud" ]; then
253 # Special case for SMP, since
254 # encoder output is never displayed, don't mute echos
255 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
264 normalize|normalize-audio)
265 if [ "$RETURN" = "2" ]; then
266 # File was already normalized.
271 if [ "$RETURN" != "0" ]; then
272 # Put an error in the errors file. For various reasons we
273 # can't capture a copy of the program's output but we can
274 # log what we attempted to execute and the error code
275 # returned by the program.
276 if [ "$BLURB" ]; then
279 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
280 return $RETURN # Do not pass go, do not update the status file
282 if [ "$BLURB" ]; then
283 echo $BLURB >> "$ABCDETEMPDIR/status"
287 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
288 # distributed under the terms of the GNU GPL v2 or later, at your option
290 # Function to determine if a word contains a slash.
299 # Function to give the relative path from one file to another.
300 # Usage: relpath fromfile tofile
301 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
302 # (the result would be Album/Song.mp3)
303 # Output is relative path to $2 from $1 on stdout
305 # This code has the following restrictions:
306 # Multiple ////s are not collapsed into single /s, with strange effects.
307 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
308 # If FR is a directory it must have a trailing /
316 /*) ;; # No processing is needed for absolute paths
318 # Loop through common prefixes, ignoring them.
319 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
321 FR="$(echo "$FR" | cut -d/ -f2-)"
322 TO="$(echo "$TO" | cut -d/ -f2-)"
324 # Loop through directory portions left in FR, adding appropriate ../s.
327 FR="$(echo "$FR" | cut -d/ -f2-)"
338 if [ ! "$@" = "" ]; then
339 # Cut off any command-line option we added in
340 X=$(echo $@ | cut -d' ' -f2)
341 if [ "$(which $X)" = "" ]; then
343 elif [ ! -x $(which $X) ]; then
352 if [ ! "$@" = "" ]; then
353 # Cut off any command-line option we added in
354 X=$(echo $@ | cut -d' ' -f2)
355 # Test for built-in abcde.function
356 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
357 if [ "$(which $X)" = "" ]; then
358 log error "$X is not in your path." >&2
359 log info "Define the full path to the executable if it exists on your system." >&2
360 if [ -e /etc/debian_release ] ; then
362 oggenc) MISSING_PACKAGE=vorbis-tools ;;
363 lame|flac) MISSING_PACKAGE=$X ;;
365 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
368 elif [ ! -x "$(which $X)" ]; then
369 log error "$X is not executable." >&2
375 # diffentries <filename> <max_value> <entry1>,<entry2>
376 # max_value: the range of entries goes from 1 to <max_value>
381 local CDDBDIFFCHOICES=$1
383 local CDDBDIFFCHOICE="$@"
384 if [ ! X"$DIFF" = "X" ]; then
385 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
386 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
387 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
388 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
389 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
390 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
392 # We parse the 2 choices to diff, store them in temporary files and diff them.
393 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
394 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
396 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
397 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
398 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
399 page "$ABCDETEMPDIR/$FILENAME.diff"
401 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
405 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
410 # Finds an specific field from cddbinfo
415 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
418 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
421 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
427 # Get the track number we are going to use for different actions
430 if [ -n "$STARTTRACKNUMBER" ] ; then
431 # Get the trackpadding from the current track, also trim whitespace for MacOSX
432 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
433 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
435 TRACKNUM=${UTRACKNUM}
441 # Calculate cddb disc ids without requiring specialized helper programs.
442 # largely copied from cd-discid and musicbrainz examples. some of the steps
443 # don't make sense, but they're necessary to match the ids generated by other
446 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
447 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
448 # processing offsetimes 00:00:00 04:47:10 08:20:37 11:46:46 17:45:36 21:41:57 27:32:21 32:03:73 35:39:28 38:27:33 43:50:38 44:42:34
449 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
450 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
451 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
453 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
456 if [ X"$LEADOUT" = "X" ]; then
457 log warning "Error trying to calculate disc ids without lead-out information."
461 # default to a two second lead-in
463 LEADIN=${LEADIN:=150}
465 # number of cdframes per second
468 # reset cddb checksum for cddb disc-id calululation
472 for OFFSET in $(echo $OFFSETS)
474 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
476 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
477 while [ $OFFSETTIME -gt 0 ]; do
478 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
479 OFFSETTIME=$(($OFFSETTIME / 10))
484 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
486 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
487 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
489 case "$CDDBMETHOD" in
491 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
494 # FIXME: don't assume the first track is 1
495 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
496 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
500 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
505 if checkstatus replaygain; then :; else
506 run_command "" echo "Adding replaygain information..."
507 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
511 OUTPUT=$OGGOUTPUTCONTAINER
514 OUTPUT=$OPUSOUTPUTCONTAINER
517 OUTPUT=$FLACOUTPUTCONTAINER
525 for UTRACKNUM in $TRACKQUEUE
527 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
528 getcddbinfo TRACKNAME
530 TRACKFILE="$(mungefilename "$TRACKNAME")"
531 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
532 ALBUMFILE="$(mungefilename "$DALBUM")"
533 GENRE="$(mungegenre "$GENRE")"
534 YEAR=${CDYEAR:-$CDYEAR}
536 if [ "$ONETRACK" = "y" ]; then
537 if [ "$VARIOUSARTISTS" = "y" ]; then
538 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
540 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
543 if [ "$VARIOUSARTISTS" = "y" ]; then
544 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
546 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
549 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
550 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
554 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
555 #run_command replaygain-flac true
558 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
561 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
564 run_command replaygain-mpc nice $ENCNICE $MPPGAIN --auto "${OUTPUTFILES[@]}"
569 if checkerrors "replaygain-.{3,6}"; then :; else
570 run_command replaygain true
575 # This code splits the a Various Artist track name from one of the following
578 # forward: Artist / Track
579 # forward-dash: Artist - Track
580 # reverse: Track / Artist
581 # reverse-dash: Track - Artist
582 # colon: Artist: Track
583 # trailing-paren: Artist (Track)
586 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
589 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
590 case "$VARIOUSARTISTSTYLE" in
592 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
593 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
594 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
597 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
598 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
599 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
602 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
603 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
604 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
607 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
608 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
609 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
612 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
613 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
614 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
617 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
618 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
619 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
622 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
623 TRACKARTIST="Various"
625 TRACKARTIST="$DARTIST"
630 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
634 "classic rock") id=1 ;;
652 "industrial") id=19 ;;
653 "alternative") id=20 ;;
655 "death metal") id=22 ;;
657 "soundtrack") id=24 ;;
658 "euro-techno") id=25 ;;
662 "jazz+funk") id=29 ;;
665 "classical") id=32 ;;
666 "instrumental") id=33 ;;
670 "sound clip") id=37 ;;
673 "alt. rock") id=40 ;;
678 "meditative") id=45 ;;
679 "instrum. pop") id=46 ;;
680 "instrum. rock") id=47 ;;
684 "techno-indust.") id=51 ;;
685 "electronic") id=52 ;;
687 "eurodance") id=54 ;;
689 "southern rock") id=56 ;;
694 "christian rap") id=61 ;;
695 "pop/funk"|"pop / funk") id=62 ;;
697 "native american") id=64 ;;
700 "psychadelic") id=67 ;;
702 "showtunes") id=69 ;;
706 "acid punk") id=73 ;;
707 "acid jazz") id=74 ;;
711 "rock & roll") id=78 ;;
712 "hard rock") id=79 ;;
714 "folk/rock") id=81 ;;
715 "national folk") id=82 ;;
722 "bluegrass") id=89 ;;
723 "avantgarde") id=90 ;;
724 "gothic rock") id=91 ;;
725 "progress. rock") id=92 ;;
726 "psychadel. rock") id=93 ;;
727 "symphonic rock") id=94 ;;
728 "slow rock") id=95 ;;
731 "easy listening") id=98 ;;
737 "chamber music") id=104 ;;
739 "symphony") id=106 ;;
740 "booty bass") id=107 ;;
742 "porn groove") id=109 ;;
744 "slow jam") id=111 ;;
748 "folklore") id=115 ;;
750 "power ballad") id=117 ;;
751 "rhythmic soul") id=118 ;;
752 "freestyle") id=119 ;;
754 "punk rock") id=121 ;;
755 "drum solo") id=122 ;;
756 "a capella") id=123 ;;
757 "euro-house") id=124 ;;
758 "dance hall") id=125 ;;
760 "drum & bass") id=127 ;;
761 "club-house") id=128 ;;
762 "hardcore") id=129 ;;
766 "negerpunk") id=133 ;;
767 "polsk punk") id=134 ;;
769 "christian gangsta rap") id=136 ;;
770 "heavy metal") id=137 ;;
771 "black metal") id=138 ;;
772 "crossover") id=139 ;;
773 "contemporary christian")id=140 ;;
774 "christian rock") id=141 ;;
775 "merengue") id=142 ;;
777 "thrash metal") id=144 ;;
780 "synthpop") id=147 ;;
781 "rock/pop"|"rock / pop") id=148 ;;
788 # do_tag [tracknumber]
789 # id3 tags a filename
791 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
792 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
795 COMMENTOUTPUT="$(eval echo ${COMMENT})"
796 if [ -z "$COMMENTOUTPUT" ]; then
797 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
799 if [ "$CDDBMETHOD" = "cddb" ]; then
800 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
802 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
803 # If we want to start the tracks with a given number, we need to modify the
804 # TRACKNUM value before evaluation
805 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
808 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
812 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
813 GENREID=$(do_getgenreid "${CDGENRE}")
814 # Set TPE2 in case we have a Various Artists rip.
816 if [ "$VARIOUSARTISTS" = "y" ]; then
823 # FIXME # track numbers in mp3 come with 1/10, so we cannot
824 # happily substitute them with $TRACKNUM
826 eyed3_06) addopts=( \
827 ${ENCODING:+--set-encoding="$ENCODING"} \
828 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
829 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
832 ${ENCODING:+--encoding="$ENCODING"} \
833 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
834 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
837 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
839 -a "$TRACKARTIST" -t "$TRACKNAME" ${CDYEAR:+-Y "$CDYEAR"} \
840 -G "$GENREID" -n "${TRACKNUM:-$1}" \
841 ${TRACKNUM:+-N "$TRACKS"} \
843 "$ABCDETEMPDIR/track$1.$OUTPUT"
845 # FIXME # Still not activated...
847 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
848 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
849 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" \
850 -y "$CDYEAR" -g "$GENREID" -k "${TRACKNUM:-$1}" \
851 "$ABCDETEMPDIR/track$1.$OUTPUT"
854 # FIXME # track numbers in mp3 come with 1/10, so we cannot
855 # happily substitute them with $TRACKNUM
856 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
857 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
858 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
859 -y "$CDYEAR" -g "$GENREID" \
860 -T "${TRACKNUM:-$1}/$TRACKS" \
861 ${TPE2:+--TPE2 "$TPE2"} \
862 "$ABCDETEMPDIR/track$1.$OUTPUT"
867 case "$OGGENCODERSYNTAX" in
869 # vorbiscomment can't do in-place modification, mv the file first
870 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
871 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
875 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
877 echo ARTIST="$TRACKARTIST"
879 echo TITLE="$TRACKNAME"
880 if [ -n "$CDYEAR" ]; then
883 if [ -n "$CDGENRE" ]; then
884 echo GENRE="$CDGENRE"
886 echo TRACKNUMBER=${TRACKNUM:-$1}
887 if [ -n "$DISCNUMBER" ]; then
888 echo DISCNUMBER="$DISCNUMBER"
890 echo CDDB=$CDDBDISCID
891 if [ "$(eval echo ${COMMENT})" != "" ]; then
892 case "$COMMENTOUTPUT" in
893 *=*) echo "$COMMENTOUTPUT";;
894 *) echo COMMENT="$COMMENTOUTPUT";;
897 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
898 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
899 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
900 # Doublecheck that the commented file was created
901 # successfully before wiping the original
902 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
903 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
905 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
911 run_command tagtrack-$OUTPUT-$1 true
916 echo ARTIST="$TRACKARTIST"
918 echo TITLE="$TRACKNAME"
919 if [ -n "$CDYEAR" ]; then
922 if [ -n "$CDGENRE" ]; then
923 echo GENRE="$CDGENRE"
925 echo TRACKNUMBER="${TRACKNUM:-$1}"
926 if [ -n "$DISCNUMBER" ]; then
927 echo DISCNUMBER="$DISCNUMBER"
929 echo CDDB="$CDDBDISCID"
930 if [ "$(eval echo ${COMMENT})" != "" ]; then
931 case "$COMMENTOUTPUT" in
932 *=*) echo "$COMMENTOUTPUT";;
933 *) echo COMMENT="$COMMENTOUTPUT";;
936 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
939 run_command tagtrack-$OUTPUT-$1 true
942 run_command tagtrack-$OUTPUT-$1 true
945 run_command tagtrack-$OUTPUT-$1 true
948 case "$AACENCODERSYNTAX" in
949 fdkaac) # We will use inline tagging...
950 run_command tagtrack-$OUTPUT-$1 true
952 neroAacEnc) # Tag post encode with neroAacTag...
953 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
954 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
955 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
958 run_command tagtrack-$OUTPUT-$1 true
963 run_command tagtrack-$OUTPUT-$1 true
967 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
968 run_command tagtrack-$1 true
975 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
978 # The commands here don't go through run_command because they're never
979 # supposed to be silenced
980 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
981 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
985 case "$MP3ENCODERSYNTAX" in
990 for UTRACKNUM in $TRACKQUEUE
992 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
994 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
996 if [ "$RETURN" != "0" ]; then
997 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
999 for UTRACKNUM in $TRACKQUEUE
1001 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1002 #run_command encodetrack-$UTRACKNUM true
1011 if checkerrors "nogap-encode"; then :; else
1012 if [ ! "$KEEPWAVS" = "y" ] ; then
1013 if [ ! "$KEEPWAVS" = "move" ] ; then
1018 # Other encoders fall through to normal encoding as the tracks have not
1019 # been entered in the status file.
1022 # do_encode [tracknumber] [hostname]
1023 # If no hostname is specified, encode locally
1025 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1028 if [ "$USEPIPES" = "y" ]; then
1031 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1034 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1037 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1040 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1043 TEMPARG="PIPE_$SPEEXENCODER"
1046 TEMPARG="PIPE_$MPCENCODER"
1049 TEMPARG="PIPE_$AACENCODERSYNTAX"
1052 TEMPARG="PIPE_$AACENCODERSYNTAX"
1055 IN="$( eval echo "\$$TEMPARG" )"
1057 IN="$ABCDETEMPDIR/track$1.wav"
1060 case "$MP3ENCODERSYNTAX" in
1061 # FIXME # check if mp3enc needs -if for pipes
1062 # FIXME # I have not been able to find a working mp3enc binary
1076 # We need IN to proceed, if we are not using pipes.
1077 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1078 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1080 case "$TMPOUTPUT" in
1082 OUTPUT=$OGGOUTPUTCONTAINER
1085 OUTPUT=$OPUSOUTPUTCONTAINER
1088 OUTPUT=$FLACOUTPUTCONTAINER
1094 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1095 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1098 if [ X"$USEPIPES" = "Xy" ]; then
1100 # We need a way to store the creation of the files when using PIPES
1101 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1102 # When pipping it does not make sense to have a higher nice for
1103 # reading than for encoding, since it will be hold by the
1104 # encoding process. Setting an effective nice, to calm down a
1105 # bit the reading process.
1106 EFFECTIVE_NICE=$READNICE
1108 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1109 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1110 EFFECTIVE_NICE=$ENCNICE
1116 case "$MP3ENCODERSYNTAX" in
1117 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1118 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1119 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1120 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1121 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1125 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1132 case "$OGGENCODERSYNTAX" in
1133 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1134 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1138 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1145 case "$OPUSENCODERSYNTAX" in
1148 if [ "$(eval echo ${COMMENT})" != "" ]; then
1151 *) COMMENT="COMMENT=$COMMENT" ;;
1154 # Tag the file at encode time, as it can't be done after encoding.
1155 if [ "$DOTAG" = "y" ]; then
1156 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1158 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1164 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1171 case "$FLACENCODERSYNTAX" in
1172 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1177 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1178 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1183 if [ "$(eval echo ${COMMENT})" != "" ]; then
1186 *) COMMENT="COMMENT=$COMMENT" ;;
1189 # Tag the file at encode time, as it can't be done after encoding.
1190 if [ "$DOTAG" = "y" ]; then
1191 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1193 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1197 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1198 # tagging. Uses mpcenc for Musepack SV8 encoding, changed from
1199 # Musepack SV7 which used mppenc....
1200 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
1203 # aac container is only used to catch faac encoded files where faac
1204 # is compiled without mp4 support (with libmp4v2). Andrew.
1205 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1208 case "$AACENCODERSYNTAX" in
1210 if [ "$DOTAG" = "y" ]; then
1211 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" \
1212 --album "$DALBUM" --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" \
1213 --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1215 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1219 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1222 if [ "$DOTAG" = "y" ]; then
1223 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1224 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --long-tag Year:"$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1226 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1232 # In case of wav output we need nothing. Just keep the wavs.
1237 # Only remove .wav if the encoding succeeded
1238 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1239 run_command encodetrack-$1 true
1240 if [ ! "$KEEPWAVS" = "y" ] ; then
1241 if [ ! "$KEEPWAVS" = "move" ] ; then
1247 run_command "" echo "HEH! The file we were about to encode disappeared:"
1248 run_command "" echo ">> $IN"
1249 run_command encodetrack-$1 false
1253 # do_preprocess [tracknumber]
1255 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1258 # IN="$ABCDETEMPDIR/track$1.wav"
1259 # # We need IN to proceed.
1260 # if [ -s "$IN" ] ; then
1261 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1263 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1264 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1265 # case "$POSTPROCESSFORMAT" in
1267 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1269 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1271 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1273 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1275 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1278 # # Only remove .wav if the encoding succeeded
1279 # if checkerrors "preprocess-(.{3,4})-$1"; then
1280 # run_command preprocess-$1 false
1282 # run_command preprocess-$1 true
1285 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1286 # echo "HEH! The file we were about to pre-process disappeared:"
1289 # run_command preprocess-$1 false
1294 # do_postprocess [tracknumber]
1296 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1299 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1301 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1302 # # We need IN to proceed.
1303 # if [ -s "$IN" ] ; then
1304 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1305 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1306 # case "$POSTPROCESSFORMAT" in
1308 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1310 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1312 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1314 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1316 # # Only remove .wav if the encoding succeeded
1317 # if checkerrors "postprocess-(.{3,4})-$1"; then
1318 # run_command postprocess-$1 false
1320 # run_command postprocess-$1 true
1323 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1324 # echo "HEH! The file we were about to post-process disappeared:"
1327 # run_command postprocess-$1 false
1342 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1346 # The commands here don't go through run_command because they're never supposed to be silenced
1347 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1352 for UTRACKNUM in $TRACKQUEUE
1354 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1356 # FIXME # Hard-coded batch option!
1357 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1359 if [ "$RETURN" != "0" ]; then
1360 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1362 for UTRACKNUM in $TRACKQUEUE
1364 echo normalizetrack-$UTRACKNUM >> status
1370 # do_batch_normalize
1372 # NORMALIZER, NORMALIZEROPTS
1373 do_batch_normalize ()
1375 # The commands here don't go through run_command because they're never supposed to be silenced
1376 echo "Batch normalizing tracks: $TRACKQUEUE"
1381 for UTRACKNUM in $TRACKQUEUE
1383 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1385 # XXX: Hard-coded batch option!
1386 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1388 if [ "$RETURN" != "0" ]; then
1389 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1391 for UTRACKNUM in $TRACKQUEUE
1393 echo normalizetrack-$UTRACKNUM >> status
1399 # do_normalize [tracknumber]
1401 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1404 IN="$ABCDETEMPDIR/track$1.wav"
1405 if [ -e "$IN" ] ; then
1406 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1407 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1409 if [ "$(checkstatus encode-output)" = "loud" ]; then
1410 echo "HEH! The file we were about to normalize disappeared:"
1413 run_command normalizetrack-$1 false "File $IN was not found"
1417 # do_move [tracknumber]
1418 # Deduces the outfile from environment variables
1419 # Creates directory if necessary
1421 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1424 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1426 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1427 # defined the OUTPUTFILE:
1430 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1431 # Munge filenames as follows:
1436 # Eat control characters
1437 ALBUMFILE="$(mungefilename "$DALBUM")"
1438 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1439 TRACKFILE="$(mungefilename "$TRACKNAME")"
1440 GENRE="$(mungegenre "$GENRE")"
1441 YEAR=${CDYEAR:-$CDYEAR}
1442 # If we want to start the tracks with a given number, we need to modify
1443 # the TRACKNUM value before evaluation
1445 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1446 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1447 if [ "$ONETRACK" = "y" ]; then
1448 if [ "$VARIOUSARTISTS" = "y" ]; then
1449 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1451 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1454 if [ "$VARIOUSARTISTS" = "y" ]; then
1455 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1457 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1460 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1461 # Once we know the specific output was successful, we can change
1462 # the OUTPUT to the value containing the container
1465 OUTPUT=$OGGOUTPUTCONTAINER
1468 OUTPUT=$OPUSOUTPUTCONTAINER
1471 OUTPUT=$FLACOUTPUTCONTAINER
1477 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1478 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1481 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1482 # FIXME # introduce warnings?
1485 # mkdir -p shouldn't return an error if the directory already exists
1486 mkdir -p "$OUTPUTFILEDIR"
1487 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1488 if checkstatus movetrack-output-$OUTPUT; then :; else
1489 run_command movetrack-output-$OUTPUT true
1494 # mkdir -p shouldn't return an error if the directory already exists
1495 mkdir -p "$OUTPUTFILEDIR"
1496 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1497 if checkstatus movetrack-output-$OUTPUT; then :; else
1498 run_command movetrack-output-$OUTPUT true
1502 # Lets move the cue file
1503 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1504 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1505 if checkstatus movecue-$OUTPUT; then :; else
1506 # Silence the Copying output since it overlaps with encoding processes...
1507 #run_command '' vecho "Copying cue file to its destination directory..."
1508 if checkstatus onetrack >/dev/null ; then
1511 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1512 # We dont have the dir, since it was not created before.
1515 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1518 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1519 # http://brianvictor.tripod.com/mp3cue.htm#details
1520 [a-z0-9][a-z0-9][a-z0-9])
1521 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1524 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1528 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1530 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1539 # Create the playlist if wanted
1541 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1542 # VARIOUSARTISTS, OUTPUTDIR
1545 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1549 OUTPUT=$OGGOUTPUTCONTAINER
1552 OUTPUT=$OPUSOUTPUTCONTAINER
1555 OUTPUT=$FLACOUTPUTCONTAINER
1561 # Create a playlist file for the playlist data to go into.
1562 # We used to wipe it out if it existed. Now we request permission if interactive.
1563 for LASTTRACK in $TRACKQUEUE; do :; done
1564 ALBUMFILE="$(mungefilename "$DALBUM")"
1565 ARTISTFILE="$(mungefilename "$DARTIST")"
1566 GENRE="$(mungegenre "$GENRE")"
1567 YEAR=${CDYEAR:-$CDYEAR}
1568 if [ "$VARIOUSARTISTS" = "y" ] ; then
1569 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1571 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1573 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1574 mkdir -p "$FINALPLAYLISTDIR"
1575 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1576 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1577 if [ "$INTERACTIVE" = "y" ]; then
1578 while [ "$DONE" != "y" ]; do
1580 case $ERASEPLAYLIST in
1581 e|E|a|A|k|K) DONE=y ;;
1582 "") ERASEPLAYLIST=e ; DONE=y ;;
1590 # Once we erase the playlist, we use append to create the new one.
1591 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1593 # The playlist does not exist, so we can safelly use append to create the new list
1596 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1597 touch "$OUTPUTDIR/$PLAYLISTFILE"
1598 for UTRACKNUM in $TRACKQUEUE
1600 # Shares some code with do_move since the filenames have to match
1601 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1602 getcddbinfo TRACKNAME
1604 TRACKFILE="$(mungefilename "$TRACKNAME")"
1605 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1606 ALBUMFILE="$(mungefilename "$DALBUM")"
1607 # If we want to start the tracks with a given number, we need to modify the
1608 # TRACKNUM value before evaluation
1610 if [ "$VARIOUSARTISTS" = "y" ]; then
1611 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1613 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1615 if [ "$VARIOUSARTISTS" = "y" ]; then
1616 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1617 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1619 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1622 if [ "$PLAYLISTDATAPREFIX" ]; then
1623 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1625 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1630 ## this will convert the playlist to have CRLF line-endings, if specified
1631 ## (some hardware players insist on CRLF endings)
1632 if [ "$DOSPLAYLIST" = "y" ]; then
1633 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1634 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1635 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1637 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1642 # This function reads a cuefile on stdin and writes an extended
1643 # cddb query on stdout. Any PREGAP for track 1 is properly
1644 # handled, although cue files embedded in FLAC files do not
1645 # appear to properly store the PREGAP setting. :(
1646 abcde.cue2discid () {
1651 while [ $val -gt 0 ] ; do
1652 ret=$(( $ret + ( $val % 10) ))
1653 val=$(( $val / 10 ))
1663 local first second third
1664 first=$(expr ${1} + 0 )
1665 second=$(expr ${2} + 0 )
1666 third=$(expr ${3} + 0 )
1668 echo $(( ((($first * 60) + $second) * 75) + $third ))
1678 while read line ; do
1681 TRACK) i=$(( i + 1 ))
1683 INDEX) if [ "$2" -eq 1 ] ; then
1685 START=$(( $LBA + $PREGAP + $OFFSET ))
1687 X=$(cddb_sum $(( $START / 75 )) )
1691 PREGAP) PREGAP=$(msf2lba $2)
1695 LEADOUT=$(( $4 / 588 ))
1698 LEADIN=$(( $3 / 588 ))
1707 LEADOUT=$(( $LEADOUT + $LEADIN ))
1709 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1710 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1711 printf "%08x %i" $DISCID $TRACKS
1714 while [ $j -le $TRACKS ] ; do
1715 eval echo -n "\" \$TRACK$j\""
1718 echo " $(( $LEADOUT / 75 ))"
1722 # abcde.mkcue [--wholedisk]
1723 # This creates a cuefile directly from the extended discid information
1724 # The --wholedisk option controls whether we're ripping data from the
1725 # start of track one or from the start of the disk (usually, but not
1726 # always the same thing!)
1728 # Track one leadin/pregap (if any) handeling:
1729 # --wholedisk specified:
1732 # INDEX 01 <pregap value>
1733 # Remaining track index values unchanged from disc TOC
1735 # --wholedisk not specified
1737 # PREGAP <pregap value>
1739 # Remaining track index values offset by <pregap value>
1746 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1749 local MODE DISCID TRACKS
1753 if [ "$1" = --wholedisc ] ; then
1759 vecho "One track is $ONETRACK"
1760 TRACKFILE="$(mungefilename "$TRACKNAME")"
1761 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1762 ALBUMFILE="$(mungefilename "$DALBUM")"
1763 if [ "$ONETRACK" = "y" ]; then
1764 if [ "$VARIOUSARTISTS" = "y" ]; then
1765 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1767 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1769 vecho "Cue wav file is $CUEWAVFILE"
1771 CUEWAVFILE="dummy.wav"
1780 echo REM DISCID $DISCID
1781 echo FILE \""$CUEWAVFILE"\" WAVE
1783 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1790 while [ $i -le "$TRACKS" ] ; do
1791 LBA=$(( $1 - $OFFSET ))
1792 printf " TRACK %02i AUDIO\n" $i
1793 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1794 if [ $MODE = PREGAP ] ; then
1795 echomsf " PREGAP " $(($OFFSET-150))
1797 echo " INDEX 00 00:00:00"
1800 echomsf " INDEX 01 " $LBA
1807 # This essentially the start of things
1810 # Query the CD to get the track info, unless the user specified -C
1811 # or we are using some actions which do not need the CDDB data at all
1812 #if [ ! X"$EXPACTIONS" = "X" ]; then
1814 #elif [ -z "$DISCID" ]; then
1815 if [ -z "$DISCID" ]; then
1816 vecho -n "Getting CD track info... "
1817 # In OSX, unmount the disc before a query
1818 if [ "$OSFLAVOUR" = "OSX" ]; then
1819 diskutil unmount ${CDROM#/dev/}
1821 case "$CDROMREADERSYNTAX" in
1823 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1824 case "$CUE2DISCID" in
1825 # FIXME # right now we have 2 cue2discid internal
1826 # implementations: builtin and abcde.cue2discid. Test
1827 # both of them and decide which one we want to use.
1829 #vecho "Using builtin cue2discid implementation..."
1830 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1832 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1834 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1835 TRACKS=${#OFFSETTIMES[@]}
1837 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1838 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1839 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1840 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1843 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1844 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1848 #vecho "Using external python cue2discid implementation..."
1849 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1853 log error "the input flac file does not contain a cuesheet."
1858 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1860 # if [ ! "$RET" = "0" ];then
1861 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1864 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1865 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1867 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1868 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1872 case "$CDDBMETHOD" in
1873 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1874 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1878 # Make sure there's a CD in there by checking cd-discid's return code
1879 if [ ! "$?" = "0" ]; then
1880 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1881 log error "cuesheet information from the flac file could not be read."
1882 log error "Perhaps the flac file does not contain a cuesheet?."
1885 log error "CD could not be read. Perhaps there's no CD in the drive?"
1889 # In OSX, remount the disc again
1890 if [ "$OSFLAVOUR" = "OSX" ]; then
1891 diskutil mount ${CDROM#/dev/}
1894 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1896 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1899 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1900 # This needs to be done now because a section of the resuming code will need
1903 # get the number of digits to pad TRACKNUM with - we'll use this later
1904 # a CD can only hold 99 tracks, but since we support a feature for starting
1905 # numbering the tracks from a given number, we might need to set it as a
1906 # variable for the user to define... or obtain it somehow.
1907 if [ "$PADTRACKS" = "y" ] ; then
1911 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1912 if [ -z "$TRACKQUEUE" ]; then
1913 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1914 case "$CDROMREADERSYNTAX" in
1916 if [ "$WEHAVEACD" = "y" ]; then
1917 vecho "Querying the CD for audio tracks..."
1918 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1920 if [ ! "$RET" = "0" ];then
1921 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1923 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1924 CDPARANOIAAUDIOTRACKS="$TRACKS"
1926 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1927 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1928 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1929 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1931 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1932 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1936 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1939 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1941 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1942 log info "The disc does not contain any tracks. Giving up..."
1945 echo -n "Grabbing entire CD - tracks: "
1946 if [ ! "$PADTRACKS" = "y" ] ; then
1947 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1949 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1951 while [ "$X" -ne "$TRACKS" ]
1953 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1954 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1958 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1959 # User-supplied track queue.
1960 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1961 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1962 # Once cleaned, obtain the highest value in the trackqueue for number padding
1963 for LASTTRACK in $TRACKQUEUE; do :; done
1964 if [ ! "$PADTRACKS" = "y" ] ; then
1965 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1967 # Now we normalize the trackqueue
1968 for TRACK in $TRACKQUEUE ; do
1969 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1970 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1972 TRACKQUEUE=$PADTRACKQUEUE
1973 echo Grabbing tracks: "$TRACKQUEUE"
1976 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1978 # We have the discid, create a temp directory after it to store all the temp
1981 if [ -e "$ABCDETEMPDIR" ]; then
1982 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1983 # It already exists, see if it's a directory
1984 if [ ! -d "$ABCDETEMPDIR" ]; then
1985 # This is a file/socket/fifo/device/etc, not a directory
1988 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1989 echo "Please investigate, remove it, and rerun abcde." >&2
1993 # It's a directory, let's see if it's writable by us
1994 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
1995 # Nope, complain and exit
1997 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
1998 echo "Please investigate, remove it, and rerun abcde." >&2
2002 # See if it's populated
2003 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2004 # Wipe and start fresh
2005 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2006 echo -n "this directory to continue. Continue [y/N]? " >&2
2007 if [ "$INTERACTIVE" = "y" ]; then
2013 if [ "$ANSWER" != "y" ]; then
2016 rm -rf "$ABCDETEMPDIR" || exit 1
2017 mkdir -p "$ABCDETEMPDIR"
2018 if [ "$?" -gt "0" ]; then
2019 # Directory already exists or could not be created
2020 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2024 # Everything is fine. Check for ^encodetracklocation-
2025 # and encode-output entries in the status file and
2026 # remove them. These are not relevant across sessions.
2027 if [ -f "$ABCDETEMPDIR/status" ]; then
2028 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2029 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2030 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2032 # Remove old error messages
2033 if [ -f "$ABCDETEMPDIR/errors" ]; then
2034 rm -f "$ABCDETEMPDIR/errors"
2038 # We are starting from scratch
2039 mkdir -p "$ABCDETEMPDIR"
2040 if [ "$?" -gt "0" ]; then
2041 # Directory already exists or could not be created
2042 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2045 cat /dev/null > "$ABCDETEMPDIR/status"
2046 # Store the abcde version in the status file.
2047 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2049 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2050 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2051 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2052 vecho "Creating cue file..."
2053 case $CDROMREADERSYNTAX in
2055 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2056 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2058 log warning "the input flac file does not contain a cuesheet."
2062 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2063 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2065 log warning "reading the CUE sheet is still considered experimental"
2066 log warning "and there was a problem with the CD reading. abcde will continue,"
2067 log warning "but consider reporting the problem to the abcde author"
2073 # If we got the CDPARANOIA status and it is not recorded, save it now
2074 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2075 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2076 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2080 # Create the discid file
2081 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2082 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2083 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2088 # Create a proper CUE file based on the CUE file we created before.
2091 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2092 CUEFILE_OUT=$CUEFILE_IN.out
2093 ### FIXME ### checkstatus cddb
2094 if [ -e "$CDDBDATA" ]; then
2095 vecho "Adding metadata to the cue file..."
2096 # FIXME It doesn't preserve spaces! Why?
2097 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2099 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2100 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2101 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2105 cat "$CUEFILE_IN" | while read line
2107 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2108 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2109 # echo "$line" >> "$CUEFILE_OUT"
2110 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2111 eval track="\$TRACK$n"
2113 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2114 # When making a single-track rip, put the
2115 # actual file name into the file declaration
2116 # in the cue file so that it is usable by
2117 # music players and the like
2118 elif [ "$ONETRACK" = "y" ] &&
2119 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2121 TRACKFILE="$(mungefilename "$TRACKNAME")"
2122 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2123 ALBUMFILE="$(mungefilename "$DALBUM")"
2125 if [ "$VARIOUSARTISTS" = "y" ]; then
2126 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2128 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2131 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2134 # FIXME # If the lines above are uncommented, remove the line below.
2135 echo "$line" >> "$CUEFILE_OUT"
2138 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2139 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2145 # Parses a CDDB file and outputs the title and the track names.
2146 # Variables: CDDBFILE
2150 # List out disc title/author and contents
2151 if [ "$ONETRACK" = "y" ]; then
2152 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2154 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2155 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2156 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2157 if [ ! X"$PARSEDYEAR" = "X" ]; then
2158 echo "Year: $PARSEDYEAR"
2161 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2162 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2163 if [ ! X"$PARSEDGENRE" = "X" ]; then
2164 echo "Genre: $PARSEDGENRE"
2167 if [ ! "$ONETRACK" = "y" ]; then
2168 for TRACK in $(f_seq_row 1 $TRACKS)
2170 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2176 # Check for a local CDDB file, and report success
2179 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2181 CDDBLOCALSTATUS="notfound"
2182 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2185 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2186 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2187 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2188 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2189 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2190 CDDBLOCALMATCH=single
2191 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2192 CDDBLOCALMATCH=multiple
2197 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2198 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2199 CDDBLOCALMATCH=single
2204 # If the user has selected to check a local CDDB repo, we proceed with it
2205 case $CDDBLOCALMATCH in
2207 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2209 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2211 # List out disc title/author and contents
2212 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2213 cat "$RESULT" > "${CDDBLOCALREAD}"
2216 do_cddbparse "${CDDBLOCALREAD}"
2218 ##FIXME## QUICK HACK !!!!
2219 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2220 } >> "$ABCDETEMPDIR/cddblocalchoices"
2222 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2223 page "$ABCDETEMPDIR/cddblocalchoices"
2225 # It's all going to fit in one page, cat it
2226 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2228 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2229 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2230 CDDBLOCALCHOICENUM=-1
2231 if [ "$INTERACTIVE" = "y" ]; then
2232 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2233 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2234 read CDDBLOCALCHOICE
2235 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2236 # FIXME # Introduce diff's
2237 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2238 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2239 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2240 # Make sure we get a valid choice
2241 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2242 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2243 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2249 #echo "Selected ..."
2251 CDDBLOCALCHOICENUM=1
2253 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2254 #echo "Using local copy of CDDB data"
2255 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2256 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2257 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2258 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2259 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2260 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2261 CDDBLOCALSTATUS="found"
2263 #echo "Not using local copy of CDDB data"
2264 CDDBLOCALSTATUS="notfound"
2268 # List out disc title/author and contents
2269 do_cddbparse "${CDDBLOCALFILE}"
2270 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2271 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2273 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2275 if [ "$INTERACTIVE" = "y" ]; then
2277 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2278 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2281 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2285 if [ "$USELOCALRESP" = "y" ]; then
2286 #echo "Using local copy of CDDB data"
2287 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2288 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2289 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2290 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2291 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2292 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2293 CDDBLOCALSTATUS="single"
2295 #echo "Not using local copy of CDDB data"
2296 CDDBLOCALSTATUS="notfound"
2300 CDDBLOCALSTATUS="notfound"
2307 # Try to read CD-Text from the drive using icedax / cdda2wav
2310 if new_checkexec icedax; then
2311 CDTEXT_READER=icedax
2312 elif new_checkexec cdda2wav; then
2313 CDTEXT_READER=cdda2wav
2315 # Didn't find either, bail
2319 if [ "$OSFLAVOUR" = "OSX" ] ; then
2320 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2321 diskutil unmount ${CDROM#/dev/}
2322 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2323 CDDA2WAVCDROM="IODVDServices"
2324 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2325 CDDA2WAVCDROM="$CDROMID"
2327 if [ "$CDROMID" = "" ]; then
2328 CDDA2WAVCDROM="$CDROM"
2330 CDDA2WAVCDROM="$CDROMID"
2334 # Do we have CD-Text on the disc (and can the drive read it?)
2335 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2336 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2338 if [ $ERRORCODE -ne 0 ]; then
2339 # No CD-Text found, bail
2343 rm -f "$ABCDETEMPDIR/cddbchoices"
2345 # Make an empty template
2346 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2347 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2348 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2349 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2350 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2351 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2352 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2353 # List out disc title/author and contents
2354 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2355 for TRACK in $(f_seq_row 1 $TRACKS)
2357 TRACKM1=$(($TRACK - 1))
2358 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2359 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2360 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2361 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2363 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2364 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2365 echo >> "$ABCDETEMPDIR/cddbchoices"
2366 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2370 # Work with the musicbrainz WS API, then transform the results here so
2371 # they look (very) like the results from CDDB. Maybe not the best way
2372 # to go, but it Works For Me (TM)
2376 if checkstatus musicbrainz-readcomplete; then :; else
2377 vecho "Obtaining Musicbrainz results..."
2378 # If MB is to be used, interpret the query results and read all
2379 # the available entries.
2380 rm -f "$ABCDETEMPDIR/cddbchoices"
2381 CDDBCHOICES=1 # Overridden by multiple matches
2382 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2383 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2385 # The helper script will write disc matches out to
2386 # cddbread.*. Count how many we have
2387 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2388 # No matches. Use the normal cddb template for the user to
2390 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2391 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2392 # List out disc title/author and contents of template
2393 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2395 for TRACK in $(f_seq_row 1 $TRACKS)
2397 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2399 echo >> "$ABCDETEMPDIR/cddbchoices"
2400 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2401 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2402 echo 503 > "$ABCDETEMPDIR/cddbquery"
2404 # We have some matches
2405 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2406 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2408 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2409 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2410 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2411 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2412 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2413 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2414 # List out disc title/author and contents
2415 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2416 for TRACK in $(f_seq_row 1 $TRACKS)
2418 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2420 echo >> "$ABCDETEMPDIR/cddbchoices"
2422 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2423 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2424 for file in "$ABCDETEMPDIR"/cddbread.*
2426 X=$(echo $file | sed 's/^.*cddbread\.//g')
2427 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2428 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2429 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2430 # List out disc title/author and contents
2431 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2432 for TRACK in $(f_seq_row 1 $TRACKS)
2434 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2436 echo >> "$ABCDETEMPDIR/cddbchoices"
2438 echo "." >> "$ABCDETEMPDIR/cddbquery"
2441 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2448 # Perform CDDB protocol version check if it hasn't already been done
2449 if checkstatus cddb-statcomplete; then :; else
2450 if [ "$CDDBAVAIL" = "n" ]; then
2452 echo 503 > "$ABCDETEMPDIR/cddbstat"
2455 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2456 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2457 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2458 vecho "Checking CDDB server status..."
2459 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2460 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2461 case "$RESPONSECODE" in
2462 210) # 210 OK, status information follows (until terminating `.')
2465 501) # 501 Illegal CDDB protocol level: <n>.
2466 CDDBPROTO=`expr $CDDBPROTO - 1`
2468 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2469 # FreeDB TESTCD disc-id is used for query
2470 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2471 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2472 case "$RESPONSECODE" in
2473 2??) # Server responded, everything seems OK
2483 if test $rc -eq 1; then
2487 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2495 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2496 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2498 # Perform CDDB query if it hasn't already been done
2499 if checkstatus cddb-querycomplete; then :; else
2500 if [ "$CDDBAVAIL" = "n" ]; then
2502 echo 503 > "$ABCDETEMPDIR/cddbquery"
2503 # The default CDDBLOCALSTATUS is "notfound"
2504 # This part will be triggered if the user CDDB repo does not
2505 # contain the entry, or if we are not trying to use the repo.
2507 vecho "Querying the CDDB server..."
2508 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2509 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2510 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2516 # no match found in database,
2517 # wget/fetch error, or user requested not to use CDDB
2518 # Make up an error code (503) that abcde
2519 # will recognize in do_cddbread
2520 # and compensate by making a template
2521 echo 503 > "$ABCDETEMPDIR/cddbquery"
2523 *) # strange and unknown error
2524 echo ERRORCODE=$ERRORCODE
2525 echo "abcde: $CDDBTOOL returned unknown error code"
2529 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2536 # If it's not to be used, generate a template.
2537 # Then, display it (or them) and let the user choose/edit it
2538 if checkstatus cddb-readcomplete; then :; else
2539 vecho "Obtaining CDDB results..."
2540 # If CDDB is to be used, interpret the query results and read all
2541 # the available entries.
2542 rm -f "$ABCDETEMPDIR/cddbchoices"
2543 CDDBCHOICES=1 # Overridden by multiple matches
2544 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2545 case "$RESPONSECODE" in
2547 # One exact match, retrieve it
2548 # 200 [section] [discid] [artist] / [title]
2549 if checkstatus cddb-read-1-complete; then :; else
2550 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2551 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2552 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2553 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2554 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2556 # List out disc title/author and contents
2557 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2558 for TRACK in $(f_seq_row 1 $TRACKS)
2560 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2562 echo >> "$ABCDETEMPDIR/cddbchoices"
2566 case "$RESPONSECODE" in
2567 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2568 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2569 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2571 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2572 # List out disc title/author and contents of template
2573 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2575 for TRACK in $(f_seq_row 1 $TRACKS)
2577 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2579 echo >> "$ABCDETEMPDIR/cddbchoices"
2580 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2581 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2584 # Multiple exact, (possibly multiple) inexact matches
2586 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2587 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2588 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2589 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2590 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2592 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2594 vecho -n "Retrieving multiple matches... "
2595 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2596 read DISCINFO # eat top line
2600 if checkstatus cddb-read-$X-complete; then :; else
2601 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2602 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2604 # List out disc title/author and contents
2605 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2606 for TRACK in $(f_seq_row 1 $TRACKS)
2608 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2610 echo >> "$ABCDETEMPDIR/cddbchoices"
2613 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2617 for TRACK in $(f_seq_row 1 $TRACKS)
2619 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2621 echo >> "$ABCDETEMPDIR/cddbchoices"
2622 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2623 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2626 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2633 if checkstatus cddb-edit >/dev/null; then
2634 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2635 VARIOUSARTISTS="$(checkstatus variousartists)"
2636 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2639 if [ "$INTERACTIVE" = "y" ]; then
2640 # We should show the CDDB results both when we are not using the local CDDB repo
2641 # or when we are using it but we could not find a proper match
2642 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2643 # Display the $ABCDETEMPDIR/cddbchoices file created above
2644 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2645 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2646 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2647 CHOICE=$(checkstatus cddb-choice)
2648 if [ -n "$CHOICE" ] ; then
2649 case $CDDBCHOICES in
2650 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2651 log error "CDDB query failed!"
2654 cat "$ABCDETEMPDIR/cddbchoices"
2657 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2659 echo "Selected: #$CHOICE"
2660 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2664 # The user has a choice to make, display the info in a pager if necessary
2665 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2666 page "$ABCDETEMPDIR/cddbchoices"
2668 # It's all going to fit in one page, cat it
2669 cat "$ABCDETEMPDIR/cddbchoices" >&2
2673 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2675 # I'll take CDDB read #3 for $400, Alex
2676 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2677 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2679 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2680 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2681 if [ ! X"$DIFF" = "X" ]; then
2682 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2683 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2684 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2685 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2686 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2687 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2689 # We parse the 2 choices to diff, store them in temporary files and diff them.
2690 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2691 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2693 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2694 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2695 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2696 page "$ABCDETEMPDIR/cddbread.diff"
2698 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2702 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2704 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2705 # Make sure we get a valid choice
2706 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2707 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2708 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2712 if [ "$CDCHOICENUM" = "0" ]; then
2713 vecho "Creating empty CDDB template..."
2715 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2717 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2718 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2720 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2724 # We need some code to show the selected option when local repository is selected and we have found a match
2725 vecho "Using cached CDDB match..." >&2
2726 # Display the $ABCDETEMPDIR/cddbchoices file created above
2727 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2728 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2729 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2730 CHOICE=$(checkstatus cddb-choice)
2731 if [ "$USELOCALRESP" = "y" ]; then :; else
2732 if [ -n "$CHOICE" ] ; then
2733 case $CDDBCHOICES in
2736 echo "Selected template."
2738 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2740 echo "Selected: #$CHOICE"
2741 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2749 # We're noninteractive - pick the first choice.
2750 # But in case we run a previous instance and selected a choice, use it.
2751 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2752 # Show the choice if we are not using the locally stored one
2753 # or when the local search failed to find a match.
2754 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2755 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2756 #if [ "$PREVIOUSCHOICE" ]; then
2757 cat "$ABCDETEMPDIR/cddbchoices"
2760 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2761 CDCHOICENUM=$PREVIOUSCHOICE
2764 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2766 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2771 if checkstatus cddb-choice >/dev/null; then :; else
2772 echo "abcde: internal error: cddb-choice not recorded." >&2
2775 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2776 echo -n "Edit selected CDDB data " >&2
2777 if [ "$INTERACTIVE" = "y" ]; then
2778 if [ "$UNKNOWNDISK" = "y" ]; then
2779 echo -n "[Y/n]? " >&2
2781 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2783 echo -n "[y/N]? " >&2
2790 if [ "$EDITCDDB" = "y" ]; then
2791 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2793 # Use the debian sensible-editor wrapper to pick the editor that the
2794 # user has requested via their $EDITOR environment variable
2795 if [ -x "/usr/bin/sensible-editor" ]; then
2796 /usr/bin/sensible-editor "$CDDBDATA"
2797 elif [ -n "$EDITOR" ]; then
2798 if [ -x $(which "${EDITOR%%\ *}") ]; then
2799 # That failed, try to load the preferred editor, starting
2800 # with their EDITOR variable
2801 eval $(echo "$EDITOR") \"$CDDBDATA\"
2803 # If that fails, check for a vi
2804 elif which vi >/dev/null 2>&1; then
2806 elif [ -x /usr/bin/vim ]; then
2807 /usr/bin/vim "$CDDBDATA"
2808 elif [ -x /usr/bin/vi ]; then
2809 /usr/bin/vi "$CDDBDATA"
2810 elif [ -x /bin/vi ]; then
2812 # nano should be on all (modern, i.e., sarge) debian systems
2813 elif which nano >/dev/null 2>&1 ; then
2815 elif [ -x /usr/bin/nano ]; then
2816 /usr/bin/nano "$CDDBDATA"
2817 # mg should be on all OpenBSD systems
2818 elif which mg >/dev/null 2>&1 ; then
2820 elif [ -x /usr/bin/mg ]; then
2821 /usr/bin/mg "$CDDBDATA"
2824 log warning "no editor available. Check your EDITOR environment variable."
2826 # delete editor backup file if it exists
2827 if [ -w "$CDDBDATA~" ]; then
2832 # Some heuristics first. Look at Disc Title, and if it starts with
2833 # "Various", then we'll assume Various Artists
2834 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2835 echo "Looks like a Multi-Artist CD" >&2
2838 echo -n "Is the CD multi-artist [y/N]? " >&2
2839 if [ "$INTERACTIVE" = "y" ]; then
2846 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2849 # Need NUMTRACKS before cddb-tool will return it:
2850 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2851 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2852 # More than 1/2 tracks contain a "/", so guess forward
2854 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2855 # More than 1/2 contain a "-", so guess forward-dash
2857 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2858 # More than 1/2 contain something in parens, so guess trailing-paren
2862 echo "1) Artist / Title" >&2
2863 echo "2) Artist - Title" >&2
2864 echo "3) Title / Artist" >&2
2865 echo "4) Title - Artist" >&2
2866 echo "5) Artist: Title" >&2
2867 echo "6) Title (Artist)" >&2
2868 echo "7) This is a single-artist CD" >&2
2869 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2870 if [ "$INTERACTIVE" = "y" ]; then
2871 read VARIOUSARTISTSTYLE
2873 echo $DEFAULTSTYLE >&2
2874 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2876 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2877 # If they press Enter, then the default style (0) was chosen
2878 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2879 echo "Invalid selection. Please choose a number between 1 and 7."
2880 echo -n "Selection [1-7]: "
2881 read VARIOUSARTISTSTYLE
2882 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2884 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2885 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2887 vecho "Selected: $VARIOUSARTISTSTYLE"
2888 case "$VARIOUSARTISTSTYLE" in
2890 VARIOUSARTISTSTYLE=forward
2893 VARIOUSARTISTSTYLE=forward-dash
2896 VARIOUSARTISTSTYLE=reverse
2899 VARIOUSARTISTSTYLE=reverse-dash
2902 VARIOUSARTISTSTYLE=colon
2905 VARIOUSARTISTSTYLE=trailing-paren
2913 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2914 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2916 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2917 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2918 # This works but does not have the necessary error checking
2919 # yet. If you are familiar with the CDDB spec
2920 # (see http://www.freedb.org/src/latest/DBFORMAT)
2921 # and can create an error-free entry on your own, then put
2922 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2923 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2924 # your abcde.conf to change the email address submissions are
2927 # submit the modified file, if they want
2928 if [ "$NOSUBMIT" != "y" ]; then
2929 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2931 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2932 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2934 echo -n 'Invalid selection. Please answer "y" or "n": '
2937 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2938 echo -n "Sending..."
2939 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2946 # User CDDBLOCALPOLICY to find out if we store the file or not...
2947 # Cache edited CDDB entry in the user's cddb dir
2948 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2949 # Make sure the cache directory exists
2950 mkdir -p $CDDBLOCALDIR
2951 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2954 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2957 # do_cdread [tracknumber]
2958 # do_cdread onetrack [firsttrack] [lasttrack]
2962 # The commands here don't go through run_command because they're never supposed to be silenced
2963 # return codes need to be doublechecked anyway, however
2964 if [ "$1" = "onetrack" ]; then
2965 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2966 # FIXME # Until then, we grab the whole CD in one track, no matter what
2968 # We need the first and last track for cdda2wav/icedax
2970 LASTTRACK=$(expr $3 + 0)
2971 UTRACKNUM=$FIRSTTRACK
2972 case "$CDROMREADERSYNTAX" in
2973 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2976 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
2977 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2978 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
2979 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
2980 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2986 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2987 if [ "$USEPIPES" = "y" ]; then
2988 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
2989 FILEARG="$( eval echo "\$$TEMPARG" )"
2991 PIPE_MESSAGE="and encoding "
2993 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2994 case "$CDROMREADERSYNTAX" in
2995 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2997 FILEARG="--output-name=$WAVDATA"
3000 FILEARG="-f $WAVDATA"
3008 if [ "$1" = "onetrack" ]; then
3009 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2