2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
5 # Copyright (c) 2012- Steve McIntyre <93sam@@debian.org>
6 # Copyright (c) 2015-2016 Andrew Strong <andrew.david.strong@gmail.com>
7 # This code is hereby licensed for public consumption under either the
8 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
10 # You should have received a copy of the GNU General Public License along
11 # with this program; if not, write to the Free Software Foundation, Inc.,
12 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14 VERSION='2.8.2-UNRELEASED'
18 echo "This is abcde v$VERSION."
19 echo "Usage: abcde [options] [tracks]"
21 echo "-1 Encode the whole CD in a single file"
22 echo "-a <action1[,action2]...>"
23 echo " Actions to perform:"
24 echo " cddb,read,getalbumart,embedalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
25 #echo "-A Experimental actions (retag, transcode)"
26 echo "-b Enable batch normalization"
27 echo "-B Embed albumart (this also activates getalbumart)"
29 echo " Specify a configuration file (overrides system and user config files)"
31 echo " Specify discid to resume from (only needed if you no longer have the cd)"
33 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
34 echo "-D Debugging mode (equivalent to sh -x abcde)"
35 echo "-e Erase encoded track information from status file"
36 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
37 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
38 echo "-G Get album art by using the 'getalbumart' action"
39 echo "-h This help information"
40 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
41 echo "-j <#> Number of encoder processes to run at once (localhost)"
42 echo "-k Keep the wav tracks for later use"
43 echo "-l Use low disk space algorithm"
44 echo "-L Use local CDDB storage directory"
45 echo "-m Modify playlist to include CRLF endings, to comply with some players"
46 #echo " WARNING: Deprecated. Use \"cue\" action"
47 #echo "-M Create a CUE file"
48 echo "-n No lookup. Don't query CDDB, just create and use template"
49 echo "-N Noninteractive. Never prompt for anything"
50 echo "-o <type1[,type2]...>"
51 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,mka,wv,ape,mp2,tta,aiff). Defaults to vorbis"
52 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
53 echo "-P Use UNIX pipes to read+encode without wav files"
54 echo "-Q Select CDDBMETHOD method(s) from the command line. Choose from any/all of musicbrainz,cddb,cdtext. Defaults to musicbrainz".
55 echo "-r <host1[,host2]...>"
56 echo " Also encode on these remote hosts"
58 echo " Show fields from the CDDB info (year,genre)"
59 echo "-S <#> Set the CD speed"
60 echo "-t <#> Start the track numbering at a given number"
61 echo "-T <#> Same as -t but modifies tag numbering"
62 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
63 echo "-v Show version number and exit"
64 echo "-V Be a bit more verbose about what is happening behind the scenes"
65 echo "-x Eject CD after all tracks are read"
67 echo " Add a comment to the CD tracks"
68 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
69 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
71 echo "Tracks is a space-delimited list of tracks to grab."
72 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
74 #echo "Double hyphens are used to concatenate tracks"
79 echo "$@" >> "$ABCDETEMPDIR/status"
82 # log [level] [message]
84 # log outputs the right message in a common format
90 error) >&2 echo "[ERROR] abcde: $@" >&2 ;;
91 warning) >&2 echo "[WARNING] $@" >&2 ;;
92 info) >&4 echo "[INFO] $@" ;;
96 # Functions to replace the need of seq, which is too distribution dependent.
100 while [ $i -ne `expr $2 + 1` ]
110 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
111 while [ $i -ne `expr $2 + 1` ]
118 log error "syntax error while processing track numbers ($i)"
123 # Functions to replace the need of awk {print $1} and {print $NF}
126 if [ X"$1" = "X" ]; then
127 for first in `cat`; do
138 if [ X"$1" = "X" ]; then
139 for stdin in `cat`; do
143 for last in $@ ; do :; done
148 # checkstatus [blurb]
149 # Returns "0" if the blurb was found, returns 1 if it wasn't
150 # Puts the blurb content, if available, on stdout.
151 # Otherwise, returns "".
154 # Take the last line in the status file if there's multiple matches
156 BLURB=$(grep -E $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
158 if [ -z "$BLURB" ]; then
163 # See if there's a = in it
164 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
165 echo "$(echo $BLURB | cut -f2- -d=)"
171 # checkwarnings [blurb]
172 # Returns "0" if the blurb was found (meaning there was an warning),
173 # returns 1 if it wasn't (yes this is a little backwards).
174 # Does not print the blurb on stdout.
175 # Otherwise, returns "".
178 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
181 # Take the last line in the status file if there's multiple matches
183 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
185 if [ -z "$BLURB" ]; then
186 # negative, we did not have a negative...
189 # affirmative, we had a negative...
194 # checkerrors [blurb]
195 # Returns "0" if the blurb was found (meaning there was an error),
196 # returns 1 if it wasn't (yes this is a little backwards).
197 # Does not print the blurb on stdout.
198 # Otherwise, returns "".
201 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
204 # Take the last line in the status file if there's multiple matches
206 BLURB="$(grep -E $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
208 if [ -z "$BLURB" ]; then
209 # negative, we did not have a negative...
212 # affirmative, we had a negative...
218 # Finds the right pager in the system to display a file
222 # Use the debian sensible-pager wrapper to pick the pager
223 # user has requested via their $PAGER environment variable
224 if [ -x "/usr/bin/sensible-pager" ]; then
225 /usr/bin/sensible-pager "$PAGEFILE"
226 elif [ -x "$PAGER" ]; then
227 # That failed, try to load the preferred editor, starting
228 # with their PAGER variable
230 # If that fails, check for less
231 elif [ -x /usr/bin/less ]; then
232 /usr/bin/less -f "$PAGEFILE"
233 # more should be on all UNIX systems
234 elif [ -x /bin/more ]; then
235 /bin/more "$PAGEFILE"
237 # No bananas, just cat the thing
242 # run_command [blurb] [command...]
243 # Runs a command, silently if necessary, and updates the status file
249 # See if this is supposed to be silent
250 if [ "$(checkstatus encode-output)" = "loud" ]; then
254 # Special case for SMP, since
255 # encoder output is never displayed, don't mute echos
256 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
265 normalize|normalize-audio)
266 if [ "$RETURN" = "2" ]; then
267 # File was already normalized.
272 if [ "$RETURN" != "0" ]; then
273 # Put an error in the errors file. For various reasons we
274 # can't capture a copy of the program's output but we can
275 # log what we attempted to execute and the error code
276 # returned by the program.
277 if [ "$BLURB" ]; then
280 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
281 return $RETURN # Do not pass go, do not update the status file
283 if [ "$BLURB" ]; then
284 echo $BLURB >> "$ABCDETEMPDIR/status"
288 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
289 # distributed under the terms of the GNU GPL v2 or later, at your option
291 # Function to determine if a word contains a slash.
300 # Function to give the relative path from one file to another.
301 # Usage: relpath fromfile tofile
302 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
303 # (the result would be Album/Song.mp3)
304 # Output is relative path to $2 from $1 on stdout
306 # This code has the following restrictions:
307 # Multiple ////s are not collapsed into single /s, with strange effects.
308 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
309 # If FR is a directory it must have a trailing /
317 /*) ;; # No processing is needed for absolute paths
319 # Loop through common prefixes, ignoring them.
320 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
322 FR="$(echo "$FR" | cut -d/ -f2-)"
323 TO="$(echo "$TO" | cut -d/ -f2-)"
325 # Loop through directory portions left in FR, adding appropriate ../s.
328 FR="$(echo "$FR" | cut -d/ -f2-)"
339 if [ ! "$@" = "" ]; then
340 # Cut off any command-line option we added in
341 X=$(echo $@ | cut -d' ' -f2)
342 if [ "$(which $X)" = "" ]; then
344 elif [ ! -x $(which $X) ]; then
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X=$(echo $@ | cut -d' ' -f2)
356 # Test for built-in abcde.function
357 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
358 if [ "$(which $X)" = "" ]; then
359 log error "$X is not in your path." >&2
360 log info "Define the full path to the executable if it exists on your system." >&2
361 if [ -e /etc/debian_* ] ; then
363 oggenc) MISSING_PACKAGE=vorbis-tools ;;
364 lame|flac) MISSING_PACKAGE=$X ;;
366 log info "Hint: sudo apt-get install $MISSING_PACKAGE" >&2
369 elif [ ! -x "$(which $X)" ]; then
370 log error "$X is not executable." >&2
376 # diffentries <filename> <max_value> <entry1>,<entry2>
377 # max_value: the range of entries goes from 1 to <max_value>
382 local CDDBDIFFCHOICES=$1
384 local CDDBDIFFCHOICE="$@"
385 if [ ! X"$DIFF" = "X" ]; then
386 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
387 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
388 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
389 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
390 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
391 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
393 # We parse the 2 choices to diff, store them in temporary files and diff them.
394 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
395 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
397 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
398 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
399 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge $LINES ]; then
400 page "$ABCDETEMPDIR/$FILENAME.diff"
402 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
406 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
411 # Finds an specific field from cddbinfo
416 TRACKNAME="$(grep -a ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
419 TRACKNAME="$(grep -a ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
422 grep -a ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\\n/\n/g'
428 # Get the track number we are going to use for different actions
431 if [ -n "$STARTTRACKNUMBER" ] ; then
432 # Get the trackpadding from the current track, also trim whitespace for MacOSX
433 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c | tr -d ' ')
434 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
436 TRACKNUM=${UTRACKNUM}
442 # Calculate cddb disc ids without requiring specialized helper programs.
443 # largely copied from cd-discid and musicbrainz examples. some of the steps
444 # don't make sense, but they're necessary to match the ids generated by other
447 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
448 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
449 # 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
450 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
451 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
452 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
454 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
457 if [ X"$LEADOUT" = "X" ]; then
458 log warning "Error trying to calculate disc ids without lead-out information."
462 # default to a two second lead-in
464 LEADIN=${LEADIN:=150}
466 # number of cdframes per second
469 # reset cddb checksum for cddb disc-id calululation
473 for OFFSET in $(echo $OFFSETS)
475 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
477 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
478 while [ $OFFSETTIME -gt 0 ]; do
479 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
480 OFFSETTIME=$(($OFFSETTIME / 10))
485 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
487 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
488 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
490 vvecho "makeids: PREGAP $PREGAP, LEADIN $LEADIN, LEADOUT $LEADOUT"
492 # Calculate both the cddb discid *and* the musicbrainz discid
493 # now. We'll use the cddb discid for reference in most cases
494 # for consistency, but we also have the musicbrainz discid for
496 printf -v CDDBDISCID "%08lx" $(( ($CDDBCKSUM % 0xff) * 16777216 | $TOTALTIME * 256 | $TRACKS))
497 CDDBTRACKINFO="${CDDBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
501 # FIXME: don't assume the first track is 1
502 MBDISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $(($PREGAP + $LEADOUT)) $OFFSETS)
503 MBTRACKINFO="${MBDISCID} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
510 if checkstatus replaygain; then :; else
511 run_command "" echo "Adding replaygain information..."
512 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
516 OUTPUT=$OGGOUTPUTCONTAINER
519 OUTPUT=$OPUSOUTPUTCONTAINER
522 OUTPUT=$FLACOUTPUTCONTAINER
530 for UTRACKNUM in $TRACKQUEUE
532 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
533 getcddbinfo TRACKNAME
535 TRACKFILE="$(mungetrackname "$TRACKNAME")"
536 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
537 ALBUMFILE="$(mungealbumname "$DALBUM")"
538 GENRE="$(mungegenre "$GENRE")"
539 YEAR=${CDYEAR:-$CDYEAR}
541 if [ "$ONETRACK" = "y" ]; then
542 if [ "$VARIOUSARTISTS" = "y" ]; then
543 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
545 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
548 if [ "$VARIOUSARTISTS" = "y" ]; then
549 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
551 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
554 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
555 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
559 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
560 #run_command replaygain-flac true
563 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
566 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
569 run_command replaygain-mpc nice $ENCNICE $MPCGAIN "${OUTPUTFILES[@]}"
572 run_command replaygain-wv nice $ENCNICE $WVGAIN $WVGAINOPTS "${OUTPUTFILES[@]}"
577 if checkerrors "replaygain-.{3,6}"; then :; else
578 run_command replaygain true
583 # This code splits the a Various Artist track name from one of the following
586 # forward: Artist / Track
587 # forward-dash: Artist - Track
588 # reverse: Track / Artist
589 # reverse-dash: Track - Artist
590 # colon: Artist: Track
591 # trailing-paren: Artist (Track)
594 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
597 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
598 case "$VARIOUSARTISTSTYLE" in
600 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
601 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
602 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
605 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
606 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
607 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
610 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
611 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
612 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
615 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
616 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
617 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
620 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
621 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
622 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
625 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
626 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
627 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
630 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
631 TRACKARTIST="Various"
633 TRACKARTIST="$DARTIST"
638 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
642 "classic rock") id=1 ;;
660 "industrial") id=19 ;;
661 "alternative") id=20 ;;
663 "death metal") id=22 ;;
665 "soundtrack") id=24 ;;
666 "euro-techno") id=25 ;;
670 "jazz+funk") id=29 ;;
673 "classical") id=32 ;;
674 "instrumental") id=33 ;;
678 "sound clip") id=37 ;;
681 "alt. rock") id=40 ;;
686 "meditative") id=45 ;;
687 "instrum. pop") id=46 ;;
688 "instrum. rock") id=47 ;;
692 "techno-indust.") id=51 ;;
693 "electronic") id=52 ;;
695 "eurodance") id=54 ;;
697 "southern rock") id=56 ;;
702 "christian rap") id=61 ;;
703 "pop/funk"|"pop / funk") id=62 ;;
705 "native american") id=64 ;;
708 "psychadelic") id=67 ;;
710 "showtunes") id=69 ;;
714 "acid punk") id=73 ;;
715 "acid jazz") id=74 ;;
719 "rock & roll") id=78 ;;
720 "hard rock") id=79 ;;
722 "folk/rock") id=81 ;;
723 "national folk") id=82 ;;
730 "bluegrass") id=89 ;;
731 "avantgarde") id=90 ;;
732 "gothic rock") id=91 ;;
733 "progress. rock") id=92 ;;
734 "psychadel. rock") id=93 ;;
735 "symphonic rock") id=94 ;;
736 "slow rock") id=95 ;;
739 "easy listening") id=98 ;;
745 "chamber music") id=104 ;;
747 "symphony") id=106 ;;
748 "booty bass") id=107 ;;
750 "porn groove") id=109 ;;
752 "slow jam") id=111 ;;
756 "folklore") id=115 ;;
758 "power ballad") id=117 ;;
759 "rhythmic soul") id=118 ;;
760 "freestyle") id=119 ;;
762 "punk rock") id=121 ;;
763 "drum solo") id=122 ;;
764 "a capella") id=123 ;;
765 "euro-house") id=124 ;;
766 "dance hall") id=125 ;;
768 "drum & bass") id=127 ;;
769 "club-house") id=128 ;;
770 "hardcore") id=129 ;;
774 "negerpunk") id=133 ;;
775 "polsk punk") id=134 ;;
777 "christian gangsta rap") id=136 ;;
778 "heavy metal") id=137 ;;
779 "black metal") id=138 ;;
780 "crossover") id=139 ;;
781 "contemporary christian")id=140 ;;
782 "christian rock") id=141 ;;
783 "merengue") id=142 ;;
785 "thrash metal") id=144 ;;
788 "synthpop") id=147 ;;
789 "rock/pop"|"rock / pop") id=148 ;;
796 # do_tag [tracknumber]
797 # id3 tags a filename
799 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
800 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
803 COMMENTOUTPUT="$(eval echo ${COMMENT})"
804 if [ -z "$COMMENTOUTPUT" ]; then
805 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
807 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
808 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
809 # If we want to start the tracks with a given number, we need to modify the
810 # TRACKNUM value before evaluation
811 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
814 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
818 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
819 GENREID=$(do_getgenreid "${CDGENRE}")
820 # Set TPE2 in case we have a Various Artists rip.
822 if [ "$VARIOUSARTISTS" = "y" ]; then
828 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
829 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
830 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
831 -y "$CDYEAR" -g "$GENREID" \
832 -T "${TRACKNUM:-$1}" \
833 "$ABCDETEMPDIR/track$1.$OUTPUT"
836 # FIXME # track numbers in mp3 come with 1/10, so we cannot
837 # happily substitute them with $TRACKNUM
838 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
839 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
840 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
841 -y "$CDYEAR" -g "$GENREID" \
842 -T "${TRACKNUM:-$1}/$TRACKS" \
843 ${TPE2:+--TPE2 "$TPE2"} \
844 "$ABCDETEMPDIR/track$1.$OUTPUT"
847 # FIXME # track numbers in mp3 come with 1/10, so we cannot
848 # happily substitute them with $TRACKNUM
849 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
850 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
851 -A "$DALBUM" -a "$TRACKARTIST" -s "$TRACKNAME" \
852 -y "$CDYEAR" -g "$GENREID" \
853 -t "${TRACKNUM:-$1}" ${TRACKNUM:+-T "$TRACKS"} \
854 "$ABCDETEMPDIR/track$1.$OUTPUT"
857 # FIXME # track numbers in mp3 come with 1/10, so we cannot
858 # happily substitute them with $TRACKNUM
860 eyed3_06) addopts=( \
861 ${ENCODING:+--set-encoding="$ENCODING"} \
862 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
863 # We set 'recording-date' so the date tag will show
864 # in Audacious, vlc and friends... Andrew.
865 ${CDYEAR:+--set-text-frame="TDRC:$CDYEAR"} \
866 ${COMMENTOUTPUT:+--comment=::"$COMMENTOUTPUT"} \
869 ${ENCODING:+--encoding="$ENCODING"} \
870 ${TPE2:+--text-frame=TPE2:"$TPE2"} \
871 # We set 'recording-date' so the date tag will show
872 # in Audacious, vlc and friends... Andrew.
873 ${CDYEAR:+--text-frame="TDRC:$CDYEAR"} \
874 ${COMMENTOUTPUT:+--comment "$COMMENTOUTPUT"} \
877 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
879 -a "$TRACKARTIST" -t "$TRACKNAME" \
880 -G "$GENREID" -n "${TRACKNUM:-$1}" \
881 ${TRACKNUM:+-N "$TRACKS"} \
883 "$ABCDETEMPDIR/track$1.$OUTPUT"
886 log error "Internal error: ID3SYNTAX has an illegal value"
892 case "$OGGENCODERSYNTAX" in
894 # vorbiscomment can't do in-place modification, mv the file first
895 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
896 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
900 # https://www.xiph.org/vorbis/doc/v-comment.html
902 echo ARTIST="$TRACKARTIST"
904 echo TITLE="$TRACKNAME"
905 if [ -n "$CDYEAR" ]; then
908 if [ -n "$CDGENRE" ]; then
909 echo GENRE="$CDGENRE"
911 echo TRACKNUMBER=${TRACKNUM:-$1}
912 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
913 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
914 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
915 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
916 echo TRACKTOTAL="${TRACKS}"
917 if [ -n "$DISCNUMBER" ]; then
918 echo DISCNUMBER="$DISCNUMBER"
920 echo CDDB=$CDDBDISCID
921 if [ "$(eval echo ${COMMENT})" != "" ]; then
922 case "$COMMENTOUTPUT" in
923 *=*) echo "$COMMENTOUTPUT";;
924 *) echo COMMENT="$COMMENTOUTPUT";;
927 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
928 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
929 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
930 # Doublecheck that the commented file was created
931 # successfully before wiping the original
932 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
933 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
935 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
941 run_command tagtrack-$OUTPUT-$1 true
944 run_command tagtrack-$OUTPUT-$1 true
947 run_command tagtrack-$OUTPUT-$1 true
951 echo ARTIST="$TRACKARTIST"
953 echo TITLE="$TRACKNAME"
954 if [ -n "$CDYEAR" ]; then
957 if [ -n "$CDGENRE" ]; then
958 echo GENRE="$CDGENRE"
960 echo TRACKNUMBER="${TRACKNUM:-$1}"
961 # TRACKTOTAL is not in the proposed, minimal list of standard field names from
962 # xiph.org: https://www.xiph.org/vorbis/doc/v-comment.html but is in common usage
963 # and read by mediainfo, ffprobe, vlc, Aqualung, ogg123, Foobar. And now abcde :)
964 # The tag is quietly ignored by Audacious, MPlayer, mpv, XMMS....
965 echo TRACKTOTAL="${TRACKS}"
966 if [ -n "$DISCNUMBER" ]; then
967 echo DISCNUMBER="$DISCNUMBER"
969 echo CDDB="$CDDBDISCID"
970 if [ "$(eval echo ${COMMENT})" != "" ]; then
971 case "$COMMENTOUTPUT" in
972 *=*) echo "$COMMENTOUTPUT";;
973 *) echo COMMENT="$COMMENTOUTPUT";;
976 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} \
977 --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
980 run_command tagtrack-$OUTPUT-$1 true
983 run_command tagtrack-$OUTPUT-$1 true
986 run_command tagtrack-$OUTPUT-$1 true
989 # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio
990 # Console port (mac) used for encoding does not have the ability to tag.
991 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$APETAG" -i "$ABCDETEMPDIR/track$1.ape" -m overwrite \
992 -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track=${TRACKNUM:-$1} \
993 -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"}
996 # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
997 # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
998 # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
999 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1000 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1001 "$ABCDETEMPDIR/track$1.mp2"
1004 run_command tagtrack-$OUTPUT-$1 true
1007 case "$AACENCODERSYNTAX" in
1009 # We will use inline tagging...
1010 run_command tagtrack-$OUTPUT-$1 true
1013 # Tag post encode with neroAacTag...
1014 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$NEROAACTAG" "$ABCDETEMPDIR/track$1.m4a" \
1015 -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track=${TRACKNUM:-$1} \
1016 -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
1019 run_command tagtrack-$OUTPUT-$1 true
1022 run_command tagtrack-$OUTPUT-$1 true
1025 # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
1026 # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
1027 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$ATOMICPARSLEY" "$ABCDETEMPDIR/track$1.m4a" \
1028 --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum=${TRACKNUM:-$1} \
1029 --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
1032 run_command tagtrack-$OUTPUT-$1 true
1037 # We use mid3v2 tagging for True Audio:
1038 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
1039 -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
1040 "$ABCDETEMPDIR/track$1.tta"
1043 run_command tagtrack-$OUTPUT-$1 true
1047 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1048 run_command tagtrack-$1 true
1054 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
1057 # The commands here don't go through run_command because they're never
1058 # supposed to be silenced
1059 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
1060 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1064 case "$MP3ENCODERSYNTAX" in
1069 for UTRACKNUM in $TRACKQUEUE
1071 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1073 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
1075 if [ "$RETURN" != "0" ]; then
1076 echo "nogap-encode: $ENCODER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1078 for UTRACKNUM in $TRACKQUEUE
1080 run_command encodetrack-$OUTPUT-$UTRACKNUM true
1081 #run_command encodetrack-$UTRACKNUM true
1090 if checkerrors "nogap-encode"; then :; else
1091 if [ ! "$KEEPWAVS" = "y" ] ; then
1092 if [ ! "$KEEPWAVS" = "move" ] ; then
1097 # Other encoders fall through to normal encoding as the tracks have not
1098 # been entered in the status file.
1101 # do_encode [tracknumber] [hostname]
1102 # If no hostname is specified, encode locally
1104 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS,
1105 # DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1108 if [ "$USEPIPES" = "y" ]; then
1111 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
1114 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1117 TEMPARG="PIPE_$OPUSENCODERSYNTAX"
1120 TEMPARG="PIPE_$MKAENCODERSYNTAX"
1123 TEMPARG="PIPE_$AIFFENCODERSYNTAX"
1126 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1129 TEMPARG="PIPE_$SPEEXENCODER"
1132 TEMPARG="PIPE_$MPCENCODER"
1135 TEMPARG="PIPE_$WVENCODERSYNTAX"
1138 TEMPARG="PIPE_$TTAENCODERSYNTAX"
1141 TEMPARG="PIPE_$AACENCODERSYNTAX"
1144 TEMPARG="PIPE_$AACENCODERSYNTAX"
1147 IN="$( eval echo "\$$TEMPARG" )"
1149 IN="$ABCDETEMPDIR/track$1.wav"
1151 # We need IN to proceed, if we are not using pipes.
1152 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1153 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1155 case "$TMPOUTPUT" in
1157 OUTPUT=$OGGOUTPUTCONTAINER
1160 OUTPUT=$OPUSOUTPUTCONTAINER
1163 OUTPUT=$MKAOUTPUTCONTAINER
1166 OUTPUT=$AIFFOUTPUTCONTAINER
1169 OUTPUT=$FLACOUTPUTCONTAINER
1175 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1176 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1179 if [ X"$USEPIPES" = "Xy" ]; then
1181 # We need a way to store the creation of the files when using PIPES
1182 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1183 # When piping it does not make sense to have a higher nice for
1184 # reading than for encoding, since it will be hold by the
1185 # encoding process. Setting an effective nice, to calm down a
1186 # bit the reading process.
1187 EFFECTIVE_NICE=$READNICE
1189 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1190 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1191 EFFECTIVE_NICE=$ENCNICE
1197 case "$MP3ENCODERSYNTAX" in
1198 lame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1199 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" "$OUT" ;;
1200 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1201 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1205 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1212 case "$OGGENCODERSYNTAX" in
1213 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1214 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1218 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1225 case "$OPUSENCODERSYNTAX" in
1227 # Tag the file at encode time, as it can't be done after encoding.
1228 if [ "$DOTAG" = "y" ]; then
1229 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
1230 --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
1231 ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
1233 $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
1239 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1244 case "$MKAENCODERSYNTAX" in
1246 if [ "$DOTAG" = "y" ]; then
1247 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS -metadata artist="$TRACKARTIST" \
1248 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1249 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1251 $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
1257 case "$AIFFENCODERSYNTAX" in
1259 if [ "$DOTAG" = "y" ]; then
1260 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS -metadata artist="$TRACKARTIST" \
1261 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1262 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1264 $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
1272 case "$FLACENCODERSYNTAX" in
1273 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1278 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1279 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1284 if [ "$(eval echo ${COMMENT})" != "" ]; then
1287 *) COMMENT="COMMENT=$COMMENT" ;;
1290 # Tag the file at encode time, as it can't be done after encoding.
1291 if [ "$DOTAG" = "y" ]; then
1292 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
1293 ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1295 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1299 # Tag the file inline at encode time.
1300 if [ "$DOTAG" = "y" ]; then
1301 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1302 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1304 $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
1308 case "$TTAENCODERSYNTAX" in
1309 # tta is the newer version with a small syntax change...
1311 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" "$OUT"
1314 $RUN_COMMAND nice $EFFECTIVE_NICE $TTAENCODER -e $TTAENCODEROPTS "$IN" -o "$OUT"
1319 case "$WVENCODERSYNTAX" in
1321 if [ "$DOTAG" = "y" ]; then
1322 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
1323 -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
1325 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
1329 if [ "$DOTAG" = "y" ]; then
1330 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
1331 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1332 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1334 $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
1340 $RUN_COMMAND nice $EFFECTIVE_NICE $APENCODER "$IN" "$OUT" $APENCODEROPTS
1343 case "$MP2ENCODERSYNTAX" in
1345 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
1348 $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT"
1353 # aac container is only used to catch faac encoded files where faac
1354 # is compiled without mp4 support (with libmp4v2).
1355 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1358 case "$AACENCODERSYNTAX" in
1360 if [ "$DOTAG" = "y" ]; then
1361 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1362 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1364 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1368 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -if "$IN" -of "$OUT"
1371 if [ "$DOTAG" = "y" ]; then
1372 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1373 --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
1375 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
1379 if [ "$DOTAG" = "y" ]; then
1380 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
1381 --title "$TRACKNAME" --track ${TRACKNUM:-$1} --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
1383 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1387 $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS "$IN" "$OUT"
1390 if [ "$DOTAG" = "y" ]; then
1391 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
1392 -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track=${TRACKNUM:-$1} -metadata date="$CDYEAR" \
1393 -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
1395 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS "$OUT"
1401 # In case of wav output we need nothing. Just keep the wavs.
1402 # But we need the following to allow full logging and subsequent
1403 # successful cleaning of $ABCDETEMPDIR.
1404 echo "encodetrack-$OUTPUT-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1409 # Only remove .wav if the encoding succeeded
1410 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1411 run_command encodetrack-$1 true
1412 if [ ! "$KEEPWAVS" = "y" ] ; then
1413 if [ ! "$KEEPWAVS" = "move" ] ; then
1419 run_command "" echo "HEH! The file we were about to encode disappeared:"
1420 run_command "" echo ">> $IN"
1421 run_command encodetrack-$1 false
1425 # do_preprocess [tracknumber]
1427 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1430 # IN="$ABCDETEMPDIR/track$1.wav"
1431 # # We need IN to proceed.
1432 # if [ -s "$IN" ] ; then
1433 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1435 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1436 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1437 # case "$POSTPROCESSFORMAT" in
1439 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1441 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1443 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1445 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1447 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1450 # # Only remove .wav if the encoding succeeded
1451 # if checkerrors "preprocess-(.{3,4})-$1"; then
1452 # run_command preprocess-$1 false
1454 # run_command preprocess-$1 true
1457 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1458 # echo "HEH! The file we were about to pre-process disappeared:"
1461 # run_command preprocess-$1 false
1466 # do_postprocess [tracknumber]
1468 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1471 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1473 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1474 # # We need IN to proceed.
1475 # if [ -s "$IN" ] ; then
1476 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1477 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1478 # case "$POSTPROCESSFORMAT" in
1480 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1482 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1484 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1486 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1488 # # Only remove .wav if the encoding succeeded
1489 # if checkerrors "postprocess-(.{3,4})-$1"; then
1490 # run_command postprocess-$1 false
1492 # run_command postprocess-$1 true
1495 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1496 # echo "HEH! The file we were about to post-process disappeared:"
1499 # run_command postprocess-$1 false
1514 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPCGAIN
1518 # The commands here don't go through run_command because they're never supposed to be silenced
1519 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1524 for UTRACKNUM in $TRACKQUEUE
1526 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1528 # FIXME # Hard-coded batch option!
1529 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1531 if [ "$RETURN" != "0" ]; then
1532 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1534 for UTRACKNUM in $TRACKQUEUE
1536 echo "normalizetrack-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1542 # do_batch_normalize
1544 # NORMALIZER, NORMALIZEROPTS
1545 do_batch_normalize ()
1547 # The commands here don't go through run_command because they're never supposed to be silenced
1548 echo "Batch normalizing tracks: $TRACKQUEUE"
1553 for UTRACKNUM in $TRACKQUEUE
1555 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1557 # XXX: Hard-coded batch option!
1558 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1560 if [ "$RETURN" != "0" ]; then
1561 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
1563 for UTRACKNUM in $TRACKQUEUE
1565 echo "normalizetrack-$UTRACKNUM" >> "$ABCDETEMPDIR/status"
1571 # do_normalize [tracknumber]
1573 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1576 IN="$ABCDETEMPDIR/track$1.wav"
1577 if [ -e "$IN" ] ; then
1578 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1579 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1581 if [ "$(checkstatus encode-output)" = "loud" ]; then
1582 echo "HEH! The file we were about to normalize disappeared:"
1585 run_command normalizetrack-$1 false "File $IN was not found"
1589 # do_move [tracknumber]
1590 # Deduces the outfile from environment variables
1591 # Creates directory if necessary
1593 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1596 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1598 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1599 # defined the OUTPUTFILE:
1602 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1603 ALBUMFILE="$(mungealbumname "$DALBUM")"
1604 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1605 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1606 GENRE="$(mungegenre "$GENRE")"
1607 YEAR=${CDYEAR:-$CDYEAR}
1608 # If we want to start the tracks with a given number, we need to modify
1609 # the TRACKNUM value before evaluation
1611 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1612 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1613 if [ "$ONETRACK" = "y" ]; then
1614 if [ "$VARIOUSARTISTS" = "y" ]; then
1615 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1617 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1620 if [ "$VARIOUSARTISTS" = "y" ]; then
1621 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1623 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1626 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1627 # Once we know the specific output was successful, we can change
1628 # the OUTPUT to the value containing the container
1631 OUTPUT=$OGGOUTPUTCONTAINER
1634 OUTPUT=$OPUSOUTPUTCONTAINER
1637 OUTPUT=$MKAOUTPUTCONTAINER
1640 OUTPUT=$AIFFOUTPUTCONTAINER
1643 OUTPUT=$FLACOUTPUTCONTAINER
1649 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1650 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1653 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1654 # FIXME # introduce warnings?
1657 # mkdir -p shouldn't return an error if the directory already exists
1658 mkdir -p "$OUTPUTFILEDIR"
1659 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1660 if checkstatus movetrack-output-$OUTPUT; then :; else
1661 run_command movetrack-output-$OUTPUT true
1666 # mkdir -p shouldn't return an error if the directory already exists
1667 mkdir -p "$OUTPUTFILEDIR"
1668 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1669 if checkstatus movetrack-output-$OUTPUT; then :; else
1670 run_command movetrack-output-$OUTPUT true
1674 # Lets move the cue file
1675 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1676 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1677 if checkstatus movecue-$OUTPUT; then :; else
1678 # Silence the Copying output since it overlaps with encoding processes...
1679 #run_command '' vecho "Copying cue file to its destination directory..."
1680 if checkstatus onetrack >/dev/null ; then
1683 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1684 # We dont have the dir, since it was not created before.
1687 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1690 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1691 # http://brianvictor.tripod.com/mp3cue.htm#details
1692 [a-z0-9][a-z0-9][a-z0-9])
1693 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1696 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1700 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1702 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1711 # Create the playlist if wanted
1713 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1714 # VARIOUSARTISTS, OUTPUTDIR
1717 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1721 OUTPUT=$OGGOUTPUTCONTAINER
1724 OUTPUT=$OPUSOUTPUTCONTAINER
1727 OUTPUT=$MKAOUTPUTCONTAINER
1730 OUTPUT=$AIFFOUTPUTCONTAINER
1733 OUTPUT=$FLACOUTPUTCONTAINER
1739 # Create a playlist file for the playlist data to go into.
1740 # We used to wipe it out if it existed. Now we request permission if interactive.
1741 for LASTTRACK in $TRACKQUEUE; do :; done
1742 ALBUMFILE="$(mungealbumname "$DALBUM")"
1743 ARTISTFILE="$(mungeartistname "$DARTIST")"
1744 GENRE="$(mungegenre "$GENRE")"
1745 YEAR=${CDYEAR:-$CDYEAR}
1746 if [ "$VARIOUSARTISTS" = "y" ] ; then
1747 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1749 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1751 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1752 mkdir -p "$FINALPLAYLISTDIR"
1753 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1754 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1755 if [ "$INTERACTIVE" = "y" ]; then
1756 while [ "$DONE" != "y" ]; do
1758 case $ERASEPLAYLIST in
1759 e|E|a|A|k|K) DONE=y ;;
1760 "") ERASEPLAYLIST=e ; DONE=y ;;
1768 # Once we erase the playlist, we use append to create the new one.
1769 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1771 # The playlist does not exist, so we can safelly use append to create the new list
1774 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1775 touch "$OUTPUTDIR/$PLAYLISTFILE"
1776 for UTRACKNUM in $TRACKQUEUE
1778 # Shares some code with do_move since the filenames have to match
1779 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1780 getcddbinfo TRACKNAME
1782 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1783 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1784 ALBUMFILE="$(mungealbumname "$DALBUM")"
1785 # If we want to start the tracks with a given number, we need to modify the
1786 # TRACKNUM value before evaluation
1788 if [ "$VARIOUSARTISTS" = "y" ]; then
1789 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1791 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1793 if [ "$VARIOUSARTISTS" = "y" ]; then
1794 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1795 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1797 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1800 if [ "$PLAYLISTDATAPREFIX" ]; then
1801 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1803 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1808 ## this will convert the playlist to have CRLF line-endings, if specified
1809 ## (some hardware players insist on CRLF endings)
1810 if [ "$DOSPLAYLIST" = "y" ]; then
1811 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1812 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1813 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1815 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1820 # This function reads a cuefile on stdin and writes an extended
1821 # cddb query on stdout. Any PREGAP for track 1 is properly
1822 # handled, although cue files embedded in FLAC files do not
1823 # appear to properly store the PREGAP setting. :(
1824 abcde.cue2discid () {
1829 while [ $val -gt 0 ] ; do
1830 ret=$(( $ret + ( $val % 10) ))
1831 val=$(( $val / 10 ))
1841 local first second third
1842 first=$(expr ${1} + 0 )
1843 second=$(expr ${2} + 0 )
1844 third=$(expr ${3} + 0 )
1846 echo $(( ((($first * 60) + $second) * 75) + $third ))
1856 while read line ; do
1859 TRACK) i=$(( i + 1 ))
1861 INDEX) if [ "$2" -eq 1 ] ; then
1863 START=$(( $LBA + $PREGAP + $OFFSET ))
1865 X=$(cddb_sum $(( $START / 75 )) )
1869 PREGAP) PREGAP=$(msf2lba $2)
1873 LEADOUT=$(( $4 / 588 ))
1876 LEADIN=$(( $3 / 588 ))
1885 LEADOUT=$(( $LEADOUT + $LEADIN ))
1887 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1888 CDDBDISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1889 printf "%08x %i" $CDDBDISCID $TRACKS
1892 while [ $j -le $TRACKS ] ; do
1893 eval echo -n "\" \$TRACK$j\""
1896 echo " $(( $LEADOUT / 75 ))"
1900 # abcde.mkcue [--wholedisk]
1901 # This creates a cuefile directly from the extended discid information
1902 # The --wholedisk option controls whether we're ripping data from the
1903 # start of track one or from the start of the disk (usually, but not
1904 # always the same thing!)
1906 # Track one leadin/pregap (if any) handeling:
1907 # --wholedisk specified:
1910 # INDEX 01 <pregap value>
1911 # Remaining track index values unchanged from disc TOC
1913 # --wholedisk not specified
1915 # PREGAP <pregap value>
1917 # Remaining track index values offset by <pregap value>
1924 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1927 local MODE DISCID TRACKS
1931 if [ "$1" = --wholedisk ] ; then
1937 vecho "One track is $ONETRACK"
1938 TRACKFILE="$(mungetrackname "$TRACKNAME")"
1939 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
1940 ALBUMFILE="$(mungealbumname "$DALBUM")"
1941 if [ "$ONETRACK" = "y" ]; then
1942 if [ "$VARIOUSARTISTS" = "y" ]; then
1943 CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1945 CUEWAVFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1947 vecho "Cue wav file is $CUEWAVFILE"
1949 CUEWAVFILE="dummy.wav"
1952 set -- $CDDBTRACKINFO
1958 echo REM DISCID $DISCID
1959 echo FILE \""$CUEWAVFILE"\" WAVE
1961 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1968 while [ $i -le "$TRACKS" ] ; do
1969 LBA=$(( $1 - $OFFSET ))
1970 printf " TRACK %02i AUDIO\n" $i
1971 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1972 if [ $MODE = PREGAP ] ; then
1973 echomsf " PREGAP " $(($OFFSET-150))
1975 echo " INDEX 00 00:00:00"
1978 echomsf " INDEX 01 " $LBA
1985 # This is essentially the start of things
1988 if [ -z "$CDDBDISCID" ]; then
1989 vecho -n "Getting CD track info... "
1990 # In OSX, unmount the disc before a query
1991 if [ "$OSFLAVOUR" = "OSX" ]; then
1992 diskutil unmount ${CDROM#/dev/}
1994 case "$CDROMREADERSYNTAX" in
1996 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1997 case "$CUE2DISCID" in
1998 # FIXME # right now we have 2 cue2discid internal
1999 # implementations: builtin and abcde.cue2discid. Test
2000 # both of them and decide which one we want to use.
2002 #vecho "Using builtin cue2discid implementation..."
2003 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
2005 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
2007 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
2008 TRACKS=${#OFFSETTIMES[@]}
2010 #echo "processing offsetimes ${OFFSETTIMES[@]}"
2011 for OFFSETTIME in ${OFFSETTIMES[@]}; do
2012 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
2013 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
2016 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) * 75 / 44100 ))
2017 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) * 75 / 44100 ))
2021 #vecho "Using external python cue2discid implementation..."
2022 CDDBTRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
2026 log error "the input flac file does not contain a cuesheet."
2031 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2033 if [ ! "$RET" = "0" ];then
2034 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2037 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2038 CDPARANOIAAUDIOTRACKS="$TRACKS"
2040 LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
2041 OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
2045 # Calculate the cddb discid in all
2046 # cases now. We'll use the cddb discid
2047 # for reference in most cases for
2048 # consistency. Also calculate the
2049 # musicbrainz discid if we need it.
2050 CDDBTRACKINFO=$($CDDISCID "$CDROM")
2051 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2054 MBTRACKINFO=$($MUSICBRAINZ --command id --device "$CDROM")
2055 MBDISCID=$(echo $MBTRACKINFO | cut -d' ' -f1)
2059 # Make sure there's a CD in there by checking cd-discid's return code
2060 if [ ! "$?" = "0" ]; then
2061 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2062 log error "cuesheet information from the flac file could not be read."
2063 log error "Perhaps the flac file does not contain a cuesheet?."
2066 log error "CD could not be read. Perhaps there's no CD in the drive?"
2070 # In OSX, remount the disc again
2071 if [ "$OSFLAVOUR" = "OSX" ]; then
2072 diskutil mount ${CDROM#/dev/}
2075 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -f1 -d' ')
2077 CDDBTRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$CDDBDISCID/cddbdiscid")
2080 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
2081 # This needs to be done now because a section of the resuming code will need
2084 # get the number of digits to pad TRACKNUM with - we'll use this later
2085 # a CD can only hold 99 tracks, but since we support a feature for starting
2086 # numbering the tracks from a given number, we might need to set it as a
2087 # variable for the user to define... or obtain it somehow.
2088 if [ "$PADTRACKS" = "y" ] ; then
2092 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $CDDBTRACKINFO | cut -f1 -d' ')"
2093 if [ -z "$TRACKQUEUE" ]; then
2094 if [ ! "$STRIPDATATRACKS" = "n" ]; then
2095 case "$CDROMREADERSYNTAX" in
2096 cdparanoia|libcdio|debug)
2097 if [ "$WEHAVEACD" = "y" ]; then
2098 vecho "Querying the CD for audio tracks..."
2099 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
2101 if [ ! "$RET" = "0" ];then
2102 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
2104 TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
2105 CDPARANOIAAUDIOTRACKS="$TRACKS"
2107 # Previous versions of abcde would store the tracks on a file, instead of the status record.
2108 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
2109 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
2110 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
2112 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
2113 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2117 *) TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ') ;;
2120 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2122 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
2123 log info "The disc does not contain any tracks. Giving up..."
2126 echo -n "Grabbing entire CD - tracks: "
2127 if [ ! "$PADTRACKS" = "y" ] ; then
2128 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
2130 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
2132 while [ "$X" -ne "$TRACKS" ]
2134 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
2135 TRACKQUEUE=$(echo $TRACKQUEUE $X)
2139 TRACKS=$(echo $CDDBTRACKINFO | cut -f2 -d' ')
2140 # User-supplied track queue.
2141 # Weed out non-numbers, whitespace, then sort and weed out duplicates
2142 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
2143 # Once cleaned, obtain the highest value in the trackqueue for number padding
2144 for LASTTRACK in $TRACKQUEUE; do :; done
2145 if [ ! "$PADTRACKS" = "y" ] ; then
2146 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
2148 # Now we normalize the trackqueue
2149 for TRACK in $TRACKQUEUE ; do
2150 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
2151 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
2153 TRACKQUEUE=$PADTRACKQUEUE
2154 echo Grabbing tracks: "$TRACKQUEUE"
2157 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
2159 # We have the discid, create a temp directory after it to store all the temp
2162 if [ -e "$ABCDETEMPDIR" ]; then
2163 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
2164 # It already exists, see if it's a directory
2165 if [ ! -d "$ABCDETEMPDIR" ]; then
2166 # This is a file/socket/fifo/device/etc, not a directory
2169 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
2170 echo "Please investigate, remove it, and rerun abcde." >&2
2174 # It's a directory, let's see if it's writable by us
2175 if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
2176 # Nope, complain and exit
2178 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
2179 echo "Please investigate, remove it, and rerun abcde." >&2
2183 # See if it's populated
2184 if [ ! -f "$ABCDETEMPDIR/cddbdiscid" ]; then
2185 # Wipe and start fresh
2186 echo "abcde: $ABCDETEMPDIR/cddbdiscid not found. Abcde must remove and recreate" >&2
2187 echo -n "this directory to continue. Continue [y/N]? " >&2
2188 if [ "$INTERACTIVE" = "y" ]; then
2194 if [ "$ANSWER" != "y" ]; then
2197 rm -rf "$ABCDETEMPDIR" || exit 1
2198 mkdir -p "$ABCDETEMPDIR"
2199 if [ "$?" -gt "0" ]; then
2200 # Directory already exists or could not be created
2201 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2205 # Everything is fine. Check for ^encodetracklocation-
2206 # and encode-output entries in the status file and
2207 # remove them. These are not relevant across sessions.
2208 if [ -f "$ABCDETEMPDIR/status" ]; then
2209 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
2210 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
2211 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
2213 # Remove old error messages
2214 if [ -f "$ABCDETEMPDIR/errors" ]; then
2215 rm -f "$ABCDETEMPDIR/errors"
2219 # We are starting from scratch
2220 mkdir -p "$ABCDETEMPDIR"
2221 if [ "$?" -gt "0" ]; then
2222 # Directory already exists or could not be created
2223 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
2226 cat /dev/null > "$ABCDETEMPDIR/status"
2227 # Store the abcde version in the status file.
2228 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
2230 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
2231 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
2232 CUEFILE=cue-$(echo "$CDDBTRACKINFO" | cut -f1 -d' ').txt
2233 vecho "Creating cue file..."
2234 case $CDROMREADERSYNTAX in
2236 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
2237 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2239 log warning "the input flac file does not contain a cuesheet."
2243 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
2244 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
2246 log warning "reading the CUE sheet is still considered experimental"
2247 log warning "and there was a problem with the CD reading. abcde will continue,"
2248 log warning "but consider reporting the problem to the abcde author"
2254 # If we got the CDPARANOIA status and it is not recorded, save it now
2255 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2256 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
2257 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2261 # Create the discid files
2262 echo "$CDDBTRACKINFO" > "$ABCDETEMPDIR/cddbdiscid"
2265 echo "$MBTRACKINFO" > "$ABCDETEMPDIR/mbdiscid"
2271 # Create a proper CUE file based on the CUE file we created before.
2274 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
2275 CUEFILE_OUT=$CUEFILE_IN.out
2276 ### FIXME ### checkstatus cddb
2277 if [ -e "$CDDBDATA" ]; then
2278 vecho "Adding metadata to the cue file..."
2279 # FIXME It doesn't preserve spaces! Why?
2280 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2282 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2283 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2284 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2288 cat "$CUEFILE_IN" | while read line
2290 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2291 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2292 # echo "$line" >> "$CUEFILE_OUT"
2293 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2294 eval track="\$TRACK$n"
2296 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2297 # When making a single-track rip, put the
2298 # actual file name into the file declaration
2299 # in the cue file so that it is usable by
2300 # music players and the like
2301 elif [ "$ONETRACK" = "y" ] &&
2302 echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
2304 TRACKFILE="$(mungetrackname "$TRACKNAME")"
2305 ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
2306 ALBUMFILE="$(mungealbumname "$DALBUM")"
2308 if [ "$VARIOUSARTISTS" = "y" ]; then
2309 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2311 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2314 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2317 # FIXME # If the lines above are uncommented, remove the line below.
2318 echo "$line" >> "$CUEFILE_OUT"
2321 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2322 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2328 # Parses a CDDB file and outputs the title and the track names.
2329 # Variables: CDDBFILE
2333 # List out disc title/author and contents
2334 if [ "$ONETRACK" = "y" ]; then
2335 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2337 echo "---- $(grep -a DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2338 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2339 PARSEDYEAR=$(grep -a DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2340 if [ ! X"$PARSEDYEAR" = "X" ]; then
2341 echo "Year: $PARSEDYEAR"
2344 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2345 PARSEDGENRE=$(grep -a DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2346 if [ ! X"$PARSEDGENRE" = "X" ]; then
2347 echo "Genre: $PARSEDGENRE"
2350 if [ ! "$ONETRACK" = "y" ]; then
2351 for TRACK in $(f_seq_row 1 $TRACKS)
2353 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2359 # Check for a local CDDB file, and report success
2360 do_localcddb_read ()
2362 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2364 CDDBLOCALSTATUS="notfound"
2365 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2368 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2369 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2370 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2371 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2372 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2373 CDDBLOCALMATCH=single
2374 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2375 CDDBLOCALMATCH=multiple
2380 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2381 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2382 CDDBLOCALMATCH=single
2387 # If the user has selected to check a local CDDB repo, we proceed with it
2388 case $CDDBLOCALMATCH in
2390 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2392 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2394 # List out disc title/author and contents
2395 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2396 cat "$RESULT" > "${CDDBLOCALREAD}"
2399 do_cddbparse "${CDDBLOCALREAD}"
2401 ##FIXME## QUICK HACK !!!!
2402 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2403 } >> "$ABCDETEMPDIR/cddblocalchoices"
2405 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge $LINES ] && [ "$INTERACTIVE" = "y" ]; then
2406 page "$ABCDETEMPDIR/cddblocalchoices"
2408 # It's all going to fit in one page, cat it
2409 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2411 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2412 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2413 CDDBLOCALCHOICENUM=-1
2414 if [ "$INTERACTIVE" = "y" ]; then
2415 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2416 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2417 read CDDBLOCALCHOICE
2418 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2419 # FIXME # Introduce diff's
2420 if echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2421 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2422 elif echo $CDDBLOCALCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2423 # Make sure we get a valid choice
2424 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2425 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2426 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2432 #echo "Selected ..."
2434 CDDBLOCALCHOICENUM=1
2436 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2437 #echo "Using local copy of CDDB data"
2438 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2439 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2440 echo "local" > "$ABCDETEMPDIR/datasource.1"
2441 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2442 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2443 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2444 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2445 CDDBLOCALSTATUS="found"
2447 #echo "Not using local copy of CDDB data"
2448 CDDBLOCALSTATUS="notfound"
2452 # List out disc title/author and contents
2453 do_cddbparse "${CDDBLOCALFILE}"
2454 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2455 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2457 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2459 if [ "$INTERACTIVE" = "y" ]; then
2461 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2462 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2465 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2469 if [ "$USELOCALRESP" = "y" ]; then
2470 #echo "Using local copy of CDDB data"
2471 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2472 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2473 echo "local" > "$ABCDETEMPDIR/datasource.1"
2474 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2475 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2476 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2477 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2478 CDDBLOCALSTATUS="single"
2480 #echo "Not using local copy of CDDB data"
2481 CDDBLOCALSTATUS="notfound"
2485 CDDBLOCALSTATUS="notfound"
2492 # Try to read CD-Text from the drive using icedax / cdda2wav
2495 if new_checkexec icedax; then
2496 CDTEXT_READER=icedax
2497 elif new_checkexec cdda2wav; then
2498 CDTEXT_READER=cdda2wav
2500 # Didn't find either, bail
2504 vecho "Obtaining CD-Text results..."
2505 CDTDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2506 local SOURCE_WORKDIR="$ABCDETEMPDIR/data-cdtext"
2507 mkdir -p "${SOURCE_WORKDIR}"
2509 if [ "$OSFLAVOUR" = "OSX" ] ; then
2510 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2511 diskutil unmount ${CDROM#/dev/}
2512 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2513 CDDA2WAVCDROM="IODVDServices"
2514 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2515 CDDA2WAVCDROM="$CDROMID"
2517 if [ "$CDROMID" = "" ]; then
2518 CDDA2WAVCDROM="$CDROM"
2520 CDDA2WAVCDROM="$CDROMID"
2524 # Do we have CD-Text on the disc (and can the drive read it?)
2526 cd "${SOURCE_WORKDIR}" && rm -f audio.* audio_*
2527 ${CDTEXT_READER} -J -v titles -D ${CDDA2WAVCDROM} > "${SOURCE_WORKDIR}/cd-text" 2>&1
2529 grep -a -q '^CD-Text: detected' "${SOURCE_WORKDIR}/cd-text"
2531 if [ $ERRORCODE -ne 0 ]; then
2532 # No CD-Text found, bail
2536 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2537 # Make an empty template
2538 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2539 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2540 rm -f "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2542 # XXX FIXME - this is a hack and should be replaced by proper
2543 # character set tracking for the CDDB data we have.
2544 if test "$CDDBPROTO" -ge 6 ; then
2545 # convert to Unicode
2546 iconv -f iso-8859-1 -t utf-8 <"${SOURCE_WORKDIR}/audio.cddb" >"${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2548 # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
2549 # apparently icedax/cdda2wav have no support for 16-bit
2550 # characters yet, either
2551 cp -p "${SOURCE_WORKDIR}/audio.cddb" "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2554 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2555 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2556 echo "CD-Text" > ${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}
2557 echo "none $CDDBDISCID ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2559 ( cd "${SOURCE_WORKDIR}" && rm -f audio_* audio.* )
2560 cp "${SOURCE_WORKDIR}/"*."${NUM_CDDB_MATCHES}" "$ABCDETEMPDIR"
2561 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2564 # do_musicbrainz_read
2565 # Work with the musicbrainz WS API, then transform the results here so
2566 # they look (very) like the results from CDDB. Maybe not the best way
2567 # to go, but it Works For Me (TM)
2569 # List out all the matches individually into $SOURCE_WORKDIR/cddbread.X
2571 do_musicbrainz_read ()
2573 if checkstatus musicbrainz-readcomplete; then :; else
2574 vecho "Obtaining Musicbrainz results..."
2575 # If MB is to be used, interpret the query results and read all
2576 # the available entries.
2577 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2578 MBDISCID=$(echo $MBTRACKINFO | cut -d' ' -f1)
2579 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-musicbrainz"
2580 mkdir -p "${SOURCE_WORKDIR}"
2581 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "${SOURCE_WORKDIR}" --start ${NUM_CDDB_MATCHES}
2583 # Check for no matches.
2584 # The helper script will write disc matches out to
2585 # cddbread.*. Count how many we have
2586 NUM_RESPONSES=$(echo "${SOURCE_WORKDIR}"/cddbread.* | wc -w)
2587 if [ "$NUM_RESPONSES" -gt 0 ] ; then
2588 # One or more exact matches
2590 while [ $i -le $NUM_RESPONSES ]; do
2591 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2593 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "$ABCDETEMPDIR/status"
2594 ATITLE=$(grep -a -e '^DTITLE=' "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}" | cut -c8- | tr -d \\r\\n)
2595 echo "none $CDDBDISCID ${ATITLE}" >> "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
2596 echo "Musicbrainz" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
2597 cp -f "${SOURCE_WORKDIR}/"*."${NUM_CDDB_MATCHES}" "$ABCDETEMPDIR"
2600 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2607 local SOURCE_WORKDIR="${ABCDETEMPDIR}/data-cddb"
2608 mkdir -p "${SOURCE_WORKDIR}"
2614 # Perform CDDB protocol version check if it hasn't already been done
2615 if checkstatus cddb-statcomplete; then :; else
2616 if [ "$CDDBAVAIL" = "n" ]; then
2618 echo 503 > "${SOURCE_WORKDIR}/cddbstat"
2621 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2622 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2623 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2624 vecho "Checking CDDB server status..."
2625 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "${SOURCE_WORKDIR}/cddbstat"
2626 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2627 case "$RESPONSECODE" in
2628 210) # 210 OK, status information follows (until terminating `.')
2631 501) # 501 Illegal CDDB protocol level: <n>.
2632 CDDBPROTO=`expr $CDDBPROTO - 1`
2634 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2635 # FreeDB TESTCD disc-id is used for query
2636 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "${SOURCE_WORKDIR}/cddbstat"
2637 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbstat" | cut -f1 -d' ')
2638 case "$RESPONSECODE" in
2639 2??) # Server responded, everything seems OK
2649 if test $rc -eq 1; then
2653 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2660 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
2661 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2663 # Perform CDDB query if it hasn't already been done
2664 if checkstatus cddb-querycomplete; then :; else
2665 if [ "$CDDBAVAIL" = "n" ]; then
2667 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2668 # The default CDDBLOCALSTATUS is "notfound"
2669 # This part will be triggered if the user CDDB repo does not
2670 # contain the entry, or if we are not trying to use the repo.
2672 vecho "Querying the CDDB server..."
2673 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2674 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2675 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $CDDBTRACKINFO > "${SOURCE_WORKDIR}/cddbquery"
2681 # no match found in database, wget/fetch error,
2682 # or user requested not to use CDDB. Make up an
2683 # error code (503) that abcde will recognize later
2684 # and compensate by making a template
2685 echo 503 > "${SOURCE_WORKDIR}/cddbquery"
2687 *) # strange and unknown error
2688 echo ERRORCODE=$ERRORCODE
2689 echo "abcde: $CDDBTOOL returned unknown error code"
2693 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2700 # If it's not to be used, generate a template.
2701 # Then, display it (or them) and let the user choose/edit it
2702 if checkstatus cddb-readcomplete; then :; else
2703 RESPONSECODE=$(head -n 1 "${SOURCE_WORKDIR}/cddbquery" | cut -f1 -d' ')
2704 vecho "Obtaining CDDB results..."
2705 case "$RESPONSECODE" in
2707 # One exact match, retrieve it
2708 # 200 [section] [discid] [artist] / [title]
2709 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2710 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2711 cat ${SOURCE_WORKDIR}/cddbquery | cut -f2- -d' ' > ${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}
2712 echo "cddb" > ${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}
2713 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "${ABCDETEMPDIR}/status"
2715 202|403|409|500|503)
2716 # TODO: Explain these error codes a little more accurately:
2717 # http://ftp.freedb.org/pub/freedb/misc/freedb_CDDB_protcoldoc.zip
2718 # No match response:
2721 # Multiple exact, (possibly multiple) inexact matches
2722 vecho -n "Retrieving multiple matches... "
2723 grep -v ^[.]$ "${SOURCE_WORKDIR}/cddbquery" | (
2724 read DISCINFO # eat top line
2727 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2728 if checkstatus cddb-read-${NUM_CDDB_MATCHES}-complete; then :; else
2729 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
2730 echo "$DISCINFO" > ${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}
2731 echo "cddb/$CDDBHOST" > ${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}
2732 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "$ABCDETEMPDIR/status"
2739 NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
2740 echo cddb-read-${NUM_CDDB_MATCHES}-complete >> "$ABCDETEMPDIR/status"
2743 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2744 cp -f "${SOURCE_WORKDIR}/"*.* "$ABCDETEMPDIR"
2751 if checkstatus cddb-edit >/dev/null; then
2752 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2753 VARIOUSARTISTS="$(checkstatus variousartists)"
2754 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2757 if [ "$INTERACTIVE" = "y" ]; then
2758 # We should show the CDDB results both when we are not using the local CDDB repo
2759 # or when we are using it but we could not find a proper match
2760 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2761 # Display the $ABCDETEMPDIR/cddbchoices file created above
2762 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2763 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2764 CHOICE=$(checkstatus cddb-choice)
2765 if [ -n "$CHOICE" ] ; then
2766 case $NUM_CDDB_MATCHES in
2767 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2769 ATITLE=$(grep -a ^DTITLE= "$ABCDETEMPDIR/cddbread.$CHOICE" | cut -f2- -d= | tr -d \\r\\n)
2770 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CHOICE")
2771 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)"
2772 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2776 # The user has a choice to make, display the info in a pager if necessary
2777 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge $LINES ]; then
2778 page "$ABCDETEMPDIR/cddbchoices"
2780 # It's all going to fit in one page, cat it
2781 cat "$ABCDETEMPDIR/cddbchoices" >&2
2785 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2787 # I'll take CDDB read #3 for $400, Alex
2788 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; do
2789 echo -n "Which entry would you like abcde to use (0 for none)? [0-$NUM_CDDB_MATCHES]: " >&2
2791 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2792 if echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2793 if [ ! X"$DIFF" = "X" ]; then
2794 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2795 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2796 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $NUM_CDDB_MATCHES ] || \
2797 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $NUM_CDDB_MATCHES ] || \
2798 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2799 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
2801 # We parse the 2 choices to diff, store them in temporary files and diff them.
2802 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2803 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2805 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2806 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2807 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge $LINES ]; then
2808 page "$ABCDETEMPDIR/cddbread.diff"
2810 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2814 echo "The diff program was not found in your path. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2816 elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2817 # Make sure we get a valid choice
2818 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2819 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $NUM_CDDB_MATCHES ]; then
2820 echo "Invalid selection. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
2824 if [ "$CDCHOICENUM" = "0" ]; then
2825 vecho "Creating empty CDDB template..."
2827 $CDDBTOOL template $(cat "$ABCDETEMPDIR/cddbdiscid") > "$ABCDETEMPDIR/cddbread.0"
2829 ATITLE=$(grep -a ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n)
2830 SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CDCHOICENUM")
2831 echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)" >&2
2832 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2834 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2838 # We need some code to show the selected option when local repository is selected and we have found a match
2839 vecho "Using cached CDDB match..." >&2
2840 # Display the $ABCDETEMPDIR/cddbchoices file created above
2841 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2842 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2843 CHOICE=$(checkstatus cddb-choice)
2844 if [ "$USELOCALRESP" = "y" ]; then :; else
2845 if [ -n "$CHOICE" ] ; then
2846 case $NUM_CDDB_MATCHES in
2849 echo "Selected template."
2851 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2853 echo "Selected: #$CHOICE"
2854 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2862 # We're noninteractive - pick the first choice.
2863 # But in case we run a previous instance and selected a choice, use it.
2864 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2865 # Show the choice if we are not using the locally stored one
2866 # or when the local search failed to find a match.
2867 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2868 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2869 #if [ "$PREVIOUSCHOICE" ]; then
2870 cat "$ABCDETEMPDIR/cddbchoices"
2873 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2874 CDCHOICENUM=$PREVIOUSCHOICE
2877 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2879 echo "Selected: #$CDCHOICENUM ($(grep -a ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2884 if checkstatus cddb-choice >/dev/null; then :; else
2885 echo "abcde: internal error: cddb-choice not recorded." >&2
2888 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2889 CDDBSOURCE=$(cat "$ABCDETEMPDIR/datasource.$(checkstatus cddb-choice)")
2890 echo -n "Edit selected CDDB data " >&2
2891 if [ "$INTERACTIVE" = "y" ]; then
2892 if [ "$UNKNOWNDISK" = "y" ]; then
2893 echo -n "[Y/n]? " >&2
2895 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2897 echo -n "[y/N]? " >&2
2904 if [ "$EDITCDDB" = "y" ]; then
2905 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2907 # Use the debian sensible-editor wrapper to pick the editor that the
2908 # user has requested via their $EDITOR environment variable
2909 if [ -x "/usr/bin/sensible-editor" ]; then
2910 /usr/bin/sensible-editor "$CDDBDATA"
2911 elif [ -n "$EDITOR" ]; then
2912 if [ -x $(which "${EDITOR%%\ *}") ]; then
2913 # That failed, try to load the preferred editor, starting
2914 # with their EDITOR variable
2915 eval $(echo "$EDITOR") \"$CDDBDATA\"
2917 # If that fails, check for a vi
2918 elif which vi >/dev/null 2>&1; then
2920 elif [ -x /usr/bin/vim ]; then
2921 /usr/bin/vim "$CDDBDATA"
2922 elif [ -x /usr/bin/vi ]; then
2923 /usr/bin/vi "$CDDBDATA"
2924 elif [ -x /bin/vi ]; then
2926 # nano should be on all (modern, i.e., sarge) debian systems
2927 elif which nano >/dev/null 2>&1 ; then
2929 elif [ -x /usr/bin/nano ]; then
2930 /usr/bin/nano "$CDDBDATA"
2931 # mg should be on all OpenBSD systems
2932 elif which mg >/dev/null 2>&1 ; then
2934 elif [ -x /usr/bin/mg ]; then
2935 /usr/bin/mg "$CDDBDATA"
2938 log warning "no editor available. Check your EDITOR environment variable."
2940 # delete editor backup file if it exists
2941 if [ -w "$CDDBDATA~" ]; then
2946 # Some heuristics first. Look at Disc Title, and if it starts with
2947 # "Various", then we'll assume Various Artists
2948 if [ "$(grep -a ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -aEci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2949 echo "Looks like a Multi-Artist CD" >&2
2952 echo -n "Is the CD multi-artist [y/N]? " >&2
2953 if [ "$INTERACTIVE" = "y" ]; then
2960 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2963 # Need NUMTRACKS before cddb-tool will return it:
2964 NUMTRACKS=$(grep -a -E '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2965 if [ "$(grep -ac "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2966 # More than 1/2 tracks contain a "/", so guess forward
2968 elif [ "$(grep -ac "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2969 # More than 1/2 contain a "-", so guess forward-dash
2971 elif [ "$(grep -ac "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2972 # More than 1/2 contain something in parens, so guess trailing-paren
2976 echo "1) Artist / Title" >&2
2977 echo "2) Artist - Title" >&2
2978 echo "3) Title / Artist" >&2
2979 echo "4) Title - Artist" >&2
2980 echo "5) Artist: Title" >&2
2981 echo "6) Title (Artist)" >&2
2982 echo "7) This is a single-artist CD" >&2
2983 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2984 if [ "$INTERACTIVE" = "y" ]; then
2985 read VARIOUSARTISTSTYLE
2987 echo $DEFAULTSTYLE >&2
2988 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2990 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2991 # If they press Enter, then the default style (0) was chosen
2992 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2993 echo "Invalid selection. Please choose a number between 1 and 7."
2994 echo -n "Selection [1-7]: "
2995 read VARIOUSARTISTSTYLE
2996 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2998 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2999 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
3001 vecho "Selected: $VARIOUSARTISTSTYLE"
3002 case "$VARIOUSARTISTSTYLE" in
3004 VARIOUSARTISTSTYLE=forward
3007 VARIOUSARTISTSTYLE=forward-dash
3010 VARIOUSARTISTSTYLE=reverse
3013 VARIOUSARTISTSTYLE=reverse-dash
3016 VARIOUSARTISTSTYLE=colon
3019 VARIOUSARTISTSTYLE=trailing-paren
3027 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
3028 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
3030 if [ "$EDITCDDB" = "y" ] && [ "$CDDBSOURCE" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
3031 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
3032 # This works but does not have the necessary error checking
3033 # yet. If you are familiar with the CDDB spec
3034 # (see http://www.freedb.org/src/latest/DBFORMAT)
3035 # and can create an error-free entry on your own, then put
3036 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
3037 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
3038 # your abcde.conf to change the email address submissions are
3041 # submit the modified file, if they want
3042 if [ "$NOSUBMIT" != "y" ]; then
3043 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
3045 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3046 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3048 echo -n 'Invalid selection. Please answer "y" or "n": '
3051 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3052 echo -n "Sending..."
3053 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
3060 # User CDDBLOCALPOLICY to find out if we store the file or not...
3061 # Cache edited CDDB entry in the user's cddb dir
3062 if [ "$CDDBCOPYLOCAL" = "y" ]; then
3063 # Make sure the cache directory exists
3064 mkdir -p $CDDBLOCALDIR
3065 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$CDDBTRACKINFO" | cut -d' ' -f1)
3068 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
3072 # try to download CD cover
3076 ALBUMFILE="$(mungealbumname "$DALBUM")"
3077 ARTISTFILE="$(mungeartistname "$DARTIST")"
3078 GENRE="$(mungegenre "$GENRE")"
3079 YEAR=${CDYEAR:-$CDYEAR}
3080 # have we got a musicbrainz mbid or amazon asin?
3081 case "$CDDBMETHOD" in
3083 # try musicbrainz mbid
3084 if [ -s "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)" ]; then
3085 MBID=$(cat "$ABCDETEMPDIR/mbid.$(checkstatus cddb-choice)")
3086 vecho "trying to get cover from coverartarchive.orq with musicbrainz mbid $MBID" >&2
3087 ALBUMARTURL="http://coverartarchive.org/release/$MBID/front"
3088 vecho "cover URL: $ALBUMARTURL" >&2
3089 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3090 if [ $? -ne 0 ]; then
3091 vecho "could not download cover from musicbrainz" >&2
3093 if [ -s "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)" ]; then
3094 ASIN=$(cat "$ABCDETEMPDIR/asin.$(checkstatus cddb-choice)")
3095 vecho "trying to get cover from amazon.com with asin $ASIN" >&2
3096 ALBUMARTURL="http://ec1.images-amazon.com/images/P/$ASIN.01.LZZZZZZZZ.jpg"
3097 vecho "cover URL: $ALBUMARTURL" >&2
3098 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3099 if [ $? -ne 0 ]; then
3100 vecho "could not download cover from amazon" >&2
3102 # Check that size is reasonable; sometimes when there is no cover image
3103 # on amazon.com a 1x1 pixel gif image will be downloaded instead:
3104 FILESIZE=$(wc -c < "$ABCDETEMPDIR/$ALBUMARTFILE")
3105 if [ "$FILESIZE" -lt 1024 ]; then
3106 rm "$ABCDETEMPDIR/$ALBUMARTFILE"
3107 vecho "could not download cover from amazon" >&2
3111 vecho "no amazon ID found" >&2
3115 vecho "no musicbrainz ID found" >&2
3120 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3121 vecho "trying to get cover with glyrc for $ARTISTFILE / $ALBUMFILE" >&2
3122 $GLYRC cover --artist "$ARTISTFILE" --album "$ALBUMFILE" --write "$ABCDETEMPDIR/$ALBUMARTFILE" $GLYRCOPTS
3123 if [ $? -ne 0 ]; then
3124 vecho "could not download cover with glyrc" >&2
3129 if [ "$INTERACTIVE" = "y" ]; then
3130 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3131 # display properties of coverart when identify is available
3132 if new_checkexec $IDENTIFY; then
3133 $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
3135 # display coverart when DISPLAY is set and display command is available
3136 if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
3137 $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
3140 # nothing downloaded yet
3141 vecho "automatic album art downloading failed" >&2
3143 # see if the user can find a better album art manually
3144 echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
3146 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
3147 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
3149 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
3152 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
3153 echo -n "Enter URL or local path (ENTER to cancel) :" >&2
3155 if [ ! -z "$ALBUMARTURL" ]; then
3156 if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
3157 $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
3158 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3159 vecho "unable to download $ALBUMARTURL" >&2
3161 else # it's a local path
3162 cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
3163 if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3164 vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
3170 # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
3171 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
3172 ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
3173 if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
3174 if new_checkexec $CONVERT; then
3175 mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3176 $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
3177 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
3179 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3180 vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
3184 # copy to target directories
3185 if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
3186 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3188 # put cover in the same place as the album
3189 if [ "$ONETRACK" = "y" ] ; then
3190 if [ "$VARIOUSARTISTS" = "y" ] ; then
3191 ALBUMARTDIR="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3193 ALBUMARTDIR="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3196 if [ "$VARIOUSARTISTS" = "y" ] ; then
3197 ALBUMARTDIR="$(eval echo "$VAOUTPUTFORMAT")"
3199 ALBUMARTDIR="$(eval echo "$OUTPUTFORMAT")"
3202 FINALALBUMARTDIR="$(dirname "$OUTPUTDIR/$ALBUMARTDIR")"
3203 vecho "copying cover to target directory $FINALALBUMARTDIR" >&2
3204 mkdir -p "$FINALALBUMARTDIR"
3205 cp "$ABCDETEMPDIR/$ALBUMARTFILE" "$FINALALBUMARTDIR"
3207 rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
3208 echo "get-album-art=$ALBUMARTURL" >> "$ABCDETEMPDIR/status"
3210 log warning "could not get cover"
3211 echo "get-album-art=none" >> "$ABCDETEMPDIR/status"
3215 # Optionally embed the albumart downloaded by the getalbumart fuction.
3216 # FIXME: It would be nice to have this also selectable from within the
3217 # FIXME: getalbumart function itself. Andrew
3221 ALBUMFILE="$(mungealbumname "$DALBUM")"
3222 ARTISTFILE="$(mungeartistname "$DARTIST")"
3223 GENRE="$(mungegenre "$GENRE")"
3224 YEAR=${CDYEAR:-$CDYEAR}
3226 # Allow for multiple output formats:
3227 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3229 # Find the output directory for multi track encodes:
3230 if [ "$ONETRACK" != "y" ] ; then
3231 if [ "$VARIOUSARTISTS" = "y" ] ; then
3232 FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
3234 FINDPATH="$(eval echo "$OUTPUTFORMAT")"
3237 # Find the output directory for single track encodes:
3238 if [ "$ONETRACK" = "y" ] ; then
3239 if [ "$VARIOUSARTISTS" = "y" ] ; then
3240 FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
3242 FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
3246 FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
3249 # Instructions for each format, feel free to add more. It would be nice to
3250 # make the backup directory selectable and perhaps also have an option for
3251 # the bold to simply have the image deleted. Work for another day... Andrew.
3252 if [ -e "$ALBUMARTFILE" ] ; then
3257 "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$i"
3259 mkdir "$FINALDIR"/albumart_backup
3260 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3261 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3266 "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
3268 mkdir "$FINALDIR"/albumart_backup
3269 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3270 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3275 "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
3277 mkdir "$FINALDIR"/albumart_backup
3278 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3279 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3284 "$WVTAG" --write-binary-tag "Cover Art (Front)=@"$ALBUMARTFILE"" "$i"
3286 mkdir "$FINALDIR"/albumart_backup
3287 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3288 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3292 # This technique is drawn from 2 sources (the first link being the primary source):
3293 # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
3294 # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
3295 # In abcde a few steps are used in this sequence:
3297 # 1. Create a 'legal' header for the cover art image
3298 # 2. Makes a copy of the existing tags
3299 # 3. base64 the cover art image
3300 # 4. Copy the original tags + the base64 image back to the original ogg file
3302 # Might need some fine tuning but it is a start for abcde 2.8.2 Andrew.
3303 # FIXME: I am not sure if there is a maximum size for images converted in this
3304 # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
3306 # First some variables we can reuse:
3307 # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
3308 MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
3309 EXPORTTAGS="$ABCDETEMPDIR/export_ogg_tags"
3310 BUILDHEADER="$ABCDETEMPDIR/build_header"
3311 # Now build the header, gory details are here:
3312 # https://xiph.org/flac/format.html#metadata_block_picture
3314 printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
3316 printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3318 echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
3319 # Description length. FIXME: I have used 'Cover Image' but I am not sure
3320 # if this is better left as an empty field. Andrew
3321 printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
3323 echo -n "Cover Image" >> "$BUILDHEADER"
3325 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3327 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3328 # Picture color depth:
3329 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3330 # Picture color count:
3331 printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
3333 printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
3334 # cat the image file:
3335 cat "$ALBUMARTFILE" >> "$BUILDHEADER"
3336 # Now process each ogg file by first exporting the original tags then
3337 # appending the cover image and finally copying the whole thing back
3338 # to the original image:
3341 # Make a backup of the existing tags:
3342 "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
3343 # base64 the file and then mix it all together with the exported tags:
3344 echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
3345 # Update the original ogg file with exported tags and the appended base64'd image:
3346 "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
3347 # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
3348 # note that the header file BUILDHEADER will be reused for each file in the loop:
3351 mkdir "$FINALDIR"/albumart_backup
3352 mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
3353 vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
3355 *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
3358 vecho "Suitable cover image not found, no embedding done..." >&2
3363 # do_cdread [tracknumber]
3364 # do_cdread onetrack [firsttrack] [lasttrack]
3368 # The commands here don't go through run_command because they're never supposed to be silenced
3369 # return codes need to be doublechecked anyway, however
3370 if [ "$1" = "onetrack" ]; then
3371 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
3372 # FIXME # Until then, we grab the whole CD in one track, no matter what
3374 # We need the first and last track for cdda2wav/icedax
3376 LASTTRACK=$(expr $3 + 0)
3377 UTRACKNUM=$FIRSTTRACK
3378 case "$CDROMREADERSYNTAX" in
3379 flac) READTRACKNUMS="-" ;;
3382 # Add a variable to check if tracks are provided in command line and if not, rip the whole CD
3383 # We must make sure to rip from sector 0, both lines below work
3384 # READTRACKNUMS="-- -$LASTTRACK" ;;
3385 READTRACKNUMS="[.0]-" ;;
3386 cdda2wav | icedax) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
3387 pird) READTRACKNUMS="$FIRSTTRACK..$LASTTRACK" ;;
3388 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
3394 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
3395 if [ "$USEPIPES" = "y" ]; then
3396 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
3397 FILEARG="$( eval echo "\$$TEMPARG" )"
3398 PIPE_MESSAGE="and encoding "
3400 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
3401 case "$CDROMREADERSYNTAX" in
3402 ## FIXME ## Find the cases for flac, to avoid exceptions
3404 FILEARG="--output-name=$WAVDATA"
3411 if [ "$1" = "onetrack" ]; then
3412 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
3414 if [ -r "$CDDBDATA" ]; then
3415 getcddbinfo TRACKNAME
3416 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
3418 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
3421 case "$CDROMREADERSYNTAX" in
3422 ### FIXME ### use an exception for flac, since it uses -o
3423 ### FIXME ### Shall we just use -o $FILEARG ??
3425 # Avoid problems with math expressions by unpadding the given UTRACKNUM
3426 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
3427 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
3429 if [ "$USEPIPES" = "y" ]; then
3430 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3432 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3436 if [ "$OSFLAVOUR" = "OSX" ] ; then
3437 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
3438 diskutil unmount ${CDROM#/dev/}
3439 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
3440 CDDA2WAVCDROM="IODVDServices"
3441 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
3442 CDDA2WAVCDROM="$CDROMID"
3444 if [ "$CDROMID" = "" ]; then
3445 CDDA2WAVCDROM="$CDROM"
3447 CDDA2WAVCDROM="$CDROMID"
3450 if [ "$USEPIPES" = "y" ]; then
3451 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
3453 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
3457 # I cannot get USEPIPES to work with dagrab so just this:
3458 nice $READNICE $CDROMREADER -d "$CDROM" -f "$FILEARG" -v $UTRACKNUM >&2
3461 if [ "$USEPIPES" = "y" ]; then
3462 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$FILEARG"
3464 # Write ripped audio data to stdout and redirect to $FILEARG.
3465 # Progress is written to stderr by default and thus >&2 is not required.
3466 nice $READNICE $CDROMREADER -j ${READTRACKNUMS:-$UTRACKNUM} "$CDROM" "$PIPERIPPER_pird" > "$FILEARG"
3470 # Find the track's mounted path
3471 REALTRACKNUM=$(expr $UTRACKNUM + 0)
3472 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
3473 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
3474 # If the file exists, copy it
3475 if [ -e "$FILEPATH" ] ; then
3476 if [ "$USEPIPES" = "y" ]; then
3477 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
3479 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
3485 if [ "$USEPIPES" = "y" ]; then
3486 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3488 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
3493 # If we get some error or we get some missing wav
3494 # (as long as we dont use pipes)
3495 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
3496 # Thank goodness errors is only machine-parseable up to the
3497 # first colon, otherwise this woulda sucked
3498 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3499 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
3501 if [ "$USEPIPES" = "y" ]; then
3502 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3504 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3508 if [ "$USEPIPES" = "y" ]; then
3509 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3511 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3513 if [ "$1" = "onetrack" ]; then
3514 echo onetrack >> "$ABCDETEMPDIR/status"
3520 # No values accepted, only uses env variables
3523 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
3524 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
3526 echo "abcde: unable to set the device speed" >&2
3532 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3535 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3537 warning) shift ; log warning "$@" ;;
3545 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3548 if [ x"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3550 warning) shift ; log warning "$@" ;;
3558 # decho outputs a debug message if DEBUG is selected
3561 if [ x"$DEBUG" != "x" ]; then
3562 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
3563 DEBUGECHO=$(echo "$@" | tr -d '[]')
3564 echo >&4 "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3566 echo >&4 "[DEBUG] $1"
3571 # User-redefinable functions
3572 # Custom filename munging:
3575 echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
3578 # Custom filename munging specific to track names:
3584 # Custom filename munging specific to artist names:
3590 # Custom filename munging specific to album names:
3596 # Custom genre munging:
3599 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
3603 # Empty pre_read function, to be defined in the configuration file.
3610 # Empty post_read function, to be defined in the configuration file.
3617 # Empty post_encode function, to be defined in the configuration file.
3623 ###############################################################################
3626 # Start of execution
3627 ###############################################################################
3632 # Currently three supported options ("musicbrainz", "cddb" for freedb.org and "cdtext")
3633 CDDBMETHOD=musicbrainz
3634 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
3635 CDDBSUBMIT=freedb-submit@freedb.org
3637 HELLOINFO="$(whoami)@$(hostname)"
3639 CDDBLOCALPOLICY="always"
3640 CDDBLOCALRECURSIVE="y"
3641 CDDBLOCALDIR="$HOME/.cddb"
3644 # List of fields we parse and show during the CDDB parsing...
3645 SHOWCDDBFIELDS="year,genre"
3648 #CDROMREADERSYNTAX=cdparanoia
3649 ENCODERSYNTAX=default
3651 MP3ENCODERSYNTAX=default
3652 OGGENCODERSYNTAX=default
3653 OPUSENCODERSYNTAX=default
3654 MKAENCODERSYNTAX=default
3655 AIFFENCODERSYNTAX=default
3656 FLACENCODERSYNTAX=default
3657 SPEEXENCODERSYNTAX=default
3658 MPCENCODERSYNTAX=default
3659 WVENCODERSYNTAX=default
3660 TTAENCODERSYNTAX=default
3661 APENCODERSYNTAX=default
3662 MP2ENCODERSYNTAX=default
3663 AACENCODERSYNTAX=default
3664 NORMALIZERSYNTAX=default
3665 CUEREADERSYNTAX=default
3667 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3668 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3669 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3670 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3671 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3672 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
3673 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3674 PLAYLISTDATAPREFIX=''
3675 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3676 VAPLAYLISTDATAPREFIX=''
3684 VARIOUSARTISTSTYLE=forward
3691 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3692 # i.e. CDROMID="1,0,0"
3694 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3695 # If we are using the ide-scsi emulation layer, we need to define a "g"
3696 CDPARANOIACDROMBUS="d"
3698 # program paths - defaults to checking your $PATH
3704 XINGMP3ENC=xingmp3enc
3718 # WVENC is retained in abcde 2.7.1 for backwards compatibility
3722 # True Audio: 'tta' is the newer version, 'ttaenc' is the older version:
3732 NEROAACENC=neroAacEnc
3734 # Note that the qaac PATH will almost always require adjustment
3735 # as it is a Windows application being run through Wine. More
3736 # detailed notes in the sample abcde.conf file in the abcde tarball.
3739 # The path to 'avconv' rather than 'ffmpeg'can be used here:
3747 VORBISCOMMENT=vorbiscomment
3749 NEROAACTAG=neroAacTag
3750 ATOMICPARSLEY=AtomicParsley
3754 CDPARANOIA=cdparanoia
3755 CD_PARANOIA=cd-paranoia
3762 MUSICBRAINZ=abcde-musicbrainz-tool
3766 NORMALIZE=normalize-audio
3768 VORBISGAIN=vorbisgain
3772 # For Wavpack replay gain we set both the default of 'track gain'
3773 # as well as this option for 'album gain'. Better media players
3774 # such as vlc can select either or neither. Andrew.
3785 # Options for programs called from abcde:
3788 # These options needed by FFmpeg for tagging and selection of id3v2 version:
3789 # 1. '-write_id3v2 1' allows id3v2 tagging while '-write_id3v2 0' disables tagging
3790 # 2. '-id3v2_version 4' gives version id3v2.4 while '3' gives id3v2.3
3791 AIFFENCOPTS="-write_id3v2 1 -id3v2_version 4"
3803 VORBISGAINOPTS="--album"
3807 # The flac option is a workaround for an error where flac fails
3808 # to encode with error 'floating point exception'. This is flac
3809 # error in get_console_width(), corrected in flac 1.3.1
3811 FLACGAINOPTS="--add-replay-gain"
3818 # True Audio has no useful options but it is here anyway :)
3821 # Monkey's Audio Console (mac) chokes without a mode setting
3822 # so we set one here.
3829 # fdkaac chokes without either a bitrate or bitrate-mode specified so
3830 # we set bitrate here.
3831 FDKAACENCOPTS='--bitrate 192k'
3853 VORBISCOMMENTOPTS="-R"
3854 METAFLACOPTS="--no-utf8-convert"
3859 DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
3861 # Defaults for album art downloads
3862 ALBUMARTFILE="cover.jpg"
3864 ALBUMARTALWAYSCONVERT="n"
3866 # Default to one process if -j isn't specified
3869 # List of actions to perform - by default, run to completion
3870 ACTIONS=cddb,read,encode,tag,move,clean
3872 # This option is basically for Debian package dependencies:
3873 # List of preferred outputs - by default, run with whatever we have in the path
3874 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex,m4a:fdkaac:opus
3876 # List of preferred cdromreaders - by default, run whichever we have in the path
3877 DEFAULT_CDROMREADERS="cdparanoia icedax cdda2wav libcdio pird"
3879 # fd for when `vecho` and `log info` called with redirected stdout
3882 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3883 # Linux/OpenBSD. ftp is user for NetBSD.
3884 # Let's use these checkings to determine the OS flavour, which will be used
3886 if [ X$(uname) = "XFreeBSD" ] ; then
3891 elif [ X$(uname) = "XDarwin" ] ; then
3893 # By default md5sum is not installed, use md5 instead:
3896 # We should have diskutil in OSX, but let's be sure...
3898 CDROMREADERSYNTAX=cddafs
3899 # We won't find the eject program in OSX, and doing checkexec will fail further below...
3901 elif [ X$(uname) = "XOpenBSD" ] ; then
3905 elif [ X$(uname) = "XNetBSD" ] ; then
3909 elif [ X$(uname) = "SunOS" ] ; then
3917 # If CDDBAVAIL is set to n, no CDDB read is done
3921 # But before we get into business, let us chop off any GREP environmental
3926 # Length of the terminal *should* be in $LINES. If it's not, guess at
3927 # a reasonable number instead
3928 if [ -z "$LINES" ]; then
3932 if [ -z "$OUTPUTDIR" ]; then
3936 if [ -z "$WAVOUTPUTDIR" ]; then
3937 WAVOUTPUTDIR="$OUTPUTDIR"
3940 # Load system defaults
3941 if [ -r /etc/abcde.conf ]; then
3944 # Load user preference defaults
3945 if [ -r $HOME/.abcde.conf ]; then
3949 # By this time, we need some HTTPGETOPTS already defined.
3950 # If the user has defined a non-default HTTPGET method, we should not be empty.
3952 if [ "$HTTPGETOPTS" = "" ] ; then
3954 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3955 curl) HTTPGETOPTS="-f -s -L";;
3956 fetch)HTTPGETOPTS="-q -o -";;
3957 ftp) HTTPGETOPTS="-a -V -o - ";;
3958 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3962 # If the CDROM has not been set yet, find a suitable one.
3963 # If this is a devfs system, default to /dev/cdroms/cdrom0
3964 # instead of /dev/cdrom
3965 if [ "$CDROM" = "" ] ; then
3966 if [ -e /dev/cdroms/cdrom0 ]; then
3967 CDROM=/dev/cdroms/cdrom0
3968 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $(diskutil list) =~ CD_part[^/]*(disk.)$'\n' ]]; then
3969 CDROM=/dev/${BASH_REMATCH[1]}
3970 elif [ -e /dev/cdrom ]; then
3972 elif [ -e /dev/sr0 ]; then
3974 elif [ -e /dev/cd0c ]; then
3976 elif [ -e /dev/acd0c ]; then
3978 elif [ -e /dev/disk1 ]; then
3983 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3984 # that's changed to a number to allow for more control. Deal with
3985 # EXTRAVERBOSE=y/n, set it to 1/0 for backwards compatibility.
3986 case "$EXTRAVERBOSE" in
3995 # Parse command line options
3996 while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pP:Q:r:s:S:t:T:UvVxX:w:W:z opt ; do
3999 a) ACTIONS="$OPTARG" ;;
4000 A) EXPACTIONS="$OPTARG" ;;
4002 B) GETALBUMART=y ; EMBEDALBUMART=y ;;
4003 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
4004 C) CDDBDISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
4005 d) CDROM="$OPTARG" ;;
4008 e) ERASEENCODEDSTATUS=y ;;
4009 E) ENCODING="$OPTARG" ;;
4014 j) MAXPROCS="$OPTARG" ;;
4017 L) CDDBUSELOCAL=y ;;
4022 o) OUTPUTTYPE="$OPTARG" ;;
4025 Q) CDDBMETHOD="$OPTARG" ;;
4026 r) REMOTEHOSTS="$OPTARG" ;;
4027 R) CDDBLOCALRECURSIVE=y ;;
4028 s) SHOWCDDBFIELDS="$OPTARG" ;;
4029 S) CDSPEEDVALUE="$OPTARG" ;;
4030 t) STARTTRACKNUMBER="$OPTARG" ;;
4031 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
4034 echo "This is abcde v$VERSION."
4035 echo "Usage: abcde [options] [tracks]"
4036 echo "abcde -h for extra help"
4039 V) EXTRAVERBOSE=$(($EXTRAVERBOSE + 1)) ;;
4041 X) CUE2DISCID="$OPTARG" ;;
4042 w) COMMENT="$OPTARG" ;;
4043 W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
4044 STARTTRACKNUMBER="${OPTARG}$(printf %02d ${STARTTRACKNUMBER:-01})"
4045 STARTTRACKNUMBERTAG="y"
4046 COMMENT="CD${OPTARG}"
4047 DISCNUMBER="${OPTARG}"
4049 log error "argument of -W must be integer"
4053 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
4058 shift $(($OPTIND - 1))
4060 # Here it comes the worse part of the whole thing. From here until we start
4061 # ripping, we have a mixture of sanity checks, verifications, default settigs
4062 # and other crazy stuff that interdepends, but hey, someone has to do it.
4064 # If NOCDDBQUERY is set, don't query the CDDB server.
4065 if [ "$NOCDDBQUERY" = "y" ]; then
4069 # If the user specified a flac file, then switch to special flac mode
4070 if echo "$CDROM" | grep -i '.flac$' > /dev/null 2>&1 ; then
4071 if [ ! -f "$CDROM" ]; then
4072 log error "the defined file for FLAC ripping cannot be found" >&2
4075 vecho warning "switching to flac CDROMREADERSYNTAX..."
4076 CDROMREADERSYNTAX=flac
4077 # We have a builtin version of cue2discid...
4078 case "$CUE2DISCID" in
4080 *) NEEDCUE2DISCID=y;;
4086 # If the user provided a CDDBDISCID, disable eject
4087 if [ -n "$CDDBDISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
4089 # Check the available cd rippers in the system, from the ones we know.
4090 if [ "$CDROMREADERSYNTAX" = "" ]; then
4091 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
4092 if new_checkexec $DEFAULT_CDROMREADER; then
4093 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
4097 if [ "$CDROMREADERSYNTAX" = "" ]; then
4098 log error "no cdreader found in your PATH"
4099 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4104 # Decide if we can continue.
4105 if [ "$ONETRACK" = "y" ]; then
4106 # FIXME # remove check as soon as we find out about the other readers
4107 case "$CDROMREADERSYNTAX" in
4109 cdparanoia | libcdio) ;;
4110 cdda2wav | icedax) ;;
4112 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
4115 if [ "$BATCHNORM" = "y" ]; then
4116 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
4119 if [ "$NOGAP" = "y" ]; then
4120 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
4123 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
4124 # FIXME # allow ranges of tracks to be selected for onetrack ripping
4125 if [ $# -gt 0 ]; then
4126 log warning "ONETRACK mode selected, grabbing all tracks..."
4129 while [ $# -gt 0 ]; do
4130 # Range parsing code courtesy of Vincent Ho
4131 # Cleaned up to use shell built-ins by Charles Steinkuehler
4132 if [ "${1#*[^0-9-]}" != "$1" ]; then
4133 log error "syntax error while processing track numbers ($1)"
4138 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
4139 TRACKQUEUE="$TRACKQUEUE $RSTART"
4140 RSTART=$(( $RSTART + 1 ))
4147 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
4148 # List of experimental actions: retag,transcode
4150 # Determine what actions are to be done from $ACTIONS and set the
4151 # following environment variables for them:
4163 ## FIXME ## Lets keep compatibility with -M
4164 [ "$DOCUE" != "y" ] && DOCUE=n
4166 for ACTION in $(echo $ACTIONS | tr , \ )
4169 default) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOCLEAN=y;;
4170 cue) DOCUE=y ; MAKECUEFILE=y ;;
4173 normalize) DONORMALIZE=y; DOREAD=y;;
4174 # preprocess) DOPREPROCESS=y; DOREAD=y;;
4175 encode) DOENCODE=y; DOREAD=y;;
4176 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
4177 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4178 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
4179 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
4180 playlist) DOCDDB=y; DOPLAYLIST=y;;
4182 getalbumart) GETALBUMART=y;;
4183 embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
4187 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
4188 # FIXME # should we abort on error or just inform the user?
4189 log warning "selected both normalize and replaygain actions"
4192 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
4193 case $SHOWCDDBFIELD in
4194 y*|Y*) SHOWCDDBYEAR="y";;
4195 g*|G*) SHOWCDDBGENRE="y";;
4200 # At this point a CDROM has to be defined, so we check it exists.
4201 if [ X"$CDROM" != "X" ] ; then
4202 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] || [ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
4203 if [ "$OSFLAVOUR" = "FBSD" ]; then
4204 if echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then :; else
4205 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
4206 log error "Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
4210 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
4211 log error "CDROM device cannot be found."
4214 # avoid processing if we are not going to hit the CDROM.
4215 elif [ X"$DOREAD" = "Xy" ]; then
4216 log error "CDROM has not been defined or cannot be found"
4220 # USEPIPES pre-tests, before we get into more serious stuff
4221 # Not compatible with:
4222 # - multiple outputs
4224 # - lowdisk algorithm
4226 if [ X"$USEPIPES" = "Xy" ]; then
4227 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
4228 log error "Unix pipes not compatible with multiple outputs"
4231 if [ X"$DONORMALIZE" = "Xy" ]; then
4232 log error "Unix pipes not compatible with normalizer"
4233 # FIXME # Do we need to exit or shall we just disable the mode?
4236 if [ X"$BATCHNORM" = "Xy" ]; then
4237 log error "Unix pipes not compatible with BATCHNORM encoding"
4240 if [ X"$NOGAP" = "Xy" ]; then
4241 log error "Unix pipes not compatible with NOGAP encoding"
4244 if [ X"$DOENCODE" = "Xn" ]; then
4245 vecho warning "Disabling Unix pipes since we are not encoding!"
4248 if [ X"$LOWDISK" = "Xy" ]; then
4249 log error "Unix pipes not compatible with lowdisk algorithm"
4254 # LOWDISK pre-tests, before we get into more problematic stuff
4255 # Not compatible with anything that needs all the files in the hard disc:
4258 if [ X"$LOWDISK" = "Xy" ]; then
4259 if [ X"$BATCHNORM" = "Xy" ]; then
4260 log error "Unix pipes not compatible with BATCHNORM encoding"
4263 if [ X"$NOGAP" = "Xy" ]; then
4264 log error "Unix pipes not compatible with NOGAP encoding"
4269 # BATCHNORM pre-tests, before we get into serious problems
4270 # Not compatible with
4271 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
4272 vecho warning "Disabling BATCHNORM since we are not normalizing!"
4276 # Check the encoding format from the ones available in the system, if nothing has been configured.
4277 if [ X"$OUTPUTTYPE" = "X" ]; then
4278 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
4279 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
4280 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
4281 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
4282 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
4283 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
4287 if [ X"$OUTPUTTYPE" = "X" ]; then
4288 log error "no encoder found in the PATH"
4289 log error "hints: are all dependencies installed? has the \$PATH been modified?"
4294 # Decide which CDROM reader we're gonna use
4295 case "$CDROMREADERSYNTAX" in
4297 CDROMREADER="$CDPARANOIA"
4298 CDROMREADEROPTS="$CDPARANOIAOPTS"
4301 # GNU's libcdio package will use cd-paranoia but I believe will be happy with
4302 # the standard cdparanoia options. If I am wrong this will need to be fixed :).
4303 CDROMREADER="$CD_PARANOIA"
4304 CDROMREADEROPTS="$CDPARANOIAOPTS"
4307 CDROMREADER="$CDDA2WAV"
4308 CDROMREADEROPTS="$CDDA2WAVOPTS"
4311 CDROMREADER="$DAGRAB"
4312 CDROMREADEROPTS="$DAGRABOPTS"
4316 CDROMREADEROPTS="$PIRDOPTS"
4319 CDROMREADER="$CDDAFS"
4320 CDROMREADEROPTS="$CDDAFSOPTS"
4324 CDROMREADEROPTS="$FLACOPTS"
4328 # There's only one normalize...
4329 case "$NORMALIZERSYNTAX" in
4331 NORMALIZER="$NORMALIZE"
4332 NORMALIZEROPTS="$NORMALIZEOPTS"
4336 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
4337 case "$OUTPUTTYPE" in *:*)
4338 for OUTPUT in $(echo "$OUTPUTTYPE" | tr \ \|| tr , \ ); do
4339 OUTPUT="$(echo "$OUTPUT" | tr \| \ )"
4341 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4342 opus:*) OPUSENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4343 mka:*) MKAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4344 aiff:*) AIFFENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4345 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4346 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4347 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4348 mpc:*) MPCENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4349 wv:*) WVENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4350 tta:*) TTAENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4351 ape:*) APENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4352 mp2:*) MP2ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4353 m4a:*|aac:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
4356 # Allows commandline selection of options while using multiple outputs.
4357 # Example: abcde -o 'flac:-8,mp3:-b 320' Patch by Matthias Andree.
4358 for OUTPUT in $(echo "$OUTPUTTYPE" | tr -d ' ' | tr , ' '); do
4359 TEMPOUTPUT=${OUTPUT%%:*}
4360 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
4362 OUTPUTTYPE="$TEMPOUTPUTTYPE"
4366 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
4367 # for flacs and speexenc for speex and mpcenc for mpcs and fdkaac for m4as and
4368 # wavpack for wvs...
4370 # Getting ready for multiple output changes
4371 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
4375 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
4376 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
4377 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
4378 OGGOUTPUTCONTAINER=ogg
4381 [ "$OPUSENCODERSYNTAX" = "default" ] && OPUSENCODERSYNTAX=opusenc
4382 OPUSOUTPUTCONTAINER=opus
4385 [ "$MKAENCODERSYNTAX" = "default" ] && MKAENCODERSYNTAX=ffmpeg
4386 MKAOUTPUTCONTAINER=mka
4389 [ "$AIFFENCODERSYNTAX" = "default" ] && AIFFENCODERSYNTAX=ffmpeg
4390 AIFFOUTPUTCONTAINER=aiff
4393 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
4394 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
4395 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
4396 [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
4399 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
4400 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
4401 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
4402 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
4403 [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
4406 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
4407 # [ "$DOREPLAYGAIN" = "y" ] &&
4410 [ "$MPCENCODERSYNTAX" = "default" ] && MPCENCODERSYNTAX=mpcenc
4411 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPCGAIN=y
4414 [ "$WVENCODERSYNTAX" = "default" ] && WVENCODERSYNTAX=wavpack
4416 [ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
4417 [ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
4418 [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
4421 [ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
4422 [ "$DOTAG" = "y" ] && NEEDAPETAG=y
4425 [ "$MP2ENCODERSYNTAX" = "default" ] && MP2ENCODERSYNTAX=twolame
4426 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4427 [ "$MP2ENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4430 [ "$TTAENCODERSYNTAX" = "default" ] && TTAENCODERSYNTAX=tta
4431 [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4432 [ "$TTAENCODERSYNTAX" = "ttaenc" ] && [ "$DOTAG" = "y" ] && NEEDMID3V2=y
4435 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
4437 # Neither Faac nor AtomicParsley can tag the .aac files which are used for faac
4438 # compiled without libmp4v2... Andrew.
4441 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=fdkaac
4442 [ "$AACENCODERSYNTAX" = "faac" ] && [ "$DOTAG" = "y" ] && CHECKFAACBUILD=y
4443 [ "$AACENCODERSYNTAX" = "neroAacEnc" ] && NEEDNEROAACTAG=y
4444 [ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
4445 [ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
4446 [ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
4447 [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
4450 if [ "$KEEPWAVS" = "y" ]; then
4451 vecho "Setting the KEEPWAVS option, since the resulting wav files were requested..."
4455 *) log error "Invalid OUTPUTTYPE defined"
4461 # decide which encoder
4462 case "$MP3ENCODERSYNTAX" in
4464 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
4468 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
4472 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
4473 MP3ENCODER="$BLADEENC"
4476 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
4480 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
4481 MP3ENCODER="$XINGMP3ENC"
4484 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
4485 MP3ENCODER="$MP3ENC"
4488 case "$OGGENCODERSYNTAX" in
4490 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
4491 OGGENCODER="$VORBIZE"
4494 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
4495 OGGENCODER="$OGGENC"
4498 case "$OPUSENCODERSYNTAX" in
4500 OPUSENCODEROPTS="${OPUSENCODEROPTSCLI:-$OPUSENCOPTS}"
4501 OPUSENCODER="$OPUSENC"
4504 case "$MKAENCODERSYNTAX" in
4506 MKAENCODEROPTS="${MKAENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4507 MKAENCODER="$FFMPEG"
4510 case "$AIFFENCODERSYNTAX" in
4512 AIFFENCODEROPTS="${AIFFENCODEROPTSCLI:-$AIFFENCOPTS}"
4513 AIFFENCODER="$FFMPEG"
4516 case "$FLACENCODERSYNTAX" in
4518 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
4520 if [ "$DOREPLAYGAIN" = "y" ]; then
4521 FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
4523 # FLAC streams can be encapsulated on a Ogg transport layer
4524 if echo "$FLACENCODEROPTS" | grep -E -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
4525 log error "FLAC on an Ogg container is not yet supported"
4526 log error "due to problem with adding comments to such files"
4528 FLACOUTPUTCONTAINER=ogg
4530 FLACOUTPUTCONTAINER=flac
4534 case "$SPEEXENCODERSYNTAX" in
4536 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
4537 SPEEXENCODER="$SPEEXENC"
4540 case "$MPCENCODERSYNTAX" in
4542 MPCENCODEROPTS="${MPCENCODEROPTSCLI:-$MPCENCOPTS}"
4543 MPCENCODER="$MPCENC"
4546 case "$WVENCODERSYNTAX" in
4548 # Syntax changed slightly between abcde 2.7 and abcde 2.7.1,
4549 # and in the interests of backward compatibility:
4550 if [ -z "$WAVPACKENCOPTS" ] && [ -n "$WVENCOPTS" ]; then
4551 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WVENCOPTS}"
4552 WVENCODER="$WAVPACK"
4554 WVENCODEROPTS="${WVENCODEROPTSCLI:-$WAVPACKENCOPTS}"
4555 WVENCODER="$WAVPACK"
4559 WVENCODEROPTS="${WVENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4563 case "$TTAENCODERSYNTAX" in
4565 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4569 TTAENCODEROPTS="${TTAENCODEROPTSCLI:-$TTAENCOPTS}"
4570 TTAENCODER="$TTAENC"
4573 case "$APENCODERSYNTAX" in
4575 APENCODEROPTS="${APENCODEROPTSCLI:-$APENCOPTS}"
4579 case "$MP2ENCODERSYNTAX" in
4581 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$TWOLAMENCOPTS}"
4582 MP2ENCODER="$TWOLAME"
4585 MP2ENCODEROPTS="${MP2ENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4586 MP2ENCODER="$FFMPEG"
4589 case "$AACENCODERSYNTAX" in
4590 # Some elaborate 'if' work to keep backward compatibility for those
4591 # who don't realise that AACENCOPTS does not work with abcde from
4592 # version 2.7 onwards.
4594 if [ -z "$FAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4595 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4598 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FAACENCOPTS}"
4603 if [ -z "$NEROAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4604 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4605 AACENCODER="$NEROAACENC"
4607 AACENCODEROPTS="${AACENCODEROPTSCLI:-$NEROAACENCOPTS}"
4608 AACENCODER="$NEROAACENC"
4612 if [ -z "$FDKAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4613 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4614 AACENCODER="$FDKAAC"
4616 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FDKAACENCOPTS}"
4617 AACENCODER="$FDKAAC"
4621 if [ -z "$QAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4622 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4625 AACENCODEROPTS="${AACENCODEROPTSCLI:-$QAACENCOPTS}"
4630 if [ -z "$FHGAACENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4631 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4632 AACENCODER="$FHGAACENC"
4634 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FHGAACENCOPTS}"
4635 AACENCODER="$FHGAACENC"
4639 if [ -z "$FFMPEGENCOPTS" ] && [ -n "$AACENCOPTS" ]; then
4640 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
4641 AACENCODER="$FFMPEG"
4643 AACENCODEROPTS="${AACENCODEROPTSCLI:-$FFMPEGENCOPTS}"
4644 AACENCODER="$FFMPEG"
4654 TAGGEROPTS="$ID3OPTS"
4659 TAGGEROPTS="$ID3V2OPTS"
4664 TAGGEROPTS="$ID3TAGOPTS"
4668 # Note that eyeD3 is set to tag in utf-16 (below). This causes
4669 # trouble with CDDBPROTO=5 (which we test here) but also
4670 # with cached cddb files in latin1 (which we cannot test).
4671 if [ "$CDDBPROTO" -lt 6 ]; then
4672 log warning "You cannot have id3v2.4 tags encoded in latin1. Setting CDDBPROTO to 6 for now."
4675 # eyeD3 version 0.7 changed syntax
4676 if $EYED3 --help 2>&1 | grep -q -- --set-encoding ; then
4677 # only if it offers the --set-encoding, assume <= 0.6.x
4679 TAGGEROPTS="--set-encoding utf16-LE $EYED3OPTS"
4681 # anything wrong, any failure, assume >= 0.7
4683 TAGGEROPTS="--encoding utf16 $EYED3OPTS"
4687 log error "Error: ID3TAGV must be either \"id3v1\", \"id3v2.3\" or \"id3v2.4\""
4692 # NOGAP is specific to lame. Other encoders fail ...
4693 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
4694 log warning "the NOGAP option is specific to lame. Deactivating..."
4699 case "$CUEREADERSYNTAX" in
4701 CUEREADEROPTS="${CDROM}"
4705 CUEREADEROPTS="$MKCUEOPTS ${CDROM}"
4710 # which information retrieval tool are we using?
4716 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
4717 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
4718 log error "FLAC on an Ogg container is not yet supported"
4719 log error "due to problem with adding comments to such files"
4721 OGGOUTPUTCONTAINER=ogg.ogg
4722 FLACOUTPUTCONTAINER=flac.ogg
4723 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
4726 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
4728 if [ "$ENCNICE" ]; then
4729 ENCNICE="-n $ENCNICE"
4731 if [ "$READNICE" ]; then
4732 READNICE="-n $READNICE"
4734 if [ "$DISTMP3NICE" ]; then
4735 DISTMP3NICE="-n $DISTMP3NICE"
4738 # Don't check for stuff if it's not needed
4739 if [ "$REMOTEHOSTS" ]; then
4742 if [ "$DONORMALIZE" = "y" ]; then
4745 if [ "$EJECTCD" = "y" ]; then
4748 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
4749 # Need an http tool to be able to do CDDB
4755 if [ "$DOCUE" = "y" ]; then
4759 if [ X"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
4760 case "$CDROMREADERSYNTAX" in
4761 cdparanoia|libcdio|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
4762 pird) CDROMREADEROPTS="$PIRDOPTS -s $CDSPEEDVALUE" ;;
4763 ### FIXME ### translate "cue2discid" from python to bash
4764 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ; CDSPEEDVALUE="" ;;
4769 if [ "$GETALBUMART" = "y" ]; then
4774 ###USEPIPESSUPPORT###
4776 # Rippers with USEPIPE support
4777 PIPERIPPER_cdparanoia="-"
4778 PIPERIPPER_libcdio="-"
4779 # Note that by default in abcde cdda2wav redirects to icedax.
4780 PIPERIPPER_cdda2wav="-"
4781 PIPERIPPER_debug="-"
4782 PIPERIPPER_flac="-c "
4785 # Encoders with USEPIPE support
4788 PIPE_bladeenc="stdin"
4801 # Both neroAacEnc and fdkaac seem to manage without the addition of
4802 # the 'ignorelength' option in PIPE_$AACENCODERSYNTAX when piping
4803 # in this manner. Andrew.
4807 # Figure out if we can use pipes with the ripper/encoder combination
4809 if [ "$USEPIPES" = "y" ]; then
4810 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
4813 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
4815 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
4817 PIPEENCODERSVARCHECK="PIPE_$OPUSENCODERSYNTAX" ;;
4819 PIPEENCODERSVARCHECK="PIPE_$MKAENCODERSYNTAX" ;;
4821 PIPEENCODERSVARCHECK="PIPE_$AIFFENCODERSYNTAX" ;;
4823 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
4825 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODERSYNTAX" ;;
4827 PIPEENCODERSVARCHECK="PIPE_$MPCENCODERSYNTAX" ;;
4829 PIPEENCODERSVARCHECK="PIPE_$WVENCODERSYNTAX" ;;
4831 PIPEENCODERSVARCHECK="PIPE_$TTAENCODERSYNTAX" ;;
4833 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4835 PIPEENCODERSVARCHECK="PIPE_$AACENCODERSYNTAX" ;;
4837 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
4838 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
4839 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
4840 log error "no support for pipes with given ripper"
4841 log error "read the FAQ file from the source tarball to get help."
4844 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
4845 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
4846 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
4847 log error "no support for pipes with given encoder"
4848 log error "read the FAQ file from the source tarball to get help"
4853 # Make sure a buncha things exist
4854 for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4855 $OGGENCODER $OPUSENCODER $MKAENCODER $FLACENCODER $SPEEXENCODER $MPCENCODER \
4856 $AACENCODER $WVENCODER $CDDBTOOL $APENCODER $MP2ENCODER $TTAENCODER $AIFFENCODER \
4857 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4858 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4859 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4860 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4861 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4862 ${NEEDMPCGAIN+$MPCGAIN} ${NEEDCUEREADER+$CUEREADER} \
4863 ${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
4864 ${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
4865 ${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4866 ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
4871 # Under Debian and Ubuntu faac is compiled without libmp4v2 which means no support
4872 # for the mp4 container and no tagging capability. (AtomicParsley also cannot tag
4873 # these files). The resulting files are actually ADTS streams which belong in an
4874 # aac container and with some version sniffing this is all cleaned up below. If
4875 # faac is compiled with libmp4v2 inline tagging occurs with faac.
4877 # FIXME: Should this be in this location? (Better incorporated into the checks above.)
4878 if [ "$CHECKFAACBUILD" = "y" ] && [ "$AACENCODERSYNTAX" = "faac" ] ; then
4879 if faac --help 2>&1 | grep -q -F 'MP4 support unavailable.'; then
4880 echo "WARNING: Your copy of Faac does not have mp4 support"
4881 echo "WARNING: Encoding untagged files to aac..."
4882 # Replace m4a with aac for single and multi-output encodes:
4883 OUTPUTTYPE=$(echo "$OUTPUTTYPE" | sed 's/m4a/aac/')
4885 echo "Using Faac to Tag AAC Tracks..."
4889 # And last but not least, check if we can diff between files. We do not abort,
4890 # since diffing is not critical...
4891 if [ -x $(which $DIFF) ]; then :; else
4892 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
4896 ## Now that we have metaflac, check if we need cue2discid
4897 #case $CDROMREADERSYNTAX in
4899 # CDDBTRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4900 # if [ "$CDDBTRACKINFO" = "" ]; then
4901 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4906 CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
4907 CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
4908 HTTPGET="$HTTPGET $HTTPGETOPTS"
4910 # Here it used to say:
4911 # One thousand lines in, we can start doing stuff with things
4912 # Well, right now we are at line 3737 ;)
4913 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
4915 # Export needed things so they can be read in this subshell
4916 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4917 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4919 if [ "$DOREAD" = "y" ]; then
4920 # User-definable function to set some things. Use it for
4921 # - closing the CD tray with eject -t
4922 # - set the CD speed value with eject -x
4923 vecho -n "Executing customizable pre-read function... "
4925 pre_read # Execute the user-defined pre-read function. Close the CD with it.
4930 # Get ABCDETEMPDIR created and status file initialized
4933 if [ "$DOCDDB" = "y" ]; then
4934 # start with a sane default:
4935 CDDBLOCALSTATUS=notfound
4936 if [ $CDDBUSELOCAL = "y" ]; then
4939 if checkstatus cddb-choice > /dev/null; then
4943 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4945 for CDDBMETHCHOICE in $(echo "$CDDBMETHOD" | tr -d ' ' | tr , ' ')
4947 addstatus "CDDB method $idx: $CDDBMETHCHOICE"
4949 vecho "Trying CDDB method ${CDDBMETHCHOICE}, found $NUM_CDDB_MATCHES matches so far"
4951 # Run all the desired data acquisition methods, in the order
4952 # specified by the user. Each will use its own temporary
4953 # subdirectory, then copy the cddbread.* etc. files up into
4955 case "$CDDBMETHCHOICE" in
4966 echo "Unknown CDDB method $CDDBMETHCHOICE. Aborting." >&2
4973 rm -f "${ABCDETEMPDIR}/cddbchoices"
4974 CDDBDISCID=$(echo $CDDBTRACKINFO | cut -d' ' -f1)
4976 if [ $NUM_CDDB_MATCHES = 0 ]; then
4977 # If we got no matches, we need to
4978 # generate a blank CDDB template.
4979 vecho "Unable to find any matches, generating unknown template."
4980 echo "No CDDB match." >> "${ABCDETEMPDIR}/cddbchoices"
4981 $CDDBTOOL template $(cat "${ABCDETEMPDIR}/cddbdiscid") > "${ABCDETEMPDIR}/cddbread.0"
4982 # List out disc title/author and contents of template
4983 echo ---- Unknown Artist / Unknown Album ---- >> "${ABCDETEMPDIR}/cddbchoices"
4985 for TRACK in $(f_seq_row 1 $TRACKS)
4987 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "${ABCDETEMPDIR}/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
4989 echo >> "${ABCDETEMPDIR}/cddbchoices"
4990 echo cddb-read-0-complete >> "${ABCDETEMPDIR}/status"
4991 echo cddb-choice=0 >> "${ABCDETEMPDIR}/status"
4992 echo 503 > "$ABCDETEMPDIR/cddbquery"
4994 # We have matches; create the cddbchoices and cddbquery
4995 # files from all the inputs we have
4996 if [ $NUM_CDDB_MATCHES = 1 ]; then
4997 echo "Retrieved 1 match..." >> "$ABCDETEMPDIR/cddbchoices"
4998 echo -n "200 " > "$ABCDETEMPDIR/cddbquery"
4999 cat "$ABCDETEMPDIR/cddbquery.1" >> "$ABCDETEMPDIR/cddbquery"
5001 echo "Retrieved $NUM_CDDB_MATCHES matches..." >> "$ABCDETEMPDIR/cddbchoices"
5002 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
5003 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5005 cat "$ABCDETEMPDIR/cddbquery.$X" >> "$ABCDETEMPDIR/cddbquery"
5007 echo "." >> "$ABCDETEMPDIR/cddbquery"
5010 for X in $(f_seq_row 1 $NUM_CDDB_MATCHES)
5012 ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.$X" | cut -c8- | tr -d \\r\\n)
5013 SOURCE=$(cat ${ABCDETEMPDIR}/datasource.$X)
5014 echo "#$X ($SOURCE): ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
5015 for TRACK in $(f_seq_row 1 $TRACKS)
5017 echo $TRACK: "$(grep -a ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
5019 echo >> "$ABCDETEMPDIR/cddbchoices"
5026 eval "$($CDDBTOOL parse "$CDDBDATA")"
5029 # Before reading tracks, we set the speed of the device
5031 if [ X"$CDSPEEDVALUE" != "X" ]; then
5032 case "$CDROMREADERSYNTAX" in
5033 cdparanoia|libcdio|debug) ;;
5040 # Define the first and last track, since we might need them later in several places
5041 FIRSTTRACK=$( get_first $TRACKQUEUE )
5042 LASTTRACK=$( get_last $TRACKQUEUE )
5044 if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
5045 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
5046 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
5047 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
5050 if checkstatus onetrack ; then ONETRACK=y ; fi
5052 if [ "$ONETRACK" = "y" ]; then
5053 # Reuse the CUEFILE in case we created it (now or in a previous run)
5054 if CUEFILE=$(checkstatus cuefile); then
5059 # Create playlist if needed (backgroundable) and start reading in tracks
5063 if [ ! "$ONETRACK" = "y" ]; then
5064 if [ "$DOPLAYLIST" = "y" ]; then
5065 echo Creating playlist... >&2
5070 if [ "$GETALBUMART" = "y" ]; then
5074 # For the lowdisk option, only one program is running at once so the encoder
5075 # can be unsilenced right away.
5076 if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
5077 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
5080 if [ "$ONETRACK" = "y" ]; then
5081 TRACKS="$FIRSTTRACK"
5082 if [ "$USEPIPES" = "y" ]; then
5083 if checkstatus readencodetrack-$FIRSTTRACK; then :; else
5084 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
5087 if checkstatus readtrack-$FIRSTTRACK; then :; else
5088 do_cdread onetrack $FIRSTTRACK $LASTTRACK
5092 for UTRACKNUM in $TRACKQUEUE
5094 if [ "$DOREAD" = "y" ]; then
5095 if [ "$USEPIPES" = "y" ]; then
5096 if checkstatus readencodetrack-$UTRACKNUM; then :; else
5097 # Read, pipe, shut up!
5098 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
5101 if checkstatus readtrack-$UTRACKNUM; then :; else
5102 do_cdread $UTRACKNUM
5104 if [ "$?" != "0" ]; then
5105 # CD read failed - don't give the goahead to
5112 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
5115 # If we are not reading, set the encode output to loud already, so
5116 # that we can see the output of the first track.
5117 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
5118 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
5120 echo NEXTTRACK # Get the encoder machine churning again
5121 if [ "$DOREAD" = "y" ]; then
5122 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
5123 until checkstatus encodetrack-$UTRACKNUM
5125 if checkerrors encodetrack-$UTRACKNUM; then
5136 # Now that we're done the encoding can be loud again -
5137 # if we're not using SMP.
5138 if [ "$MAXPROCS" = "1" ]; then
5139 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
5142 # All tracks read, start encoding.
5143 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
5147 # Execute the user-defined post_read function before ejecting CD
5150 # We are now finished with the cdrom - it can be safely ejected. Note that
5151 # abcde will not have completed yet.
5152 if [ "$EJECTCD" = "y" ]; then
5153 # We check if the disk we are processing is actually the disk inside the
5154 # CD tray. If not, we do not eject the CD, since it might be so that the
5155 # user ejected it manually.
5156 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
5157 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$CDDBTRACKINFO" ] ; then
5158 # More FreeBSD bits.
5159 if [ X"$(uname)" = X"FreeBSD" ] ; then
5160 # FreeBSD eject uses the EJECT environment variable to name the CDROM
5161 # but in this script EJECT is in the envionment and names the program
5164 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
5165 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
5166 $eject $EJECTOPTS $cd
5167 elif [ X"$(uname)" = X"Darwin" ] ; then
5168 diskutil eject ${CDROM#/dev/} 0
5169 elif [ -x $(which $EJECT) ]; then
5170 $EJECT $EJECTOPTS "$CDROM"
5177 ## Do we need to pre-process
5178 #if [ x"$PREPROCESS" = "x" ] ; then
5181 # for PRETRACKNUM in $TRACKQUEUE
5184 # if [ "$GOAHEAD" = "NO" ]; then break; fi
5186 # until [ $PREPROCEED ]
5188 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
5189 # # all locations are working, wait and try again later
5190 # if [ ! $PREPROCEED ]; then sleep 3; fi
5192 # ( do_preprocess $PRETRACKNUM
5200 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
5202 if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
5203 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5204 if [ "$GOAHEAD" != "NO" ]; then
5205 for LASTTRACK in $TRACKQUEUE; do :; done
5206 if checkstatus readtrack-$LASTTRACK; then
5207 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
5208 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
5209 if checkerrors batch-normalize; then exit 1; fi
5211 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
5212 if [ "$DONORMALIZE" = "y" ]; then
5213 for UTRACKNUM in $TRACKQUEUE
5215 if checkstatus readtrack-$UTRACKNUM; then
5216 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5220 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
5221 if checkerrors nogap-encode; then exit 1; fi
5227 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
5228 if [ "$ONETRACK" = "y" ] ; then
5229 TRACKQUEUE="$FIRSTTRACK"
5230 TRACKS="$FIRSTTRACK"
5233 # Do the encoding, including parallelization of remote encoding
5234 # Figure out where each track is going to be encoded
5235 ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
5236 if [ "$MAXPROCS" != "0" ]; then
5237 for NUM in $(f_seq_row 1 "$MAXPROCS")
5239 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
5243 ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
5244 for UTRACKNUM in $TRACKQUEUE
5247 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
5248 if [ "$GOAHEAD" = "NO" ]; then break; fi
5249 # find out where this track is to be encoded
5250 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5251 # Make sure we have a place to encode this, if not, exit stage right
5252 if [ -z "$ENCODELOCATIONS" ]; then
5258 for LOCATION in $ENCODELOCATIONS
5260 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5261 # check first if a track has ever been assigned to this location
5262 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
5263 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
5264 if checkerrors encodetrack-$PREVIOUSTRACK; then
5265 for TEMPLOCATION in $ENCODELOCATIONS
5267 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
5268 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
5271 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
5276 # We're still here, this location must have been previously assigned,
5277 # and last completed without error - check if it's done with the
5278 # previous track yet
5279 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
5281 # all locations are working, wait and try again later
5282 if [ ! $PROCEED ]; then sleep 3; fi
5284 # Record the location we're about to encode the next track at
5285 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
5287 # Don't proceed with the rest of the loop if we can't encode
5288 if [ "$ABORT" ]; then continue; fi
5289 ## FIXME ## Add here
5290 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
5291 # Set TRACKNUM, TRACKNAME
5292 if [ -e "$CDDBDATA" ]; then
5293 if [ "$ONETRACK" = "y" ]; then
5295 TRACKNUM="$FIRSTTRACK"
5299 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
5300 getcddbinfo TRACKNAME
5304 # You can't encode a file which needs to be normalized before finishing
5305 # You can't tag a file before it's finished encoding -
5306 # thus all of this is backgrounded together
5308 if [ "$DONORMALIZE" = "y" ]; then
5309 if checkstatus readtrack-$UTRACKNUM; then
5310 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
5313 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
5314 if checkstatus readtrack-$UTRACKNUM; then
5315 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
5316 if [ "$DONORMALIZE" = "y" ]; then
5317 if checkstatus normalizetrack-$UTRACKNUM; then
5318 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5321 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
5325 if [ "$DOTAG" = "y" ]; then
5326 if checkstatus encodetrack-$UTRACKNUM; then
5327 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
5329 # Lets tag the cue file
5330 if checkstatus cleancuefile >/dev/null; then :; else
5331 if checkstatus cuefile >/dev/null ; then
5336 if [ "$DOMOVE" = "y" ]; then
5337 if checkstatus tagtrack-$UTRACKNUM; then
5338 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
5345 # Go through it again and make sure there's no distmp3 stragglers, otherwise
5346 # we'll delete the files they're working on
5347 # Do NOT play ball if there is no ball to play (so ABORT if needed)
5348 ## FIXME ## Check also for files which are encoded using PIPEs.
5349 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
5354 for LOCATION in $ENCODELOCATIONS
5356 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
5357 # "How can he give us a status update, if he's DEAD?"
5358 if checkstatus encodetrack-$CHECKTRACK; then
5361 # Nothing to see here please go quietly back to your homes
5362 if [ -z "$CHECKTRACK" ]; then continue; fi
5363 # You're still here? Maybe there is something...
5364 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
5367 if [ ! $PROCEED ]; then sleep 5; fi
5370 # If the above didn't catch the stragglers, this will
5372 if [ "$DOREPLAYGAIN" = "y" ]; then
5376 if [ "$EMBEDALBUMART" = "y" ]; then
5380 # Execute the user-defined post_encode function before cleaning up
5383 # Check to see if run_command logged any errors
5384 if [ -f "$ABCDETEMPDIR/errors" ]; then
5385 log error "The following commands failed to run:"
5386 cat "$ABCDETEMPDIR/errors"
5390 if [ "$KEEPWAVS" = "y" ];then
5394 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
5395 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
5396 ENCODED_FORMATS=$(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
5397 MOVED_FORMATS=$(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
5398 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
5399 log warning "The encoded formats does not match with the moved ones"
5400 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
5401 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
5402 log warning "Use \"abcde -a clean -f -C $CDDBDISCID\" to force the removal of the remaining data."
5406 if [ "$DOCLEAN" = "y" ]; then
5407 # Wipe all the evidence
5408 # Gimme gimme gimme some more time!
5410 rm -rf "$ABCDETEMPDIR"
5413 echo "Finished. Not cleaning $ABCDETEMPDIR."