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
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")
230 # Check the terminal length every time we're called - the user
231 # might have resized since last time we were here
233 if new_checkexec tput; then
237 # If tput didn't work, 24 will do...
238 if [ -z "$LINES" ]; then
242 # Is the text long enough to need a pager?
243 if [ "$NUM_LINES" -ge $LINES ]; then
245 # Use the debian sensible-pager wrapper to pick the pager user
246 # has requested via their $PAGER environment variable
247 if [ -x "/usr/bin/sensible-pager" ]; then
248 /usr/bin/sensible-pager "$PAGEFILE"
249 elif [ -x "$PAGER" ]; then
250 # That failed, try to load the preferred pager, starting
251 # with their PAGER variable
253 # If that fails, check for less
254 elif [ -x /usr/bin/less ]; then
255 /usr/bin/less -f "$PAGEFILE"
256 # more should be on all UNIX systems
257 elif [ -x /bin/more ]; then
258 /bin/more "$PAGEFILE"
260 # No bananas, just cat the thing
264 # No, just cat the thing
269 # run_command [blurb] [command...]
270 # Runs a command, silently if necessary, and updates the status file
276 # See if this is supposed to be silent
277 if [ "$(checkstatus encode-output)" = "loud" ]; then
281 # Special case for SMP, since
282 # encoder output is never displayed, don't mute echos
283 if [ -z "$BLURB" ] && [ "$MAXPROCS" != "1" ]; then
292 normalize|normalize-audio)
293 if [ "$RETURN" = "2" ]; then
294 # File was already normalized.
299 if [ "$RETURN" != "0" ]; then
300 # Put an error in the errors file. For various reasons we
301 # can't capture a copy of the program's output but we can
302 # log what we attempted to execute and the error code
303 # returned by the program.
304 if [ "$BLURB" ]; then
307 echo "${TWEAK}returned code $RETURN: $@" >> "${ABCDETEMPDIR}/errors"
308 return $RETURN # Do not pass go, do not update the status file
310 if [ "$BLURB" ]; then
311 echo "$BLURB" >> "${ABCDETEMPDIR}/status"
315 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
316 # distributed under the terms of the GNU GPL v2 or later, at your option
318 # Function to determine if a word contains a slash.
327 # Function to give the relative path from one file to another.
328 # Usage: relpath fromfile tofile
329 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
330 # (the result would be Album/Song.mp3)
331 # Output is relative path to $2 from $1 on stdout
333 # This code has the following restrictions:
334 # Multiple ////s are not collapsed into single /s, with strange effects.
335 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
336 # If FR is a directory it must have a trailing /
344 /*) ;; # No processing is needed for absolute paths
346 # Loop through common prefixes, ignoring them.
347 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
349 FR="$(echo "$FR" | cut -d/ -f2-)"
350 TO="$(echo "$TO" | cut -d/ -f2-)"
352 # Loop through directory portions left in FR, adding appropriate ../s.
355 FR="$(echo "$FR" | cut -d/ -f2-)"
366 if [ ! "$@" = "" ]; then
367 # Cut off any command-line option we added in
368 X=$(echo "$@" | cut -d' ' -f2)
369 WHICH=$(which "$X" 2>/dev/null)
370 if [ -z "$WHICH" ]; then
372 elif [ ! -x "$WHICH" ]; then
381 if [ ! "$@" = "" ]; then
382 # Cut off any command-line option we added in
383 X=$(echo "$@" | cut -d' ' -f2)
384 # Test for built-in abcde.function
385 [ "$X" != "${X#abcde.}" ] && type "$X" >/dev/null 2>&1 && return
386 WHICH=$(which "$X" 2>/dev/null)
387 if [ -z "$WHICH" ]; then
388 log error "$X is not in your path." >&2
389 log info "Define the full path to the executable if it exists on your system." >&2
390 if [ -e /etc/debian_version ] ; then
393 MISSING_PACKAGE=vorbis-tools
395 lame|flac|cd-discid|eject|mkcue|icedax|glyrc)
399 log info "Hint: sudo apt-get install $MISSING_PACKAGE" >&2
402 elif [ ! -x "$WHICH" ]; then
403 log error "$X is not executable." >&2
409 # diffentries <filename> <max_value> <entry1>,<entry2>
410 # max_value: the range of entries goes from 1 to <max_value>
415 local CDDBDIFFCHOICES=$1
417 local CDDBDIFFCHOICE="$@"
418 if [ ! X"$DIFF" = "X" ]; then
419 PARSECHOICE1=$(echo "$CDDBDIFFCHOICE" | cut -d"," -f1 | xargs printf %d 2>/dev/null)
420 PARSECHOICE2=$(echo "$CDDBDIFFCHOICE" | cut -d"," -f2 | xargs printf %d 2>/dev/null)
421 if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$CDDBDIFFCHOICES" ] || \
422 [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$CDDBDIFFCHOICES" ] || \
423 [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
424 echo "Invalid diff range." >&2
425 echo "Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
427 # We parse the 2 choices to diff, store them in temporary files and diff them.
428 for PARSECHOICE in $(echo "$CDDBDIFFCHOICE" | tr , \ ); do
429 do_cddbparse "${ABCDETEMPDIR}/$FILENAME.$PARSECHOICE" > "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE"
431 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "${ABCDETEMPDIR}/$FILENAME.diff"
432 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE1" \
433 "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/$FILENAME.diff"
434 page "${ABCDETEMPDIR}/$FILENAME.diff"
437 echo "The diff program was not found in your path." >&2
438 echo "Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
443 # Finds an specific field from cddbinfo
448 TRACKNAME="$(grep -a "^TTITLE$CDDBTRACKNUM=" "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
451 TRACKNAME="$(grep -a "^TTITLE$CDDBTRACKNUM=" "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
454 grep -a "^EXTT$CDDBTRACKNUM=" "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
460 # Get the track number we are going to use for different actions
463 if [ -n "$STARTTRACKNUMBER" ] ; then
464 # Get the trackpadding from the current track, also trim whitespace for MacOSX
465 CURRENTTRACKPADDING=$(echo -n "$UTRACKNUM" | wc -c | tr -d ' ')
466 TRACKNUM=$( printf %0."${CURRENTTRACKPADDING}"d $(("${UTRACKNUM}" + "${STARTTRACKNUMBER}" - "${FIRSTTRACK}")))
468 TRACKNUM="${UTRACKNUM}"
474 # Calculate cddb disc ids without requiring specialized helper programs.
475 # largely copied from cd-discid and musicbrainz examples. some of the steps
476 # don't make sense, but they're necessary to match the ids generated by other
479 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
480 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
481 # 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
482 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
483 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
484 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
486 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
489 if [ X"$LEADOUT" = "X" ]; then
490 log warning "Error trying to calculate disc ids without lead-out information."
494 # default to a two second lead-in
496 LEADIN=${LEADIN:=150}
498 # number of cdframes per second
501 # reset cddb checksum for cddb disc-id calululation
505 for OFFSET in $OFFSETS
507 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
509 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
510 while [ $OFFSETTIME -gt 0 ]; do
511 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
512 OFFSETTIME=$(($OFFSETTIME / 10))
517 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
519 PREGAP=$(echo $OFFSETS | cut -f1 -d' ')
520 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
522 vvecho "makeids: PREGAP $PREGAP, LEADIN $LEADIN, LEADOUT $LEADOUT"
524 # Calculate both the cddb discid *and* the musicbrainz discid
525 # now. We'll use the cddb discid for reference in most cases
526 # for consistency, but we also have the musicbrainz discid for
528 printf -v CDDBDISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
529 CDDBTRACKINFO="${CDDBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
533 # FIXME: don't assume the first track is 1
534 MBDISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $(($PREGAP + $LEADOUT)) $OFFSETS)
536 if [ $error != 0 ]; then
537 log error "$MUSICBRAINZ failed to run; ABORT"
540 MBTRACKINFO="${MBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
547 if checkstatus replaygain; then :; else
548 run_command "" echo "Adding replaygain information..."
549 for TMPOUTPUT in $( echo "$OUTPUTTYPE" | tr , \ )
553 OUTPUT=$OGGOUTPUTCONTAINER
556 OUTPUT=$OPUSOUTPUTCONTAINER
559 OUTPUT=$FLACOUTPUTCONTAINER
567 for UTRACKNUM in $TRACKQUEUE
569 CDDBTRACKNUM=$(expr "$UTRACKNUM" - 1) # Unpad
570 getcddbinfo TRACKNAME
572 TRACKFILE="$(mungetrackname "$TRACKNAME")"
573 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
574 ALBUMFILE="$(mungealbumname "$DALBUM")"
575 GENRE="$(mungegenre "$GENRE")"
576 YEAR=${CDYEAR:-$CDYEAR}
578 if [ "$ONETRACK" = "y" ]; then
579 if [ "$VARIOUSARTISTS" = "y" ]; then
580 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
582 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
585 if [ "$VARIOUSARTISTS" = "y" ]; then
586 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
588 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
591 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
592 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
596 run_command "replaygain-flac" nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
599 run_command "replaygain-vorbis" nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
602 run_command "replaygain-mp3" nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
605 run_command "replaygain-mpc" nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
608 run_command "replaygain-wv" nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
613 if checkerrors "replaygain-.{3,6}"; then :; else
614 run_command "replaygain" true
619 # This code splits the a Various Artist track name from one of the following
622 # forward: Artist / Track
623 # forward-dash: Artist - Track
624 # reverse: Track / Artist
625 # reverse-dash: Track - Artist
626 # colon: Artist: Track
627 # trailing-paren: Artist (Track)
630 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
633 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
634 case "$VARIOUSARTISTSTYLE" in
636 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
637 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
638 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
641 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
642 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
643 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
646 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
647 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
648 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
651 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
652 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
653 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
656 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
657 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
658 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
661 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
662 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
663 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
666 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
667 TRACKARTIST="Various"
669 TRACKARTIST="$DARTIST"
674 local genre=$(echo "${@}" | tr 'A-Z' 'a-z')
678 "classic rock") id=1 ;;
696 "industrial") id=19 ;;
697 "alternative") id=20 ;;
699 "death metal") id=22 ;;
701 "soundtrack") id=24 ;;
702 "euro-techno") id=25 ;;
706 "jazz+funk") id=29 ;;
709 "classical") id=32 ;;
710 "instrumental") id=33 ;;
714 "sound clip") id=37 ;;
717 "alt. rock") id=40 ;;
722 "meditative") id=45 ;;
723 "instrum. pop") id=46 ;;
724 "instrum. rock") id=47 ;;
728 "techno-indust.") id=51 ;;
729 "electronic") id=52 ;;
731 "eurodance") id=54 ;;
733 "southern rock") id=56 ;;
738 "christian rap") id=61 ;;
739 "pop/funk"|"pop / funk") id=62 ;;
741 "native american") id=64 ;;
744 "psychadelic") id=67 ;;
746 "showtunes") id=69 ;;
750 "acid punk") id=73 ;;
751 "acid jazz") id=74 ;;
755 "rock & roll") id=78 ;;
756 "hard rock") id=79 ;;
758 "folk/rock") id=81 ;;
759 "national folk") id=82 ;;
766 "bluegrass") id=89 ;;
767 "avantgarde") id=90 ;;
768 "gothic rock") id=91 ;;
769 "progress. rock") id=92 ;;
770 "psychadel. rock") id=93 ;;
771 "symphonic rock") id=94 ;;
772 "slow rock") id=95 ;;
775 "easy listening") id=98 ;;
781 "chamber music") id=104 ;;
783 "symphony") id=106 ;;
784 "booty bass") id=107 ;;
786 "porn groove") id=109 ;;
788 "slow jam") id=111 ;;
792 "folklore") id=115 ;;
794 "power ballad") id=117 ;;
795 "rhythmic soul") id=118 ;;
796 "freestyle") id=119 ;;
798 "punk rock") id=121 ;;
799 "drum solo") id=122 ;;
800 "a capella") id=123 ;;
801 "euro-house") id=124 ;;
802 "dance hall") id=125 ;;
804 "drum & bass") id=127 ;;
805 "club-house") id=128 ;;
806 "hardcore") id=129 ;;
810 "negerpunk") id=133 ;;
811 "polsk punk") id=134 ;;
813 "christian gangsta rap") id=136 ;;
814 "heavy metal") id=137 ;;
815 "black metal") id=138 ;;
816 "crossover") id=139 ;;
817 "contemporary christian")id=140 ;;
818 "christian rock") id=141 ;;
819 "merengue") id=142 ;;
821 "thrash metal") id=144 ;;
824 "synthpop") id=147 ;;
825 "rock/pop"|"rock / pop") id=148 ;;
832 # do_tag [tracknumber]
833 # id3 tags a filename
835 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
836 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
839 COMMENTOUTPUT="$(eval echo "${COMMENT}")"
840 if [ -z "$COMMENTOUTPUT" ]; then
841 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
843 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
844 run_command "" echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
845 # If we want to start the tracks with a given number, we need to modify the
846 # TRACKNUM value before evaluation
847 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
850 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
854 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
855 GENREID=$(do_getgenreid "${CDGENRE}")
856 # Set TPE2 in case we have a Various Artists rip.
858 if [ "$VARIOUSARTISTS" = "y" ]; then
864 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
865 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
866 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
867 -y "$CDYEAR" -g "$GENREID" \
868 -T "${TRACKNUM:-$1}" \
869 "${ABCDETEMPDIR}/track$1.$OUTPUT"
872 # FIXME # track numbers in mp3 come with 1/10, so we cannot
873 # happily substitute them with $TRACKNUM
874 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
875 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
876 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
877 -y "$CDYEAR" -g "$GENREID" \
878 -T "${TRACKNUM:-$1}/$TRACKS" \
879 ${TPE2:+--TPE2 "$TPE2"} \
880 "${ABCDETEMPDIR}/track$1.$OUTPUT"
883 # FIXME # track numbers in mp3 come with 1/10, so we cannot
884 # happily substitute them with $TRACKNUM
885 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
886 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
887 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
888 -y "$CDYEAR" -g "$GENREID" \
889 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
890 "${ABCDETEMPDIR}/track$1.$OUTPUT"
893 # FIXME # track numbers in mp3 come with 1/10, so we cannot
894 # happily substitute them with $TRACKNUM
896 eyed3_06) addopts=( \
897 ${ENCODING:+--set-encoding="$ENCODING"} \
898 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
899 # We set 'recording-date' so the date tag will show
900 # in Audacious, vlc and friends... Andrew.
901 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
902 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
905 ${ENCODING:+--encoding="$ENCODING"} \
906 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
907 # We set 'recording-date' so the date tag will show
908 # in Audacious, vlc and friends... Andrew.
909 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
910 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
913 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $TAGGER $TAGGEROPTS \
915 -a "$TRACKARTIST" -t "$TRACKNAME" \
916 -G "$GENREID" -n "${TRACKNUM:-$1}" \
917 ${TRACKNUM:+-N "$TRACKS"} \
919 "${ABCDETEMPDIR}/track$1.$OUTPUT"
922 log error "Internal error: ID3SYNTAX has an illegal value"
928 case "$OGGENCODERSYNTAX" in
930 # vorbiscomment can't do in-place modification, mv the file first
931 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ] && \
932 [ ! -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
933 mv "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" \
934 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
938 # https://www.xiph.org/vorbis/doc/v-comment.html
940 echo ARTIST="$TRACKARTIST"
942 echo TITLE="$TRACKNAME"
943 if [ -n "$CDYEAR" ]; then
946 if [ -n "$CDGENRE" ]; then
947 echo GENRE="$CDGENRE"
949 echo TRACKNUMBER="${TRACKNUM:-$1}"
950 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
951 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
952 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
953 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
954 echo TRACKTOTAL="${TRACKS}"
955 if [ -n "$DISCNUMBER" ]; then
956 echo DISCNUMBER="$DISCNUMBER"
958 echo CDDB="${CDDBDISCID}"
959 if [ "$(eval echo ${COMMENT})" != "" ]; then
960 case "$COMMENTOUTPUT" in
961 *=*) echo "$COMMENTOUTPUT";;
962 *) echo COMMENT="$COMMENTOUTPUT";;
965 ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
966 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
967 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
968 "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
969 # Doublecheck that the commented file was created
970 # successfully before wiping the original
971 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ]; then
972 rm -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
974 mv "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
975 "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
981 run_command "tagtrack-$OUTPUT-$1" true
984 run_command "tagtrack-$OUTPUT-$1" true
987 run_command "tagtrack-$OUTPUT-$1" true
991 echo ARTIST="$TRACKARTIST"
993 echo TITLE="$TRACKNAME"
994 if [ -n "$CDYEAR" ]; then
997 if [ -n "$CDGENRE" ]; then
998 echo GENRE="$CDGENRE"
1000 echo TRACKNUMBER="${TRACKNUM:-$1}"
1001 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
1002 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
1003 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
1004 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
1005 echo TRACKTOTAL="${TRACKS}"
1006 if [ -n "$DISCNUMBER" ]; then
1007 echo DISCNUMBER="$DISCNUMBER"
1009 echo CDDB="${CDDBDISCID}"
1010 if [ -n "$(eval echo "${COMMENT}")" ]; then
1011 case "$COMMENTOUTPUT" in
1012 *=*) echo "$COMMENTOUTPUT";;
1013 *) echo COMMENT="$COMMENTOUTPUT";;
1016 ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $METAFLAC $METAFLACOPTS \
1017 ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} \
1018 --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
1021 run_command "tagtrack-$OUTPUT-$1" true
1024 run_command "tagtrack-$OUTPUT-$1" true
1027 run_command "tagtrack-$OUTPUT-$1" true
1030 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
1031 # Console port (mac) used for encoding does not have the ability to tag.
1032 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$APETAG" -i "${ABCDETEMPDIR}/track$1.ape" -m overwrite \
1033 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track="${TRACKNUM:-$1}" \
1034 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
1037 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
1038 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
1039 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
1040 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
1041 -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
1042 -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
1043 ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1044 "${ABCDETEMPDIR}/track$1.mp2"
1047 run_command "tagtrack-$OUTPUT-$1" true
1050 case "$AACENCODERSYNTAX" in
1052 # We will use inline tagging...
1053 run_command "tagtrack-$OUTPUT-$1" true
1056 # Tag post encode with neroAacTag...
1057 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$NEROAACTAG" \
1058 "${ABCDETEMPDIR}/track$1.m4a" \
1059 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" \
1060 -meta:title="$TRACKNAME" -meta:track="${TRACKNUM:-$1}" \
1061 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1064 run_command "tagtrack-$OUTPUT-$1" true
1067 run_command "tagtrack-$OUTPUT-$1" true
1070 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1071 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1072 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$ATOMICPARSLEY" \
1073 "${ABCDETEMPDIR}/track$1.m4a" --artist="$TRACKARTIST" --album="$DALBUM" \
1074 --title="$TRACKNAME" --tracknum="${TRACKNUM:-$1}" \
1075 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" \
1076 $ATOMICPARSLEYOPTS --overWrite
1079 run_command "tagtrack-$OUTPUT-$1" true
1084 # We use mid3v2 tagging for True Audio:
1085 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
1086 -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
1087 -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
1088 ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} "${ABCDETEMPDIR}/track$1.tta"
1091 run_command "tagtrack-$OUTPUT-$1" true
1095 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1096 run_command "tagtrack-$1" true
1102 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1105 # The commands here don't go through run_command because they're never
1106 # supposed to be silenced
1107 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1108 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1112 case "$MP3ENCODERSYNTAX" in
1115 cd "${ABCDETEMPDIR}"
1117 for THISTRACKNUM in $TRACKQUEUE
1119 TRACKFILES="$TRACKFILES track$THISTRACKNUM.wav"
1121 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1123 if [ "$RETURN" != "0" ]; then
1124 echo "nogap-encode: $MP3ENCODER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1126 for THISTRACKNUM in $TRACKQUEUE
1128 run_command "encodetrack-$OUTPUT-$THISTRACKNUM" true
1137 if checkerrors "nogap-encode"; then :; else
1138 if [ ! "$KEEPWAVS" = "y" ] ; then
1139 if [ ! "$KEEPWAVS" = "move" ] ; then
1144 # Other encoders fall through to normal encoding as the tracks have not
1145 # been entered in the status file.
1148 # do_encode [tracknumber] [hostname]
1149 # If no hostname is specified, encode locally
1151 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1152 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1155 if [ "$USEPIPES" = "y" ]; then
1158 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1161 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1164 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1167 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1170 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1173 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1176 TEMPARG="PIPE_$SPEEXENCODER"
1179 TEMPARG="PIPE_$MPCENCODER"
1182 TEMPARG="PIPE_$WVENCODERSYNTAX"
1185 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1188 TEMPARG="PIPE_$AACENCODERSYNTAX"
1191 TEMPARG="PIPE_$AACENCODERSYNTAX"
1194 IN="$( eval echo "\$$TEMPARG" )"
1196 IN="${ABCDETEMPDIR}/track$1.wav"
1198 # We need IN to proceed, if we are not using pipes.
1199 if [ -s "$IN" ] || [ X"$USEPIPES" = "Xy" ] ; then
1200 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1202 case "$TMPOUTPUT" in
1204 OUTPUT=$OGGOUTPUTCONTAINER
1207 OUTPUT=$OPUSOUTPUTCONTAINER
1210 OUTPUT=$MKAOUTPUTCONTAINER
1213 OUTPUT=$AIFFOUTPUTCONTAINER
1216 OUTPUT=$FLACOUTPUTCONTAINER
1222 OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1223 if [ "$NOGAP" = "y" ] && checkstatus "encodetrack-$OUTPUT-$1" ; then
1226 if [ X"$USEPIPES" = "Xy" ]; then
1228 # We need a way to store the creation of the files when using PIPES
1229 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1230 # When piping it does not make sense to have a higher nice for
1231 # reading than for encoding, since it will be hold by the
1232 # encoding process. Setting an effective nice, to calm down a
1233 # bit the reading process.
1234 EFFECTIVE_NICE=$READNICE
1236 run_command "" echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1237 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1238 EFFECTIVE_NICE=$ENCNICE
1244 case "$MP3ENCODERSYNTAX" in
1245 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1246 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1247 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1248 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1252 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1259 case "$OGGENCODERSYNTAX" in
1260 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1261 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1265 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1272 case "$OPUSENCODERSYNTAX" in
1274 # Tag the file at encode time, as it can't be done after encoding.
1275 if [ "$DOTAG" = "y" ]; then
1276 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS \
1277 --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
1278 --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1279 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1281 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1287 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1292 case "$MKAENCODERSYNTAX" in
1294 if [ "$DOTAG" = "y" ]; then
1295 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS \
1296 -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
1297 -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
1298 -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
1299 -metadata comment="$COMMENT" "$OUT"
1301 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1307 case "$AIFFENCODERSYNTAX" in
1309 if [ "$DOTAG" = "y" ]; then
1310 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS \
1311 -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
1312 -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
1313 -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
1314 -metadata comment="$COMMENT" "$OUT"
1316 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1324 case "$FLACENCODERSYNTAX" in
1325 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1330 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1331 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1336 if [ -n "$(eval echo "${COMMENT}")" ]; then
1339 *) COMMENT="COMMENT=$COMMENT" ;;
1342 # Tag the file at encode time, as it can't be done after encoding.
1343 if [ "$DOTAG" = "y" ]; then
1344 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS \
1345 --author "$TRACKARTIST" --title "$TRACKNAME" \
1346 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1348 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1352 # Tag the file inline at encode time.
1353 if [ "$DOTAG" = "y" ]; then
1354 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS \
1355 --artist "$TRACKARTIST" --album "$DALBUM" \
1356 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
1357 --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1359 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1363 case "$TTAENCODERSYNTAX" in
1364 # tta is the newer version with a small syntax change...
1366 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1369 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1374 case "$WVENCODERSYNTAX" in
1376 if [ "$DOTAG" = "y" ]; then
1377 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS \
1378 -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1379 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" \
1380 -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1382 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1386 if [ "$DOTAG" = "y" ]; then
1387 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS \
1388 -metadata artist="$TRACKARTIST" \
1389 -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
1390 -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
1391 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1393 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1399 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1402 case "$MP2ENCODERSYNTAX" in
1404 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1407 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1412 # aac container is only used to catch faac encoded files where faac
1413 # is compiled without mp4 support (with libmp4v2).
1414 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1417 case "$AACENCODERSYNTAX" in
1419 if [ "$DOTAG" = "y" ]; then
1420 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
1421 --artist "$TRACKARTIST" --album "$DALBUM" \
1422 --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
1423 --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1425 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1429 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1432 if [ "$DOTAG" = "y" ]; then
1433 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
1434 --artist "$TRACKARTIST" --album "$DALBUM" \
1435 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
1436 --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1438 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1442 if [ "$DOTAG" = "y" ]; then
1443 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS \
1444 --artist "$TRACKARTIST" --album "$DALBUM" \
1445 --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
1446 --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1448 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1452 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1455 if [ "$DOTAG" = "y" ]; then
1456 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" \
1457 $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1458 -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
1459 -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
1460 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1462 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1468 # In case of wav output we need nothing. Just keep the wavs.
1469 # But we need the following to allow full logging and subsequent
1470 # successful cleaning of ${ABCDETEMPDIR}.
1471 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1476 # Only remove .wav if the encoding succeeded
1477 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1478 run_command "encodetrack-$1" true
1479 if [ ! "$KEEPWAVS" = "y" ] ; then
1480 if [ ! "$KEEPWAVS" = "move" ] ; then
1486 run_command "" echo "HEH! The file we were about to encode disappeared:"
1487 run_command "" echo ">> $IN"
1488 run_command "encodetrack-$1" false
1492 # do_preprocess [tracknumber]
1494 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX,
1495 # OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1498 # IN="${ABCDETEMPDIR}/track$1.wav"
1499 # # We need IN to proceed.
1500 # if [ -s "$IN" ] ; then
1501 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1503 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1504 # run_command "" echo "Pre-processing track $1 of $TRACKS..."
1505 # case "$POSTPROCESSFORMAT" in
1507 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $WAV_PRE $IF $OF ;;
1509 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $MP3_PRE $IF $OF ;;
1511 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $OGG_PRE $IF $OF ;;
1513 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $FLAC_PRE $IF $OF ;;
1515 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $SPX_PRE $IF $OF ;;
1518 # # Only remove .wav if the encoding succeeded
1519 # if checkerrors "preprocess-(.{3,4})-$1"; then
1520 # run_command "preprocess-$1" false
1522 # run_command "preprocess-$1" true
1525 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1526 # echo "HEH! The file we were about to pre-process disappeared:"
1529 # run_command "preprocess-$1" false
1534 # do_postprocess [tracknumber]
1536 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1537 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1540 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1542 # IN="${ABCDETEMPDIR}/track$1.$POSTPROCESSFORMAT"
1543 # # We need IN to proceed.
1544 # if [ -s "$IN" ] ; then
1545 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1546 # run_command "" echo "Post-processing track $1 of $TRACKS..."
1547 # case "$POSTPROCESSFORMAT" in
1549 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $MP3_POST $IF $OF ;;
1551 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $OGG_POST $IF $OF ;;
1553 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $FLAC_POST $IF $OF ;;
1555 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $SPX_POST $IF $OF ;;
1557 # # Only remove .wav if the encoding succeeded
1558 # if checkerrors "postprocess-(.{3,4})-$1"; then
1559 # run_command "postprocess-$1" false
1561 # run_command "postprocess-$1" true
1564 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1565 # echo "HEH! The file we were about to post-process disappeared:"
1568 # run_command "postprocess-$1" false
1583 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1587 # The commands here don't go through run_command because they're never supposed to be silenced
1588 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1590 cd "${ABCDETEMPDIR}"
1593 for UTRACKNUM in $TRACKQUEUE
1595 TRACKFILES="$TRACKFILES track$UTRACKNUM.mp3"
1597 # FIXME # Hard-coded batch option!
1598 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1600 if [ "$RETURN" != "0" ]; then
1601 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1603 for UTRACKNUM in $TRACKQUEUE
1605 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1611 # do_batch_normalize
1613 # NORMALIZER, NORMALIZEROPTS
1614 do_batch_normalize ()
1616 # The commands here don't go through run_command because they're never supposed to be silenced
1617 echo "Batch normalizing tracks: $TRACKQUEUE"
1619 cd "${ABCDETEMPDIR}"
1622 for UTRACKNUM in $TRACKQUEUE
1624 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1626 # XXX: Hard-coded batch option!
1627 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1629 if [ "$RETURN" != "0" ]; then
1630 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1632 for UTRACKNUM in $TRACKQUEUE
1634 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1640 # do_normalize [tracknumber]
1642 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1645 IN="${ABCDETEMPDIR}/track$1.wav"
1646 if [ -e "$IN" ] ; then
1647 run_command "" echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1648 run_command "normalizetrack-$1" $NORMALIZER $NORMALIZEROPTS "$IN"
1650 if [ "$(checkstatus encode-output)" = "loud" ]; then
1651 echo "HEH! The file we were about to normalize disappeared:"
1654 run_command "normalizetrack-$1" false "File $IN was not found"
1658 # do_move [tracknumber]
1659 # Deduces the outfile from environment variables
1660 # Creates directory if necessary
1662 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1665 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1667 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1668 # defined the OUTPUTFILE:
1671 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1672 ALBUMFILE="$(mungealbumname "$DALBUM")"
1673 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1674 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1675 GENRE="$(mungegenre "$GENRE")"
1676 YEAR=${CDYEAR:-$CDYEAR}
1677 # If we want to start the tracks with a given number, we need to modify
1678 # the TRACKNUM value before evaluation
1680 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1681 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1682 if [ "$ONETRACK" = "y" ]; then
1683 if [ "$VARIOUSARTISTS" = "y" ]; then
1684 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1686 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1689 if [ "$VARIOUSARTISTS" = "y" ]; then
1690 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1692 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1695 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1696 # Once we know the specific output was successful, we can change
1697 # the OUTPUT to the value containing the container
1700 OUTPUT=$OGGOUTPUTCONTAINER
1703 OUTPUT=$OPUSOUTPUTCONTAINER
1706 OUTPUT=$MKAOUTPUTCONTAINER
1709 OUTPUT=$AIFFOUTPUTCONTAINER
1712 OUTPUT=$FLACOUTPUTCONTAINER
1718 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1719 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1722 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1723 # FIXME # introduce warnings?
1726 # mkdir -p shouldn't return an error if the directory already exists
1727 mkdir -p "$OUTPUTFILEDIR"
1728 run_command "movetrack-$1" mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1729 if checkstatus "movetrack-output-$OUTPUT"; then :; else
1730 run_command "movetrack-output-$OUTPUT" true
1735 # mkdir -p shouldn't return an error if the directory already exists
1736 mkdir -p "$OUTPUTFILEDIR"
1737 run_command "movetrack-$1" mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1738 if checkstatus "movetrack-output-$OUTPUT"; then :; else
1739 run_command "movetrack-output-$OUTPUT" true
1743 # Lets move the cue file
1744 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1745 if [ -r "${ABCDETEMPDIR}/$CUEFILE" ]; then
1746 if checkstatus "movecue-$OUTPUT"; then :; else
1747 # Silence the Copying output since it overlaps with encoding processes...
1748 #run_command "" vecho "Copying cue file to its destination directory..."
1749 if checkstatus onetrack >/dev/null ; then
1752 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1753 # We dont have the dir, since it was not created before.
1756 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1759 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1760 # http://brianvictor.tripod.com/mp3cue.htm#details
1761 [a-z0-9][a-z0-9][a-z0-9])
1762 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1765 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1769 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1771 echo "movecue-$OUTPUT" >> "${ABCDETEMPDIR}/status"
1780 # Create the playlist if wanted
1782 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1783 # VARIOUSARTISTS, OUTPUTDIR
1786 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1790 OUTPUT=$OGGOUTPUTCONTAINER
1793 OUTPUT=$OPUSOUTPUTCONTAINER
1796 OUTPUT=$MKAOUTPUTCONTAINER
1799 OUTPUT=$AIFFOUTPUTCONTAINER
1802 OUTPUT=$FLACOUTPUTCONTAINER
1808 # Create a playlist file for the playlist data to go into.
1809 # We used to wipe it out if it existed. Now we request permission if interactive.
1810 for LASTTRACK in $TRACKQUEUE; do :; done
1811 ALBUMFILE="$(mungealbumname "$DALBUM")"
1812 ARTISTFILE="$(mungeartistname "$DARTIST")"
1813 GENRE="$(mungegenre "$GENRE")"
1814 YEAR=${CDYEAR:-$CDYEAR}
1815 if [ "$VARIOUSARTISTS" = "y" ] ; then
1816 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1818 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1820 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1821 mkdir -p "$FINALPLAYLISTDIR"
1822 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1823 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1824 if [ "$INTERACTIVE" = "y" ]; then
1825 while [ "$DONE" != "y" ]; do
1827 case $ERASEPLAYLIST in
1828 e|E|a|A|k|K) DONE=y ;;
1829 "") ERASEPLAYLIST=e ; DONE=y ;;
1837 # Once we erase the playlist, we use append to create the new one.
1838 [ "$ERASEPLAYLIST" = "e" ] || [ "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1840 # The playlist does not exist, so we can safelly use append to create the new list
1843 if [ "$ERASEPLAYLIST" = "a" ] || [ "$ERASEPLAYLIST" = "A" ]; then
1844 touch "$OUTPUTDIR/$PLAYLISTFILE"
1845 for UTRACKNUM in $TRACKQUEUE
1847 # Shares some code with do_move since the filenames have to match
1848 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
1849 getcddbinfo TRACKNAME
1851 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1852 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1853 ALBUMFILE="$(mungealbumname "$DALBUM")"
1854 # If we want to start the tracks with a given number, we need to modify the
1855 # TRACKNUM value before evaluation
1857 if [ "$VARIOUSARTISTS" = "y" ]; then
1858 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1860 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1862 if [ "$VARIOUSARTISTS" = "y" ]; then
1863 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1864 echo "${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1866 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1869 if [ "$PLAYLISTDATAPREFIX" ]; then
1870 echo "${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1872 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1877 ## this will convert the playlist to have CRLF line-endings, if specified
1878 ## (some hardware players insist on CRLF endings)
1879 if [ "$DOSPLAYLIST" = "y" ]; then
1880 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "${ABCDETEMPDIR}/PLAYLISTFILE.tmp"
1881 # mv -f "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1882 cat "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1884 echo "playlistcomplete" >> "${ABCDETEMPDIR}/status"
1889 # This function reads a cuefile on stdin and writes an extended
1890 # cddb query on stdout. Any PREGAP for track 1 is properly
1891 # handled, although cue files embedded in FLAC files do not
1892 # appear to properly store the PREGAP setting. :(
1893 abcde.cue2discid () {
1898 while [ "$val" -gt 0 ] ; do
1899 ret=$(( "$ret" + ( "$val" % 10) ))
1900 val=$(( "$val" / 10 ))
1910 local first second third
1912 second=$(( $2 + 0 ))
1915 echo $(( ((("$first" * 60) + "$second") * 75) + "$third" ))
1925 while read line ; do
1928 TRACK) i=$(( i + 1 ))
1930 INDEX) if [ "$2" -eq 1 ] ; then
1932 START=$(( "$LBA" + "$PREGAP" + "$OFFSET" ))
1934 X=$(cddb_sum $(( "$START" / 75 )) )
1935 N=$(( "$N" + "$X" ))
1938 PREGAP) PREGAP=$(msf2lba "$2")
1942 LEADOUT=$(( "$4" / 588 ))
1945 LEADIN=$(( "$3" / 588 ))
1954 LEADOUT=$(( "$LEADOUT" + "$LEADIN" ))
1956 LENGTH=$(( "$LEADOUT"/75 - "$TRACK1"/75 ))
1957 CDDBDISCID=$(( ( "$N" % 255 ) * 2**24 | "$LENGTH" * 2**8 | "$TRACKS" ))
1958 printf "%08x %i" "${CDDBDISCID}" "$TRACKS"
1961 while [ $j -le "$TRACKS" ] ; do
1962 eval echo -n "\" \$TRACK$j\""
1965 echo " $(( $LEADOUT / 75 ))"
1969 # abcde.mkcue [--wholedisk]
1970 # This creates a cuefile directly from the extended discid information
1971 # The --wholedisk option controls whether we're ripping data from the
1972 # start of track one or from the start of the disk (usually, but not
1973 # always the same thing!)
1975 # Track one leadin/pregap (if any) handeling:
1976 # --wholedisk specified:
1979 # INDEX 01 <pregap value>
1980 # Remaining track index values unchanged from disc TOC
1982 # --wholedisk not specified
1984 # PREGAP <pregap value>
1986 # Remaining track index values offset by <pregap value>
1993 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1996 local MODE DISCID TRACKS
2000 if [ "$1" = --wholedisk ] ; then
2006 vecho "One track is $ONETRACK"
2007 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2008 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2009 ALBUMFILE="$(mungealbumname "$DALBUM")"
2010 if [ "$ONETRACK" = "y" ]; then
2011 if [ "$VARIOUSARTISTS" = "y" ]; then
2012 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2014 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2016 vecho "Cue wav file is $CUEWAVFILE"
2018 CUEWAVFILE="dummy.wav"
2021 set -- "$CDDBTRACKINFO"
2027 echo "REM DISCID $DISCID"
2028 echo FILE \""$CUEWAVFILE"\" WAVE
2030 if [ "$1" -ne 150 ] && [ "$MODE" = "PREGAP" ] ; then
2037 while [ $i -le "$TRACKS" ] ; do
2038 LBA=$(( $1 - $OFFSET ))
2039 printf " TRACK %02i AUDIO\n" $i
2040 if [ "$i" -eq 1 ] && [ "$1" -ne 150 ] ; then
2041 if [ "$MODE" = PREGAP ] ; then
2042 echomsf " PREGAP " $(($"OFFSET" - 150))
2044 echo " INDEX 00 00:00:00"
2047 echomsf " INDEX 01 " "$LBA"
2054 # This is essentially the start of things
2057 if [ -z "${CDDBDISCID}" ]; then
2058 vecho -n "Getting CD track info... "
2059 # In OSX, unmount the disc before a query
2060 if [ "$OSFLAVOUR" = "OSX" ]; then
2061 diskutil unmount "${CDROM#/dev/}"
2063 case "$CDROMREADERSYNTAX" in
2065 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
2066 case "$CUE2DISCID" in
2067 # FIXME # right now we have 2 cue2discid internal
2068 # implementations: builtin and abcde.cue2discid. Test
2069 # both of them and decide which one we want to use.
2071 #vecho "Using builtin cue2discid implementation..."
2072 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2074 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2076 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2077 TRACKS=${#OFFSETTIMES[@]}
2079 #echo "processing offsetimes ${OFFSETTIMES[@]}"
2080 for OFFSETTIME in ${OFFSETTIMES[@]}; do
2081 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2082 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
2085 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2086 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2090 #vecho "Using external python cue2discid implementation..."
2091 CDDBTRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2095 log error "the input flac file does not contain a cuesheet."
2100 CDPARANOIAOUTPUT="$( $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -Q --verbose 2>&1 )"
2102 if [ ! "$RET" = "0" ];then
2103 log warning "something went wrong while querying the CD... Maybe a DATA CD or the CD is not loaded?"
2106 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2107 CDPARANOIAAUDIOTRACKS="$TRACKS"
2109 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2110 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2114 # Calculate the cddb discid in all
2115 # cases now. We'll use the cddb discid
2116 # for reference in most cases for
2117 # consistency. Also calculate the
2118 # musicbrainz discid if we need it.
2119 CDDBTRACKINFO=$($CDDISCID "$CDROM")
2120 if [ "$CDDISCID_NEEDS_PAUSE"x = "y"x ]; then
2123 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2124 case "$CDDBMETHOD" in
2126 MBTRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM")
2128 if [ $error != 0 ]; then
2129 log error "$MUSICBRAINZ failed to run; ABORT"
2132 MBDISCID=$(echo "$MBTRACKINFO" | cut -d' ' -f1)
2136 # Make sure there's a CD in there by checking cd-discid's return code
2137 if [ ! "$?" = "0" ]; then
2138 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2139 log error "cuesheet information from the flac file could not be read."
2140 log error "Perhaps the flac file does not contain a cuesheet?."
2143 log error "CD could not be read. Perhaps there's no CD in the drive?"
2147 # In OSX, remount the disc again
2148 if [ "$OSFLAVOUR" = "OSX" ]; then
2149 diskutil mount "${CDROM#/dev/}"
2152 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -f1 -d' ')
2154 CDDBTRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.${CDDBDISCID}/cddbdiscid")
2157 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2158 # This needs to be done now because a section of the resuming code will need
2161 # get the number of digits to pad TRACKNUM with - we'll use this later
2162 # a CD can only hold 99 tracks, but since we support a feature for starting
2163 # numbering the tracks from a given number, we might need to set it as a
2164 # variable for the user to define... or obtain it somehow.
2165 if [ "$PADTRACKS" = "y" ] ; then
2169 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo "$CDDBTRACKINFO" | cut -f1 -d' ')"
2170 if [ -z "$TRACKQUEUE" ]; then
2171 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2172 case "$CDROMREADERSYNTAX" in
2173 cdparanoia|libcdio|debug)
2174 if [ "$WEHAVEACD" = "y" ]; then
2175 vecho "Querying the CD for audio tracks..."
2176 CDPARANOIAOUTPUT="$( $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -Q --verbose 2>&1 )"
2178 if [ ! "$RET" = "0" ];then
2179 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2181 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2182 CDPARANOIAAUDIOTRACKS="$TRACKS"
2184 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2185 if [ -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks" ]; then
2186 echo "cdparanoia-audio-tracks=$( cat "${ABCDETEMPDIR}/cdparanoia-audio-tracks" )" >> "${ABCDETEMPDIR}/status"
2187 rm -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks"
2189 if [ -f "${ABCDETEMPDIR}/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2190 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2194 *) TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ') ;;
2197 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2199 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2200 log info "The disc does not contain any tracks. Giving up..."
2203 echo -n "Grabbing entire CD - tracks: "
2204 if [ ! "$PADTRACKS" = "y" ] ; then
2205 TRACKNUMPADDING=$(echo -n "$TRACKS" | wc -c | tr -d ' ')
2208 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2210 while [ "$X" -ne "$TRACKS" ]
2212 PT=$(printf "%0.${TRACKNUMPADDING}d" $(($X + 1)))
2213 TRACKQUEUE="$TRACKQUEUE $PT"
2218 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2219 # User-supplied track queue.
2220 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2221 TRACKQUEUE=$(echo "$TRACKQUEUE" | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2222 # Once cleaned, obtain the highest value in the trackqueue for number padding
2223 for LASTTRACK in $TRACKQUEUE; do :; done
2224 if [ ! "$PADTRACKS" = "y" ] ; then
2225 TRACKNUMPADDING=$(echo -n "$LASTTRACK" | wc -c | tr -d ' ')
2227 # Now we normalize the trackqueue
2228 for TRACK in $TRACKQUEUE ; do
2229 TRACKNUM=$(printf "%0.${TRACKNUMPADDING}d" $(($TRACK + 0)))
2230 PADTRACKQUEUE="$PADTRACKQUEUE $TRACKNUM"
2232 TRACKQUEUE="$PADTRACKQUEUE"
2233 echo Grabbing tracks: "$TRACKQUEUE"
2236 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2238 # We have the discid, create a temp directory after it to store all the temp
2241 if [ -e "${ABCDETEMPDIR}" ]; then
2242 echo -n "abcde: attempting to resume from ${ABCDETEMPDIR}"
2243 # It already exists, see if it's a directory
2244 if [ ! -d "${ABCDETEMPDIR}" ]; then
2245 # This is a file/socket/fifo/device/etc, not a directory
2248 echo "abcde: file ${ABCDETEMPDIR} already exists and does not belong to abcde." >&2
2249 echo "Please investigate, remove it, and rerun abcde." >&2
2253 # It's a directory, let's see if it's writable by us
2254 if [ ! -r "${ABCDETEMPDIR}" ] || [ ! -w "${ABCDETEMPDIR}" ] || [ ! -x "${ABCDETEMPDIR}" ]; then
2255 # Nope, complain and exit
2257 echo "abcde: directory ${ABCDETEMPDIR} already exists and is not writeable." >&2
2258 echo "Please investigate, remove it, and rerun abcde." >&2
2262 # Check to see the version of abcde that was used. If it's not
2263 # the same version as we are, bail.
2264 RESUME_VERSION="$(checkstatus abcde-version)"
2265 if [ "$RESUME_VERSION" != "$VERSION" ]; then
2266 # Nope, complain and exit
2268 echo "abcde: Working directory ${ABCDETEMPDIR} was created using version $RESUME_VERSION." >&2
2269 echo "abcde: Current version is $VERSION." >&2
2270 echo "abcde: Refusing to resume with a version mismatch." >&2
2271 echo "Please remove it, and rerun abcde." >&2
2275 # See if it's populated
2276 if [ ! -f "${ABCDETEMPDIR}/cddbdiscid" ]; then
2277 # Wipe and start fresh
2278 echo "abcde: ${ABCDETEMPDIR}/cddbdiscid not found. Abcde must remove and recreate" >&2
2279 echo -n "this directory to continue. Continue [y/N]? " >&2
2280 if [ "$INTERACTIVE" = "y" ]; then
2286 if [ "$ANSWER" != "y" ]; then
2289 rm -rf "${ABCDETEMPDIR}" || exit 1
2290 mkdir -p "${ABCDETEMPDIR}"
2291 if [ "$?" -gt "0" ]; then
2292 # Directory already exists or could not be created
2293 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2297 # Everything is fine. Check for ^encodetracklocation-
2298 # and encode-output entries in the status file and
2299 # remove them. These are not relevant across sessions.
2300 echo "Resuming" >> "${ABCDETEMPDIR}/status"
2301 if [ -f "${ABCDETEMPDIR}/status" ]; then
2302 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
2303 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
2304 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
2306 # Remove old error messages
2307 if [ -f "${ABCDETEMPDIR}/errors" ]; then
2308 rm -f "${ABCDETEMPDIR}/errors"
2312 # We are starting from scratch
2313 mkdir -p "${ABCDETEMPDIR}"
2314 if [ "$?" -gt "0" ]; then
2315 # Directory already exists or could not be created
2316 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2319 cat /dev/null > "${ABCDETEMPDIR}/status"
2320 # Store the abcde version in the status file.
2321 echo "abcde-version=$VERSION" >> "${ABCDETEMPDIR}/status"
2323 if [ X"$DOCUE" = "Xy" ] && [ X"$WEHAVEACD" = "Xy" ]; then
2324 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2325 CUEFILE=cue-$(echo "$CDDBTRACKINFO" | cut -f1 -d' ').txt
2326 vecho "Creating cue file..."
2327 case "$CDROMREADERSYNTAX" in
2329 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "${ABCDETEMPDIR}/$CUEFILE"; then
2330 echo "cuefile=$CUEFILE" >> "${ABCDETEMPDIR}/status"
2332 log warning "the input flac file does not contain a cuesheet."
2336 if $CUEREADER $CUEREADEROPTS > "${ABCDETEMPDIR}/$CUEFILE"; then
2337 echo "cuefile=$CUEFILE" >> "${ABCDETEMPDIR}/status"
2339 log warning "reading the CUE sheet is still considered experimental"
2340 log warning "and there was a problem with the CD reading. abcde will continue,"
2341 log warning "but consider reporting the problem to the abcde author"
2347 # If we got the CDPARANOIA status and it is not recorded, save it now
2348 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2349 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2350 echo "cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS" >> "${ABCDETEMPDIR}/status"
2354 # Create the discid files
2355 echo "$CDDBTRACKINFO" > "${ABCDETEMPDIR}/cddbdiscid"
2356 case "$CDDBMETHOD" in
2358 echo "$MBTRACKINFO" > "${ABCDETEMPDIR}/mbdiscid"
2364 # Create a proper CUE file based on the CUE file we created before.
2367 if CUEFILE_IN="${ABCDETEMPDIR}"/$(checkstatus cuefile); then
2368 CUEFILE_OUT=$CUEFILE_IN.out
2369 ### FIXME ### checkstatus cddb
2370 if [ -e "$CDDBDATA" ]; then
2371 vecho "Adding metadata to the cue file..."
2372 # FIXME It doesn't preserve spaces! Why?
2373 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2375 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2376 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2377 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2381 cat "$CUEFILE_IN" | while read line
2383 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2384 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2385 # echo "$line" >> "$CUEFILE_OUT"
2386 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2387 eval track="\$TRACK$n"
2389 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2390 # When making a single-track rip, put the
2391 # actual file name into the file declaration
2392 # in the cue file so that it is usable by
2393 # music players and the like
2394 elif [ "$ONETRACK" = "y" ] &&
2395 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2397 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2398 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2399 ALBUMFILE="$(mungealbumname "$DALBUM")"
2401 if [ "$VARIOUSARTISTS" = "y" ]; then
2402 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2404 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2407 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2410 # FIXME # If the lines above are uncommented, remove the line below.
2411 echo "$line" >> "$CUEFILE_OUT"
2414 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2415 echo "cleancuefile" >> "${ABCDETEMPDIR}/status"
2421 # Parses a CDDB file and outputs the title and the track names.
2422 # Variables: CDDBFILE
2426 # List out disc title/author and contents
2427 if [ "$ONETRACK" = "y" ]; then
2428 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2430 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2431 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2432 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2433 if [ ! X"$PARSEDYEAR" = "X" ]; then
2434 echo "Year: $PARSEDYEAR"
2437 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2438 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2439 if [ ! X"$PARSEDGENRE" = "X" ]; then
2440 echo "Genre: $PARSEDGENRE"
2443 if [ ! "$ONETRACK" = "y" ]; then
2444 for TRACK in $(f_seq_row 1 $TRACKS)
2446 echo "$TRACK": "$(grep -a ^TTITLE$(($TRACK - 1))= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2452 # Check for a local CDDB file, and report success
2453 do_localcddb_read ()
2455 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2457 CDDBLOCALSTATUS="notfound"
2458 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2461 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2462 CDDBLOCALRESULTS="$(find "${CDDBLOCALDIR}" -name "${CDDBDISCID}" -type f 2> /dev/null)"
2463 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2464 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2465 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2466 CDDBLOCALMATCH=single
2467 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2468 CDDBLOCALMATCH=multiple
2473 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2474 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2475 CDDBLOCALMATCH=single
2480 # If the user has selected to check a local CDDB repo, we proceed with it
2481 case $CDDBLOCALMATCH in
2483 echo "Processing multiple matching CDDB entries..." > "${ABCDETEMPDIR}/cddblocalchoices"
2485 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2487 # List out disc title/author and contents
2488 CDDBLOCALREAD="${ABCDETEMPDIR}/cddblocalread.$X"
2489 cat "$RESULT" > "${CDDBLOCALREAD}"
2492 do_cddbparse "${CDDBLOCALREAD}"
2494 ##FIXME## QUICK HACK !!!!
2495 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2496 } >> "${ABCDETEMPDIR}/cddblocalchoices"
2498 page "${ABCDETEMPDIR}/cddblocalchoices"
2499 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2500 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2501 CDDBLOCALCHOICENUM=-1
2502 if [ "$INTERACTIVE" = "y" ]; then
2503 while [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; do
2504 echo "Locally cached CDDB entries found." >&2
2505 echo -n "Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2506 read CDDBLOCALCHOICE
2507 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2508 # FIXME # Introduce diff's
2509 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2510 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2511 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2512 # Make sure we get a valid choice
2513 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2514 if [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; then
2515 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2520 CDDBLOCALCHOICENUM=1
2522 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2523 #echo "Using local copy of CDDB data"
2524 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2525 cat "${ABCDETEMPDIR}/cddblocalread.$CDDBLOCALCHOICENUM" >> "${ABCDETEMPDIR}/cddbread.1"
2526 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2527 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2528 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2529 do_cddbparse "${ABCDETEMPDIR}/cddbread.1" > "${ABCDETEMPDIR}/cddbchoices"
2530 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2531 CDDBLOCALSTATUS="found"
2533 #echo "Not using local copy of CDDB data"
2534 CDDBLOCALSTATUS="notfound"
2538 # List out disc title/author and contents
2539 do_cddbparse "${CDDBLOCALFILE}"
2540 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2541 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2543 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2545 if [ "$INTERACTIVE" = "y" ]; then
2547 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2548 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2551 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2555 if [ "$USELOCALRESP" = "y" ]; then
2556 #echo "Using local copy of CDDB data"
2557 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2558 cat "${CDDBLOCALFILE}" >> "${ABCDETEMPDIR}/cddbread.1"
2559 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2560 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2561 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2562 do_cddbparse "${CDDBLOCALFILE}" > "${ABCDETEMPDIR}/cddbchoices"
2563 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2564 CDDBLOCALSTATUS="single"
2566 #echo "Not using local copy of CDDB data"
2567 CDDBLOCALSTATUS="notfound"
2571 CDDBLOCALSTATUS="notfound"
2578 # Try to read CD-Text from the drive using icedax / cdda2wav
2581 if new_checkexec icedax; then
2582 CDTEXT_READER=icedax
2583 elif new_checkexec cdda2wav; then
2584 CDTEXT_READER=cdda2wav
2586 # Didn't find either, bail
2590 if checkstatus cdtext-readcomplete; then
2591 NUM_RESPONSES=$(checkstatus "cdtext-entries")
2592 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2593 vecho "Re-using existing data from CD-Text"
2595 vecho "Obtaining CD-Text results..."
2596 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cdtext"
2597 mkdir -p "${SOURCE_WORKDIR}"
2599 if [ "$OSFLAVOUR" = "OSX" ] ; then
2600 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2601 diskutil unmount "${CDROM#/dev/}"
2602 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2603 CDDA2WAVCDROM="IODVDServices"
2604 elif [ "$OSFLAVOUR" = "FBSD" ] || [ "$OSFLAVOUR" = "IRIX" ]; then
2605 CDDA2WAVCDROM="$CDROMID"
2607 if [ "$CDROMID" = "" ]; then
2608 CDDA2WAVCDROM="$CDROM"
2610 CDDA2WAVCDROM="$CDROMID"
2614 # Do we have CD-Text on the disc (and can the drive read it?)
2616 cd "${SOURCE_WORKDIR}" && rm -f audio.* audio_*
2617 ${CDTEXT_READER} -J -v titles -D "${CDDA2WAVCDROM}" > "${SOURCE_WORKDIR}/cd-text" 2>&1
2619 grep -a -q '^CD-Text: detected' "${SOURCE_WORKDIR}/cd-text"
2621 if [ $ERRORCODE -ne 0 ]; then
2622 # No CD-Text found, bail
2626 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2627 # Make an empty template
2628 $CDDBTOOL template "$(cat "${ABCDETEMPDIR}/cddbdiscid")" > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2629 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2630 rm -f "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2632 # XXX FIXME - this is a hack and should be replaced by proper
2633 # character set tracking for the CDDB data we have.
2634 if [ "$CDDBPROTO" -ge 6 ]; then
2635 # convert to Unicode
2636 iconv -f iso-8859-1 -t utf-8 <"${SOURCE_WORKDIR}/audio.cddb" >"${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2638 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2639 # apparently icedax/cdda2wav have no support for 16-bit
2640 # characters yet, either
2641 cp -p "${SOURCE_WORKDIR}/audio.cddb" "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2644 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2645 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2646 echo "CD-Text" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2647 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2649 ( cd "${SOURCE_WORKDIR}" && rm -f audio_* audio.* )
2650 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2651 if [ -f "$file" ]; then
2652 cp "$file" "${ABCDETEMPDIR}"
2655 echo "cdtext-readcomplete" >> "${ABCDETEMPDIR}/status"
2656 echo "cdtext-entries=1" >> "${ABCDETEMPDIR}/status"
2660 # do_musicbrainz_read
2661 # Work with the musicbrainz WS API, then transform the results here so
2662 # they look (very) like the results from CDDB. Maybe not the best way
2663 # to go, but it Works For Me (TM)
2665 # List out all the matches individually into $SOURCE_WORKDIR/cddbread.X
2667 do_musicbrainz_read ()
2669 if checkstatus musicbrainz-readcomplete; then
2670 NUM_RESPONSES=$(checkstatus "musicbrainz-entries")
2671 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2672 vecho "Re-using existing data from $NUM_RESPONSES Musicbrainz match(es)"
2674 vecho "Obtaining Musicbrainz results..."
2675 # If MB is to be used, interpret the query results and read all
2676 # the available entries.
2677 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2678 MBDISCID=$(echo "$MBTRACKINFO" | cut -d' ' -f1)
2679 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-musicbrainz"
2680 mkdir -p "${SOURCE_WORKDIR}"
2681 ${MUSICBRAINZ} --command data --discid "${MBDISCID}" --workdir "${SOURCE_WORKDIR}" --start ${NUM_CDDB_MATCHES}
2683 if [ $error != 0 ]; then
2684 log error "$MUSICBRAINZ failed to run; ABORT"
2688 # Check for no matches.
2689 # The helper script will write disc matches out to
2690 # cddbread.*. Count how many we have
2691 NUM_RESPONSES=$(echo "${SOURCE_WORKDIR}"/cddbread.* | wc -w)
2692 if [ "$NUM_RESPONSES" -gt 0 ] ; then
2693 # One or more exact matches
2695 while [ $i -le "$NUM_RESPONSES" ]; do
2696 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2698 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2699 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2700 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2701 echo "Musicbrainz" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2702 cp -f "${SOURCE_WORKDIR}/"*."${NUM_CDDB_MATCHES}" "${ABCDETEMPDIR}"
2705 echo "musicbrainz-readcomplete" >> "${ABCDETEMPDIR}/status"
2706 echo "musicbrainz-entries=$NUM_RESPONSES" >> "${ABCDETEMPDIR}/status"
2713 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cddb"
2714 mkdir -p "${SOURCE_WORKDIR}"
2720 # Perform CDDB protocol version check if it hasn't already been done
2721 if checkstatus cddb-statcomplete; then :; else
2722 if [ "$CDDBAVAIL" = "n" ]; then
2724 echo 503 > "${SOURCE_WORKDIR}/cddbstat"
2727 CDDBUSER=$(echo "$HELLOINFO" | cut -f1 -d'@')
2728 CDDBHOST=$(echo "$HELLOINFO" | cut -f2- -d'@')
2729 while [ $rc -eq 1 ] && [ "$CDDBPROTO" -ge 3 ]; do
2730 vecho "Checking CDDB server status..."
2731 $CDDBTOOL stat "$CDDBURL" "$CDDBUSER" "$CDDBHOST" "$CDDBPROTO" > "${SOURCE_WORKDIR}/cddbstat"
2732 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2733 case "$RESPONSECODE" in
2734 210) # 210 OK, status information follows (until terminating `.')
2737 501) # 501 Illegal CDDB protocol level: <n>.
2738 CDDBPROTO=$(($CDDBPROTO - 1))
2740 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2741 # FreeDB TESTCD disc-id is used for query
2742 $CDDBTOOL query "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" 03015501 1 296 344 > "${SOURCE_WORKDIR}/cddbstat"
2743 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2744 case "$RESPONSECODE" in
2745 2??) # Server responded, everything seems OK
2755 if [ $rc -eq 1 ]; then
2759 echo cddb-statcomplete >> "${ABCDETEMPDIR}/status"
2766 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2767 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2769 # Perform CDDB query if it hasn't already been done
2770 if checkstatus cddb-querycomplete; then :; else
2771 if [ "$CDDBAVAIL" = "n" ]; then
2773 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2774 # The default CDDBLOCALSTATUS is "notfound"
2775 # This part will be triggered if the user CDDB repo does not
2776 # contain the entry, or if we are not trying to use the repo.
2778 vecho "Querying the CDDB server..."
2779 CDDBUSER=$(echo "$HELLOINFO" | cut -f1 -d'@')
2780 CDDBHOST=$(echo "$HELLOINFO" | cut -f2- -d'@')
2781 $CDDBTOOL query "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" "$CDDBTRACKINFO" > "${SOURCE_WORKDIR}/cddbquery"
2787 # no match found in database, wget/fetch error,
2788 # or user requested not to use CDDB. Make up an
2789 # error code (503) that abcde will recognize later
2790 # and compensate by making a template
2791 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2793 *) # strange and unknown error
2794 echo "ERRORCODE=$ERRORCODE"
2795 echo "abcde: $CDDBTOOL returned unknown error code"
2799 echo cddb-querycomplete >> "${ABCDETEMPDIR}/status"
2806 # If it's not to be used, generate a template.
2807 # Then, display it (or them) and let the user choose/edit it
2808 if checkstatus cddb-readcomplete; then
2809 NUM_RESPONSES=$(checkstatus "cddb-entries")
2810 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2811 vecho "Re-using existing data from $NUM_RESPONSES cddb match(es)"
2813 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbquery" | cut -f1 -d' ')
2814 vecho "Obtaining CDDB results..."
2815 case "$RESPONSECODE" in
2817 # One exact match, retrieve it
2818 # 200 [section] [discid] [artist] / [title]
2820 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2821 $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
2822 $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") \
2823 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2824 cat "${SOURCE_WORKDIR}/cddbquery" | cut -f2- -d' ' > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2825 echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2826 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2828 202|403|409|500|503)
2829 # TODO: Explain these error codes a little more accurately:
2830 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2831 # No match response:
2834 # Multiple exact, (possibly multiple) inexact matches
2835 vecho -n "Retrieving multiple matches... "
2836 grep -v '^[.]$' "${SOURCE_WORKDIR}/cddbquery" | (
2837 # IN A SUB-SHELL - VARIABLES MODIFIED
2838 # HERE DO NOT PERSIST IN THE PARENT
2839 read DISCINFO # eat top line
2842 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2843 if checkstatus "cddb-read-${NUM_CDDB_MATCHES}-complete"; then :; else
2844 $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
2845 $(echo "$DISCINFO" | cut -f1,2 -d' ') \
2846 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2847 echo "$DISCINFO" > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2848 echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2849 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2852 # Need to re-count the entries here to be able
2853 # to incrememnt $NUM_CDDB_MATCHES in the
2855 NUM_RESPONSES=$(echo "${SOURCE_WORKDIR}/datasource.*" | wc -w)
2856 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2862 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2863 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2866 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2867 if [ -f "$file" ]; then
2868 cp "$file" "${ABCDETEMPDIR}"
2871 echo "cddb-readcomplete" >> "${ABCDETEMPDIR}/status"
2872 echo "cddb-entries=$NUM_RESPONSES" >> "${ABCDETEMPDIR}/status"
2879 if checkstatus cddb-edit >/dev/null; then
2880 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2881 VARIOUSARTISTS="$(checkstatus variousartists)"
2882 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2885 if [ "$INTERACTIVE" = "y" ]; then
2886 # We should show the CDDB results both when we are not using the local CDDB repo
2887 # or when we are using it but we could not find a proper match
2888 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2889 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2890 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2891 CHOICE=$(checkstatus cddb-choice)
2892 if [ -n "$CHOICE" ] ; then
2893 case $NUM_CDDB_MATCHES in
2894 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2896 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CHOICE" | cut -f2- -d= | tr -d \\r\\n)
2897 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CHOICE")
2898 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)"
2899 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2903 page "${ABCDETEMPDIR}/cddbchoices"
2905 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2907 # I'll take CDDB read #3 for $400, Alex
2908 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; do
2909 echo -n "Which entry would you like abcde to use (0 for none)? [0-$NUM_CDDB_MATCHES]: " >&2
2911 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2912 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2913 if [ ! X"$DIFF" = "X" ]; then
2914 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2915 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2916 if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$NUM_CDDB_MATCHES" ] || \
2917 [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$NUM_CDDB_MATCHES" ] || \
2918 [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
2919 echo "Invalid diff range." >&2
2920 echo "Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
2922 # We parse the 2 choices to diff, store them in temporary files and diff them.
2923 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2924 do_cddbparse "${ABCDETEMPDIR}/cddbread.$PARSECHOICE" \
2925 > "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE"
2927 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." \
2928 > "${ABCDETEMPDIR}/cddbread.diff"
2929 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE1" \
2930 "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE2" \
2931 >> "${ABCDETEMPDIR}/cddbread.diff"
2932 page "${ABCDETEMPDIR}/cddbread.diff"
2935 echo "The diff program was not found in your path." >&2
2936 echo "Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2938 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2939 # Make sure we get a valid choice
2940 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2941 if [ "$CDCHOICENUM" -lt 0 ] || [ "$CDCHOICENUM" -gt "$NUM_CDDB_MATCHES" ]; then
2942 echo "Invalid selection. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2946 if [ "$CDCHOICENUM" = "0" ]; then
2947 vecho "Creating empty CDDB template..."
2949 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
2950 echo "template" > "${ABCDETEMPDIR}/datasource.0"
2952 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n)
2953 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CDCHOICENUM")
2954 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)" >&2
2956 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM"
2957 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2961 # We need some code to show the selected option when local repository is selected and we have found a match
2962 vecho "Using cached CDDB match..." >&2
2963 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2964 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2965 CHOICE=$(checkstatus cddb-choice)
2966 if [ "$USELOCALRESP" = "y" ]; then :; else
2967 if [ -n "$CHOICE" ] ; then
2968 case $NUM_CDDB_MATCHES in
2971 echo "Selected template."
2973 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2975 echo "Selected: #$CHOICE"
2976 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2984 # We're noninteractive - pick the first choice.
2985 # But in case we run a previous instance and selected a choice, use it.
2986 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2987 # Show the choice if we are not using the locally stored one
2988 # or when the local search failed to find a match.
2989 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2990 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2991 #if [ "$PREVIOUSCHOICE" ]; then
2992 cat "${ABCDETEMPDIR}/cddbchoices"
2995 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2996 CDCHOICENUM=$PREVIOUSCHOICE
2999 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
3001 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
3006 if checkstatus cddb-choice >/dev/null; then :; else
3007 echo "abcde: internal error: cddb-choice not recorded." >&2
3010 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
3011 CDDBSOURCE=$(cat "${ABCDETEMPDIR}/datasource.$(checkstatus cddb-choice)")
3012 echo -n "Edit selected CDDB data " >&2
3013 if [ "$INTERACTIVE" = "y" ]; then
3014 if [ "$UNKNOWNDISK" = "y" ]; then
3015 echo -n "[Y/n]? " >&2
3017 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
3019 echo -n "[y/N]? " >&2
3026 if [ "$EDITCDDB" = "y" ]; then
3027 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
3029 # Use the debian sensible-editor wrapper to pick the editor that the
3030 # user has requested via their $EDITOR environment variable
3031 if [ -x "/usr/bin/sensible-editor" ]; then
3032 /usr/bin/sensible-editor "$CDDBDATA"
3033 elif [ -n "$EDITOR" ]; then
3034 if [ -x "$(which "${EDITOR%%\ *}")" ]; then
3035 # That failed, try to load the preferred editor, starting
3036 # with their EDITOR variable
3039 # If that fails, check for a vi
3040 elif which vi >/dev/null 2>&1; then
3042 elif [ -x /usr/bin/vim ]; then
3043 /usr/bin/vim "$CDDBDATA"
3044 elif [ -x /usr/bin/vi ]; then
3045 /usr/bin/vi "$CDDBDATA"
3046 elif [ -x /bin/vi ]; then
3048 # nano should be on all (modern, i.e., sarge) debian systems
3049 elif which nano >/dev/null 2>&1 ; then
3051 elif [ -x /usr/bin/nano ]; then
3052 /usr/bin/nano "$CDDBDATA"
3053 # mg should be on all OpenBSD systems
3054 elif which mg >/dev/null 2>&1 ; then
3056 elif [ -x /usr/bin/mg ]; then
3057 /usr/bin/mg "$CDDBDATA"
3060 log warning "no editor available. Check your EDITOR environment variable."
3062 # delete editor backup file if it exists
3063 if [ -w "$CDDBDATA~" ]; then
3068 # Some heuristics first. Look at Disc Title, and if it starts with
3069 # "Various", then we'll assume Various Artists
3070 if [ "$(grep -a ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -aEci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
3071 echo "Looks like a Multi-Artist CD" >&2
3074 echo -n "Is the CD multi-artist [y/N]? " >&2
3075 if [ "$INTERACTIVE" = "y" ]; then
3082 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
3085 # Need NUMTRACKS before cddb-tool will return it:
3086 NUMTRACKS=$(grep -a -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
3087 if [ "$(grep -ac "^TTITLE.*\/" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3088 # More than 1/2 tracks contain a "/", so guess forward
3090 elif [ "$(grep -ac "^TTITLE.*\-" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3091 # More than 1/2 contain a "-", so guess forward-dash
3093 elif [ "$(grep -ac "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3094 # More than 1/2 contain something in parens, so guess trailing-paren
3098 echo "1) Artist / Title" >&2
3099 echo "2) Artist - Title" >&2
3100 echo "3) Title / Artist" >&2
3101 echo "4) Title - Artist" >&2
3102 echo "5) Artist: Title" >&2
3103 echo "6) Title (Artist)" >&2
3104 echo "7) This is a single-artist CD" >&2
3105 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
3106 if [ "$INTERACTIVE" = "y" ]; then
3107 read VARIOUSARTISTSTYLE
3109 echo $DEFAULTSTYLE >&2
3110 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3112 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3113 # If they press Enter, then the default style (0) was chosen
3114 while [ "$VARIOUSARTISTSTYLE" -lt 0 ] || [ "$VARIOUSARTISTSTYLE" -gt 7 ]; do
3115 echo "Invalid selection. Please choose a number between 1 and 7."
3116 echo -n "Selection [1-7]: "
3117 read VARIOUSARTISTSTYLE
3118 VARIOUSARTISTSTYLE=$(echo "0$VARIOUSARTISTSTYLE" | xargs printf "%d")
3120 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3121 VARIOUSARTISTSTYLE="$DEFAULTSTYLE"
3123 vecho "Selected: $VARIOUSARTISTSTYLE"
3124 case "$VARIOUSARTISTSTYLE" in
3126 VARIOUSARTISTSTYLE=forward
3129 VARIOUSARTISTSTYLE=forward-dash
3132 VARIOUSARTISTSTYLE=reverse
3135 VARIOUSARTISTSTYLE=reverse-dash
3138 VARIOUSARTISTSTYLE=colon
3141 VARIOUSARTISTSTYLE=trailing-paren
3149 echo "variousartists=$VARIOUSARTISTS" >> "${ABCDETEMPDIR}/status"
3150 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "${ABCDETEMPDIR}/status"
3152 if [ "$EDITCDDB" = "y" ] && [ "$CDDBSOURCE" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3153 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3154 # This works but does not have the necessary error checking
3155 # yet. If you are familiar with the CDDB spec
3156 # (see http://www.freedb.org/src/latest/DBFORMAT)
3157 # and can create an error-free entry on your own, then put
3158 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3159 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3160 # your abcde.conf to change the email address submissions are
3163 # submit the modified file, if they want
3164 if [ "$NOSUBMIT" != "y" ]; then
3165 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3167 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3168 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3170 echo -n 'Invalid selection. Please answer "y" or "n": '
3173 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3174 echo -n "Sending..."
3175 $CDDBTOOL send "$CDDBDATA" "$CDDBSUBMIT"
3182 # User CDDBLOCALPOLICY to find out if we store the file or not...
3183 # Cache edited CDDB entry in the user's cddb dir
3184 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3185 # Make sure the cache directory exists
3186 mkdir -p "$CDDBLOCALDIR"
3187 NUM_LINES=$(( $(wc -l < "$CDDBDATA") - 1 ))
3188 OUTPUT_FILE="$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)"
3189 tail -n "$NUM_LINES" < "$CDDBDATA" > "${CDDBLOCALDIR}/${OUTPUT_FILE}"
3192 echo "cddb-edit" >> "${ABCDETEMPDIR}/status"
3196 # try to download CD cover
3199 if checkstatus "get-album-art"; then :; else
3201 ALBUMFILE="$(mungealbumname "$DALBUM")"
3202 ARTISTFILE="$(mungeartistname "$DARTIST")"
3203 GENRE="$(mungegenre "$GENRE")"
3204 YEAR=${CDYEAR:-$CDYEAR}
3205 # have we got a musicbrainz mbid or amazon asin?
3206 case "$CDDBMETHOD" in
3208 # try musicbrainz mbid
3209 if [ -s "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)" ]; then
3210 MBID=$(cat "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)")
3211 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3212 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3213 vecho "cover URL: $ALBUMARTURL" >&2
3214 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3215 if [ $? -ne 0 ]; then
3216 vecho "could not download cover from musicbrainz" >&2
3218 if [ -s "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)" ]; then
3219 ASIN=$(cat "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)")
3220 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3221 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3222 vecho "cover URL: $ALBUMARTURL" >&2
3223 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3224 if [ $? -ne 0 ]; then
3225 vecho "could not download cover from amazon" >&2
3227 # Check that size is reasonable; sometimes when there is no cover image
3228 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3229 FILESIZE=$(wc -c < "${ABCDETEMPDIR}/$ALBUMARTFILE")
3230 if [ "$FILESIZE" -lt 1024 ]; then
3231 rm "${ABCDETEMPDIR}/$ALBUMARTFILE"
3232 vecho "could not download cover from amazon" >&2
3236 vecho "no amazon ID found" >&2
3240 vecho "no musicbrainz ID found" >&2
3245 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3246 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3247 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "${ABCDETEMPDIR}/$ALBUMARTFILE" $GLYRCOPTS
3248 if [ $? -ne 0 ]; then
3249 vecho "could not download cover with glyrc" >&2
3254 if [ "$INTERACTIVE" = "y" ]; then
3255 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3256 # display properties of coverart when identify is available
3257 if new_checkexec "$IDENTIFY"; then
3258 $IDENTIFY $IDENTIFYOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3260 # display coverart when DISPLAY is set and display command is available
3261 if new_checkexec "$DISPLAYCMD" && [ "$DISPLAY" != "" ]; then
3262 $DISPLAYCMD $DISPLAYCMDOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2 &
3265 # nothing downloaded yet
3266 vecho "automatic album art downloading failed" >&2
3268 # see if the user can find a better album art manually
3269 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3271 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3272 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3274 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3277 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3278 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3280 if [ ! -z "$ALBUMARTURL" ]; then
3281 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3282 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3283 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3284 vecho "unable to download $ALBUMARTURL" >&2
3286 else # it's a local path
3287 cp "$ALBUMARTURL" "${ABCDETEMPDIR}/$ALBUMARTFILE"
3288 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3289 vecho "unable to copy $ALBUMARTURL to ${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3295 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3296 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ] && new_checkexec "$IDENTIFY"; then
3297 ALBUMARTURLTYPE=$($IDENTIFY "${ABCDETEMPDIR}/$ALBUMARTFILE" | cut -d' ' -f2)
3298 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" ] || [ "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3299 if new_checkexec "$CONVERT"; then
3300 mv "${ABCDETEMPDIR}/$ALBUMARTFILE" "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3301 $CONVERT "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp" $CONVERTOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE"
3302 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3304 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3305 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE" >&2
3306 vecho "without ImageMagick convert" >&2
3310 # copy to target directories
3311 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3312 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
3314 # put cover in the same place as the album
3315 if [ "$ONETRACK" = "y" ] ; then
3316 if [ "$VARIOUSARTISTS" = "y" ] ; then
3317 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3319 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3322 if [ "$VARIOUSARTISTS" = "y" ] ; then
3323 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3325 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3328 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3329 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3330 mkdir -p "$FINALALBUMARTDIR"
3331 cp "${ABCDETEMPDIR}/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3333 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3334 echo "get-album-art=$ALBUMARTURL" >> "${ABCDETEMPDIR}/status"
3336 log warning "could not get cover"
3337 echo "get-album-art=none" >> "${ABCDETEMPDIR}/status"
3342 # Optionally embed the albumart downloaded by the getalbumart fuction.
3343 # FIXME: It would be nice to have this also selectable from within the
3344 # FIXME: getalbumart function itself. Andrew
3348 ALBUMFILE="$(mungealbumname "$DALBUM")"
3349 ARTISTFILE="$(mungeartistname "$DARTIST")"
3350 GENRE="$(mungegenre "$GENRE")"
3351 YEAR=${CDYEAR:-$CDYEAR}
3353 # Allow for multiple output formats:
3354 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
3356 # Find the output directory for multi track encodes:
3357 if [ "$ONETRACK" != "y" ] ; then
3358 if [ "$VARIOUSARTISTS" = "y" ] ; then
3359 FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
3361 FINDPATH="$(eval echo "$OUTPUTFORMAT")"
3364 # Find the output directory for single track encodes:
3365 if [ "$ONETRACK" = "y" ] ; then
3366 if [ "$VARIOUSARTISTS" = "y" ] ; then
3367 FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3369 FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3373 FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
3376 # Instructions for each format, feel free to add more. It would be nice to
3377 # make the backup directory selectable and perhaps also have an option for
3378 # the bold to simply have the image deleted. Work for another day... Andrew.
3379 if [ -e "$ALBUMARTFILE" ] ; then
3384 "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$i"
3386 mkdir "$FINALDIR"/albumart_backup
3387 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3388 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3393 "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
3395 mkdir "$FINALDIR"/albumart_backup
3396 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3397 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3402 "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
3404 mkdir "$FINALDIR"/albumart_backup
3405 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3406 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3411 "$WVTAG" --write-binary-tag "Cover Art (Front)=@$ALBUMARTFILE" "$i"
3413 mkdir "$FINALDIR"/albumart_backup
3414 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3415 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3419 # This technique is drawn from 2 sources (the first link being the primary source):
3420 # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
3421 # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
3422 # In abcde a few steps are used in this sequence:
3424 # 1. Create a 'legal' header for the cover art image
3425 # 2. Makes a copy of the existing tags
3426 # 3. base64 the cover art image
3427 # 4. Copy the original tags + the base64 image back to the original ogg file
3429 # Might need some fine tuning but it is a start for abcde 2.9. Andrew.
3430 # FIXME: I am not sure if there is a maximum size for images converted in this
3431 # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
3433 # First some variables we can reuse:
3434 # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
3435 MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
3436 EXPORTTAGS="${ABCDETEMPDIR}/export_ogg_tags"
3437 BUILDHEADER="${ABCDETEMPDIR}/build_header"
3438 # Now build the header, gory details are here:
3439 # https://xiph.org/flac/format.html#metadata_block_picture
3441 printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
3443 printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3445 echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
3446 # Description length. FIXME: I have used 'Cover Image' but I am not sure
3447 # if this is better left as an empty field. Andrew
3448 printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3450 echo -n "Cover Image" >> "$BUILDHEADER"
3452 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3454 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3455 # Picture color depth:
3456 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3457 # Picture color count:
3458 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3460 printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
3461 # cat the image file:
3462 cat "$ALBUMARTFILE" >> "$BUILDHEADER"
3463 # Now process each ogg file by first exporting the original tags then
3464 # appending the cover image and finally copying the whole thing back
3465 # to the original image:
3468 # Make a backup of the existing tags:
3469 "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
3470 # base64 the file and then mix it all together with the exported tags:
3471 echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
3472 # Update the original ogg file with exported tags and the appended base64'd image:
3473 "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
3474 # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
3475 # note that the header file BUILDHEADER will be reused for each file in the loop:
3478 mkdir "$FINALDIR"/albumart_backup
3479 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3480 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3482 *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
3485 vecho "Suitable cover image not found, no embedding done..." >&2
3490 # do_cdread [tracknumber]
3491 # do_cdread onetrack [firsttrack] [lasttrack]
3495 # The commands here don't go through run_command because they're never supposed to be silenced
3496 # return codes need to be doublechecked anyway, however
3497 if [ "$1" = "onetrack" ]; then
3498 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3499 # FIXME # Until then, we grab the whole CD in one track, no matter what
3501 # We need the first and last track for cdda2wav/icedax
3503 LASTTRACK=$(expr $3 + 0)
3504 UTRACKNUM=$FIRSTTRACK
3505 case "$CDROMREADERSYNTAX" in
3506 flac) READTRACKNUMS="-" ;;
3509 # Add a variable to check if tracks are provided in command line and if not, rip the whole CD
3510 # We must make sure to rip from sector 0, both lines below work
3511 # READTRACKNUMS="-- -$LASTTRACK" ;;
3512 READTRACKNUMS="[.0]-" ;;
3513 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3514 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3515 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3521 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
3522 if [ "$USEPIPES" = "y" ]; then
3523 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3524 FILEARG="$( eval echo "\$$TEMPARG" )"
3525 PIPE_MESSAGE="and encoding "
3527 WAVDATA="${ABCDETEMPDIR}/track$UTRACKNUM.wav"
3528 case "$CDROMREADERSYNTAX" in
3529 ## FIXME ## Find the cases for flac, to avoid exceptions
3531 FILEARG="--output-name=$WAVDATA"
3538 if [ "$1" = "onetrack" ]; then
3539 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3541 if [ -r "$CDDBDATA" ]; then
3542 getcddbinfo TRACKNAME
3543 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3545 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3548 case "$CDROMREADERSYNTAX" in
3549 ### FIXME ### use an exception for flac, since it uses -o
3550 ### FIXME ### Shall we just use -o $FILEARG ??
3552 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3553 STRIPTRACKNUM=$(expr $UTRACKNUM + 0 )
3554 nice $READNICE $FLAC -d -f --cue="${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0}" "$FILEARG" "$CDROM" ;;
3556 if [ "$USEPIPES" = "y" ]; then
3557 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG"
3559 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG" >&2
3563 if [ "$OSFLAVOUR" = "OSX" ] ; then
3564 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3565 diskutil unmount "${CDROM#/dev/}"
3566 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3567 CDDA2WAVCDROM="IODVDServices"
3568 elif [ "$OSFLAVOUR" = "FBSD" ] || [ "$OSFLAVOUR" = "IRIX" ]; then
3569 CDDA2WAVCDROM="$CDROMID"
3571 if [ "$CDROMID" = "" ]; then
3572 CDDA2WAVCDROM="$CDROM"
3574 CDDA2WAVCDROM="$CDROMID"
3577 if [ "$USEPIPES" = "y" ]; then
3578 nice $READNICE $CDROMREADER -D "$CDDA2WAVCDROM" -t "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG"
3580 nice $READNICE $CDROMREADER -D "$CDDA2WAVCDROM" -t "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG" >&2
3584 # I cannot get USEPIPES to work with dagrab so just this:
3585 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v "$UTRACKNUM" >&2
3588 if [ "$USEPIPES" = "y" ]; then
3589 nice $READNICE $CDROMREADER -j "${READTRACKNUMS:-$UTRACKNUM}" "$CDROM" "$FILEARG"
3591 # Write ripped audio data to stdout and redirect to $FILEARG.
3592 # Progress is written to stderr by default and thus >&2 is not required.
3593 nice $READNICE $CDROMREADER -j "${READTRACKNUMS:-$UTRACKNUM}" "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3597 # Find the track's mounted path
3598 REALTRACKNUM=$(expr $UTRACKNUM + 0) # Unpad
3599 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3600 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3601 # If the file exists, copy it
3602 if [ -e "$FILEPATH" ] ; then
3603 if [ "$USEPIPES" = "y" ]; then
3604 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3606 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3612 if [ "$USEPIPES" = "y" ]; then
3613 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -w "$UTRACKNUM-[:1]" "$FILEARG"
3615 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -w "$UTRACKNUM-[:1]" "$FILEARG" >&2
3620 # If we get some error or we get some missing wav
3621 # (as long as we dont use pipes)
3622 if [ "$RETURN" != "0" ] || ( [ ! -s "$WAVDATA" ] && [ X"$USEPIPES" != "Xy" ] ); then
3623 # Thank goodness errors is only machine-parseable up to the
3624 # first colon, otherwise this woulda sucked
3625 if [ "$RETURN" = "0" ] || [ ! -s "$WAVDATA" ]; then
3626 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3628 if [ "$USEPIPES" = "y" ]; then
3629 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3631 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3635 if [ "$USEPIPES" = "y" ]; then
3636 echo "readencodetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
3638 echo "readtrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
3640 if [ "$1" = "onetrack" ]; then
3641 echo onetrack >> "${ABCDETEMPDIR}/status"
3647 # No values accepted, only uses env variables
3650 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3651 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3653 echo "abcde: unable to set the device speed" >&2
3659 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3662 if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 0 ] ; then
3664 warning) shift ; log warning "$@" ;;
3672 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3675 if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 1 ] ; then
3677 warning) shift ; log warning "$@" ;;
3685 # decho outputs a debug message if DEBUG is selected
3688 if [ x"$DEBUG" != "x" ]; then
3689 if echo "$1" | grep "^\[" > /dev/null 2>&1 ; then
3690 DEBUGECHO=$(echo "$@" | tr -d '[]')
3691 echo >&4 "[DEBUG] $DEBUGECHO: $(eval echo \\$${DEBUGECHO})"
3693 echo >&4 "[DEBUG] $1"
3698 # User-redefinable functions
3699 # Custom filename munging:
3702 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3705 # Custom filename munging specific to track names:
3711 # Custom filename munging specific to artist names:
3717 # Custom filename munging specific to album names:
3723 # Custom genre munging:
3726 echo "$CDGENRE" | tr "[:upper:]" "[:lower:]"
3730 # Empty pre_read function, to be defined in the configuration file.
3737 # Empty post_read function, to be defined in the configuration file.
3744 # Empty post_encode function, to be defined in the configuration file.
3750 ###############################################################################
3753 # Start of execution
3754 ###############################################################################
3759 # Currently three supported options ("musicbrainz", "cddb" for freedb.org and "cdtext")
3760 CDDBMETHOD=musicbrainz
3761 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3762 CDDBSUBMIT=freedb-submit@freedb.org
3764 HELLOINFO="$(whoami)@$(hostname)"
3766 CDDBLOCALPOLICY="always"
3767 CDDBLOCALRECURSIVE="y"
3768 CDDBLOCALDIR="$HOME/.cddb"
3771 # List of fields we parse and show during the CDDB parsing...
3772 SHOWCDDBFIELDS="year,genre"
3775 #CDROMREADERSYNTAX=cdparanoia
3776 ENCODERSYNTAX=default
3778 MP3ENCODERSYNTAX=default
3779 OGGENCODERSYNTAX=default
3780 OPUSENCODERSYNTAX=default
3781 MKAENCODERSYNTAX=default
3782 AIFFENCODERSYNTAX=default
3783 FLACENCODERSYNTAX=default
3784 SPEEXENCODERSYNTAX=default
3785 MPCENCODERSYNTAX=default
3786 WVENCODERSYNTAX=default
3787 TTAENCODERSYNTAX=default
3788 APENCODERSYNTAX=default
3789 MP2ENCODERSYNTAX=default
3790 AACENCODERSYNTAX=default
3791 NORMALIZERSYNTAX=default
3792 CUEREADERSYNTAX=default
3794 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3795 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3796 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3797 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3798 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3799 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3800 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3801 PLAYLISTDATAPREFIX=''
3802 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3803 VAPLAYLISTDATAPREFIX=''
3811 VARIOUSARTISTSTYLE=forward
3818 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3819 # i.e. CDROMID="1,0,0"
3821 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3822 # If we are using the ide-scsi emulation layer, we need to define a "g"
3823 CDPARANOIACDROMBUS="d"
3825 # program paths - defaults to checking your $PATH
3831 XINGMP3ENC=xingmp3enc
3845 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3849 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3859 NEROAACENC=neroAacEnc
3861 # Note that the qaac PATH will almost always require adjustment
3862 # as it is a Windows application being run through Wine. More
3863 # detailed notes in the sample abcde.conf file in the abcde tarball.
3866 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3874 VORBISCOMMENT=vorbiscomment
3876 NEROAACTAG=neroAacTag
3877 ATOMICPARSLEY=AtomicParsley
3881 CDPARANOIA=cdparanoia
3882 CD_PARANOIA="cd-paranoia"
3887 CDDISCID="cd-discid"
3889 MUSICBRAINZ=abcde-musicbrainz-tool
3893 NORMALIZE="normalize-audio"
3895 VORBISGAIN=vorbisgain
3899 # For Wavpack replay gain we set both the default of 'track gain'
3900 # as well as this option for 'album gain'. Better media players
3901 # such as vlc can select either or neither. Andrew.
3912 # Options for programs called from abcde:
3915 # These options needed by FFmpeg for tagging and selection of id3v2 version:
3916 # 1. '-write_id3v2 1' allows id3v2 tagging while '-write_id3v2 0' disables tagging
3917 # 2. '-id3v2_version 4' gives version id3v2.4 while '3' gives id3v2.3
3918 AIFFENCOPTS="-write_id3v2 1 -id3v2_version 4"
3930 VORBISGAINOPTS="--album"
3934 # The flac option is a workaround for an error where flac fails
3935 # to encode with error 'floating point exception'. This is flac
3936 # error in get_console_width(), corrected in flac 1.3.1
3938 FLACGAINOPTS="--add-replay-gain"
3945 # True Audio has no useful options but it is here anyway :)
3948 # Monkey's Audio Console (mac) chokes without a mode setting
3949 # so we set one here.
3956 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3957 # we set bitrate here.
3958 FDKAACENCOPTS='--bitrate 192k'
3980 VORBISCOMMENTOPTS="-R"
3981 METAFLACOPTS="--no-utf8-convert"
3986 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3988 # Defaults for album art downloads
3989 ALBUMARTFILE="cover.jpg"
3991 ALBUMARTALWAYSCONVERT="n"
3993 # Default to one process if -j isn't specified
3996 # List of actions to perform - by default, run to completion
3997 ACTIONS=cddb,read,encode,tag,move,clean
3999 # This option is basically for Debian package dependencies:
4000 # List of preferred outputs - by default, run with whatever we have in the path
4001 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:fdkaac:opus
4003 # List of preferred cdromreaders - by default, run whichever we have in the path
4004 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
4006 # fd for when `vecho` and `log info` called with redirected stdout
4009 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
4010 # Linux/OpenBSD. ftp is user for NetBSD.
4011 # Let's use these checkings to determine the OS flavour, which will be used
4014 if [ X"$UNAME" = "XFreeBSD" ] ; then
4019 elif [ X"$UNAME" = "XDarwin" ] ; then
4021 # By default md5sum is not installed, use md5 instead:
4024 # We should have diskutil in OSX, but let's be sure...
4026 CDROMREADERSYNTAX=cddafs
4027 # We won't find the eject program in OSX, and doing checkexec will fail further below...
4029 elif [ X"$UNAME" = "XOpenBSD" ] ; then
4033 elif [ X"$UNAME" = "XNetBSD" ] ; then
4037 elif [ X"$UNAME" = X"SunOS" ] ; then
4041 elif [ X"$UNAME" = X"IRIX64" ] ; then
4045 # Apparently necessary - see
4046 # https://abcde.einval.com/bugzilla/show_bug.cgi?id=29
4047 CDDISCID_NEEDS_PAUSE=y
4052 # If CDDBAVAIL is set to n, no CDDB read is done
4056 # But before we get into business, let us chop off any GREP environmental
4061 if [ -z "$OUTPUTDIR" ]; then
4065 if [ -z "$WAVOUTPUTDIR" ]; then
4066 WAVOUTPUTDIR="$OUTPUTDIR"
4069 # Load system defaults
4070 if [ -r /etc/abcde.conf ]; then
4073 # Load user preference defaults
4074 if [ -r "$HOME/.abcde.conf" ]; then
4075 . "$HOME/.abcde.conf"
4078 # By this time, we need some HTTPGETOPTS already defined.
4079 # If the user has defined a non-default HTTPGET method, we should not be empty.
4081 if [ "$HTTPGETOPTS" = "" ] ; then
4083 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
4084 curl) HTTPGETOPTS="-f -s -L";;
4085 fetch)HTTPGETOPTS="-q -o -";;
4086 ftp) HTTPGETOPTS="-a -V -o - ";;
4087 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
4091 # If the CDROM has not been set yet, find a suitable one.
4092 # If this is a devfs system, default to /dev/cdroms/cdrom0
4093 # instead of /dev/cdrom
4094 if [ "$CDROM" = "" ] ; then
4095 if [ -e /dev/cdroms/cdrom0 ]; then
4096 CDROM=/dev/cdroms/cdrom0
4097 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
4098 CDROM=/dev/${BASH_REMATCH[1]}
4099 elif [ -e /dev/cdrom ]; then
4101 elif [ -e /dev/sr0 ]; then
4103 elif [ -e /dev/cd0c ]; then
4105 elif [ -e /dev/acd0c ]; then
4107 elif [ -e /dev/disk1 ]; then
4112 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
4113 # that's changed to a number to allow for more control. Deal with
4114 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
4115 case "$EXTRAVERBOSE" in
4124 # Parse command line options
4125 while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pPQ:r:s:S:t:T:UvVxX:w:W:z opt ; do
4128 a) ACTIONS="$OPTARG" ;;
4129 A) EXPACTIONS="$OPTARG" ;;
4131 B) GETALBUMART=y ; EMBEDALBUMART=y ;;
4132 c) if [ -e "$OPTARG" ]; then
4135 log error "config file \"$OPTARG\" cannot be found."
4139 C) CDDBDISCID="$( echo "${OPTARG#abcde.}" | tr -d /)" ;;
4140 d) CDROM="$OPTARG" ;;
4143 e) ERASEENCODEDSTATUS=y ;;
4144 E) ENCODING="$OPTARG" ;;
4149 j) MAXPROCS="$OPTARG" ;;
4152 L) CDDBUSELOCAL=y ;;
4157 o) OUTPUTTYPE="$OPTARG" ;;
4160 Q) CDDBMETHOD="$OPTARG" ;;
4161 r) REMOTEHOSTS="$OPTARG" ;;
4162 R) CDDBLOCALRECURSIVE=y ;;
4163 s) SHOWCDDBFIELDS="$OPTARG" ;;
4164 S) CDSPEEDVALUE="$OPTARG" ;;
4165 t) STARTTRACKNUMBER="$OPTARG" ;;
4166 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
4169 echo "This is abcde v$VERSION."
4170 echo "Usage: abcde [options] [tracks]"
4171 echo "abcde -h for extra help"
4174 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
4176 X) CUE2DISCID="$OPTARG" ;;
4177 w) COMMENT="$OPTARG" ;;
4178 W) if echo "$OPTARG" | grep "[[:digit:]]" > /dev/null 2>&1 ; then
4179 STARTTRACKNUMBER="${OPTARG}$(printf "%02d" "${STARTTRACKNUMBER:-01}")"
4180 STARTTRACKNUMBERTAG="y"
4181 COMMENT="CD${OPTARG}"
4182 DISCNUMBER="${OPTARG}"
4184 log error "argument of -W must be integer"
4188 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
4193 shift $(($OPTIND - 1))
4195 # Here it comes the worse part of the whole thing. From here until we start
4196 # ripping, we have a mixture of sanity checks, verifications, default settigs
4197 # and other crazy stuff that interdepends, but hey, someone has to do it.
4199 # If NOCDDBQUERY is set, don't query the CDDB server.
4200 if [ "$NOCDDBQUERY" = "y" ]; then
4204 # If the user specified a flac file, then switch to special flac mode
4205 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
4206 if [ ! -f "$CDROM" ]; then
4207 log error "the defined file for FLAC ripping cannot be found" >&2
4210 vecho warning "switching to flac CDROMREADERSYNTAX..."
4211 CDROMREADERSYNTAX=flac
4212 # We have a builtin version of cue2discid...
4213 case "$CUE2DISCID" in
4215 *) NEEDCUE2DISCID=y;;
4221 # If the user provided a CDDBDISCID, disable eject
4222 if [ -n "${CDDBDISCID}" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
4224 # Check the available cd rippers in the system, from the ones we know.
4225 if [ "$CDROMREADERSYNTAX" = "" ]; then
4226 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
4227 if new_checkexec "$DEFAULT_CDROMREADER"; then
4228 CDROMREADERSYNTAX="$DEFAULT_CDROMREADER"
4232 if [ "$CDROMREADERSYNTAX" = "" ]; then
4233 log error "no cdreader found in your PATH"
4234 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4239 # Decide if we can continue.
4240 if [ "$ONETRACK" = "y" ]; then
4241 # FIXME # remove check as soon as we find out about the other readers
4242 case "$CDROMREADERSYNTAX" in
4244 cdparanoia | libcdio) ;;
4245 cdda2wav | icedax) ;;
4247 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
4250 if [ "$BATCHNORM" = "y" ]; then
4251 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
4254 if [ "$NOGAP" = "y" ]; then
4255 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
4258 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
4259 # FIXME # allow ranges of tracks to be selected for onetrack ripping
4260 if [ $# -gt 0 ]; then
4261 log warning "ONETRACK mode selected, grabbing all tracks..."
4264 while [ $# -gt 0 ]; do
4265 # Range parsing code courtesy of Vincent Ho
4266 # Cleaned up to use shell built-ins by Charles Steinkuehler
4267 if [ "${1#*[^0-9-]}" != "$1" ]; then
4268 log error "syntax error while processing track numbers ($1)"
4273 while [ "${RSTART:=1}" -le "${REND:=0}" ] ; do
4274 TRACKQUEUE="$TRACKQUEUE $RSTART"
4275 RSTART=$(( $RSTART + 1 ))
4282 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
4283 # List of experimental actions: retag,transcode
4285 # Determine what actions are to be done from $ACTIONS and set the
4286 # following environment variables for them:
4298 ## FIXME ## Lets keep compatibility with -M
4299 [ "$DOCUE" != "y" ] && DOCUE=n
4301 for ACTION in $(echo "$ACTIONS" | tr , \ )
4304 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4305 cue) DOCUE=y ; MAKECUEFILE=y ;;
4308 normalize) DONORMALIZE=y; DOREAD=y;;
4309 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4310 encode) DOENCODE=y; DOREAD=y;;
4311 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4312 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4313 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4314 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4315 playlist) DOCDDB=y; DOPLAYLIST=y;;
4317 getalbumart) GETALBUMART=y;;
4318 embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
4322 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4323 # FIXME # should we abort on error or just inform the user?
4324 log warning "selected both normalize and replaygain actions"
4327 for SHOWCDDBFIELD in $(echo "$SHOWCDDBFIELDS" | tr , \ ); do
4328 case $SHOWCDDBFIELD in
4329 y*|Y*) SHOWCDDBYEAR="y";;
4330 g*|G*) SHOWCDDBGENRE="y";;
4335 # At this point a CDROM has to be defined, so we check it exists.
4336 if [ X"$CDROM" != "X" ] ; then
4337 if [ "$NEEDCDROMID" = "y" ] ; then
4338 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ]; then
4339 if [ "$OSFLAVOUR" = "IRIX" ]; then
4340 if [ -z "$CDROMID" ]; then
4341 CDROMID="$(echo "$CDROM" | sed -e 's;/dev/scsi/sc\([0-9]*\)d\([0-9]*\)l\([0-9]*\)$;\1,\2,\3;')"
4344 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
4345 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4346 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4350 elif [ ! -e "$CDROM" ] && [ X"$DOREAD" = "Xy" ]; then
4351 log error "CDROM device cannot be found."
4354 # avoid processing if we are not going to hit the CDROM.
4355 elif [ X"$DOREAD" = "Xy" ]; then
4356 log error "CDROM has not been defined or cannot be found"
4360 # USEPIPES pre-tests, before we get into more serious stuff
4361 # Not compatible with:
4362 # - multiple outputs
4364 # - lowdisk algorithm
4366 if [ X"$USEPIPES" = "Xy" ]; then
4367 NUM_OUTPUT_TYPES="$(echo "$OUTPUTTYPE" | tr , \ | wc -w )"
4368 if [ "$NUM_OUTPUT_TYPES" -gt 1 ]; then
4369 log error "Unix pipes not compatible with multiple outputs"
4372 if [ X"$DONORMALIZE" = "Xy" ]; then
4373 log error "Unix pipes not compatible with normalizer"
4374 # FIXME # Do we need to exit or shall we just disable the mode?
4377 if [ X"$BATCHNORM" = "Xy" ]; then
4378 log error "Unix pipes not compatible with BATCHNORM encoding"
4381 if [ X"$NOGAP" = "Xy" ]; then
4382 log error "Unix pipes not compatible with NOGAP encoding"
4385 if [ X"$DOENCODE" = "Xn" ]; then
4386 vecho warning "Disabling Unix pipes since we are not encoding!"
4389 if [ X"$LOWDISK" = "Xy" ]; then
4390 log error "Unix pipes not compatible with lowdisk algorithm"
4395 # LOWDISK pre-tests, before we get into more problematic stuff
4396 # Not compatible with anything that needs all the files in the hard disc:
4399 if [ X"$LOWDISK" = "Xy" ]; then
4400 if [ X"$BATCHNORM" = "Xy" ]; then
4401 log error "Unix pipes not compatible with BATCHNORM encoding"
4404 if [ X"$NOGAP" = "Xy" ]; then
4405 log error "Unix pipes not compatible with NOGAP encoding"
4410 # BATCHNORM pre-tests, before we get into serious problems
4411 # Not compatible with
4412 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4413 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4417 # Check the encoding format from the ones available in the system, if nothing has been configured.
4418 if [ X"$OUTPUTTYPE" = "X" ]; then
4419 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4420 DEFAULT_OUTPUT_FORMAT="$(echo "$DEFAULT_OUTPUT" | cut -d ":" -f 1)"
4421 DEFAULT_OUTPUT_BINARY="$(echo "$DEFAULT_OUTPUT" | cut -d ":" -f 2)"
4422 if [ -x "$(which "$DEFAULT_OUTPUT_BINARY")" ] ; then
4423 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4424 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4428 if [ X"$OUTPUTTYPE" = "X" ]; then
4429 log error "no encoder found in the PATH"
4430 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4435 # Decide which CDROM reader we're gonna use
4436 case "$CDROMREADERSYNTAX" in
4438 CDROMREADER="$CDPARANOIA"
4439 CDROMREADEROPTS="$CDPARANOIAOPTS"
4442 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4443 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4444 CDROMREADER="$CD_PARANOIA"
4445 CDROMREADEROPTS="$CDPARANOIAOPTS"
4448 CDROMREADER="$CDDA2WAV"
4449 CDROMREADEROPTS="$CDDA2WAVOPTS"
4452 CDROMREADER="$DAGRAB"
4453 CDROMREADEROPTS="$DAGRABOPTS"
4457 CDROMREADEROPTS="$PIRDOPTS"
4460 CDROMREADER="$CDDAFS"
4461 CDROMREADEROPTS="$CDDAFSOPTS"
4465 CDROMREADEROPTS="$FLACOPTS"
4469 # There's only one normalize...
4470 case "$NORMALIZERSYNTAX" in
4472 NORMALIZER="$NORMALIZE"
4473 NORMALIZEROPTS="$NORMALIZEOPTS"
4477 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4478 case "$OUTPUTTYPE" in *:*)
4479 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4480 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4482 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4483 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4484 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4485 aiff:*) AIFFENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4486 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4487 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4488 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4489 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4490 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4491 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4492 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4493 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4494 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4497 # Allows commandline selection of options while using multiple outputs.
4498 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4499 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4500 TEMPOUTPUT=${OUTPUT%%:*}
4501 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4503 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4507 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4508 # for flacs and speexenc for speex and mpcenc for mpcs and fdkaac for m4as and
4509 # wavpack for wvs...
4511 # Getting ready for multiple output changes
4512 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
4516 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4517 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4518 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4519 OGGOUTPUTCONTAINER=ogg
4522 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4523 OPUSOUTPUTCONTAINER=opus
4526 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4527 MKAOUTPUTCONTAINER=mka
4530 [ "$AIFFENCODERSYNTAX" = "default" ] && AIFFENCODERSYNTAX=ffmpeg
4531 AIFFOUTPUTCONTAINER=aiff
4534 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4535 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4536 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4537 [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
4540 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4541 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4542 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4543 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4544 [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
4547 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4548 # [ "$DOREPLAYGAIN" = "y" ] &&
4551 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4552 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4555 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4557 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4558 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4559 [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
4562 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4563 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4566 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4567 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4568 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4571 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4572 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4573 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4576 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4578 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4579 # compiled without libmp4v2... Andrew.
4582 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=fdkaac
4583 [ "$AACENCODERSYNTAX" = "faac" ] && [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4584 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4585 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4586 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4587 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4588 [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
4591 if [ "$KEEPWAVS" = "y" ]; then
4592 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4596 *) log error "Invalid OUTPUTTYPE defined"
4602 # decide which encoder
4603 case "$MP3ENCODERSYNTAX" in
4605 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4609 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4613 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4614 MP3ENCODER="$BLADEENC"
4617 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4621 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4622 MP3ENCODER="$XINGMP3ENC"
4625 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4626 MP3ENCODER="$MP3ENC"
4629 case "$OGGENCODERSYNTAX" in
4631 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4632 OGGENCODER="$VORBIZE"
4635 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4636 OGGENCODER="$OGGENC"
4639 case "$OPUSENCODERSYNTAX" in
4641 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4642 OPUSENCODER="$OPUSENC"
4645 case "$MKAENCODERSYNTAX" in
4647 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4648 MKAENCODER="$FFMPEG"
4651 case "$AIFFENCODERSYNTAX" in
4653 AIFFENCODEROPTS="${AIFFENCODEROPTSCLI:-$AIFFENCOPTS}"
4654 AIFFENCODER="$FFMPEG"
4657 case "$FLACENCODERSYNTAX" in
4659 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4661 if [ "$DOREPLAYGAIN" = "y" ]; then
4662 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4664 # FLAC streams can be encapsulated on a Ogg transport layer
4665 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4666 log error "FLAC on an Ogg container is not yet supported"
4667 log error "due to problem with adding comments to such files"
4669 FLACOUTPUTCONTAINER=ogg
4671 FLACOUTPUTCONTAINER=flac
4675 case "$SPEEXENCODERSYNTAX" in
4677 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4678 SPEEXENCODER="$SPEEXENC"
4681 case "$MPCENCODERSYNTAX" in
4683 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4684 MPCENCODER="$MPCENC"
4687 case "$WVENCODERSYNTAX" in
4689 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4690 # and in the interests of backward compatibility:
4691 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4692 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4693 WVENCODER="$WAVPACK"
4695 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4696 WVENCODER="$WAVPACK"
4700 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4704 case "$TTAENCODERSYNTAX" in
4706 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4710 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4711 TTAENCODER="$TTAENC"
4714 case "$APENCODERSYNTAX" in
4716 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4720 case "$MP2ENCODERSYNTAX" in
4722 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4723 MP2ENCODER="$TWOLAME"
4726 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4727 MP2ENCODER="$FFMPEG"
4730 case "$AACENCODERSYNTAX" in
4731 # Some elaborate 'if' work to keep backward compatibility for those
4732 # who don't realise that AACENCOPTS does not work with abcde from
4733 # version 2.7 onwards.
4735 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4736 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4739 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4744 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4745 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4746 AACENCODER="$NEROAACENC"
4748 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4749 AACENCODER="$NEROAACENC"
4753 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4754 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4755 AACENCODER="$FDKAAC"
4757 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4758 AACENCODER="$FDKAAC"
4762 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4763 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4766 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4771 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4772 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4773 AACENCODER="$FHGAACENC"
4775 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4776 AACENCODER="$FHGAACENC"
4780 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4781 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4782 AACENCODER="$FFMPEG"
4784 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4785 AACENCODER="$FFMPEG"
4795 TAGGEROPTS="$ID3OPTS"
4800 TAGGEROPTS="$ID3V2OPTS"
4805 TAGGEROPTS="$ID3TAGOPTS"
4809 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4810 # trouble with CDDBPROTO=5 (which we test here) but also
4811 # with cached cddb files in latin1 (which we cannot test).
4812 if [ "$CDDBPROTO" -lt 6 ]; then
4813 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4816 # eyeD3 version 0.7 changed syntax
4817 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4818 # only if it offers the --set-encoding, assume <= 0.6.x
4820 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4822 # anything wrong, any failure, assume >= 0.7
4824 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4828 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4833 # NOGAP is specific to lame. Other encoders fail ...
4834 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4835 log warning "the NOGAP option is specific to lame. Deactivating..."
4840 case "$CUEREADERSYNTAX" in
4842 CUEREADEROPTS="${CDROM}"
4846 CUEREADEROPTS="$MKCUEOPTS ${CDROM}"
4851 # which information retrieval tool are we using?
4857 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4858 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4859 log error "FLAC on an Ogg container is not yet supported"
4860 log error "due to problem with adding comments to such files"
4862 OGGOUTPUTCONTAINER=ogg.ogg
4863 FLACOUTPUTCONTAINER=flac.ogg
4864 vecho warning "modified file endings due to conflicting transport"
4865 vecho warning "layers in Ogg/Vorbis and Ogg/FLAC"
4868 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4870 if [ "$ENCNICE" ]; then
4871 ENCNICE="-n $ENCNICE"
4873 if [ "$READNICE" ]; then
4874 READNICE="-n $READNICE"
4876 if [ "$DISTMP3NICE" ]; then
4877 DISTMP3NICE="-n $DISTMP3NICE"
4880 # Don't check for stuff if it's not needed
4881 if [ "$REMOTEHOSTS" ]; then
4884 if [ "$DONORMALIZE" = "y" ]; then
4887 if [ "$EJECTCD" = "y" ]; then
4890 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4891 # Need an http tool to be able to do CDDB
4897 if [ "$DOCUE" = "y" ]; then
4901 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4902 case "$CDROMREADERSYNTAX" in
4903 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4904 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4905 ### FIXME ### translate "cue2discid" from python to bash
4906 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4911 if [ "$GETALBUMART" = "y" ]; then
4916 ###USEPIPESSUPPORT###
4918 # Rippers with USEPIPE support
4919 PIPERIPPER_cdparanoia="-"
4920 PIPERIPPER_libcdio="-"
4921 # Note that by default in abcde cdda2wav redirects to icedax.
4922 PIPERIPPER_cdda2wav="-"
4923 PIPERIPPER_debug="-"
4924 PIPERIPPER_flac="-c "
4927 # Encoders with USEPIPE support
4930 PIPE_bladeenc="stdin"
4943 # Both neroAacEnc and fdkaac seem to manage without the addition of
4944 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4945 # in this manner. Andrew.
4949 # Figure out if we can use pipes with the ripper/encoder combination
4951 if [ "$USEPIPES" = "y" ]; then
4952 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4955 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4957 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4959 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4961 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4963 PIPEENCODERSVARCHECK="PIPE_$AIFFENCODERSYNTAX" ;;
4965 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4967 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4969 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4971 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4973 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4975 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4977 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4979 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4980 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4981 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4982 log error "no support for pipes with given ripper"
4983 log error "read the FAQ file from the source tarball to get help."
4986 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4987 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4988 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4989 log error "no support for pipes with given encoder"
4990 log error "read the FAQ file from the source tarball to get help"
4995 # Make sure a buncha things exist
4996 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4997 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4998 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER $AIFFENCODER \
4999 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
5000 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
5001 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
5002 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
5003 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
5004 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
5005 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
5006 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
5007 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
5008 ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
5013 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
5014 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
5015 # these files). The resulting files are actually ADTS streams which belong in an
5016 # aac container and with some version sniffing this is all cleaned up below. If
5017 # faac is compiled with libmp4v2 inline tagging occurs with faac.
5019 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
5020 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
5021 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
5022 echo "WARNING: Your copy of Faac does not have mp4 support"
5023 echo "WARNING: Encoding untagged files to aac..."
5024 # Replace m4a with aac for single and multi-output encodes:
5025 OUTPUTTYPE=$(echo "$OUTPUTTYPE" | sed 's/m4a/aac/')
5027 echo "Using Faac to Tag AAC Tracks..."
5031 # And last but not least, check if we can diff between files. We do not abort,
5032 # since diffing is not critical...
5033 if [ -x "$(which "$DIFF")" ]; then :; else
5034 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
5038 ## Now that we have metaflac, check if we need cue2discid
5039 #case $CDROMREADERSYNTAX in
5041 # CDDBTRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
5042 # if [ "$CDDBTRACKINFO" = "" ]; then
5043 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
5048 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
5049 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
5050 HTTPGET="$HTTPGET $HTTPGETOPTS"
5052 # Here it used to say:
5053 # One thousand lines in, we can start doing stuff with things
5054 # Well, right now we are at line 3737 ;)
5055 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
5057 # Export needed things so they can be read in this subshell
5058 export CDDBTOOL # Path and options for the tool to query CDDB
5059 export ABCDETEMPDIR # Path to the tmpdir for this rip
5060 export TRACKQUEUE # 0-padded list of tracks to be processed
5061 export LOWDISK # Are we using the low-diskspace algorithm?
5062 export EJECTCD # Should we eject the CD when we're finished ripping?
5063 export EJECT # The commend to use to eject the CD, if we have one
5064 export EJECTOPTS # Options to that command
5065 export CDROM # Device path for the CD device
5066 export CDDBDATA # The filename we're using for CD lookup data
5067 export REMOTEHOSTS # List of remote hosts for parallel encoding, if given
5068 export MAXPROCS # The number of *local* encodes to do in parallel
5069 export HTTPGET # Program to use to grab files via http
5070 export MD5SUM # Program to calculate MD5 checksums
5072 if [ "$DOREAD" = "y" ]; then
5073 # User-definable function to set some things. Use it for
5074 # - closing the CD tray with eject -t
5075 # - set the CD speed value with eject -x
5076 vecho -n "Executing customizable pre-read function... "
5078 pre_read # Execute the user-defined pre-read function. Close the CD with it.
5083 # Get ABCDETEMPDIR created and status file initialized
5086 if [ "$DOCDDB" = "y" ]; then
5087 # start with a sane default:
5088 CDDBLOCALSTATUS=notfound
5089 if [ $CDDBUSELOCAL = "y" ]; then
5092 if checkstatus cddb-choice > /dev/null; then
5096 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
5098 for CDDBMETHCHOICE in $(echo "$CDDBMETHOD" | tr -d ' ' | tr , ' ')
5100 addstatus "Lookup method $idx: $CDDBMETHCHOICE"
5102 vecho "Found $NUM_CDDB_MATCHES matches so far"
5103 vecho "Trying lookup method ${CDDBMETHCHOICE}"
5105 # Run all the desired data acquisition methods, in the order
5106 # specified by the user. Each will use its own temporary
5107 # subdirectory, then copy the cddbread.* etc. files up into
5109 case "$CDDBMETHCHOICE" in
5120 echo "Unknown lookup method $CDDBMETHCHOICE. Aborting." >&2
5127 rm -f "${ABCDETEMPDIR}/cddbchoices"
5128 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
5130 if [ $NUM_CDDB_MATCHES = 0 ]; then
5131 # If we got no matches, we need to
5132 # generate a blank CDDB template.
5133 vecho "Unable to find any matches, generating unknown template."
5134 echo "No lookup matches." >> "${ABCDETEMPDIR}/cddbchoices"
5135 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
5136 echo "template" > "${ABCDETEMPDIR}/datasource.0"
5137 # List out disc title/author and contents of template
5138 echo ---- Unknown Artist / Unknown Album ---- >> "${ABCDETEMPDIR}/cddbchoices"
5140 for TRACK in $(f_seq_row 1 $TRACKS)
5142 echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5144 echo >> "${ABCDETEMPDIR}/cddbchoices"
5145 echo cddb-read-0-complete >> "${ABCDETEMPDIR}/status"
5146 echo cddb-choice=0 >> "${ABCDETEMPDIR}/status"
5147 echo 503 > "${ABCDETEMPDIR}/cddbquery"
5149 # We have matches; create the cddbchoices and cddbquery
5150 # files from all the inputs we have
5151 if [ $NUM_CDDB_MATCHES = 1 ]; then
5152 echo "Retrieved 1 match..." >> "${ABCDETEMPDIR}/cddbchoices"
5153 echo -n "200 " > "${ABCDETEMPDIR}/cddbquery"
5154 cat "${ABCDETEMPDIR}/cddbquery.1" >> "${ABCDETEMPDIR}/cddbquery"
5156 echo "Retrieved $NUM_CDDB_MATCHES matches..." >> "${ABCDETEMPDIR}/cddbchoices"
5157 echo "210 Found exact matches, list follows (until terminating .)" > "${ABCDETEMPDIR}/cddbquery"
5158 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5160 cat "${ABCDETEMPDIR}/cddbquery.$X" >> "${ABCDETEMPDIR}/cddbquery"
5162 echo "." >> "${ABCDETEMPDIR}/cddbquery"
5165 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5167 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.$X" | cut -c8- | tr -d \\r\\n)
5168 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$X")
5169 echo "#$X ($SOURCE): ---- ${ATITLE} ----" >> "${ABCDETEMPDIR}/cddbchoices"
5170 for TRACK in $(f_seq_row 1 $TRACKS)
5172 echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5174 echo >> "${ABCDETEMPDIR}/cddbchoices"
5181 eval "$($CDDBTOOL parse "$CDDBDATA")"
5184 # Before reading tracks, we set the speed of the device
5186 if [ X"$CDSPEEDVALUE" != "X" ]; then
5187 case "$CDROMREADERSYNTAX" in
5188 cdparanoia|libcdio|debug) ;;
5195 # Define the first and last track, since we might need them later in several places
5196 FIRSTTRACK=$( get_first $TRACKQUEUE )
5197 LASTTRACK=$( get_last $TRACKQUEUE )
5199 if [ -f "${ABCDETEMPDIR}/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
5200 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
5201 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
5202 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
5205 if checkstatus onetrack ; then ONETRACK=y ; fi
5207 if [ "$ONETRACK" = "y" ]; then
5208 # Reuse the CUEFILE in case we created it (now or in a previous run)
5209 if CUEFILE=$(checkstatus cuefile); then
5214 # Create playlist if needed (backgroundable) and start reading in tracks
5218 if [ ! "$ONETRACK" = "y" ]; then
5219 if [ "$DOPLAYLIST" = "y" ]; then
5220 echo Creating playlist... >&2
5225 if [ "$GETALBUMART" = "y" ]; then
5229 # For the lowdisk option, only one program is running at once so the encoder
5230 # can be unsilenced right away.
5231 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
5232 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5235 if [ "$ONETRACK" = "y" ]; then
5237 if [ "$USEPIPES" = "y" ]; then
5238 if checkstatus "readencodetrack-$FIRSTTRACK"; then :; else
5239 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
5242 if checkstatus "readtrack-$FIRSTTRACK"; then :; else
5243 do_cdread onetrack $FIRSTTRACK $LASTTRACK
5247 for UTRACKNUM in $TRACKQUEUE
5249 if [ "$DOREAD" = "y" ]; then
5250 if [ "$USEPIPES" = "y" ]; then
5251 if checkstatus "readencodetrack-$UTRACKNUM"; then :; else
5252 # Read, pipe, shut up!
5253 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
5256 if checkstatus "readtrack-$UTRACKNUM"; then :; else
5257 do_cdread $UTRACKNUM
5259 if [ "$?" != "0" ]; then
5260 # CD read failed - don't give the goahead to
5267 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
5270 # If we are not reading, set the encode output to loud already, so
5271 # that we can see the output of the first track.
5272 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
5273 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5275 echo NEXTTRACK # Get the encoder machine churning again
5276 if [ "$DOREAD" = "y" ]; then
5277 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
5278 until checkstatus "encodetrack-$UTRACKNUM"
5280 if checkerrors "encodetrack-$UTRACKNUM"; then
5291 # Now that we're done the encoding can be loud again -
5292 # if we're not using SMP.
5293 if [ "$MAXPROCS" = "1" ]; then
5294 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5297 # All tracks read, start encoding.
5298 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
5302 # Execute the user-defined post_read function before ejecting CD
5305 # We are now finished with the cdrom - it can be safely ejected. Note that
5306 # abcde will not have completed yet.
5307 if [ "$EJECTCD" = "y" ]; then
5308 # We check if the disk we are processing is actually the disk inside the
5309 # CD tray. If not, we do not eject the CD, since it might be so that the
5310 # user ejected it manually.
5311 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
5312 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$CDDBTRACKINFO" ] ; then
5313 # More FreeBSD bits.
5314 if [ X"$UNAME" = X"FreeBSD" ] ; then
5315 # FreeBSD eject uses the EJECT environment variable to name the CDROM
5316 # but in this script EJECT is in the envionment and names the program
5319 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
5320 cd="$(echo "$CDROM" | sed -e 's=.*/==;s=[a-h]$==;')"
5321 $eject $EJECTOPTS $cd
5322 elif [ X"$UNAME" = X"Darwin" ] ; then
5323 diskutil eject "${CDROM#/dev/}" 0
5324 elif [ -x "$(which "$EJECT")" ]; then
5325 $EJECT $EJECTOPTS "$CDROM"
5332 ## Do we need to pre-process
5333 #if [ x"$PREPROCESS" = "x" ] ; then
5336 # for PRETRACKNUM in $TRACKQUEUE
5339 # if [ "$GOAHEAD" = "NO" ]; then break; fi
5341 # until [ $PREPROCEED ]
5343 # if checkstatus "readtrack-$PRETRACKNUM"; then PREPROCEED=y; break; fi
5344 # # all locations are working, wait and try again later
5345 # if [ ! $PREPROCEED ]; then sleep 3; fi
5347 # ( do_preprocess $PRETRACKNUM
5355 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
5357 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
5358 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5359 if [ "$GOAHEAD" != "NO" ]; then
5360 for LASTTRACK in $TRACKQUEUE; do :; done
5361 if checkstatus "readtrack-$LASTTRACK"; then
5362 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
5363 if checkstatus "normalizetrack-$LASTTRACK"; then :; else do_batch_normalize; fi
5364 if checkerrors batch-normalize; then exit 1; fi
5366 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
5367 if [ "$DONORMALIZE" = "y" ]; then
5368 for UTRACKNUM in $TRACKQUEUE
5370 if checkstatus "readtrack-$UTRACKNUM"; then
5371 if checkstatus "normalizetrack-$UTRACKNUM"; then :; else do_normalize "$UTRACKNUM"; fi
5375 if checkstatus "encodetrack-$LASTTRACK"; then :; else do_nogap_encode; fi
5376 if checkerrors nogap-encode; then exit 1; fi
5382 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
5383 if [ "$ONETRACK" = "y" ] ; then
5384 TRACKQUEUE="$FIRSTTRACK"
5385 TRACKS="$FIRSTTRACK"
5388 # Do the encoding, including parallelization of remote encoding
5389 # Figure out where each track is going to be encoded
5390 ENCODELOCATIONS="$(echo "$REMOTEHOSTS" | tr , ' ')"
5391 if [ "$MAXPROCS" != "0" ]; then
5392 for NUM in $(f_seq_row 1 $MAXPROCS)
5394 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5398 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5399 for UTRACKNUM in $TRACKQUEUE
5402 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5403 if [ "$GOAHEAD" = "NO" ]; then break; fi
5404 # find out where this track is to be encoded
5405 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ]; then
5406 # Make sure we have a place to encode this, if not, exit stage right
5407 if [ -z "$ENCODELOCATIONS" ]; then
5413 for LOCATION in $ENCODELOCATIONS
5415 PREVIOUSTRACK="$(checkstatus "encodetracklocation-$LOCATION")"
5416 # check first if a track has ever been assigned to this location
5417 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5418 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5419 if checkerrors "encodetrack-$PREVIOUSTRACK"; then
5420 for TEMPLOCATION in $ENCODELOCATIONS
5422 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5423 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5426 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5431 # We're still here, this location must have been previously assigned,
5432 # and last completed without error - check if it's done with the
5433 # previous track yet
5434 if checkstatus "encodetrack-$PREVIOUSTRACK"; then PROCEED=y; break; fi
5436 # all locations are working, wait and try again later
5437 if [ ! "$PROCEED" ]; then sleep 3; fi
5439 # Record the location we're about to encode the next track at
5440 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
5442 # Don't proceed with the rest of the loop if we can't encode
5443 if [ "$ABORT" ]; then continue; fi
5444 ## FIXME ## Add here
5445 ## run_command "tagtrack-$OUTPUT-$1" $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
5446 # Set TRACKNUM, TRACKNAME
5447 if [ -e "$CDDBDATA" ]; then
5448 if [ "$ONETRACK" = "y" ]; then
5450 TRACKNUM="$FIRSTTRACK"
5453 TRACKNUM="$UTRACKNUM"
5454 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
5455 getcddbinfo TRACKNAME
5459 # You can't encode a file which needs to be normalized before finishing
5460 # You can't tag a file before it's finished encoding -
5461 # thus all of this is backgrounded together
5463 if [ "$DONORMALIZE" = "y" ]; then
5464 if checkstatus "readtrack-$UTRACKNUM"; then
5465 if checkstatus "normalizetrack-$UTRACKNUM"; then :; else do_normalize "$UTRACKNUM"; fi
5468 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ]; then
5469 if checkstatus "readtrack-$UTRACKNUM"; then
5470 if [ "$DONORMALIZE" = "y" ]; then
5471 if checkstatus "normalizetrack-$UTRACKNUM"; then
5472 if checkstatus "encodetrack-$UTRACKNUM"; then :; else do_encode "$UTRACKNUM" "$LOCATION" "$OUTPUT"; fi
5475 if checkstatus "encodetrack-$UTRACKNUM"; then :; else do_encode "$UTRACKNUM" "$LOCATION" "$OUTPUT"; fi
5479 if [ "$DOTAG" = "y" ]; then
5480 if checkstatus "encodetrack-$UTRACKNUM"; then
5481 if checkstatus "tagtrack-$UTRACKNUM"; then :; else do_tag "$UTRACKNUM"; fi
5483 # Lets tag the cue file
5484 if checkstatus cleancuefile >/dev/null; then :; else
5485 if checkstatus cuefile >/dev/null ; then
5490 if [ "$DOMOVE" = "y" ]; then
5491 if checkstatus "tagtrack-$UTRACKNUM"; then
5492 if checkstatus "movetrack-$UTRACKNUM"; then :; else do_move "$UTRACKNUM"; fi
5499 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5500 # we'll delete the files they're working on
5501 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5502 ## FIXME ## Check also for files which are encoded using PIPEs.
5503 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5508 for LOCATION in $ENCODELOCATIONS
5510 CHECKTRACK="$(checkstatus "encodetracklocation-$LOCATION")"
5511 # "How can he give us a status update, if he's DEAD?"
5512 if checkstatus "encodetrack-$CHECKTRACK"; then
5515 # Nothing to see here please go quietly back to your homes
5516 if [ -z "$CHECKTRACK" ]; then continue; fi
5517 # You're still here? Maybe there is something...
5518 if checkstatus "encodetrack-$CHECKTRACK"; then :; else PROCEED= ; break; fi
5521 if [ ! $PROCEED ]; then sleep 5; fi
5524 # If the above didn't catch the stragglers, this will
5526 if [ "$DOREPLAYGAIN" = "y" ]; then
5530 if [ "$EMBEDALBUMART" = "y" ]; then
5534 # Execute the user-defined post_encode function before cleaning up
5537 # Check to see if run_command logged any errors
5538 if [ -f "${ABCDETEMPDIR}/errors" ]; then
5539 log error "The following commands failed to run:"
5540 cat "${ABCDETEMPDIR}/errors"
5544 if [ "$KEEPWAVS" = "y" ];then
5548 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5549 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5550 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5551 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5552 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5553 log warning "The encoded formats does not match with the moved ones"
5554 log warning "Formats encoded: $( echo "$ENCODED_FORMATS" | tr "|" " " )"
5555 log warning "Formats moved: $( echo "$MOVED_FORMATS" | tr "|" " " )"
5556 log warning "Use \"abcde -a clean -f -C ${CDDBDISCID}\" to force the removal of the remaining data."
5560 if [ "$DOCLEAN" = "y" ]; then
5561 # Wipe all the evidence
5562 # Gimme gimme gimme some more time!
5564 rm -rf "${ABCDETEMPDIR}"
5567 echo "Finished. Not cleaning ${ABCDETEMPDIR}."