2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # This code is hereby licensed for public consumption under either the
5 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
7 # You should have received a copy of the GNU General Public License along
8 # with this program; if not, write to the Free Software Foundation, Inc.,
9 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
16 VERSION='2.5.3-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"
29 #echo "-B Disable batch replaygain (do file by file)"
31 echo " Specify a configuration file (overrides system and user config files)"
33 echo " Specify discid to resume from (only needed if you no longer have the cd)"
35 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
36 echo "-D Debugging mode (equivalent to sh -x abcde)"
37 echo "-e Erase encoded track information from status file"
38 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
39 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
40 echo "-h This help information"
41 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
42 echo "-j <#> Number of encoder processes to run at once (localhost)"
43 echo "-k Keep the wav tracks for later use"
44 echo "-l Use low disk space algorithm"
45 echo "-L Use local CDDB storage directory"
46 echo "-m Modify playlist to include CRLF endings, to comply with some players"
47 #echo " WARNING: Deprecated. Use \"cue\" action"
48 #echo "-M Create a CUE file"
49 echo "-n No lookup. Don't query CDDB, just create and use template"
50 echo "-N Noninteractive. Never prompt for anything"
51 echo "-o <type1[,type2]...>"
52 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
53 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
54 echo "-P Use UNIX pipes to read+encode without wav files"
56 echo " Set quality level (high,medium,low)"
57 echo "-r <host1[,host2]...>"
58 echo " Also encode on these remote hosts"
60 echo " Show fields from the CDDB info (year,genre)"
61 echo "-S <#> Set the CD speed"
62 echo "-t <#> Start the track numbering at a given number"
63 echo "-T <#> Same as -t but modifies tag numbering"
64 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
65 echo "-v Show version number and exit"
66 echo "-V Be a bit more verbose about what is happening behind the scenes"
67 echo "-x Eject CD after all tracks are read"
69 echo " Add a comment to the CD tracks"
70 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
71 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
73 echo "Tracks is a space-delimited list of tracks to grab."
74 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
76 #echo "Double hyphens are used to concatenate tracks"
81 echo "$@" >> "$ABCDETEMPDIR/status"
84 # log [level] [message]
86 # log outputs the right message in a common format
92 error) echo "[ERROR] abcde: $@" >&2 ;;
93 warning) echo "[WARNING] $@" >&2 ;;
94 info) echo "[INFO] $@" ;;
98 # Functions to replace the need of seq, which is too distribution dependent.
102 while [ $i -ne `expr $2 + 1` ]
112 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
113 while [ $i -ne `expr $2 + 1` ]
120 log error "syntax error while processing track numbers ($i)"
125 # Functions to replace the need of awk {print $1} and {print $NF}
128 if [ X"$1" = "X" ]; then
129 for first in `cat`; do
140 if [ X"$1" = "X" ]; then
141 for stdin in `cat`; do
145 for last in $@ ; do :; done
150 # checkstatus [blurb]
151 # Returns "0" if the blurb was found, returns 1 if it wasn't
152 # Puts the blurb content, if available, on stdout.
153 # Otherwise, returns "".
156 # Take the last line in the status file if there's multiple matches
158 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
160 if [ -z "$BLURB" ]; then
165 # See if there's a = in it
166 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
167 echo "$(echo $BLURB | cut -f2- -d=)"
173 # checkwarnings [blurb]
174 # Returns "0" if the blurb was found (meaning there was an warning),
175 # returns 1 if it wasn't (yes this is a little backwards).
176 # Does not print the blurb on stdout.
177 # Otherwise, returns "".
180 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
183 # Take the last line in the status file if there's multiple matches
185 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
187 if [ -z "$BLURB" ]; then
188 # negative, we did not have a negative...
191 # affirmative, we had a negative...
196 # checkerrors [blurb]
197 # Returns "0" if the blurb was found (meaning there was an error),
198 # returns 1 if it wasn't (yes this is a little backwards).
199 # Does not print the blurb on stdout.
200 # Otherwise, returns "".
203 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
206 # Take the last line in the status file if there's multiple matches
208 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
210 if [ -z "$BLURB" ]; then
211 # negative, we did not have a negative...
214 # affirmative, we had a negative...
220 # Finds the right pager in the system to display a file
224 # Use the debian sensible-pager wrapper to pick the pager
225 # user has requested via their $PAGER environment variable
226 if [ -x "/usr/bin/sensible-pager" ]; then
227 /usr/bin/sensible-pager "$PAGEFILE"
228 elif [ -x "$PAGER" ]; then
229 # That failed, try to load the preferred editor, starting
230 # with their PAGER variable
232 # If that fails, check for less
233 elif [ -x /usr/bin/less ]; then
234 /usr/bin/less -f "$PAGEFILE"
235 # more should be on all UNIX systems
236 elif [ -x /bin/more ]; then
237 /bin/more "$PAGEFILE"
239 # No bananas, just cat the thing
244 # run_command [blurb] [command...]
245 # Runs a command, silently if necessary, and updates the status file
251 # See if this is supposed to be silent
252 if [ "$(checkstatus encode-output)" = "loud" ]; then
256 # Special case for SMP, since
257 # encoder output is never displayed, don't mute echos
258 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
267 normalize|normalize-audio)
268 if [ "$RETURN" = "2" ]; then
269 # File was already normalized.
274 if [ "$RETURN" != "0" ]; then
275 # Put an error in the errors file. For various reasons we
276 # can't capture a copy of the program's output but we can
277 # log what we attempted to execute and the error code
278 # returned by the program.
279 if [ "$BLURB" ]; then
282 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
283 return $RETURN # Do not pass go, do not update the status file
285 if [ "$BLURB" ]; then
286 echo $BLURB >> "$ABCDETEMPDIR/status"
290 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
291 # distributed under the terms of the GNU GPL v2 or later, at your option
293 # Function to determine if a word contains a slash.
302 # Function to give the relative path from one file to another.
303 # Usage: relpath fromfile tofile
304 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
305 # (the result would be Album/Song.mp3)
306 # Output is relative path to $2 from $1 on stdout
308 # This code has the following restrictions:
309 # Multiple ////s are not collapsed into single /s, with strange effects.
310 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
311 # If FR is a directory it must have a trailing /
319 /*) ;; # No processing is needed for absolute paths
321 # Loop through common prefixes, ignoring them.
322 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
324 FR="$(echo "$FR" | cut -d/ -f2-)"
325 TO="$(echo "$TO" | cut -d/ -f2-)"
327 # Loop through directory portions left in FR, adding appropriate ../s.
330 FR="$(echo "$FR" | cut -d/ -f2-)"
341 if [ ! "$@" = "" ]; then
342 # Cut off any command-line option we added in
343 X=$(echo $@ | cut -d' ' -f2)
344 if [ "$(which $X)" = "" ]; then
346 elif [ ! -x $(which $X) ]; then
355 if [ ! "$@" = "" ]; then
356 # Cut off any command-line option we added in
357 X=$(echo $@ | cut -d' ' -f2)
358 # Test for built-in abcde.function
359 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
360 if [ "$(which $X)" = "" ]; then
361 log error "$X is not in your path." >&2
362 log info "Define the full path to the executable if it exists on your system." >&2
363 if [ -e /etc/debian_release ] ; then
365 oggenc) MISSING_PACKAGE=vorbis-tools ;;
366 lame|flac) MISSING_PACKAGE=$X ;;
368 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
371 elif [ ! -x "$(which $X)" ]; then
372 log error "$X is not executable." >&2
378 # diffentries <filename> <max_value> <entry1>,<entry2>
379 # max_value: the range of entries goes from 1 to <max_value>
384 local CDDBDIFFCHOICES=$1
386 local CDDBDIFFCHOICE="$@"
387 if [ ! X"$DIFF" = "X" ]; then
388 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
389 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
390 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
391 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
392 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
393 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
395 # We parse the 2 choices to diff, store them in temporary files and diff them.
396 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
397 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
399 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
400 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
401 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
402 page "$ABCDETEMPDIR/$FILENAME.diff"
404 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
408 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
413 # Finds an specific field from cddbinfo
418 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
421 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
424 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
430 # Get the track number we are going to use for different actions
433 if [ -n "$STARTTRACKNUMBER" ] ; then
434 # Get the trackpadding from the current track
435 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
436 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
438 TRACKNUM=${UTRACKNUM}
444 # Calculate cddb disc ids without requiring specialized helper programs.
445 # largely copied from cd-discid and musicbrainz examples. some of the steps
446 # don't make sense, but they're necessary to match the ids generated by other
449 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
450 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
451 # 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
452 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
453 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
454 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
456 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
459 if [ X"$LEADOUT" = "X" ]; then
460 log warning "Error trying to calculate disc ids without lead-out information."
464 # default to a two second lead-in
466 LEADIN=${LEADIN:=150}
468 # number of cdframes per second
471 # reset cddb checksum for cddb disc-id calululation
475 for OFFSET in $(echo $OFFSETS)
477 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
479 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
480 while [ $OFFSETTIME -gt 0 ]; do
481 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
482 OFFSETTIME=$(($OFFSETTIME / 10))
487 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
489 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
490 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
492 case "$CDDBMETHOD" in
494 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
497 # FIXME: don't assume the first track is 1
498 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
499 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
503 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
508 if checkstatus replaygain; then :; else
509 run_command "" echo "Adding replaygain information..."
510 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
514 OUTPUT=$OGGOUTPUTCONTAINER
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, ATOMICPARSLEY
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
825 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
826 --comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
827 -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
828 -G "$GENREID" -n "${TRACKNUM:-$1}" \
829 "${TRACKNUM:+-N $TRACKS}" \
830 "${ENCODING:+--set-encoding=$ENCODING}" \
831 "${TPE2:+--set-user-text-frame=TPE2:$TPE2}" \
832 "$ABCDETEMPDIR/track$1.$OUTPUT"
834 # FIXME # Still not activated...
836 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
837 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
838 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" \
839 -y "$CDYEAR" -g "$GENREID" -k "${TRACKNUM:-$1}" \
840 "$ABCDETEMPDIR/track$1.$OUTPUT"
843 # FIXME # track numbers in mp3 come with 1/10, so we cannot
844 # happily substitute them with $TRACKNUM
845 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
846 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
847 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
848 -y "$CDYEAR" -g "$GENREID" \
849 -T "${TRACKNUM:-$1}/$TRACKS" \
850 ${TPE2:+--TPE2 "$TPE2"} \
851 "$ABCDETEMPDIR/track$1.$OUTPUT"
856 case "$OGGENCODERSYNTAX" in
858 # vorbiscomment can't do in-place modification, mv the file first
859 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
860 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
864 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
866 echo ARTIST="$TRACKARTIST"
868 echo TITLE="$TRACKNAME"
869 if [ -n "$CDYEAR" ]; then
872 if [ -n "$CDGENRE" ]; then
873 echo GENRE="$CDGENRE"
875 echo TRACKNUMBER=${TRACKNUM:-$1}
876 if [ -n "$DISCNUMBER" ]; then
877 echo DISCNUMBER="$DISCNUMBER"
879 echo CDDB=$CDDBDISCID
880 if [ "$(eval echo ${COMMENT})" != "" ]; then
881 case "$COMMENTOUTPUT" in
882 *=*) echo "$COMMENTOUTPUT";;
883 *) echo COMMENT="$COMMENTOUTPUT";;
886 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
887 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
888 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
889 # Doublecheck that the commented file was created
890 # successfully before wiping the original
891 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
892 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
894 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
901 echo ARTIST="$TRACKARTIST"
903 echo TITLE="$TRACKNAME"
904 if [ -n "$CDYEAR" ]; then
907 if [ -n "$CDGENRE" ]; then
908 echo GENRE="$CDGENRE"
910 echo TRACKNUMBER="${TRACKNUM:-$1}"
911 if [ -n "$DISCNUMBER" ]; then
912 echo DISCNUMBER="$DISCNUMBER"
914 echo CDDB="$CDDBDISCID"
915 if [ "$(eval echo ${COMMENT})" != "" ]; then
916 case "$COMMENTOUTPUT" in
917 *=*) echo "$COMMENTOUTPUT";;
918 *) echo COMMENT="$COMMENTOUTPUT";;
921 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
924 run_command tagtrack-$OUTPUT-$1 true
927 run_command tagtrack-$OUTPUT-$1 true
930 # Use a temp-file of our choice. --overWrite seems to
931 # case core dumps with AtomicParsley 0.9.0
932 ATOMICTEMPFILE="$ABCDETEMPDIR/track$1.m4a-atomic"
935 if [ "$VARIOUSARTISTS" = "y" ]; then
939 #It has to be command file opts for AtomicParsley
940 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
941 if [ -f $ATOMICTEMPFILE ]; then
942 mv "$ATOMICTEMPFILE" "$ABCDETEMPDIR/track$1.m4a"
946 run_command tagtrack-$OUTPUT-$1 true
950 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
951 run_command tagtrack-$1 true
958 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
961 # The commands here don't go through run_command because they're never
962 # supposed to be silenced
963 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
964 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
968 case "$MP3ENCODERSYNTAX" in
973 for UTRACKNUM in $TRACKQUEUE
975 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
977 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
979 if [ "$RETURN" != "0" ]; then
980 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
982 for UTRACKNUM in $TRACKQUEUE
984 run_command encodetrack-$OUTPUT-$UTRACKNUM true
985 #run_command encodetrack-$UTRACKNUM true
994 if checkerrors "nogap-encode"; then :; else
995 if [ ! "$KEEPWAVS" = "y" ] ; then
996 if [ ! "$KEEPWAVS" = "move" ] ; then
1001 # Other encoders fall through to normal encoding as the tracks have not
1002 # been entered in the status file.
1005 # do_encode [tracknumber] [hostname]
1006 # If no hostname is specified, encode locally
1008 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1011 if [ "$USEPIPES" = "y" ]; then
1014 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1017 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1020 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1023 TEMPARG="PIPE_$SPEEXENCODER"
1026 TEMPARG="PIPE_$MPPENCODER"
1029 TEMPARG="PIPE_$AACENCODERSYNTAX"
1032 IN="$( eval echo "\$$TEMPARG" )"
1034 IN="$ABCDETEMPDIR/track$1.wav"
1037 case "$MP3ENCODERSYNTAX" in
1038 # FIXME # check if mp3enc needs -if for pipes
1039 # FIXME # I have not been able to find a working mp3enc binary
1053 # We need IN to proceed, if we are not using pipes.
1054 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1055 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1057 case "$TMPOUTPUT" in
1059 OUTPUT=$OGGOUTPUTCONTAINER
1062 OUTPUT=$FLACOUTPUTCONTAINER
1068 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1069 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1072 if [ X"$USEPIPES" = "Xy" ]; then
1074 # We need a way to store the creation of the files when using PIPES
1075 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1076 # When pipping it does not make sense to have a higher nice for
1077 # reading than for encoding, since it will be hold by the
1078 # encoding process. Setting an effective nice, to calm down a
1079 # bit the reading process.
1080 EFFECTIVE_NICE=$READNICE
1082 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1083 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1084 EFFECTIVE_NICE=$ENCNICE
1090 case "$MP3ENCODERSYNTAX" in
1091 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1092 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1093 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1094 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1095 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1099 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1106 case "$OGGENCODERSYNTAX" in
1107 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1108 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1112 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1119 case "$FLACENCODERSYNTAX" in
1120 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1125 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1126 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1131 if [ "$(eval echo ${COMMENT})" != "" ]; then
1134 *) COMMENT="COMMENT=$COMMENT" ;;
1137 # Tag the file at encode time, as it can't be done after encoding.
1138 if [ "$DOTAG" = "y" ]; then
1139 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1141 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1145 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1147 # I tried compiling the mppenc from corecodecs.org and got some
1148 # errors, so I have not tried it myself.
1149 ## FIXME ## Needs some cleanup to determine if an empty tag sent
1150 ## FIXME ## to the encoder ends up empty.
1151 $RUN_COMMAND nice $EFFECTIVE_NICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
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 $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
1159 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1163 # In case of wav output we need nothing. Just keep the wavs.
1168 # Only remove .wav if the encoding succeeded
1169 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1170 run_command encodetrack-$1 true
1171 if [ ! "$KEEPWAVS" = "y" ] ; then
1172 if [ ! "$KEEPWAVS" = "move" ] ; then
1178 run_command "" echo "HEH! The file we were about to encode disappeared:"
1179 run_command "" echo ">> $IN"
1180 run_command encodetrack-$1 false
1184 # do_preprocess [tracknumber]
1186 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1189 # IN="$ABCDETEMPDIR/track$1.wav"
1190 # # We need IN to proceed.
1191 # if [ -s "$IN" ] ; then
1192 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1194 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1195 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1196 # case "$POSTPROCESSFORMAT" in
1198 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1200 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1202 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1204 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1206 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1209 # # Only remove .wav if the encoding succeeded
1210 # if checkerrors "preprocess-(.{3,4})-$1"; then
1211 # run_command preprocess-$1 false
1213 # run_command preprocess-$1 true
1216 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1217 # echo "HEH! The file we were about to pre-process disappeared:"
1220 # run_command preprocess-$1 false
1225 # do_postprocess [tracknumber]
1227 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1230 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1232 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1233 # # We need IN to proceed.
1234 # if [ -s "$IN" ] ; then
1235 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1236 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1237 # case "$POSTPROCESSFORMAT" in
1239 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1241 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1243 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1245 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1247 # # Only remove .wav if the encoding succeeded
1248 # if checkerrors "postprocess-(.{3,4})-$1"; then
1249 # run_command postprocess-$1 false
1251 # run_command postprocess-$1 true
1254 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1255 # echo "HEH! The file we were about to post-process disappeared:"
1258 # run_command postprocess-$1 false
1273 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1277 # The commands here don't go through run_command because they're never supposed to be silenced
1278 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1283 for UTRACKNUM in $TRACKQUEUE
1285 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1287 # FIXME # Hard-coded batch option!
1288 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1290 if [ "$RETURN" != "0" ]; then
1291 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1293 for UTRACKNUM in $TRACKQUEUE
1295 echo normalizetrack-$UTRACKNUM >> status
1301 # do_batch_normalize
1303 # NORMALIZER, NORMALIZEROPTS
1304 do_batch_normalize ()
1306 # The commands here don't go through run_command because they're never supposed to be silenced
1307 echo "Batch normalizing tracks: $TRACKQUEUE"
1312 for UTRACKNUM in $TRACKQUEUE
1314 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1316 # XXX: Hard-coded batch option!
1317 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1319 if [ "$RETURN" != "0" ]; then
1320 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1322 for UTRACKNUM in $TRACKQUEUE
1324 echo normalizetrack-$UTRACKNUM >> status
1330 # do_normalize [tracknumber]
1332 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1335 IN="$ABCDETEMPDIR/track$1.wav"
1336 if [ -e "$IN" ] ; then
1337 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1338 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1340 if [ "$(checkstatus encode-output)" = "loud" ]; then
1341 echo "HEH! The file we were about to normalize disappeared:"
1344 run_command normalizetrack-$1 false "File $IN was not found"
1348 # do_move [tracknumber]
1349 # Deduces the outfile from environment variables
1350 # Creates directory if necessary
1352 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1355 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1357 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1358 # defined the OUTPUTFILE:
1361 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1362 # Munge filenames as follows:
1367 # Eat control characters
1368 ALBUMFILE="$(mungefilename "$DALBUM")"
1369 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1370 TRACKFILE="$(mungefilename "$TRACKNAME")"
1371 GENRE="$(mungegenre "$GENRE")"
1372 YEAR=${CDYEAR:-$CDYEAR}
1373 # If we want to start the tracks with a given number, we need to modify
1374 # the TRACKNUM value before evaluation
1376 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1377 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1378 if [ "$ONETRACK" = "y" ]; then
1379 if [ "$VARIOUSARTISTS" = "y" ]; then
1380 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1382 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1385 if [ "$VARIOUSARTISTS" = "y" ]; then
1386 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1388 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1391 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1392 # Once we know the specific output was successful, we can change
1393 # the OUTPUT to the value containing the container
1396 OUTPUT=$OGGOUTPUTCONTAINER
1399 OUTPUT=$FLACOUTPUTCONTAINER
1405 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1406 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1409 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1410 # FIXME # introduce warnings?
1413 # mkdir -p shouldn't return an error if the directory already exists
1414 mkdir -p "$OUTPUTFILEDIR"
1415 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1416 if checkstatus movetrack-output-$OUTPUT; then :; else
1417 run_command movetrack-output-$OUTPUT true
1422 # mkdir -p shouldn't return an error if the directory already exists
1423 mkdir -p "$OUTPUTFILEDIR"
1424 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1425 if checkstatus movetrack-output-$OUTPUT; then :; else
1426 run_command movetrack-output-$OUTPUT true
1430 # Lets move the cue file
1431 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1432 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1433 if checkstatus movecue-$OUTPUT; then :; else
1434 # Silence the Copying output since it overlaps with encoding processes...
1435 #run_command '' vecho "Copying cue file to its destination directory..."
1436 if checkstatus onetrack >/dev/null ; then
1439 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1440 # We dont have the dir, since it was not created before.
1443 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1446 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1447 # http://brianvictor.tripod.com/mp3cue.htm#details
1448 [a-z0-9][a-z0-9][a-z0-9])
1449 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1452 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1456 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1458 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1467 # Create the playlist if wanted
1469 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1470 # VARIOUSARTISTS, OUTPUTDIR
1473 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1477 OUTPUT=$OGGOUTPUTCONTAINER
1480 OUTPUT=$FLACOUTPUTCONTAINER
1486 # Create a playlist file for the playlist data to go into.
1487 # We used to wipe it out if it existed. Now we request permision if interactive.
1488 for LASTTRACK in $TRACKQUEUE; do :; done
1489 ALBUMFILE="$(mungefilename "$DALBUM")"
1490 ARTISTFILE="$(mungefilename "$DARTIST")"
1491 GENRE="$(mungegenre "$GENRE")"
1492 YEAR=${CDYEAR:-$CDYEAR}
1493 if [ "$VARIOUSARTISTS" = "y" ] ; then
1494 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1496 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1498 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1499 mkdir -p "$FINALPLAYLISTDIR"
1500 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1501 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1502 if [ "$INTERACTIVE" = "y" ]; then
1503 while [ "$DONE" != "y" ]; do
1505 case $ERASEPLAYLIST in
1506 e|E|a|A|k|K) DONE=y ;;
1507 "") ERASEPLAYLIST=e ; DONE=y ;;
1515 # Once we erase the playlist, we use append to create the new one.
1516 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1518 # The playlist does not exist, so we can safelly use append to create the new list
1521 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1522 touch "$OUTPUTDIR/$PLAYLISTFILE"
1523 for UTRACKNUM in $TRACKQUEUE
1525 # Shares some code with do_move since the filenames have to match
1526 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1527 getcddbinfo TRACKNAME
1529 TRACKFILE="$(mungefilename "$TRACKNAME")"
1530 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1531 ALBUMFILE="$(mungefilename "$DALBUM")"
1532 # If we want to start the tracks with a given number, we need to modify the
1533 # TRACKNUM value before evaluation
1535 if [ "$VARIOUSARTISTS" = "y" ]; then
1536 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1538 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1540 if [ "$VARIOUSARTISTS" = "y" ]; then
1541 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1542 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1544 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1547 if [ "$PLAYLISTDATAPREFIX" ]; then
1548 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1550 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1555 ## this will convert the playlist to have CRLF line-endings, if specified
1556 ## (some hardware players insist on CRLF endings)
1557 if [ "$DOSPLAYLIST" = "y" ]; then
1558 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1559 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1560 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1562 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1567 # This function reads a cuefile on stdin and writes an extended
1568 # cddb query on stdout. Any PREGAP for track 1 is properly
1569 # handled, although cue files embedded in FLAC files do not
1570 # appear to properly store the PREGAP setting. :(
1571 abcde.cue2discid () {
1576 while [ $val -gt 0 ] ; do
1577 ret=$(( $ret + ( $val % 10) ))
1578 val=$(( $val / 10 ))
1588 local first second third
1589 first=$(expr ${1} + 0 )
1590 second=$(expr ${2} + 0 )
1591 third=$(expr ${3} + 0 )
1593 echo $(( ((($first * 60) + $second) * 75) + $third ))
1603 while read line ; do
1606 TRACK) i=$(( i + 1 ))
1608 INDEX) if [ "$2" -eq 1 ] ; then
1610 START=$(( $LBA + $PREGAP + $OFFSET ))
1612 X=$(cddb_sum $(( $START / 75 )) )
1616 PREGAP) PREGAP=$(msf2lba $2)
1620 LEADOUT=$(( $4 / 588 ))
1623 LEADIN=$(( $3 / 588 ))
1632 LEADOUT=$(( $LEADOUT + $LEADIN ))
1634 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1635 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1636 printf "%08x %i" $DISCID $TRACKS
1639 while [ $j -le $TRACKS ] ; do
1640 eval echo -n "\" \$TRACK$j\""
1643 echo " $(( $LEADOUT / 75 ))"
1647 # abcde.mkcue [--wholedisk]
1648 # This creates a cuefile directly from the extended discid information
1649 # The --wholedisk option controls whether we're ripping data from the
1650 # start of track one or from the start of the disk (usually, but not
1651 # always the same thing!)
1653 # Track one leadin/pregap (if any) handeling:
1654 # --wholedisk specified:
1657 # INDEX 01 <pregap value>
1658 # Remaining track index values unchanged from disc TOC
1660 # --wholedisk not specified
1662 # PREGAP <pregap value>
1664 # Remaining track index values offset by <pregap value>
1671 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1674 local MODE DISCID TRACKS
1678 if [ "$1" = --wholedisc ] ; then
1684 vecho "One track is $ONETRACK"
1685 TRACKFILE="$(mungefilename "$TRACKNAME")"
1686 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1687 ALBUMFILE="$(mungefilename "$DALBUM")"
1688 if [ "$ONETRACK" = "y" ]; then
1689 if [ "$VARIOUSARTISTS" = "y" ]; then
1690 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1692 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1694 vecho "Cue wav file is $CUEWAVFILE"
1696 CUEWAVFILE="dummy.wav"
1705 echo REM DISCID $DISCID
1706 echo FILE \""$CUEWAVEFILE"\" WAVE
1708 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1715 while [ $i -le "$TRACKS" ] ; do
1716 LBA=$(( $1 - $OFFSET ))
1717 printf " TRACK %02i AUDIO\n" $i
1718 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1719 if [ $MODE = PREGAP ] ; then
1720 echomsf " PREGAP " $(($OFFSET-150))
1722 echo " INDEX 00 00:00:00"
1725 echomsf " INDEX 01 " $LBA
1732 # This essentially the start of things
1735 # Query the CD to get the track info, unless the user specified -C
1736 # or we are using some actions which do not need the CDDB data at all
1737 #if [ ! X"$EXPACTIONS" = "X" ]; then
1739 #elif [ -z "$DISCID" ]; then
1740 if [ -z "$DISCID" ]; then
1741 vecho -n "Getting CD track info... "
1742 # In OSX, unmount the disc before a query
1743 if [ "$OSFLAVOUR" = "OSX" ]; then
1744 diskutil unmount ${CDROM#/dev/}
1746 case "$CDROMREADERSYNTAX" in
1748 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1749 case "$CUE2DISCID" in
1750 # FIXME # right now we have 2 cue2discid internal
1751 # implementations: builtin and abcde.cue2discid. Test
1752 # both of them and decide which one we want to use.
1754 #vecho "Using builtin cue2discid implementation..."
1755 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1757 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1759 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1760 TRACKS=${#OFFSETTIMES[@]}
1762 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1763 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1764 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1765 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1768 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1769 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1773 #vecho "Using external python cue2discid implementation..."
1774 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1778 log error "the input flac file does not contain a cuesheet."
1783 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1785 # if [ ! "$RET" = "0" ];then
1786 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1789 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1790 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1792 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1793 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1797 case "$CDDBMETHOD" in
1798 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1799 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1803 # Make sure there's a CD in there by checking cd-discid's return code
1804 if [ ! "$?" = "0" ]; then
1805 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1806 log error "cuesheet information from the flac file could not be read."
1807 log error "Perhaps the flac file does not contain a cuesheet?."
1810 log error "CD could not be read. Perhaps there's no CD in the drive?"
1814 # In OSX, remount the disc again
1815 if [ "$OSFLAVOUR" = "OSX" ]; then
1816 diskutil mount ${CDROM#/dev/}
1819 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1821 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1824 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1825 # This needs to be done now because a section of the resuming code will need
1828 # get the number of digits to pad TRACKNUM with - we'll use this later
1829 # a CD can only hold 99 tracks, but since we support a feature for starting
1830 # numbering the tracks from a given number, we might need to set it as a
1831 # variable for the user to define... or obtain it somehow.
1832 if [ "$PADTRACKS" = "y" ] ; then
1836 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1837 if [ -z "$TRACKQUEUE" ]; then
1838 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1839 case "$CDROMREADERSYNTAX" in
1841 if [ "$WEHAVEACD" = "y" ]; then
1842 vecho "Querying the CD for audio tracks..."
1843 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1845 if [ ! "$RET" = "0" ];then
1846 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1848 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1849 CDPARANOIAAUDIOTRACKS="$TRACKS"
1851 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1852 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1853 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1854 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1856 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1857 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1861 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1864 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1866 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1867 log info "The disc does not contain any tracks. Giving up..."
1870 echo -n "Grabbing entire CD - tracks: "
1871 if [ ! "$PADTRACKS" = "y" ] ; then
1872 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1874 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1876 while [ "$X" -ne "$TRACKS" ]
1878 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1879 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1883 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1884 # User-supplied track queue.
1885 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1886 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1887 # Once cleaned, obtain the highest value in the trackqueue for number padding
1888 for LASTTRACK in $TRACKQUEUE; do :; done
1889 if [ ! "$PADTRACKS" = "y" ] ; then
1890 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1892 # Now we normalize the trackqueue
1893 for TRACK in $TRACKQUEUE ; do
1894 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1895 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1897 TRACKQUEUE=$PADTRACKQUEUE
1898 echo Grabbing tracks: "$TRACKQUEUE"
1901 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1903 # We have the discid, create a temp directory after it to store all the temp
1906 if [ -e "$ABCDETEMPDIR" ]; then
1907 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1908 # It already exists, see if it's a directory
1909 if [ ! -d "$ABCDETEMPDIR" ]; then
1910 # This is a file/socket/fifo/device/etc, not a directory
1913 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1914 echo "Please investigate, remove it, and rerun abcde." >&2
1918 # It's a directory, let's see if it's writable by us
1919 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
1920 # Nope, complain and exit
1922 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
1923 echo "Please investigate, remove it, and rerun abcde." >&2
1927 # See if it's populated
1928 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1929 # Wipe and start fresh
1930 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1931 echo -n "this directory to continue. Continue [y/N]? " >&2
1932 if [ "$INTERACTIVE" = "y" ]; then
1938 if [ "$ANSWER" != "y" ]; then
1941 rm -rf "$ABCDETEMPDIR" || exit 1
1942 mkdir -p "$ABCDETEMPDIR"
1943 if [ "$?" -gt "0" ]; then
1944 # Directory already exists or could not be created
1945 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1949 # Everything is fine. Check for ^encodetracklocation-
1950 # and encode-output entries in the status file and
1951 # remove them. These are not relevant across sessions.
1952 if [ -f "$ABCDETEMPDIR/status" ]; then
1953 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1954 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1955 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1957 # Remove old error messages
1958 if [ -f "$ABCDETEMPDIR/errors" ]; then
1959 rm -f "$ABCDETEMPDIR/errors"
1963 # We are starting from scratch
1964 mkdir -p "$ABCDETEMPDIR"
1965 if [ "$?" -gt "0" ]; then
1966 # Directory already exists or could not be created
1967 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1970 cat /dev/null > "$ABCDETEMPDIR/status"
1971 # Store the abcde version in the status file.
1972 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1974 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1975 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1976 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1977 vecho "Creating cue file..."
1978 case $CDROMREADERSYNTAX in
1980 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
1981 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1983 log warning "the input flac file does not contain a cuesheet."
1987 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1988 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1990 log warning "reading the CUE sheet is still considered experimental"
1991 log warning "and there was a problem with the CD reading. abcde will continue,"
1992 log warning "but consider reporting the problem to the abcde author"
1998 # If we got the CDPARANOIA status and it is not recorded, save it now
1999 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2000 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2001 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2005 # Create the discid file
2006 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2007 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2008 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2013 # Create a proper CUE file based on the CUE file we created before.
2016 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2017 CUEFILE_OUT=$CUEFILE_IN.out
2018 ### FIXME ### checkstatus cddb
2019 if [ -e "$CDDBDATA" ]; then
2020 vecho "Adding metadata to the cue file..."
2021 # FIXME It doesn't preserve spaces! Why?
2022 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2024 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2025 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2026 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2030 cat "$CUEFILE_IN" | while read line
2032 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2033 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2034 # echo "$line" >> "$CUEFILE_OUT"
2035 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2036 eval track="\$TRACK$n"
2038 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2039 # When making a single-track rip, put the
2040 # actual file name into the file declaration
2041 # in the cue file so that it is usable by
2042 # music players and the like
2043 elif [ "$ONETRACK" = "y" ] &&
2044 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2046 TRACKFILE="$(mungefilename "$TRACKNAME")"
2047 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2048 ALBUMFILE="$(mungefilename "$DALBUM")"
2050 if [ "$VARIOUSARTISTS" = "y" ]; then
2051 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2053 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2056 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2059 # FIXME # If the lines above are uncommented, remove the line below.
2060 echo "$line" >> "$CUEFILE_OUT"
2063 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2064 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2070 # Parses a CDDB file and outputs the title and the track names.
2071 # Variables: CDDBFILE
2075 # List out disc title/author and contents
2076 if [ "$ONETRACK" = "y" ]; then
2077 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2079 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2080 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2081 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2082 if [ ! X"$PARSEDYEAR" = "X" ]; then
2083 echo "Year: $PARSEDYEAR"
2086 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2087 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2088 if [ ! X"$PARSEDGENRE" = "X" ]; then
2089 echo "Genre: $PARSEDGENRE"
2092 if [ ! "$ONETRACK" = "y" ]; then
2093 for TRACK in $(f_seq_row 1 $TRACKS)
2095 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2101 # Check for a local CDDB file, and report success
2104 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2106 CDDBLOCALSTATUS="notfound"
2107 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2110 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2111 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2112 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2113 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2114 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2115 CDDBLOCALMATCH=single
2116 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2117 CDDBLOCALMATCH=multiple
2122 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2123 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2124 CDDBLOCALMATCH=single
2129 # If the user has selected to check a local CDDB repo, we proceed with it
2130 case $CDDBLOCALMATCH in
2132 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2134 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2136 # List out disc title/author and contents
2137 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2138 cat "$RESULT" > "${CDDBLOCALREAD}"
2141 do_cddbparse "${CDDBLOCALREAD}"
2143 ##FIXME## QUICK HACK !!!!
2144 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2145 } >> "$ABCDETEMPDIR/cddblocalchoices"
2147 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2148 page "$ABCDETEMPDIR/cddblocalchoices"
2150 # It's all going to fit in one page, cat it
2151 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2153 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2154 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2155 CDDBLOCALCHOICENUM=-1
2156 if [ "$INTERACTIVE" = "y" ]; then
2157 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2158 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2159 read CDDBLOCALCHOICE
2160 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2161 # FIXME # Introduce diff's
2162 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2163 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2164 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2165 # Make sure we get a valid choice
2166 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2167 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2168 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2174 #echo "Selected ..."
2176 CDDBLOCALCHOICENUM=1
2178 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2179 #echo "Using local copy of CDDB data"
2180 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2181 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2182 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2183 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2184 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2185 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2186 CDDBLOCALSTATUS="found"
2188 #echo "Not using local copy of CDDB data"
2189 CDDBLOCALSTATUS="notfound"
2193 # List out disc title/author and contents
2194 do_cddbparse "${CDDBLOCALFILE}"
2195 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2196 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2198 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2200 if [ "$INTERACTIVE" = "y" ]; then
2202 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2203 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2206 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2210 if [ "$USELOCALRESP" = "y" ]; then
2211 #echo "Using local copy of CDDB data"
2212 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2213 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2214 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2215 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2216 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2217 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2218 CDDBLOCALSTATUS="single"
2220 #echo "Not using local copy of CDDB data"
2221 CDDBLOCALSTATUS="notfound"
2225 CDDBLOCALSTATUS="notfound"
2232 # Try to read CD-Text from the drive using icedax / cdda2wav
2235 if new_checkexec icedax; then
2236 CDTEXT_READER=icedax
2237 elif new_checkexec cdda2wav; then
2238 CDTEXT_READER=cdda2wav
2240 # Didn't find either, bail
2244 if [ "$OSFLAVOUR" = "OSX" ] ; then
2245 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2246 diskutil unmount ${CDROM#/dev/}
2247 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2248 CDDA2WAVCDROM="IODVDServices"
2249 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2250 CDDA2WAVCDROM="$CDROMID"
2252 if [ "$CDROMID" = "" ]; then
2253 CDDA2WAVCDROM="$CDROM"
2255 CDDA2WAVCDROM="$CDROMID"
2259 # Do we have CD-Text on the disc (and can the drive read it?)
2260 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2261 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2263 if [ $ERRORCODE -ne 0 ]; then
2264 # No CD-Text found, bail
2268 rm -f "$ABCDETEMPDIR/cddbchoices"
2270 # Make an empty template
2271 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2272 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2273 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2274 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2275 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2276 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2277 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2278 # List out disc title/author and contents
2279 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2280 for TRACK in $(f_seq_row 1 $TRACKS)
2282 TRACKM1=$(($TRACK - 1))
2283 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2284 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2285 sed -i "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1"
2287 sed -i "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1"
2288 echo >> "$ABCDETEMPDIR/cddbchoices"
2289 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2293 # Work with the musicbrainz WS API, then transform the results here so
2294 # they look (very) like the results from CDDB. Maybe not the best way
2295 # to go, but it Works For Me (TM)
2299 if checkstatus musicbrainz-readcomplete; then :; else
2300 vecho "Obtaining Musicbrainz results..."
2301 # If MB is to be used, interpret the query results and read all
2302 # the available entries.
2303 rm -f "$ABCDETEMPDIR/cddbchoices"
2304 CDDBCHOICES=1 # Overridden by multiple matches
2305 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2306 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2308 # The helper script will write disc matches out to
2309 # cddbread.*. Count how many we have
2310 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2311 # No matches. Use the normal cddb template for the user to
2313 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2314 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2315 # List out disc title/author and contents of template
2316 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2318 for TRACK in $(f_seq_row 1 $TRACKS)
2320 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2322 echo >> "$ABCDETEMPDIR/cddbchoices"
2323 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2324 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2325 echo 503 > "$ABCDETEMPDIR/cddbquery"
2327 # We have some matches
2328 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2329 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2331 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2332 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2333 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2334 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2335 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2336 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2337 # List out disc title/author and contents
2338 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2339 for TRACK in $(f_seq_row 1 $TRACKS)
2341 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2343 echo >> "$ABCDETEMPDIR/cddbchoices"
2345 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2346 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2347 for file in "$ABCDETEMPDIR"/cddbread.*
2349 X=$(echo $file | sed 's/^.*cddbread\.//g')
2350 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2351 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2352 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2353 # List out disc title/author and contents
2354 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2355 for TRACK in $(f_seq_row 1 $TRACKS)
2357 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2359 echo >> "$ABCDETEMPDIR/cddbchoices"
2361 echo "." >> "$ABCDETEMPDIR/cddbquery"
2364 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2371 # Perform CDDB protocol version check if it hasn't already been done
2372 if checkstatus cddb-statcomplete; then :; else
2373 if [ "$CDDBAVAIL" = "n" ]; then
2375 echo 503 > "$ABCDETEMPDIR/cddbstat"
2378 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2379 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2380 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2381 vecho "Checking CDDB server status..."
2382 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2383 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2384 case "$RESPONSECODE" in
2385 210) # 210 OK, status information follows (until terminating `.')
2388 501) # 501 Illegal CDDB protocol level: <n>.
2389 CDDBPROTO=`expr $CDDBPROTO - 1`
2391 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2392 # FreeDB TESTCD disc-id is used for query
2393 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2394 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2395 case "$RESPONSECODE" in
2396 2??) # Server responded, everything seems OK
2403 if test $rc -eq 1; then
2407 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2415 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2416 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2418 # Perform CDDB query if it hasn't already been done
2419 if checkstatus cddb-querycomplete; then :; else
2420 if [ "$CDDBAVAIL" = "n" ]; then
2422 echo 503 > "$ABCDETEMPDIR/cddbquery"
2423 # The default CDDBLOCALSTATUS is "notfound"
2424 # This part will be triggered if the user CDDB repo does not
2425 # contain the entry, or if we are not trying to use the repo.
2427 vecho "Querying the CDDB server..."
2428 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2429 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2430 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2436 # no match found in database,
2437 # wget/fetch error, or user requested not to use CDDB
2438 # Make up an error code (503) that abcde
2439 # will recognize in do_cddbread
2440 # and compensate by making a template
2441 echo 503 > "$ABCDETEMPDIR/cddbquery"
2443 *) # strange and unknown error
2444 echo ERRORCODE=$ERRORCODE
2445 echo "abcde: $CDDBTOOL returned unknown error code"
2449 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2456 # If it's not to be used, generate a template.
2457 # Then, display it (or them) and let the user choose/edit it
2458 if checkstatus cddb-readcomplete; then :; else
2459 vecho "Obtaining CDDB results..."
2460 # If CDDB is to be used, interpret the query results and read all
2461 # the available entries.
2462 rm -f "$ABCDETEMPDIR/cddbchoices"
2463 CDDBCHOICES=1 # Overridden by multiple matches
2464 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2465 case "$RESPONSECODE" in
2467 # One exact match, retrieve it
2468 # 200 [section] [discid] [artist] / [title]
2469 if checkstatus cddb-read-1-complete; then :; else
2470 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2471 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2472 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2473 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2474 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2476 # List out disc title/author and contents
2477 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2478 for TRACK in $(f_seq_row 1 $TRACKS)
2480 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2482 echo >> "$ABCDETEMPDIR/cddbchoices"
2486 case "$RESPONSECODE" in
2487 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2488 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2489 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2491 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2492 # List out disc title/author and contents of template
2493 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2495 for TRACK in $(f_seq_row 1 $TRACKS)
2497 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2499 echo >> "$ABCDETEMPDIR/cddbchoices"
2500 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2501 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2504 # Multiple exact, (possibly multiple) inexact matches
2506 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2507 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2508 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2509 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2510 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2512 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2514 vecho -n "Retrieving multiple matches... "
2515 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2516 read DISCINFO # eat top line
2520 if checkstatus cddb-read-$X-complete; then :; else
2521 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2522 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2524 # List out disc title/author and contents
2525 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2526 for TRACK in $(f_seq_row 1 $TRACKS)
2528 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2530 echo >> "$ABCDETEMPDIR/cddbchoices"
2533 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2537 for TRACK in $(f_seq_row 1 $TRACKS)
2539 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2541 echo >> "$ABCDETEMPDIR/cddbchoices"
2542 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2543 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2546 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2553 if checkstatus cddb-edit >/dev/null; then
2554 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2555 VARIOUSARTISTS="$(checkstatus variousartists)"
2556 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2559 if [ "$INTERACTIVE" = "y" ]; then
2560 # We should show the CDDB results both when we are not using the local CDDB repo
2561 # or when we are using it but we could not find a proper match
2562 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2563 # Display the $ABCDETEMPDIR/cddbchoices file created above
2564 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2565 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2566 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2567 CHOICE=$(checkstatus cddb-choice)
2568 if [ -n "$CHOICE" ] ; then
2569 case $CDDBCHOICES in
2570 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2571 log error "CDDB query failed!"
2574 cat "$ABCDETEMPDIR/cddbchoices"
2577 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2579 echo "Selected: #$CHOICE"
2580 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2584 # The user has a choice to make, display the info in a pager if necessary
2585 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2586 page "$ABCDETEMPDIR/cddbchoices"
2588 # It's all going to fit in one page, cat it
2589 cat "$ABCDETEMPDIR/cddbchoices" >&2
2593 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2595 # I'll take CDDB read #3 for $400, Alex
2596 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2597 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2599 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2600 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2601 if [ ! X"$DIFF" = "X" ]; then
2602 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2603 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2604 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2605 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2606 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2607 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2609 # We parse the 2 choices to diff, store them in temporary files and diff them.
2610 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2611 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2613 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2614 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2615 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2616 page "$ABCDETEMPDIR/cddbread.diff"
2618 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2622 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2624 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2625 # Make sure we get a valid choice
2626 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2627 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2628 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2632 if [ "$CDCHOICENUM" = "0" ]; then
2633 vecho "Creating empty CDDB template..."
2635 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2637 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2638 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2640 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2644 # We need some code to show the selected option when local repository is selected and we have found a match
2645 vecho "Using cached CDDB match..." >&2
2646 # Display the $ABCDETEMPDIR/cddbchoices file created above
2647 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2648 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2649 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2650 CHOICE=$(checkstatus cddb-choice)
2651 if [ "$USELOCALRESP" = "y" ]; then :; else
2652 if [ -n "$CHOICE" ] ; then
2653 case $CDDBCHOICES in
2656 echo "Selected template."
2658 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2660 echo "Selected: #$CHOICE"
2661 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2669 # We're noninteractive - pick the first choice.
2670 # But in case we run a previous instance and selected a choice, use it.
2671 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2672 # Show the choice if we are not using the locally stored one
2673 # or when the local search failed to find a match.
2674 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2675 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2676 #if [ "$PREVIOUSCHOICE" ]; then
2677 cat "$ABCDETEMPDIR/cddbchoices"
2680 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2681 CDCHOICENUM=$PREVIOUSCHOICE
2684 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2686 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2691 if checkstatus cddb-choice >/dev/null; then :; else
2692 echo "abcde: internal error: cddb-choice not recorded." >&2
2695 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2696 echo -n "Edit selected CDDB data? [y/n] (" >&2
2697 if [ "$INTERACTIVE" = "y" ]; then
2698 if [ "$UNKNOWNDISK" = "y" ]; then
2701 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2710 if [ "$EDITCDDB" = "y" ]; then
2711 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2713 # Use the debian sensible-editor wrapper to pick the editor that the
2714 # user has requested via their $EDITOR environment variable
2715 if [ -x "/usr/bin/sensible-editor" ]; then
2716 /usr/bin/sensible-editor "$CDDBDATA"
2717 elif [ -n "$EDITOR" ]; then
2718 if [ -x $(which "${EDITOR%%\ *}") ]; then
2719 # That failed, try to load the preferred editor, starting
2720 # with their EDITOR variable
2721 eval $(echo "$EDITOR") \"$CDDBDATA\"
2723 # If that fails, check for a vi
2724 elif which vi >/dev/null 2>&1; then
2726 elif [ -x /usr/bin/vim ]; then
2727 /usr/bin/vim "$CDDBDATA"
2728 elif [ -x /usr/bin/vi ]; then
2729 /usr/bin/vi "$CDDBDATA"
2730 elif [ -x /bin/vi ]; then
2732 # nano should be on all (modern, i.e., sarge) debian systems
2733 elif which nano >/dev/null 2>&1 ; then
2735 elif [ -x /usr/bin/nano ]; then
2736 /usr/bin/nano "$CDDBDATA"
2737 # mg should be on all OpenBSD systems
2738 elif which mg >/dev/null 2>&1 ; then
2740 elif [ -x /usr/bin/mg ]; then
2741 /usr/bin/mg "$CDDBDATA"
2744 log warning "no editor available. Check your EDITOR environment variable."
2746 # delete editor backup file if it exists
2747 if [ -w "$CDDBDATA~" ]; then
2752 # Some heuristics first. Look at Disc Title, and if it starts with
2753 # "Various", then we'll assume Various Artists
2754 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2755 echo "Looks like a Multi-Artist CD" >&2
2758 echo -n "Is the CD multi-artist [y/N]? " >&2
2759 if [ "$INTERACTIVE" = "y" ]; then
2766 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2769 # Need NUMTRACKS before cddb-tool will return it:
2770 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2771 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2772 # More than 1/2 tracks contain a "/", so guess forward
2774 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2775 # More than 1/2 contain a "-", so guess forward-dash
2777 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2778 # More than 1/2 contain something in parens, so guess trailing-paren
2782 echo "1) Artist / Title" >&2
2783 echo "2) Artist - Title" >&2
2784 echo "3) Title / Artist" >&2
2785 echo "4) Title - Artist" >&2
2786 echo "5) Artist: Title" >&2
2787 echo "6) Title (Artist)" >&2
2788 echo "7) This is a single-artist CD" >&2
2789 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2790 if [ "$INTERACTIVE" = "y" ]; then
2791 read VARIOUSARTISTSTYLE
2793 echo $DEFAULTSTYLE >&2
2794 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2796 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2797 # If they press Enter, then the default style (0) was chosen
2798 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2799 echo "Invalid selection. Please choose a number between 1 and 7."
2800 echo -n "Selection [1-7]: "
2801 read VARIOUSARTISTSTYLE
2802 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2804 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2805 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2807 vecho "Selected: $VARIOUSARTISTSTYLE"
2808 case "$VARIOUSARTISTSTYLE" in
2810 VARIOUSARTISTSTYLE=forward
2813 VARIOUSARTISTSTYLE=forward-dash
2816 VARIOUSARTISTSTYLE=reverse
2819 VARIOUSARTISTSTYLE=reverse-dash
2822 VARIOUSARTISTSTYLE=colon
2825 VARIOUSARTISTSTYLE=trailing-paren
2833 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2834 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2836 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2837 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2838 # This works but does not have the necessary error checking
2839 # yet. If you are familiar with the CDDB spec
2840 # (see http://www.freedb.org/src/latest/DBFORMAT)
2841 # and can create an error-free entry on your own, then put
2842 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2843 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2844 # your abcde.conf to change the email address submissions are
2847 # submit the modified file, if they want
2848 if [ "$NOSUBMIT" != "y" ]; then
2849 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2851 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2852 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2854 echo -n 'Invalid selection. Please answer "y" or "n": '
2857 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2858 echo -n "Sending..."
2859 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2866 # User CDDBLOCALPOLICY to find out if we store the file or not...
2867 # Cache edited CDDB entry in the user's cddb dir
2868 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2869 # Make sure the cache directory exists
2870 mkdir -p $CDDBLOCALDIR
2871 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2874 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2877 # do_cdread [tracknumber]
2878 # do_cdread onetrack [firsttrack] [lasttrack]
2882 # The commands here don't go through run_command because they're never supposed to be silenced
2883 # return codes need to be doublechecked anyway, however
2884 if [ "$1" = "onetrack" ]; then
2885 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2886 # FIXME # Until then, we grab the whole CD in one track, no matter what
2888 # We need the first and last track for cdda2wav/icedax
2890 LASTTRACK=$(expr $3 + 0)
2891 UTRACKNUM=$FIRSTTRACK
2892 case "$CDROMREADERSYNTAX" in
2893 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2896 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
2897 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2898 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
2899 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2905 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2906 if [ "$USEPIPES" = "y" ]; then
2907 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
2908 FILEARG="$( eval echo "\$$TEMPARG" )"
2910 PIPE_MESSAGE="and encoding "
2912 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2913 case "$CDROMREADERSYNTAX" in
2914 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2916 FILEARG="--output-name=$WAVDATA"
2919 FILEARG="-f $WAVDATA"
2927 if [ "$1" = "onetrack" ]; then
2928 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2930 if [ -r "$CDDBDATA" ]; then
2931 getcddbinfo TRACKNAME
2932 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2934 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2937 case "$CDROMREADERSYNTAX" in
2938 ### FIXME ### use an exception for flac, since it uses -o
2939 ### FIXME ### Shall we just use -o $FILEARG ??
2941 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2942 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
2943 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2945 if [ "$REDIR" = "y" ]; then
2946 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
2948 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
2952 if [ "$OSFLAVOUR" = "OSX" ] ; then
2953 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2954 diskutil unmount ${CDROM#/dev/}
2955 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2956 CDDA2WAVCDROM="IODVDServices"
2957 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2958 CDDA2WAVCDROM="$CDROMID"
2960 if [ "$CDROMID" = "" ]; then
2961 CDDA2WAVCDROM="$CDROM"
2963 CDDA2WAVCDROM="$CDROMID"
2966 if [ "$REDIR" = "y" ]; then
2967 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
2969 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
2971 ## FIXME ## We have an exception for dagrab, since it uses -f
2972 ## FIXME ## Shall we just use -f $FILEARG ??
2974 if [ "$REDIR" = "y" ]; then
2975 nice $READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG" >&2
2977 nice $READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG"
2980 # Find the track's mounted path
2981 REALTRACKNUM=$(expr $UTRACKNUM + 0)
2982 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
2983 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2984 # If the file exists, copy it
2985 if [ -e "$FILEPATH" ] ; then
2986 if [ "$REDIR" = "y" ]; then
2987 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
2989 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
2995 if [ "$REDIR" = "y" ]; then
2996 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
2998 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3002 # If we get some error or we get some missing wav
3003 # (as long as we dont use pipes)
3004 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3005 # Thank goodness errors is only machine-parseable up to the
3006 # first colon, otherwise this woulda sucked
3007 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3008 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3010 if [ "$USEPIPES" = "y" ]; then
3011 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3013 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3017 if [ "$USEPIPES" = "y" ]; then
3018 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3020 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3022 if [ "$1" = "onetrack" ]; then
3023 echo onetrack >> "$ABCDETEMPDIR/status"
3029 # No values accepted, only uses env variables
3032 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3033 vecho "Setting CD speed to ${CDSPEEDVALUE}x"