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 method(s) from the command line. Choose from any/all of musicbrainz,cddb,cdtext. Defaults to 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 2>/dev/null)" = "" ]; then
344 elif [ ! -x $(which $X 2>/dev/null) ]; 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 2>/dev/null)" = "" ]; 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 2>/dev/null)" ]; 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 $LINES ]; 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 vvecho "makeids: PREGAP $PREGAP, LEADIN $LEADIN, LEADOUT $LEADOUT"
492 # Calculate both the cddb discid *and* the musicbrainz discid
493 # now. We'll use the cddb discid for reference in most cases
494 # for consistency, but we also have the musicbrainz discid for
496 printf -v CDDBDISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
497 CDDBTRACKINFO="${CDDBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
501 # FIXME: don't assume the first track is 1
502 MBDISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $(($PREGAP + $LEADOUT)) $OFFSETS)
503 MBTRACKINFO="${MBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
510 if checkstatus replaygain; then :; else
511 run_command "" echo "Adding replaygain information..."
512 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
516 OUTPUT=$OGGOUTPUTCONTAINER
519 OUTPUT=$OPUSOUTPUTCONTAINER
522 OUTPUT=$FLACOUTPUTCONTAINER
530 for UTRACKNUM in $TRACKQUEUE
532 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
533 getcddbinfo TRACKNAME
535 TRACKFILE="$(mungetrackname "$TRACKNAME")"
536 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
537 ALBUMFILE="$(mungealbumname "$DALBUM")"
538 GENRE="$(mungegenre "$GENRE")"
539 YEAR=${CDYEAR:-$CDYEAR}
541 if [ "$ONETRACK" = "y" ]; then
542 if [ "$VARIOUSARTISTS" = "y" ]; then
543 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
545 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
548 if [ "$VARIOUSARTISTS" = "y" ]; then
549 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
551 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
554 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
555 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
559 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
560 #run_command replaygain-flac true
563 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
566 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
569 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
572 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
577 if checkerrors "replaygain-.{3,6}"; then :; else
578 run_command replaygain true
583 # This code splits the a Various Artist track name from one of the following
586 # forward: Artist / Track
587 # forward-dash: Artist - Track
588 # reverse: Track / Artist
589 # reverse-dash: Track - Artist
590 # colon: Artist: Track
591 # trailing-paren: Artist (Track)
594 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
597 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
598 case "$VARIOUSARTISTSTYLE" in
600 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
601 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
602 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
605 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
606 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
607 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
610 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
611 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
612 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
615 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
616 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
617 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
620 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
621 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
622 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
625 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
626 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
627 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
630 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
631 TRACKARTIST="Various"
633 TRACKARTIST="$DARTIST"
638 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
642 "classic rock") id=1 ;;
660 "industrial") id=19 ;;
661 "alternative") id=20 ;;
663 "death metal") id=22 ;;
665 "soundtrack") id=24 ;;
666 "euro-techno") id=25 ;;
670 "jazz+funk") id=29 ;;
673 "classical") id=32 ;;
674 "instrumental") id=33 ;;
678 "sound clip") id=37 ;;
681 "alt. rock") id=40 ;;
686 "meditative") id=45 ;;
687 "instrum. pop") id=46 ;;
688 "instrum. rock") id=47 ;;
692 "techno-indust.") id=51 ;;
693 "electronic") id=52 ;;
695 "eurodance") id=54 ;;
697 "southern rock") id=56 ;;
702 "christian rap") id=61 ;;
703 "pop/funk"|"pop / funk") id=62 ;;
705 "native american") id=64 ;;
708 "psychadelic") id=67 ;;
710 "showtunes") id=69 ;;
714 "acid punk") id=73 ;;
715 "acid jazz") id=74 ;;
719 "rock & roll") id=78 ;;
720 "hard rock") id=79 ;;
722 "folk/rock") id=81 ;;
723 "national folk") id=82 ;;
730 "bluegrass") id=89 ;;
731 "avantgarde") id=90 ;;
732 "gothic rock") id=91 ;;
733 "progress. rock") id=92 ;;
734 "psychadel. rock") id=93 ;;
735 "symphonic rock") id=94 ;;
736 "slow rock") id=95 ;;
739 "easy listening") id=98 ;;
745 "chamber music") id=104 ;;
747 "symphony") id=106 ;;
748 "booty bass") id=107 ;;
750 "porn groove") id=109 ;;
752 "slow jam") id=111 ;;
756 "folklore") id=115 ;;
758 "power ballad") id=117 ;;
759 "rhythmic soul") id=118 ;;
760 "freestyle") id=119 ;;
762 "punk rock") id=121 ;;
763 "drum solo") id=122 ;;
764 "a capella") id=123 ;;
765 "euro-house") id=124 ;;
766 "dance hall") id=125 ;;
768 "drum & bass") id=127 ;;
769 "club-house") id=128 ;;
770 "hardcore") id=129 ;;
774 "negerpunk") id=133 ;;
775 "polsk punk") id=134 ;;
777 "christian gangsta rap") id=136 ;;
778 "heavy metal") id=137 ;;
779 "black metal") id=138 ;;
780 "crossover") id=139 ;;
781 "contemporary christian")id=140 ;;
782 "christian rock") id=141 ;;
783 "merengue") id=142 ;;
785 "thrash metal") id=144 ;;
788 "synthpop") id=147 ;;
789 "rock/pop"|"rock / pop") id=148 ;;
796 # do_tag [tracknumber]
797 # id3 tags a filename
799 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
800 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
803 COMMENTOUTPUT="$(eval echo ${COMMENT})"
804 if [ -z "$COMMENTOUTPUT" ]; then
805 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
807 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
808 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
809 # If we want to start the tracks with a given number, we need to modify the
810 # TRACKNUM value before evaluation
811 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
814 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
818 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
819 GENREID=$(do_getgenreid "${CDGENRE}")
820 # Set TPE2 in case we have a Various Artists rip.
822 if [ "$VARIOUSARTISTS" = "y" ]; then
828 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
829 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
830 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
831 -y "$CDYEAR" -g "$GENREID" \
832 -T "${TRACKNUM:-$1}" \
833 "${ABCDETEMPDIR}/track$1.$OUTPUT"
836 # FIXME # track numbers in mp3 come with 1/10, so we cannot
837 # happily substitute them with $TRACKNUM
838 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
839 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
840 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
841 -y "$CDYEAR" -g "$GENREID" \
842 -T "${TRACKNUM:-$1}/$TRACKS" \
843 ${TPE2:+--TPE2 "$TPE2"} \
844 "${ABCDETEMPDIR}/track$1.$OUTPUT"
847 # FIXME # track numbers in mp3 come with 1/10, so we cannot
848 # happily substitute them with $TRACKNUM
849 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
850 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
851 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
852 -y "$CDYEAR" -g "$GENREID" \
853 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
854 "${ABCDETEMPDIR}/track$1.$OUTPUT"
857 # FIXME # track numbers in mp3 come with 1/10, so we cannot
858 # happily substitute them with $TRACKNUM
860 eyed3_06) addopts=( \
861 ${ENCODING:+--set-encoding="$ENCODING"} \
862 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
863 # We set 'recording-date' so the date tag will show
864 # in Audacious, vlc and friends... Andrew.
865 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
866 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
869 ${ENCODING:+--encoding="$ENCODING"} \
870 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
871 # We set 'recording-date' so the date tag will show
872 # in Audacious, vlc and friends... Andrew.
873 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
874 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
877 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
879 -a "$TRACKARTIST" -t "$TRACKNAME" \
880 -G "$GENREID" -n "${TRACKNUM:-$1}" \
881 ${TRACKNUM:+-N "$TRACKS"} \
883 "${ABCDETEMPDIR}/track$1.$OUTPUT"
886 log error "Internal error: ID3SYNTAX has an illegal value"
892 case "$OGGENCODERSYNTAX" in
894 # vorbiscomment can't do in-place modification, mv the file first
895 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" -a ! -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
896 mv "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
900 # https://www.xiph.org/vorbis/doc/v-comment.html
902 echo ARTIST="$TRACKARTIST"
904 echo TITLE="$TRACKNAME"
905 if [ -n "$CDYEAR" ]; then
908 if [ -n "$CDGENRE" ]; then
909 echo GENRE="$CDGENRE"
911 echo TRACKNUMBER=${TRACKNUM:-$1}
912 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
913 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
914 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
915 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
916 echo TRACKTOTAL="${TRACKS}"
917 if [ -n "$DISCNUMBER" ]; then
918 echo DISCNUMBER="$DISCNUMBER"
920 echo CDDB=$CDDBDISCID
921 if [ "$(eval echo ${COMMENT})" != "" ]; then
922 case "$COMMENTOUTPUT" in
923 *=*) echo "$COMMENTOUTPUT";;
924 *) echo COMMENT="$COMMENTOUTPUT";;
927 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
928 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
929 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
930 # Doublecheck that the commented file was created
931 # successfully before wiping the original
932 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ]; then
933 rm -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
935 mv "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
941 run_command tagtrack-$OUTPUT-$1 true
944 run_command tagtrack-$OUTPUT-$1 true
947 run_command tagtrack-$OUTPUT-$1 true
951 echo ARTIST="$TRACKARTIST"
953 echo TITLE="$TRACKNAME"
954 if [ -n "$CDYEAR" ]; then
957 if [ -n "$CDGENRE" ]; then
958 echo GENRE="$CDGENRE"
960 echo TRACKNUMBER="${TRACKNUM:-$1}"
961 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
962 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
963 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
964 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
965 echo TRACKTOTAL="${TRACKS}"
966 if [ -n "$DISCNUMBER" ]; then
967 echo DISCNUMBER="$DISCNUMBER"
969 echo CDDB="$CDDBDISCID"
970 if [ "$(eval echo ${COMMENT})" != "" ]; then
971 case "$COMMENTOUTPUT" in
972 *=*) echo "$COMMENTOUTPUT";;
973 *) echo COMMENT="$COMMENTOUTPUT";;
976 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} \
977 --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
980 run_command tagtrack-$OUTPUT-$1 true
983 run_command tagtrack-$OUTPUT-$1 true
986 run_command tagtrack-$OUTPUT-$1 true
989 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
990 # Console port (mac) used for encoding does not have the ability to tag.
991 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "${ABCDETEMPDIR}/track$1.ape" -m overwrite \
992 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
993 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
996 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
997 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
998 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
999 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1000 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1001 "${ABCDETEMPDIR}/track$1.mp2"
1004 run_command tagtrack-$OUTPUT-$1 true
1007 case "$AACENCODERSYNTAX" in
1009 # We will use inline tagging...
1010 run_command tagtrack-$OUTPUT-$1 true
1013 # Tag post encode with neroAacTag...
1014 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "${ABCDETEMPDIR}/track$1.m4a" \
1015 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
1016 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1019 run_command tagtrack-$OUTPUT-$1 true
1022 run_command tagtrack-$OUTPUT-$1 true
1025 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1026 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1027 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$ATOMICPARSLEY" "${ABCDETEMPDIR}/track$1.m4a" \
1028 --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum=${TRACKNUM:-$1} \
1029 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
1032 run_command tagtrack-$OUTPUT-$1 true
1037 # We use mid3v2 tagging for True Audio:
1038 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1039 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1040 "${ABCDETEMPDIR}/track$1.tta"
1043 run_command tagtrack-$OUTPUT-$1 true
1047 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1048 run_command tagtrack-$1 true
1054 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1057 # The commands here don't go through run_command because they're never
1058 # supposed to be silenced
1059 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1060 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1064 case "$MP3ENCODERSYNTAX" in
1067 cd "${ABCDETEMPDIR}"
1069 for UTRACKNUM in $TRACKQUEUE
1071 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1073 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1075 if [ "$RETURN" != "0" ]; then
1076 echo "nogap-encode: $ENCODER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1078 for UTRACKNUM in $TRACKQUEUE
1080 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1081 #run_command encodetrack-$UTRACKNUM true
1090 if checkerrors "nogap-encode"; then :; else
1091 if [ ! "$KEEPWAVS" = "y" ] ; then
1092 if [ ! "$KEEPWAVS" = "move" ] ; then
1097 # Other encoders fall through to normal encoding as the tracks have not
1098 # been entered in the status file.
1101 # do_encode [tracknumber] [hostname]
1102 # If no hostname is specified, encode locally
1104 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1105 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1108 if [ "$USEPIPES" = "y" ]; then
1111 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1114 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1117 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1120 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1123 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1126 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1129 TEMPARG="PIPE_$SPEEXENCODER"
1132 TEMPARG="PIPE_$MPCENCODER"
1135 TEMPARG="PIPE_$WVENCODERSYNTAX"
1138 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1141 TEMPARG="PIPE_$AACENCODERSYNTAX"
1144 TEMPARG="PIPE_$AACENCODERSYNTAX"
1147 IN="$( eval echo "\$$TEMPARG" )"
1149 IN="${ABCDETEMPDIR}/track$1.wav"
1151 # We need IN to proceed, if we are not using pipes.
1152 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1153 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1155 case "$TMPOUTPUT" in
1157 OUTPUT=$OGGOUTPUTCONTAINER
1160 OUTPUT=$OPUSOUTPUTCONTAINER
1163 OUTPUT=$MKAOUTPUTCONTAINER
1166 OUTPUT=$AIFFOUTPUTCONTAINER
1169 OUTPUT=$FLACOUTPUTCONTAINER
1175 OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1176 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1179 if [ X"$USEPIPES" = "Xy" ]; then
1181 # We need a way to store the creation of the files when using PIPES
1182 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1183 # When piping it does not make sense to have a higher nice for
1184 # reading than for encoding, since it will be hold by the
1185 # encoding process. Setting an effective nice, to calm down a
1186 # bit the reading process.
1187 EFFECTIVE_NICE=$READNICE
1189 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1190 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1191 EFFECTIVE_NICE=$ENCNICE
1197 case "$MP3ENCODERSYNTAX" in
1198 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1199 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1200 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1201 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1205 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1212 case "$OGGENCODERSYNTAX" in
1213 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1214 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1218 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1225 case "$OPUSENCODERSYNTAX" in
1227 # Tag the file at encode time, as it can't be done after encoding.
1228 if [ "$DOTAG" = "y" ]; then
1229 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1230 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1231 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1233 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1239 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1244 case "$MKAENCODERSYNTAX" in
1246 if [ "$DOTAG" = "y" ]; then
1247 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS -metadata artist="$TRACKARTIST" \
1248 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1249 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1251 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1257 case "$AIFFENCODERSYNTAX" in
1259 if [ "$DOTAG" = "y" ]; then
1260 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS -metadata artist="$TRACKARTIST" \
1261 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1262 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1264 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1272 case "$FLACENCODERSYNTAX" in
1273 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1278 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1279 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1284 if [ "$(eval echo ${COMMENT})" != "" ]; then
1287 *) COMMENT="COMMENT=$COMMENT" ;;
1290 # Tag the file at encode time, as it can't be done after encoding.
1291 if [ "$DOTAG" = "y" ]; then
1292 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1293 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1295 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1299 # Tag the file inline at encode time.
1300 if [ "$DOTAG" = "y" ]; then
1301 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1302 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1304 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1308 case "$TTAENCODERSYNTAX" in
1309 # tta is the newer version with a small syntax change...
1311 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1314 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1319 case "$WVENCODERSYNTAX" in
1321 if [ "$DOTAG" = "y" ]; then
1322 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1323 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1325 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1329 if [ "$DOTAG" = "y" ]; then
1330 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1331 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1332 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1334 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1340 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1343 case "$MP2ENCODERSYNTAX" in
1345 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1348 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1353 # aac container is only used to catch faac encoded files where faac
1354 # is compiled without mp4 support (with libmp4v2).
1355 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1358 case "$AACENCODERSYNTAX" in
1360 if [ "$DOTAG" = "y" ]; then
1361 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1362 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1364 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1368 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1371 if [ "$DOTAG" = "y" ]; then
1372 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1373 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1375 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1379 if [ "$DOTAG" = "y" ]; then
1380 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1381 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1383 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1387 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1390 if [ "$DOTAG" = "y" ]; then
1391 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1392 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1393 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1395 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1401 # In case of wav output we need nothing. Just keep the wavs.
1402 # But we need the following to allow full logging and subsequent
1403 # successful cleaning of ${ABCDETEMPDIR}.
1404 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1409 # Only remove .wav if the encoding succeeded
1410 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1411 run_command encodetrack-$1 true
1412 if [ ! "$KEEPWAVS" = "y" ] ; then
1413 if [ ! "$KEEPWAVS" = "move" ] ; then
1419 run_command "" echo "HEH! The file we were about to encode disappeared:"
1420 run_command "" echo ">> $IN"
1421 run_command encodetrack-$1 false
1425 # do_preprocess [tracknumber]
1427 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1430 # IN="${ABCDETEMPDIR}/track$1.wav"
1431 # # We need IN to proceed.
1432 # if [ -s "$IN" ] ; then
1433 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1435 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1436 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1437 # case "$POSTPROCESSFORMAT" in
1439 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1441 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1443 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1445 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1447 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1450 # # Only remove .wav if the encoding succeeded
1451 # if checkerrors "preprocess-(.{3,4})-$1"; then
1452 # run_command preprocess-$1 false
1454 # run_command preprocess-$1 true
1457 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1458 # echo "HEH! The file we were about to pre-process disappeared:"
1461 # run_command preprocess-$1 false
1466 # do_postprocess [tracknumber]
1468 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1471 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1473 # IN="${ABCDETEMPDIR}/track$1.$POSTPROCESSFORMAT"
1474 # # We need IN to proceed.
1475 # if [ -s "$IN" ] ; then
1476 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1477 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1478 # case "$POSTPROCESSFORMAT" in
1480 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1482 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1484 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1486 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1488 # # Only remove .wav if the encoding succeeded
1489 # if checkerrors "postprocess-(.{3,4})-$1"; then
1490 # run_command postprocess-$1 false
1492 # run_command postprocess-$1 true
1495 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1496 # echo "HEH! The file we were about to post-process disappeared:"
1499 # run_command postprocess-$1 false
1514 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1518 # The commands here don't go through run_command because they're never supposed to be silenced
1519 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1521 cd "${ABCDETEMPDIR}"
1524 for UTRACKNUM in $TRACKQUEUE
1526 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1528 # FIXME # Hard-coded batch option!
1529 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1531 if [ "$RETURN" != "0" ]; then
1532 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1534 for UTRACKNUM in $TRACKQUEUE
1536 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1542 # do_batch_normalize
1544 # NORMALIZER, NORMALIZEROPTS
1545 do_batch_normalize ()
1547 # The commands here don't go through run_command because they're never supposed to be silenced
1548 echo "Batch normalizing tracks: $TRACKQUEUE"
1550 cd "${ABCDETEMPDIR}"
1553 for UTRACKNUM in $TRACKQUEUE
1555 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1557 # XXX: Hard-coded batch option!
1558 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1560 if [ "$RETURN" != "0" ]; then
1561 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1563 for UTRACKNUM in $TRACKQUEUE
1565 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1571 # do_normalize [tracknumber]
1573 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1576 IN="${ABCDETEMPDIR}/track$1.wav"
1577 if [ -e "$IN" ] ; then
1578 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1579 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1581 if [ "$(checkstatus encode-output)" = "loud" ]; then
1582 echo "HEH! The file we were about to normalize disappeared:"
1585 run_command normalizetrack-$1 false "File $IN was not found"
1589 # do_move [tracknumber]
1590 # Deduces the outfile from environment variables
1591 # Creates directory if necessary
1593 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1596 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1598 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1599 # defined the OUTPUTFILE:
1602 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1603 ALBUMFILE="$(mungealbumname "$DALBUM")"
1604 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1605 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1606 GENRE="$(mungegenre "$GENRE")"
1607 YEAR=${CDYEAR:-$CDYEAR}
1608 # If we want to start the tracks with a given number, we need to modify
1609 # the TRACKNUM value before evaluation
1611 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1612 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1613 if [ "$ONETRACK" = "y" ]; then
1614 if [ "$VARIOUSARTISTS" = "y" ]; then
1615 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1617 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1620 if [ "$VARIOUSARTISTS" = "y" ]; then
1621 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1623 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1626 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1627 # Once we know the specific output was successful, we can change
1628 # the OUTPUT to the value containing the container
1631 OUTPUT=$OGGOUTPUTCONTAINER
1634 OUTPUT=$OPUSOUTPUTCONTAINER
1637 OUTPUT=$MKAOUTPUTCONTAINER
1640 OUTPUT=$AIFFOUTPUTCONTAINER
1643 OUTPUT=$FLACOUTPUTCONTAINER
1649 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1650 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1653 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1654 # FIXME # introduce warnings?
1657 # mkdir -p shouldn't return an error if the directory already exists
1658 mkdir -p "$OUTPUTFILEDIR"
1659 run_command movetrack-$1 mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1660 if checkstatus movetrack-output-$OUTPUT; then :; else
1661 run_command movetrack-output-$OUTPUT true
1666 # mkdir -p shouldn't return an error if the directory already exists
1667 mkdir -p "$OUTPUTFILEDIR"
1668 run_command movetrack-$1 mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1669 if checkstatus movetrack-output-$OUTPUT; then :; else
1670 run_command movetrack-output-$OUTPUT true
1674 # Lets move the cue file
1675 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1676 if [ -r "${ABCDETEMPDIR}/$CUEFILE" ]; then
1677 if checkstatus movecue-$OUTPUT; then :; else
1678 # Silence the Copying output since it overlaps with encoding processes...
1679 #run_command '' vecho "Copying cue file to its destination directory..."
1680 if checkstatus onetrack >/dev/null ; then
1683 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1684 # We dont have the dir, since it was not created before.
1687 run_command movecue-$OUTPUT cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1690 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1691 # http://brianvictor.tripod.com/mp3cue.htm#details
1692 [a-z0-9][a-z0-9][a-z0-9])
1693 run_command movecue-$OUTPUT cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1696 run_command movecue-$OUTPUT cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1700 run_command movecue-$OUTPUT cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1702 echo movecue-$OUTPUT >> "${ABCDETEMPDIR}/status"
1711 # Create the playlist if wanted
1713 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1714 # VARIOUSARTISTS, OUTPUTDIR
1717 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1721 OUTPUT=$OGGOUTPUTCONTAINER
1724 OUTPUT=$OPUSOUTPUTCONTAINER
1727 OUTPUT=$MKAOUTPUTCONTAINER
1730 OUTPUT=$AIFFOUTPUTCONTAINER
1733 OUTPUT=$FLACOUTPUTCONTAINER
1739 # Create a playlist file for the playlist data to go into.
1740 # We used to wipe it out if it existed. Now we request permission if interactive.
1741 for LASTTRACK in $TRACKQUEUE; do :; done
1742 ALBUMFILE="$(mungealbumname "$DALBUM")"
1743 ARTISTFILE="$(mungeartistname "$DARTIST")"
1744 GENRE="$(mungegenre "$GENRE")"
1745 YEAR=${CDYEAR:-$CDYEAR}
1746 if [ "$VARIOUSARTISTS" = "y" ] ; then
1747 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1749 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1751 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1752 mkdir -p "$FINALPLAYLISTDIR"
1753 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1754 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1755 if [ "$INTERACTIVE" = "y" ]; then
1756 while [ "$DONE" != "y" ]; do
1758 case $ERASEPLAYLIST in
1759 e|E|a|A|k|K) DONE=y ;;
1760 "") ERASEPLAYLIST=e ; DONE=y ;;
1768 # Once we erase the playlist, we use append to create the new one.
1769 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1771 # The playlist does not exist, so we can safelly use append to create the new list
1774 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1775 touch "$OUTPUTDIR/$PLAYLISTFILE"
1776 for UTRACKNUM in $TRACKQUEUE
1778 # Shares some code with do_move since the filenames have to match
1779 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1780 getcddbinfo TRACKNAME
1782 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1783 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1784 ALBUMFILE="$(mungealbumname "$DALBUM")"
1785 # If we want to start the tracks with a given number, we need to modify the
1786 # TRACKNUM value before evaluation
1788 if [ "$VARIOUSARTISTS" = "y" ]; then
1789 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1791 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1793 if [ "$VARIOUSARTISTS" = "y" ]; then
1794 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1795 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1797 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1800 if [ "$PLAYLISTDATAPREFIX" ]; then
1801 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1803 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1808 ## this will convert the playlist to have CRLF line-endings, if specified
1809 ## (some hardware players insist on CRLF endings)
1810 if [ "$DOSPLAYLIST" = "y" ]; then
1811 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "${ABCDETEMPDIR}/PLAYLISTFILE.tmp"
1812 # mv -f "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1813 cat "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1815 echo "playlistcomplete" >> "${ABCDETEMPDIR}/status"
1820 # This function reads a cuefile on stdin and writes an extended
1821 # cddb query on stdout. Any PREGAP for track 1 is properly
1822 # handled, although cue files embedded in FLAC files do not
1823 # appear to properly store the PREGAP setting. :(
1824 abcde.cue2discid () {
1829 while [ $val -gt 0 ] ; do
1830 ret=$(( $ret + ( $val % 10) ))
1831 val=$(( $val / 10 ))
1841 local first second third
1842 first=$(expr ${1} + 0 )
1843 second=$(expr ${2} + 0 )
1844 third=$(expr ${3} + 0 )
1846 echo $(( ((($first * 60) + $second) * 75) + $third ))
1856 while read line ; do
1859 TRACK) i=$(( i + 1 ))
1861 INDEX) if [ "$2" -eq 1 ] ; then
1863 START=$(( $LBA + $PREGAP + $OFFSET ))
1865 X=$(cddb_sum $(( $START / 75 )) )
1869 PREGAP) PREGAP=$(msf2lba $2)
1873 LEADOUT=$(( $4 / 588 ))
1876 LEADIN=$(( $3 / 588 ))
1885 LEADOUT=$(( $LEADOUT + $LEADIN ))
1887 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1888 CDDBDISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1889 printf "%08x %i" $CDDBDISCID $TRACKS
1892 while [ $j -le $TRACKS ] ; do
1893 eval echo -n "\" \$TRACK$j\""
1896 echo " $(( $LEADOUT / 75 ))"
1900 # abcde.mkcue [--wholedisk]
1901 # This creates a cuefile directly from the extended discid information
1902 # The --wholedisk option controls whether we're ripping data from the
1903 # start of track one or from the start of the disk (usually, but not
1904 # always the same thing!)
1906 # Track one leadin/pregap (if any) handeling:
1907 # --wholedisk specified:
1910 # INDEX 01 <pregap value>
1911 # Remaining track index values unchanged from disc TOC
1913 # --wholedisk not specified
1915 # PREGAP <pregap value>
1917 # Remaining track index values offset by <pregap value>
1924 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1927 local MODE DISCID TRACKS
1931 if [ "$1" = --wholedisk ] ; then
1937 vecho "One track is $ONETRACK"
1938 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1939 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1940 ALBUMFILE="$(mungealbumname "$DALBUM")"
1941 if [ "$ONETRACK" = "y" ]; then
1942 if [ "$VARIOUSARTISTS" = "y" ]; then
1943 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1945 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1947 vecho "Cue wav file is $CUEWAVFILE"
1949 CUEWAVFILE="dummy.wav"
1952 set -- $CDDBTRACKINFO
1958 echo REM DISCID $DISCID
1959 echo FILE \""$CUEWAVFILE"\" WAVE
1961 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1968 while [ $i -le "$TRACKS" ] ; do
1969 LBA=$(( $1 - $OFFSET ))
1970 printf " TRACK %02i AUDIO\n" $i
1971 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1972 if [ $MODE = PREGAP ] ; then
1973 echomsf " PREGAP " $(($OFFSET-150))
1975 echo " INDEX 00 00:00:00"
1978 echomsf " INDEX 01 " $LBA
1985 # This is essentially the start of things
1988 if [ -z "$CDDBDISCID" ]; then
1989 vecho -n "Getting CD track info... "
1990 # In OSX, unmount the disc before a query
1991 if [ "$OSFLAVOUR" = "OSX" ]; then
1992 diskutil unmount ${CDROM#/dev/}
1994 case "$CDROMREADERSYNTAX" in
1996 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1997 case "$CUE2DISCID" in
1998 # FIXME # right now we have 2 cue2discid internal
1999 # implementations: builtin and abcde.cue2discid. Test
2000 # both of them and decide which one we want to use.
2002 #vecho "Using builtin cue2discid implementation..."
2003 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2005 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2007 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2008 TRACKS=${#OFFSETTIMES[@]}
2010 #echo "processing offsetimes ${OFFSETTIMES[@]}"
2011 for OFFSETTIME in ${OFFSETTIMES[@]}; do
2012 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2013 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
2016 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2017 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2021 #vecho "Using external python cue2discid implementation..."
2022 CDDBTRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2026 log error "the input flac file does not contain a cuesheet."
2031 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2033 if [ ! "$RET" = "0" ];then
2034 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2037 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2038 CDPARANOIAAUDIOTRACKS="$TRACKS"
2040 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2041 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2045 # Calculate the cddb discid in all
2046 # cases now. We'll use the cddb discid
2047 # for reference in most cases for
2048 # consistency. Also calculate the
2049 # musicbrainz discid if we need it.
2050 CDDBTRACKINFO=$($CDDISCID "$CDROM")
2051 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2054 MBTRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM")
2055 MBDISCID=$(echo $MBTRACKINFO | cut -d' ' -f1)
2059 # Make sure there's a CD in there by checking cd-discid's return code
2060 if [ ! "$?" = "0" ]; then
2061 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2062 log error "cuesheet information from the flac file could not be read."
2063 log error "Perhaps the flac file does not contain a cuesheet?."
2066 log error "CD could not be read. Perhaps there's no CD in the drive?"
2070 # In OSX, remount the disc again
2071 if [ "$OSFLAVOUR" = "OSX" ]; then
2072 diskutil mount ${CDROM#/dev/}
2075 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -f1 -d' ')
2077 CDDBTRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$CDDBDISCID/cddbdiscid")
2080 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2081 # This needs to be done now because a section of the resuming code will need
2084 # get the number of digits to pad TRACKNUM with - we'll use this later
2085 # a CD can only hold 99 tracks, but since we support a feature for starting
2086 # numbering the tracks from a given number, we might need to set it as a
2087 # variable for the user to define... or obtain it somehow.
2088 if [ "$PADTRACKS" = "y" ] ; then
2092 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $CDDBTRACKINFO | cut -f1 -d' ')"
2093 if [ -z "$TRACKQUEUE" ]; then
2094 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2095 case "$CDROMREADERSYNTAX" in
2096 cdparanoia|libcdio|debug)
2097 if [ "$WEHAVEACD" = "y" ]; then
2098 vecho "Querying the CD for audio tracks..."
2099 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2101 if [ ! "$RET" = "0" ];then
2102 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2104 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2105 CDPARANOIAAUDIOTRACKS="$TRACKS"
2107 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2108 if [ -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks" ]; then
2109 echo cdparanoia-audio-tracks=$( cat "${ABCDETEMPDIR}/cdparanoia-audio-tracks" ) >> "${ABCDETEMPDIR}/status"
2110 rm -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks"
2112 if [ -f "${ABCDETEMPDIR}/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2113 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2117 *) TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ') ;;
2120 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2122 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2123 log info "The disc does not contain any tracks. Giving up..."
2126 echo -n "Grabbing entire CD - tracks: "
2127 if [ ! "$PADTRACKS" = "y" ] ; then
2128 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2130 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2132 while [ "$X" -ne "$TRACKS" ]
2134 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2135 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2139 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2140 # User-supplied track queue.
2141 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2142 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2143 # Once cleaned, obtain the highest value in the trackqueue for number padding
2144 for LASTTRACK in $TRACKQUEUE; do :; done
2145 if [ ! "$PADTRACKS" = "y" ] ; then
2146 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2148 # Now we normalize the trackqueue
2149 for TRACK in $TRACKQUEUE ; do
2150 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2151 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2153 TRACKQUEUE=$PADTRACKQUEUE
2154 echo Grabbing tracks: "$TRACKQUEUE"
2157 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2159 # We have the discid, create a temp directory after it to store all the temp
2162 if [ -e "${ABCDETEMPDIR}" ]; then
2163 echo -n "abcde: attempting to resume from ${ABCDETEMPDIR}"
2164 # It already exists, see if it's a directory
2165 if [ ! -d "${ABCDETEMPDIR}" ]; then
2166 # This is a file/socket/fifo/device/etc, not a directory
2169 echo "abcde: file ${ABCDETEMPDIR} already exists and does not belong to abcde." >&2
2170 echo "Please investigate, remove it, and rerun abcde." >&2
2174 # It's a directory, let's see if it's writable by us
2175 if [ ! -r "${ABCDETEMPDIR}" ] || [ ! -w "${ABCDETEMPDIR}" ] || [ ! -x "${ABCDETEMPDIR}" ]; then
2176 # Nope, complain and exit
2178 echo "abcde: directory ${ABCDETEMPDIR} already exists and is not writeable." >&2
2179 echo "Please investigate, remove it, and rerun abcde." >&2
2183 # See if it's populated
2184 if [ ! -f "${ABCDETEMPDIR}/cddbdiscid" ]; then
2185 # Wipe and start fresh
2186 echo "abcde: ${ABCDETEMPDIR}/cddbdiscid not found. Abcde must remove and recreate" >&2
2187 echo -n "this directory to continue. Continue [y/N]? " >&2
2188 if [ "$INTERACTIVE" = "y" ]; then
2194 if [ "$ANSWER" != "y" ]; then
2197 rm -rf "${ABCDETEMPDIR}" || exit 1
2198 mkdir -p "${ABCDETEMPDIR}"
2199 if [ "$?" -gt "0" ]; then
2200 # Directory already exists or could not be created
2201 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2205 # Everything is fine. Check for ^encodetracklocation-
2206 # and encode-output entries in the status file and
2207 # remove them. These are not relevant across sessions.
2208 if [ -f "${ABCDETEMPDIR}/status" ]; then
2209 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
2210 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
2211 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
2213 # Remove old error messages
2214 if [ -f "${ABCDETEMPDIR}/errors" ]; then
2215 rm -f "${ABCDETEMPDIR}/errors"
2219 # We are starting from scratch
2220 mkdir -p "${ABCDETEMPDIR}"
2221 if [ "$?" -gt "0" ]; then
2222 # Directory already exists or could not be created
2223 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2226 cat /dev/null > "${ABCDETEMPDIR}/status"
2227 # Store the abcde version in the status file.
2228 echo "abcde-version=$VERSION" >> "${ABCDETEMPDIR}/status"
2230 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2231 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2232 CUEFILE=cue-$(echo "$CDDBTRACKINFO" | cut -f1 -d' ').txt
2233 vecho "Creating cue file..."
2234 case $CDROMREADERSYNTAX in
2236 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "${ABCDETEMPDIR}/$CUEFILE"; then
2237 echo cuefile=$CUEFILE >> "${ABCDETEMPDIR}/status"
2239 log warning "the input flac file does not contain a cuesheet."
2243 if $CUEREADER $CUEREADEROPTS > "${ABCDETEMPDIR}/$CUEFILE"; then
2244 echo cuefile=$CUEFILE >> "${ABCDETEMPDIR}/status"
2246 log warning "reading the CUE sheet is still considered experimental"
2247 log warning "and there was a problem with the CD reading. abcde will continue,"
2248 log warning "but consider reporting the problem to the abcde author"
2254 # If we got the CDPARANOIA status and it is not recorded, save it now
2255 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2256 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2257 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "${ABCDETEMPDIR}/status"
2261 # Create the discid files
2262 echo "$CDDBTRACKINFO" > "${ABCDETEMPDIR}/cddbdiscid"
2265 echo "$MBTRACKINFO" > "${ABCDETEMPDIR}/mbdiscid"
2271 # Create a proper CUE file based on the CUE file we created before.
2274 if CUEFILE_IN="${ABCDETEMPDIR}"/$(checkstatus cuefile); then
2275 CUEFILE_OUT=$CUEFILE_IN.out
2276 ### FIXME ### checkstatus cddb
2277 if [ -e "$CDDBDATA" ]; then
2278 vecho "Adding metadata to the cue file..."
2279 # FIXME It doesn't preserve spaces! Why?
2280 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2282 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2283 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2284 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2288 cat "$CUEFILE_IN" | while read line
2290 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2291 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2292 # echo "$line" >> "$CUEFILE_OUT"
2293 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2294 eval track="\$TRACK$n"
2296 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2297 # When making a single-track rip, put the
2298 # actual file name into the file declaration
2299 # in the cue file so that it is usable by
2300 # music players and the like
2301 elif [ "$ONETRACK" = "y" ] &&
2302 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2304 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2305 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2306 ALBUMFILE="$(mungealbumname "$DALBUM")"
2308 if [ "$VARIOUSARTISTS" = "y" ]; then
2309 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2311 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2314 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2317 # FIXME # If the lines above are uncommented, remove the line below.
2318 echo "$line" >> "$CUEFILE_OUT"
2321 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2322 echo "cleancuefile" >> "${ABCDETEMPDIR}/status"
2328 # Parses a CDDB file and outputs the title and the track names.
2329 # Variables: CDDBFILE
2333 # List out disc title/author and contents
2334 if [ "$ONETRACK" = "y" ]; then
2335 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2337 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2338 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2339 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2340 if [ ! X"$PARSEDYEAR" = "X" ]; then
2341 echo "Year: $PARSEDYEAR"
2344 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2345 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2346 if [ ! X"$PARSEDGENRE" = "X" ]; then
2347 echo "Genre: $PARSEDGENRE"
2350 if [ ! "$ONETRACK" = "y" ]; then
2351 for TRACK in $(f_seq_row 1 $TRACKS)
2353 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2359 # Check for a local CDDB file, and report success
2360 do_localcddb_read ()
2362 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2364 CDDBLOCALSTATUS="notfound"
2365 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2368 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2369 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2370 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2371 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2372 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2373 CDDBLOCALMATCH=single
2374 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2375 CDDBLOCALMATCH=multiple
2380 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2381 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2382 CDDBLOCALMATCH=single
2387 # If the user has selected to check a local CDDB repo, we proceed with it
2388 case $CDDBLOCALMATCH in
2390 echo "Processing multiple matching CDDB entries..." > "${ABCDETEMPDIR}/cddblocalchoices"
2392 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2394 # List out disc title/author and contents
2395 CDDBLOCALREAD="${ABCDETEMPDIR}/cddblocalread.$X"
2396 cat "$RESULT" > "${CDDBLOCALREAD}"
2399 do_cddbparse "${CDDBLOCALREAD}"
2401 ##FIXME## QUICK HACK !!!!
2402 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2403 } >> "${ABCDETEMPDIR}/cddblocalchoices"
2405 if [ $(cat "${ABCDETEMPDIR}/cddblocalchoices" | wc -l) -ge $LINES ] && [ "$INTERACTIVE" = "y" ]; then
2406 page "${ABCDETEMPDIR}/cddblocalchoices"
2408 # It's all going to fit in one page, cat it
2409 cat "${ABCDETEMPDIR}/cddblocalchoices" >&2
2411 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2412 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2413 CDDBLOCALCHOICENUM=-1
2414 if [ "$INTERACTIVE" = "y" ]; then
2415 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2416 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2417 read CDDBLOCALCHOICE
2418 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2419 # FIXME # Introduce diff's
2420 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2421 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2422 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2423 # Make sure we get a valid choice
2424 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2425 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2426 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2432 #echo "Selected ..."
2434 CDDBLOCALCHOICENUM=1
2436 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2437 #echo "Using local copy of CDDB data"
2438 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2439 cat "${ABCDETEMPDIR}/cddblocalread.$CDDBLOCALCHOICENUM" >> "${ABCDETEMPDIR}/cddbread.1"
2440 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2441 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2442 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2443 do_cddbparse "${ABCDETEMPDIR}/cddbread.1" > "${ABCDETEMPDIR}/cddbchoices"
2444 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2445 CDDBLOCALSTATUS="found"
2447 #echo "Not using local copy of CDDB data"
2448 CDDBLOCALSTATUS="notfound"
2452 # List out disc title/author and contents
2453 do_cddbparse "${CDDBLOCALFILE}"
2454 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2455 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2457 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2459 if [ "$INTERACTIVE" = "y" ]; then
2461 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2462 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2465 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2469 if [ "$USELOCALRESP" = "y" ]; then
2470 #echo "Using local copy of CDDB data"
2471 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2472 cat "${CDDBLOCALFILE}" >> "${ABCDETEMPDIR}/cddbread.1"
2473 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2474 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2475 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2476 do_cddbparse "${CDDBLOCALFILE}" > "${ABCDETEMPDIR}/cddbchoices"
2477 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2478 CDDBLOCALSTATUS="single"
2480 #echo "Not using local copy of CDDB data"
2481 CDDBLOCALSTATUS="notfound"
2485 CDDBLOCALSTATUS="notfound"
2492 # Try to read CD-Text from the drive using icedax / cdda2wav
2495 if new_checkexec icedax; then
2496 CDTEXT_READER=icedax
2497 elif new_checkexec cdda2wav; then
2498 CDTEXT_READER=cdda2wav
2500 # Didn't find either, bail
2504 vecho "Obtaining CD-Text results..."
2505 CDTDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2506 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cdtext"
2507 mkdir -p "${SOURCE_WORKDIR}"
2509 if [ "$OSFLAVOUR" = "OSX" ] ; then
2510 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2511 diskutil unmount ${CDROM#/dev/}
2512 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2513 CDDA2WAVCDROM="IODVDServices"
2514 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2515 CDDA2WAVCDROM="$CDROMID"
2517 if [ "$CDROMID" = "" ]; then
2518 CDDA2WAVCDROM="$CDROM"
2520 CDDA2WAVCDROM="$CDROMID"
2524 # Do we have CD-Text on the disc (and can the drive read it?)
2526 cd "${SOURCE_WORKDIR}" && rm -f audio.* audio_*
2527 ${CDTEXT_READER} -J -v titles -D ${CDDA2WAVCDROM} > "${SOURCE_WORKDIR}/cd-text" 2>&1
2529 grep -a -q '^CD-Text: detected' "${SOURCE_WORKDIR}/cd-text"
2531 if [ $ERRORCODE -ne 0 ]; then
2532 # No CD-Text found, bail
2536 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2537 # Make an empty template
2538 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2539 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2540 rm -f "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2542 # XXX FIXME - this is a hack and should be replaced by proper
2543 # character set tracking for the CDDB data we have.
2544 if test "$CDDBPROTO" -ge 6 ; then
2545 # convert to Unicode
2546 iconv -f iso-8859-1 -t utf-8 <"${SOURCE_WORKDIR}/audio.cddb" >"${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2548 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2549 # apparently icedax/cdda2wav have no support for 16-bit
2550 # characters yet, either
2551 cp -p "${SOURCE_WORKDIR}/audio.cddb" "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2554 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2555 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2556 echo "CD-Text" > ${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}
2557 echo "none $CDDBDISCID ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2559 ( cd "${SOURCE_WORKDIR}" && rm -f audio_* audio.* )
2560 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2561 if [ -f $file ]; then
2562 cp $file "${ABCDETEMPDIR}"
2565 echo "cdtext-readcomplete" >> "${ABCDETEMPDIR}/status"
2568 # do_musicbrainz_read
2569 # Work with the musicbrainz WS API, then transform the results here so
2570 # they look (very) like the results from CDDB. Maybe not the best way
2571 # to go, but it Works For Me (TM)
2573 # List out all the matches individually into $SOURCE_WORKDIR/cddbread.X
2575 do_musicbrainz_read ()
2577 if checkstatus musicbrainz-readcomplete; then :; else
2578 vecho "Obtaining Musicbrainz results..."
2579 # If MB is to be used, interpret the query results and read all
2580 # the available entries.
2581 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2582 MBDISCID=$(echo $MBTRACKINFO | cut -d' ' -f1)
2583 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-musicbrainz"
2584 mkdir -p "${SOURCE_WORKDIR}"
2585 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "${SOURCE_WORKDIR}" --start ${NUM_CDDB_MATCHES}
2587 # Check for no matches.
2588 # The helper script will write disc matches out to
2589 # cddbread.*. Count how many we have
2590 NUM_RESPONSES=$(echo "${SOURCE_WORKDIR}"/cddbread.* | wc -w)
2591 if [ "$NUM_RESPONSES" -gt 0 ] ; then
2592 # One or more exact matches
2594 while [ $i -le $NUM_RESPONSES ]; do
2595 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2597 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2598 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2599 echo "none $CDDBDISCID ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2600 echo "Musicbrainz" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2601 cp -f "${SOURCE_WORKDIR}/"*."${NUM_CDDB_MATCHES}" "${ABCDETEMPDIR}"
2604 echo "musicbrainz-readcomplete" >> "${ABCDETEMPDIR}/status"
2611 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cddb"
2612 mkdir -p "${SOURCE_WORKDIR}"
2618 # Perform CDDB protocol version check if it hasn't already been done
2619 if checkstatus cddb-statcomplete; then :; else
2620 if [ "$CDDBAVAIL" = "n" ]; then
2622 echo 503 > "${SOURCE_WORKDIR}/cddbstat"
2625 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2626 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2627 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2628 vecho "Checking CDDB server status..."
2629 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "${SOURCE_WORKDIR}/cddbstat"
2630 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2631 case "$RESPONSECODE" in
2632 210) # 210 OK, status information follows (until terminating `.')
2635 501) # 501 Illegal CDDB protocol level: <n>.
2636 CDDBPROTO=`expr $CDDBPROTO - 1`
2638 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2639 # FreeDB TESTCD disc-id is used for query
2640 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "${SOURCE_WORKDIR}/cddbstat"
2641 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2642 case "$RESPONSECODE" in
2643 2??) # Server responded, everything seems OK
2653 if test $rc -eq 1; then
2657 echo cddb-statcomplete >> "${ABCDETEMPDIR}/status"
2664 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2665 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2667 # Perform CDDB query if it hasn't already been done
2668 if checkstatus cddb-querycomplete; then :; else
2669 if [ "$CDDBAVAIL" = "n" ]; then
2671 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2672 # The default CDDBLOCALSTATUS is "notfound"
2673 # This part will be triggered if the user CDDB repo does not
2674 # contain the entry, or if we are not trying to use the repo.
2676 vecho "Querying the CDDB server..."
2677 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2678 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2679 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $CDDBTRACKINFO > "${SOURCE_WORKDIR}/cddbquery"
2685 # no match found in database, wget/fetch error,
2686 # or user requested not to use CDDB. Make up an
2687 # error code (503) that abcde will recognize later
2688 # and compensate by making a template
2689 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2691 *) # strange and unknown error
2692 echo ERRORCODE=$ERRORCODE
2693 echo "abcde: $CDDBTOOL returned unknown error code"
2697 echo cddb-querycomplete >> "${ABCDETEMPDIR}/status"
2704 # If it's not to be used, generate a template.
2705 # Then, display it (or them) and let the user choose/edit it
2706 if checkstatus cddb-readcomplete; then :; else
2707 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbquery" | cut -f1 -d' ')
2708 vecho "Obtaining CDDB results..."
2709 case "$RESPONSECODE" in
2711 # One exact match, retrieve it
2712 # 200 [section] [discid] [artist] / [title]
2713 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2714 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2715 cat ${SOURCE_WORKDIR}/cddbquery | cut -f2- -d' ' > ${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}
2716 echo "cddb" > ${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}
2717 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2719 202|403|409|500|503)
2720 # TODO: Explain these error codes a little more accurately:
2721 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2722 # No match response:
2725 # Multiple exact, (possibly multiple) inexact matches
2726 vecho -n "Retrieving multiple matches... "
2727 grep -v ^[.]$ "${SOURCE_WORKDIR}/cddbquery" | (
2728 # IN A SUB-SHELL - VARIABLES MODIFIED
2729 # HERE DO NOT PERSIST IN THE PARENT
2730 read DISCINFO # eat top line
2733 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2734 if checkstatus cddb-read-${NUM_CDDB_MATCHES}-complete; then :; else
2735 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2736 echo "$DISCINFO" > ${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}
2737 echo "cddb" > ${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}
2738 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2741 # Need to re-count the entries here to be able
2742 # to incrememnt $NUM_CDDB_MATCHES in the
2744 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $(echo ${SOURCE_WORKDIR}/datasource.* | wc -w)))
2749 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2750 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2753 echo "cddb-readcomplete" >> "${ABCDETEMPDIR}/status"
2754 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2755 if [ -f $file ]; then
2756 cp $file "${ABCDETEMPDIR}"
2765 if checkstatus cddb-edit >/dev/null; then
2766 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2767 VARIOUSARTISTS="$(checkstatus variousartists)"
2768 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2771 if [ "$INTERACTIVE" = "y" ]; then
2772 # We should show the CDDB results both when we are not using the local CDDB repo
2773 # or when we are using it but we could not find a proper match
2774 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2775 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2776 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2777 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2778 CHOICE=$(checkstatus cddb-choice)
2779 if [ -n "$CHOICE" ] ; then
2780 case $NUM_CDDB_MATCHES in
2781 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2783 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CHOICE" | cut -f2- -d= | tr -d \\r\\n)
2784 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CHOICE")
2785 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)"
2786 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2790 # The user has a choice to make, display the info in a pager if necessary
2791 if [ $(cat "${ABCDETEMPDIR}/cddbchoices" | wc -l) -ge $LINES ]; then
2792 page "${ABCDETEMPDIR}/cddbchoices"
2794 # It's all going to fit in one page, cat it
2795 cat "${ABCDETEMPDIR}/cddbchoices" >&2
2799 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2801 # I'll take CDDB read #3 for $400, Alex
2802 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; do
2803 echo -n "Which entry would you like abcde to use (0 for none)? [0-$NUM_CDDB_MATCHES]: " >&2
2805 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2806 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2807 if [ ! X"$DIFF" = "X" ]; then
2808 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2809 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2810 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $NUM_CDDB_MATCHES ] || \
2811 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $NUM_CDDB_MATCHES ] || \
2812 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2813 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
2815 # We parse the 2 choices to diff, store them in temporary files and diff them.
2816 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2817 do_cddbparse "${ABCDETEMPDIR}/cddbread.$PARSECHOICE" > "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE"
2819 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "${ABCDETEMPDIR}/cddbread.diff"
2820 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE1" "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/cddbread.diff"
2821 if [ $(cat "${ABCDETEMPDIR}/cddbread.diff" | wc -l) -ge $LINES ]; then
2822 page "${ABCDETEMPDIR}/cddbread.diff"
2824 cat "${ABCDETEMPDIR}/cddbread.diff" >&2
2828 echo "The diff program was not found in your path. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2830 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2831 # Make sure we get a valid choice
2832 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2833 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; then
2834 echo "Invalid selection. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2838 if [ "$CDCHOICENUM" = "0" ]; then
2839 vecho "Creating empty CDDB template..."
2841 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
2843 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n)
2844 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CDCHOICENUM")
2845 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)" >&2
2846 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM"
2848 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2852 # We need some code to show the selected option when local repository is selected and we have found a match
2853 vecho "Using cached CDDB match..." >&2
2854 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2855 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2856 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2857 CHOICE=$(checkstatus cddb-choice)
2858 if [ "$USELOCALRESP" = "y" ]; then :; else
2859 if [ -n "$CHOICE" ] ; then
2860 case $NUM_CDDB_MATCHES in
2863 echo "Selected template."
2865 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2867 echo "Selected: #$CHOICE"
2868 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2876 # We're noninteractive - pick the first choice.
2877 # But in case we run a previous instance and selected a choice, use it.
2878 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2879 # Show the choice if we are not using the locally stored one
2880 # or when the local search failed to find a match.
2881 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2882 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2883 #if [ "$PREVIOUSCHOICE" ]; then
2884 cat "${ABCDETEMPDIR}/cddbchoices"
2887 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2888 CDCHOICENUM=$PREVIOUSCHOICE
2891 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2893 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2898 if checkstatus cddb-choice >/dev/null; then :; else
2899 echo "abcde: internal error: cddb-choice not recorded." >&2
2902 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2903 CDDBSOURCE=$(cat "${ABCDETEMPDIR}/datasource.$(checkstatus cddb-choice)")
2904 echo -n "Edit selected CDDB data " >&2
2905 if [ "$INTERACTIVE" = "y" ]; then
2906 if [ "$UNKNOWNDISK" = "y" ]; then
2907 echo -n "[Y/n]? " >&2
2909 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2911 echo -n "[y/N]? " >&2
2918 if [ "$EDITCDDB" = "y" ]; then
2919 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2921 # Use the debian sensible-editor wrapper to pick the editor that the
2922 # user has requested via their $EDITOR environment variable
2923 if [ -x "/usr/bin/sensible-editor" ]; then
2924 /usr/bin/sensible-editor "$CDDBDATA"
2925 elif [ -n "$EDITOR" ]; then
2926 if [ -x $(which "${EDITOR%%\ *}") ]; then
2927 # That failed, try to load the preferred editor, starting
2928 # with their EDITOR variable
2929 eval $(echo "$EDITOR") \"$CDDBDATA\"
2931 # If that fails, check for a vi
2932 elif which vi >/dev/null 2>&1; then
2934 elif [ -x /usr/bin/vim ]; then
2935 /usr/bin/vim "$CDDBDATA"
2936 elif [ -x /usr/bin/vi ]; then
2937 /usr/bin/vi "$CDDBDATA"
2938 elif [ -x /bin/vi ]; then
2940 # nano should be on all (modern, i.e., sarge) debian systems
2941 elif which nano >/dev/null 2>&1 ; then
2943 elif [ -x /usr/bin/nano ]; then
2944 /usr/bin/nano "$CDDBDATA"
2945 # mg should be on all OpenBSD systems
2946 elif which mg >/dev/null 2>&1 ; then
2948 elif [ -x /usr/bin/mg ]; then
2949 /usr/bin/mg "$CDDBDATA"
2952 log warning "no editor available. Check your EDITOR environment variable."
2954 # delete editor backup file if it exists
2955 if [ -w "$CDDBDATA~" ]; then
2960 # Some heuristics first. Look at Disc Title, and if it starts with
2961 # "Various", then we'll assume Various Artists
2962 if [ "$(grep -a ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -aEci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2963 echo "Looks like a Multi-Artist CD" >&2
2966 echo -n "Is the CD multi-artist [y/N]? " >&2
2967 if [ "$INTERACTIVE" = "y" ]; then
2974 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2977 # Need NUMTRACKS before cddb-tool will return it:
2978 NUMTRACKS=$(grep -a -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2979 if [ "$(grep -ac "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2980 # More than 1/2 tracks contain a "/", so guess forward
2982 elif [ "$(grep -ac "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2983 # More than 1/2 contain a "-", so guess forward-dash
2985 elif [ "$(grep -ac "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2986 # More than 1/2 contain something in parens, so guess trailing-paren
2990 echo "1) Artist / Title" >&2
2991 echo "2) Artist - Title" >&2
2992 echo "3) Title / Artist" >&2
2993 echo "4) Title - Artist" >&2
2994 echo "5) Artist: Title" >&2
2995 echo "6) Title (Artist)" >&2
2996 echo "7) This is a single-artist CD" >&2
2997 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2998 if [ "$INTERACTIVE" = "y" ]; then
2999 read VARIOUSARTISTSTYLE
3001 echo $DEFAULTSTYLE >&2
3002 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3004 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3005 # If they press Enter, then the default style (0) was chosen
3006 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
3007 echo "Invalid selection. Please choose a number between 1 and 7."
3008 echo -n "Selection [1-7]: "
3009 read VARIOUSARTISTSTYLE
3010 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3012 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3013 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3015 vecho "Selected: $VARIOUSARTISTSTYLE"
3016 case "$VARIOUSARTISTSTYLE" in
3018 VARIOUSARTISTSTYLE=forward
3021 VARIOUSARTISTSTYLE=forward-dash
3024 VARIOUSARTISTSTYLE=reverse
3027 VARIOUSARTISTSTYLE=reverse-dash
3030 VARIOUSARTISTSTYLE=colon
3033 VARIOUSARTISTSTYLE=trailing-paren
3041 echo "variousartists=$VARIOUSARTISTS" >> "${ABCDETEMPDIR}/status"
3042 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "${ABCDETEMPDIR}/status"
3044 if [ "$EDITCDDB" = "y" ] && [ "$CDDBSOURCE" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3045 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3046 # This works but does not have the necessary error checking
3047 # yet. If you are familiar with the CDDB spec
3048 # (see http://www.freedb.org/src/latest/DBFORMAT)
3049 # and can create an error-free entry on your own, then put
3050 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3051 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3052 # your abcde.conf to change the email address submissions are
3055 # submit the modified file, if they want
3056 if [ "$NOSUBMIT" != "y" ]; then
3057 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3059 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3060 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3062 echo -n 'Invalid selection. Please answer "y" or "n": '
3065 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3066 echo -n "Sending..."
3067 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
3074 # User CDDBLOCALPOLICY to find out if we store the file or not...
3075 # Cache edited CDDB entry in the user's cddb dir
3076 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3077 # Make sure the cache directory exists
3078 mkdir -p $CDDBLOCALDIR
3079 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
3082 echo "cddb-edit" >> "${ABCDETEMPDIR}/status"
3086 # try to download CD cover
3090 ALBUMFILE="$(mungealbumname "$DALBUM")"
3091 ARTISTFILE="$(mungeartistname "$DARTIST")"
3092 GENRE="$(mungegenre "$GENRE")"
3093 YEAR=${CDYEAR:-$CDYEAR}
3094 # have we got a musicbrainz mbid or amazon asin?
3095 case "$CDDBMETHOD" in
3097 # try musicbrainz mbid
3098 if [ -s "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)" ]; then
3099 MBID=$(cat "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)")
3100 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3101 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3102 vecho "cover URL: $ALBUMARTURL" >&2
3103 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3104 if [ $? -ne 0 ]; then
3105 vecho "could not download cover from musicbrainz" >&2
3107 if [ -s "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)" ]; then
3108 ASIN=$(cat "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)")
3109 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3110 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3111 vecho "cover URL: $ALBUMARTURL" >&2
3112 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3113 if [ $? -ne 0 ]; then
3114 vecho "could not download cover from amazon" >&2
3116 # Check that size is reasonable; sometimes when there is no cover image
3117 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3118 FILESIZE=$(wc -c < "${ABCDETEMPDIR}/$ALBUMARTFILE")
3119 if [ "$FILESIZE" -lt 1024 ]; then
3120 rm "${ABCDETEMPDIR}/$ALBUMARTFILE"
3121 vecho "could not download cover from amazon" >&2
3125 vecho "no amazon ID found" >&2
3129 vecho "no musicbrainz ID found" >&2
3134 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3135 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3136 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "${ABCDETEMPDIR}/$ALBUMARTFILE" $GLYRCOPTS
3137 if [ $? -ne 0 ]; then
3138 vecho "could not download cover with glyrc" >&2
3143 if [ "$INTERACTIVE" = "y" ]; then
3144 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3145 # display properties of coverart when identify is available
3146 if new_checkexec $IDENTIFY; then
3147 $IDENTIFY $IDENTIFYOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3149 # display coverart when DISPLAY is set and display command is available
3150 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3151 $DISPLAYCMD $DISPLAYCMDOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2 &
3154 # nothing downloaded yet
3155 vecho "automatic album art downloading failed" >&2
3157 # see if the user can find a better album art manually
3158 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3160 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3161 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3163 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3166 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3167 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3169 if [ ! -z "$ALBUMARTURL" ]; then
3170 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3171 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3172 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3173 vecho "unable to download $ALBUMARTURL" >&2
3175 else # it's a local path
3176 cp "$ALBUMARTURL" "${ABCDETEMPDIR}/$ALBUMARTFILE"
3177 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3178 vecho "unable to copy $ALBUMARTURL to ${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3184 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3185 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3186 ALBUMARTURLTYPE=$($IDENTIFY "${ABCDETEMPDIR}/$ALBUMARTFILE" | cut -d' ' -f2)
3187 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3188 if new_checkexec $CONVERT; then
3189 mv "${ABCDETEMPDIR}/$ALBUMARTFILE" "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3190 $CONVERT "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp" $CONVERTOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE"
3191 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3193 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3194 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3198 # copy to target directories
3199 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3200 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3202 # put cover in the same place as the album
3203 if [ "$ONETRACK" = "y" ] ; then
3204 if [ "$VARIOUSARTISTS" = "y" ] ; then
3205 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3207 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3210 if [ "$VARIOUSARTISTS" = "y" ] ; then
3211 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3213 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3216 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3217 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3218 mkdir -p "$FINALALBUMARTDIR"
3219 cp "${ABCDETEMPDIR}/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3221 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3222 echo "get-album-art=$ALBUMARTURL" >> "${ABCDETEMPDIR}/status"
3224 log warning "could not get cover"
3225 echo "get-album-art=none" >> "${ABCDETEMPDIR}/status"
3229 # Optionally embed the albumart downloaded by the getalbumart fuction.
3230 # FIXME: It would be nice to have this also selectable from within the
3231 # FIXME: getalbumart function itself. Andrew
3235 ALBUMFILE="$(mungealbumname "$DALBUM")"
3236 ARTISTFILE="$(mungeartistname "$DARTIST")"
3237 GENRE="$(mungegenre "$GENRE")"
3238 YEAR=${CDYEAR:-$CDYEAR}
3240 # Allow for multiple output formats:
3241 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3243 # Find the output directory for multi track encodes:
3244 if [ "$ONETRACK" != "y" ] ; then
3245 if [ "$VARIOUSARTISTS" = "y" ] ; then
3246 FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
3248 FINDPATH="$(eval echo "$OUTPUTFORMAT")"
3251 # Find the output directory for single track encodes:
3252 if [ "$ONETRACK" = "y" ] ; then
3253 if [ "$VARIOUSARTISTS" = "y" ] ; then
3254 FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3256 FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3260 FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
3263 # Instructions for each format, feel free to add more. It would be nice to
3264 # make the backup directory selectable and perhaps also have an option for
3265 # the bold to simply have the image deleted. Work for another day... Andrew.
3266 if [ -e "$ALBUMARTFILE" ] ; then
3271 "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$i"
3273 mkdir "$FINALDIR"/albumart_backup
3274 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3275 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3280 "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
3282 mkdir "$FINALDIR"/albumart_backup
3283 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3284 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3289 "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
3291 mkdir "$FINALDIR"/albumart_backup
3292 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3293 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3298 "$WVTAG" --write-binary-tag "Cover Art (Front)=@"$ALBUMARTFILE"" "$i"
3300 mkdir "$FINALDIR"/albumart_backup
3301 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3302 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3306 # This technique is drawn from 2 sources (the first link being the primary source):
3307 # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
3308 # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
3309 # In abcde a few steps are used in this sequence:
3311 # 1. Create a 'legal' header for the cover art image
3312 # 2. Makes a copy of the existing tags
3313 # 3. base64 the cover art image
3314 # 4. Copy the original tags + the base64 image back to the original ogg file
3316 # Might need some fine tuning but it is a start for abcde 2.8.2 Andrew.
3317 # FIXME: I am not sure if there is a maximum size for images converted in this
3318 # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
3320 # First some variables we can reuse:
3321 # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
3322 MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
3323 EXPORTTAGS="${ABCDETEMPDIR}/export_ogg_tags"
3324 BUILDHEADER="${ABCDETEMPDIR}/build_header"
3325 # Now build the header, gory details are here:
3326 # https://xiph.org/flac/format.html#metadata_block_picture
3328 printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
3330 printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3332 echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
3333 # Description length. FIXME: I have used 'Cover Image' but I am not sure
3334 # if this is better left as an empty field. Andrew
3335 printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3337 echo -n "Cover Image" >> "$BUILDHEADER"
3339 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3341 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3342 # Picture color depth:
3343 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3344 # Picture color count:
3345 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3347 printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
3348 # cat the image file:
3349 cat "$ALBUMARTFILE" >> "$BUILDHEADER"
3350 # Now process each ogg file by first exporting the original tags then
3351 # appending the cover image and finally copying the whole thing back
3352 # to the original image:
3355 # Make a backup of the existing tags:
3356 "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
3357 # base64 the file and then mix it all together with the exported tags:
3358 echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
3359 # Update the original ogg file with exported tags and the appended base64'd image:
3360 "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
3361 # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
3362 # note that the header file BUILDHEADER will be reused for each file in the loop:
3365 mkdir "$FINALDIR"/albumart_backup
3366 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3367 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3369 *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
3372 vecho "Suitable cover image not found, no embedding done..." >&2
3377 # do_cdread [tracknumber]
3378 # do_cdread onetrack [firsttrack] [lasttrack]
3382 # The commands here don't go through run_command because they're never supposed to be silenced
3383 # return codes need to be doublechecked anyway, however
3384 if [ "$1" = "onetrack" ]; then
3385 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3386 # FIXME # Until then, we grab the whole CD in one track, no matter what
3388 # We need the first and last track for cdda2wav/icedax
3390 LASTTRACK=$(expr $3 + 0)
3391 UTRACKNUM=$FIRSTTRACK
3392 case "$CDROMREADERSYNTAX" in
3393 flac) READTRACKNUMS="-" ;;
3396 # Add a variable to check if tracks are provided in command line and if not, rip the whole CD
3397 # We must make sure to rip from sector 0, both lines below work
3398 # READTRACKNUMS="-- -$LASTTRACK" ;;
3399 READTRACKNUMS="[.0]-" ;;
3400 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3401 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3402 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3408 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3409 if [ "$USEPIPES" = "y" ]; then
3410 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3411 FILEARG="$( eval echo "\$$TEMPARG" )"
3412 PIPE_MESSAGE="and encoding "
3414 WAVDATA="${ABCDETEMPDIR}/track$UTRACKNUM.wav"
3415 case "$CDROMREADERSYNTAX" in
3416 ## FIXME ## Find the cases for flac, to avoid exceptions
3418 FILEARG="--output-name=$WAVDATA"
3425 if [ "$1" = "onetrack" ]; then
3426 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3428 if [ -r "$CDDBDATA" ]; then
3429 getcddbinfo TRACKNAME
3430 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3432 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3435 case "$CDROMREADERSYNTAX" in
3436 ### FIXME ### use an exception for flac, since it uses -o
3437 ### FIXME ### Shall we just use -o $FILEARG ??
3439 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3440 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3441 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3443 if [ "$USEPIPES" = "y" ]; then
3444 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3446 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3450 if [ "$OSFLAVOUR" = "OSX" ] ; then
3451 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3452 diskutil unmount ${CDROM#/dev/}
3453 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3454 CDDA2WAVCDROM="IODVDServices"
3455 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3456 CDDA2WAVCDROM="$CDROMID"
3458 if [ "$CDROMID" = "" ]; then
3459 CDDA2WAVCDROM="$CDROM"
3461 CDDA2WAVCDROM="$CDROMID"
3464 if [ "$USEPIPES" = "y" ]; then
3465 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3467 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3471 # I cannot get USEPIPES to work with dagrab so just this:
3472 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2
3475 if [ "$USEPIPES" = "y" ]; then
3476 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3478 # Write ripped audio data to stdout and redirect to $FILEARG.
3479 # Progress is written to stderr by default and thus >&2 is not required.
3480 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3484 # Find the track's mounted path
3485 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3486 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3487 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3488 # If the file exists, copy it
3489 if [ -e "$FILEPATH" ] ; then
3490 if [ "$USEPIPES" = "y" ]; then
3491 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3493 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3499 if [ "$USEPIPES" = "y" ]; then
3500 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3502 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
3507 # If we get some error or we get some missing wav
3508 # (as long as we dont use pipes)
3509 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3510 # Thank goodness errors is only machine-parseable up to the
3511 # first colon, otherwise this woulda sucked
3512 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3513 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3515 if [ "$USEPIPES" = "y" ]; then
3516 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3518 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3522 if [ "$USEPIPES" = "y" ]; then
3523 echo readencodetrack-$UTRACKNUM >> "${ABCDETEMPDIR}/status"
3525 echo readtrack-$UTRACKNUM >> "${ABCDETEMPDIR}/status"
3527 if [ "$1" = "onetrack" ]; then
3528 echo onetrack >> "${ABCDETEMPDIR}/status"
3534 # No values accepted, only uses env variables
3537 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3538 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3540 echo "abcde: unable to set the device speed" >&2
3546 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3549 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3551 warning) shift ; log warning "$@" ;;
3559 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3562 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3564 warning) shift ; log warning "$@" ;;
3572 # decho outputs a debug message if DEBUG is selected
3575 if [ x"$DEBUG" != "x" ]; then
3576 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3577 DEBUGECHO=$(echo "$@" | tr -d '[]')
3578 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3580 echo >&4 "[DEBUG] $1"
3585 # User-redefinable functions
3586 # Custom filename munging:
3589 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3592 # Custom filename munging specific to track names:
3598 # Custom filename munging specific to artist names:
3604 # Custom filename munging specific to album names:
3610 # Custom genre munging:
3613 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3617 # Empty pre_read function, to be defined in the configuration file.
3624 # Empty post_read function, to be defined in the configuration file.
3631 # Empty post_encode function, to be defined in the configuration file.
3637 ###############################################################################
3640 # Start of execution
3641 ###############################################################################
3646 # Currently three supported options ("musicbrainz", "cddb" for freedb.org and "cdtext")
3647 CDDBMETHOD=musicbrainz
3648 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3649 CDDBSUBMIT=freedb-submit@freedb.org
3651 HELLOINFO="$(whoami)@$(hostname)"
3653 CDDBLOCALPOLICY="always"
3654 CDDBLOCALRECURSIVE="y"
3655 CDDBLOCALDIR="$HOME/.cddb"
3658 # List of fields we parse and show during the CDDB parsing...
3659 SHOWCDDBFIELDS="year,genre"
3662 #CDROMREADERSYNTAX=cdparanoia
3663 ENCODERSYNTAX=default
3665 MP3ENCODERSYNTAX=default
3666 OGGENCODERSYNTAX=default
3667 OPUSENCODERSYNTAX=default
3668 MKAENCODERSYNTAX=default
3669 AIFFENCODERSYNTAX=default
3670 FLACENCODERSYNTAX=default
3671 SPEEXENCODERSYNTAX=default
3672 MPCENCODERSYNTAX=default
3673 WVENCODERSYNTAX=default
3674 TTAENCODERSYNTAX=default
3675 APENCODERSYNTAX=default
3676 MP2ENCODERSYNTAX=default
3677 AACENCODERSYNTAX=default
3678 NORMALIZERSYNTAX=default
3679 CUEREADERSYNTAX=default
3681 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3682 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3683 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3684 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3685 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3686 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3687 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3688 PLAYLISTDATAPREFIX=''
3689 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3690 VAPLAYLISTDATAPREFIX=''
3698 VARIOUSARTISTSTYLE=forward
3705 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3706 # i.e. CDROMID="1,0,0"
3708 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3709 # If we are using the ide-scsi emulation layer, we need to define a "g"
3710 CDPARANOIACDROMBUS="d"
3712 # program paths - defaults to checking your $PATH
3718 XINGMP3ENC=xingmp3enc
3732 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3736 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3746 NEROAACENC=neroAacEnc
3748 # Note that the qaac PATH will almost always require adjustment
3749 # as it is a Windows application being run through Wine. More
3750 # detailed notes in the sample abcde.conf file in the abcde tarball.
3753 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3761 VORBISCOMMENT=vorbiscomment
3763 NEROAACTAG=neroAacTag
3764 ATOMICPARSLEY=AtomicParsley
3768 CDPARANOIA=cdparanoia
3769 CD_PARANOIA=cd-paranoia
3776 MUSICBRAINZ=abcde-musicbrainz-tool
3780 NORMALIZE=normalize-audio
3782 VORBISGAIN=vorbisgain
3786 # For Wavpack replay gain we set both the default of 'track gain'
3787 # as well as this option for 'album gain'. Better media players
3788 # such as vlc can select either or neither. Andrew.
3799 # Options for programs called from abcde:
3802 # These options needed by FFmpeg for tagging and selection of id3v2 version:
3803 # 1. '-write_id3v2 1' allows id3v2 tagging while '-write_id3v2 0' disables tagging
3804 # 2. '-id3v2_version 4' gives version id3v2.4 while '3' gives id3v2.3
3805 AIFFENCOPTS="-write_id3v2 1 -id3v2_version 4"
3817 VORBISGAINOPTS="--album"
3821 # The flac option is a workaround for an error where flac fails
3822 # to encode with error 'floating point exception'. This is flac
3823 # error in get_console_width(), corrected in flac 1.3.1
3825 FLACGAINOPTS="--add-replay-gain"
3832 # True Audio has no useful options but it is here anyway :)
3835 # Monkey's Audio Console (mac) chokes without a mode setting
3836 # so we set one here.
3843 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3844 # we set bitrate here.
3845 FDKAACENCOPTS='--bitrate 192k'
3867 VORBISCOMMENTOPTS="-R"
3868 METAFLACOPTS="--no-utf8-convert"
3873 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3875 # Defaults for album art downloads
3876 ALBUMARTFILE="cover.jpg"
3878 ALBUMARTALWAYSCONVERT="n"
3880 # Default to one process if -j isn't specified
3883 # List of actions to perform - by default, run to completion
3884 ACTIONS=cddb,read,encode,tag,move,clean
3886 # This option is basically for Debian package dependencies:
3887 # List of preferred outputs - by default, run with whatever we have in the path
3888 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:fdkaac:opus
3890 # List of preferred cdromreaders - by default, run whichever we have in the path
3891 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3893 # fd for when `vecho` and `log info` called with redirected stdout
3896 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3897 # Linux/OpenBSD. ftp is user for NetBSD.
3898 # Let's use these checkings to determine the OS flavour, which will be used
3900 if [ X$(uname) = "XFreeBSD" ] ; then
3905 elif [ X$(uname) = "XDarwin" ] ; then
3907 # By default md5sum is not installed, use md5 instead:
3910 # We should have diskutil in OSX, but let's be sure...
3912 CDROMREADERSYNTAX=cddafs
3913 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3915 elif [ X$(uname) = "XOpenBSD" ] ; then
3919 elif [ X$(uname) = "XNetBSD" ] ; then
3923 elif [ X$(uname) = "SunOS" ] ; then
3931 # If CDDBAVAIL is set to n, no CDDB read is done
3935 # But before we get into business, let us chop off any GREP environmental
3940 # Length of the terminal *should* be in $LINES. If it's not, guess at
3941 # a reasonable number instead
3942 if [ -z "$LINES" ]; then
3946 if [ -z "$OUTPUTDIR" ]; then
3950 if [ -z "$WAVOUTPUTDIR" ]; then
3951 WAVOUTPUTDIR="$OUTPUTDIR"
3954 # Load system defaults
3955 if [ -r /etc/abcde.conf ]; then
3958 # Load user preference defaults
3959 if [ -r $HOME/.abcde.conf ]; then
3963 # By this time, we need some HTTPGETOPTS already defined.
3964 # If the user has defined a non-default HTTPGET method, we should not be empty.
3966 if [ "$HTTPGETOPTS" = "" ] ; then
3968 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3969 curl) HTTPGETOPTS="-f -s -L";;
3970 fetch)HTTPGETOPTS="-q -o -";;
3971 ftp) HTTPGETOPTS="-a -V -o - ";;
3972 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3976 # If the CDROM has not been set yet, find a suitable one.
3977 # If this is a devfs system, default to /dev/cdroms/cdrom0
3978 # instead of /dev/cdrom
3979 if [ "$CDROM" = "" ] ; then
3980 if [ -e /dev/cdroms/cdrom0 ]; then
3981 CDROM=/dev/cdroms/cdrom0
3982 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3983 CDROM=/dev/${BASH_REMATCH[1]}
3984 elif [ -e /dev/cdrom ]; then
3986 elif [ -e /dev/sr0 ]; then
3988 elif [ -e /dev/cd0c ]; then
3990 elif [ -e /dev/acd0c ]; then
3992 elif [ -e /dev/disk1 ]; then
3997 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3998 # that's changed to a number to allow for more control. Deal with
3999 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
4000 case "$EXTRAVERBOSE" in
4009 # Parse command line options
4010 while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pP:Q:r:s:S:t:T:UvVxX:w:W:z opt ; do
4013 a) ACTIONS="$OPTARG" ;;
4014 A) EXPACTIONS="$OPTARG" ;;
4016 B) GETALBUMART=y ; EMBEDALBUMART=y ;;
4017 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
4018 C) CDDBDISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
4019 d) CDROM="$OPTARG" ;;
4022 e) ERASEENCODEDSTATUS=y ;;
4023 E) ENCODING="$OPTARG" ;;
4028 j) MAXPROCS="$OPTARG" ;;
4031 L) CDDBUSELOCAL=y ;;
4036 o) OUTPUTTYPE="$OPTARG" ;;
4039 Q) CDDBMETHOD="$OPTARG" ;;
4040 r) REMOTEHOSTS="$OPTARG" ;;
4041 R) CDDBLOCALRECURSIVE=y ;;
4042 s) SHOWCDDBFIELDS="$OPTARG" ;;
4043 S) CDSPEEDVALUE="$OPTARG" ;;
4044 t) STARTTRACKNUMBER="$OPTARG" ;;
4045 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
4048 echo "This is abcde v$VERSION."
4049 echo "Usage: abcde [options] [tracks]"
4050 echo "abcde -h for extra help"
4053 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
4055 X) CUE2DISCID="$OPTARG" ;;
4056 w) COMMENT="$OPTARG" ;;
4057 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
4058 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
4059 STARTTRACKNUMBERTAG="y"
4060 COMMENT="CD${OPTARG}"
4061 DISCNUMBER="${OPTARG}"
4063 log error "argument of -W must be integer"
4067 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
4072 shift $(($OPTIND - 1))
4074 # Here it comes the worse part of the whole thing. From here until we start
4075 # ripping, we have a mixture of sanity checks, verifications, default settigs
4076 # and other crazy stuff that interdepends, but hey, someone has to do it.
4078 # If NOCDDBQUERY is set, don't query the CDDB server.
4079 if [ "$NOCDDBQUERY" = "y" ]; then
4083 # If the user specified a flac file, then switch to special flac mode
4084 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
4085 if [ ! -f "$CDROM" ]; then
4086 log error "the defined file for FLAC ripping cannot be found" >&2
4089 vecho warning "switching to flac CDROMREADERSYNTAX..."
4090 CDROMREADERSYNTAX=flac
4091 # We have a builtin version of cue2discid...
4092 case "$CUE2DISCID" in
4094 *) NEEDCUE2DISCID=y;;
4100 # If the user provided a CDDBDISCID, disable eject
4101 if [ -n "$CDDBDISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
4103 # Check the available cd rippers in the system, from the ones we know.
4104 if [ "$CDROMREADERSYNTAX" = "" ]; then
4105 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
4106 if new_checkexec $DEFAULT_CDROMREADER; then
4107 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
4111 if [ "$CDROMREADERSYNTAX" = "" ]; then
4112 log error "no cdreader found in your PATH"
4113 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4118 # Decide if we can continue.
4119 if [ "$ONETRACK" = "y" ]; then
4120 # FIXME # remove check as soon as we find out about the other readers
4121 case "$CDROMREADERSYNTAX" in
4123 cdparanoia | libcdio) ;;
4124 cdda2wav | icedax) ;;
4126 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
4129 if [ "$BATCHNORM" = "y" ]; then
4130 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
4133 if [ "$NOGAP" = "y" ]; then
4134 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
4137 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
4138 # FIXME # allow ranges of tracks to be selected for onetrack ripping
4139 if [ $# -gt 0 ]; then
4140 log warning "ONETRACK mode selected, grabbing all tracks..."
4143 while [ $# -gt 0 ]; do
4144 # Range parsing code courtesy of Vincent Ho
4145 # Cleaned up to use shell built-ins by Charles Steinkuehler
4146 if [ "${1#*[^0-9-]}" != "$1" ]; then
4147 log error "syntax error while processing track numbers ($1)"
4152 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
4153 TRACKQUEUE="$TRACKQUEUE $RSTART"
4154 RSTART=$(( $RSTART + 1 ))
4161 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
4162 # List of experimental actions: retag,transcode
4164 # Determine what actions are to be done from $ACTIONS and set the
4165 # following environment variables for them:
4177 ## FIXME ## Lets keep compatibility with -M
4178 [ "$DOCUE" != "y" ] && DOCUE=n
4180 for ACTION in $(echo $ACTIONS | tr , \ )
4183 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4184 cue) DOCUE=y ; MAKECUEFILE=y ;;
4187 normalize) DONORMALIZE=y; DOREAD=y;;
4188 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4189 encode) DOENCODE=y; DOREAD=y;;
4190 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4191 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4192 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4193 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4194 playlist) DOCDDB=y; DOPLAYLIST=y;;
4196 getalbumart) GETALBUMART=y;;
4197 embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
4201 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4202 # FIXME # should we abort on error or just inform the user?
4203 log warning "selected both normalize and replaygain actions"
4206 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
4207 case $SHOWCDDBFIELD in
4208 y*|Y*) SHOWCDDBYEAR="y";;
4209 g*|G*) SHOWCDDBGENRE="y";;
4214 # At this point a CDROM has to be defined, so we check it exists.
4215 if [ X"$CDROM" != "X" ] ; then
4216 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
4217 if [ "$OSFLAVOUR" = "FBSD" ]; then
4218 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
4219 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4220 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4224 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
4225 log error "CDROM device cannot be found."
4228 # avoid processing if we are not going to hit the CDROM.
4229 elif [ X"$DOREAD" = "Xy" ]; then
4230 log error "CDROM has not been defined or cannot be found"
4234 # USEPIPES pre-tests, before we get into more serious stuff
4235 # Not compatible with:
4236 # - multiple outputs
4238 # - lowdisk algorithm
4240 if [ X"$USEPIPES" = "Xy" ]; then
4241 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
4242 log error "Unix pipes not compatible with multiple outputs"
4245 if [ X"$DONORMALIZE" = "Xy" ]; then
4246 log error "Unix pipes not compatible with normalizer"
4247 # FIXME # Do we need to exit or shall we just disable the mode?
4250 if [ X"$BATCHNORM" = "Xy" ]; then
4251 log error "Unix pipes not compatible with BATCHNORM encoding"
4254 if [ X"$NOGAP" = "Xy" ]; then
4255 log error "Unix pipes not compatible with NOGAP encoding"
4258 if [ X"$DOENCODE" = "Xn" ]; then
4259 vecho warning "Disabling Unix pipes since we are not encoding!"
4262 if [ X"$LOWDISK" = "Xy" ]; then
4263 log error "Unix pipes not compatible with lowdisk algorithm"
4268 # LOWDISK pre-tests, before we get into more problematic stuff
4269 # Not compatible with anything that needs all the files in the hard disc:
4272 if [ X"$LOWDISK" = "Xy" ]; then
4273 if [ X"$BATCHNORM" = "Xy" ]; then
4274 log error "Unix pipes not compatible with BATCHNORM encoding"
4277 if [ X"$NOGAP" = "Xy" ]; then
4278 log error "Unix pipes not compatible with NOGAP encoding"
4283 # BATCHNORM pre-tests, before we get into serious problems
4284 # Not compatible with
4285 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4286 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4290 # Check the encoding format from the ones available in the system, if nothing has been configured.
4291 if [ X"$OUTPUTTYPE" = "X" ]; then
4292 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4293 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
4294 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
4295 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
4296 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4297 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4301 if [ X"$OUTPUTTYPE" = "X" ]; then
4302 log error "no encoder found in the PATH"
4303 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4308 # Decide which CDROM reader we're gonna use
4309 case "$CDROMREADERSYNTAX" in
4311 CDROMREADER="$CDPARANOIA"
4312 CDROMREADEROPTS="$CDPARANOIAOPTS"
4315 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4316 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4317 CDROMREADER="$CD_PARANOIA"
4318 CDROMREADEROPTS="$CDPARANOIAOPTS"
4321 CDROMREADER="$CDDA2WAV"
4322 CDROMREADEROPTS="$CDDA2WAVOPTS"
4325 CDROMREADER="$DAGRAB"
4326 CDROMREADEROPTS="$DAGRABOPTS"
4330 CDROMREADEROPTS="$PIRDOPTS"
4333 CDROMREADER="$CDDAFS"
4334 CDROMREADEROPTS="$CDDAFSOPTS"
4338 CDROMREADEROPTS="$FLACOPTS"
4342 # There's only one normalize...
4343 case "$NORMALIZERSYNTAX" in
4345 NORMALIZER="$NORMALIZE"
4346 NORMALIZEROPTS="$NORMALIZEOPTS"
4350 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4351 case "$OUTPUTTYPE" in *:*)
4352 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4353 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4355 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4356 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4357 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4358 aiff:*) AIFFENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4359 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4360 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4361 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4362 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4363 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4364 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4365 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4366 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4367 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4370 # Allows commandline selection of options while using multiple outputs.
4371 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4372 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4373 TEMPOUTPUT=${OUTPUT%%:*}
4374 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4376 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4380 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4381 # for flacs and speexenc for speex and mpcenc for mpcs and fdkaac for m4as and
4382 # wavpack for wvs...
4384 # Getting ready for multiple output changes
4385 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4389 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4390 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4391 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4392 OGGOUTPUTCONTAINER=ogg
4395 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4396 OPUSOUTPUTCONTAINER=opus
4399 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4400 MKAOUTPUTCONTAINER=mka
4403 [ "$AIFFENCODERSYNTAX" = "default" ] && AIFFENCODERSYNTAX=ffmpeg
4404 AIFFOUTPUTCONTAINER=aiff
4407 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4408 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4409 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4410 [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
4413 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4414 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4415 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4416 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4417 [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
4420 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4421 # [ "$DOREPLAYGAIN" = "y" ] &&
4424 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4425 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4428 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4430 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4431 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4432 [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
4435 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4436 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4439 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4440 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4441 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4444 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4445 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4446 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4449 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4451 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4452 # compiled without libmp4v2... Andrew.
4455 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=fdkaac
4456 [ "$AACENCODERSYNTAX" = "faac" ] && [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4457 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4458 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4459 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4460 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4461 [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
4464 if [ "$KEEPWAVS" = "y" ]; then
4465 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4469 *) log error "Invalid OUTPUTTYPE defined"
4475 # decide which encoder
4476 case "$MP3ENCODERSYNTAX" in
4478 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4482 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4486 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4487 MP3ENCODER="$BLADEENC"
4490 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4494 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4495 MP3ENCODER="$XINGMP3ENC"
4498 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4499 MP3ENCODER="$MP3ENC"
4502 case "$OGGENCODERSYNTAX" in
4504 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4505 OGGENCODER="$VORBIZE"
4508 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4509 OGGENCODER="$OGGENC"
4512 case "$OPUSENCODERSYNTAX" in
4514 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4515 OPUSENCODER="$OPUSENC"
4518 case "$MKAENCODERSYNTAX" in
4520 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4521 MKAENCODER="$FFMPEG"
4524 case "$AIFFENCODERSYNTAX" in
4526 AIFFENCODEROPTS="${AIFFENCODEROPTSCLI:-$AIFFENCOPTS}"
4527 AIFFENCODER="$FFMPEG"
4530 case "$FLACENCODERSYNTAX" in
4532 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4534 if [ "$DOREPLAYGAIN" = "y" ]; then
4535 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4537 # FLAC streams can be encapsulated on a Ogg transport layer
4538 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4539 log error "FLAC on an Ogg container is not yet supported"
4540 log error "due to problem with adding comments to such files"
4542 FLACOUTPUTCONTAINER=ogg
4544 FLACOUTPUTCONTAINER=flac
4548 case "$SPEEXENCODERSYNTAX" in
4550 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4551 SPEEXENCODER="$SPEEXENC"
4554 case "$MPCENCODERSYNTAX" in
4556 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4557 MPCENCODER="$MPCENC"
4560 case "$WVENCODERSYNTAX" in
4562 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4563 # and in the interests of backward compatibility:
4564 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4565 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4566 WVENCODER="$WAVPACK"
4568 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4569 WVENCODER="$WAVPACK"
4573 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4577 case "$TTAENCODERSYNTAX" in
4579 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4583 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4584 TTAENCODER="$TTAENC"
4587 case "$APENCODERSYNTAX" in
4589 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4593 case "$MP2ENCODERSYNTAX" in
4595 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4596 MP2ENCODER="$TWOLAME"
4599 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4600 MP2ENCODER="$FFMPEG"
4603 case "$AACENCODERSYNTAX" in
4604 # Some elaborate 'if' work to keep backward compatibility for those
4605 # who don't realise that AACENCOPTS does not work with abcde from
4606 # version 2.7 onwards.
4608 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4609 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4612 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4617 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4618 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4619 AACENCODER="$NEROAACENC"
4621 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4622 AACENCODER="$NEROAACENC"
4626 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4627 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4628 AACENCODER="$FDKAAC"
4630 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4631 AACENCODER="$FDKAAC"
4635 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4636 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4639 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4644 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4645 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4646 AACENCODER="$FHGAACENC"
4648 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4649 AACENCODER="$FHGAACENC"
4653 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4654 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4655 AACENCODER="$FFMPEG"
4657 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4658 AACENCODER="$FFMPEG"
4668 TAGGEROPTS="$ID3OPTS"
4673 TAGGEROPTS="$ID3V2OPTS"
4678 TAGGEROPTS="$ID3TAGOPTS"
4682 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4683 # trouble with CDDBPROTO=5 (which we test here) but also
4684 # with cached cddb files in latin1 (which we cannot test).
4685 if [ "$CDDBPROTO" -lt 6 ]; then
4686 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4689 # eyeD3 version 0.7 changed syntax
4690 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4691 # only if it offers the --set-encoding, assume <= 0.6.x
4693 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4695 # anything wrong, any failure, assume >= 0.7
4697 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4701 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4706 # NOGAP is specific to lame. Other encoders fail ...
4707 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4708 log warning "the NOGAP option is specific to lame. Deactivating..."
4713 case "$CUEREADERSYNTAX" in
4715 CUEREADEROPTS="${CDROM}"
4719 CUEREADEROPTS="$MKCUEOPTS ${CDROM}"
4724 # which information retrieval tool are we using?
4730 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4731 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4732 log error "FLAC on an Ogg container is not yet supported"
4733 log error "due to problem with adding comments to such files"
4735 OGGOUTPUTCONTAINER=ogg.ogg
4736 FLACOUTPUTCONTAINER=flac.ogg
4737 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4740 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4742 if [ "$ENCNICE" ]; then
4743 ENCNICE="-n $ENCNICE"
4745 if [ "$READNICE" ]; then
4746 READNICE="-n $READNICE"
4748 if [ "$DISTMP3NICE" ]; then
4749 DISTMP3NICE="-n $DISTMP3NICE"
4752 # Don't check for stuff if it's not needed
4753 if [ "$REMOTEHOSTS" ]; then
4756 if [ "$DONORMALIZE" = "y" ]; then
4759 if [ "$EJECTCD" = "y" ]; then
4762 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4763 # Need an http tool to be able to do CDDB
4769 if [ "$DOCUE" = "y" ]; then
4773 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4774 case "$CDROMREADERSYNTAX" in
4775 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4776 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4777 ### FIXME ### translate "cue2discid" from python to bash
4778 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4783 if [ "$GETALBUMART" = "y" ]; then
4788 ###USEPIPESSUPPORT###
4790 # Rippers with USEPIPE support
4791 PIPERIPPER_cdparanoia="-"
4792 PIPERIPPER_libcdio="-"
4793 # Note that by default in abcde cdda2wav redirects to icedax.
4794 PIPERIPPER_cdda2wav="-"
4795 PIPERIPPER_debug="-"
4796 PIPERIPPER_flac="-c "
4799 # Encoders with USEPIPE support
4802 PIPE_bladeenc="stdin"
4815 # Both neroAacEnc and fdkaac seem to manage without the addition of
4816 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4817 # in this manner. Andrew.
4821 # Figure out if we can use pipes with the ripper/encoder combination
4823 if [ "$USEPIPES" = "y" ]; then
4824 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4827 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4829 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4831 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4833 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4835 PIPEENCODERSVARCHECK="PIPE_$AIFFENCODERSYNTAX" ;;
4837 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4839 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4841 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4843 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4845 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4847 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4849 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4851 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4852 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4853 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4854 log error "no support for pipes with given ripper"
4855 log error "read the FAQ file from the source tarball to get help."
4858 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4859 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4860 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4861 log error "no support for pipes with given encoder"
4862 log error "read the FAQ file from the source tarball to get help"
4867 # Make sure a buncha things exist
4868 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4869 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4870 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER $AIFFENCODER \
4871 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4872 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4873 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4874 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4875 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4876 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4877 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4878 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4879 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4880 ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
4885 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4886 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4887 # these files). The resulting files are actually ADTS streams which belong in an
4888 # aac container and with some version sniffing this is all cleaned up below. If
4889 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4891 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4892 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4893 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4894 echo "WARNING: Your copy of Faac does not have mp4 support"
4895 echo "WARNING: Encoding untagged files to aac..."
4896 # Replace m4a with aac for single and multi-output encodes:
4897 OUTPUTTYPE=$(echo "$OUTPUTTYPE" | sed 's/m4a/aac/')
4899 echo "Using Faac to Tag AAC Tracks..."
4903 # And last but not least, check if we can diff between files. We do not abort,
4904 # since diffing is not critical...
4905 if [ -x $(which $DIFF) ]; then :; else
4906 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4910 ## Now that we have metaflac, check if we need cue2discid
4911 #case $CDROMREADERSYNTAX in
4913 # CDDBTRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4914 # if [ "$CDDBTRACKINFO" = "" ]; then
4915 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4920 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4921 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4922 HTTPGET="$HTTPGET $HTTPGETOPTS"
4924 # Here it used to say:
4925 # One thousand lines in, we can start doing stuff with things
4926 # Well, right now we are at line 3737 ;)
4927 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
4929 # Export needed things so they can be read in this subshell
4930 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4931 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4933 if [ "$DOREAD" = "y" ]; then
4934 # User-definable function to set some things. Use it for
4935 # - closing the CD tray with eject -t
4936 # - set the CD speed value with eject -x
4937 vecho -n "Executing customizable pre-read function... "
4939 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4944 # Get ABCDETEMPDIR created and status file initialized
4947 if [ "$DOCDDB" = "y" ]; then
4948 # start with a sane default:
4949 CDDBLOCALSTATUS=notfound
4950 if [ $CDDBUSELOCAL = "y" ]; then
4953 if checkstatus cddb-choice > /dev/null; then
4957 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4959 for CDDBMETHCHOICE in $(echo "$CDDBMETHOD" | tr -d ' ' | tr , ' ')
4961 addstatus "Lookup method $idx: $CDDBMETHCHOICE"
4963 vecho "Found $NUM_CDDB_MATCHES matches so far"
4964 vecho "Trying lookup method ${CDDBMETHCHOICE}"
4966 # Run all the desired data acquisition methods, in the order
4967 # specified by the user. Each will use its own temporary
4968 # subdirectory, then copy the cddbread.* etc. files up into
4970 case "$CDDBMETHCHOICE" in
4981 echo "Unknown lookup method $CDDBMETHCHOICE. Aborting." >&2
4988 rm -f "${ABCDETEMPDIR}/cddbchoices"
4989 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
4991 if [ $NUM_CDDB_MATCHES = 0 ]; then
4992 # If we got no matches, we need to
4993 # generate a blank CDDB template.
4994 vecho "Unable to find any matches, generating unknown template."
4995 echo "No lookup matches." >> "${ABCDETEMPDIR}/cddbchoices"
4996 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
4997 # List out disc title/author and contents of template
4998 echo ---- Unknown Artist / Unknown Album ---- >> "${ABCDETEMPDIR}/cddbchoices"
5000 for TRACK in $(f_seq_row 1 $TRACKS)
5002 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${ABCDETEMPDIR}/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5004 echo >> "${ABCDETEMPDIR}/cddbchoices"
5005 echo cddb-read-0-complete >> "${ABCDETEMPDIR}/status"
5006 echo cddb-choice=0 >> "${ABCDETEMPDIR}/status"
5007 echo 503 > "${ABCDETEMPDIR}/cddbquery"
5009 # We have matches; create the cddbchoices and cddbquery
5010 # files from all the inputs we have
5011 if [ $NUM_CDDB_MATCHES = 1 ]; then
5012 echo "Retrieved 1 match..." >> "${ABCDETEMPDIR}/cddbchoices"
5013 echo -n "200 " > "${ABCDETEMPDIR}/cddbquery"
5014 cat "${ABCDETEMPDIR}/cddbquery.1" >> "${ABCDETEMPDIR}/cddbquery"
5016 echo "Retrieved $NUM_CDDB_MATCHES matches..." >> "${ABCDETEMPDIR}/cddbchoices"
5017 echo "210 Found exact matches, list follows (until terminating .)" > "${ABCDETEMPDIR}/cddbquery"
5018 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5020 cat "${ABCDETEMPDIR}/cddbquery.$X" >> "${ABCDETEMPDIR}/cddbquery"
5022 echo "." >> "${ABCDETEMPDIR}/cddbquery"
5025 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5027 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.$X" | cut -c8- | tr -d \\r\\n)
5028 SOURCE=$(cat ${ABCDETEMPDIR}/datasource.$X)
5029 echo "#$X ($SOURCE): ---- ${ATITLE} ----" >> "${ABCDETEMPDIR}/cddbchoices"
5030 for TRACK in $(f_seq_row 1 $TRACKS)
5032 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${ABCDETEMPDIR}/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5034 echo >> "${ABCDETEMPDIR}/cddbchoices"
5041 eval "$($CDDBTOOL parse "$CDDBDATA")"
5044 # Before reading tracks, we set the speed of the device
5046 if [ X"$CDSPEEDVALUE" != "X" ]; then
5047 case "$CDROMREADERSYNTAX" in
5048 cdparanoia|libcdio|debug) ;;
5055 # Define the first and last track, since we might need them later in several places
5056 FIRSTTRACK=$( get_first $TRACKQUEUE )
5057 LASTTRACK=$( get_last $TRACKQUEUE )
5059 if [ -f "${ABCDETEMPDIR}/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
5060 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
5061 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
5062 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
5065 if checkstatus onetrack ; then ONETRACK=y ; fi
5067 if [ "$ONETRACK" = "y" ]; then
5068 # Reuse the CUEFILE in case we created it (now or in a previous run)
5069 if CUEFILE=$(checkstatus cuefile); then
5074 # Create playlist if needed (backgroundable) and start reading in tracks
5078 if [ ! "$ONETRACK" = "y" ]; then
5079 if [ "$DOPLAYLIST" = "y" ]; then
5080 echo Creating playlist... >&2
5085 if [ "$GETALBUMART" = "y" ]; then
5089 # For the lowdisk option, only one program is running at once so the encoder
5090 # can be unsilenced right away.
5091 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
5092 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5095 if [ "$ONETRACK" = "y" ]; then
5096 TRACKS="$FIRSTTRACK"
5097 if [ "$USEPIPES" = "y" ]; then
5098 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
5099 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
5102 if checkstatus readtrack-$FIRSTTRACK; then :; else
5103 do_cdread onetrack $FIRSTTRACK $LASTTRACK
5107 for UTRACKNUM in $TRACKQUEUE
5109 if [ "$DOREAD" = "y" ]; then
5110 if [ "$USEPIPES" = "y" ]; then
5111 if checkstatus readencodetrack-$UTRACKNUM; then :; else
5112 # Read, pipe, shut up!
5113 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
5116 if checkstatus readtrack-$UTRACKNUM; then :; else
5117 do_cdread $UTRACKNUM
5119 if [ "$?" != "0" ]; then
5120 # CD read failed - don't give the goahead to
5127 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
5130 # If we are not reading, set the encode output to loud already, so
5131 # that we can see the output of the first track.
5132 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
5133 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5135 echo NEXTTRACK # Get the encoder machine churning again
5136 if [ "$DOREAD" = "y" ]; then
5137 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
5138 until checkstatus encodetrack-$UTRACKNUM
5140 if checkerrors encodetrack-$UTRACKNUM; then
5151 # Now that we're done the encoding can be loud again -
5152 # if we're not using SMP.
5153 if [ "$MAXPROCS" = "1" ]; then
5154 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5157 # All tracks read, start encoding.
5158 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
5162 # Execute the user-defined post_read function before ejecting CD
5165 # We are now finished with the cdrom - it can be safely ejected. Note that
5166 # abcde will not have completed yet.
5167 if [ "$EJECTCD" = "y" ]; then
5168 # We check if the disk we are processing is actually the disk inside the
5169 # CD tray. If not, we do not eject the CD, since it might be so that the
5170 # user ejected it manually.
5171 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
5172 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$CDDBTRACKINFO" ] ; then
5173 # More FreeBSD bits.
5174 if [ X"$(uname)" = X"FreeBSD" ] ; then
5175 # FreeBSD eject uses the EJECT environment variable to name the CDROM
5176 # but in this script EJECT is in the envionment and names the program
5179 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
5180 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
5181 $eject $EJECTOPTS $cd
5182 elif [ X"$(uname)" = X"Darwin" ] ; then
5183 diskutil eject ${CDROM#/dev/} 0
5184 elif [ -x $(which $EJECT) ]; then
5185 $EJECT $EJECTOPTS "$CDROM"
5192 ## Do we need to pre-process
5193 #if [ x"$PREPROCESS" = "x" ] ; then
5196 # for PRETRACKNUM in $TRACKQUEUE
5199 # if [ "$GOAHEAD" = "NO" ]; then break; fi
5201 # until [ $PREPROCEED ]
5203 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
5204 # # all locations are working, wait and try again later
5205 # if [ ! $PREPROCEED ]; then sleep 3; fi
5207 # ( do_preprocess $PRETRACKNUM
5215 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
5217 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
5218 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5219 if [ "$GOAHEAD" != "NO" ]; then
5220 for LASTTRACK in $TRACKQUEUE; do :; done
5221 if checkstatus readtrack-$LASTTRACK; then
5222 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
5223 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
5224 if checkerrors batch-normalize; then exit 1; fi
5226 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
5227 if [ "$DONORMALIZE" = "y" ]; then
5228 for UTRACKNUM in $TRACKQUEUE
5230 if checkstatus readtrack-$UTRACKNUM; then
5231 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5235 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
5236 if checkerrors nogap-encode; then exit 1; fi
5242 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
5243 if [ "$ONETRACK" = "y" ] ; then
5244 TRACKQUEUE="$FIRSTTRACK"
5245 TRACKS="$FIRSTTRACK"
5248 # Do the encoding, including parallelization of remote encoding
5249 # Figure out where each track is going to be encoded
5250 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
5251 if [ "$MAXPROCS" != "0" ]; then
5252 for NUM in $(f_seq_row 1 "$MAXPROCS")
5254 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5258 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5259 for UTRACKNUM in $TRACKQUEUE
5262 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5263 if [ "$GOAHEAD" = "NO" ]; then break; fi
5264 # find out where this track is to be encoded
5265 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5266 # Make sure we have a place to encode this, if not, exit stage right
5267 if [ -z "$ENCODELOCATIONS" ]; then
5273 for LOCATION in $ENCODELOCATIONS
5275 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5276 # check first if a track has ever been assigned to this location
5277 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5278 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5279 if checkerrors encodetrack-$PREVIOUSTRACK; then
5280 for TEMPLOCATION in $ENCODELOCATIONS
5282 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5283 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5286 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5291 # We're still here, this location must have been previously assigned,
5292 # and last completed without error - check if it's done with the
5293 # previous track yet
5294 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
5296 # all locations are working, wait and try again later
5297 if [ ! $PROCEED ]; then sleep 3; fi
5299 # Record the location we're about to encode the next track at
5300 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
5302 # Don't proceed with the rest of the loop if we can't encode
5303 if [ "$ABORT" ]; then continue; fi
5304 ## FIXME ## Add here
5305 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
5306 # Set TRACKNUM, TRACKNAME
5307 if [ -e "$CDDBDATA" ]; then
5308 if [ "$ONETRACK" = "y" ]; then
5310 TRACKNUM="$FIRSTTRACK"
5314 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
5315 getcddbinfo TRACKNAME
5319 # You can't encode a file which needs to be normalized before finishing
5320 # You can't tag a file before it's finished encoding -
5321 # thus all of this is backgrounded together
5323 if [ "$DONORMALIZE" = "y" ]; then
5324 if checkstatus readtrack-$UTRACKNUM; then
5325 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5328 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5329 if checkstatus readtrack-$UTRACKNUM; then
5330 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
5331 if [ "$DONORMALIZE" = "y" ]; then
5332 if checkstatus normalizetrack-$UTRACKNUM; then
5333 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5336 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5340 if [ "$DOTAG" = "y" ]; then
5341 if checkstatus encodetrack-$UTRACKNUM; then
5342 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
5344 # Lets tag the cue file
5345 if checkstatus cleancuefile >/dev/null; then :; else
5346 if checkstatus cuefile >/dev/null ; then
5351 if [ "$DOMOVE" = "y" ]; then
5352 if checkstatus tagtrack-$UTRACKNUM; then
5353 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
5360 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5361 # we'll delete the files they're working on
5362 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5363 ## FIXME ## Check also for files which are encoded using PIPEs.
5364 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5369 for LOCATION in $ENCODELOCATIONS
5371 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5372 # "How can he give us a status update, if he's DEAD?"
5373 if checkstatus encodetrack-$CHECKTRACK; then
5376 # Nothing to see here please go quietly back to your homes
5377 if [ -z "$CHECKTRACK" ]; then continue; fi
5378 # You're still here? Maybe there is something...
5379 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
5382 if [ ! $PROCEED ]; then sleep 5; fi
5385 # If the above didn't catch the stragglers, this will
5387 if [ "$DOREPLAYGAIN" = "y" ]; then
5391 if [ "$EMBEDALBUMART" = "y" ]; then
5395 # Execute the user-defined post_encode function before cleaning up
5398 # Check to see if run_command logged any errors
5399 if [ -f "${ABCDETEMPDIR}/errors" ]; then
5400 log error "The following commands failed to run:"
5401 cat "${ABCDETEMPDIR}/errors"
5405 if [ "$KEEPWAVS" = "y" ];then
5409 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5410 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5411 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5412 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5413 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5414 log warning "The encoded formats does not match with the moved ones"
5415 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
5416 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
5417 log warning "Use \"abcde -a clean -f -C $CDDBDISCID\" to force the removal of the remaining data."
5421 if [ "$DOCLEAN" = "y" ]; then
5422 # Wipe all the evidence
5423 # Gimme gimme gimme some more time!
5425 rm -rf "${ABCDETEMPDIR}"
5428 echo "Finished. Not cleaning ${ABCDETEMPDIR}."