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) echo "[ERROR] abcde: $@" >&2 ;;
91 warning) echo "[WARNING] $@" >&2 ;;
92 info) 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 if [ -n "$DISCNUMBER" ]; then
901 echo DISCNUMBER="$DISCNUMBER"
903 echo CDDB=$CDDBDISCID
904 if [ "$(eval echo ${COMMENT})" != "" ]; then
905 case "$COMMENTOUTPUT" in
906 *=*) echo "$COMMENTOUTPUT";;
907 *) echo COMMENT="$COMMENTOUTPUT";;
910 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
911 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
912 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
913 # Doublecheck that the commented file was created
914 # successfully before wiping the original
915 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
916 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
918 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
924 run_command tagtrack-$OUTPUT-$1 true
928 echo ARTIST="$TRACKARTIST"
930 echo TITLE="$TRACKNAME"
931 if [ -n "$CDYEAR" ]; then
934 if [ -n "$CDGENRE" ]; then
935 echo GENRE="$CDGENRE"
937 echo TRACKNUMBER="${TRACKNUM:-$1}"
938 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
939 # xiph.org: http://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
940 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
941 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
942 echo TRACKTOTAL="${TRACKS}"
943 if [ -n "$DISCNUMBER" ]; then
944 echo DISCNUMBER="$DISCNUMBER"
946 echo CDDB="$CDDBDISCID"
947 if [ "$(eval echo ${COMMENT})" != "" ]; then
948 case "$COMMENTOUTPUT" in
949 *=*) echo "$COMMENTOUTPUT";;
950 *) echo COMMENT="$COMMENTOUTPUT";;
953 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
954 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
957 run_command tagtrack-$OUTPUT-$1 true
960 run_command tagtrack-$OUTPUT-$1 true
963 run_command tagtrack-$OUTPUT-$1 true
966 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
967 # Console port (mac) used for encoding does not have the ability to tag.
968 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
969 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
970 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
973 run_command tagtrack-$OUTPUT-$1 true
976 case "$AACENCODERSYNTAX" in
978 # We will use inline tagging...
979 run_command tagtrack-$OUTPUT-$1 true
982 # Tag post encode with neroAacTag...
983 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
984 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
985 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
988 run_command tagtrack-$OUTPUT-$1 true
993 run_command tagtrack-$OUTPUT-$1 true
997 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
998 run_command tagtrack-$1 true
1004 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1007 # The commands here don't go through run_command because they're never
1008 # supposed to be silenced
1009 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1010 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1014 case "$MP3ENCODERSYNTAX" in
1019 for UTRACKNUM in $TRACKQUEUE
1021 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1023 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1025 if [ "$RETURN" != "0" ]; then
1026 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
1028 for UTRACKNUM in $TRACKQUEUE
1030 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1031 #run_command encodetrack-$UTRACKNUM true
1040 if checkerrors "nogap-encode"; then :; else
1041 if [ ! "$KEEPWAVS" = "y" ] ; then
1042 if [ ! "$KEEPWAVS" = "move" ] ; then
1047 # Other encoders fall through to normal encoding as the tracks have not
1048 # been entered in the status file.
1051 # do_encode [tracknumber] [hostname]
1052 # If no hostname is specified, encode locally
1054 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1055 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1058 if [ "$USEPIPES" = "y" ]; then
1061 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1064 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1067 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1070 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1073 TEMPARG="PIPE_$SPEEXENCODER"
1076 TEMPARG="PIPE_$MPCENCODER"
1079 TEMPARG="PIPE_$WVENCODERSYNTAX"
1082 TEMPARG="PIPE_$AACENCODERSYNTAX"
1085 TEMPARG="PIPE_$AACENCODERSYNTAX"
1088 IN="$( eval echo "\$$TEMPARG" )"
1090 IN="$ABCDETEMPDIR/track$1.wav"
1092 # We need IN to proceed, if we are not using pipes.
1093 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1094 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1096 case "$TMPOUTPUT" in
1098 OUTPUT=$OGGOUTPUTCONTAINER
1101 OUTPUT=$OPUSOUTPUTCONTAINER
1104 OUTPUT=$FLACOUTPUTCONTAINER
1110 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1111 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1114 if [ X"$USEPIPES" = "Xy" ]; then
1116 # We need a way to store the creation of the files when using PIPES
1117 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1118 # When piping it does not make sense to have a higher nice for
1119 # reading than for encoding, since it will be hold by the
1120 # encoding process. Setting an effective nice, to calm down a
1121 # bit the reading process.
1122 EFFECTIVE_NICE=$READNICE
1124 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1125 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1126 EFFECTIVE_NICE=$ENCNICE
1132 case "$MP3ENCODERSYNTAX" in
1133 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1134 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1135 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1136 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1140 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1147 case "$OGGENCODERSYNTAX" in
1148 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1149 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1153 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1160 case "$OPUSENCODERSYNTAX" in
1162 # Tag the file at encode time, as it can't be done after encoding.
1163 if [ "$DOTAG" = "y" ]; then
1164 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1165 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1166 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1168 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1174 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1181 case "$FLACENCODERSYNTAX" in
1182 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1187 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1188 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1193 if [ "$(eval echo ${COMMENT})" != "" ]; then
1196 *) COMMENT="COMMENT=$COMMENT" ;;
1199 # Tag the file at encode time, as it can't be done after encoding.
1200 if [ "$DOTAG" = "y" ]; then
1201 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1202 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1204 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1208 # Tag the file inline at encode time.
1209 if [ "$DOTAG" = "y" ]; then
1210 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1211 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1213 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1217 if [ "$DOTAG" = "y" ]; then
1218 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1219 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1221 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1225 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1228 # aac container is only used to catch faac encoded files where faac
1229 # is compiled without mp4 support (with libmp4v2).
1230 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1233 case "$AACENCODERSYNTAX" in
1235 if [ "$DOTAG" = "y" ]; then
1236 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1237 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1239 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1243 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1246 if [ "$DOTAG" = "y" ]; then
1247 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1248 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1250 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1256 # In case of wav output we need nothing. Just keep the wavs.
1257 # But we need the following to allow full logging and subsequent
1258 # successful cleaning of $ABCDETEMPDIR.
1259 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1264 # Only remove .wav if the encoding succeeded
1265 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1266 run_command encodetrack-$1 true
1267 if [ ! "$KEEPWAVS" = "y" ] ; then
1268 if [ ! "$KEEPWAVS" = "move" ] ; then
1274 run_command "" echo "HEH! The file we were about to encode disappeared:"
1275 run_command "" echo ">> $IN"
1276 run_command encodetrack-$1 false
1280 # do_preprocess [tracknumber]
1282 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1285 # IN="$ABCDETEMPDIR/track$1.wav"
1286 # # We need IN to proceed.
1287 # if [ -s "$IN" ] ; then
1288 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1290 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1291 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1292 # case "$POSTPROCESSFORMAT" in
1294 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1296 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1298 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1300 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1302 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1305 # # Only remove .wav if the encoding succeeded
1306 # if checkerrors "preprocess-(.{3,4})-$1"; then
1307 # run_command preprocess-$1 false
1309 # run_command preprocess-$1 true
1312 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1313 # echo "HEH! The file we were about to pre-process disappeared:"
1316 # run_command preprocess-$1 false
1321 # do_postprocess [tracknumber]
1323 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1326 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1328 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1329 # # We need IN to proceed.
1330 # if [ -s "$IN" ] ; then
1331 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1332 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1333 # case "$POSTPROCESSFORMAT" in
1335 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1337 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1339 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1341 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1343 # # Only remove .wav if the encoding succeeded
1344 # if checkerrors "postprocess-(.{3,4})-$1"; then
1345 # run_command postprocess-$1 false
1347 # run_command postprocess-$1 true
1350 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1351 # echo "HEH! The file we were about to post-process disappeared:"
1354 # run_command postprocess-$1 false
1369 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1373 # The commands here don't go through run_command because they're never supposed to be silenced
1374 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1379 for UTRACKNUM in $TRACKQUEUE
1381 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1383 # FIXME # Hard-coded batch option!
1384 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1386 if [ "$RETURN" != "0" ]; then
1387 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1389 for UTRACKNUM in $TRACKQUEUE
1391 echo normalizetrack-$UTRACKNUM >> status
1397 # do_batch_normalize
1399 # NORMALIZER, NORMALIZEROPTS
1400 do_batch_normalize ()
1402 # The commands here don't go through run_command because they're never supposed to be silenced
1403 echo "Batch normalizing tracks: $TRACKQUEUE"
1408 for UTRACKNUM in $TRACKQUEUE
1410 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1412 # XXX: Hard-coded batch option!
1413 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1415 if [ "$RETURN" != "0" ]; then
1416 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1418 for UTRACKNUM in $TRACKQUEUE
1420 echo normalizetrack-$UTRACKNUM >> status
1426 # do_normalize [tracknumber]
1428 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1431 IN="$ABCDETEMPDIR/track$1.wav"
1432 if [ -e "$IN" ] ; then
1433 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1434 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1436 if [ "$(checkstatus encode-output)" = "loud" ]; then
1437 echo "HEH! The file we were about to normalize disappeared:"
1440 run_command normalizetrack-$1 false "File $IN was not found"
1444 # do_move [tracknumber]
1445 # Deduces the outfile from environment variables
1446 # Creates directory if necessary
1448 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1451 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1453 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1454 # defined the OUTPUTFILE:
1457 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1458 # Munge filenames as follows:
1463 # Eat control characters
1464 ALBUMFILE="$(mungefilename "$DALBUM")"
1465 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1466 TRACKFILE="$(mungefilename "$TRACKNAME")"
1467 GENRE="$(mungegenre "$GENRE")"
1468 YEAR=${CDYEAR:-$CDYEAR}
1469 # If we want to start the tracks with a given number, we need to modify
1470 # the TRACKNUM value before evaluation
1472 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1473 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1474 if [ "$ONETRACK" = "y" ]; then
1475 if [ "$VARIOUSARTISTS" = "y" ]; then
1476 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1478 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1481 if [ "$VARIOUSARTISTS" = "y" ]; then
1482 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1484 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1487 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1488 # Once we know the specific output was successful, we can change
1489 # the OUTPUT to the value containing the container
1492 OUTPUT=$OGGOUTPUTCONTAINER
1495 OUTPUT=$OPUSOUTPUTCONTAINER
1498 OUTPUT=$FLACOUTPUTCONTAINER
1504 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1505 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1508 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1509 # FIXME # introduce warnings?
1512 # mkdir -p shouldn't return an error if the directory already exists
1513 mkdir -p "$OUTPUTFILEDIR"
1514 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1515 if checkstatus movetrack-output-$OUTPUT; then :; else
1516 run_command movetrack-output-$OUTPUT true
1521 # mkdir -p shouldn't return an error if the directory already exists
1522 mkdir -p "$OUTPUTFILEDIR"
1523 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1524 if checkstatus movetrack-output-$OUTPUT; then :; else
1525 run_command movetrack-output-$OUTPUT true
1529 # Lets move the cue file
1530 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1531 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1532 if checkstatus movecue-$OUTPUT; then :; else
1533 # Silence the Copying output since it overlaps with encoding processes...
1534 #run_command '' vecho "Copying cue file to its destination directory..."
1535 if checkstatus onetrack >/dev/null ; then
1538 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1539 # We dont have the dir, since it was not created before.
1542 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1545 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1546 # http://brianvictor.tripod.com/mp3cue.htm#details
1547 [a-z0-9][a-z0-9][a-z0-9])
1548 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1551 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1555 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1557 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1566 # Create the playlist if wanted
1568 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1569 # VARIOUSARTISTS, OUTPUTDIR
1572 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1576 OUTPUT=$OGGOUTPUTCONTAINER
1579 OUTPUT=$OPUSOUTPUTCONTAINER
1582 OUTPUT=$FLACOUTPUTCONTAINER
1588 # Create a playlist file for the playlist data to go into.
1589 # We used to wipe it out if it existed. Now we request permission if interactive.
1590 for LASTTRACK in $TRACKQUEUE; do :; done
1591 ALBUMFILE="$(mungefilename "$DALBUM")"
1592 ARTISTFILE="$(mungefilename "$DARTIST")"
1593 GENRE="$(mungegenre "$GENRE")"
1594 YEAR=${CDYEAR:-$CDYEAR}
1595 if [ "$VARIOUSARTISTS" = "y" ] ; then
1596 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1598 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1600 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1601 mkdir -p "$FINALPLAYLISTDIR"
1602 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1603 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1604 if [ "$INTERACTIVE" = "y" ]; then
1605 while [ "$DONE" != "y" ]; do
1607 case $ERASEPLAYLIST in
1608 e|E|a|A|k|K) DONE=y ;;
1609 "") ERASEPLAYLIST=e ; DONE=y ;;
1617 # Once we erase the playlist, we use append to create the new one.
1618 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1620 # The playlist does not exist, so we can safelly use append to create the new list
1623 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1624 touch "$OUTPUTDIR/$PLAYLISTFILE"
1625 for UTRACKNUM in $TRACKQUEUE
1627 # Shares some code with do_move since the filenames have to match
1628 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1629 getcddbinfo TRACKNAME
1631 TRACKFILE="$(mungefilename "$TRACKNAME")"
1632 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1633 ALBUMFILE="$(mungefilename "$DALBUM")"
1634 # If we want to start the tracks with a given number, we need to modify the
1635 # TRACKNUM value before evaluation
1637 if [ "$VARIOUSARTISTS" = "y" ]; then
1638 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1640 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1642 if [ "$VARIOUSARTISTS" = "y" ]; then
1643 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1644 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1646 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1649 if [ "$PLAYLISTDATAPREFIX" ]; then
1650 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1652 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1657 ## this will convert the playlist to have CRLF line-endings, if specified
1658 ## (some hardware players insist on CRLF endings)
1659 if [ "$DOSPLAYLIST" = "y" ]; then
1660 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1661 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1662 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1664 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1669 # This function reads a cuefile on stdin and writes an extended
1670 # cddb query on stdout. Any PREGAP for track 1 is properly
1671 # handled, although cue files embedded in FLAC files do not
1672 # appear to properly store the PREGAP setting. :(
1673 abcde.cue2discid () {
1678 while [ $val -gt 0 ] ; do
1679 ret=$(( $ret + ( $val % 10) ))
1680 val=$(( $val / 10 ))
1690 local first second third
1691 first=$(expr ${1} + 0 )
1692 second=$(expr ${2} + 0 )
1693 third=$(expr ${3} + 0 )
1695 echo $(( ((($first * 60) + $second) * 75) + $third ))
1705 while read line ; do
1708 TRACK) i=$(( i + 1 ))
1710 INDEX) if [ "$2" -eq 1 ] ; then
1712 START=$(( $LBA + $PREGAP + $OFFSET ))
1714 X=$(cddb_sum $(( $START / 75 )) )
1718 PREGAP) PREGAP=$(msf2lba $2)
1722 LEADOUT=$(( $4 / 588 ))
1725 LEADIN=$(( $3 / 588 ))
1734 LEADOUT=$(( $LEADOUT + $LEADIN ))
1736 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1737 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1738 printf "%08x %i" $DISCID $TRACKS
1741 while [ $j -le $TRACKS ] ; do
1742 eval echo -n "\" \$TRACK$j\""
1745 echo " $(( $LEADOUT / 75 ))"
1749 # abcde.mkcue [--wholedisk]
1750 # This creates a cuefile directly from the extended discid information
1751 # The --wholedisk option controls whether we're ripping data from the
1752 # start of track one or from the start of the disk (usually, but not
1753 # always the same thing!)
1755 # Track one leadin/pregap (if any) handeling:
1756 # --wholedisk specified:
1759 # INDEX 01 <pregap value>
1760 # Remaining track index values unchanged from disc TOC
1762 # --wholedisk not specified
1764 # PREGAP <pregap value>
1766 # Remaining track index values offset by <pregap value>
1773 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1776 local MODE DISCID TRACKS
1780 if [ "$1" = --wholedisc ] ; then
1786 vecho "One track is $ONETRACK"
1787 TRACKFILE="$(mungefilename "$TRACKNAME")"
1788 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1789 ALBUMFILE="$(mungefilename "$DALBUM")"
1790 if [ "$ONETRACK" = "y" ]; then
1791 if [ "$VARIOUSARTISTS" = "y" ]; then
1792 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1794 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1796 vecho "Cue wav file is $CUEWAVFILE"
1798 CUEWAVFILE="dummy.wav"
1807 echo REM DISCID $DISCID
1808 echo FILE \""$CUEWAVFILE"\" WAVE
1810 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1817 while [ $i -le "$TRACKS" ] ; do
1818 LBA=$(( $1 - $OFFSET ))
1819 printf " TRACK %02i AUDIO\n" $i
1820 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1821 if [ $MODE = PREGAP ] ; then
1822 echomsf " PREGAP " $(($OFFSET-150))
1824 echo " INDEX 00 00:00:00"
1827 echomsf " INDEX 01 " $LBA
1834 # This essentially the start of things
1837 # Query the CD to get the track info, unless the user specified -C
1838 # or we are using some actions which do not need the CDDB data at all
1839 #if [ ! X"$EXPACTIONS" = "X" ]; then
1841 #elif [ -z "$DISCID" ]; then
1842 if [ -z "$DISCID" ]; then
1843 vecho -n "Getting CD track info... "
1844 # In OSX, unmount the disc before a query
1845 if [ "$OSFLAVOUR" = "OSX" ]; then
1846 diskutil unmount ${CDROM#/dev/}
1848 case "$CDROMREADERSYNTAX" in
1850 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1851 case "$CUE2DISCID" in
1852 # FIXME # right now we have 2 cue2discid internal
1853 # implementations: builtin and abcde.cue2discid. Test
1854 # both of them and decide which one we want to use.
1856 #vecho "Using builtin cue2discid implementation..."
1857 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1859 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1861 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1862 TRACKS=${#OFFSETTIMES[@]}
1864 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1865 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1866 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1867 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1870 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
1871 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
1875 #vecho "Using external python cue2discid implementation..."
1876 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1880 log error "the input flac file does not contain a cuesheet."
1885 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1887 # if [ ! "$RET" = "0" ];then
1888 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1891 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1892 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1894 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1895 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1899 case "$CDDBMETHOD" in
1900 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1901 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
1905 # Make sure there's a CD in there by checking cd-discid's return code
1906 if [ ! "$?" = "0" ]; then
1907 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1908 log error "cuesheet information from the flac file could not be read."
1909 log error "Perhaps the flac file does not contain a cuesheet?."
1912 log error "CD could not be read. Perhaps there's no CD in the drive?"
1916 # In OSX, remount the disc again
1917 if [ "$OSFLAVOUR" = "OSX" ]; then
1918 diskutil mount ${CDROM#/dev/}
1921 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1923 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1926 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1927 # This needs to be done now because a section of the resuming code will need
1930 # get the number of digits to pad TRACKNUM with - we'll use this later
1931 # a CD can only hold 99 tracks, but since we support a feature for starting
1932 # numbering the tracks from a given number, we might need to set it as a
1933 # variable for the user to define... or obtain it somehow.
1934 if [ "$PADTRACKS" = "y" ] ; then
1938 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1939 if [ -z "$TRACKQUEUE" ]; then
1940 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1941 case "$CDROMREADERSYNTAX" in
1942 cdparanoia|libcdio|debug)
1943 if [ "$WEHAVEACD" = "y" ]; then
1944 vecho "Querying the CD for audio tracks..."
1945 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1947 if [ ! "$RET" = "0" ];then
1948 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1950 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1951 CDPARANOIAAUDIOTRACKS="$TRACKS"
1953 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1954 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1955 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1956 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1958 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1959 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1963 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1966 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1968 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1969 log info "The disc does not contain any tracks. Giving up..."
1972 echo -n "Grabbing entire CD - tracks: "
1973 if [ ! "$PADTRACKS" = "y" ] ; then
1974 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1976 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1978 while [ "$X" -ne "$TRACKS" ]
1980 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1981 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1985 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1986 # User-supplied track queue.
1987 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1988 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1989 # Once cleaned, obtain the highest value in the trackqueue for number padding
1990 for LASTTRACK in $TRACKQUEUE; do :; done
1991 if [ ! "$PADTRACKS" = "y" ] ; then
1992 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1994 # Now we normalize the trackqueue
1995 for TRACK in $TRACKQUEUE ; do
1996 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1997 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1999 TRACKQUEUE=$PADTRACKQUEUE
2000 echo Grabbing tracks: "$TRACKQUEUE"
2003 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2005 # We have the discid, create a temp directory after it to store all the temp
2008 if [ -e "$ABCDETEMPDIR" ]; then
2009 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2010 # It already exists, see if it's a directory
2011 if [ ! -d "$ABCDETEMPDIR" ]; then
2012 # This is a file/socket/fifo/device/etc, not a directory
2015 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2016 echo "Please investigate, remove it, and rerun abcde." >&2
2020 # It's a directory, let's see if it's writable by us
2021 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2022 # Nope, complain and exit
2024 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2025 echo "Please investigate, remove it, and rerun abcde." >&2
2029 # See if it's populated
2030 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2031 # Wipe and start fresh
2032 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2033 echo -n "this directory to continue. Continue [y/N]? " >&2
2034 if [ "$INTERACTIVE" = "y" ]; then
2040 if [ "$ANSWER" != "y" ]; then
2043 rm -rf "$ABCDETEMPDIR" || exit 1
2044 mkdir -p "$ABCDETEMPDIR"
2045 if [ "$?" -gt "0" ]; then
2046 # Directory already exists or could not be created
2047 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2051 # Everything is fine. Check for ^encodetracklocation-
2052 # and encode-output entries in the status file and
2053 # remove them. These are not relevant across sessions.
2054 if [ -f "$ABCDETEMPDIR/status" ]; then
2055 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2056 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2057 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2059 # Remove old error messages
2060 if [ -f "$ABCDETEMPDIR/errors" ]; then
2061 rm -f "$ABCDETEMPDIR/errors"
2065 # We are starting from scratch
2066 mkdir -p "$ABCDETEMPDIR"
2067 if [ "$?" -gt "0" ]; then
2068 # Directory already exists or could not be created
2069 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2072 cat /dev/null > "$ABCDETEMPDIR/status"
2073 # Store the abcde version in the status file.
2074 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2076 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2077 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2078 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2079 vecho "Creating cue file..."
2080 case $CDROMREADERSYNTAX in
2082 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2083 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2085 log warning "the input flac file does not contain a cuesheet."
2089 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2090 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2092 log warning "reading the CUE sheet is still considered experimental"
2093 log warning "and there was a problem with the CD reading. abcde will continue,"
2094 log warning "but consider reporting the problem to the abcde author"
2100 # If we got the CDPARANOIA status and it is not recorded, save it now
2101 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2102 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2103 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2107 # Create the discid file
2108 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2109 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2110 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2115 # Create a proper CUE file based on the CUE file we created before.
2118 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2119 CUEFILE_OUT=$CUEFILE_IN.out
2120 ### FIXME ### checkstatus cddb
2121 if [ -e "$CDDBDATA" ]; then
2122 vecho "Adding metadata to the cue file..."
2123 # FIXME It doesn't preserve spaces! Why?
2124 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2126 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2127 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2128 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2132 cat "$CUEFILE_IN" | while read line
2134 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2135 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2136 # echo "$line" >> "$CUEFILE_OUT"
2137 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2138 eval track="\$TRACK$n"
2140 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2141 # When making a single-track rip, put the
2142 # actual file name into the file declaration
2143 # in the cue file so that it is usable by
2144 # music players and the like
2145 elif [ "$ONETRACK" = "y" ] &&
2146 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2148 TRACKFILE="$(mungefilename "$TRACKNAME")"
2149 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
2150 ALBUMFILE="$(mungefilename "$DALBUM")"
2152 if [ "$VARIOUSARTISTS" = "y" ]; then
2153 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2155 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2158 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2161 # FIXME # If the lines above are uncommented, remove the line below.
2162 echo "$line" >> "$CUEFILE_OUT"
2165 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2166 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2172 # Parses a CDDB file and outputs the title and the track names.
2173 # Variables: CDDBFILE
2177 # List out disc title/author and contents
2178 if [ "$ONETRACK" = "y" ]; then
2179 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2181 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2182 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2183 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2184 if [ ! X"$PARSEDYEAR" = "X" ]; then
2185 echo "Year: $PARSEDYEAR"
2188 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2189 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2190 if [ ! X"$PARSEDGENRE" = "X" ]; then
2191 echo "Genre: $PARSEDGENRE"
2194 if [ ! "$ONETRACK" = "y" ]; then
2195 for TRACK in $(f_seq_row 1 $TRACKS)
2197 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2203 # Check for a local CDDB file, and report success
2206 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2208 CDDBLOCALSTATUS="notfound"
2209 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2212 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2213 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2214 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2215 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2216 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2217 CDDBLOCALMATCH=single
2218 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2219 CDDBLOCALMATCH=multiple
2224 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2225 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2226 CDDBLOCALMATCH=single
2231 # If the user has selected to check a local CDDB repo, we proceed with it
2232 case $CDDBLOCALMATCH in
2234 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2236 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2238 # List out disc title/author and contents
2239 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2240 cat "$RESULT" > "${CDDBLOCALREAD}"
2243 do_cddbparse "${CDDBLOCALREAD}"
2245 ##FIXME## QUICK HACK !!!!
2246 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2247 } >> "$ABCDETEMPDIR/cddblocalchoices"
2249 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2250 page "$ABCDETEMPDIR/cddblocalchoices"
2252 # It's all going to fit in one page, cat it
2253 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2255 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2256 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2257 CDDBLOCALCHOICENUM=-1
2258 if [ "$INTERACTIVE" = "y" ]; then
2259 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2260 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2261 read CDDBLOCALCHOICE
2262 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2263 # FIXME # Introduce diff's
2264 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2265 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2266 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2267 # Make sure we get a valid choice
2268 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2269 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2270 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2276 #echo "Selected ..."
2278 CDDBLOCALCHOICENUM=1
2280 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2281 #echo "Using local copy of CDDB data"
2282 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2283 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2284 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2285 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2286 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2287 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2288 CDDBLOCALSTATUS="found"
2290 #echo "Not using local copy of CDDB data"
2291 CDDBLOCALSTATUS="notfound"
2295 # List out disc title/author and contents
2296 do_cddbparse "${CDDBLOCALFILE}"
2297 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2298 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2300 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2302 if [ "$INTERACTIVE" = "y" ]; then
2304 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2305 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2308 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2312 if [ "$USELOCALRESP" = "y" ]; then
2313 #echo "Using local copy of CDDB data"
2314 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2315 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2316 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2317 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2318 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2319 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2320 CDDBLOCALSTATUS="single"
2322 #echo "Not using local copy of CDDB data"
2323 CDDBLOCALSTATUS="notfound"
2327 CDDBLOCALSTATUS="notfound"
2334 # Try to read CD-Text from the drive using icedax / cdda2wav
2337 if new_checkexec icedax; then
2338 CDTEXT_READER=icedax
2339 elif new_checkexec cdda2wav; then
2340 CDTEXT_READER=cdda2wav
2342 # Didn't find either, bail
2346 if [ "$OSFLAVOUR" = "OSX" ] ; then
2347 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2348 diskutil unmount ${CDROM#/dev/}
2349 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2350 CDDA2WAVCDROM="IODVDServices"
2351 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2352 CDDA2WAVCDROM="$CDROMID"
2354 if [ "$CDROMID" = "" ]; then
2355 CDDA2WAVCDROM="$CDROM"
2357 CDDA2WAVCDROM="$CDROMID"
2361 # Do we have CD-Text on the disc (and can the drive read it?)
2362 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2363 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2365 if [ $ERRORCODE -ne 0 ]; then
2366 # No CD-Text found, bail
2370 rm -f "$ABCDETEMPDIR/cddbchoices"
2372 # Make an empty template
2373 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2374 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2375 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2376 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2377 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2378 ATITLE=$(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
2379 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2380 # List out disc title/author and contents
2381 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2382 for TRACK in $(f_seq_row 1 $TRACKS)
2384 TRACKM1=$(($TRACK - 1))
2385 TITLE="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
2386 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2387 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2388 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2390 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2391 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2392 echo >> "$ABCDETEMPDIR/cddbchoices"
2393 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2397 # Work with the musicbrainz WS API, then transform the results here so
2398 # they look (very) like the results from CDDB. Maybe not the best way
2399 # to go, but it Works For Me (TM)
2403 if checkstatus musicbrainz-readcomplete; then :; else
2404 vecho "Obtaining Musicbrainz results..."
2405 # If MB is to be used, interpret the query results and read all
2406 # the available entries.
2407 rm -f "$ABCDETEMPDIR/cddbchoices"
2408 CDDBCHOICES=1 # Overridden by multiple matches
2409 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2410 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2412 # The helper script will write disc matches out to
2413 # cddbread.*. Count how many we have
2414 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2415 # No matches. Use the normal cddb template for the user to
2417 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2418 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2419 # List out disc title/author and contents of template
2420 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2422 for TRACK in $(f_seq_row 1 $TRACKS)
2424 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2426 echo >> "$ABCDETEMPDIR/cddbchoices"
2427 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2428 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2429 echo 503 > "$ABCDETEMPDIR/cddbquery"
2431 # We have some matches
2432 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2433 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2435 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2436 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2437 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2438 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2439 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2440 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2441 # List out disc title/author and contents
2442 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2443 for TRACK in $(f_seq_row 1 $TRACKS)
2445 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2447 echo >> "$ABCDETEMPDIR/cddbchoices"
2449 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2450 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2451 for file in "$ABCDETEMPDIR"/cddbread.*
2453 X=$(echo $file | sed 's/^.*cddbread\.//g')
2454 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2455 ATITLE=$(grep -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2456 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2457 # List out disc title/author and contents
2458 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2459 for TRACK in $(f_seq_row 1 $TRACKS)
2461 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2463 echo >> "$ABCDETEMPDIR/cddbchoices"
2465 echo "." >> "$ABCDETEMPDIR/cddbquery"
2468 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2475 # Perform CDDB protocol version check if it hasn't already been done
2476 if checkstatus cddb-statcomplete; then :; else
2477 if [ "$CDDBAVAIL" = "n" ]; then
2479 echo 503 > "$ABCDETEMPDIR/cddbstat"
2482 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2483 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2484 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2485 vecho "Checking CDDB server status..."
2486 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2487 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2488 case "$RESPONSECODE" in
2489 210) # 210 OK, status information follows (until terminating `.')
2492 501) # 501 Illegal CDDB protocol level: <n>.
2493 CDDBPROTO=`expr $CDDBPROTO - 1`
2495 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2496 # FreeDB TESTCD disc-id is used for query
2497 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2498 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2499 case "$RESPONSECODE" in
2500 2??) # Server responded, everything seems OK
2510 if test $rc -eq 1; then
2514 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2522 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2523 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2525 # Perform CDDB query if it hasn't already been done
2526 if checkstatus cddb-querycomplete; then :; else
2527 if [ "$CDDBAVAIL" = "n" ]; then
2529 echo 503 > "$ABCDETEMPDIR/cddbquery"
2530 # The default CDDBLOCALSTATUS is "notfound"
2531 # This part will be triggered if the user CDDB repo does not
2532 # contain the entry, or if we are not trying to use the repo.
2534 vecho "Querying the CDDB server..."
2535 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2536 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2537 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2543 # no match found in database,
2544 # wget/fetch error, or user requested not to use CDDB
2545 # Make up an error code (503) that abcde
2546 # will recognize in do_cddbread
2547 # and compensate by making a template
2548 echo 503 > "$ABCDETEMPDIR/cddbquery"
2550 *) # strange and unknown error
2551 echo ERRORCODE=$ERRORCODE
2552 echo "abcde: $CDDBTOOL returned unknown error code"
2556 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2563 # If it's not to be used, generate a template.
2564 # Then, display it (or them) and let the user choose/edit it
2565 if checkstatus cddb-readcomplete; then :; else
2566 vecho "Obtaining CDDB results..."
2567 # If CDDB is to be used, interpret the query results and read all
2568 # the available entries.
2569 rm -f "$ABCDETEMPDIR/cddbchoices"
2570 CDDBCHOICES=1 # Overridden by multiple matches
2571 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2572 case "$RESPONSECODE" in
2574 # One exact match, retrieve it
2575 # 200 [section] [discid] [artist] / [title]
2576 if checkstatus cddb-read-1-complete; then :; else
2577 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2578 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2579 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2580 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2581 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2583 # List out disc title/author and contents
2584 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2585 for TRACK in $(f_seq_row 1 $TRACKS)
2587 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2589 echo >> "$ABCDETEMPDIR/cddbchoices"
2593 case "$RESPONSECODE" in
2594 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2595 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2596 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2598 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2599 # List out disc title/author and contents of template
2600 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2602 for TRACK in $(f_seq_row 1 $TRACKS)
2604 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2606 echo >> "$ABCDETEMPDIR/cddbchoices"
2607 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2608 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2611 # Multiple exact, (possibly multiple) inexact matches
2613 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2614 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2615 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2616 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2617 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2619 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2621 vecho -n "Retrieving multiple matches... "
2622 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2623 read DISCINFO # eat top line
2627 if checkstatus cddb-read-$X-complete; then :; else
2628 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2629 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2631 # List out disc title/author and contents
2632 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2633 for TRACK in $(f_seq_row 1 $TRACKS)
2635 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2637 echo >> "$ABCDETEMPDIR/cddbchoices"
2640 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2644 for TRACK in $(f_seq_row 1 $TRACKS)
2646 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2648 echo >> "$ABCDETEMPDIR/cddbchoices"
2649 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2650 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2653 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2660 if checkstatus cddb-edit >/dev/null; then
2661 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2662 VARIOUSARTISTS="$(checkstatus variousartists)"
2663 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2666 if [ "$INTERACTIVE" = "y" ]; then
2667 # We should show the CDDB results both when we are not using the local CDDB repo
2668 # or when we are using it but we could not find a proper match
2669 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2670 # Display the $ABCDETEMPDIR/cddbchoices file created above
2671 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2672 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2673 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2674 CHOICE=$(checkstatus cddb-choice)
2675 if [ -n "$CHOICE" ] ; then
2676 case $CDDBCHOICES in
2677 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2678 log error "CDDB query failed!"
2681 cat "$ABCDETEMPDIR/cddbchoices"
2684 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2686 echo "Selected: #$CHOICE"
2687 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2691 # The user has a choice to make, display the info in a pager if necessary
2692 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2693 page "$ABCDETEMPDIR/cddbchoices"
2695 # It's all going to fit in one page, cat it
2696 cat "$ABCDETEMPDIR/cddbchoices" >&2
2700 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2702 # I'll take CDDB read #3 for $400, Alex
2703 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2704 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2706 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2707 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2708 if [ ! X"$DIFF" = "X" ]; then
2709 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2710 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2711 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2712 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2713 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2714 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2716 # We parse the 2 choices to diff, store them in temporary files and diff them.
2717 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2718 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2720 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2721 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2722 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2723 page "$ABCDETEMPDIR/cddbread.diff"
2725 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2729 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2731 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2732 # Make sure we get a valid choice
2733 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2734 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2735 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2739 if [ "$CDCHOICENUM" = "0" ]; then
2740 vecho "Creating empty CDDB template..."
2742 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2744 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2745 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2747 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2751 # We need some code to show the selected option when local repository is selected and we have found a match
2752 vecho "Using cached CDDB match..." >&2
2753 # Display the $ABCDETEMPDIR/cddbchoices file created above
2754 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2755 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2756 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2757 CHOICE=$(checkstatus cddb-choice)
2758 if [ "$USELOCALRESP" = "y" ]; then :; else
2759 if [ -n "$CHOICE" ] ; then
2760 case $CDDBCHOICES in
2763 echo "Selected template."
2765 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2767 echo "Selected: #$CHOICE"
2768 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2776 # We're noninteractive - pick the first choice.
2777 # But in case we run a previous instance and selected a choice, use it.
2778 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2779 # Show the choice if we are not using the locally stored one
2780 # or when the local search failed to find a match.
2781 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2782 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2783 #if [ "$PREVIOUSCHOICE" ]; then
2784 cat "$ABCDETEMPDIR/cddbchoices"
2787 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2788 CDCHOICENUM=$PREVIOUSCHOICE
2791 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2793 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2798 if checkstatus cddb-choice >/dev/null; then :; else
2799 echo "abcde: internal error: cddb-choice not recorded." >&2
2802 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2803 echo -n "Edit selected CDDB data " >&2
2804 if [ "$INTERACTIVE" = "y" ]; then
2805 if [ "$UNKNOWNDISK" = "y" ]; then
2806 echo -n "[Y/n]? " >&2
2808 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2810 echo -n "[y/N]? " >&2
2817 if [ "$EDITCDDB" = "y" ]; then
2818 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2820 # Use the debian sensible-editor wrapper to pick the editor that the
2821 # user has requested via their $EDITOR environment variable
2822 if [ -x "/usr/bin/sensible-editor" ]; then
2823 /usr/bin/sensible-editor "$CDDBDATA"
2824 elif [ -n "$EDITOR" ]; then
2825 if [ -x $(which "${EDITOR%%\ *}") ]; then
2826 # That failed, try to load the preferred editor, starting
2827 # with their EDITOR variable
2828 eval $(echo "$EDITOR") \"$CDDBDATA\"
2830 # If that fails, check for a vi
2831 elif which vi >/dev/null 2>&1; then
2833 elif [ -x /usr/bin/vim ]; then
2834 /usr/bin/vim "$CDDBDATA"
2835 elif [ -x /usr/bin/vi ]; then
2836 /usr/bin/vi "$CDDBDATA"
2837 elif [ -x /bin/vi ]; then
2839 # nano should be on all (modern, i.e., sarge) debian systems
2840 elif which nano >/dev/null 2>&1 ; then
2842 elif [ -x /usr/bin/nano ]; then
2843 /usr/bin/nano "$CDDBDATA"
2844 # mg should be on all OpenBSD systems
2845 elif which mg >/dev/null 2>&1 ; then
2847 elif [ -x /usr/bin/mg ]; then
2848 /usr/bin/mg "$CDDBDATA"
2851 log warning "no editor available. Check your EDITOR environment variable."
2853 # delete editor backup file if it exists
2854 if [ -w "$CDDBDATA~" ]; then
2859 # Some heuristics first. Look at Disc Title, and if it starts with
2860 # "Various", then we'll assume Various Artists
2861 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2862 echo "Looks like a Multi-Artist CD" >&2
2865 echo -n "Is the CD multi-artist [y/N]? " >&2
2866 if [ "$INTERACTIVE" = "y" ]; then
2873 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2876 # Need NUMTRACKS before cddb-tool will return it:
2877 NUMTRACKS=$(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2878 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2879 # More than 1/2 tracks contain a "/", so guess forward
2881 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2882 # More than 1/2 contain a "-", so guess forward-dash
2884 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2885 # More than 1/2 contain something in parens, so guess trailing-paren
2889 echo "1) Artist / Title" >&2
2890 echo "2) Artist - Title" >&2
2891 echo "3) Title / Artist" >&2
2892 echo "4) Title - Artist" >&2
2893 echo "5) Artist: Title" >&2
2894 echo "6) Title (Artist)" >&2
2895 echo "7) This is a single-artist CD" >&2
2896 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2897 if [ "$INTERACTIVE" = "y" ]; then
2898 read VARIOUSARTISTSTYLE
2900 echo $DEFAULTSTYLE >&2
2901 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2903 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2904 # If they press Enter, then the default style (0) was chosen
2905 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2906 echo "Invalid selection. Please choose a number between 1 and 7."
2907 echo -n "Selection [1-7]: "
2908 read VARIOUSARTISTSTYLE
2909 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2911 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2912 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2914 vecho "Selected: $VARIOUSARTISTSTYLE"
2915 case "$VARIOUSARTISTSTYLE" in
2917 VARIOUSARTISTSTYLE=forward
2920 VARIOUSARTISTSTYLE=forward-dash
2923 VARIOUSARTISTSTYLE=reverse
2926 VARIOUSARTISTSTYLE=reverse-dash
2929 VARIOUSARTISTSTYLE=colon
2932 VARIOUSARTISTSTYLE=trailing-paren
2940 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2941 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2943 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2944 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2945 # This works but does not have the necessary error checking
2946 # yet. If you are familiar with the CDDB spec
2947 # (see http://www.freedb.org/src/latest/DBFORMAT)
2948 # and can create an error-free entry on your own, then put
2949 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2950 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2951 # your abcde.conf to change the email address submissions are
2954 # submit the modified file, if they want
2955 if [ "$NOSUBMIT" != "y" ]; then
2956 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2958 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2959 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2961 echo -n 'Invalid selection. Please answer "y" or "n": '
2964 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2965 echo -n "Sending..."
2966 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2973 # User CDDBLOCALPOLICY to find out if we store the file or not...
2974 # Cache edited CDDB entry in the user's cddb dir
2975 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2976 # Make sure the cache directory exists
2977 mkdir -p $CDDBLOCALDIR
2978 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2981 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2985 # try to download CD cover
2989 ALBUMFILE="$(mungefilename "$DALBUM")"
2990 ARTISTFILE="$(mungefilename "$DARTIST")"
2991 # have we got a musicbrainz mbid or amazon asin?
2992 case "$CDDBMETHOD" in
2994 # try musicbrainz mbid
2995 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
2996 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
2997 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
2998 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
2999 vecho "cover URL: $ALBUMARTURL" >&2
3000 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3001 if [ $? -ne 0 ]; then
3002 vecho "could not download cover from musicbrainz" >&2
3004 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3005 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3006 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3007 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3008 vecho "cover URL: $ALBUMARTURL" >&2
3009 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3010 if [ $? -ne 0 ]; then
3011 vecho "could not download cover from amazon" >&2
3014 vecho "no amazon ID found" >&2
3018 vecho "no musicbrainz ID found" >&2
3023 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3024 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3025 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3026 if [ $? -ne 0 ]; then
3027 vecho "could not download cover with glyrc" >&2
3032 if [ "$INTERACTIVE" = "y" ]; then
3033 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3034 # display properties of coverart when identify is available
3035 if new_checkexec $IDENTIFY; then
3036 $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
3038 # display coverart when DISPLAY is set and display command is available
3039 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3040 $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
3043 # nothing downloaded yet
3044 vecho "automatic album art downloading failed" >&2
3046 # see if the user can find a better album art manually
3047 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3049 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3050 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3052 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3055 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3056 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3058 if [ ! -z "$ALBUMARTURL" ]; then
3059 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3060 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3061 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3062 vecho "unable to download $ALBUMARTURL" >&2
3064 else # it's a local path
3065 cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
3066 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3067 vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
3073 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3074 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3075 ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
3076 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3077 if new_checkexec $CONVERT; then
3078 mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3079 $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
3080 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3082 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3083 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3087 # copy to target directories
3088 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3089 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3091 # put cover in the same place as the album
3092 if [ "$VARIOUSARTISTS" = "y" ] ; then
3093 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3095 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3097 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3098 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3099 mkdir -p "$FINALALBUMARTDIR"
3100 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3102 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3103 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3105 log warning "could not get cover"
3106 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3110 # do_cdread [tracknumber]
3111 # do_cdread onetrack [firsttrack] [lasttrack]
3115 # The commands here don't go through run_command because they're never supposed to be silenced
3116 # return codes need to be doublechecked anyway, however
3117 if [ "$1" = "onetrack" ]; then
3118 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3119 # FIXME # Until then, we grab the whole CD in one track, no matter what
3121 # We need the first and last track for cdda2wav/icedax
3123 LASTTRACK=$(expr $3 + 0)
3124 UTRACKNUM=$FIRSTTRACK
3125 case "$CDROMREADERSYNTAX" in
3126 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
3129 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
3130 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
3131 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3132 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3133 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3139 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3140 if [ "$USEPIPES" = "y" ]; then
3141 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3142 FILEARG="$( eval echo "\$$TEMPARG" )"
3144 PIPE_MESSAGE="and encoding "
3146 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3147 case "$CDROMREADERSYNTAX" in
3148 ## FIXME ## Find the cases for flac, to avoid exceptions
3150 FILEARG="--output-name=$WAVDATA"
3158 if [ "$1" = "onetrack" ]; then
3159 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3161 if [ -r "$CDDBDATA" ]; then
3162 getcddbinfo TRACKNAME
3163 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3165 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3168 case "$CDROMREADERSYNTAX" in
3169 ### FIXME ### use an exception for flac, since it uses -o
3170 ### FIXME ### Shall we just use -o $FILEARG ??
3172 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3173 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3174 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3176 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3178 if [ "$OSFLAVOUR" = "OSX" ] ; then
3179 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3180 diskutil unmount ${CDROM#/dev/}
3181 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3182 CDDA2WAVCDROM="IODVDServices"
3183 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3184 CDDA2WAVCDROM="$CDROMID"
3186 if [ "$CDROMID" = "" ]; then
3187 CDDA2WAVCDROM="$CDROM"
3189 CDDA2WAVCDROM="$CDROMID"
3192 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
3193 dagrab) nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2 ;;
3195 if [ "$USEPIPES" = "y" ]; then
3196 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3198 # Write ripped audio data to stdout and redirect to $FILEARG.
3199 # $REDIR can be ignored. Progress is written to stderr by default.
3200 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3204 # Find the track's mounted path
3205 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3206 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3207 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3208 # If the file exists, copy it
3209 if [ -e "$FILEPATH" ] ; then
3210 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
3214 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" $REDIR ;;
3217 # If we get some error or we get some missing wav
3218 # (as long as we dont use pipes)
3219 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3220 # Thank goodness errors is only machine-parseable up to the
3221 # first colon, otherwise this woulda sucked
3222 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3223 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3225 if [ "$USEPIPES" = "y" ]; then
3226 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3228 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3232 if [ "$USEPIPES" = "y" ]; then
3233 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3235 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3237 if [ "$1" = "onetrack" ]; then
3238 echo onetrack >> "$ABCDETEMPDIR/status"
3244 # No values accepted, only uses env variables
3247 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3248 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3250 echo "abcde: unable to set the device speed" >&2
3256 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3259 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3261 warning) shift ; log warning "$@" ;;
3269 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3272 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3274 warning) shift ; log warning "$@" ;;
3282 # decho outputs a debug message if DEBUG is selected
3285 if [ x"$DEBUG" != "x" ]; then
3286 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3287 DEBUGECHO=$(echo "$@" | tr -d '[]')
3288 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3295 # User-redefinable functions
3296 # Custom filename munging:
3299 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
3300 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
3303 # Custom genre munging:
3306 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3310 # Empty pre_read function, to be defined in the configuration file.
3317 # Empty post_read function, to be defined in the configuration file.
3324 # Empty post_encode function, to be defined in the configuration file.
3330 ###############################################################################
3333 # Start of execution
3334 ###############################################################################
3339 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3341 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3342 CDDBSUBMIT=freedb-submit@freedb.org
3344 HELLOINFO="$(whoami)@$(hostname)"
3346 CDDBLOCALPOLICY="always"
3347 CDDBLOCALRECURSIVE="y"
3348 CDDBLOCALDIR="$HOME/.cddb"
3351 # List of fields we parse and show during the CDDB parsing...
3352 SHOWCDDBFIELDS="year,genre"
3355 #CDROMREADERSYNTAX=cdparanoia
3356 ENCODERSYNTAX=default
3358 MP3ENCODERSYNTAX=default
3359 OGGENCODERSYNTAX=default
3360 OPUSENCODERSYNTAX=default
3361 FLACENCODERSYNTAX=default
3362 SPEEXENCODERSYNTAX=default
3363 MPCENCODERSYNTAX=default
3364 WVENCODERSYNTAX=default
3365 APENCODERSYNTAX=default
3366 AACENCODERSYNTAX=default
3367 NORMALIZERSYNTAX=default
3368 CUEREADERSYNTAX=default
3370 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3371 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3372 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3373 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3374 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3375 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3376 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3377 PLAYLISTDATAPREFIX=''
3378 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3379 VAPLAYLISTDATAPREFIX=''
3387 VARIOUSARTISTSTYLE=forward
3394 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3395 # i.e. CDROMID="1,0,0"
3397 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3398 # If we are using the ide-scsi emulation layer, we need to define a "g"
3399 CDPARANOIACDROMBUS="d"
3401 # program paths - defaults to checking your $PATH
3408 XINGMP3ENC=xingmp3enc
3428 NEROAACENC=neroAacEnc
3434 VORBISCOMMENT=vorbiscomment
3436 NEROAACTAG=neroAacTag
3438 CDPARANOIA=cdparanoia
3439 CD_PARANOIA=cd-paranoia
3446 MUSICBRAINZ=abcde-musicbrainz-tool
3450 NORMALIZE=normalize-audio
3452 VORBISGAIN=vorbisgain
3456 # For Wavpack replay gain we set both the default of 'track gain'
3457 # as well as this option for 'album gain'. Better media players
3458 # such as vlc can select either or neither. Andrew.
3469 # Options for programs called from abcde
3482 VORBISGAINOPTS="--album"
3486 # The flac option is a workaround for an error where flac fails
3487 # to encode with error 'floating point exception'. This is flac
3488 # error in get_console_width(), corrected in flac 1.3.1
3490 FLACGAINOPTS="--add-replay-gain"
3498 # Monkey's Audio Console (mac) chokes without a mode setting
3499 # so we set one here.
3504 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3505 # we set bitrate here.
3506 FDKAACENCOPTS='--bitrate 192k'
3523 VORBISCOMMENTOPTS="-R"
3524 METAFLACOPTS="--no-utf8-convert"
3529 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3531 # Defaults for album art downloads
3532 ALBUMARTFILE="cover.jpg"
3534 ALBUMARTALWAYSCONVERT="n"
3536 # Default to one process if -j isn't specified
3539 # List of actions to perform - by default, run to completion
3540 ACTIONS=cddb,read,encode,tag,move,clean
3542 # This option is basically for Debian package dependencies:
3543 # List of preferred outputs - by default, run with whatever we have in the path
3544 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac:opus
3546 # List of preferred cdromreaders - by default, run whichever we have in the path
3547 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3549 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3550 # Linux/OpenBSD. ftp is user for NetBSD.
3551 # Let's use these checkings to determine the OS flavour, which will be used
3553 if [ X$(uname) = "XFreeBSD" ] ; then
3558 elif [ X$(uname) = "XDarwin" ] ; then
3561 # We should have diskutil in OSX, but let's be sure...
3563 CDROMREADERSYNTAX=cddafs
3564 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3566 elif [ X$(uname) = "XOpenBSD" ] ; then
3570 elif [ X$(uname) = "XNetBSD" ] ; then
3574 elif [ X$(uname) = "SunOS" ] ; then
3582 # If CDDBAVAIL is set to n, no CDDB read is done
3586 # But before we get into business, let us chop off any GREP environmental
3591 if [ -z "$OUTPUTDIR" ]; then
3595 if [ -z "$WAVOUTPUTDIR" ]; then
3596 WAVOUTPUTDIR="$OUTPUTDIR"
3599 # Load system defaults
3600 if [ -r /etc/abcde.conf ]; then
3603 # Load user preference defaults
3604 if [ -r $HOME/.abcde.conf ]; then
3608 # By this time, we need some HTTPGETOPTS already defined.
3609 # If the user has defined a non-default HTTPGET method, we should not be empty.
3611 if [ "$HTTPGETOPTS" = "" ] ; then
3613 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3614 curl) HTTPGETOPTS="-f -s";;
3615 fetch)HTTPGETOPTS="-q -o -";;
3616 ftp) HTTPGETOPTS="-a -V -o - ";;
3617 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3621 # If the CDROM has not been set yet, find a suitable one.
3622 # If this is a devfs system, default to /dev/cdroms/cdrom0
3623 # instead of /dev/cdrom
3624 if [ "$CDROM" = "" ] ; then
3625 if [ -e /dev/cdroms/cdrom0 ]; then
3626 CDROM=/dev/cdroms/cdrom0
3627 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3628 CDROM=/dev/${BASH_REMATCH[1]}
3629 elif [ -e /dev/cdrom ]; then
3631 elif [ -e /dev/sr0 ]; then
3633 elif [ -e /dev/cd0c ]; then
3635 elif [ -e /dev/acd0c ]; then
3637 elif [ -e /dev/disk1 ]; then
3642 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3643 # that's changed to a number to allow for more control. Deal with
3644 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3645 case "$EXTRAVERBOSE" in
3654 # Parse command line options
3655 while getopts 1a:bc:C:d:DefgGhj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3658 a) ACTIONS="$OPTARG" ;;
3659 A) EXPACTIONS="$OPTARG" ;;
3661 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3662 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3663 d) CDROM="$OPTARG" ;;
3666 e) ERASEENCODEDSTATUS=y ;;
3667 E) ENCODING="$OPTARG" ;;
3672 j) MAXPROCS="$OPTARG" ;;
3675 L) CDDBUSELOCAL=y ;;
3680 o) OUTPUTTYPE="$OPTARG" ;;
3683 r) REMOTEHOSTS="$OPTARG" ;;
3684 R) CDDBLOCALRECURSIVE=y ;;
3685 s) SHOWCDDBFIELDS="$OPTARG" ;;
3686 S) CDSPEEDVALUE="$OPTARG" ;;
3687 t) STARTTRACKNUMBER="$OPTARG" ;;
3688 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
3691 echo "This is abcde v$VERSION."
3692 echo "Usage: abcde [options] [tracks]"
3693 echo "abcde -h for extra help"
3696 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
3698 X) CUE2DISCID="$OPTARG" ;;
3699 w) COMMENT="$OPTARG" ;;
3700 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
3701 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
3702 STARTTRACKNUMBERTAG="y"
3703 COMMENT="CD${OPTARG}"
3704 DISCNUMBER="${OPTARG}"
3706 log error "argument of -W must be integer"
3710 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
3715 shift $(($OPTIND - 1))
3717 # Here it comes the worse part of the whole thing. From here until we start
3718 # ripping, we have a mixture of sanity checks, verifications, default settigs
3719 # and other crazy stuff that interdepends, but hey, someone has to do it.
3721 # If NOCDDBQUERY is set, don't query the CDDB server.
3722 if [ "$NOCDDBQUERY" = "y" ]; then
3726 # If the user specified a flac file, then switch to special flac mode
3727 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
3728 if [ ! -f "$CDROM" ]; then
3729 log error "the defined file for FLAC ripping cannot be found" >&2
3732 vecho warning "switching to flac CDROMREADERSYNTAX..."
3733 CDROMREADERSYNTAX=flac
3734 # We have a builtin version of cue2discid...
3735 case "$CUE2DISCID" in
3737 *) NEEDCUE2DISCID=y;;
3743 # If the user provided a DISCID, disable eject
3744 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
3746 # Check the available cd rippers in the system, from the ones we know.
3747 if [ "$CDROMREADERSYNTAX" = "" ]; then
3748 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
3749 if new_checkexec $DEFAULT_CDROMREADER; then
3750 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
3754 if [ "$CDROMREADERSYNTAX" = "" ]; then
3755 log error "no cdreader found in your PATH"
3756 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3761 # Decide if we can continue.
3762 if [ "$ONETRACK" = "y" ]; then
3763 # FIXME # remove check as soon as we find out about the other readers
3764 case "$CDROMREADERSYNTAX" in
3766 cdparanoia | libcdio) ;;
3767 cdda2wav | icedax) ;;
3769 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
3772 if [ "$BATCHNORM" = "y" ]; then
3773 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3776 if [ "$NOGAP" = "y" ]; then
3777 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3780 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3781 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3782 if [ $# -gt 0 ]; then
3783 log warning "ONETRACK mode selected, grabbing all tracks..."
3786 while [ $# -gt 0 ]; do
3787 # Range parsing code courtesy of Vincent Ho
3788 # Cleaned up to use shell built-ins by Charles Steinkuehler
3789 if [ "${1#*[^0-9-]}" != "$1" ]; then
3790 log error "syntax error while processing track numbers ($1)"
3795 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3796 TRACKQUEUE="$TRACKQUEUE $RSTART"
3797 RSTART=$(( $RSTART + 1 ))
3804 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3805 # List of experimental actions: retag,transcode
3807 # Determine what actions are to be done from $ACTIONS and set the
3808 # following environment variables for them:
3820 ## FIXME ## Lets keep compatibility with -M
3821 [ "$DOCUE" != "y" ] && DOCUE=n
3823 for ACTION in $(echo $ACTIONS | tr , \ )
3826 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
3827 cue) DOCUE=y ; MAKECUEFILE=y ;;
3830 normalize) DONORMALIZE=y; DOREAD=y;;
3831 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3832 encode) DOENCODE=y; DOREAD=y;;
3833 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3834 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3835 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
3836 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
3837 playlist) DOCDDB=y; DOPLAYLIST=y;;
3839 getalbumart) GETALBUMART=y;;
3843 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3844 # FIXME # should we abort on error or just inform the user?
3845 log warning "selected both normalize and replaygain actions"
3848 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
3849 case $SHOWCDDBFIELD in
3850 y*|Y*) SHOWCDDBYEAR="y";;
3851 g*|G*) SHOWCDDBGENRE="y";;
3856 # At this point a CDROM has to be defined, so we check it exists.
3857 if [ X"$CDROM" != "X" ] ; then
3858 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
3859 if [ "$OSFLAVOUR" = "FBSD" ]; then
3860 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
3861 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
3862 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
3866 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
3867 log error "CDROM device cannot be found."
3870 # avoid processing if we are not going to hit the CDROM.
3871 elif [ X"$DOREAD" = "Xy" ]; then
3872 log error "CDROM has not been defined or cannot be found"
3876 # USEPIPES pre-tests, before we get into more serious stuff
3877 # Not compatible with:
3878 # - multiple outputs
3880 # - lowdisk algorithm
3882 if [ X"$USEPIPES" = "Xy" ]; then
3883 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
3884 log error "Unix pipes not compatible with multiple outputs"
3887 if [ X"$DONORMALIZE" = "Xy" ]; then
3888 log error "Unix pipes not compatible with normalizer"
3889 # FIXME # Do we need to exit or shall we just disable the mode?
3892 if [ X"$BATCHNORM" = "Xy" ]; then
3893 log error "Unix pipes not compatible with BATCHNORM encoding"
3896 if [ X"$NOGAP" = "Xy" ]; then
3897 log error "Unix pipes not compatible with NOGAP encoding"
3900 if [ X"$DOENCODE" = "Xn" ]; then
3901 vecho warning "Disabling Unix pipes since we are not encoding!"
3904 if [ X"$LOWDISK" = "Xy" ]; then
3905 log error "Unix pipes not compatible with lowdisk algorithm"
3910 # LOWDISK pre-tests, before we get into more problematic stuff
3911 # Not compatible with anything that needs all the files in the hard disc:
3914 if [ X"$LOWDISK" = "Xy" ]; then
3915 if [ X"$BATCHNORM" = "Xy" ]; then
3916 log error "Unix pipes not compatible with BATCHNORM encoding"
3919 if [ X"$NOGAP" = "Xy" ]; then
3920 log error "Unix pipes not compatible with NOGAP encoding"
3925 # BATCHNORM pre-tests, before we get into serious problems
3926 # Not compatible with
3927 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3928 vecho warning "Disabling BATCHNORM since we are not normalizing!"
3932 # Check the encoding format from the ones available in the system, if nothing has been configured.
3933 if [ X"$OUTPUTTYPE" = "X" ]; then
3934 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
3935 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3936 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3937 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
3938 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
3939 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3943 if [ X"$OUTPUTTYPE" = "X" ]; then
3944 log error "no encoder found in the PATH"
3945 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3950 # Decide which CDROM reader we're gonna use
3951 case "$CDROMREADERSYNTAX" in
3953 CDROMREADER="$CDPARANOIA"
3954 CDROMREADEROPTS="$CDPARANOIAOPTS"
3957 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
3958 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
3959 CDROMREADER="$CD_PARANOIA"
3960 CDROMREADEROPTS="$CDPARANOIAOPTS"
3963 CDROMREADER="$CDDA2WAV"
3964 CDROMREADEROPTS="$CDDA2WAVOPTS"
3967 CDROMREADER="$DAGRAB"
3968 CDROMREADEROPTS="$DAGRABOPTS"
3972 CDROMREADEROPTS="$PIRDOPTS"
3975 CDROMREADER="$CDDAFS"
3976 CDROMREADEROPTS="$CDDAFSOPTS"
3980 CDROMREADEROPTS="$FLACOPTS"
3984 # There's only one normalize...
3985 case "$NORMALIZERSYNTAX" in
3987 NORMALIZER="$NORMALIZE"
3988 NORMALIZEROPTS="$NORMALIZEOPTS"
3992 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3993 case "$OUTPUTTYPE" in *:*)
3994 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
3995 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
3997 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3998 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3999 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4000 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4001 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4002 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4003 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4004 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4005 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4008 # Allows commandline selection of options while using multiple outputs.
4009 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4010 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4011 TEMPOUTPUT=${OUTPUT%%:*}
4012 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4014 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4018 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4019 # for flacs and speexenc for speex and mpcenc for mpcs and faac for m4as and
4020 # wavpack for wvs...
4022 # Getting ready for multiple output changes
4023 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4027 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4028 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4029 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4030 OGGOUTPUTCONTAINER=ogg
4033 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4034 OPUSOUTPUTCONTAINER=opus
4037 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4038 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4039 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4042 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4043 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4044 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4045 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4048 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4049 # [ "$DOREPLAYGAIN" = "y" ] &&
4052 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4053 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4056 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4058 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4061 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4062 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4065 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4067 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4068 # compiled without libmp4v2... Andrew.
4071 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4072 [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4073 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4076 if [ "$KEEPWAVS" = "y" ]; then
4077 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4081 *) log error "Invalid OUTPUTTYPE defined"
4087 # decide which encoder
4088 case "$MP3ENCODERSYNTAX" in
4090 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4094 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
4095 MP3ENCODER="$TOOLAME"
4098 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4102 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4103 MP3ENCODER="$BLADEENC"
4106 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4110 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4111 MP3ENCODER="$XINGMP3ENC"
4114 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4115 MP3ENCODER="$MP3ENC"
4118 case "$OGGENCODERSYNTAX" in
4120 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4121 OGGENCODER="$VORBIZE"
4124 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4125 OGGENCODER="$OGGENC"
4128 case "$OPUSENCODERSYNTAX" in
4130 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4131 OPUSENCODER="$OPUSENC"
4134 case "$FLACENCODERSYNTAX" in
4136 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4138 if [ "$DOREPLAYGAIN" = "y" ]; then
4139 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4141 # FLAC streams can be encapsulated on a Ogg transport layer
4142 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4143 log error "FLAC on an Ogg container is not yet supported"
4144 log error "due to problem with adding comments to such files"
4146 FLACOUTPUTCONTAINER=ogg
4148 FLACOUTPUTCONTAINER=flac
4152 case "$SPEEXENCODERSYNTAX" in
4154 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4155 SPEEXENCODER="$SPEEXENC"
4158 case "$MPCENCODERSYNTAX" in
4160 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4161 MPCENCODER="$MPCENC"
4164 case "$WVENCODERSYNTAX" in
4166 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4170 case "$APENCODERSYNTAX" in
4172 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4176 case "$AACENCODERSYNTAX" in
4177 # Some elaborate 'if' work to keep backward compatability for those
4178 # who don't realise that AACENCOPTS does not work with abcde from
4179 # version 2.6.1 onwards.
4181 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4182 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4185 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4190 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4191 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4192 AACENCODER="$NEROAACENC"
4194 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4195 AACENCODER="$NEROAACENC"
4199 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4200 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4201 AACENCODER="$FDKAAC"
4203 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4204 AACENCODER="$FDKAAC"
4214 TAGGEROPTS="$ID3OPTS"
4219 TAGGEROPTS="$ID3V2OPTS"
4223 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4224 # trouble with CDDBPROTO=5 (which we test here) but also
4225 # with cached cddb files in latin1 (which we cannot test).
4226 if [ "$CDDBPROTO" -lt 6 ]; then
4227 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4230 # eyeD3 version 0.7 changed syntax
4231 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4232 # only if it offers the --set-encoding, assume <= 0.6.x
4234 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4236 # anything wrong, any failure, assume >= 0.7
4238 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4242 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4247 # NOGAP is specific to lame. Other encoders fail ...
4248 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4249 log warning "the NOGAP option is specific to lame. Deactivating..."
4254 case "$CUEREADERSYNTAX" in
4256 CUEREADEROPTS="${CDROM}"
4261 # which information retrieval tool are we using?
4267 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4268 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4269 log error "FLAC on an Ogg container is not yet supported"
4270 log error "due to problem with adding comments to such files"
4272 OGGOUTPUTCONTAINER=ogg.ogg
4273 FLACOUTPUTCONTAINER=flac.ogg
4274 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4277 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4279 if [ "$ENCNICE" ]; then
4280 ENCNICE="-n $ENCNICE"
4282 if [ "$READNICE" ]; then
4283 READNICE="-n $READNICE"
4285 if [ "$DISTMP3NICE" ]; then
4286 DISTMP3NICE="-n $DISTMP3NICE"
4289 # Don't check for stuff if it's not needed
4290 if [ "$REMOTEHOSTS" ]; then
4293 if [ "$DONORMALIZE" = "y" ]; then
4296 if [ "$EJECTCD" = "y" ]; then
4299 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4300 if [ "$CDDBMETHOD" = "cddb" ]; then
4302 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4306 if [ "$DOCUE" = "y" ]; then
4310 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4311 case "$CDROMREADERSYNTAX" in
4312 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4313 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4314 ### FIXME ### translate "cue2discid" from python to bash
4315 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4320 if [ "$GETALBUMART" = "y" ]; then
4325 ###USEPIPESSUPPORT###
4327 # Rippers with USEPIPE support
4328 PIPERIPPER_cdparanoia="-"
4329 PIPERIPPER_libcdio="-"
4330 # Note that by default in abcde cdda2wav redirects to icedax.
4331 PIPERIPPER_cdda2wav="-"
4332 PIPERIPPER_debug="-"
4333 PIPERIPPER_flac="-c "
4336 # Encoders with USEPIPE support
4339 PIPE_bladeenc="stdin"
4347 # Both neroAacEnc and fdkaac seem to manage without the addition of
4348 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4349 # in this manner. Andrew.
4353 # Figure out if we can use pipes with the ripper/encoder combination
4355 if [ "$USEPIPES" = "y" ]; then
4356 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4359 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4361 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4363 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4365 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4367 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4369 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4371 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4373 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4375 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4377 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4378 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4379 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4380 log error "no support for pipes with given ripper"
4381 log error "read the FAQ file from the source tarball to get help."
4384 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4385 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4386 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4387 log error "no support for pipes with given encoder"
4388 log error "read the FAQ file from the source tarball to get help"
4393 # Make sure a buncha things exist
4394 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4395 $OGGENCODER $OPUSENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4396 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER \
4397 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4398 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4399 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4400 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4401 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4402 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4403 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4404 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4410 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4411 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4412 # these files). The resulting files are actually ADTS streams which belong in an
4413 # aac container and with some version sniffing this is all cleaned up below. If
4414 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4416 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4417 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4418 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4419 echo "WARNING: Your copy of Faac does not have mp4 support"
4420 echo "WARNING: Encoding untagged files to aac..."
4423 echo "Using Faac to Tag AAC Tracks..."
4427 # And last but not least, check if we can diff between files. We do not abort,
4428 # since diffing is not critical...
4429 if [ -x $(which $DIFF) ]; then :; else
4430 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4434 ## Now that we have metaflac, check if we need cue2discid
4435 #case $CDROMREADERSYNTAX in
4437 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4438 # if [ "$TRACKINFO" = "" ]; then
4439 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4444 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4445 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4446 HTTPGET="$HTTPGET $HTTPGETOPTS"
4448 # Here it used to say:
4449 # One thousand lines in, we can start doing stuff with things
4450 # Well, right now we are at line 3737 ;)
4452 # Export needed things so they can be read in this subshell
4453 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4454 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4456 if [ "$DOREAD" = "y" ]; then
4457 # User-definable function to set some things. Use it for
4458 # - closing the CD tray with eject -t
4459 # - set the CD speed value with eject -x
4460 vecho -n "Executing customizable pre-read function... "
4462 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4467 # Get ABCDETEMPDIR created and status file initialized
4470 if [ "$DOCDDB" = "y" ]; then
4471 # start with a sane default:
4472 CDDBLOCALSTATUS=notfound
4473 if [ $CDDBUSELOCAL = "y" ]; then
4476 if checkstatus cddb-choice > /dev/null; then
4479 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4480 case "$CDDBMETHOD" in
4491 CHOICE=$(checkstatus cddb-choice)
4492 if [ "$CHOICE" = 0 ] ; then
4493 # We don't have any information at all; try to fall back
4494 # to CD-Text for basic information
4495 vecho "No CDDB information found, trying cdtext from the CD"
4501 eval "$($CDDBTOOL parse "$CDDBDATA")"
4504 # Before reading tracks, we set the speed of the device
4506 if [ X"$CDSPEEDVALUE" != "X" ]; then
4507 case "$CDROMREADERSYNTAX" in
4508 cdparanoia|libcdio|debug) ;;
4515 # Define the first and last track, since we might need them later in several places
4516 FIRSTTRACK=$( get_first $TRACKQUEUE )
4517 LASTTRACK=$( get_last $TRACKQUEUE )
4519 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
4520 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4521 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
4522 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
4525 if checkstatus onetrack ; then ONETRACK=y ; fi
4527 if [ "$ONETRACK" = "y" ]; then
4528 # Reuse the CUEFILE in case we created it (now or in a previous run)
4529 if CUEFILE=$(checkstatus cuefile); then
4534 # Create playlist if needed (backgroundable) and start reading in tracks
4538 if [ ! "$ONETRACK" = "y" ]; then
4539 if [ "$DOPLAYLIST" = "y" ]; then
4540 echo Creating playlist... >&2
4545 if [ "$GETALBUMART" = "y" ]; then
4549 # For the lowdisk option, only one program is running at once so the encoder
4550 # can be unsilenced right away.
4551 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
4552 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4555 if [ "$ONETRACK" = "y" ]; then
4556 TRACKS="$FIRSTTRACK"
4557 if [ "$USEPIPES" = "y" ]; then
4558 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
4559 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
4562 if checkstatus readtrack-$FIRSTTRACK; then :; else
4563 do_cdread onetrack $FIRSTTRACK $LASTTRACK
4567 for UTRACKNUM in $TRACKQUEUE
4569 if [ "$DOREAD" = "y" ]; then
4570 if [ "$USEPIPES" = "y" ]; then
4571 if checkstatus readencodetrack-$UTRACKNUM; then :; else
4572 # Read, pipe, shut up!
4573 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
4576 if checkstatus readtrack-$UTRACKNUM; then :; else
4577 do_cdread $UTRACKNUM
4579 if [ "$?" != "0" ]; then
4580 # CD read failed - don't give the goahead to
4587 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
4590 # If we are not reading, set the encode output to loud already, so
4591 # that we can see the output of the first track.
4592 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4593 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4595 echo NEXTTRACK # Get the encoder machine churning again
4596 if [ "$DOREAD" = "y" ]; then
4597 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4598 until checkstatus encodetrack-$UTRACKNUM
4600 if checkerrors encodetrack-$UTRACKNUM; then
4611 # Now that we're done the encoding can be loud again -
4612 # if we're not using SMP.
4613 if [ "$MAXPROCS" = "1" ]; then
4614 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4617 # All tracks read, start encoding.
4618 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
4622 # Execute the user-defined post_read function before ejecting CD
4625 # We are now finished with the cdrom - it can be safely ejected. Note that
4626 # abcde will not have completed yet.
4627 if [ "$EJECTCD" = "y" ]; then
4628 # We check if the disk we are processing is actually the disk inside the
4629 # CD tray. If not, we do not eject the CD, since it might be so that the
4630 # user ejected it manually.
4631 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4632 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4633 # More FreeBSD bits.
4634 if [ X"$(uname)" = X"FreeBSD" ] ; then
4635 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4636 # but in this script EJECT is in the envionment and names the program
4639 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4640 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4641 $eject $EJECTOPTS $cd
4642 elif [ X"$(uname)" = X"Darwin" ] ; then
4643 diskutil eject ${CDROM#/dev/} 0
4644 elif [ -x $(which $EJECT) ]; then
4645 $EJECT $EJECTOPTS "$CDROM"
4652 ## Do we need to pre-process
4653 #if [ x"$PREPROCESS" = "x" ] ; then
4656 # for PRETRACKNUM in $TRACKQUEUE
4659 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4661 # until [ $PREPROCEED ]
4663 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4664 # # all locations are working, wait and try again later
4665 # if [ ! $PREPROCEED ]; then sleep 3; fi
4667 # ( do_preprocess $PRETRACKNUM
4675 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4677 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
4678 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4679 if [ "$GOAHEAD" = "NO" ]; then break; fi
4680 for LASTTRACK in $TRACKQUEUE; do :; done
4681 if checkstatus readtrack-$LASTTRACK; then
4682 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4683 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
4684 if checkerrors batch-normalize; then exit 1; fi
4686 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4687 if [ "$DONORMALIZE" = "y" ]; then
4688 for UTRACKNUM in $TRACKQUEUE
4690 if checkstatus readtrack-$UTRACKNUM; then
4691 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4695 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
4696 if checkerrors nogap-encode; then exit 1; fi
4701 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4702 if [ "$ONETRACK" = "y" ] ; then
4703 TRACKQUEUE="$FIRSTTRACK"
4704 TRACKS="$FIRSTTRACK"
4707 # Do the encoding, including parallelization of remote encoding
4708 # Figure out where each track is going to be encoded
4709 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
4710 if [ "$MAXPROCS" != "0" ]; then
4711 for NUM in $(f_seq_row 1 "$MAXPROCS")
4713 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
4717 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
4718 for UTRACKNUM in $TRACKQUEUE
4721 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
4722 if [ "$GOAHEAD" = "NO" ]; then break; fi
4723 # find out where this track is to be encoded
4724 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4725 # Make sure we have a place to encode this, if not, exit stage right
4726 if [ -z "$ENCODELOCATIONS" ]; then
4732 for LOCATION in $ENCODELOCATIONS
4734 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4735 # check first if a track has ever been assigned to this location
4736 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
4737 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4738 if checkerrors encodetrack-$PREVIOUSTRACK; then
4739 for TEMPLOCATION in $ENCODELOCATIONS
4741 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4742 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
4745 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
4750 # We're still here, this location must have been previously assigned,
4751 # and last completed without error - check if it's done with the
4752 # previous track yet
4753 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
4755 # all locations are working, wait and try again later
4756 if [ ! $PROCEED ]; then sleep 3; fi
4758 # Record the location we're about to encode the next track at
4759 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4761 # Don't proceed with the rest of the loop if we can't encode
4762 if [ "$ABORT" ]; then continue; fi
4763 ## FIXME ## Add here
4764 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4765 # Set TRACKNUM, TRACKNAME
4766 if [ -e "$CDDBDATA" ]; then
4767 if [ "$ONETRACK" = "y" ]; then
4769 TRACKNUM="$FIRSTTRACK"
4773 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
4774 getcddbinfo TRACKNAME
4778 # You can't encode a file which needs to be normalized before finishing
4779 # You can't tag a file before it's finished encoding -
4780 # thus all of this is backgrounded together
4782 if [ "$DONORMALIZE" = "y" ]; then
4783 if checkstatus readtrack-$UTRACKNUM; then
4784 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
4787 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4788 if checkstatus readtrack-$UTRACKNUM; then
4789 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4790 if [ "$DONORMALIZE" = "y" ]; then
4791 if checkstatus normalizetrack-$UTRACKNUM; then
4792 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4795 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
4799 if [ "$DOTAG" = "y" ]; then
4800 if checkstatus encodetrack-$UTRACKNUM; then
4801 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
4803 # Lets tag the cue file
4804 if checkstatus cleancuefile >/dev/null; then :; else
4805 if checkstatus cuefile >/dev/null ; then
4810 if [ "$DOMOVE" = "y" ]; then
4811 if checkstatus tagtrack-$UTRACKNUM; then
4812 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
4819 # Go through it again and make sure there's no distmp3 stragglers, otherwise
4820 # we'll delete the files they're working on
4821 # Do NOT play ball if there is no ball to play (so ABORT if needed)
4822 ## FIXME ## Check also for files which are encoded using PIPEs.
4823 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
4828 for LOCATION in $ENCODELOCATIONS
4830 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
4831 # "How can he give us a status update, if he's DEAD?"
4832 if checkstatus encodetrack-$CHECKTRACK; then
4835 # Nothing to see here please go quietly back to your homes
4836 if [ -z "$CHECKTRACK" ]; then continue; fi
4837 # You're still here? Maybe there is something...
4838 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
4841 if [ ! $PROCEED ]; then sleep 5; fi
4844 # If the above didn't catch the stragglers, this will
4846 if [ "$DOREPLAYGAIN" = "y" ]; then
4850 # Execute the user-defined post_encode function before cleaning up
4853 # Check to see if run_command logged any errors
4854 if [ -f "$ABCDETEMPDIR/errors" ]; then
4855 log error "The following commands failed to run:"
4856 cat "$ABCDETEMPDIR/errors"
4860 if [ "$KEEPWAVS" = "y" ];then
4864 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
4865 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
4866 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
4867 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
4868 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
4869 log warning "The encoded formats does not match with the moved ones"
4870 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
4871 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
4872 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
4876 if [ "$DOCLEAN" = "y" ]; then
4877 # Wipe all the evidence
4878 # Gimme gimme gimme some more time!
4880 rm -rf "$ABCDETEMPDIR"
4883 echo "Finished. Not cleaning $ABCDETEMPDIR."