2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
5 # Copyright (c) 2012-2018 Steve McIntyre <93sam@@debian.org>
6 # Copyright (c) 2015-2017 Andrew Strong <andrew.david.strong@gmail.com>
7 # This code is hereby licensed for public consumption under either the
8 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
10 # You should have received a copy of the GNU General Public License along
11 # with this program; if not, write to the Free Software Foundation, Inc.,
12 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14 VERSION='2.8.2-UNRELEASED'
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform, comma separated:"
24 echo " (cddb,read,getalbumart,embedalbumart,normalize,encode,"
25 echo " tag,move,replaygain,playlist,clean)"
26 #echo "-A Experimental actions (retag, transcode)"
27 echo "-b Enable batch normalization"
28 echo "-B Embed albumart (this also activates getalbumart)"
30 echo " Specify a configuration file (overrides system and user config files)"
32 echo " Specify discid to resume from (only needed if you no longer have the cd)"
34 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
35 echo "-D Debugging mode (equivalent to sh -x abcde)"
36 echo "-e Erase encoded track information from status file"
37 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
38 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
39 echo "-G Get album art by using the 'getalbumart' action"
40 echo "-h This help information"
41 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
42 echo "-j <#> Number of encoder processes to run at once (localhost)"
43 echo "-k Keep the wav tracks for later use"
44 echo "-l Use low disk space algorithm"
45 echo "-L Use local CDDB storage directory"
46 echo "-m Modify playlist to include CRLF endings, to comply with some players"
47 #echo " WARNING: Deprecated. Use \"cue\" action"
48 #echo "-M Create a CUE file"
49 echo "-n No lookup. Don't query CDDB, just create and use template"
50 echo "-N Noninteractive. Never prompt for anything"
51 echo "-o <type1[,type2]...>"
52 echo " Output file type(s), comma separated"
53 echo " (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,mka,wv,ape,mp2,tta,aiff)."
54 echo " Defaults to vorbis"
55 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
56 echo "-P Use UNIX pipes to read+encode without wav files"
57 echo "-Q CD lookup method(s), comma separated"
58 echo " (musicbrainz,cddb,cdtext). Defaults to musicbrainz".
59 echo "-r <host1[,host2]...>"
60 echo " Also encode on these remote hosts"
62 echo " Show fields from the CDDB info (year,genre)"
63 echo "-S <#> Set the CD speed"
64 echo "-t <#> Start the track numbering at a given number"
65 echo "-T <#> Same as -t but modifies tag numbering"
66 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
67 echo "-v Show version number and exit"
68 echo "-V Be a bit more verbose about what is happening behind the scenes"
69 echo "-x Eject CD after all tracks are read"
71 echo " Add a comment to the CD tracks"
72 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
73 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
75 echo "Tracks is a space-delimited list of tracks to grab."
76 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
78 #echo "Double hyphens are used to concatenate tracks"
83 echo "$@" >> "${ABCDETEMPDIR}/status"
86 # log [level] [message]
88 # log outputs the right message in a common format
94 error) >&2 echo "[ERROR] abcde: $@" >&2 ;;
95 warning) >&2 echo "[WARNING] $@" >&2 ;;
96 info) >&4 echo "[INFO] $@" ;;
100 # Functions to replace the need of seq, which is too distribution dependent.
114 if echo "$i" | grep "[[:digit:]]" > /dev/null 2>&1 ; then
122 log error "syntax error while processing track numbers ($i)"
127 # Functions to replace the need of awk {print $1} and {print $NF}
130 if [ X"$1" = "X" ]; then
131 for first in $(cat); do
142 if [ X"$1" = "X" ]; then
143 for stdin in $(cat); do
147 for last in $@ ; do :; done
152 # checkstatus [blurb]
153 # Returns "0" if the blurb was found, returns 1 if it wasn't
154 # Puts the blurb content, if available, on stdout.
155 # Otherwise, returns "".
158 # Take the last line in the status file if there's multiple matches
160 BLURB=$(grep -E "$PATTERN" "${ABCDETEMPDIR}/status" | tail -n 1)
162 if [ -z "$BLURB" ]; then
167 # See if there's a = in it
168 if ( echo "$BLURB" | grep -q '=' ); then
169 echo "$BLURB" | cut -f2- -d=
175 # checkwarnings [blurb]
176 # Returns "0" if the blurb was found (meaning there was an warning),
177 # returns 1 if it wasn't (yes this is a little backwards).
178 # Does not print the blurb on stdout.
179 # Otherwise, returns "".
182 if [ -e "${ABCDETEMPDIR}/warnings" ]; then :; else
185 # Take the last line in the status file if there's multiple matches
187 BLURB=$(grep -E "$PATTERN" "${ABCDETEMPDIR}/warnings" | tail -n 1)
189 if [ -z "$BLURB" ]; then
190 # negative, we did not have a negative...
193 # affirmative, we had a negative...
198 # checkerrors [blurb]
199 # Returns "0" if the blurb was found (meaning there was an error),
200 # returns 1 if it wasn't (yes this is a little backwards).
201 # Does not print the blurb on stdout.
202 # Otherwise, returns "".
205 if [ -e "${ABCDETEMPDIR}/errors" ]; then :; else
208 # Take the last line in the status file if there's multiple matches
210 BLURB=$(grep -E "$PATTERN" "${ABCDETEMPDIR}/errors" | tail -n 1)
212 if [ -z "$BLURB" ]; then
213 # negative, we did not have a negative...
216 # affirmative, we had a negative...
222 # Display a file. If it's too long to fit the current terminal size,
223 # find the right pager in the system and use it
227 local NUM_LINES=$(wc -l < "$PAGEFILE")
229 # Is the text long enough to need a pager?
230 if [ "$NUM_LINES" -ge $LINES ]; then
232 # Use the debian sensible-pager wrapper to pick the pager user
233 # has requested via their $PAGER environment variable
234 if [ -x "/usr/bin/sensible-pager" ]; then
235 /usr/bin/sensible-pager "$PAGEFILE"
236 elif [ -x "$PAGER" ]; then
237 # That failed, try to load the preferred pager, starting
238 # with their PAGER variable
240 # If that fails, check for less
241 elif [ -x /usr/bin/less ]; then
242 /usr/bin/less -f "$PAGEFILE"
243 # more should be on all UNIX systems
244 elif [ -x /bin/more ]; then
245 /bin/more "$PAGEFILE"
247 # No bananas, just cat the thing
251 # No, just cat the thing
256 # run_command [blurb] [command...]
257 # Runs a command, silently if necessary, and updates the status file
263 # See if this is supposed to be silent
264 if [ "$(checkstatus encode-output)" = "loud" ]; then
268 # Special case for SMP, since
269 # encoder output is never displayed, don't mute echos
270 if [ -z "$BLURB" ] && [ "$MAXPROCS" != "1" ]; then
279 normalize|normalize-audio)
280 if [ "$RETURN" = "2" ]; then
281 # File was already normalized.
286 if [ "$RETURN" != "0" ]; then
287 # Put an error in the errors file. For various reasons we
288 # can't capture a copy of the program's output but we can
289 # log what we attempted to execute and the error code
290 # returned by the program.
291 if [ "$BLURB" ]; then
294 echo "${TWEAK}returned code $RETURN: $@" >> "${ABCDETEMPDIR}/errors"
295 return $RETURN # Do not pass go, do not update the status file
297 if [ "$BLURB" ]; then
298 echo "$BLURB" >> "${ABCDETEMPDIR}/status"
302 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
303 # distributed under the terms of the GNU GPL v2 or later, at your option
305 # Function to determine if a word contains a slash.
314 # Function to give the relative path from one file to another.
315 # Usage: relpath fromfile tofile
316 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
317 # (the result would be Album/Song.mp3)
318 # Output is relative path to $2 from $1 on stdout
320 # This code has the following restrictions:
321 # Multiple ////s are not collapsed into single /s, with strange effects.
322 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
323 # If FR is a directory it must have a trailing /
331 /*) ;; # No processing is needed for absolute paths
333 # Loop through common prefixes, ignoring them.
334 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
336 FR="$(echo "$FR" | cut -d/ -f2-)"
337 TO="$(echo "$TO" | cut -d/ -f2-)"
339 # Loop through directory portions left in FR, adding appropriate ../s.
342 FR="$(echo "$FR" | cut -d/ -f2-)"
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X=$(echo "$@" | cut -d' ' -f2)
356 WHICH=$(which "$X" 2>/dev/null)
357 if [ -z "$WHICH" ]; then
359 elif [ ! -x "$WHICH" ]; then
368 if [ ! "$@" = "" ]; then
369 # Cut off any command-line option we added in
370 X=$(echo "$@" | cut -d' ' -f2)
371 # Test for built-in abcde.function
372 [ "$X" != "${X#abcde.}" ] && type "$X" >/dev/null 2>&1 && return
373 WHICH=$(which "$X" 2>/dev/null)
374 if [ -z "$WHICH" ]; then
375 log error "$X is not in your path." >&2
376 log info "Define the full path to the executable if it exists on your system." >&2
377 if [ -e /etc/debian_version ] ; then
380 MISSING_PACKAGE=vorbis-tools
382 lame|flac|cd-discid|eject|mkcue|icedax|glyrc)
386 log info "Hint: sudo apt-get install $MISSING_PACKAGE" >&2
389 elif [ ! -x "$WHICH" ]; then
390 log error "$X is not executable." >&2
396 # diffentries <filename> <max_value> <entry1>,<entry2>
397 # max_value: the range of entries goes from 1 to <max_value>
402 local CDDBDIFFCHOICES=$1
404 local CDDBDIFFCHOICE="$@"
405 if [ ! X"$DIFF" = "X" ]; then
406 PARSECHOICE1=$(echo "$CDDBDIFFCHOICE" | cut -d"," -f1 | xargs printf %d 2>/dev/null)
407 PARSECHOICE2=$(echo "$CDDBDIFFCHOICE" | cut -d"," -f2 | xargs printf %d 2>/dev/null)
408 if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$CDDBDIFFCHOICES" ] || \
409 [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$CDDBDIFFCHOICES" ] || \
410 [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
411 echo "Invalid diff range." >&2
412 echo "Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
414 # We parse the 2 choices to diff, store them in temporary files and diff them.
415 for PARSECHOICE in $(echo "$CDDBDIFFCHOICE" | tr , \ ); do
416 do_cddbparse "${ABCDETEMPDIR}/$FILENAME.$PARSECHOICE" > "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE"
418 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "${ABCDETEMPDIR}/$FILENAME.diff"
419 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE1" \
420 "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/$FILENAME.diff"
421 page "${ABCDETEMPDIR}/$FILENAME.diff"
424 echo "The diff program was not found in your path." >&2
425 echo "Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
430 # Finds an specific field from cddbinfo
435 TRACKNAME="$(grep -a "^TTITLE$CDDBTRACKNUM=" "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
438 TRACKNAME="$(grep -a "^TTITLE$CDDBTRACKNUM=" "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
441 grep -a "^EXTT$CDDBTRACKNUM=" "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
447 # Get the track number we are going to use for different actions
450 if [ -n "$STARTTRACKNUMBER" ] ; then
451 # Get the trackpadding from the current track, also trim whitespace for MacOSX
452 CURRENTTRACKPADDING=$(echo -n "$UTRACKNUM" | wc -c | tr -d ' ')
453 TRACKNUM=$( printf %0."${CURRENTTRACKPADDING}"d $(("${UTRACKNUM}" + "${STARTTRACKNUMBER}" - "${FIRSTTRACK}")))
455 TRACKNUM="${UTRACKNUM}"
461 # Calculate cddb disc ids without requiring specialized helper programs.
462 # largely copied from cd-discid and musicbrainz examples. some of the steps
463 # don't make sense, but they're necessary to match the ids generated by other
466 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
467 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
468 # processing offsetimes 00:00:00 04:47:10 08:20:37 11:46:46 17:45:36 21:41:57 27:32:21 32:03:73 35:39:28 38:27:33 43:50:38 44:42:34
469 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
470 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
471 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
473 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
476 if [ X"$LEADOUT" = "X" ]; then
477 log warning "Error trying to calculate disc ids without lead-out information."
481 # default to a two second lead-in
483 LEADIN=${LEADIN:=150}
485 # number of cdframes per second
488 # reset cddb checksum for cddb disc-id calululation
492 for OFFSET in $OFFSETS
494 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
496 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
497 while [ $OFFSETTIME -gt 0 ]; do
498 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
499 OFFSETTIME=$(($OFFSETTIME / 10))
504 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
506 PREGAP=$(echo $OFFSETS | cut -f1 -d' ')
507 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
509 vvecho "makeids: PREGAP $PREGAP, LEADIN $LEADIN, LEADOUT $LEADOUT"
511 # Calculate both the cddb discid *and* the musicbrainz discid
512 # now. We'll use the cddb discid for reference in most cases
513 # for consistency, but we also have the musicbrainz discid for
515 printf -v CDDBDISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
516 CDDBTRACKINFO="${CDDBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
520 # FIXME: don't assume the first track is 1
521 MBDISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $(($PREGAP + $LEADOUT)) $OFFSETS)
523 if [ $error != 0 ]; then
524 log error "$MUSICBRAINZ failed to run; ABORT"
527 MBTRACKINFO="${MBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
534 if checkstatus replaygain; then :; else
535 run_command "" echo "Adding replaygain information..."
536 for TMPOUTPUT in $( echo "$OUTPUTTYPE" | tr , \ )
540 OUTPUT=$OGGOUTPUTCONTAINER
543 OUTPUT=$OPUSOUTPUTCONTAINER
546 OUTPUT=$FLACOUTPUTCONTAINER
554 for UTRACKNUM in $TRACKQUEUE
556 CDDBTRACKNUM=$(expr "$UTRACKNUM" - 1) # Unpad
557 getcddbinfo TRACKNAME
559 TRACKFILE="$(mungetrackname "$TRACKNAME")"
560 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
561 ALBUMFILE="$(mungealbumname "$DALBUM")"
562 GENRE="$(mungegenre "$GENRE")"
563 YEAR=${CDYEAR:-$CDYEAR}
565 if [ "$ONETRACK" = "y" ]; then
566 if [ "$VARIOUSARTISTS" = "y" ]; then
567 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
569 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
572 if [ "$VARIOUSARTISTS" = "y" ]; then
573 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
575 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
578 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
579 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
583 run_command "replaygain-flac" nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
586 run_command "replaygain-vorbis" nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
589 run_command "replaygain-mp3" nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
592 run_command "replaygain-mpc" nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
595 run_command "replaygain-wv" nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
600 if checkerrors "replaygain-.{3,6}"; then :; else
601 run_command "replaygain" true
606 # This code splits the a Various Artist track name from one of the following
609 # forward: Artist / Track
610 # forward-dash: Artist - Track
611 # reverse: Track / Artist
612 # reverse-dash: Track - Artist
613 # colon: Artist: Track
614 # trailing-paren: Artist (Track)
617 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
620 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
621 case "$VARIOUSARTISTSTYLE" in
623 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
624 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
625 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
628 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
629 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
630 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
633 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
634 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
635 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
638 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
639 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
640 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
643 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
644 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
645 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
648 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
649 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
650 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
653 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
654 TRACKARTIST="Various"
656 TRACKARTIST="$DARTIST"
661 local genre=$(echo "${@}" | tr 'A-Z' 'a-z')
665 "classic rock") id=1 ;;
683 "industrial") id=19 ;;
684 "alternative") id=20 ;;
686 "death metal") id=22 ;;
688 "soundtrack") id=24 ;;
689 "euro-techno") id=25 ;;
693 "jazz+funk") id=29 ;;
696 "classical") id=32 ;;
697 "instrumental") id=33 ;;
701 "sound clip") id=37 ;;
704 "alt. rock") id=40 ;;
709 "meditative") id=45 ;;
710 "instrum. pop") id=46 ;;
711 "instrum. rock") id=47 ;;
715 "techno-indust.") id=51 ;;
716 "electronic") id=52 ;;
718 "eurodance") id=54 ;;
720 "southern rock") id=56 ;;
725 "christian rap") id=61 ;;
726 "pop/funk"|"pop / funk") id=62 ;;
728 "native american") id=64 ;;
731 "psychadelic") id=67 ;;
733 "showtunes") id=69 ;;
737 "acid punk") id=73 ;;
738 "acid jazz") id=74 ;;
742 "rock & roll") id=78 ;;
743 "hard rock") id=79 ;;
745 "folk/rock") id=81 ;;
746 "national folk") id=82 ;;
753 "bluegrass") id=89 ;;
754 "avantgarde") id=90 ;;
755 "gothic rock") id=91 ;;
756 "progress. rock") id=92 ;;
757 "psychadel. rock") id=93 ;;
758 "symphonic rock") id=94 ;;
759 "slow rock") id=95 ;;
762 "easy listening") id=98 ;;
768 "chamber music") id=104 ;;
770 "symphony") id=106 ;;
771 "booty bass") id=107 ;;
773 "porn groove") id=109 ;;
775 "slow jam") id=111 ;;
779 "folklore") id=115 ;;
781 "power ballad") id=117 ;;
782 "rhythmic soul") id=118 ;;
783 "freestyle") id=119 ;;
785 "punk rock") id=121 ;;
786 "drum solo") id=122 ;;
787 "a capella") id=123 ;;
788 "euro-house") id=124 ;;
789 "dance hall") id=125 ;;
791 "drum & bass") id=127 ;;
792 "club-house") id=128 ;;
793 "hardcore") id=129 ;;
797 "negerpunk") id=133 ;;
798 "polsk punk") id=134 ;;
800 "christian gangsta rap") id=136 ;;
801 "heavy metal") id=137 ;;
802 "black metal") id=138 ;;
803 "crossover") id=139 ;;
804 "contemporary christian")id=140 ;;
805 "christian rock") id=141 ;;
806 "merengue") id=142 ;;
808 "thrash metal") id=144 ;;
811 "synthpop") id=147 ;;
812 "rock/pop"|"rock / pop") id=148 ;;
819 # do_tag [tracknumber]
820 # id3 tags a filename
822 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
823 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
826 COMMENTOUTPUT="$(eval echo "${COMMENT}")"
827 if [ -z "$COMMENTOUTPUT" ]; then
828 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
830 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
831 run_command "" echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
832 # If we want to start the tracks with a given number, we need to modify the
833 # TRACKNUM value before evaluation
834 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
837 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
841 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
842 GENREID=$(do_getgenreid "${CDGENRE}")
843 # Set TPE2 in case we have a Various Artists rip.
845 if [ "$VARIOUSARTISTS" = "y" ]; then
851 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
852 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
853 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
854 -y "$CDYEAR" -g "$GENREID" \
855 -T "${TRACKNUM:-$1}" \
856 "${ABCDETEMPDIR}/track$1.$OUTPUT"
859 # FIXME # track numbers in mp3 come with 1/10, so we cannot
860 # happily substitute them with $TRACKNUM
861 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
862 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
863 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
864 -y "$CDYEAR" -g "$GENREID" \
865 -T "${TRACKNUM:-$1}/$TRACKS" \
866 ${TPE2:+--TPE2 "$TPE2"} \
867 "${ABCDETEMPDIR}/track$1.$OUTPUT"
870 # FIXME # track numbers in mp3 come with 1/10, so we cannot
871 # happily substitute them with $TRACKNUM
872 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
873 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
874 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
875 -y "$CDYEAR" -g "$GENREID" \
876 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
877 "${ABCDETEMPDIR}/track$1.$OUTPUT"
880 # FIXME # track numbers in mp3 come with 1/10, so we cannot
881 # happily substitute them with $TRACKNUM
883 eyed3_06) addopts=( \
884 ${ENCODING:+--set-encoding="$ENCODING"} \
885 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
886 # We set 'recording-date' so the date tag will show
887 # in Audacious, vlc and friends... Andrew.
888 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
889 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
892 ${ENCODING:+--encoding="$ENCODING"} \
893 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
894 # We set 'recording-date' so the date tag will show
895 # in Audacious, vlc and friends... Andrew.
896 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
897 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
900 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $TAGGER $TAGGEROPTS \
902 -a "$TRACKARTIST" -t "$TRACKNAME" \
903 -G "$GENREID" -n "${TRACKNUM:-$1}" \
904 ${TRACKNUM:+-N "$TRACKS"} \
906 "${ABCDETEMPDIR}/track$1.$OUTPUT"
909 log error "Internal error: ID3SYNTAX has an illegal value"
915 case "$OGGENCODERSYNTAX" in
917 # vorbiscomment can't do in-place modification, mv the file first
918 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ] && \
919 [ ! -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
920 mv "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" \
921 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
925 # https://www.xiph.org/vorbis/doc/v-comment.html
927 echo ARTIST="$TRACKARTIST"
929 echo TITLE="$TRACKNAME"
930 if [ -n "$CDYEAR" ]; then
933 if [ -n "$CDGENRE" ]; then
934 echo GENRE="$CDGENRE"
936 echo TRACKNUMBER="${TRACKNUM:-$1}"
937 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
938 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
939 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
940 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
941 echo TRACKTOTAL="${TRACKS}"
942 if [ -n "$DISCNUMBER" ]; then
943 echo DISCNUMBER="$DISCNUMBER"
945 echo CDDB="${CDDBDISCID}"
946 if [ "$(eval echo ${COMMENT})" != "" ]; then
947 case "$COMMENTOUTPUT" in
948 *=*) echo "$COMMENTOUTPUT";;
949 *) echo COMMENT="$COMMENTOUTPUT";;
952 ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
953 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
954 "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
955 "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
956 # Doublecheck that the commented file was created
957 # successfully before wiping the original
958 if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ]; then
959 rm -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
961 mv "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
962 "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
968 run_command "tagtrack-$OUTPUT-$1" true
971 run_command "tagtrack-$OUTPUT-$1" true
974 run_command "tagtrack-$OUTPUT-$1" true
978 echo ARTIST="$TRACKARTIST"
980 echo TITLE="$TRACKNAME"
981 if [ -n "$CDYEAR" ]; then
984 if [ -n "$CDGENRE" ]; then
985 echo GENRE="$CDGENRE"
987 echo TRACKNUMBER="${TRACKNUM:-$1}"
988 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
989 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
990 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
991 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
992 echo TRACKTOTAL="${TRACKS}"
993 if [ -n "$DISCNUMBER" ]; then
994 echo DISCNUMBER="$DISCNUMBER"
996 echo CDDB="${CDDBDISCID}"
997 if [ -n "$(eval echo "${COMMENT}")" ]; then
998 case "$COMMENTOUTPUT" in
999 *=*) echo "$COMMENTOUTPUT";;
1000 *) echo COMMENT="$COMMENTOUTPUT";;
1003 ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $METAFLAC $METAFLACOPTS \
1004 ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} \
1005 --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
1008 run_command "tagtrack-$OUTPUT-$1" true
1011 run_command "tagtrack-$OUTPUT-$1" true
1014 run_command "tagtrack-$OUTPUT-$1" true
1017 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
1018 # Console port (mac) used for encoding does not have the ability to tag.
1019 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$APETAG" -i "${ABCDETEMPDIR}/track$1.ape" -m overwrite \
1020 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track="${TRACKNUM:-$1}" \
1021 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
1024 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
1025 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
1026 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
1027 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
1028 -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
1029 -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
1030 ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1031 "${ABCDETEMPDIR}/track$1.mp2"
1034 run_command "tagtrack-$OUTPUT-$1" true
1037 case "$AACENCODERSYNTAX" in
1039 # We will use inline tagging...
1040 run_command "tagtrack-$OUTPUT-$1" true
1043 # Tag post encode with neroAacTag...
1044 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$NEROAACTAG" \
1045 "${ABCDETEMPDIR}/track$1.m4a" \
1046 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" \
1047 -meta:title="$TRACKNAME" -meta:track="${TRACKNUM:-$1}" \
1048 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1051 run_command "tagtrack-$OUTPUT-$1" true
1054 run_command "tagtrack-$OUTPUT-$1" true
1057 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1058 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1059 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$ATOMICPARSLEY" \
1060 "${ABCDETEMPDIR}/track$1.m4a" --artist="$TRACKARTIST" --album="$DALBUM" \
1061 --title="$TRACKNAME" --tracknum="${TRACKNUM:-$1}" \
1062 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" \
1063 $ATOMICPARSLEYOPTS --overWrite
1066 run_command "tagtrack-$OUTPUT-$1" true
1071 # We use mid3v2 tagging for True Audio:
1072 run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
1073 -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
1074 -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
1075 ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} "${ABCDETEMPDIR}/track$1.tta"
1078 run_command "tagtrack-$OUTPUT-$1" true
1082 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1083 run_command "tagtrack-$1" true
1089 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1092 # The commands here don't go through run_command because they're never
1093 # supposed to be silenced
1094 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1095 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1099 case "$MP3ENCODERSYNTAX" in
1102 cd "${ABCDETEMPDIR}"
1104 for THISTRACKNUM in $TRACKQUEUE
1106 TRACKFILES="$TRACKFILES track$THISTRACKNUM.wav"
1108 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1110 if [ "$RETURN" != "0" ]; then
1111 echo "nogap-encode: $MP3ENCODER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1113 for THISTRACKNUM in $TRACKQUEUE
1115 run_command "encodetrack-$OUTPUT-$THISTRACKNUM" true
1124 if checkerrors "nogap-encode"; then :; else
1125 if [ ! "$KEEPWAVS" = "y" ] ; then
1126 if [ ! "$KEEPWAVS" = "move" ] ; then
1131 # Other encoders fall through to normal encoding as the tracks have not
1132 # been entered in the status file.
1135 # do_encode [tracknumber] [hostname]
1136 # If no hostname is specified, encode locally
1138 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1139 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1142 if [ "$USEPIPES" = "y" ]; then
1145 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1148 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1151 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1154 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1157 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1160 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1163 TEMPARG="PIPE_$SPEEXENCODER"
1166 TEMPARG="PIPE_$MPCENCODER"
1169 TEMPARG="PIPE_$WVENCODERSYNTAX"
1172 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1175 TEMPARG="PIPE_$AACENCODERSYNTAX"
1178 TEMPARG="PIPE_$AACENCODERSYNTAX"
1181 IN="$( eval echo "\$$TEMPARG" )"
1183 IN="${ABCDETEMPDIR}/track$1.wav"
1185 # We need IN to proceed, if we are not using pipes.
1186 if [ -s "$IN" ] || [ X"$USEPIPES" = "Xy" ] ; then
1187 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1189 case "$TMPOUTPUT" in
1191 OUTPUT=$OGGOUTPUTCONTAINER
1194 OUTPUT=$OPUSOUTPUTCONTAINER
1197 OUTPUT=$MKAOUTPUTCONTAINER
1200 OUTPUT=$AIFFOUTPUTCONTAINER
1203 OUTPUT=$FLACOUTPUTCONTAINER
1209 OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1210 if [ "$NOGAP" = "y" ] && checkstatus "encodetrack-$OUTPUT-$1" ; then
1213 if [ X"$USEPIPES" = "Xy" ]; then
1215 # We need a way to store the creation of the files when using PIPES
1216 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1217 # When piping it does not make sense to have a higher nice for
1218 # reading than for encoding, since it will be hold by the
1219 # encoding process. Setting an effective nice, to calm down a
1220 # bit the reading process.
1221 EFFECTIVE_NICE=$READNICE
1223 run_command "" echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1224 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1225 EFFECTIVE_NICE=$ENCNICE
1231 case "$MP3ENCODERSYNTAX" in
1232 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1233 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1234 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1235 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1239 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1246 case "$OGGENCODERSYNTAX" in
1247 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1248 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1252 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1259 case "$OPUSENCODERSYNTAX" in
1261 # Tag the file at encode time, as it can't be done after encoding.
1262 if [ "$DOTAG" = "y" ]; then
1263 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS \
1264 --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
1265 --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1266 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1268 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1274 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1279 case "$MKAENCODERSYNTAX" in
1281 if [ "$DOTAG" = "y" ]; then
1282 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS \
1283 -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
1284 -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
1285 -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
1286 -metadata comment="$COMMENT" "$OUT"
1288 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1294 case "$AIFFENCODERSYNTAX" in
1296 if [ "$DOTAG" = "y" ]; then
1297 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS \
1298 -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
1299 -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
1300 -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
1301 -metadata comment="$COMMENT" "$OUT"
1303 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1311 case "$FLACENCODERSYNTAX" in
1312 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1317 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1318 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1323 if [ -n "$(eval echo "${COMMENT}")" ]; then
1326 *) COMMENT="COMMENT=$COMMENT" ;;
1329 # Tag the file at encode time, as it can't be done after encoding.
1330 if [ "$DOTAG" = "y" ]; then
1331 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS \
1332 --author "$TRACKARTIST" --title "$TRACKNAME" \
1333 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1335 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1339 # Tag the file inline at encode time.
1340 if [ "$DOTAG" = "y" ]; then
1341 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS \
1342 --artist "$TRACKARTIST" --album "$DALBUM" \
1343 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
1344 --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1346 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1350 case "$TTAENCODERSYNTAX" in
1351 # tta is the newer version with a small syntax change...
1353 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1356 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1361 case "$WVENCODERSYNTAX" in
1363 if [ "$DOTAG" = "y" ]; then
1364 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS \
1365 -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1366 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" \
1367 -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1369 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1373 if [ "$DOTAG" = "y" ]; then
1374 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS \
1375 -metadata artist="$TRACKARTIST" \
1376 -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
1377 -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
1378 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1380 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1386 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1389 case "$MP2ENCODERSYNTAX" in
1391 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1394 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1399 # aac container is only used to catch faac encoded files where faac
1400 # is compiled without mp4 support (with libmp4v2).
1401 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1404 case "$AACENCODERSYNTAX" in
1406 if [ "$DOTAG" = "y" ]; then
1407 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
1408 --artist "$TRACKARTIST" --album "$DALBUM" \
1409 --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
1410 --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1412 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1416 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1419 if [ "$DOTAG" = "y" ]; then
1420 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
1421 --artist "$TRACKARTIST" --album "$DALBUM" \
1422 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
1423 --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1425 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1429 if [ "$DOTAG" = "y" ]; then
1430 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS \
1431 --artist "$TRACKARTIST" --album "$DALBUM" \
1432 --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
1433 --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1435 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1439 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1442 if [ "$DOTAG" = "y" ]; then
1443 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" \
1444 $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1445 -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
1446 -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
1447 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1449 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1455 # In case of wav output we need nothing. Just keep the wavs.
1456 # But we need the following to allow full logging and subsequent
1457 # successful cleaning of ${ABCDETEMPDIR}.
1458 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1463 # Only remove .wav if the encoding succeeded
1464 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1465 run_command "encodetrack-$1" true
1466 if [ ! "$KEEPWAVS" = "y" ] ; then
1467 if [ ! "$KEEPWAVS" = "move" ] ; then
1473 run_command "" echo "HEH! The file we were about to encode disappeared:"
1474 run_command "" echo ">> $IN"
1475 run_command "encodetrack-$1" false
1479 # do_preprocess [tracknumber]
1481 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX,
1482 # OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1485 # IN="${ABCDETEMPDIR}/track$1.wav"
1486 # # We need IN to proceed.
1487 # if [ -s "$IN" ] ; then
1488 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1490 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1491 # run_command "" echo "Pre-processing track $1 of $TRACKS..."
1492 # case "$POSTPROCESSFORMAT" in
1494 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $WAV_PRE $IF $OF ;;
1496 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $MP3_PRE $IF $OF ;;
1498 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $OGG_PRE $IF $OF ;;
1500 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $FLAC_PRE $IF $OF ;;
1502 # run_command "preprocess-$OUTPUT-$1" nice $PRENICE $SPX_PRE $IF $OF ;;
1505 # # Only remove .wav if the encoding succeeded
1506 # if checkerrors "preprocess-(.{3,4})-$1"; then
1507 # run_command "preprocess-$1" false
1509 # run_command "preprocess-$1" true
1512 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1513 # echo "HEH! The file we were about to pre-process disappeared:"
1516 # run_command "preprocess-$1" false
1521 # do_postprocess [tracknumber]
1523 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1524 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1527 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1529 # IN="${ABCDETEMPDIR}/track$1.$POSTPROCESSFORMAT"
1530 # # We need IN to proceed.
1531 # if [ -s "$IN" ] ; then
1532 # #OUT="${ABCDETEMPDIR}/track$1.$OUTPUT"
1533 # run_command "" echo "Post-processing track $1 of $TRACKS..."
1534 # case "$POSTPROCESSFORMAT" in
1536 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $MP3_POST $IF $OF ;;
1538 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $OGG_POST $IF $OF ;;
1540 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $FLAC_POST $IF $OF ;;
1542 # run_command "postprocess-$OUTPUT-$1" nice $POSTNICE $SPX_POST $IF $OF ;;
1544 # # Only remove .wav if the encoding succeeded
1545 # if checkerrors "postprocess-(.{3,4})-$1"; then
1546 # run_command "postprocess-$1" false
1548 # run_command "postprocess-$1" true
1551 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1552 # echo "HEH! The file we were about to post-process disappeared:"
1555 # run_command "postprocess-$1" false
1570 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1574 # The commands here don't go through run_command because they're never supposed to be silenced
1575 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1577 cd "${ABCDETEMPDIR}"
1580 for UTRACKNUM in $TRACKQUEUE
1582 TRACKFILES="$TRACKFILES track$UTRACKNUM.mp3"
1584 # FIXME # Hard-coded batch option!
1585 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1587 if [ "$RETURN" != "0" ]; then
1588 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1590 for UTRACKNUM in $TRACKQUEUE
1592 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1598 # do_batch_normalize
1600 # NORMALIZER, NORMALIZEROPTS
1601 do_batch_normalize ()
1603 # The commands here don't go through run_command because they're never supposed to be silenced
1604 echo "Batch normalizing tracks: $TRACKQUEUE"
1606 cd "${ABCDETEMPDIR}"
1609 for UTRACKNUM in $TRACKQUEUE
1611 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1613 # XXX: Hard-coded batch option!
1614 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1616 if [ "$RETURN" != "0" ]; then
1617 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
1619 for UTRACKNUM in $TRACKQUEUE
1621 echo "normalizetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
1627 # do_normalize [tracknumber]
1629 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1632 IN="${ABCDETEMPDIR}/track$1.wav"
1633 if [ -e "$IN" ] ; then
1634 run_command "" echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1635 run_command "normalizetrack-$1" $NORMALIZER $NORMALIZEROPTS "$IN"
1637 if [ "$(checkstatus encode-output)" = "loud" ]; then
1638 echo "HEH! The file we were about to normalize disappeared:"
1641 run_command "normalizetrack-$1" false "File $IN was not found"
1645 # do_move [tracknumber]
1646 # Deduces the outfile from environment variables
1647 # Creates directory if necessary
1649 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1652 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1654 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1655 # defined the OUTPUTFILE:
1658 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1659 ALBUMFILE="$(mungealbumname "$DALBUM")"
1660 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1661 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1662 GENRE="$(mungegenre "$GENRE")"
1663 YEAR=${CDYEAR:-$CDYEAR}
1664 # If we want to start the tracks with a given number, we need to modify
1665 # the TRACKNUM value before evaluation
1667 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1668 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1669 if [ "$ONETRACK" = "y" ]; then
1670 if [ "$VARIOUSARTISTS" = "y" ]; then
1671 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1673 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1676 if [ "$VARIOUSARTISTS" = "y" ]; then
1677 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1679 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1682 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1683 # Once we know the specific output was successful, we can change
1684 # the OUTPUT to the value containing the container
1687 OUTPUT=$OGGOUTPUTCONTAINER
1690 OUTPUT=$OPUSOUTPUTCONTAINER
1693 OUTPUT=$MKAOUTPUTCONTAINER
1696 OUTPUT=$AIFFOUTPUTCONTAINER
1699 OUTPUT=$FLACOUTPUTCONTAINER
1705 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1706 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1709 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1710 # FIXME # introduce warnings?
1713 # mkdir -p shouldn't return an error if the directory already exists
1714 mkdir -p "$OUTPUTFILEDIR"
1715 run_command "movetrack-$1" mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1716 if checkstatus "movetrack-output-$OUTPUT"; then :; else
1717 run_command "movetrack-output-$OUTPUT" true
1722 # mkdir -p shouldn't return an error if the directory already exists
1723 mkdir -p "$OUTPUTFILEDIR"
1724 run_command "movetrack-$1" mv "${ABCDETEMPDIR}/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1725 if checkstatus "movetrack-output-$OUTPUT"; then :; else
1726 run_command "movetrack-output-$OUTPUT" true
1730 # Lets move the cue file
1731 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1732 if [ -r "${ABCDETEMPDIR}/$CUEFILE" ]; then
1733 if checkstatus "movecue-$OUTPUT"; then :; else
1734 # Silence the Copying output since it overlaps with encoding processes...
1735 #run_command "" vecho "Copying cue file to its destination directory..."
1736 if checkstatus onetrack >/dev/null ; then
1739 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1740 # We dont have the dir, since it was not created before.
1743 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1746 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1747 # http://brianvictor.tripod.com/mp3cue.htm#details
1748 [a-z0-9][a-z0-9][a-z0-9])
1749 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1752 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1756 run_command "movecue-$OUTPUT" cp "${ABCDETEMPDIR}/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1758 echo "movecue-$OUTPUT" >> "${ABCDETEMPDIR}/status"
1767 # Create the playlist if wanted
1769 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1770 # VARIOUSARTISTS, OUTPUTDIR
1773 for TMPOUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
1777 OUTPUT=$OGGOUTPUTCONTAINER
1780 OUTPUT=$OPUSOUTPUTCONTAINER
1783 OUTPUT=$MKAOUTPUTCONTAINER
1786 OUTPUT=$AIFFOUTPUTCONTAINER
1789 OUTPUT=$FLACOUTPUTCONTAINER
1795 # Create a playlist file for the playlist data to go into.
1796 # We used to wipe it out if it existed. Now we request permission if interactive.
1797 for LASTTRACK in $TRACKQUEUE; do :; done
1798 ALBUMFILE="$(mungealbumname "$DALBUM")"
1799 ARTISTFILE="$(mungeartistname "$DARTIST")"
1800 GENRE="$(mungegenre "$GENRE")"
1801 YEAR=${CDYEAR:-$CDYEAR}
1802 if [ "$VARIOUSARTISTS" = "y" ] ; then
1803 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1805 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1807 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1808 mkdir -p "$FINALPLAYLISTDIR"
1809 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1810 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1811 if [ "$INTERACTIVE" = "y" ]; then
1812 while [ "$DONE" != "y" ]; do
1814 case $ERASEPLAYLIST in
1815 e|E|a|A|k|K) DONE=y ;;
1816 "") ERASEPLAYLIST=e ; DONE=y ;;
1824 # Once we erase the playlist, we use append to create the new one.
1825 [ "$ERASEPLAYLIST" = "e" ] || [ "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1827 # The playlist does not exist, so we can safelly use append to create the new list
1830 if [ "$ERASEPLAYLIST" = "a" ] || [ "$ERASEPLAYLIST" = "A" ]; then
1831 touch "$OUTPUTDIR/$PLAYLISTFILE"
1832 for UTRACKNUM in $TRACKQUEUE
1834 # Shares some code with do_move since the filenames have to match
1835 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
1836 getcddbinfo TRACKNAME
1838 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1839 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1840 ALBUMFILE="$(mungealbumname "$DALBUM")"
1841 # If we want to start the tracks with a given number, we need to modify the
1842 # TRACKNUM value before evaluation
1844 if [ "$VARIOUSARTISTS" = "y" ]; then
1845 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1847 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1849 if [ "$VARIOUSARTISTS" = "y" ]; then
1850 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1851 echo "${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1853 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1856 if [ "$PLAYLISTDATAPREFIX" ]; then
1857 echo "${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1859 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1864 ## this will convert the playlist to have CRLF line-endings, if specified
1865 ## (some hardware players insist on CRLF endings)
1866 if [ "$DOSPLAYLIST" = "y" ]; then
1867 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "${ABCDETEMPDIR}/PLAYLISTFILE.tmp"
1868 # mv -f "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1869 cat "${ABCDETEMPDIR}/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1871 echo "playlistcomplete" >> "${ABCDETEMPDIR}/status"
1876 # This function reads a cuefile on stdin and writes an extended
1877 # cddb query on stdout. Any PREGAP for track 1 is properly
1878 # handled, although cue files embedded in FLAC files do not
1879 # appear to properly store the PREGAP setting. :(
1880 abcde.cue2discid () {
1885 while [ "$val" -gt 0 ] ; do
1886 ret=$(( "$ret" + ( "$val" % 10) ))
1887 val=$(( "$val" / 10 ))
1897 local first second third
1899 second=$(( $2 + 0 ))
1902 echo $(( ((("$first" * 60) + "$second") * 75) + "$third" ))
1912 while read line ; do
1915 TRACK) i=$(( i + 1 ))
1917 INDEX) if [ "$2" -eq 1 ] ; then
1919 START=$(( "$LBA" + "$PREGAP" + "$OFFSET" ))
1921 X=$(cddb_sum $(( "$START" / 75 )) )
1922 N=$(( "$N" + "$X" ))
1925 PREGAP) PREGAP=$(msf2lba "$2")
1929 LEADOUT=$(( "$4" / 588 ))
1932 LEADIN=$(( "$3" / 588 ))
1941 LEADOUT=$(( "$LEADOUT" + "$LEADIN" ))
1943 LENGTH=$(( "$LEADOUT"/75 - "$TRACK1"/75 ))
1944 CDDBDISCID=$(( ( "$N" % 255 ) * 2**24 | "$LENGTH" * 2**8 | "$TRACKS" ))
1945 printf "%08x %i" "${CDDBDISCID}" "$TRACKS"
1948 while [ $j -le "$TRACKS" ] ; do
1949 eval echo -n "\" \$TRACK$j\""
1952 echo " $(( $LEADOUT / 75 ))"
1956 # abcde.mkcue [--wholedisk]
1957 # This creates a cuefile directly from the extended discid information
1958 # The --wholedisk option controls whether we're ripping data from the
1959 # start of track one or from the start of the disk (usually, but not
1960 # always the same thing!)
1962 # Track one leadin/pregap (if any) handeling:
1963 # --wholedisk specified:
1966 # INDEX 01 <pregap value>
1967 # Remaining track index values unchanged from disc TOC
1969 # --wholedisk not specified
1971 # PREGAP <pregap value>
1973 # Remaining track index values offset by <pregap value>
1980 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1983 local MODE DISCID TRACKS
1987 if [ "$1" = --wholedisk ] ; then
1993 vecho "One track is $ONETRACK"
1994 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1995 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1996 ALBUMFILE="$(mungealbumname "$DALBUM")"
1997 if [ "$ONETRACK" = "y" ]; then
1998 if [ "$VARIOUSARTISTS" = "y" ]; then
1999 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2001 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2003 vecho "Cue wav file is $CUEWAVFILE"
2005 CUEWAVFILE="dummy.wav"
2008 set -- "$CDDBTRACKINFO"
2014 echo "REM DISCID $DISCID"
2015 echo FILE \""$CUEWAVFILE"\" WAVE
2017 if [ "$1" -ne 150 ] && [ "$MODE" = "PREGAP" ] ; then
2024 while [ $i -le "$TRACKS" ] ; do
2025 LBA=$(( $1 - $OFFSET ))
2026 printf " TRACK %02i AUDIO\n" $i
2027 if [ "$i" -eq 1 ] && [ "$1" -ne 150 ] ; then
2028 if [ "$MODE" = PREGAP ] ; then
2029 echomsf " PREGAP " $(($"OFFSET" - 150))
2031 echo " INDEX 00 00:00:00"
2034 echomsf " INDEX 01 " "$LBA"
2041 # This is essentially the start of things
2044 if [ -z "${CDDBDISCID}" ]; then
2045 vecho -n "Getting CD track info... "
2046 # In OSX, unmount the disc before a query
2047 if [ "$OSFLAVOUR" = "OSX" ]; then
2048 diskutil unmount "${CDROM#/dev/}"
2050 case "$CDROMREADERSYNTAX" in
2052 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
2053 case "$CUE2DISCID" in
2054 # FIXME # right now we have 2 cue2discid internal
2055 # implementations: builtin and abcde.cue2discid. Test
2056 # both of them and decide which one we want to use.
2058 #vecho "Using builtin cue2discid implementation..."
2059 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2061 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2063 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2064 TRACKS=${#OFFSETTIMES[@]}
2066 #echo "processing offsetimes ${OFFSETTIMES[@]}"
2067 for OFFSETTIME in ${OFFSETTIMES[@]}; do
2068 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2069 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
2072 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2073 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2077 #vecho "Using external python cue2discid implementation..."
2078 CDDBTRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2082 log error "the input flac file does not contain a cuesheet."
2087 CDPARANOIAOUTPUT="$( $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -Q --verbose 2>&1 )"
2089 if [ ! "$RET" = "0" ];then
2090 log warning "something went wrong while querying the CD... Maybe a DATA CD or the CD is not loaded?"
2093 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2094 CDPARANOIAAUDIOTRACKS="$TRACKS"
2096 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2097 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2101 # Calculate the cddb discid in all
2102 # cases now. We'll use the cddb discid
2103 # for reference in most cases for
2104 # consistency. Also calculate the
2105 # musicbrainz discid if we need it.
2106 CDDBTRACKINFO=$($CDDISCID "$CDROM")
2107 if [ "$CDDISCID_NEEDS_PAUSE"x = "y"x ]; then
2110 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2111 case "$CDDBMETHOD" in
2113 MBTRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM")
2115 if [ $error != 0 ]; then
2116 log error "$MUSICBRAINZ failed to run; ABORT"
2119 MBDISCID=$(echo "$MBTRACKINFO" | cut -d' ' -f1)
2123 # Make sure there's a CD in there by checking cd-discid's return code
2124 if [ ! "$?" = "0" ]; then
2125 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2126 log error "cuesheet information from the flac file could not be read."
2127 log error "Perhaps the flac file does not contain a cuesheet?."
2130 log error "CD could not be read. Perhaps there's no CD in the drive?"
2134 # In OSX, remount the disc again
2135 if [ "$OSFLAVOUR" = "OSX" ]; then
2136 diskutil mount "${CDROM#/dev/}"
2139 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -f1 -d' ')
2141 CDDBTRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.${CDDBDISCID}/cddbdiscid")
2144 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2145 # This needs to be done now because a section of the resuming code will need
2148 # get the number of digits to pad TRACKNUM with - we'll use this later
2149 # a CD can only hold 99 tracks, but since we support a feature for starting
2150 # numbering the tracks from a given number, we might need to set it as a
2151 # variable for the user to define... or obtain it somehow.
2152 if [ "$PADTRACKS" = "y" ] ; then
2156 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo "$CDDBTRACKINFO" | cut -f1 -d' ')"
2157 if [ -z "$TRACKQUEUE" ]; then
2158 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2159 case "$CDROMREADERSYNTAX" in
2160 cdparanoia|libcdio|debug)
2161 if [ "$WEHAVEACD" = "y" ]; then
2162 vecho "Querying the CD for audio tracks..."
2163 CDPARANOIAOUTPUT="$( $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -Q --verbose 2>&1 )"
2165 if [ ! "$RET" = "0" ];then
2166 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2168 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2169 CDPARANOIAAUDIOTRACKS="$TRACKS"
2171 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2172 if [ -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks" ]; then
2173 echo "cdparanoia-audio-tracks=$( cat "${ABCDETEMPDIR}/cdparanoia-audio-tracks" )" >> "${ABCDETEMPDIR}/status"
2174 rm -f "${ABCDETEMPDIR}/cdparanoia-audio-tracks"
2176 if [ -f "${ABCDETEMPDIR}/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2177 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2181 *) TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ') ;;
2184 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2186 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2187 log info "The disc does not contain any tracks. Giving up..."
2190 echo -n "Grabbing entire CD - tracks: "
2191 if [ ! "$PADTRACKS" = "y" ] ; then
2192 TRACKNUMPADDING=$(echo -n "$TRACKS" | wc -c | tr -d ' ')
2195 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2197 while [ "$X" -ne "$TRACKS" ]
2199 PT=$(printf "%0.${TRACKNUMPADDING}d" $(($X + 1)))
2200 TRACKQUEUE="$TRACKQUEUE $PT"
2205 TRACKS=$(echo "$CDDBTRACKINFO" | cut -f2 -d' ')
2206 # User-supplied track queue.
2207 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2208 TRACKQUEUE=$(echo "$TRACKQUEUE" | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2209 # Once cleaned, obtain the highest value in the trackqueue for number padding
2210 for LASTTRACK in $TRACKQUEUE; do :; done
2211 if [ ! "$PADTRACKS" = "y" ] ; then
2212 TRACKNUMPADDING=$(echo -n "$LASTTRACK" | wc -c | tr -d ' ')
2214 # Now we normalize the trackqueue
2215 for TRACK in $TRACKQUEUE ; do
2216 TRACKNUM=$(printf "%0.${TRACKNUMPADDING}d" $(($TRACK + 0)))
2217 PADTRACKQUEUE="$PADTRACKQUEUE $TRACKNUM"
2219 TRACKQUEUE="$PADTRACKQUEUE"
2220 echo Grabbing tracks: "$TRACKQUEUE"
2223 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2225 # We have the discid, create a temp directory after it to store all the temp
2228 if [ -e "${ABCDETEMPDIR}" ]; then
2229 echo -n "abcde: attempting to resume from ${ABCDETEMPDIR}"
2230 # It already exists, see if it's a directory
2231 if [ ! -d "${ABCDETEMPDIR}" ]; then
2232 # This is a file/socket/fifo/device/etc, not a directory
2235 echo "abcde: file ${ABCDETEMPDIR} already exists and does not belong to abcde." >&2
2236 echo "Please investigate, remove it, and rerun abcde." >&2
2240 # It's a directory, let's see if it's writable by us
2241 if [ ! -r "${ABCDETEMPDIR}" ] || [ ! -w "${ABCDETEMPDIR}" ] || [ ! -x "${ABCDETEMPDIR}" ]; then
2242 # Nope, complain and exit
2244 echo "abcde: directory ${ABCDETEMPDIR} already exists and is not writeable." >&2
2245 echo "Please investigate, remove it, and rerun abcde." >&2
2249 # See if it's populated
2250 if [ ! -f "${ABCDETEMPDIR}/cddbdiscid" ]; then
2251 # Wipe and start fresh
2252 echo "abcde: ${ABCDETEMPDIR}/cddbdiscid not found. Abcde must remove and recreate" >&2
2253 echo -n "this directory to continue. Continue [y/N]? " >&2
2254 if [ "$INTERACTIVE" = "y" ]; then
2260 if [ "$ANSWER" != "y" ]; then
2263 rm -rf "${ABCDETEMPDIR}" || exit 1
2264 mkdir -p "${ABCDETEMPDIR}"
2265 if [ "$?" -gt "0" ]; then
2266 # Directory already exists or could not be created
2267 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2271 # Everything is fine. Check for ^encodetracklocation-
2272 # and encode-output entries in the status file and
2273 # remove them. These are not relevant across sessions.
2274 echo "Resuming" >> "${ABCDETEMPDIR}/status"
2275 if [ -f "${ABCDETEMPDIR}/status" ]; then
2276 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
2277 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
2278 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
2280 # Remove old error messages
2281 if [ -f "${ABCDETEMPDIR}/errors" ]; then
2282 rm -f "${ABCDETEMPDIR}/errors"
2286 # We are starting from scratch
2287 mkdir -p "${ABCDETEMPDIR}"
2288 if [ "$?" -gt "0" ]; then
2289 # Directory already exists or could not be created
2290 echo "abcde: Temp directory ${ABCDETEMPDIR} could not be created." >&2
2293 cat /dev/null > "${ABCDETEMPDIR}/status"
2294 # Store the abcde version in the status file.
2295 echo "abcde-version=$VERSION" >> "${ABCDETEMPDIR}/status"
2297 if [ X"$DOCUE" = "Xy" ] && [ X"$WEHAVEACD" = "Xy" ]; then
2298 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2299 CUEFILE=cue-$(echo "$CDDBTRACKINFO" | cut -f1 -d' ').txt
2300 vecho "Creating cue file..."
2301 case "$CDROMREADERSYNTAX" in
2303 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "${ABCDETEMPDIR}/$CUEFILE"; then
2304 echo "cuefile=$CUEFILE" >> "${ABCDETEMPDIR}/status"
2306 log warning "the input flac file does not contain a cuesheet."
2310 if $CUEREADER $CUEREADEROPTS > "${ABCDETEMPDIR}/$CUEFILE"; then
2311 echo "cuefile=$CUEFILE" >> "${ABCDETEMPDIR}/status"
2313 log warning "reading the CUE sheet is still considered experimental"
2314 log warning "and there was a problem with the CD reading. abcde will continue,"
2315 log warning "but consider reporting the problem to the abcde author"
2321 # If we got the CDPARANOIA status and it is not recorded, save it now
2322 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2323 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2324 echo "cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS" >> "${ABCDETEMPDIR}/status"
2328 # Create the discid files
2329 echo "$CDDBTRACKINFO" > "${ABCDETEMPDIR}/cddbdiscid"
2330 case "$CDDBMETHOD" in
2332 echo "$MBTRACKINFO" > "${ABCDETEMPDIR}/mbdiscid"
2338 # Create a proper CUE file based on the CUE file we created before.
2341 if CUEFILE_IN="${ABCDETEMPDIR}"/$(checkstatus cuefile); then
2342 CUEFILE_OUT=$CUEFILE_IN.out
2343 ### FIXME ### checkstatus cddb
2344 if [ -e "$CDDBDATA" ]; then
2345 vecho "Adding metadata to the cue file..."
2346 # FIXME It doesn't preserve spaces! Why?
2347 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2349 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2350 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2351 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2355 cat "$CUEFILE_IN" | while read line
2357 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2358 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2359 # echo "$line" >> "$CUEFILE_OUT"
2360 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2361 eval track="\$TRACK$n"
2363 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2364 # When making a single-track rip, put the
2365 # actual file name into the file declaration
2366 # in the cue file so that it is usable by
2367 # music players and the like
2368 elif [ "$ONETRACK" = "y" ] &&
2369 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2371 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2372 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2373 ALBUMFILE="$(mungealbumname "$DALBUM")"
2375 if [ "$VARIOUSARTISTS" = "y" ]; then
2376 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2378 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2381 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2384 # FIXME # If the lines above are uncommented, remove the line below.
2385 echo "$line" >> "$CUEFILE_OUT"
2388 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2389 echo "cleancuefile" >> "${ABCDETEMPDIR}/status"
2395 # Parses a CDDB file and outputs the title and the track names.
2396 # Variables: CDDBFILE
2400 # List out disc title/author and contents
2401 if [ "$ONETRACK" = "y" ]; then
2402 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2404 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2405 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2406 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2407 if [ ! X"$PARSEDYEAR" = "X" ]; then
2408 echo "Year: $PARSEDYEAR"
2411 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2412 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2413 if [ ! X"$PARSEDGENRE" = "X" ]; then
2414 echo "Genre: $PARSEDGENRE"
2417 if [ ! "$ONETRACK" = "y" ]; then
2418 for TRACK in $(f_seq_row 1 $TRACKS)
2420 echo "$TRACK": "$(grep -a ^TTITLE$(($TRACK - 1))= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2426 # Check for a local CDDB file, and report success
2427 do_localcddb_read ()
2429 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2431 CDDBLOCALSTATUS="notfound"
2432 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2435 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2436 CDDBLOCALRESULTS="$(find "${CDDBLOCALDIR}" -name "${CDDBDISCID}" -type f 2> /dev/null)"
2437 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2438 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2439 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2440 CDDBLOCALMATCH=single
2441 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2442 CDDBLOCALMATCH=multiple
2447 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2448 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2449 CDDBLOCALMATCH=single
2454 # If the user has selected to check a local CDDB repo, we proceed with it
2455 case $CDDBLOCALMATCH in
2457 echo "Processing multiple matching CDDB entries..." > "${ABCDETEMPDIR}/cddblocalchoices"
2459 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2461 # List out disc title/author and contents
2462 CDDBLOCALREAD="${ABCDETEMPDIR}/cddblocalread.$X"
2463 cat "$RESULT" > "${CDDBLOCALREAD}"
2466 do_cddbparse "${CDDBLOCALREAD}"
2468 ##FIXME## QUICK HACK !!!!
2469 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2470 } >> "${ABCDETEMPDIR}/cddblocalchoices"
2472 page "${ABCDETEMPDIR}/cddblocalchoices"
2473 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2474 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2475 CDDBLOCALCHOICENUM=-1
2476 if [ "$INTERACTIVE" = "y" ]; then
2477 while [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; do
2478 echo "Locally cached CDDB entries found." >&2
2479 echo -n "Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2480 read CDDBLOCALCHOICE
2481 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2482 # FIXME # Introduce diff's
2483 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2484 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2485 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2486 # Make sure we get a valid choice
2487 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2488 if [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; then
2489 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2494 CDDBLOCALCHOICENUM=1
2496 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2497 #echo "Using local copy of CDDB data"
2498 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2499 cat "${ABCDETEMPDIR}/cddblocalread.$CDDBLOCALCHOICENUM" >> "${ABCDETEMPDIR}/cddbread.1"
2500 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2501 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2502 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2503 do_cddbparse "${ABCDETEMPDIR}/cddbread.1" > "${ABCDETEMPDIR}/cddbchoices"
2504 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2505 CDDBLOCALSTATUS="found"
2507 #echo "Not using local copy of CDDB data"
2508 CDDBLOCALSTATUS="notfound"
2512 # List out disc title/author and contents
2513 do_cddbparse "${CDDBLOCALFILE}"
2514 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2515 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2517 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2519 if [ "$INTERACTIVE" = "y" ]; then
2521 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2522 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2525 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2529 if [ "$USELOCALRESP" = "y" ]; then
2530 #echo "Using local copy of CDDB data"
2531 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "${ABCDETEMPDIR}/cddbread.1"
2532 cat "${CDDBLOCALFILE}" >> "${ABCDETEMPDIR}/cddbread.1"
2533 echo "local" > "${ABCDETEMPDIR}/datasource.1"
2534 echo 999 > "${ABCDETEMPDIR}/cddbquery" # Assuming 999 isn't used by CDDB
2535 echo cddb-readcomplete >> "${ABCDETEMPDIR}/status"
2536 do_cddbparse "${CDDBLOCALFILE}" > "${ABCDETEMPDIR}/cddbchoices"
2537 echo cddb-choice=1 >> "${ABCDETEMPDIR}/status"
2538 CDDBLOCALSTATUS="single"
2540 #echo "Not using local copy of CDDB data"
2541 CDDBLOCALSTATUS="notfound"
2545 CDDBLOCALSTATUS="notfound"
2552 # Try to read CD-Text from the drive using icedax / cdda2wav
2555 if new_checkexec icedax; then
2556 CDTEXT_READER=icedax
2557 elif new_checkexec cdda2wav; then
2558 CDTEXT_READER=cdda2wav
2560 # Didn't find either, bail
2564 if checkstatus cdtext-readcomplete; then
2565 NUM_RESPONSES=$(checkstatus "cdtext-entries")
2566 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2567 vecho "Re-using existing data from CD-Text"
2569 vecho "Obtaining CD-Text results..."
2570 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cdtext"
2571 mkdir -p "${SOURCE_WORKDIR}"
2573 if [ "$OSFLAVOUR" = "OSX" ] ; then
2574 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2575 diskutil unmount "${CDROM#/dev/}"
2576 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2577 CDDA2WAVCDROM="IODVDServices"
2578 elif [ "$OSFLAVOUR" = "FBSD" ] || [ "$OSFLAVOUR" = "IRIX" ]; then
2579 CDDA2WAVCDROM="$CDROMID"
2581 if [ "$CDROMID" = "" ]; then
2582 CDDA2WAVCDROM="$CDROM"
2584 CDDA2WAVCDROM="$CDROMID"
2588 # Do we have CD-Text on the disc (and can the drive read it?)
2590 cd "${SOURCE_WORKDIR}" && rm -f audio.* audio_*
2591 ${CDTEXT_READER} -J -v titles -D "${CDDA2WAVCDROM}" > "${SOURCE_WORKDIR}/cd-text" 2>&1
2593 grep -a -q '^CD-Text: detected' "${SOURCE_WORKDIR}/cd-text"
2595 if [ $ERRORCODE -ne 0 ]; then
2596 # No CD-Text found, bail
2600 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2601 # Make an empty template
2602 $CDDBTOOL template "$(cat "${ABCDETEMPDIR}/cddbdiscid")" > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2603 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2604 rm -f "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2606 # XXX FIXME - this is a hack and should be replaced by proper
2607 # character set tracking for the CDDB data we have.
2608 if [ "$CDDBPROTO" -ge 6 ]; then
2609 # convert to Unicode
2610 iconv -f iso-8859-1 -t utf-8 <"${SOURCE_WORKDIR}/audio.cddb" >"${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2612 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2613 # apparently icedax/cdda2wav have no support for 16-bit
2614 # characters yet, either
2615 cp -p "${SOURCE_WORKDIR}/audio.cddb" "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2618 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2619 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2620 echo "CD-Text" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2621 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2623 ( cd "${SOURCE_WORKDIR}" && rm -f audio_* audio.* )
2624 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2625 if [ -f "$file" ]; then
2626 cp "$file" "${ABCDETEMPDIR}"
2629 echo "cdtext-readcomplete" >> "${ABCDETEMPDIR}/status"
2630 echo "cdtext-entries=1" >> "${ABCDETEMPDIR}/status"
2634 # do_musicbrainz_read
2635 # Work with the musicbrainz WS API, then transform the results here so
2636 # they look (very) like the results from CDDB. Maybe not the best way
2637 # to go, but it Works For Me (TM)
2639 # List out all the matches individually into $SOURCE_WORKDIR/cddbread.X
2641 do_musicbrainz_read ()
2643 if checkstatus musicbrainz-readcomplete; then
2644 NUM_RESPONSES=$(checkstatus "musicbrainz-entries")
2645 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2646 vecho "Re-using existing data from $NUM_RESPONSES Musicbrainz match(es)"
2648 vecho "Obtaining Musicbrainz results..."
2649 # If MB is to be used, interpret the query results and read all
2650 # the available entries.
2651 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2652 MBDISCID=$(echo "$MBTRACKINFO" | cut -d' ' -f1)
2653 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-musicbrainz"
2654 mkdir -p "${SOURCE_WORKDIR}"
2655 ${MUSICBRAINZ} --command data --discid "${MBDISCID}" --workdir "${SOURCE_WORKDIR}" --start ${NUM_CDDB_MATCHES}
2657 if [ $error != 0 ]; then
2658 log error "$MUSICBRAINZ failed to run; ABORT"
2662 # Check for no matches.
2663 # The helper script will write disc matches out to
2664 # cddbread.*. Count how many we have
2665 NUM_RESPONSES=$(echo "${SOURCE_WORKDIR}"/cddbread.* | wc -w)
2666 if [ "$NUM_RESPONSES" -gt 0 ] ; then
2667 # One or more exact matches
2669 while [ $i -le "$NUM_RESPONSES" ]; do
2670 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2672 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2673 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2674 echo "none ${CDDBDISCID} ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2675 echo "Musicbrainz" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2676 cp -f "${SOURCE_WORKDIR}/"*."${NUM_CDDB_MATCHES}" "${ABCDETEMPDIR}"
2679 echo "musicbrainz-readcomplete" >> "${ABCDETEMPDIR}/status"
2680 echo "musicbrainz-entries=$NUM_RESPONSES" >> "${ABCDETEMPDIR}/status"
2687 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cddb"
2688 mkdir -p "${SOURCE_WORKDIR}"
2694 # Perform CDDB protocol version check if it hasn't already been done
2695 if checkstatus cddb-statcomplete; then :; else
2696 if [ "$CDDBAVAIL" = "n" ]; then
2698 echo 503 > "${SOURCE_WORKDIR}/cddbstat"
2701 CDDBUSER=$(echo "$HELLOINFO" | cut -f1 -d'@')
2702 CDDBHOST=$(echo "$HELLOINFO" | cut -f2- -d'@')
2703 while [ $rc -eq 1 ] && [ "$CDDBPROTO" -ge 3 ]; do
2704 vecho "Checking CDDB server status..."
2705 $CDDBTOOL stat "$CDDBURL" "$CDDBUSER" "$CDDBHOST" "$CDDBPROTO" > "${SOURCE_WORKDIR}/cddbstat"
2706 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2707 case "$RESPONSECODE" in
2708 210) # 210 OK, status information follows (until terminating `.')
2711 501) # 501 Illegal CDDB protocol level: <n>.
2712 CDDBPROTO=$(($CDDBPROTO - 1))
2714 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2715 # FreeDB TESTCD disc-id is used for query
2716 $CDDBTOOL query "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" 03015501 1 296 344 > "${SOURCE_WORKDIR}/cddbstat"
2717 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2718 case "$RESPONSECODE" in
2719 2??) # Server responded, everything seems OK
2729 if [ $rc -eq 1 ]; then
2733 echo cddb-statcomplete >> "${ABCDETEMPDIR}/status"
2740 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
2741 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2743 # Perform CDDB query if it hasn't already been done
2744 if checkstatus cddb-querycomplete; then :; else
2745 if [ "$CDDBAVAIL" = "n" ]; then
2747 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2748 # The default CDDBLOCALSTATUS is "notfound"
2749 # This part will be triggered if the user CDDB repo does not
2750 # contain the entry, or if we are not trying to use the repo.
2752 vecho "Querying the CDDB server..."
2753 CDDBUSER=$(echo "$HELLOINFO" | cut -f1 -d'@')
2754 CDDBHOST=$(echo "$HELLOINFO" | cut -f2- -d'@')
2755 $CDDBTOOL query "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" "$CDDBTRACKINFO" > "${SOURCE_WORKDIR}/cddbquery"
2761 # no match found in database, wget/fetch error,
2762 # or user requested not to use CDDB. Make up an
2763 # error code (503) that abcde will recognize later
2764 # and compensate by making a template
2765 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2767 *) # strange and unknown error
2768 echo "ERRORCODE=$ERRORCODE"
2769 echo "abcde: $CDDBTOOL returned unknown error code"
2773 echo cddb-querycomplete >> "${ABCDETEMPDIR}/status"
2780 # If it's not to be used, generate a template.
2781 # Then, display it (or them) and let the user choose/edit it
2782 if checkstatus cddb-readcomplete; then
2783 NUM_RESPONSES=$(checkstatus "cddb-entries")
2784 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2785 vecho "Re-using existing data from $NUM_RESPONSES cddb match(es)"
2787 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbquery" | cut -f1 -d' ')
2788 vecho "Obtaining CDDB results..."
2789 case "$RESPONSECODE" in
2791 # One exact match, retrieve it
2792 # 200 [section] [discid] [artist] / [title]
2794 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2795 $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
2796 $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") \
2797 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2798 cat "${SOURCE_WORKDIR}/cddbquery" | cut -f2- -d' ' > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2799 echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2800 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2802 202|403|409|500|503)
2803 # TODO: Explain these error codes a little more accurately:
2804 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2805 # No match response:
2808 # Multiple exact, (possibly multiple) inexact matches
2809 vecho -n "Retrieving multiple matches... "
2810 grep -v '^[.]$' "${SOURCE_WORKDIR}/cddbquery" | (
2811 # IN A SUB-SHELL - VARIABLES MODIFIED
2812 # HERE DO NOT PERSIST IN THE PARENT
2813 read DISCINFO # eat top line
2816 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2817 if checkstatus "cddb-read-${NUM_CDDB_MATCHES}-complete"; then :; else
2818 $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
2819 $(echo "$DISCINFO" | cut -f1,2 -d' ') \
2820 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2821 echo "$DISCINFO" > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2822 echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2823 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2826 # Need to re-count the entries here to be able
2827 # to incrememnt $NUM_CDDB_MATCHES in the
2829 NUM_RESPONSES=$(echo "${SOURCE_WORKDIR}/datasource.*" | wc -w)
2830 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2836 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + $NUM_RESPONSES))
2837 echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
2840 for file in ${SOURCE_WORKDIR}/cddbread.* ${SOURCE_WORKDIR}/cddbquery.* ${SOURCE_WORKDIR}/datasource.*; do
2841 if [ -f "$file" ]; then
2842 cp "$file" "${ABCDETEMPDIR}"
2845 echo "cddb-readcomplete" >> "${ABCDETEMPDIR}/status"
2846 echo "cddb-entries=$NUM_RESPONSES" >> "${ABCDETEMPDIR}/status"
2853 if checkstatus cddb-edit >/dev/null; then
2854 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2855 VARIOUSARTISTS="$(checkstatus variousartists)"
2856 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2859 if [ "$INTERACTIVE" = "y" ]; then
2860 # We should show the CDDB results both when we are not using the local CDDB repo
2861 # or when we are using it but we could not find a proper match
2862 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2863 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2864 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2865 CHOICE=$(checkstatus cddb-choice)
2866 if [ -n "$CHOICE" ] ; then
2867 case $NUM_CDDB_MATCHES in
2868 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2870 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CHOICE" | cut -f2- -d= | tr -d \\r\\n)
2871 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CHOICE")
2872 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)"
2873 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2877 page "${ABCDETEMPDIR}/cddbchoices"
2879 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2881 # I'll take CDDB read #3 for $400, Alex
2882 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; do
2883 echo -n "Which entry would you like abcde to use (0 for none)? [0-$NUM_CDDB_MATCHES]: " >&2
2885 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2886 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2887 if [ ! X"$DIFF" = "X" ]; then
2888 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2889 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2890 if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$NUM_CDDB_MATCHES" ] || \
2891 [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$NUM_CDDB_MATCHES" ] || \
2892 [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
2893 echo "Invalid diff range." >&2
2894 echo "Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
2896 # We parse the 2 choices to diff, store them in temporary files and diff them.
2897 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2898 do_cddbparse "${ABCDETEMPDIR}/cddbread.$PARSECHOICE" \
2899 > "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE"
2901 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." \
2902 > "${ABCDETEMPDIR}/cddbread.diff"
2903 $DIFF $DIFFOPTS "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE1" \
2904 "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE2" \
2905 >> "${ABCDETEMPDIR}/cddbread.diff"
2906 page "${ABCDETEMPDIR}/cddbread.diff"
2909 echo "The diff program was not found in your path." >&2
2910 echo "Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2912 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2913 # Make sure we get a valid choice
2914 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2915 if [ "$CDCHOICENUM" -lt 0 ] || [ "$CDCHOICENUM" -gt "$NUM_CDDB_MATCHES" ]; then
2916 echo "Invalid selection. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2920 if [ "$CDCHOICENUM" = "0" ]; then
2921 vecho "Creating empty CDDB template..."
2923 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
2924 echo "template" > "${ABCDETEMPDIR}/datasource.0"
2926 ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n)
2927 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CDCHOICENUM")
2928 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)" >&2
2930 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM"
2931 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2935 # We need some code to show the selected option when local repository is selected and we have found a match
2936 vecho "Using cached CDDB match..." >&2
2937 # Display the ${ABCDETEMPDIR}/cddbchoices file created above
2938 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2939 CHOICE=$(checkstatus cddb-choice)
2940 if [ "$USELOCALRESP" = "y" ]; then :; else
2941 if [ -n "$CHOICE" ] ; then
2942 case $NUM_CDDB_MATCHES in
2945 echo "Selected template."
2947 1) cat "${ABCDETEMPDIR}/cddbchoices" ;;
2949 echo "Selected: #$CHOICE"
2950 do_cddbparse "${ABCDETEMPDIR}/cddbread.$CHOICE"
2958 # We're noninteractive - pick the first choice.
2959 # But in case we run a previous instance and selected a choice, use it.
2960 if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
2961 # Show the choice if we are not using the locally stored one
2962 # or when the local search failed to find a match.
2963 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2964 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2965 #if [ "$PREVIOUSCHOICE" ]; then
2966 cat "${ABCDETEMPDIR}/cddbchoices"
2969 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2970 CDCHOICENUM=$PREVIOUSCHOICE
2973 echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
2975 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2980 if checkstatus cddb-choice >/dev/null; then :; else
2981 echo "abcde: internal error: cddb-choice not recorded." >&2
2984 CDDBDATA="${ABCDETEMPDIR}/cddbread.$(checkstatus cddb-choice)"
2985 CDDBSOURCE=$(cat "${ABCDETEMPDIR}/datasource.$(checkstatus cddb-choice)")
2986 echo -n "Edit selected CDDB data " >&2
2987 if [ "$INTERACTIVE" = "y" ]; then
2988 if [ "$UNKNOWNDISK" = "y" ]; then
2989 echo -n "[Y/n]? " >&2
2991 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2993 echo -n "[y/N]? " >&2
3000 if [ "$EDITCDDB" = "y" ]; then
3001 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
3003 # Use the debian sensible-editor wrapper to pick the editor that the
3004 # user has requested via their $EDITOR environment variable
3005 if [ -x "/usr/bin/sensible-editor" ]; then
3006 /usr/bin/sensible-editor "$CDDBDATA"
3007 elif [ -n "$EDITOR" ]; then
3008 if [ -x "$(which "${EDITOR%%\ *}")" ]; then
3009 # That failed, try to load the preferred editor, starting
3010 # with their EDITOR variable
3013 # If that fails, check for a vi
3014 elif which vi >/dev/null 2>&1; then
3016 elif [ -x /usr/bin/vim ]; then
3017 /usr/bin/vim "$CDDBDATA"
3018 elif [ -x /usr/bin/vi ]; then
3019 /usr/bin/vi "$CDDBDATA"
3020 elif [ -x /bin/vi ]; then
3022 # nano should be on all (modern, i.e., sarge) debian systems
3023 elif which nano >/dev/null 2>&1 ; then
3025 elif [ -x /usr/bin/nano ]; then
3026 /usr/bin/nano "$CDDBDATA"
3027 # mg should be on all OpenBSD systems
3028 elif which mg >/dev/null 2>&1 ; then
3030 elif [ -x /usr/bin/mg ]; then
3031 /usr/bin/mg "$CDDBDATA"
3034 log warning "no editor available. Check your EDITOR environment variable."
3036 # delete editor backup file if it exists
3037 if [ -w "$CDDBDATA~" ]; then
3042 # Some heuristics first. Look at Disc Title, and if it starts with
3043 # "Various", then we'll assume Various Artists
3044 if [ "$(grep -a ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -aEci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
3045 echo "Looks like a Multi-Artist CD" >&2
3048 echo -n "Is the CD multi-artist [y/N]? " >&2
3049 if [ "$INTERACTIVE" = "y" ]; then
3056 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
3059 # Need NUMTRACKS before cddb-tool will return it:
3060 NUMTRACKS=$(grep -a -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
3061 if [ "$(grep -ac "^TTITLE.*\/" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3062 # More than 1/2 tracks contain a "/", so guess forward
3064 elif [ "$(grep -ac "^TTITLE.*\-" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3065 # More than 1/2 contain a "-", so guess forward-dash
3067 elif [ "$(grep -ac "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(( $NUMTRACKS / 2 ))" ]; then
3068 # More than 1/2 contain something in parens, so guess trailing-paren
3072 echo "1) Artist / Title" >&2
3073 echo "2) Artist - Title" >&2
3074 echo "3) Title / Artist" >&2
3075 echo "4) Title - Artist" >&2
3076 echo "5) Artist: Title" >&2
3077 echo "6) Title (Artist)" >&2
3078 echo "7) This is a single-artist CD" >&2
3079 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
3080 if [ "$INTERACTIVE" = "y" ]; then
3081 read VARIOUSARTISTSTYLE
3083 echo $DEFAULTSTYLE >&2
3084 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3086 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
3087 # If they press Enter, then the default style (0) was chosen
3088 while [ "$VARIOUSARTISTSTYLE" -lt 0 ] || [ "$VARIOUSARTISTSTYLE" -gt 7 ]; do
3089 echo "Invalid selection. Please choose a number between 1 and 7."
3090 echo -n "Selection [1-7]: "
3091 read VARIOUSARTISTSTYLE
3092 VARIOUSARTISTSTYLE=$(echo "0$VARIOUSARTISTSTYLE" | xargs printf "%d")
3094 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
3095 VARIOUSARTISTSTYLE="$DEFAULTSTYLE"
3097 vecho "Selected: $VARIOUSARTISTSTYLE"
3098 case "$VARIOUSARTISTSTYLE" in
3100 VARIOUSARTISTSTYLE=forward
3103 VARIOUSARTISTSTYLE=forward-dash
3106 VARIOUSARTISTSTYLE=reverse
3109 VARIOUSARTISTSTYLE=reverse-dash
3112 VARIOUSARTISTSTYLE=colon
3115 VARIOUSARTISTSTYLE=trailing-paren
3123 echo "variousartists=$VARIOUSARTISTS" >> "${ABCDETEMPDIR}/status"
3124 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "${ABCDETEMPDIR}/status"
3126 if [ "$EDITCDDB" = "y" ] && [ "$CDDBSOURCE" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3127 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3128 # This works but does not have the necessary error checking
3129 # yet. If you are familiar with the CDDB spec
3130 # (see http://www.freedb.org/src/latest/DBFORMAT)
3131 # and can create an error-free entry on your own, then put
3132 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3133 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3134 # your abcde.conf to change the email address submissions are
3137 # submit the modified file, if they want
3138 if [ "$NOSUBMIT" != "y" ]; then
3139 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3141 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3142 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3144 echo -n 'Invalid selection. Please answer "y" or "n": '
3147 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3148 echo -n "Sending..."
3149 $CDDBTOOL send "$CDDBDATA" "$CDDBSUBMIT"
3156 # User CDDBLOCALPOLICY to find out if we store the file or not...
3157 # Cache edited CDDB entry in the user's cddb dir
3158 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3159 # Make sure the cache directory exists
3160 mkdir -p "$CDDBLOCALDIR"
3161 NUM_LINES=$(( $(wc -l < "$CDDBDATA") - 1 ))
3162 OUTPUT_FILE="$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)"
3163 tail -n "$NUM_LINES" < "$CDDBDATA" > "${CDDBLOCALDIR}/${OUTPUT_FILE}"
3166 echo "cddb-edit" >> "${ABCDETEMPDIR}/status"
3170 # try to download CD cover
3173 if checkstatus "get-album-art"; then :; else
3175 ALBUMFILE="$(mungealbumname "$DALBUM")"
3176 ARTISTFILE="$(mungeartistname "$DARTIST")"
3177 GENRE="$(mungegenre "$GENRE")"
3178 YEAR=${CDYEAR:-$CDYEAR}
3179 # have we got a musicbrainz mbid or amazon asin?
3180 case "$CDDBMETHOD" in
3182 # try musicbrainz mbid
3183 if [ -s "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)" ]; then
3184 MBID=$(cat "${ABCDETEMPDIR}/mbid.$(checkstatus cddb-choice)")
3185 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3186 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3187 vecho "cover URL: $ALBUMARTURL" >&2
3188 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3189 if [ $? -ne 0 ]; then
3190 vecho "could not download cover from musicbrainz" >&2
3192 if [ -s "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)" ]; then
3193 ASIN=$(cat "${ABCDETEMPDIR}/asin.$(checkstatus cddb-choice)")
3194 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3195 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3196 vecho "cover URL: $ALBUMARTURL" >&2
3197 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3198 if [ $? -ne 0 ]; then
3199 vecho "could not download cover from amazon" >&2
3201 # Check that size is reasonable; sometimes when there is no cover image
3202 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3203 FILESIZE=$(wc -c < "${ABCDETEMPDIR}/$ALBUMARTFILE")
3204 if [ "$FILESIZE" -lt 1024 ]; then
3205 rm "${ABCDETEMPDIR}/$ALBUMARTFILE"
3206 vecho "could not download cover from amazon" >&2
3210 vecho "no amazon ID found" >&2
3214 vecho "no musicbrainz ID found" >&2
3219 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3220 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3221 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "${ABCDETEMPDIR}/$ALBUMARTFILE" $GLYRCOPTS
3222 if [ $? -ne 0 ]; then
3223 vecho "could not download cover with glyrc" >&2
3228 if [ "$INTERACTIVE" = "y" ]; then
3229 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3230 # display properties of coverart when identify is available
3231 if new_checkexec "$IDENTIFY"; then
3232 $IDENTIFY $IDENTIFYOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3234 # display coverart when DISPLAY is set and display command is available
3235 if new_checkexec "$DISPLAYCMD" && [ "$DISPLAY" != "" ]; then
3236 $DISPLAYCMD $DISPLAYCMDOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE" >&2 &
3239 # nothing downloaded yet
3240 vecho "automatic album art downloading failed" >&2
3242 # see if the user can find a better album art manually
3243 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3245 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3246 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3248 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3251 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3252 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3254 if [ ! -z "$ALBUMARTURL" ]; then
3255 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3256 $HTTPGET "$ALBUMARTURL" > "${ABCDETEMPDIR}/$ALBUMARTFILE"
3257 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3258 vecho "unable to download $ALBUMARTURL" >&2
3260 else # it's a local path
3261 cp "$ALBUMARTURL" "${ABCDETEMPDIR}/$ALBUMARTFILE"
3262 if [ ! -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3263 vecho "unable to copy $ALBUMARTURL to ${ABCDETEMPDIR}/$ALBUMARTFILE" >&2
3269 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3270 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ] && new_checkexec "$IDENTIFY"; then
3271 ALBUMARTURLTYPE=$($IDENTIFY "${ABCDETEMPDIR}/$ALBUMARTFILE" | cut -d' ' -f2)
3272 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" ] || [ "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3273 if new_checkexec "$CONVERT"; then
3274 mv "${ABCDETEMPDIR}/$ALBUMARTFILE" "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3275 $CONVERT "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp" $CONVERTOPTS "${ABCDETEMPDIR}/$ALBUMARTFILE"
3276 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
3278 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3279 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE" >&2
3280 vecho "without ImageMagick convert" >&2
3284 # copy to target directories
3285 if [ -s "${ABCDETEMPDIR}/$ALBUMARTFILE" ]; then
3286 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
3288 # put cover in the same place as the album
3289 if [ "$ONETRACK" = "y" ] ; then
3290 if [ "$VARIOUSARTISTS" = "y" ] ; then
3291 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3293 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3296 if [ "$VARIOUSARTISTS" = "y" ] ; then
3297 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3299 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3302 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3303 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3304 mkdir -p "$FINALALBUMARTDIR"
3305 cp "${ABCDETEMPDIR}/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3307 rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
3308 echo "get-album-art=$ALBUMARTURL" >> "${ABCDETEMPDIR}/status"
3310 log warning "could not get cover"
3311 echo "get-album-art=none" >> "${ABCDETEMPDIR}/status"
3316 # Optionally embed the albumart downloaded by the getalbumart fuction.
3317 # FIXME: It would be nice to have this also selectable from within the
3318 # FIXME: getalbumart function itself. Andrew
3322 ALBUMFILE="$(mungealbumname "$DALBUM")"
3323 ARTISTFILE="$(mungeartistname "$DARTIST")"
3324 GENRE="$(mungegenre "$GENRE")"
3325 YEAR=${CDYEAR:-$CDYEAR}
3327 # Allow for multiple output formats:
3328 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
3330 # Find the output directory for multi track encodes:
3331 if [ "$ONETRACK" != "y" ] ; then
3332 if [ "$VARIOUSARTISTS" = "y" ] ; then
3333 FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
3335 FINDPATH="$(eval echo "$OUTPUTFORMAT")"
3338 # Find the output directory for single track encodes:
3339 if [ "$ONETRACK" = "y" ] ; then
3340 if [ "$VARIOUSARTISTS" = "y" ] ; then
3341 FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3343 FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3347 FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
3350 # Instructions for each format, feel free to add more. It would be nice to
3351 # make the backup directory selectable and perhaps also have an option for
3352 # the bold to simply have the image deleted. Work for another day... Andrew.
3353 if [ -e "$ALBUMARTFILE" ] ; then
3358 "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$i"
3360 mkdir "$FINALDIR"/albumart_backup
3361 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3362 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3367 "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
3369 mkdir "$FINALDIR"/albumart_backup
3370 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3371 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3376 "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
3378 mkdir "$FINALDIR"/albumart_backup
3379 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3380 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3385 "$WVTAG" --write-binary-tag "Cover Art (Front)=@$ALBUMARTFILE" "$i"
3387 mkdir "$FINALDIR"/albumart_backup
3388 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3389 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3393 # This technique is drawn from 2 sources (the first link being the primary source):
3394 # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
3395 # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
3396 # In abcde a few steps are used in this sequence:
3398 # 1. Create a 'legal' header for the cover art image
3399 # 2. Makes a copy of the existing tags
3400 # 3. base64 the cover art image
3401 # 4. Copy the original tags + the base64 image back to the original ogg file
3403 # Might need some fine tuning but it is a start for abcde 2.8.2 Andrew.
3404 # FIXME: I am not sure if there is a maximum size for images converted in this
3405 # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
3407 # First some variables we can reuse:
3408 # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
3409 MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
3410 EXPORTTAGS="${ABCDETEMPDIR}/export_ogg_tags"
3411 BUILDHEADER="${ABCDETEMPDIR}/build_header"
3412 # Now build the header, gory details are here:
3413 # https://xiph.org/flac/format.html#metadata_block_picture
3415 printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
3417 printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3419 echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
3420 # Description length. FIXME: I have used 'Cover Image' but I am not sure
3421 # if this is better left as an empty field. Andrew
3422 printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3424 echo -n "Cover Image" >> "$BUILDHEADER"
3426 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3428 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3429 # Picture color depth:
3430 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3431 # Picture color count:
3432 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3434 printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
3435 # cat the image file:
3436 cat "$ALBUMARTFILE" >> "$BUILDHEADER"
3437 # Now process each ogg file by first exporting the original tags then
3438 # appending the cover image and finally copying the whole thing back
3439 # to the original image:
3442 # Make a backup of the existing tags:
3443 "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
3444 # base64 the file and then mix it all together with the exported tags:
3445 echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
3446 # Update the original ogg file with exported tags and the appended base64'd image:
3447 "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
3448 # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
3449 # note that the header file BUILDHEADER will be reused for each file in the loop:
3452 mkdir "$FINALDIR"/albumart_backup
3453 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3454 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3456 *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
3459 vecho "Suitable cover image not found, no embedding done..." >&2
3464 # do_cdread [tracknumber]
3465 # do_cdread onetrack [firsttrack] [lasttrack]
3469 # The commands here don't go through run_command because they're never supposed to be silenced
3470 # return codes need to be doublechecked anyway, however
3471 if [ "$1" = "onetrack" ]; then
3472 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3473 # FIXME # Until then, we grab the whole CD in one track, no matter what
3475 # We need the first and last track for cdda2wav/icedax
3477 LASTTRACK=$(expr $3 + 0)
3478 UTRACKNUM=$FIRSTTRACK
3479 case "$CDROMREADERSYNTAX" in
3480 flac) READTRACKNUMS="-" ;;
3483 # Add a variable to check if tracks are provided in command line and if not, rip the whole CD
3484 # We must make sure to rip from sector 0, both lines below work
3485 # READTRACKNUMS="-- -$LASTTRACK" ;;
3486 READTRACKNUMS="[.0]-" ;;
3487 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3488 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3489 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3495 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
3496 if [ "$USEPIPES" = "y" ]; then
3497 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3498 FILEARG="$( eval echo "\$$TEMPARG" )"
3499 PIPE_MESSAGE="and encoding "
3501 WAVDATA="${ABCDETEMPDIR}/track$UTRACKNUM.wav"
3502 case "$CDROMREADERSYNTAX" in
3503 ## FIXME ## Find the cases for flac, to avoid exceptions
3505 FILEARG="--output-name=$WAVDATA"
3512 if [ "$1" = "onetrack" ]; then
3513 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3515 if [ -r "$CDDBDATA" ]; then
3516 getcddbinfo TRACKNAME
3517 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3519 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3522 case "$CDROMREADERSYNTAX" in
3523 ### FIXME ### use an exception for flac, since it uses -o
3524 ### FIXME ### Shall we just use -o $FILEARG ??
3526 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3527 STRIPTRACKNUM=$(expr $UTRACKNUM + 0 )
3528 nice $READNICE $FLAC -d -f --cue="${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0}" "$FILEARG" "$CDROM" ;;
3530 if [ "$USEPIPES" = "y" ]; then
3531 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG"
3533 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG" >&2
3537 if [ "$OSFLAVOUR" = "OSX" ] ; then
3538 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3539 diskutil unmount "${CDROM#/dev/}"
3540 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3541 CDDA2WAVCDROM="IODVDServices"
3542 elif [ "$OSFLAVOUR" = "FBSD" ] || [ "$OSFLAVOUR" = "IRIX" ]; then
3543 CDDA2WAVCDROM="$CDROMID"
3545 if [ "$CDROMID" = "" ]; then
3546 CDDA2WAVCDROM="$CDROM"
3548 CDDA2WAVCDROM="$CDROMID"
3551 if [ "$USEPIPES" = "y" ]; then
3552 nice $READNICE $CDROMREADER -D "$CDDA2WAVCDROM" -t "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG"
3554 nice $READNICE $CDROMREADER -D "$CDDA2WAVCDROM" -t "${READTRACKNUMS:-$UTRACKNUM}" "$FILEARG" >&2
3558 # I cannot get USEPIPES to work with dagrab so just this:
3559 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v "$UTRACKNUM" >&2
3562 if [ "$USEPIPES" = "y" ]; then
3563 nice $READNICE $CDROMREADER -j "${READTRACKNUMS:-$UTRACKNUM}" "$CDROM" "$FILEARG"
3565 # Write ripped audio data to stdout and redirect to $FILEARG.
3566 # Progress is written to stderr by default and thus >&2 is not required.
3567 nice $READNICE $CDROMREADER -j "${READTRACKNUMS:-$UTRACKNUM}" "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3571 # Find the track's mounted path
3572 REALTRACKNUM=$(expr $UTRACKNUM + 0) # Unpad
3573 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3574 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3575 # If the file exists, copy it
3576 if [ -e "$FILEPATH" ] ; then
3577 if [ "$USEPIPES" = "y" ]; then
3578 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3580 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3586 if [ "$USEPIPES" = "y" ]; then
3587 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -w "$UTRACKNUM-[:1]" "$FILEARG"
3589 nice $READNICE $CDROMREADER -"$CDPARANOIACDROMBUS" "$CDROM" -w "$UTRACKNUM-[:1]" "$FILEARG" >&2
3594 # If we get some error or we get some missing wav
3595 # (as long as we dont use pipes)
3596 if [ "$RETURN" != "0" ] || ( [ ! -s "$WAVDATA" ] && [ X"$USEPIPES" != "Xy" ] ); then
3597 # Thank goodness errors is only machine-parseable up to the
3598 # first colon, otherwise this woulda sucked
3599 if [ "$RETURN" = "0" ] || [ ! -s "$WAVDATA" ]; then
3600 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3602 if [ "$USEPIPES" = "y" ]; then
3603 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3605 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
3609 if [ "$USEPIPES" = "y" ]; then
3610 echo "readencodetrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
3612 echo "readtrack-$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
3614 if [ "$1" = "onetrack" ]; then
3615 echo onetrack >> "${ABCDETEMPDIR}/status"
3621 # No values accepted, only uses env variables
3624 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3625 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3627 echo "abcde: unable to set the device speed" >&2
3633 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3636 if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 0 ] ; then
3638 warning) shift ; log warning "$@" ;;
3646 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3649 if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 1 ] ; then
3651 warning) shift ; log warning "$@" ;;
3659 # decho outputs a debug message if DEBUG is selected
3662 if [ x"$DEBUG" != "x" ]; then
3663 if echo "$1" | grep "^\[" > /dev/null 2>&1 ; then
3664 DEBUGECHO=$(echo "$@" | tr -d '[]')
3665 echo >&4 "[DEBUG] $DEBUGECHO: $(eval echo \\$${DEBUGECHO})"
3667 echo >&4 "[DEBUG] $1"
3672 # User-redefinable functions
3673 # Custom filename munging:
3676 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3679 # Custom filename munging specific to track names:
3685 # Custom filename munging specific to artist names:
3691 # Custom filename munging specific to album names:
3697 # Custom genre munging:
3700 echo "$CDGENRE" | tr "[:upper:]" "[:lower:]"
3704 # Empty pre_read function, to be defined in the configuration file.
3711 # Empty post_read function, to be defined in the configuration file.
3718 # Empty post_encode function, to be defined in the configuration file.
3724 ###############################################################################
3727 # Start of execution
3728 ###############################################################################
3733 # Currently three supported options ("musicbrainz", "cddb" for freedb.org and "cdtext")
3734 CDDBMETHOD=musicbrainz
3735 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3736 CDDBSUBMIT=freedb-submit@freedb.org
3738 HELLOINFO="$(whoami)@$(hostname)"
3740 CDDBLOCALPOLICY="always"
3741 CDDBLOCALRECURSIVE="y"
3742 CDDBLOCALDIR="$HOME/.cddb"
3745 # List of fields we parse and show during the CDDB parsing...
3746 SHOWCDDBFIELDS="year,genre"
3749 #CDROMREADERSYNTAX=cdparanoia
3750 ENCODERSYNTAX=default
3752 MP3ENCODERSYNTAX=default
3753 OGGENCODERSYNTAX=default
3754 OPUSENCODERSYNTAX=default
3755 MKAENCODERSYNTAX=default
3756 AIFFENCODERSYNTAX=default
3757 FLACENCODERSYNTAX=default
3758 SPEEXENCODERSYNTAX=default
3759 MPCENCODERSYNTAX=default
3760 WVENCODERSYNTAX=default
3761 TTAENCODERSYNTAX=default
3762 APENCODERSYNTAX=default
3763 MP2ENCODERSYNTAX=default
3764 AACENCODERSYNTAX=default
3765 NORMALIZERSYNTAX=default
3766 CUEREADERSYNTAX=default
3768 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3769 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3770 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3771 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3772 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3773 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3774 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3775 PLAYLISTDATAPREFIX=''
3776 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3777 VAPLAYLISTDATAPREFIX=''
3785 VARIOUSARTISTSTYLE=forward
3792 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3793 # i.e. CDROMID="1,0,0"
3795 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3796 # If we are using the ide-scsi emulation layer, we need to define a "g"
3797 CDPARANOIACDROMBUS="d"
3799 # program paths - defaults to checking your $PATH
3805 XINGMP3ENC=xingmp3enc
3819 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3823 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3833 NEROAACENC=neroAacEnc
3835 # Note that the qaac PATH will almost always require adjustment
3836 # as it is a Windows application being run through Wine. More
3837 # detailed notes in the sample abcde.conf file in the abcde tarball.
3840 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3848 VORBISCOMMENT=vorbiscomment
3850 NEROAACTAG=neroAacTag
3851 ATOMICPARSLEY=AtomicParsley
3855 CDPARANOIA=cdparanoia
3856 CD_PARANOIA="cd-paranoia"
3861 CDDISCID="cd-discid"
3863 MUSICBRAINZ=abcde-musicbrainz-tool
3867 NORMALIZE="normalize-audio"
3869 VORBISGAIN=vorbisgain
3873 # For Wavpack replay gain we set both the default of 'track gain'
3874 # as well as this option for 'album gain'. Better media players
3875 # such as vlc can select either or neither. Andrew.
3886 # Options for programs called from abcde:
3889 # These options needed by FFmpeg for tagging and selection of id3v2 version:
3890 # 1. '-write_id3v2 1' allows id3v2 tagging while '-write_id3v2 0' disables tagging
3891 # 2. '-id3v2_version 4' gives version id3v2.4 while '3' gives id3v2.3
3892 AIFFENCOPTS="-write_id3v2 1 -id3v2_version 4"
3904 VORBISGAINOPTS="--album"
3908 # The flac option is a workaround for an error where flac fails
3909 # to encode with error 'floating point exception'. This is flac
3910 # error in get_console_width(), corrected in flac 1.3.1
3912 FLACGAINOPTS="--add-replay-gain"
3919 # True Audio has no useful options but it is here anyway :)
3922 # Monkey's Audio Console (mac) chokes without a mode setting
3923 # so we set one here.
3930 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3931 # we set bitrate here.
3932 FDKAACENCOPTS='--bitrate 192k'
3954 VORBISCOMMENTOPTS="-R"
3955 METAFLACOPTS="--no-utf8-convert"
3960 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3962 # Defaults for album art downloads
3963 ALBUMARTFILE="cover.jpg"
3965 ALBUMARTALWAYSCONVERT="n"
3967 # Default to one process if -j isn't specified
3970 # List of actions to perform - by default, run to completion
3971 ACTIONS=cddb,read,encode,tag,move,clean
3973 # This option is basically for Debian package dependencies:
3974 # List of preferred outputs - by default, run with whatever we have in the path
3975 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:fdkaac:opus
3977 # List of preferred cdromreaders - by default, run whichever we have in the path
3978 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3980 # fd for when `vecho` and `log info` called with redirected stdout
3983 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3984 # Linux/OpenBSD. ftp is user for NetBSD.
3985 # Let's use these checkings to determine the OS flavour, which will be used
3988 if [ X"$UNAME" = "XFreeBSD" ] ; then
3993 elif [ X"$UNAME" = "XDarwin" ] ; then
3995 # By default md5sum is not installed, use md5 instead:
3998 # We should have diskutil in OSX, but let's be sure...
4000 CDROMREADERSYNTAX=cddafs
4001 # We won't find the eject program in OSX, and doing checkexec will fail further below...
4003 elif [ X"$UNAME" = "XOpenBSD" ] ; then
4007 elif [ X"$UNAME" = "XNetBSD" ] ; then
4011 elif [ X"$UNAME" = X"SunOS" ] ; then
4015 elif [ X"$UNAME" = X"IRIX64" ] ; then
4019 # Apparently necessary - see
4020 # https://abcde.einval.com/bugzilla/show_bug.cgi?id=29
4021 CDDISCID_NEEDS_PAUSE=y
4026 # If CDDBAVAIL is set to n, no CDDB read is done
4030 # But before we get into business, let us chop off any GREP environmental
4035 # Length of the terminal *should* be in $LINES. If it's not, guess at
4036 # a reasonable number instead
4037 if [ -z "$LINES" ]; then
4041 if [ -z "$OUTPUTDIR" ]; then
4045 if [ -z "$WAVOUTPUTDIR" ]; then
4046 WAVOUTPUTDIR="$OUTPUTDIR"
4049 # Load system defaults
4050 if [ -r /etc/abcde.conf ]; then
4053 # Load user preference defaults
4054 if [ -r "$HOME/.abcde.conf" ]; then
4055 . "$HOME/.abcde.conf"
4058 # By this time, we need some HTTPGETOPTS already defined.
4059 # If the user has defined a non-default HTTPGET method, we should not be empty.
4061 if [ "$HTTPGETOPTS" = "" ] ; then
4063 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
4064 curl) HTTPGETOPTS="-f -s -L";;
4065 fetch)HTTPGETOPTS="-q -o -";;
4066 ftp) HTTPGETOPTS="-a -V -o - ";;
4067 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
4071 # If the CDROM has not been set yet, find a suitable one.
4072 # If this is a devfs system, default to /dev/cdroms/cdrom0
4073 # instead of /dev/cdrom
4074 if [ "$CDROM" = "" ] ; then
4075 if [ -e /dev/cdroms/cdrom0 ]; then
4076 CDROM=/dev/cdroms/cdrom0
4077 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
4078 CDROM=/dev/${BASH_REMATCH[1]}
4079 elif [ -e /dev/cdrom ]; then
4081 elif [ -e /dev/sr0 ]; then
4083 elif [ -e /dev/cd0c ]; then
4085 elif [ -e /dev/acd0c ]; then
4087 elif [ -e /dev/disk1 ]; then
4092 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
4093 # that's changed to a number to allow for more control. Deal with
4094 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
4095 case "$EXTRAVERBOSE" in
4104 # Parse command line options
4105 while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pPQ:r:s:S:t:T:UvVxX:w:W:z opt ; do
4108 a) ACTIONS="$OPTARG" ;;
4109 A) EXPACTIONS="$OPTARG" ;;
4111 B) GETALBUMART=y ; EMBEDALBUMART=y ;;
4112 c) if [ -e "$OPTARG" ]; then
4115 log error "config file \"$OPTARG\" cannot be found."
4119 C) CDDBDISCID="$( echo "${OPTARG#abcde.}" | tr -d /)" ;;
4120 d) CDROM="$OPTARG" ;;
4123 e) ERASEENCODEDSTATUS=y ;;
4124 E) ENCODING="$OPTARG" ;;
4129 j) MAXPROCS="$OPTARG" ;;
4132 L) CDDBUSELOCAL=y ;;
4137 o) OUTPUTTYPE="$OPTARG" ;;
4140 Q) CDDBMETHOD="$OPTARG" ;;
4141 r) REMOTEHOSTS="$OPTARG" ;;
4142 R) CDDBLOCALRECURSIVE=y ;;
4143 s) SHOWCDDBFIELDS="$OPTARG" ;;
4144 S) CDSPEEDVALUE="$OPTARG" ;;
4145 t) STARTTRACKNUMBER="$OPTARG" ;;
4146 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
4149 echo "This is abcde v$VERSION."
4150 echo "Usage: abcde [options] [tracks]"
4151 echo "abcde -h for extra help"
4154 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
4156 X) CUE2DISCID="$OPTARG" ;;
4157 w) COMMENT="$OPTARG" ;;
4158 W) if echo "$OPTARG" | grep "[[:digit:]]" > /dev/null 2>&1 ; then
4159 STARTTRACKNUMBER="${OPTARG}$(printf "%02d" "${STARTTRACKNUMBER:-01}")"
4160 STARTTRACKNUMBERTAG="y"
4161 COMMENT="CD${OPTARG}"
4162 DISCNUMBER="${OPTARG}"
4164 log error "argument of -W must be integer"
4168 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
4173 shift $(($OPTIND - 1))
4175 # Here it comes the worse part of the whole thing. From here until we start
4176 # ripping, we have a mixture of sanity checks, verifications, default settigs
4177 # and other crazy stuff that interdepends, but hey, someone has to do it.
4179 # If NOCDDBQUERY is set, don't query the CDDB server.
4180 if [ "$NOCDDBQUERY" = "y" ]; then
4184 # If the user specified a flac file, then switch to special flac mode
4185 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
4186 if [ ! -f "$CDROM" ]; then
4187 log error "the defined file for FLAC ripping cannot be found" >&2
4190 vecho warning "switching to flac CDROMREADERSYNTAX..."
4191 CDROMREADERSYNTAX=flac
4192 # We have a builtin version of cue2discid...
4193 case "$CUE2DISCID" in
4195 *) NEEDCUE2DISCID=y;;
4201 # If the user provided a CDDBDISCID, disable eject
4202 if [ -n "${CDDBDISCID}" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
4204 # Check the available cd rippers in the system, from the ones we know.
4205 if [ "$CDROMREADERSYNTAX" = "" ]; then
4206 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
4207 if new_checkexec "$DEFAULT_CDROMREADER"; then
4208 CDROMREADERSYNTAX="$DEFAULT_CDROMREADER"
4212 if [ "$CDROMREADERSYNTAX" = "" ]; then
4213 log error "no cdreader found in your PATH"
4214 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4219 # Decide if we can continue.
4220 if [ "$ONETRACK" = "y" ]; then
4221 # FIXME # remove check as soon as we find out about the other readers
4222 case "$CDROMREADERSYNTAX" in
4224 cdparanoia | libcdio) ;;
4225 cdda2wav | icedax) ;;
4227 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
4230 if [ "$BATCHNORM" = "y" ]; then
4231 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
4234 if [ "$NOGAP" = "y" ]; then
4235 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
4238 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
4239 # FIXME # allow ranges of tracks to be selected for onetrack ripping
4240 if [ $# -gt 0 ]; then
4241 log warning "ONETRACK mode selected, grabbing all tracks..."
4244 while [ $# -gt 0 ]; do
4245 # Range parsing code courtesy of Vincent Ho
4246 # Cleaned up to use shell built-ins by Charles Steinkuehler
4247 if [ "${1#*[^0-9-]}" != "$1" ]; then
4248 log error "syntax error while processing track numbers ($1)"
4253 while [ "${RSTART:=1}" -le "${REND:=0}" ] ; do
4254 TRACKQUEUE="$TRACKQUEUE $RSTART"
4255 RSTART=$(( $RSTART + 1 ))
4262 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
4263 # List of experimental actions: retag,transcode
4265 # Determine what actions are to be done from $ACTIONS and set the
4266 # following environment variables for them:
4278 ## FIXME ## Lets keep compatibility with -M
4279 [ "$DOCUE" != "y" ] && DOCUE=n
4281 for ACTION in $(echo "$ACTIONS" | tr , \ )
4284 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4285 cue) DOCUE=y ; MAKECUEFILE=y ;;
4288 normalize) DONORMALIZE=y; DOREAD=y;;
4289 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4290 encode) DOENCODE=y; DOREAD=y;;
4291 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4292 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4293 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4294 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4295 playlist) DOCDDB=y; DOPLAYLIST=y;;
4297 getalbumart) GETALBUMART=y;;
4298 embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
4302 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4303 # FIXME # should we abort on error or just inform the user?
4304 log warning "selected both normalize and replaygain actions"
4307 for SHOWCDDBFIELD in $(echo "$SHOWCDDBFIELDS" | tr , \ ); do
4308 case $SHOWCDDBFIELD in
4309 y*|Y*) SHOWCDDBYEAR="y";;
4310 g*|G*) SHOWCDDBGENRE="y";;
4315 # At this point a CDROM has to be defined, so we check it exists.
4316 if [ X"$CDROM" != "X" ] ; then
4317 if [ "$NEEDCDROMID" = "y" ] ; then
4318 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ]; then
4319 if [ "$OSFLAVOUR" = "IRIX" ]; then
4320 if [ -z "$CDROMID" ]; then
4321 CDROMID="$(echo "$CDROM" | sed -e 's;/dev/scsi/sc\([0-9]*\)d\([0-9]*\)l\([0-9]*\)$;\1,\2,\3;')"
4324 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
4325 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4326 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4330 elif [ ! -e "$CDROM" ] && [ X"$DOREAD" = "Xy" ]; then
4331 log error "CDROM device cannot be found."
4334 # avoid processing if we are not going to hit the CDROM.
4335 elif [ X"$DOREAD" = "Xy" ]; then
4336 log error "CDROM has not been defined or cannot be found"
4340 # USEPIPES pre-tests, before we get into more serious stuff
4341 # Not compatible with:
4342 # - multiple outputs
4344 # - lowdisk algorithm
4346 if [ X"$USEPIPES" = "Xy" ]; then
4347 NUM_OUTPUT_TYPES="$(echo "$OUTPUTTYPE" | tr , \ | wc -w )"
4348 if [ "$NUM_OUTPUT_TYPES" -gt 1 ]; then
4349 log error "Unix pipes not compatible with multiple outputs"
4352 if [ X"$DONORMALIZE" = "Xy" ]; then
4353 log error "Unix pipes not compatible with normalizer"
4354 # FIXME # Do we need to exit or shall we just disable the mode?
4357 if [ X"$BATCHNORM" = "Xy" ]; then
4358 log error "Unix pipes not compatible with BATCHNORM encoding"
4361 if [ X"$NOGAP" = "Xy" ]; then
4362 log error "Unix pipes not compatible with NOGAP encoding"
4365 if [ X"$DOENCODE" = "Xn" ]; then
4366 vecho warning "Disabling Unix pipes since we are not encoding!"
4369 if [ X"$LOWDISK" = "Xy" ]; then
4370 log error "Unix pipes not compatible with lowdisk algorithm"
4375 # LOWDISK pre-tests, before we get into more problematic stuff
4376 # Not compatible with anything that needs all the files in the hard disc:
4379 if [ X"$LOWDISK" = "Xy" ]; then
4380 if [ X"$BATCHNORM" = "Xy" ]; then
4381 log error "Unix pipes not compatible with BATCHNORM encoding"
4384 if [ X"$NOGAP" = "Xy" ]; then
4385 log error "Unix pipes not compatible with NOGAP encoding"
4390 # BATCHNORM pre-tests, before we get into serious problems
4391 # Not compatible with
4392 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4393 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4397 # Check the encoding format from the ones available in the system, if nothing has been configured.
4398 if [ X"$OUTPUTTYPE" = "X" ]; then
4399 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4400 DEFAULT_OUTPUT_FORMAT="$(echo "$DEFAULT_OUTPUT" | cut -d ":" -f 1)"
4401 DEFAULT_OUTPUT_BINARY="$(echo "$DEFAULT_OUTPUT" | cut -d ":" -f 2)"
4402 if [ -x "$(which "$DEFAULT_OUTPUT_BINARY")" ] ; then
4403 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4404 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4408 if [ X"$OUTPUTTYPE" = "X" ]; then
4409 log error "no encoder found in the PATH"
4410 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4415 # Decide which CDROM reader we're gonna use
4416 case "$CDROMREADERSYNTAX" in
4418 CDROMREADER="$CDPARANOIA"
4419 CDROMREADEROPTS="$CDPARANOIAOPTS"
4422 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4423 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4424 CDROMREADER="$CD_PARANOIA"
4425 CDROMREADEROPTS="$CDPARANOIAOPTS"
4428 CDROMREADER="$CDDA2WAV"
4429 CDROMREADEROPTS="$CDDA2WAVOPTS"
4432 CDROMREADER="$DAGRAB"
4433 CDROMREADEROPTS="$DAGRABOPTS"
4437 CDROMREADEROPTS="$PIRDOPTS"
4440 CDROMREADER="$CDDAFS"
4441 CDROMREADEROPTS="$CDDAFSOPTS"
4445 CDROMREADEROPTS="$FLACOPTS"
4449 # There's only one normalize...
4450 case "$NORMALIZERSYNTAX" in
4452 NORMALIZER="$NORMALIZE"
4453 NORMALIZEROPTS="$NORMALIZEOPTS"
4457 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4458 case "$OUTPUTTYPE" in *:*)
4459 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4460 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4462 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4463 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4464 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4465 aiff:*) AIFFENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4466 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4467 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4468 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4469 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4470 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4471 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4472 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4473 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4474 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4477 # Allows commandline selection of options while using multiple outputs.
4478 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4479 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4480 TEMPOUTPUT=${OUTPUT%%:*}
4481 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4483 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4487 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4488 # for flacs and speexenc for speex and mpcenc for mpcs and fdkaac for m4as and
4489 # wavpack for wvs...
4491 # Getting ready for multiple output changes
4492 for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
4496 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4497 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4498 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4499 OGGOUTPUTCONTAINER=ogg
4502 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4503 OPUSOUTPUTCONTAINER=opus
4506 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4507 MKAOUTPUTCONTAINER=mka
4510 [ "$AIFFENCODERSYNTAX" = "default" ] && AIFFENCODERSYNTAX=ffmpeg
4511 AIFFOUTPUTCONTAINER=aiff
4514 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4515 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4516 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4517 [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
4520 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4521 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4522 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4523 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4524 [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
4527 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4528 # [ "$DOREPLAYGAIN" = "y" ] &&
4531 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4532 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4535 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4537 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4538 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4539 [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
4542 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4543 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4546 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4547 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4548 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4551 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4552 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4553 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4556 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4558 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4559 # compiled without libmp4v2... Andrew.
4562 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=fdkaac
4563 [ "$AACENCODERSYNTAX" = "faac" ] && [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4564 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4565 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4566 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4567 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4568 [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
4571 if [ "$KEEPWAVS" = "y" ]; then
4572 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4576 *) log error "Invalid OUTPUTTYPE defined"
4582 # decide which encoder
4583 case "$MP3ENCODERSYNTAX" in
4585 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4589 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4593 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4594 MP3ENCODER="$BLADEENC"
4597 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4601 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4602 MP3ENCODER="$XINGMP3ENC"
4605 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4606 MP3ENCODER="$MP3ENC"
4609 case "$OGGENCODERSYNTAX" in
4611 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4612 OGGENCODER="$VORBIZE"
4615 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4616 OGGENCODER="$OGGENC"
4619 case "$OPUSENCODERSYNTAX" in
4621 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4622 OPUSENCODER="$OPUSENC"
4625 case "$MKAENCODERSYNTAX" in
4627 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4628 MKAENCODER="$FFMPEG"
4631 case "$AIFFENCODERSYNTAX" in
4633 AIFFENCODEROPTS="${AIFFENCODEROPTSCLI:-$AIFFENCOPTS}"
4634 AIFFENCODER="$FFMPEG"
4637 case "$FLACENCODERSYNTAX" in
4639 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4641 if [ "$DOREPLAYGAIN" = "y" ]; then
4642 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4644 # FLAC streams can be encapsulated on a Ogg transport layer
4645 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4646 log error "FLAC on an Ogg container is not yet supported"
4647 log error "due to problem with adding comments to such files"
4649 FLACOUTPUTCONTAINER=ogg
4651 FLACOUTPUTCONTAINER=flac
4655 case "$SPEEXENCODERSYNTAX" in
4657 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4658 SPEEXENCODER="$SPEEXENC"
4661 case "$MPCENCODERSYNTAX" in
4663 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4664 MPCENCODER="$MPCENC"
4667 case "$WVENCODERSYNTAX" in
4669 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4670 # and in the interests of backward compatibility:
4671 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4672 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4673 WVENCODER="$WAVPACK"
4675 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4676 WVENCODER="$WAVPACK"
4680 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4684 case "$TTAENCODERSYNTAX" in
4686 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4690 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4691 TTAENCODER="$TTAENC"
4694 case "$APENCODERSYNTAX" in
4696 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4700 case "$MP2ENCODERSYNTAX" in
4702 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4703 MP2ENCODER="$TWOLAME"
4706 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4707 MP2ENCODER="$FFMPEG"
4710 case "$AACENCODERSYNTAX" in
4711 # Some elaborate 'if' work to keep backward compatibility for those
4712 # who don't realise that AACENCOPTS does not work with abcde from
4713 # version 2.7 onwards.
4715 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4716 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4719 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4724 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4725 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4726 AACENCODER="$NEROAACENC"
4728 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4729 AACENCODER="$NEROAACENC"
4733 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4734 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4735 AACENCODER="$FDKAAC"
4737 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4738 AACENCODER="$FDKAAC"
4742 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4743 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4746 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4751 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4752 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4753 AACENCODER="$FHGAACENC"
4755 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4756 AACENCODER="$FHGAACENC"
4760 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4761 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4762 AACENCODER="$FFMPEG"
4764 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4765 AACENCODER="$FFMPEG"
4775 TAGGEROPTS="$ID3OPTS"
4780 TAGGEROPTS="$ID3V2OPTS"
4785 TAGGEROPTS="$ID3TAGOPTS"
4789 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4790 # trouble with CDDBPROTO=5 (which we test here) but also
4791 # with cached cddb files in latin1 (which we cannot test).
4792 if [ "$CDDBPROTO" -lt 6 ]; then
4793 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4796 # eyeD3 version 0.7 changed syntax
4797 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4798 # only if it offers the --set-encoding, assume <= 0.6.x
4800 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4802 # anything wrong, any failure, assume >= 0.7
4804 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4808 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4813 # NOGAP is specific to lame. Other encoders fail ...
4814 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4815 log warning "the NOGAP option is specific to lame. Deactivating..."
4820 case "$CUEREADERSYNTAX" in
4822 CUEREADEROPTS="${CDROM}"
4826 CUEREADEROPTS="$MKCUEOPTS ${CDROM}"
4831 # which information retrieval tool are we using?
4837 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4838 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4839 log error "FLAC on an Ogg container is not yet supported"
4840 log error "due to problem with adding comments to such files"
4842 OGGOUTPUTCONTAINER=ogg.ogg
4843 FLACOUTPUTCONTAINER=flac.ogg
4844 vecho warning "modified file endings due to conflicting transport"
4845 vecho warning "layers in Ogg/Vorbis and Ogg/FLAC"
4848 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4850 if [ "$ENCNICE" ]; then
4851 ENCNICE="-n $ENCNICE"
4853 if [ "$READNICE" ]; then
4854 READNICE="-n $READNICE"
4856 if [ "$DISTMP3NICE" ]; then
4857 DISTMP3NICE="-n $DISTMP3NICE"
4860 # Don't check for stuff if it's not needed
4861 if [ "$REMOTEHOSTS" ]; then
4864 if [ "$DONORMALIZE" = "y" ]; then
4867 if [ "$EJECTCD" = "y" ]; then
4870 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4871 # Need an http tool to be able to do CDDB
4877 if [ "$DOCUE" = "y" ]; then
4881 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4882 case "$CDROMREADERSYNTAX" in
4883 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4884 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4885 ### FIXME ### translate "cue2discid" from python to bash
4886 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4891 if [ "$GETALBUMART" = "y" ]; then
4896 ###USEPIPESSUPPORT###
4898 # Rippers with USEPIPE support
4899 PIPERIPPER_cdparanoia="-"
4900 PIPERIPPER_libcdio="-"
4901 # Note that by default in abcde cdda2wav redirects to icedax.
4902 PIPERIPPER_cdda2wav="-"
4903 PIPERIPPER_debug="-"
4904 PIPERIPPER_flac="-c "
4907 # Encoders with USEPIPE support
4910 PIPE_bladeenc="stdin"
4923 # Both neroAacEnc and fdkaac seem to manage without the addition of
4924 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4925 # in this manner. Andrew.
4929 # Figure out if we can use pipes with the ripper/encoder combination
4931 if [ "$USEPIPES" = "y" ]; then
4932 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4935 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4937 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4939 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4941 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4943 PIPEENCODERSVARCHECK="PIPE_$AIFFENCODERSYNTAX" ;;
4945 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4947 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4949 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4951 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4953 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4955 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4957 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4959 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4960 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4961 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4962 log error "no support for pipes with given ripper"
4963 log error "read the FAQ file from the source tarball to get help."
4966 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4967 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4968 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4969 log error "no support for pipes with given encoder"
4970 log error "read the FAQ file from the source tarball to get help"
4975 # Make sure a buncha things exist
4976 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4977 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4978 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER $AIFFENCODER \
4979 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4980 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4981 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4982 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4983 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4984 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4985 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4986 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4987 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4988 ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
4993 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4994 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4995 # these files). The resulting files are actually ADTS streams which belong in an
4996 # aac container and with some version sniffing this is all cleaned up below. If
4997 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4999 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
5000 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
5001 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
5002 echo "WARNING: Your copy of Faac does not have mp4 support"
5003 echo "WARNING: Encoding untagged files to aac..."
5004 # Replace m4a with aac for single and multi-output encodes:
5005 OUTPUTTYPE=$(echo "$OUTPUTTYPE" | sed 's/m4a/aac/')
5007 echo "Using Faac to Tag AAC Tracks..."
5011 # And last but not least, check if we can diff between files. We do not abort,
5012 # since diffing is not critical...
5013 if [ -x "$(which "$DIFF")" ]; then :; else
5014 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
5018 ## Now that we have metaflac, check if we need cue2discid
5019 #case $CDROMREADERSYNTAX in
5021 # CDDBTRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
5022 # if [ "$CDDBTRACKINFO" = "" ]; then
5023 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
5028 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
5029 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
5030 HTTPGET="$HTTPGET $HTTPGETOPTS"
5032 # Here it used to say:
5033 # One thousand lines in, we can start doing stuff with things
5034 # Well, right now we are at line 3737 ;)
5035 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
5037 # Export needed things so they can be read in this subshell
5038 export CDDBTOOL # Path and options for the tool to query CDDB
5039 export ABCDETEMPDIR # Path to the tmpdir for this rip
5040 export TRACKQUEUE # 0-padded list of tracks to be processed
5041 export LOWDISK # Are we using the low-diskspace algorithm?
5042 export EJECTCD # Should we eject the CD when we're finished ripping?
5043 export EJECT # The commend to use to eject the CD, if we have one
5044 export EJECTOPTS # Options to that command
5045 export CDROM # Device path for the CD device
5046 export CDDBDATA # The filename we're using for CD lookup data
5047 export REMOTEHOSTS # List of remote hosts for parallel encoding, if given
5048 export MAXPROCS # The number of *local* encodes to do in parallel
5049 export HTTPGET # Program to use to grab files via http
5050 export MD5SUM # Program to calculate MD5 checksums
5052 if [ "$DOREAD" = "y" ]; then
5053 # User-definable function to set some things. Use it for
5054 # - closing the CD tray with eject -t
5055 # - set the CD speed value with eject -x
5056 vecho -n "Executing customizable pre-read function... "
5058 pre_read # Execute the user-defined pre-read function. Close the CD with it.
5063 # Get ABCDETEMPDIR created and status file initialized
5066 if [ "$DOCDDB" = "y" ]; then
5067 # start with a sane default:
5068 CDDBLOCALSTATUS=notfound
5069 if [ $CDDBUSELOCAL = "y" ]; then
5072 if checkstatus cddb-choice > /dev/null; then
5076 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
5078 for CDDBMETHCHOICE in $(echo "$CDDBMETHOD" | tr -d ' ' | tr , ' ')
5080 addstatus "Lookup method $idx: $CDDBMETHCHOICE"
5082 vecho "Found $NUM_CDDB_MATCHES matches so far"
5083 vecho "Trying lookup method ${CDDBMETHCHOICE}"
5085 # Run all the desired data acquisition methods, in the order
5086 # specified by the user. Each will use its own temporary
5087 # subdirectory, then copy the cddbread.* etc. files up into
5089 case "$CDDBMETHCHOICE" in
5100 echo "Unknown lookup method $CDDBMETHCHOICE. Aborting." >&2
5107 rm -f "${ABCDETEMPDIR}/cddbchoices"
5108 CDDBDISCID=$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
5110 if [ $NUM_CDDB_MATCHES = 0 ]; then
5111 # If we got no matches, we need to
5112 # generate a blank CDDB template.
5113 vecho "Unable to find any matches, generating unknown template."
5114 echo "No lookup matches." >> "${ABCDETEMPDIR}/cddbchoices"
5115 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
5116 echo "template" > "${ABCDETEMPDIR}/datasource.0"
5117 # List out disc title/author and contents of template
5118 echo ---- Unknown Artist / Unknown Album ---- >> "${ABCDETEMPDIR}/cddbchoices"
5120 for TRACK in $(f_seq_row 1 $TRACKS)
5122 echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5124 echo >> "${ABCDETEMPDIR}/cddbchoices"
5125 echo cddb-read-0-complete >> "${ABCDETEMPDIR}/status"
5126 echo cddb-choice=0 >> "${ABCDETEMPDIR}/status"
5127 echo 503 > "${ABCDETEMPDIR}/cddbquery"
5129 # We have matches; create the cddbchoices and cddbquery
5130 # files from all the inputs we have
5131 if [ $NUM_CDDB_MATCHES = 1 ]; then
5132 echo "Retrieved 1 match..." >> "${ABCDETEMPDIR}/cddbchoices"
5133 echo -n "200 " > "${ABCDETEMPDIR}/cddbquery"
5134 cat "${ABCDETEMPDIR}/cddbquery.1" >> "${ABCDETEMPDIR}/cddbquery"
5136 echo "Retrieved $NUM_CDDB_MATCHES matches..." >> "${ABCDETEMPDIR}/cddbchoices"
5137 echo "210 Found exact matches, list follows (until terminating .)" > "${ABCDETEMPDIR}/cddbquery"
5138 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5140 cat "${ABCDETEMPDIR}/cddbquery.$X" >> "${ABCDETEMPDIR}/cddbquery"
5142 echo "." >> "${ABCDETEMPDIR}/cddbquery"
5145 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5147 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.$X" | cut -c8- | tr -d \\r\\n)
5148 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$X")
5149 echo "#$X ($SOURCE): ---- ${ATITLE} ----" >> "${ABCDETEMPDIR}/cddbchoices"
5150 for TRACK in $(f_seq_row 1 $TRACKS)
5152 echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
5154 echo >> "${ABCDETEMPDIR}/cddbchoices"
5161 eval "$($CDDBTOOL parse "$CDDBDATA")"
5164 # Before reading tracks, we set the speed of the device
5166 if [ X"$CDSPEEDVALUE" != "X" ]; then
5167 case "$CDROMREADERSYNTAX" in
5168 cdparanoia|libcdio|debug) ;;
5175 # Define the first and last track, since we might need them later in several places
5176 FIRSTTRACK=$( get_first $TRACKQUEUE )
5177 LASTTRACK=$( get_last $TRACKQUEUE )
5179 if [ -f "${ABCDETEMPDIR}/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
5180 mv "${ABCDETEMPDIR}/status" "${ABCDETEMPDIR}/status.old"
5181 grep -v ^encodetracklocation- < "${ABCDETEMPDIR}/status.old" \
5182 | grep -v ^encode-output > "${ABCDETEMPDIR}/status"
5185 if checkstatus onetrack ; then ONETRACK=y ; fi
5187 if [ "$ONETRACK" = "y" ]; then
5188 # Reuse the CUEFILE in case we created it (now or in a previous run)
5189 if CUEFILE=$(checkstatus cuefile); then
5194 # Create playlist if needed (backgroundable) and start reading in tracks
5198 if [ ! "$ONETRACK" = "y" ]; then
5199 if [ "$DOPLAYLIST" = "y" ]; then
5200 echo Creating playlist... >&2
5205 if [ "$GETALBUMART" = "y" ]; then
5209 # For the lowdisk option, only one program is running at once so the encoder
5210 # can be unsilenced right away.
5211 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
5212 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5215 if [ "$ONETRACK" = "y" ]; then
5217 if [ "$USEPIPES" = "y" ]; then
5218 if checkstatus "readencodetrack-$FIRSTTRACK"; then :; else
5219 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
5222 if checkstatus "readtrack-$FIRSTTRACK"; then :; else
5223 do_cdread onetrack $FIRSTTRACK $LASTTRACK
5227 for UTRACKNUM in $TRACKQUEUE
5229 if [ "$DOREAD" = "y" ]; then
5230 if [ "$USEPIPES" = "y" ]; then
5231 if checkstatus "readencodetrack-$UTRACKNUM"; then :; else
5232 # Read, pipe, shut up!
5233 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
5236 if checkstatus "readtrack-$UTRACKNUM"; then :; else
5237 do_cdread $UTRACKNUM
5239 if [ "$?" != "0" ]; then
5240 # CD read failed - don't give the goahead to
5247 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
5250 # If we are not reading, set the encode output to loud already, so
5251 # that we can see the output of the first track.
5252 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
5253 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5255 echo NEXTTRACK # Get the encoder machine churning again
5256 if [ "$DOREAD" = "y" ]; then
5257 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
5258 until checkstatus "encodetrack-$UTRACKNUM"
5260 if checkerrors "encodetrack-$UTRACKNUM"; then
5271 # Now that we're done the encoding can be loud again -
5272 # if we're not using SMP.
5273 if [ "$MAXPROCS" = "1" ]; then
5274 echo "encode-output=loud" >> "${ABCDETEMPDIR}/status"
5277 # All tracks read, start encoding.
5278 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
5282 # Execute the user-defined post_read function before ejecting CD
5285 # We are now finished with the cdrom - it can be safely ejected. Note that
5286 # abcde will not have completed yet.
5287 if [ "$EJECTCD" = "y" ]; then
5288 # We check if the disk we are processing is actually the disk inside the
5289 # CD tray. If not, we do not eject the CD, since it might be so that the
5290 # user ejected it manually.
5291 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
5292 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$CDDBTRACKINFO" ] ; then
5293 # More FreeBSD bits.
5294 if [ X"$UNAME" = X"FreeBSD" ] ; then
5295 # FreeBSD eject uses the EJECT environment variable to name the CDROM
5296 # but in this script EJECT is in the envionment and names the program
5299 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
5300 cd="$(echo "$CDROM" | sed -e 's=.*/==;s=[a-h]$==;')"
5301 $eject $EJECTOPTS $cd
5302 elif [ X"$UNAME" = X"Darwin" ] ; then
5303 diskutil eject "${CDROM#/dev/}" 0
5304 elif [ -x "$(which "$EJECT")" ]; then
5305 $EJECT $EJECTOPTS "$CDROM"
5312 ## Do we need to pre-process
5313 #if [ x"$PREPROCESS" = "x" ] ; then
5316 # for PRETRACKNUM in $TRACKQUEUE
5319 # if [ "$GOAHEAD" = "NO" ]; then break; fi
5321 # until [ $PREPROCEED ]
5323 # if checkstatus "readtrack-$PRETRACKNUM"; then PREPROCEED=y; break; fi
5324 # # all locations are working, wait and try again later
5325 # if [ ! $PREPROCEED ]; then sleep 3; fi
5327 # ( do_preprocess $PRETRACKNUM
5335 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
5337 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
5338 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5339 if [ "$GOAHEAD" != "NO" ]; then
5340 for LASTTRACK in $TRACKQUEUE; do :; done
5341 if checkstatus "readtrack-$LASTTRACK"; then
5342 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
5343 if checkstatus "normalizetrack-$LASTTRACK"; then :; else do_batch_normalize; fi
5344 if checkerrors batch-normalize; then exit 1; fi
5346 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
5347 if [ "$DONORMALIZE" = "y" ]; then
5348 for UTRACKNUM in $TRACKQUEUE
5350 if checkstatus "readtrack-$UTRACKNUM"; then
5351 if checkstatus "normalizetrack-$UTRACKNUM"; then :; else do_normalize "$UTRACKNUM"; fi
5355 if checkstatus "encodetrack-$LASTTRACK"; then :; else do_nogap_encode; fi
5356 if checkerrors nogap-encode; then exit 1; fi
5362 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
5363 if [ "$ONETRACK" = "y" ] ; then
5364 TRACKQUEUE="$FIRSTTRACK"
5365 TRACKS="$FIRSTTRACK"
5368 # Do the encoding, including parallelization of remote encoding
5369 # Figure out where each track is going to be encoded
5370 ENCODELOCATIONS="$(echo "$REMOTEHOSTS" | tr , ' ')"
5371 if [ "$MAXPROCS" != "0" ]; then
5372 for NUM in $(f_seq_row 1 $MAXPROCS)
5374 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5378 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5379 for UTRACKNUM in $TRACKQUEUE
5382 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5383 if [ "$GOAHEAD" = "NO" ]; then break; fi
5384 # find out where this track is to be encoded
5385 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ]; then
5386 # Make sure we have a place to encode this, if not, exit stage right
5387 if [ -z "$ENCODELOCATIONS" ]; then
5393 for LOCATION in $ENCODELOCATIONS
5395 PREVIOUSTRACK="$(checkstatus "encodetracklocation-$LOCATION")"
5396 # check first if a track has ever been assigned to this location
5397 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5398 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5399 if checkerrors "encodetrack-$PREVIOUSTRACK"; then
5400 for TEMPLOCATION in $ENCODELOCATIONS
5402 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5403 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5406 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5411 # We're still here, this location must have been previously assigned,
5412 # and last completed without error - check if it's done with the
5413 # previous track yet
5414 if checkstatus "encodetrack-$PREVIOUSTRACK"; then PROCEED=y; break; fi
5416 # all locations are working, wait and try again later
5417 if [ ! "$PROCEED" ]; then sleep 3; fi
5419 # Record the location we're about to encode the next track at
5420 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "${ABCDETEMPDIR}/status"
5422 # Don't proceed with the rest of the loop if we can't encode
5423 if [ "$ABORT" ]; then continue; fi
5424 ## FIXME ## Add here
5425 ## run_command "tagtrack-$OUTPUT-$1" $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
5426 # Set TRACKNUM, TRACKNAME
5427 if [ -e "$CDDBDATA" ]; then
5428 if [ "$ONETRACK" = "y" ]; then
5430 TRACKNUM="$FIRSTTRACK"
5433 TRACKNUM="$UTRACKNUM"
5434 CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
5435 getcddbinfo TRACKNAME
5439 # You can't encode a file which needs to be normalized before finishing
5440 # You can't tag a file before it's finished encoding -
5441 # thus all of this is backgrounded together
5443 if [ "$DONORMALIZE" = "y" ]; then
5444 if checkstatus "readtrack-$UTRACKNUM"; then
5445 if checkstatus "normalizetrack-$UTRACKNUM"; then :; else do_normalize "$UTRACKNUM"; fi
5448 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ]; then
5449 if checkstatus "readtrack-$UTRACKNUM"; then
5450 if [ "$DONORMALIZE" = "y" ]; then
5451 if checkstatus "normalizetrack-$UTRACKNUM"; then
5452 if checkstatus "encodetrack-$UTRACKNUM"; then :; else do_encode "$UTRACKNUM" "$LOCATION" "$OUTPUT"; fi
5455 if checkstatus "encodetrack-$UTRACKNUM"; then :; else do_encode "$UTRACKNUM" "$LOCATION" "$OUTPUT"; fi
5459 if [ "$DOTAG" = "y" ]; then
5460 if checkstatus "encodetrack-$UTRACKNUM"; then
5461 if checkstatus "tagtrack-$UTRACKNUM"; then :; else do_tag "$UTRACKNUM"; fi
5463 # Lets tag the cue file
5464 if checkstatus cleancuefile >/dev/null; then :; else
5465 if checkstatus cuefile >/dev/null ; then
5470 if [ "$DOMOVE" = "y" ]; then
5471 if checkstatus "tagtrack-$UTRACKNUM"; then
5472 if checkstatus "movetrack-$UTRACKNUM"; then :; else do_move "$UTRACKNUM"; fi
5479 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5480 # we'll delete the files they're working on
5481 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5482 ## FIXME ## Check also for files which are encoded using PIPEs.
5483 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5488 for LOCATION in $ENCODELOCATIONS
5490 CHECKTRACK="$(checkstatus "encodetracklocation-$LOCATION")"
5491 # "How can he give us a status update, if he's DEAD?"
5492 if checkstatus "encodetrack-$CHECKTRACK"; then
5495 # Nothing to see here please go quietly back to your homes
5496 if [ -z "$CHECKTRACK" ]; then continue; fi
5497 # You're still here? Maybe there is something...
5498 if checkstatus "encodetrack-$CHECKTRACK"; then :; else PROCEED= ; break; fi
5501 if [ ! $PROCEED ]; then sleep 5; fi
5504 # If the above didn't catch the stragglers, this will
5506 if [ "$DOREPLAYGAIN" = "y" ]; then
5510 if [ "$EMBEDALBUMART" = "y" ]; then
5514 # Execute the user-defined post_encode function before cleaning up
5517 # Check to see if run_command logged any errors
5518 if [ -f "${ABCDETEMPDIR}/errors" ]; then
5519 log error "The following commands failed to run:"
5520 cat "${ABCDETEMPDIR}/errors"
5524 if [ "$KEEPWAVS" = "y" ];then
5528 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5529 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5530 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5531 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "${ABCDETEMPDIR}/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5532 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5533 log warning "The encoded formats does not match with the moved ones"
5534 log warning "Formats encoded: $( echo "$ENCODED_FORMATS" | tr "|" " " )"
5535 log warning "Formats moved: $( echo "$MOVED_FORMATS" | tr "|" " " )"
5536 log warning "Use \"abcde -a clean -f -C ${CDDBDISCID}\" to force the removal of the remaining data."
5540 if [ "$DOCLEAN" = "y" ]; then
5541 # Wipe all the evidence
5542 # Gimme gimme gimme some more time!
5544 rm -rf "${ABCDETEMPDIR}"
5547 echo "Finished. Not cleaning ${ABCDETEMPDIR}."