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-2018 Steve McIntyre <93sam@@debian.org>
6 # Copyright (c) 2015-2017 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, comma separated:"
24 echo " (cddb,read,getalbumart,embedalbumart,normalize,encode,"
25 echo " tag,move,replaygain,playlist,clean)"
26 #echo "-A Experimental actions (retag, transcode)"
27 echo "-b Enable batch normalization"
28 echo "-B Embed albumart (this also activates getalbumart)"
30 echo " Specify a configuration file (overrides system and user config files)"
32 echo " Specify discid to resume from (only needed if you no longer have the cd)"
34 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
35 echo "-D Debugging mode (equivalent to sh -x abcde)"
36 echo "-e Erase encoded track information from status file"
37 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
38 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
39 echo "-G Get album art by using the 'getalbumart' action"
40 echo "-h This help information"
41 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
42 echo "-j <#> Number of encoder processes to run at once (localhost)"
43 echo "-k Keep the wav tracks for later use"
44 echo "-l Use low disk space algorithm"
45 echo "-L Use local CDDB storage directory"
46 echo "-m Modify playlist to include CRLF endings, to comply with some players"
47 #echo " WARNING: Deprecated. Use \"cue\" action"
48 #echo "-M Create a CUE file"
49 echo "-n No lookup. Don't query CDDB, just create and use template"
50 echo "-N Noninteractive. Never prompt for anything"
51 echo "-o <type1[,type2]...>"
52 echo " Output file type(s), comma separated"
53 echo " (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,mka,wv,ape,mp2,tta,aiff)."
54 echo " Defaults to vorbis"
55 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
56 echo "-P Use UNIX pipes to read+encode without wav files"
57 echo "-Q CD lookup method(s), comma separated"
58 echo " (musicbrainz,cddb,cdtext). Defaults to musicbrainz".
59 echo "-r <host1[,host2]...>"
60 echo " Also encode on these remote hosts"
62 echo " Show fields from the CDDB info (year,genre)"
63 echo "-S <#> Set the CD speed"
64 echo "-t <#> Start the track numbering at a given number"
65 echo "-T <#> Same as -t but modifies tag numbering"
66 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
67 echo "-v Show version number and exit"
68 echo "-V Be a bit more verbose about what is happening behind the scenes"
69 echo "-x Eject CD after all tracks are read"
71 echo " Add a comment to the CD tracks"
72 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
73 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
75 echo "Tracks is a space-delimited list of tracks to grab."
76 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
78 #echo "Double hyphens are used to concatenate tracks"
83 echo "$@" >> "${ABCDETEMPDIR}/status"
86 # log [level] [message]
88 # log outputs the right message in a common format
94 error) >&2 echo "[ERROR] abcde: $@" >&2 ;;
95 warning) >&2 echo "[WARNING] $@" >&2 ;;
96 info) >&4 echo "[INFO] $@" ;;
100 # Functions to replace the need of seq, which is too distribution dependent.
114 if echo "$i" | grep "[[:digit:]]" > /dev/null 2>&1 ; then
122 log error "syntax error while processing track numbers ($i)"
127 # Functions to replace the need of awk {print $1} and {print $NF}
130 if [ X"$1" = "X" ]; then
131 for first in $(cat); do
142 if [ X"$1" = "X" ]; then
143 for stdin in $(cat); do
147 for last in "$@" ; do :; done
152 # checkstatus [blurb]
153 # Returns "0" if the blurb was found, returns 1 if it wasn't
154 # Puts the blurb content, if available, on stdout.
155 # Otherwise, returns "".
158 # Take the last line in the status file if there's multiple matches
160 BLURB=$(grep -E "$PATTERN" "${ABCDETEMPDIR}/status" | tail -n 1)
162 if [ -z "$BLURB" ]; then
167 # See if there's a = in it
168 if ( echo "$BLURB" | grep -q '=' ); then
169 echo "$BLURB" | cut -f2- -d=
175 # checkwarnings [blurb]
176 # Returns "0" if the blurb was found (meaning there was an warning),
177 # returns 1 if it wasn't (yes this is a little backwards).
178 # Does not print the blurb on stdout.
179 # Otherwise, returns "".
182 if [ -e "${ABCDETEMPDIR}/warnings" ]; then :; else
185 # Take the last line in the status file if there's multiple matches
187 BLURB=$(grep -E "$PATTERN" "${ABCDETEMPDIR}/warnings" | tail -n 1)
189 if [ -z "$BLURB" ]; then
190 # negative, we did not have a negative...
193 # affirmative, we had a negative...
198 # checkerrors [blurb]
199 # Returns "0" if the blurb was found (meaning there was an error),
200 # returns 1 if it wasn't (yes this is a little backwards).
201 # Does not print the blurb on stdout.
202 # Otherwise, returns "".
205 if [ -e "${ABCDETEMPDIR}/errors" ]; then :; else
208 # Take the last line in the status file if there's multiple matches
210 BLURB=$(grep -E "$PATTERN" "${ABCDETEMPDIR}/errors" | tail -n 1)
212 if [ -z "$BLURB" ]; then
213 # negative, we did not have a negative...
216 # affirmative, we had a negative...
222 # Display a file. If it's too long to fit the current terminal size,
223 # find the right pager in the system and use it
227 local NUM_LINES=$(wc -l < "$PAGEFILE")
229 # Is the text long enough to need a pager?
230 if [ "$NUM_LINES" -ge $LINES ]; then
232 # Use the debian sensible-pager wrapper to pick the pager user
233 # has requested via their $PAGER environment variable
234 if [ -x "/usr/bin/sensible-pager" ]; then
235 /usr/bin/sensible-pager "$PAGEFILE"
236 elif [ -x "$PAGER" ]; then
237 # That failed, try to load the preferred pager, starting
238 # with their PAGER variable
240 # If that fails, check for less
241 elif [ -x /usr/bin/less ]; then
242 /usr/bin/less -f "$PAGEFILE"
243 # more should be on all UNIX systems
244 elif [ -x /bin/more ]; then
245 /bin/more "$PAGEFILE"
247 # No bananas, just cat the thing
251 # No, just cat the thing
256 # run_command [blurb] [command...]
257 # Runs a command, silently if necessary, and updates the status file
263 # See if this is supposed to be silent
264 if [ "$(checkstatus encode-output)" = "loud" ]; then
268 # Special case for SMP, since
269 # encoder output is never displayed, don't mute echos
270 if [ -z "$BLURB" ] && [ "$MAXPROCS" != "1" ]; then
279 normalize|normalize-audio)
280 if [ "$RETURN" = "2" ]; then
281 # File was already normalized.
286 if [ "$RETURN" != "0" ]; then
287 # Put an error in the errors file. For various reasons we
288 # can't capture a copy of the program's output but we can
289 # log what we attempted to execute and the error code
290 # returned by the program.
291 if [ "$BLURB" ]; then
294 echo "${TWEAK}returned code $RETURN: $@" >> "${ABCDETEMPDIR}/errors"
295 return $RETURN # Do not pass go, do not update the status file
297 if [ "$BLURB" ]; then
298 echo "$BLURB" >> "${ABCDETEMPDIR}/status"
302 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
303 # distributed under the terms of the GNU GPL v2 or later, at your option
305 # Function to determine if a word contains a slash.
314 # Function to give the relative path from one file to another.
315 # Usage: relpath fromfile tofile
316 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
317 # (the result would be Album/Song.mp3)
318 # Output is relative path to $2 from $1 on stdout
320 # This code has the following restrictions:
321 # Multiple ////s are not collapsed into single /s, with strange effects.
322 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
323 # If FR is a directory it must have a trailing /
331 /*) ;; # No processing is needed for absolute paths
333 # Loop through common prefixes, ignoring them.
334 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
336 FR="$(echo "$FR" | cut -d/ -f2-)"
337 TO="$(echo "$TO" | cut -d/ -f2-)"
339 # Loop through directory portions left in FR, adding appropriate ../s.
342 FR="$(echo "$FR" | cut -d/ -f2-)"
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X=$(echo "$@" | cut -d' ' -f2)
356 WHICH=$(which "$X" 2>/dev/null)
357 if [ -z "$WHICH" ]; then
359 elif [ ! -x "$WHICH" ]; then
368 if [ ! "$@" = "" ]; then
369 # Cut off any command-line option we added in
370 X=$(echo "$@" | cut -d' ' -f2)
371 # Test for built-in abcde.function
372 [ "$X" != "${X#abcde.}" ] && type "$X" >/dev/null 2>&1 && return
373 WHICH=$(which "$X" 2>/dev/null)
374 if [ -z "$WHICH" ]; then
375 log error "$X is not in your path." >&2
376 log info "Define the full path to the executable if it exists on your system." >&2
377 if [ -e /etc/debian_version ] ; then
380 MISSING_PACKAGE=vorbis-tools
382 lame|flac|cd-discid|eject|mkcue|icedax|glyrc)
386 log info "Hint: sudo apt-get install $MISSING_PACKAGE" >&2
389 elif [ ! -x "$WHICH" ]; then
390 log error "$X is not executable." >&2
396 # diffentries <filename> <max_value> <entry1>,<entry2>
397 # max_value: the range of entries goes from 1 to <max_value>
402 local CDDBDIFFCHOICES=$1
404 local CDDBDIFFCHOICE="$@"
405 if [ ! X"$DIFF" = "X" ]; then
406 PARSECHOICE1=$(echo "$CDDBDIFFCHOICE" | cut -d"," -f1 | xargs printf %d 2>/dev/null)
407 PARSECHOICE2=$(echo "$CDDBDIFFCHOICE" | cut -d"," -f2 | xargs printf %d 2>/dev/null)
408 if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$CDDBDIFFCHOICES" ] || \
409 [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$CDDBDIFFCHOICES" ] || \
410 [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
411 echo "Invalid diff range." >&2
412 echo "Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
414 # We parse the 2 choices to diff, store them in temporary files and diff them.
415 for PARSECHOICE in $(echo "$CDDBDIFFCHOICE" | tr , \ ); do
416 do_cddbparse "${ABCDETEMPDIR}/$FILENAME.$PARSECHOICE" > "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE"
418 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "${ABCDETEMPDIR}/$FILENAME.diff"
419 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE1" \
420 "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/$FILENAME.diff"
421 page "${ABCDETEMPDIR}/$FILENAME.diff"
424 echo "The diff program was not found in your path." >&2
425 echo "Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
430 # Finds an specific field from cddbinfo
435 TRACKNAME="$(grep -a "^TTITLE$CDDBTRACKNUM=" "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
438 TRACKNAME="$(grep -a "^TTITLE$CDDBTRACKNUM=" "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
441 grep -a "^EXTT$CDDBTRACKNUM=" "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
447 # Get the track number we are going to use for different actions
450 if [ -n "$STARTTRACKNUMBER" ] ; then
451 # Get the trackpadding from the current track, also trim whitespace for MacOSX
452 CURRENTTRACKPADDING=$(echo -n "$UTRACKNUM" | wc -c | tr -d ' ')
453 TRACKNUM=$( printf %0."${CURRENTTRACKPADDING}"d $(("${UTRACKNUM}" + "${STARTTRACKNUMBER}" - "${FIRSTTRACK}")))
455 TRACKNUM="${UTRACKNUM}"
461 # Calculate cddb disc ids without requiring specialized helper programs.
462 # largely copied from cd-discid and musicbrainz examples. some of the steps
463 # don't make sense, but they're necessary to match the ids generated by other
466 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
467 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
468 # 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
469 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
470 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
471 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
473 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
476 if [ X"$LEADOUT" = "X" ]; then
477 log warning "Error trying to calculate disc ids without lead-out information."
481 # default to a two second lead-in
483 LEADIN=${LEADIN:=150}
485 # number of cdframes per second
488 # reset cddb checksum for cddb disc-id calululation
492 for OFFSET in $OFFSETS
494 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
496 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
497 while [ $OFFSETTIME -gt 0 ]; do
498 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
499 OFFSETTIME=$(($OFFSETTIME / 10))
504 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
506 PREGAP=$(echo $OFFSETS | cut -f1 -d' ')
507 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
509 vvecho "makeids: PREGAP $PREGAP, LEADIN $LEADIN, LEADOUT $LEADOUT"
511 # Calculate both the cddb discid *and* the musicbrainz discid
512 # now. We'll use the cddb discid for reference in most cases
513 # for consistency, but we also have the musicbrainz discid for
515 printf -v CDDBDISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
516 CDDBTRACKINFO="${CDDBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
520 # FIXME: don't assume the first track is 1
521 MBDISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $(($PREGAP + $LEADOUT)) $OFFSETS)
523 if [ $error != 0 ]; then
524 log error "$MUSICBRAINZ failed to run; ABORT"
527 MBTRACKINFO="${MBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
534 if checkstatus replaygain; then :; else
535 run_command "" echo "Adding replaygain information..."
536 for TMPOUTPUT in $( echo "$OUTPUTTYPE" | tr , \ )
540 OUTPUT=$OGGOUTPUTCONTAINER
543 OUTPUT=$OPUSOUTPUTCONTAINER
546 OUTPUT=$FLACOUTPUTCONTAINER
554 for UTRACKNUM in $TRACKQUEUE
556 CDDBTRACKNUM=$(("$UTRACKNUM" - 1))
557 getcddbinfo TRACKNAME
559 TRACKFILE="$(mungetrackname "$TRACKNAME")"
560 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
561 ALBUMFILE="$(mungealbumname "$DALBUM")"
562 GENRE="$(mungegenre "$GENRE")"
563 YEAR=${CDYEAR:-$CDYEAR}
565 if [ "$ONETRACK" = "y" ]; then
566 if [ "$VARIOUSARTISTS" = "y" ]; then
567 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
569 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
572 if [ "$VARIOUSARTISTS" = "y" ]; then
573 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
575 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
578 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
579 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
583 run_command "replaygain-flac" nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
586 run_command "replaygain-vorbis" nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
589 run_command "replaygain-mp3" nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
592 run_command "replaygain-mpc" nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
595 run_command "replaygain-wv" nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
600 if checkerrors "replaygain-.{3,6}"; then :; else
601 run_command "replaygain" true
606 # This code splits the a Various Artist track name from one of the following
609 # forward: Artist / Track
610 # forward-dash: Artist - Track
611 # reverse: Track / Artist
612 # reverse-dash: Track - Artist
613 # colon: Artist: Track
614 # trailing-paren: Artist (Track)
617 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
620 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
621 case "$VARIOUSARTISTSTYLE" in
623 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
624 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
625 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
628 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
629 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
630 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
633 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
634 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
635 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
638 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
639 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
640 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
643 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
644 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
645 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
648 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
649 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
650 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
653 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
654 TRACKARTIST="Various"
656 TRACKARTIST="$DARTIST"
661 local genre=$(echo "${@}" | tr 'A-Z' 'a-z')
665 "classic rock") id=1 ;;
683 "industrial") id=19 ;;
684 "alternative") id=20 ;;
686 "death metal") id=22 ;;
688 "soundtrack") id=24 ;;
689 "euro-techno") id=25 ;;
693 "jazz+funk") id=29 ;;
696 "classical") id=32 ;;
697 "instrumental") id=33 ;;
701 "sound clip") id=37 ;;
704 "alt. rock") id=40 ;;
709 "meditative") id=45 ;;
710 "instrum. pop") id=46 ;;
711 "instrum. rock") id=47 ;;
715 "techno-indust.") id=51 ;;
716 "electronic") id=52 ;;
718 "eurodance") id=54 ;;
720 "southern rock") id=56 ;;
725 "christian rap") id=61 ;;
726 "pop/funk"|"pop / funk") id=62 ;;
728 "native american") id=64 ;;
731 "psychadelic") id=67 ;;
733 "showtunes") id=69 ;;
737 "acid punk") id=73 ;;
738 "acid jazz") id=74 ;;
742 "rock & roll") id=78 ;;
743 "hard rock") id=79 ;;
745 "folk/rock") id=81 ;;
746 "national folk") id=82 ;;
753 "bluegrass") id=89 ;;
754 "avantgarde") id=90 ;;
755 "gothic rock") id=91 ;;
756 "progress. rock") id=92 ;;
757 "psychadel. rock") id=93 ;;
758 "symphonic rock") id=94 ;;
759 "slow rock") id=95 ;;
762 "easy listening") id=98 ;;
768 "chamber music") id=104 ;;
770 "symphony") id=106 ;;
771 "booty bass") id=107 ;;
773 "porn groove") id=109 ;;
775 "slow jam") id=111 ;;
779 "folklore") id=115 ;;
781 "power ballad") id=117 ;;
782 "rhythmic soul") id=118 ;;
783 "freestyle") id=119 ;;
785 "punk rock") id=121 ;;
786 "drum solo") id=122 ;;
787 "a capella") id=123 ;;
788 "euro-house") id=124 ;;
789 "dance hall") id=125 ;;
791 "drum & bass") id=127 ;;
792 "club-house") id=128 ;;
793 "hardcore") id=129 ;;
797 "negerpunk") id=133 ;;
798 "polsk punk") id=134 ;;
800 "christian gangsta rap") id=136 ;;
801 "heavy metal") id=137 ;;
802 "black metal") id=138 ;;
803 "crossover") id=139 ;;
804 "contemporary christian")id=140 ;;
805 "christian rock") id=141 ;;
806 "merengue") id=142 ;;
808 "thrash metal") id=144 ;;
811 "synthpop") id=147 ;;
812 "rock/pop"|"rock / pop") id=148 ;;
819 # do_tag [tracknumber]
820 # id3 tags a filename
822 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
823 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
826 COMMENTOUTPUT="$(eval echo "${COMMENT}")"
827 if [ -z "$COMMENTOUTPUT" ]; then
828 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
830 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
831 run_command "" echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
832 # If we want to start the tracks with a given number, we need to modify the
833 # TRACKNUM value before evaluation
834 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
837 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
841 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
842 GENREID=$(do_getgenreid "${CDGENRE}")
843 # Set TPE2 in case we have a Various Artists rip.
845 if [ "$VARIOUSARTISTS" = "y" ]; then
851 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
852 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
853 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
854 -y "$CDYEAR" -g "$GENREID" \
855 -T "${TRACKNUM:-$1}" \
856 "${ABCDETEMPDIR}/track$1.$OUTPUT"
859 # FIXME # track numbers in mp3 come with 1/10, so we cannot
860 # happily substitute them with $TRACKNUM
861 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
862 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
863 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
864 -y "$CDYEAR" -g "$GENREID" \
865 -T "${TRACKNUM:-$1}/$TRACKS" \
866 ${TPE2:+--TPE2 "$TPE2"} \
867 "${ABCDETEMPDIR}/track$1.$OUTPUT"
870 # FIXME # track numbers in mp3 come with 1/10, so we cannot
871 # happily substitute them with $TRACKNUM
872 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
873 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
874 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
875 -y "$CDYEAR" -g "$GENREID" \
876 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
877 "${ABCDETEMPDIR}/track$1.$OUTPUT"
880 # FIXME # track numbers in mp3 come with 1/10, so we cannot
881 # happily substitute them with $TRACKNUM
883 eyed3_06) addopts=( \
884 ${ENCODING:+--set-encoding="$ENCODING"} \
885 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
886 # We set 'recording-date' so the date tag will show
887 # in Audacious, vlc and friends... Andrew.
888 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
889 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
892 ${ENCODING:+--encoding="$ENCODING"} \
893 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
894 # We set 'recording-date' so the date tag will show
895 # in Audacious, vlc and friends... Andrew.
896 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
897 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
900 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $TAGGER $TAGGEROPTS \
902 -a "$TRACKARTIST" -t "$TRACKNAME" \
903 -G "$GENREID" -n "${TRACKNUM:-$1}" \
904 ${TRACKNUM:+-N "$TRACKS"} \
906 "${ABCDETEMPDIR}/track$1.$OUTPUT"
909 log error "Internal error: ID3SYNTAX has an illegal value"
915 case "$OGGENCODERSYNTAX" in
917 # vorbiscomment can't do in-place modification, mv the file first
918 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ] && \
919 [ ! -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
920 mv "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" \
921 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
925 # https://www.xiph.org/vorbis/doc/v-comment.html
927 echo ARTIST="$TRACKARTIST"
929 echo TITLE="$TRACKNAME"
930 if [ -n "$CDYEAR" ]; then
933 if [ -n "$CDGENRE" ]; then
934 echo GENRE="$CDGENRE"
936 echo TRACKNUMBER="${TRACKNUM:-$1}"
937 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
938 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
939 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
940 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
941 echo TRACKTOTAL="${TRACKS}"
942 if [ -n "$DISCNUMBER" ]; then
943 echo DISCNUMBER="$DISCNUMBER"
945 echo CDDB="${CDDBDISCID}"
946 if [ "$(eval echo ${COMMENT})" != "" ]; then
947 case "$COMMENTOUTPUT" in
948 *=*) echo "$COMMENTOUTPUT";;
949 *) echo COMMENT="$COMMENTOUTPUT";;
952 ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
953 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
954 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
955 "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
956 # Doublecheck that the commented file was created
957 # successfully before wiping the original
958 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ]; then
959 rm -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
961 mv "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
962 "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
968 run_command "tagtrack-$OUTPUT-$1" true
971 run_command "tagtrack-$OUTPUT-$1" true
974 run_command "tagtrack-$OUTPUT-$1" true
978 echo ARTIST="$TRACKARTIST"
980 echo TITLE="$TRACKNAME"
981 if [ -n "$CDYEAR" ]; then
984 if [ -n "$CDGENRE" ]; then
985 echo GENRE="$CDGENRE"
987 echo TRACKNUMBER="${TRACKNUM:-$1}"
988 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
989 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
990 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
991 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
992 echo TRACKTOTAL="${TRACKS}"
993 if [ -n "$DISCNUMBER" ]; then
994 echo DISCNUMBER="$DISCNUMBER"
996 echo CDDB="${CDDBDISCID}"
997 if [ -n "$(eval echo "${COMMENT}")" ]; then
998 case "$COMMENTOUTPUT" in
999 *=*) echo "$COMMENTOUTPUT";;
1000 *) echo COMMENT="$COMMENTOUTPUT";;
1003 ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $METAFLAC $METAFLACOPTS \
1004 ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} \
1005 --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
1008 run_command "tagtrack-$OUTPUT-$1" true
1011 run_command "tagtrack-$OUTPUT-$1" true
1014 run_command "tagtrack-$OUTPUT-$1" true
1017 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
1018 # Console port (mac) used for encoding does not have the ability to tag.
1019 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$APETAG" -i "${ABCDETEMPDIR}/track$1.ape" -m overwrite \
1020 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track="${TRACKNUM:-$1}" \
1021 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
1024 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
1025 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
1026 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
1027 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
1028 -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
1029 -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
1030 ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1031 "${ABCDETEMPDIR}/track$1.mp2"
1034 run_command "tagtrack-$OUTPUT-$1" true
1037 case "$AACENCODERSYNTAX" in
1039 # We will use inline tagging...
1040 run_command "tagtrack-$OUTPUT-$1" true
1043 # Tag post encode with neroAacTag...
1044 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$NEROAACTAG" \
1045 "${ABCDETEMPDIR}/track$1.m4a" \
1046 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" \
1047 -meta:title="$TRACKNAME" -meta:track="${TRACKNUM:-$1}" \
1048 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1051 run_command "tagtrack-$OUTPUT-$1" true
1054 run_command "tagtrack-$OUTPUT-$1" true
1057 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1058 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1059 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$ATOMICPARSLEY" \
1060 "${ABCDETEMPDIR}/track$1.m4a" --artist="$TRACKARTIST" --album="$DALBUM" \
1061 --title="$TRACKNAME" --tracknum="${TRACKNUM:-$1}" \
1062 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" \
1063 $ATOMICPARSLEYOPTS --overWrite
1066 run_command "tagtrack-$OUTPUT-$1" true
1071 # We use mid3v2 tagging for True Audio:
1072 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
1073 -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
1074 -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
1075 ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} "${ABCDETEMPDIR}/track$1.tta"
1078 run_command "tagtrack-$OUTPUT-$1" true
1082 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1083 run_command "tagtrack-$1" true
1089 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1092 # The commands here don't go through run_command because they're never
1093 # supposed to be silenced
1094 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1095 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1099 case "$MP3ENCODERSYNTAX" in
1102 cd "${ABCDETEMPDIR}"
1104 for THISTRACKNUM in $TRACKQUEUE
1106 TRACKFILES="$TRACKFILES track$THISTRACKNUM.wav"
1108 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1110 if [ "$RETURN" != "0" ]; then
1111 echo "nogap-encode: $MP3ENCODER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1113 for THISTRACKNUM in $TRACKQUEUE
1115 run_command "encodetrack-$OUTPUT-$THISTRACKNUM" true
1124 if checkerrors "nogap-encode"; then :; else
1125 if [ ! "$KEEPWAVS" = "y" ] ; then
1126 if [ ! "$KEEPWAVS" = "move" ] ; then
1131 # Other encoders fall through to normal encoding as the tracks have not
1132 # been entered in the status file.
1135 # do_encode [tracknumber] [hostname]
1136 # If no hostname is specified, encode locally
1138 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1139 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1142 if [ "$USEPIPES" = "y" ]; then
1145 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1148 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1151 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1154 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1157 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1160 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1163 TEMPARG="PIPE_$SPEEXENCODER"
1166 TEMPARG="PIPE_$MPCENCODER"
1169 TEMPARG="PIPE_$WVENCODERSYNTAX"
1172 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1175 TEMPARG="PIPE_$AACENCODERSYNTAX"
1178 TEMPARG="PIPE_$AACENCODERSYNTAX"
1181 IN="$( eval echo "\$$TEMPARG" )"
1183 IN="${ABCDETEMPDIR}/track$1.wav"
1185 # We need IN to proceed, if we are not using pipes.
1186 if [ -s "$IN" ] || [ X"$USEPIPES" = "Xy" ] ; then
1187 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1189 case "$TMPOUTPUT" in
1191 OUTPUT=$OGGOUTPUTCONTAINER
1194 OUTPUT=$OPUSOUTPUTCONTAINER
1197 OUTPUT=$MKAOUTPUTCONTAINER
1200 OUTPUT=$AIFFOUTPUTCONTAINER
1203 OUTPUT=$FLACOUTPUTCONTAINER
1209 OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1210 if [ "$NOGAP" = "y" ] && checkstatus "encodetrack-$OUTPUT-$1" ; then
1213 if [ X"$USEPIPES" = "Xy" ]; then
1215 # We need a way to store the creation of the files when using PIPES
1216 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1217 # When piping it does not make sense to have a higher nice for
1218 # reading than for encoding, since it will be hold by the
1219 # encoding process. Setting an effective nice, to calm down a
1220 # bit the reading process.
1221 EFFECTIVE_NICE=$READNICE
1223 run_command "" echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1224 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1225 EFFECTIVE_NICE=$ENCNICE
1231 case "$MP3ENCODERSYNTAX" in
1232 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1233 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1234 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1235 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1239 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1246 case "$OGGENCODERSYNTAX" in
1247 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1248 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1252 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1259 case "$OPUSENCODERSYNTAX" in
1261 # Tag the file at encode time, as it can't be done after encoding.
1262 if [ "$DOTAG" = "y" ]; then
1263 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS \
1264 --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
1265 --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1266 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1268 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1274 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1279 case "$MKAENCODERSYNTAX" in
1281 if [ "$DOTAG" = "y" ]; then
1282 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS \
1283 -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
1284 -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
1285 -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
1286 -metadata comment="$COMMENT" "$OUT"
1288 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1294 case "$AIFFENCODERSYNTAX" in
1296 if [ "$DOTAG" = "y" ]; then
1297 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS \
1298 -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
1299 -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
1300 -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
1301 -metadata comment="$COMMENT" "$OUT"
1303 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1311 case "$FLACENCODERSYNTAX" in
1312 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1317 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1318 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1323 if [ -n "$(eval echo "${COMMENT}")" ]; then
1326 *) COMMENT="COMMENT=$COMMENT" ;;
1329 # Tag the file at encode time, as it can't be done after encoding.
1330 if [ "$DOTAG" = "y" ]; then
1331 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS \
1332 --author "$TRACKARTIST" --title "$TRACKNAME" \
1333 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1335 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1339 # Tag the file inline at encode time.
1340 if [ "$DOTAG" = "y" ]; then
1341 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS \
1342 --artist "$TRACKARTIST" --album "$DALBUM" \
1343 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
1344 --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1346 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1350 case "$TTAENCODERSYNTAX" in
1351 # tta is the newer version with a small syntax change...
1353 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1356 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1361 case "$WVENCODERSYNTAX" in
1363 if [ "$DOTAG" = "y" ]; then
1364 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS \
1365 -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1366 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" \
1367 -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1369 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1373 if [ "$DOTAG" = "y" ]; then
1374 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS \
1375 -metadata artist="$TRACKARTIST" \
1376 -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
1377 -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
1378 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1380 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1386 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1389 case "$MP2ENCODERSYNTAX" in
1391 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1394 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1399 # aac container is only used to catch faac encoded files where faac
1400 # is compiled without mp4 support (with libmp4v2).
1401 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1404 case "$AACENCODERSYNTAX" in
1406 if [ "$DOTAG" = "y" ]; then
1407 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
1408 --artist "$TRACKARTIST" --album "$DALBUM" \
1409 --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
1410 --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1412 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1416 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1419 if [ "$DOTAG" = "y" ]; then
1420 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
1421 --artist "$TRACKARTIST" --album "$DALBUM" \
1422 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
1423 --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1425 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1429 if [ "$DOTAG" = "y" ]; then
1430 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS \
1431 --artist "$TRACKARTIST" --album "$DALBUM" \
1432 --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
1433 --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1435 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1439 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1442 if [ "$DOTAG" = "y" ]; then
1443 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" \
1444 $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1445 -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
1446 -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
1447 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1449 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1455 # In case of wav output we need nothing. Just keep the wavs.
1456 # But we need the following to allow full logging and subsequent
1457 # successful cleaning of ${ABCDETEMPDIR}.
1458 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1463 # Only remove .wav if the encoding succeeded
1464 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1465 run_command "encodetrack-$1" true
1466 if [ ! "$KEEPWAVS" = "y" ] ; then
1467 if [ ! "$KEEPWAVS" = "move" ] ; then
1473 run_command "" echo "HEH! The file we were about to encode disappeared:"
1474 run_command "" echo ">> $IN"
1475 run_command "encodetrack-$1" false
1479 # do_preprocess [tracknumber]
1481 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX,
1482 # OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1485 # IN="${ABCDETEMPDIR}/track$1.wav"
1486 # # We need IN to proceed.
1487 # if [ -s "$IN" ] ; then
1488 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1490 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1491 # run_command "" echo "Pre-processing track $1 of $TRACKS..."
1492 # case "$POSTPROCESSFORMAT" in
1494 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $WAV_PRE $IF $OF ;;
1496 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $MP3_PRE $IF $OF ;;
1498 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $OGG_PRE $IF $OF ;;
1500 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $FLAC_PRE $IF $OF ;;
1502 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $SPX_PRE $IF $OF ;;
1505 # # Only remove .wav if the encoding succeeded
1506 # if checkerrors "preprocess-(.{3,4})-$1"; then
1507 # run_command "preprocess-$1" false
1509 # run_command "preprocess-$1" true
1512 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1513 # echo "HEH! The file we were about to pre-process disappeared:"
1516 # run_command "preprocess-$1" false
1521 # do_postprocess [tracknumber]
1523 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1524 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1527 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1529 # IN="${ABCDETEMPDIR}/track$1.$POSTPROCESSFORMAT"
1530 # # We need IN to proceed.
1531 # if [ -s "$IN" ] ; then
1532 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1533 # run_command "" echo "Post-processing track $1 of $TRACKS..."
1534 # case "$POSTPROCESSFORMAT" in
1536 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $MP3_POST $IF $OF ;;
1538 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $OGG_POST $IF $OF ;;
1540 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $FLAC_POST $IF $OF ;;
1542 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $SPX_POST $IF $OF ;;
1544 # # Only remove .wav if the encoding succeeded
1545 # if checkerrors "postprocess-(.{3,4})-$1"; then
1546 # run_command "postprocess-$1" false
1548 # run_command "postprocess-$1" true
1551 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1552 # echo "HEH! The file we were about to post-process disappeared:"
1555 # run_command "postprocess-$1" false
1570 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1574 # The commands here don't go through run_command because they're never supposed to be silenced
1575 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1577 cd "${ABCDETEMPDIR}"
1580 for UTRACKNUM in $TRACKQUEUE
1582 TRACKFILES="$TRACKFILES track$UTRACKNUM.mp3"
1584 # FIXME # Hard-coded batch option!
1585 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1587 if [ "$RETURN" != "0" ]; then
1588 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1590 for UTRACKNUM in $TRACKQUEUE
1592 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1598 # do_batch_normalize
1600 # NORMALIZER, NORMALIZEROPTS
1601 do_batch_normalize ()
1603 # The commands here don't go through run_command because they're never supposed to be silenced
1604 echo "Batch normalizing tracks: $TRACKQUEUE"
1606 cd "${ABCDETEMPDIR}"
1609 for UTRACKNUM in $TRACKQUEUE
1611 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1613 # XXX: Hard-coded batch option!
1614 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1616 if [ "$RETURN" != "0" ]; then
1617 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1619 for UTRACKNUM in $TRACKQUEUE
1621 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1627 # do_normalize [tracknumber]
1629 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1632 IN="${ABCDETEMPDIR}/track$1.wav"
1633 if [ -e "$IN" ] ; then
1634 run_command "" echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1635 run_command "normalizetrack-$1" $NORMALIZER $NORMALIZEROPTS "$IN"
1637 if [ "$(checkstatus encode-output)" = "loud" ]; then
1638 echo "HEH! The file we were about to normalize disappeared:"
1641 run_command "normalizetrack-$1" false "File $IN was not found"
1645 # do_move [tracknumber]
1646 # Deduces the outfile from environment variables
1647 # Creates directory if necessary
1649 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1652 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1654 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1655 # defined the OUTPUTFILE:
1658 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1659 ALBUMFILE="$(mungealbumname "$DALBUM")"
1660 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1661 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1662 GENRE="$(mungegenre "$GENRE")"
1663 YEAR=${CDYEAR:-$CDYEAR}
1664 # If we want to start the tracks with a given number, we need to modify
1665 # the TRACKNUM value before evaluation
1667 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1668 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1669 if [ "$ONETRACK" = "y" ]; then
1670 if [ "$VARIOUSARTISTS" = "y" ]; then
1671 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1673 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1676 if [ "$VARIOUSARTISTS" = "y" ]; then
1677 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1679 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1682 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1683 # Once we know the specific output was successful, we can change
1684 # the OUTPUT to the value containing the container
1687 OUTPUT=$OGGOUTPUTCONTAINER
1690 OUTPUT=$OPUSOUTPUTCONTAINER
1693 OUTPUT=$MKAOUTPUTCONTAINER
1696 OUTPUT=$AIFFOUTPUTCONTAINER
1699 OUTPUT=$FLACOUTPUTCONTAINER
1705 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1706 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1709 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1710 # FIXME # introduce warnings?
1713 # mkdir -p shouldn't return an error if the directory already exists
1714 mkdir -p "$OUTPUTFILEDIR"
1715 run_command "movetrack-$1" mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1716 if checkstatus "movetrack-output-$OUTPUT"; then :; else
1717 run_command "movetrack-output-$OUTPUT" true
1722 # mkdir -p shouldn't return an error if the directory already exists
1723 mkdir -p "$OUTPUTFILEDIR"
1724 run_command "movetrack-$1" mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1725 if checkstatus "movetrack-output-$OUTPUT"; then :; else
1726 run_command "movetrack-output-$OUTPUT" true
1730 # Lets move the cue file
1731 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1732 if [ -r "${ABCDETEMPDIR}/$CUEFILE" ]; then
1733 if checkstatus "movecue-$OUTPUT"; then :; else
1734 # Silence the Copying output since it overlaps with encoding processes...
1735 #run_command "" vecho "Copying cue file to its destination directory..."
1736 if checkstatus onetrack >/dev/null ; then
1739 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1740 # We dont have the dir, since it was not created before.
1743 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1746 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1747 # http://brianvictor.tripod.com/mp3cue.htm#details
1748 [a-z0-9][a-z0-9][a-z0-9])
1749 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1752 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1756 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1758 echo "movecue-$OUTPUT" >> "${ABCDETEMPDIR}/status"
1767 # Create the playlist if wanted
1769 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1770 # VARIOUSARTISTS, OUTPUTDIR
1773 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1777 OUTPUT=$OGGOUTPUTCONTAINER
1780 OUTPUT=$OPUSOUTPUTCONTAINER
1783 OUTPUT=$MKAOUTPUTCONTAINER
1786 OUTPUT=$AIFFOUTPUTCONTAINER
1789 OUTPUT=$FLACOUTPUTCONTAINER
1795 # Create a playlist file for the playlist data to go into.
1796 # We used to wipe it out if it existed. Now we request permission if interactive.
1797 for LASTTRACK in $TRACKQUEUE; do :; done
1798 ALBUMFILE="$(mungealbumname "$DALBUM")"
1799 ARTISTFILE="$(mungeartistname "$DARTIST")"
1800 GENRE="$(mungegenre "$GENRE")"
1801 YEAR=${CDYEAR:-$CDYEAR}
1802 if [ "$VARIOUSARTISTS" = "y" ] ; then
1803 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1805 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1807 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1808 mkdir -p "$FINALPLAYLISTDIR"
1809 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1810 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1811 if [ "$INTERACTIVE" = "y" ]; then
1812 while [ "$DONE" != "y" ]; do
1814 case $ERASEPLAYLIST in
1815 e|E|a|A|k|K) DONE=y ;;
1816 "") ERASEPLAYLIST=e ; DONE=y ;;
1824 # Once we erase the playlist, we use append to create the new one.
1825 [ "$ERASEPLAYLIST" = "e" ] || [ "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1827 # The playlist does not exist, so we can safelly use append to create the new list
1830 if [ "$ERASEPLAYLIST" = "a" ] || [ "$ERASEPLAYLIST" = "A" ]; then
1831 touch "$OUTPUTDIR/$PLAYLISTFILE"
1832 for UTRACKNUM in $TRACKQUEUE
1834 # Shares some code with do_move since the filenames have to match
1835 CDDBTRACKNUM=$(($UTRACKNUM - 1))
1836 getcddbinfo TRACKNAME
1838 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1839 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1840 ALBUMFILE="$(mungealbumname "$DALBUM")"
1841 # If we want to start the tracks with a given number, we need to modify the
1842 # TRACKNUM value before evaluation
1844 if [ "$VARIOUSARTISTS" = "y" ]; then
1845 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1847 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1849 if [ "$VARIOUSARTISTS" = "y" ]; then
1850 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1851 echo "${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1853 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1856 if [ "$PLAYLISTDATAPREFIX" ]; then
1857 echo "${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1859 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1864 ## this will convert the playlist to have CRLF line-endings, if specified
1865 ## (some hardware players insist on CRLF endings)
1866 if [ "$DOSPLAYLIST" = "y" ]; then
1867 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "${ABCDETEMPDIR}/PLAYLISTFILE.tmp"
1868 # mv -f "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1869 cat "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1871 echo "playlistcomplete" >> "${ABCDETEMPDIR}/status"
1876 # This function reads a cuefile on stdin and writes an extended
1877 # cddb query on stdout. Any PREGAP for track 1 is properly
1878 # handled, although cue files embedded in FLAC files do not
1879 # appear to properly store the PREGAP setting. :(
1880 abcde.cue2discid () {
1885 while [ "$val" -gt 0 ] ; do
1886 ret=$(( "$ret" + ( "$val" % 10) ))
1887 val=$(( "$val" / 10 ))
1897 local first second third
1899 second=$(( $2 + 0 ))
1902 echo $(( ((("$first" * 60) + "$second") * 75) + "$third" ))
1912 while read line ; do
1915 TRACK) i=$(( i + 1 ))
1917 INDEX) if [ "$2" -eq 1 ] ; then
1919 START=$(( "$LBA" + "$PREGAP" + "$OFFSET" ))
1921 X=$(cddb_sum $(( "$START" / 75 )) )
1922 N=$(( "$N" + "$X" ))
1925 PREGAP) PREGAP=$(msf2lba "$2")
1929 LEADOUT=$(( "$4" / 588 ))
1932 LEADIN=$(( "$3" / 588 ))
1941 LEADOUT=$(( "$LEADOUT" + "$LEADIN" ))
1943 LENGTH=$(( "$LEADOUT"/75 - "$TRACK1"/75 ))
1944 CDDBDISCID=$(( ( "$N" % 255 ) * 2**24 | "$LENGTH" * 2**8 | "$TRACKS" ))
1945 printf "%08x %i" "${CDDBDISCID}" "$TRACKS"
1948 while [ $j -le "$TRACKS" ] ; do
1949 eval echo -n "\" \$TRACK$j\""
1952 echo " $(( $LEADOUT / 75 ))"
1956 # abcde.mkcue [--wholedisk]
1957 # This creates a cuefile directly from the extended discid information
1958 # The --wholedisk option controls whether we're ripping data from the
1959 # start of track one or from the start of the disk (usually, but not
1960 # always the same thing!)
1962 # Track one leadin/pregap (if any) handeling:
1963 # --wholedisk specified:
1966 # INDEX 01 <pregap value>
1967 # Remaining track index values unchanged from disc TOC
1969 # --wholedisk not specified
1971 # PREGAP <pregap value>
1973 # Remaining track index values offset by <pregap value>
1980 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1983 local MODE DISCID TRACKS
1987 if [ "$1" = --wholedisk ] ; then
1993 vecho "One track is $ONETRACK"
1994 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1995 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1996 ALBUMFILE="$(mungealbumname "$DALBUM")"
1997 if [ "$ONETRACK" = "y" ]; then
1998 if [ "$VARIOUSARTISTS" = "y" ]; then
1999 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2001 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2003 vecho "Cue wav file is $CUEWAVFILE"
2005 CUEWAVFILE="dummy.wav"
2008 set -- "$CDDBTRACKINFO"
2014 echo "REM DISCID $DISCID"
2015 echo FILE \""$CUEWAVFILE"\" WAVE
2017 if [ "$1" -ne 150 ] && [ "$MODE" = "PREGAP" ] ; then
2024 while [ $i -le "$TRACKS" ] ; do
2025 LBA=$(( $1 - $OFFSET ))
2026 printf " TRACK %02i AUDIO\n" $i
2027 if [ "$i" -eq 1 ] && [ "$1" -ne 150 ] ; then
2028 if [ "$MODE" = PREGAP ] ; then
2029 echomsf " PREGAP " $(($"OFFSET" - 150))
2031 echo " INDEX 00 00:00:00"
2034 echomsf " INDEX 01 " "$LBA"
2041 # This is essentially the start of things
2044 if [ -z "${CDDBDISCID}" ]; then
2045 vecho -n "Getting CD track info... "
2046 # In OSX, unmount the disc before a query
2047 if [ "$OSFLAVOUR" = "OSX" ]; then
2048 diskutil unmount "${CDROM#/dev/}"
2050 case "$CDROMREADERSYNTAX" in
2052 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
2053 case "$CUE2DISCID" in
2054 # FIXME # right now we have 2 cue2discid internal
2055 # implementations: builtin and abcde.cue2discid. Test
2056 # both of them and decide which one we want to use.
2058 #vecho "Using builtin cue2discid implementation..."
2059 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2061 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2063 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2064 TRACKS=${#OFFSETTIMES[@]}
2066 #echo "processing offsetimes ${OFFSETTIMES[@]}"
2067 for OFFSETTIME in "${OFFSETTIMES[@]}"; do
2068 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2069 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
2072 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2073 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2077 #vecho "Using external python cue2discid implementation..."
2078 CDDBTRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2082 log error "the input flac file does not contain a cuesheet."
2087 CDPARANOIAOUTPUT="$( $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -Q --verbose 2>&1 )"
2089 if [ ! "$RET" = "0" ];then
2090 log warning "something went wrong while querying the CD... Maybe a DATA CD or the CD is not loaded?"
2093 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2094 CDPARANOIAAUDIOTRACKS="$TRACKS"
2096 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2097 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2101 # Calculate the cddb discid in all
2102 # cases now. We'll use the cddb discid
2103 # for reference in most cases for
2104 # consistency. Also calculate the
2105 # musicbrainz discid if we need it.
2106 CDDBTRACKINFO=$($CDDISCID "$CDROM")
2107 if [ "$CDDISCID_NEEDS_PAUSE"x = "y"x ]; then
2110 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2111 case "$CDDBMETHOD" in
2113 MBTRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM")
2115 if [ $error != 0 ]; then
2116 log error "$MUSICBRAINZ failed to run; ABORT"
2119 MBDISCID=$(echo "$MBTRACKINFO" | cut -d' ' -f1)
2123 # Make sure there's a CD in there by checking cd-discid's return code
2124 if [ ! "$?" = "0" ]; then
2125 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2126 log error "cuesheet information from the flac file could not be read."
2127 log error "Perhaps the flac file does not contain a cuesheet?."
2130 log error "CD could not be read. Perhaps there's no CD in the drive?"
2134 # In OSX, remount the disc again
2135 if [ "$OSFLAVOUR" = "OSX" ]; then
2136 diskutil mount "${CDROM#/dev/}"
2139 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -f1 -d' ')
2141 CDDBTRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.${CDDBDISCID}/cddbdiscid")
2144 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2145 # This needs to be done now because a section of the resuming code will need
2148 # get the number of digits to pad TRACKNUM with - we'll use this later
2149 # a CD can only hold 99 tracks, but since we support a feature for starting
2150 # numbering the tracks from a given number, we might need to set it as a
2151 # variable for the user to define... or obtain it somehow.
2152 if [ "$PADTRACKS" = "y" ] ; then
2156 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo "$CDDBTRACKINFO" | cut -f1 -d' ')"
2157 if [ -z "$TRACKQUEUE" ]; then
2158 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2159 case "$CDROMREADERSYNTAX" in
2160 cdparanoia|libcdio|debug)
2161 if [ "$WEHAVEACD" = "y" ]; then
2162 vecho "Querying the CD for audio tracks..."
2163 CDPARANOIAOUTPUT="$( $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -Q --verbose 2>&1 )"
2165 if [ ! "$RET" = "0" ];then
2166 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2168 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2169 CDPARANOIAAUDIOTRACKS="$TRACKS"
2171 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2172 if [ -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks" ]; then
2173 echo "cdparanoia-audio-tracks=$( cat "${ABCDETEMPDIR}/cdparanoia-audio-tracks" )" >> "${ABCDETEMPDIR}/status"
2174 rm -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks"
2176 if [ -f "${ABCDETEMPDIR}/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2177 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2181 *) TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ') ;;
2184 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2186 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2187 log info "The disc does not contain any tracks. Giving up..."
2190 echo -n "Grabbing entire CD - tracks: "
2191 if [ ! "$PADTRACKS" = "y" ] ; then
2192 TRACKNUMPADDING=$(echo -n "$TRACKS" | wc -c | tr -d ' ')
2195 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2197 while [ "$X" -ne "$TRACKS" ]
2199 PT=$(printf "%0.${TRACKNUMPADDING}d" $(($X + 1)))
2200 TRACKQUEUE="$TRACKQUEUE $PT"
2205 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2206 # User-supplied track queue.
2207 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2208 TRACKQUEUE=$(echo "$TRACKQUEUE" | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2209 # Once cleaned, obtain the highest value in the trackqueue for number padding
2210 for LASTTRACK in $TRACKQUEUE; do :; done
2211 if [ ! "$PADTRACKS" = "y" ] ; then
2212 TRACKNUMPADDING=$(echo -n "$LASTTRACK" | wc -c | tr -d ' ')
2214 # Now we normalize the trackqueue
2215 for TRACK in $TRACKQUEUE ; do
2216 TRACKNUM=$(printf "%0.${TRACKNUMPADDING}d" $(($TRACK + 0)))
2217 PADTRACKQUEUE="$PADTRACKQUEUE $TRACKNUM"
2219 TRACKQUEUE="$PADTRACKQUEUE"
2220 echo Grabbing tracks: "$TRACKQUEUE"
2223 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2225 # We have the discid, create a temp directory after it to store all the temp
2228 if [ -e "${ABCDETEMPDIR}" ]; then
2229 echo -n "abcde: attempting to resume from ${ABCDETEMPDIR}"
2230 # It already exists, see if it's a directory
2231 if [ ! -d "${ABCDETEMPDIR}" ]; then
2232 # This is a file/socket/fifo/device/etc, not a directory
2235 echo "abcde: file ${ABCDETEMPDIR} already exists and does not belong to abcde." >&2
2236 echo "Please investigate, remove it, and rerun abcde." >&2
2240 # It's a directory, let's see if it's writable by us
2241 if [ ! -r "${ABCDETEMPDIR}" ] || [ ! -w "${ABCDETEMPDIR}" ] || [ ! -x "${ABCDETEMPDIR}" ]; then
2242 # Nope, complain and exit
2244 echo "abcde: directory ${ABCDETEMPDIR} already exists and is not writeable." >&2
2245 echo "Please investigate, remove it, and rerun abcde." >&2
2249 # See if it's populated
2250 if [ ! -f "${ABCDETEMPDIR}/cddbdiscid" ]; then
2251 # Wipe and start fresh
2252 echo "abcde: ${ABCDETEMPDIR}/cddbdiscid not found. Abcde must remove and recreate" >&2
2253 echo -n "this directory to continue. Continue [y/N]? " >&2
2254 if [ "$INTERACTIVE" = "y" ]; then
2260 if [ "$ANSWER" != "y" ]; then
2263 rm -rf "${ABCDETEMPDIR}" || exit 1
2264 mkdir -p "${ABCDETEMPDIR}"
2265 if [ "$?" -gt "0" ]; then
2266 # Directory already exists or could not be created
2267 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2271 # Everything is fine. Check for ^encodetracklocation-
2272 # and encode-output entries in the status file and
2273 # remove them. These are not relevant across sessions.
2274 if [ -f "${ABCDETEMPDIR}/status" ]; then
2275 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
2276 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
2277 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
2279 # Remove old error messages
2280 if [ -f "${ABCDETEMPDIR}/errors" ]; then
2281 rm -f "${ABCDETEMPDIR}/errors"
2285 # We are starting from scratch
2286 mkdir -p "${ABCDETEMPDIR}"
2287 if [ "$?" -gt "0" ]; then
2288 # Directory already exists or could not be created
2289 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2292 cat /dev/null > "${ABCDETEMPDIR}/status"
2293 # Store the abcde version in the status file.
2294 echo "abcde-version=$VERSION" >> "${ABCDETEMPDIR}/status"
2296 if [ X"$DOCUE" = "Xy" ] && [ X"$WEHAVEACD" = "Xy" ]; then
2297 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2298 CUEFILE=cue-$(echo "$CDDBTRACKINFO" | cut -f1 -d' ').txt
2299 vecho "Creating cue file..."
2300 case "$CDROMREADERSYNTAX" in
2302 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "${ABCDETEMPDIR}/$CUEFILE"; then
2303 echo "cuefile=$CUEFILE" >> "${ABCDETEMPDIR}/status"
2305 log warning "the input flac file does not contain a cuesheet."
2309 if $CUEREADER $CUEREADEROPTS > "${ABCDETEMPDIR}/$CUEFILE"; then
2310 echo "cuefile=$CUEFILE" >> "${ABCDETEMPDIR}/status"
2312 log warning "reading the CUE sheet is still considered experimental"
2313 log warning "and there was a problem with the CD reading. abcde will continue,"
2314 log warning "but consider reporting the problem to the abcde author"
2320 # If we got the CDPARANOIA status and it is not recorded, save it now
2321 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2322 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2323 echo "cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS" >> "${ABCDETEMPDIR}/status"
2327 # Create the discid files
2328 echo "$CDDBTRACKINFO" > "${ABCDETEMPDIR}/cddbdiscid"
2329 case "$CDDBMETHOD" in
2331 echo "$MBTRACKINFO" > "${ABCDETEMPDIR}/mbdiscid"
2337 # Create a proper CUE file based on the CUE file we created before.
2340 if CUEFILE_IN="${ABCDETEMPDIR}"/$(checkstatus cuefile); then
2341 CUEFILE_OUT=$CUEFILE_IN.out
2342 ### FIXME ### checkstatus cddb
2343 if [ -e "$CDDBDATA" ]; then
2344 vecho "Adding metadata to the cue file..."
2345 # FIXME It doesn't preserve spaces! Why?
2346 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2348 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2349 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2350 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2354 cat "$CUEFILE_IN" | while read line
2356 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2357 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2358 # echo "$line" >> "$CUEFILE_OUT"
2359 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2360 eval track="\$TRACK$n"
2362 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2363 # When making a single-track rip, put the
2364 # actual file name into the file declaration
2365 # in the cue file so that it is usable by
2366 # music players and the like
2367 elif [ "$ONETRACK" = "y" ] &&
2368 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2370 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2371 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2372 ALBUMFILE="$(mungealbumname "$DALBUM")"
2374 if [ "$VARIOUSARTISTS" = "y" ]; then
2375 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2377 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2380 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2383 # FIXME # If the lines above are uncommented, remove the line below.
2384 echo "$line" >> "$CUEFILE_OUT"
2387 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2388 echo "cleancuefile" >> "${ABCDETEMPDIR}/status"
2394 # Parses a CDDB file and outputs the title and the track names.
2395 # Variables: CDDBFILE
2399 # List out disc title/author and contents
2400 if [ "$ONETRACK" = "y" ]; then
2401 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2403 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2404 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2405 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2406 if [ ! X"$PARSEDYEAR" = "X" ]; then
2407 echo "Year: $PARSEDYEAR"
2410 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2411 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2412 if [ ! X"$PARSEDGENRE" = "X" ]; then
2413 echo "Genre: $PARSEDGENRE"
2416 if [ ! "$ONETRACK" = "y" ]; then
2417 for TRACK in $(f_seq_row 1 $TRACKS)
2419 echo "$TRACK": "$(grep -a ^TTITLE$(($TRACK - 1))= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2425 # Check for a local CDDB file, and report success
2426 do_localcddb_read ()
2428 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2430 CDDBLOCALSTATUS="notfound"
2431 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2434 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2435 CDDBLOCALRESULTS="$(find "${CDDBLOCALDIR}" -name "${CDDBDISCID}" -type f 2> /dev/null)"
2436 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2437 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2438 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2439 CDDBLOCALMATCH=single
2440 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2441 CDDBLOCALMATCH=multiple
2446 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2447 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2448 CDDBLOCALMATCH=single
2453 # If the user has selected to check a local CDDB repo, we proceed with it
2454 case $CDDBLOCALMATCH in
2456 echo "Processing multiple matching CDDB entries..." > "${ABCDETEMPDIR}/cddblocalchoices"
2458 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2460 # List out disc title/author and contents
2461 CDDBLOCALREAD="${ABCDETEMPDIR}/cddblocalread.$X"
2462 cat "$RESULT" > "${CDDBLOCALREAD}"
2465 do_cddbparse "${CDDBLOCALREAD}"
2467 ##FIXME## QUICK HACK !!!!
2468 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2469 } >> "${ABCDETEMPDIR}/cddblocalchoices"
2471 page "${ABCDETEMPDIR}/cddblocalchoices"
2472 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2473 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2474 CDDBLOCALCHOICENUM=-1
2475 if [ "$INTERACTIVE" = "y" ]; then
2476 while [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; do
2477 echo "Locally cached CDDB entries found." >&2
2478 echo -n "Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2479 read CDDBLOCALCHOICE
2480 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2481 # FIXME # Introduce diff's
2482 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2483 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2484 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2485 # Make sure we get a valid choice
2486 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2487 if [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; then
2488 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2493 CDDBLOCALCHOICENUM=1
2495 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2496 #echo "Using local copy of CDDB data"
2497 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2498 cat "${ABCDETEMPDIR}/cddblocalread.$CDDBLOCALCHOICENUM" >> "${ABCDETEMPDIR}/cddbread.1"
2499 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2500 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2501 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2502 do_cddbparse "${ABCDETEMPDIR}/cddbread.1" > "${ABCDETEMPDIR}/cddbchoices"
2503 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2504 CDDBLOCALSTATUS="found"
2506 #echo "Not using local copy of CDDB data"
2507 CDDBLOCALSTATUS="notfound"
2511 # List out disc title/author and contents
2512 do_cddbparse "${CDDBLOCALFILE}"
2513 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2514 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2516 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2518 if [ "$INTERACTIVE" = "y" ]; then
2520 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2521 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2524 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2528 if [ "$USELOCALRESP" = "y" ]; then
2529 #echo "Using local copy of CDDB data"
2530 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2531 cat "${CDDBLOCALFILE}" >> "${ABCDETEMPDIR}/cddbread.1"
2532 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2533 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2534 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2535 do_cddbparse "${CDDBLOCALFILE}" > "${ABCDETEMPDIR}/cddbchoices"
2536 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2537 CDDBLOCALSTATUS="single"
2539 #echo "Not using local copy of CDDB data"
2540 CDDBLOCALSTATUS="notfound"
2544 CDDBLOCALSTATUS="notfound"
2551 # Try to read CD-Text from the drive using icedax / cdda2wav
2554 if new_checkexec icedax; then
2555 CDTEXT_READER=icedax
2556 elif new_checkexec cdda2wav; then
2557 CDTEXT_READER=cdda2wav
2559 # Didn't find either, bail
2563 vecho "Obtaining CD-Text results..."
2564 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cdtext"
2565 mkdir -p "${SOURCE_WORKDIR}"
2567 if [ "$OSFLAVOUR" = "OSX" ] ; then
2568 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2569 diskutil unmount "${CDROM#/dev/}"
2570 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2571 CDDA2WAVCDROM="IODVDServices"
2572 elif [ "$OSFLAVOUR" = "FBSD" ] || [ "$OSFLAVOUR" = "IRIX" ]; then
2573 CDDA2WAVCDROM="$CDROMID"
2575 if [ "$CDROMID" = "" ]; then
2576 CDDA2WAVCDROM="$CDROM"
2578 CDDA2WAVCDROM="$CDROMID"
2582 # Do we have CD-Text on the disc (and can the drive read it?)
2584 cd "${SOURCE_WORKDIR}" && rm -f audio.* audio_*
2585 ${CDTEXT_READER} -J -v titles -D "${CDDA2WAVCDROM}" > "${SOURCE_WORKDIR}/cd-text" 2>&1
2587 grep -a -q '^CD-Text: detected' "${SOURCE_WORKDIR}/cd-text"
2589 if [ $ERRORCODE -ne 0 ]; then
2590 # No CD-Text found, bail
2594 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2595 # Make an empty template
2596 $CDDBTOOL template "$(cat "${ABCDETEMPDIR}/cddbdiscid")" > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2597 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2598 rm -f "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2600 # XXX FIXME - this is a hack and should be replaced by proper
2601 # character set tracking for the CDDB data we have.
2602 if [ "$CDDBPROTO" -ge 6 ]; then
2603 # convert to Unicode
2604 iconv -f iso-8859-1 -t utf-8 <"${SOURCE_WORKDIR}/audio.cddb" >"${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2606 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2607 # apparently icedax/cdda2wav have no support for 16-bit
2608 # characters yet, either
2609 cp -p "${SOURCE_WORKDIR}/audio.cddb" "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2612 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2613 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2614 echo "CD-Text" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2615 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2617 ( cd "${SOURCE_WORKDIR}" && rm -f audio_* audio.* )
2618 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2619 if [ -f "$file" ]; then
2620 cp "$file" "${ABCDETEMPDIR}"
2623 echo "cdtext-readcomplete" >> "${ABCDETEMPDIR}/status"
2626 # do_musicbrainz_read
2627 # Work with the musicbrainz WS API, then transform the results here so
2628 # they look (very) like the results from CDDB. Maybe not the best way
2629 # to go, but it Works For Me (TM)
2631 # List out all the matches individually into $SOURCE_WORKDIR/cddbread.X
2633 do_musicbrainz_read ()
2635 if checkstatus musicbrainz-readcomplete; then :; else
2636 vecho "Obtaining Musicbrainz results..."
2637 # If MB is to be used, interpret the query results and read all
2638 # the available entries.
2639 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2640 MBDISCID=$(echo "$MBTRACKINFO" | cut -d' ' -f1)
2641 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-musicbrainz"
2642 mkdir -p "${SOURCE_WORKDIR}"
2643 ${MUSICBRAINZ} --command data --discid "${MBDISCID}" --workdir "${SOURCE_WORKDIR}" --start ${NUM_CDDB_MATCHES}
2645 if [ $error != 0 ]; then
2646 log error "$MUSICBRAINZ failed to run; ABORT"
2650 # Check for no matches.
2651 # The helper script will write disc matches out to
2652 # cddbread.*. Count how many we have
2653 NUM_RESPONSES=$(echo "${SOURCE_WORKDIR}"/cddbread.* | wc -w)
2654 if [ "$NUM_RESPONSES" -gt 0 ] ; then
2655 # One or more exact matches
2657 while [ $i -le "$NUM_RESPONSES" ]; do
2658 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2660 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2661 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2662 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2663 echo "Musicbrainz" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2664 cp -f "${SOURCE_WORKDIR}/"*."${NUM_CDDB_MATCHES}" "${ABCDETEMPDIR}"
2667 echo "musicbrainz-readcomplete" >> "${ABCDETEMPDIR}/status"
2674 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cddb"
2675 mkdir -p "${SOURCE_WORKDIR}"
2681 # Perform CDDB protocol version check if it hasn't already been done
2682 if checkstatus cddb-statcomplete; then :; else
2683 if [ "$CDDBAVAIL" = "n" ]; then
2685 echo 503 > "${SOURCE_WORKDIR}/cddbstat"
2688 CDDBUSER=$(echo "$HELLOINFO" | cut -f1 -d'@')
2689 CDDBHOST=$(echo "$HELLOINFO" | cut -f2- -d'@')
2690 while [ $rc -eq 1 ] && [ "$CDDBPROTO" -ge 3 ]; do
2691 vecho "Checking CDDB server status..."
2692 $CDDBTOOL stat "$CDDBURL" "$CDDBUSER" "$CDDBHOST" "$CDDBPROTO" > "${SOURCE_WORKDIR}/cddbstat"
2693 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2694 case "$RESPONSECODE" in
2695 210) # 210 OK, status information follows (until terminating `.')
2698 501) # 501 Illegal CDDB protocol level: <n>.
2699 CDDBPROTO=$(($CDDBPROTO - 1))
2701 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2702 # FreeDB TESTCD disc-id is used for query
2703 $CDDBTOOL query "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" 03015501 1 296 344 > "${SOURCE_WORKDIR}/cddbstat"
2704 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2705 case "$RESPONSECODE" in
2706 2??) # Server responded, everything seems OK
2716 if [ $rc -eq 1 ]; then
2720 echo cddb-statcomplete >> "${ABCDETEMPDIR}/status"
2727 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2728 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2730 # Perform CDDB query if it hasn't already been done
2731 if checkstatus cddb-querycomplete; then :; else
2732 if [ "$CDDBAVAIL" = "n" ]; then
2734 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2735 # The default CDDBLOCALSTATUS is "notfound"
2736 # This part will be triggered if the user CDDB repo does not
2737 # contain the entry, or if we are not trying to use the repo.
2739 vecho "Querying the CDDB server..."
2740 CDDBUSER=$(echo "$HELLOINFO" | cut -f1 -d'@')
2741 CDDBHOST=$(echo "$HELLOINFO" | cut -f2- -d'@')
2742 $CDDBTOOL query "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" "$CDDBTRACKINFO" > "${SOURCE_WORKDIR}/cddbquery"
2748 # no match found in database, wget/fetch error,
2749 # or user requested not to use CDDB. Make up an
2750 # error code (503) that abcde will recognize later
2751 # and compensate by making a template
2752 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2754 *) # strange and unknown error
2755 echo "ERRORCODE=$ERRORCODE"
2756 echo "abcde: $CDDBTOOL returned unknown error code"
2760 echo cddb-querycomplete >> "${ABCDETEMPDIR}/status"
2767 # If it's not to be used, generate a template.
2768 # Then, display it (or them) and let the user choose/edit it
2769 if checkstatus cddb-readcomplete; then :; else
2770 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbquery" | cut -f1 -d' ')
2771 vecho "Obtaining CDDB results..."
2772 case "$RESPONSECODE" in
2774 # One exact match, retrieve it
2775 # 200 [section] [discid] [artist] / [title]
2776 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2777 $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
2778 $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") \
2779 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2780 cat "${SOURCE_WORKDIR}/cddbquery" | cut -f2- -d' ' > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2781 echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2782 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2784 202|403|409|500|503)
2785 # TODO: Explain these error codes a little more accurately:
2786 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2787 # No match response:
2790 # Multiple exact, (possibly multiple) inexact matches
2791 vecho -n "Retrieving multiple matches... "
2792 grep -v '^[.]$' "${SOURCE_WORKDIR}/cddbquery" | (
2793 # IN A SUB-SHELL - VARIABLES MODIFIED
2794 # HERE DO NOT PERSIST IN THE PARENT
2795 read DISCINFO # eat top line
2798 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2799 if checkstatus "cddb-read-${NUM_CDDB_MATCHES}-complete"; then :; else
2800 $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
2801 $(echo "$DISCINFO" | cut -f1,2 -d' ') \
2802 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2803 echo "$DISCINFO" > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2804 echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2805 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2808 # Need to re-count the entries here to be able
2809 # to incrememnt $NUM_CDDB_MATCHES in the
2811 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $(echo "${SOURCE_WORKDIR}/datasource.*" | wc -w)))
2816 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2817 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2820 echo "cddb-readcomplete" >> "${ABCDETEMPDIR}/status"
2821 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2822 if [ -f "$file" ]; then
2823 cp "$file" "${ABCDETEMPDIR}"
2832 if checkstatus cddb-edit >/dev/null; then
2833 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2834 VARIOUSARTISTS="$(checkstatus variousartists)"
2835 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2838 if [ "$INTERACTIVE" = "y" ]; then
2839 # We should show the CDDB results both when we are not using the local CDDB repo
2840 # or when we are using it but we could not find a proper match
2841 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2842 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2843 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2844 CHOICE=$(checkstatus cddb-choice)
2845 if [ -n "$CHOICE" ] ; then
2846 case $NUM_CDDB_MATCHES in
2847 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2849 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CHOICE" | cut -f2- -d= | tr -d \\r\\n)
2850 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CHOICE")
2851 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)"
2852 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2856 page "${ABCDETEMPDIR}/cddbchoices"
2858 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2860 # I'll take CDDB read #3 for $400, Alex
2861 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; do
2862 echo -n "Which entry would you like abcde to use (0 for none)? [0-$NUM_CDDB_MATCHES]: " >&2
2864 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2865 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2866 if [ ! X"$DIFF" = "X" ]; then
2867 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2868 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2869 if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$NUM_CDDB_MATCHES" ] || \
2870 [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$NUM_CDDB_MATCHES" ] || \
2871 [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
2872 echo "Invalid diff range." >&2
2873 echo "Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
2875 # We parse the 2 choices to diff, store them in temporary files and diff them.
2876 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2877 do_cddbparse "${ABCDETEMPDIR}/cddbread.$PARSECHOICE" \
2878 > "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE"
2880 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." \
2881 > "${ABCDETEMPDIR}/cddbread.diff"
2882 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE1" \
2883 "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE2" \
2884 >> "${ABCDETEMPDIR}/cddbread.diff"
2885 page "${ABCDETEMPDIR}/cddbread.diff"
2888 echo "The diff program was not found in your path." >&2
2889 echo "Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2891 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2892 # Make sure we get a valid choice
2893 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2894 if [ "$CDCHOICENUM" -lt 0 ] || [ "$CDCHOICENUM" -gt "$NUM_CDDB_MATCHES" ]; then
2895 echo "Invalid selection. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2899 if [ "$CDCHOICENUM" = "0" ]; then
2900 vecho "Creating empty CDDB template..."
2902 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
2903 echo "template" > "${ABCDETEMPDIR}/datasource.0"
2905 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n)
2906 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CDCHOICENUM")
2907 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)" >&2
2909 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM"
2910 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2914 # We need some code to show the selected option when local repository is selected and we have found a match
2915 vecho "Using cached CDDB match..." >&2
2916 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2917 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2918 CHOICE=$(checkstatus cddb-choice)
2919 if [ "$USELOCALRESP" = "y" ]; then :; else
2920 if [ -n "$CHOICE" ] ; then
2921 case $NUM_CDDB_MATCHES in
2924 echo "Selected template."
2926 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2928 echo "Selected: #$CHOICE"
2929 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2937 # We're noninteractive - pick the first choice.
2938 # But in case we run a previous instance and selected a choice, use it.
2939 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2940 # Show the choice if we are not using the locally stored one
2941 # or when the local search failed to find a match.
2942 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2943 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2944 #if [ "$PREVIOUSCHOICE" ]; then
2945 cat "${ABCDETEMPDIR}/cddbchoices"
2948 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2949 CDCHOICENUM=$PREVIOUSCHOICE
2952 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2954 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2959 if checkstatus cddb-choice >/dev/null; then :; else
2960 echo "abcde: internal error: cddb-choice not recorded." >&2
2963 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2964 CDDBSOURCE=$(cat "${ABCDETEMPDIR}/datasource.$(checkstatus cddb-choice)")
2965 echo -n "Edit selected CDDB data " >&2
2966 if [ "$INTERACTIVE" = "y" ]; then
2967 if [ "$UNKNOWNDISK" = "y" ]; then
2968 echo -n "[Y/n]? " >&2
2970 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2972 echo -n "[y/N]? " >&2
2979 if [ "$EDITCDDB" = "y" ]; then
2980 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2982 # Use the debian sensible-editor wrapper to pick the editor that the
2983 # user has requested via their $EDITOR environment variable
2984 if [ -x "/usr/bin/sensible-editor" ]; then
2985 /usr/bin/sensible-editor "$CDDBDATA"
2986 elif [ -n "$EDITOR" ]; then
2987 if [ -x "$(which "${EDITOR%%\ *}")" ]; then
2988 # That failed, try to load the preferred editor, starting
2989 # with their EDITOR variable
2992 # If that fails, check for a vi
2993 elif which vi >/dev/null 2>&1; then
2995 elif [ -x /usr/bin/vim ]; then
2996 /usr/bin/vim "$CDDBDATA"
2997 elif [ -x /usr/bin/vi ]; then
2998 /usr/bin/vi "$CDDBDATA"
2999 elif [ -x /bin/vi ]; then
3001 # nano should be on all (modern, i.e., sarge) debian systems
3002 elif which nano >/dev/null 2>&1 ; then
3004 elif [ -x /usr/bin/nano ]; then
3005 /usr/bin/nano "$CDDBDATA"
3006 # mg should be on all OpenBSD systems
3007 elif which mg >/dev/null 2>&1 ; then
3009 elif [ -x /usr/bin/mg ]; then
3010 /usr/bin/mg "$CDDBDATA"
3013 log warning "no editor available. Check your EDITOR environment variable."
3015 # delete editor backup file if it exists
3016 if [ -w "$CDDBDATA~" ]; then
3021 # Some heuristics first. Look at Disc Title, and if it starts with
3022 # "Various", then we'll assume Various Artists
3023 if [ "$(grep -a ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -aEci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
3024 echo "Looks like a Multi-Artist CD" >&2
3027 echo -n "Is the CD multi-artist [y/N]? " >&2
3028 if [ "$INTERACTIVE" = "y" ]; then
3035 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
3038 # Need NUMTRACKS before cddb-tool will return it:
3039 NUMTRACKS=$(grep -a -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
3040 if [ "$(grep -ac "^TTITLE.*\/" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3041 # More than 1/2 tracks contain a "/", so guess forward
3043 elif [ "$(grep -ac "^TTITLE.*\-" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3044 # More than 1/2 contain a "-", so guess forward-dash
3046 elif [ "$(grep -ac "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3047 # More than 1/2 contain something in parens, so guess trailing-paren
3051 echo "1) Artist / Title" >&2
3052 echo "2) Artist - Title" >&2
3053 echo "3) Title / Artist" >&2
3054 echo "4) Title - Artist" >&2
3055 echo "5) Artist: Title" >&2
3056 echo "6) Title (Artist)" >&2
3057 echo "7) This is a single-artist CD" >&2
3058 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
3059 if [ "$INTERACTIVE" = "y" ]; then
3060 read VARIOUSARTISTSTYLE
3062 echo $DEFAULTSTYLE >&2
3063 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3065 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3066 # If they press Enter, then the default style (0) was chosen
3067 while [ "$VARIOUSARTISTSTYLE" -lt 0 ] || [ "$VARIOUSARTISTSTYLE" -gt 7 ]; do
3068 echo "Invalid selection. Please choose a number between 1 and 7."
3069 echo -n "Selection [1-7]: "
3070 read VARIOUSARTISTSTYLE
3071 VARIOUSARTISTSTYLE=$(echo "0$VARIOUSARTISTSTYLE" | xargs printf "%d")
3073 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3074 VARIOUSARTISTSTYLE="$DEFAULTSTYLE"
3076 vecho "Selected: $VARIOUSARTISTSTYLE"
3077 case "$VARIOUSARTISTSTYLE" in
3079 VARIOUSARTISTSTYLE=forward
3082 VARIOUSARTISTSTYLE=forward-dash
3085 VARIOUSARTISTSTYLE=reverse
3088 VARIOUSARTISTSTYLE=reverse-dash
3091 VARIOUSARTISTSTYLE=colon
3094 VARIOUSARTISTSTYLE=trailing-paren
3102 echo "variousartists=$VARIOUSARTISTS" >> "${ABCDETEMPDIR}/status"
3103 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "${ABCDETEMPDIR}/status"
3105 if [ "$EDITCDDB" = "y" ] && [ "$CDDBSOURCE" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3106 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3107 # This works but does not have the necessary error checking
3108 # yet. If you are familiar with the CDDB spec
3109 # (see http://www.freedb.org/src/latest/DBFORMAT)
3110 # and can create an error-free entry on your own, then put
3111 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3112 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3113 # your abcde.conf to change the email address submissions are
3116 # submit the modified file, if they want
3117 if [ "$NOSUBMIT" != "y" ]; then
3118 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3120 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3121 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3123 echo -n 'Invalid selection. Please answer "y" or "n": '
3126 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3127 echo -n "Sending..."
3128 $CDDBTOOL send "$CDDBDATA" "$CDDBSUBMIT"
3135 # User CDDBLOCALPOLICY to find out if we store the file or not...
3136 # Cache edited CDDB entry in the user's cddb dir
3137 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3138 # Make sure the cache directory exists
3139 mkdir -p "$CDDBLOCALDIR"
3140 NUM_LINES=$(( $(wc -l < "$CDDBDATA") - 1 ))
3141 OUTPUT_FILE="$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)"
3142 tail -n "$NUM_LINES" < "$CDDBDATA" > "${CDDBLOCALDIR}/${OUTPUT_FILE}"
3145 echo "cddb-edit" >> "${ABCDETEMPDIR}/status"
3149 # try to download CD cover
3153 ALBUMFILE="$(mungealbumname "$DALBUM")"
3154 ARTISTFILE="$(mungeartistname "$DARTIST")"
3155 GENRE="$(mungegenre "$GENRE")"
3156 YEAR=${CDYEAR:-$CDYEAR}
3157 # have we got a musicbrainz mbid or amazon asin?
3158 case "$CDDBMETHOD" in
3160 # try musicbrainz mbid
3161 if [ -s "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)" ]; then
3162 MBID=$(cat "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)")
3163 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3164 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3165 vecho "cover URL: $ALBUMARTURL" >&2
3166 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3167 if [ $? -ne 0 ]; then
3168 vecho "could not download cover from musicbrainz" >&2
3170 if [ -s "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)" ]; then
3171 ASIN=$(cat "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)")
3172 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3173 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3174 vecho "cover URL: $ALBUMARTURL" >&2
3175 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3176 if [ $? -ne 0 ]; then
3177 vecho "could not download cover from amazon" >&2
3179 # Check that size is reasonable; sometimes when there is no cover image
3180 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3181 FILESIZE=$(wc -c < "${ABCDETEMPDIR}/$ALBUMARTFILE")
3182 if [ "$FILESIZE" -lt 1024 ]; then
3183 rm "${ABCDETEMPDIR}/$ALBUMARTFILE"
3184 vecho "could not download cover from amazon" >&2
3188 vecho "no amazon ID found" >&2
3192 vecho "no musicbrainz ID found" >&2
3197 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3198 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3199 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "${ABCDETEMPDIR}/$ALBUMARTFILE" $GLYRCOPTS
3200 if [ $? -ne 0 ]; then
3201 vecho "could not download cover with glyrc" >&2
3206 if [ "$INTERACTIVE" = "y" ]; then
3207 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3208 # display properties of coverart when identify is available
3209 if new_checkexec "$IDENTIFY"; then
3210 $IDENTIFY $IDENTIFYOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3212 # display coverart when DISPLAY is set and display command is available
3213 if new_checkexec "$DISPLAYCMD" && [ "$DISPLAY" != "" ]; then
3214 $DISPLAYCMD $DISPLAYCMDOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2 &
3217 # nothing downloaded yet
3218 vecho "automatic album art downloading failed" >&2
3220 # see if the user can find a better album art manually
3221 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3223 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3224 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3226 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3229 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3230 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3232 if [ ! -z "$ALBUMARTURL" ]; then
3233 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3234 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3235 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3236 vecho "unable to download $ALBUMARTURL" >&2
3238 else # it's a local path
3239 cp "$ALBUMARTURL" "${ABCDETEMPDIR}/$ALBUMARTFILE"
3240 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3241 vecho "unable to copy $ALBUMARTURL to ${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3247 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3248 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ] && new_checkexec "$IDENTIFY"; then
3249 ALBUMARTURLTYPE=$($IDENTIFY "${ABCDETEMPDIR}/$ALBUMARTFILE" | cut -d' ' -f2)
3250 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" ] || [ "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3251 if new_checkexec "$CONVERT"; then
3252 mv "${ABCDETEMPDIR}/$ALBUMARTFILE" "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3253 $CONVERT "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp" $CONVERTOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE"
3254 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3256 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3257 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE" >&2
3258 vecho "without ImageMagick convert" >&2
3262 # copy to target directories
3263 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3264 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
3266 # put cover in the same place as the album
3267 if [ "$ONETRACK" = "y" ] ; then
3268 if [ "$VARIOUSARTISTS" = "y" ] ; then
3269 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3271 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3274 if [ "$VARIOUSARTISTS" = "y" ] ; then
3275 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3277 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3280 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3281 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3282 mkdir -p "$FINALALBUMARTDIR"
3283 cp "${ABCDETEMPDIR}/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3285 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3286 echo "get-album-art=$ALBUMARTURL" >> "${ABCDETEMPDIR}/status"
3288 log warning "could not get cover"
3289 echo "get-album-art=none" >> "${ABCDETEMPDIR}/status"
3293 # Optionally embed the albumart downloaded by the getalbumart fuction.
3294 # FIXME: It would be nice to have this also selectable from within the
3295 # FIXME: getalbumart function itself. Andrew
3299 ALBUMFILE="$(mungealbumname "$DALBUM")"
3300 ARTISTFILE="$(mungeartistname "$DARTIST")"
3301 GENRE="$(mungegenre "$GENRE")"
3302 YEAR=${CDYEAR:-$CDYEAR}
3304 # Allow for multiple output formats:
3305 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
3307 # Find the output directory for multi track encodes:
3308 if [ "$ONETRACK" != "y" ] ; then
3309 if [ "$VARIOUSARTISTS" = "y" ] ; then
3310 FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
3312 FINDPATH="$(eval echo "$OUTPUTFORMAT")"
3315 # Find the output directory for single track encodes:
3316 if [ "$ONETRACK" = "y" ] ; then
3317 if [ "$VARIOUSARTISTS" = "y" ] ; then
3318 FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3320 FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3324 FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
3327 # Instructions for each format, feel free to add more. It would be nice to
3328 # make the backup directory selectable and perhaps also have an option for
3329 # the bold to simply have the image deleted. Work for another day... Andrew.
3330 if [ -e "$ALBUMARTFILE" ] ; then
3335 "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$i"
3337 mkdir "$FINALDIR"/albumart_backup
3338 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3339 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3344 "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
3346 mkdir "$FINALDIR"/albumart_backup
3347 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3348 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3353 "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
3355 mkdir "$FINALDIR"/albumart_backup
3356 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3357 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3362 "$WVTAG" --write-binary-tag "Cover Art (Front)=@$ALBUMARTFILE" "$i"
3364 mkdir "$FINALDIR"/albumart_backup
3365 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3366 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3370 # This technique is drawn from 2 sources (the first link being the primary source):
3371 # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
3372 # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
3373 # In abcde a few steps are used in this sequence:
3375 # 1. Create a 'legal' header for the cover art image
3376 # 2. Makes a copy of the existing tags
3377 # 3. base64 the cover art image
3378 # 4. Copy the original tags + the base64 image back to the original ogg file
3380 # Might need some fine tuning but it is a start for abcde 2.8.2 Andrew.
3381 # FIXME: I am not sure if there is a maximum size for images converted in this
3382 # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
3384 # First some variables we can reuse:
3385 # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
3386 MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
3387 EXPORTTAGS="${ABCDETEMPDIR}/export_ogg_tags"
3388 BUILDHEADER="${ABCDETEMPDIR}/build_header"
3389 # Now build the header, gory details are here:
3390 # https://xiph.org/flac/format.html#metadata_block_picture
3392 printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
3394 printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3396 echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
3397 # Description length. FIXME: I have used 'Cover Image' but I am not sure
3398 # if this is better left as an empty field. Andrew
3399 printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3401 echo -n "Cover Image" >> "$BUILDHEADER"
3403 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3405 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3406 # Picture color depth:
3407 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3408 # Picture color count:
3409 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3411 printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
3412 # cat the image file:
3413 cat "$ALBUMARTFILE" >> "$BUILDHEADER"
3414 # Now process each ogg file by first exporting the original tags then
3415 # appending the cover image and finally copying the whole thing back
3416 # to the original image:
3419 # Make a backup of the existing tags:
3420 "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
3421 # base64 the file and then mix it all together with the exported tags:
3422 echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
3423 # Update the original ogg file with exported tags and the appended base64'd image:
3424 "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
3425 # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
3426 # note that the header file BUILDHEADER will be reused for each file in the loop:
3429 mkdir "$FINALDIR"/albumart_backup
3430 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3431 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3433 *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
3436 vecho "Suitable cover image not found, no embedding done..." >&2
3441 # do_cdread [tracknumber]
3442 # do_cdread onetrack [firsttrack] [lasttrack]
3446 # The commands here don't go through run_command because they're never supposed to be silenced
3447 # return codes need to be doublechecked anyway, however
3448 if [ "$1" = "onetrack" ]; then
3449 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3450 # FIXME # Until then, we grab the whole CD in one track, no matter what
3452 # We need the first and last track for cdda2wav/icedax
3454 LASTTRACK=$(($3 + 0))
3455 UTRACKNUM="$FIRSTTRACK"
3456 case "$CDROMREADERSYNTAX" in
3457 flac) READTRACKNUMS="-" ;;
3460 # Add a variable to check if tracks are provided in command line and if not, rip the whole CD
3461 # We must make sure to rip from sector 0, both lines below work
3462 # READTRACKNUMS="-- -$LASTTRACK" ;;
3463 READTRACKNUMS="[.0]-" ;;
3464 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3465 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3466 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3472 CDDBTRACKNUM=$(($UTRACKNUM - 1))
3473 if [ "$USEPIPES" = "y" ]; then
3474 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3475 FILEARG="$( eval echo "\$$TEMPARG" )"
3476 PIPE_MESSAGE="and encoding "
3478 WAVDATA="${ABCDETEMPDIR}/track$UTRACKNUM.wav"
3479 case "$CDROMREADERSYNTAX" in
3480 ## FIXME ## Find the cases for flac, to avoid exceptions
3482 FILEARG="--output-name=$WAVDATA"
3489 if [ "$1" = "onetrack" ]; then
3490 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3492 if [ -r "$CDDBDATA" ]; then
3493 getcddbinfo TRACKNAME
3494 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3496 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3499 case "$CDROMREADERSYNTAX" in
3500 ### FIXME ### use an exception for flac, since it uses -o
3501 ### FIXME ### Shall we just use -o $FILEARG ??
3503 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3504 STRIPTRACKNUM=$(( $UTRACKNUM + 0 ))
3505 nice $READNICE $FLAC -d -f --cue="${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0}" "$FILEARG" "$CDROM" ;;
3507 if [ "$USEPIPES" = "y" ]; then
3508 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG"
3510 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG" >&2
3514 if [ "$OSFLAVOUR" = "OSX" ] ; then
3515 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3516 diskutil unmount "${CDROM#/dev/}"
3517 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3518 CDDA2WAVCDROM="IODVDServices"
3519 elif [ "$OSFLAVOUR" = "FBSD" ] || [ "$OSFLAVOUR" = "IRIX" ]; then
3520 CDDA2WAVCDROM="$CDROMID"
3522 if [ "$CDROMID" = "" ]; then
3523 CDDA2WAVCDROM="$CDROM"
3525 CDDA2WAVCDROM="$CDROMID"
3528 if [ "$USEPIPES" = "y" ]; then
3529 nice $READNICE $CDROMREADER -D "$CDDA2WAVCDROM" -t "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG"
3531 nice $READNICE $CDROMREADER -D "$CDDA2WAVCDROM" -t "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG" >&2
3535 # I cannot get USEPIPES to work with dagrab so just this:
3536 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v "$UTRACKNUM" >&2
3539 if [ "$USEPIPES" = "y" ]; then
3540 nice $READNICE $CDROMREADER -j "${READTRACKNUMS:-$UTRACKNUM}" "$CDROM" "$FILEARG"
3542 # Write ripped audio data to stdout and redirect to $FILEARG.
3543 # Progress is written to stderr by default and thus >&2 is not required.
3544 nice $READNICE $CDROMREADER -j "${READTRACKNUMS:-$UTRACKNUM}" "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3548 # Find the track's mounted path
3549 REALTRACKNUM=$(($UTRACKNUM + 0))
3550 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3551 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3552 # If the file exists, copy it
3553 if [ -e "$FILEPATH" ] ; then
3554 if [ "$USEPIPES" = "y" ]; then
3555 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3557 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3563 if [ "$USEPIPES" = "y" ]; then
3564 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -w "$UTRACKNUM-[:1]" "$FILEARG"
3566 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -w "$UTRACKNUM-[:1]" "$FILEARG" >&2
3571 # If we get some error or we get some missing wav
3572 # (as long as we dont use pipes)
3573 if [ "$RETURN" != "0" ] || ( [ ! -s "$WAVDATA" ] && [ X"$USEPIPES" != "Xy" ] ); then
3574 # Thank goodness errors is only machine-parseable up to the
3575 # first colon, otherwise this woulda sucked
3576 if [ "$RETURN" = "0" ] || [ ! -s "$WAVDATA" ]; then
3577 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3579 if [ "$USEPIPES" = "y" ]; then
3580 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3582 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3586 if [ "$USEPIPES" = "y" ]; then
3587 echo "readencodetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
3589 echo "readtrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
3591 if [ "$1" = "onetrack" ]; then
3592 echo onetrack >> "${ABCDETEMPDIR}/status"
3598 # No values accepted, only uses env variables
3601 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3602 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3604 echo "abcde: unable to set the device speed" >&2
3610 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3613 if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 0 ] ; then
3615 warning) shift ; log warning "$@" ;;
3623 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3626 if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 1 ] ; then
3628 warning) shift ; log warning "$@" ;;
3636 # decho outputs a debug message if DEBUG is selected
3639 if [ x"$DEBUG" != "x" ]; then
3640 if echo "$1" | grep "^\[" > /dev/null 2>&1 ; then
3641 DEBUGECHO=$(echo "$@" | tr -d '[]')
3642 echo >&4 "[DEBUG] $DEBUGECHO: $(eval echo \\$${DEBUGECHO})"
3644 echo >&4 "[DEBUG] $1"
3649 # User-redefinable functions
3650 # Custom filename munging:
3653 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3656 # Custom filename munging specific to track names:
3662 # Custom filename munging specific to artist names:
3668 # Custom filename munging specific to album names:
3674 # Custom genre munging:
3677 echo "$CDGENRE" | tr "[:upper:]" "[:lower:]"
3681 # Empty pre_read function, to be defined in the configuration file.
3688 # Empty post_read function, to be defined in the configuration file.
3695 # Empty post_encode function, to be defined in the configuration file.
3701 ###############################################################################
3704 # Start of execution
3705 ###############################################################################
3710 # Currently three supported options ("musicbrainz", "cddb" for freedb.org and "cdtext")
3711 CDDBMETHOD=musicbrainz
3712 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3713 CDDBSUBMIT=freedb-submit@freedb.org
3715 HELLOINFO="$(whoami)@$(hostname)"
3717 CDDBLOCALPOLICY="always"
3718 CDDBLOCALRECURSIVE="y"
3719 CDDBLOCALDIR="$HOME/.cddb"
3722 # List of fields we parse and show during the CDDB parsing...
3723 SHOWCDDBFIELDS="year,genre"
3726 #CDROMREADERSYNTAX=cdparanoia
3727 ENCODERSYNTAX=default
3729 MP3ENCODERSYNTAX=default
3730 OGGENCODERSYNTAX=default
3731 OPUSENCODERSYNTAX=default
3732 MKAENCODERSYNTAX=default
3733 AIFFENCODERSYNTAX=default
3734 FLACENCODERSYNTAX=default
3735 SPEEXENCODERSYNTAX=default
3736 MPCENCODERSYNTAX=default
3737 WVENCODERSYNTAX=default
3738 TTAENCODERSYNTAX=default
3739 APENCODERSYNTAX=default
3740 MP2ENCODERSYNTAX=default
3741 AACENCODERSYNTAX=default
3742 NORMALIZERSYNTAX=default
3743 CUEREADERSYNTAX=default
3745 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3746 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3747 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3748 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3749 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3750 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3751 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3752 PLAYLISTDATAPREFIX=''
3753 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3754 VAPLAYLISTDATAPREFIX=''
3762 VARIOUSARTISTSTYLE=forward
3769 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3770 # i.e. CDROMID="1,0,0"
3772 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3773 # If we are using the ide-scsi emulation layer, we need to define a "g"
3774 CDPARANOIACDROMBUS="d"
3776 # program paths - defaults to checking your $PATH
3782 XINGMP3ENC=xingmp3enc
3796 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3800 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3810 NEROAACENC=neroAacEnc
3812 # Note that the qaac PATH will almost always require adjustment
3813 # as it is a Windows application being run through Wine. More
3814 # detailed notes in the sample abcde.conf file in the abcde tarball.
3817 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3825 VORBISCOMMENT=vorbiscomment
3827 NEROAACTAG=neroAacTag
3828 ATOMICPARSLEY=AtomicParsley
3832 CDPARANOIA=cdparanoia
3833 CD_PARANOIA="cd-paranoia"
3838 CDDISCID="cd-discid"
3840 MUSICBRAINZ=abcde-musicbrainz-tool
3844 NORMALIZE="normalize-audio"
3846 VORBISGAIN=vorbisgain
3850 # For Wavpack replay gain we set both the default of 'track gain'
3851 # as well as this option for 'album gain'. Better media players
3852 # such as vlc can select either or neither. Andrew.
3863 # Options for programs called from abcde:
3866 # These options needed by FFmpeg for tagging and selection of id3v2 version:
3867 # 1. '-write_id3v2 1' allows id3v2 tagging while '-write_id3v2 0' disables tagging
3868 # 2. '-id3v2_version 4' gives version id3v2.4 while '3' gives id3v2.3
3869 AIFFENCOPTS="-write_id3v2 1 -id3v2_version 4"
3881 VORBISGAINOPTS="--album"
3885 # The flac option is a workaround for an error where flac fails
3886 # to encode with error 'floating point exception'. This is flac
3887 # error in get_console_width(), corrected in flac 1.3.1
3889 FLACGAINOPTS="--add-replay-gain"
3896 # True Audio has no useful options but it is here anyway :)
3899 # Monkey's Audio Console (mac) chokes without a mode setting
3900 # so we set one here.
3907 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3908 # we set bitrate here.
3909 FDKAACENCOPTS='--bitrate 192k'
3931 VORBISCOMMENTOPTS="-R"
3932 METAFLACOPTS="--no-utf8-convert"
3937 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3939 # Defaults for album art downloads
3940 ALBUMARTFILE="cover.jpg"
3942 ALBUMARTALWAYSCONVERT="n"
3944 # Default to one process if -j isn't specified
3947 # List of actions to perform - by default, run to completion
3948 ACTIONS=cddb,read,encode,tag,move,clean
3950 # This option is basically for Debian package dependencies:
3951 # List of preferred outputs - by default, run with whatever we have in the path
3952 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:fdkaac:opus
3954 # List of preferred cdromreaders - by default, run whichever we have in the path
3955 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3957 # fd for when `vecho` and `log info` called with redirected stdout
3960 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3961 # Linux/OpenBSD. ftp is user for NetBSD.
3962 # Let's use these checkings to determine the OS flavour, which will be used
3965 if [ X"$UNAME" = "XFreeBSD" ] ; then
3970 elif [ X"$UNAME" = "XDarwin" ] ; then
3972 # By default md5sum is not installed, use md5 instead:
3975 # We should have diskutil in OSX, but let's be sure...
3977 CDROMREADERSYNTAX=cddafs
3978 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3980 elif [ X"$UNAME" = "XOpenBSD" ] ; then
3984 elif [ X"$UNAME" = "XNetBSD" ] ; then
3988 elif [ X"$UNAME" = X"SunOS" ] ; then
3992 elif [ X"$UNAME" = X"IRIX64" ] ; then
3996 # Apparently necessary - see
3997 # https://abcde.einval.com/bugzilla/show_bug.cgi?id=29
3998 CDDISCID_NEEDS_PAUSE=y
4003 # If CDDBAVAIL is set to n, no CDDB read is done
4007 # But before we get into business, let us chop off any GREP environmental
4012 # Length of the terminal *should* be in $LINES. If it's not, guess at
4013 # a reasonable number instead
4014 if [ -z "$LINES" ]; then
4018 if [ -z "$OUTPUTDIR" ]; then
4022 if [ -z "$WAVOUTPUTDIR" ]; then
4023 WAVOUTPUTDIR="$OUTPUTDIR"
4026 # Load system defaults
4027 if [ -r /etc/abcde.conf ]; then
4030 # Load user preference defaults
4031 if [ -r "$HOME/.abcde.conf" ]; then
4032 . "$HOME/.abcde.conf"
4035 # By this time, we need some HTTPGETOPTS already defined.
4036 # If the user has defined a non-default HTTPGET method, we should not be empty.
4038 if [ "$HTTPGETOPTS" = "" ] ; then
4040 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
4041 curl) HTTPGETOPTS="-f -s -L";;
4042 fetch)HTTPGETOPTS="-q -o -";;
4043 ftp) HTTPGETOPTS="-a -V -o - ";;
4044 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
4048 # If the CDROM has not been set yet, find a suitable one.
4049 # If this is a devfs system, default to /dev/cdroms/cdrom0
4050 # instead of /dev/cdrom
4051 if [ "$CDROM" = "" ] ; then
4052 if [ -e /dev/cdroms/cdrom0 ]; then
4053 CDROM=/dev/cdroms/cdrom0
4054 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
4055 CDROM=/dev/${BASH_REMATCH[1]}
4056 elif [ -e /dev/cdrom ]; then
4058 elif [ -e /dev/sr0 ]; then
4060 elif [ -e /dev/cd0c ]; then
4062 elif [ -e /dev/acd0c ]; then
4064 elif [ -e /dev/disk1 ]; then
4069 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
4070 # that's changed to a number to allow for more control. Deal with
4071 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
4072 case "$EXTRAVERBOSE" in
4081 # Parse command line options
4082 while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pP:Q:r:s:S:t:T:UvVxX:w:W:z opt ; do
4085 a) ACTIONS="$OPTARG" ;;
4086 A) EXPACTIONS="$OPTARG" ;;
4088 B) GETALBUMART=y ; EMBEDALBUMART=y ;;
4089 c) if [ -e "$OPTARG" ]; then
4092 log error "config file \"$OPTARG\" cannot be found."
4096 C) CDDBDISCID="$( echo "${OPTARG#abcde.}" | tr -d /)" ;;
4097 d) CDROM="$OPTARG" ;;
4100 e) ERASEENCODEDSTATUS=y ;;
4101 E) ENCODING="$OPTARG" ;;
4106 j) MAXPROCS="$OPTARG" ;;
4109 L) CDDBUSELOCAL=y ;;
4114 o) OUTPUTTYPE="$OPTARG" ;;
4117 Q) CDDBMETHOD="$OPTARG" ;;
4118 r) REMOTEHOSTS="$OPTARG" ;;
4119 R) CDDBLOCALRECURSIVE=y ;;
4120 s) SHOWCDDBFIELDS="$OPTARG" ;;
4121 S) CDSPEEDVALUE="$OPTARG" ;;
4122 t) STARTTRACKNUMBER="$OPTARG" ;;
4123 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
4126 echo "This is abcde v$VERSION."
4127 echo "Usage: abcde [options] [tracks]"
4128 echo "abcde -h for extra help"
4131 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
4133 X) CUE2DISCID="$OPTARG" ;;
4134 w) COMMENT="$OPTARG" ;;
4135 W) if echo "$OPTARG" | grep "[[:digit:]]" > /dev/null 2>&1 ; then
4136 STARTTRACKNUMBER="${OPTARG}$(printf "%02d" "${STARTTRACKNUMBER:-01}")"
4137 STARTTRACKNUMBERTAG="y"
4138 COMMENT="CD${OPTARG}"
4139 DISCNUMBER="${OPTARG}"
4141 log error "argument of -W must be integer"
4145 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
4150 shift $(($OPTIND - 1))
4152 # Here it comes the worse part of the whole thing. From here until we start
4153 # ripping, we have a mixture of sanity checks, verifications, default settigs
4154 # and other crazy stuff that interdepends, but hey, someone has to do it.
4156 # If NOCDDBQUERY is set, don't query the CDDB server.
4157 if [ "$NOCDDBQUERY" = "y" ]; then
4161 # If the user specified a flac file, then switch to special flac mode
4162 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
4163 if [ ! -f "$CDROM" ]; then
4164 log error "the defined file for FLAC ripping cannot be found" >&2
4167 vecho warning "switching to flac CDROMREADERSYNTAX..."
4168 CDROMREADERSYNTAX=flac
4169 # We have a builtin version of cue2discid...
4170 case "$CUE2DISCID" in
4172 *) NEEDCUE2DISCID=y;;
4178 # If the user provided a CDDBDISCID, disable eject
4179 if [ -n "${CDDBDISCID}" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
4181 # Check the available cd rippers in the system, from the ones we know.
4182 if [ "$CDROMREADERSYNTAX" = "" ]; then
4183 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
4184 if new_checkexec "$DEFAULT_CDROMREADER"; then
4185 CDROMREADERSYNTAX="$DEFAULT_CDROMREADER"
4189 if [ "$CDROMREADERSYNTAX" = "" ]; then
4190 log error "no cdreader found in your PATH"
4191 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4196 # Decide if we can continue.
4197 if [ "$ONETRACK" = "y" ]; then
4198 # FIXME # remove check as soon as we find out about the other readers
4199 case "$CDROMREADERSYNTAX" in
4201 cdparanoia | libcdio) ;;
4202 cdda2wav | icedax) ;;
4204 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
4207 if [ "$BATCHNORM" = "y" ]; then
4208 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
4211 if [ "$NOGAP" = "y" ]; then
4212 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
4215 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
4216 # FIXME # allow ranges of tracks to be selected for onetrack ripping
4217 if [ $# -gt 0 ]; then
4218 log warning "ONETRACK mode selected, grabbing all tracks..."
4221 while [ $# -gt 0 ]; do
4222 # Range parsing code courtesy of Vincent Ho
4223 # Cleaned up to use shell built-ins by Charles Steinkuehler
4224 if [ "${1#*[^0-9-]}" != "$1" ]; then
4225 log error "syntax error while processing track numbers ($1)"
4230 while [ "${RSTART:=1}" -le "${REND:=0}" ] ; do
4231 TRACKQUEUE="$TRACKQUEUE $RSTART"
4232 RSTART=$(( $RSTART + 1 ))
4239 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
4240 # List of experimental actions: retag,transcode
4242 # Determine what actions are to be done from $ACTIONS and set the
4243 # following environment variables for them:
4255 ## FIXME ## Lets keep compatibility with -M
4256 [ "$DOCUE" != "y" ] && DOCUE=n
4258 for ACTION in $(echo "$ACTIONS" | tr , \ )
4261 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4262 cue) DOCUE=y ; MAKECUEFILE=y ;;
4265 normalize) DONORMALIZE=y; DOREAD=y;;
4266 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4267 encode) DOENCODE=y; DOREAD=y;;
4268 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4269 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4270 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4271 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4272 playlist) DOCDDB=y; DOPLAYLIST=y;;
4274 getalbumart) GETALBUMART=y;;
4275 embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
4279 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4280 # FIXME # should we abort on error or just inform the user?
4281 log warning "selected both normalize and replaygain actions"
4284 for SHOWCDDBFIELD in $(echo "$SHOWCDDBFIELDS" | tr , \ ); do
4285 case $SHOWCDDBFIELD in
4286 y*|Y*) SHOWCDDBYEAR="y";;
4287 g*|G*) SHOWCDDBGENRE="y";;
4292 # At this point a CDROM has to be defined, so we check it exists.
4293 if [ X"$CDROM" != "X" ] ; then
4294 if [ "$NEEDCDROMID" = "y" ] ; then
4295 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ]; then
4296 if [ "$OSFLAVOUR" = "IRIX" ]; then
4297 if [ -z "$CDROMID" ]; then
4298 CDROMID="$(echo "$CDROM" | sed -e 's;/dev/scsi/sc\([0-9]*\)d\([0-9]*\)l\([0-9]*\)$;\1,\2,\3;')"
4301 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
4302 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4303 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4307 elif [ ! -e "$CDROM" ] && [ X"$DOREAD" = "Xy" ]; then
4308 log error "CDROM device cannot be found."
4311 # avoid processing if we are not going to hit the CDROM.
4312 elif [ X"$DOREAD" = "Xy" ]; then
4313 log error "CDROM has not been defined or cannot be found"
4317 # USEPIPES pre-tests, before we get into more serious stuff
4318 # Not compatible with:
4319 # - multiple outputs
4321 # - lowdisk algorithm
4323 if [ X"$USEPIPES" = "Xy" ]; then
4324 NUM_OUTPUT_TYPES="$(echo "$OUTPUTTYPE" | tr , \ | wc -w )"
4325 if [ "$NUM_OUTPUT_TYPES" -gt 1 ]; then
4326 log error "Unix pipes not compatible with multiple outputs"
4329 if [ X"$DONORMALIZE" = "Xy" ]; then
4330 log error "Unix pipes not compatible with normalizer"
4331 # FIXME # Do we need to exit or shall we just disable the mode?
4334 if [ X"$BATCHNORM" = "Xy" ]; then
4335 log error "Unix pipes not compatible with BATCHNORM encoding"
4338 if [ X"$NOGAP" = "Xy" ]; then
4339 log error "Unix pipes not compatible with NOGAP encoding"
4342 if [ X"$DOENCODE" = "Xn" ]; then
4343 vecho warning "Disabling Unix pipes since we are not encoding!"
4346 if [ X"$LOWDISK" = "Xy" ]; then
4347 log error "Unix pipes not compatible with lowdisk algorithm"
4352 # LOWDISK pre-tests, before we get into more problematic stuff
4353 # Not compatible with anything that needs all the files in the hard disc:
4356 if [ X"$LOWDISK" = "Xy" ]; then
4357 if [ X"$BATCHNORM" = "Xy" ]; then
4358 log error "Unix pipes not compatible with BATCHNORM encoding"
4361 if [ X"$NOGAP" = "Xy" ]; then
4362 log error "Unix pipes not compatible with NOGAP encoding"
4367 # BATCHNORM pre-tests, before we get into serious problems
4368 # Not compatible with
4369 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4370 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4374 # Check the encoding format from the ones available in the system, if nothing has been configured.
4375 if [ X"$OUTPUTTYPE" = "X" ]; then
4376 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4377 DEFAULT_OUTPUT_FORMAT="$(echo "$DEFAULT_OUTPUT" | cut -d ":" -f 1)"
4378 DEFAULT_OUTPUT_BINARY="$(echo "$DEFAULT_OUTPUT" | cut -d ":" -f 2)"
4379 if [ -x "$(which "$DEFAULT_OUTPUT_BINARY")" ] ; then
4380 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4381 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4385 if [ X"$OUTPUTTYPE" = "X" ]; then
4386 log error "no encoder found in the PATH"
4387 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4392 # Decide which CDROM reader we're gonna use
4393 case "$CDROMREADERSYNTAX" in
4395 CDROMREADER="$CDPARANOIA"
4396 CDROMREADEROPTS="$CDPARANOIAOPTS"
4399 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4400 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4401 CDROMREADER="$CD_PARANOIA"
4402 CDROMREADEROPTS="$CDPARANOIAOPTS"
4405 CDROMREADER="$CDDA2WAV"
4406 CDROMREADEROPTS="$CDDA2WAVOPTS"
4409 CDROMREADER="$DAGRAB"
4410 CDROMREADEROPTS="$DAGRABOPTS"
4414 CDROMREADEROPTS="$PIRDOPTS"
4417 CDROMREADER="$CDDAFS"
4418 CDROMREADEROPTS="$CDDAFSOPTS"
4422 CDROMREADEROPTS="$FLACOPTS"
4426 # There's only one normalize...
4427 case "$NORMALIZERSYNTAX" in
4429 NORMALIZER="$NORMALIZE"
4430 NORMALIZEROPTS="$NORMALIZEOPTS"
4434 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4435 case "$OUTPUTTYPE" in *:*)
4436 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4437 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4439 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4440 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4441 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4442 aiff:*) AIFFENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4443 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4444 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4445 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4446 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4447 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4448 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4449 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4450 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4451 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4454 # Allows commandline selection of options while using multiple outputs.
4455 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4456 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4457 TEMPOUTPUT=${OUTPUT%%:*}
4458 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4460 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4464 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4465 # for flacs and speexenc for speex and mpcenc for mpcs and fdkaac for m4as and
4466 # wavpack for wvs...
4468 # Getting ready for multiple output changes
4469 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
4473 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4474 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4475 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4476 OGGOUTPUTCONTAINER=ogg
4479 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4480 OPUSOUTPUTCONTAINER=opus
4483 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4484 MKAOUTPUTCONTAINER=mka
4487 [ "$AIFFENCODERSYNTAX" = "default" ] && AIFFENCODERSYNTAX=ffmpeg
4488 AIFFOUTPUTCONTAINER=aiff
4491 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4492 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4493 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4494 [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
4497 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4498 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4499 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4500 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4501 [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
4504 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4505 # [ "$DOREPLAYGAIN" = "y" ] &&
4508 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4509 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4512 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4514 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4515 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4516 [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
4519 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4520 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4523 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4524 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4525 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4528 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4529 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4530 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4533 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4535 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4536 # compiled without libmp4v2... Andrew.
4539 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=fdkaac
4540 [ "$AACENCODERSYNTAX" = "faac" ] && [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4541 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4542 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4543 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4544 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4545 [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
4548 if [ "$KEEPWAVS" = "y" ]; then
4549 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4553 *) log error "Invalid OUTPUTTYPE defined"
4559 # decide which encoder
4560 case "$MP3ENCODERSYNTAX" in
4562 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4566 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4570 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4571 MP3ENCODER="$BLADEENC"
4574 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4578 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4579 MP3ENCODER="$XINGMP3ENC"
4582 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4583 MP3ENCODER="$MP3ENC"
4586 case "$OGGENCODERSYNTAX" in
4588 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4589 OGGENCODER="$VORBIZE"
4592 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4593 OGGENCODER="$OGGENC"
4596 case "$OPUSENCODERSYNTAX" in
4598 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4599 OPUSENCODER="$OPUSENC"
4602 case "$MKAENCODERSYNTAX" in
4604 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4605 MKAENCODER="$FFMPEG"
4608 case "$AIFFENCODERSYNTAX" in
4610 AIFFENCODEROPTS="${AIFFENCODEROPTSCLI:-$AIFFENCOPTS}"
4611 AIFFENCODER="$FFMPEG"
4614 case "$FLACENCODERSYNTAX" in
4616 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4618 if [ "$DOREPLAYGAIN" = "y" ]; then
4619 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4621 # FLAC streams can be encapsulated on a Ogg transport layer
4622 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4623 log error "FLAC on an Ogg container is not yet supported"
4624 log error "due to problem with adding comments to such files"
4626 FLACOUTPUTCONTAINER=ogg
4628 FLACOUTPUTCONTAINER=flac
4632 case "$SPEEXENCODERSYNTAX" in
4634 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4635 SPEEXENCODER="$SPEEXENC"
4638 case "$MPCENCODERSYNTAX" in
4640 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4641 MPCENCODER="$MPCENC"
4644 case "$WVENCODERSYNTAX" in
4646 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4647 # and in the interests of backward compatibility:
4648 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4649 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4650 WVENCODER="$WAVPACK"
4652 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4653 WVENCODER="$WAVPACK"
4657 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4661 case "$TTAENCODERSYNTAX" in
4663 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4667 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4668 TTAENCODER="$TTAENC"
4671 case "$APENCODERSYNTAX" in
4673 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4677 case "$MP2ENCODERSYNTAX" in
4679 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4680 MP2ENCODER="$TWOLAME"
4683 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4684 MP2ENCODER="$FFMPEG"
4687 case "$AACENCODERSYNTAX" in
4688 # Some elaborate 'if' work to keep backward compatibility for those
4689 # who don't realise that AACENCOPTS does not work with abcde from
4690 # version 2.7 onwards.
4692 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4693 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4696 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4701 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4702 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4703 AACENCODER="$NEROAACENC"
4705 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4706 AACENCODER="$NEROAACENC"
4710 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4711 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4712 AACENCODER="$FDKAAC"
4714 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4715 AACENCODER="$FDKAAC"
4719 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4720 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4723 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4728 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4729 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4730 AACENCODER="$FHGAACENC"
4732 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4733 AACENCODER="$FHGAACENC"
4737 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4738 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4739 AACENCODER="$FFMPEG"
4741 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4742 AACENCODER="$FFMPEG"
4752 TAGGEROPTS="$ID3OPTS"
4757 TAGGEROPTS="$ID3V2OPTS"
4762 TAGGEROPTS="$ID3TAGOPTS"
4766 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4767 # trouble with CDDBPROTO=5 (which we test here) but also
4768 # with cached cddb files in latin1 (which we cannot test).
4769 if [ "$CDDBPROTO" -lt 6 ]; then
4770 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4773 # eyeD3 version 0.7 changed syntax
4774 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4775 # only if it offers the --set-encoding, assume <= 0.6.x
4777 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4779 # anything wrong, any failure, assume >= 0.7
4781 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4785 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4790 # NOGAP is specific to lame. Other encoders fail ...
4791 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4792 log warning "the NOGAP option is specific to lame. Deactivating..."
4797 case "$CUEREADERSYNTAX" in
4799 CUEREADEROPTS="${CDROM}"
4803 CUEREADEROPTS="$MKCUEOPTS ${CDROM}"
4808 # which information retrieval tool are we using?
4814 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4815 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4816 log error "FLAC on an Ogg container is not yet supported"
4817 log error "due to problem with adding comments to such files"
4819 OGGOUTPUTCONTAINER=ogg.ogg
4820 FLACOUTPUTCONTAINER=flac.ogg
4821 vecho warning "modified file endings due to conflicting transport"
4822 vecho warning "layers in Ogg/Vorbis and Ogg/FLAC"
4825 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4827 if [ "$ENCNICE" ]; then
4828 ENCNICE="-n $ENCNICE"
4830 if [ "$READNICE" ]; then
4831 READNICE="-n $READNICE"
4833 if [ "$DISTMP3NICE" ]; then
4834 DISTMP3NICE="-n $DISTMP3NICE"
4837 # Don't check for stuff if it's not needed
4838 if [ "$REMOTEHOSTS" ]; then
4841 if [ "$DONORMALIZE" = "y" ]; then
4844 if [ "$EJECTCD" = "y" ]; then
4847 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4848 # Need an http tool to be able to do CDDB
4854 if [ "$DOCUE" = "y" ]; then
4858 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4859 case "$CDROMREADERSYNTAX" in
4860 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4861 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4862 ### FIXME ### translate "cue2discid" from python to bash
4863 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4868 if [ "$GETALBUMART" = "y" ]; then
4873 ###USEPIPESSUPPORT###
4875 # Rippers with USEPIPE support
4876 PIPERIPPER_cdparanoia="-"
4877 PIPERIPPER_libcdio="-"
4878 # Note that by default in abcde cdda2wav redirects to icedax.
4879 PIPERIPPER_cdda2wav="-"
4880 PIPERIPPER_debug="-"
4881 PIPERIPPER_flac="-c "
4884 # Encoders with USEPIPE support
4887 PIPE_bladeenc="stdin"
4900 # Both neroAacEnc and fdkaac seem to manage without the addition of
4901 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4902 # in this manner. Andrew.
4906 # Figure out if we can use pipes with the ripper/encoder combination
4908 if [ "$USEPIPES" = "y" ]; then
4909 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4912 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4914 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4916 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4918 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4920 PIPEENCODERSVARCHECK="PIPE_$AIFFENCODERSYNTAX" ;;
4922 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4924 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4926 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4928 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4930 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4932 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4934 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4936 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4937 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4938 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4939 log error "no support for pipes with given ripper"
4940 log error "read the FAQ file from the source tarball to get help."
4943 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4944 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4945 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4946 log error "no support for pipes with given encoder"
4947 log error "read the FAQ file from the source tarball to get help"
4952 # Make sure a buncha things exist
4953 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4954 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4955 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER $AIFFENCODER \
4956 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4957 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4958 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4959 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4960 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4961 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4962 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4963 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4964 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4965 ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
4970 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4971 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4972 # these files). The resulting files are actually ADTS streams which belong in an
4973 # aac container and with some version sniffing this is all cleaned up below. If
4974 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4976 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4977 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4978 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4979 echo "WARNING: Your copy of Faac does not have mp4 support"
4980 echo "WARNING: Encoding untagged files to aac..."
4981 # Replace m4a with aac for single and multi-output encodes:
4982 OUTPUTTYPE=$(echo "$OUTPUTTYPE" | sed 's/m4a/aac/')
4984 echo "Using Faac to Tag AAC Tracks..."
4988 # And last but not least, check if we can diff between files. We do not abort,
4989 # since diffing is not critical...
4990 if [ -x "$(which "$DIFF")" ]; then :; else
4991 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4995 ## Now that we have metaflac, check if we need cue2discid
4996 #case $CDROMREADERSYNTAX in
4998 # CDDBTRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4999 # if [ "$CDDBTRACKINFO" = "" ]; then
5000 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
5005 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
5006 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
5007 HTTPGET="$HTTPGET $HTTPGETOPTS"
5009 # Here it used to say:
5010 # One thousand lines in, we can start doing stuff with things
5011 # Well, right now we are at line 3737 ;)
5012 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
5014 # Export needed things so they can be read in this subshell
5015 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
5016 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
5018 if [ "$DOREAD" = "y" ]; then
5019 # User-definable function to set some things. Use it for
5020 # - closing the CD tray with eject -t
5021 # - set the CD speed value with eject -x
5022 vecho -n "Executing customizable pre-read function... "
5024 pre_read # Execute the user-defined pre-read function. Close the CD with it.
5029 # Get ABCDETEMPDIR created and status file initialized
5032 if [ "$DOCDDB" = "y" ]; then
5033 # start with a sane default:
5034 CDDBLOCALSTATUS=notfound
5035 if [ $CDDBUSELOCAL = "y" ]; then
5038 if checkstatus cddb-choice > /dev/null; then
5042 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
5044 for CDDBMETHCHOICE in $(echo "$CDDBMETHOD" | tr -d ' ' | tr , ' ')
5046 addstatus "Lookup method $idx: $CDDBMETHCHOICE"
5048 vecho "Found $NUM_CDDB_MATCHES matches so far"
5049 vecho "Trying lookup method ${CDDBMETHCHOICE}"
5051 # Run all the desired data acquisition methods, in the order
5052 # specified by the user. Each will use its own temporary
5053 # subdirectory, then copy the cddbread.* etc. files up into
5055 case "$CDDBMETHCHOICE" in
5066 echo "Unknown lookup method $CDDBMETHCHOICE. Aborting." >&2
5073 rm -f "${ABCDETEMPDIR}/cddbchoices"
5074 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
5076 if [ $NUM_CDDB_MATCHES = 0 ]; then
5077 # If we got no matches, we need to
5078 # generate a blank CDDB template.
5079 vecho "Unable to find any matches, generating unknown template."
5080 echo "No lookup matches." >> "${ABCDETEMPDIR}/cddbchoices"
5081 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
5082 echo "template" > "${ABCDETEMPDIR}/datasource.0"
5083 # List out disc title/author and contents of template
5084 echo ---- Unknown Artist / Unknown Album ---- >> "${ABCDETEMPDIR}/cddbchoices"
5086 for TRACK in $(f_seq_row 1 $TRACKS)
5088 echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5090 echo >> "${ABCDETEMPDIR}/cddbchoices"
5091 echo cddb-read-0-complete >> "${ABCDETEMPDIR}/status"
5092 echo cddb-choice=0 >> "${ABCDETEMPDIR}/status"
5093 echo 503 > "${ABCDETEMPDIR}/cddbquery"
5095 # We have matches; create the cddbchoices and cddbquery
5096 # files from all the inputs we have
5097 if [ $NUM_CDDB_MATCHES = 1 ]; then
5098 echo "Retrieved 1 match..." >> "${ABCDETEMPDIR}/cddbchoices"
5099 echo -n "200 " > "${ABCDETEMPDIR}/cddbquery"
5100 cat "${ABCDETEMPDIR}/cddbquery.1" >> "${ABCDETEMPDIR}/cddbquery"
5102 echo "Retrieved $NUM_CDDB_MATCHES matches..." >> "${ABCDETEMPDIR}/cddbchoices"
5103 echo "210 Found exact matches, list follows (until terminating .)" > "${ABCDETEMPDIR}/cddbquery"
5104 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5106 cat "${ABCDETEMPDIR}/cddbquery.$X" >> "${ABCDETEMPDIR}/cddbquery"
5108 echo "." >> "${ABCDETEMPDIR}/cddbquery"
5111 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5113 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.$X" | cut -c8- | tr -d \\r\\n)
5114 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$X")
5115 echo "#$X ($SOURCE): ---- ${ATITLE} ----" >> "${ABCDETEMPDIR}/cddbchoices"
5116 for TRACK in $(f_seq_row 1 $TRACKS)
5118 echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5120 echo >> "${ABCDETEMPDIR}/cddbchoices"
5127 eval "$($CDDBTOOL parse "$CDDBDATA")"
5130 # Before reading tracks, we set the speed of the device
5132 if [ X"$CDSPEEDVALUE" != "X" ]; then
5133 case "$CDROMREADERSYNTAX" in
5134 cdparanoia|libcdio|debug) ;;
5141 # Define the first and last track, since we might need them later in several places
5142 FIRSTTRACK=$( get_first $TRACKQUEUE )
5143 LASTTRACK=$( get_last $TRACKQUEUE )
5145 if [ -f "${ABCDETEMPDIR}/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
5146 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
5147 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
5148 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
5151 if checkstatus onetrack ; then ONETRACK=y ; fi
5153 if [ "$ONETRACK" = "y" ]; then
5154 # Reuse the CUEFILE in case we created it (now or in a previous run)
5155 if CUEFILE=$(checkstatus cuefile); then
5160 # Create playlist if needed (backgroundable) and start reading in tracks
5164 if [ ! "$ONETRACK" = "y" ]; then
5165 if [ "$DOPLAYLIST" = "y" ]; then
5166 echo Creating playlist... >&2
5171 if [ "$GETALBUMART" = "y" ]; then
5175 # For the lowdisk option, only one program is running at once so the encoder
5176 # can be unsilenced right away.
5177 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
5178 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5181 if [ "$ONETRACK" = "y" ]; then
5182 TRACKS="$FIRSTTRACK"
5183 if [ "$USEPIPES" = "y" ]; then
5184 if checkstatus "readencodetrack-$FIRSTTRACK"; then :; else
5185 do_cdread onetrack "$FIRSTTRACK" "$LASTTRACK" | do_encode "$FIRSTTRACK" %local0% > /dev/null 2>&1
5188 if checkstatus "readtrack-$FIRSTTRACK"; then :; else
5189 do_cdread onetrack "$FIRSTTRACK" "$LASTTRACK"
5193 for UTRACKNUM in $TRACKQUEUE
5195 if [ "$DOREAD" = "y" ]; then
5196 if [ "$USEPIPES" = "y" ]; then
5197 if checkstatus "readencodetrack-$UTRACKNUM"; then :; else
5198 # Read, pipe, shut up!
5199 do_cdread "$UTRACKNUM" | do_encode "$UTRACKNUM" %local0% > /dev/null 2>&1
5202 if checkstatus "readtrack-$UTRACKNUM"; then :; else
5203 do_cdread "$UTRACKNUM"
5205 if [ "$?" != "0" ]; then
5206 # CD read failed - don't give the goahead to
5213 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
5216 # If we are not reading, set the encode output to loud already, so
5217 # that we can see the output of the first track.
5218 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
5219 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5221 echo NEXTTRACK # Get the encoder machine churning again
5222 if [ "$DOREAD" = "y" ]; then
5223 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
5224 until checkstatus "encodetrack-$UTRACKNUM"
5226 if checkerrors "encodetrack-$UTRACKNUM"; then
5237 # Now that we're done the encoding can be loud again -
5238 # if we're not using SMP.
5239 if [ "$MAXPROCS" = "1" ]; then
5240 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5243 # All tracks read, start encoding.
5244 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
5248 # Execute the user-defined post_read function before ejecting CD
5251 # We are now finished with the cdrom - it can be safely ejected. Note that
5252 # abcde will not have completed yet.
5253 if [ "$EJECTCD" = "y" ]; then
5254 # We check if the disk we are processing is actually the disk inside the
5255 # CD tray. If not, we do not eject the CD, since it might be so that the
5256 # user ejected it manually.
5257 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
5258 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$CDDBTRACKINFO" ] ; then
5259 # More FreeBSD bits.
5260 if [ X"$UNAME" = X"FreeBSD" ] ; then
5261 # FreeBSD eject uses the EJECT environment variable to name the CDROM
5262 # but in this script EJECT is in the envionment and names the program
5265 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
5266 cd="$(echo "$CDROM" | sed -e 's=.*/==;s=[a-h]$==;')"
5267 $eject $EJECTOPTS $cd
5268 elif [ X"$UNAME" = X"Darwin" ] ; then
5269 diskutil eject "${CDROM#/dev/}" 0
5270 elif [ -x "$(which "$EJECT")" ]; then
5271 $EJECT $EJECTOPTS "$CDROM"
5278 ## Do we need to pre-process
5279 #if [ x"$PREPROCESS" = "x" ] ; then
5282 # for PRETRACKNUM in $TRACKQUEUE
5285 # if [ "$GOAHEAD" = "NO" ]; then break; fi
5287 # until [ $PREPROCEED ]
5289 # if checkstatus "readtrack-$PRETRACKNUM"; then PREPROCEED=y; break; fi
5290 # # all locations are working, wait and try again later
5291 # if [ ! $PREPROCEED ]; then sleep 3; fi
5293 # ( do_preprocess $PRETRACKNUM
5301 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
5303 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
5304 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5305 if [ "$GOAHEAD" != "NO" ]; then
5306 for LASTTRACK in $TRACKQUEUE; do :; done
5307 if checkstatus "readtrack-$LASTTRACK"; then
5308 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
5309 if checkstatus "normalizetrack-$LASTTRACK"; then :; else do_batch_normalize; fi
5310 if checkerrors batch-normalize; then exit 1; fi
5312 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
5313 if [ "$DONORMALIZE" = "y" ]; then
5314 for UTRACKNUM in $TRACKQUEUE
5316 if checkstatus "readtrack-$UTRACKNUM"; then
5317 if checkstatus "normalizetrack-$UTRACKNUM"; then :; else do_normalize "$UTRACKNUM"; fi
5321 if checkstatus "encodetrack-$LASTTRACK"; then :; else do_nogap_encode; fi
5322 if checkerrors nogap-encode; then exit 1; fi
5328 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
5329 if [ "$ONETRACK" = "y" ] ; then
5330 TRACKQUEUE="$FIRSTTRACK"
5331 TRACKS="$FIRSTTRACK"
5334 # Do the encoding, including parallelization of remote encoding
5335 # Figure out where each track is going to be encoded
5336 ENCODELOCATIONS="$(echo "$REMOTEHOSTS" | tr , ' ')"
5337 if [ "$MAXPROCS" != "0" ]; then
5338 for NUM in $(f_seq_row 1 $MAXPROCS)
5340 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5344 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5345 for UTRACKNUM in $TRACKQUEUE
5348 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5349 if [ "$GOAHEAD" = "NO" ]; then break; fi
5350 # find out where this track is to be encoded
5351 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ]; then
5352 # Make sure we have a place to encode this, if not, exit stage right
5353 if [ -z "$ENCODELOCATIONS" ]; then
5359 for LOCATION in $ENCODELOCATIONS
5361 PREVIOUSTRACK="$(checkstatus "encodetracklocation-$LOCATION")"
5362 # check first if a track has ever been assigned to this location
5363 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5364 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5365 if checkerrors "encodetrack-$PREVIOUSTRACK"; then
5366 for TEMPLOCATION in $ENCODELOCATIONS
5368 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5369 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5372 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5377 # We're still here, this location must have been previously assigned,
5378 # and last completed without error - check if it's done with the
5379 # previous track yet
5380 if checkstatus "encodetrack-$PREVIOUSTRACK"; then PROCEED=y; break; fi
5382 # all locations are working, wait and try again later
5383 if [ ! "$PROCEED" ]; then sleep 3; fi
5385 # Record the location we're about to encode the next track at
5386 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
5388 # Don't proceed with the rest of the loop if we can't encode
5389 if [ "$ABORT" ]; then continue; fi
5390 ## FIXME ## Add here
5391 ## run_command "tagtrack-$OUTPUT-$1" $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
5392 # Set TRACKNUM, TRACKNAME
5393 if [ -e "$CDDBDATA" ]; then
5394 if [ "$ONETRACK" = "y" ]; then
5396 TRACKNUM="$FIRSTTRACK"
5399 TRACKNUM="$UTRACKNUM"
5400 CDDBTRACKNUM=$(($UTRACKNUM - 1))
5401 getcddbinfo TRACKNAME
5405 # You can't encode a file which needs to be normalized before finishing
5406 # You can't tag a file before it's finished encoding -
5407 # thus all of this is backgrounded together
5409 if [ "$DONORMALIZE" = "y" ]; then
5410 if checkstatus "readtrack-$UTRACKNUM"; then
5411 if checkstatus "normalizetrack-$UTRACKNUM"; then :; else do_normalize "$UTRACKNUM"; fi
5414 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ]; then
5415 if checkstatus "readtrack-$UTRACKNUM"; then
5416 if [ "$DONORMALIZE" = "y" ]; then
5417 if checkstatus "normalizetrack-$UTRACKNUM"; then
5418 if checkstatus "encodetrack-$UTRACKNUM"; then :; else do_encode "$UTRACKNUM" "$LOCATION" "$OUTPUT"; fi
5421 if checkstatus "encodetrack-$UTRACKNUM"; then :; else do_encode "$UTRACKNUM" "$LOCATION" "$OUTPUT"; fi
5425 if [ "$DOTAG" = "y" ]; then
5426 if checkstatus "encodetrack-$UTRACKNUM"; then
5427 if checkstatus "tagtrack-$UTRACKNUM"; then :; else do_tag "$UTRACKNUM"; fi
5429 # Lets tag the cue file
5430 if checkstatus cleancuefile >/dev/null; then :; else
5431 if checkstatus cuefile >/dev/null ; then
5436 if [ "$DOMOVE" = "y" ]; then
5437 if checkstatus "tagtrack-$UTRACKNUM"; then
5438 if checkstatus "movetrack-$UTRACKNUM"; then :; else do_move "$UTRACKNUM"; fi
5445 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5446 # we'll delete the files they're working on
5447 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5448 ## FIXME ## Check also for files which are encoded using PIPEs.
5449 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5454 for LOCATION in $ENCODELOCATIONS
5456 CHECKTRACK="$(checkstatus "encodetracklocation-$LOCATION")"
5457 # "How can he give us a status update, if he's DEAD?"
5458 if checkstatus "encodetrack-$CHECKTRACK"; then
5461 # Nothing to see here please go quietly back to your homes
5462 if [ -z "$CHECKTRACK" ]; then continue; fi
5463 # You're still here? Maybe there is something...
5464 if checkstatus "encodetrack-$CHECKTRACK"; then :; else PROCEED= ; break; fi
5467 if [ ! $PROCEED ]; then sleep 5; fi
5470 # If the above didn't catch the stragglers, this will
5472 if [ "$DOREPLAYGAIN" = "y" ]; then
5476 if [ "$EMBEDALBUMART" = "y" ]; then
5480 # Execute the user-defined post_encode function before cleaning up
5483 # Check to see if run_command logged any errors
5484 if [ -f "${ABCDETEMPDIR}/errors" ]; then
5485 log error "The following commands failed to run:"
5486 cat "${ABCDETEMPDIR}/errors"
5490 if [ "$KEEPWAVS" = "y" ];then
5494 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5495 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5496 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5497 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5498 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5499 log warning "The encoded formats does not match with the moved ones"
5500 log warning "Formats encoded: $( echo "$ENCODED_FORMATS" | tr "|" " " )"
5501 log warning "Formats moved: $( echo "$MOVED_FORMATS" | tr "|" " " )"
5502 log warning "Use \"abcde -a clean -f -C ${CDDBDISCID}\" to force the removal of the remaining data."
5506 if [ "$DOCLEAN" = "y" ]; then
5507 # Wipe all the evidence
5508 # Gimme gimme gimme some more time!
5510 rm -rf "${ABCDETEMPDIR}"
5513 echo "Finished. Not cleaning ${ABCDETEMPDIR}."