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 REALTRACKNUM=$(expr $UTRACKNUM + 0) # Unpad
467 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $((${REALTRACKNUM} + ${STARTTRACKNUMBER} - ${FIRSTTRACK})))
469 TRACKNUM=${UTRACKNUM}
475 # Calculate cddb disc ids without requiring specialized helper programs.
476 # largely copied from cd-discid and musicbrainz examples. some of the steps
477 # don't make sense, but they're necessary to match the ids generated by other
480 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
481 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
482 # 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
483 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
484 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
485 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
487 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
490 if [ X"$LEADOUT" = "X" ]; then
491 log warning "Error trying to calculate disc ids without lead-out information."
495 # default to a two second lead-in
497 LEADIN=${LEADIN:=150}
499 # number of cdframes per second
502 # reset cddb checksum for cddb disc-id calululation
506 for OFFSET in $OFFSETS
508 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
510 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
511 while [ $OFFSETTIME -gt 0 ]; do
512 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
513 OFFSETTIME=$(($OFFSETTIME / 10))
518 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
520 PREGAP=$(echo $OFFSETS | cut -f1 -d' ')
521 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
523 vvecho "makeids: PREGAP $PREGAP, LEADIN $LEADIN, LEADOUT $LEADOUT"
525 # Calculate both the cddb discid *and* the musicbrainz discid
526 # now. We'll use the cddb discid for reference in most cases
527 # for consistency, but we also have the musicbrainz discid for
529 printf -v CDDBDISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
530 CDDBTRACKINFO="${CDDBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
534 # FIXME: don't assume the first track is 1
535 MBDISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $(($PREGAP + $LEADOUT)) $OFFSETS)
537 if [ $error != 0 ]; then
538 log error "$MUSICBRAINZ failed to run; ABORT"
541 MBTRACKINFO="${MBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
548 if checkstatus replaygain; then :; else
549 run_command "" echo "Adding replaygain information..."
550 for TMPOUTPUT in $( echo "$OUTPUTTYPE" | tr , \ )
554 OUTPUT=$OGGOUTPUTCONTAINER
557 OUTPUT=$OPUSOUTPUTCONTAINER
560 OUTPUT=$FLACOUTPUTCONTAINER
568 for UTRACKNUM in $TRACKQUEUE
570 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
571 getcddbinfo TRACKNAME
573 TRACKFILE="$(mungetrackname "$TRACKNAME")"
574 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
575 ALBUMFILE="$(mungealbumname "$DALBUM")"
576 GENRE="$(mungegenre "$GENRE")"
577 YEAR=${CDYEAR:-$CDYEAR}
579 if [ "$ONETRACK" = "y" ]; then
580 if [ "$VARIOUSARTISTS" = "y" ]; then
581 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
583 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
586 if [ "$VARIOUSARTISTS" = "y" ]; then
587 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
589 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
592 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
593 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
597 run_command "replaygain-flac" nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
600 run_command "replaygain-vorbis" nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
603 run_command "replaygain-mp3" nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
606 run_command "replaygain-mpc" nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
609 run_command "replaygain-wv" nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
614 if checkerrors "replaygain-.{3,6}"; then :; else
615 run_command "replaygain" true
620 # This code splits the a Various Artist track name from one of the following
623 # forward: Artist / Track
624 # forward-dash: Artist - Track
625 # reverse: Track / Artist
626 # reverse-dash: Track - Artist
627 # colon: Artist: Track
628 # trailing-paren: Artist (Track)
631 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
634 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
635 case "$VARIOUSARTISTSTYLE" in
637 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
638 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
639 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
642 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
643 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
644 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
647 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
648 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
649 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
652 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
653 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
654 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
657 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
658 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
659 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
662 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
663 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
664 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
667 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
668 TRACKARTIST="Various"
670 TRACKARTIST="$DARTIST"
675 local genre=$(echo "${@}" | tr 'A-Z' 'a-z')
679 "classic rock") id=1 ;;
697 "industrial") id=19 ;;
698 "alternative") id=20 ;;
700 "death metal") id=22 ;;
702 "soundtrack") id=24 ;;
703 "euro-techno") id=25 ;;
707 "jazz+funk") id=29 ;;
710 "classical") id=32 ;;
711 "instrumental") id=33 ;;
715 "sound clip") id=37 ;;
718 "alt. rock") id=40 ;;
723 "meditative") id=45 ;;
724 "instrum. pop") id=46 ;;
725 "instrum. rock") id=47 ;;
729 "techno-indust.") id=51 ;;
730 "electronic") id=52 ;;
732 "eurodance") id=54 ;;
734 "southern rock") id=56 ;;
739 "christian rap") id=61 ;;
740 "pop/funk"|"pop / funk") id=62 ;;
742 "native american") id=64 ;;
745 "psychadelic") id=67 ;;
747 "showtunes") id=69 ;;
751 "acid punk") id=73 ;;
752 "acid jazz") id=74 ;;
756 "rock & roll") id=78 ;;
757 "hard rock") id=79 ;;
759 "folk/rock") id=81 ;;
760 "national folk") id=82 ;;
767 "bluegrass") id=89 ;;
768 "avantgarde") id=90 ;;
769 "gothic rock") id=91 ;;
770 "progress. rock") id=92 ;;
771 "psychadel. rock") id=93 ;;
772 "symphonic rock") id=94 ;;
773 "slow rock") id=95 ;;
776 "easy listening") id=98 ;;
782 "chamber music") id=104 ;;
784 "symphony") id=106 ;;
785 "booty bass") id=107 ;;
787 "porn groove") id=109 ;;
789 "slow jam") id=111 ;;
793 "folklore") id=115 ;;
795 "power ballad") id=117 ;;
796 "rhythmic soul") id=118 ;;
797 "freestyle") id=119 ;;
799 "punk rock") id=121 ;;
800 "drum solo") id=122 ;;
801 "a capella") id=123 ;;
802 "euro-house") id=124 ;;
803 "dance hall") id=125 ;;
805 "drum & bass") id=127 ;;
806 "club-house") id=128 ;;
807 "hardcore") id=129 ;;
811 "negerpunk") id=133 ;;
812 "polsk punk") id=134 ;;
814 "christian gangsta rap") id=136 ;;
815 "heavy metal") id=137 ;;
816 "black metal") id=138 ;;
817 "crossover") id=139 ;;
818 "contemporary christian")id=140 ;;
819 "christian rock") id=141 ;;
820 "merengue") id=142 ;;
822 "thrash metal") id=144 ;;
825 "synthpop") id=147 ;;
826 "rock/pop"|"rock / pop") id=148 ;;
833 # do_tag [tracknumber]
834 # id3 tags a filename
836 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
837 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
840 COMMENTOUTPUT="$(eval echo "${COMMENT}")"
841 if [ -z "$COMMENTOUTPUT" ]; then
842 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
844 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
845 run_command "" echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
846 # If we want to start the tracks with a given number, we need to modify the
847 # TRACKNUM value before evaluation
848 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
851 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
855 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
856 GENREID=$(do_getgenreid "${CDGENRE}")
857 # Set TPE2 in case we have a Various Artists rip.
859 if [ "$VARIOUSARTISTS" = "y" ]; then
865 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
866 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
867 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
868 -y "$CDYEAR" -g "$GENREID" \
869 -T "${TRACKNUM:-$1}" \
870 "${ABCDETEMPDIR}/track$1.$OUTPUT"
873 # FIXME # track numbers in mp3 come with 1/10, so we cannot
874 # happily substitute them with $TRACKNUM
875 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
876 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
877 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
878 -y "$CDYEAR" -g "$GENREID" \
879 -T "${TRACKNUM:-$1}/$TRACKS" \
880 ${TPE2:+--TPE2 "$TPE2"} \
881 "${ABCDETEMPDIR}/track$1.$OUTPUT"
884 # FIXME # track numbers in mp3 come with 1/10, so we cannot
885 # happily substitute them with $TRACKNUM
886 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
887 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
888 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
889 -y "$CDYEAR" -g "$GENREID" \
890 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
891 "${ABCDETEMPDIR}/track$1.$OUTPUT"
894 # FIXME # track numbers in mp3 come with 1/10, so we cannot
895 # happily substitute them with $TRACKNUM
897 eyed3_06) addopts=( \
898 ${ENCODING:+--set-encoding="$ENCODING"} \
899 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
900 # We set 'recording-date' so the date tag will show
901 # in Audacious, vlc and friends... Andrew.
902 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
903 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
906 ${ENCODING:+--encoding="$ENCODING"} \
907 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
908 # We set 'recording-date' so the date tag will show
909 # in Audacious, vlc and friends... Andrew.
910 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
911 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
914 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $TAGGER $TAGGEROPTS \
916 -a "$TRACKARTIST" -t "$TRACKNAME" \
917 -G "$GENREID" -n "${TRACKNUM:-$1}" \
918 ${TRACKNUM:+-N "$TRACKS"} \
920 "${ABCDETEMPDIR}/track$1.$OUTPUT"
923 log error "Internal error: ID3SYNTAX has an illegal value"
929 case "$OGGENCODERSYNTAX" in
931 # vorbiscomment can't do in-place modification, mv the file first
932 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ] && \
933 [ ! -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
934 mv "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" \
935 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
939 # https://www.xiph.org/vorbis/doc/v-comment.html
941 echo ARTIST="$TRACKARTIST"
943 echo TITLE="$TRACKNAME"
944 if [ -n "$CDYEAR" ]; then
947 if [ -n "$CDGENRE" ]; then
948 echo GENRE="$CDGENRE"
950 echo TRACKNUMBER="${TRACKNUM:-$1}"
951 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
952 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
953 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
954 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
955 echo TRACKTOTAL="${TRACKS}"
956 if [ -n "$DISCNUMBER" ]; then
957 echo DISCNUMBER="$DISCNUMBER"
959 echo CDDB="${CDDBDISCID}"
960 if [ "$(eval echo ${COMMENT})" != "" ]; then
961 case "$COMMENTOUTPUT" in
962 *=*) echo "$COMMENTOUTPUT";;
963 *) echo COMMENT="$COMMENTOUTPUT";;
966 ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
967 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
968 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
969 "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
970 # Doublecheck that the commented file was created
971 # successfully before wiping the original
972 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ]; then
973 rm -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
975 mv "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
976 "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
982 run_command "tagtrack-$OUTPUT-$1" true
985 run_command "tagtrack-$OUTPUT-$1" true
988 run_command "tagtrack-$OUTPUT-$1" true
992 echo ARTIST="$TRACKARTIST"
994 echo TITLE="$TRACKNAME"
995 if [ -n "$CDYEAR" ]; then
998 if [ -n "$CDGENRE" ]; then
999 echo GENRE="$CDGENRE"
1001 echo TRACKNUMBER="${TRACKNUM:-$1}"
1002 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
1003 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
1004 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
1005 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
1006 echo TRACKTOTAL="${TRACKS}"
1007 if [ -n "$DISCNUMBER" ]; then
1008 echo DISCNUMBER="$DISCNUMBER"
1010 echo CDDB="${CDDBDISCID}"
1011 if [ -n "$(eval echo "${COMMENT}")" ]; then
1012 case "$COMMENTOUTPUT" in
1013 *=*) echo "$COMMENTOUTPUT";;
1014 *) echo COMMENT="$COMMENTOUTPUT";;
1017 ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $METAFLAC $METAFLACOPTS \
1018 ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} \
1019 --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
1022 run_command "tagtrack-$OUTPUT-$1" true
1025 run_command "tagtrack-$OUTPUT-$1" true
1028 run_command "tagtrack-$OUTPUT-$1" true
1031 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
1032 # Console port (mac) used for encoding does not have the ability to tag.
1033 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$APETAG" -i "${ABCDETEMPDIR}/track$1.ape" -m overwrite \
1034 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track="${TRACKNUM:-$1}" \
1035 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
1038 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
1039 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
1040 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
1041 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
1042 -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
1043 -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
1044 ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1045 "${ABCDETEMPDIR}/track$1.mp2"
1048 run_command "tagtrack-$OUTPUT-$1" true
1051 case "$AACENCODERSYNTAX" in
1053 # We will use inline tagging...
1054 run_command "tagtrack-$OUTPUT-$1" true
1057 # Tag post encode with neroAacTag...
1058 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$NEROAACTAG" \
1059 "${ABCDETEMPDIR}/track$1.m4a" \
1060 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" \
1061 -meta:title="$TRACKNAME" -meta:track="${TRACKNUM:-$1}" \
1062 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1065 run_command "tagtrack-$OUTPUT-$1" true
1068 run_command "tagtrack-$OUTPUT-$1" true
1071 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1072 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1073 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$ATOMICPARSLEY" \
1074 "${ABCDETEMPDIR}/track$1.m4a" --artist="$TRACKARTIST" --album="$DALBUM" \
1075 --title="$TRACKNAME" --tracknum="${TRACKNUM:-$1}" \
1076 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" \
1077 $ATOMICPARSLEYOPTS --overWrite
1080 run_command "tagtrack-$OUTPUT-$1" true
1085 # We use mid3v2 tagging for True Audio:
1086 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
1087 -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
1088 -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
1089 ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} "${ABCDETEMPDIR}/track$1.tta"
1092 run_command "tagtrack-$OUTPUT-$1" true
1096 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1097 run_command "tagtrack-$1" true
1103 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1106 # The commands here don't go through run_command because they're never
1107 # supposed to be silenced
1108 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1109 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1113 case "$MP3ENCODERSYNTAX" in
1116 cd "${ABCDETEMPDIR}"
1118 for THISTRACKNUM in $TRACKQUEUE
1120 TRACKFILES="$TRACKFILES track$THISTRACKNUM.wav"
1122 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1124 if [ "$RETURN" != "0" ]; then
1125 echo "nogap-encode: $MP3ENCODER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1127 for THISTRACKNUM in $TRACKQUEUE
1129 run_command "encodetrack-$OUTPUT-$THISTRACKNUM" true
1138 if checkerrors "nogap-encode"; then :; else
1139 if [ ! "$KEEPWAVS" = "y" ] ; then
1140 if [ ! "$KEEPWAVS" = "move" ] ; then
1145 # Other encoders fall through to normal encoding as the tracks have not
1146 # been entered in the status file.
1149 # do_encode [tracknumber] [hostname]
1150 # If no hostname is specified, encode locally
1152 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1153 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1156 if [ "$USEPIPES" = "y" ]; then
1159 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1162 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1165 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1168 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1171 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1174 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1177 TEMPARG="PIPE_$SPEEXENCODER"
1180 TEMPARG="PIPE_$MPCENCODER"
1183 TEMPARG="PIPE_$WVENCODERSYNTAX"
1186 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1189 TEMPARG="PIPE_$AACENCODERSYNTAX"
1192 TEMPARG="PIPE_$AACENCODERSYNTAX"
1195 IN="$( eval echo "\$$TEMPARG" )"
1197 IN="${ABCDETEMPDIR}/track$1.wav"
1199 # We need IN to proceed, if we are not using pipes.
1200 if [ -s "$IN" ] || [ X"$USEPIPES" = "Xy" ] ; then
1201 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1203 case "$TMPOUTPUT" in
1205 OUTPUT=$OGGOUTPUTCONTAINER
1208 OUTPUT=$OPUSOUTPUTCONTAINER
1211 OUTPUT=$MKAOUTPUTCONTAINER
1214 OUTPUT=$AIFFOUTPUTCONTAINER
1217 OUTPUT=$FLACOUTPUTCONTAINER
1223 OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1224 if [ "$NOGAP" = "y" ] && checkstatus "encodetrack-$OUTPUT-$1" ; then
1227 if [ X"$USEPIPES" = "Xy" ]; then
1229 # We need a way to store the creation of the files when using PIPES
1230 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1231 # When piping it does not make sense to have a higher nice for
1232 # reading than for encoding, since it will be hold by the
1233 # encoding process. Setting an effective nice, to calm down a
1234 # bit the reading process.
1235 EFFECTIVE_NICE=$READNICE
1237 run_command "" echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1238 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1239 EFFECTIVE_NICE=$ENCNICE
1245 case "$MP3ENCODERSYNTAX" in
1246 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1247 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1248 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1249 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1253 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1260 case "$OGGENCODERSYNTAX" in
1261 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1262 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1266 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1273 case "$OPUSENCODERSYNTAX" in
1275 # Tag the file at encode time, as it can't be done after encoding.
1276 if [ "$DOTAG" = "y" ]; then
1277 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS \
1278 --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
1279 --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1280 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1282 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1288 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1293 case "$MKAENCODERSYNTAX" in
1295 if [ "$DOTAG" = "y" ]; then
1296 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS \
1297 -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
1298 -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
1299 -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
1300 -metadata comment="$COMMENT" "$OUT"
1302 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1308 case "$AIFFENCODERSYNTAX" in
1310 if [ "$DOTAG" = "y" ]; then
1311 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS \
1312 -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
1313 -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
1314 -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
1315 -metadata comment="$COMMENT" "$OUT"
1317 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1325 case "$FLACENCODERSYNTAX" in
1326 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1331 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1332 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1337 if [ -n "$(eval echo "${COMMENT}")" ]; then
1340 *) COMMENT="COMMENT=$COMMENT" ;;
1343 # Tag the file at encode time, as it can't be done after encoding.
1344 if [ "$DOTAG" = "y" ]; then
1345 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS \
1346 --author "$TRACKARTIST" --title "$TRACKNAME" \
1347 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1349 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1353 # Tag the file inline at encode time.
1354 if [ "$DOTAG" = "y" ]; then
1355 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS \
1356 --artist "$TRACKARTIST" --album "$DALBUM" \
1357 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
1358 --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1360 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1364 case "$TTAENCODERSYNTAX" in
1365 # tta is the newer version with a small syntax change...
1367 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1370 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1375 case "$WVENCODERSYNTAX" in
1377 if [ "$DOTAG" = "y" ]; then
1378 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS \
1379 -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1380 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" \
1381 -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1383 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1387 if [ "$DOTAG" = "y" ]; then
1388 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS \
1389 -metadata artist="$TRACKARTIST" \
1390 -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
1391 -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
1392 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1394 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1400 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1403 case "$MP2ENCODERSYNTAX" in
1405 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1408 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1413 # aac container is only used to catch faac encoded files where faac
1414 # is compiled without mp4 support (with libmp4v2).
1415 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1418 case "$AACENCODERSYNTAX" in
1420 if [ "$DOTAG" = "y" ]; then
1421 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
1422 --artist "$TRACKARTIST" --album "$DALBUM" \
1423 --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
1424 --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1426 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1430 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1433 if [ "$DOTAG" = "y" ]; then
1434 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
1435 --artist "$TRACKARTIST" --album "$DALBUM" \
1436 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
1437 --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1439 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1443 if [ "$DOTAG" = "y" ]; then
1444 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS \
1445 --artist "$TRACKARTIST" --album "$DALBUM" \
1446 --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
1447 --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1449 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1453 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1456 if [ "$DOTAG" = "y" ]; then
1457 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" \
1458 $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1459 -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
1460 -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
1461 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1463 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1469 # In case of wav output we need nothing. Just keep the wavs.
1470 # But we need the following to allow full logging and subsequent
1471 # successful cleaning of ${ABCDETEMPDIR}.
1472 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1477 # Only remove .wav if the encoding succeeded
1478 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1479 run_command "encodetrack-$1" true
1480 if [ ! "$KEEPWAVS" = "y" ] ; then
1481 if [ ! "$KEEPWAVS" = "move" ] ; then
1487 run_command "" echo "HEH! The file we were about to encode disappeared:"
1488 run_command "" echo ">> $IN"
1489 run_command "encodetrack-$1" false
1493 # do_preprocess [tracknumber]
1495 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX,
1496 # OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1499 # IN="${ABCDETEMPDIR}/track$1.wav"
1500 # # We need IN to proceed.
1501 # if [ -s "$IN" ] ; then
1502 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1504 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1505 # run_command "" echo "Pre-processing track $1 of $TRACKS..."
1506 # case "$POSTPROCESSFORMAT" in
1508 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $WAV_PRE $IF $OF ;;
1510 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $MP3_PRE $IF $OF ;;
1512 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $OGG_PRE $IF $OF ;;
1514 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $FLAC_PRE $IF $OF ;;
1516 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $SPX_PRE $IF $OF ;;
1519 # # Only remove .wav if the encoding succeeded
1520 # if checkerrors "preprocess-(.{3,4})-$1"; then
1521 # run_command "preprocess-$1" false
1523 # run_command "preprocess-$1" true
1526 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1527 # echo "HEH! The file we were about to pre-process disappeared:"
1530 # run_command "preprocess-$1" false
1535 # do_postprocess [tracknumber]
1537 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1538 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1541 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1543 # IN="${ABCDETEMPDIR}/track$1.$POSTPROCESSFORMAT"
1544 # # We need IN to proceed.
1545 # if [ -s "$IN" ] ; then
1546 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1547 # run_command "" echo "Post-processing track $1 of $TRACKS..."
1548 # case "$POSTPROCESSFORMAT" in
1550 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $MP3_POST $IF $OF ;;
1552 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $OGG_POST $IF $OF ;;
1554 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $FLAC_POST $IF $OF ;;
1556 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $SPX_POST $IF $OF ;;
1558 # # Only remove .wav if the encoding succeeded
1559 # if checkerrors "postprocess-(.{3,4})-$1"; then
1560 # run_command "postprocess-$1" false
1562 # run_command "postprocess-$1" true
1565 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1566 # echo "HEH! The file we were about to post-process disappeared:"
1569 # run_command "postprocess-$1" false
1584 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1588 # The commands here don't go through run_command because they're never supposed to be silenced
1589 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1591 cd "${ABCDETEMPDIR}"
1594 for UTRACKNUM in $TRACKQUEUE
1596 TRACKFILES="$TRACKFILES track$UTRACKNUM.mp3"
1598 # FIXME # Hard-coded batch option!
1599 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1601 if [ "$RETURN" != "0" ]; then
1602 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1604 for UTRACKNUM in $TRACKQUEUE
1606 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1612 # do_batch_normalize
1614 # NORMALIZER, NORMALIZEROPTS
1615 do_batch_normalize ()
1617 # The commands here don't go through run_command because they're never supposed to be silenced
1618 echo "Batch normalizing tracks: $TRACKQUEUE"
1620 cd "${ABCDETEMPDIR}"
1623 for UTRACKNUM in $TRACKQUEUE
1625 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1627 # XXX: Hard-coded batch option!
1628 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1630 if [ "$RETURN" != "0" ]; then
1631 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1633 for UTRACKNUM in $TRACKQUEUE
1635 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1641 # do_normalize [tracknumber]
1643 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1646 IN="${ABCDETEMPDIR}/track$1.wav"
1647 if [ -e "$IN" ] ; then
1648 run_command "" echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1649 run_command "normalizetrack-$1" $NORMALIZER $NORMALIZEROPTS "$IN"
1651 if [ "$(checkstatus encode-output)" = "loud" ]; then
1652 echo "HEH! The file we were about to normalize disappeared:"
1655 run_command "normalizetrack-$1" false "File $IN was not found"
1659 # do_move [tracknumber]
1660 # Deduces the outfile from environment variables
1661 # Creates directory if necessary
1663 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1666 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1668 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1669 # defined the OUTPUTFILE:
1672 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1673 ALBUMFILE="$(mungealbumname "$DALBUM")"
1674 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1675 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1676 GENRE="$(mungegenre "$GENRE")"
1677 YEAR=${CDYEAR:-$CDYEAR}
1678 # If we want to start the tracks with a given number, we need to modify
1679 # the TRACKNUM value before evaluation
1681 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1682 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1683 if [ "$ONETRACK" = "y" ]; then
1684 if [ "$VARIOUSARTISTS" = "y" ]; then
1685 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1687 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1690 if [ "$VARIOUSARTISTS" = "y" ]; then
1691 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1693 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1696 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1697 # Once we know the specific output was successful, we can change
1698 # the OUTPUT to the value containing the container
1701 OUTPUT=$OGGOUTPUTCONTAINER
1704 OUTPUT=$OPUSOUTPUTCONTAINER
1707 OUTPUT=$MKAOUTPUTCONTAINER
1710 OUTPUT=$AIFFOUTPUTCONTAINER
1713 OUTPUT=$FLACOUTPUTCONTAINER
1719 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1720 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1723 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1724 # FIXME # introduce warnings?
1727 # mkdir -p shouldn't return an error if the directory already exists
1728 mkdir -p "$OUTPUTFILEDIR"
1729 run_command "movetrack-$1" mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1730 if checkstatus "movetrack-output-$OUTPUT"; then :; else
1731 run_command "movetrack-output-$OUTPUT" true
1736 # mkdir -p shouldn't return an error if the directory already exists
1737 mkdir -p "$OUTPUTFILEDIR"
1738 run_command "movetrack-$1" mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1739 if checkstatus "movetrack-output-$OUTPUT"; then :; else
1740 run_command "movetrack-output-$OUTPUT" true
1744 # Lets move the cue file
1745 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1746 if [ -r "${ABCDETEMPDIR}/$CUEFILE" ]; then
1747 if checkstatus "movecue-$OUTPUT"; then :; else
1748 # Silence the Copying output since it overlaps with encoding processes...
1749 #run_command "" vecho "Copying cue file to its destination directory..."
1750 if checkstatus onetrack >/dev/null ; then
1753 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1754 # We dont have the dir, since it was not created before.
1757 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1760 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1761 # http://brianvictor.tripod.com/mp3cue.htm#details
1762 [a-z0-9][a-z0-9][a-z0-9])
1763 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1766 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1770 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1772 echo "movecue-$OUTPUT" >> "${ABCDETEMPDIR}/status"
1781 # Create the playlist if wanted
1783 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1784 # VARIOUSARTISTS, OUTPUTDIR
1787 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1791 OUTPUT=$OGGOUTPUTCONTAINER
1794 OUTPUT=$OPUSOUTPUTCONTAINER
1797 OUTPUT=$MKAOUTPUTCONTAINER
1800 OUTPUT=$AIFFOUTPUTCONTAINER
1803 OUTPUT=$FLACOUTPUTCONTAINER
1809 # Create a playlist file for the playlist data to go into.
1810 # We used to wipe it out if it existed. Now we request permission if interactive.
1811 for LASTTRACK in $TRACKQUEUE; do :; done
1812 ALBUMFILE="$(mungealbumname "$DALBUM")"
1813 ARTISTFILE="$(mungeartistname "$DARTIST")"
1814 GENRE="$(mungegenre "$GENRE")"
1815 YEAR=${CDYEAR:-$CDYEAR}
1816 if [ "$VARIOUSARTISTS" = "y" ] ; then
1817 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1819 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1821 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1822 mkdir -p "$FINALPLAYLISTDIR"
1823 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1824 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1825 if [ "$INTERACTIVE" = "y" ]; then
1826 while [ "$DONE" != "y" ]; do
1828 case $ERASEPLAYLIST in
1829 e|E|a|A|k|K) DONE=y ;;
1830 "") ERASEPLAYLIST=e ; DONE=y ;;
1838 # Once we erase the playlist, we use append to create the new one.
1839 [ "$ERASEPLAYLIST" = "e" ] || [ "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1841 # The playlist does not exist, so we can safelly use append to create the new list
1844 if [ "$ERASEPLAYLIST" = "a" ] || [ "$ERASEPLAYLIST" = "A" ]; then
1845 touch "$OUTPUTDIR/$PLAYLISTFILE"
1846 for UTRACKNUM in $TRACKQUEUE
1848 # Shares some code with do_move since the filenames have to match
1849 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
1850 getcddbinfo TRACKNAME
1852 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1853 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1854 ALBUMFILE="$(mungealbumname "$DALBUM")"
1855 # If we want to start the tracks with a given number, we need to modify the
1856 # TRACKNUM value before evaluation
1858 if [ "$VARIOUSARTISTS" = "y" ]; then
1859 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1861 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1863 if [ "$VARIOUSARTISTS" = "y" ]; then
1864 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1865 echo "${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1867 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1870 if [ "$PLAYLISTDATAPREFIX" ]; then
1871 echo "${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1873 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1878 ## this will convert the playlist to have CRLF line-endings, if specified
1879 ## (some hardware players insist on CRLF endings)
1880 if [ "$DOSPLAYLIST" = "y" ]; then
1881 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "${ABCDETEMPDIR}/PLAYLISTFILE.tmp"
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
1932 if [ "$2" -eq 1 ] ; then
1934 START=$(( $LBA + $PREGAP + $OFFSET ))
1936 X=$(cddb_sum $(( $START / 75 )) )
1941 PREGAP=$(msf2lba $2)
1946 LEADOUT=$(( $4 / 588 ))
1949 LEADIN=$(( $3 / 588 ))
1958 LEADOUT=$(( $LEADOUT + $LEADIN ))
1960 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1961 CDDBDISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1962 printf %08x %i ${CDDBDISCID} $TRACKS
1965 while [ $j -le $TRACKS ] ; do
1966 eval echo -n "\" \$TRACK$j\""
1969 echo $(( $LEADOUT / 75 ))
1973 # abcde.mkcue [--wholedisk]
1974 # This creates a cuefile directly from the extended discid information
1975 # The --wholedisk option controls whether we're ripping data from the
1976 # start of track one or from the start of the disk (usually, but not
1977 # always the same thing!)
1979 # Track one leadin/pregap (if any) handeling:
1980 # --wholedisk specified:
1983 # INDEX 01 <pregap value>
1984 # Remaining track index values unchanged from disc TOC
1986 # --wholedisk not specified
1988 # PREGAP <pregap value>
1990 # Remaining track index values offset by <pregap value>
1997 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
2000 local MODE DISCID TRACKS
2004 if [ "$1" = "--wholedisk" ] ; then
2010 vecho "One track is $ONETRACK"
2011 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2012 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2013 ALBUMFILE="$(mungealbumname "$DALBUM")"
2014 if [ "$ONETRACK" = "y" ]; then
2015 if [ "$VARIOUSARTISTS" = "y" ]; then
2016 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2018 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2020 vecho "Cue wav file is $CUEWAVFILE"
2022 CUEWAVFILE="dummy.wav"
2025 set -- $CDDBTRACKINFO
2031 echo "REM DISCID $DISCID"
2032 echo FILE \""$CUEWAVFILE"\" WAVE
2034 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
2041 while [ $i -le "$TRACKS" ] ; do
2042 LBA=$(( $1 - $OFFSET ))
2043 printf " TRACK %02i AUDIO\n" $i
2044 if [ "$i" -eq 1 ] && [ "$1" -ne 150 ] ; then
2045 if [ "$MODE" = PREGAP ] ; then
2046 echomsf " PREGAP " $(($"OFFSET" - 150))
2048 echo " INDEX 00 00:00:00"
2051 echomsf " INDEX 01 " "$LBA"
2058 # This is essentially the start of things
2061 if [ -z "${CDDBDISCID}" ]; then
2062 vecho -n "Getting CD track info... "
2063 # In OSX, unmount the disc before a query
2064 if [ "$OSFLAVOUR" = "OSX" ]; then
2065 diskutil unmount "${CDROM#/dev/}"
2067 case "$CDROMREADERSYNTAX" in
2069 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
2070 case "$CUE2DISCID" in
2071 # FIXME # right now we have 2 cue2discid internal
2072 # implementations: builtin and abcde.cue2discid. Test
2073 # both of them and decide which one we want to use.
2075 #vecho "Using builtin cue2discid implementation..."
2076 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2078 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2080 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2081 TRACKS=${#OFFSETTIMES[@]}
2083 vecho "processing offsetimes ${OFFSETTIMES[@]}"
2084 for OFFSETTIME in ${OFFSETTIMES[@]}; do
2085 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2088 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2089 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2093 #vecho "Using external python cue2discid implementation..."
2094 CDDBTRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2098 log error "the input flac file does not contain a cuesheet."
2103 CDPARANOIAOUTPUT="$( $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -Q --verbose 2>&1 )"
2105 if [ ! "$RET" = "0" ];then
2106 log warning "something went wrong while querying the CD... Maybe a DATA CD or the CD is not loaded?"
2109 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2110 CDPARANOIAAUDIOTRACKS="$TRACKS"
2112 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2113 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2117 # Calculate the cddb discid in all
2118 # cases now. We'll use the cddb discid
2119 # for reference in most cases for
2120 # consistency. Also calculate the
2121 # musicbrainz discid if we need it.
2122 CDDBTRACKINFO=$($CDDISCID "$CDROM")
2123 if [ "$CDDISCID_NEEDS_PAUSE"x = "y"x ]; then
2126 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2127 case "$CDDBMETHOD" in
2129 MBTRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM")
2131 if [ $error != 0 ]; then
2132 log error "$MUSICBRAINZ failed to run; ABORT"
2135 MBDISCID=$(echo "$MBTRACKINFO" | cut -d' ' -f1)
2139 # Make sure there's a CD in there by checking cd-discid's return code
2140 if [ ! "$?" = "0" ]; then
2141 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2142 log error "cuesheet information from the flac file could not be read."
2143 log error "Perhaps the flac file does not contain a cuesheet?."
2146 log error "CD could not be read. Perhaps there's no CD in the drive?"
2150 # In OSX, remount the disc again
2151 if [ "$OSFLAVOUR" = "OSX" ]; then
2152 diskutil mount "${CDROM#/dev/}"
2155 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -f1 -d' ')
2157 CDDBTRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.${CDDBDISCID}/cddbdiscid")
2160 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2161 # This needs to be done now because a section of the resuming code will need
2164 # get the number of digits to pad TRACKNUM with - we'll use this later
2165 # a CD can only hold 99 tracks, but since we support a feature for starting
2166 # numbering the tracks from a given number, we might need to set it as a
2167 # variable for the user to define... or obtain it somehow.
2168 if [ "$PADTRACKS" = "y" ] ; then
2172 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.${CDDBDISCID}"
2173 if [ -z "$TRACKQUEUE" ]; then
2174 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2175 case "$CDROMREADERSYNTAX" in
2176 cdparanoia|libcdio|debug)
2177 if [ "$WEHAVEACD" = "y" ]; then
2178 vecho "Querying the CD for audio tracks..."
2179 CDPARANOIAOUTPUT="$( $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -Q --verbose 2>&1 )"
2181 if [ ! "$RET" = "0" ];then
2182 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2184 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2185 CDPARANOIAAUDIOTRACKS="$TRACKS"
2187 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2188 if [ -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks" ]; then
2189 echo "cdparanoia-audio-tracks=$( cat "${ABCDETEMPDIR}/cdparanoia-audio-tracks" )" >> "${ABCDETEMPDIR}/status"
2190 rm -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks"
2192 if [ -f "${ABCDETEMPDIR}/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2193 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2197 *) TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ') ;;
2200 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2202 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2203 log info "The disc does not contain any tracks. Giving up..."
2206 echo -n "Grabbing entire CD - tracks: "
2207 if [ ! "$PADTRACKS" = "y" ] ; then
2208 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2211 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2213 while [ $X -le $TRACKS ]
2215 PT=$(printf "%0.${TRACKNUMPADDING}d" $X)
2216 TRACKQUEUE="$TRACKQUEUE $PT"
2221 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2222 # User-supplied track queue.
2223 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2224 TRACKQUEUE=$(echo "$TRACKQUEUE" | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2225 # Once cleaned, obtain the highest value in the trackqueue for number padding
2226 for LASTTRACK in $TRACKQUEUE; do :; done
2227 if [ ! "$PADTRACKS" = "y" ] ; then
2228 TRACKNUMPADDING=$(echo -n "$LASTTRACK" | wc -c | tr -d ' ')
2230 # Now we normalize the trackqueue
2231 for TRACK in $TRACKQUEUE; do
2232 PADTRACKNUM=$(printf "%0.${TRACKNUMPADDING}d" $(expr ${TRACK} + 0 ))
2233 PADTRACKQUEUE="$PADTRACKQUEUE $PADTRACKNUM"
2235 TRACKQUEUE="$PADTRACKQUEUE"
2236 echo Grabbing tracks: "$TRACKQUEUE"
2239 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2241 # We have the discid, create a temp directory after it to store all the temp
2244 if [ -e "${ABCDETEMPDIR}" ]; then
2245 echo -n "abcde: attempting to resume from ${ABCDETEMPDIR}"
2246 # It already exists, see if it's a directory
2247 if [ ! -d "${ABCDETEMPDIR}" ]; then
2248 # This is a file/socket/fifo/device/etc, not a directory
2251 echo "abcde: file ${ABCDETEMPDIR} already exists and does not belong to abcde." >&2
2252 echo "Please investigate, remove it, and rerun abcde." >&2
2256 # It's a directory, let's see if it's writable by us
2257 if [ ! -r "${ABCDETEMPDIR}" ] || [ ! -w "${ABCDETEMPDIR}" ] || [ ! -x "${ABCDETEMPDIR}" ]; then
2258 # Nope, complain and exit
2260 echo "abcde: directory ${ABCDETEMPDIR} already exists and is not writeable." >&2
2261 echo "Please investigate, remove it, and rerun abcde." >&2
2265 # Check to see the version of abcde that was used. If it's not
2266 # the same version as we are, bail.
2267 RESUME_VERSION="$(checkstatus abcde-version)"
2268 if [ "$RESUME_VERSION" != "$VERSION" ]; then
2269 # Nope, complain and exit
2271 echo "abcde: Working directory ${ABCDETEMPDIR} was created using version $RESUME_VERSION." >&2
2272 echo "abcde: Current version is $VERSION." >&2
2273 echo "abcde: Refusing to resume with a version mismatch." >&2
2274 echo "Please remove it, and rerun abcde." >&2
2278 # See if it's populated
2279 if [ ! -f "${ABCDETEMPDIR}/cddbdiscid" ]; then
2280 # Wipe and start fresh
2281 echo "abcde: ${ABCDETEMPDIR}/cddbdiscid not found. Abcde must remove and recreate" >&2
2282 echo -n "this directory to continue. Continue [y/N]? " >&2
2283 if [ "$INTERACTIVE" = "y" ]; then
2289 if [ "$ANSWER" != "y" ]; then
2292 rm -rf "${ABCDETEMPDIR}" || exit 1
2293 mkdir -p "${ABCDETEMPDIR}"
2294 if [ "$?" -gt "0" ]; then
2295 # Directory already exists or could not be created
2296 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2300 # Everything is fine. Check for ^encodetracklocation-
2301 # and encode-output entries in the status file and
2302 # remove them. These are not relevant across sessions.
2303 echo "Resuming" >> "${ABCDETEMPDIR}/status"
2304 if [ -f "${ABCDETEMPDIR}/status" ]; then
2305 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
2306 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
2307 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
2309 # Remove old error messages
2310 if [ -f "${ABCDETEMPDIR}/errors" ]; then
2311 rm -f "${ABCDETEMPDIR}/errors"
2315 # We are starting from scratch
2316 mkdir -p "${ABCDETEMPDIR}"
2317 if [ "$?" -gt "0" ]; then
2318 # Directory already exists or could not be created
2319 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2322 cat /dev/null > "${ABCDETEMPDIR}/status"
2323 # Store the abcde version in the status file.
2324 echo "abcde-version=$VERSION" >> "${ABCDETEMPDIR}/status"
2326 if [ X"$DOCUE" = "Xy" ] && [ X"$WEHAVEACD" = "Xy" ]; then
2327 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2328 CUEFILE=cue-$(echo "$CDDBTRACKINFO" | cut -f1 -d' ').txt
2329 vecho "Creating cue file..."
2330 case "$CDROMREADERSYNTAX" in
2332 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "${ABCDETEMPDIR}/$CUEFILE"; then
2333 echo "cuefile=$CUEFILE" >> "${ABCDETEMPDIR}/status"
2335 log warning "the input flac file does not contain a cuesheet."
2339 if $CUEREADER $CUEREADEROPTS > "${ABCDETEMPDIR}/$CUEFILE"; then
2340 echo "cuefile=$CUEFILE" >> "${ABCDETEMPDIR}/status"
2342 log warning "reading the CUE sheet is still considered experimental"
2343 log warning "and there was a problem with the CD reading. abcde will continue,"
2344 log warning "but consider reporting the problem to the abcde authors"
2350 # If we got the CDPARANOIA status and it is not recorded, save it now
2351 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2352 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2353 echo "cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS" >> "${ABCDETEMPDIR}/status"
2357 # Create the discid files
2358 echo "$CDDBTRACKINFO" > "${ABCDETEMPDIR}/cddbdiscid"
2359 case "$CDDBMETHOD" in
2361 echo "$MBTRACKINFO" > "${ABCDETEMPDIR}/mbdiscid"
2367 # Create a proper CUE file based on the CUE file we created before.
2370 if CUEFILE_IN="${ABCDETEMPDIR}"/$(checkstatus cuefile); then
2371 CUEFILE_OUT=$CUEFILE_IN.out
2372 ### FIXME ### checkstatus cddb
2373 if [ -e "$CDDBDATA" ]; then
2374 vecho "Adding metadata to the cue file..."
2375 # FIXME It doesn't preserve spaces! Why?
2376 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2378 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2379 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2380 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2384 cat "$CUEFILE_IN" | while read line
2386 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2387 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2388 # echo "$line" >> "$CUEFILE_OUT"
2389 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2390 eval track="\$TRACK$n"
2392 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2393 # When making a single-track rip, put the
2394 # actual file name into the file declaration
2395 # in the cue file so that it is usable by
2396 # music players and the like
2397 elif [ "$ONETRACK" = "y" ] &&
2398 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2400 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2401 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2402 ALBUMFILE="$(mungealbumname "$DALBUM")"
2404 if [ "$VARIOUSARTISTS" = "y" ]; then
2405 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2407 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2410 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2413 # FIXME # If the lines above are uncommented, remove the line below.
2414 echo "$line" >> "$CUEFILE_OUT"
2417 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2418 echo "cleancuefile" >> "${ABCDETEMPDIR}/status"
2424 # Parses a CDDB file and outputs the title and the track names.
2425 # Variables: CDDBFILE
2429 # List out disc title/author and contents
2430 if [ "$ONETRACK" = "y" ]; then
2431 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2433 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2434 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2435 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2436 if [ ! X"$PARSEDYEAR" = "X" ]; then
2437 echo "Year: $PARSEDYEAR"
2440 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2441 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2442 if [ ! X"$PARSEDGENRE" = "X" ]; then
2443 echo "Genre: $PARSEDGENRE"
2446 if [ ! "$ONETRACK" = "y" ]; then
2447 for TRACK in $(f_seq_row 1 $TRACKS)
2449 echo "$TRACK": "$(grep -a ^TTITLE$(($TRACK - 1))= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2455 # Check for a local CDDB file, and report success
2456 do_localcddb_read ()
2458 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2460 CDDBLOCALSTATUS="notfound"
2461 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2464 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2465 CDDBLOCALRESULTS="$(find "${CDDBLOCALDIR}" -name "${CDDBDISCID}" -type f 2> /dev/null)"
2466 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2467 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2468 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2469 CDDBLOCALMATCH=single
2470 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2471 CDDBLOCALMATCH=multiple
2476 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2477 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2478 CDDBLOCALMATCH=single
2483 # If the user has selected to check a local CDDB repo, we proceed with it
2484 case $CDDBLOCALMATCH in
2486 echo "Processing multiple matching CDDB entries..." > "${ABCDETEMPDIR}/cddblocalchoices"
2488 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2490 # List out disc title/author and contents
2491 CDDBLOCALREAD="${ABCDETEMPDIR}/cddblocalread.$X"
2492 cat "$RESULT" > "${CDDBLOCALREAD}"
2495 do_cddbparse "${CDDBLOCALREAD}"
2497 ##FIXME## QUICK HACK !!!!
2498 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2499 } >> "${ABCDETEMPDIR}/cddblocalchoices"
2501 page "${ABCDETEMPDIR}/cddblocalchoices"
2502 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2503 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2504 CDDBLOCALCHOICENUM=-1
2505 if [ "$INTERACTIVE" = "y" ]; then
2506 while [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; do
2507 echo "Locally cached CDDB entries found." >&2
2508 echo -n "Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2509 read CDDBLOCALCHOICE
2510 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2511 # FIXME # Introduce diff's
2512 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2513 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2514 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2515 # Make sure we get a valid choice
2516 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2517 if [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; then
2518 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2523 CDDBLOCALCHOICENUM=1
2525 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2526 #echo "Using local copy of CDDB data"
2527 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2528 cat "${ABCDETEMPDIR}/cddblocalread.$CDDBLOCALCHOICENUM" >> "${ABCDETEMPDIR}/cddbread.1"
2529 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2530 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2531 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2532 do_cddbparse "${ABCDETEMPDIR}/cddbread.1" > "${ABCDETEMPDIR}/cddbchoices"
2533 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2534 CDDBLOCALSTATUS="found"
2536 #echo "Not using local copy of CDDB data"
2537 CDDBLOCALSTATUS="notfound"
2541 # List out disc title/author and contents
2542 do_cddbparse "${CDDBLOCALFILE}"
2543 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2544 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2546 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2548 if [ "$INTERACTIVE" = "y" ]; then
2550 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2551 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2554 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2558 if [ "$USELOCALRESP" = "y" ]; then
2559 #echo "Using local copy of CDDB data"
2560 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2561 cat "${CDDBLOCALFILE}" >> "${ABCDETEMPDIR}/cddbread.1"
2562 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2563 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2564 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2565 do_cddbparse "${CDDBLOCALFILE}" > "${ABCDETEMPDIR}/cddbchoices"
2566 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2567 CDDBLOCALSTATUS="single"
2569 #echo "Not using local copy of CDDB data"
2570 CDDBLOCALSTATUS="notfound"
2574 CDDBLOCALSTATUS="notfound"
2581 # Try to read CD-Text from the drive using icedax / cdda2wav
2584 if new_checkexec icedax; then
2585 CDTEXT_READER=icedax
2586 elif new_checkexec cdda2wav; then
2587 CDTEXT_READER=cdda2wav
2589 # Didn't find either, bail
2593 if checkstatus cdtext-readcomplete; then
2594 NUM_RESPONSES=$(checkstatus "cdtext-entries")
2595 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2596 vecho "Re-using existing data from CD-Text"
2598 vecho "Obtaining CD-Text results..."
2599 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cdtext"
2600 mkdir -p "${SOURCE_WORKDIR}"
2602 if [ "$OSFLAVOUR" = "OSX" ] ; then
2603 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2604 diskutil unmount "${CDROM#/dev/}"
2605 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2606 CDDA2WAVCDROM="IODVDServices"
2607 elif [ "$OSFLAVOUR" = "FBSD" ] || [ "$OSFLAVOUR" = "IRIX" ]; then
2608 CDDA2WAVCDROM="$CDROMID"
2610 if [ "$CDROMID" = "" ]; then
2611 CDDA2WAVCDROM="$CDROM"
2613 CDDA2WAVCDROM="$CDROMID"
2617 # Do we have CD-Text on the disc (and can the drive read it?)
2619 cd "${SOURCE_WORKDIR}" && rm -f audio.* audio_*
2620 ${CDTEXT_READER} -J -v titles -D "${CDDA2WAVCDROM}" > "${SOURCE_WORKDIR}/cd-text" 2>&1
2622 grep -a -q '^CD-Text: detected' "${SOURCE_WORKDIR}/cd-text"
2624 if [ $ERRORCODE -ne 0 ]; then
2625 # No CD-Text found, bail
2629 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2630 # Make an empty template
2631 $CDDBTOOL template "$(cat "${ABCDETEMPDIR}/cddbdiscid")" > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2632 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2633 rm -f "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2635 # XXX FIXME - this is a hack and should be replaced by proper
2636 # character set tracking for the CDDB data we have.
2637 if [ "$CDDBPROTO" -ge 6 ]; then
2638 # convert to Unicode
2639 iconv -f iso-8859-1 -t utf-8 <"${SOURCE_WORKDIR}/audio.cddb" >"${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2641 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2642 # apparently icedax/cdda2wav have no support for 16-bit
2643 # characters yet, either
2644 cp -p "${SOURCE_WORKDIR}/audio.cddb" "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2647 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2648 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2649 echo "CD-Text" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2650 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2653 cd "${SOURCE_WORKDIR}"
2654 rm -f audio_* audio.*
2655 for file in cddbread.* cddbquery.* datasource.*; do
2656 if [ -f "$file" ]; then
2657 cp "$file" "${ABCDETEMPDIR}"
2661 echo "cdtext-readcomplete" >> "${ABCDETEMPDIR}/status"
2662 echo "cdtext-entries=1" >> "${ABCDETEMPDIR}/status"
2666 # do_musicbrainz_read
2667 # Work with the musicbrainz WS API, then transform the results here so
2668 # they look (very) like the results from CDDB. Maybe not the best way
2669 # to go, but it Works For Me (TM)
2671 # List out all the matches individually into $SOURCE_WORKDIR/cddbread.X
2673 do_musicbrainz_read ()
2675 if checkstatus musicbrainz-readcomplete; then
2676 NUM_RESPONSES=$(checkstatus "musicbrainz-entries")
2677 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2678 vecho "Re-using existing data from $NUM_RESPONSES Musicbrainz match(es)"
2680 vecho "Obtaining Musicbrainz results..."
2681 # If MB is to be used, interpret the query results and read all
2682 # the available entries.
2683 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2684 MBDISCID=$(echo "$MBTRACKINFO" | cut -d' ' -f1)
2685 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-musicbrainz"
2686 mkdir -p "${SOURCE_WORKDIR}"
2687 ${MUSICBRAINZ} --command data --discid "${MBDISCID}" --workdir "${SOURCE_WORKDIR}" --start ${NUM_CDDB_MATCHES}
2689 if [ $error != 0 ]; then
2690 log error "$MUSICBRAINZ failed to run; ABORT"
2694 # Check for no matches.
2695 # The helper script will write disc matches out to
2696 # cddbread.*. Count how many we have
2697 NUM_RESPONSES=$(ls -1 "${SOURCE_WORKDIR}"/cddbread.* 2>/dev/null | wc -l)
2698 if [ $NUM_RESPONSES -gt 0 ] ; then
2699 # One or more exact matches
2701 while [ $i -le $NUM_RESPONSES ]; do
2702 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2704 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2705 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2706 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2707 echo "Musicbrainz" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2708 cp -f "${SOURCE_WORKDIR}/"*."${NUM_CDDB_MATCHES}" "${ABCDETEMPDIR}"
2711 echo "musicbrainz-readcomplete" >> "${ABCDETEMPDIR}/status"
2712 echo "musicbrainz-entries=$NUM_RESPONSES" >> "${ABCDETEMPDIR}/status"
2719 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cddb"
2720 mkdir -p "${SOURCE_WORKDIR}"
2726 # Perform CDDB protocol version check if it hasn't already been done
2727 if checkstatus cddb-statcomplete; then :; else
2728 if [ "$CDDBAVAIL" = "n" ]; then
2730 echo 503 > "${SOURCE_WORKDIR}/cddbstat"
2733 CDDBUSER=$(echo "$HELLOINFO" | cut -f1 -d'@')
2734 CDDBHOST=$(echo "$HELLOINFO" | cut -f2- -d'@')
2735 while [ $rc -eq 1 ] && [ "$CDDBPROTO" -ge 3 ]; do
2736 vecho "Checking CDDB server status..."
2737 $CDDBTOOL stat "$CDDBURL" "$CDDBUSER" "$CDDBHOST" "$CDDBPROTO" > "${SOURCE_WORKDIR}/cddbstat"
2738 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2739 case "$RESPONSECODE" in
2740 210) # 210 OK, status information follows (until terminating `.')
2743 501) # 501 Illegal CDDB protocol level: <n>.
2744 CDDBPROTO=$(($CDDBPROTO - 1))
2746 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2747 # FreeDB TESTCD disc-id is used for query
2748 $CDDBTOOL query "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" 03015501 1 296 344 > "${SOURCE_WORKDIR}/cddbstat"
2749 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2750 case "$RESPONSECODE" in
2751 2??) # Server responded, everything seems OK
2761 if [ $rc -eq 1 ]; then
2765 echo cddb-statcomplete >> "${ABCDETEMPDIR}/status"
2772 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2773 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2775 # Perform CDDB query if it hasn't already been done
2776 if checkstatus cddb-querycomplete; then :; else
2777 if [ "$CDDBAVAIL" = "n" ]; then
2779 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2780 # The default CDDBLOCALSTATUS is "notfound"
2781 # This part will be triggered if the user CDDB repo does not
2782 # contain the entry, or if we are not trying to use the repo.
2784 vecho "Querying the CDDB server..."
2785 CDDBUSER=$(echo "$HELLOINFO" | cut -f1 -d'@')
2786 CDDBHOST=$(echo "$HELLOINFO" | cut -f2- -d'@')
2787 $CDDBTOOL query "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" "$CDDBTRACKINFO" > "${SOURCE_WORKDIR}/cddbquery"
2793 # no match found in database, wget/fetch error,
2794 # or user requested not to use CDDB. Make up an
2795 # error code (503) that abcde will recognize later
2796 # and compensate by making a template
2797 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2799 *) # strange and unknown error
2800 echo "ERRORCODE=$ERRORCODE"
2801 echo "abcde: $CDDBTOOL returned unknown error code"
2805 echo cddb-querycomplete >> "${ABCDETEMPDIR}/status"
2812 # If it's not to be used, generate a template.
2813 # Then, display it (or them) and let the user choose/edit it
2814 if checkstatus cddb-readcomplete; then
2815 NUM_RESPONSES=$(checkstatus "cddb-entries")
2816 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2817 vecho "Re-using existing data from $NUM_RESPONSES cddb match(es)"
2819 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbquery" | cut -f1 -d' ')
2820 vecho "Obtaining CDDB results..."
2821 case "$RESPONSECODE" in
2823 # One exact match, retrieve it
2824 # 200 [section] [discid] [artist] / [title]
2826 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2827 $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
2828 $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") \
2829 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2830 cat "${SOURCE_WORKDIR}/cddbquery" | cut -f2- -d' ' > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2831 echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2832 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2834 202|403|409|500|503)
2835 # TODO: Explain these error codes a little more accurately:
2836 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2837 # No match response:
2840 # Multiple exact, (possibly multiple) inexact matches
2841 vecho -n "Retrieving multiple matches... "
2842 grep -v '^[.]$' "${SOURCE_WORKDIR}/cddbquery" | (
2843 # IN A SUB-SHELL - VARIABLES MODIFIED
2844 # HERE DO NOT PERSIST IN THE PARENT
2845 read DISCINFO # eat top line
2848 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2849 if checkstatus "cddb-read-${NUM_CDDB_MATCHES}-complete"; then :; else
2850 $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
2851 $(echo "$DISCINFO" | cut -f1,2 -d' ') \
2852 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2853 echo "$DISCINFO" > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2854 echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2855 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2858 # Need to re-count the entries here to be able
2859 # to incrememnt $NUM_CDDB_MATCHES in the
2861 NUM_RESPONSES=$(ls -1 "${SOURCE_WORKDIR}"/datasource.* 2>/dev/null | wc -l)
2862 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2868 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2869 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2873 cd "${SOURCE_WORKDIR}"
2874 for file in cddbread.* cddbquery.* datasource.*; do
2875 if [ -f "$file" ]; then
2876 cp "$file" "${ABCDETEMPDIR}"
2880 echo "cddb-readcomplete" >> "${ABCDETEMPDIR}/status"
2881 echo "cddb-entries=$NUM_RESPONSES" >> "${ABCDETEMPDIR}/status"
2888 if checkstatus cddb-edit >/dev/null; then
2889 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2890 VARIOUSARTISTS="$(checkstatus variousartists)"
2891 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2894 if [ "$INTERACTIVE" = "y" ]; then
2895 # We should show the CDDB results both when we are not using the local CDDB repo
2896 # or when we are using it but we could not find a proper match
2897 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2898 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2899 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2900 CHOICE=$(checkstatus cddb-choice)
2901 if [ -n "$CHOICE" ] ; then
2902 case $NUM_CDDB_MATCHES in
2903 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2905 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CHOICE" | cut -f2- -d= | tr -d \\r\\n)
2906 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CHOICE")
2907 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)"
2908 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2912 page "${ABCDETEMPDIR}/cddbchoices"
2914 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2916 # I'll take CDDB read #3 for $400, Alex
2917 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; do
2918 echo -n "Which entry would you like abcde to use (0 for none)? [0-$NUM_CDDB_MATCHES]: " >&2
2920 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2921 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2922 if [ ! X"$DIFF" = "X" ]; then
2923 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2924 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2925 if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$NUM_CDDB_MATCHES" ] || \
2926 [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$NUM_CDDB_MATCHES" ] || \
2927 [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
2928 echo "Invalid diff range." >&2
2929 echo "Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
2931 # We parse the 2 choices to diff, store them in temporary files and diff them.
2932 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2933 do_cddbparse "${ABCDETEMPDIR}/cddbread.$PARSECHOICE" \
2934 > "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE"
2936 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." \
2937 > "${ABCDETEMPDIR}/cddbread.diff"
2938 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE1" \
2939 "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE2" \
2940 >> "${ABCDETEMPDIR}/cddbread.diff"
2941 page "${ABCDETEMPDIR}/cddbread.diff"
2944 echo "The diff program was not found in your path." >&2
2945 echo "Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2947 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2948 # Make sure we get a valid choice
2949 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2950 if [ "$CDCHOICENUM" -lt 0 ] || [ "$CDCHOICENUM" -gt "$NUM_CDDB_MATCHES" ]; then
2951 echo "Invalid selection. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2955 if [ "$CDCHOICENUM" = "0" ]; then
2956 vecho "Creating empty CDDB template..."
2958 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
2959 echo "template" > "${ABCDETEMPDIR}/datasource.0"
2961 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n)
2962 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CDCHOICENUM")
2963 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)" >&2
2965 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM"
2966 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2970 # We need some code to show the selected option when local repository is selected and we have found a match
2971 vecho "Using cached CDDB match..." >&2
2972 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2973 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2974 CHOICE=$(checkstatus cddb-choice)
2975 if [ "$USELOCALRESP" = "y" ]; then :; else
2976 if [ -n "$CHOICE" ] ; then
2977 case $NUM_CDDB_MATCHES in
2980 echo "Selected template."
2982 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2984 echo "Selected: #$CHOICE"
2985 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2993 # We're noninteractive - pick the first choice.
2994 # But in case we run a previous instance and selected a choice, use it.
2995 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2996 # Show the choice if we are not using the locally stored one
2997 # or when the local search failed to find a match.
2998 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2999 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
3000 #if [ "$PREVIOUSCHOICE" ]; then
3001 cat "${ABCDETEMPDIR}/cddbchoices"
3004 if [ ! -z "$PREVIOUSCHOICE" ] ; then
3005 CDCHOICENUM=$PREVIOUSCHOICE
3008 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
3010 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
3015 if checkstatus cddb-choice >/dev/null; then :; else
3016 echo "abcde: internal error: cddb-choice not recorded." >&2
3019 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
3020 CDDBSOURCE=$(cat "${ABCDETEMPDIR}/datasource.$(checkstatus cddb-choice)")
3021 echo -n "Edit selected CDDB data " >&2
3022 if [ "$INTERACTIVE" = "y" ]; then
3023 if [ "$UNKNOWNDISK" = "y" ]; then
3024 echo -n "[Y/n]? " >&2
3026 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
3028 echo -n "[y/N]? " >&2
3035 if [ "$EDITCDDB" = "y" ]; then
3036 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
3038 # Use the debian sensible-editor wrapper to pick the editor that the
3039 # user has requested via their $EDITOR environment variable
3040 if [ -x "/usr/bin/sensible-editor" ]; then
3041 /usr/bin/sensible-editor "$CDDBDATA"
3042 elif [ -n "$EDITOR" ]; then
3043 if [ -x "$(which "${EDITOR%%\ *}")" ]; then
3044 # That failed, try to load the preferred editor, starting
3045 # with their EDITOR variable
3048 # If that fails, check for a vi
3049 elif which vi >/dev/null 2>&1; then
3051 elif [ -x /usr/bin/vim ]; then
3052 /usr/bin/vim "$CDDBDATA"
3053 elif [ -x /usr/bin/vi ]; then
3054 /usr/bin/vi "$CDDBDATA"
3055 elif [ -x /bin/vi ]; then
3057 # nano should be on all (modern, i.e., sarge) debian systems
3058 elif which nano >/dev/null 2>&1 ; then
3060 elif [ -x /usr/bin/nano ]; then
3061 /usr/bin/nano "$CDDBDATA"
3062 # mg should be on all OpenBSD systems
3063 elif which mg >/dev/null 2>&1 ; then
3065 elif [ -x /usr/bin/mg ]; then
3066 /usr/bin/mg "$CDDBDATA"
3069 log warning "no editor available. Check your EDITOR environment variable."
3071 # delete editor backup file if it exists
3072 if [ -w "$CDDBDATA~" ]; then
3077 # Some heuristics first. Look at Disc Title, and if it starts with
3078 # "Various", then we'll assume Various Artists
3079 if [ "$(grep -a ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -aEci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
3080 echo "Looks like a Multi-Artist CD" >&2
3083 echo -n "Is the CD multi-artist [y/N]? " >&2
3084 if [ "$INTERACTIVE" = "y" ]; then
3091 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
3094 # Need NUMTRACKS before cddb-tool will return it:
3095 NUMTRACKS=$(grep -a -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
3096 if [ "$(grep -ac "^TTITLE.*\/" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3097 # More than 1/2 tracks contain a "/", so guess forward
3099 elif [ "$(grep -ac "^TTITLE.*\-" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3100 # More than 1/2 contain a "-", so guess forward-dash
3102 elif [ "$(grep -ac "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3103 # More than 1/2 contain something in parens, so guess trailing-paren
3107 echo "1) Artist / Title" >&2
3108 echo "2) Artist - Title" >&2
3109 echo "3) Title / Artist" >&2
3110 echo "4) Title - Artist" >&2
3111 echo "5) Artist: Title" >&2
3112 echo "6) Title (Artist)" >&2
3113 echo "7) This is a single-artist CD" >&2
3114 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
3115 if [ "$INTERACTIVE" = "y" ]; then
3116 read VARIOUSARTISTSTYLE
3118 echo $DEFAULTSTYLE >&2
3119 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3121 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3122 # If they press Enter, then the default style (0) was chosen
3123 while [ "$VARIOUSARTISTSTYLE" -lt 0 ] || [ "$VARIOUSARTISTSTYLE" -gt 7 ]; do
3124 echo "Invalid selection. Please choose a number between 1 and 7."
3125 echo -n "Selection [1-7]: "
3126 read VARIOUSARTISTSTYLE
3127 VARIOUSARTISTSTYLE=$(echo "0$VARIOUSARTISTSTYLE" | xargs printf "%d")
3129 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3130 VARIOUSARTISTSTYLE="$DEFAULTSTYLE"
3132 vecho "Selected: $VARIOUSARTISTSTYLE"
3133 case "$VARIOUSARTISTSTYLE" in
3135 VARIOUSARTISTSTYLE=forward
3138 VARIOUSARTISTSTYLE=forward-dash
3141 VARIOUSARTISTSTYLE=reverse
3144 VARIOUSARTISTSTYLE=reverse-dash
3147 VARIOUSARTISTSTYLE=colon
3150 VARIOUSARTISTSTYLE=trailing-paren
3158 echo "variousartists=$VARIOUSARTISTS" >> "${ABCDETEMPDIR}/status"
3159 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "${ABCDETEMPDIR}/status"
3161 if [ "$EDITCDDB" = "y" ] && [ "$CDDBSOURCE" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3162 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3163 # This works but does not have the necessary error checking
3164 # yet. If you are familiar with the CDDB spec
3165 # (see http://www.freedb.org/src/latest/DBFORMAT)
3166 # and can create an error-free entry on your own, then put
3167 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3168 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3169 # your abcde.conf to change the email address submissions are
3172 # submit the modified file, if they want
3173 if [ "$NOSUBMIT" != "y" ]; then
3174 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3176 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3177 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3179 echo -n 'Invalid selection. Please answer "y" or "n": '
3182 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3183 echo -n "Sending..."
3184 $CDDBTOOL send "$CDDBDATA" "$CDDBSUBMIT"
3191 # User CDDBLOCALPOLICY to find out if we store the file or not...
3192 # Cache edited CDDB entry in the user's cddb dir
3193 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3194 # Make sure the cache directory exists
3195 mkdir -p "$CDDBLOCALDIR"
3196 NUM_LINES=$(( $(wc -l < "$CDDBDATA") - 1 ))
3197 OUTPUT_FILE="$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)"
3198 tail -n "$NUM_LINES" < "$CDDBDATA" > "${CDDBLOCALDIR}/${OUTPUT_FILE}"
3201 echo "cddb-edit" >> "${ABCDETEMPDIR}/status"
3205 # try to download CD cover
3208 if checkstatus "get-album-art"; then :; else
3210 ALBUMFILE="$(mungealbumname "$DALBUM")"
3211 ARTISTFILE="$(mungeartistname "$DARTIST")"
3212 GENRE="$(mungegenre "$GENRE")"
3213 YEAR=${CDYEAR:-$CDYEAR}
3214 # have we got a musicbrainz mbid or amazon asin?
3215 case "$CDDBMETHOD" in
3217 # try musicbrainz mbid
3218 if [ -s "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)" ]; then
3219 MBID=$(cat "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)")
3220 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3221 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3222 vecho "cover URL: $ALBUMARTURL" >&2
3223 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3224 if [ $? -ne 0 ]; then
3225 vecho "could not download cover from musicbrainz" >&2
3227 if [ -s "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)" ]; then
3228 ASIN=$(cat "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)")
3229 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3230 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3231 vecho "cover URL: $ALBUMARTURL" >&2
3232 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3233 if [ $? -ne 0 ]; then
3234 vecho "could not download cover from amazon" >&2
3236 # Check that size is reasonable; sometimes when there is no cover image
3237 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3238 FILESIZE=$(wc -c < "${ABCDETEMPDIR}/$ALBUMARTFILE")
3239 if [ "$FILESIZE" -lt 1024 ]; then
3240 rm "${ABCDETEMPDIR}/$ALBUMARTFILE"
3241 vecho "could not download cover from amazon" >&2
3245 vecho "no amazon ID found" >&2
3249 vecho "no musicbrainz ID found" >&2
3254 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3255 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3256 env LC_ALL=C $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "${ABCDETEMPDIR}/$ALBUMARTFILE" $GLYRCOPTS
3257 if [ $? -ne 0 ]; then
3258 vecho "could not download cover with glyrc" >&2
3263 if [ "$INTERACTIVE" = "y" ]; then
3264 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3265 # display properties of coverart when identify is available
3266 if new_checkexec "$IDENTIFY"; then
3267 $IDENTIFY $IDENTIFYOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3269 # display coverart when DISPLAY is set and display command is available
3270 if new_checkexec "$DISPLAYCMD" && [ "$DISPLAY" != "" ]; then
3271 $DISPLAYCMD $DISPLAYCMDOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2 &
3274 # nothing downloaded yet
3275 vecho "automatic album art downloading failed" >&2
3277 # see if the user can find a better album art manually
3278 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3280 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3281 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3283 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3286 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3287 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3289 if [ ! -z "$ALBUMARTURL" ]; then
3290 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3291 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3292 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3293 vecho "unable to download $ALBUMARTURL" >&2
3295 else # it's a local path
3296 cp "$ALBUMARTURL" "${ABCDETEMPDIR}/$ALBUMARTFILE"
3297 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3298 vecho "unable to copy $ALBUMARTURL to ${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3304 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3305 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ] && new_checkexec "$IDENTIFY"; then
3306 ALBUMARTURLTYPE=$($IDENTIFY "${ABCDETEMPDIR}/$ALBUMARTFILE" | cut -d' ' -f2)
3307 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" ] || [ "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3308 if new_checkexec "$CONVERT"; then
3309 mv "${ABCDETEMPDIR}/$ALBUMARTFILE" "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3310 $CONVERT "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp" $CONVERTOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE"
3311 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3313 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3314 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE" >&2
3315 vecho "without ImageMagick convert" >&2
3319 # copy to target directories
3320 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3321 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
3323 # put cover in the same place as the album
3324 if [ "$ONETRACK" = "y" ] ; then
3325 if [ "$VARIOUSARTISTS" = "y" ] ; then
3326 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3328 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3331 if [ "$VARIOUSARTISTS" = "y" ] ; then
3332 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3334 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3337 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3338 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3339 mkdir -p "$FINALALBUMARTDIR"
3340 cp "${ABCDETEMPDIR}/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3342 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3343 echo "get-album-art=$ALBUMARTURL" >> "${ABCDETEMPDIR}/status"
3345 log warning "could not get cover"
3346 echo "get-album-art=none" >> "${ABCDETEMPDIR}/status"
3351 # Optionally embed the albumart downloaded by the getalbumart fuction.
3352 # FIXME: It would be nice to have this also selectable from within the
3353 # FIXME: getalbumart function itself. Andrew
3357 ALBUMFILE="$(mungealbumname "$DALBUM")"
3358 ARTISTFILE="$(mungeartistname "$DARTIST")"
3359 GENRE="$(mungegenre "$GENRE")"
3360 YEAR=${CDYEAR:-$CDYEAR}
3362 # Allow for multiple output formats:
3363 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
3365 # Find the output directory for multi track encodes:
3366 if [ "$ONETRACK" != "y" ] ; then
3367 if [ "$VARIOUSARTISTS" = "y" ] ; then
3368 FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
3370 FINDPATH="$(eval echo "$OUTPUTFORMAT")"
3373 # Find the output directory for single track encodes:
3374 if [ "$ONETRACK" = "y" ] ; then
3375 if [ "$VARIOUSARTISTS" = "y" ] ; then
3376 FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3378 FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3382 FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
3385 # Instructions for each format, feel free to add more. It would be nice to
3386 # make the backup directory selectable and perhaps also have an option for
3387 # the bold to simply have the image deleted. Work for another day... Andrew.
3388 if [ -e "$ALBUMARTFILE" ] ; then
3393 "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$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 "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
3404 mkdir "$FINALDIR"/albumart_backup
3405 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3406 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3411 "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
3413 mkdir "$FINALDIR"/albumart_backup
3414 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3415 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3420 "$WVTAG" --write-binary-tag "Cover Art (Front)=@$ALBUMARTFILE" "$i"
3422 mkdir "$FINALDIR"/albumart_backup
3423 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3424 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3428 # This technique is drawn from 2 sources (the first link being the primary source):
3429 # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
3430 # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
3431 # In abcde a few steps are used in this sequence:
3433 # 1. Create a 'legal' header for the cover art image
3434 # 2. Makes a copy of the existing tags
3435 # 3. base64 the cover art image
3436 # 4. Copy the original tags + the base64 image back to the original ogg file
3438 # Might need some fine tuning but it is a start for abcde 2.9. Andrew.
3439 # FIXME: I am not sure if there is a maximum size for images converted in this
3440 # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
3442 # First some variables we can reuse:
3443 # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
3444 MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
3445 EXPORTTAGS="${ABCDETEMPDIR}/export_ogg_tags"
3446 BUILDHEADER="${ABCDETEMPDIR}/build_header"
3447 # Now build the header, gory details are here:
3448 # https://xiph.org/flac/format.html#metadata_block_picture
3450 printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
3452 printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3454 echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
3455 # Description length. FIXME: I have used 'Cover Image' but I am not sure
3456 # if this is better left as an empty field. Andrew
3457 printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3459 echo -n "Cover Image" >> "$BUILDHEADER"
3461 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3463 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3464 # Picture color depth:
3465 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3466 # Picture color count:
3467 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3469 printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
3470 # cat the image file:
3471 cat "$ALBUMARTFILE" >> "$BUILDHEADER"
3472 # Now process each ogg file by first exporting the original tags then
3473 # appending the cover image and finally copying the whole thing back
3474 # to the original image:
3477 # Make a backup of the existing tags:
3478 "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
3479 # base64 the file and then mix it all together with the exported tags:
3480 echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
3481 # Update the original ogg file with exported tags and the appended base64'd image:
3482 "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
3483 # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
3484 # note that the header file BUILDHEADER will be reused for each file in the loop:
3487 mkdir "$FINALDIR"/albumart_backup
3488 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3489 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3491 *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
3494 vecho "Suitable cover image not found, no embedding done..." >&2
3499 # do_cdread [tracknumber]
3500 # do_cdread onetrack [firsttrack] [lasttrack]
3504 # The commands here don't go through run_command because they're never supposed to be silenced
3505 # return codes need to be doublechecked anyway, however
3506 if [ "$1" = "onetrack" ]; then
3507 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3508 # FIXME # Until then, we grab the whole CD in one track, no matter what
3510 # We need the first and last track for cdda2wav/icedax
3512 LASTTRACK=$(expr $3 + 0) # Unpad
3513 UTRACKNUM=$FIRSTTRACK
3514 case "$CDROMREADERSYNTAX" in
3515 flac) READTRACKNUMS="-" ;;
3518 # Add a variable to check if tracks are provided in command line and if not, rip the whole CD
3519 # We must make sure to rip from sector 0, both lines below work
3520 # READTRACKNUMS="-- -$LASTTRACK" ;;
3521 READTRACKNUMS="[.0]-" ;;
3522 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3523 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3524 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3530 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
3531 if [ "$USEPIPES" = "y" ]; then
3532 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3533 FILEARG="$( eval echo "\$$TEMPARG" )"
3534 PIPE_MESSAGE="and encoding "
3536 WAVDATA="${ABCDETEMPDIR}/track$UTRACKNUM.wav"
3537 case "$CDROMREADERSYNTAX" in
3538 ## FIXME ## Find the cases for flac, to avoid exceptions
3540 FILEARG="--output-name=$WAVDATA"
3547 if [ "$1" = "onetrack" ]; then
3548 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3550 if [ -r "$CDDBDATA" ]; then
3551 getcddbinfo TRACKNAME
3552 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3554 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3557 case "$CDROMREADERSYNTAX" in
3558 ### FIXME ### use an exception for flac, since it uses -o
3559 ### FIXME ### Shall we just use -o $FILEARG ??
3561 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3562 STRIPTRACKNUM=$(expr $UTRACKNUM + 0 )
3563 nice $READNICE $FLAC -d -f --cue="${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0}" "$FILEARG" "$CDROM" ;;
3565 if [ "$USEPIPES" = "y" ]; then
3566 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG"
3568 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG" >&2
3572 if [ "$OSFLAVOUR" = "OSX" ] ; then
3573 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3574 diskutil unmount "${CDROM#/dev/}"
3575 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3576 CDDA2WAVCDROM="IODVDServices"
3577 elif [ "$OSFLAVOUR" = "FBSD" ] || [ "$OSFLAVOUR" = "IRIX" ]; then
3578 CDDA2WAVCDROM="$CDROMID"
3580 if [ "$CDROMID" = "" ]; then
3581 CDDA2WAVCDROM="$CDROM"
3583 CDDA2WAVCDROM="$CDROMID"
3586 if [ "$USEPIPES" = "y" ]; then
3587 nice $READNICE $CDROMREADER -D "$CDDA2WAVCDROM" -t "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG"
3589 nice $READNICE $CDROMREADER -D "$CDDA2WAVCDROM" -t "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG" >&2
3593 # I cannot get USEPIPES to work with dagrab so just this:
3594 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v "$UTRACKNUM" >&2
3597 if [ "$USEPIPES" = "y" ]; then
3598 nice $READNICE $CDROMREADER -j "${READTRACKNUMS:-$UTRACKNUM}" "$CDROM" "$FILEARG"
3600 # Write ripped audio data to stdout and redirect to $FILEARG.
3601 # Progress is written to stderr by default and thus >&2 is not required.
3602 nice $READNICE $CDROMREADER -j "${READTRACKNUMS:-$UTRACKNUM}" "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3606 # Find the track's mounted path
3607 REALTRACKNUM=$(expr $UTRACKNUM + 0) # Unpad
3608 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3609 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3610 # If the file exists, copy it
3611 if [ -e "$FILEPATH" ] ; then
3612 if [ "$USEPIPES" = "y" ]; then
3613 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3615 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3621 if [ "$USEPIPES" = "y" ]; then
3622 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -w "$UTRACKNUM-[:1]" "$FILEARG"
3624 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -w "$UTRACKNUM-[:1]" "$FILEARG" >&2
3629 # If we get some error or we get some missing wav
3630 # (as long as we dont use pipes)
3631 if [ "$RETURN" != "0" ] || ( [ ! -s "$WAVDATA" ] && [ X"$USEPIPES" != "Xy" ] ); then
3632 # Thank goodness errors is only machine-parseable up to the
3633 # first colon, otherwise this woulda sucked
3634 if [ "$RETURN" = "0" ] || [ ! -s "$WAVDATA" ]; then
3635 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3637 if [ "$USEPIPES" = "y" ]; then
3638 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3640 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3644 if [ "$USEPIPES" = "y" ]; then
3645 echo "readencodetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
3647 echo "readtrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
3649 if [ "$1" = "onetrack" ]; then
3650 echo onetrack >> "${ABCDETEMPDIR}/status"
3656 # No values accepted, only uses env variables
3659 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3660 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3662 echo "abcde: unable to set the device speed" >&2
3668 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3671 if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 0 ] ; then
3673 warning) shift ; log warning "$@" ;;
3681 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3684 if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 1 ] ; then
3686 warning) shift ; log warning "$@" ;;
3694 # decho outputs a debug message if DEBUG is selected
3697 if [ x"$DEBUG" != "x" ]; then
3698 if echo "$1" | grep "^\[" > /dev/null 2>&1 ; then
3699 DEBUGECHO=$(echo "$@" | tr -d '[]')
3700 echo >&4 "[DEBUG] $DEBUGECHO: $(eval echo \\$${DEBUGECHO})"
3702 echo >&4 "[DEBUG] $1"
3707 # User-redefinable functions
3708 # Custom filename munging:
3711 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3714 # Custom filename munging specific to track names:
3720 # Custom filename munging specific to artist names:
3726 # Custom filename munging specific to album names:
3732 # Custom genre munging:
3735 echo "$CDGENRE" | tr "[:upper:]" "[:lower:]"
3739 # Empty pre_read function, to be defined in the configuration file.
3746 # Empty post_read function, to be defined in the configuration file.
3753 # Empty post_encode function, to be defined in the configuration file.
3759 ###############################################################################
3762 # Start of execution
3763 ###############################################################################
3768 # Currently three supported options ("musicbrainz", "cddb" for freedb.org and "cdtext")
3769 CDDBMETHOD=musicbrainz
3770 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3771 CDDBSUBMIT=freedb-submit@freedb.org
3773 HELLOINFO="$(whoami)@$(hostname)"
3775 CDDBLOCALPOLICY="always"
3776 CDDBLOCALRECURSIVE="y"
3777 CDDBLOCALDIR="$HOME/.cddb"
3780 # List of fields we parse and show during the CDDB parsing...
3781 SHOWCDDBFIELDS="year,genre"
3784 #CDROMREADERSYNTAX=cdparanoia
3785 ENCODERSYNTAX=default
3787 MP3ENCODERSYNTAX=default
3788 OGGENCODERSYNTAX=default
3789 OPUSENCODERSYNTAX=default
3790 MKAENCODERSYNTAX=default
3791 AIFFENCODERSYNTAX=default
3792 FLACENCODERSYNTAX=default
3793 SPEEXENCODERSYNTAX=default
3794 MPCENCODERSYNTAX=default
3795 WVENCODERSYNTAX=default
3796 TTAENCODERSYNTAX=default
3797 APENCODERSYNTAX=default
3798 MP2ENCODERSYNTAX=default
3799 AACENCODERSYNTAX=default
3800 NORMALIZERSYNTAX=default
3801 CUEREADERSYNTAX=default
3803 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3804 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3805 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3806 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3807 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3808 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3809 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3810 PLAYLISTDATAPREFIX=''
3811 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3812 VAPLAYLISTDATAPREFIX=''
3820 VARIOUSARTISTSTYLE=forward
3827 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3828 # i.e. CDROMID="1,0,0"
3830 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3831 # If we are using the ide-scsi emulation layer, we need to define a "g"
3832 CDPARANOIACDROMBUS="d"
3834 # program paths - defaults to checking your $PATH
3840 XINGMP3ENC=xingmp3enc
3854 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3858 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3868 NEROAACENC=neroAacEnc
3870 # Note that the qaac PATH will almost always require adjustment
3871 # as it is a Windows application being run through Wine. More
3872 # detailed notes in the sample abcde.conf file in the abcde tarball.
3875 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3883 VORBISCOMMENT=vorbiscomment
3885 NEROAACTAG=neroAacTag
3886 ATOMICPARSLEY=AtomicParsley
3890 CDPARANOIA=cdparanoia
3891 CD_PARANOIA="cd-paranoia"
3896 CDDISCID="cd-discid"
3898 MUSICBRAINZ=abcde-musicbrainz-tool
3902 NORMALIZE="normalize-audio"
3904 VORBISGAIN=vorbisgain
3908 # For Wavpack replay gain we set both the default of 'track gain'
3909 # as well as this option for 'album gain'. Better media players
3910 # such as vlc can select either or neither. Andrew.
3921 # Options for programs called from abcde:
3924 # These options needed by FFmpeg for tagging and selection of id3v2 version:
3925 # 1. '-write_id3v2 1' allows id3v2 tagging while '-write_id3v2 0' disables tagging
3926 # 2. '-id3v2_version 4' gives version id3v2.4 while '3' gives id3v2.3
3927 AIFFENCOPTS="-write_id3v2 1 -id3v2_version 4"
3939 VORBISGAINOPTS="--album"
3943 # The flac option is a workaround for an error where flac fails
3944 # to encode with error 'floating point exception'. This is flac
3945 # error in get_console_width(), corrected in flac 1.3.1
3947 FLACGAINOPTS="--add-replay-gain"
3954 # True Audio has no useful options but it is here anyway :)
3957 # Monkey's Audio Console (mac) chokes without a mode setting
3958 # so we set one here.
3965 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3966 # we set bitrate here.
3967 FDKAACENCOPTS='--bitrate 192k'
3989 VORBISCOMMENTOPTS="-R"
3990 METAFLACOPTS="--no-utf8-convert"
3995 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3997 # Defaults for album art downloads
3998 ALBUMARTFILE="cover.jpg"
4000 ALBUMARTALWAYSCONVERT="n"
4002 # Default to one process if -j isn't specified
4005 # List of actions to perform - by default, run to completion
4006 ACTIONS=cddb,read,encode,tag,move,clean
4008 # This option is basically for Debian package dependencies:
4009 # List of preferred outputs - by default, run with whatever we have in the path
4010 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:fdkaac:opus
4012 # List of preferred cdromreaders - by default, run whichever we have in the path
4013 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
4015 # fd for when `vecho` and `log info` called with redirected stdout
4018 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
4019 # Linux/OpenBSD. ftp is user for NetBSD.
4020 # Let's use these checkings to determine the OS flavour, which will be used
4023 if [ X"$UNAME" = "XFreeBSD" ] ; then
4028 elif [ X"$UNAME" = "XDarwin" ] ; then
4030 # By default md5sum is not installed, use md5 instead:
4033 # We should have diskutil in OSX, but let's be sure...
4035 CDROMREADERSYNTAX=cddafs
4036 # We won't find the eject program in OSX, and doing checkexec will fail further below...
4038 elif [ X"$UNAME" = "XOpenBSD" ] ; then
4042 elif [ X"$UNAME" = "XNetBSD" ] ; then
4046 elif [ X"$UNAME" = X"SunOS" ] ; then
4050 elif [ X"$UNAME" = X"IRIX64" ] ; then
4054 # Apparently necessary - see
4055 # https://abcde.einval.com/bugzilla/show_bug.cgi?id=29
4056 CDDISCID_NEEDS_PAUSE=y
4061 # If CDDBAVAIL is set to n, no CDDB read is done
4065 # But before we get into business, let us chop off any GREP environmental
4070 if [ -z "$OUTPUTDIR" ]; then
4074 if [ -z "$WAVOUTPUTDIR" ]; then
4075 WAVOUTPUTDIR="$OUTPUTDIR"
4078 # Load system defaults
4079 if [ -r /etc/abcde.conf ]; then
4082 # Load user preference defaults
4083 if [ -r "$HOME/.abcde.conf" ]; then
4084 . "$HOME/.abcde.conf"
4087 # By this time, we need some HTTPGETOPTS already defined.
4088 # If the user has defined a non-default HTTPGET method, we should not be empty.
4090 if [ "$HTTPGETOPTS" = "" ] ; then
4092 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
4093 curl) HTTPGETOPTS="-f -s -L";;
4094 fetch)HTTPGETOPTS="-q -o -";;
4095 ftp) HTTPGETOPTS="-a -V -o - ";;
4096 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
4100 # If the CDROM has not been set yet, find a suitable one.
4101 # If this is a devfs system, default to /dev/cdroms/cdrom0
4102 # instead of /dev/cdrom
4103 if [ "$CDROM" = "" ] ; then
4104 if [ -e /dev/cdroms/cdrom0 ]; then
4105 CDROM=/dev/cdroms/cdrom0
4106 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
4107 CDROM=/dev/${BASH_REMATCH[1]}
4108 elif [ -e /dev/cdrom ]; then
4110 elif [ -e /dev/sr0 ]; then
4112 elif [ -e /dev/cd0c ]; then
4114 elif [ -e /dev/acd0c ]; then
4116 elif [ -e /dev/disk1 ]; then
4121 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
4122 # that's changed to a number to allow for more control. Deal with
4123 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
4124 case "$EXTRAVERBOSE" in
4133 # Parse command line options
4134 while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pPQ:r:s:S:t:T:UvVxX:w:W:z opt ; do
4137 a) ACTIONS="$OPTARG" ;;
4138 A) EXPACTIONS="$OPTARG" ;;
4140 B) GETALBUMART=y ; EMBEDALBUMART=y ;;
4141 c) if [ -e "$OPTARG" ]; then
4144 log error "config file \"$OPTARG\" cannot be found."
4148 C) CDDBDISCID="$( echo "${OPTARG#abcde.}" | tr -d /)" ;;
4149 d) CDROM="$OPTARG" ;;
4152 e) ERASEENCODEDSTATUS=y ;;
4153 E) ENCODING="$OPTARG" ;;
4158 j) MAXPROCS="$OPTARG" ;;
4161 L) CDDBUSELOCAL=y ;;
4166 o) OUTPUTTYPE="$OPTARG" ;;
4169 Q) CDDBMETHOD="$OPTARG" ;;
4170 r) REMOTEHOSTS="$OPTARG" ;;
4171 R) CDDBLOCALRECURSIVE=y ;;
4172 s) SHOWCDDBFIELDS="$OPTARG" ;;
4173 S) CDSPEEDVALUE="$OPTARG" ;;
4174 t) STARTTRACKNUMBER="$OPTARG" ;;
4175 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
4178 echo "This is abcde v$VERSION."
4179 echo "Usage: abcde [options] [tracks]"
4180 echo "abcde -h for extra help"
4183 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
4185 X) CUE2DISCID="$OPTARG" ;;
4186 w) COMMENT="$OPTARG" ;;
4187 W) if echo "$OPTARG" | grep "[[:digit:]]" > /dev/null 2>&1 ; then
4188 STARTTRACKNUMBER="${OPTARG}$(printf "%02d" "${STARTTRACKNUMBER:-01}")"
4189 STARTTRACKNUMBERTAG="y"
4190 COMMENT="CD${OPTARG}"
4191 DISCNUMBER="${OPTARG}"
4193 log error "argument of -W must be integer"
4197 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
4202 shift $(($OPTIND - 1))
4204 # Here it comes the worse part of the whole thing. From here until we start
4205 # ripping, we have a mixture of sanity checks, verifications, default settigs
4206 # and other crazy stuff that interdepends, but hey, someone has to do it.
4208 # If NOCDDBQUERY is set, don't query the CDDB server.
4209 if [ "$NOCDDBQUERY" = "y" ]; then
4213 # If the user specified a flac file, then switch to special flac mode
4214 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
4215 if [ ! -f "$CDROM" ]; then
4216 log error "the defined file for FLAC ripping cannot be found" >&2
4219 vecho warning "switching to flac CDROMREADERSYNTAX..."
4220 CDROMREADERSYNTAX=flac
4221 # We have a builtin version of cue2discid...
4222 case "$CUE2DISCID" in
4224 *) NEEDCUE2DISCID=y;;
4230 # If the user provided a CDDBDISCID, disable eject
4231 if [ -n "${CDDBDISCID}" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
4233 # Check the available cd rippers in the system, from the ones we know.
4234 if [ "$CDROMREADERSYNTAX" = "" ]; then
4235 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
4236 if new_checkexec "$DEFAULT_CDROMREADER"; then
4237 CDROMREADERSYNTAX="$DEFAULT_CDROMREADER"
4241 if [ "$CDROMREADERSYNTAX" = "" ]; then
4242 log error "no cdreader found in your PATH"
4243 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4248 # Decide if we can continue.
4249 if [ "$ONETRACK" = "y" ]; then
4250 # FIXME # remove check as soon as we find out about the other readers
4251 case "$CDROMREADERSYNTAX" in
4253 cdparanoia | libcdio) ;;
4254 cdda2wav | icedax) ;;
4256 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
4259 if [ "$BATCHNORM" = "y" ]; then
4260 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
4263 if [ "$NOGAP" = "y" ]; then
4264 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
4267 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
4268 # FIXME # allow ranges of tracks to be selected for onetrack ripping
4269 if [ $# -gt 0 ]; then
4270 log warning "ONETRACK mode selected, grabbing all tracks..."
4273 while [ $# -gt 0 ]; do
4274 # Range parsing code courtesy of Vincent Ho
4275 # Cleaned up to use shell built-ins by Charles Steinkuehler
4276 if [ "${1#*[^0-9-]}" != "$1" ]; then
4277 log error "syntax error while processing track numbers ($1)"
4282 while [ "${RSTART:=1}" -le "${REND:=0}" ] ; do
4283 TRACKQUEUE="$TRACKQUEUE $RSTART"
4284 RSTART=$(( $RSTART + 1 ))
4291 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
4292 # List of experimental actions: retag,transcode
4294 # Determine what actions are to be done from $ACTIONS and set the
4295 # following environment variables for them:
4307 ## FIXME ## Lets keep compatibility with -M
4308 [ "$DOCUE" != "y" ] && DOCUE=n
4310 for ACTION in $(echo "$ACTIONS" | tr , \ )
4313 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4314 cue) DOCUE=y ; MAKECUEFILE=y ;;
4317 normalize) DONORMALIZE=y; DOREAD=y;;
4318 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4319 encode) DOENCODE=y; DOREAD=y;;
4320 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4321 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4322 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4323 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4324 playlist) DOCDDB=y; DOPLAYLIST=y;;
4326 getalbumart) GETALBUMART=y;;
4327 embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
4331 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4332 # FIXME # should we abort on error or just inform the user?
4333 log warning "selected both normalize and replaygain actions"
4336 for SHOWCDDBFIELD in $(echo "$SHOWCDDBFIELDS" | tr , \ ); do
4337 case $SHOWCDDBFIELD in
4338 y*|Y*) SHOWCDDBYEAR="y";;
4339 g*|G*) SHOWCDDBGENRE="y";;
4344 # At this point a CDROM has to be defined, so we check it exists.
4345 if [ X"$CDROM" != "X" ] ; then
4346 if [ "$NEEDCDROMID" = "y" ] ; then
4347 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ]; then
4348 if [ "$OSFLAVOUR" = "IRIX" ]; then
4349 if [ -z "$CDROMID" ]; then
4350 CDROMID="$(echo "$CDROM" | sed -e 's;/dev/scsi/sc\([0-9]*\)d\([0-9]*\)l\([0-9]*\)$;\1,\2,\3;')"
4353 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
4354 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4355 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4359 elif [ ! -e "$CDROM" ] && [ X"$DOREAD" = "Xy" ]; then
4360 log error "CDROM device cannot be found."
4363 # avoid processing if we are not going to hit the CDROM.
4364 elif [ X"$DOREAD" = "Xy" ]; then
4365 log error "CDROM has not been defined or cannot be found"
4369 # USEPIPES pre-tests, before we get into more serious stuff
4370 # Not compatible with:
4371 # - multiple outputs
4373 # - lowdisk algorithm
4375 if [ X"$USEPIPES" = "Xy" ]; then
4376 NUM_OUTPUT_TYPES="$(echo "$OUTPUTTYPE" | tr , \ | wc -w )"
4377 if [ "$NUM_OUTPUT_TYPES" -gt 1 ]; then
4378 log error "Unix pipes not compatible with multiple outputs"
4381 if [ X"$DONORMALIZE" = "Xy" ]; then
4382 log error "Unix pipes not compatible with normalizer"
4383 # FIXME # Do we need to exit or shall we just disable the mode?
4386 if [ X"$BATCHNORM" = "Xy" ]; then
4387 log error "Unix pipes not compatible with BATCHNORM encoding"
4390 if [ X"$NOGAP" = "Xy" ]; then
4391 log error "Unix pipes not compatible with NOGAP encoding"
4394 if [ X"$DOENCODE" = "Xn" ]; then
4395 vecho warning "Disabling Unix pipes since we are not encoding!"
4398 if [ X"$LOWDISK" = "Xy" ]; then
4399 log error "Unix pipes not compatible with lowdisk algorithm"
4404 # LOWDISK pre-tests, before we get into more problematic stuff
4405 # Not compatible with anything that needs all the files in the hard disc:
4408 if [ X"$LOWDISK" = "Xy" ]; then
4409 if [ X"$BATCHNORM" = "Xy" ]; then
4410 log error "Unix pipes not compatible with BATCHNORM encoding"
4413 if [ X"$NOGAP" = "Xy" ]; then
4414 log error "Unix pipes not compatible with NOGAP encoding"
4419 # BATCHNORM pre-tests, before we get into serious problems
4420 # Not compatible with
4421 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4422 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4426 # Check the encoding format from the ones available in the system, if nothing has been configured.
4427 if [ X"$OUTPUTTYPE" = "X" ]; then
4428 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4429 DEFAULT_OUTPUT_FORMAT="$(echo "$DEFAULT_OUTPUT" | cut -d ":" -f 1)"
4430 DEFAULT_OUTPUT_BINARY="$(echo "$DEFAULT_OUTPUT" | cut -d ":" -f 2)"
4431 if [ -x "$(which "$DEFAULT_OUTPUT_BINARY")" ] ; then
4432 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4433 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4437 if [ X"$OUTPUTTYPE" = "X" ]; then
4438 log error "no encoder found in the PATH"
4439 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4444 # Decide which CDROM reader we're gonna use
4445 case "$CDROMREADERSYNTAX" in
4447 CDROMREADER="$CDPARANOIA"
4448 CDROMREADEROPTS="$CDPARANOIAOPTS"
4451 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4452 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4453 CDROMREADER="$CD_PARANOIA"
4454 CDROMREADEROPTS="$CDPARANOIAOPTS"
4457 CDROMREADER="$CDDA2WAV"
4458 CDROMREADEROPTS="$CDDA2WAVOPTS"
4461 CDROMREADER="$DAGRAB"
4462 CDROMREADEROPTS="$DAGRABOPTS"
4466 CDROMREADEROPTS="$PIRDOPTS"
4469 CDROMREADER="$CDDAFS"
4470 CDROMREADEROPTS="$CDDAFSOPTS"
4474 CDROMREADEROPTS="$FLACOPTS"
4478 # There's only one normalize...
4479 case "$NORMALIZERSYNTAX" in
4481 NORMALIZER="$NORMALIZE"
4482 NORMALIZEROPTS="$NORMALIZEOPTS"
4486 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4487 case "$OUTPUTTYPE" in *:*)
4488 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4489 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4491 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4492 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4493 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4494 aiff:*) AIFFENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4495 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4496 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4497 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4498 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4499 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4500 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4501 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4502 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4503 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4506 # Allows commandline selection of options while using multiple outputs.
4507 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4508 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4509 TEMPOUTPUT=${OUTPUT%%:*}
4510 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4512 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4516 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4517 # for flacs and speexenc for speex and mpcenc for mpcs and fdkaac for m4as and
4518 # wavpack for wvs...
4520 # Getting ready for multiple output changes
4521 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
4525 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4526 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4527 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4528 OGGOUTPUTCONTAINER=ogg
4531 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4532 OPUSOUTPUTCONTAINER=opus
4535 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4536 MKAOUTPUTCONTAINER=mka
4539 [ "$AIFFENCODERSYNTAX" = "default" ] && AIFFENCODERSYNTAX=ffmpeg
4540 AIFFOUTPUTCONTAINER=aiff
4543 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4544 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4545 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4546 [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
4549 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4550 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4551 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4552 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4553 [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
4556 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4557 # [ "$DOREPLAYGAIN" = "y" ] &&
4560 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4561 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4564 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4566 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4567 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4568 [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
4571 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4572 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4575 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4576 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4577 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4580 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4581 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4582 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4585 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4587 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4588 # compiled without libmp4v2... Andrew.
4591 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=fdkaac
4592 [ "$AACENCODERSYNTAX" = "faac" ] && [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4593 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4594 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4595 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4596 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4597 [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
4600 if [ "$KEEPWAVS" = "y" ]; then
4601 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4605 *) log error "Invalid OUTPUTTYPE defined"
4611 # decide which encoder
4612 case "$MP3ENCODERSYNTAX" in
4614 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4618 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4622 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4623 MP3ENCODER="$BLADEENC"
4626 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4630 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4631 MP3ENCODER="$XINGMP3ENC"
4634 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4635 MP3ENCODER="$MP3ENC"
4638 case "$OGGENCODERSYNTAX" in
4640 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4641 OGGENCODER="$VORBIZE"
4644 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4645 OGGENCODER="$OGGENC"
4648 case "$OPUSENCODERSYNTAX" in
4650 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4651 OPUSENCODER="$OPUSENC"
4654 case "$MKAENCODERSYNTAX" in
4656 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4657 MKAENCODER="$FFMPEG"
4660 case "$AIFFENCODERSYNTAX" in
4662 AIFFENCODEROPTS="${AIFFENCODEROPTSCLI:-$AIFFENCOPTS}"
4663 AIFFENCODER="$FFMPEG"
4666 case "$FLACENCODERSYNTAX" in
4668 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4670 if [ "$DOREPLAYGAIN" = "y" ]; then
4671 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4673 # FLAC streams can be encapsulated on a Ogg transport layer
4674 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4675 log error "FLAC on an Ogg container is not yet supported"
4676 log error "due to problem with adding comments to such files"
4678 FLACOUTPUTCONTAINER=ogg
4680 FLACOUTPUTCONTAINER=flac
4684 case "$SPEEXENCODERSYNTAX" in
4686 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4687 SPEEXENCODER="$SPEEXENC"
4690 case "$MPCENCODERSYNTAX" in
4692 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4693 MPCENCODER="$MPCENC"
4696 case "$WVENCODERSYNTAX" in
4698 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4699 # and in the interests of backward compatibility:
4700 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4701 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4702 WVENCODER="$WAVPACK"
4704 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4705 WVENCODER="$WAVPACK"
4709 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4713 case "$TTAENCODERSYNTAX" in
4715 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4719 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4720 TTAENCODER="$TTAENC"
4723 case "$APENCODERSYNTAX" in
4725 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4729 case "$MP2ENCODERSYNTAX" in
4731 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4732 MP2ENCODER="$TWOLAME"
4735 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4736 MP2ENCODER="$FFMPEG"
4739 case "$AACENCODERSYNTAX" in
4740 # Some elaborate 'if' work to keep backward compatibility for those
4741 # who don't realise that AACENCOPTS does not work with abcde from
4742 # version 2.7 onwards.
4744 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4745 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4748 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4753 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4754 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4755 AACENCODER="$NEROAACENC"
4757 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4758 AACENCODER="$NEROAACENC"
4762 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4763 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4764 AACENCODER="$FDKAAC"
4766 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4767 AACENCODER="$FDKAAC"
4771 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4772 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4775 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4780 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4781 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4782 AACENCODER="$FHGAACENC"
4784 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4785 AACENCODER="$FHGAACENC"
4789 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4790 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4791 AACENCODER="$FFMPEG"
4793 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4794 AACENCODER="$FFMPEG"
4804 TAGGEROPTS="$ID3OPTS"
4809 TAGGEROPTS="$ID3V2OPTS"
4814 TAGGEROPTS="$ID3TAGOPTS"
4818 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4819 # trouble with CDDBPROTO=5 (which we test here) but also
4820 # with cached cddb files in latin1 (which we cannot test).
4821 if [ "$CDDBPROTO" -lt 6 ]; then
4822 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4825 # eyeD3 version 0.7 changed syntax
4826 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4827 # only if it offers the --set-encoding, assume <= 0.6.x
4829 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4831 # anything wrong, any failure, assume >= 0.7
4833 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4837 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4842 # NOGAP is specific to lame. Other encoders fail ...
4843 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4844 log warning "the NOGAP option is specific to lame. Deactivating..."
4849 case "$CUEREADERSYNTAX" in
4851 CUEREADEROPTS="${CDROM}"
4855 CUEREADEROPTS="$MKCUEOPTS ${CDROM}"
4860 # which information retrieval tool are we using?
4866 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4867 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4868 log error "FLAC on an Ogg container is not yet supported"
4869 log error "due to problem with adding comments to such files"
4871 OGGOUTPUTCONTAINER=ogg.ogg
4872 FLACOUTPUTCONTAINER=flac.ogg
4873 vecho warning "modified file endings due to conflicting transport"
4874 vecho warning "layers in Ogg/Vorbis and Ogg/FLAC"
4877 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4879 if [ "$ENCNICE" ]; then
4880 ENCNICE="-n $ENCNICE"
4882 if [ "$READNICE" ]; then
4883 READNICE="-n $READNICE"
4885 if [ "$DISTMP3NICE" ]; then
4886 DISTMP3NICE="-n $DISTMP3NICE"
4889 # Don't check for stuff if it's not needed
4890 if [ "$REMOTEHOSTS" ]; then
4893 if [ "$DONORMALIZE" = "y" ]; then
4896 if [ "$EJECTCD" = "y" ]; then
4899 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4900 # Need an http tool to be able to do CDDB
4906 if [ "$DOCUE" = "y" ]; then
4910 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4911 case "$CDROMREADERSYNTAX" in
4912 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4913 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4914 ### FIXME ### translate "cue2discid" from python to bash
4915 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4920 if [ "$GETALBUMART" = "y" ]; then
4925 ###USEPIPESSUPPORT###
4927 # Rippers with USEPIPE support
4928 PIPERIPPER_cdparanoia="-"
4929 PIPERIPPER_libcdio="-"
4930 # Note that by default in abcde cdda2wav redirects to icedax.
4931 PIPERIPPER_cdda2wav="-"
4932 PIPERIPPER_debug="-"
4933 PIPERIPPER_flac="-c "
4936 # Encoders with USEPIPE support
4939 PIPE_bladeenc="stdin"
4952 # Both neroAacEnc and fdkaac seem to manage without the addition of
4953 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4954 # in this manner. Andrew.
4958 # Figure out if we can use pipes with the ripper/encoder combination
4960 if [ "$USEPIPES" = "y" ]; then
4961 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4964 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4966 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4968 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4970 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4972 PIPEENCODERSVARCHECK="PIPE_$AIFFENCODERSYNTAX" ;;
4974 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4976 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4978 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4980 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4982 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4984 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4986 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4988 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4989 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4990 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4991 log error "no support for pipes with given ripper"
4992 log error "read the FAQ file from the source tarball to get help."
4995 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4996 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4997 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4998 log error "no support for pipes with given encoder"
4999 log error "read the FAQ file from the source tarball to get help"
5004 # Make sure a buncha things exist
5005 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
5006 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
5007 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER $AIFFENCODER \
5008 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
5009 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
5010 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
5011 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
5012 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
5013 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
5014 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
5015 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
5016 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
5017 ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
5022 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
5023 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
5024 # these files). The resulting files are actually ADTS streams which belong in an
5025 # aac container and with some version sniffing this is all cleaned up below. If
5026 # faac is compiled with libmp4v2 inline tagging occurs with faac.
5028 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
5029 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
5030 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
5031 echo "WARNING: Your copy of Faac does not have mp4 support"
5032 echo "WARNING: Encoding untagged files to aac..."
5033 # Replace m4a with aac for single and multi-output encodes:
5034 OUTPUTTYPE=$(echo "$OUTPUTTYPE" | sed 's/m4a/aac/')
5036 echo "Using Faac to Tag AAC Tracks..."
5040 # And last but not least, check if we can diff between files. We do not abort,
5041 # since diffing is not critical...
5042 if [ -x "$(which "$DIFF")" ]; then :; else
5043 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
5047 ## Now that we have metaflac, check if we need cue2discid
5048 #case $CDROMREADERSYNTAX in
5050 # CDDBTRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
5051 # if [ "$CDDBTRACKINFO" = "" ]; then
5052 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
5057 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
5058 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
5059 HTTPGET="$HTTPGET $HTTPGETOPTS"
5061 # Here it used to say:
5062 # One thousand lines in, we can start doing stuff with things
5063 # Well, right now we are at line 3737 ;)
5064 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
5066 # Export needed things so they can be read in this subshell
5067 export CDDBTOOL # Path and options for the tool to query CDDB
5068 export ABCDETEMPDIR # Path to the tmpdir for this rip
5069 export TRACKQUEUE # 0-padded list of tracks to be processed
5070 export LOWDISK # Are we using the low-diskspace algorithm?
5071 export EJECTCD # Should we eject the CD when we're finished ripping?
5072 export EJECT # The commend to use to eject the CD, if we have one
5073 export EJECTOPTS # Options to that command
5074 export CDROM # Device path for the CD device
5075 export CDDBDATA # The filename we're using for CD lookup data
5076 export REMOTEHOSTS # List of remote hosts for parallel encoding, if given
5077 export MAXPROCS # The number of *local* encodes to do in parallel
5078 export HTTPGET # Program to use to grab files via http
5079 export MD5SUM # Program to calculate MD5 checksums
5081 if [ "$DOREAD" = "y" ]; then
5082 # User-definable function to set some things. Use it for
5083 # - closing the CD tray with eject -t
5084 # - set the CD speed value with eject -x
5085 vecho -n "Executing customizable pre-read function... "
5087 pre_read # Execute the user-defined pre-read function. Close the CD with it.
5092 # Get ABCDETEMPDIR created and status file initialized
5095 if [ "$DOCDDB" = "y" ]; then
5096 # start with a sane default:
5097 CDDBLOCALSTATUS=notfound
5098 if [ $CDDBUSELOCAL = "y" ]; then
5101 if checkstatus cddb-choice > /dev/null; then
5105 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
5107 for CDDBMETHCHOICE in $(echo "$CDDBMETHOD" | tr -d ' ' | tr , ' ')
5109 addstatus "Lookup method $idx: $CDDBMETHCHOICE"
5111 vecho "Found $NUM_CDDB_MATCHES matches so far"
5112 vecho "Trying lookup method ${CDDBMETHCHOICE}"
5114 # Run all the desired data acquisition methods, in the order
5115 # specified by the user. Each will use its own temporary
5116 # subdirectory, then copy the cddbread.* etc. files up into
5118 case "$CDDBMETHCHOICE" in
5129 echo "Unknown lookup method $CDDBMETHCHOICE. Aborting." >&2
5136 rm -f "${ABCDETEMPDIR}/cddbchoices"
5137 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
5139 if [ $NUM_CDDB_MATCHES = 0 ]; then
5140 # If we got no matches, we need to
5141 # generate a blank CDDB template.
5142 vecho "Unable to find any matches, generating unknown template."
5143 echo "No lookup matches." >> "${ABCDETEMPDIR}/cddbchoices"
5144 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
5145 echo "template" > "${ABCDETEMPDIR}/datasource.0"
5146 # List out disc title/author and contents of template
5147 echo ---- Unknown Artist / Unknown Album ---- >> "${ABCDETEMPDIR}/cddbchoices"
5149 for TRACK in $(f_seq_row 1 $TRACKS)
5151 echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5153 echo >> "${ABCDETEMPDIR}/cddbchoices"
5154 echo cddb-read-0-complete >> "${ABCDETEMPDIR}/status"
5155 echo cddb-choice=0 >> "${ABCDETEMPDIR}/status"
5156 echo 503 > "${ABCDETEMPDIR}/cddbquery"
5158 # We have matches; create the cddbchoices and cddbquery
5159 # files from all the inputs we have
5160 if [ $NUM_CDDB_MATCHES = 1 ]; then
5161 echo "Retrieved 1 match..." >> "${ABCDETEMPDIR}/cddbchoices"
5162 echo -n "200 " > "${ABCDETEMPDIR}/cddbquery"
5163 cat "${ABCDETEMPDIR}/cddbquery.1" >> "${ABCDETEMPDIR}/cddbquery"
5165 echo "Retrieved $NUM_CDDB_MATCHES matches..." >> "${ABCDETEMPDIR}/cddbchoices"
5166 echo "210 Found exact matches, list follows (until terminating .)" > "${ABCDETEMPDIR}/cddbquery"
5167 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5169 cat "${ABCDETEMPDIR}/cddbquery.$X" >> "${ABCDETEMPDIR}/cddbquery"
5171 echo "." >> "${ABCDETEMPDIR}/cddbquery"
5174 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5176 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.$X" | cut -c8- | tr -d \\r\\n)
5177 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$X")
5178 echo "#$X ($SOURCE): ---- ${ATITLE} ----" >> "${ABCDETEMPDIR}/cddbchoices"
5179 for TRACK in $(f_seq_row 1 $TRACKS)
5181 echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5183 echo >> "${ABCDETEMPDIR}/cddbchoices"
5190 eval "$($CDDBTOOL parse "$CDDBDATA")"
5193 # Before reading tracks, we set the speed of the device
5195 if [ X"$CDSPEEDVALUE" != "X" ]; then
5196 case "$CDROMREADERSYNTAX" in
5197 cdparanoia|libcdio|debug) ;;
5204 # Define the first and last track, since we might need them later in several places
5205 FIRSTTRACK=$( get_first $TRACKQUEUE )
5206 LASTTRACK=$( get_last $TRACKQUEUE )
5208 if [ -f "${ABCDETEMPDIR}/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
5209 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
5210 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
5211 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
5214 if checkstatus onetrack ; then ONETRACK=y ; fi
5216 if [ "$ONETRACK" = "y" ]; then
5217 # Reuse the CUEFILE in case we created it (now or in a previous run)
5218 if CUEFILE=$(checkstatus cuefile); then
5223 # Create playlist if needed (backgroundable) and start reading in tracks
5227 if [ ! "$ONETRACK" = "y" ]; then
5228 if [ "$DOPLAYLIST" = "y" ]; then
5229 echo Creating playlist... >&2
5234 if [ "$GETALBUMART" = "y" ]; then
5238 # For the lowdisk option, only one program is running at once so the encoder
5239 # can be unsilenced right away.
5240 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
5241 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5244 if [ "$ONETRACK" = "y" ]; then
5246 if [ "$USEPIPES" = "y" ]; then
5247 if checkstatus "readencodetrack-$FIRSTTRACK"; then :; else
5248 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
5251 if checkstatus "readtrack-$FIRSTTRACK"; then :; else
5252 do_cdread onetrack $FIRSTTRACK $LASTTRACK
5256 for UTRACKNUM in $TRACKQUEUE
5258 if [ "$DOREAD" = "y" ]; then
5259 if [ "$USEPIPES" = "y" ]; then
5260 if checkstatus "readencodetrack-$UTRACKNUM"; then :; else
5261 # Read, pipe, shut up!
5262 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
5265 if checkstatus "readtrack-$UTRACKNUM"; then :; else
5266 do_cdread $UTRACKNUM
5268 if [ "$?" != "0" ]; then
5269 # CD read failed - don't give the goahead to
5276 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
5279 # If we are not reading, set the encode output to loud already, so
5280 # that we can see the output of the first track.
5281 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
5282 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5284 echo NEXTTRACK # Get the encoder machine churning again
5285 if [ "$DOREAD" = "y" ]; then
5286 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
5287 until checkstatus "encodetrack-$UTRACKNUM"
5289 if checkerrors "encodetrack-$UTRACKNUM"; then
5300 # Now that we're done the encoding can be loud again -
5301 # if we're not using SMP.
5302 if [ "$MAXPROCS" = "1" ]; then
5303 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5306 # All tracks read, start encoding.
5307 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
5311 # Execute the user-defined post_read function before ejecting CD
5314 # We are now finished with the cdrom - it can be safely ejected. Note that
5315 # abcde will not have completed yet.
5316 if [ "$EJECTCD" = "y" ]; then
5317 # We check if the disk we are processing is actually the disk inside the
5318 # CD tray. If not, we do not eject the CD, since it might be so that the
5319 # user ejected it manually.
5320 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
5321 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$CDDBTRACKINFO" ] ; then
5322 # More FreeBSD bits.
5323 if [ X"$UNAME" = X"FreeBSD" ] ; then
5324 # FreeBSD eject uses the EJECT environment variable to name the CDROM
5325 # but in this script EJECT is in the envionment and names the program
5328 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
5329 cd="$(echo "$CDROM" | sed -e 's=.*/==;s=[a-h]$==;')"
5330 $eject $EJECTOPTS $cd
5331 elif [ X"$UNAME" = X"Darwin" ] ; then
5332 diskutil eject "${CDROM#/dev/}" 0
5333 elif [ -x "$(which "$EJECT")" ]; then
5334 $EJECT $EJECTOPTS "$CDROM"
5341 ## Do we need to pre-process
5342 #if [ x"$PREPROCESS" = "x" ] ; then
5345 # for PRETRACKNUM in $TRACKQUEUE
5348 # if [ "$GOAHEAD" = "NO" ]; then break; fi
5350 # until [ $PREPROCEED ]
5352 # if checkstatus "readtrack-$PRETRACKNUM"; then PREPROCEED=y; break; fi
5353 # # all locations are working, wait and try again later
5354 # if [ ! $PREPROCEED ]; then sleep 3; fi
5356 # ( do_preprocess $PRETRACKNUM
5364 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
5366 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
5367 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5368 if [ "$GOAHEAD" != "NO" ]; then
5369 for LASTTRACK in $TRACKQUEUE; do :; done
5370 if checkstatus "readtrack-$LASTTRACK"; then
5371 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
5372 if checkstatus "normalizetrack-$LASTTRACK"; then :; else do_batch_normalize; fi
5373 if checkerrors batch-normalize; then exit 1; fi
5375 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
5376 if [ "$DONORMALIZE" = "y" ]; then
5377 for UTRACKNUM in $TRACKQUEUE
5379 if checkstatus "readtrack-$UTRACKNUM"; then
5380 if checkstatus "normalizetrack-$UTRACKNUM"; then :; else do_normalize "$UTRACKNUM"; fi
5384 if checkstatus "encodetrack-$LASTTRACK"; then :; else do_nogap_encode; fi
5385 if checkerrors nogap-encode; then exit 1; fi
5391 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
5392 if [ "$ONETRACK" = "y" ] ; then
5393 TRACKQUEUE="$FIRSTTRACK"
5394 TRACKS="$FIRSTTRACK"
5397 # Do the encoding, including parallelization of remote encoding
5398 # Figure out where each track is going to be encoded
5399 ENCODELOCATIONS="$(echo "$REMOTEHOSTS" | tr , ' ')"
5400 if [ "$MAXPROCS" != "0" ]; then
5401 for NUM in $(f_seq_row 1 $MAXPROCS)
5403 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5407 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5408 for UTRACKNUM in $TRACKQUEUE
5411 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5412 if [ "$GOAHEAD" = "NO" ]; then break; fi
5413 # find out where this track is to be encoded
5414 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ]; then
5415 # Make sure we have a place to encode this, if not, exit stage right
5416 if [ -z "$ENCODELOCATIONS" ]; then
5422 for LOCATION in $ENCODELOCATIONS
5424 PREVIOUSTRACK="$(checkstatus "encodetracklocation-$LOCATION")"
5425 # check first if a track has ever been assigned to this location
5426 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5427 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5428 if checkerrors "encodetrack-$PREVIOUSTRACK"; then
5429 for TEMPLOCATION in $ENCODELOCATIONS
5431 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5432 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5435 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5440 # We're still here, this location must have been previously assigned,
5441 # and last completed without error - check if it's done with the
5442 # previous track yet
5443 if checkstatus "encodetrack-$PREVIOUSTRACK"; then PROCEED=y; break; fi
5445 # all locations are working, wait and try again later
5446 if [ ! "$PROCEED" ]; then sleep 3; fi
5448 # Record the location we're about to encode the next track at
5449 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
5451 # Don't proceed with the rest of the loop if we can't encode
5452 if [ "$ABORT" ]; then continue; fi
5453 ## FIXME ## Add here
5454 ## run_command "tagtrack-$OUTPUT-$1" $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
5455 # Set TRACKNUM, TRACKNAME
5456 if [ -e "$CDDBDATA" ]; then
5457 if [ "$ONETRACK" = "y" ]; then
5459 TRACKNUM="$FIRSTTRACK"
5462 TRACKNUM="$UTRACKNUM"
5463 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
5464 getcddbinfo TRACKNAME
5468 # You can't encode a file which needs to be normalized before finishing
5469 # You can't tag a file before it's finished encoding -
5470 # thus all of this is backgrounded together
5472 if [ "$DONORMALIZE" = "y" ]; then
5473 if checkstatus "readtrack-$UTRACKNUM"; then
5474 if checkstatus "normalizetrack-$UTRACKNUM"; then :; else do_normalize "$UTRACKNUM"; fi
5477 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ]; then
5478 if checkstatus "readtrack-$UTRACKNUM"; then
5479 if [ "$DONORMALIZE" = "y" ]; then
5480 if checkstatus "normalizetrack-$UTRACKNUM"; then
5481 if checkstatus "encodetrack-$UTRACKNUM"; then :; else do_encode "$UTRACKNUM" "$LOCATION" "$OUTPUT"; fi
5484 if checkstatus "encodetrack-$UTRACKNUM"; then :; else do_encode "$UTRACKNUM" "$LOCATION" "$OUTPUT"; fi
5488 if [ "$DOTAG" = "y" ]; then
5489 if checkstatus "encodetrack-$UTRACKNUM"; then
5490 if checkstatus "tagtrack-$UTRACKNUM"; then :; else do_tag "$UTRACKNUM"; fi
5492 # Lets tag the cue file
5493 if checkstatus cleancuefile >/dev/null; then :; else
5494 if checkstatus cuefile >/dev/null ; then
5499 if [ "$DOMOVE" = "y" ]; then
5500 if checkstatus "tagtrack-$UTRACKNUM"; then
5501 if checkstatus "movetrack-$UTRACKNUM"; then :; else do_move "$UTRACKNUM"; fi
5508 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5509 # we'll delete the files they're working on
5510 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5511 ## FIXME ## Check also for files which are encoded using PIPEs.
5512 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5517 for LOCATION in $ENCODELOCATIONS
5519 CHECKTRACK="$(checkstatus "encodetracklocation-$LOCATION")"
5520 # "How can he give us a status update, if he's DEAD?"
5521 if checkstatus "encodetrack-$CHECKTRACK"; then
5524 # Nothing to see here please go quietly back to your homes
5525 if [ -z "$CHECKTRACK" ]; then continue; fi
5526 # You're still here? Maybe there is something...
5527 if checkstatus "encodetrack-$CHECKTRACK"; then :; else PROCEED= ; break; fi
5530 if [ ! $PROCEED ]; then sleep 5; fi
5533 # If the above didn't catch the stragglers, this will
5535 if [ "$DOREPLAYGAIN" = "y" ]; then
5539 if [ "$EMBEDALBUMART" = "y" ]; then
5543 # Execute the user-defined post_encode function before cleaning up
5546 # Check to see if run_command logged any errors
5547 if [ -f "${ABCDETEMPDIR}/errors" ]; then
5548 log error "The following commands failed to run:"
5549 cat "${ABCDETEMPDIR}/errors"
5553 if [ "$KEEPWAVS" = "y" ];then
5557 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5558 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5559 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5560 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5561 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5562 log warning "The encoded formats does not match with the moved ones"
5563 log warning "Formats encoded: $( echo "$ENCODED_FORMATS" | tr "|" " " )"
5564 log warning "Formats moved: $( echo "$MOVED_FORMATS" | tr "|" " " )"
5565 log warning "Use \"abcde -a clean -f -C ${CDDBDISCID}\" to force the removal of the remaining data."
5569 if [ "$DOCLEAN" = "y" ]; then
5570 # Wipe all the evidence
5571 # Gimme gimme gimme some more time!
5573 rm -rf "${ABCDETEMPDIR}"
5576 echo "Finished. Not cleaning ${ABCDETEMPDIR}."