2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
5 # Copyright (c) 2012 Steve McIntyre <93sam@@debian.org>
6 # This code is hereby licensed for public consumption under either the
7 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
9 # You should have received a copy of the GNU General Public License along
10 # with this program; if not, write to the Free Software Foundation, Inc.,
11 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13 # Copyright for this work is to expire January 1, 2010, after which it
14 # shall be public domain.
16 VERSION='2.6.1-UNRELEASED'
20 echo "This is abcde v$VERSION."
21 echo "Usage: abcde [options] [tracks]"
23 echo "-1 Encode the whole CD in a single file"
24 echo "-a <action1[,action2]...>"
25 echo " Actions to perform:"
26 echo " cddb,read,getalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
27 #echo "-A Experimental actions (retag, transcode)"
28 echo "-b Enable batch normalization"
30 echo " Specify a configuration file (overrides system and user config files)"
32 echo " Specify discid to resume from (only needed if you no longer have the cd)"
34 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
35 echo "-D Debugging mode (equivalent to sh -x abcde)"
36 echo "-e Erase encoded track information from status file"
37 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
38 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
39 echo "-G Get album art by using the 'getalbumart' action"
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,opus,wv,ape). 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"
55 echo "-r <host1[,host2]...>"
56 echo " Also encode on these remote hosts"
58 echo " Show fields from the CDDB info (year,genre)"
59 echo "-S <#> Set the CD speed"
60 echo "-t <#> Start the track numbering at a given number"
61 echo "-T <#> Same as -t but modifies tag numbering"
62 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
63 echo "-v Show version number and exit"
64 echo "-V Be a bit more verbose about what is happening behind the scenes"
65 echo "-x Eject CD after all tracks are read"
67 echo " Add a comment to the CD tracks"
68 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
69 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
71 echo "Tracks is a space-delimited list of tracks to grab."
72 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
74 #echo "Double hyphens are used to concatenate tracks"
79 echo "$@" >> "$ABCDETEMPDIR/status"
82 # log [level] [message]
84 # log outputs the right message in a common format
90 error) >&2 echo "[ERROR] abcde: $@" >&2 ;;
91 warning) >&2 echo "[WARNING] $@" >&2 ;;
92 info) >&4 echo "[INFO] $@" ;;
96 # Functions to replace the need of seq, which is too distribution dependent.
100 while [ $i -ne `expr $2 + 1` ]
110 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
111 while [ $i -ne `expr $2 + 1` ]
118 log error "syntax error while processing track numbers ($i)"
123 # Functions to replace the need of awk {print $1} and {print $NF}
126 if [ X"$1" = "X" ]; then
127 for first in `cat`; do
138 if [ X"$1" = "X" ]; then
139 for stdin in `cat`; do
143 for last in $@ ; do :; done
148 # checkstatus [blurb]
149 # Returns "0" if the blurb was found, returns 1 if it wasn't
150 # Puts the blurb content, if available, on stdout.
151 # Otherwise, returns "".
154 # Take the last line in the status file if there's multiple matches
156 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
158 if [ -z "$BLURB" ]; then
163 # See if there's a = in it
164 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
165 echo "$(echo $BLURB | cut -f2- -d=)"
171 # checkwarnings [blurb]
172 # Returns "0" if the blurb was found (meaning there was an warning),
173 # returns 1 if it wasn't (yes this is a little backwards).
174 # Does not print the blurb on stdout.
175 # Otherwise, returns "".
178 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
181 # Take the last line in the status file if there's multiple matches
183 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
185 if [ -z "$BLURB" ]; then
186 # negative, we did not have a negative...
189 # affirmative, we had a negative...
194 # checkerrors [blurb]
195 # Returns "0" if the blurb was found (meaning there was an error),
196 # returns 1 if it wasn't (yes this is a little backwards).
197 # Does not print the blurb on stdout.
198 # Otherwise, returns "".
201 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
204 # Take the last line in the status file if there's multiple matches
206 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
208 if [ -z "$BLURB" ]; then
209 # negative, we did not have a negative...
212 # affirmative, we had a negative...
218 # Finds the right pager in the system to display a file
222 # Use the debian sensible-pager wrapper to pick the pager
223 # user has requested via their $PAGER environment variable
224 if [ -x "/usr/bin/sensible-pager" ]; then
225 /usr/bin/sensible-pager "$PAGEFILE"
226 elif [ -x "$PAGER" ]; then
227 # That failed, try to load the preferred editor, starting
228 # with their PAGER variable
230 # If that fails, check for less
231 elif [ -x /usr/bin/less ]; then
232 /usr/bin/less -f "$PAGEFILE"
233 # more should be on all UNIX systems
234 elif [ -x /bin/more ]; then
235 /bin/more "$PAGEFILE"
237 # No bananas, just cat the thing
242 # run_command [blurb] [command...]
243 # Runs a command, silently if necessary, and updates the status file
249 # See if this is supposed to be silent
250 if [ "$(checkstatus encode-output)" = "loud" ]; then
254 # Special case for SMP, since
255 # encoder output is never displayed, don't mute echos
256 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
265 normalize|normalize-audio)
266 if [ "$RETURN" = "2" ]; then
267 # File was already normalized.
272 if [ "$RETURN" != "0" ]; then
273 # Put an error in the errors file. For various reasons we
274 # can't capture a copy of the program's output but we can
275 # log what we attempted to execute and the error code
276 # returned by the program.
277 if [ "$BLURB" ]; then
280 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
281 return $RETURN # Do not pass go, do not update the status file
283 if [ "$BLURB" ]; then
284 echo $BLURB >> "$ABCDETEMPDIR/status"
288 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
289 # distributed under the terms of the GNU GPL v2 or later, at your option
291 # Function to determine if a word contains a slash.
300 # Function to give the relative path from one file to another.
301 # Usage: relpath fromfile tofile
302 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
303 # (the result would be Album/Song.mp3)
304 # Output is relative path to $2 from $1 on stdout
306 # This code has the following restrictions:
307 # Multiple ////s are not collapsed into single /s, with strange effects.
308 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
309 # If FR is a directory it must have a trailing /
317 /*) ;; # No processing is needed for absolute paths
319 # Loop through common prefixes, ignoring them.
320 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
322 FR="$(echo "$FR" | cut -d/ -f2-)"
323 TO="$(echo "$TO" | cut -d/ -f2-)"
325 # Loop through directory portions left in FR, adding appropriate ../s.
328 FR="$(echo "$FR" | cut -d/ -f2-)"
339 if [ ! "$@" = "" ]; then
340 # Cut off any command-line option we added in
341 X=$(echo $@ | cut -d' ' -f2)
342 if [ "$(which $X)" = "" ]; then
344 elif [ ! -x $(which $X) ]; then
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X=$(echo $@ | cut -d' ' -f2)
356 # Test for built-in abcde.function
357 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
358 if [ "$(which $X)" = "" ]; then
359 log error "$X is not in your path." >&2
360 log info "Define the full path to the executable if it exists on your system." >&2
361 if [ -e /etc/debian_release ] ; then
363 oggenc) MISSING_PACKAGE=vorbis-tools ;;
364 lame|flac) MISSING_PACKAGE=$X ;;
366 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
369 elif [ ! -x "$(which $X)" ]; then
370 log error "$X is not executable." >&2
376 # diffentries <filename> <max_value> <entry1>,<entry2>
377 # max_value: the range of entries goes from 1 to <max_value>
382 local CDDBDIFFCHOICES=$1
384 local CDDBDIFFCHOICE="$@"
385 if [ ! X"$DIFF" = "X" ]; then
386 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
387 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
388 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
389 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
390 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
391 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
393 # We parse the 2 choices to diff, store them in temporary files and diff them.
394 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
395 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
397 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
398 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
399 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
400 page "$ABCDETEMPDIR/$FILENAME.diff"
402 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
406 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
411 # Finds an specific field from cddbinfo
416 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
419 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
422 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
428 # Get the track number we are going to use for different actions
431 if [ -n "$STARTTRACKNUMBER" ] ; then
432 # Get the trackpadding from the current track, also trim whitespace for MacOSX
433 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
434 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
436 TRACKNUM=${UTRACKNUM}
442 # Calculate cddb disc ids without requiring specialized helper programs.
443 # largely copied from cd-discid and musicbrainz examples. some of the steps
444 # don't make sense, but they're necessary to match the ids generated by other
447 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
448 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
449 # processing offsetimes 00:00:00 04:47:10 08:20:37 11:46:46 17:45:36 21:41:57 27:32:21 32:03:73 35:39:28 38:27:33 43:50:38 44:42:34
450 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
451 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
452 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
454 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
457 if [ X"$LEADOUT" = "X" ]; then
458 log warning "Error trying to calculate disc ids without lead-out information."
462 # default to a two second lead-in
464 LEADIN=${LEADIN:=150}
466 # number of cdframes per second
469 # reset cddb checksum for cddb disc-id calululation
473 for OFFSET in $(echo $OFFSETS)
475 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
477 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
478 while [ $OFFSETTIME -gt 0 ]; do
479 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
480 OFFSETTIME=$(($OFFSETTIME / 10))
485 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
487 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
488 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
490 case "$CDDBMETHOD" in
492 printf -v DISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
495 # FIXME: don't assume the first track is 1
496 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
497 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
501 TRACKINFO="${DISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
506 if checkstatus replaygain; then :; else
507 run_command "" echo "Adding replaygain information..."
508 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
512 OUTPUT=$OGGOUTPUTCONTAINER
515 OUTPUT=$OPUSOUTPUTCONTAINER
518 OUTPUT=$FLACOUTPUTCONTAINER
526 for UTRACKNUM in $TRACKQUEUE
528 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
529 getcddbinfo TRACKNAME
531 TRACKFILE="$(mungefilename "$TRACKNAME")"
532 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
533 ALBUMFILE="$(mungefilename "$DALBUM")"
534 GENRE="$(mungegenre "$GENRE")"
535 YEAR=${CDYEAR:-$CDYEAR}
537 if [ "$ONETRACK" = "y" ]; then
538 if [ "$VARIOUSARTISTS" = "y" ]; then
539 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
541 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
544 if [ "$VARIOUSARTISTS" = "y" ]; then
545 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
547 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
550 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
551 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
555 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
556 #run_command replaygain-flac true
559 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
562 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
565 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
568 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
573 if checkerrors "replaygain-.{3,6}"; then :; else
574 run_command replaygain true
579 # This code splits the a Various Artist track name from one of the following
582 # forward: Artist / Track
583 # forward-dash: Artist - Track
584 # reverse: Track / Artist
585 # reverse-dash: Track - Artist
586 # colon: Artist: Track
587 # trailing-paren: Artist (Track)
590 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
593 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
594 case "$VARIOUSARTISTSTYLE" in
596 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
597 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
598 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
601 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
602 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
603 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
606 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
607 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
608 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
611 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
612 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
613 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
616 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
617 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
618 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
621 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
622 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
623 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
626 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
627 TRACKARTIST="Various"
629 TRACKARTIST="$DARTIST"
634 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
638 "classic rock") id=1 ;;
656 "industrial") id=19 ;;
657 "alternative") id=20 ;;
659 "death metal") id=22 ;;
661 "soundtrack") id=24 ;;
662 "euro-techno") id=25 ;;
666 "jazz+funk") id=29 ;;
669 "classical") id=32 ;;
670 "instrumental") id=33 ;;
674 "sound clip") id=37 ;;
677 "alt. rock") id=40 ;;
682 "meditative") id=45 ;;
683 "instrum. pop") id=46 ;;
684 "instrum. rock") id=47 ;;
688 "techno-indust.") id=51 ;;
689 "electronic") id=52 ;;
691 "eurodance") id=54 ;;
693 "southern rock") id=56 ;;
698 "christian rap") id=61 ;;
699 "pop/funk"|"pop / funk") id=62 ;;
701 "native american") id=64 ;;
704 "psychadelic") id=67 ;;
706 "showtunes") id=69 ;;
710 "acid punk") id=73 ;;
711 "acid jazz") id=74 ;;
715 "rock & roll") id=78 ;;
716 "hard rock") id=79 ;;
718 "folk/rock") id=81 ;;
719 "national folk") id=82 ;;
726 "bluegrass") id=89 ;;
727 "avantgarde") id=90 ;;
728 "gothic rock") id=91 ;;
729 "progress. rock") id=92 ;;
730 "psychadel. rock") id=93 ;;
731 "symphonic rock") id=94 ;;
732 "slow rock") id=95 ;;
735 "easy listening") id=98 ;;
741 "chamber music") id=104 ;;
743 "symphony") id=106 ;;
744 "booty bass") id=107 ;;
746 "porn groove") id=109 ;;
748 "slow jam") id=111 ;;
752 "folklore") id=115 ;;
754 "power ballad") id=117 ;;
755 "rhythmic soul") id=118 ;;
756 "freestyle") id=119 ;;
758 "punk rock") id=121 ;;
759 "drum solo") id=122 ;;
760 "a capella") id=123 ;;
761 "euro-house") id=124 ;;
762 "dance hall") id=125 ;;
764 "drum & bass") id=127 ;;
765 "club-house") id=128 ;;
766 "hardcore") id=129 ;;
770 "negerpunk") id=133 ;;
771 "polsk punk") id=134 ;;
773 "christian gangsta rap") id=136 ;;
774 "heavy metal") id=137 ;;
775 "black metal") id=138 ;;
776 "crossover") id=139 ;;
777 "contemporary christian")id=140 ;;
778 "christian rock") id=141 ;;
779 "merengue") id=142 ;;
781 "thrash metal") id=144 ;;
784 "synthpop") id=147 ;;
785 "rock/pop"|"rock / pop") id=148 ;;
792 # do_tag [tracknumber]
793 # id3 tags a filename
795 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
796 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
799 COMMENTOUTPUT="$(eval echo ${COMMENT})"
800 if [ -z "$COMMENTOUTPUT" ]; then
801 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
803 if [ "$CDDBMETHOD" = "cddb" ]; then
804 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
806 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
807 # If we want to start the tracks with a given number, we need to modify the
808 # TRACKNUM value before evaluation
809 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
812 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
816 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
817 GENREID=$(do_getgenreid "${CDGENRE}")
818 # Set TPE2 in case we have a Various Artists rip.
820 if [ "$VARIOUSARTISTS" = "y" ]; then
826 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
827 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
828 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
829 -y "$CDYEAR" -g "$GENREID" \
830 -T "${TRACKNUM:-$1}" \
831 "$ABCDETEMPDIR/track$1.$OUTPUT"
834 # FIXME # track numbers in mp3 come with 1/10, so we cannot
835 # happily substitute them with $TRACKNUM
836 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
837 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
838 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
839 -y "$CDYEAR" -g "$GENREID" \
840 -T "${TRACKNUM:-$1}/$TRACKS" \
841 ${TPE2:+--TPE2 "$TPE2"} \
842 "$ABCDETEMPDIR/track$1.$OUTPUT"
845 # FIXME # track numbers in mp3 come with 1/10, so we cannot
846 # happily substitute them with $TRACKNUM
848 eyed3_06) addopts=( \
849 ${ENCODING:+--set-encoding="$ENCODING"} \
850 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
851 # We set 'recording-date' so the date tag will show
852 # in Audacious, vlc and friends... Andrew.
853 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
854 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
857 ${ENCODING:+--encoding="$ENCODING"} \
858 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
859 # We set 'recording-date' so the date tag will show
860 # in Audacious, vlc and friends... Andrew.
861 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
862 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
865 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
867 -a "$TRACKARTIST" -t "$TRACKNAME" \
868 -G "$GENREID" -n "${TRACKNUM:-$1}" \
869 ${TRACKNUM:+-N "$TRACKS"} \
871 "$ABCDETEMPDIR/track$1.$OUTPUT"
874 log error "Internal error: ID3SYNTAX has an illegal value"
880 case "$OGGENCODERSYNTAX" in
882 # vorbiscomment can't do in-place modification, mv the file first
883 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
884 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
888 # http://www.xiph.org/vorbis/doc/v-comment.html
890 echo ARTIST="$TRACKARTIST"
892 echo TITLE="$TRACKNAME"
893 if [ -n "$CDYEAR" ]; then
896 if [ -n "$CDGENRE" ]; then
897 echo GENRE="$CDGENRE"
899 echo TRACKNUMBER=${TRACKNUM:-$1}
900 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
901 # xiph.org: http://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
902 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
903 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
904 echo TRACKTOTAL="${TRACKS}"
905 if [ -n "$DISCNUMBER" ]; then
906 echo DISCNUMBER="$DISCNUMBER"
908 echo CDDB=$CDDBDISCID
909 if [ "$(eval echo ${COMMENT})" != "" ]; then
910 case "$COMMENTOUTPUT" in
911 *=*) echo "$COMMENTOUTPUT";;
912 *) echo COMMENT="$COMMENTOUTPUT";;
915 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
916 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
917 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
918 # Doublecheck that the commented file was created
919 # successfully before wiping the original
920 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
921 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
923 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
929 run_command tagtrack-$OUTPUT-$1 true
933 echo ARTIST="$TRACKARTIST"
935 echo TITLE="$TRACKNAME"
936 if [ -n "$CDYEAR" ]; then
939 if [ -n "$CDGENRE" ]; then
940 echo GENRE="$CDGENRE"
942 echo TRACKNUMBER="${TRACKNUM:-$1}"
943 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
944 # xiph.org: http://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
945 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
946 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
947 echo TRACKTOTAL="${TRACKS}"
948 if [ -n "$DISCNUMBER" ]; then
949 echo DISCNUMBER="$DISCNUMBER"
951 echo CDDB="$CDDBDISCID"
952 if [ "$(eval echo ${COMMENT})" != "" ]; then
953 case "$COMMENTOUTPUT" in
954 *=*) echo "$COMMENTOUTPUT";;
955 *) echo COMMENT="$COMMENTOUTPUT";;
958 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
959 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
962 run_command tagtrack-$OUTPUT-$1 true
965 run_command tagtrack-$OUTPUT-$1 true
968 run_command tagtrack-$OUTPUT-$1 true
971 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
972 # Console port (mac) used for encoding does not have the ability to tag.
973 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
974 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
975 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
978 run_command tagtrack-$OUTPUT-$1 true
981 case "$AACENCODERSYNTAX" in
983 # We will use inline tagging...
984 run_command tagtrack-$OUTPUT-$1 true
987 # Tag post encode with neroAacTag...
988 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
989 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
990 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
993 run_command tagtrack-$OUTPUT-$1 true
998 run_command tagtrack-$OUTPUT-$1 true
1002 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1003 run_command tagtrack-$1 true
1009 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1012 # The commands here don't go through run_command because they're never
1013 # supposed to be silenced
1014 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1015 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1019 case "$MP3ENCODERSYNTAX" in
1024 for UTRACKNUM in $TRACKQUEUE
1026 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1028 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1030 if [ "$RETURN" != "0" ]; then
1031 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1033 for UTRACKNUM in $TRACKQUEUE
1035 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1036 #run_command encodetrack-$UTRACKNUM true
1045 if checkerrors "nogap-encode"; then :; else
1046 if [ ! "$KEEPWAVS" = "y" ] ; then
1047 if [ ! "$KEEPWAVS" = "move" ] ; then
1052 # Other encoders fall through to normal encoding as the tracks have not
1053 # been entered in the status file.
1056 # do_encode [tracknumber] [hostname]
1057 # If no hostname is specified, encode locally
1059 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1060 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1063 if [ "$USEPIPES" = "y" ]; then
1066 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1069 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1072 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1075 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1078 TEMPARG="PIPE_$SPEEXENCODER"
1081 TEMPARG="PIPE_$MPCENCODER"
1084 TEMPARG="PIPE_$WVENCODERSYNTAX"
1087 TEMPARG="PIPE_$AACENCODERSYNTAX"
1090 TEMPARG="PIPE_$AACENCODERSYNTAX"
1093 IN="$( eval echo "\$$TEMPARG" )"
1095 IN="$ABCDETEMPDIR/track$1.wav"
1097 # We need IN to proceed, if we are not using pipes.
1098 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1099 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1101 case "$TMPOUTPUT" in
1103 OUTPUT=$OGGOUTPUTCONTAINER
1106 OUTPUT=$OPUSOUTPUTCONTAINER
1109 OUTPUT=$FLACOUTPUTCONTAINER
1115 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1116 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1119 if [ X"$USEPIPES" = "Xy" ]; then
1121 # We need a way to store the creation of the files when using PIPES
1122 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1123 # When piping it does not make sense to have a higher nice for
1124 # reading than for encoding, since it will be hold by the
1125 # encoding process. Setting an effective nice, to calm down a
1126 # bit the reading process.
1127 EFFECTIVE_NICE=$READNICE
1129 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1130 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1131 EFFECTIVE_NICE=$ENCNICE
1137 case "$MP3ENCODERSYNTAX" in
1138 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1139 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1140 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1141 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1145 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1152 case "$OGGENCODERSYNTAX" in
1153 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1154 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1158 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1165 case "$OPUSENCODERSYNTAX" in
1167 # Tag the file at encode time, as it can't be done after encoding.
1168 if [ "$DOTAG" = "y" ]; then
1169 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1170 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1171 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1173 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1179 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1186 case "$FLACENCODERSYNTAX" in
1187 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1192 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1193 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1198 if [ "$(eval echo ${COMMENT})" != "" ]; then
1201 *) COMMENT="COMMENT=$COMMENT" ;;
1204 # Tag the file at encode time, as it can't be done after encoding.
1205 if [ "$DOTAG" = "y" ]; then
1206 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1207 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1209 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1213 # Tag the file inline at encode time.
1214 if [ "$DOTAG" = "y" ]; then
1215 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1216 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1218 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1222 if [ "$DOTAG" = "y" ]; then
1223 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1224 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1226 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1230 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1233 # aac container is only used to catch faac encoded files where faac
1234 # is compiled without mp4 support (with libmp4v2).
1235 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1238 case "$AACENCODERSYNTAX" in
1240 if [ "$DOTAG" = "y" ]; then
1241 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1242 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1244 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1248 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1251 if [ "$DOTAG" = "y" ]; then
1252 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1253 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1255 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1261 # In case of wav output we need nothing. Just keep the wavs.
1262 # But we need the following to allow full logging and subsequent
1263 # successful cleaning of $ABCDETEMPDIR.
1264 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1269 # Only remove .wav if the encoding succeeded
1270 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1271 run_command encodetrack-$1 true
1272 if [ ! "$KEEPWAVS" = "y" ] ; then
1273 if [ ! "$KEEPWAVS" = "move" ] ; then
1279 run_command "" echo "HEH! The file we were about to encode disappeared:"
1280 run_command "" echo ">> $IN"
1281 run_command encodetrack-$1 false
1285 # do_preprocess [tracknumber]
1287 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1290 # IN="$ABCDETEMPDIR/track$1.wav"
1291 # # We need IN to proceed.
1292 # if [ -s "$IN" ] ; then
1293 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1295 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1296 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1297 # case "$POSTPROCESSFORMAT" in
1299 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1301 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1303 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1305 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1307 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1310 # # Only remove .wav if the encoding succeeded
1311 # if checkerrors "preprocess-(.{3,4})-$1"; then
1312 # run_command preprocess-$1 false
1314 # run_command preprocess-$1 true
1317 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1318 # echo "HEH! The file we were about to pre-process disappeared:"
1321 # run_command preprocess-$1 false
1326 # do_postprocess [tracknumber]
1328 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1331 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1333 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1334 # # We need IN to proceed.
1335 # if [ -s "$IN" ] ; then
1336 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1337 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1338 # case "$POSTPROCESSFORMAT" in
1340 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1342 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1344 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1346 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1348 # # Only remove .wav if the encoding succeeded
1349 # if checkerrors "postprocess-(.{3,4})-$1"; then
1350 # run_command postprocess-$1 false
1352 # run_command postprocess-$1 true
1355 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1356 # echo "HEH! The file we were about to post-process disappeared:"
1359 # run_command postprocess-$1 false
1374 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1378 # The commands here don't go through run_command because they're never supposed to be silenced
1379 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1384 for UTRACKNUM in $TRACKQUEUE
1386 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1388 # FIXME # Hard-coded batch option!
1389 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1391 if [ "$RETURN" != "0" ]; then
1392 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1394 for UTRACKNUM in $TRACKQUEUE
1396 echo normalizetrack-$UTRACKNUM >> status
1402 # do_batch_normalize
1404 # NORMALIZER, NORMALIZEROPTS
1405 do_batch_normalize ()
1407 # The commands here don't go through run_command because they're never supposed to be silenced
1408 echo "Batch normalizing tracks: $TRACKQUEUE"
1413 for UTRACKNUM in $TRACKQUEUE
1415 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1417 # XXX: Hard-coded batch option!
1418 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1420 if [ "$RETURN" != "0" ]; then
1421 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1423 for UTRACKNUM in $TRACKQUEUE
1425 echo normalizetrack-$UTRACKNUM >> status
1431 # do_normalize [tracknumber]
1433 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1436 IN="$ABCDETEMPDIR/track$1.wav"
1437 if [ -e "$IN" ] ; then
1438 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1439 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1441 if [ "$(checkstatus encode-output)" = "loud" ]; then
1442 echo "HEH! The file we were about to normalize disappeared:"
1445 run_command normalizetrack-$1 false "File $IN was not found"
1449 # do_move [tracknumber]
1450 # Deduces the outfile from environment variables
1451 # Creates directory if necessary
1453 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1456 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1458 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1459 # defined the OUTPUTFILE:
1462 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1463 # Munge filenames as follows:
1468 # Eat control characters
1469 ALBUMFILE="$(mungefilename "$DALBUM")"
1470 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1471 TRACKFILE="$(mungefilename "$TRACKNAME")"
1472 GENRE="$(mungegenre "$GENRE")"
1473 YEAR=${CDYEAR:-$CDYEAR}
1474 # If we want to start the tracks with a given number, we need to modify
1475 # the TRACKNUM value before evaluation
1477 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1478 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1479 if [ "$ONETRACK" = "y" ]; then
1480 if [ "$VARIOUSARTISTS" = "y" ]; then
1481 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1483 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1486 if [ "$VARIOUSARTISTS" = "y" ]; then
1487 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1489 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1492 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1493 # Once we know the specific output was successful, we can change
1494 # the OUTPUT to the value containing the container
1497 OUTPUT=$OGGOUTPUTCONTAINER
1500 OUTPUT=$OPUSOUTPUTCONTAINER
1503 OUTPUT=$FLACOUTPUTCONTAINER
1509 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1510 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1513 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1514 # FIXME # introduce warnings?
1517 # mkdir -p shouldn't return an error if the directory already exists
1518 mkdir -p "$OUTPUTFILEDIR"
1519 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1520 if checkstatus movetrack-output-$OUTPUT; then :; else
1521 run_command movetrack-output-$OUTPUT true
1526 # mkdir -p shouldn't return an error if the directory already exists
1527 mkdir -p "$OUTPUTFILEDIR"
1528 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1529 if checkstatus movetrack-output-$OUTPUT; then :; else
1530 run_command movetrack-output-$OUTPUT true
1534 # Lets move the cue file
1535 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1536 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1537 if checkstatus movecue-$OUTPUT; then :; else
1538 # Silence the Copying output since it overlaps with encoding processes...
1539 #run_command '' vecho "Copying cue file to its destination directory..."
1540 if checkstatus onetrack >/dev/null ; then
1543 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1544 # We dont have the dir, since it was not created before.
1547 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1550 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1551 # http://brianvictor.tripod.com/mp3cue.htm#details
1552 [a-z0-9][a-z0-9][a-z0-9])
1553 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1556 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1560 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1562 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1571 # Create the playlist if wanted
1573 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1574 # VARIOUSARTISTS, OUTPUTDIR
1577 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1581 OUTPUT=$OGGOUTPUTCONTAINER
1584 OUTPUT=$OPUSOUTPUTCONTAINER
1587 OUTPUT=$FLACOUTPUTCONTAINER
1593 # Create a playlist file for the playlist data to go into.
1594 # We used to wipe it out if it existed. Now we request permission if interactive.
1595 for LASTTRACK in $TRACKQUEUE; do :; done
1596 ALBUMFILE="$(mungefilename "$DALBUM")"
1597 ARTISTFILE="$(mungefilename "$DARTIST")"
1598 GENRE="$(mungegenre "$GENRE")"
1599 YEAR=${CDYEAR:-$CDYEAR}
1600 if [ "$VARIOUSARTISTS" = "y" ] ; then
1601 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1603 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1605 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1606 mkdir -p "$FINALPLAYLISTDIR"
1607 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1608 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1609 if [ "$INTERACTIVE" = "y" ]; then
1610 while [ "$DONE" != "y" ]; do
1612 case $ERASEPLAYLIST in
1613 e|E|a|A|k|K) DONE=y ;;
1614 "") ERASEPLAYLIST=e ; DONE=y ;;
1622 # Once we erase the playlist, we use append to create the new one.
1623 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1625 # The playlist does not exist, so we can safelly use append to create the new list
1628 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1629 touch "$OUTPUTDIR/$PLAYLISTFILE"
1630 for UTRACKNUM in $TRACKQUEUE
1632 # Shares some code with do_move since the filenames have to match
1633 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1634 getcddbinfo TRACKNAME
1636 TRACKFILE="$(mungefilename "$TRACKNAME")"
1637 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1638 ALBUMFILE="$(mungefilename "$DALBUM")"
1639 # If we want to start the tracks with a given number, we need to modify the
1640 # TRACKNUM value before evaluation
1642 if [ "$VARIOUSARTISTS" = "y" ]; then
1643 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1645 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1647 if [ "$VARIOUSARTISTS" = "y" ]; then
1648 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1649 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1651 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1654 if [ "$PLAYLISTDATAPREFIX" ]; then
1655 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1657 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1662 ## this will convert the playlist to have CRLF line-endings, if specified
1663 ## (some hardware players insist on CRLF endings)
1664 if [ "$DOSPLAYLIST" = "y" ]; then
1665 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1666 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1667 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1669 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1674 # This function reads a cuefile on stdin and writes an extended
1675 # cddb query on stdout. Any PREGAP for track 1 is properly
1676 # handled, although cue files embedded in FLAC files do not
1677 # appear to properly store the PREGAP setting. :(
1678 abcde.cue2discid () {
1683 while [ $val -gt 0 ] ; do
1684 ret=$(( $ret + ( $val % 10) ))
1685 val=$(( $val / 10 ))
1695 local first second third
1696 first=$(expr ${1} + 0 )
1697 second=$(expr ${2} + 0 )
1698 third=$(expr ${3} + 0 )
1700 echo $(( ((($first * 60) + $second) * 75) + $third ))
1710 while read line ; do
1713 TRACK) i=$(( i + 1 ))
1715 INDEX) if [ "$2" -eq 1 ] ; then
1717 START=$(( $LBA + $PREGAP + $OFFSET ))
1719 X=$(cddb_sum $(( $START / 75 )) )
1723 PREGAP) PREGAP=$(msf2lba $2)
1727 LEADOUT=$(( $4 / 588 ))
1730 LEADIN=$(( $3 / 588 ))
1739 LEADOUT=$(( $LEADOUT + $LEADIN ))
1741 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1742 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1743 printf "%08x %i" $DISCID $TRACKS
1746 while [ $j -le $TRACKS ] ; do
1747 eval echo -n "\" \$TRACK$j\""
1750 echo " $(( $LEADOUT / 75 ))"
1754 # abcde.mkcue [--wholedisk]
1755 # This creates a cuefile directly from the extended discid information
1756 # The --wholedisk option controls whether we're ripping data from the
1757 # start of track one or from the start of the disk (usually, but not
1758 # always the same thing!)
1760 # Track one leadin/pregap (if any) handeling:
1761 # --wholedisk specified:
1764 # INDEX 01 <pregap value>
1765 # Remaining track index values unchanged from disc TOC
1767 # --wholedisk not specified
1769 # PREGAP <pregap value>
1771 # Remaining track index values offset by <pregap value>
1778 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1781 local MODE DISCID TRACKS
1785 if [ "$1" = --wholedisc ] ; then
1791 vecho "One track is $ONETRACK"
1792 TRACKFILE="$(mungefilename "$TRACKNAME")"
1793 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1794 ALBUMFILE="$(mungefilename "$DALBUM")"
1795 if [ "$ONETRACK" = "y" ]; then
1796 if [ "$VARIOUSARTISTS" = "y" ]; then
1797 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1799 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1801 vecho "Cue wav file is $CUEWAVFILE"
1803 CUEWAVFILE="dummy.wav"
1812 echo REM DISCID $DISCID
1813 echo FILE \""$CUEWAVFILE"\" WAVE
1815 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1822 while [ $i -le "$TRACKS" ] ; do
1823 LBA=$(( $1 - $OFFSET ))
1824 printf " TRACK %02i AUDIO\n" $i
1825 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1826 if [ $MODE = PREGAP ] ; then
1827 echomsf " PREGAP " $(($OFFSET-150))
1829 echo " INDEX 00 00:00:00"
1832 echomsf " INDEX 01 " $LBA
1839 # This essentially the start of things
1842 # Query the CD to get the track info, unless the user specified -C
1843 # or we are using some actions which do not need the CDDB data at all
1844 #if [ ! X"$EXPACTIONS" = "X" ]; then
1846 #elif [ -z "$DISCID" ]; then
1847 if [ -z "$DISCID" ]; then
1848 vecho -n "Getting CD track info... "
1849 # In OSX, unmount the disc before a query
1850 if [ "$OSFLAVOUR" = "OSX" ]; then
1851 diskutil unmount ${CDROM#/dev/}
1853 case "$CDROMREADERSYNTAX" in
1855 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1856 case "$CUE2DISCID" in
1857 # FIXME # right now we have 2 cue2discid internal
1858 # implementations: builtin and abcde.cue2discid. Test
1859 # both of them and decide which one we want to use.
1861 #vecho "Using builtin cue2discid implementation..."
1862 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1864 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1866 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1867 TRACKS=${#OFFSETTIMES[@]}
1869 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1870 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1871 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1872 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1875 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1876 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1880 #vecho "Using external python cue2discid implementation..."
1881 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1885 log error "the input flac file does not contain a cuesheet."
1890 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1892 # if [ ! "$RET" = "0" ];then
1893 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1896 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1897 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1899 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1900 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1904 case "$CDDBMETHOD" in
1905 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1906 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1910 # Make sure there's a CD in there by checking cd-discid's return code
1911 if [ ! "$?" = "0" ]; then
1912 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1913 log error "cuesheet information from the flac file could not be read."
1914 log error "Perhaps the flac file does not contain a cuesheet?."
1917 log error "CD could not be read. Perhaps there's no CD in the drive?"
1921 # In OSX, remount the disc again
1922 if [ "$OSFLAVOUR" = "OSX" ]; then
1923 diskutil mount ${CDROM#/dev/}
1926 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1928 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1931 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1932 # This needs to be done now because a section of the resuming code will need
1935 # get the number of digits to pad TRACKNUM with - we'll use this later
1936 # a CD can only hold 99 tracks, but since we support a feature for starting
1937 # numbering the tracks from a given number, we might need to set it as a
1938 # variable for the user to define... or obtain it somehow.
1939 if [ "$PADTRACKS" = "y" ] ; then
1943 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1944 if [ -z "$TRACKQUEUE" ]; then
1945 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1946 case "$CDROMREADERSYNTAX" in
1947 cdparanoia|libcdio|debug)
1948 if [ "$WEHAVEACD" = "y" ]; then
1949 vecho "Querying the CD for audio tracks..."
1950 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1952 if [ ! "$RET" = "0" ];then
1953 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1955 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1956 CDPARANOIAAUDIOTRACKS="$TRACKS"
1958 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1959 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1960 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1961 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1963 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1964 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1968 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1971 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1973 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1974 log info "The disc does not contain any tracks. Giving up..."
1977 echo -n "Grabbing entire CD - tracks: "
1978 if [ ! "$PADTRACKS" = "y" ] ; then
1979 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1981 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1983 while [ "$X" -ne "$TRACKS" ]
1985 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1986 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1990 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1991 # User-supplied track queue.
1992 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1993 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1994 # Once cleaned, obtain the highest value in the trackqueue for number padding
1995 for LASTTRACK in $TRACKQUEUE; do :; done
1996 if [ ! "$PADTRACKS" = "y" ] ; then
1997 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1999 # Now we normalize the trackqueue
2000 for TRACK in $TRACKQUEUE ; do
2001 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2002 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2004 TRACKQUEUE=$PADTRACKQUEUE
2005 echo Grabbing tracks: "$TRACKQUEUE"
2008 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2010 # We have the discid, create a temp directory after it to store all the temp
2013 if [ -e "$ABCDETEMPDIR" ]; then
2014 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2015 # It already exists, see if it's a directory
2016 if [ ! -d "$ABCDETEMPDIR" ]; then
2017 # This is a file/socket/fifo/device/etc, not a directory
2020 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2021 echo "Please investigate, remove it, and rerun abcde." >&2
2025 # It's a directory, let's see if it's writable by us
2026 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2027 # Nope, complain and exit
2029 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2030 echo "Please investigate, remove it, and rerun abcde." >&2
2034 # See if it's populated
2035 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2036 # Wipe and start fresh
2037 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2038 echo -n "this directory to continue. Continue [y/N]? " >&2
2039 if [ "$INTERACTIVE" = "y" ]; then
2045 if [ "$ANSWER" != "y" ]; then
2048 rm -rf "$ABCDETEMPDIR" || exit 1
2049 mkdir -p "$ABCDETEMPDIR"
2050 if [ "$?" -gt "0" ]; then
2051 # Directory already exists or could not be created
2052 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2056 # Everything is fine. Check for ^encodetracklocation-
2057 # and encode-output entries in the status file and
2058 # remove them. These are not relevant across sessions.
2059 if [ -f "$ABCDETEMPDIR/status" ]; then
2060 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2061 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2062 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2064 # Remove old error messages
2065 if [ -f "$ABCDETEMPDIR/errors" ]; then
2066 rm -f "$ABCDETEMPDIR/errors"
2070 # We are starting from scratch
2071 mkdir -p "$ABCDETEMPDIR"
2072 if [ "$?" -gt "0" ]; then
2073 # Directory already exists or could not be created
2074 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2077 cat /dev/null > "$ABCDETEMPDIR/status"
2078 # Store the abcde version in the status file.
2079 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2081 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2082 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2083 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2084 vecho "Creating cue file..."
2085 case $CDROMREADERSYNTAX in
2087 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2088 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2090 log warning "the input flac file does not contain a cuesheet."
2094 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2095 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2097 log warning "reading the CUE sheet is still considered experimental"
2098 log warning "and there was a problem with the CD reading. abcde will continue,"
2099 log warning "but consider reporting the problem to the abcde author"
2105 # If we got the CDPARANOIA status and it is not recorded, save it now
2106 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2107 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2108 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2112 # Create the discid file
2113 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2114 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2115 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2120 # Create a proper CUE file based on the CUE file we created before.
2123 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2124 CUEFILE_OUT=$CUEFILE_IN.out
2125 ### FIXME ### checkstatus cddb
2126 if [ -e "$CDDBDATA" ]; then
2127 vecho "Adding metadata to the cue file..."
2128 # FIXME It doesn't preserve spaces! Why?
2129 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2131 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2132 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2133 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2137 cat "$CUEFILE_IN" | while read line
2139 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2140 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2141 # echo "$line" >> "$CUEFILE_OUT"
2142 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2143 eval track="\$TRACK$n"
2145 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2146 # When making a single-track rip, put the
2147 # actual file name into the file declaration
2148 # in the cue file so that it is usable by
2149 # music players and the like
2150 elif [ "$ONETRACK" = "y" ] &&
2151 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2153 TRACKFILE="$(mungefilename "$TRACKNAME")"
2154 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2155 ALBUMFILE="$(mungefilename "$DALBUM")"
2157 if [ "$VARIOUSARTISTS" = "y" ]; then
2158 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2160 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2163 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2166 # FIXME # If the lines above are uncommented, remove the line below.
2167 echo "$line" >> "$CUEFILE_OUT"
2170 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2171 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2177 # Parses a CDDB file and outputs the title and the track names.
2178 # Variables: CDDBFILE
2182 # List out disc title/author and contents
2183 if [ "$ONETRACK" = "y" ]; then
2184 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2186 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2187 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2188 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2189 if [ ! X"$PARSEDYEAR" = "X" ]; then
2190 echo "Year: $PARSEDYEAR"
2193 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2194 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2195 if [ ! X"$PARSEDGENRE" = "X" ]; then
2196 echo "Genre: $PARSEDGENRE"
2199 if [ ! "$ONETRACK" = "y" ]; then
2200 for TRACK in $(f_seq_row 1 $TRACKS)
2202 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2208 # Check for a local CDDB file, and report success
2211 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2213 CDDBLOCALSTATUS="notfound"
2214 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2217 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2218 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2219 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2220 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2221 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2222 CDDBLOCALMATCH=single
2223 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2224 CDDBLOCALMATCH=multiple
2229 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2230 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2231 CDDBLOCALMATCH=single
2236 # If the user has selected to check a local CDDB repo, we proceed with it
2237 case $CDDBLOCALMATCH in
2239 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2241 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2243 # List out disc title/author and contents
2244 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2245 cat "$RESULT" > "${CDDBLOCALREAD}"
2248 do_cddbparse "${CDDBLOCALREAD}"
2250 ##FIXME## QUICK HACK !!!!
2251 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2252 } >> "$ABCDETEMPDIR/cddblocalchoices"
2254 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2255 page "$ABCDETEMPDIR/cddblocalchoices"
2257 # It's all going to fit in one page, cat it
2258 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2260 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2261 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2262 CDDBLOCALCHOICENUM=-1
2263 if [ "$INTERACTIVE" = "y" ]; then
2264 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2265 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2266 read CDDBLOCALCHOICE
2267 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2268 # FIXME # Introduce diff's
2269 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2270 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2271 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2272 # Make sure we get a valid choice
2273 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2274 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2275 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2281 #echo "Selected ..."
2283 CDDBLOCALCHOICENUM=1
2285 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2286 #echo "Using local copy of CDDB data"
2287 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2288 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2289 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2290 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2291 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2292 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2293 CDDBLOCALSTATUS="found"
2295 #echo "Not using local copy of CDDB data"
2296 CDDBLOCALSTATUS="notfound"
2300 # List out disc title/author and contents
2301 do_cddbparse "${CDDBLOCALFILE}"
2302 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2303 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2305 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2307 if [ "$INTERACTIVE" = "y" ]; then
2309 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2310 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2313 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2317 if [ "$USELOCALRESP" = "y" ]; then
2318 #echo "Using local copy of CDDB data"
2319 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2320 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2321 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2322 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2323 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2324 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2325 CDDBLOCALSTATUS="single"
2327 #echo "Not using local copy of CDDB data"
2328 CDDBLOCALSTATUS="notfound"
2332 CDDBLOCALSTATUS="notfound"
2339 # Try to read CD-Text from the drive using icedax / cdda2wav
2342 if new_checkexec icedax; then
2343 CDTEXT_READER=icedax
2344 elif new_checkexec cdda2wav; then
2345 CDTEXT_READER=cdda2wav
2347 # Didn't find either, bail
2351 if [ "$OSFLAVOUR" = "OSX" ] ; then
2352 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2353 diskutil unmount ${CDROM#/dev/}
2354 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2355 CDDA2WAVCDROM="IODVDServices"
2356 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2357 CDDA2WAVCDROM="$CDROMID"
2359 if [ "$CDROMID" = "" ]; then
2360 CDDA2WAVCDROM="$CDROM"
2362 CDDA2WAVCDROM="$CDROMID"
2366 # Do we have CD-Text on the disc (and can the drive read it?)
2367 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2368 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2370 if [ $ERRORCODE -ne 0 ]; then
2371 # No CD-Text found, bail
2375 rm -f "$ABCDETEMPDIR/cddbchoices"
2377 # Make an empty template
2378 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2379 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2380 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2381 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2382 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2383 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2384 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2385 # List out disc title/author and contents
2386 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2387 for TRACK in $(f_seq_row 1 $TRACKS)
2389 TRACKM1=$(($TRACK - 1))
2390 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2391 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2392 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2393 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2395 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2396 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2397 echo >> "$ABCDETEMPDIR/cddbchoices"
2398 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2402 # Work with the musicbrainz WS API, then transform the results here so
2403 # they look (very) like the results from CDDB. Maybe not the best way
2404 # to go, but it Works For Me (TM)
2408 if checkstatus musicbrainz-readcomplete; then :; else
2409 vecho "Obtaining Musicbrainz results..."
2410 # If MB is to be used, interpret the query results and read all
2411 # the available entries.
2412 rm -f "$ABCDETEMPDIR/cddbchoices"
2413 CDDBCHOICES=1 # Overridden by multiple matches
2414 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2415 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2417 # The helper script will write disc matches out to
2418 # cddbread.*. Count how many we have
2419 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2420 # No matches. Use the normal cddb template for the user to
2422 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2423 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2424 # List out disc title/author and contents of template
2425 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2427 for TRACK in $(f_seq_row 1 $TRACKS)
2429 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2431 echo >> "$ABCDETEMPDIR/cddbchoices"
2432 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2433 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2434 echo 503 > "$ABCDETEMPDIR/cddbquery"
2436 # We have some matches
2437 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2438 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2440 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2441 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2442 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2443 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2444 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2445 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2446 # List out disc title/author and contents
2447 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2448 for TRACK in $(f_seq_row 1 $TRACKS)
2450 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2452 echo >> "$ABCDETEMPDIR/cddbchoices"
2454 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2455 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2456 for file in "$ABCDETEMPDIR"/cddbread.*
2458 X=$(echo $file | sed 's/^.*cddbread\.//g')
2459 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2460 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2461 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2462 # List out disc title/author and contents
2463 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2464 for TRACK in $(f_seq_row 1 $TRACKS)
2466 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2468 echo >> "$ABCDETEMPDIR/cddbchoices"
2470 echo "." >> "$ABCDETEMPDIR/cddbquery"
2473 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2480 # Perform CDDB protocol version check if it hasn't already been done
2481 if checkstatus cddb-statcomplete; then :; else
2482 if [ "$CDDBAVAIL" = "n" ]; then
2484 echo 503 > "$ABCDETEMPDIR/cddbstat"
2487 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2488 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2489 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2490 vecho "Checking CDDB server status..."
2491 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2492 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2493 case "$RESPONSECODE" in
2494 210) # 210 OK, status information follows (until terminating `.')
2497 501) # 501 Illegal CDDB protocol level: <n>.
2498 CDDBPROTO=`expr $CDDBPROTO - 1`
2500 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2501 # FreeDB TESTCD disc-id is used for query
2502 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2503 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2504 case "$RESPONSECODE" in
2505 2??) # Server responded, everything seems OK
2515 if test $rc -eq 1; then
2519 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2527 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2528 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2530 # Perform CDDB query if it hasn't already been done
2531 if checkstatus cddb-querycomplete; then :; else
2532 if [ "$CDDBAVAIL" = "n" ]; then
2534 echo 503 > "$ABCDETEMPDIR/cddbquery"
2535 # The default CDDBLOCALSTATUS is "notfound"
2536 # This part will be triggered if the user CDDB repo does not
2537 # contain the entry, or if we are not trying to use the repo.
2539 vecho "Querying the CDDB server..."
2540 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2541 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2542 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2548 # no match found in database,
2549 # wget/fetch error, or user requested not to use CDDB
2550 # Make up an error code (503) that abcde
2551 # will recognize in do_cddbread
2552 # and compensate by making a template
2553 echo 503 > "$ABCDETEMPDIR/cddbquery"
2555 *) # strange and unknown error
2556 echo ERRORCODE=$ERRORCODE
2557 echo "abcde: $CDDBTOOL returned unknown error code"
2561 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2568 # If it's not to be used, generate a template.
2569 # Then, display it (or them) and let the user choose/edit it
2570 if checkstatus cddb-readcomplete; then :; else
2571 vecho "Obtaining CDDB results..."
2572 # If CDDB is to be used, interpret the query results and read all
2573 # the available entries.
2574 rm -f "$ABCDETEMPDIR/cddbchoices"
2575 CDDBCHOICES=1 # Overridden by multiple matches
2576 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2577 case "$RESPONSECODE" in
2579 # One exact match, retrieve it
2580 # 200 [section] [discid] [artist] / [title]
2581 if checkstatus cddb-read-1-complete; then :; else
2582 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2583 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2584 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2585 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2586 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2588 # List out disc title/author and contents
2589 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2590 for TRACK in $(f_seq_row 1 $TRACKS)
2592 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2594 echo >> "$ABCDETEMPDIR/cddbchoices"
2598 case "$RESPONSECODE" in
2599 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2600 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2601 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2603 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2604 # List out disc title/author and contents of template
2605 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2607 for TRACK in $(f_seq_row 1 $TRACKS)
2609 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2611 echo >> "$ABCDETEMPDIR/cddbchoices"
2612 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2613 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2616 # Multiple exact, (possibly multiple) inexact matches
2618 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2619 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2620 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2621 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2622 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2624 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2626 vecho -n "Retrieving multiple matches... "
2627 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2628 read DISCINFO # eat top line
2632 if checkstatus cddb-read-$X-complete; then :; else
2633 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2634 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2636 # List out disc title/author and contents
2637 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2638 for TRACK in $(f_seq_row 1 $TRACKS)
2640 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2642 echo >> "$ABCDETEMPDIR/cddbchoices"
2645 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2649 for TRACK in $(f_seq_row 1 $TRACKS)
2651 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2653 echo >> "$ABCDETEMPDIR/cddbchoices"
2654 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2655 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2658 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2665 if checkstatus cddb-edit >/dev/null; then
2666 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2667 VARIOUSARTISTS="$(checkstatus variousartists)"
2668 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2671 if [ "$INTERACTIVE" = "y" ]; then
2672 # We should show the CDDB results both when we are not using the local CDDB repo
2673 # or when we are using it but we could not find a proper match
2674 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2675 # Display the $ABCDETEMPDIR/cddbchoices file created above
2676 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2677 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2678 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2679 CHOICE=$(checkstatus cddb-choice)
2680 if [ -n "$CHOICE" ] ; then
2681 case $CDDBCHOICES in
2682 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2683 log error "CDDB query failed!"
2686 cat "$ABCDETEMPDIR/cddbchoices"
2689 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2691 echo "Selected: #$CHOICE"
2692 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2696 # The user has a choice to make, display the info in a pager if necessary
2697 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2698 page "$ABCDETEMPDIR/cddbchoices"
2700 # It's all going to fit in one page, cat it
2701 cat "$ABCDETEMPDIR/cddbchoices" >&2
2705 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2707 # I'll take CDDB read #3 for $400, Alex
2708 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2709 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2711 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2712 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2713 if [ ! X"$DIFF" = "X" ]; then
2714 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2715 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2716 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2717 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2718 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2719 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2721 # We parse the 2 choices to diff, store them in temporary files and diff them.
2722 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2723 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2725 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2726 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2727 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2728 page "$ABCDETEMPDIR/cddbread.diff"
2730 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2734 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2736 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2737 # Make sure we get a valid choice
2738 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2739 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2740 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2744 if [ "$CDCHOICENUM" = "0" ]; then
2745 vecho "Creating empty CDDB template..."
2747 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2749 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2750 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2752 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2756 # We need some code to show the selected option when local repository is selected and we have found a match
2757 vecho "Using cached CDDB match..." >&2
2758 # Display the $ABCDETEMPDIR/cddbchoices file created above
2759 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2760 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2761 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2762 CHOICE=$(checkstatus cddb-choice)
2763 if [ "$USELOCALRESP" = "y" ]; then :; else
2764 if [ -n "$CHOICE" ] ; then
2765 case $CDDBCHOICES in
2768 echo "Selected template."
2770 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2772 echo "Selected: #$CHOICE"
2773 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2781 # We're noninteractive - pick the first choice.
2782 # But in case we run a previous instance and selected a choice, use it.
2783 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2784 # Show the choice if we are not using the locally stored one
2785 # or when the local search failed to find a match.
2786 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2787 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2788 #if [ "$PREVIOUSCHOICE" ]; then
2789 cat "$ABCDETEMPDIR/cddbchoices"
2792 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2793 CDCHOICENUM=$PREVIOUSCHOICE
2796 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2798 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2803 if checkstatus cddb-choice >/dev/null; then :; else
2804 echo "abcde: internal error: cddb-choice not recorded." >&2
2807 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2808 echo -n "Edit selected CDDB data " >&2
2809 if [ "$INTERACTIVE" = "y" ]; then
2810 if [ "$UNKNOWNDISK" = "y" ]; then
2811 echo -n "[Y/n]? " >&2
2813 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2815 echo -n "[y/N]? " >&2
2822 if [ "$EDITCDDB" = "y" ]; then
2823 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2825 # Use the debian sensible-editor wrapper to pick the editor that the
2826 # user has requested via their $EDITOR environment variable
2827 if [ -x "/usr/bin/sensible-editor" ]; then
2828 /usr/bin/sensible-editor "$CDDBDATA"
2829 elif [ -n "$EDITOR" ]; then
2830 if [ -x $(which "${EDITOR%%\ *}") ]; then
2831 # That failed, try to load the preferred editor, starting
2832 # with their EDITOR variable
2833 eval $(echo "$EDITOR") \"$CDDBDATA\"
2835 # If that fails, check for a vi
2836 elif which vi >/dev/null 2>&1; then
2838 elif [ -x /usr/bin/vim ]; then
2839 /usr/bin/vim "$CDDBDATA"
2840 elif [ -x /usr/bin/vi ]; then
2841 /usr/bin/vi "$CDDBDATA"
2842 elif [ -x /bin/vi ]; then
2844 # nano should be on all (modern, i.e., sarge) debian systems
2845 elif which nano >/dev/null 2>&1 ; then
2847 elif [ -x /usr/bin/nano ]; then
2848 /usr/bin/nano "$CDDBDATA"
2849 # mg should be on all OpenBSD systems
2850 elif which mg >/dev/null 2>&1 ; then
2852 elif [ -x /usr/bin/mg ]; then
2853 /usr/bin/mg "$CDDBDATA"
2856 log warning "no editor available. Check your EDITOR environment variable."
2858 # delete editor backup file if it exists
2859 if [ -w "$CDDBDATA~" ]; then
2864 # Some heuristics first. Look at Disc Title, and if it starts with
2865 # "Various", then we'll assume Various Artists
2866 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2867 echo "Looks like a Multi-Artist CD" >&2
2870 echo -n "Is the CD multi-artist [y/N]? " >&2
2871 if [ "$INTERACTIVE" = "y" ]; then
2878 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2881 # Need NUMTRACKS before cddb-tool will return it:
2882 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2883 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2884 # More than 1/2 tracks contain a "/", so guess forward
2886 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2887 # More than 1/2 contain a "-", so guess forward-dash
2889 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2890 # More than 1/2 contain something in parens, so guess trailing-paren
2894 echo "1) Artist / Title" >&2
2895 echo "2) Artist - Title" >&2
2896 echo "3) Title / Artist" >&2
2897 echo "4) Title - Artist" >&2
2898 echo "5) Artist: Title" >&2
2899 echo "6) Title (Artist)" >&2
2900 echo "7) This is a single-artist CD" >&2
2901 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2902 if [ "$INTERACTIVE" = "y" ]; then
2903 read VARIOUSARTISTSTYLE
2905 echo $DEFAULTSTYLE >&2
2906 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2908 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2909 # If they press Enter, then the default style (0) was chosen
2910 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2911 echo "Invalid selection. Please choose a number between 1 and 7."
2912 echo -n "Selection [1-7]: "
2913 read VARIOUSARTISTSTYLE
2914 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2916 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2917 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2919 vecho "Selected: $VARIOUSARTISTSTYLE"
2920 case "$VARIOUSARTISTSTYLE" in
2922 VARIOUSARTISTSTYLE=forward
2925 VARIOUSARTISTSTYLE=forward-dash
2928 VARIOUSARTISTSTYLE=reverse
2931 VARIOUSARTISTSTYLE=reverse-dash
2934 VARIOUSARTISTSTYLE=colon
2937 VARIOUSARTISTSTYLE=trailing-paren
2945 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2946 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2948 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2949 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2950 # This works but does not have the necessary error checking
2951 # yet. If you are familiar with the CDDB spec
2952 # (see http://www.freedb.org/src/latest/DBFORMAT)
2953 # and can create an error-free entry on your own, then put
2954 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2955 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2956 # your abcde.conf to change the email address submissions are
2959 # submit the modified file, if they want
2960 if [ "$NOSUBMIT" != "y" ]; then
2961 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2963 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2964 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2966 echo -n 'Invalid selection. Please answer "y" or "n": '
2969 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2970 echo -n "Sending..."
2971 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2978 # User CDDBLOCALPOLICY to find out if we store the file or not...
2979 # Cache edited CDDB entry in the user's cddb dir
2980 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2981 # Make sure the cache directory exists
2982 mkdir -p $CDDBLOCALDIR
2983 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2986 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2990 # try to download CD cover
2994 ALBUMFILE="$(mungefilename "$DALBUM")"
2995 ARTISTFILE="$(mungefilename "$DARTIST")"
2996 # have we got a musicbrainz mbid or amazon asin?
2997 case "$CDDBMETHOD" in
2999 # try musicbrainz mbid
3000 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
3001 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
3002 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3003 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3004 vecho "cover URL: $ALBUMARTURL" >&2
3005 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3006 if [ $? -ne 0 ]; then
3007 vecho "could not download cover from musicbrainz" >&2
3009 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3010 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3011 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3012 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3013 vecho "cover URL: $ALBUMARTURL" >&2
3014 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3015 if [ $? -ne 0 ]; then
3016 vecho "could not download cover from amazon" >&2
3018 # Check that size is reasonable; sometimes when there is no cover image
3019 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3020 FILESIZE=$(wc -c < "$ABCDETEMPDIR/$ALBUMARTFILE")
3021 if [ "$FILESIZE" -lt 1024 ]; then
3022 rm "$ABCDETEMPDIR/$ALBUMARTFILE"
3023 vecho "could not download cover from amazon" >&2
3027 vecho "no amazon ID found" >&2
3031 vecho "no musicbrainz ID found" >&2
3036 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3037 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3038 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3039 if [ $? -ne 0 ]; then
3040 vecho "could not download cover with glyrc" >&2
3045 if [ "$INTERACTIVE" = "y" ]; then
3046 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3047 # display properties of coverart when identify is available
3048 if new_checkexec $IDENTIFY; then
3049 $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
3051 # display coverart when DISPLAY is set and display command is available
3052 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3053 $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
3056 # nothing downloaded yet
3057 vecho "automatic album art downloading failed" >&2
3059 # see if the user can find a better album art manually
3060 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3062 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3063 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3065 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3068 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3069 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3071 if [ ! -z "$ALBUMARTURL" ]; then
3072 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3073 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3074 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3075 vecho "unable to download $ALBUMARTURL" >&2
3077 else # it's a local path
3078 cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
3079 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3080 vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
3086 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3087 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3088 ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
3089 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3090 if new_checkexec $CONVERT; then
3091 mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3092 $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
3093 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3095 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3096 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3100 # copy to target directories
3101 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3102 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3104 # put cover in the same place as the album
3105 if [ "$VARIOUSARTISTS" = "y" ] ; then
3106 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3108 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3110 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3111 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3112 mkdir -p "$FINALALBUMARTDIR"
3113 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3115 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3116 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3118 log warning "could not get cover"
3119 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3123 # do_cdread [tracknumber]
3124 # do_cdread onetrack [firsttrack] [lasttrack]
3128 # The commands here don't go through run_command because they're never supposed to be silenced
3129 # return codes need to be doublechecked anyway, however
3130 if [ "$1" = "onetrack" ]; then
3131 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3132 # FIXME # Until then, we grab the whole CD in one track, no matter what
3134 # We need the first and last track for cdda2wav/icedax
3136 LASTTRACK=$(expr $3 + 0)
3137 UTRACKNUM=$FIRSTTRACK
3138 case "$CDROMREADERSYNTAX" in
3139 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
3142 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
3143 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
3144 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3145 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3146 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3152 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3153 if [ "$USEPIPES" = "y" ]; then
3154 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3155 FILEARG="$( eval echo "\$$TEMPARG" )"
3157 PIPE_MESSAGE="and encoding "
3159 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3160 case "$CDROMREADERSYNTAX" in
3161 ## FIXME ## Find the cases for flac, to avoid exceptions
3163 FILEARG="--output-name=$WAVDATA"
3171 if [ "$1" = "onetrack" ]; then
3172 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3174 if [ -r "$CDDBDATA" ]; then
3175 getcddbinfo TRACKNAME
3176 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3178 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3181 case "$CDROMREADERSYNTAX" in
3182 ### FIXME ### use an exception for flac, since it uses -o
3183 ### FIXME ### Shall we just use -o $FILEARG ??
3185 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3186 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3187 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3189 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3191 if [ "$OSFLAVOUR" = "OSX" ] ; then
3192 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3193 diskutil unmount ${CDROM#/dev/}
3194 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3195 CDDA2WAVCDROM="IODVDServices"
3196 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3197 CDDA2WAVCDROM="$CDROMID"
3199 if [ "$CDROMID" = "" ]; then
3200 CDDA2WAVCDROM="$CDROM"
3202 CDDA2WAVCDROM="$CDROMID"
3205 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3206 dagrab) nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2 ;;
3208 if [ "$USEPIPES" = "y" ]; then
3209 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3211 # Write ripped audio data to stdout and redirect to $FILEARG.
3212 # $REDIR can be ignored. Progress is written to stderr by default.
3213 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3217 # Find the track's mounted path
3218 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3219 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3220 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3221 # If the file exists, copy it
3222 if [ -e "$FILEPATH" ] ; then
3223 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
3227 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" $REDIR ;;
3230 # If we get some error or we get some missing wav
3231 # (as long as we dont use pipes)
3232 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3233 # Thank goodness errors is only machine-parseable up to the
3234 # first colon, otherwise this woulda sucked
3235 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3236 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3238 if [ "$USEPIPES" = "y" ]; then
3239 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3241 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3245 if [ "$USEPIPES" = "y" ]; then
3246 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3248 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3250 if [ "$1" = "onetrack" ]; then
3251 echo onetrack >> "$ABCDETEMPDIR/status"
3257 # No values accepted, only uses env variables
3260 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3261 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3263 echo "abcde: unable to set the device speed" >&2
3269 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3272 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3274 warning) shift ; log warning "$@" ;;
3282 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3285 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3287 warning) shift ; log warning "$@" ;;
3295 # decho outputs a debug message if DEBUG is selected
3298 if [ x"$DEBUG" != "x" ]; then
3299 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3300 DEBUGECHO=$(echo "$@" | tr -d '[]')
3301 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3303 echo >&4 "[DEBUG] $1"
3308 # User-redefinable functions
3309 # Custom filename munging:
3312 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
3313 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
3316 # Custom genre munging:
3319 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3323 # Empty pre_read function, to be defined in the configuration file.
3330 # Empty post_read function, to be defined in the configuration file.
3337 # Empty post_encode function, to be defined in the configuration file.
3343 ###############################################################################
3346 # Start of execution
3347 ###############################################################################
3352 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3354 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3355 CDDBSUBMIT=freedb-submit@freedb.org
3357 HELLOINFO="$(whoami)@$(hostname)"
3359 CDDBLOCALPOLICY="always"
3360 CDDBLOCALRECURSIVE="y"
3361 CDDBLOCALDIR="$HOME/.cddb"
3364 # List of fields we parse and show during the CDDB parsing...
3365 SHOWCDDBFIELDS="year,genre"
3368 #CDROMREADERSYNTAX=cdparanoia
3369 ENCODERSYNTAX=default
3371 MP3ENCODERSYNTAX=default
3372 OGGENCODERSYNTAX=default
3373 OPUSENCODERSYNTAX=default
3374 FLACENCODERSYNTAX=default
3375 SPEEXENCODERSYNTAX=default
3376 MPCENCODERSYNTAX=default
3377 WVENCODERSYNTAX=default
3378 APENCODERSYNTAX=default
3379 AACENCODERSYNTAX=default
3380 NORMALIZERSYNTAX=default
3381 CUEREADERSYNTAX=default
3383 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3384 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3385 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3386 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3387 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3388 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3389 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3390 PLAYLISTDATAPREFIX=''
3391 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3392 VAPLAYLISTDATAPREFIX=''
3400 VARIOUSARTISTSTYLE=forward
3407 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3408 # i.e. CDROMID="1,0,0"
3410 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3411 # If we are using the ide-scsi emulation layer, we need to define a "g"
3412 CDPARANOIACDROMBUS="d"
3414 # program paths - defaults to checking your $PATH
3421 XINGMP3ENC=xingmp3enc
3441 NEROAACENC=neroAacEnc
3447 VORBISCOMMENT=vorbiscomment
3449 NEROAACTAG=neroAacTag
3451 CDPARANOIA=cdparanoia
3452 CD_PARANOIA=cd-paranoia
3459 MUSICBRAINZ=abcde-musicbrainz-tool
3463 NORMALIZE=normalize-audio
3465 VORBISGAIN=vorbisgain
3469 # For Wavpack replay gain we set both the default of 'track gain'
3470 # as well as this option for 'album gain'. Better media players
3471 # such as vlc can select either or neither. Andrew.
3482 # Options for programs called from abcde
3495 VORBISGAINOPTS="--album"
3499 # The flac option is a workaround for an error where flac fails
3500 # to encode with error 'floating point exception'. This is flac
3501 # error in get_console_width(), corrected in flac 1.3.1
3503 FLACGAINOPTS="--add-replay-gain"
3511 # Monkey's Audio Console (mac) chokes without a mode setting
3512 # so we set one here.
3517 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3518 # we set bitrate here.
3519 FDKAACENCOPTS='--bitrate 192k'
3536 VORBISCOMMENTOPTS="-R"
3537 METAFLACOPTS="--no-utf8-convert"
3542 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3544 # Defaults for album art downloads
3545 ALBUMARTFILE="cover.jpg"
3547 ALBUMARTALWAYSCONVERT="n"
3549 # Default to one process if -j isn't specified
3552 # List of actions to perform - by default, run to completion
3553 ACTIONS=cddb,read,encode,tag,move,clean
3555 # This option is basically for Debian package dependencies:
3556 # List of preferred outputs - by default, run with whatever we have in the path
3557 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
3559 # List of preferred cdromreaders - by default, run whichever we have in the path
3560 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3562 # fd for when `vecho` and `log info` called with redirected stdout
3565 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3566 # Linux/OpenBSD. ftp is user for NetBSD.
3567 # Let's use these checkings to determine the OS flavour, which will be used
3569 if [ X$(uname) = "XFreeBSD" ] ; then
3574 elif [ X$(uname) = "XDarwin" ] ; then
3577 # We should have diskutil in OSX, but let's be sure...
3579 CDROMREADERSYNTAX=cddafs
3580 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3582 elif [ X$(uname) = "XOpenBSD" ] ; then
3586 elif [ X$(uname) = "XNetBSD" ] ; then
3590 elif [ X$(uname) = "SunOS" ] ; then
3598 # If CDDBAVAIL is set to n, no CDDB read is done
3602 # But before we get into business, let us chop off any GREP environmental
3607 if [ -z "$OUTPUTDIR" ]; then
3611 if [ -z "$WAVOUTPUTDIR" ]; then
3612 WAVOUTPUTDIR="$OUTPUTDIR"
3615 # Load system defaults
3616 if [ -r /etc/abcde.conf ]; then
3619 # Load user preference defaults
3620 if [ -r $HOME/.abcde.conf ]; then
3624 # By this time, we need some HTTPGETOPTS already defined.
3625 # If the user has defined a non-default HTTPGET method, we should not be empty.
3627 if [ "$HTTPGETOPTS" = "" ] ; then
3629 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3630 curl) HTTPGETOPTS="-f -s";;
3631 fetch)HTTPGETOPTS="-q -o -";;
3632 ftp) HTTPGETOPTS="-a -V -o - ";;
3633 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3637 # If the CDROM has not been set yet, find a suitable one.
3638 # If this is a devfs system, default to /dev/cdroms/cdrom0
3639 # instead of /dev/cdrom
3640 if [ "$CDROM" = "" ] ; then
3641 if [ -e /dev/cdroms/cdrom0 ]; then
3642 CDROM=/dev/cdroms/cdrom0
3643 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3644 CDROM=/dev/${BASH_REMATCH[1]}
3645 elif [ -e /dev/cdrom ]; then
3647 elif [ -e /dev/sr0 ]; then
3649 elif [ -e /dev/cd0c ]; then
3651 elif [ -e /dev/acd0c ]; then
3653 elif [ -e /dev/disk1 ]; then
3658 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3659 # that's changed to a number to allow for more control. Deal with
3660 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3661 case "$EXTRAVERBOSE" in
3670 # Parse command line options
3671 while getopts 1a:bc:C:d:DefgGhj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3674 a) ACTIONS="$OPTARG" ;;
3675 A) EXPACTIONS="$OPTARG" ;;
3677 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3678 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3679 d) CDROM="$OPTARG" ;;
3682 e) ERASEENCODEDSTATUS=y ;;
3683 E) ENCODING="$OPTARG" ;;
3688 j) MAXPROCS="$OPTARG" ;;
3691 L) CDDBUSELOCAL=y ;;
3696 o) OUTPUTTYPE="$OPTARG" ;;
3699 r) REMOTEHOSTS="$OPTARG" ;;
3700 R) CDDBLOCALRECURSIVE=y ;;
3701 s) SHOWCDDBFIELDS="$OPTARG" ;;
3702 S) CDSPEEDVALUE="$OPTARG" ;;
3703 t) STARTTRACKNUMBER="$OPTARG" ;;
3704 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3707 echo "This is abcde v$VERSION."
3708 echo "Usage: abcde [options] [tracks]"
3709 echo "abcde -h for extra help"
3712 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3714 X) CUE2DISCID="$OPTARG" ;;
3715 w) COMMENT="$OPTARG" ;;
3716 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3717 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
3718 STARTTRACKNUMBERTAG="y"
3719 COMMENT="CD${OPTARG}"
3720 DISCNUMBER="${OPTARG}"
3722 log error "argument of -W must be integer"
3726 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3731 shift $(($OPTIND - 1))
3733 # Here it comes the worse part of the whole thing. From here until we start
3734 # ripping, we have a mixture of sanity checks, verifications, default settigs
3735 # and other crazy stuff that interdepends, but hey, someone has to do it.
3737 # If NOCDDBQUERY is set, don't query the CDDB server.
3738 if [ "$NOCDDBQUERY" = "y" ]; then
3742 # If the user specified a flac file, then switch to special flac mode
3743 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3744 if [ ! -f "$CDROM" ]; then
3745 log error "the defined file for FLAC ripping cannot be found" >&2
3748 vecho warning "switching to flac CDROMREADERSYNTAX..."
3749 CDROMREADERSYNTAX=flac
3750 # We have a builtin version of cue2discid...
3751 case "$CUE2DISCID" in
3753 *) NEEDCUE2DISCID=y;;
3759 # If the user provided a DISCID, disable eject
3760 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3762 # Check the available cd rippers in the system, from the ones we know.
3763 if [ "$CDROMREADERSYNTAX" = "" ]; then
3764 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3765 if new_checkexec $DEFAULT_CDROMREADER; then
3766 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3770 if [ "$CDROMREADERSYNTAX" = "" ]; then
3771 log error "no cdreader found in your PATH"
3772 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3777 # Decide if we can continue.
3778 if [ "$ONETRACK" = "y" ]; then
3779 # FIXME # remove check as soon as we find out about the other readers
3780 case "$CDROMREADERSYNTAX" in
3782 cdparanoia | libcdio) ;;
3783 cdda2wav | icedax) ;;
3785 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3788 if [ "$BATCHNORM" = "y" ]; then
3789 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3792 if [ "$NOGAP" = "y" ]; then
3793 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3796 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3797 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3798 if [ $# -gt 0 ]; then
3799 log warning "ONETRACK mode selected, grabbing all tracks..."
3802 while [ $# -gt 0 ]; do
3803 # Range parsing code courtesy of Vincent Ho
3804 # Cleaned up to use shell built-ins by Charles Steinkuehler
3805 if [ "${1#*[^0-9-]}" != "$1" ]; then
3806 log error "syntax error while processing track numbers ($1)"
3811 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3812 TRACKQUEUE="$TRACKQUEUE $RSTART"
3813 RSTART=$(( $RSTART + 1 ))
3820 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3821 # List of experimental actions: retag,transcode
3823 # Determine what actions are to be done from $ACTIONS and set the
3824 # following environment variables for them:
3836 ## FIXME ## Lets keep compatibility with -M
3837 [ "$DOCUE" != "y" ] && DOCUE=n
3839 for ACTION in $(echo $ACTIONS | tr , \ )
3842 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
3843 cue) DOCUE=y ; MAKECUEFILE=y ;;
3846 normalize) DONORMALIZE=y; DOREAD=y;;
3847 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3848 encode) DOENCODE=y; DOREAD=y;;
3849 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3850 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3851 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3852 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
3853 playlist) DOCDDB=y; DOPLAYLIST=y;;
3855 getalbumart) GETALBUMART=y;;
3859 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3860 # FIXME # should we abort on error or just inform the user?
3861 log warning "selected both normalize and replaygain actions"
3864 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
3865 case $SHOWCDDBFIELD in
3866 y*|Y*) SHOWCDDBYEAR="y";;
3867 g*|G*) SHOWCDDBGENRE="y";;
3872 # At this point a CDROM has to be defined, so we check it exists.
3873 if [ X"$CDROM" != "X" ] ; then
3874 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
3875 if [ "$OSFLAVOUR" = "FBSD" ]; then
3876 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
3877 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
3878 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
3882 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
3883 log error "CDROM device cannot be found."
3886 # avoid processing if we are not going to hit the CDROM.
3887 elif [ X"$DOREAD" = "Xy" ]; then
3888 log error "CDROM has not been defined or cannot be found"
3892 # USEPIPES pre-tests, before we get into more serious stuff
3893 # Not compatible with:
3894 # - multiple outputs
3896 # - lowdisk algorithm
3898 if [ X"$USEPIPES" = "Xy" ]; then
3899 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
3900 log error "Unix pipes not compatible with multiple outputs"
3903 if [ X"$DONORMALIZE" = "Xy" ]; then
3904 log error "Unix pipes not compatible with normalizer"
3905 # FIXME # Do we need to exit or shall we just disable the mode?
3908 if [ X"$BATCHNORM" = "Xy" ]; then
3909 log error "Unix pipes not compatible with BATCHNORM encoding"
3912 if [ X"$NOGAP" = "Xy" ]; then
3913 log error "Unix pipes not compatible with NOGAP encoding"
3916 if [ X"$DOENCODE" = "Xn" ]; then
3917 vecho warning "Disabling Unix pipes since we are not encoding!"
3920 if [ X"$LOWDISK" = "Xy" ]; then
3921 log error "Unix pipes not compatible with lowdisk algorithm"
3926 # LOWDISK pre-tests, before we get into more problematic stuff
3927 # Not compatible with anything that needs all the files in the hard disc:
3930 if [ X"$LOWDISK" = "Xy" ]; then
3931 if [ X"$BATCHNORM" = "Xy" ]; then
3932 log error "Unix pipes not compatible with BATCHNORM encoding"
3935 if [ X"$NOGAP" = "Xy" ]; then
3936 log error "Unix pipes not compatible with NOGAP encoding"
3941 # BATCHNORM pre-tests, before we get into serious problems
3942 # Not compatible with
3943 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3944 vecho warning "Disabling BATCHNORM since we are not normalizing!"
3948 # Check the encoding format from the ones available in the system, if nothing has been configured.
3949 if [ X"$OUTPUTTYPE" = "X" ]; then
3950 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
3951 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3952 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3953 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
3954 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
3955 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3959 if [ X"$OUTPUTTYPE" = "X" ]; then
3960 log error "no encoder found in the PATH"
3961 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3966 # Decide which CDROM reader we're gonna use
3967 case "$CDROMREADERSYNTAX" in
3969 CDROMREADER="$CDPARANOIA"
3970 CDROMREADEROPTS="$CDPARANOIAOPTS"
3973 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
3974 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
3975 CDROMREADER="$CD_PARANOIA"
3976 CDROMREADEROPTS="$CDPARANOIAOPTS"
3979 CDROMREADER="$CDDA2WAV"
3980 CDROMREADEROPTS="$CDDA2WAVOPTS"
3983 CDROMREADER="$DAGRAB"
3984 CDROMREADEROPTS="$DAGRABOPTS"
3988 CDROMREADEROPTS="$PIRDOPTS"
3991 CDROMREADER="$CDDAFS"
3992 CDROMREADEROPTS="$CDDAFSOPTS"
3996 CDROMREADEROPTS="$FLACOPTS"
4000 # There's only one normalize...
4001 case "$NORMALIZERSYNTAX" in
4003 NORMALIZER="$NORMALIZE"
4004 NORMALIZEROPTS="$NORMALIZEOPTS"
4008 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4009 case "$OUTPUTTYPE" in *:*)
4010 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4011 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4013 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4014 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4015 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4016 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4017 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4018 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4019 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4020 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4021 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4024 # Allows commandline selection of options while using multiple outputs.
4025 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4026 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4027 TEMPOUTPUT=${OUTPUT%%:*}
4028 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4030 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4034 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4035 # for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as and
4036 # wavpack for wvs...
4038 # Getting ready for multiple output changes
4039 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4043 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4044 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4045 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4046 OGGOUTPUTCONTAINER=ogg
4049 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4050 OPUSOUTPUTCONTAINER=opus
4053 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4054 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4055 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4058 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4059 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4060 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4061 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4064 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4065 # [ "$DOREPLAYGAIN" = "y" ] &&
4068 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4069 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4072 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4074 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4077 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4078 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4081 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4083 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4084 # compiled without libmp4v2... Andrew.
4087 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4088 [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4089 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4092 if [ "$KEEPWAVS" = "y" ]; then
4093 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4097 *) log error "Invalid OUTPUTTYPE defined"
4103 # decide which encoder
4104 case "$MP3ENCODERSYNTAX" in
4106 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4110 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
4111 MP3ENCODER="$TOOLAME"
4114 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4118 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4119 MP3ENCODER="$BLADEENC"
4122 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4126 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4127 MP3ENCODER="$XINGMP3ENC"
4130 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4131 MP3ENCODER="$MP3ENC"
4134 case "$OGGENCODERSYNTAX" in
4136 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4137 OGGENCODER="$VORBIZE"
4140 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4141 OGGENCODER="$OGGENC"
4144 case "$OPUSENCODERSYNTAX" in
4146 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4147 OPUSENCODER="$OPUSENC"
4150 case "$FLACENCODERSYNTAX" in
4152 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4154 if [ "$DOREPLAYGAIN" = "y" ]; then
4155 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4157 # FLAC streams can be encapsulated on a Ogg transport layer
4158 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4159 log error "FLAC on an Ogg container is not yet supported"
4160 log error "due to problem with adding comments to such files"
4162 FLACOUTPUTCONTAINER=ogg
4164 FLACOUTPUTCONTAINER=flac
4168 case "$SPEEXENCODERSYNTAX" in
4170 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4171 SPEEXENCODER="$SPEEXENC"
4174 case "$MPCENCODERSYNTAX" in
4176 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4177 MPCENCODER="$MPCENC"
4180 case "$WVENCODERSYNTAX" in
4182 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4186 case "$APENCODERSYNTAX" in
4188 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4192 case "$AACENCODERSYNTAX" in
4193 # Some elaborate 'if' work to keep backward compatability for those
4194 # who don't realise that AACENCOPTS does not work with abcde from
4195 # version 2.6.1 onwards.
4197 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4198 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4201 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4206 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4207 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4208 AACENCODER="$NEROAACENC"
4210 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4211 AACENCODER="$NEROAACENC"
4215 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4216 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4217 AACENCODER="$FDKAAC"
4219 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4220 AACENCODER="$FDKAAC"
4230 TAGGEROPTS="$ID3OPTS"
4235 TAGGEROPTS="$ID3V2OPTS"
4239 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4240 # trouble with CDDBPROTO=5 (which we test here) but also
4241 # with cached cddb files in latin1 (which we cannot test).
4242 if [ "$CDDBPROTO" -lt 6 ]; then
4243 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4246 # eyeD3 version 0.7 changed syntax
4247 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4248 # only if it offers the --set-encoding, assume <= 0.6.x
4250 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4252 # anything wrong, any failure, assume >= 0.7
4254 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4258 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4263 # NOGAP is specific to lame. Other encoders fail ...
4264 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4265 log warning "the NOGAP option is specific to lame. Deactivating..."
4270 case "$CUEREADERSYNTAX" in
4272 CUEREADEROPTS="${CDROM}"
4277 # which information retrieval tool are we using?
4283 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4284 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4285 log error "FLAC on an Ogg container is not yet supported"
4286 log error "due to problem with adding comments to such files"
4288 OGGOUTPUTCONTAINER=ogg.ogg
4289 FLACOUTPUTCONTAINER=flac.ogg
4290 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4293 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4295 if [ "$ENCNICE" ]; then
4296 ENCNICE="-n $ENCNICE"
4298 if [ "$READNICE" ]; then
4299 READNICE="-n $READNICE"
4301 if [ "$DISTMP3NICE" ]; then
4302 DISTMP3NICE="-n $DISTMP3NICE"
4305 # Don't check for stuff if it's not needed
4306 if [ "$REMOTEHOSTS" ]; then
4309 if [ "$DONORMALIZE" = "y" ]; then
4312 if [ "$EJECTCD" = "y" ]; then
4315 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4316 if [ "$CDDBMETHOD" = "cddb" ]; then
4318 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4322 if [ "$DOCUE" = "y" ]; then
4326 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4327 case "$CDROMREADERSYNTAX" in
4328 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4329 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4330 ### FIXME ### translate "cue2discid" from python to bash
4331 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4336 if [ "$GETALBUMART" = "y" ]; then
4341 ###USEPIPESSUPPORT###
4343 # Rippers with USEPIPE support
4344 PIPERIPPER_cdparanoia="-"
4345 PIPERIPPER_libcdio="-"
4346 # Note that by default in abcde cdda2wav redirects to icedax.
4347 PIPERIPPER_cdda2wav="-"
4348 PIPERIPPER_debug="-"
4349 PIPERIPPER_flac="-c "
4352 # Encoders with USEPIPE support
4355 PIPE_bladeenc="stdin"
4363 # Both neroAacEnc and fdkaac seem to manage without the addition of
4364 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4365 # in this manner. Andrew.
4369 # Figure out if we can use pipes with the ripper/encoder combination
4371 if [ "$USEPIPES" = "y" ]; then
4372 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4375 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4377 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4379 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4381 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4383 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4385 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4387 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4389 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4391 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4393 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4394 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4395 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4396 log error "no support for pipes with given ripper"
4397 log error "read the FAQ file from the source tarball to get help."
4400 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4401 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4402 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4403 log error "no support for pipes with given encoder"
4404 log error "read the FAQ file from the source tarball to get help"
4409 # Make sure a buncha things exist
4410 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4411 $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4412 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER \
4413 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4414 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4415 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4416 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4417 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4418 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4419 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4420 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4426 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4427 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4428 # these files). The resulting files are actually ADTS streams which belong in an
4429 # aac container and with some version sniffing this is all cleaned up below. If
4430 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4432 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4433 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4434 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4435 echo "WARNING: Your copy of Faac does not have mp4 support"
4436 echo "WARNING: Encoding untagged files to aac..."
4439 echo "Using Faac to Tag AAC Tracks..."
4443 # And last but not least, check if we can diff between files. We do not abort,
4444 # since diffing is not critical...
4445 if [ -x $(which $DIFF) ]; then :; else
4446 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4450 ## Now that we have metaflac, check if we need cue2discid
4451 #case $CDROMREADERSYNTAX in
4453 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4454 # if [ "$TRACKINFO" = "" ]; then
4455 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4460 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4461 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4462 HTTPGET="$HTTPGET $HTTPGETOPTS"
4464 # Here it used to say:
4465 # One thousand lines in, we can start doing stuff with things
4466 # Well, right now we are at line 3737 ;)
4468 # Export needed things so they can be read in this subshell
4469 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4470 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4472 if [ "$DOREAD" = "y" ]; then
4473 # User-definable function to set some things. Use it for
4474 # - closing the CD tray with eject -t
4475 # - set the CD speed value with eject -x
4476 vecho -n "Executing customizable pre-read function... "
4478 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4483 # Get ABCDETEMPDIR created and status file initialized
4486 if [ "$DOCDDB" = "y" ]; then
4487 # start with a sane default:
4488 CDDBLOCALSTATUS=notfound
4489 if [ $CDDBUSELOCAL = "y" ]; then
4492 if checkstatus cddb-choice > /dev/null; then
4495 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4496 case "$CDDBMETHOD" in
4507 CHOICE=$(checkstatus cddb-choice)
4508 if [ "$CHOICE" = 0 ] ; then
4509 # We don't have any information at all; try to fall back
4510 # to CD-Text for basic information
4511 vecho "No CDDB information found, trying cdtext from the CD"
4517 eval "$($CDDBTOOL parse "$CDDBDATA")"
4520 # Before reading tracks, we set the speed of the device
4522 if [ X"$CDSPEEDVALUE" != "X" ]; then
4523 case "$CDROMREADERSYNTAX" in
4524 cdparanoia|libcdio|debug) ;;
4531 # Define the first and last track, since we might need them later in several places
4532 FIRSTTRACK=$( get_first $TRACKQUEUE )
4533 LASTTRACK=$( get_last $TRACKQUEUE )
4535 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4536 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4537 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4538 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4541 if checkstatus onetrack ; then ONETRACK=y ; fi
4543 if [ "$ONETRACK" = "y" ]; then
4544 # Reuse the CUEFILE in case we created it (now or in a previous run)
4545 if CUEFILE=$(checkstatus cuefile); then
4550 # Create playlist if needed (backgroundable) and start reading in tracks
4554 if [ ! "$ONETRACK" = "y" ]; then
4555 if [ "$DOPLAYLIST" = "y" ]; then
4556 echo Creating playlist... >&2
4561 if [ "$GETALBUMART" = "y" ]; then
4565 # For the lowdisk option, only one program is running at once so the encoder
4566 # can be unsilenced right away.
4567 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4568 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4571 if [ "$ONETRACK" = "y" ]; then
4572 TRACKS="$FIRSTTRACK"
4573 if [ "$USEPIPES" = "y" ]; then
4574 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4575 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4578 if checkstatus readtrack-$FIRSTTRACK; then :; else
4579 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4583 for UTRACKNUM in $TRACKQUEUE
4585 if [ "$DOREAD" = "y" ]; then
4586 if [ "$USEPIPES" = "y" ]; then
4587 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4588 # Read, pipe, shut up!
4589 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4592 if checkstatus readtrack-$UTRACKNUM; then :; else
4593 do_cdread $UTRACKNUM
4595 if [ "$?" != "0" ]; then
4596 # CD read failed - don't give the goahead to
4603 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4606 # If we are not reading, set the encode output to loud already, so
4607 # that we can see the output of the first track.
4608 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4609 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4611 echo NEXTTRACK # Get the encoder machine churning again
4612 if [ "$DOREAD" = "y" ]; then
4613 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4614 until checkstatus encodetrack-$UTRACKNUM
4616 if checkerrors encodetrack-$UTRACKNUM; then
4627 # Now that we're done the encoding can be loud again -
4628 # if we're not using SMP.
4629 if [ "$MAXPROCS" = "1" ]; then
4630 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4633 # All tracks read, start encoding.
4634 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4638 # Execute the user-defined post_read function before ejecting CD
4641 # We are now finished with the cdrom - it can be safely ejected. Note that
4642 # abcde will not have completed yet.
4643 if [ "$EJECTCD" = "y" ]; then
4644 # We check if the disk we are processing is actually the disk inside the
4645 # CD tray. If not, we do not eject the CD, since it might be so that the
4646 # user ejected it manually.
4647 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4648 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4649 # More FreeBSD bits.
4650 if [ X"$(uname)" = X"FreeBSD" ] ; then
4651 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4652 # but in this script EJECT is in the envionment and names the program
4655 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4656 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4657 $eject $EJECTOPTS $cd
4658 elif [ X"$(uname)" = X"Darwin" ] ; then
4659 diskutil eject ${CDROM#/dev/} 0
4660 elif [ -x $(which $EJECT) ]; then
4661 $EJECT $EJECTOPTS "$CDROM"
4668 ## Do we need to pre-process
4669 #if [ x"$PREPROCESS" = "x" ] ; then
4672 # for PRETRACKNUM in $TRACKQUEUE
4675 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4677 # until [ $PREPROCEED ]
4679 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4680 # # all locations are working, wait and try again later
4681 # if [ ! $PREPROCEED ]; then sleep 3; fi
4683 # ( do_preprocess $PRETRACKNUM
4691 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4693 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4694 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4695 if [ "$GOAHEAD" = "NO" ]; then break; fi
4696 for LASTTRACK in $TRACKQUEUE; do :; done
4697 if checkstatus readtrack-$LASTTRACK; then
4698 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4699 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4700 if checkerrors batch-normalize; then exit 1; fi
4702 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4703 if [ "$DONORMALIZE" = "y" ]; then
4704 for UTRACKNUM in $TRACKQUEUE
4706 if checkstatus readtrack-$UTRACKNUM; then
4707 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4711 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4712 if checkerrors nogap-encode; then exit 1; fi
4717 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4718 if [ "$ONETRACK" = "y" ] ; then
4719 TRACKQUEUE="$FIRSTTRACK"
4720 TRACKS="$FIRSTTRACK"
4723 # Do the encoding, including parallelization of remote encoding
4724 # Figure out where each track is going to be encoded
4725 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4726 if [ "$MAXPROCS" != "0" ]; then
4727 for NUM in $(f_seq_row 1 "$MAXPROCS")
4729 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
4733 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
4734 for UTRACKNUM in $TRACKQUEUE
4737 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4738 if [ "$GOAHEAD" = "NO" ]; then break; fi
4739 # find out where this track is to be encoded
4740 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4741 # Make sure we have a place to encode this, if not, exit stage right
4742 if [ -z "$ENCODELOCATIONS" ]; then
4748 for LOCATION in $ENCODELOCATIONS
4750 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4751 # check first if a track has ever been assigned to this location
4752 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
4753 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4754 if checkerrors encodetrack-$PREVIOUSTRACK; then
4755 for TEMPLOCATION in $ENCODELOCATIONS
4757 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4758 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
4761 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
4766 # We're still here, this location must have been previously assigned,
4767 # and last completed without error - check if it's done with the
4768 # previous track yet
4769 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
4771 # all locations are working, wait and try again later
4772 if [ ! $PROCEED ]; then sleep 3; fi
4774 # Record the location we're about to encode the next track at
4775 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4777 # Don't proceed with the rest of the loop if we can't encode
4778 if [ "$ABORT" ]; then continue; fi
4779 ## FIXME ## Add here
4780 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4781 # Set TRACKNUM, TRACKNAME
4782 if [ -e "$CDDBDATA" ]; then
4783 if [ "$ONETRACK" = "y" ]; then
4785 TRACKNUM="$FIRSTTRACK"
4789 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
4790 getcddbinfo TRACKNAME
4794 # You can't encode a file which needs to be normalized before finishing
4795 # You can't tag a file before it's finished encoding -
4796 # thus all of this is backgrounded together
4798 if [ "$DONORMALIZE" = "y" ]; then
4799 if checkstatus readtrack-$UTRACKNUM; then
4800 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4803 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4804 if checkstatus readtrack-$UTRACKNUM; then
4805 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4806 if [ "$DONORMALIZE" = "y" ]; then
4807 if checkstatus normalizetrack-$UTRACKNUM; then
4808 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4811 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4815 if [ "$DOTAG" = "y" ]; then
4816 if checkstatus encodetrack-$UTRACKNUM; then
4817 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
4819 # Lets tag the cue file
4820 if checkstatus cleancuefile >/dev/null; then :; else
4821 if checkstatus cuefile >/dev/null ; then
4826 if [ "$DOMOVE" = "y" ]; then
4827 if checkstatus tagtrack-$UTRACKNUM; then
4828 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
4835 # Go through it again and make sure there's no distmp3 stragglers, otherwise
4836 # we'll delete the files they're working on
4837 # Do NOT play ball if there is no ball to play (so ABORT if needed)
4838 ## FIXME ## Check also for files which are encoded using PIPEs.
4839 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
4844 for LOCATION in $ENCODELOCATIONS
4846 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4847 # "How can he give us a status update, if he's DEAD?"
4848 if checkstatus encodetrack-$CHECKTRACK; then
4851 # Nothing to see here please go quietly back to your homes
4852 if [ -z "$CHECKTRACK" ]; then continue; fi
4853 # You're still here? Maybe there is something...
4854 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
4857 if [ ! $PROCEED ]; then sleep 5; fi
4860 # If the above didn't catch the stragglers, this will
4862 if [ "$DOREPLAYGAIN" = "y" ]; then
4866 # Execute the user-defined post_encode function before cleaning up
4869 # Check to see if run_command logged any errors
4870 if [ -f "$ABCDETEMPDIR/errors" ]; then
4871 log error "The following commands failed to run:"
4872 cat "$ABCDETEMPDIR/errors"
4876 if [ "$KEEPWAVS" = "y" ];then
4880 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
4881 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
4882 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
4883 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
4884 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
4885 log warning "The encoded formats does not match with the moved ones"
4886 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
4887 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
4888 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
4892 if [ "$DOCLEAN" = "y" ]; then
4893 # Wipe all the evidence
4894 # Gimme gimme gimme some more time!
4896 rm -rf "$ABCDETEMPDIR"
4899 echo "Finished. Not cleaning $ABCDETEMPDIR."