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.
18 VERSION='2.5.5-UNRELEASED'
22 echo "This is abcde v$VERSION."
23 echo "Usage: abcde [options] [tracks]"
25 echo "-1 Encode the whole CD in a single file"
26 echo "-a <action1[,action2]...>"
27 echo " Actions to perform:"
28 echo " cddb,read,normalize,encode,tag,move,replaygain,playlist,clean"
29 #echo "-A Experimental actions (retag, transcode)"
30 echo "-b Enable batch normalization"
31 #echo "-B Disable batch replaygain (do file by file)"
33 echo " Specify a configuration file (overrides system and user config files)"
35 echo " Specify discid to resume from (only needed if you no longer have the cd)"
37 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
38 echo "-D Debugging mode (equivalent to sh -x abcde)"
39 echo "-e Erase encoded track information from status file"
40 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
41 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
42 echo "-h This help information"
43 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
44 echo "-j <#> Number of encoder processes to run at once (localhost)"
45 echo "-k Keep the wav tracks for later use"
46 echo "-l Use low disk space algorithm"
47 echo "-L Use local CDDB storage directory"
48 echo "-m Modify playlist to include CRLF endings, to comply with some players"
49 #echo " WARNING: Deprecated. Use \"cue\" action"
50 #echo "-M Create a CUE file"
51 echo "-n No lookup. Don't query CDDB, just create and use template"
52 echo "-N Noninteractive. Never prompt for anything"
53 echo "-o <type1[,type2]...>"
54 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus). Defaults to vorbis"
55 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
56 echo "-P Use UNIX pipes to read+encode without wav files"
58 echo " Set quality level (high,medium,low)"
59 echo "-r <host1[,host2]...>"
60 echo " Also encode on these remote hosts"
62 echo " Show fields from the CDDB info (year,genre)"
63 echo "-S <#> Set the CD speed"
64 echo "-t <#> Start the track numbering at a given number"
65 echo "-T <#> Same as -t but modifies tag numbering"
66 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
67 echo "-v Show version number and exit"
68 echo "-V Be a bit more verbose about what is happening behind the scenes"
69 echo "-x Eject CD after all tracks are read"
71 echo " Add a comment to the CD tracks"
72 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
73 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
75 echo "Tracks is a space-delimited list of tracks to grab."
76 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
78 #echo "Double hyphens are used to concatenate tracks"
83 echo "$@" >> "$ABCDETEMPDIR/status"
86 # log [level] [message]
88 # log outputs the right message in a common format
94 error) echo "[ERROR] abcde: $@" >&2 ;;
95 warning) echo "[WARNING] $@" >&2 ;;
96 info) echo "[INFO] $@" ;;
100 # Functions to replace the need of seq, which is too distribution dependent.
104 while [ $i -ne `expr $2 + 1` ]
114 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
115 while [ $i -ne `expr $2 + 1` ]
122 log error "syntax error while processing track numbers ($i)"
127 # Functions to replace the need of awk {print $1} and {print $NF}
130 if [ X"$1" = "X" ]; then
131 for first in `cat`; do
142 if [ X"$1" = "X" ]; then
143 for stdin in `cat`; do
147 for last in $@ ; do :; done
152 # checkstatus [blurb]
153 # Returns "0" if the blurb was found, returns 1 if it wasn't
154 # Puts the blurb content, if available, on stdout.
155 # Otherwise, returns "".
158 # Take the last line in the status file if there's multiple matches
160 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
162 if [ -z "$BLURB" ]; then
167 # See if there's a = in it
168 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
169 echo "$(echo $BLURB | cut -f2- -d=)"
175 # checkwarnings [blurb]
176 # Returns "0" if the blurb was found (meaning there was an warning),
177 # returns 1 if it wasn't (yes this is a little backwards).
178 # Does not print the blurb on stdout.
179 # Otherwise, returns "".
182 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
185 # Take the last line in the status file if there's multiple matches
187 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
189 if [ -z "$BLURB" ]; then
190 # negative, we did not have a negative...
193 # affirmative, we had a negative...
198 # checkerrors [blurb]
199 # Returns "0" if the blurb was found (meaning there was an error),
200 # returns 1 if it wasn't (yes this is a little backwards).
201 # Does not print the blurb on stdout.
202 # Otherwise, returns "".
205 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
208 # Take the last line in the status file if there's multiple matches
210 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
212 if [ -z "$BLURB" ]; then
213 # negative, we did not have a negative...
216 # affirmative, we had a negative...
222 # Finds the right pager in the system to display a file
226 # Use the debian sensible-pager wrapper to pick the pager
227 # user has requested via their $PAGER environment variable
228 if [ -x "/usr/bin/sensible-pager" ]; then
229 /usr/bin/sensible-pager "$PAGEFILE"
230 elif [ -x "$PAGER" ]; then
231 # That failed, try to load the preferred editor, starting
232 # with their PAGER variable
234 # If that fails, check for less
235 elif [ -x /usr/bin/less ]; then
236 /usr/bin/less -f "$PAGEFILE"
237 # more should be on all UNIX systems
238 elif [ -x /bin/more ]; then
239 /bin/more "$PAGEFILE"
241 # No bananas, just cat the thing
246 # run_command [blurb] [command...]
247 # Runs a command, silently if necessary, and updates the status file
253 # See if this is supposed to be silent
254 if [ "$(checkstatus encode-output)" = "loud" ]; then
258 # Special case for SMP, since
259 # encoder output is never displayed, don't mute echos
260 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
269 normalize|normalize-audio)
270 if [ "$RETURN" = "2" ]; then
271 # File was already normalized.
276 if [ "$RETURN" != "0" ]; then
277 # Put an error in the errors file. For various reasons we
278 # can't capture a copy of the program's output but we can
279 # log what we attempted to execute and the error code
280 # returned by the program.
281 if [ "$BLURB" ]; then
284 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
285 return $RETURN # Do not pass go, do not update the status file
287 if [ "$BLURB" ]; then
288 echo $BLURB >> "$ABCDETEMPDIR/status"
292 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
293 # distributed under the terms of the GNU GPL v2 or later, at your option
295 # Function to determine if a word contains a slash.
304 # Function to give the relative path from one file to another.
305 # Usage: relpath fromfile tofile
306 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
307 # (the result would be Album/Song.mp3)
308 # Output is relative path to $2 from $1 on stdout
310 # This code has the following restrictions:
311 # Multiple ////s are not collapsed into single /s, with strange effects.
312 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
313 # If FR is a directory it must have a trailing /
321 /*) ;; # No processing is needed for absolute paths
323 # Loop through common prefixes, ignoring them.
324 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
326 FR="$(echo "$FR" | cut -d/ -f2-)"
327 TO="$(echo "$TO" | cut -d/ -f2-)"
329 # Loop through directory portions left in FR, adding appropriate ../s.
332 FR="$(echo "$FR" | cut -d/ -f2-)"
343 if [ ! "$@" = "" ]; then
344 # Cut off any command-line option we added in
345 X=$(echo $@ | cut -d' ' -f2)
346 if [ "$(which $X)" = "" ]; then
348 elif [ ! -x $(which $X) ]; then
357 if [ ! "$@" = "" ]; then
358 # Cut off any command-line option we added in
359 X=$(echo $@ | cut -d' ' -f2)
360 # Test for built-in abcde.function
361 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
362 if [ "$(which $X)" = "" ]; then
363 log error "$X is not in your path." >&2
364 log info "Define the full path to the executable if it exists on your system." >&2
365 if [ -e /etc/debian_release ] ; then
367 oggenc) MISSING_PACKAGE=vorbis-tools ;;
368 lame|flac) MISSING_PACKAGE=$X ;;
370 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
373 elif [ ! -x "$(which $X)" ]; then
374 log error "$X is not executable." >&2
380 # diffentries <filename> <max_value> <entry1>,<entry2>
381 # max_value: the range of entries goes from 1 to <max_value>
386 local CDDBDIFFCHOICES=$1
388 local CDDBDIFFCHOICE="$@"
389 if [ ! X"$DIFF" = "X" ]; then
390 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
391 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
392 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
393 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
394 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
395 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
397 # We parse the 2 choices to diff, store them in temporary files and diff them.
398 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
399 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
401 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
402 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
403 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
404 page "$ABCDETEMPDIR/$FILENAME.diff"
406 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
410 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
415 # Finds an specific field from cddbinfo
420 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
423 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
426 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
432 # Get the track number we are going to use for different actions
435 if [ -n "$STARTTRACKNUMBER" ] ; then
436 # Get the trackpadding from the current track, also trim whitespace for MacOSX
437 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
438 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
440 TRACKNUM=${UTRACKNUM}
446 # Calculate cddb disc ids without requiring specialized helper programs.
447 # largely copied from cd-discid and musicbrainz examples. some of the steps
448 # don't make sense, but they're necessary to match the ids generated by other
451 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
452 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
453 # 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
454 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
455 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
456 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
458 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
461 if [ X"$LEADOUT" = "X" ]; then
462 log warning "Error trying to calculate disc ids without lead-out information."
466 # default to a two second lead-in
468 LEADIN=${LEADIN:=150}
470 # number of cdframes per second
473 # reset cddb checksum for cddb disc-id calululation
477 for OFFSET in $(echo $OFFSETS)
479 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
481 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
482 while [ $OFFSETTIME -gt 0 ]; do
483 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
484 OFFSETTIME=$(($OFFSETTIME / 10))
489 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
491 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
492 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
494 case "$CDDBMETHOD" in
496 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
499 # FIXME: don't assume the first track is 1
500 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
501 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
505 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
510 if checkstatus replaygain; then :; else
511 run_command "" echo "Adding replaygain information..."
512 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
516 OUTPUT=$OGGOUTPUTCONTAINER
519 OUTPUT=$OPUSOUTPUTCONTAINER
522 OUTPUT=$FLACOUTPUTCONTAINER
530 for UTRACKNUM in $TRACKQUEUE
532 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
533 getcddbinfo TRACKNAME
535 TRACKFILE="$(mungefilename "$TRACKNAME")"
536 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
537 ALBUMFILE="$(mungefilename "$DALBUM")"
538 GENRE="$(mungegenre "$GENRE")"
539 YEAR=${CDYEAR:-$CDYEAR}
541 if [ "$ONETRACK" = "y" ]; then
542 if [ "$VARIOUSARTISTS" = "y" ]; then
543 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
545 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
548 if [ "$VARIOUSARTISTS" = "y" ]; then
549 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
551 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
554 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
555 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
559 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
560 #run_command replaygain-flac true
563 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
566 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
569 run_command replaygain-mpc nice $ENCNICE $MPPGAIN --auto "${OUTPUTFILES[@]}"
574 if checkerrors "replaygain-.{3,6}"; then :; else
575 run_command replaygain true
580 # This code splits the a Various Artist track name from one of the following
583 # forward: Artist / Track
584 # forward-dash: Artist - Track
585 # reverse: Track / Artist
586 # reverse-dash: Track - Artist
587 # colon: Artist: Track
588 # trailing-paren: Artist (Track)
591 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
594 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
595 case "$VARIOUSARTISTSTYLE" in
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 -f1 -d~)"
604 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -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 -f2 -d~)"
614 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
617 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
618 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
619 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
622 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
623 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
624 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
627 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
628 TRACKARTIST="Various"
630 TRACKARTIST="$DARTIST"
635 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
639 "classic rock") id=1 ;;
657 "industrial") id=19 ;;
658 "alternative") id=20 ;;
660 "death metal") id=22 ;;
662 "soundtrack") id=24 ;;
663 "euro-techno") id=25 ;;
667 "jazz+funk") id=29 ;;
670 "classical") id=32 ;;
671 "instrumental") id=33 ;;
675 "sound clip") id=37 ;;
678 "alt. rock") id=40 ;;
683 "meditative") id=45 ;;
684 "instrum. pop") id=46 ;;
685 "instrum. rock") id=47 ;;
689 "techno-indust.") id=51 ;;
690 "electronic") id=52 ;;
692 "eurodance") id=54 ;;
694 "southern rock") id=56 ;;
699 "christian rap") id=61 ;;
700 "pop/funk"|"pop / funk") id=62 ;;
702 "native american") id=64 ;;
705 "psychadelic") id=67 ;;
707 "showtunes") id=69 ;;
711 "acid punk") id=73 ;;
712 "acid jazz") id=74 ;;
716 "rock & roll") id=78 ;;
717 "hard rock") id=79 ;;
719 "folk/rock") id=81 ;;
720 "national folk") id=82 ;;
727 "bluegrass") id=89 ;;
728 "avantgarde") id=90 ;;
729 "gothic rock") id=91 ;;
730 "progress. rock") id=92 ;;
731 "psychadel. rock") id=93 ;;
732 "symphonic rock") id=94 ;;
733 "slow rock") id=95 ;;
736 "easy listening") id=98 ;;
742 "chamber music") id=104 ;;
744 "symphony") id=106 ;;
745 "booty bass") id=107 ;;
747 "porn groove") id=109 ;;
749 "slow jam") id=111 ;;
753 "folklore") id=115 ;;
755 "power ballad") id=117 ;;
756 "rhythmic soul") id=118 ;;
757 "freestyle") id=119 ;;
759 "punk rock") id=121 ;;
760 "drum solo") id=122 ;;
761 "a capella") id=123 ;;
762 "euro-house") id=124 ;;
763 "dance hall") id=125 ;;
765 "drum & bass") id=127 ;;
766 "club-house") id=128 ;;
767 "hardcore") id=129 ;;
771 "negerpunk") id=133 ;;
772 "polsk punk") id=134 ;;
774 "christian gangsta rap") id=136 ;;
775 "heavy metal") id=137 ;;
776 "black metal") id=138 ;;
777 "crossover") id=139 ;;
778 "contemporary christian")id=140 ;;
779 "christian rock") id=141 ;;
780 "merengue") id=142 ;;
782 "thrash metal") id=144 ;;
785 "synthpop") id=147 ;;
786 "rock/pop"|"rock / pop") id=148 ;;
793 # do_tag [tracknumber]
794 # id3 tags a filename
796 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC, ATOMICPARSLEY
797 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
800 COMMENTOUTPUT="$(eval echo ${COMMENT})"
801 if [ -z "$COMMENTOUTPUT" ]; then
802 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
804 if [ "$CDDBMETHOD" = "cddb" ]; then
805 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
807 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
808 # If we want to start the tracks with a given number, we need to modify the
809 # TRACKNUM value before evaluation
810 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
813 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
817 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
818 GENREID=$(do_getgenreid "${CDGENRE}")
819 # Set TPE2 in case we have a Various Artists rip.
821 if [ "$VARIOUSARTISTS" = "y" ]; then
828 # FIXME # track numbers in mp3 come with 1/10, so we cannot
829 # happily substitute them with $TRACKNUM
830 # FIXME as well! # Older versions of eyeD3 (< 0.7.0) expect
831 # --set-encoding and --set-text-frame so perhaps some version
832 # sniffing would be useful. Might also be better to simply cut
833 # ties with the older eyeD3... Andrew.
834 # eyeD3 --comment syntax is also different in < and >= 0.7.0
835 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
836 --comment="$COMMENTOUTPUT" -A "$DALBUM" \
837 -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
838 -G "$GENREID" -n "${TRACKNUM:-$1}" \
839 ${TRACKNUM:+-N "$TRACKS"} \
840 ${ENCODING:+--encoding="$ENCODING"} \
841 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
842 "$ABCDETEMPDIR/track$1.$OUTPUT"
844 # FIXME # Still not activated...
846 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
847 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
848 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" \
849 -y "$CDYEAR" -g "$GENREID" -k "${TRACKNUM:-$1}" \
850 "$ABCDETEMPDIR/track$1.$OUTPUT"
853 # FIXME # track numbers in mp3 come with 1/10, so we cannot
854 # happily substitute them with $TRACKNUM
855 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
856 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
857 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
858 -y "$CDYEAR" -g "$GENREID" \
859 -T "${TRACKNUM:-$1}/$TRACKS" \
860 ${TPE2:+--TPE2 "$TPE2"} \
861 "$ABCDETEMPDIR/track$1.$OUTPUT"
866 case "$OGGENCODERSYNTAX" in
868 # vorbiscomment can't do in-place modification, mv the file first
869 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
870 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
874 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
876 echo ARTIST="$TRACKARTIST"
878 echo TITLE="$TRACKNAME"
879 if [ -n "$CDYEAR" ]; then
882 if [ -n "$CDGENRE" ]; then
883 echo GENRE="$CDGENRE"
885 echo TRACKNUMBER=${TRACKNUM:-$1}
886 if [ -n "$DISCNUMBER" ]; then
887 echo DISCNUMBER="$DISCNUMBER"
889 echo CDDB=$CDDBDISCID
890 if [ "$(eval echo ${COMMENT})" != "" ]; then
891 case "$COMMENTOUTPUT" in
892 *=*) echo "$COMMENTOUTPUT";;
893 *) echo COMMENT="$COMMENTOUTPUT";;
896 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
897 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
898 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
899 # Doublecheck that the commented file was created
900 # successfully before wiping the original
901 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
902 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
904 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
910 run_command tagtrack-$OUTPUT-$1 true
915 echo ARTIST="$TRACKARTIST"
917 echo TITLE="$TRACKNAME"
918 if [ -n "$CDYEAR" ]; then
921 if [ -n "$CDGENRE" ]; then
922 echo GENRE="$CDGENRE"
924 echo TRACKNUMBER="${TRACKNUM:-$1}"
925 if [ -n "$DISCNUMBER" ]; then
926 echo DISCNUMBER="$DISCNUMBER"
928 echo CDDB="$CDDBDISCID"
929 if [ "$(eval echo ${COMMENT})" != "" ]; then
930 case "$COMMENTOUTPUT" in
931 *=*) echo "$COMMENTOUTPUT";;
932 *) echo COMMENT="$COMMENTOUTPUT";;
935 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
938 run_command tagtrack-$OUTPUT-$1 true
941 run_command tagtrack-$OUTPUT-$1 true
944 # Use a temp-file of our choice. --overWrite seems to
945 # case core dumps with AtomicParsley 0.9.0
946 ATOMICTEMPFILE="$ABCDETEMPDIR/track$1.m4a-atomic"
949 if [ "$VARIOUSARTISTS" = "y" ]; then
953 #It has to be command file opts for AtomicParsley
954 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $ATOMICPARSLEY "$ABCDETEMPDIR/track$1.m4a" --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --tracknum ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --compilation $VARIOUSBOOL --comment "$COMMENTOUTPUT" --output $ATOMICTEMPFILE
955 if [ -f $ATOMICTEMPFILE ]; then
956 mv "$ATOMICTEMPFILE" "$ABCDETEMPDIR/track$1.m4a"
960 run_command tagtrack-$OUTPUT-$1 true
964 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
965 run_command tagtrack-$1 true
972 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
975 # The commands here don't go through run_command because they're never
976 # supposed to be silenced
977 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
978 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
982 case "$MP3ENCODERSYNTAX" in
987 for UTRACKNUM in $TRACKQUEUE
989 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
991 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
993 if [ "$RETURN" != "0" ]; then
994 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
996 for UTRACKNUM in $TRACKQUEUE
998 run_command encodetrack-$OUTPUT-$UTRACKNUM true
999 #run_command encodetrack-$UTRACKNUM true
1008 if checkerrors "nogap-encode"; then :; else
1009 if [ ! "$KEEPWAVS" = "y" ] ; then
1010 if [ ! "$KEEPWAVS" = "move" ] ; then
1015 # Other encoders fall through to normal encoding as the tracks have not
1016 # been entered in the status file.
1019 # do_encode [tracknumber] [hostname]
1020 # If no hostname is specified, encode locally
1022 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1025 if [ "$USEPIPES" = "y" ]; then
1028 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1031 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1034 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1037 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1040 TEMPARG="PIPE_$SPEEXENCODER"
1043 TEMPARG="PIPE_$MPCENCODER"
1046 TEMPARG="PIPE_$AACENCODERSYNTAX"
1049 IN="$( eval echo "\$$TEMPARG" )"
1051 IN="$ABCDETEMPDIR/track$1.wav"
1054 case "$MP3ENCODERSYNTAX" in
1055 # FIXME # check if mp3enc needs -if for pipes
1056 # FIXME # I have not been able to find a working mp3enc binary
1070 # We need IN to proceed, if we are not using pipes.
1071 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1072 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1074 case "$TMPOUTPUT" in
1076 OUTPUT=$OGGOUTPUTCONTAINER
1079 OUTPUT=$OPUSOUTPUTCONTAINER
1082 OUTPUT=$FLACOUTPUTCONTAINER
1088 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1089 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1092 if [ X"$USEPIPES" = "Xy" ]; then
1094 # We need a way to store the creation of the files when using PIPES
1095 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1096 # When pipping it does not make sense to have a higher nice for
1097 # reading than for encoding, since it will be hold by the
1098 # encoding process. Setting an effective nice, to calm down a
1099 # bit the reading process.
1100 EFFECTIVE_NICE=$READNICE
1102 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1103 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1104 EFFECTIVE_NICE=$ENCNICE
1110 case "$MP3ENCODERSYNTAX" in
1111 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1112 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1113 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1114 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1115 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1119 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1126 case "$OGGENCODERSYNTAX" in
1127 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1128 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1132 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1139 case "$OPUSENCODERSYNTAX" in
1142 if [ "$(eval echo ${COMMENT})" != "" ]; then
1145 *) COMMENT="COMMENT=$COMMENT" ;;
1148 # Tag the file at encode time, as it can't be done after encoding.
1149 if [ "$DOTAG" = "y" ]; then
1150 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" --comment album="$DALBUM" --title "$TRACKNAME" --comment track="$1" --comment genre="$CDGENRE" --comment year="$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1152 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1158 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1165 case "$FLACENCODERSYNTAX" in
1166 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1171 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1172 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1177 if [ "$(eval echo ${COMMENT})" != "" ]; then
1180 *) COMMENT="COMMENT=$COMMENT" ;;
1183 # Tag the file at encode time, as it can't be done after encoding.
1184 if [ "$DOTAG" = "y" ]; then
1185 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1187 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1191 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1192 # tagging. Uses mpcenc for Musepack SV8 encoding, changed from
1193 # Musepack SV7 which used mppenc....
1194 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
1197 # Tag the file at encode time, as it can't be done after encoding.
1198 if [ "$AACENC" = "neroAacEnc" ] ; then
1200 $RUN_COMMAND nice $ENCNICE $AACENC $AACENCOPTS -if "$IN" -of "$OUT"
1201 elif [ ! "$DOTAG" = "y" ]; then
1202 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
1205 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1209 # In case of wav output we need nothing. Just keep the wavs.
1214 # Only remove .wav if the encoding succeeded
1215 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1216 run_command encodetrack-$1 true
1217 if [ ! "$KEEPWAVS" = "y" ] ; then
1218 if [ ! "$KEEPWAVS" = "move" ] ; then
1224 run_command "" echo "HEH! The file we were about to encode disappeared:"
1225 run_command "" echo ">> $IN"
1226 run_command encodetrack-$1 false
1230 # do_preprocess [tracknumber]
1232 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1235 # IN="$ABCDETEMPDIR/track$1.wav"
1236 # # We need IN to proceed.
1237 # if [ -s "$IN" ] ; then
1238 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1240 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1241 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1242 # case "$POSTPROCESSFORMAT" in
1244 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1246 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1248 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1250 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1252 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1255 # # Only remove .wav if the encoding succeeded
1256 # if checkerrors "preprocess-(.{3,4})-$1"; then
1257 # run_command preprocess-$1 false
1259 # run_command preprocess-$1 true
1262 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1263 # echo "HEH! The file we were about to pre-process disappeared:"
1266 # run_command preprocess-$1 false
1271 # do_postprocess [tracknumber]
1273 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1276 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1278 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1279 # # We need IN to proceed.
1280 # if [ -s "$IN" ] ; then
1281 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1282 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1283 # case "$POSTPROCESSFORMAT" in
1285 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1287 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1289 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1291 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1293 # # Only remove .wav if the encoding succeeded
1294 # if checkerrors "postprocess-(.{3,4})-$1"; then
1295 # run_command postprocess-$1 false
1297 # run_command postprocess-$1 true
1300 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1301 # echo "HEH! The file we were about to post-process disappeared:"
1304 # run_command postprocess-$1 false
1319 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1323 # The commands here don't go through run_command because they're never supposed to be silenced
1324 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1329 for UTRACKNUM in $TRACKQUEUE
1331 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1333 # FIXME # Hard-coded batch option!
1334 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1336 if [ "$RETURN" != "0" ]; then
1337 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1339 for UTRACKNUM in $TRACKQUEUE
1341 echo normalizetrack-$UTRACKNUM >> status
1347 # do_batch_normalize
1349 # NORMALIZER, NORMALIZEROPTS
1350 do_batch_normalize ()
1352 # The commands here don't go through run_command because they're never supposed to be silenced
1353 echo "Batch normalizing tracks: $TRACKQUEUE"
1358 for UTRACKNUM in $TRACKQUEUE
1360 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1362 # XXX: Hard-coded batch option!
1363 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1365 if [ "$RETURN" != "0" ]; then
1366 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1368 for UTRACKNUM in $TRACKQUEUE
1370 echo normalizetrack-$UTRACKNUM >> status
1376 # do_normalize [tracknumber]
1378 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1381 IN="$ABCDETEMPDIR/track$1.wav"
1382 if [ -e "$IN" ] ; then
1383 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1384 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1386 if [ "$(checkstatus encode-output)" = "loud" ]; then
1387 echo "HEH! The file we were about to normalize disappeared:"
1390 run_command normalizetrack-$1 false "File $IN was not found"
1394 # do_move [tracknumber]
1395 # Deduces the outfile from environment variables
1396 # Creates directory if necessary
1398 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1401 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1403 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1404 # defined the OUTPUTFILE:
1407 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1408 # Munge filenames as follows:
1413 # Eat control characters
1414 ALBUMFILE="$(mungefilename "$DALBUM")"
1415 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1416 TRACKFILE="$(mungefilename "$TRACKNAME")"
1417 GENRE="$(mungegenre "$GENRE")"
1418 YEAR=${CDYEAR:-$CDYEAR}
1419 # If we want to start the tracks with a given number, we need to modify
1420 # the TRACKNUM value before evaluation
1422 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1423 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1424 if [ "$ONETRACK" = "y" ]; then
1425 if [ "$VARIOUSARTISTS" = "y" ]; then
1426 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1428 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1431 if [ "$VARIOUSARTISTS" = "y" ]; then
1432 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1434 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1437 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1438 # Once we know the specific output was successful, we can change
1439 # the OUTPUT to the value containing the container
1442 OUTPUT=$OGGOUTPUTCONTAINER
1445 OUTPUT=$OPUSOUTPUTCONTAINER
1448 OUTPUT=$FLACOUTPUTCONTAINER
1454 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1455 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1458 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1459 # FIXME # introduce warnings?
1462 # mkdir -p shouldn't return an error if the directory already exists
1463 mkdir -p "$OUTPUTFILEDIR"
1464 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1465 if checkstatus movetrack-output-$OUTPUT; then :; else
1466 run_command movetrack-output-$OUTPUT true
1471 # mkdir -p shouldn't return an error if the directory already exists
1472 mkdir -p "$OUTPUTFILEDIR"
1473 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1474 if checkstatus movetrack-output-$OUTPUT; then :; else
1475 run_command movetrack-output-$OUTPUT true
1479 # Lets move the cue file
1480 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1481 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1482 if checkstatus movecue-$OUTPUT; then :; else
1483 # Silence the Copying output since it overlaps with encoding processes...
1484 #run_command '' vecho "Copying cue file to its destination directory..."
1485 if checkstatus onetrack >/dev/null ; then
1488 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1489 # We dont have the dir, since it was not created before.
1492 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1495 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1496 # http://brianvictor.tripod.com/mp3cue.htm#details
1497 [a-z0-9][a-z0-9][a-z0-9])
1498 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1501 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1505 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1507 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1516 # Create the playlist if wanted
1518 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1519 # VARIOUSARTISTS, OUTPUTDIR
1522 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1526 OUTPUT=$OGGOUTPUTCONTAINER
1529 OUTPUT=$OPUSOUTPUTCONTAINER
1532 OUTPUT=$FLACOUTPUTCONTAINER
1538 # Create a playlist file for the playlist data to go into.
1539 # We used to wipe it out if it existed. Now we request permision if interactive.
1540 for LASTTRACK in $TRACKQUEUE; do :; done
1541 ALBUMFILE="$(mungefilename "$DALBUM")"
1542 ARTISTFILE="$(mungefilename "$DARTIST")"
1543 GENRE="$(mungegenre "$GENRE")"
1544 YEAR=${CDYEAR:-$CDYEAR}
1545 if [ "$VARIOUSARTISTS" = "y" ] ; then
1546 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1548 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1550 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1551 mkdir -p "$FINALPLAYLISTDIR"
1552 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1553 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1554 if [ "$INTERACTIVE" = "y" ]; then
1555 while [ "$DONE" != "y" ]; do
1557 case $ERASEPLAYLIST in
1558 e|E|a|A|k|K) DONE=y ;;
1559 "") ERASEPLAYLIST=e ; DONE=y ;;
1567 # Once we erase the playlist, we use append to create the new one.
1568 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1570 # The playlist does not exist, so we can safelly use append to create the new list
1573 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1574 touch "$OUTPUTDIR/$PLAYLISTFILE"
1575 for UTRACKNUM in $TRACKQUEUE
1577 # Shares some code with do_move since the filenames have to match
1578 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1579 getcddbinfo TRACKNAME
1581 TRACKFILE="$(mungefilename "$TRACKNAME")"
1582 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1583 ALBUMFILE="$(mungefilename "$DALBUM")"
1584 # If we want to start the tracks with a given number, we need to modify the
1585 # TRACKNUM value before evaluation
1587 if [ "$VARIOUSARTISTS" = "y" ]; then
1588 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1590 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1592 if [ "$VARIOUSARTISTS" = "y" ]; then
1593 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1594 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1596 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1599 if [ "$PLAYLISTDATAPREFIX" ]; then
1600 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1602 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1607 ## this will convert the playlist to have CRLF line-endings, if specified
1608 ## (some hardware players insist on CRLF endings)
1609 if [ "$DOSPLAYLIST" = "y" ]; then
1610 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1611 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1612 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1614 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1619 # This function reads a cuefile on stdin and writes an extended
1620 # cddb query on stdout. Any PREGAP for track 1 is properly
1621 # handled, although cue files embedded in FLAC files do not
1622 # appear to properly store the PREGAP setting. :(
1623 abcde.cue2discid () {
1628 while [ $val -gt 0 ] ; do
1629 ret=$(( $ret + ( $val % 10) ))
1630 val=$(( $val / 10 ))
1640 local first second third
1641 first=$(expr ${1} + 0 )
1642 second=$(expr ${2} + 0 )
1643 third=$(expr ${3} + 0 )
1645 echo $(( ((($first * 60) + $second) * 75) + $third ))
1655 while read line ; do
1658 TRACK) i=$(( i + 1 ))
1660 INDEX) if [ "$2" -eq 1 ] ; then
1662 START=$(( $LBA + $PREGAP + $OFFSET ))
1664 X=$(cddb_sum $(( $START / 75 )) )
1668 PREGAP) PREGAP=$(msf2lba $2)
1672 LEADOUT=$(( $4 / 588 ))
1675 LEADIN=$(( $3 / 588 ))
1684 LEADOUT=$(( $LEADOUT + $LEADIN ))
1686 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1687 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1688 printf "%08x %i" $DISCID $TRACKS
1691 while [ $j -le $TRACKS ] ; do
1692 eval echo -n "\" \$TRACK$j\""
1695 echo " $(( $LEADOUT / 75 ))"
1699 # abcde.mkcue [--wholedisk]
1700 # This creates a cuefile directly from the extended discid information
1701 # The --wholedisk option controls whether we're ripping data from the
1702 # start of track one or from the start of the disk (usually, but not
1703 # always the same thing!)
1705 # Track one leadin/pregap (if any) handeling:
1706 # --wholedisk specified:
1709 # INDEX 01 <pregap value>
1710 # Remaining track index values unchanged from disc TOC
1712 # --wholedisk not specified
1714 # PREGAP <pregap value>
1716 # Remaining track index values offset by <pregap value>
1723 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1726 local MODE DISCID TRACKS
1730 if [ "$1" = --wholedisc ] ; then
1736 vecho "One track is $ONETRACK"
1737 TRACKFILE="$(mungefilename "$TRACKNAME")"
1738 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1739 ALBUMFILE="$(mungefilename "$DALBUM")"
1740 if [ "$ONETRACK" = "y" ]; then
1741 if [ "$VARIOUSARTISTS" = "y" ]; then
1742 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1744 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1746 vecho "Cue wav file is $CUEWAVFILE"
1748 CUEWAVFILE="dummy.wav"
1757 echo REM DISCID $DISCID
1758 echo FILE \""$CUEWAVFILE"\" WAVE
1760 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1767 while [ $i -le "$TRACKS" ] ; do
1768 LBA=$(( $1 - $OFFSET ))
1769 printf " TRACK %02i AUDIO\n" $i
1770 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1771 if [ $MODE = PREGAP ] ; then
1772 echomsf " PREGAP " $(($OFFSET-150))
1774 echo " INDEX 00 00:00:00"
1777 echomsf " INDEX 01 " $LBA
1784 # This essentially the start of things
1787 # Query the CD to get the track info, unless the user specified -C
1788 # or we are using some actions which do not need the CDDB data at all
1789 #if [ ! X"$EXPACTIONS" = "X" ]; then
1791 #elif [ -z "$DISCID" ]; then
1792 if [ -z "$DISCID" ]; then
1793 vecho -n "Getting CD track info... "
1794 # In OSX, unmount the disc before a query
1795 if [ "$OSFLAVOUR" = "OSX" ]; then
1796 diskutil unmount ${CDROM#/dev/}
1798 case "$CDROMREADERSYNTAX" in
1800 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1801 case "$CUE2DISCID" in
1802 # FIXME # right now we have 2 cue2discid internal
1803 # implementations: builtin and abcde.cue2discid. Test
1804 # both of them and decide which one we want to use.
1806 #vecho "Using builtin cue2discid implementation..."
1807 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1809 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1811 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1812 TRACKS=${#OFFSETTIMES[@]}
1814 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1815 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1816 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1817 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1820 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1821 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1825 #vecho "Using external python cue2discid implementation..."
1826 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1830 log error "the input flac file does not contain a cuesheet."
1835 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1837 # if [ ! "$RET" = "0" ];then
1838 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1841 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1842 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1844 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1845 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1849 case "$CDDBMETHOD" in
1850 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1851 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1855 # Make sure there's a CD in there by checking cd-discid's return code
1856 if [ ! "$?" = "0" ]; then
1857 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1858 log error "cuesheet information from the flac file could not be read."
1859 log error "Perhaps the flac file does not contain a cuesheet?."
1862 log error "CD could not be read. Perhaps there's no CD in the drive?"
1866 # In OSX, remount the disc again
1867 if [ "$OSFLAVOUR" = "OSX" ]; then
1868 diskutil mount ${CDROM#/dev/}
1871 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1873 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1876 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1877 # This needs to be done now because a section of the resuming code will need
1880 # get the number of digits to pad TRACKNUM with - we'll use this later
1881 # a CD can only hold 99 tracks, but since we support a feature for starting
1882 # numbering the tracks from a given number, we might need to set it as a
1883 # variable for the user to define... or obtain it somehow.
1884 if [ "$PADTRACKS" = "y" ] ; then
1888 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1889 if [ -z "$TRACKQUEUE" ]; then
1890 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1891 case "$CDROMREADERSYNTAX" in
1893 if [ "$WEHAVEACD" = "y" ]; then
1894 vecho "Querying the CD for audio tracks..."
1895 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1897 if [ ! "$RET" = "0" ];then
1898 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1900 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1901 CDPARANOIAAUDIOTRACKS="$TRACKS"
1903 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1904 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1905 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1906 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1908 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1909 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1913 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1916 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1918 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1919 log info "The disc does not contain any tracks. Giving up..."
1922 echo -n "Grabbing entire CD - tracks: "
1923 if [ ! "$PADTRACKS" = "y" ] ; then
1924 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1926 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1928 while [ "$X" -ne "$TRACKS" ]
1930 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1931 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1935 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1936 # User-supplied track queue.
1937 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1938 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1939 # Once cleaned, obtain the highest value in the trackqueue for number padding
1940 for LASTTRACK in $TRACKQUEUE; do :; done
1941 if [ ! "$PADTRACKS" = "y" ] ; then
1942 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1944 # Now we normalize the trackqueue
1945 for TRACK in $TRACKQUEUE ; do
1946 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1947 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1949 TRACKQUEUE=$PADTRACKQUEUE
1950 echo Grabbing tracks: "$TRACKQUEUE"
1953 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1955 # We have the discid, create a temp directory after it to store all the temp
1958 if [ -e "$ABCDETEMPDIR" ]; then
1959 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1960 # It already exists, see if it's a directory
1961 if [ ! -d "$ABCDETEMPDIR" ]; then
1962 # This is a file/socket/fifo/device/etc, not a directory
1965 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1966 echo "Please investigate, remove it, and rerun abcde." >&2
1970 # It's a directory, let's see if it's writable by us
1971 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
1972 # Nope, complain and exit
1974 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
1975 echo "Please investigate, remove it, and rerun abcde." >&2
1979 # See if it's populated
1980 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1981 # Wipe and start fresh
1982 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1983 echo -n "this directory to continue. Continue [y/N]? " >&2
1984 if [ "$INTERACTIVE" = "y" ]; then
1990 if [ "$ANSWER" != "y" ]; then
1993 rm -rf "$ABCDETEMPDIR" || exit 1
1994 mkdir -p "$ABCDETEMPDIR"
1995 if [ "$?" -gt "0" ]; then
1996 # Directory already exists or could not be created
1997 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2001 # Everything is fine. Check for ^encodetracklocation-
2002 # and encode-output entries in the status file and
2003 # remove them. These are not relevant across sessions.
2004 if [ -f "$ABCDETEMPDIR/status" ]; then
2005 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2006 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2007 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2009 # Remove old error messages
2010 if [ -f "$ABCDETEMPDIR/errors" ]; then
2011 rm -f "$ABCDETEMPDIR/errors"
2015 # We are starting from scratch
2016 mkdir -p "$ABCDETEMPDIR"
2017 if [ "$?" -gt "0" ]; then
2018 # Directory already exists or could not be created
2019 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2022 cat /dev/null > "$ABCDETEMPDIR/status"
2023 # Store the abcde version in the status file.
2024 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2026 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2027 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2028 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2029 vecho "Creating cue file..."
2030 case $CDROMREADERSYNTAX in
2032 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2033 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2035 log warning "the input flac file does not contain a cuesheet."
2039 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2040 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2042 log warning "reading the CUE sheet is still considered experimental"
2043 log warning "and there was a problem with the CD reading. abcde will continue,"
2044 log warning "but consider reporting the problem to the abcde author"
2050 # If we got the CDPARANOIA status and it is not recorded, save it now
2051 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2052 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2053 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2057 # Create the discid file
2058 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2059 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2060 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2065 # Create a proper CUE file based on the CUE file we created before.
2068 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2069 CUEFILE_OUT=$CUEFILE_IN.out
2070 ### FIXME ### checkstatus cddb
2071 if [ -e "$CDDBDATA" ]; then
2072 vecho "Adding metadata to the cue file..."
2073 # FIXME It doesn't preserve spaces! Why?
2074 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2076 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2077 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2078 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2082 cat "$CUEFILE_IN" | while read line
2084 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2085 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2086 # echo "$line" >> "$CUEFILE_OUT"
2087 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2088 eval track="\$TRACK$n"
2090 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2091 # When making a single-track rip, put the
2092 # actual file name into the file declaration
2093 # in the cue file so that it is usable by
2094 # music players and the like
2095 elif [ "$ONETRACK" = "y" ] &&
2096 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2098 TRACKFILE="$(mungefilename "$TRACKNAME")"
2099 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2100 ALBUMFILE="$(mungefilename "$DALBUM")"
2102 if [ "$VARIOUSARTISTS" = "y" ]; then
2103 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2105 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2108 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2111 # FIXME # If the lines above are uncommented, remove the line below.
2112 echo "$line" >> "$CUEFILE_OUT"
2115 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2116 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2122 # Parses a CDDB file and outputs the title and the track names.
2123 # Variables: CDDBFILE
2127 # List out disc title/author and contents
2128 if [ "$ONETRACK" = "y" ]; then
2129 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2131 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2132 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2133 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2134 if [ ! X"$PARSEDYEAR" = "X" ]; then
2135 echo "Year: $PARSEDYEAR"
2138 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2139 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2140 if [ ! X"$PARSEDGENRE" = "X" ]; then
2141 echo "Genre: $PARSEDGENRE"
2144 if [ ! "$ONETRACK" = "y" ]; then
2145 for TRACK in $(f_seq_row 1 $TRACKS)
2147 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2153 # Check for a local CDDB file, and report success
2156 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2158 CDDBLOCALSTATUS="notfound"
2159 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2162 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2163 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2164 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2165 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2166 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2167 CDDBLOCALMATCH=single
2168 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2169 CDDBLOCALMATCH=multiple
2174 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2175 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2176 CDDBLOCALMATCH=single
2181 # If the user has selected to check a local CDDB repo, we proceed with it
2182 case $CDDBLOCALMATCH in
2184 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2186 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2188 # List out disc title/author and contents
2189 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2190 cat "$RESULT" > "${CDDBLOCALREAD}"
2193 do_cddbparse "${CDDBLOCALREAD}"
2195 ##FIXME## QUICK HACK !!!!
2196 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2197 } >> "$ABCDETEMPDIR/cddblocalchoices"
2199 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2200 page "$ABCDETEMPDIR/cddblocalchoices"
2202 # It's all going to fit in one page, cat it
2203 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2205 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2206 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2207 CDDBLOCALCHOICENUM=-1
2208 if [ "$INTERACTIVE" = "y" ]; then
2209 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2210 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2211 read CDDBLOCALCHOICE
2212 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2213 # FIXME # Introduce diff's
2214 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2215 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2216 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2217 # Make sure we get a valid choice
2218 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2219 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2220 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2226 #echo "Selected ..."
2228 CDDBLOCALCHOICENUM=1
2230 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2231 #echo "Using local copy of CDDB data"
2232 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2233 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2234 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2235 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2236 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2237 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2238 CDDBLOCALSTATUS="found"
2240 #echo "Not using local copy of CDDB data"
2241 CDDBLOCALSTATUS="notfound"
2245 # List out disc title/author and contents
2246 do_cddbparse "${CDDBLOCALFILE}"
2247 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2248 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2250 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2252 if [ "$INTERACTIVE" = "y" ]; then
2254 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2255 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2258 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2262 if [ "$USELOCALRESP" = "y" ]; then
2263 #echo "Using local copy of CDDB data"
2264 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2265 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2266 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2267 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2268 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2269 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2270 CDDBLOCALSTATUS="single"
2272 #echo "Not using local copy of CDDB data"
2273 CDDBLOCALSTATUS="notfound"
2277 CDDBLOCALSTATUS="notfound"
2284 # Try to read CD-Text from the drive using icedax / cdda2wav
2287 if new_checkexec icedax; then
2288 CDTEXT_READER=icedax
2289 elif new_checkexec cdda2wav; then
2290 CDTEXT_READER=cdda2wav
2292 # Didn't find either, bail
2296 if [ "$OSFLAVOUR" = "OSX" ] ; then
2297 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2298 diskutil unmount ${CDROM#/dev/}
2299 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2300 CDDA2WAVCDROM="IODVDServices"
2301 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2302 CDDA2WAVCDROM="$CDROMID"
2304 if [ "$CDROMID" = "" ]; then
2305 CDDA2WAVCDROM="$CDROM"
2307 CDDA2WAVCDROM="$CDROMID"
2311 # Do we have CD-Text on the disc (and can the drive read it?)
2312 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2313 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2315 if [ $ERRORCODE -ne 0 ]; then
2316 # No CD-Text found, bail
2320 rm -f "$ABCDETEMPDIR/cddbchoices"
2322 # Make an empty template
2323 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2324 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2325 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2326 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2327 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2328 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2329 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2330 # List out disc title/author and contents
2331 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2332 for TRACK in $(f_seq_row 1 $TRACKS)
2334 TRACKM1=$(($TRACK - 1))
2335 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2336 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2337 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2338 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2340 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2341 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2342 echo >> "$ABCDETEMPDIR/cddbchoices"
2343 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2347 # Work with the musicbrainz WS API, then transform the results here so
2348 # they look (very) like the results from CDDB. Maybe not the best way
2349 # to go, but it Works For Me (TM)
2353 if checkstatus musicbrainz-readcomplete; then :; else
2354 vecho "Obtaining Musicbrainz results..."
2355 # If MB is to be used, interpret the query results and read all
2356 # the available entries.
2357 rm -f "$ABCDETEMPDIR/cddbchoices"
2358 CDDBCHOICES=1 # Overridden by multiple matches
2359 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2360 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2362 # The helper script will write disc matches out to
2363 # cddbread.*. Count how many we have
2364 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2365 # No matches. Use the normal cddb template for the user to
2367 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2368 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2369 # List out disc title/author and contents of template
2370 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2372 for TRACK in $(f_seq_row 1 $TRACKS)
2374 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2376 echo >> "$ABCDETEMPDIR/cddbchoices"
2377 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2378 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2379 echo 503 > "$ABCDETEMPDIR/cddbquery"
2381 # We have some matches
2382 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2383 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2385 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2386 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2387 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2388 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2389 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2390 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2391 # List out disc title/author and contents
2392 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2393 for TRACK in $(f_seq_row 1 $TRACKS)
2395 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2397 echo >> "$ABCDETEMPDIR/cddbchoices"
2399 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2400 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2401 for file in "$ABCDETEMPDIR"/cddbread.*
2403 X=$(echo $file | sed 's/^.*cddbread\.//g')
2404 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2405 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2406 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2407 # List out disc title/author and contents
2408 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2409 for TRACK in $(f_seq_row 1 $TRACKS)
2411 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2413 echo >> "$ABCDETEMPDIR/cddbchoices"
2415 echo "." >> "$ABCDETEMPDIR/cddbquery"
2418 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2425 # Perform CDDB protocol version check if it hasn't already been done
2426 if checkstatus cddb-statcomplete; then :; else
2427 if [ "$CDDBAVAIL" = "n" ]; then
2429 echo 503 > "$ABCDETEMPDIR/cddbstat"
2432 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2433 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2434 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2435 vecho "Checking CDDB server status..."
2436 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2437 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2438 case "$RESPONSECODE" in
2439 210) # 210 OK, status information follows (until terminating `.')
2442 501) # 501 Illegal CDDB protocol level: <n>.
2443 CDDBPROTO=`expr $CDDBPROTO - 1`
2445 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2446 # FreeDB TESTCD disc-id is used for query
2447 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2448 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2449 case "$RESPONSECODE" in
2450 2??) # Server responded, everything seems OK
2460 if test $rc -eq 1; then
2464 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2472 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2473 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2475 # Perform CDDB query if it hasn't already been done
2476 if checkstatus cddb-querycomplete; then :; else
2477 if [ "$CDDBAVAIL" = "n" ]; then
2479 echo 503 > "$ABCDETEMPDIR/cddbquery"
2480 # The default CDDBLOCALSTATUS is "notfound"
2481 # This part will be triggered if the user CDDB repo does not
2482 # contain the entry, or if we are not trying to use the repo.
2484 vecho "Querying the CDDB server..."
2485 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2486 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2487 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2493 # no match found in database,
2494 # wget/fetch error, or user requested not to use CDDB
2495 # Make up an error code (503) that abcde
2496 # will recognize in do_cddbread
2497 # and compensate by making a template
2498 echo 503 > "$ABCDETEMPDIR/cddbquery"
2500 *) # strange and unknown error
2501 echo ERRORCODE=$ERRORCODE
2502 echo "abcde: $CDDBTOOL returned unknown error code"
2506 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2513 # If it's not to be used, generate a template.
2514 # Then, display it (or them) and let the user choose/edit it
2515 if checkstatus cddb-readcomplete; then :; else
2516 vecho "Obtaining CDDB results..."
2517 # If CDDB is to be used, interpret the query results and read all
2518 # the available entries.
2519 rm -f "$ABCDETEMPDIR/cddbchoices"
2520 CDDBCHOICES=1 # Overridden by multiple matches
2521 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2522 case "$RESPONSECODE" in
2524 # One exact match, retrieve it
2525 # 200 [section] [discid] [artist] / [title]
2526 if checkstatus cddb-read-1-complete; then :; else
2527 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2528 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2529 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2530 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2531 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2533 # List out disc title/author and contents
2534 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2535 for TRACK in $(f_seq_row 1 $TRACKS)
2537 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2539 echo >> "$ABCDETEMPDIR/cddbchoices"
2543 case "$RESPONSECODE" in
2544 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2545 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2546 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2548 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2549 # List out disc title/author and contents of template
2550 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2552 for TRACK in $(f_seq_row 1 $TRACKS)
2554 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2556 echo >> "$ABCDETEMPDIR/cddbchoices"
2557 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2558 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2561 # Multiple exact, (possibly multiple) inexact matches
2563 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2564 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2565 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2566 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2567 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2569 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2571 vecho -n "Retrieving multiple matches... "
2572 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2573 read DISCINFO # eat top line
2577 if checkstatus cddb-read-$X-complete; then :; else
2578 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2579 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2581 # List out disc title/author and contents
2582 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2583 for TRACK in $(f_seq_row 1 $TRACKS)
2585 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2587 echo >> "$ABCDETEMPDIR/cddbchoices"
2590 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2594 for TRACK in $(f_seq_row 1 $TRACKS)
2596 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2598 echo >> "$ABCDETEMPDIR/cddbchoices"
2599 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2600 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2603 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2610 if checkstatus cddb-edit >/dev/null; then
2611 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2612 VARIOUSARTISTS="$(checkstatus variousartists)"
2613 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2616 if [ "$INTERACTIVE" = "y" ]; then
2617 # We should show the CDDB results both when we are not using the local CDDB repo
2618 # or when we are using it but we could not find a proper match
2619 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2620 # Display the $ABCDETEMPDIR/cddbchoices file created above
2621 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2622 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2623 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2624 CHOICE=$(checkstatus cddb-choice)
2625 if [ -n "$CHOICE" ] ; then
2626 case $CDDBCHOICES in
2627 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2628 log error "CDDB query failed!"
2631 cat "$ABCDETEMPDIR/cddbchoices"
2634 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2636 echo "Selected: #$CHOICE"
2637 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2641 # The user has a choice to make, display the info in a pager if necessary
2642 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2643 page "$ABCDETEMPDIR/cddbchoices"
2645 # It's all going to fit in one page, cat it
2646 cat "$ABCDETEMPDIR/cddbchoices" >&2
2650 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2652 # I'll take CDDB read #3 for $400, Alex
2653 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2654 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2656 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2657 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2658 if [ ! X"$DIFF" = "X" ]; then
2659 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2660 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2661 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2662 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2663 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2664 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2666 # We parse the 2 choices to diff, store them in temporary files and diff them.
2667 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2668 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2670 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2671 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2672 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2673 page "$ABCDETEMPDIR/cddbread.diff"
2675 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2679 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2681 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2682 # Make sure we get a valid choice
2683 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2684 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2685 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2689 if [ "$CDCHOICENUM" = "0" ]; then
2690 vecho "Creating empty CDDB template..."
2692 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2694 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2695 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2697 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2701 # We need some code to show the selected option when local repository is selected and we have found a match
2702 vecho "Using cached CDDB match..." >&2
2703 # Display the $ABCDETEMPDIR/cddbchoices file created above
2704 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2705 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2706 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2707 CHOICE=$(checkstatus cddb-choice)
2708 if [ "$USELOCALRESP" = "y" ]; then :; else
2709 if [ -n "$CHOICE" ] ; then
2710 case $CDDBCHOICES in
2713 echo "Selected template."
2715 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2717 echo "Selected: #$CHOICE"
2718 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2726 # We're noninteractive - pick the first choice.
2727 # But in case we run a previous instance and selected a choice, use it.
2728 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2729 # Show the choice if we are not using the locally stored one
2730 # or when the local search failed to find a match.
2731 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2732 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2733 #if [ "$PREVIOUSCHOICE" ]; then
2734 cat "$ABCDETEMPDIR/cddbchoices"
2737 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2738 CDCHOICENUM=$PREVIOUSCHOICE
2741 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2743 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2748 if checkstatus cddb-choice >/dev/null; then :; else
2749 echo "abcde: internal error: cddb-choice not recorded." >&2
2752 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2753 echo -n "Edit selected CDDB data? [y/n] (" >&2
2754 if [ "$INTERACTIVE" = "y" ]; then
2755 if [ "$UNKNOWNDISK" = "y" ]; then
2758 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2767 if [ "$EDITCDDB" = "y" ]; then
2768 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2770 # Use the debian sensible-editor wrapper to pick the editor that the
2771 # user has requested via their $EDITOR environment variable
2772 if [ -x "/usr/bin/sensible-editor" ]; then
2773 /usr/bin/sensible-editor "$CDDBDATA"
2774 elif [ -n "$EDITOR" ]; then
2775 if [ -x $(which "${EDITOR%%\ *}") ]; then
2776 # That failed, try to load the preferred editor, starting
2777 # with their EDITOR variable
2778 eval $(echo "$EDITOR") \"$CDDBDATA\"
2780 # If that fails, check for a vi
2781 elif which vi >/dev/null 2>&1; then
2783 elif [ -x /usr/bin/vim ]; then
2784 /usr/bin/vim "$CDDBDATA"
2785 elif [ -x /usr/bin/vi ]; then
2786 /usr/bin/vi "$CDDBDATA"
2787 elif [ -x /bin/vi ]; then
2789 # nano should be on all (modern, i.e., sarge) debian systems
2790 elif which nano >/dev/null 2>&1 ; then
2792 elif [ -x /usr/bin/nano ]; then
2793 /usr/bin/nano "$CDDBDATA"
2794 # mg should be on all OpenBSD systems
2795 elif which mg >/dev/null 2>&1 ; then
2797 elif [ -x /usr/bin/mg ]; then
2798 /usr/bin/mg "$CDDBDATA"
2801 log warning "no editor available. Check your EDITOR environment variable."
2803 # delete editor backup file if it exists
2804 if [ -w "$CDDBDATA~" ]; then
2809 # Some heuristics first. Look at Disc Title, and if it starts with
2810 # "Various", then we'll assume Various Artists
2811 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2812 echo "Looks like a Multi-Artist CD" >&2
2815 echo -n "Is the CD multi-artist [y/N]? " >&2
2816 if [ "$INTERACTIVE" = "y" ]; then
2823 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2826 # Need NUMTRACKS before cddb-tool will return it:
2827 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2828 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2829 # More than 1/2 tracks contain a "/", so guess forward
2831 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2832 # More than 1/2 contain a "-", so guess forward-dash
2834 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2835 # More than 1/2 contain something in parens, so guess trailing-paren
2839 echo "1) Artist / Title" >&2
2840 echo "2) Artist - Title" >&2
2841 echo "3) Title / Artist" >&2
2842 echo "4) Title - Artist" >&2
2843 echo "5) Artist: Title" >&2
2844 echo "6) Title (Artist)" >&2
2845 echo "7) This is a single-artist CD" >&2
2846 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2847 if [ "$INTERACTIVE" = "y" ]; then
2848 read VARIOUSARTISTSTYLE
2850 echo $DEFAULTSTYLE >&2
2851 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2853 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2854 # If they press Enter, then the default style (0) was chosen
2855 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2856 echo "Invalid selection. Please choose a number between 1 and 7."
2857 echo -n "Selection [1-7]: "
2858 read VARIOUSARTISTSTYLE
2859 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2861 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2862 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2864 vecho "Selected: $VARIOUSARTISTSTYLE"
2865 case "$VARIOUSARTISTSTYLE" in
2867 VARIOUSARTISTSTYLE=forward
2870 VARIOUSARTISTSTYLE=forward-dash
2873 VARIOUSARTISTSTYLE=reverse
2876 VARIOUSARTISTSTYLE=reverse-dash
2879 VARIOUSARTISTSTYLE=colon
2882 VARIOUSARTISTSTYLE=trailing-paren
2890 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2891 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2893 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2894 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2895 # This works but does not have the necessary error checking
2896 # yet. If you are familiar with the CDDB spec
2897 # (see http://www.freedb.org/src/latest/DBFORMAT)
2898 # and can create an error-free entry on your own, then put
2899 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2900 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2901 # your abcde.conf to change the email address submissions are
2904 # submit the modified file, if they want
2905 if [ "$NOSUBMIT" != "y" ]; then
2906 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2908 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2909 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2911 echo -n 'Invalid selection. Please answer "y" or "n": '
2914 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2915 echo -n "Sending..."
2916 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2923 # User CDDBLOCALPOLICY to find out if we store the file or not...
2924 # Cache edited CDDB entry in the user's cddb dir
2925 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2926 # Make sure the cache directory exists
2927 mkdir -p $CDDBLOCALDIR
2928 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2931 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2934 # do_cdread [tracknumber]
2935 # do_cdread onetrack [firsttrack] [lasttrack]
2939 # The commands here don't go through run_command because they're never supposed to be silenced
2940 # return codes need to be doublechecked anyway, however
2941 if [ "$1" = "onetrack" ]; then
2942 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2943 # FIXME # Until then, we grab the whole CD in one track, no matter what
2945 # We need the first and last track for cdda2wav/icedax
2947 LASTTRACK=$(expr $3 + 0)
2948 UTRACKNUM=$FIRSTTRACK
2949 case "$CDROMREADERSYNTAX" in
2950 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2953 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
2954 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2955 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
2956 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
2957 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2963 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2964 if [ "$USEPIPES" = "y" ]; then
2965 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
2966 FILEARG="$( eval echo "\$$TEMPARG" )"
2968 PIPE_MESSAGE="and encoding "
2970 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2971 case "$CDROMREADERSYNTAX" in
2972 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2974 FILEARG="--output-name=$WAVDATA"
2977 FILEARG="-f $WAVDATA"
2985 if [ "$1" = "onetrack" ]; then
2986 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2988 if [ -r "$CDDBDATA" ]; then
2989 getcddbinfo TRACKNAME
2990 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2992 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2995 case "$CDROMREADERSYNTAX" in
2996 ### FIXME ### use an exception for flac, since it uses -o
2997 ### FIXME ### Shall we just use -o $FILEARG ??
2999 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
3000 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3001 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3003 if [ "$REDIR" = "y" ]; then
3004 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3006 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3010 if [ "$OSFLAVOUR" = "OSX" ] ; then
3011 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3012 diskutil unmount ${CDROM#/dev/}
3013 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3014 CDDA2WAVCDROM="IODVDServices"
3015 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3016 CDDA2WAVCDROM="$CDROMID"
3018 if [ "$CDROMID" = "" ]; then
3019 CDDA2WAVCDROM="$CDROM"