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 # Copyright (c) 2015-2016 Andrew Strong <andrew.david.strong@gmail.com>
7 # This code is hereby licensed for public consumption under either the
8 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
10 # You should have received a copy of the GNU General Public License along
11 # with this program; if not, write to the Free Software Foundation, Inc.,
12 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14 VERSION='2.8.2-UNRELEASED'
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform:"
24 echo " cddb,read,getalbumart,embedalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
25 #echo "-A Experimental actions (retag, transcode)"
26 echo "-b Enable batch normalization"
27 echo "-B Embed albumart (this also activates getalbumart)"
29 echo " Specify a configuration file (overrides system and user config files)"
31 echo " Specify discid to resume from (only needed if you no longer have the cd)"
33 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
34 echo "-D Debugging mode (equivalent to sh -x abcde)"
35 echo "-e Erase encoded track information from status file"
36 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
37 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
38 echo "-G Get album art by using the 'getalbumart' action"
39 echo "-h This help information"
40 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
41 echo "-j <#> Number of encoder processes to run at once (localhost)"
42 echo "-k Keep the wav tracks for later use"
43 echo "-l Use low disk space algorithm"
44 echo "-L Use local CDDB storage directory"
45 echo "-m Modify playlist to include CRLF endings, to comply with some players"
46 #echo " WARNING: Deprecated. Use \"cue\" action"
47 #echo "-M Create a CUE file"
48 echo "-n No lookup. Don't query CDDB, just create and use template"
49 echo "-N Noninteractive. Never prompt for anything"
50 echo "-o <type1[,type2]...>"
51 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,mka,wv,ape,mp2,tta,aiff). Defaults to vorbis"
52 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
53 echo "-P Use UNIX pipes to read+encode without wav files"
54 echo "-Q Select CDDBMETHOD from the command line. Choice is cddb or musicbrainz".
55 echo "-r <host1[,host2]...>"
56 echo " Also encode on these remote hosts"
58 echo " Show fields from the CDDB info (year,genre)"
59 echo "-S <#> Set the CD speed"
60 echo "-t <#> Start the track numbering at a given number"
61 echo "-T <#> Same as -t but modifies tag numbering"
62 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
63 echo "-v Show version number and exit"
64 echo "-V Be a bit more verbose about what is happening behind the scenes"
65 echo "-x Eject CD after all tracks are read"
67 echo " Add a comment to the CD tracks"
68 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
69 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
71 echo "Tracks is a space-delimited list of tracks to grab."
72 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
74 #echo "Double hyphens are used to concatenate tracks"
79 echo "$@" >> "$ABCDETEMPDIR/status"
82 # log [level] [message]
84 # log outputs the right message in a common format
90 error) >&2 echo "[ERROR] abcde: $@" >&2 ;;
91 warning) >&2 echo "[WARNING] $@" >&2 ;;
92 info) >&4 echo "[INFO] $@" ;;
96 # Functions to replace the need of seq, which is too distribution dependent.
100 while [ $i -ne `expr $2 + 1` ]
110 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
111 while [ $i -ne `expr $2 + 1` ]
118 log error "syntax error while processing track numbers ($i)"
123 # Functions to replace the need of awk {print $1} and {print $NF}
126 if [ X"$1" = "X" ]; then
127 for first in `cat`; do
138 if [ X"$1" = "X" ]; then
139 for stdin in `cat`; do
143 for last in $@ ; do :; done
148 # checkstatus [blurb]
149 # Returns "0" if the blurb was found, returns 1 if it wasn't
150 # Puts the blurb content, if available, on stdout.
151 # Otherwise, returns "".
154 # Take the last line in the status file if there's multiple matches
156 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
158 if [ -z "$BLURB" ]; then
163 # See if there's a = in it
164 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
165 echo "$(echo $BLURB | cut -f2- -d=)"
171 # checkwarnings [blurb]
172 # Returns "0" if the blurb was found (meaning there was an warning),
173 # returns 1 if it wasn't (yes this is a little backwards).
174 # Does not print the blurb on stdout.
175 # Otherwise, returns "".
178 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
181 # Take the last line in the status file if there's multiple matches
183 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
185 if [ -z "$BLURB" ]; then
186 # negative, we did not have a negative...
189 # affirmative, we had a negative...
194 # checkerrors [blurb]
195 # Returns "0" if the blurb was found (meaning there was an error),
196 # returns 1 if it wasn't (yes this is a little backwards).
197 # Does not print the blurb on stdout.
198 # Otherwise, returns "".
201 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
204 # Take the last line in the status file if there's multiple matches
206 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
208 if [ -z "$BLURB" ]; then
209 # negative, we did not have a negative...
212 # affirmative, we had a negative...
218 # Finds the right pager in the system to display a file
222 # Use the debian sensible-pager wrapper to pick the pager
223 # user has requested via their $PAGER environment variable
224 if [ -x "/usr/bin/sensible-pager" ]; then
225 /usr/bin/sensible-pager "$PAGEFILE"
226 elif [ -x "$PAGER" ]; then
227 # That failed, try to load the preferred editor, starting
228 # with their PAGER variable
230 # If that fails, check for less
231 elif [ -x /usr/bin/less ]; then
232 /usr/bin/less -f "$PAGEFILE"
233 # more should be on all UNIX systems
234 elif [ -x /bin/more ]; then
235 /bin/more "$PAGEFILE"
237 # No bananas, just cat the thing
242 # run_command [blurb] [command...]
243 # Runs a command, silently if necessary, and updates the status file
249 # See if this is supposed to be silent
250 if [ "$(checkstatus encode-output)" = "loud" ]; then
254 # Special case for SMP, since
255 # encoder output is never displayed, don't mute echos
256 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
265 normalize|normalize-audio)
266 if [ "$RETURN" = "2" ]; then
267 # File was already normalized.
272 if [ "$RETURN" != "0" ]; then
273 # Put an error in the errors file. For various reasons we
274 # can't capture a copy of the program's output but we can
275 # log what we attempted to execute and the error code
276 # returned by the program.
277 if [ "$BLURB" ]; then
280 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
281 return $RETURN # Do not pass go, do not update the status file
283 if [ "$BLURB" ]; then
284 echo $BLURB >> "$ABCDETEMPDIR/status"
288 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
289 # distributed under the terms of the GNU GPL v2 or later, at your option
291 # Function to determine if a word contains a slash.
300 # Function to give the relative path from one file to another.
301 # Usage: relpath fromfile tofile
302 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
303 # (the result would be Album/Song.mp3)
304 # Output is relative path to $2 from $1 on stdout
306 # This code has the following restrictions:
307 # Multiple ////s are not collapsed into single /s, with strange effects.
308 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
309 # If FR is a directory it must have a trailing /
317 /*) ;; # No processing is needed for absolute paths
319 # Loop through common prefixes, ignoring them.
320 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
322 FR="$(echo "$FR" | cut -d/ -f2-)"
323 TO="$(echo "$TO" | cut -d/ -f2-)"
325 # Loop through directory portions left in FR, adding appropriate ../s.
328 FR="$(echo "$FR" | cut -d/ -f2-)"
339 if [ ! "$@" = "" ]; then
340 # Cut off any command-line option we added in
341 X=$(echo $@ | cut -d' ' -f2)
342 if [ "$(which $X)" = "" ]; then
344 elif [ ! -x $(which $X) ]; then
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X=$(echo $@ | cut -d' ' -f2)
356 # Test for built-in abcde.function
357 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
358 if [ "$(which $X)" = "" ]; then
359 log error "$X is not in your path." >&2
360 log info "Define the full path to the executable if it exists on your system." >&2
361 if [ -e /etc/debian_* ] ; then
363 oggenc) MISSING_PACKAGE=vorbis-tools ;;
364 lame|flac) MISSING_PACKAGE=$X ;;
366 log info "Hint: sudo 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 -a ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
419 TRACKNAME="$(grep -a ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
422 grep -a ^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="$(mungetrackname "$TRACKNAME")"
532 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
533 ALBUMFILE="$(mungealbumname "$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
847 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
848 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
849 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
850 -y "$CDYEAR" -g "$GENREID" \
851 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
852 "$ABCDETEMPDIR/track$1.$OUTPUT"
855 # FIXME # track numbers in mp3 come with 1/10, so we cannot
856 # happily substitute them with $TRACKNUM
858 eyed3_06) addopts=( \
859 ${ENCODING:+--set-encoding="$ENCODING"} \
860 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
861 # We set 'recording-date' so the date tag will show
862 # in Audacious, vlc and friends... Andrew.
863 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
864 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
867 ${ENCODING:+--encoding="$ENCODING"} \
868 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
869 # We set 'recording-date' so the date tag will show
870 # in Audacious, vlc and friends... Andrew.
871 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
872 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
875 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
877 -a "$TRACKARTIST" -t "$TRACKNAME" \
878 -G "$GENREID" -n "${TRACKNUM:-$1}" \
879 ${TRACKNUM:+-N "$TRACKS"} \
881 "$ABCDETEMPDIR/track$1.$OUTPUT"
884 log error "Internal error: ID3SYNTAX has an illegal value"
890 case "$OGGENCODERSYNTAX" in
892 # vorbiscomment can't do in-place modification, mv the file first
893 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
894 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
898 # https://www.xiph.org/vorbis/doc/v-comment.html
900 echo ARTIST="$TRACKARTIST"
902 echo TITLE="$TRACKNAME"
903 if [ -n "$CDYEAR" ]; then
906 if [ -n "$CDGENRE" ]; then
907 echo GENRE="$CDGENRE"
909 echo TRACKNUMBER=${TRACKNUM:-$1}
910 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
911 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
912 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
913 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
914 echo TRACKTOTAL="${TRACKS}"
915 if [ -n "$DISCNUMBER" ]; then
916 echo DISCNUMBER="$DISCNUMBER"
918 echo CDDB=$CDDBDISCID
919 if [ "$(eval echo ${COMMENT})" != "" ]; then
920 case "$COMMENTOUTPUT" in
921 *=*) echo "$COMMENTOUTPUT";;
922 *) echo COMMENT="$COMMENTOUTPUT";;
925 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
926 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
927 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
928 # Doublecheck that the commented file was created
929 # successfully before wiping the original
930 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
931 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
933 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
939 run_command tagtrack-$OUTPUT-$1 true
942 run_command tagtrack-$OUTPUT-$1 true
945 run_command tagtrack-$OUTPUT-$1 true
949 echo ARTIST="$TRACKARTIST"
951 echo TITLE="$TRACKNAME"
952 if [ -n "$CDYEAR" ]; then
955 if [ -n "$CDGENRE" ]; then
956 echo GENRE="$CDGENRE"
958 echo TRACKNUMBER="${TRACKNUM:-$1}"
959 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
960 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
961 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
962 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
963 echo TRACKTOTAL="${TRACKS}"
964 if [ -n "$DISCNUMBER" ]; then
965 echo DISCNUMBER="$DISCNUMBER"
967 echo CDDB="$CDDBDISCID"
968 if [ "$(eval echo ${COMMENT})" != "" ]; then
969 case "$COMMENTOUTPUT" in
970 *=*) echo "$COMMENTOUTPUT";;
971 *) echo COMMENT="$COMMENTOUTPUT";;
974 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
975 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
978 run_command tagtrack-$OUTPUT-$1 true
981 run_command tagtrack-$OUTPUT-$1 true
984 run_command tagtrack-$OUTPUT-$1 true
987 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
988 # Console port (mac) used for encoding does not have the ability to tag.
989 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
990 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
991 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
994 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
995 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
996 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
997 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
998 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
999 "$ABCDETEMPDIR/track$1.mp2"
1002 run_command tagtrack-$OUTPUT-$1 true
1005 case "$AACENCODERSYNTAX" in
1007 # We will use inline tagging...
1008 run_command tagtrack-$OUTPUT-$1 true
1011 # Tag post encode with neroAacTag...
1012 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
1013 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
1014 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1017 run_command tagtrack-$OUTPUT-$1 true
1020 run_command tagtrack-$OUTPUT-$1 true
1023 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1024 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1025 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$ATOMICPARSLEY" "$ABCDETEMPDIR/track$1.m4a" \
1026 --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum=${TRACKNUM:-$1} \
1027 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
1030 run_command tagtrack-$OUTPUT-$1 true
1035 # We use mid3v2 tagging for True Audio:
1036 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1037 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1038 "$ABCDETEMPDIR/track$1.tta"
1041 run_command tagtrack-$OUTPUT-$1 true
1045 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1046 run_command tagtrack-$1 true
1052 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1055 # The commands here don't go through run_command because they're never
1056 # supposed to be silenced
1057 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1058 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1062 case "$MP3ENCODERSYNTAX" in
1067 for UTRACKNUM in $TRACKQUEUE
1069 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1071 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1073 if [ "$RETURN" != "0" ]; then
1074 echo "nogap-encode: $ENCODER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1076 for UTRACKNUM in $TRACKQUEUE
1078 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1079 #run_command encodetrack-$UTRACKNUM true
1088 if checkerrors "nogap-encode"; then :; else
1089 if [ ! "$KEEPWAVS" = "y" ] ; then
1090 if [ ! "$KEEPWAVS" = "move" ] ; then
1095 # Other encoders fall through to normal encoding as the tracks have not
1096 # been entered in the status file.
1099 # do_encode [tracknumber] [hostname]
1100 # If no hostname is specified, encode locally
1102 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1103 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1106 if [ "$USEPIPES" = "y" ]; then
1109 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1112 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1115 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1118 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1121 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1124 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1127 TEMPARG="PIPE_$SPEEXENCODER"
1130 TEMPARG="PIPE_$MPCENCODER"
1133 TEMPARG="PIPE_$WVENCODERSYNTAX"
1136 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1139 TEMPARG="PIPE_$AACENCODERSYNTAX"
1142 TEMPARG="PIPE_$AACENCODERSYNTAX"
1145 IN="$( eval echo "\$$TEMPARG" )"
1147 IN="$ABCDETEMPDIR/track$1.wav"
1149 # We need IN to proceed, if we are not using pipes.
1150 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1151 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1153 case "$TMPOUTPUT" in
1155 OUTPUT=$OGGOUTPUTCONTAINER
1158 OUTPUT=$OPUSOUTPUTCONTAINER
1161 OUTPUT=$MKAOUTPUTCONTAINER
1164 OUTPUT=$AIFFOUTPUTCONTAINER
1167 OUTPUT=$FLACOUTPUTCONTAINER
1173 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1174 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1177 if [ X"$USEPIPES" = "Xy" ]; then
1179 # We need a way to store the creation of the files when using PIPES
1180 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1181 # When piping it does not make sense to have a higher nice for
1182 # reading than for encoding, since it will be hold by the
1183 # encoding process. Setting an effective nice, to calm down a
1184 # bit the reading process.
1185 EFFECTIVE_NICE=$READNICE
1187 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1188 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1189 EFFECTIVE_NICE=$ENCNICE
1195 case "$MP3ENCODERSYNTAX" in
1196 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1197 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1198 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1199 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1203 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1210 case "$OGGENCODERSYNTAX" in
1211 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1212 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1216 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1223 case "$OPUSENCODERSYNTAX" in
1225 # Tag the file at encode time, as it can't be done after encoding.
1226 if [ "$DOTAG" = "y" ]; then
1227 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1228 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1229 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1231 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1237 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1242 case "$MKAENCODERSYNTAX" in
1244 if [ "$DOTAG" = "y" ]; then
1245 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS -metadata artist="$TRACKARTIST" \
1246 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1247 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1249 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1255 case "$AIFFENCODERSYNTAX" in
1257 if [ "$DOTAG" = "y" ]; then
1258 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS -metadata artist="$TRACKARTIST" \
1259 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1260 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1262 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1270 case "$FLACENCODERSYNTAX" in
1271 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1276 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1277 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1282 if [ "$(eval echo ${COMMENT})" != "" ]; then
1285 *) COMMENT="COMMENT=$COMMENT" ;;
1288 # Tag the file at encode time, as it can't be done after encoding.
1289 if [ "$DOTAG" = "y" ]; then
1290 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1291 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1293 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1297 # Tag the file inline at encode time.
1298 if [ "$DOTAG" = "y" ]; then
1299 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1300 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1302 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1306 case "$TTAENCODERSYNTAX" in
1307 # tta is the newer version with a small syntax change...
1309 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1312 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1317 case "$WVENCODERSYNTAX" in
1319 if [ "$DOTAG" = "y" ]; then
1320 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1321 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1323 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1327 if [ "$DOTAG" = "y" ]; then
1328 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1329 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1330 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1332 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1338 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1341 case "$MP2ENCODERSYNTAX" in
1343 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1346 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1351 # aac container is only used to catch faac encoded files where faac
1352 # is compiled without mp4 support (with libmp4v2).
1353 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1356 case "$AACENCODERSYNTAX" in
1358 if [ "$DOTAG" = "y" ]; then
1359 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1360 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1362 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1366 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1369 if [ "$DOTAG" = "y" ]; then
1370 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1371 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1373 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1377 if [ "$DOTAG" = "y" ]; then
1378 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1379 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1381 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1385 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1388 if [ "$DOTAG" = "y" ]; then
1389 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1390 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1391 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1393 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1399 # In case of wav output we need nothing. Just keep the wavs.
1400 # But we need the following to allow full logging and subsequent
1401 # successful cleaning of $ABCDETEMPDIR.
1402 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1407 # Only remove .wav if the encoding succeeded
1408 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1409 run_command encodetrack-$1 true
1410 if [ ! "$KEEPWAVS" = "y" ] ; then
1411 if [ ! "$KEEPWAVS" = "move" ] ; then
1417 run_command "" echo "HEH! The file we were about to encode disappeared:"
1418 run_command "" echo ">> $IN"
1419 run_command encodetrack-$1 false
1423 # do_preprocess [tracknumber]
1425 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1428 # IN="$ABCDETEMPDIR/track$1.wav"
1429 # # We need IN to proceed.
1430 # if [ -s "$IN" ] ; then
1431 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1433 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1434 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1435 # case "$POSTPROCESSFORMAT" in
1437 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1439 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1441 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1443 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1445 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1448 # # Only remove .wav if the encoding succeeded
1449 # if checkerrors "preprocess-(.{3,4})-$1"; then
1450 # run_command preprocess-$1 false
1452 # run_command preprocess-$1 true
1455 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1456 # echo "HEH! The file we were about to pre-process disappeared:"
1459 # run_command preprocess-$1 false
1464 # do_postprocess [tracknumber]
1466 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1469 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1471 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1472 # # We need IN to proceed.
1473 # if [ -s "$IN" ] ; then
1474 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1475 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1476 # case "$POSTPROCESSFORMAT" in
1478 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1480 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1482 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1484 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1486 # # Only remove .wav if the encoding succeeded
1487 # if checkerrors "postprocess-(.{3,4})-$1"; then
1488 # run_command postprocess-$1 false
1490 # run_command postprocess-$1 true
1493 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1494 # echo "HEH! The file we were about to post-process disappeared:"
1497 # run_command postprocess-$1 false
1512 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1516 # The commands here don't go through run_command because they're never supposed to be silenced
1517 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1522 for UTRACKNUM in $TRACKQUEUE
1524 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1526 # FIXME # Hard-coded batch option!
1527 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1529 if [ "$RETURN" != "0" ]; then
1530 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1532 for UTRACKNUM in $TRACKQUEUE
1534 echo "normalizetrack-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1540 # do_batch_normalize
1542 # NORMALIZER, NORMALIZEROPTS
1543 do_batch_normalize ()
1545 # The commands here don't go through run_command because they're never supposed to be silenced
1546 echo "Batch normalizing tracks: $TRACKQUEUE"
1551 for UTRACKNUM in $TRACKQUEUE
1553 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1555 # XXX: Hard-coded batch option!
1556 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1558 if [ "$RETURN" != "0" ]; then
1559 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1561 for UTRACKNUM in $TRACKQUEUE
1563 echo "normalizetrack-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1569 # do_normalize [tracknumber]
1571 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1574 IN="$ABCDETEMPDIR/track$1.wav"
1575 if [ -e "$IN" ] ; then
1576 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1577 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1579 if [ "$(checkstatus encode-output)" = "loud" ]; then
1580 echo "HEH! The file we were about to normalize disappeared:"
1583 run_command normalizetrack-$1 false "File $IN was not found"
1587 # do_move [tracknumber]
1588 # Deduces the outfile from environment variables
1589 # Creates directory if necessary
1591 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1594 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1596 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1597 # defined the OUTPUTFILE:
1600 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1601 ALBUMFILE="$(mungealbumname "$DALBUM")"
1602 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1603 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1604 GENRE="$(mungegenre "$GENRE")"
1605 YEAR=${CDYEAR:-$CDYEAR}
1606 # If we want to start the tracks with a given number, we need to modify
1607 # the TRACKNUM value before evaluation
1609 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1610 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1611 if [ "$ONETRACK" = "y" ]; then
1612 if [ "$VARIOUSARTISTS" = "y" ]; then
1613 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1615 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1618 if [ "$VARIOUSARTISTS" = "y" ]; then
1619 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1621 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1624 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1625 # Once we know the specific output was successful, we can change
1626 # the OUTPUT to the value containing the container
1629 OUTPUT=$OGGOUTPUTCONTAINER
1632 OUTPUT=$OPUSOUTPUTCONTAINER
1635 OUTPUT=$MKAOUTPUTCONTAINER
1638 OUTPUT=$AIFFOUTPUTCONTAINER
1641 OUTPUT=$FLACOUTPUTCONTAINER
1647 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1648 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1651 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1652 # FIXME # introduce warnings?
1655 # mkdir -p shouldn't return an error if the directory already exists
1656 mkdir -p "$OUTPUTFILEDIR"
1657 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1658 if checkstatus movetrack-output-$OUTPUT; then :; else
1659 run_command movetrack-output-$OUTPUT true
1664 # mkdir -p shouldn't return an error if the directory already exists
1665 mkdir -p "$OUTPUTFILEDIR"
1666 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1667 if checkstatus movetrack-output-$OUTPUT; then :; else
1668 run_command movetrack-output-$OUTPUT true
1672 # Lets move the cue file
1673 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1674 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1675 if checkstatus movecue-$OUTPUT; then :; else
1676 # Silence the Copying output since it overlaps with encoding processes...
1677 #run_command '' vecho "Copying cue file to its destination directory..."
1678 if checkstatus onetrack >/dev/null ; then
1681 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1682 # We dont have the dir, since it was not created before.
1685 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1688 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1689 # http://brianvictor.tripod.com/mp3cue.htm#details
1690 [a-z0-9][a-z0-9][a-z0-9])
1691 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1694 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1698 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1700 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1709 # Create the playlist if wanted
1711 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1712 # VARIOUSARTISTS, OUTPUTDIR
1715 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1719 OUTPUT=$OGGOUTPUTCONTAINER
1722 OUTPUT=$OPUSOUTPUTCONTAINER
1725 OUTPUT=$MKAOUTPUTCONTAINER
1728 OUTPUT=$AIFFOUTPUTCONTAINER
1731 OUTPUT=$FLACOUTPUTCONTAINER
1737 # Create a playlist file for the playlist data to go into.
1738 # We used to wipe it out if it existed. Now we request permission if interactive.
1739 for LASTTRACK in $TRACKQUEUE; do :; done
1740 ALBUMFILE="$(mungealbumname "$DALBUM")"
1741 ARTISTFILE="$(mungeartistname "$DARTIST")"
1742 GENRE="$(mungegenre "$GENRE")"
1743 YEAR=${CDYEAR:-$CDYEAR}
1744 if [ "$VARIOUSARTISTS" = "y" ] ; then
1745 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1747 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1749 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1750 mkdir -p "$FINALPLAYLISTDIR"
1751 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1752 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1753 if [ "$INTERACTIVE" = "y" ]; then
1754 while [ "$DONE" != "y" ]; do
1756 case $ERASEPLAYLIST in
1757 e|E|a|A|k|K) DONE=y ;;
1758 "") ERASEPLAYLIST=e ; DONE=y ;;
1766 # Once we erase the playlist, we use append to create the new one.
1767 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1769 # The playlist does not exist, so we can safelly use append to create the new list
1772 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1773 touch "$OUTPUTDIR/$PLAYLISTFILE"
1774 for UTRACKNUM in $TRACKQUEUE
1776 # Shares some code with do_move since the filenames have to match
1777 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1778 getcddbinfo TRACKNAME
1780 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1781 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1782 ALBUMFILE="$(mungealbumname "$DALBUM")"
1783 # If we want to start the tracks with a given number, we need to modify the
1784 # TRACKNUM value before evaluation
1786 if [ "$VARIOUSARTISTS" = "y" ]; then
1787 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1789 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1791 if [ "$VARIOUSARTISTS" = "y" ]; then
1792 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1793 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1795 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1798 if [ "$PLAYLISTDATAPREFIX" ]; then
1799 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1801 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1806 ## this will convert the playlist to have CRLF line-endings, if specified
1807 ## (some hardware players insist on CRLF endings)
1808 if [ "$DOSPLAYLIST" = "y" ]; then
1809 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1810 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1811 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1813 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1818 # This function reads a cuefile on stdin and writes an extended
1819 # cddb query on stdout. Any PREGAP for track 1 is properly
1820 # handled, although cue files embedded in FLAC files do not
1821 # appear to properly store the PREGAP setting. :(
1822 abcde.cue2discid () {
1827 while [ $val -gt 0 ] ; do
1828 ret=$(( $ret + ( $val % 10) ))
1829 val=$(( $val / 10 ))
1839 local first second third
1840 first=$(expr ${1} + 0 )
1841 second=$(expr ${2} + 0 )
1842 third=$(expr ${3} + 0 )
1844 echo $(( ((($first * 60) + $second) * 75) + $third ))
1854 while read line ; do
1857 TRACK) i=$(( i + 1 ))
1859 INDEX) if [ "$2" -eq 1 ] ; then
1861 START=$(( $LBA + $PREGAP + $OFFSET ))
1863 X=$(cddb_sum $(( $START / 75 )) )
1867 PREGAP) PREGAP=$(msf2lba $2)
1871 LEADOUT=$(( $4 / 588 ))
1874 LEADIN=$(( $3 / 588 ))
1883 LEADOUT=$(( $LEADOUT + $LEADIN ))
1885 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1886 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1887 printf "%08x %i" $DISCID $TRACKS
1890 while [ $j -le $TRACKS ] ; do
1891 eval echo -n "\" \$TRACK$j\""
1894 echo " $(( $LEADOUT / 75 ))"
1898 # abcde.mkcue [--wholedisk]
1899 # This creates a cuefile directly from the extended discid information
1900 # The --wholedisk option controls whether we're ripping data from the
1901 # start of track one or from the start of the disk (usually, but not
1902 # always the same thing!)
1904 # Track one leadin/pregap (if any) handeling:
1905 # --wholedisk specified:
1908 # INDEX 01 <pregap value>
1909 # Remaining track index values unchanged from disc TOC
1911 # --wholedisk not specified
1913 # PREGAP <pregap value>
1915 # Remaining track index values offset by <pregap value>
1922 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1925 local MODE DISCID TRACKS
1929 if [ "$1" = --wholedisc ] ; then
1935 vecho "One track is $ONETRACK"
1936 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1937 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1938 ALBUMFILE="$(mungealbumname "$DALBUM")"
1939 if [ "$ONETRACK" = "y" ]; then
1940 if [ "$VARIOUSARTISTS" = "y" ]; then
1941 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1943 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1945 vecho "Cue wav file is $CUEWAVFILE"
1947 CUEWAVFILE="dummy.wav"
1956 echo REM DISCID $DISCID
1957 echo FILE \""$CUEWAVFILE"\" WAVE
1959 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1966 while [ $i -le "$TRACKS" ] ; do
1967 LBA=$(( $1 - $OFFSET ))
1968 printf " TRACK %02i AUDIO\n" $i
1969 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1970 if [ $MODE = PREGAP ] ; then
1971 echomsf " PREGAP " $(($OFFSET-150))
1973 echo " INDEX 00 00:00:00"
1976 echomsf " INDEX 01 " $LBA
1983 # This essentially the start of things
1986 # Query the CD to get the track info, unless the user specified -C
1987 # or we are using some actions which do not need the CDDB data at all
1988 #if [ ! X"$EXPACTIONS" = "X" ]; then
1990 #elif [ -z "$DISCID" ]; then
1991 if [ -z "$DISCID" ]; then
1992 vecho -n "Getting CD track info... "
1993 # In OSX, unmount the disc before a query
1994 if [ "$OSFLAVOUR" = "OSX" ]; then
1995 diskutil unmount ${CDROM#/dev/}
1997 case "$CDROMREADERSYNTAX" in
1999 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
2000 case "$CUE2DISCID" in
2001 # FIXME # right now we have 2 cue2discid internal
2002 # implementations: builtin and abcde.cue2discid. Test
2003 # both of them and decide which one we want to use.
2005 #vecho "Using builtin cue2discid implementation..."
2006 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2008 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2010 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2011 TRACKS=${#OFFSETTIMES[@]}
2013 #echo "processing offsetimes ${OFFSETTIMES[@]}"
2014 for OFFSETTIME in ${OFFSETTIMES[@]}; do
2015 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2016 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
2019 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2020 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2024 #vecho "Using external python cue2discid implementation..."
2025 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2029 log error "the input flac file does not contain a cuesheet."
2034 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2036 if [ ! "$RET" = "0" ];then
2037 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2040 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2041 CDPARANOIAAUDIOTRACKS="$TRACKS"
2043 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2044 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2048 case "$CDDBMETHOD" in
2049 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
2050 musicbrainz) TRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM") ;;
2054 # Make sure there's a CD in there by checking cd-discid's return code
2055 if [ ! "$?" = "0" ]; then
2056 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2057 log error "cuesheet information from the flac file could not be read."
2058 log error "Perhaps the flac file does not contain a cuesheet?."
2061 log error "CD could not be read. Perhaps there's no CD in the drive?"
2065 # In OSX, remount the disc again
2066 if [ "$OSFLAVOUR" = "OSX" ]; then
2067 diskutil mount ${CDROM#/dev/}
2070 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
2072 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
2075 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2076 # This needs to be done now because a section of the resuming code will need
2079 # get the number of digits to pad TRACKNUM with - we'll use this later
2080 # a CD can only hold 99 tracks, but since we support a feature for starting
2081 # numbering the tracks from a given number, we might need to set it as a
2082 # variable for the user to define... or obtain it somehow.
2083 if [ "$PADTRACKS" = "y" ] ; then
2087 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
2088 if [ -z "$TRACKQUEUE" ]; then
2089 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2090 case "$CDROMREADERSYNTAX" in
2091 cdparanoia|libcdio|debug)
2092 if [ "$WEHAVEACD" = "y" ]; then
2093 vecho "Querying the CD for audio tracks..."
2094 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2096 if [ ! "$RET" = "0" ];then
2097 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2099 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2100 CDPARANOIAAUDIOTRACKS="$TRACKS"
2102 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2103 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
2104 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
2105 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
2107 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2108 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2112 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
2115 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2117 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2118 log info "The disc does not contain any tracks. Giving up..."
2121 echo -n "Grabbing entire CD - tracks: "
2122 if [ ! "$PADTRACKS" = "y" ] ; then
2123 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2125 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2127 while [ "$X" -ne "$TRACKS" ]
2129 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2130 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2134 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
2135 # User-supplied track queue.
2136 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2137 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2138 # Once cleaned, obtain the highest value in the trackqueue for number padding
2139 for LASTTRACK in $TRACKQUEUE; do :; done
2140 if [ ! "$PADTRACKS" = "y" ] ; then
2141 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2143 # Now we normalize the trackqueue
2144 for TRACK in $TRACKQUEUE ; do
2145 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2146 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2148 TRACKQUEUE=$PADTRACKQUEUE
2149 echo Grabbing tracks: "$TRACKQUEUE"
2152 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2154 # We have the discid, create a temp directory after it to store all the temp
2157 if [ -e "$ABCDETEMPDIR" ]; then
2158 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2159 # It already exists, see if it's a directory
2160 if [ ! -d "$ABCDETEMPDIR" ]; then
2161 # This is a file/socket/fifo/device/etc, not a directory
2164 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2165 echo "Please investigate, remove it, and rerun abcde." >&2
2169 # It's a directory, let's see if it's writable by us
2170 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2171 # Nope, complain and exit
2173 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2174 echo "Please investigate, remove it, and rerun abcde." >&2
2178 # See if it's populated
2179 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
2180 # Wipe and start fresh
2181 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
2182 echo -n "this directory to continue. Continue [y/N]? " >&2
2183 if [ "$INTERACTIVE" = "y" ]; then
2189 if [ "$ANSWER" != "y" ]; then
2192 rm -rf "$ABCDETEMPDIR" || exit 1
2193 mkdir -p "$ABCDETEMPDIR"
2194 if [ "$?" -gt "0" ]; then
2195 # Directory already exists or could not be created
2196 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2200 # Everything is fine. Check for ^encodetracklocation-
2201 # and encode-output entries in the status file and
2202 # remove them. These are not relevant across sessions.
2203 if [ -f "$ABCDETEMPDIR/status" ]; then
2204 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2205 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2206 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2208 # Remove old error messages
2209 if [ -f "$ABCDETEMPDIR/errors" ]; then
2210 rm -f "$ABCDETEMPDIR/errors"
2214 # We are starting from scratch
2215 mkdir -p "$ABCDETEMPDIR"
2216 if [ "$?" -gt "0" ]; then
2217 # Directory already exists or could not be created
2218 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2221 cat /dev/null > "$ABCDETEMPDIR/status"
2222 # Store the abcde version in the status file.
2223 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2225 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2226 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2227 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
2228 vecho "Creating cue file..."
2229 case $CDROMREADERSYNTAX in
2231 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2232 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2234 log warning "the input flac file does not contain a cuesheet."
2238 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2239 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2241 log warning "reading the CUE sheet is still considered experimental"
2242 log warning "and there was a problem with the CD reading. abcde will continue,"
2243 log warning "but consider reporting the problem to the abcde author"
2249 # If we got the CDPARANOIA status and it is not recorded, save it now
2250 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2251 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2252 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2256 # Create the discid file
2257 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2258 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
2259 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2264 # Create a proper CUE file based on the CUE file we created before.
2267 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2268 CUEFILE_OUT=$CUEFILE_IN.out
2269 ### FIXME ### checkstatus cddb
2270 if [ -e "$CDDBDATA" ]; then
2271 vecho "Adding metadata to the cue file..."
2272 # FIXME It doesn't preserve spaces! Why?
2273 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2275 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2276 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2277 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2281 cat "$CUEFILE_IN" | while read line
2283 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2284 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2285 # echo "$line" >> "$CUEFILE_OUT"
2286 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2287 eval track="\$TRACK$n"
2289 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2290 # When making a single-track rip, put the
2291 # actual file name into the file declaration
2292 # in the cue file so that it is usable by
2293 # music players and the like
2294 elif [ "$ONETRACK" = "y" ] &&
2295 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2297 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2298 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2299 ALBUMFILE="$(mungealbumname "$DALBUM")"
2301 if [ "$VARIOUSARTISTS" = "y" ]; then
2302 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2304 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2307 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2310 # FIXME # If the lines above are uncommented, remove the line below.
2311 echo "$line" >> "$CUEFILE_OUT"
2314 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2315 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2321 # Parses a CDDB file and outputs the title and the track names.
2322 # Variables: CDDBFILE
2326 # List out disc title/author and contents
2327 if [ "$ONETRACK" = "y" ]; then
2328 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2330 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2331 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2332 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2333 if [ ! X"$PARSEDYEAR" = "X" ]; then
2334 echo "Year: $PARSEDYEAR"
2337 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2338 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2339 if [ ! X"$PARSEDGENRE" = "X" ]; then
2340 echo "Genre: $PARSEDGENRE"
2343 if [ ! "$ONETRACK" = "y" ]; then
2344 for TRACK in $(f_seq_row 1 $TRACKS)
2346 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2352 # Check for a local CDDB file, and report success
2355 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2357 CDDBLOCALSTATUS="notfound"
2358 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2361 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2362 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2363 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2364 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2365 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2366 CDDBLOCALMATCH=single
2367 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2368 CDDBLOCALMATCH=multiple
2373 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2374 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2375 CDDBLOCALMATCH=single
2380 # If the user has selected to check a local CDDB repo, we proceed with it
2381 case $CDDBLOCALMATCH in
2383 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2385 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2387 # List out disc title/author and contents
2388 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2389 cat "$RESULT" > "${CDDBLOCALREAD}"
2392 do_cddbparse "${CDDBLOCALREAD}"
2394 ##FIXME## QUICK HACK !!!!
2395 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2396 } >> "$ABCDETEMPDIR/cddblocalchoices"
2398 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2399 page "$ABCDETEMPDIR/cddblocalchoices"
2401 # It's all going to fit in one page, cat it
2402 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2404 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2405 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2406 CDDBLOCALCHOICENUM=-1
2407 if [ "$INTERACTIVE" = "y" ]; then
2408 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2409 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2410 read CDDBLOCALCHOICE
2411 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2412 # FIXME # Introduce diff's
2413 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2414 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2415 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2416 # Make sure we get a valid choice
2417 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2418 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2419 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2425 #echo "Selected ..."
2427 CDDBLOCALCHOICENUM=1
2429 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2430 #echo "Using local copy of CDDB data"
2431 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2432 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2433 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2434 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2435 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2436 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2437 CDDBLOCALSTATUS="found"
2439 #echo "Not using local copy of CDDB data"
2440 CDDBLOCALSTATUS="notfound"
2444 # List out disc title/author and contents
2445 do_cddbparse "${CDDBLOCALFILE}"
2446 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2447 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2449 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2451 if [ "$INTERACTIVE" = "y" ]; then
2453 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2454 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2457 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2461 if [ "$USELOCALRESP" = "y" ]; then
2462 #echo "Using local copy of CDDB data"
2463 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2464 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2465 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2466 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2467 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2468 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2469 CDDBLOCALSTATUS="single"
2471 #echo "Not using local copy of CDDB data"
2472 CDDBLOCALSTATUS="notfound"
2476 CDDBLOCALSTATUS="notfound"
2483 # Try to read CD-Text from the drive using icedax / cdda2wav
2486 if new_checkexec icedax; then
2487 CDTEXT_READER=icedax
2488 elif new_checkexec cdda2wav; then
2489 CDTEXT_READER=cdda2wav
2491 # Didn't find either, bail
2495 if [ "$OSFLAVOUR" = "OSX" ] ; then
2496 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2497 diskutil unmount ${CDROM#/dev/}
2498 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2499 CDDA2WAVCDROM="IODVDServices"
2500 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2501 CDDA2WAVCDROM="$CDROMID"
2503 if [ "$CDROMID" = "" ]; then
2504 CDDA2WAVCDROM="$CDROM"
2506 CDDA2WAVCDROM="$CDROMID"
2510 # Do we have CD-Text on the disc (and can the drive read it?)
2512 cd "$ABCDETEMPDIR" && rm -f audio.* audio_*
2513 ${CDTEXT_READER} -J -v titles -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2515 grep -a -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2517 if [ $ERRORCODE -ne 0 ]; then
2518 # No CD-Text found, bail
2522 rm -f "$ABCDETEMPDIR/cddbchoices"
2524 # Make an empty template
2525 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2526 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2527 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2528 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2529 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2530 #ATITLE=$(grep -ae '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- | sed "s~'\(.*\)'.*\[from \(.*\)]$~\2 / \1~")
2531 ATITLE=$(grep -ae '^DTITLE=' "${ABCDETEMPDIR}/audio.cddb" | cut -c8-)
2532 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2533 # List out disc title/author and contents
2534 echo "---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2535 sed -n 's~^Track \(..:\) .\(.*\).$~\1 \2~gp;' "$ABCDETEMPDIR/cd-text" >>"$ABCDETEMPDIR/cddbchoices"
2536 rm -f "$ABCDETEMPDIR/cddbread.1"
2537 # XXX FIXME - this is a hack and should be replaced by proper
2538 # character set tracking for the CDDB data we have.
2539 if test "$CDDBPROTO" -ge 6 ; then
2540 # convert to Unicode
2541 iconv -f iso-8859-1 -t utf-8 <"$ABCDETEMPDIR/audio.cddb" >"$ABCDETEMPDIR/cddbread.1"
2543 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2544 # apparently icedax/cdda2wav have no support for 16-bit
2545 # characters yet, either
2546 cp -p "$ABCDETEMPDIR/audio.cddb" "$ABCDETEMPDIR/cddbread.1"
2548 ( cd "$ABCDETEMPDIR" && rm -f audio_* audio.* )
2549 echo >> "$ABCDETEMPDIR/cddbchoices"
2550 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2554 # Work with the musicbrainz WS API, then transform the results here so
2555 # they look (very) like the results from CDDB. Maybe not the best way
2556 # to go, but it Works For Me (TM)
2560 if checkstatus musicbrainz-readcomplete; then :; else
2561 vecho "Obtaining Musicbrainz results..."
2562 # If MB is to be used, interpret the query results and read all
2563 # the available entries.
2564 rm -f "$ABCDETEMPDIR/cddbchoices"
2565 CDDBCHOICES=1 # Overridden by multiple matches
2566 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2567 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2569 # The helper script will write disc matches out to
2570 # cddbread.*. Count how many we have
2571 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2572 if [ $CDDBLASTMETHOD = "y" ]
2574 # We're the end of the line.
2576 # No matches. Use the normal cddb template for the user to
2578 vecho "Unable to find a match with ${CDDBMETHCHOICE}, generating CDDB template."
2579 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2580 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2581 # List out disc title/author and contents of template
2582 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2584 for TRACK in $(f_seq_row 1 $TRACKS)
2586 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2588 echo >> "$ABCDETEMPDIR/cddbchoices"
2589 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2590 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2591 echo 503 > "$ABCDETEMPDIR/cddbquery"
2593 # Neat, we'll let the next guy take care of this CDDB
2595 vecho "Unable to find a match with ${CDDBMETHCHOICE}, moving on to the next option."
2598 # We have some matches
2599 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2600 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2602 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2603 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2604 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2605 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2606 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2607 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2608 # List out disc title/author and contents
2609 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2610 for TRACK in $(f_seq_row 1 $TRACKS)
2612 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2614 echo >> "$ABCDETEMPDIR/cddbchoices"
2616 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2617 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2618 for file in "$ABCDETEMPDIR"/cddbread.*
2620 X=$(echo $file | sed 's/^.*cddbread\.//g')
2621 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2622 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2623 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2624 # List out disc title/author and contents
2625 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2626 for TRACK in $(f_seq_row 1 $TRACKS)
2628 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2630 echo >> "$ABCDETEMPDIR/cddbchoices"
2632 echo "." >> "$ABCDETEMPDIR/cddbquery"
2635 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2642 # Perform CDDB protocol version check if it hasn't already been done
2643 if checkstatus cddb-statcomplete; then :; else
2644 if [ "$CDDBAVAIL" = "n" ]; then
2646 echo 503 > "$ABCDETEMPDIR/cddbstat"
2649 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2650 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2651 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2652 vecho "Checking CDDB server status..."
2653 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2654 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2655 case "$RESPONSECODE" in
2656 210) # 210 OK, status information follows (until terminating `.')
2659 501) # 501 Illegal CDDB protocol level: <n>.
2660 CDDBPROTO=`expr $CDDBPROTO - 1`
2662 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2663 # FreeDB TESTCD disc-id is used for query
2664 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2665 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2666 case "$RESPONSECODE" in
2667 2??) # Server responded, everything seems OK
2677 if test $rc -eq 1; then
2681 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2689 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2690 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2692 # Perform CDDB query if it hasn't already been done
2693 if checkstatus cddb-querycomplete; then :; else
2694 if [ "$CDDBAVAIL" = "n" ]; then
2696 echo 503 > "$ABCDETEMPDIR/cddbquery"
2697 # The default CDDBLOCALSTATUS is "notfound"
2698 # This part will be triggered if the user CDDB repo does not
2699 # contain the entry, or if we are not trying to use the repo.
2701 vecho "Querying the CDDB server..."
2702 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2703 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2704 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2710 # no match found in database,
2711 # wget/fetch error, or user requested not to use CDDB
2712 # Make up an error code (503) that abcde
2713 # will recognize in do_cddbread
2714 # and compensate by making a template
2715 echo 503 > "$ABCDETEMPDIR/cddbquery"
2717 *) # strange and unknown error
2718 echo ERRORCODE=$ERRORCODE
2719 echo "abcde: $CDDBTOOL returned unknown error code"
2723 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2730 # If it's not to be used, generate a template.
2731 # Then, display it (or them) and let the user choose/edit it
2732 if checkstatus cddb-readcomplete; then :; else
2733 vecho "Obtaining CDDB results..."
2734 # If CDDB is to be used, interpret the query results and read all
2735 # the available entries.
2736 rm -f "$ABCDETEMPDIR/cddbchoices"
2737 CDDBCHOICES=1 # Overridden by multiple matches
2738 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2739 case "$RESPONSECODE" in
2741 # One exact match, retrieve it
2742 # 200 [section] [discid] [artist] / [title]
2743 if checkstatus cddb-read-1-complete; then :; else
2744 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2745 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2746 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2747 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2748 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2750 # List out disc title/author and contents
2751 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2752 for TRACK in $(f_seq_row 1 $TRACKS)
2754 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2756 echo >> "$ABCDETEMPDIR/cddbchoices"
2758 202|403|409|500|503)
2759 # TODO: Explain these error codes a little more accurately:
2760 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2761 # No match response:
2762 if [ $CDDBLASTMETHOD = "y" ]
2764 # We're the caboose, so we need to generate the CDDB
2766 vecho "Unable to find a match with ${CDDBMETHCHOICE}, generating CDDB template."
2767 case "$RESPONSECODE" in
2768 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2769 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2770 500|503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2772 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2773 # List out disc title/author and contents of template
2774 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2776 for TRACK in $(f_seq_row 1 $TRACKS)
2778 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2780 echo >> "$ABCDETEMPDIR/cddbchoices"
2781 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2782 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2784 # Template's the next chump's job.
2785 vecho "Unable to find a match with ${CDDBMETHCHOICE}, moving on to the next option."
2789 # Multiple exact, (possibly multiple) inexact matches
2791 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2792 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2793 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2794 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2795 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2797 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2799 vecho -n "Retrieving multiple matches... "
2800 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2801 read DISCINFO # eat top line
2805 if checkstatus cddb-read-$X-complete; then :; else
2806 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2807 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2809 # List out disc title/author and contents
2810 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2811 for TRACK in $(f_seq_row 1 $TRACKS)
2813 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2815 echo >> "$ABCDETEMPDIR/cddbchoices"
2818 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2822 for TRACK in $(f_seq_row 1 $TRACKS)
2824 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2826 echo >> "$ABCDETEMPDIR/cddbchoices"
2827 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2828 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2831 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2838 if checkstatus cddb-edit >/dev/null; then
2839 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2840 VARIOUSARTISTS="$(checkstatus variousartists)"
2841 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2844 if [ "$INTERACTIVE" = "y" ]; then
2845 # We should show the CDDB results both when we are not using the local CDDB repo
2846 # or when we are using it but we could not find a proper match
2847 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2848 # Display the $ABCDETEMPDIR/cddbchoices file created above
2849 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2850 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2851 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2852 CHOICE=$(checkstatus cddb-choice)
2853 if [ -n "$CHOICE" ] ; then
2854 case $CDDBCHOICES in
2855 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep -a "^$" > /dev/null 2>&1 ; then
2856 log error "CDDB query failed!"
2859 cat "$ABCDETEMPDIR/cddbchoices"
2862 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2864 echo "Selected: #$CHOICE"
2865 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2869 # The user has a choice to make, display the info in a pager if necessary
2870 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2871 page "$ABCDETEMPDIR/cddbchoices"
2873 # It's all going to fit in one page, cat it
2874 cat "$ABCDETEMPDIR/cddbchoices" >&2
2878 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2880 # I'll take CDDB read #3 for $400, Alex
2881 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2882 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2884 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2885 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2886 if [ ! X"$DIFF" = "X" ]; then
2887 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2888 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2889 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2890 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2891 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2892 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2894 # We parse the 2 choices to diff, store them in temporary files and diff them.
2895 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2896 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2898 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2899 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2900 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2901 page "$ABCDETEMPDIR/cddbread.diff"
2903 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2907 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2909 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2910 # Make sure we get a valid choice
2911 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2912 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2913 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2917 if [ "$CDCHOICENUM" = "0" ]; then
2918 vecho "Creating empty CDDB template..."
2920 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2922 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2923 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2925 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2929 # We need some code to show the selected option when local repository is selected and we have found a match
2930 vecho "Using cached CDDB match..." >&2
2931 # Display the $ABCDETEMPDIR/cddbchoices file created above
2932 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2933 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2934 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2935 CHOICE=$(checkstatus cddb-choice)
2936 if [ "$USELOCALRESP" = "y" ]; then :; else
2937 if [ -n "$CHOICE" ] ; then
2938 case $CDDBCHOICES in
2941 echo "Selected template."
2943 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2945 echo "Selected: #$CHOICE"
2946 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2954 # We're noninteractive - pick the first choice.
2955 # But in case we run a previous instance and selected a choice, use it.
2956 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2957 # Show the choice if we are not using the locally stored one
2958 # or when the local search failed to find a match.
2959 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2960 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2961 #if [ "$PREVIOUSCHOICE" ]; then
2962 cat "$ABCDETEMPDIR/cddbchoices"
2965 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2966 CDCHOICENUM=$PREVIOUSCHOICE
2969 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2971 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2976 if checkstatus cddb-choice >/dev/null; then :; else
2977 echo "abcde: internal error: cddb-choice not recorded." >&2
2980 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2981 echo -n "Edit selected CDDB data " >&2
2982 if [ "$INTERACTIVE" = "y" ]; then
2983 if [ "$UNKNOWNDISK" = "y" ]; then
2984 echo -n "[Y/n]? " >&2
2986 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2988 echo -n "[y/N]? " >&2
2995 if [ "$EDITCDDB" = "y" ]; then
2996 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2998 # Use the debian sensible-editor wrapper to pick the editor that the
2999 # user has requested via their $EDITOR environment variable
3000 if [ -x "/usr/bin/sensible-editor" ]; then
3001 /usr/bin/sensible-editor "$CDDBDATA"
3002 elif [ -n "$EDITOR" ]; then
3003 if [ -x $(which "${EDITOR%%\ *}") ]; then
3004 # That failed, try to load the preferred editor, starting
3005 # with their EDITOR variable
3006 eval $(echo "$EDITOR") \"$CDDBDATA\"
3008 # If that fails, check for a vi
3009 elif which vi >/dev/null 2>&1; then
3011 elif [ -x /usr/bin/vim ]; then
3012 /usr/bin/vim "$CDDBDATA"
3013 elif [ -x /usr/bin/vi ]; then
3014 /usr/bin/vi "$CDDBDATA"
3015 elif [ -x /bin/vi ]; then
3017 # nano should be on all (modern, i.e., sarge) debian systems
3018 elif which nano >/dev/null 2>&1 ; then
3020 elif [ -x /usr/bin/nano ]; then
3021 /usr/bin/nano "$CDDBDATA"
3022 # mg should be on all OpenBSD systems
3023 elif which mg >/dev/null 2>&1 ; then
3025 elif [ -x /usr/bin/mg ]; then
3026 /usr/bin/mg "$CDDBDATA"
3029 log warning "no editor available. Check your EDITOR environment variable."
3031 # delete editor backup file if it exists
3032 if [ -w "$CDDBDATA~" ]; then
3037 # Some heuristics first. Look at Disc Title, and if it starts with
3038 # "Various", then we'll assume Various Artists
3039 if [ "$(grep -a ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -aEci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
3040 echo "Looks like a Multi-Artist CD" >&2
3043 echo -n "Is the CD multi-artist [y/N]? " >&2
3044 if [ "$INTERACTIVE" = "y" ]; then
3051 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
3054 # Need NUMTRACKS before cddb-tool will return it:
3055 NUMTRACKS=$(grep -a -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
3056 if [ "$(grep -ac "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3057 # More than 1/2 tracks contain a "/", so guess forward
3059 elif [ "$(grep -ac "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3060 # More than 1/2 contain a "-", so guess forward-dash
3062 elif [ "$(grep -ac "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3063 # More than 1/2 contain something in parens, so guess trailing-paren
3067 echo "1) Artist / Title" >&2
3068 echo "2) Artist - Title" >&2
3069 echo "3) Title / Artist" >&2
3070 echo "4) Title - Artist" >&2
3071 echo "5) Artist: Title" >&2
3072 echo "6) Title (Artist)" >&2
3073 echo "7) This is a single-artist CD" >&2
3074 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
3075 if [ "$INTERACTIVE" = "y" ]; then
3076 read VARIOUSARTISTSTYLE
3078 echo $DEFAULTSTYLE >&2
3079 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3081 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3082 # If they press Enter, then the default style (0) was chosen
3083 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
3084 echo "Invalid selection. Please choose a number between 1 and 7."
3085 echo -n "Selection [1-7]: "
3086 read VARIOUSARTISTSTYLE
3087 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3089 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3090 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3092 vecho "Selected: $VARIOUSARTISTSTYLE"
3093 case "$VARIOUSARTISTSTYLE" in
3095 VARIOUSARTISTSTYLE=forward
3098 VARIOUSARTISTSTYLE=forward-dash
3101 VARIOUSARTISTSTYLE=reverse
3104 VARIOUSARTISTSTYLE=reverse-dash
3107 VARIOUSARTISTSTYLE=colon
3110 VARIOUSARTISTSTYLE=trailing-paren
3118 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
3119 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
3121 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3122 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3123 # This works but does not have the necessary error checking
3124 # yet. If you are familiar with the CDDB spec
3125 # (see http://www.freedb.org/src/latest/DBFORMAT)
3126 # and can create an error-free entry on your own, then put
3127 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3128 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3129 # your abcde.conf to change the email address submissions are
3132 # submit the modified file, if they want
3133 if [ "$NOSUBMIT" != "y" ]; then
3134 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3136 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3137 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3139 echo -n 'Invalid selection. Please answer "y" or "n": '
3142 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3143 echo -n "Sending..."
3144 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
3151 # User CDDBLOCALPOLICY to find out if we store the file or not...
3152 # Cache edited CDDB entry in the user's cddb dir
3153 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3154 # Make sure the cache directory exists
3155 mkdir -p $CDDBLOCALDIR
3156 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
3159 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
3163 # try to download CD cover
3167 ALBUMFILE="$(mungealbumname "$DALBUM")"
3168 ARTISTFILE="$(mungeartistname "$DARTIST")"
3169 GENRE="$(mungegenre "$GENRE")"
3170 YEAR=${CDYEAR:-$CDYEAR}
3171 # have we got a musicbrainz mbid or amazon asin?
3172 case "$CDDBMETHOD" in
3174 # try musicbrainz mbid
3175 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
3176 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
3177 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3178 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3179 vecho "cover URL: $ALBUMARTURL" >&2
3180 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3181 if [ $? -ne 0 ]; then
3182 vecho "could not download cover from musicbrainz" >&2
3184 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3185 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3186 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3187 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3188 vecho "cover URL: $ALBUMARTURL" >&2
3189 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3190 if [ $? -ne 0 ]; then
3191 vecho "could not download cover from amazon" >&2
3193 # Check that size is reasonable; sometimes when there is no cover image
3194 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3195 FILESIZE=$(wc -c < "$ABCDETEMPDIR/$ALBUMARTFILE")
3196 if [ "$FILESIZE" -lt 1024 ]; then
3197 rm "$ABCDETEMPDIR/$ALBUMARTFILE"
3198 vecho "could not download cover from amazon" >&2
3202 vecho "no amazon ID found" >&2
3206 vecho "no musicbrainz ID found" >&2
3211 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3212 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3213 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3214 if [ $? -ne 0 ]; then
3215 vecho "could not download cover with glyrc" >&2
3220 if [ "$INTERACTIVE" = "y" ]; then
3221 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3222 # display properties of coverart when identify is available
3223 if new_checkexec $IDENTIFY; then
3224 $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
3226 # display coverart when DISPLAY is set and display command is available
3227 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3228 $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
3231 # nothing downloaded yet
3232 vecho "automatic album art downloading failed" >&2
3234 # see if the user can find a better album art manually
3235 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3237 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3238 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3240 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3243 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3244 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3246 if [ ! -z "$ALBUMARTURL" ]; then
3247 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3248 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3249 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3250 vecho "unable to download $ALBUMARTURL" >&2
3252 else # it's a local path
3253 cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
3254 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3255 vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
3261 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3262 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3263 ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
3264 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3265 if new_checkexec $CONVERT; then
3266 mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3267 $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
3268 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3270 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3271 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3275 # copy to target directories
3276 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3277 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3279 # put cover in the same place as the album
3280 if [ "$ONETRACK" = "y" ] ; then
3281 if [ "$VARIOUSARTISTS" = "y" ] ; then
3282 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3284 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3287 if [ "$VARIOUSARTISTS" = "y" ] ; then
3288 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3290 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3293 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3294 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3295 mkdir -p "$FINALALBUMARTDIR"
3296 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3298 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3299 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3301 log warning "could not get cover"
3302 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3306 # Optionally embed the albumart downloaded by the getalbumart fuction.
3307 # FIXME: It would be nice to have this also selectable from within the
3308 # FIXME: getalbumart function itself. Andrew
3312 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
3313 ALBUMFILE="$(mungefilename "$DALBUM")"
3314 YEAR=${CDYEAR:-$CDYEAR}
3316 # Allow for multiple output formats:
3317 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3319 # Find the output directory for multi track encodes:
3320 if [ "$ONETRACK" != "y" ] ; then
3321 if [ "$VARIOUSARTISTS" = "y" ] ; then
3322 FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
3324 FINDPATH="$(eval echo "$OUTPUTFORMAT")"
3327 # Find the output directory for single track encodes:
3328 if [ "$ONETRACK" = "y" ] ; then
3329 if [ "$VARIOUSARTISTS" = "y" ] ; then
3330 FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3332 FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3336 FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
3339 # Instructions for each format, feel free to add more. It would be nice to
3340 # make the backup directory selectable and perhaps also have an option for
3341 # the bold to simply have the image deleted. Work for another day... Andrew.
3342 if [ -e "$ALBUMARTFILE" ] ; then
3347 "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$i"
3349 mkdir "$FINALDIR"/albumart_backup
3350 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3351 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3356 "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
3358 mkdir "$FINALDIR"/albumart_backup
3359 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3360 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3365 "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
3367 mkdir "$FINALDIR"/albumart_backup
3368 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3369 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3374 "$WVTAG" --write-binary-tag "Cover Art (Front)=@"$ALBUMARTFILE"" "$i"
3376 mkdir "$FINALDIR"/albumart_backup
3377 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3378 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3382 # This technique is drawn from 2 sources (the first link being the primary source):
3383 # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
3384 # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
3385 # In abcde a few steps are used in this sequence:
3387 # 1. Create a 'legal' header for the cover art image
3388 # 2. Makes a copy of the existing tags
3389 # 3. base64 the cover art image
3390 # 4. Copy the original tags + the base64 image back to the original ogg file
3392 # Might need some fine tuning but it is a start for abcde 2.8.2 Andrew.
3393 # FIXME: I am not sure if there is a maximum size for images converted in this
3394 # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
3396 # First some variables we can reuse:
3397 # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
3398 MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
3399 EXPORTTAGS="$ABCDETEMPDIR/export_ogg_tags"
3400 BUILDHEADER="$ABCDETEMPDIR/build_header"
3401 # Now build the header, gory details are here:
3402 # https://xiph.org/flac/format.html#metadata_block_picture
3404 printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
3406 printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3408 echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
3409 # Description length. FIXME: I have used 'Cover Image' but I am not sure
3410 # if this is better left as an empty field. Andrew
3411 printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3413 echo -n "Cover Image" >> "$BUILDHEADER"
3415 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3417 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3418 # Picture color depth:
3419 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3420 # Picture color count:
3421 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3423 printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
3424 # cat the image file:
3425 cat "$ALBUMARTFILE" >> "$BUILDHEADER"
3426 # Now process each ogg file by first exporting the original tags then
3427 # appending the cover image and finally copying the whole thing back
3428 # to the original image:
3431 # Make a backup of the existing tags:
3432 "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
3433 # base64 the file and then mix it all together with the exported tags:
3434 echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
3435 # Update the original ogg file with exported tags and the appended base64'd image:
3436 "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
3437 # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
3438 # note that the header file BUILDHEADER will be reused for each file in the loop:
3441 mkdir "$FINALDIR"/albumart_backup
3442 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3443 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3445 *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
3448 vecho "Suitable cover image not found, no embedding done..." >&2
3453 # do_cdread [tracknumber]
3454 # do_cdread onetrack [firsttrack] [lasttrack]
3458 # The commands here don't go through run_command because they're never supposed to be silenced
3459 # return codes need to be doublechecked anyway, however
3460 if [ "$1" = "onetrack" ]; then
3461 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3462 # FIXME # Until then, we grab the whole CD in one track, no matter what
3464 # We need the first and last track for cdda2wav/icedax
3466 LASTTRACK=$(expr $3 + 0)
3467 UTRACKNUM=$FIRSTTRACK
3468 case "$CDROMREADERSYNTAX" in
3469 flac) READTRACKNUMS="-" ;;
3472 # Add a variable to check if tracks are provided in command line and if not, rip the whole CD
3473 # We must make sure to rip from sector 0, both lines below work
3474 # READTRACKNUMS="-- -$LASTTRACK" ;;
3475 READTRACKNUMS="[.0]-" ;;
3476 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3477 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3478 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3484 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3485 if [ "$USEPIPES" = "y" ]; then
3486 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3487 FILEARG="$( eval echo "\$$TEMPARG" )"
3488 PIPE_MESSAGE="and encoding "
3490 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3491 case "$CDROMREADERSYNTAX" in
3492 ## FIXME ## Find the cases for flac, to avoid exceptions
3494 FILEARG="--output-name=$WAVDATA"
3501 if [ "$1" = "onetrack" ]; then
3502 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3504 if [ -r "$CDDBDATA" ]; then
3505 getcddbinfo TRACKNAME
3506 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3508 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3511 case "$CDROMREADERSYNTAX" in
3512 ### FIXME ### use an exception for flac, since it uses -o
3513 ### FIXME ### Shall we just use -o $FILEARG ??
3515 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3516 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3517 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3519 if [ "$USEPIPES" = "y" ]; then
3520 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3522 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3526 if [ "$OSFLAVOUR" = "OSX" ] ; then
3527 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3528 diskutil unmount ${CDROM#/dev/}
3529 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3530 CDDA2WAVCDROM="IODVDServices"
3531 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3532 CDDA2WAVCDROM="$CDROMID"
3534 if [ "$CDROMID" = "" ]; then
3535 CDDA2WAVCDROM="$CDROM"
3537 CDDA2WAVCDROM="$CDROMID"
3540 if [ "$USEPIPES" = "y" ]; then
3541 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3543 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3547 # I cannot get USEPIPES to work with dagrab so just this:
3548 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2
3551 if [ "$USEPIPES" = "y" ]; then
3552 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3554 # Write ripped audio data to stdout and redirect to $FILEARG.
3555 # Progress is written to stderr by default and thus >&2 is not required.
3556 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3560 # Find the track's mounted path
3561 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3562 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3563 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3564 # If the file exists, copy it
3565 if [ -e "$FILEPATH" ] ; then
3566 if [ "$USEPIPES" = "y" ]; then
3567 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3569 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3575 if [ "$USEPIPES" = "y" ]; then
3576 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3578 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
3583 # If we get some error or we get some missing wav
3584 # (as long as we dont use pipes)
3585 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3586 # Thank goodness errors is only machine-parseable up to the
3587 # first colon, otherwise this woulda sucked
3588 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3589 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3591 if [ "$USEPIPES" = "y" ]; then
3592 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3594 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3598 if [ "$USEPIPES" = "y" ]; then
3599 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3601 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3603 if [ "$1" = "onetrack" ]; then
3604 echo onetrack >> "$ABCDETEMPDIR/status"
3610 # No values accepted, only uses env variables
3613 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3614 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3616 echo "abcde: unable to set the device speed" >&2
3622 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3625 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3627 warning) shift ; log warning "$@" ;;
3635 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3638 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3640 warning) shift ; log warning "$@" ;;
3648 # decho outputs a debug message if DEBUG is selected
3651 if [ x"$DEBUG" != "x" ]; then
3652 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3653 DEBUGECHO=$(echo "$@" | tr -d '[]')
3654 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3656 echo >&4 "[DEBUG] $1"
3661 # User-redefinable functions
3662 # Custom filename munging:
3665 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3668 # Custom filename munging specific to track names:
3674 # Custom filename munging specific to artist names:
3680 # Custom filename munging specific to album names:
3686 # Custom genre munging:
3689 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3693 # Empty pre_read function, to be defined in the configuration file.
3700 # Empty post_read function, to be defined in the configuration file.
3707 # Empty post_encode function, to be defined in the configuration file.
3713 ###############################################################################
3716 # Start of execution
3717 ###############################################################################
3722 # Currently two supported options ("musicbrainz" and "cddb" for freedb.org)
3723 CDDBMETHOD=musicbrainz
3724 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3725 CDDBSUBMIT=freedb-submit@freedb.org
3727 HELLOINFO="$(whoami)@$(hostname)"
3729 CDDBLOCALPOLICY="always"
3730 CDDBLOCALRECURSIVE="y"
3731 CDDBLOCALDIR="$HOME/.cddb"
3733 # pre-declare a variable we'll use if the user provides a
3734 # comma-separated list of CDDBMETHODs
3735 declare -a CDDBMETHODS
3738 # List of fields we parse and show during the CDDB parsing...
3739 SHOWCDDBFIELDS="year,genre"
3742 #CDROMREADERSYNTAX=cdparanoia
3743 ENCODERSYNTAX=default
3745 MP3ENCODERSYNTAX=default
3746 OGGENCODERSYNTAX=default
3747 OPUSENCODERSYNTAX=default
3748 MKAENCODERSYNTAX=default
3749 AIFFENCODERSYNTAX=default
3750 FLACENCODERSYNTAX=default
3751 SPEEXENCODERSYNTAX=default
3752 MPCENCODERSYNTAX=default
3753 WVENCODERSYNTAX=default
3754 TTAENCODERSYNTAX=default
3755 APENCODERSYNTAX=default
3756 MP2ENCODERSYNTAX=default
3757 AACENCODERSYNTAX=default
3758 NORMALIZERSYNTAX=default
3759 CUEREADERSYNTAX=default
3761 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3762 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3763 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3764 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3765 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3766 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3767 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3768 PLAYLISTDATAPREFIX=''
3769 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3770 VAPLAYLISTDATAPREFIX=''
3778 VARIOUSARTISTSTYLE=forward
3785 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3786 # i.e. CDROMID="1,0,0"
3788 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3789 # If we are using the ide-scsi emulation layer, we need to define a "g"
3790 CDPARANOIACDROMBUS="d"
3792 # program paths - defaults to checking your $PATH
3798 XINGMP3ENC=xingmp3enc
3812 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3816 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3826 NEROAACENC=neroAacEnc
3828 # Note that the qaac PATH will almost always require adjustment
3829 # as it is a Windows application being run through Wine. More
3830 # detailed notes in the sample abcde.conf file in the abcde tarball.
3833 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3841 VORBISCOMMENT=vorbiscomment
3843 NEROAACTAG=neroAacTag
3844 ATOMICPARSLEY=AtomicParsley
3848 CDPARANOIA=cdparanoia
3849 CD_PARANOIA=cd-paranoia
3856 MUSICBRAINZ=abcde-musicbrainz-tool
3860 NORMALIZE=normalize-audio
3862 VORBISGAIN=vorbisgain
3866 # For Wavpack replay gain we set both the default of 'track gain'
3867 # as well as this option for 'album gain'. Better media players
3868 # such as vlc can select either or neither. Andrew.
3879 # Options for programs called from abcde:
3882 # These options needed by FFmpeg for tagging and selection of id3v2 version:
3883 # 1. '-write_id3v2 1' allows id3v2 tagging while '-write_id3v2 0' disables tagging
3884 # 2. '-id3v2_version 4' gives version id3v2.4 while '3' gives id3v2.3
3885 AIFFENCOPTS="-write_id3v2 1 -id3v2_version 4"
3897 VORBISGAINOPTS="--album"
3901 # The flac option is a workaround for an error where flac fails
3902 # to encode with error 'floating point exception'. This is flac
3903 # error in get_console_width(), corrected in flac 1.3.1
3905 FLACGAINOPTS="--add-replay-gain"
3912 # True Audio has no useful options but it is here anyway :)
3915 # Monkey's Audio Console (mac) chokes without a mode setting
3916 # so we set one here.
3923 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3924 # we set bitrate here.
3925 FDKAACENCOPTS='--bitrate 192k'
3947 VORBISCOMMENTOPTS="-R"
3948 METAFLACOPTS="--no-utf8-convert"
3953 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3955 # Defaults for album art downloads
3956 ALBUMARTFILE="cover.jpg"
3958 ALBUMARTALWAYSCONVERT="n"
3960 # Default to one process if -j isn't specified
3963 # List of actions to perform - by default, run to completion
3964 ACTIONS=cddb,read,encode,tag,move,clean
3966 # This option is basically for Debian package dependencies:
3967 # List of preferred outputs - by default, run with whatever we have in the path
3968 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:fdkaac:opus
3970 # List of preferred cdromreaders - by default, run whichever we have in the path
3971 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3973 # fd for when `vecho` and `log info` called with redirected stdout
3976 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3977 # Linux/OpenBSD. ftp is user for NetBSD.
3978 # Let's use these checkings to determine the OS flavour, which will be used
3980 if [ X$(uname) = "XFreeBSD" ] ; then
3985 elif [ X$(uname) = "XDarwin" ] ; then
3987 # By default md5sum is not installed, use md5 instead:
3990 # We should have diskutil in OSX, but let's be sure...
3992 CDROMREADERSYNTAX=cddafs
3993 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3995 elif [ X$(uname) = "XOpenBSD" ] ; then
3999 elif [ X$(uname) = "XNetBSD" ] ; then
4003 elif [ X$(uname) = "SunOS" ] ; then
4011 # If CDDBAVAIL is set to n, no CDDB read is done
4015 # But before we get into business, let us chop off any GREP environmental
4020 if [ -z "$OUTPUTDIR" ]; then
4024 if [ -z "$WAVOUTPUTDIR" ]; then
4025 WAVOUTPUTDIR="$OUTPUTDIR"
4028 # Load system defaults
4029 if [ -r /etc/abcde.conf ]; then
4032 # Load user preference defaults
4033 if [ -r $HOME/.abcde.conf ]; then
4037 # By this time, we need some HTTPGETOPTS already defined.
4038 # If the user has defined a non-default HTTPGET method, we should not be empty.
4040 if [ "$HTTPGETOPTS" = "" ] ; then
4042 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
4043 curl) HTTPGETOPTS="-f -s -L";;
4044 fetch)HTTPGETOPTS="-q -o -";;
4045 ftp) HTTPGETOPTS="-a -V -o - ";;
4046 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
4050 # If the CDROM has not been set yet, find a suitable one.
4051 # If this is a devfs system, default to /dev/cdroms/cdrom0
4052 # instead of /dev/cdrom
4053 if [ "$CDROM" = "" ] ; then
4054 if [ -e /dev/cdroms/cdrom0 ]; then
4055 CDROM=/dev/cdroms/cdrom0
4056 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
4057 CDROM=/dev/${BASH_REMATCH[1]}
4058 elif [ -e /dev/cdrom ]; then
4060 elif [ -e /dev/sr0 ]; then
4062 elif [ -e /dev/cd0c ]; then
4064 elif [ -e /dev/acd0c ]; then
4066 elif [ -e /dev/disk1 ]; then
4071 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
4072 # that's changed to a number to allow for more control. Deal with
4073 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
4074 case "$EXTRAVERBOSE" in
4083 # Parse command line options
4084 while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pP:Q:r:s:S:t:T:UvVxX:w:W:z opt ; do
4087 a) ACTIONS="$OPTARG" ;;
4088 A) EXPACTIONS="$OPTARG" ;;
4090 B) GETALBUMART=y ; EMBEDALBUMART=y ;;
4091 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
4092 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
4093 d) CDROM="$OPTARG" ;;
4096 e) ERASEENCODEDSTATUS=y ;;
4097 E) ENCODING="$OPTARG" ;;
4102 j) MAXPROCS="$OPTARG" ;;
4105 L) CDDBUSELOCAL=y ;;
4110 o) OUTPUTTYPE="$OPTARG" ;;
4113 Q) CDDBMETHOD="$OPTARG" ;;
4114 r) REMOTEHOSTS="$OPTARG" ;;
4115 R) CDDBLOCALRECURSIVE=y ;;
4116 s) SHOWCDDBFIELDS="$OPTARG" ;;
4117 S) CDSPEEDVALUE="$OPTARG" ;;
4118 t) STARTTRACKNUMBER="$OPTARG" ;;
4119 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
4122 echo "This is abcde v$VERSION."
4123 echo "Usage: abcde [options] [tracks]"
4124 echo "abcde -h for extra help"
4127 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
4129 X) CUE2DISCID="$OPTARG" ;;
4130 w) COMMENT="$OPTARG" ;;
4131 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
4132 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
4133 STARTTRACKNUMBERTAG="y"
4134 COMMENT="CD${OPTARG}"
4135 DISCNUMBER="${OPTARG}"
4137 log error "argument of -W must be integer"
4141 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
4146 shift $(($OPTIND - 1))
4148 # Here it comes the worse part of the whole thing. From here until we start
4149 # ripping, we have a mixture of sanity checks, verifications, default settigs
4150 # and other crazy stuff that interdepends, but hey, someone has to do it.
4152 # If NOCDDBQUERY is set, don't query the CDDB server.
4153 if [ "$NOCDDBQUERY" = "y" ]; then
4157 # If the user specified a flac file, then switch to special flac mode
4158 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
4159 if [ ! -f "$CDROM" ]; then
4160 log error "the defined file for FLAC ripping cannot be found" >&2
4163 vecho warning "switching to flac CDROMREADERSYNTAX..."
4164 CDROMREADERSYNTAX=flac
4165 # We have a builtin version of cue2discid...
4166 case "$CUE2DISCID" in
4168 *) NEEDCUE2DISCID=y;;
4174 # If the user provided a DISCID, disable eject
4175 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
4177 # Check the available cd rippers in the system, from the ones we know.
4178 if [ "$CDROMREADERSYNTAX" = "" ]; then
4179 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
4180 if new_checkexec $DEFAULT_CDROMREADER; then
4181 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
4185 if [ "$CDROMREADERSYNTAX" = "" ]; then
4186 log error "no cdreader found in your PATH"
4187 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4192 # Decide if we can continue.
4193 if [ "$ONETRACK" = "y" ]; then
4194 # FIXME # remove check as soon as we find out about the other readers
4195 case "$CDROMREADERSYNTAX" in
4197 cdparanoia | libcdio) ;;
4198 cdda2wav | icedax) ;;
4200 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
4203 if [ "$BATCHNORM" = "y" ]; then
4204 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
4207 if [ "$NOGAP" = "y" ]; then
4208 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
4211 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
4212 # FIXME # allow ranges of tracks to be selected for onetrack ripping
4213 if [ $# -gt 0 ]; then
4214 log warning "ONETRACK mode selected, grabbing all tracks..."
4217 while [ $# -gt 0 ]; do
4218 # Range parsing code courtesy of Vincent Ho
4219 # Cleaned up to use shell built-ins by Charles Steinkuehler
4220 if [ "${1#*[^0-9-]}" != "$1" ]; then
4221 log error "syntax error while processing track numbers ($1)"
4226 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
4227 TRACKQUEUE="$TRACKQUEUE $RSTART"
4228 RSTART=$(( $RSTART + 1 ))
4235 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
4236 # List of experimental actions: retag,transcode
4238 # Determine what actions are to be done from $ACTIONS and set the
4239 # following environment variables for them:
4251 ## FIXME ## Lets keep compatibility with -M
4252 [ "$DOCUE" != "y" ] && DOCUE=n
4254 for ACTION in $(echo $ACTIONS | tr , \ )
4257 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4258 cue) DOCUE=y ; MAKECUEFILE=y ;;
4261 normalize) DONORMALIZE=y; DOREAD=y;;
4262 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4263 encode) DOENCODE=y; DOREAD=y;;
4264 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4265 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4266 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4267 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4268 playlist) DOCDDB=y; DOPLAYLIST=y;;
4270 getalbumart) GETALBUMART=y;;
4271 embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
4275 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4276 # FIXME # should we abort on error or just inform the user?
4277 log warning "selected both normalize and replaygain actions"
4280 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
4281 case $SHOWCDDBFIELD in
4282 y*|Y*) SHOWCDDBYEAR="y";;
4283 g*|G*) SHOWCDDBGENRE="y";;
4288 # At this point a CDROM has to be defined, so we check it exists.
4289 if [ X"$CDROM" != "X" ] ; then
4290 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
4291 if [ "$OSFLAVOUR" = "FBSD" ]; then
4292 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
4293 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4294 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4298 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
4299 log error "CDROM device cannot be found."
4302 # avoid processing if we are not going to hit the CDROM.
4303 elif [ X"$DOREAD" = "Xy" ]; then
4304 log error "CDROM has not been defined or cannot be found"
4308 # USEPIPES pre-tests, before we get into more serious stuff
4309 # Not compatible with:
4310 # - multiple outputs
4312 # - lowdisk algorithm
4314 if [ X"$USEPIPES" = "Xy" ]; then
4315 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
4316 log error "Unix pipes not compatible with multiple outputs"
4319 if [ X"$DONORMALIZE" = "Xy" ]; then
4320 log error "Unix pipes not compatible with normalizer"
4321 # FIXME # Do we need to exit or shall we just disable the mode?
4324 if [ X"$BATCHNORM" = "Xy" ]; then
4325 log error "Unix pipes not compatible with BATCHNORM encoding"
4328 if [ X"$NOGAP" = "Xy" ]; then
4329 log error "Unix pipes not compatible with NOGAP encoding"
4332 if [ X"$DOENCODE" = "Xn" ]; then
4333 vecho warning "Disabling Unix pipes since we are not encoding!"
4336 if [ X"$LOWDISK" = "Xy" ]; then
4337 log error "Unix pipes not compatible with lowdisk algorithm"
4342 # LOWDISK pre-tests, before we get into more problematic stuff
4343 # Not compatible with anything that needs all the files in the hard disc:
4346 if [ X"$LOWDISK" = "Xy" ]; then
4347 if [ X"$BATCHNORM" = "Xy" ]; then
4348 log error "Unix pipes not compatible with BATCHNORM encoding"
4351 if [ X"$NOGAP" = "Xy" ]; then
4352 log error "Unix pipes not compatible with NOGAP encoding"
4357 # BATCHNORM pre-tests, before we get into serious problems
4358 # Not compatible with
4359 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4360 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4364 # Check the encoding format from the ones available in the system, if nothing has been configured.
4365 if [ X"$OUTPUTTYPE" = "X" ]; then
4366 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4367 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
4368 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
4369 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
4370 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4371 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4375 if [ X"$OUTPUTTYPE" = "X" ]; then
4376 log error "no encoder found in the PATH"
4377 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4382 # Decide which CDROM reader we're gonna use
4383 case "$CDROMREADERSYNTAX" in
4385 CDROMREADER="$CDPARANOIA"
4386 CDROMREADEROPTS="$CDPARANOIAOPTS"
4389 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4390 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4391 CDROMREADER="$CD_PARANOIA"
4392 CDROMREADEROPTS="$CDPARANOIAOPTS"
4395 CDROMREADER="$CDDA2WAV"
4396 CDROMREADEROPTS="$CDDA2WAVOPTS"
4399 CDROMREADER="$DAGRAB"
4400 CDROMREADEROPTS="$DAGRABOPTS"
4404 CDROMREADEROPTS="$PIRDOPTS"
4407 CDROMREADER="$CDDAFS"
4408 CDROMREADEROPTS="$CDDAFSOPTS"
4412 CDROMREADEROPTS="$FLACOPTS"
4416 # There's only one normalize...
4417 case "$NORMALIZERSYNTAX" in
4419 NORMALIZER="$NORMALIZE"
4420 NORMALIZEROPTS="$NORMALIZEOPTS"
4424 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4425 case "$OUTPUTTYPE" in *:*)
4426 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4427 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4429 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4430 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4431 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4432 aiff:*) AIFFENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4433 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4434 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4435 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4436 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4437 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4438 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4439 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4440 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4441 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4444 # Allows commandline selection of options while using multiple outputs.
4445 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4446 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4447 TEMPOUTPUT=${OUTPUT%%:*}
4448 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4450 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4454 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4455 # for flacs and speexenc for speex and mpcenc for mpcs and fdkaac for m4as and
4456 # wavpack for wvs...
4458 # Getting ready for multiple output changes
4459 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4463 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4464 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4465 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4466 OGGOUTPUTCONTAINER=ogg
4469 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4470 OPUSOUTPUTCONTAINER=opus
4473 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4474 MKAOUTPUTCONTAINER=mka
4477 [ "$AIFFENCODERSYNTAX" = "default" ] && AIFFENCODERSYNTAX=ffmpeg
4478 AIFFOUTPUTCONTAINER=aiff
4481 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4482 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4483 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4484 [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
4487 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4488 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4489 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4490 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4491 [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
4494 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4495 # [ "$DOREPLAYGAIN" = "y" ] &&
4498 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4499 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4502 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4504 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4505 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4506 [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
4509 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4510 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4513 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4514 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4515 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4518 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4519 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4520 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4523 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4525 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4526 # compiled without libmp4v2... Andrew.
4529 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=fdkaac
4530 [ "$AACENCODERSYNTAX" = "faac" ] && [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4531 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4532 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4533 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4534 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4535 [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
4538 if [ "$KEEPWAVS" = "y" ]; then
4539 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4543 *) log error "Invalid OUTPUTTYPE defined"
4549 # decide which encoder
4550 case "$MP3ENCODERSYNTAX" in
4552 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4556 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4560 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4561 MP3ENCODER="$BLADEENC"
4564 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4568 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4569 MP3ENCODER="$XINGMP3ENC"
4572 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4573 MP3ENCODER="$MP3ENC"
4576 case "$OGGENCODERSYNTAX" in
4578 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4579 OGGENCODER="$VORBIZE"
4582 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4583 OGGENCODER="$OGGENC"
4586 case "$OPUSENCODERSYNTAX" in
4588 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4589 OPUSENCODER="$OPUSENC"
4592 case "$MKAENCODERSYNTAX" in
4594 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4595 MKAENCODER="$FFMPEG"
4598 case "$AIFFENCODERSYNTAX" in
4600 AIFFENCODEROPTS="${AIFFENCODEROPTSCLI:-$AIFFENCOPTS}"
4601 AIFFENCODER="$FFMPEG"
4604 case "$FLACENCODERSYNTAX" in
4606 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4608 if [ "$DOREPLAYGAIN" = "y" ]; then
4609 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4611 # FLAC streams can be encapsulated on a Ogg transport layer
4612 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4613 log error "FLAC on an Ogg container is not yet supported"
4614 log error "due to problem with adding comments to such files"
4616 FLACOUTPUTCONTAINER=ogg
4618 FLACOUTPUTCONTAINER=flac
4622 case "$SPEEXENCODERSYNTAX" in
4624 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4625 SPEEXENCODER="$SPEEXENC"
4628 case "$MPCENCODERSYNTAX" in
4630 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4631 MPCENCODER="$MPCENC"
4634 case "$WVENCODERSYNTAX" in
4636 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4637 # and in the interests of backward compatibility:
4638 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4639 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4640 WVENCODER="$WAVPACK"
4642 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4643 WVENCODER="$WAVPACK"
4647 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4651 case "$TTAENCODERSYNTAX" in
4653 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4657 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4658 TTAENCODER="$TTAENC"
4661 case "$APENCODERSYNTAX" in
4663 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4667 case "$MP2ENCODERSYNTAX" in
4669 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4670 MP2ENCODER="$TWOLAME"
4673 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4674 MP2ENCODER="$FFMPEG"
4677 case "$AACENCODERSYNTAX" in
4678 # Some elaborate 'if' work to keep backward compatibility for those
4679 # who don't realise that AACENCOPTS does not work with abcde from
4680 # version 2.7 onwards.
4682 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4683 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4686 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4691 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4692 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4693 AACENCODER="$NEROAACENC"
4695 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4696 AACENCODER="$NEROAACENC"
4700 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4701 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4702 AACENCODER="$FDKAAC"
4704 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4705 AACENCODER="$FDKAAC"
4709 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4710 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4713 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4718 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4719 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4720 AACENCODER="$FHGAACENC"
4722 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4723 AACENCODER="$FHGAACENC"
4727 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4728 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4729 AACENCODER="$FFMPEG"
4731 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4732 AACENCODER="$FFMPEG"
4742 TAGGEROPTS="$ID3OPTS"
4747 TAGGEROPTS="$ID3V2OPTS"
4752 TAGGEROPTS="$ID3TAGOPTS"
4756 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4757 # trouble with CDDBPROTO=5 (which we test here) but also
4758 # with cached cddb files in latin1 (which we cannot test).
4759 if [ "$CDDBPROTO" -lt 6 ]; then
4760 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4763 # eyeD3 version 0.7 changed syntax
4764 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4765 # only if it offers the --set-encoding, assume <= 0.6.x
4767 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4769 # anything wrong, any failure, assume >= 0.7
4771 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4775 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4780 # NOGAP is specific to lame. Other encoders fail ...
4781 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4782 log warning "the NOGAP option is specific to lame. Deactivating..."
4787 case "$CUEREADERSYNTAX" in
4789 CUEREADEROPTS="${CDROM}"
4794 # which information retrieval tool are we using?
4800 # 2016-08-30: adding comma-separated list (in this case, to be used in
4801 # sequence until successful) support ala OUTPUTYPE. -GR
4803 for CDDBCHOICE in $(echo "$CDDBMETHOD" | tr -d ' ' | tr , ' ')
4805 # The OUTPUTTYPE code uses bash-specific syntax (var=${var:+var}),
4806 # but then doesn't just use an array to store the output, which seems
4807 # weird. So I'm going to use an array for this...? -GR
4808 CDDBMETHODS[$idx]=$CDDBCHOICE
4809 vvecho "CDDB method $idx: $CDDBCHOICE"
4813 # Just so CDDBMETHOD is a legible value for functions, in case I
4814 # miss something, set it to the first choice: -GR
4815 CDDBMETHOD=${CDDBMETHODS[0]}
4817 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4818 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4819 log error "FLAC on an Ogg container is not yet supported"
4820 log error "due to problem with adding comments to such files"
4822 OGGOUTPUTCONTAINER=ogg.ogg
4823 FLACOUTPUTCONTAINER=flac.ogg
4824 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4827 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4829 if [ "$ENCNICE" ]; then
4830 ENCNICE="-n $ENCNICE"
4832 if [ "$READNICE" ]; then
4833 READNICE="-n $READNICE"
4835 if [ "$DISTMP3NICE" ]; then
4836 DISTMP3NICE="-n $DISTMP3NICE"
4839 # Don't check for stuff if it's not needed
4840 if [ "$REMOTEHOSTS" ]; then
4843 if [ "$DONORMALIZE" = "y" ]; then
4846 if [ "$EJECTCD" = "y" ]; then
4849 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4850 if [ "$CDDBMETHOD" = "cddb" ]; then
4852 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
4856 if [ "$DOCUE" = "y" ]; then
4860 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4861 case "$CDROMREADERSYNTAX" in
4862 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4863 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4864 ### FIXME ### translate "cue2discid" from python to bash
4865 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4870 if [ "$GETALBUMART" = "y" ]; then
4875 ###USEPIPESSUPPORT###
4877 # Rippers with USEPIPE support
4878 PIPERIPPER_cdparanoia="-"
4879 PIPERIPPER_libcdio="-"
4880 # Note that by default in abcde cdda2wav redirects to icedax.
4881 PIPERIPPER_cdda2wav="-"
4882 PIPERIPPER_debug="-"
4883 PIPERIPPER_flac="-c "
4886 # Encoders with USEPIPE support
4889 PIPE_bladeenc="stdin"
4902 # Both neroAacEnc and fdkaac seem to manage without the addition of
4903 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4904 # in this manner. Andrew.
4908 # Figure out if we can use pipes with the ripper/encoder combination
4910 if [ "$USEPIPES" = "y" ]; then
4911 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4914 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4916 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4918 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4920 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4922 PIPEENCODERSVARCHECK="PIPE_$AIFFENCODERSYNTAX" ;;
4924 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4926 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4928 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4930 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4932 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4934 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4936 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4938 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4939 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4940 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4941 log error "no support for pipes with given ripper"
4942 log error "read the FAQ file from the source tarball to get help."
4945 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4946 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4947 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4948 log error "no support for pipes with given encoder"
4949 log error "read the FAQ file from the source tarball to get help"
4954 # Make sure a buncha things exist
4955 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4956 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4957 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER $AIFFENCODER \
4958 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4959 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4960 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4961 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4962 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4963 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4964 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4965 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4966 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4967 ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
4972 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4973 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4974 # these files). The resulting files are actually ADTS streams which belong in an
4975 # aac container and with some version sniffing this is all cleaned up below. If
4976 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4978 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4979 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4980 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4981 echo "WARNING: Your copy of Faac does not have mp4 support"
4982 echo "WARNING: Encoding untagged files to aac..."
4983 # Replace m4a with aac for single and multi-output encodes:
4984 OUTPUTTYPE=$(echo "$OUTPUTTYPE" | sed 's/m4a/aac/')
4986 echo "Using Faac to Tag AAC Tracks..."
4990 # And last but not least, check if we can diff between files. We do not abort,
4991 # since diffing is not critical...
4992 if [ -x $(which $DIFF) ]; then :; else
4993 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4997 ## Now that we have metaflac, check if we need cue2discid
4998 #case $CDROMREADERSYNTAX in
5000 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
5001 # if [ "$TRACKINFO" = "" ]; then
5002 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
5007 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
5008 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
5009 HTTPGET="$HTTPGET $HTTPGETOPTS"
5011 # Here it used to say:
5012 # One thousand lines in, we can start doing stuff with things
5013 # Well, right now we are at line 3737 ;)
5014 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
5016 # Export needed things so they can be read in this subshell
5017 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
5018 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
5020 if [ "$DOREAD" = "y" ]; then
5021 # User-definable function to set some things. Use it for
5022 # - closing the CD tray with eject -t
5023 # - set the CD speed value with eject -x
5024 vecho -n "Executing customizable pre-read function... "
5026 pre_read # Execute the user-defined pre-read function. Close the CD with it.
5031 # Get ABCDETEMPDIR created and status file initialized
5034 if [ "$DOCDDB" = "y" ]; then
5035 # start with a sane default:
5036 CDDBLOCALSTATUS=notfound
5037 if [ $CDDBUSELOCAL = "y" ]; then
5040 if checkstatus cddb-choice > /dev/null; then
5043 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
5044 for CDDBMETHCHOICE in ${CDDBMETHODS[@]}
5046 vecho "Trying CDDB method ${CDDBMETHCHOICE}."
5047 if [ $CDDBLASTMETHOD = "n" ]
5049 if [ ${#CDDBMETHODS[@]} -le 1 ]
5054 CDDBMETHODS=("${CDDBMETHODS[@]:1}")
5055 # (performs shift on an array in bash)
5058 vvecho "(Last chance before manual entry...)"
5060 case "$CDDBMETHCHOICE" in
5070 if [ -f "$ABCDETEMPDIR/cddbchoices" ]
5072 # If this pass found something, we're done.
5077 CHOICE=$(checkstatus cddb-choice)
5078 if [ "$CHOICE" = 0 ] ; then
5079 # We don't have any information at all; try to fall back
5080 # to CD-Text for basic information
5081 vecho "No CDDB information found, trying cdtext from the CD"
5087 eval "$($CDDBTOOL parse "$CDDBDATA")"
5090 # Before reading tracks, we set the speed of the device
5092 if [ X"$CDSPEEDVALUE" != "X" ]; then
5093 case "$CDROMREADERSYNTAX" in
5094 cdparanoia|libcdio|debug) ;;
5101 # Define the first and last track, since we might need them later in several places
5102 FIRSTTRACK=$( get_first $TRACKQUEUE )
5103 LASTTRACK=$( get_last $TRACKQUEUE )
5105 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
5106 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
5107 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
5108 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
5111 if checkstatus onetrack ; then ONETRACK=y ; fi
5113 if [ "$ONETRACK" = "y" ]; then
5114 # Reuse the CUEFILE in case we created it (now or in a previous run)
5115 if CUEFILE=$(checkstatus cuefile); then
5120 # Create playlist if needed (backgroundable) and start reading in tracks
5124 if [ ! "$ONETRACK" = "y" ]; then
5125 if [ "$DOPLAYLIST" = "y" ]; then
5126 echo Creating playlist... >&2
5131 if [ "$GETALBUMART" = "y" ]; then
5135 # For the lowdisk option, only one program is running at once so the encoder
5136 # can be unsilenced right away.
5137 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
5138 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
5141 if [ "$ONETRACK" = "y" ]; then
5142 TRACKS="$FIRSTTRACK"
5143 if [ "$USEPIPES" = "y" ]; then
5144 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
5145 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
5148 if checkstatus readtrack-$FIRSTTRACK; then :; else
5149 do_cdread onetrack $FIRSTTRACK $LASTTRACK
5153 for UTRACKNUM in $TRACKQUEUE
5155 if [ "$DOREAD" = "y" ]; then
5156 if [ "$USEPIPES" = "y" ]; then
5157 if checkstatus readencodetrack-$UTRACKNUM; then :; else
5158 # Read, pipe, shut up!
5159 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
5162 if checkstatus readtrack-$UTRACKNUM; then :; else
5163 do_cdread $UTRACKNUM
5165 if [ "$?" != "0" ]; then
5166 # CD read failed - don't give the goahead to
5173 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
5176 # If we are not reading, set the encode output to loud already, so
5177 # that we can see the output of the first track.
5178 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
5179 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
5181 echo NEXTTRACK # Get the encoder machine churning again
5182 if [ "$DOREAD" = "y" ]; then
5183 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
5184 until checkstatus encodetrack-$UTRACKNUM
5186 if checkerrors encodetrack-$UTRACKNUM; then
5197 # Now that we're done the encoding can be loud again -
5198 # if we're not using SMP.
5199 if [ "$MAXPROCS" = "1" ]; then
5200 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
5203 # All tracks read, start encoding.
5204 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
5208 # Execute the user-defined post_read function before ejecting CD
5211 # We are now finished with the cdrom - it can be safely ejected. Note that
5212 # abcde will not have completed yet.
5213 if [ "$EJECTCD" = "y" ]; then
5214 # We check if the disk we are processing is actually the disk inside the
5215 # CD tray. If not, we do not eject the CD, since it might be so that the
5216 # user ejected it manually.
5217 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
5218 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
5219 # More FreeBSD bits.
5220 if [ X"$(uname)" = X"FreeBSD" ] ; then
5221 # FreeBSD eject uses the EJECT environment variable to name the CDROM
5222 # but in this script EJECT is in the envionment and names the program
5225 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
5226 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
5227 $eject $EJECTOPTS $cd
5228 elif [ X"$(uname)" = X"Darwin" ] ; then
5229 diskutil eject ${CDROM#/dev/} 0
5230 elif [ -x $(which $EJECT) ]; then
5231 $EJECT $EJECTOPTS "$CDROM"
5238 ## Do we need to pre-process
5239 #if [ x"$PREPROCESS" = "x" ] ; then
5242 # for PRETRACKNUM in $TRACKQUEUE
5245 # if [ "$GOAHEAD" = "NO" ]; then break; fi
5247 # until [ $PREPROCEED ]
5249 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
5250 # # all locations are working, wait and try again later
5251 # if [ ! $PREPROCEED ]; then sleep 3; fi
5253 # ( do_preprocess $PRETRACKNUM
5261 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
5263 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
5264 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5265 if [ "$GOAHEAD" != "NO" ]; then
5266 for LASTTRACK in $TRACKQUEUE; do :; done
5267 if checkstatus readtrack-$LASTTRACK; then
5268 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
5269 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
5270 if checkerrors batch-normalize; then exit 1; fi
5272 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
5273 if [ "$DONORMALIZE" = "y" ]; then
5274 for UTRACKNUM in $TRACKQUEUE
5276 if checkstatus readtrack-$UTRACKNUM; then
5277 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5281 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
5282 if checkerrors nogap-encode; then exit 1; fi
5288 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
5289 if [ "$ONETRACK" = "y" ] ; then
5290 TRACKQUEUE="$FIRSTTRACK"
5291 TRACKS="$FIRSTTRACK"
5294 # Do the encoding, including parallelization of remote encoding
5295 # Figure out where each track is going to be encoded
5296 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
5297 if [ "$MAXPROCS" != "0" ]; then
5298 for NUM in $(f_seq_row 1 "$MAXPROCS")
5300 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5304 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5305 for UTRACKNUM in $TRACKQUEUE
5308 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5309 if [ "$GOAHEAD" = "NO" ]; then break; fi
5310 # find out where this track is to be encoded
5311 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5312 # Make sure we have a place to encode this, if not, exit stage right
5313 if [ -z "$ENCODELOCATIONS" ]; then
5319 for LOCATION in $ENCODELOCATIONS
5321 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5322 # check first if a track has ever been assigned to this location
5323 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5324 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5325 if checkerrors encodetrack-$PREVIOUSTRACK; then
5326 for TEMPLOCATION in $ENCODELOCATIONS
5328 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5329 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5332 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5337 # We're still here, this location must have been previously assigned,
5338 # and last completed without error - check if it's done with the
5339 # previous track yet
5340 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
5342 # all locations are working, wait and try again later
5343 if [ ! $PROCEED ]; then sleep 3; fi
5345 # Record the location we're about to encode the next track at
5346 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
5348 # Don't proceed with the rest of the loop if we can't encode
5349 if [ "$ABORT" ]; then continue; fi
5350 ## FIXME ## Add here
5351 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
5352 # Set TRACKNUM, TRACKNAME
5353 if [ -e "$CDDBDATA" ]; then
5354 if [ "$ONETRACK" = "y" ]; then
5356 TRACKNUM="$FIRSTTRACK"
5360 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
5361 getcddbinfo TRACKNAME
5365 # You can't encode a file which needs to be normalized before finishing
5366 # You can't tag a file before it's finished encoding -
5367 # thus all of this is backgrounded together
5369 if [ "$DONORMALIZE" = "y" ]; then
5370 if checkstatus readtrack-$UTRACKNUM; then
5371 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5374 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5375 if checkstatus readtrack-$UTRACKNUM; then
5376 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
5377 if [ "$DONORMALIZE" = "y" ]; then
5378 if checkstatus normalizetrack-$UTRACKNUM; then
5379 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5382 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5386 if [ "$DOTAG" = "y" ]; then
5387 if checkstatus encodetrack-$UTRACKNUM; then
5388 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
5390 # Lets tag the cue file
5391 if checkstatus cleancuefile >/dev/null; then :; else
5392 if checkstatus cuefile >/dev/null ; then
5397 if [ "$DOMOVE" = "y" ]; then
5398 if checkstatus tagtrack-$UTRACKNUM; then
5399 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
5406 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5407 # we'll delete the files they're working on
5408 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5409 ## FIXME ## Check also for files which are encoded using PIPEs.
5410 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5415 for LOCATION in $ENCODELOCATIONS
5417 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5418 # "How can he give us a status update, if he's DEAD?"
5419 if checkstatus encodetrack-$CHECKTRACK; then
5422 # Nothing to see here please go quietly back to your homes
5423 if [ -z "$CHECKTRACK" ]; then continue; fi
5424 # You're still here? Maybe there is something...
5425 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
5428 if [ ! $PROCEED ]; then sleep 5; fi
5431 # If the above didn't catch the stragglers, this will
5433 if [ "$DOREPLAYGAIN" = "y" ]; then
5437 if [ "$EMBEDALBUMART" = "y" ]; then
5441 # Execute the user-defined post_encode function before cleaning up
5444 # Check to see if run_command logged any errors
5445 if [ -f "$ABCDETEMPDIR/errors" ]; then
5446 log error "The following commands failed to run:"
5447 cat "$ABCDETEMPDIR/errors"
5451 if [ "$KEEPWAVS" = "y" ];then
5455 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5456 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5457 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5458 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5459 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5460 log warning "The encoded formats does not match with the moved ones"
5461 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
5462 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
5463 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
5467 if [ "$DOCLEAN" = "y" ]; then
5468 # Wipe all the evidence
5469 # Gimme gimme gimme some more time!
5471 rm -rf "$ABCDETEMPDIR"
5474 echo "Finished. Not cleaning $ABCDETEMPDIR."