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_version ] ; then
364 MISSING_PACKAGE=vorbis-tools
366 lame|flac|cd-discid|eject|mkcue|icedax|glyrc)
370 log info "Hint: sudo apt-get install $MISSING_PACKAGE" >&2
373 elif [ ! -x "$(which $X 2>/dev/null)" ]; then
374 log error "$X is not executable." >&2
380 # diffentries <filename> <max_value> <entry1>,<entry2>
381 # max_value: the range of entries goes from 1 to <max_value>
386 local CDDBDIFFCHOICES=$1
388 local CDDBDIFFCHOICE="$@"
389 if [ ! X"$DIFF" = "X" ]; then
390 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
391 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
392 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
393 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
394 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
395 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
397 # We parse the 2 choices to diff, store them in temporary files and diff them.
398 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
399 do_cddbparse "${ABCDETEMPDIR}/$FILENAME.$PARSECHOICE" > "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE"
401 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "${ABCDETEMPDIR}/$FILENAME.diff"
402 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE1" "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/$FILENAME.diff"
403 if [ $(cat "${ABCDETEMPDIR}/$FILENAME.diff" | wc -l) -ge $LINES ]; then
404 page "${ABCDETEMPDIR}/$FILENAME.diff"
406 cat "${ABCDETEMPDIR}/$FILENAME.diff" >&2
410 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
415 # Finds an specific field from cddbinfo
420 TRACKNAME="$(grep -a ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
423 TRACKNAME="$(grep -a ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
426 grep -a ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
432 # Get the track number we are going to use for different actions
435 if [ -n "$STARTTRACKNUMBER" ] ; then
436 # Get the trackpadding from the current track, also trim whitespace for MacOSX
437 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
438 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
440 TRACKNUM=${UTRACKNUM}
446 # Calculate cddb disc ids without requiring specialized helper programs.
447 # largely copied from cd-discid and musicbrainz examples. some of the steps
448 # don't make sense, but they're necessary to match the ids generated by other
451 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
452 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
453 # 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
454 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
455 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
456 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
458 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
461 if [ X"$LEADOUT" = "X" ]; then
462 log warning "Error trying to calculate disc ids without lead-out information."
466 # default to a two second lead-in
468 LEADIN=${LEADIN:=150}
470 # number of cdframes per second
473 # reset cddb checksum for cddb disc-id calululation
477 for OFFSET in $(echo $OFFSETS)
479 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
481 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
482 while [ $OFFSETTIME -gt 0 ]; do
483 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
484 OFFSETTIME=$(($OFFSETTIME / 10))
489 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
491 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
492 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
494 vvecho "makeids: PREGAP $PREGAP, LEADIN $LEADIN, LEADOUT $LEADOUT"
496 # Calculate both the cddb discid *and* the musicbrainz discid
497 # now. We'll use the cddb discid for reference in most cases
498 # for consistency, but we also have the musicbrainz discid for
500 printf -v CDDBDISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
501 CDDBTRACKINFO="${CDDBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
505 # FIXME: don't assume the first track is 1
506 MBDISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $(($PREGAP + $LEADOUT)) $OFFSETS)
508 if [ $error != 0 ]; then
509 log error "$MUSICBRAINZ failed to run; ABORT"
512 MBTRACKINFO="${MBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
519 if checkstatus replaygain; then :; else
520 run_command "" echo "Adding replaygain information..."
521 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
525 OUTPUT=$OGGOUTPUTCONTAINER
528 OUTPUT=$OPUSOUTPUTCONTAINER
531 OUTPUT=$FLACOUTPUTCONTAINER
539 for UTRACKNUM in $TRACKQUEUE
541 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
542 getcddbinfo TRACKNAME
544 TRACKFILE="$(mungetrackname "$TRACKNAME")"
545 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
546 ALBUMFILE="$(mungealbumname "$DALBUM")"
547 GENRE="$(mungegenre "$GENRE")"
548 YEAR=${CDYEAR:-$CDYEAR}
550 if [ "$ONETRACK" = "y" ]; then
551 if [ "$VARIOUSARTISTS" = "y" ]; then
552 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
554 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
557 if [ "$VARIOUSARTISTS" = "y" ]; then
558 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
560 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
563 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
564 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
568 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
569 #run_command replaygain-flac true
572 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
575 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
578 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
581 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
586 if checkerrors "replaygain-.{3,6}"; then :; else
587 run_command replaygain true
592 # This code splits the a Various Artist track name from one of the following
595 # forward: Artist / Track
596 # forward-dash: Artist - Track
597 # reverse: Track / Artist
598 # reverse-dash: Track - Artist
599 # colon: Artist: Track
600 # trailing-paren: Artist (Track)
603 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
606 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
607 case "$VARIOUSARTISTSTYLE" in
609 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
610 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
611 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
614 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
615 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
616 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
619 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
620 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
621 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
624 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
625 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
626 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
629 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
630 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
631 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
634 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
635 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
636 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
639 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
640 TRACKARTIST="Various"
642 TRACKARTIST="$DARTIST"
647 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
651 "classic rock") id=1 ;;
669 "industrial") id=19 ;;
670 "alternative") id=20 ;;
672 "death metal") id=22 ;;
674 "soundtrack") id=24 ;;
675 "euro-techno") id=25 ;;
679 "jazz+funk") id=29 ;;
682 "classical") id=32 ;;
683 "instrumental") id=33 ;;
687 "sound clip") id=37 ;;
690 "alt. rock") id=40 ;;
695 "meditative") id=45 ;;
696 "instrum. pop") id=46 ;;
697 "instrum. rock") id=47 ;;
701 "techno-indust.") id=51 ;;
702 "electronic") id=52 ;;
704 "eurodance") id=54 ;;
706 "southern rock") id=56 ;;
711 "christian rap") id=61 ;;
712 "pop/funk"|"pop / funk") id=62 ;;
714 "native american") id=64 ;;
717 "psychadelic") id=67 ;;
719 "showtunes") id=69 ;;
723 "acid punk") id=73 ;;
724 "acid jazz") id=74 ;;
728 "rock & roll") id=78 ;;
729 "hard rock") id=79 ;;
731 "folk/rock") id=81 ;;
732 "national folk") id=82 ;;
739 "bluegrass") id=89 ;;
740 "avantgarde") id=90 ;;
741 "gothic rock") id=91 ;;
742 "progress. rock") id=92 ;;
743 "psychadel. rock") id=93 ;;
744 "symphonic rock") id=94 ;;
745 "slow rock") id=95 ;;
748 "easy listening") id=98 ;;
754 "chamber music") id=104 ;;
756 "symphony") id=106 ;;
757 "booty bass") id=107 ;;
759 "porn groove") id=109 ;;
761 "slow jam") id=111 ;;
765 "folklore") id=115 ;;
767 "power ballad") id=117 ;;
768 "rhythmic soul") id=118 ;;
769 "freestyle") id=119 ;;
771 "punk rock") id=121 ;;
772 "drum solo") id=122 ;;
773 "a capella") id=123 ;;
774 "euro-house") id=124 ;;
775 "dance hall") id=125 ;;
777 "drum & bass") id=127 ;;
778 "club-house") id=128 ;;
779 "hardcore") id=129 ;;
783 "negerpunk") id=133 ;;
784 "polsk punk") id=134 ;;
786 "christian gangsta rap") id=136 ;;
787 "heavy metal") id=137 ;;
788 "black metal") id=138 ;;
789 "crossover") id=139 ;;
790 "contemporary christian")id=140 ;;
791 "christian rock") id=141 ;;
792 "merengue") id=142 ;;
794 "thrash metal") id=144 ;;
797 "synthpop") id=147 ;;
798 "rock/pop"|"rock / pop") id=148 ;;
805 # do_tag [tracknumber]
806 # id3 tags a filename
808 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
809 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
812 COMMENTOUTPUT="$(eval echo ${COMMENT})"
813 if [ -z "$COMMENTOUTPUT" ]; then
814 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
816 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
817 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
818 # If we want to start the tracks with a given number, we need to modify the
819 # TRACKNUM value before evaluation
820 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
823 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
827 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
828 GENREID=$(do_getgenreid "${CDGENRE}")
829 # Set TPE2 in case we have a Various Artists rip.
831 if [ "$VARIOUSARTISTS" = "y" ]; then
837 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
838 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
839 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
840 -y "$CDYEAR" -g "$GENREID" \
841 -T "${TRACKNUM:-$1}" \
842 "${ABCDETEMPDIR}/track$1.$OUTPUT"
845 # FIXME # track numbers in mp3 come with 1/10, so we cannot
846 # happily substitute them with $TRACKNUM
847 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
848 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
849 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
850 -y "$CDYEAR" -g "$GENREID" \
851 -T "${TRACKNUM:-$1}/$TRACKS" \
852 ${TPE2:+--TPE2 "$TPE2"} \
853 "${ABCDETEMPDIR}/track$1.$OUTPUT"
856 # FIXME # track numbers in mp3 come with 1/10, so we cannot
857 # happily substitute them with $TRACKNUM
858 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
859 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
860 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
861 -y "$CDYEAR" -g "$GENREID" \
862 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
863 "${ABCDETEMPDIR}/track$1.$OUTPUT"
866 # FIXME # track numbers in mp3 come with 1/10, so we cannot
867 # happily substitute them with $TRACKNUM
869 eyed3_06) addopts=( \
870 ${ENCODING:+--set-encoding="$ENCODING"} \
871 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
872 # We set 'recording-date' so the date tag will show
873 # in Audacious, vlc and friends... Andrew.
874 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
875 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
878 ${ENCODING:+--encoding="$ENCODING"} \
879 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
880 # We set 'recording-date' so the date tag will show
881 # in Audacious, vlc and friends... Andrew.
882 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
883 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
886 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
888 -a "$TRACKARTIST" -t "$TRACKNAME" \
889 -G "$GENREID" -n "${TRACKNUM:-$1}" \
890 ${TRACKNUM:+-N "$TRACKS"} \
892 "${ABCDETEMPDIR}/track$1.$OUTPUT"
895 log error "Internal error: ID3SYNTAX has an illegal value"
901 case "$OGGENCODERSYNTAX" in
903 # vorbiscomment can't do in-place modification, mv the file first
904 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" -a ! -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
905 mv "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
909 # https://www.xiph.org/vorbis/doc/v-comment.html
911 echo ARTIST="$TRACKARTIST"
913 echo TITLE="$TRACKNAME"
914 if [ -n "$CDYEAR" ]; then
917 if [ -n "$CDGENRE" ]; then
918 echo GENRE="$CDGENRE"
920 echo TRACKNUMBER=${TRACKNUM:-$1}
921 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
922 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
923 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
924 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
925 echo TRACKTOTAL="${TRACKS}"
926 if [ -n "$DISCNUMBER" ]; then
927 echo DISCNUMBER="$DISCNUMBER"
929 echo CDDB="${CDDBDISCID}"
930 if [ "$(eval echo ${COMMENT})" != "" ]; then
931 case "$COMMENTOUTPUT" in
932 *=*) echo "$COMMENTOUTPUT";;
933 *) echo COMMENT="$COMMENTOUTPUT";;
936 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
937 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
938 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
939 # Doublecheck that the commented file was created
940 # successfully before wiping the original
941 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ]; then
942 rm -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
944 mv "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
950 run_command tagtrack-$OUTPUT-$1 true
953 run_command tagtrack-$OUTPUT-$1 true
956 run_command tagtrack-$OUTPUT-$1 true
960 echo ARTIST="$TRACKARTIST"
962 echo TITLE="$TRACKNAME"
963 if [ -n "$CDYEAR" ]; then
966 if [ -n "$CDGENRE" ]; then
967 echo GENRE="$CDGENRE"
969 echo TRACKNUMBER="${TRACKNUM:-$1}"
970 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
971 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
972 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
973 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
974 echo TRACKTOTAL="${TRACKS}"
975 if [ -n "$DISCNUMBER" ]; then
976 echo DISCNUMBER="$DISCNUMBER"
978 echo CDDB="${CDDBDISCID}"
979 if [ "$(eval echo ${COMMENT})" != "" ]; then
980 case "$COMMENTOUTPUT" in
981 *=*) echo "$COMMENTOUTPUT";;
982 *) echo COMMENT="$COMMENTOUTPUT";;
985 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} \
986 --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
989 run_command tagtrack-$OUTPUT-$1 true
992 run_command tagtrack-$OUTPUT-$1 true
995 run_command tagtrack-$OUTPUT-$1 true
998 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
999 # Console port (mac) used for encoding does not have the ability to tag.
1000 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "${ABCDETEMPDIR}/track$1.ape" -m overwrite \
1001 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
1002 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
1005 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
1006 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
1007 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
1008 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1009 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1010 "${ABCDETEMPDIR}/track$1.mp2"
1013 run_command tagtrack-$OUTPUT-$1 true
1016 case "$AACENCODERSYNTAX" in
1018 # We will use inline tagging...
1019 run_command tagtrack-$OUTPUT-$1 true
1022 # Tag post encode with neroAacTag...
1023 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "${ABCDETEMPDIR}/track$1.m4a" \
1024 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
1025 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1028 run_command tagtrack-$OUTPUT-$1 true
1031 run_command tagtrack-$OUTPUT-$1 true
1034 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1035 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1036 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$ATOMICPARSLEY" "${ABCDETEMPDIR}/track$1.m4a" \
1037 --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum=${TRACKNUM:-$1} \
1038 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
1041 run_command tagtrack-$OUTPUT-$1 true
1046 # We use mid3v2 tagging for True Audio:
1047 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1048 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1049 "${ABCDETEMPDIR}/track$1.tta"
1052 run_command tagtrack-$OUTPUT-$1 true
1056 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1057 run_command tagtrack-$1 true
1063 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1066 # The commands here don't go through run_command because they're never
1067 # supposed to be silenced
1068 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1069 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1073 case "$MP3ENCODERSYNTAX" in
1076 cd "${ABCDETEMPDIR}"
1078 for UTRACKNUM in $TRACKQUEUE
1080 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1082 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1084 if [ "$RETURN" != "0" ]; then
1085 echo "nogap-encode: $ENCODER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1087 for UTRACKNUM in $TRACKQUEUE
1089 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1090 #run_command encodetrack-$UTRACKNUM true
1099 if checkerrors "nogap-encode"; then :; else
1100 if [ ! "$KEEPWAVS" = "y" ] ; then
1101 if [ ! "$KEEPWAVS" = "move" ] ; then
1106 # Other encoders fall through to normal encoding as the tracks have not
1107 # been entered in the status file.
1110 # do_encode [tracknumber] [hostname]
1111 # If no hostname is specified, encode locally
1113 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1114 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1117 if [ "$USEPIPES" = "y" ]; then
1120 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1123 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1126 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1129 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1132 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1135 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1138 TEMPARG="PIPE_$SPEEXENCODER"
1141 TEMPARG="PIPE_$MPCENCODER"
1144 TEMPARG="PIPE_$WVENCODERSYNTAX"
1147 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1150 TEMPARG="PIPE_$AACENCODERSYNTAX"
1153 TEMPARG="PIPE_$AACENCODERSYNTAX"
1156 IN="$( eval echo "\$$TEMPARG" )"
1158 IN="${ABCDETEMPDIR}/track$1.wav"
1160 # We need IN to proceed, if we are not using pipes.
1161 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1162 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1164 case "$TMPOUTPUT" in
1166 OUTPUT=$OGGOUTPUTCONTAINER
1169 OUTPUT=$OPUSOUTPUTCONTAINER
1172 OUTPUT=$MKAOUTPUTCONTAINER
1175 OUTPUT=$AIFFOUTPUTCONTAINER
1178 OUTPUT=$FLACOUTPUTCONTAINER
1184 OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1185 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1188 if [ X"$USEPIPES" = "Xy" ]; then
1190 # We need a way to store the creation of the files when using PIPES
1191 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1192 # When piping it does not make sense to have a higher nice for
1193 # reading than for encoding, since it will be hold by the
1194 # encoding process. Setting an effective nice, to calm down a
1195 # bit the reading process.
1196 EFFECTIVE_NICE=$READNICE
1198 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1199 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1200 EFFECTIVE_NICE=$ENCNICE
1206 case "$MP3ENCODERSYNTAX" in
1207 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1208 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1209 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1210 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1214 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1221 case "$OGGENCODERSYNTAX" in
1222 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1223 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1227 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1234 case "$OPUSENCODERSYNTAX" in
1236 # Tag the file at encode time, as it can't be done after encoding.
1237 if [ "$DOTAG" = "y" ]; then
1238 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1239 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1240 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1242 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1248 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1253 case "$MKAENCODERSYNTAX" in
1255 if [ "$DOTAG" = "y" ]; then
1256 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS -metadata artist="$TRACKARTIST" \
1257 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1258 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1260 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1266 case "$AIFFENCODERSYNTAX" in
1268 if [ "$DOTAG" = "y" ]; then
1269 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS -metadata artist="$TRACKARTIST" \
1270 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1271 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1273 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1281 case "$FLACENCODERSYNTAX" in
1282 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1287 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1288 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1293 if [ "$(eval echo ${COMMENT})" != "" ]; then
1296 *) COMMENT="COMMENT=$COMMENT" ;;
1299 # Tag the file at encode time, as it can't be done after encoding.
1300 if [ "$DOTAG" = "y" ]; then
1301 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1302 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1304 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1308 # Tag the file inline at encode time.
1309 if [ "$DOTAG" = "y" ]; then
1310 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1311 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1313 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1317 case "$TTAENCODERSYNTAX" in
1318 # tta is the newer version with a small syntax change...
1320 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1323 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1328 case "$WVENCODERSYNTAX" in
1330 if [ "$DOTAG" = "y" ]; then
1331 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1332 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1334 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1338 if [ "$DOTAG" = "y" ]; then
1339 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1340 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1341 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1343 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1349 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1352 case "$MP2ENCODERSYNTAX" in
1354 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1357 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1362 # aac container is only used to catch faac encoded files where faac
1363 # is compiled without mp4 support (with libmp4v2).
1364 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1367 case "$AACENCODERSYNTAX" in
1369 if [ "$DOTAG" = "y" ]; then
1370 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1371 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1373 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1377 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1380 if [ "$DOTAG" = "y" ]; then
1381 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1382 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1384 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1388 if [ "$DOTAG" = "y" ]; then
1389 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1390 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1392 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1396 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1399 if [ "$DOTAG" = "y" ]; then
1400 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1401 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1402 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1404 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1410 # In case of wav output we need nothing. Just keep the wavs.
1411 # But we need the following to allow full logging and subsequent
1412 # successful cleaning of ${ABCDETEMPDIR}.
1413 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1418 # Only remove .wav if the encoding succeeded
1419 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1420 run_command encodetrack-$1 true
1421 if [ ! "$KEEPWAVS" = "y" ] ; then
1422 if [ ! "$KEEPWAVS" = "move" ] ; then
1428 run_command "" echo "HEH! The file we were about to encode disappeared:"
1429 run_command "" echo ">> $IN"
1430 run_command encodetrack-$1 false
1434 # do_preprocess [tracknumber]
1436 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1439 # IN="${ABCDETEMPDIR}/track$1.wav"
1440 # # We need IN to proceed.
1441 # if [ -s "$IN" ] ; then
1442 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1444 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1445 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1446 # case "$POSTPROCESSFORMAT" in
1448 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1450 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1452 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1454 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1456 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1459 # # Only remove .wav if the encoding succeeded
1460 # if checkerrors "preprocess-(.{3,4})-$1"; then
1461 # run_command preprocess-$1 false
1463 # run_command preprocess-$1 true
1466 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1467 # echo "HEH! The file we were about to pre-process disappeared:"
1470 # run_command preprocess-$1 false
1475 # do_postprocess [tracknumber]
1477 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1480 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1482 # IN="${ABCDETEMPDIR}/track$1.$POSTPROCESSFORMAT"
1483 # # We need IN to proceed.
1484 # if [ -s "$IN" ] ; then
1485 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1486 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1487 # case "$POSTPROCESSFORMAT" in
1489 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1491 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1493 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1495 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1497 # # Only remove .wav if the encoding succeeded
1498 # if checkerrors "postprocess-(.{3,4})-$1"; then
1499 # run_command postprocess-$1 false
1501 # run_command postprocess-$1 true
1504 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1505 # echo "HEH! The file we were about to post-process disappeared:"
1508 # run_command postprocess-$1 false
1523 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1527 # The commands here don't go through run_command because they're never supposed to be silenced
1528 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1530 cd "${ABCDETEMPDIR}"
1533 for UTRACKNUM in $TRACKQUEUE
1535 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1537 # FIXME # Hard-coded batch option!
1538 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1540 if [ "$RETURN" != "0" ]; then
1541 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1543 for UTRACKNUM in $TRACKQUEUE
1545 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1551 # do_batch_normalize
1553 # NORMALIZER, NORMALIZEROPTS
1554 do_batch_normalize ()
1556 # The commands here don't go through run_command because they're never supposed to be silenced
1557 echo "Batch normalizing tracks: $TRACKQUEUE"
1559 cd "${ABCDETEMPDIR}"
1562 for UTRACKNUM in $TRACKQUEUE
1564 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1566 # XXX: Hard-coded batch option!
1567 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1569 if [ "$RETURN" != "0" ]; then
1570 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1572 for UTRACKNUM in $TRACKQUEUE
1574 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1580 # do_normalize [tracknumber]
1582 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1585 IN="${ABCDETEMPDIR}/track$1.wav"
1586 if [ -e "$IN" ] ; then
1587 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1588 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1590 if [ "$(checkstatus encode-output)" = "loud" ]; then
1591 echo "HEH! The file we were about to normalize disappeared:"
1594 run_command normalizetrack-$1 false "File $IN was not found"
1598 # do_move [tracknumber]
1599 # Deduces the outfile from environment variables
1600 # Creates directory if necessary
1602 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1605 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1607 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1608 # defined the OUTPUTFILE:
1611 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1612 ALBUMFILE="$(mungealbumname "$DALBUM")"
1613 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1614 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1615 GENRE="$(mungegenre "$GENRE")"
1616 YEAR=${CDYEAR:-$CDYEAR}
1617 # If we want to start the tracks with a given number, we need to modify
1618 # the TRACKNUM value before evaluation
1620 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1621 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1622 if [ "$ONETRACK" = "y" ]; then
1623 if [ "$VARIOUSARTISTS" = "y" ]; then
1624 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1626 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1629 if [ "$VARIOUSARTISTS" = "y" ]; then
1630 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1632 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1635 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1636 # Once we know the specific output was successful, we can change
1637 # the OUTPUT to the value containing the container
1640 OUTPUT=$OGGOUTPUTCONTAINER
1643 OUTPUT=$OPUSOUTPUTCONTAINER
1646 OUTPUT=$MKAOUTPUTCONTAINER
1649 OUTPUT=$AIFFOUTPUTCONTAINER
1652 OUTPUT=$FLACOUTPUTCONTAINER
1658 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1659 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1662 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1663 # FIXME # introduce warnings?
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
1675 # mkdir -p shouldn't return an error if the directory already exists
1676 mkdir -p "$OUTPUTFILEDIR"
1677 run_command movetrack-$1 mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1678 if checkstatus movetrack-output-$OUTPUT; then :; else
1679 run_command movetrack-output-$OUTPUT true
1683 # Lets move the cue file
1684 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1685 if [ -r "${ABCDETEMPDIR}/$CUEFILE" ]; then
1686 if checkstatus movecue-$OUTPUT; then :; else
1687 # Silence the Copying output since it overlaps with encoding processes...
1688 #run_command '' vecho "Copying cue file to its destination directory..."
1689 if checkstatus onetrack >/dev/null ; then
1692 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1693 # We dont have the dir, since it was not created before.
1696 run_command movecue-$OUTPUT cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1699 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1700 # http://brianvictor.tripod.com/mp3cue.htm#details
1701 [a-z0-9][a-z0-9][a-z0-9])
1702 run_command movecue-$OUTPUT cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1705 run_command movecue-$OUTPUT cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1709 run_command movecue-$OUTPUT cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1711 echo movecue-$OUTPUT >> "${ABCDETEMPDIR}/status"
1720 # Create the playlist if wanted
1722 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1723 # VARIOUSARTISTS, OUTPUTDIR
1726 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1730 OUTPUT=$OGGOUTPUTCONTAINER
1733 OUTPUT=$OPUSOUTPUTCONTAINER
1736 OUTPUT=$MKAOUTPUTCONTAINER
1739 OUTPUT=$AIFFOUTPUTCONTAINER
1742 OUTPUT=$FLACOUTPUTCONTAINER
1748 # Create a playlist file for the playlist data to go into.
1749 # We used to wipe it out if it existed. Now we request permission if interactive.
1750 for LASTTRACK in $TRACKQUEUE; do :; done
1751 ALBUMFILE="$(mungealbumname "$DALBUM")"
1752 ARTISTFILE="$(mungeartistname "$DARTIST")"
1753 GENRE="$(mungegenre "$GENRE")"
1754 YEAR=${CDYEAR:-$CDYEAR}
1755 if [ "$VARIOUSARTISTS" = "y" ] ; then
1756 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1758 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1760 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1761 mkdir -p "$FINALPLAYLISTDIR"
1762 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1763 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1764 if [ "$INTERACTIVE" = "y" ]; then
1765 while [ "$DONE" != "y" ]; do
1767 case $ERASEPLAYLIST in
1768 e|E|a|A|k|K) DONE=y ;;
1769 "") ERASEPLAYLIST=e ; DONE=y ;;
1777 # Once we erase the playlist, we use append to create the new one.
1778 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1780 # The playlist does not exist, so we can safelly use append to create the new list
1783 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1784 touch "$OUTPUTDIR/$PLAYLISTFILE"
1785 for UTRACKNUM in $TRACKQUEUE
1787 # Shares some code with do_move since the filenames have to match
1788 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1789 getcddbinfo TRACKNAME
1791 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1792 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1793 ALBUMFILE="$(mungealbumname "$DALBUM")"
1794 # If we want to start the tracks with a given number, we need to modify the
1795 # TRACKNUM value before evaluation
1797 if [ "$VARIOUSARTISTS" = "y" ]; then
1798 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1800 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1802 if [ "$VARIOUSARTISTS" = "y" ]; then
1803 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1804 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1806 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1809 if [ "$PLAYLISTDATAPREFIX" ]; then
1810 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1812 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1817 ## this will convert the playlist to have CRLF line-endings, if specified
1818 ## (some hardware players insist on CRLF endings)
1819 if [ "$DOSPLAYLIST" = "y" ]; then
1820 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "${ABCDETEMPDIR}/PLAYLISTFILE.tmp"
1821 # mv -f "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1822 cat "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1824 echo "playlistcomplete" >> "${ABCDETEMPDIR}/status"
1829 # This function reads a cuefile on stdin and writes an extended
1830 # cddb query on stdout. Any PREGAP for track 1 is properly
1831 # handled, although cue files embedded in FLAC files do not
1832 # appear to properly store the PREGAP setting. :(
1833 abcde.cue2discid () {
1838 while [ $val -gt 0 ] ; do
1839 ret=$(( $ret + ( $val % 10) ))
1840 val=$(( $val / 10 ))
1850 local first second third
1851 first=$(expr ${1} + 0 )
1852 second=$(expr ${2} + 0 )
1853 third=$(expr ${3} + 0 )
1855 echo $(( ((($first * 60) + $second) * 75) + $third ))
1865 while read line ; do
1868 TRACK) i=$(( i + 1 ))
1870 INDEX) if [ "$2" -eq 1 ] ; then
1872 START=$(( $LBA + $PREGAP + $OFFSET ))
1874 X=$(cddb_sum $(( $START / 75 )) )
1878 PREGAP) PREGAP=$(msf2lba $2)
1882 LEADOUT=$(( $4 / 588 ))
1885 LEADIN=$(( $3 / 588 ))
1894 LEADOUT=$(( $LEADOUT + $LEADIN ))
1896 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1897 CDDBDISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1898 printf "%08x %i" ${CDDBDISCID} $TRACKS
1901 while [ $j -le $TRACKS ] ; do
1902 eval echo -n "\" \$TRACK$j\""
1905 echo " $(( $LEADOUT / 75 ))"
1909 # abcde.mkcue [--wholedisk]
1910 # This creates a cuefile directly from the extended discid information
1911 # The --wholedisk option controls whether we're ripping data from the
1912 # start of track one or from the start of the disk (usually, but not
1913 # always the same thing!)
1915 # Track one leadin/pregap (if any) handeling:
1916 # --wholedisk specified:
1919 # INDEX 01 <pregap value>
1920 # Remaining track index values unchanged from disc TOC
1922 # --wholedisk not specified
1924 # PREGAP <pregap value>
1926 # Remaining track index values offset by <pregap value>
1933 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1936 local MODE DISCID TRACKS
1940 if [ "$1" = --wholedisk ] ; then
1946 vecho "One track is $ONETRACK"
1947 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1948 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1949 ALBUMFILE="$(mungealbumname "$DALBUM")"
1950 if [ "$ONETRACK" = "y" ]; then
1951 if [ "$VARIOUSARTISTS" = "y" ]; then
1952 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1954 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1956 vecho "Cue wav file is $CUEWAVFILE"
1958 CUEWAVFILE="dummy.wav"
1961 set -- $CDDBTRACKINFO
1967 echo REM DISCID $DISCID
1968 echo FILE \""$CUEWAVFILE"\" WAVE
1970 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1977 while [ $i -le "$TRACKS" ] ; do
1978 LBA=$(( $1 - $OFFSET ))
1979 printf " TRACK %02i AUDIO\n" $i
1980 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1981 if [ $MODE = PREGAP ] ; then
1982 echomsf " PREGAP " $(($OFFSET-150))
1984 echo " INDEX 00 00:00:00"
1987 echomsf " INDEX 01 " $LBA
1994 # This is essentially the start of things
1997 if [ -z "${CDDBDISCID}" ]; then
1998 vecho -n "Getting CD track info... "
1999 # In OSX, unmount the disc before a query
2000 if [ "$OSFLAVOUR" = "OSX" ]; then
2001 diskutil unmount ${CDROM#/dev/}
2003 case "$CDROMREADERSYNTAX" in
2005 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
2006 case "$CUE2DISCID" in
2007 # FIXME # right now we have 2 cue2discid internal
2008 # implementations: builtin and abcde.cue2discid. Test
2009 # both of them and decide which one we want to use.
2011 #vecho "Using builtin cue2discid implementation..."
2012 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2014 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2016 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2017 TRACKS=${#OFFSETTIMES[@]}
2019 #echo "processing offsetimes ${OFFSETTIMES[@]}"
2020 for OFFSETTIME in ${OFFSETTIMES[@]}; do
2021 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2022 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
2025 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2026 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2030 #vecho "Using external python cue2discid implementation..."
2031 CDDBTRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2035 log error "the input flac file does not contain a cuesheet."
2040 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2042 if [ ! "$RET" = "0" ];then
2043 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2046 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2047 CDPARANOIAAUDIOTRACKS="$TRACKS"
2049 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2050 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2054 # Calculate the cddb discid in all
2055 # cases now. We'll use the cddb discid
2056 # for reference in most cases for
2057 # consistency. Also calculate the
2058 # musicbrainz discid if we need it.
2059 CDDBTRACKINFO=$($CDDISCID "$CDROM")
2060 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2063 MBTRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM")
2065 if [ $error != 0 ]; then
2066 log error "$MUSICBRAINZ failed to run; ABORT"
2069 MBDISCID=$(echo $MBTRACKINFO | cut -d' ' -f1)
2073 # Make sure there's a CD in there by checking cd-discid's return code
2074 if [ ! "$?" = "0" ]; then
2075 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2076 log error "cuesheet information from the flac file could not be read."
2077 log error "Perhaps the flac file does not contain a cuesheet?."
2080 log error "CD could not be read. Perhaps there's no CD in the drive?"
2084 # In OSX, remount the disc again
2085 if [ "$OSFLAVOUR" = "OSX" ]; then
2086 diskutil mount ${CDROM#/dev/}
2089 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -f1 -d' ')
2091 CDDBTRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.${CDDBDISCID}/cddbdiscid")
2094 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2095 # This needs to be done now because a section of the resuming code will need
2098 # get the number of digits to pad TRACKNUM with - we'll use this later
2099 # a CD can only hold 99 tracks, but since we support a feature for starting
2100 # numbering the tracks from a given number, we might need to set it as a
2101 # variable for the user to define... or obtain it somehow.
2102 if [ "$PADTRACKS" = "y" ] ; then
2106 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $CDDBTRACKINFO | cut -f1 -d' ')"
2107 if [ -z "$TRACKQUEUE" ]; then
2108 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2109 case "$CDROMREADERSYNTAX" in
2110 cdparanoia|libcdio|debug)
2111 if [ "$WEHAVEACD" = "y" ]; then
2112 vecho "Querying the CD for audio tracks..."
2113 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2115 if [ ! "$RET" = "0" ];then
2116 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2118 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2119 CDPARANOIAAUDIOTRACKS="$TRACKS"
2121 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2122 if [ -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks" ]; then
2123 echo cdparanoia-audio-tracks=$( cat "${ABCDETEMPDIR}/cdparanoia-audio-tracks" ) >> "${ABCDETEMPDIR}/status"
2124 rm -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks"
2126 if [ -f "${ABCDETEMPDIR}/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2127 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2131 *) TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ') ;;
2134 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2136 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2137 log info "The disc does not contain any tracks. Giving up..."
2140 echo -n "Grabbing entire CD - tracks: "
2141 if [ ! "$PADTRACKS" = "y" ] ; then
2142 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2144 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2146 while [ "$X" -ne "$TRACKS" ]
2148 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2149 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2153 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2154 # User-supplied track queue.
2155 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2156 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2157 # Once cleaned, obtain the highest value in the trackqueue for number padding
2158 for LASTTRACK in $TRACKQUEUE; do :; done
2159 if [ ! "$PADTRACKS" = "y" ] ; then
2160 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2162 # Now we normalize the trackqueue
2163 for TRACK in $TRACKQUEUE ; do
2164 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2165 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2167 TRACKQUEUE=$PADTRACKQUEUE
2168 echo Grabbing tracks: "$TRACKQUEUE"
2171 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2173 # We have the discid, create a temp directory after it to store all the temp
2176 if [ -e "${ABCDETEMPDIR}" ]; then
2177 echo -n "abcde: attempting to resume from ${ABCDETEMPDIR}"
2178 # It already exists, see if it's a directory
2179 if [ ! -d "${ABCDETEMPDIR}" ]; then
2180 # This is a file/socket/fifo/device/etc, not a directory
2183 echo "abcde: file ${ABCDETEMPDIR} already exists and does not belong to abcde." >&2
2184 echo "Please investigate, remove it, and rerun abcde." >&2
2188 # It's a directory, let's see if it's writable by us
2189 if [ ! -r "${ABCDETEMPDIR}" ] || [ ! -w "${ABCDETEMPDIR}" ] || [ ! -x "${ABCDETEMPDIR}" ]; then
2190 # Nope, complain and exit
2192 echo "abcde: directory ${ABCDETEMPDIR} already exists and is not writeable." >&2
2193 echo "Please investigate, remove it, and rerun abcde." >&2
2197 # See if it's populated
2198 if [ ! -f "${ABCDETEMPDIR}/cddbdiscid" ]; then
2199 # Wipe and start fresh
2200 echo "abcde: ${ABCDETEMPDIR}/cddbdiscid not found. Abcde must remove and recreate" >&2
2201 echo -n "this directory to continue. Continue [y/N]? " >&2
2202 if [ "$INTERACTIVE" = "y" ]; then
2208 if [ "$ANSWER" != "y" ]; then
2211 rm -rf "${ABCDETEMPDIR}" || exit 1
2212 mkdir -p "${ABCDETEMPDIR}"
2213 if [ "$?" -gt "0" ]; then
2214 # Directory already exists or could not be created
2215 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2219 # Everything is fine. Check for ^encodetracklocation-
2220 # and encode-output entries in the status file and
2221 # remove them. These are not relevant across sessions.
2222 if [ -f "${ABCDETEMPDIR}/status" ]; then
2223 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
2224 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
2225 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
2227 # Remove old error messages
2228 if [ -f "${ABCDETEMPDIR}/errors" ]; then
2229 rm -f "${ABCDETEMPDIR}/errors"
2233 # We are starting from scratch
2234 mkdir -p "${ABCDETEMPDIR}"
2235 if [ "$?" -gt "0" ]; then
2236 # Directory already exists or could not be created
2237 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2240 cat /dev/null > "${ABCDETEMPDIR}/status"
2241 # Store the abcde version in the status file.
2242 echo "abcde-version=$VERSION" >> "${ABCDETEMPDIR}/status"
2244 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2245 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2246 CUEFILE=cue-$(echo "$CDDBTRACKINFO" | cut -f1 -d' ').txt
2247 vecho "Creating cue file..."
2248 case $CDROMREADERSYNTAX in
2250 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "${ABCDETEMPDIR}/$CUEFILE"; then
2251 echo cuefile=$CUEFILE >> "${ABCDETEMPDIR}/status"
2253 log warning "the input flac file does not contain a cuesheet."
2257 if $CUEREADER $CUEREADEROPTS > "${ABCDETEMPDIR}/$CUEFILE"; then
2258 echo cuefile=$CUEFILE >> "${ABCDETEMPDIR}/status"
2260 log warning "reading the CUE sheet is still considered experimental"
2261 log warning "and there was a problem with the CD reading. abcde will continue,"
2262 log warning "but consider reporting the problem to the abcde author"
2268 # If we got the CDPARANOIA status and it is not recorded, save it now
2269 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2270 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2271 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "${ABCDETEMPDIR}/status"
2275 # Create the discid files
2276 echo "$CDDBTRACKINFO" > "${ABCDETEMPDIR}/cddbdiscid"
2279 echo "$MBTRACKINFO" > "${ABCDETEMPDIR}/mbdiscid"
2285 # Create a proper CUE file based on the CUE file we created before.
2288 if CUEFILE_IN="${ABCDETEMPDIR}"/$(checkstatus cuefile); then
2289 CUEFILE_OUT=$CUEFILE_IN.out
2290 ### FIXME ### checkstatus cddb
2291 if [ -e "$CDDBDATA" ]; then
2292 vecho "Adding metadata to the cue file..."
2293 # FIXME It doesn't preserve spaces! Why?
2294 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2296 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2297 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2298 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2302 cat "$CUEFILE_IN" | while read line
2304 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2305 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2306 # echo "$line" >> "$CUEFILE_OUT"
2307 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2308 eval track="\$TRACK$n"
2310 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2311 # When making a single-track rip, put the
2312 # actual file name into the file declaration
2313 # in the cue file so that it is usable by
2314 # music players and the like
2315 elif [ "$ONETRACK" = "y" ] &&
2316 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2318 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2319 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2320 ALBUMFILE="$(mungealbumname "$DALBUM")"
2322 if [ "$VARIOUSARTISTS" = "y" ]; then
2323 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2325 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2328 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2331 # FIXME # If the lines above are uncommented, remove the line below.
2332 echo "$line" >> "$CUEFILE_OUT"
2335 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2336 echo "cleancuefile" >> "${ABCDETEMPDIR}/status"
2342 # Parses a CDDB file and outputs the title and the track names.
2343 # Variables: CDDBFILE
2347 # List out disc title/author and contents
2348 if [ "$ONETRACK" = "y" ]; then
2349 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2351 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2352 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2353 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2354 if [ ! X"$PARSEDYEAR" = "X" ]; then
2355 echo "Year: $PARSEDYEAR"
2358 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2359 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2360 if [ ! X"$PARSEDGENRE" = "X" ]; then
2361 echo "Genre: $PARSEDGENRE"
2364 if [ ! "$ONETRACK" = "y" ]; then
2365 for TRACK in $(f_seq_row 1 $TRACKS)
2367 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2373 # Check for a local CDDB file, and report success
2374 do_localcddb_read ()
2376 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2378 CDDBLOCALSTATUS="notfound"
2379 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2382 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2383 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2384 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2385 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2386 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2387 CDDBLOCALMATCH=single
2388 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2389 CDDBLOCALMATCH=multiple
2394 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2395 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2396 CDDBLOCALMATCH=single
2401 # If the user has selected to check a local CDDB repo, we proceed with it
2402 case $CDDBLOCALMATCH in
2404 echo "Processing multiple matching CDDB entries..." > "${ABCDETEMPDIR}/cddblocalchoices"
2406 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2408 # List out disc title/author and contents
2409 CDDBLOCALREAD="${ABCDETEMPDIR}/cddblocalread.$X"
2410 cat "$RESULT" > "${CDDBLOCALREAD}"
2413 do_cddbparse "${CDDBLOCALREAD}"
2415 ##FIXME## QUICK HACK !!!!
2416 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2417 } >> "${ABCDETEMPDIR}/cddblocalchoices"
2419 if [ $(cat "${ABCDETEMPDIR}/cddblocalchoices" | wc -l) -ge $LINES ] && [ "$INTERACTIVE" = "y" ]; then
2420 page "${ABCDETEMPDIR}/cddblocalchoices"
2422 # It's all going to fit in one page, cat it
2423 cat "${ABCDETEMPDIR}/cddblocalchoices" >&2
2425 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2426 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2427 CDDBLOCALCHOICENUM=-1
2428 if [ "$INTERACTIVE" = "y" ]; then
2429 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2430 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2431 read CDDBLOCALCHOICE
2432 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2433 # FIXME # Introduce diff's
2434 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2435 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2436 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2437 # Make sure we get a valid choice
2438 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2439 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2440 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2446 #echo "Selected ..."
2448 CDDBLOCALCHOICENUM=1
2450 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2451 #echo "Using local copy of CDDB data"
2452 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2453 cat "${ABCDETEMPDIR}/cddblocalread.$CDDBLOCALCHOICENUM" >> "${ABCDETEMPDIR}/cddbread.1"
2454 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2455 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2456 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2457 do_cddbparse "${ABCDETEMPDIR}/cddbread.1" > "${ABCDETEMPDIR}/cddbchoices"
2458 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2459 CDDBLOCALSTATUS="found"
2461 #echo "Not using local copy of CDDB data"
2462 CDDBLOCALSTATUS="notfound"
2466 # List out disc title/author and contents
2467 do_cddbparse "${CDDBLOCALFILE}"
2468 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2469 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2471 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2473 if [ "$INTERACTIVE" = "y" ]; then
2475 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2476 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2479 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2483 if [ "$USELOCALRESP" = "y" ]; then
2484 #echo "Using local copy of CDDB data"
2485 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2486 cat "${CDDBLOCALFILE}" >> "${ABCDETEMPDIR}/cddbread.1"
2487 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2488 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2489 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2490 do_cddbparse "${CDDBLOCALFILE}" > "${ABCDETEMPDIR}/cddbchoices"
2491 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2492 CDDBLOCALSTATUS="single"
2494 #echo "Not using local copy of CDDB data"
2495 CDDBLOCALSTATUS="notfound"
2499 CDDBLOCALSTATUS="notfound"
2506 # Try to read CD-Text from the drive using icedax / cdda2wav
2509 if new_checkexec icedax; then
2510 CDTEXT_READER=icedax
2511 elif new_checkexec cdda2wav; then
2512 CDTEXT_READER=cdda2wav
2514 # Didn't find either, bail
2518 vecho "Obtaining CD-Text results..."
2519 CDTDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2520 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cdtext"
2521 mkdir -p "${SOURCE_WORKDIR}"
2523 if [ "$OSFLAVOUR" = "OSX" ] ; then
2524 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2525 diskutil unmount ${CDROM#/dev/}
2526 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2527 CDDA2WAVCDROM="IODVDServices"
2528 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2529 CDDA2WAVCDROM="$CDROMID"
2531 if [ "$CDROMID" = "" ]; then
2532 CDDA2WAVCDROM="$CDROM"
2534 CDDA2WAVCDROM="$CDROMID"
2538 # Do we have CD-Text on the disc (and can the drive read it?)
2540 cd "${SOURCE_WORKDIR}" && rm -f audio.* audio_*
2541 ${CDTEXT_READER} -J -v titles -D ${CDDA2WAVCDROM} > "${SOURCE_WORKDIR}/cd-text" 2>&1
2543 grep -a -q '^CD-Text: detected' "${SOURCE_WORKDIR}/cd-text"
2545 if [ $ERRORCODE -ne 0 ]; then
2546 # No CD-Text found, bail
2550 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2551 # Make an empty template
2552 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2553 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2554 rm -f "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2556 # XXX FIXME - this is a hack and should be replaced by proper
2557 # character set tracking for the CDDB data we have.
2558 if test "$CDDBPROTO" -ge 6 ; then
2559 # convert to Unicode
2560 iconv -f iso-8859-1 -t utf-8 <"${SOURCE_WORKDIR}/audio.cddb" >"${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2562 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2563 # apparently icedax/cdda2wav have no support for 16-bit
2564 # characters yet, either
2565 cp -p "${SOURCE_WORKDIR}/audio.cddb" "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2568 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2569 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2570 echo "CD-Text" > ${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}
2571 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2573 ( cd "${SOURCE_WORKDIR}" && rm -f audio_* audio.* )
2574 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2575 if [ -f $file ]; then
2576 cp $file "${ABCDETEMPDIR}"
2579 echo "cdtext-readcomplete" >> "${ABCDETEMPDIR}/status"
2582 # do_musicbrainz_read
2583 # Work with the musicbrainz WS API, then transform the results here so
2584 # they look (very) like the results from CDDB. Maybe not the best way
2585 # to go, but it Works For Me (TM)
2587 # List out all the matches individually into $SOURCE_WORKDIR/cddbread.X
2589 do_musicbrainz_read ()
2591 if checkstatus musicbrainz-readcomplete; then :; else
2592 vecho "Obtaining Musicbrainz results..."
2593 # If MB is to be used, interpret the query results and read all
2594 # the available entries.
2595 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2596 MBDISCID=$(echo $MBTRACKINFO | cut -d' ' -f1)
2597 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-musicbrainz"
2598 mkdir -p "${SOURCE_WORKDIR}"
2599 ${MUSICBRAINZ} --command data --discid "${MBDISCID}" --workdir "${SOURCE_WORKDIR}" --start ${NUM_CDDB_MATCHES}
2600 # To have got this far, must have been able to run
2601 # $MUSICBRAINZ earlier to calculate the ID. Errors here are
2602 # non-fatal, maybe a lookup failure? Log and continue.
2604 if [ $error != 0 ]; then
2605 log error "$MUSICBRAINZ failed to run"
2608 # Check for no matches.
2609 # The helper script will write disc matches out to
2610 # cddbread.*. Count how many we have
2611 NUM_RESPONSES=$(echo "${SOURCE_WORKDIR}"/cddbread.* | wc -w)
2612 if [ "$NUM_RESPONSES" -gt 0 ] ; then
2613 # One or more exact matches
2615 while [ $i -le $NUM_RESPONSES ]; do
2616 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2618 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2619 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2620 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2621 echo "Musicbrainz" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2622 cp -f "${SOURCE_WORKDIR}/"*."${NUM_CDDB_MATCHES}" "${ABCDETEMPDIR}"
2625 echo "musicbrainz-readcomplete" >> "${ABCDETEMPDIR}/status"
2632 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cddb"
2633 mkdir -p "${SOURCE_WORKDIR}"
2639 # Perform CDDB protocol version check if it hasn't already been done
2640 if checkstatus cddb-statcomplete; then :; else
2641 if [ "$CDDBAVAIL" = "n" ]; then
2643 echo 503 > "${SOURCE_WORKDIR}/cddbstat"
2646 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2647 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2648 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2649 vecho "Checking CDDB server status..."
2650 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "${SOURCE_WORKDIR}/cddbstat"
2651 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2652 case "$RESPONSECODE" in
2653 210) # 210 OK, status information follows (until terminating `.')
2656 501) # 501 Illegal CDDB protocol level: <n>.
2657 CDDBPROTO=`expr $CDDBPROTO - 1`
2659 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2660 # FreeDB TESTCD disc-id is used for query
2661 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "${SOURCE_WORKDIR}/cddbstat"
2662 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2663 case "$RESPONSECODE" in
2664 2??) # Server responded, everything seems OK
2674 if test $rc -eq 1; then
2678 echo cddb-statcomplete >> "${ABCDETEMPDIR}/status"
2685 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2686 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2688 # Perform CDDB query if it hasn't already been done
2689 if checkstatus cddb-querycomplete; then :; else
2690 if [ "$CDDBAVAIL" = "n" ]; then
2692 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2693 # The default CDDBLOCALSTATUS is "notfound"
2694 # This part will be triggered if the user CDDB repo does not
2695 # contain the entry, or if we are not trying to use the repo.
2697 vecho "Querying the CDDB server..."
2698 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2699 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2700 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $CDDBTRACKINFO > "${SOURCE_WORKDIR}/cddbquery"
2706 # no match found in database, wget/fetch error,
2707 # or user requested not to use CDDB. Make up an
2708 # error code (503) that abcde will recognize later
2709 # and compensate by making a template
2710 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2712 *) # strange and unknown error
2713 echo ERRORCODE=$ERRORCODE
2714 echo "abcde: $CDDBTOOL returned unknown error code"
2718 echo cddb-querycomplete >> "${ABCDETEMPDIR}/status"
2725 # If it's not to be used, generate a template.
2726 # Then, display it (or them) and let the user choose/edit it
2727 if checkstatus cddb-readcomplete; then :; else
2728 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbquery" | cut -f1 -d' ')
2729 vecho "Obtaining CDDB results..."
2730 case "$RESPONSECODE" in
2732 # One exact match, retrieve it
2733 # 200 [section] [discid] [artist] / [title]
2734 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2735 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2736 cat ${SOURCE_WORKDIR}/cddbquery | cut -f2- -d' ' > ${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"
2740 202|403|409|500|503)
2741 # TODO: Explain these error codes a little more accurately:
2742 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2743 # No match response:
2746 # Multiple exact, (possibly multiple) inexact matches
2747 vecho -n "Retrieving multiple matches... "
2748 grep -v ^[.]$ "${SOURCE_WORKDIR}/cddbquery" | (
2749 # IN A SUB-SHELL - VARIABLES MODIFIED
2750 # HERE DO NOT PERSIST IN THE PARENT
2751 read DISCINFO # eat top line
2754 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2755 if checkstatus cddb-read-${NUM_CDDB_MATCHES}-complete; then :; else
2756 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2757 echo "$DISCINFO" > ${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}
2758 echo "cddb" > ${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}
2759 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2762 # Need to re-count the entries here to be able
2763 # to incrememnt $NUM_CDDB_MATCHES in the
2765 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $(echo ${SOURCE_WORKDIR}/datasource.* | wc -w)))
2770 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2771 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2774 echo "cddb-readcomplete" >> "${ABCDETEMPDIR}/status"
2775 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2776 if [ -f $file ]; then
2777 cp $file "${ABCDETEMPDIR}"
2786 if checkstatus cddb-edit >/dev/null; then
2787 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2788 VARIOUSARTISTS="$(checkstatus variousartists)"
2789 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2792 if [ "$INTERACTIVE" = "y" ]; then
2793 # We should show the CDDB results both when we are not using the local CDDB repo
2794 # or when we are using it but we could not find a proper match
2795 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2796 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2797 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2798 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2799 CHOICE=$(checkstatus cddb-choice)
2800 if [ -n "$CHOICE" ] ; then
2801 case $NUM_CDDB_MATCHES in
2802 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2804 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CHOICE" | cut -f2- -d= | tr -d \\r\\n)
2805 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CHOICE")
2806 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)"
2807 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2811 # The user has a choice to make, display the info in a pager if necessary
2812 if [ $(cat "${ABCDETEMPDIR}/cddbchoices" | wc -l) -ge $LINES ]; then
2813 page "${ABCDETEMPDIR}/cddbchoices"
2815 # It's all going to fit in one page, cat it
2816 cat "${ABCDETEMPDIR}/cddbchoices" >&2
2820 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2822 # I'll take CDDB read #3 for $400, Alex
2823 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; do
2824 echo -n "Which entry would you like abcde to use (0 for none)? [0-$NUM_CDDB_MATCHES]: " >&2
2826 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2827 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2828 if [ ! X"$DIFF" = "X" ]; then
2829 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2830 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2831 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $NUM_CDDB_MATCHES ] || \
2832 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $NUM_CDDB_MATCHES ] || \
2833 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2834 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
2836 # We parse the 2 choices to diff, store them in temporary files and diff them.
2837 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2838 do_cddbparse "${ABCDETEMPDIR}/cddbread.$PARSECHOICE" > "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE"
2840 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "${ABCDETEMPDIR}/cddbread.diff"
2841 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE1" "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/cddbread.diff"
2842 if [ $(cat "${ABCDETEMPDIR}/cddbread.diff" | wc -l) -ge $LINES ]; then
2843 page "${ABCDETEMPDIR}/cddbread.diff"
2845 cat "${ABCDETEMPDIR}/cddbread.diff" >&2
2849 echo "The diff program was not found in your path. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2851 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2852 # Make sure we get a valid choice
2853 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2854 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; then
2855 echo "Invalid selection. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2859 if [ "$CDCHOICENUM" = "0" ]; then
2860 vecho "Creating empty CDDB template..."
2862 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
2864 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n)
2865 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CDCHOICENUM")
2866 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)" >&2
2867 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM"
2869 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2873 # We need some code to show the selected option when local repository is selected and we have found a match
2874 vecho "Using cached CDDB match..." >&2
2875 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2876 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2877 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2878 CHOICE=$(checkstatus cddb-choice)
2879 if [ "$USELOCALRESP" = "y" ]; then :; else
2880 if [ -n "$CHOICE" ] ; then
2881 case $NUM_CDDB_MATCHES in
2884 echo "Selected template."
2886 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2888 echo "Selected: #$CHOICE"
2889 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2897 # We're noninteractive - pick the first choice.
2898 # But in case we run a previous instance and selected a choice, use it.
2899 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2900 # Show the choice if we are not using the locally stored one
2901 # or when the local search failed to find a match.
2902 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2903 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2904 #if [ "$PREVIOUSCHOICE" ]; then
2905 cat "${ABCDETEMPDIR}/cddbchoices"
2908 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2909 CDCHOICENUM=$PREVIOUSCHOICE
2912 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2914 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2919 if checkstatus cddb-choice >/dev/null; then :; else
2920 echo "abcde: internal error: cddb-choice not recorded." >&2
2923 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2924 CDDBSOURCE=$(cat "${ABCDETEMPDIR}/datasource.$(checkstatus cddb-choice)")
2925 echo -n "Edit selected CDDB data " >&2
2926 if [ "$INTERACTIVE" = "y" ]; then
2927 if [ "$UNKNOWNDISK" = "y" ]; then
2928 echo -n "[Y/n]? " >&2
2930 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2932 echo -n "[y/N]? " >&2
2939 if [ "$EDITCDDB" = "y" ]; then
2940 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2942 # Use the debian sensible-editor wrapper to pick the editor that the
2943 # user has requested via their $EDITOR environment variable
2944 if [ -x "/usr/bin/sensible-editor" ]; then
2945 /usr/bin/sensible-editor "$CDDBDATA"
2946 elif [ -n "$EDITOR" ]; then
2947 if [ -x $(which "${EDITOR%%\ *}") ]; then
2948 # That failed, try to load the preferred editor, starting
2949 # with their EDITOR variable
2950 eval $(echo "$EDITOR") \"$CDDBDATA\"
2952 # If that fails, check for a vi
2953 elif which vi >/dev/null 2>&1; then
2955 elif [ -x /usr/bin/vim ]; then
2956 /usr/bin/vim "$CDDBDATA"
2957 elif [ -x /usr/bin/vi ]; then
2958 /usr/bin/vi "$CDDBDATA"
2959 elif [ -x /bin/vi ]; then
2961 # nano should be on all (modern, i.e., sarge) debian systems
2962 elif which nano >/dev/null 2>&1 ; then
2964 elif [ -x /usr/bin/nano ]; then
2965 /usr/bin/nano "$CDDBDATA"
2966 # mg should be on all OpenBSD systems
2967 elif which mg >/dev/null 2>&1 ; then
2969 elif [ -x /usr/bin/mg ]; then
2970 /usr/bin/mg "$CDDBDATA"
2973 log warning "no editor available. Check your EDITOR environment variable."
2975 # delete editor backup file if it exists
2976 if [ -w "$CDDBDATA~" ]; then
2981 # Some heuristics first. Look at Disc Title, and if it starts with
2982 # "Various", then we'll assume Various Artists
2983 if [ "$(grep -a ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -aEci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2984 echo "Looks like a Multi-Artist CD" >&2
2987 echo -n "Is the CD multi-artist [y/N]? " >&2
2988 if [ "$INTERACTIVE" = "y" ]; then
2995 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2998 # Need NUMTRACKS before cddb-tool will return it:
2999 NUMTRACKS=$(grep -a -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
3000 if [ "$(grep -ac "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3001 # More than 1/2 tracks contain a "/", so guess forward
3003 elif [ "$(grep -ac "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3004 # More than 1/2 contain a "-", so guess forward-dash
3006 elif [ "$(grep -ac "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
3007 # More than 1/2 contain something in parens, so guess trailing-paren
3011 echo "1) Artist / Title" >&2
3012 echo "2) Artist - Title" >&2
3013 echo "3) Title / Artist" >&2
3014 echo "4) Title - Artist" >&2
3015 echo "5) Artist: Title" >&2
3016 echo "6) Title (Artist)" >&2
3017 echo "7) This is a single-artist CD" >&2
3018 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
3019 if [ "$INTERACTIVE" = "y" ]; then
3020 read VARIOUSARTISTSTYLE
3022 echo $DEFAULTSTYLE >&2
3023 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3025 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3026 # If they press Enter, then the default style (0) was chosen
3027 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
3028 echo "Invalid selection. Please choose a number between 1 and 7."
3029 echo -n "Selection [1-7]: "
3030 read VARIOUSARTISTSTYLE
3031 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3033 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3034 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3036 vecho "Selected: $VARIOUSARTISTSTYLE"
3037 case "$VARIOUSARTISTSTYLE" in
3039 VARIOUSARTISTSTYLE=forward
3042 VARIOUSARTISTSTYLE=forward-dash
3045 VARIOUSARTISTSTYLE=reverse
3048 VARIOUSARTISTSTYLE=reverse-dash
3051 VARIOUSARTISTSTYLE=colon
3054 VARIOUSARTISTSTYLE=trailing-paren
3062 echo "variousartists=$VARIOUSARTISTS" >> "${ABCDETEMPDIR}/status"
3063 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "${ABCDETEMPDIR}/status"
3065 if [ "$EDITCDDB" = "y" ] && [ "$CDDBSOURCE" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3066 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3067 # This works but does not have the necessary error checking
3068 # yet. If you are familiar with the CDDB spec
3069 # (see http://www.freedb.org/src/latest/DBFORMAT)
3070 # and can create an error-free entry on your own, then put
3071 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3072 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3073 # your abcde.conf to change the email address submissions are
3076 # submit the modified file, if they want
3077 if [ "$NOSUBMIT" != "y" ]; then
3078 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3080 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3081 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3083 echo -n 'Invalid selection. Please answer "y" or "n": '
3086 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3087 echo -n "Sending..."
3088 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
3095 # User CDDBLOCALPOLICY to find out if we store the file or not...
3096 # Cache edited CDDB entry in the user's cddb dir
3097 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3098 # Make sure the cache directory exists
3099 mkdir -p $CDDBLOCALDIR
3100 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
3103 echo "cddb-edit" >> "${ABCDETEMPDIR}/status"
3107 # try to download CD cover
3111 ALBUMFILE="$(mungealbumname "$DALBUM")"
3112 ARTISTFILE="$(mungeartistname "$DARTIST")"
3113 GENRE="$(mungegenre "$GENRE")"
3114 YEAR=${CDYEAR:-$CDYEAR}
3115 # have we got a musicbrainz mbid or amazon asin?
3116 case "$CDDBMETHOD" in
3118 # try musicbrainz mbid
3119 if [ -s "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)" ]; then
3120 MBID=$(cat "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)")
3121 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3122 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3123 vecho "cover URL: $ALBUMARTURL" >&2
3124 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3125 if [ $? -ne 0 ]; then
3126 vecho "could not download cover from musicbrainz" >&2
3128 if [ -s "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)" ]; then
3129 ASIN=$(cat "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)")
3130 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3131 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3132 vecho "cover URL: $ALBUMARTURL" >&2
3133 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3134 if [ $? -ne 0 ]; then
3135 vecho "could not download cover from amazon" >&2
3137 # Check that size is reasonable; sometimes when there is no cover image
3138 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3139 FILESIZE=$(wc -c < "${ABCDETEMPDIR}/$ALBUMARTFILE")
3140 if [ "$FILESIZE" -lt 1024 ]; then
3141 rm "${ABCDETEMPDIR}/$ALBUMARTFILE"
3142 vecho "could not download cover from amazon" >&2
3146 vecho "no amazon ID found" >&2
3150 vecho "no musicbrainz ID found" >&2
3155 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3156 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3157 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "${ABCDETEMPDIR}/$ALBUMARTFILE" $GLYRCOPTS
3158 if [ $? -ne 0 ]; then
3159 vecho "could not download cover with glyrc" >&2
3164 if [ "$INTERACTIVE" = "y" ]; then
3165 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3166 # display properties of coverart when identify is available
3167 if new_checkexec $IDENTIFY; then
3168 $IDENTIFY $IDENTIFYOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3170 # display coverart when DISPLAY is set and display command is available
3171 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3172 $DISPLAYCMD $DISPLAYCMDOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2 &
3175 # nothing downloaded yet
3176 vecho "automatic album art downloading failed" >&2
3178 # see if the user can find a better album art manually
3179 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3181 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3182 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3184 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3187 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3188 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3190 if [ ! -z "$ALBUMARTURL" ]; then
3191 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3192 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3193 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3194 vecho "unable to download $ALBUMARTURL" >&2
3196 else # it's a local path
3197 cp "$ALBUMARTURL" "${ABCDETEMPDIR}/$ALBUMARTFILE"
3198 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3199 vecho "unable to copy $ALBUMARTURL to ${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3205 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3206 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3207 ALBUMARTURLTYPE=$($IDENTIFY "${ABCDETEMPDIR}/$ALBUMARTFILE" | cut -d' ' -f2)
3208 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3209 if new_checkexec $CONVERT; then
3210 mv "${ABCDETEMPDIR}/$ALBUMARTFILE" "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3211 $CONVERT "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp" $CONVERTOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE"
3212 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3214 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3215 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3219 # copy to target directories
3220 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3221 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3223 # put cover in the same place as the album
3224 if [ "$ONETRACK" = "y" ] ; then
3225 if [ "$VARIOUSARTISTS" = "y" ] ; then
3226 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3228 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3231 if [ "$VARIOUSARTISTS" = "y" ] ; then
3232 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3234 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3237 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3238 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3239 mkdir -p "$FINALALBUMARTDIR"
3240 cp "${ABCDETEMPDIR}/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3242 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3243 echo "get-album-art=$ALBUMARTURL" >> "${ABCDETEMPDIR}/status"
3245 log warning "could not get cover"
3246 echo "get-album-art=none" >> "${ABCDETEMPDIR}/status"
3250 # Optionally embed the albumart downloaded by the getalbumart fuction.
3251 # FIXME: It would be nice to have this also selectable from within the
3252 # FIXME: getalbumart function itself. Andrew
3256 ALBUMFILE="$(mungealbumname "$DALBUM")"
3257 ARTISTFILE="$(mungeartistname "$DARTIST")"
3258 GENRE="$(mungegenre "$GENRE")"
3259 YEAR=${CDYEAR:-$CDYEAR}
3261 # Allow for multiple output formats:
3262 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3264 # Find the output directory for multi track encodes:
3265 if [ "$ONETRACK" != "y" ] ; then
3266 if [ "$VARIOUSARTISTS" = "y" ] ; then
3267 FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
3269 FINDPATH="$(eval echo "$OUTPUTFORMAT")"
3272 # Find the output directory for single track encodes:
3273 if [ "$ONETRACK" = "y" ] ; then
3274 if [ "$VARIOUSARTISTS" = "y" ] ; then
3275 FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3277 FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3281 FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
3284 # Instructions for each format, feel free to add more. It would be nice to
3285 # make the backup directory selectable and perhaps also have an option for
3286 # the bold to simply have the image deleted. Work for another day... Andrew.
3287 if [ -e "$ALBUMARTFILE" ] ; then
3292 "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$i"
3294 mkdir "$FINALDIR"/albumart_backup
3295 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3296 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3301 "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
3303 mkdir "$FINALDIR"/albumart_backup
3304 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3305 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3310 "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
3312 mkdir "$FINALDIR"/albumart_backup
3313 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3314 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3319 "$WVTAG" --write-binary-tag "Cover Art (Front)=@"$ALBUMARTFILE"" "$i"
3321 mkdir "$FINALDIR"/albumart_backup
3322 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3323 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3327 # This technique is drawn from 2 sources (the first link being the primary source):
3328 # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
3329 # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
3330 # In abcde a few steps are used in this sequence:
3332 # 1. Create a 'legal' header for the cover art image
3333 # 2. Makes a copy of the existing tags
3334 # 3. base64 the cover art image
3335 # 4. Copy the original tags + the base64 image back to the original ogg file
3337 # Might need some fine tuning but it is a start for abcde 2.8.2 Andrew.
3338 # FIXME: I am not sure if there is a maximum size for images converted in this
3339 # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
3341 # First some variables we can reuse:
3342 # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
3343 MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
3344 EXPORTTAGS="${ABCDETEMPDIR}/export_ogg_tags"
3345 BUILDHEADER="${ABCDETEMPDIR}/build_header"
3346 # Now build the header, gory details are here:
3347 # https://xiph.org/flac/format.html#metadata_block_picture
3349 printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
3351 printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3353 echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
3354 # Description length. FIXME: I have used 'Cover Image' but I am not sure
3355 # if this is better left as an empty field. Andrew
3356 printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3358 echo -n "Cover Image" >> "$BUILDHEADER"
3360 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3362 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3363 # Picture color depth:
3364 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3365 # Picture color count:
3366 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3368 printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
3369 # cat the image file:
3370 cat "$ALBUMARTFILE" >> "$BUILDHEADER"
3371 # Now process each ogg file by first exporting the original tags then
3372 # appending the cover image and finally copying the whole thing back
3373 # to the original image:
3376 # Make a backup of the existing tags:
3377 "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
3378 # base64 the file and then mix it all together with the exported tags:
3379 echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
3380 # Update the original ogg file with exported tags and the appended base64'd image:
3381 "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
3382 # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
3383 # note that the header file BUILDHEADER will be reused for each file in the loop:
3386 mkdir "$FINALDIR"/albumart_backup
3387 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3388 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3390 *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
3393 vecho "Suitable cover image not found, no embedding done..." >&2
3398 # do_cdread [tracknumber]
3399 # do_cdread onetrack [firsttrack] [lasttrack]
3403 # The commands here don't go through run_command because they're never supposed to be silenced
3404 # return codes need to be doublechecked anyway, however
3405 if [ "$1" = "onetrack" ]; then
3406 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3407 # FIXME # Until then, we grab the whole CD in one track, no matter what
3409 # We need the first and last track for cdda2wav/icedax
3411 LASTTRACK=$(expr $3 + 0)
3412 UTRACKNUM=$FIRSTTRACK
3413 case "$CDROMREADERSYNTAX" in
3414 flac) READTRACKNUMS="-" ;;
3417 # Add a variable to check if tracks are provided in command line and if not, rip the whole CD
3418 # We must make sure to rip from sector 0, both lines below work
3419 # READTRACKNUMS="-- -$LASTTRACK" ;;
3420 READTRACKNUMS="[.0]-" ;;
3421 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3422 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3423 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3429 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3430 if [ "$USEPIPES" = "y" ]; then
3431 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3432 FILEARG="$( eval echo "\$$TEMPARG" )"
3433 PIPE_MESSAGE="and encoding "
3435 WAVDATA="${ABCDETEMPDIR}/track$UTRACKNUM.wav"
3436 case "$CDROMREADERSYNTAX" in
3437 ## FIXME ## Find the cases for flac, to avoid exceptions
3439 FILEARG="--output-name=$WAVDATA"
3446 if [ "$1" = "onetrack" ]; then
3447 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3449 if [ -r "$CDDBDATA" ]; then
3450 getcddbinfo TRACKNAME
3451 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3453 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3456 case "$CDROMREADERSYNTAX" in
3457 ### FIXME ### use an exception for flac, since it uses -o
3458 ### FIXME ### Shall we just use -o $FILEARG ??
3460 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3461 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3462 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3464 if [ "$USEPIPES" = "y" ]; then
3465 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3467 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3471 if [ "$OSFLAVOUR" = "OSX" ] ; then
3472 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3473 diskutil unmount ${CDROM#/dev/}
3474 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3475 CDDA2WAVCDROM="IODVDServices"
3476 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3477 CDDA2WAVCDROM="$CDROMID"
3479 if [ "$CDROMID" = "" ]; then
3480 CDDA2WAVCDROM="$CDROM"
3482 CDDA2WAVCDROM="$CDROMID"
3485 if [ "$USEPIPES" = "y" ]; then
3486 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3488 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3492 # I cannot get USEPIPES to work with dagrab so just this:
3493 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2
3496 if [ "$USEPIPES" = "y" ]; then
3497 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3499 # Write ripped audio data to stdout and redirect to $FILEARG.
3500 # Progress is written to stderr by default and thus >&2 is not required.
3501 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3505 # Find the track's mounted path
3506 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3507 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3508 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3509 # If the file exists, copy it
3510 if [ -e "$FILEPATH" ] ; then
3511 if [ "$USEPIPES" = "y" ]; then
3512 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3514 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3520 if [ "$USEPIPES" = "y" ]; then
3521 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3523 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
3528 # If we get some error or we get some missing wav
3529 # (as long as we dont use pipes)
3530 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3531 # Thank goodness errors is only machine-parseable up to the
3532 # first colon, otherwise this woulda sucked
3533 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3534 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3536 if [ "$USEPIPES" = "y" ]; then
3537 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3539 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3543 if [ "$USEPIPES" = "y" ]; then
3544 echo readencodetrack-$UTRACKNUM >> "${ABCDETEMPDIR}/status"
3546 echo readtrack-$UTRACKNUM >> "${ABCDETEMPDIR}/status"
3548 if [ "$1" = "onetrack" ]; then
3549 echo onetrack >> "${ABCDETEMPDIR}/status"
3555 # No values accepted, only uses env variables
3558 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3559 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3561 echo "abcde: unable to set the device speed" >&2
3567 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3570 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3572 warning) shift ; log warning "$@" ;;
3580 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3583 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3585 warning) shift ; log warning "$@" ;;
3593 # decho outputs a debug message if DEBUG is selected
3596 if [ x"$DEBUG" != "x" ]; then
3597 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3598 DEBUGECHO=$(echo "$@" | tr -d '[]')
3599 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3601 echo >&4 "[DEBUG] $1"
3606 # User-redefinable functions
3607 # Custom filename munging:
3610 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3613 # Custom filename munging specific to track names:
3619 # Custom filename munging specific to artist names:
3625 # Custom filename munging specific to album names:
3631 # Custom genre munging:
3634 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3638 # Empty pre_read function, to be defined in the configuration file.
3645 # Empty post_read function, to be defined in the configuration file.
3652 # Empty post_encode function, to be defined in the configuration file.
3658 ###############################################################################
3661 # Start of execution
3662 ###############################################################################
3667 # Currently three supported options ("musicbrainz", "cddb" for freedb.org and "cdtext")
3668 CDDBMETHOD=musicbrainz
3669 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3670 CDDBSUBMIT=freedb-submit@freedb.org
3672 HELLOINFO="$(whoami)@$(hostname)"
3674 CDDBLOCALPOLICY="always"
3675 CDDBLOCALRECURSIVE="y"
3676 CDDBLOCALDIR="$HOME/.cddb"
3679 # List of fields we parse and show during the CDDB parsing...
3680 SHOWCDDBFIELDS="year,genre"
3683 #CDROMREADERSYNTAX=cdparanoia
3684 ENCODERSYNTAX=default
3686 MP3ENCODERSYNTAX=default
3687 OGGENCODERSYNTAX=default
3688 OPUSENCODERSYNTAX=default
3689 MKAENCODERSYNTAX=default
3690 AIFFENCODERSYNTAX=default
3691 FLACENCODERSYNTAX=default
3692 SPEEXENCODERSYNTAX=default
3693 MPCENCODERSYNTAX=default
3694 WVENCODERSYNTAX=default
3695 TTAENCODERSYNTAX=default
3696 APENCODERSYNTAX=default
3697 MP2ENCODERSYNTAX=default
3698 AACENCODERSYNTAX=default
3699 NORMALIZERSYNTAX=default
3700 CUEREADERSYNTAX=default
3702 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3703 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3704 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3705 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3706 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3707 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3708 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3709 PLAYLISTDATAPREFIX=''
3710 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3711 VAPLAYLISTDATAPREFIX=''
3719 VARIOUSARTISTSTYLE=forward
3726 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3727 # i.e. CDROMID="1,0,0"
3729 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3730 # If we are using the ide-scsi emulation layer, we need to define a "g"
3731 CDPARANOIACDROMBUS="d"
3733 # program paths - defaults to checking your $PATH
3739 XINGMP3ENC=xingmp3enc
3753 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3757 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3767 NEROAACENC=neroAacEnc
3769 # Note that the qaac PATH will almost always require adjustment
3770 # as it is a Windows application being run through Wine. More
3771 # detailed notes in the sample abcde.conf file in the abcde tarball.
3774 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3782 VORBISCOMMENT=vorbiscomment
3784 NEROAACTAG=neroAacTag
3785 ATOMICPARSLEY=AtomicParsley
3789 CDPARANOIA=cdparanoia
3790 CD_PARANOIA=cd-paranoia
3797 MUSICBRAINZ=abcde-musicbrainz-tool
3801 NORMALIZE=normalize-audio
3803 VORBISGAIN=vorbisgain
3807 # For Wavpack replay gain we set both the default of 'track gain'
3808 # as well as this option for 'album gain'. Better media players
3809 # such as vlc can select either or neither. Andrew.
3820 # Options for programs called from abcde:
3823 # These options needed by FFmpeg for tagging and selection of id3v2 version:
3824 # 1. '-write_id3v2 1' allows id3v2 tagging while '-write_id3v2 0' disables tagging
3825 # 2. '-id3v2_version 4' gives version id3v2.4 while '3' gives id3v2.3
3826 AIFFENCOPTS="-write_id3v2 1 -id3v2_version 4"
3838 VORBISGAINOPTS="--album"
3842 # The flac option is a workaround for an error where flac fails
3843 # to encode with error 'floating point exception'. This is flac
3844 # error in get_console_width(), corrected in flac 1.3.1
3846 FLACGAINOPTS="--add-replay-gain"
3853 # True Audio has no useful options but it is here anyway :)
3856 # Monkey's Audio Console (mac) chokes without a mode setting
3857 # so we set one here.
3864 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3865 # we set bitrate here.
3866 FDKAACENCOPTS='--bitrate 192k'
3888 VORBISCOMMENTOPTS="-R"
3889 METAFLACOPTS="--no-utf8-convert"
3894 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3896 # Defaults for album art downloads
3897 ALBUMARTFILE="cover.jpg"
3899 ALBUMARTALWAYSCONVERT="n"
3901 # Default to one process if -j isn't specified
3904 # List of actions to perform - by default, run to completion
3905 ACTIONS=cddb,read,encode,tag,move,clean
3907 # This option is basically for Debian package dependencies:
3908 # List of preferred outputs - by default, run with whatever we have in the path
3909 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:fdkaac:opus
3911 # List of preferred cdromreaders - by default, run whichever we have in the path
3912 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3914 # fd for when `vecho` and `log info` called with redirected stdout
3917 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3918 # Linux/OpenBSD. ftp is user for NetBSD.
3919 # Let's use these checkings to determine the OS flavour, which will be used
3921 if [ X$(uname) = "XFreeBSD" ] ; then
3926 elif [ X$(uname) = "XDarwin" ] ; then
3928 # By default md5sum is not installed, use md5 instead:
3931 # We should have diskutil in OSX, but let's be sure...
3933 CDROMREADERSYNTAX=cddafs
3934 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3936 elif [ X$(uname) = "XOpenBSD" ] ; then
3940 elif [ X$(uname) = "XNetBSD" ] ; then
3944 elif [ X$(uname) = "SunOS" ] ; then
3952 # If CDDBAVAIL is set to n, no CDDB read is done
3956 # But before we get into business, let us chop off any GREP environmental
3961 # Length of the terminal *should* be in $LINES. If it's not, guess at
3962 # a reasonable number instead
3963 if [ -z "$LINES" ]; then
3967 if [ -z "$OUTPUTDIR" ]; then
3971 if [ -z "$WAVOUTPUTDIR" ]; then
3972 WAVOUTPUTDIR="$OUTPUTDIR"
3975 # Load system defaults
3976 if [ -r /etc/abcde.conf ]; then
3979 # Load user preference defaults
3980 if [ -r $HOME/.abcde.conf ]; then
3984 # By this time, we need some HTTPGETOPTS already defined.
3985 # If the user has defined a non-default HTTPGET method, we should not be empty.
3987 if [ "$HTTPGETOPTS" = "" ] ; then
3989 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3990 curl) HTTPGETOPTS="-f -s -L";;
3991 fetch)HTTPGETOPTS="-q -o -";;
3992 ftp) HTTPGETOPTS="-a -V -o - ";;
3993 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3997 # If the CDROM has not been set yet, find a suitable one.
3998 # If this is a devfs system, default to /dev/cdroms/cdrom0
3999 # instead of /dev/cdrom
4000 if [ "$CDROM" = "" ] ; then
4001 if [ -e /dev/cdroms/cdrom0 ]; then
4002 CDROM=/dev/cdroms/cdrom0
4003 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
4004 CDROM=/dev/${BASH_REMATCH[1]}
4005 elif [ -e /dev/cdrom ]; then
4007 elif [ -e /dev/sr0 ]; then
4009 elif [ -e /dev/cd0c ]; then
4011 elif [ -e /dev/acd0c ]; then
4013 elif [ -e /dev/disk1 ]; then
4018 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
4019 # that's changed to a number to allow for more control. Deal with
4020 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
4021 case "$EXTRAVERBOSE" in
4030 # Parse command line options
4031 while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pP:Q:r:s:S:t:T:UvVxX:w:W:z opt ; do
4034 a) ACTIONS="$OPTARG" ;;
4035 A) EXPACTIONS="$OPTARG" ;;
4037 B) GETALBUMART=y ; EMBEDALBUMART=y ;;
4038 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
4039 C) CDDBDISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
4040 d) CDROM="$OPTARG" ;;
4043 e) ERASEENCODEDSTATUS=y ;;
4044 E) ENCODING="$OPTARG" ;;
4049 j) MAXPROCS="$OPTARG" ;;
4052 L) CDDBUSELOCAL=y ;;
4057 o) OUTPUTTYPE="$OPTARG" ;;
4060 Q) CDDBMETHOD="$OPTARG" ;;
4061 r) REMOTEHOSTS="$OPTARG" ;;
4062 R) CDDBLOCALRECURSIVE=y ;;
4063 s) SHOWCDDBFIELDS="$OPTARG" ;;
4064 S) CDSPEEDVALUE="$OPTARG" ;;
4065 t) STARTTRACKNUMBER="$OPTARG" ;;
4066 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
4069 echo "This is abcde v$VERSION."
4070 echo "Usage: abcde [options] [tracks]"
4071 echo "abcde -h for extra help"
4074 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
4076 X) CUE2DISCID="$OPTARG" ;;
4077 w) COMMENT="$OPTARG" ;;
4078 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
4079 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
4080 STARTTRACKNUMBERTAG="y"
4081 COMMENT="CD${OPTARG}"
4082 DISCNUMBER="${OPTARG}"
4084 log error "argument of -W must be integer"
4088 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
4093 shift $(($OPTIND - 1))
4095 # Here it comes the worse part of the whole thing. From here until we start
4096 # ripping, we have a mixture of sanity checks, verifications, default settigs
4097 # and other crazy stuff that interdepends, but hey, someone has to do it.
4099 # If NOCDDBQUERY is set, don't query the CDDB server.
4100 if [ "$NOCDDBQUERY" = "y" ]; then
4104 # If the user specified a flac file, then switch to special flac mode
4105 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
4106 if [ ! -f "$CDROM" ]; then
4107 log error "the defined file for FLAC ripping cannot be found" >&2
4110 vecho warning "switching to flac CDROMREADERSYNTAX..."
4111 CDROMREADERSYNTAX=flac
4112 # We have a builtin version of cue2discid...
4113 case "$CUE2DISCID" in
4115 *) NEEDCUE2DISCID=y;;
4121 # If the user provided a CDDBDISCID, disable eject
4122 if [ -n "${CDDBDISCID}" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
4124 # Check the available cd rippers in the system, from the ones we know.
4125 if [ "$CDROMREADERSYNTAX" = "" ]; then
4126 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
4127 if new_checkexec $DEFAULT_CDROMREADER; then
4128 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
4132 if [ "$CDROMREADERSYNTAX" = "" ]; then
4133 log error "no cdreader found in your PATH"
4134 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4139 # Decide if we can continue.
4140 if [ "$ONETRACK" = "y" ]; then
4141 # FIXME # remove check as soon as we find out about the other readers
4142 case "$CDROMREADERSYNTAX" in
4144 cdparanoia | libcdio) ;;
4145 cdda2wav | icedax) ;;
4147 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
4150 if [ "$BATCHNORM" = "y" ]; then
4151 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
4154 if [ "$NOGAP" = "y" ]; then
4155 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
4158 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
4159 # FIXME # allow ranges of tracks to be selected for onetrack ripping
4160 if [ $# -gt 0 ]; then
4161 log warning "ONETRACK mode selected, grabbing all tracks..."
4164 while [ $# -gt 0 ]; do
4165 # Range parsing code courtesy of Vincent Ho
4166 # Cleaned up to use shell built-ins by Charles Steinkuehler
4167 if [ "${1#*[^0-9-]}" != "$1" ]; then
4168 log error "syntax error while processing track numbers ($1)"
4173 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
4174 TRACKQUEUE="$TRACKQUEUE $RSTART"
4175 RSTART=$(( $RSTART + 1 ))
4182 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
4183 # List of experimental actions: retag,transcode
4185 # Determine what actions are to be done from $ACTIONS and set the
4186 # following environment variables for them:
4198 ## FIXME ## Lets keep compatibility with -M
4199 [ "$DOCUE" != "y" ] && DOCUE=n
4201 for ACTION in $(echo $ACTIONS | tr , \ )
4204 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4205 cue) DOCUE=y ; MAKECUEFILE=y ;;
4208 normalize) DONORMALIZE=y; DOREAD=y;;
4209 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4210 encode) DOENCODE=y; DOREAD=y;;
4211 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4212 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4213 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4214 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4215 playlist) DOCDDB=y; DOPLAYLIST=y;;
4217 getalbumart) GETALBUMART=y;;
4218 embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
4222 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4223 # FIXME # should we abort on error or just inform the user?
4224 log warning "selected both normalize and replaygain actions"
4227 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
4228 case $SHOWCDDBFIELD in
4229 y*|Y*) SHOWCDDBYEAR="y";;
4230 g*|G*) SHOWCDDBGENRE="y";;
4235 # At this point a CDROM has to be defined, so we check it exists.
4236 if [ X"$CDROM" != "X" ] ; then
4237 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
4238 if [ "$OSFLAVOUR" = "FBSD" ]; then
4239 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
4240 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4241 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4245 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
4246 log error "CDROM device cannot be found."
4249 # avoid processing if we are not going to hit the CDROM.
4250 elif [ X"$DOREAD" = "Xy" ]; then
4251 log error "CDROM has not been defined or cannot be found"
4255 # USEPIPES pre-tests, before we get into more serious stuff
4256 # Not compatible with:
4257 # - multiple outputs
4259 # - lowdisk algorithm
4261 if [ X"$USEPIPES" = "Xy" ]; then
4262 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
4263 log error "Unix pipes not compatible with multiple outputs"
4266 if [ X"$DONORMALIZE" = "Xy" ]; then
4267 log error "Unix pipes not compatible with normalizer"
4268 # FIXME # Do we need to exit or shall we just disable the mode?
4271 if [ X"$BATCHNORM" = "Xy" ]; then
4272 log error "Unix pipes not compatible with BATCHNORM encoding"
4275 if [ X"$NOGAP" = "Xy" ]; then
4276 log error "Unix pipes not compatible with NOGAP encoding"
4279 if [ X"$DOENCODE" = "Xn" ]; then
4280 vecho warning "Disabling Unix pipes since we are not encoding!"
4283 if [ X"$LOWDISK" = "Xy" ]; then
4284 log error "Unix pipes not compatible with lowdisk algorithm"
4289 # LOWDISK pre-tests, before we get into more problematic stuff
4290 # Not compatible with anything that needs all the files in the hard disc:
4293 if [ X"$LOWDISK" = "Xy" ]; then
4294 if [ X"$BATCHNORM" = "Xy" ]; then
4295 log error "Unix pipes not compatible with BATCHNORM encoding"
4298 if [ X"$NOGAP" = "Xy" ]; then
4299 log error "Unix pipes not compatible with NOGAP encoding"
4304 # BATCHNORM pre-tests, before we get into serious problems
4305 # Not compatible with
4306 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4307 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4311 # Check the encoding format from the ones available in the system, if nothing has been configured.
4312 if [ X"$OUTPUTTYPE" = "X" ]; then
4313 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4314 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
4315 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
4316 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
4317 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4318 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4322 if [ X"$OUTPUTTYPE" = "X" ]; then
4323 log error "no encoder found in the PATH"
4324 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4329 # Decide which CDROM reader we're gonna use
4330 case "$CDROMREADERSYNTAX" in
4332 CDROMREADER="$CDPARANOIA"
4333 CDROMREADEROPTS="$CDPARANOIAOPTS"
4336 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4337 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4338 CDROMREADER="$CD_PARANOIA"
4339 CDROMREADEROPTS="$CDPARANOIAOPTS"
4342 CDROMREADER="$CDDA2WAV"
4343 CDROMREADEROPTS="$CDDA2WAVOPTS"
4346 CDROMREADER="$DAGRAB"
4347 CDROMREADEROPTS="$DAGRABOPTS"
4351 CDROMREADEROPTS="$PIRDOPTS"
4354 CDROMREADER="$CDDAFS"
4355 CDROMREADEROPTS="$CDDAFSOPTS"
4359 CDROMREADEROPTS="$FLACOPTS"
4363 # There's only one normalize...
4364 case "$NORMALIZERSYNTAX" in
4366 NORMALIZER="$NORMALIZE"
4367 NORMALIZEROPTS="$NORMALIZEOPTS"
4371 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4372 case "$OUTPUTTYPE" in *:*)
4373 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4374 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4376 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4377 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4378 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4379 aiff:*) AIFFENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4380 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4381 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4382 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4383 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4384 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4385 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4386 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4387 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4388 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4391 # Allows commandline selection of options while using multiple outputs.
4392 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4393 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4394 TEMPOUTPUT=${OUTPUT%%:*}
4395 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4397 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4401 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4402 # for flacs and speexenc for speex and mpcenc for mpcs and fdkaac for m4as and
4403 # wavpack for wvs...
4405 # Getting ready for multiple output changes
4406 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4410 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4411 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4412 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4413 OGGOUTPUTCONTAINER=ogg
4416 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4417 OPUSOUTPUTCONTAINER=opus
4420 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4421 MKAOUTPUTCONTAINER=mka
4424 [ "$AIFFENCODERSYNTAX" = "default" ] && AIFFENCODERSYNTAX=ffmpeg
4425 AIFFOUTPUTCONTAINER=aiff
4428 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4429 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4430 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4431 [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
4434 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4435 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4436 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4437 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4438 [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
4441 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4442 # [ "$DOREPLAYGAIN" = "y" ] &&
4445 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4446 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4449 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4451 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4452 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4453 [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
4456 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4457 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4460 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4461 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4462 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4465 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4466 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4467 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4470 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4472 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4473 # compiled without libmp4v2... Andrew.
4476 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=fdkaac
4477 [ "$AACENCODERSYNTAX" = "faac" ] && [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4478 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4479 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4480 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4481 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4482 [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
4485 if [ "$KEEPWAVS" = "y" ]; then
4486 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4490 *) log error "Invalid OUTPUTTYPE defined"
4496 # decide which encoder
4497 case "$MP3ENCODERSYNTAX" in
4499 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4503 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4507 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4508 MP3ENCODER="$BLADEENC"
4511 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4515 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4516 MP3ENCODER="$XINGMP3ENC"
4519 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4520 MP3ENCODER="$MP3ENC"
4523 case "$OGGENCODERSYNTAX" in
4525 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4526 OGGENCODER="$VORBIZE"
4529 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4530 OGGENCODER="$OGGENC"
4533 case "$OPUSENCODERSYNTAX" in
4535 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4536 OPUSENCODER="$OPUSENC"
4539 case "$MKAENCODERSYNTAX" in
4541 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4542 MKAENCODER="$FFMPEG"
4545 case "$AIFFENCODERSYNTAX" in
4547 AIFFENCODEROPTS="${AIFFENCODEROPTSCLI:-$AIFFENCOPTS}"
4548 AIFFENCODER="$FFMPEG"
4551 case "$FLACENCODERSYNTAX" in
4553 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4555 if [ "$DOREPLAYGAIN" = "y" ]; then
4556 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4558 # FLAC streams can be encapsulated on a Ogg transport layer
4559 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4560 log error "FLAC on an Ogg container is not yet supported"
4561 log error "due to problem with adding comments to such files"
4563 FLACOUTPUTCONTAINER=ogg
4565 FLACOUTPUTCONTAINER=flac
4569 case "$SPEEXENCODERSYNTAX" in
4571 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4572 SPEEXENCODER="$SPEEXENC"
4575 case "$MPCENCODERSYNTAX" in
4577 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4578 MPCENCODER="$MPCENC"
4581 case "$WVENCODERSYNTAX" in
4583 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4584 # and in the interests of backward compatibility:
4585 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4586 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4587 WVENCODER="$WAVPACK"
4589 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4590 WVENCODER="$WAVPACK"
4594 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4598 case "$TTAENCODERSYNTAX" in
4600 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4604 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4605 TTAENCODER="$TTAENC"
4608 case "$APENCODERSYNTAX" in
4610 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4614 case "$MP2ENCODERSYNTAX" in
4616 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4617 MP2ENCODER="$TWOLAME"
4620 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4621 MP2ENCODER="$FFMPEG"
4624 case "$AACENCODERSYNTAX" in
4625 # Some elaborate 'if' work to keep backward compatibility for those
4626 # who don't realise that AACENCOPTS does not work with abcde from
4627 # version 2.7 onwards.
4629 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4630 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4633 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4638 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4639 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4640 AACENCODER="$NEROAACENC"
4642 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4643 AACENCODER="$NEROAACENC"
4647 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4648 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4649 AACENCODER="$FDKAAC"
4651 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4652 AACENCODER="$FDKAAC"
4656 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4657 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4660 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4665 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4666 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4667 AACENCODER="$FHGAACENC"
4669 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4670 AACENCODER="$FHGAACENC"
4674 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4675 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4676 AACENCODER="$FFMPEG"
4678 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4679 AACENCODER="$FFMPEG"
4689 TAGGEROPTS="$ID3OPTS"
4694 TAGGEROPTS="$ID3V2OPTS"
4699 TAGGEROPTS="$ID3TAGOPTS"
4703 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4704 # trouble with CDDBPROTO=5 (which we test here) but also
4705 # with cached cddb files in latin1 (which we cannot test).
4706 if [ "$CDDBPROTO" -lt 6 ]; then
4707 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4710 # eyeD3 version 0.7 changed syntax
4711 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4712 # only if it offers the --set-encoding, assume <= 0.6.x
4714 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4716 # anything wrong, any failure, assume >= 0.7
4718 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4722 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4727 # NOGAP is specific to lame. Other encoders fail ...
4728 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4729 log warning "the NOGAP option is specific to lame. Deactivating..."
4734 case "$CUEREADERSYNTAX" in
4736 CUEREADEROPTS="${CDROM}"
4740 CUEREADEROPTS="$MKCUEOPTS ${CDROM}"
4745 # which information retrieval tool are we using?
4751 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4752 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4753 log error "FLAC on an Ogg container is not yet supported"
4754 log error "due to problem with adding comments to such files"
4756 OGGOUTPUTCONTAINER=ogg.ogg
4757 FLACOUTPUTCONTAINER=flac.ogg
4758 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4761 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4763 if [ "$ENCNICE" ]; then
4764 ENCNICE="-n $ENCNICE"
4766 if [ "$READNICE" ]; then
4767 READNICE="-n $READNICE"
4769 if [ "$DISTMP3NICE" ]; then
4770 DISTMP3NICE="-n $DISTMP3NICE"
4773 # Don't check for stuff if it's not needed
4774 if [ "$REMOTEHOSTS" ]; then
4777 if [ "$DONORMALIZE" = "y" ]; then
4780 if [ "$EJECTCD" = "y" ]; then
4783 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4784 # Need an http tool to be able to do CDDB
4790 if [ "$DOCUE" = "y" ]; then
4794 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4795 case "$CDROMREADERSYNTAX" in
4796 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4797 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4798 ### FIXME ### translate "cue2discid" from python to bash
4799 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4804 if [ "$GETALBUMART" = "y" ]; then
4809 ###USEPIPESSUPPORT###
4811 # Rippers with USEPIPE support
4812 PIPERIPPER_cdparanoia="-"
4813 PIPERIPPER_libcdio="-"
4814 # Note that by default in abcde cdda2wav redirects to icedax.
4815 PIPERIPPER_cdda2wav="-"
4816 PIPERIPPER_debug="-"
4817 PIPERIPPER_flac="-c "
4820 # Encoders with USEPIPE support
4823 PIPE_bladeenc="stdin"
4836 # Both neroAacEnc and fdkaac seem to manage without the addition of
4837 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4838 # in this manner. Andrew.
4842 # Figure out if we can use pipes with the ripper/encoder combination
4844 if [ "$USEPIPES" = "y" ]; then
4845 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4848 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4850 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4852 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4854 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4856 PIPEENCODERSVARCHECK="PIPE_$AIFFENCODERSYNTAX" ;;
4858 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4860 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4862 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4864 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4866 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4868 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4870 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4872 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4873 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4874 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4875 log error "no support for pipes with given ripper"
4876 log error "read the FAQ file from the source tarball to get help."
4879 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4880 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4881 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4882 log error "no support for pipes with given encoder"
4883 log error "read the FAQ file from the source tarball to get help"
4888 # Make sure a buncha things exist
4889 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4890 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4891 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER $AIFFENCODER \
4892 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4893 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4894 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4895 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4896 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4897 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4898 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4899 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4900 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4901 ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
4906 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4907 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4908 # these files). The resulting files are actually ADTS streams which belong in an
4909 # aac container and with some version sniffing this is all cleaned up below. If
4910 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4912 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4913 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4914 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4915 echo "WARNING: Your copy of Faac does not have mp4 support"
4916 echo "WARNING: Encoding untagged files to aac..."
4917 # Replace m4a with aac for single and multi-output encodes:
4918 OUTPUTTYPE=$(echo "$OUTPUTTYPE" | sed 's/m4a/aac/')
4920 echo "Using Faac to Tag AAC Tracks..."
4924 # And last but not least, check if we can diff between files. We do not abort,
4925 # since diffing is not critical...
4926 if [ -x $(which $DIFF) ]; then :; else
4927 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4931 ## Now that we have metaflac, check if we need cue2discid
4932 #case $CDROMREADERSYNTAX in
4934 # CDDBTRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4935 # if [ "$CDDBTRACKINFO" = "" ]; then
4936 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4941 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4942 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4943 HTTPGET="$HTTPGET $HTTPGETOPTS"
4945 # Here it used to say:
4946 # One thousand lines in, we can start doing stuff with things
4947 # Well, right now we are at line 3737 ;)
4948 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
4950 # Export needed things so they can be read in this subshell
4951 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4952 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4954 if [ "$DOREAD" = "y" ]; then
4955 # User-definable function to set some things. Use it for
4956 # - closing the CD tray with eject -t
4957 # - set the CD speed value with eject -x
4958 vecho -n "Executing customizable pre-read function... "
4960 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4965 # Get ABCDETEMPDIR created and status file initialized
4968 if [ "$DOCDDB" = "y" ]; then
4969 # start with a sane default:
4970 CDDBLOCALSTATUS=notfound
4971 if [ $CDDBUSELOCAL = "y" ]; then
4974 if checkstatus cddb-choice > /dev/null; then
4978 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4980 for CDDBMETHCHOICE in $(echo "$CDDBMETHOD" | tr -d ' ' | tr , ' ')
4982 addstatus "Lookup method $idx: $CDDBMETHCHOICE"
4984 vecho "Found $NUM_CDDB_MATCHES matches so far"
4985 vecho "Trying lookup method ${CDDBMETHCHOICE}"
4987 # Run all the desired data acquisition methods, in the order
4988 # specified by the user. Each will use its own temporary
4989 # subdirectory, then copy the cddbread.* etc. files up into
4991 case "$CDDBMETHCHOICE" in
5002 echo "Unknown lookup method $CDDBMETHCHOICE. Aborting." >&2
5009 rm -f "${ABCDETEMPDIR}/cddbchoices"
5010 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
5012 if [ $NUM_CDDB_MATCHES = 0 ]; then
5013 # If we got no matches, we need to
5014 # generate a blank CDDB template.
5015 vecho "Unable to find any matches, generating unknown template."
5016 echo "No lookup matches." >> "${ABCDETEMPDIR}/cddbchoices"
5017 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
5018 # List out disc title/author and contents of template
5019 echo ---- Unknown Artist / Unknown Album ---- >> "${ABCDETEMPDIR}/cddbchoices"
5021 for TRACK in $(f_seq_row 1 $TRACKS)
5023 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${ABCDETEMPDIR}/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5025 echo >> "${ABCDETEMPDIR}/cddbchoices"
5026 echo cddb-read-0-complete >> "${ABCDETEMPDIR}/status"
5027 echo cddb-choice=0 >> "${ABCDETEMPDIR}/status"
5028 echo 503 > "${ABCDETEMPDIR}/cddbquery"
5030 # We have matches; create the cddbchoices and cddbquery
5031 # files from all the inputs we have
5032 if [ $NUM_CDDB_MATCHES = 1 ]; then
5033 echo "Retrieved 1 match..." >> "${ABCDETEMPDIR}/cddbchoices"
5034 echo -n "200 " > "${ABCDETEMPDIR}/cddbquery"
5035 cat "${ABCDETEMPDIR}/cddbquery.1" >> "${ABCDETEMPDIR}/cddbquery"
5037 echo "Retrieved $NUM_CDDB_MATCHES matches..." >> "${ABCDETEMPDIR}/cddbchoices"
5038 echo "210 Found exact matches, list follows (until terminating .)" > "${ABCDETEMPDIR}/cddbquery"
5039 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5041 cat "${ABCDETEMPDIR}/cddbquery.$X" >> "${ABCDETEMPDIR}/cddbquery"
5043 echo "." >> "${ABCDETEMPDIR}/cddbquery"
5046 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5048 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.$X" | cut -c8- | tr -d \\r\\n)
5049 SOURCE=$(cat ${ABCDETEMPDIR}/datasource.$X)
5050 echo "#$X ($SOURCE): ---- ${ATITLE} ----" >> "${ABCDETEMPDIR}/cddbchoices"
5051 for TRACK in $(f_seq_row 1 $TRACKS)
5053 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${ABCDETEMPDIR}/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5055 echo >> "${ABCDETEMPDIR}/cddbchoices"
5062 eval "$($CDDBTOOL parse "$CDDBDATA")"
5065 # Before reading tracks, we set the speed of the device
5067 if [ X"$CDSPEEDVALUE" != "X" ]; then
5068 case "$CDROMREADERSYNTAX" in
5069 cdparanoia|libcdio|debug) ;;
5076 # Define the first and last track, since we might need them later in several places
5077 FIRSTTRACK=$( get_first $TRACKQUEUE )
5078 LASTTRACK=$( get_last $TRACKQUEUE )
5080 if [ -f "${ABCDETEMPDIR}/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
5081 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
5082 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
5083 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
5086 if checkstatus onetrack ; then ONETRACK=y ; fi
5088 if [ "$ONETRACK" = "y" ]; then
5089 # Reuse the CUEFILE in case we created it (now or in a previous run)
5090 if CUEFILE=$(checkstatus cuefile); then
5095 # Create playlist if needed (backgroundable) and start reading in tracks
5099 if [ ! "$ONETRACK" = "y" ]; then
5100 if [ "$DOPLAYLIST" = "y" ]; then
5101 echo Creating playlist... >&2
5106 if [ "$GETALBUMART" = "y" ]; then
5110 # For the lowdisk option, only one program is running at once so the encoder
5111 # can be unsilenced right away.
5112 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
5113 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5116 if [ "$ONETRACK" = "y" ]; then
5117 TRACKS="$FIRSTTRACK"
5118 if [ "$USEPIPES" = "y" ]; then
5119 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
5120 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
5123 if checkstatus readtrack-$FIRSTTRACK; then :; else
5124 do_cdread onetrack $FIRSTTRACK $LASTTRACK
5128 for UTRACKNUM in $TRACKQUEUE
5130 if [ "$DOREAD" = "y" ]; then
5131 if [ "$USEPIPES" = "y" ]; then
5132 if checkstatus readencodetrack-$UTRACKNUM; then :; else
5133 # Read, pipe, shut up!
5134 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
5137 if checkstatus readtrack-$UTRACKNUM; then :; else
5138 do_cdread $UTRACKNUM
5140 if [ "$?" != "0" ]; then
5141 # CD read failed - don't give the goahead to
5148 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
5151 # If we are not reading, set the encode output to loud already, so
5152 # that we can see the output of the first track.
5153 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
5154 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5156 echo NEXTTRACK # Get the encoder machine churning again
5157 if [ "$DOREAD" = "y" ]; then
5158 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
5159 until checkstatus encodetrack-$UTRACKNUM
5161 if checkerrors encodetrack-$UTRACKNUM; then
5172 # Now that we're done the encoding can be loud again -
5173 # if we're not using SMP.
5174 if [ "$MAXPROCS" = "1" ]; then
5175 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5178 # All tracks read, start encoding.
5179 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
5183 # Execute the user-defined post_read function before ejecting CD
5186 # We are now finished with the cdrom - it can be safely ejected. Note that
5187 # abcde will not have completed yet.
5188 if [ "$EJECTCD" = "y" ]; then
5189 # We check if the disk we are processing is actually the disk inside the
5190 # CD tray. If not, we do not eject the CD, since it might be so that the
5191 # user ejected it manually.
5192 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
5193 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$CDDBTRACKINFO" ] ; then
5194 # More FreeBSD bits.
5195 if [ X"$(uname)" = X"FreeBSD" ] ; then
5196 # FreeBSD eject uses the EJECT environment variable to name the CDROM
5197 # but in this script EJECT is in the envionment and names the program
5200 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
5201 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
5202 $eject $EJECTOPTS $cd
5203 elif [ X"$(uname)" = X"Darwin" ] ; then
5204 diskutil eject ${CDROM#/dev/} 0
5205 elif [ -x $(which $EJECT) ]; then
5206 $EJECT $EJECTOPTS "$CDROM"
5213 ## Do we need to pre-process
5214 #if [ x"$PREPROCESS" = "x" ] ; then
5217 # for PRETRACKNUM in $TRACKQUEUE
5220 # if [ "$GOAHEAD" = "NO" ]; then break; fi
5222 # until [ $PREPROCEED ]
5224 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
5225 # # all locations are working, wait and try again later
5226 # if [ ! $PREPROCEED ]; then sleep 3; fi
5228 # ( do_preprocess $PRETRACKNUM
5236 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
5238 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
5239 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5240 if [ "$GOAHEAD" != "NO" ]; then
5241 for LASTTRACK in $TRACKQUEUE; do :; done
5242 if checkstatus readtrack-$LASTTRACK; then
5243 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
5244 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
5245 if checkerrors batch-normalize; then exit 1; fi
5247 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
5248 if [ "$DONORMALIZE" = "y" ]; then
5249 for UTRACKNUM in $TRACKQUEUE
5251 if checkstatus readtrack-$UTRACKNUM; then
5252 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5256 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
5257 if checkerrors nogap-encode; then exit 1; fi
5263 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
5264 if [ "$ONETRACK" = "y" ] ; then
5265 TRACKQUEUE="$FIRSTTRACK"
5266 TRACKS="$FIRSTTRACK"
5269 # Do the encoding, including parallelization of remote encoding
5270 # Figure out where each track is going to be encoded
5271 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
5272 if [ "$MAXPROCS" != "0" ]; then
5273 for NUM in $(f_seq_row 1 "$MAXPROCS")
5275 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5279 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5280 for UTRACKNUM in $TRACKQUEUE
5283 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5284 if [ "$GOAHEAD" = "NO" ]; then break; fi
5285 # find out where this track is to be encoded
5286 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5287 # Make sure we have a place to encode this, if not, exit stage right
5288 if [ -z "$ENCODELOCATIONS" ]; then
5294 for LOCATION in $ENCODELOCATIONS
5296 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5297 # check first if a track has ever been assigned to this location
5298 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5299 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5300 if checkerrors encodetrack-$PREVIOUSTRACK; then
5301 for TEMPLOCATION in $ENCODELOCATIONS
5303 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5304 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5307 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5312 # We're still here, this location must have been previously assigned,
5313 # and last completed without error - check if it's done with the
5314 # previous track yet
5315 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
5317 # all locations are working, wait and try again later
5318 if [ ! $PROCEED ]; then sleep 3; fi
5320 # Record the location we're about to encode the next track at
5321 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
5323 # Don't proceed with the rest of the loop if we can't encode
5324 if [ "$ABORT" ]; then continue; fi
5325 ## FIXME ## Add here
5326 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
5327 # Set TRACKNUM, TRACKNAME
5328 if [ -e "$CDDBDATA" ]; then
5329 if [ "$ONETRACK" = "y" ]; then
5331 TRACKNUM="$FIRSTTRACK"
5335 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
5336 getcddbinfo TRACKNAME
5340 # You can't encode a file which needs to be normalized before finishing
5341 # You can't tag a file before it's finished encoding -
5342 # thus all of this is backgrounded together
5344 if [ "$DONORMALIZE" = "y" ]; then
5345 if checkstatus readtrack-$UTRACKNUM; then
5346 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5349 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5350 if checkstatus readtrack-$UTRACKNUM; then
5351 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
5352 if [ "$DONORMALIZE" = "y" ]; then
5353 if checkstatus normalizetrack-$UTRACKNUM; then
5354 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5357 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5361 if [ "$DOTAG" = "y" ]; then
5362 if checkstatus encodetrack-$UTRACKNUM; then
5363 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
5365 # Lets tag the cue file
5366 if checkstatus cleancuefile >/dev/null; then :; else
5367 if checkstatus cuefile >/dev/null ; then
5372 if [ "$DOMOVE" = "y" ]; then
5373 if checkstatus tagtrack-$UTRACKNUM; then
5374 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
5381 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5382 # we'll delete the files they're working on
5383 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5384 ## FIXME ## Check also for files which are encoded using PIPEs.
5385 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5390 for LOCATION in $ENCODELOCATIONS
5392 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5393 # "How can he give us a status update, if he's DEAD?"
5394 if checkstatus encodetrack-$CHECKTRACK; then
5397 # Nothing to see here please go quietly back to your homes
5398 if [ -z "$CHECKTRACK" ]; then continue; fi
5399 # You're still here? Maybe there is something...
5400 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
5403 if [ ! $PROCEED ]; then sleep 5; fi
5406 # If the above didn't catch the stragglers, this will
5408 if [ "$DOREPLAYGAIN" = "y" ]; then
5412 if [ "$EMBEDALBUMART" = "y" ]; then
5416 # Execute the user-defined post_encode function before cleaning up
5419 # Check to see if run_command logged any errors
5420 if [ -f "${ABCDETEMPDIR}/errors" ]; then
5421 log error "The following commands failed to run:"
5422 cat "${ABCDETEMPDIR}/errors"
5426 if [ "$KEEPWAVS" = "y" ];then
5430 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5431 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5432 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5433 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5434 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5435 log warning "The encoded formats does not match with the moved ones"
5436 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
5437 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
5438 log warning "Use \"abcde -a clean -f -C ${CDDBDISCID}\" to force the removal of the remaining data."
5442 if [ "$DOCLEAN" = "y" ]; then
5443 # Wipe all the evidence
5444 # Gimme gimme gimme some more time!
5446 rm -rf "${ABCDETEMPDIR}"
5449 echo "Finished. Not cleaning ${ABCDETEMPDIR}."