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 # This code is hereby licensed for public consumption under either the
7 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
9 # You should have received a copy of the GNU General Public License along
10 # with this program; if not, write to the Free Software Foundation, Inc.,
11 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13 # Copyright for this work is to expire January 1, 2010, after which it
14 # shall be public domain.
18 VERSION
='2.5.4-UNRELEASED'
22 echo "This is abcde v$VERSION."
23 echo "Usage: abcde [options] [tracks]"
25 echo "-1 Encode the whole CD in a single file"
26 echo "-a <action1[,action2]...>"
27 echo " Actions to perform:"
28 echo " cddb,read,normalize,encode,tag,move,replaygain,playlist,clean"
29 #echo "-A Experimental actions (retag, transcode)"
30 echo "-b Enable batch normalization"
31 #echo "-B Disable batch replaygain (do file by file)"
33 echo " Specify a configuration file (overrides system and user config files)"
35 echo " Specify discid to resume from (only needed if you no longer have the cd)"
37 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
38 echo "-D Debugging mode (equivalent to sh -x abcde)"
39 echo "-e Erase encoded track information from status file"
40 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
41 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
42 echo "-h This help information"
43 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
44 echo "-j <#> Number of encoder processes to run at once (localhost)"
45 echo "-k Keep the wav tracks for later use"
46 echo "-l Use low disk space algorithm"
47 echo "-L Use local CDDB storage directory"
48 echo "-m Modify playlist to include CRLF endings, to comply with some players"
49 #echo " WARNING: Deprecated. Use \"cue\" action"
50 #echo "-M Create a CUE file"
51 echo "-n No lookup. Don't query CDDB, just create and use template"
52 echo "-N Noninteractive. Never prompt for anything"
53 echo "-o <type1[,type2]...>"
54 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
55 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
56 echo "-P Use UNIX pipes to read+encode without wav files"
58 echo " Set quality level (high,medium,low)"
59 echo "-r <host1[,host2]...>"
60 echo " Also encode on these remote hosts"
62 echo " Show fields from the CDDB info (year,genre)"
63 echo "-S <#> Set the CD speed"
64 echo "-t <#> Start the track numbering at a given number"
65 echo "-T <#> Same as -t but modifies tag numbering"
66 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
67 echo "-v Show version number and exit"
68 echo "-V Be a bit more verbose about what is happening behind the scenes"
69 echo "-x Eject CD after all tracks are read"
71 echo " Add a comment to the CD tracks"
72 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
73 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
75 echo "Tracks is a space-delimited list of tracks to grab."
76 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
78 #echo "Double hyphens are used to concatenate tracks"
83 echo "$@" >> "$ABCDETEMPDIR/status"
86 # log [level] [message]
88 # log outputs the right message in a common format
94 error
) echo "[ERROR] abcde: $@" >&2 ;;
95 warning
) echo "[WARNING] $@" >&2 ;;
96 info
) echo "[INFO] $@" ;;
100 # Functions to replace the need of seq, which is too distribution dependent.
104 while [ $i -ne `expr $2 + 1` ]
114 if echo $i |
grep "[[:digit:]]" > /dev
/null
2>&1 ; then
115 while [ $i -ne `expr $2 + 1` ]
122 log error
"syntax error while processing track numbers ($i)"
127 # Functions to replace the need of awk {print $1} and {print $NF}
130 if [ X
"$1" = "X" ]; then
131 for first
in `cat`; do
142 if [ X
"$1" = "X" ]; then
143 for stdin
in `cat`; do
147 for last
in $@
; do :; done
152 # checkstatus [blurb]
153 # Returns "0" if the blurb was found, returns 1 if it wasn't
154 # Puts the blurb content, if available, on stdout.
155 # Otherwise, returns "".
158 # Take the last line in the status file if there's multiple matches
160 BLURB
=$
(grep -E $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
162 if [ -z "$BLURB" ]; then
167 # See if there's a = in it
168 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
169 echo "$(echo $BLURB | cut -f2- -d=)"
175 # checkwarnings [blurb]
176 # Returns "0" if the blurb was found (meaning there was an warning),
177 # returns 1 if it wasn't (yes this is a little backwards).
178 # Does not print the blurb on stdout.
179 # Otherwise, returns "".
182 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
185 # Take the last line in the status file if there's multiple matches
187 BLURB
="$(grep -E $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
189 if [ -z "$BLURB" ]; then
190 # negative, we did not have a negative...
193 # affirmative, we had a negative...
198 # checkerrors [blurb]
199 # Returns "0" if the blurb was found (meaning there was an error),
200 # returns 1 if it wasn't (yes this is a little backwards).
201 # Does not print the blurb on stdout.
202 # Otherwise, returns "".
205 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
208 # Take the last line in the status file if there's multiple matches
210 BLURB
="$(grep -E $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
212 if [ -z "$BLURB" ]; then
213 # negative, we did not have a negative...
216 # affirmative, we had a negative...
222 # Finds the right pager in the system to display a file
226 # Use the debian sensible-pager wrapper to pick the pager
227 # user has requested via their $PAGER environment variable
228 if [ -x "/usr/bin/sensible-pager" ]; then
229 /usr
/bin
/sensible-pager
"$PAGEFILE"
230 elif [ -x "$PAGER" ]; then
231 # That failed, try to load the preferred editor, starting
232 # with their PAGER variable
234 # If that fails, check for less
235 elif [ -x /usr
/bin
/less ]; then
236 /usr
/bin
/less -f "$PAGEFILE"
237 # more should be on all UNIX systems
238 elif [ -x /bin
/more ]; then
239 /bin
/more "$PAGEFILE"
241 # No bananas, just cat the thing
246 # run_command [blurb] [command...]
247 # Runs a command, silently if necessary, and updates the status file
253 # See if this is supposed to be silent
254 if [ "$(checkstatus encode-output)" = "loud" ]; then
258 # Special case for SMP, since
259 # encoder output is never displayed, don't mute echos
260 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
269 normalize|normalize-audio
)
270 if [ "$RETURN" = "2" ]; then
271 # File was already normalized.
276 if [ "$RETURN" != "0" ]; then
277 # Put an error in the errors file. For various reasons we
278 # can't capture a copy of the program's output but we can
279 # log what we attempted to execute and the error code
280 # returned by the program.
281 if [ "$BLURB" ]; then
284 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
285 return $RETURN # Do not pass go, do not update the status file
287 if [ "$BLURB" ]; then
288 echo $BLURB >> "$ABCDETEMPDIR/status"
292 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
293 # distributed under the terms of the GNU GPL v2 or later, at your option
295 # Function to determine if a word contains a slash.
304 # Function to give the relative path from one file to another.
305 # Usage: relpath fromfile tofile
306 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
307 # (the result would be Album/Song.mp3)
308 # Output is relative path to $2 from $1 on stdout
310 # This code has the following restrictions:
311 # Multiple ////s are not collapsed into single /s, with strange effects.
312 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
313 # If FR is a directory it must have a trailing /
321 /*) ;; # No processing is needed for absolute paths
323 # Loop through common prefixes, ignoring them.
324 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
326 FR
="$(echo "$FR" | cut -d/ -f2-)"
327 TO
="$(echo "$TO" | cut -d/ -f2-)"
329 # Loop through directory portions left in FR, adding appropriate ../s.
332 FR
="$(echo "$FR" | cut -d/ -f2-)"
343 if [ ! "$@" = "" ]; then
344 # Cut off any command-line option we added in
345 X
=$
(echo $@ | cut
-d' ' -f2)
346 if [ "$(which $X)" = "" ]; then
348 elif [ ! -x $
(which $X) ]; then
357 if [ ! "$@" = "" ]; then
358 # Cut off any command-line option we added in
359 X
=$
(echo $@ | cut
-d' ' -f2)
360 # Test for built-in abcde.function
361 [ "$X" != "${X#abcde.}" ] && type $X >/dev
/null
2>&1 && return
362 if [ "$(which $X)" = "" ]; then
363 log error
"$X is not in your path." >&2
364 log info
"Define the full path to the executable if it exists on your system." >&2
365 if [ -e /etc
/debian_release
] ; then
367 oggenc
) MISSING_PACKAGE
=vorbis-tools
;;
368 lame|flac
) MISSING_PACKAGE
=$X ;;
370 log info
"Hint: apt-get install $MISSING_PACKAGE" >&2
373 elif [ ! -x "$(which $X)" ]; then
374 log error
"$X is not executable." >&2
380 # diffentries <filename> <max_value> <entry1>,<entry2>
381 # max_value: the range of entries goes from 1 to <max_value>
386 local CDDBDIFFCHOICES
=$1
388 local CDDBDIFFCHOICE
="$@"
389 if [ ! X
"$DIFF" = "X" ]; then
390 PARSECHOICE1
=$
(echo $CDDBDIFFCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
391 PARSECHOICE2
=$
(echo $CDDBDIFFCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
392 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
393 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
394 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
395 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
397 # We parse the 2 choices to diff, store them in temporary files and diff them.
398 for PARSECHOICE
in $
(echo $CDDBDIFFCHOICE |
tr , \
); do
399 do_cddbparse
"$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
401 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
402 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
403 if [ $
(cat "$ABCDETEMPDIR/$FILENAME.diff" |
wc -l) -ge 24 ]; then
404 page
"$ABCDETEMPDIR/$FILENAME.diff"
406 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
410 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
415 # Finds an specific field from cddbinfo
420 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
423 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
426 grep ^EXTT
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2- -d= |
tr -d \
[:cntrl
:\
] |
sed 's/\\n/\n/g'
432 # Get the track number we are going to use for different actions
435 if [ -n "$STARTTRACKNUMBER" ] ; then
436 # Get the trackpadding from the current track
437 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
438 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
440 TRACKNUM
=${UTRACKNUM}
446 # Calculate cddb disc ids without requiring specialized helper programs.
447 # largely copied from cd-discid and musicbrainz examples. some of the steps
448 # don't make sense, but they're necessary to match the ids generated by other
451 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
452 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
453 # 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
454 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
455 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
456 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
458 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
461 if [ X
"$LEADOUT" = "X" ]; then
462 log warning
"Error trying to calculate disc ids without lead-out information."
466 # default to a two second lead-in
468 LEADIN
=${LEADIN:=150}
470 # number of cdframes per second
473 # reset cddb checksum for cddb disc-id calululation
477 for OFFSET
in $
(echo $OFFSETS)
479 COOKEDOFFSETS
="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
481 OFFSETTIME
=$
(( ($OFFSET + $LEADIN) / $CDFRAMES ))
482 while [ $OFFSETTIME -gt 0 ]; do
483 CDDBCKSUM
=$
(($CDDBCKSUM + $OFFSETTIME % 10))
484 OFFSETTIME
=$
(($OFFSETTIME / 10))
489 COOKEDOFFSETS
="${COOKEDOFFSETS:1}" # eat the leading space
491 PREGAP
=$
(($
(echo $OFFSETS | cut
-f1 -d' ')))
492 TOTALTIME
=$
(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
494 case "$CDDBMETHOD" in
496 printf -v DISCID
"%08lx" $
(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
499 # FIXME: don't assume the first track is 1
500 echo "dasd: 1 $TRACKS $LEADIN $LEADOUT $OFFSETS "
501 DISCID=$($MUSICBRAINZ --command calcid --discinfo 1 $TRACKS $LEADIN $LEADOUT $OFFSETS)
505 TRACKINFO="${DISCID} $((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=$FLACOUTPUTCONTAINER
527 for UTRACKNUM in $TRACKQUEUE
529 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
530 getcddbinfo TRACKNAME
532 TRACKFILE="$(mungefilename "$TRACKNAME")"
533 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
534 ALBUMFILE="$(mungefilename "$DALBUM")"
535 GENRE="$(mungegenre "$GENRE")"
536 YEAR=${CDYEAR:-$CDYEAR}
538 if [ "$ONETRACK" = "y" ]; then
539 if [ "$VARIOUSARTISTS" = "y" ]; then
540 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
542 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
545 if [ "$VARIOUSARTISTS" = "y" ]; then
546 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
548 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
551 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
552 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
556 run_command replaygain-flac nice $ENCNICE $METAFLAC $FLACGAINOPTS "${OUTPUTFILES[@]}"
557 #run_command replaygain-flac true
560 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN $VORBISGAINOPTS "${OUTPUTFILES[@]}"
563 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN $MP3GAINOPTS "${OUTPUTFILES[@]}"
566 run_command replaygain-mpc nice $ENCNICE $MPPGAIN --auto "${OUTPUTFILES[@]}"
571 if checkerrors "replaygain-.{3,6}"; then :; else
572 run_command replaygain true
577 # This code splits the a Various Artist track name from one of the following
580 # forward: Artist / Track
581 # forward-dash: Artist - Track
582 # reverse: Track / Artist
583 # reverse-dash: Track - Artist
584 # colon: Artist: Track
585 # trailing-paren: Artist (Track)
588 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
591 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
592 case "$VARIOUSARTISTSTYLE" in
594 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
595 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
596 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
599 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
600 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
601 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
604 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
605 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
606 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
609 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
610 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
611 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
614 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
615 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
616 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
619 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
620 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
621 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
624 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
625 TRACKARTIST="Various"
627 TRACKARTIST="$DARTIST"
632 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
636 "classic rock") id=1 ;;
654 "industrial") id=19 ;;
655 "alternative") id=20 ;;
657 "death metal") id=22 ;;
659 "soundtrack") id=24 ;;
660 "euro-techno") id
=25 ;;
664 "jazz+funk") id
=29 ;;
667 "classical") id
=32 ;;
668 "instrumental") id
=33 ;;
672 "sound clip") id
=37 ;;
675 "alt. rock") id
=40 ;;
680 "meditative") id
=45 ;;
681 "instrum. pop") id
=46 ;;
682 "instrum. rock") id
=47 ;;
686 "techno-indust.") id
=51 ;;
687 "electronic") id
=52 ;;
689 "eurodance") id
=54 ;;
691 "southern rock") id
=56 ;;
696 "christian rap") id
=61 ;;
697 "pop/funk"|
"pop / funk") id
=62 ;;
699 "native american") id
=64 ;;
702 "psychadelic") id
=67 ;;
704 "showtunes") id
=69 ;;
708 "acid punk") id
=73 ;;
709 "acid jazz") id
=74 ;;
713 "rock & roll") id
=78 ;;
714 "hard rock") id
=79 ;;
716 "folk/rock") id
=81 ;;
717 "national folk") id
=82 ;;
724 "bluegrass") id
=89 ;;
725 "avantgarde") id
=90 ;;
726 "gothic rock") id
=91 ;;
727 "progress. rock") id
=92 ;;
728 "psychadel. rock") id
=93 ;;
729 "symphonic rock") id
=94 ;;
730 "slow rock") id
=95 ;;
733 "easy listening") id
=98 ;;
739 "chamber music") id
=104 ;;
741 "symphony") id
=106 ;;
742 "booty bass") id
=107 ;;
744 "porn groove") id
=109 ;;
746 "slow jam") id
=111 ;;
750 "folklore") id
=115 ;;
752 "power ballad") id
=117 ;;
753 "rhythmic soul") id
=118 ;;
754 "freestyle") id
=119 ;;
756 "punk rock") id
=121 ;;
757 "drum solo") id
=122 ;;
758 "a capella") id
=123 ;;
759 "euro-house") id
=124 ;;
760 "dance hall") id
=125 ;;
762 "drum & bass") id
=127 ;;
763 "club-house") id
=128 ;;
764 "hardcore") id
=129 ;;
768 "negerpunk") id
=133 ;;
769 "polsk punk") id
=134 ;;
771 "christian gangsta rap") id
=136 ;;
772 "heavy metal") id
=137 ;;
773 "black metal") id
=138 ;;
774 "crossover") id
=139 ;;
775 "contemporary christian")id
=140 ;;
776 "christian rock") id
=141 ;;
777 "merengue") id
=142 ;;
779 "thrash metal") id
=144 ;;
782 "synthpop") id
=147 ;;
783 "rock/pop"|
"rock / pop") id
=148 ;;
790 # do_tag [tracknumber]
791 # id3 tags a filename
793 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC, ATOMICPARSLEY
794 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE
797 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
798 if [ -z "$COMMENTOUTPUT" ]; then
799 COMMENTOUTPUT
="$(getcddbinfo TRACK-INFO)"
801 if [ "$CDDBMETHOD" = "cddb" ]; then
802 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
804 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
805 # If we want to start the tracks with a given number, we need to modify the
806 # TRACKNUM value before evaluation
807 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
810 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
814 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
815 GENREID
=$
(do_getgenreid
"${CDGENRE}")
816 # Set TPE2 in case we have a Various Artists rip.
818 if [ "$VARIOUSARTISTS" = "y" ]; then
825 # FIXME # track numbers in mp3 come with 1/10, so we cannot
826 # happily substitute them with $TRACKNUM
827 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $TAGGER $TAGGEROPTS \
828 --comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
829 -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
830 -G "$GENREID" -n "${TRACKNUM:-$1}" \
831 ${TRACKNUM:+-N "$TRACKS"} \
832 ${ENCODING:+--set-encoding="$ENCODING"} \
833 ${TPE2:+--set-text-frame=TPE2:"$TPE2"} \
834 "$ABCDETEMPDIR/track$1.$OUTPUT"
836 # FIXME # Still not activated...
838 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE \
839 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
840 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" \
841 -y "$CDYEAR" -g "$GENREID" -k "${TRACKNUM:-$1}" \
842 "$ABCDETEMPDIR/track$1.$OUTPUT"
845 # FIXME # track numbers in mp3 come with 1/10, so we cannot
846 # happily substitute them with $TRACKNUM
847 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE \
848 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
849 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
850 -y "$CDYEAR" -g "$GENREID" \
851 -T "${TRACKNUM:-$1}/$TRACKS" \
852 ${TPE2:+--TPE2 "$TPE2"} \
853 "$ABCDETEMPDIR/track$1.$OUTPUT"
858 case "$OGGENCODERSYNTAX" in
860 # vorbiscomment can't do in-place modification, mv the file first
861 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
862 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
866 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
868 echo ARTIST
="$TRACKARTIST"
870 echo TITLE
="$TRACKNAME"
871 if [ -n "$CDYEAR" ]; then
874 if [ -n "$CDGENRE" ]; then
875 echo GENRE
="$CDGENRE"
877 echo TRACKNUMBER
=${TRACKNUM:-$1}
878 if [ -n "$DISCNUMBER" ]; then
879 echo DISCNUMBER
="$DISCNUMBER"
881 echo CDDB
=$CDDBDISCID
882 if [ "$(eval echo ${COMMENT})" != "" ]; then
883 case "$COMMENTOUTPUT" in
884 *=*) echo "$COMMENTOUTPUT";;
885 *) echo COMMENT
="$COMMENTOUTPUT";;
888 ) | run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE \
889 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
890 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
891 # Doublecheck that the commented file was created
892 # successfully before wiping the original
893 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
894 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
896 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
903 echo ARTIST
="$TRACKARTIST"
905 echo TITLE
="$TRACKNAME"
906 if [ -n "$CDYEAR" ]; then
909 if [ -n "$CDGENRE" ]; then
910 echo GENRE
="$CDGENRE"
912 echo TRACKNUMBER
="${TRACKNUM:-$1}"
913 if [ -n "$DISCNUMBER" ]; then
914 echo DISCNUMBER
="$DISCNUMBER"
916 echo CDDB
="$CDDBDISCID"
917 if [ "$(eval echo ${COMMENT})" != "" ]; then
918 case "$COMMENTOUTPUT" in
919 *=*) echo "$COMMENTOUTPUT";;
920 *) echo COMMENT
="$COMMENTOUTPUT";;
923 ) | run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
926 run_command tagtrack-
$OUTPUT-$1 true
929 run_command tagtrack-
$OUTPUT-$1 true
932 # Use a temp-file of our choice. --overWrite seems to
933 # case core dumps with AtomicParsley 0.9.0
934 ATOMICTEMPFILE
="$ABCDETEMPDIR/track$1.m4a-atomic"
937 if [ "$VARIOUSARTISTS" = "y" ]; then
941 #It has to be command file opts for AtomicParsley
942 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $ATOMICPARSLEY "$ABCDETEMPDIR/track$1.m4a" --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --tracknum ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --compilation $VARIOUSBOOL --comment "$COMMENTOUTPUT" --output $ATOMICTEMPFILE
943 if [ -f $ATOMICTEMPFILE ]; then
944 mv "$ATOMICTEMPFILE" "$ABCDETEMPDIR/track$1.m4a"
948 run_command tagtrack-
$OUTPUT-$1 true
952 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
953 run_command tagtrack-
$1 true
960 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
963 # The commands here don't go through run_command because they're never
964 # supposed to be silenced
965 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
966 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
970 case "$MP3ENCODERSYNTAX" in
975 for UTRACKNUM
in $TRACKQUEUE
977 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
979 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
981 if [ "$RETURN" != "0" ]; then
982 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
984 for UTRACKNUM
in $TRACKQUEUE
986 run_command encodetrack-
$OUTPUT-$UTRACKNUM true
987 #run_command encodetrack-$UTRACKNUM true
996 if checkerrors
"nogap-encode"; then :; else
997 if [ ! "$KEEPWAVS" = "y" ] ; then
998 if [ ! "$KEEPWAVS" = "move" ] ; then
1003 # Other encoders fall through to normal encoding as the tracks have not
1004 # been entered in the status file.
1007 # do_encode [tracknumber] [hostname]
1008 # If no hostname is specified, encode locally
1010 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1013 if [ "$USEPIPES" = "y" ]; then
1016 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
1019 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
1022 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
1025 TEMPARG
="PIPE_$SPEEXENCODER"
1028 TEMPARG
="PIPE_$MPPENCODER"
1031 TEMPARG
="PIPE_$AACENCODERSYNTAX"
1034 IN
="$( eval echo "\$
$TEMPARG" )"
1036 IN
="$ABCDETEMPDIR/track$1.wav"
1039 case "$MP3ENCODERSYNTAX" in
1040 # FIXME # check if mp3enc needs -if for pipes
1041 # FIXME # I have not been able to find a working mp3enc binary
1055 # We need IN to proceed, if we are not using pipes.
1056 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
1057 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1059 case "$TMPOUTPUT" in
1061 OUTPUT
=$OGGOUTPUTCONTAINER
1064 OUTPUT
=$FLACOUTPUTCONTAINER
1070 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
1071 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-
$OUTPUT-$1 ; then
1074 if [ X
"$USEPIPES" = "Xy" ]; then
1076 # We need a way to store the creation of the files when using PIPES
1077 RUN_COMMAND_PIPES
="run_command encodetrack-$OUTPUT-$1 true"
1078 # When pipping it does not make sense to have a higher nice for
1079 # reading than for encoding, since it will be hold by the
1080 # encoding process. Setting an effective nice, to calm down a
1081 # bit the reading process.
1082 EFFECTIVE_NICE
=$READNICE
1084 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1085 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
1086 EFFECTIVE_NICE
=$ENCNICE
1092 case "$MP3ENCODERSYNTAX" in
1093 lame|toolame|gogo
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1094 bladeenc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1095 l3enc|xingmp3enc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1096 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1097 mp3enc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1101 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
1108 case "$OGGENCODERSYNTAX" in
1109 vorbize
) $RUN_COMMAND nice
$EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1110 oggenc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1114 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
1121 case "$FLACENCODERSYNTAX" in
1122 flac
) $RUN_COMMAND nice
$EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1127 vecho
"$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1128 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
1133 if [ "$(eval echo ${COMMENT})" != "" ]; then
1136 *) COMMENT
="COMMENT=$COMMENT" ;;
1139 # Tag the file at encode time, as it can't be done after encoding.
1140 if [ "$DOTAG" = "y" ]; then
1141 $RUN_COMMAND nice
$EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
1143 $RUN_COMMAND nice
$EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1147 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1149 # I tried compiling the mppenc from corecodecs.org and got some
1150 # errors, so I have not tried it myself.
1151 ## FIXME ## Needs some cleanup to determine if an empty tag sent
1152 ## FIXME ## to the encoder ends up empty.
1153 $RUN_COMMAND nice
$EFFECTIVE_NICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
1156 # Tag the file at encode time, as it can't be done after encoding.
1157 if [ "$DOTAG" = "y" ]; then
1158 $RUN_COMMAND nice
$EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
1161 $RUN_COMMAND nice
$ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1165 # In case of wav output we need nothing. Just keep the wavs.
1170 # Only remove .wav if the encoding succeeded
1171 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
1172 run_command encodetrack-
$1 true
1173 if [ ! "$KEEPWAVS" = "y" ] ; then
1174 if [ ! "$KEEPWAVS" = "move" ] ; then
1180 run_command
"" echo "HEH! The file we were about to encode disappeared:"
1181 run_command
"" echo ">> $IN"
1182 run_command encodetrack-
$1 false
1186 # do_preprocess [tracknumber]
1188 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1191 # IN="$ABCDETEMPDIR/track$1.wav"
1192 # # We need IN to proceed.
1193 # if [ -s "$IN" ] ; then
1194 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1196 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1197 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1198 # case "$POSTPROCESSFORMAT" in
1200 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1202 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1204 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1206 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1208 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1211 # # Only remove .wav if the encoding succeeded
1212 # if checkerrors "preprocess-(.{3,4})-$1"; then
1213 # run_command preprocess-$1 false
1215 # run_command preprocess-$1 true
1218 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1219 # echo "HEH! The file we were about to pre-process disappeared:"
1222 # run_command preprocess-$1 false
1227 # do_postprocess [tracknumber]
1229 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1232 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1234 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1235 # # We need IN to proceed.
1236 # if [ -s "$IN" ] ; then
1237 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1238 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1239 # case "$POSTPROCESSFORMAT" in
1241 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1243 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1245 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1247 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1249 # # Only remove .wav if the encoding succeeded
1250 # if checkerrors "postprocess-(.{3,4})-$1"; then
1251 # run_command postprocess-$1 false
1253 # run_command postprocess-$1 true
1256 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1257 # echo "HEH! The file we were about to post-process disappeared:"
1260 # run_command postprocess-$1 false
1275 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1279 # The commands here don't go through run_command because they're never supposed to be silenced
1280 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1285 for UTRACKNUM
in $TRACKQUEUE
1287 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1289 # FIXME # Hard-coded batch option!
1290 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1292 if [ "$RETURN" != "0" ]; then
1293 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1295 for UTRACKNUM
in $TRACKQUEUE
1297 echo normalizetrack-
$UTRACKNUM >> status
1303 # do_batch_normalize
1305 # NORMALIZER, NORMALIZEROPTS
1306 do_batch_normalize
()
1308 # The commands here don't go through run_command because they're never supposed to be silenced
1309 echo "Batch normalizing tracks: $TRACKQUEUE"
1314 for UTRACKNUM
in $TRACKQUEUE
1316 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1318 # XXX: Hard-coded batch option!
1319 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1321 if [ "$RETURN" != "0" ]; then
1322 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1324 for UTRACKNUM
in $TRACKQUEUE
1326 echo normalizetrack-
$UTRACKNUM >> status
1332 # do_normalize [tracknumber]
1334 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1337 IN
="$ABCDETEMPDIR/track$1.wav"
1338 if [ -e "$IN" ] ; then
1339 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1340 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1342 if [ "$(checkstatus encode-output)" = "loud" ]; then
1343 echo "HEH! The file we were about to normalize disappeared:"
1346 run_command normalizetrack-
$1 false
"File $IN was not found"
1350 # do_move [tracknumber]
1351 # Deduces the outfile from environment variables
1352 # Creates directory if necessary
1354 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1357 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1359 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1360 # defined the OUTPUTFILE:
1363 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1364 # Munge filenames as follows:
1369 # Eat control characters
1370 ALBUMFILE
="$(mungefilename "$DALBUM")"
1371 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1372 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1373 GENRE
="$(mungegenre "$GENRE")"
1374 YEAR
=${CDYEAR:-$CDYEAR}
1375 # If we want to start the tracks with a given number, we need to modify
1376 # the TRACKNUM value before evaluation
1378 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1379 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1380 if [ "$ONETRACK" = "y" ]; then
1381 if [ "$VARIOUSARTISTS" = "y" ]; then
1382 OUTPUTFILE
="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1384 OUTPUTFILE
="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1387 if [ "$VARIOUSARTISTS" = "y" ]; then
1388 OUTPUTFILE
="$(eval echo \""$VAOUTPUTFORMAT"\")"
1390 OUTPUTFILE
="$(eval echo \""$OUTPUTFORMAT"\")"
1393 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1394 # Once we know the specific output was successful, we can change
1395 # the OUTPUT to the value containing the container
1398 OUTPUT
=$OGGOUTPUTCONTAINER
1401 OUTPUT
=$FLACOUTPUTCONTAINER
1407 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1408 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1411 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1412 # FIXME # introduce warnings?
1415 # mkdir -p shouldn't return an error if the directory already exists
1416 mkdir
-p "$OUTPUTFILEDIR"
1417 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1418 if checkstatus movetrack-output-
$OUTPUT; then :; else
1419 run_command movetrack-output-
$OUTPUT true
1424 # mkdir -p shouldn't return an error if the directory already exists
1425 mkdir
-p "$OUTPUTFILEDIR"
1426 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1427 if checkstatus movetrack-output-
$OUTPUT; then :; else
1428 run_command movetrack-output-
$OUTPUT true
1432 # Lets move the cue file
1433 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1434 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1435 if checkstatus movecue-
$OUTPUT; then :; else
1436 # Silence the Copying output since it overlaps with encoding processes...
1437 #run_command '' vecho "Copying cue file to its destination directory..."
1438 if checkstatus onetrack
>/dev
/null
; then
1441 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1442 # We dont have the dir, since it was not created before.
1445 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1448 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1449 # http://brianvictor.tripod.com/mp3cue.htm#details
1450 [a-z0-9
][a-z0-9
][a-z0-9
])
1451 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1454 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1458 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1460 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1469 # Create the playlist if wanted
1471 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1472 # VARIOUSARTISTS, OUTPUTDIR
1475 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1479 OUTPUT
=$OGGOUTPUTCONTAINER
1482 OUTPUT
=$FLACOUTPUTCONTAINER
1488 # Create a playlist file for the playlist data to go into.
1489 # We used to wipe it out if it existed. Now we request permision if interactive.
1490 for LASTTRACK
in $TRACKQUEUE; do :; done
1491 ALBUMFILE
="$(mungefilename "$DALBUM")"
1492 ARTISTFILE
="$(mungefilename "$DARTIST")"
1493 GENRE
="$(mungegenre "$GENRE")"
1494 YEAR
=${CDYEAR:-$CDYEAR}
1495 if [ "$VARIOUSARTISTS" = "y" ] ; then
1496 PLAYLISTFILE
="$(eval echo "$VAPLAYLISTFORMAT")"
1498 PLAYLISTFILE
="$(eval echo "$PLAYLISTFORMAT")"
1500 FINALPLAYLISTDIR
="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1501 mkdir
-p "$FINALPLAYLISTDIR"
1502 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1503 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1504 if [ "$INTERACTIVE" = "y" ]; then
1505 while [ "$DONE" != "y" ]; do
1507 case $ERASEPLAYLIST in
1508 e|E|a|A|k|K
) DONE
=y
;;
1509 "") ERASEPLAYLIST
=e
; DONE
=y
;;
1517 # Once we erase the playlist, we use append to create the new one.
1518 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1520 # The playlist does not exist, so we can safelly use append to create the new list
1523 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1524 touch "$OUTPUTDIR/$PLAYLISTFILE"
1525 for UTRACKNUM
in $TRACKQUEUE
1527 # Shares some code with do_move since the filenames have to match
1528 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1529 getcddbinfo TRACKNAME
1531 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1532 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1533 ALBUMFILE
="$(mungefilename "$DALBUM")"
1534 # If we want to start the tracks with a given number, we need to modify the
1535 # TRACKNUM value before evaluation
1537 if [ "$VARIOUSARTISTS" = "y" ]; then
1538 OUTPUTFILE
="$(eval echo \""$VAOUTPUTFORMAT\"")"
1540 OUTPUTFILE
="$(eval echo \""$OUTPUTFORMAT\"")"
1542 if [ "$VARIOUSARTISTS" = "y" ]; then
1543 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1544 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1546 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1549 if [ "$PLAYLISTDATAPREFIX" ]; then
1550 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1552 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1557 ## this will convert the playlist to have CRLF line-endings, if specified
1558 ## (some hardware players insist on CRLF endings)
1559 if [ "$DOSPLAYLIST" = "y" ]; then
1560 awk '{sub("\r$",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1561 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1562 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1564 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1569 # This function reads a cuefile on stdin and writes an extended
1570 # cddb query on stdout. Any PREGAP for track 1 is properly
1571 # handled, although cue files embedded in FLAC files do not
1572 # appear to properly store the PREGAP setting. :(
1573 abcde.cue2discid
() {
1578 while [ $val -gt 0 ] ; do
1579 ret
=$
(( $ret + ( $val % 10) ))
1580 val
=$
(( $val / 10 ))
1590 local first second third
1591 first
=$
(expr ${1} + 0 )
1592 second
=$
(expr ${2} + 0 )
1593 third
=$
(expr ${3} + 0 )
1595 echo $
(( ((($first * 60) + $second) * 75) + $third ))
1605 while read line
; do
1608 TRACK
) i
=$
(( i
+ 1 ))
1610 INDEX
) if [ "$2" -eq 1 ] ; then
1612 START
=$
(( $LBA + $PREGAP + $OFFSET ))
1614 X
=$
(cddb_sum $
(( $START / 75 )) )
1618 PREGAP
) PREGAP
=$
(msf2lba
$2)
1622 LEADOUT
=$
(( $4 / 588 ))
1625 LEADIN
=$
(( $3 / 588 ))
1634 LEADOUT
=$
(( $LEADOUT + $LEADIN ))
1636 LENGTH
=$
(( $LEADOUT/75 - $TRACK1/75 ))
1637 DISCID
=$
(( ( $N % 255 ) * 2**24 |
$LENGTH * 2**8 |
$TRACKS ))
1638 printf "%08x %i" $DISCID $TRACKS
1641 while [ $j -le $TRACKS ] ; do
1642 eval echo -n "\" \$TRACK$j\""
1645 echo " $(( $LEADOUT / 75 ))"
1649 # abcde.mkcue [--wholedisk]
1650 # This creates a cuefile directly from the extended discid information
1651 # The --wholedisk option controls whether we're ripping data from the
1652 # start of track one or from the start of the disk (usually, but not
1653 # always the same thing!)
1655 # Track one leadin/pregap (if any) handeling:
1656 # --wholedisk specified:
1659 # INDEX 01 <pregap value>
1660 # Remaining track index values unchanged from disc TOC
1662 # --wholedisk not specified
1664 # PREGAP <pregap value>
1666 # Remaining track index values offset by <pregap value>
1673 printf "$1%02i:%02i:%02i\n" $
(($2/4500)) $
((($2/75)%60)) $
(($2%75))
1676 local MODE DISCID TRACKS
1680 if [ "$1" = --wholedisc ] ; then
1686 vecho
"One track is $ONETRACK"
1687 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1688 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1689 ALBUMFILE
="$(mungefilename "$DALBUM")"
1690 if [ "$ONETRACK" = "y" ]; then
1691 if [ "$VARIOUSARTISTS" = "y" ]; then
1692 CUEWAVFILE
="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1694 CUEWAVFILE
="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
1696 vecho
"Cue wav file is $CUEWAVFILE"
1698 CUEWAVFILE
="dummy.wav"
1707 echo REM DISCID
$DISCID
1708 echo FILE
\""$CUEWAVEFILE"\" WAVE
1710 if [ $1 -ne 150 ] && [ $MODE = "PREGAP" ] ; then
1717 while [ $i -le "$TRACKS" ] ; do
1718 LBA
=$
(( $1 - $OFFSET ))
1719 printf " TRACK %02i AUDIO\n" $i
1720 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1721 if [ $MODE = PREGAP
] ; then
1722 echomsf
" PREGAP " $
(($OFFSET-150))
1724 echo " INDEX 00 00:00:00"
1727 echomsf
" INDEX 01 " $LBA
1734 # This essentially the start of things
1737 # Query the CD to get the track info, unless the user specified -C
1738 # or we are using some actions which do not need the CDDB data at all
1739 #if [ ! X"$EXPACTIONS" = "X" ]; then
1741 #elif [ -z "$DISCID" ]; then
1742 if [ -z "$DISCID" ]; then
1743 vecho
-n "Getting CD track info... "
1744 # In OSX, unmount the disc before a query
1745 if [ "$OSFLAVOUR" = "OSX" ]; then
1746 diskutil unmount
${CDROM#/dev/}
1748 case "$CDROMREADERSYNTAX" in
1750 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev
/null
2>&1 ; then
1751 case "$CUE2DISCID" in
1752 # FIXME # right now we have 2 cue2discid internal
1753 # implementations: builtin and abcde.cue2discid. Test
1754 # both of them and decide which one we want to use.
1756 #vecho "Using builtin cue2discid implementation..."
1757 CUESHEET
="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1759 #TRACKS=$(echo $CUESHEET | grep -E "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1761 OFFSETTIMES
=( $
(echo "$CUESHEET" |
sed -n -e's/\ *INDEX 01\ \+//p' ) )
1762 TRACKS
=${#OFFSETTIMES[@]}
1764 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1765 for OFFSETTIME
in ${OFFSETTIMES[@]}; do
1766 OFFSETS
="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1767 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1770 LEADOUT
=$
(( $
(echo "$CUESHEET" |
grep lead-out | get_last
) * 75 / 44100 ))
1771 LEADIN
=$
(( $
(echo "$CUESHEET" |
grep lead-in | get_last
) * 75 / 44100 ))
1775 #vecho "Using external python cue2discid implementation..."
1776 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" |
$CUE2DISCID)
1780 log error
"the input flac file does not contain a cuesheet."
1785 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1787 # if [ ! "$RET" = "0" ];then
1788 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1791 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1792 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1794 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | grep -Eo '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1795 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1799 case "$CDDBMETHOD" in
1800 cddb
) TRACKINFO
=$
($CDDISCID "$CDROM") ;;
1801 musicbrainz
) TRACKINFO
=$
($MUSICBRAINZ --command id
--device "$CDROM") ;;
1805 # Make sure there's a CD in there by checking cd-discid's return code
1806 if [ ! "$?" = "0" ]; then
1807 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1808 log error
"cuesheet information from the flac file could not be read."
1809 log error
"Perhaps the flac file does not contain a cuesheet?."
1812 log error
"CD could not be read. Perhaps there's no CD in the drive?"
1816 # In OSX, remount the disc again
1817 if [ "$OSFLAVOUR" = "OSX" ]; then
1818 diskutil mount
${CDROM#/dev/}
1821 DISCID
=$
(echo $TRACKINFO | cut
-f1 -d' ')
1823 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1826 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1827 # This needs to be done now because a section of the resuming code will need
1830 # get the number of digits to pad TRACKNUM with - we'll use this later
1831 # a CD can only hold 99 tracks, but since we support a feature for starting
1832 # numbering the tracks from a given number, we might need to set it as a
1833 # variable for the user to define... or obtain it somehow.
1834 if [ "$PADTRACKS" = "y" ] ; then
1838 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1839 if [ -z "$TRACKQUEUE" ]; then
1840 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1841 case "$CDROMREADERSYNTAX" in
1843 if [ "$WEHAVEACD" = "y" ]; then
1844 vecho
"Querying the CD for audio tracks..."
1845 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1847 if [ ! "$RET" = "0" ];then
1848 log warning
"something went wrong while querying the CD... Maybe a DATA CD?"
1850 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | grep -E '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1851 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1853 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1854 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1855 echo cdparanoia-audio-tracks
=$
( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1856 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1858 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1859 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1863 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1866 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1868 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1869 log info
"The disc does not contain any tracks. Giving up..."
1872 echo -n "Grabbing entire CD - tracks: "
1873 if [ ! "$PADTRACKS" = "y" ] ; then
1874 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1876 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1878 while [ "$X" -ne "$TRACKS" ]
1880 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1881 TRACKQUEUE
=$
(echo $TRACKQUEUE $X)
1885 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1886 # User-supplied track queue.
1887 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1888 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1889 # Once cleaned, obtain the highest value in the trackqueue for number padding
1890 for LASTTRACK
in $TRACKQUEUE; do :; done
1891 if [ ! "$PADTRACKS" = "y" ] ; then
1892 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1894 # Now we normalize the trackqueue
1895 for TRACK
in $TRACKQUEUE ; do
1896 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1897 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1899 TRACKQUEUE
=$PADTRACKQUEUE
1900 echo Grabbing tracks
: "$TRACKQUEUE"
1903 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1905 # We have the discid, create a temp directory after it to store all the temp
1908 if [ -e "$ABCDETEMPDIR" ]; then
1909 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1910 # It already exists, see if it's a directory
1911 if [ ! -d "$ABCDETEMPDIR" ]; then
1912 # This is a file/socket/fifo/device/etc, not a directory
1915 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1916 echo "Please investigate, remove it, and rerun abcde." >&2
1920 # It's a directory, let's see if it's writable by us
1921 if [ ! -r "$ABCDETEMPDIR" ] ||
[ ! -w "$ABCDETEMPDIR" ] ||
[ ! -x "$ABCDETEMPDIR" ]; then
1922 # Nope, complain and exit
1924 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
1925 echo "Please investigate, remove it, and rerun abcde." >&2
1929 # See if it's populated
1930 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1931 # Wipe and start fresh
1932 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1933 echo -n "this directory to continue. Continue [y/N]? " >&2
1934 if [ "$INTERACTIVE" = "y" ]; then
1940 if [ "$ANSWER" != "y" ]; then
1943 rm -rf "$ABCDETEMPDIR" ||
exit 1
1944 mkdir
-p "$ABCDETEMPDIR"
1945 if [ "$?" -gt "0" ]; then
1946 # Directory already exists or could not be created
1947 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1951 # Everything is fine. Check for ^encodetracklocation-
1952 # and encode-output entries in the status file and
1953 # remove them. These are not relevant across sessions.
1954 if [ -f "$ABCDETEMPDIR/status" ]; then
1955 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1956 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1957 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1959 # Remove old error messages
1960 if [ -f "$ABCDETEMPDIR/errors" ]; then
1961 rm -f "$ABCDETEMPDIR/errors"
1965 # We are starting from scratch
1966 mkdir
-p "$ABCDETEMPDIR"
1967 if [ "$?" -gt "0" ]; then
1968 # Directory already exists or could not be created
1969 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1972 cat /dev
/null
> "$ABCDETEMPDIR/status"
1973 # Store the abcde version in the status file.
1974 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1976 if [ X
"$DOCUE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1977 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1978 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1979 vecho
"Creating cue file..."
1980 case $CDROMREADERSYNTAX in
1982 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
1983 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1985 log warning
"the input flac file does not contain a cuesheet."
1989 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1990 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1992 log warning
"reading the CUE sheet is still considered experimental"
1993 log warning
"and there was a problem with the CD reading. abcde will continue,"
1994 log warning
"but consider reporting the problem to the abcde author"
2000 # If we got the CDPARANOIA status and it is not recorded, save it now
2001 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
2002 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
2003 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
2007 # Create the discid file
2008 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
2009 if checkstatus cddbmethod
> /dev
/null
2>&1 ; then :; else
2010 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
2015 # Create a proper CUE file based on the CUE file we created before.
2018 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
2019 CUEFILE_OUT
=$CUEFILE_IN.out
2020 ### FIXME ### checkstatus cddb
2021 if [ -e "$CDDBDATA" ]; then
2022 vecho
"Adding metadata to the cue file..."
2023 # FIXME It doesn't preserve spaces! Why?
2024 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
2026 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
2027 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
2028 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
2032 cat "$CUEFILE_IN" |
while read line
2034 if echo "$line" |
grep "INDEX 01" > /dev
/null
2>&1 ; then
2035 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2036 # echo "$line" >> "$CUEFILE_OUT"
2037 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2038 eval track
="\$TRACK$n"
2040 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2041 # When making a single-track rip, put the
2042 # actual file name into the file declaration
2043 # in the cue file so that it is usable by
2044 # music players and the like
2045 elif [ "$ONETRACK" = "y" ] &&
2046 echo "$line" |
grep '^FILE "dummy.wav" WAVE' > /dev
/null
2>&1 ; then
2048 TRACKFILE
="$(mungefilename "$TRACKNAME")"
2049 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
2050 ALBUMFILE
="$(mungefilename "$DALBUM")"
2052 if [ "$VARIOUSARTISTS" = "y" ]; then
2053 OUTPUTFILE
="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2055 OUTPUTFILE
="$(eval echo \""$ONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
2058 echo "FILE \"$OUTPUTFILE\" WAVE" >> "$CUEFILE_OUT"
2061 # FIXME # If the lines above are uncommented, remove the line below.
2062 echo "$line" >> "$CUEFILE_OUT"
2065 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2066 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2072 # Parses a CDDB file and outputs the title and the track names.
2073 # Variables: CDDBFILE
2077 # List out disc title/author and contents
2078 if [ "$ONETRACK" = "y" ]; then
2079 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
2081 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2082 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
2083 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
2084 if [ ! X
"$PARSEDYEAR" = "X" ]; then
2085 echo "Year: $PARSEDYEAR"
2088 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
2089 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
2090 if [ ! X
"$PARSEDGENRE" = "X" ]; then
2091 echo "Genre: $PARSEDGENRE"
2094 if [ ! "$ONETRACK" = "y" ]; then
2095 for TRACK
in $
(f_seq_row
1 $TRACKS)
2097 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2103 # Check for a local CDDB file, and report success
2106 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
2108 CDDBLOCALSTATUS
="notfound"
2109 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
2112 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2113 CDDBLOCALRESULTS
="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2114 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2115 if (( $
(echo "${CDDBLOCALRESULTS}" |
wc -l) == 1 )); then
2116 CDDBLOCALFILE
="${CDDBLOCALRESULTS}"
2117 CDDBLOCALMATCH
=single
2118 elif (( $
(echo "${CDDBLOCALRESULTS}" |
wc -l) > 1 )); then
2119 CDDBLOCALMATCH
=multiple
2124 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2125 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
2126 CDDBLOCALMATCH
=single
2131 # If the user has selected to check a local CDDB repo, we proceed with it
2132 case $CDDBLOCALMATCH in
2134 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2136 echo "$CDDBLOCALRESULTS" |
while read RESULT
; do
2138 # List out disc title/author and contents
2139 CDDBLOCALREAD
="$ABCDETEMPDIR/cddblocalread.$X"
2140 cat "$RESULT" > "${CDDBLOCALREAD}"
2143 do_cddbparse
"${CDDBLOCALREAD}"
2145 ##FIXME## QUICK HACK !!!!
2146 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2147 } >> "$ABCDETEMPDIR/cddblocalchoices"
2149 if [ $
(cat "$ABCDETEMPDIR/cddblocalchoices" |
wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2150 page
"$ABCDETEMPDIR/cddblocalchoices"
2152 # It's all going to fit in one page, cat it
2153 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2155 CDDBLOCALCHOICES
=$
( echo "$CDDBLOCALRESULTS" |
wc -l )
2156 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2157 CDDBLOCALCHOICENUM
=-1
2158 if [ "$INTERACTIVE" = "y" ]; then
2159 while [ $CDDBLOCALCHOICENUM -lt 0 ] ||
[ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2160 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2161 read CDDBLOCALCHOICE
2162 [ x
"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE
="1"
2163 # FIXME # Introduce diff's
2164 if echo $CDDBLOCALCHOICE |
grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2165 diffentries cddblocalread
"$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2166 elif echo $CDDBLOCALCHOICE |
grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2167 # Make sure we get a valid choice
2168 CDDBLOCALCHOICENUM
=$
(echo $CDDBLOCALCHOICE |
xargs printf %d
2>/dev
/null
)
2169 if [ $CDDBLOCALCHOICENUM -lt 0 ] ||
[ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2170 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2176 #echo "Selected ..."
2178 CDDBLOCALCHOICENUM
=1
2180 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2181 #echo "Using local copy of CDDB data"
2182 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2183 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2184 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2185 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
2186 do_cddbparse
"$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2187 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2188 CDDBLOCALSTATUS
="found"
2190 #echo "Not using local copy of CDDB data"
2191 CDDBLOCALSTATUS
="notfound"
2195 # List out disc title/author and contents
2196 do_cddbparse
"${CDDBLOCALFILE}"
2197 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2198 # echo -n "Embedded cuesheet entry found, use it [Y/n]? " >&2
2200 echo -n "Locally cached CDDB entry found, use it [Y/n]? " >&2
2202 if [ "$INTERACTIVE" = "y" ]; then
2204 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2205 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2208 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
2212 if [ "$USELOCALRESP" = "y" ]; then
2213 #echo "Using local copy of CDDB data"
2214 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2215 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2216 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2217 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
2218 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2219 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2220 CDDBLOCALSTATUS
="single"
2222 #echo "Not using local copy of CDDB data"
2223 CDDBLOCALSTATUS
="notfound"
2227 CDDBLOCALSTATUS
="notfound"
2234 # Try to read CD-Text from the drive using icedax / cdda2wav
2237 if new_checkexec icedax
; then
2238 CDTEXT_READER
=icedax
2239 elif new_checkexec cdda2wav
; then
2240 CDTEXT_READER
=cdda2wav
2242 # Didn't find either, bail
2246 if [ "$OSFLAVOUR" = "OSX" ] ; then
2247 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2248 diskutil unmount
${CDROM#/dev/}
2249 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2250 CDDA2WAVCDROM
="IODVDServices"
2251 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2252 CDDA2WAVCDROM
="$CDROMID"
2254 if [ "$CDROMID" = "" ]; then
2255 CDDA2WAVCDROM
="$CDROM"
2257 CDDA2WAVCDROM
="$CDROMID"
2261 # Do we have CD-Text on the disc (and can the drive read it?)
2262 ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
2263 grep -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
2265 if [ $ERRORCODE -ne 0 ]; then
2266 # No CD-Text found, bail
2270 rm -f "$ABCDETEMPDIR/cddbchoices"
2272 # Make an empty template
2273 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.1"
2274 echo -n "Retrieved 1 CD-Text match..." >> "$ABCDETEMPDIR/cddbchoices"
2275 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2276 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2277 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2278 ATITLE
=$
(grep -e '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut
-c14- )
2279 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2280 # List out disc title/author and contents
2281 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2282 for TRACK
in $
(f_seq_row
1 $TRACKS)
2284 TRACKM1
=$
(($TRACK - 1))
2285 TITLE
="$(grep -E ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text
" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~
'$~~g")"
2286 echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
2287 sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2288 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2290 sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new"
2291 mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
2292 echo >> "$ABCDETEMPDIR/cddbchoices"
2293 echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
2297 # Work with the musicbrainz WS API, then transform the results here so
2298 # they look (very) like the results from CDDB. Maybe not the best way
2299 # to go, but it Works For Me (TM)
2303 if checkstatus musicbrainz-readcomplete; then :; else
2304 vecho "Obtaining Musicbrainz results..."
2305 # If MB is to be used, interpret the query results and read all
2306 # the available entries.
2307 rm -f "$ABCDETEMPDIR/cddbchoices"
2308 CDDBCHOICES=1 # Overridden by multiple matches
2309 MBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2310 ${MUSICBRAINZ} --command data --discid "$MBDISCID" --workdir "$ABCDETEMPDIR"
2312 # The helper script will write disc matches out to
2313 # cddbread.*. Count how many we have
2314 if [ ! -f "${ABCDETEMPDIR}/cddbread.1" ] ; then
2315 # No matches. Use the normal cddb template for the user to
2317 echo "No Musicbrainz match." >> "$ABCDETEMPDIR/cddbchoices"
2318 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2319 # List out disc title/author and contents of template
2320 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2322 for TRACK in $(f_seq_row 1 $TRACKS)
2324 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2326 echo >> "$ABCDETEMPDIR/cddbchoices"
2327 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2328 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2329 echo 503 > "$ABCDETEMPDIR/cddbquery"
2331 # We have some matches
2332 NUM_RESPONSES=$(echo "${ABCDETEMPDIR}"/cddbread.* | wc -w)
2333 if [ "$NUM_RESPONSES" -eq 1 ] ; then
2335 echo -n "Retrieved 1 Musicbrainz match..." >> "$ABCDETEMPDIR/cddbchoices"
2336 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2337 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2338 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2339 ATITLE=$(grep -e '^DTITLE
=' "${ABCDETEMPDIR}/cddbread.1" | cut -c8- )
2340 echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2341 # List out disc title/author and contents
2342 echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
2343 for TRACK in $(f_seq_row 1 $TRACKS)
2345 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2347 echo >> "$ABCDETEMPDIR/cddbchoices"
2349 echo "210 Found exact matches, list follows (until terminating .)" > "$ABCDETEMPDIR/cddbquery"
2350 echo "Multiple Musicbrainz matches:" >> "$ABCDETEMPDIR/cddbchoices"
2351 for file in "$ABCDETEMPDIR"/cddbread.*
2353 X=$(echo $file | sed 's
/^.
*cddbread\.
//g
')
2354 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2355 ATITLE=$(grep -e '^DTITLE
=' "${ABCDETEMPDIR}"/cddbread.$X | cut -c8- )
2356 echo "none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
2357 # List out disc title/author and contents
2358 echo "#$X: ---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
2359 for TRACK in $(f_seq_row 1 $TRACKS)
2361 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2363 echo >> "$ABCDETEMPDIR/cddbchoices"
2365 echo "." >> "$ABCDETEMPDIR/cddbquery"
2368 echo "musicbrainz-readcomplete" >> "$ABCDETEMPDIR/status"
2375 # Perform CDDB protocol version check if it hasn't already been
done
2376 if checkstatus cddb-statcomplete
; then :; else
2377 if [ "$CDDBAVAIL" = "n" ]; then
2379 echo 503 > "$ABCDETEMPDIR/cddbstat"
2382 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
2383 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
2384 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2385 vecho
"Checking CDDB server status..."
2386 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2387 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
2388 case "$RESPONSECODE" in
2389 210) # 210 OK, status information follows (until terminating `.')
2392 501) # 501 Illegal CDDB protocol level: <n>.
2393 CDDBPROTO
=`expr $CDDBPROTO - 1`
2395 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2396 # FreeDB TESTCD disc-id is used for query
2397 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2398 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
2399 case "$RESPONSECODE" in
2400 2??
) # Server responded, everything seems OK
2407 if test $rc -eq 1; then
2411 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
2419 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
2420 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
2422 # Perform CDDB query if it hasn't already been done
2423 if checkstatus cddb-querycomplete
; then :; else
2424 if [ "$CDDBAVAIL" = "n" ]; then
2426 echo 503 > "$ABCDETEMPDIR/cddbquery"
2427 # The default CDDBLOCALSTATUS is "notfound"
2428 # This part will be triggered if the user CDDB repo does not
2429 # contain the entry, or if we are not trying to use the repo.
2431 vecho
"Querying the CDDB server..."
2432 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
2433 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
2434 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2440 # no match found in database,
2441 # wget/fetch error, or user requested not to use CDDB
2442 # Make up an error code (503) that abcde
2443 # will recognize in do_cddbread
2444 # and compensate by making a template
2445 echo 503 > "$ABCDETEMPDIR/cddbquery"
2447 *) # strange and unknown error
2448 echo ERRORCODE
=$ERRORCODE
2449 echo "abcde: $CDDBTOOL returned unknown error code"
2453 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
2460 # If it's not to be used, generate a template.
2461 # Then, display it (or them) and let the user choose/edit it
2462 if checkstatus cddb-readcomplete
; then :; else
2463 vecho
"Obtaining CDDB results..."
2464 # If CDDB is to be used, interpret the query results and read all
2465 # the available entries.
2466 rm -f "$ABCDETEMPDIR/cddbchoices"
2467 CDDBCHOICES
=1 # Overridden by multiple matches
2468 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
2469 case "$RESPONSECODE" in
2471 # One exact match, retrieve it
2472 # 200 [section] [discid] [artist] / [title]
2473 if checkstatus cddb-read-1-complete
; then :; else
2474 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2475 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2476 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2477 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2478 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2480 # List out disc title/author and contents
2481 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2482 for TRACK
in $
(f_seq_row
1 $TRACKS)
2484 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2486 echo >> "$ABCDETEMPDIR/cddbchoices"
2490 case "$RESPONSECODE" in
2491 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2492 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2493 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2495 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2496 # List out disc title/author and contents of template
2497 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
2499 for TRACK
in $
(f_seq_row
1 $TRACKS)
2501 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2503 echo >> "$ABCDETEMPDIR/cddbchoices"
2504 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
2505 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
2508 # Multiple exact, (possibly multiple) inexact matches
2510 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
2511 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
2512 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2513 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2514 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2516 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2518 vecho
-n "Retrieving multiple matches... "
2519 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
2520 read DISCINFO
# eat top line
2524 if checkstatus cddb-read-
$X-complete; then :; else
2525 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2526 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
2528 # List out disc title/author and contents
2529 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2530 for TRACK
in $
(f_seq_row
1 $TRACKS)
2532 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2534 echo >> "$ABCDETEMPDIR/cddbchoices"
2537 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2541 for TRACK
in $
(f_seq_row
1 $TRACKS)
2543 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2545 echo >> "$ABCDETEMPDIR/cddbchoices"
2546 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2547 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2550 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2557 if checkstatus cddb-edit
>/dev
/null
; then
2558 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2559 VARIOUSARTISTS
="$(checkstatus variousartists)"
2560 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
2563 if [ "$INTERACTIVE" = "y" ]; then
2564 # We should show the CDDB results both when we are not using the local CDDB repo
2565 # or when we are using it but we could not find a proper match
2566 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
2567 # Display the $ABCDETEMPDIR/cddbchoices file created above
2568 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2569 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2570 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2571 CHOICE
=$
(checkstatus cddb-choice
)
2572 if [ -n "$CHOICE" ] ; then
2573 case $CDDBCHOICES in
2574 -1) if head -1 "$ABCDETEMPDIR/cddbquery" |
grep "^$" > /dev
/null
2>&1 ; then
2575 log error
"CDDB query failed!"
2578 cat "$ABCDETEMPDIR/cddbchoices"
2581 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2583 echo "Selected: #$CHOICE"
2584 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
2588 # The user has a choice to make, display the info in a pager if necessary
2589 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
2590 page
"$ABCDETEMPDIR/cddbchoices"
2592 # It's all going to fit in one page, cat it
2593 cat "$ABCDETEMPDIR/cddbchoices" >&2
2597 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2599 # I'll take CDDB read #3 for $400, Alex
2600 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2601 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2603 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
2604 if echo $CDDBCHOICE |
grep -E "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2605 if [ ! X
"$DIFF" = "X" ]; then
2606 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
2607 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
2608 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2609 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2610 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2611 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2613 # We parse the 2 choices to diff, store them in temporary files and diff them.
2614 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
2615 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2617 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2618 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2619 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
2620 page
"$ABCDETEMPDIR/cddbread.diff"
2622 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2626 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2628 elif echo $CDDBCHOICE |
grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2629 # Make sure we get a valid choice
2630 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
2631 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2632 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2636 if [ "$CDCHOICENUM" = "0" ]; then
2637 vecho
"Creating empty CDDB template..."
2639 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2641 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2642 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2644 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2648 # We need some code to show the selected option when local repository is selected and we have found a match
2649 vecho
"Using cached CDDB match..." >&2
2650 # Display the $ABCDETEMPDIR/cddbchoices file created above
2651 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2652 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2653 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2654 CHOICE
=$
(checkstatus cddb-choice
)
2655 if [ "$USELOCALRESP" = "y" ]; then :; else
2656 if [ -n "$CHOICE" ] ; then
2657 case $CDDBCHOICES in
2660 echo "Selected template."
2662 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2664 echo "Selected: #$CHOICE"
2665 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
2673 # We're noninteractive - pick the first choice.
2674 # But in case we run a previous instance and selected a choice, use it.
2675 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2676 # Show the choice if we are not using the locally stored one
2677 # or when the local search failed to find a match.
2678 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
2679 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
2680 #if [ "$PREVIOUSCHOICE" ]; then
2681 cat "$ABCDETEMPDIR/cddbchoices"
2684 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2685 CDCHOICENUM
=$PREVIOUSCHOICE
2688 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2690 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2695 if checkstatus cddb-choice
>/dev
/null
; then :; else
2696 echo "abcde: internal error: cddb-choice not recorded." >&2
2699 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2700 echo -n "Edit selected CDDB data? [y/n] (" >&2
2701 if [ "$INTERACTIVE" = "y" ]; then
2702 if [ "$UNKNOWNDISK" = "y" ]; then
2705 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
2714 if [ "$EDITCDDB" = "y" ]; then
2715 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
2717 # Use the debian sensible-editor wrapper to pick the editor that the
2718 # user has requested via their $EDITOR environment variable
2719 if [ -x "/usr/bin/sensible-editor" ]; then
2720 /usr
/bin
/sensible-editor
"$CDDBDATA"
2721 elif [ -n "$EDITOR" ]; then
2722 if [ -x $
(which "${EDITOR%%\ *}") ]; then
2723 # That failed, try to load the preferred editor, starting
2724 # with their EDITOR variable
2725 eval $
(echo "$EDITOR") \"$CDDBDATA\"
2727 # If that fails, check for a vi
2728 elif which vi
>/dev
/null
2>&1; then
2730 elif [ -x /usr
/bin
/vim
]; then
2731 /usr
/bin
/vim
"$CDDBDATA"
2732 elif [ -x /usr
/bin
/vi
]; then
2733 /usr
/bin
/vi
"$CDDBDATA"
2734 elif [ -x /bin
/vi
]; then
2736 # nano should be on all (modern, i.e., sarge) debian systems
2737 elif which nano
>/dev
/null
2>&1 ; then
2739 elif [ -x /usr
/bin
/nano
]; then
2740 /usr
/bin
/nano
"$CDDBDATA"
2741 # mg should be on all OpenBSD systems
2742 elif which mg
>/dev
/null
2>&1 ; then
2744 elif [ -x /usr
/bin
/mg
]; then
2745 /usr
/bin
/mg
"$CDDBDATA"
2748 log warning
"no editor available. Check your EDITOR environment variable."
2750 # delete editor backup file if it exists
2751 if [ -w "$CDDBDATA~" ]; then
2756 # Some heuristics first. Look at Disc Title, and if it starts with
2757 # "Various", then we'll assume Various Artists
2758 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | grep -Eci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2759 echo "Looks like a Multi-Artist CD" >&2
2762 echo -n "Is the CD multi-artist [y/N]? " >&2
2763 if [ "$INTERACTIVE" = "y" ]; then
2770 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2773 # Need NUMTRACKS before cddb-tool will return it:
2774 NUMTRACKS
=$
(grep -E '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
2775 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2776 # More than 1/2 tracks contain a "/", so guess forward
2778 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2779 # More than 1/2 contain a "-", so guess forward-dash
2781 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2782 # More than 1/2 contain something in parens, so guess trailing-paren
2786 echo "1) Artist / Title" >&2
2787 echo "2) Artist - Title" >&2
2788 echo "3) Title / Artist" >&2
2789 echo "4) Title - Artist" >&2
2790 echo "5) Artist: Title" >&2
2791 echo "6) Title (Artist)" >&2
2792 echo "7) This is a single-artist CD" >&2
2793 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2794 if [ "$INTERACTIVE" = "y" ]; then
2795 read VARIOUSARTISTSTYLE
2797 echo $DEFAULTSTYLE >&2
2798 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2800 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2801 # If they press Enter, then the default style (0) was chosen
2802 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2803 echo "Invalid selection. Please choose a number between 1 and 7."
2804 echo -n "Selection [1-7]: "
2805 read VARIOUSARTISTSTYLE
2806 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2808 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2809 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2811 vecho
"Selected: $VARIOUSARTISTSTYLE"
2812 case "$VARIOUSARTISTSTYLE" in
2814 VARIOUSARTISTSTYLE
=forward
2817 VARIOUSARTISTSTYLE
=forward-dash
2820 VARIOUSARTISTSTYLE
=reverse
2823 VARIOUSARTISTSTYLE
=reverse-dash
2826 VARIOUSARTISTSTYLE
=colon
2829 VARIOUSARTISTSTYLE
=trailing-paren
2837 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2838 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2840 if [ "$EDITCDDB" = "y" ] && [ "$CDDBMETHOD" = "cddb" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2841 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2842 # This works but does not have the necessary error checking
2843 # yet. If you are familiar with the CDDB spec
2844 # (see http://www.freedb.org/src/latest/DBFORMAT)
2845 # and can create an error-free entry on your own, then put
2846 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2847 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2848 # your abcde.conf to change the email address submissions are
2851 # submit the modified file, if they want
2852 if [ "$NOSUBMIT" != "y" ]; then
2853 echo -n "Do you want to submit this entry to $CDDBSUBMIT [y/N]? "
2855 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2856 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2858 echo -n 'Invalid selection. Please answer "y" or "n": '
2861 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2862 echo -n "Sending..."
2863 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2870 # User CDDBLOCALPOLICY to find out if we store the file or not...
2871 # Cache edited CDDB entry in the user's cddb dir
2872 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2873 # Make sure the cache directory exists
2874 mkdir
-p $CDDBLOCALDIR
2875 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2878 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2881 # do_cdread [tracknumber]
2882 # do_cdread onetrack [firsttrack] [lasttrack]
2886 # The commands here don't go through run_command because they're never supposed to be silenced
2887 # return codes need to be doublechecked anyway, however
2888 if [ "$1" = "onetrack" ]; then
2889 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2890 # FIXME # Until then, we grab the whole CD in one track, no matter what
2892 # We need the first and last track for cdda2wav/icedax
2894 LASTTRACK
=$
(expr $3 + 0)
2895 UTRACKNUM
=$FIRSTTRACK
2896 case "$CDROMREADERSYNTAX" in
2897 flac
) READTRACKNUMS
="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2900 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
2901 READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
2902 cdda2wav | icedax
) READTRACKNUMS
="$FIRSTTRACK+$LASTTRACK" ;;
2903 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2909 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2910 if [ "$USEPIPES" = "y" ]; then
2911 TEMPARG
="PIPERIPPER_$CDROMREADERSYNTAX"
2912 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2914 PIPE_MESSAGE
="and encoding "
2916 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2917 case "$CDROMREADERSYNTAX" in
2918 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2920 FILEARG
="--output-name=$WAVDATA"
2923 FILEARG
="-f $WAVDATA"
2931 if [ "$1" = "onetrack" ]; then
2932 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2934 if [ -r "$CDDBDATA" ]; then
2935 getcddbinfo TRACKNAME
2936 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2938 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2941 case "$CDROMREADERSYNTAX" in
2942 ### FIXME ### use an exception for flac, since it uses -o
2943 ### FIXME ### Shall we just use -o $FILEARG ??
2945 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2946 STRIPTRACKNUM
=$
(expr $UTRACKNUM + 0)
2947 nice
$READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2949 if [ "$REDIR" = "y" ]; then
2950 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
2952 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
2956 if [ "$OSFLAVOUR" = "OSX" ] ; then
2957 # Hei, we have to unmount the device before running anything like cdda2wav/icedax in OSX
2958 diskutil unmount
${CDROM#/dev/}
2959 # Also, in OSX the cdrom device for cdda2wav/icedax changes...
2960 CDDA2WAVCDROM
="IODVDServices"
2961 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2962 CDDA2WAVCDROM
="$CDROMID"
2964 if [ "$CDROMID" = "" ]; then
2965 CDDA2WAVCDROM
="$CDROM"
2967 CDDA2WAVCDROM
="$CDROMID"
2970 if [ "$REDIR" = "y" ]; then
2971 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" >&2
2973 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG"
2975 ## FIXME ## We have an exception for dagrab, since it uses -f
2976 ## FIXME ## Shall we just use -f $FILEARG ??
2978 if [ "$REDIR" = "y" ]; then
2979 nice
$READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG" >&2
2981 nice
$READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG"
2984 # Find the track's mounted path
2985 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2986 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2987 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2988 # If the file exists, copy it
2989 if [ -e "$FILEPATH" ] ; then
2990 if [ "$REDIR" = "y" ]; then
2991 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" >&2
2993 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
2999 if [ "$REDIR" = "y" ]; then
3000 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" >&2
3002 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG"
3006 # If we get some error or we get some missing wav
3007 # (as long as we dont use pipes)
3008 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
3009 # Thank goodness errors is only machine-parseable up to the
3010 # first colon, otherwise this woulda sucked
3011 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
3012 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
3014 if [ "$USEPIPES" = "y" ]; then
3015 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3017 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
3021 if [ "$USEPIPES" = "y" ]; then
3022 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
3024 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
3026 if [ "$1" = "onetrack" ]; then
3027 echo onetrack
>> "$ABCDETEMPDIR/status"
3033 # No values accepted, only uses env variables
3036 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
3037 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
3039 echo "abcde: unable to set the device speed" >&2
3045 # vecho outputs a message if EXTRAVERBOSE is 1 or more
3048 if [ x
"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 0 ] ; then
3050 warning
) shift ; log warning
"$@" ;;
3058 # vvecho outputs a message if EXTRAVERBOSE is 2 or more
3061 if [ x
"$EXTRAVERBOSE" != "x" ] && [ $EXTRAVERBOSE -gt 1 ] ; then
3063 warning
) shift ; log warning
"$@" ;;
3071 # decho outputs a debug message if DEBUG is selected
3074 if [ x
"$DEBUG" != "x" ]; then
3075 if echo $1 |
grep "^\[" > /dev
/null
2>&1 ; then
3076 DEBUGECHO
=$
(echo "$@" |
tr -d '[]')
3077 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
3084 # User-redefinable functions
3085 # Custom filename munging:
3088 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
3089 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
3092 # Custom genre munging:
3095 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
3099 # Empty pre_read function, to be defined in the configuration file.
3106 # Empty post_read function, to be defined in the configuration file.
3113 # Empty post_encode function, to be defined in the configuration file.
3119 ###############################################################################
3122 # Start of execution
3123 ###############################################################################
3128 # Defaults to FreeDB, but musicbrainz can be used too, via the abcde-musicbrainz-tool script
3130 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
3131 CDDBSUBMIT
=freedb-submit@freedb.org
3133 HELLOINFO
="$(whoami)@$(hostname)"
3135 CDDBLOCALPOLICY
="always"
3136 CDDBLOCALRECURSIVE
="y"
3137 CDDBLOCALDIR
="$HOME/.cddb"
3140 # List of fields we parse and show during the CDDB parsing...
3141 SHOWCDDBFIELDS
="year,genre"
3144 #CDROMREADERSYNTAX=cdparanoia
3145 ENCODERSYNTAX
=default
3147 MP3ENCODERSYNTAX
=default
3148 OGGENCODERSYNTAX
=default
3149 FLACENCODERSYNTAX
=default
3150 SPEEXENCODERSYNTAX
=default
3151 MPPENCODERSYNTAX
=default
3152 AACENCODERSYNTAX
=default
3153 NORMALIZERSYNTAX
=default
3154 CUEREADERSYNTAX
=default
3156 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
3157 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
3158 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
3159 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
3160 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
3161 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
3162 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3163 PLAYLISTDATAPREFIX
=''
3164 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
3165 VAPLAYLISTDATAPREFIX
=''
3173 VARIOUSARTISTSTYLE
=forward
3180 # If using scsi devices, cdda2wav/icedax needs a CDROMID, instead of a device node
3181 # i.e. CDROMID="1,0,0"
3183 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
3184 # If we are using the ide-scsi emulation layer, we need to define a "g"
3185 CDPARANOIACDROMBUS
="d"
3187 # program paths - defaults to checking your $PATH
3194 XINGMP3ENC
=xingmp3enc
3211 VORBISCOMMENT
=vorbiscomment
3214 ATOMICPARSLEY
=AtomicParsley
3216 CDPARANOIA
=cdparanoia
3222 MUSICBRAINZ
=abcde-musicbrainz-tool
3226 NORMALIZE
=normalize-audio
3228 VORBISGAIN
=vorbisgain
3236 # Options for programs called from abcde
3249 VORBISGAINOPTS
="--album"
3252 FLACGAINOPTS
="--add-replay-gain"
3274 VORBISCOMMENTOPTS
="-R"
3275 METAFLACOPTS
="--no-utf8-convert"
3278 # Default to one process if -j isn't specified
3281 # List of actions to perform - by default, run to completion
3282 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
3284 # This option is basically for Debian package dependencies:
3285 # List of preferred outputs - by default, run with whatever we have in the path
3286 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:toolame
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
,m4a
:faac
3288 # List of preferred cdromreaders - by default, run whichever we have in the path
3289 DEFAULT_CDROMREADERS
="cdparanoia icedax cdda2wav"
3291 # List of quality levels associated with the encoders:
3292 DEFAULT_QUALITY_XLO
="oggenc:-q -1,lame:-q 9,speex:--quality 1,m4a:"
3293 DEFAULT_QUALITY_LO
="oggenc:-q 1,lame:-q 7,speex:--quality 5,m4a:"
3294 DEFAULT_QUALITY_HI
="oggenc:-q 7,lame:--preset standard,speex:--quality 9,m4a:"
3295 DEFAULT_QUALITY_XHI
="oggenc:-q 10,lame:--preset extreme,speex:--quality 10,m4a:"
3297 # Assume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3298 # Linux/OpenBSD. ftp is user for NetBSD.
3299 # Let's use these checkings to determine the OS flavour, which will be used
3301 if [ X$
(uname
) = "XFreeBSD" ] ; then
3306 elif [ X$
(uname
) = "XDarwin" ] ; then
3309 # We should have diskutil in OSX, but let's be sure...
3311 CDROMREADERSYNTAX
=cddafs
3312 elif [ X$
(uname
) = "XOpenBSD" ] ; then
3316 elif [ X$
(uname
) = "XNetBSD" ] ; then
3320 elif [ X$
(uname
) = "SunOS" ] ; then
3328 # If CDDBAVAIL is set to n, no CDDB read is done
3329 # If USEID3 is set to n, no ID3 tagging is done
3335 # But before we get into business, let us chop off any GREP environmental
3340 if [ -z "$OUTPUTDIR" ]; then
3344 if [ -z "$WAVOUTPUTDIR" ]; then
3345 WAVOUTPUTDIR
="$OUTPUTDIR"
3348 # Load system defaults
3349 if [ -r /etc
/abcde.conf
]; then
3352 # Load user preference defaults
3353 if [ -r $HOME/.abcde.conf
]; then
3357 # By this time, we need some HTTPGETOPTS already defined.
3358 # If the user has defined a non-default HTTPGET method, we should not be empty.
3360 if [ "$HTTPGETOPTS" = "" ] ; then
3362 wget
) HTTPGETOPTS
="-q -nv -e timestamping=off -O -";;
3363 curl
) HTTPGETOPTS
="-f -s";;
3364 fetch
)HTTPGETOPTS
="-q -o -";;
3365 ftp) HTTPGETOPTS
="-a -V -o - ";;
3366 *) log warning
"HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3370 # If the CDROM has not been set yet, find a suitable one.
3371 # If this is a devfs system, default to /dev/cdroms/cdrom0
3372 # instead of /dev/cdrom
3373 if [ "$CDROM" = "" ] ; then
3374 if [ -e /dev
/cdroms
/cdrom0
]; then
3375 CDROM
=/dev
/cdroms
/cdrom0
3376 elif [ -e /dev
/cdrom
]; then
3378 elif [ -e /dev
/sr0
]; then
3380 elif [ -e /dev
/cd0c
]; then
3382 elif [ -e /dev
/acd0c
]; then
3384 elif [ -e /dev
/disk1
]; then
3386 elif [ "$OSFLAVOUR" = "OSX" ] && [[ $
(diskutil list
) =~ CD_part.
*(disk.
)$
'\n' ]]; then
3387 CDROM
=/dev
/${BASH_REMATCH[1]}
3391 # We used to use EXTRAVERBOSE=y to turn on more debug output. Now
3392 # that's changed to a number to allow for more control. If
3393 # EXTRAVERBOSE=y, set it to 1 for backwards compatibility.
3394 if [ "$EXTRAVERBOSE" = "y" ]; then
3397 if [ "$EXTRAVERBOSE" = "n" ]; then
3401 # Parse command line options
3402 #while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPq:r:Rs:S:t:T:vVxw:W: opt ; do
3403 while getopts 1a
:bBc
:C
:d
:Defghj
:klLmMnNo
:pPq
:r
:s
:S
:t
:T
:UvVxX
:w
:W
:z opt
; do
3406 a
) ACTIONS
="$OPTARG" ;;
3407 A
) EXPACTIONS
="$OPTARG" ;;
3409 B
) NOBATCHREPLAYGAIN
=y
;;
3410 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else log error
"config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3411 C
) DISCID
="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3412 d
) CDROM
="$OPTARG" ;;
3415 e
) ERASEENCODEDSTATUS
=y
;;
3416 E
) ENCODING
="$OPTARG" ;;
3420 j
) MAXPROCS
="$OPTARG" ;;
3423 L
) CDDBUSELOCAL
=y
;;
3428 o
) OUTPUTTYPE
="$OPTARG" ;;
3431 q
) QUALITYLEVEL
="$OPTARG" ;;
3432 r
) REMOTEHOSTS
="$OPTARG" ;;
3433 R
) CDDBLOCALRECURSIVE
=y
;;
3434 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
3435 S
) CDSPEEDVALUE
="$OPTARG" ;;
3436 t
) STARTTRACKNUMBER
="$OPTARG" ;;
3437 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
3440 echo "This is abcde v$VERSION."
3441 echo "Usage: abcde [options] [tracks]"
3442 echo "abcde -h for extra help"
3445 V
) EXTRAVERBOSE
=$
(($EXTRAVERBOSE + 1)) ;;
3447 X
) CUE2DISCID
="$OPTARG" ;;
3448 w
) COMMENT
="$OPTARG" ;;
3449 W
) if echo $OPTARG |
grep "[[:digit:]]" > /dev
/null
2>&1 ; then
3450 STARTTRACKNUMBER
="${OPTARG}01"
3451 STARTTRACKNUMBERTAG
="y"
3452 COMMENT
="CD${OPTARG}"
3453 DISCNUMBER
="${OPTARG}"
3455 log error
"argument of -W must be integer"
3459 z
) DEBUG
=y
; CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
3464 shift $
(($OPTIND - 1))
3466 # Here it comes the worse part of the whole thing. From here until we start
3467 # ripping, we have a mixture of sanity checks, verifications, default settigs
3468 # and other crazy stuff that interdepends, but hey, someone has to do it.
3470 # If NOCDDBQUERY is set, don't query the CDDB server.
3471 if [ "$NOCDDBQUERY" = "y" ]; then
3475 # If the user specified a flac file, then switch to special flac mode
3476 if echo "$CDROM" |
grep -i '.flac$' > /dev
/null
2>&1 ; then
3477 if [ ! -f "$CDROM" ]; then
3478 log error
"the defined file for FLAC ripping cannot be found" >&2
3481 vecho warning
"switching to flac CDROMREADERSYNTAX..."
3482 CDROMREADERSYNTAX
=flac
3483 # We have a builtin version of cue2discid...
3484 case "$CUE2DISCID" in
3486 *) NEEDCUE2DISCID
=y
;;
3492 # If the user provided a DISCID, disable eject
3493 if [ -n "$DISCID" ] ||
[ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD
=n
; fi
3495 # Check the available cd rippers in the system, from the ones we know.
3496 if [ "$CDROMREADERSYNTAX" = "" ]; then
3497 for DEFAULT_CDROMREADER
in $DEFAULT_CDROMREADERS; do
3498 if new_checkexec
$DEFAULT_CDROMREADER; then
3499 CDROMREADERSYNTAX
=$DEFAULT_CDROMREADER
3503 if [ "$CDROMREADERSYNTAX" = "" ]; then
3504 log error
"no cdreader found in your PATH"
3505 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
3510 # Decide if we can continue.
3511 if [ "$ONETRACK" = "y" ]; then
3512 # FIXME # remove check as soon as we find out about the other readers
3513 case "$CDROMREADERSYNTAX" in
3516 cdda2wav | icedax
) ;;
3517 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
3520 if [ "$BATCHNORM" = "y" ]; then
3521 log warning
"BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3524 if [ "$NOGAP" = "y" ]; then
3525 log warning
"NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3528 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3529 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3530 if [ $# -gt 0 ]; then
3531 log warning
"ONETRACK mode selected, grabbing all tracks..."
3534 while [ $# -gt 0 ]; do
3535 # Range parsing code courtesy of Vincent Ho
3536 # Cleaned up to use shell built-ins by Charles Steinkuehler
3537 if [ "${1#*[^0-9-]}" != "$1" ]; then
3538 log error
"syntax error while processing track numbers ($1)"
3543 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3544 TRACKQUEUE
="$TRACKQUEUE $RSTART"
3545 RSTART
=$
(( $RSTART + 1 ))
3552 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3553 # List of experimental actions: retag,transcode
3555 # Determine what actions are to be done from $ACTIONS and set the
3556 # following environment variables for them:
3568 ## FIXME ## Lets keep compatibility with -M
3569 [ "$DOCUE" != "y" ] && DOCUE
=n
3571 for ACTION
in $
(echo $ACTIONS |
tr , \
)
3574 default
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOCLEAN
=y
;;
3575 cue
) DOCUE
=y
; MAKECUEFILE
=y
;;
3578 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
3579 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3580 encode
) DOENCODE
=y
; DOREAD
=y
;;
3581 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3582 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
3583 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
3584 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
3585 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
3590 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3591 # FIXME # should we abort on error or just inform the user?
3592 log warning
"selected both normalize and replaygain actions"
3595 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
3596 case $SHOWCDDBFIELD in
3597 y
*|Y
*) SHOWCDDBYEAR
="y";;
3598 g
*|G
*) SHOWCDDBGENRE
="y";;
3603 # At this point a CDROM has to be defined, so we check it exists.
3604 if [ X
"$CDROM" != "X" ] ; then
3605 if ( [ "$CDROMREADERSYNTAX" = "cdda2wav" ] ||
[ "$CDROMREADERSYNTAX" = "icedax" ] ) && [ "$NEEDCDROMID" = "y" ] ; then
3606 if [ "$OSFLAVOUR" = "FBSD" ]; then
3607 if echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then :; else
3608 log error
"CDROMID not in the right format for $CDROMREADERSYNTAX"
3609 log error
"Use \"cdrecord -scanbus\" to obtain an adequate ID and set CDROMID accordingly"
3613 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
3614 log error
"CDROM device cannot be found."
3617 # avoid processing if we are not going to hit the CDROM.
3618 elif [ X
"$DOREAD" = "Xy" ]; then
3619 log error
"CDROM has not been defined or cannot be found"
3623 # USEPIPES pre-tests, before we get into more serious stuff
3624 # Not compatible with:
3625 # - multiple outputs
3627 # - lowdisk algorithm
3629 if [ X
"$USEPIPES" = "Xy" ]; then
3630 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
3631 log error
"Unix pipes not compatible with multiple outputs"
3634 if [ X
"$DONORMALIZE" = "Xy" ]; then
3635 log error
"Unix pipes not compatible with normalizer"
3636 # FIXME # Do we need to exit or shall we just disable the mode?
3639 if [ X
"$BATCHNORM" = "Xy" ]; then
3640 log error
"Unix pipes not compatible with BATCHNORM encoding"
3643 if [ X
"$NOGAP" = "Xy" ]; then
3644 log error
"Unix pipes not compatible with NOGAP encoding"
3647 if [ X
"$DOENCODE" = "Xn" ]; then
3648 vecho warning
"Disabling Unix pipes since we are not encoding!"
3651 if [ X
"$LOWDISK" = "Xy" ]; then
3652 log error
"Unix pipes not compatible with lowdisk algorithm"
3657 # LOWDISK pre-tests, before we get into more problematic stuff
3658 # Not compatible with anything that needs all the files in the hard disc:
3661 if [ X
"$LOWDISK" = "Xy" ]; then
3662 if [ X
"$BATCHNORM" = "Xy" ]; then
3663 log error
"Unix pipes not compatible with BATCHNORM encoding"
3666 if [ X
"$NOGAP" = "Xy" ]; then
3667 log error
"Unix pipes not compatible with NOGAP encoding"
3672 # BATCHNORM pre-tests, before we get into serious problems
3673 # Not compatible with
3674 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3675 vecho warning
"Disabling BATCHNORM since we are not normalizing!"
3679 # Check the encoding format from the ones available in the system, if nothing has been configured.
3680 if [ X
"$OUTPUTTYPE" = "X" ]; then
3681 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
3682 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3683 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3684 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
3685 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
3686 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3690 if [ X
"$OUTPUTTYPE" = "X" ]; then
3691 log error
"no encoder found in the PATH"
3692 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
3697 # Decide which CDROM reader we're gonna use
3698 case "$CDROMREADERSYNTAX" in
3700 CDROMREADER
="$CDPARANOIA"
3701 CDROMREADEROPTS
="$CDPARANOIAOPTS"
3704 CDROMREADER
="$CDDA2WAV"
3705 CDROMREADEROPTS
="$CDDA2WAVOPTS"
3708 CDROMREADER
="$DAGRAB"
3709 CDROMREADEROPTS
="$DAGRABOPTS"
3712 CDROMREADER
="$CDDAFS"
3713 CDROMREADEROPTS
="$CDDAFSOPTS"
3717 CDROMREADEROPTS
="$FLACOPTS"
3721 # There's only one normalize...
3722 case "$NORMALIZERSYNTAX" in
3724 NORMALIZER
="$NORMALIZE"
3725 NORMALIZEROPTS
="$NORMALIZEOPTS"
3729 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3730 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
3731 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr \ \|| tr , \ | tr \| \ )"; do
3733 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3734 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3735 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3736 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3737 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3738 m4a
:*) AACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3741 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
3742 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
3743 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
3745 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
3748 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
3749 # for flacs and speexenc for speex and mppenc for mpps and faac for m4as
3751 # Getting ready for multiple output changes
3752 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
3756 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
3757 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
3758 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
3759 OGGOUTPUTCONTAINER
=ogg
3762 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
3763 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
3764 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN
=y
3767 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
3768 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
3769 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
3770 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC
=y
3773 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
3774 # [ "$DOREPLAYGAIN" = "y" ] &&
3777 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
3778 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN
=y
3781 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX
=faac
3782 [ "$DOTAG" = "y" ] && CHECKATOMICPARSLEY
=y
3785 if [ "$KEEPWAVS" = "y" ]; then
3786 vecho
"Setting the KEEPWAVS option, since the resulting wav files were requested..."
3790 *) log error
"Invalid OUTPUTTYPE defined"
3796 # decide which encoder
3797 case "$MP3ENCODERSYNTAX" in
3799 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
3803 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
3804 MP3ENCODER
="$TOOLAME"
3807 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
3811 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
3812 MP3ENCODER
="$BLADEENC"
3815 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
3819 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
3820 MP3ENCODER
="$XINGMP3ENC"
3823 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
3824 MP3ENCODER
="$MP3ENC"
3827 case "$OGGENCODERSYNTAX" in
3829 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
3830 OGGENCODER
="$VORBIZE"
3833 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
3834 OGGENCODER
="$OGGENC"
3837 case "$FLACENCODERSYNTAX" in
3839 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
3841 if [ "$DOREPLAYGAIN" = "y" ]; then
3842 FLACENCODEROPTS
="${FLACENCODEROPTS} --replay-gain"
3844 # FLAC streams can be encapsulated on a Ogg transport layer
3845 if echo "$FLACENCODEROPTS" |
grep -E -- "(^| )--ogg($| )" > /dev
/null
2>&1 ;then
3846 log error
"FLAC on an Ogg container is not yet supported"
3847 log error
"due to problem with adding comments to such files"
3849 FLACOUTPUTCONTAINER
=ogg
3851 FLACOUTPUTCONTAINER
=flac
3855 case "$SPEEXENCODERSYNTAX" in
3857 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
3858 SPEEXENCODER
="$SPEEXENC"
3861 case "$MPPENCODERSYNTAX" in
3863 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
3864 MPPENCODER
="$MPPENC"
3867 case "$AACENCODERSYNTAX" in
3869 AACENCODEROPTS
="${AACENCODEROPTSCLI:-$AACENCOPTS}"
3870 AACENCODER
="$AACENC"
3875 if [ "$ID3TAGV" = "1" ]; then
3877 TAGGEROPTS
="$ID3OPTS"
3880 TAGGEROPTS
="$ID3V2OPTS"
3883 # NOGAP is specific to lame. Other encoders fail ...
3884 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
3885 log warning
"the NOGAP option is specific to lame. Deactivating..."
3890 case "$CUEREADERSYNTAX" in
3892 CUEREADEROPTS
="${CDROM}"
3897 # which information retrieval tool are we using?
3903 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
3904 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
3905 log error
"FLAC on an Ogg container is not yet supported"
3906 log error
"due to problem with adding comments to such files"
3908 OGGOUTPUTCONTAINER
=ogg.ogg
3909 FLACOUTPUTCONTAINER
=flac.ogg
3910 vecho warning
"modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
3913 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
3915 if [ "$ENCNICE" ]; then
3916 ENCNICE
="-n $ENCNICE"
3918 if [ "$READNICE" ]; then
3919 READNICE
="-n $READNICE"
3921 if [ "$DISTMP3NICE" ]; then
3922 DISTMP3NICE
="-n $DISTMP3NICE"
3925 # Don't check for stuff if it's not needed
3926 if [ "$REMOTEHOSTS" ]; then
3929 if [ "$DONORMALIZE" = "y" ]; then
3932 if [ "$EJECTCD" = "y" ]; then
3935 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
3936 if [ "$CDDBMETHOD" = "cddb" ]; then
3938 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
3942 if [ "$DOCUE" = "y" ]; then
3946 if [ X
"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
3947 case "$CDROMREADERSYNTAX" in
3948 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
3949 ### FIXME ### translate "cue2discid" from python to bash
3950 flac
) NEEDMETAFLAC
=y
; NEEDCUE2DISCID
=y
; CDSPEEDVALUE
="" ;;
3955 ###USEPIPESSUPPORT###
3957 # Rippers with USEPIPE support
3958 # FIXME # Include here all the rippers we can figure out support pipes
3959 PIPERIPPER_cdparanoia
="-"
3960 PIPERIPPER_debug
="-"
3961 PIPERIPPER_flac
="-c "
3963 # Encoders with USEPIPE support
3964 # FIXME # Include here all the encoders we can figure out support pipes
3970 # Figure out if we can use pipes with the ripper/encoder combination
3972 if [ "$USEPIPES" = "y" ]; then
3973 PIPERIPPERSVARCHECK
="PIPERIPPER_${CDROMREADERSYNTAX}"
3976 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
3978 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
3980 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
3982 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
3984 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
3986 decho
"PIPERIPPERSVARCHECK: $( eval echo "\$
$PIPERIPPERSVARCHECK" )"
3987 if [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "$" ] || \
3988 [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "" ] ; then
3989 log error
"no support for pipes with given ripper"
3990 log error
"read the USEPIPES file from the source tarball to get help."
3991 log error
"On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
3994 decho
"PIPEENCODERSVARCHECK: $( eval echo "\$
$PIPEENCODERSVARCHECK" )"
3995 if [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "$" ] || \
3996 [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "" ] ; then
3997 log error
"no support for pipes with given encoder"
3998 log error
"read the USEPIPES file from the source tarball to help"
3999 log error
"on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
4004 # Make sure a buncha things exist
4005 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
4006 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
4007 $AACENCODER $CDDBTOOL \
4008 ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
4009 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
4010 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
4011 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
4012 ${NEEDDISKUTIL+diskutil} ${NEEDCDSPEED+$CDSPEED} \
4013 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
4014 ${NEEDMPPGAIN+$MPPGAIN} ${NEEDCUEREADER+$CUEREADER} \
4015 ${NEEDCUE2DISCID+$CUE2DISCID}
4020 if [ "$CHECKATOMICPARSLEY" = "y" ]; then
4021 if ! new_checkexec
"$ATOMICPARSLEY"; then
4022 echo "WARNING: $ATOMICPARSLEY Not Found Not Post-Tagging!"
4025 echo "Using $ATOMICPARSLEY To Tag AAC Tracks."
4029 # And last but not least, check if we can diff between files. We do not abort,
4030 # since diffing is not critical...
4031 if [ -x $
(which $DIFF) ]; then :; else
4032 vecho warning
"Disabling diff since we cannot find it in the \$PATH..."
4036 ## Now that we have metaflac, check if we need cue2discid
4037 #case $CDROMREADERSYNTAX in
4039 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | grep -E "[a-f0-9]{8}")
4040 # if [ "$TRACKINFO" = "" ]; then
4041 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
4046 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
4047 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
4048 HTTPGET
="$HTTPGET $HTTPGETOPTS"
4050 # Here it used to say:
4051 # One thousand lines in, we can start doing stuff with things
4052 # Well, right now we are at line 3737 ;)
4054 # Export needed things so they can be read in this subshell
4055 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
4056 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
4058 if [ "$DOREAD" = "y" ]; then
4059 # User-definable function to set some things. Use it for
4060 # - closing the CD tray with eject -t
4061 # - set the CD speed value with eject -x
4062 vecho
-n "Executing customizable pre-read function... "
4064 pre_read
# Execute the user-defined pre-read function. Close the CD with it.
4069 # Get ABCDETEMPDIR created and status file initialized
4072 if [ "$DOCDDB" = "y" ]; then
4073 # start with a sane default:
4074 CDDBLOCALSTATUS
=notfound
4075 if [ $CDDBUSELOCAL = "y" ]; then
4078 if checkstatus cddb-choice
> /dev
/null
; then
4081 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
4082 case "$CDDBMETHOD" in
4093 CHOICE
=$
(checkstatus cddb-choice
)
4094 if [ "$CHOICE" = 0 ] ; then
4095 # We don't have any information at all; try to fall back
4096 # to CD-Text for basic information
4097 vecho
"No CDDB information found, trying cdtext from the CD"
4103 eval "$($CDDBTOOL parse "$CDDBDATA")"
4106 # Before reading tracks, we set the speed of the device
4108 if [ X
"$CDSPEEDVALUE" != "X" ]; then
4109 case "$CDROMREADERSYNTAX" in
4110 cdparanoia|debug
) ;;
4116 # Define the first and last track, since we might need them later in several places
4117 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
4118 LASTTRACK
=$
( get_last
$TRACKQUEUE )
4120 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
4121 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
4122 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
4123 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
4126 if checkstatus onetrack
; then ONETRACK
=y
; fi
4128 if [ "$ONETRACK" = "y" ]; then
4129 # Reuse the CUEFILE in case we created it (now or in a previous run)
4130 if CUEFILE
=$
(checkstatus cuefile
); then
4135 # Create playlist if needed (backgroundable) and start reading in tracks
4139 if [ ! "$ONETRACK" = "y" ]; then
4140 if [ "$DOPLAYLIST" = "y" ]; then
4141 echo Creating playlist...
>&2
4146 # For the lowdisk option, only one program is running at once so the encoder
4147 # can be unsilenced right away.
4148 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
4149 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4152 if [ "$ONETRACK" = "y" ]; then
4153 TRACKS
="$FIRSTTRACK"
4154 if [ "$USEPIPES" = "y" ]; then
4155 if checkstatus readencodetrack-
$FIRSTTRACK; then :; else
4156 do_cdread onetrack
$FIRSTTRACK $LASTTRACK | do_encode
$FIRSTTRACK %local0
% > /dev
/null
2>&1
4159 if checkstatus readtrack-
$FIRSTTRACK; then :; else
4160 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
4164 for UTRACKNUM
in $TRACKQUEUE
4166 if [ "$DOREAD" = "y" ]; then
4167 if [ "$USEPIPES" = "y" ]; then
4168 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
4169 # Read, pipe, shut up!
4170 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
4173 if checkstatus readtrack-
$UTRACKNUM; then :; else
4174 do_cdread
$UTRACKNUM
4176 if [ "$?" != "0" ]; then
4177 # CD read failed - don't give the goahead to
4184 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ]; then
4187 # If we are not reading, set the encode output to loud already, so
4188 # that we can see the output of the first track.
4189 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
4190 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4192 echo NEXTTRACK
# Get the encoder machine churning again
4193 if [ "$DOREAD" = "y" ]; then
4194 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
4195 until checkstatus encodetrack-
$UTRACKNUM
4197 if checkerrors encodetrack-
$UTRACKNUM; then
4208 # Now that we're done the encoding can be loud again -
4209 # if we're not using SMP.
4210 if [ "$MAXPROCS" = "1" ]; then
4211 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
4214 # All tracks read, start encoding.
4215 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
4219 # Execute the user-defined post_read function before ejecting CD
4222 # We are now finished with the cdrom - it can be safely ejected. Note that
4223 # abcde will not have completed yet.
4224 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
4225 # We check if the disk we are processing is actually the disk inside the
4226 # CD tray. If not, we do not eject the CD, since it might be so that the
4227 # user ejected it manually.
4228 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
4229 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
4230 # More FreeBSD bits.
4231 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
4232 # FreeBSD eject uses the EJECT environment variable to name the CDROM
4233 # but in this script EJECT is in the envionment and names the program
4236 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
4237 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
4238 $eject $EJECTOPTS $cd
4239 elif [ X
"$(uname)" = X
"Darwin" ] ; then
4240 diskutil eject
${CDROM#/dev/} 0
4242 $EJECT $EJECTOPTS "$CDROM"
4249 ## Do we need to pre-process
4250 #if [ x"$PREPROCESS" = "x" ] ; then
4253 # for PRETRACKNUM in $TRACKQUEUE
4256 # if [ "$GOAHEAD" = "NO" ]; then break; fi
4258 # until [ $PREPROCEED ]
4260 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
4261 # # all locations are working, wait and try again later
4262 # if [ ! $PREPROCEED ]; then sleep 3; fi
4264 # ( do_preprocess $PRETRACKNUM
4272 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
4274 if [ "$BATCHNORM" = "y" ] ||
[ "$NOGAP" = "y" ]; then
4275 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
4276 if [ "$GOAHEAD" = "NO" ]; then break; fi
4277 for LASTTRACK
in $TRACKQUEUE; do :; done
4278 if checkstatus readtrack-
$LASTTRACK; then
4279 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
4280 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
4281 if checkerrors batch-normalize
; then exit 1; fi
4283 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
4284 if [ "$DONORMALIZE" = "y" ]; then
4285 for UTRACKNUM
in $TRACKQUEUE
4287 if checkstatus readtrack-
$UTRACKNUM; then
4288 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
4292 if checkstatus encodetrack-
$LASTTRACK; then :; else do_nogap_encode
; fi
4293 if checkerrors nogap-encode
; then exit 1; fi
4298 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
4299 if [ "$ONETRACK" = "y" ] ; then
4300 TRACKQUEUE
="$FIRSTTRACK"
4301 TRACKS
="$FIRSTTRACK"
4304 # Do the encoding, including parallelization of remote encoding
4305 # Figure out where each track is going to be encoded
4306 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
4307 if [ "$MAXPROCS" != "0" ]; then
4308 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
4310 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
4314 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
4315 for UTRACKNUM
in $TRACKQUEUE
4318 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
4319 if [ "$GOAHEAD" = "NO" ]; then break; fi
4320 # find out where this track is to be encoded
4321 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4322 # Make sure we have a place to encode this, if not, exit stage right
4323 if [ -z "$ENCODELOCATIONS" ]; then
4329 for LOCATION
in $ENCODELOCATIONS
4331 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
4332 # check first if a track has ever been assigned to this location
4333 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
4334 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
4335 if checkerrors encodetrack-
$PREVIOUSTRACK; then
4336 for TEMPLOCATION
in $ENCODELOCATIONS
4338 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4339 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
4342 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
4347 # We're still here, this location must have been previously assigned,
4348 # and last completed without error - check if it's done with the
4349 # previous track yet
4350 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
4352 # all locations are working, wait and try again later
4353 if [ ! $PROCEED ]; then sleep 3; fi
4355 # Record the location we're about to encode the next track at
4356 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4358 # Don't proceed with the rest of the loop if we can't encode
4359 if [ "$ABORT" ]; then continue; fi
4360 ## FIXME ## Add here
4361 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4362 # Set TRACKNUM, TRACKNAME
4363 if [ -e "$CDDBDATA" ]; then
4364 if [ "$ONETRACK" = "y" ]; then
4366 TRACKNUM
="$FIRSTTRACK"
4370 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
4371 getcddbinfo TRACKNAME
4375 # You can't encode a file which needs to be normalized before finishing
4376 # You can't tag a file before it's finished encoding -
4377 # thus all of this is backgrounded together
4379 if [ "$DONORMALIZE" = "y" ]; then
4380 if checkstatus readtrack-
$UTRACKNUM; then
4381 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
4384 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4385 if checkstatus readtrack-
$UTRACKNUM; then
4386 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4387 if [ "$DONORMALIZE" = "y" ]; then
4388 if checkstatus normalizetrack-
$UTRACKNUM; then
4389 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
4392 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
4396 if [ "$DOTAG" = "y" ]; then
4397 if checkstatus encodetrack-
$UTRACKNUM; then
4398 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
4400 # Lets tag the cue file
4401 if checkstatus cleancuefile
>/dev
/null
; then :; else
4402 if checkstatus cuefile
>/dev
/null
; then
4407 if [ "$DOMOVE" = "y" ]; then
4408 if checkstatus tagtrack-
$UTRACKNUM; then
4409 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
4416 # Go through it again and make sure there's no distmp3 stragglers, otherwise
4417 # we'll delete the files they're working on
4418 # Do NOT play ball if there is no ball to play (so ABORT if needed)
4419 ## FIXME ## Check also for files which are encoded using PIPEs.
4420 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
4425 for LOCATION
in $ENCODELOCATIONS
4427 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
4428 # "How can he give us a status update, if he's DEAD?"
4429 if checkstatus encodetrack-
$CHECKTRACK; then
4432 # Nothing to see here please go quietly back to your homes
4433 if [ -z "$CHECKTRACK" ]; then continue; fi
4434 # You're still here? Maybe there is something...
4435 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
4438 if [ ! $PROCEED ]; then sleep 5; fi
4441 # If the above didn't catch the stragglers, this will
4443 if [ "$DOREPLAYGAIN" = "y" ]; then
4447 # Execute the user-defined post_encode function before cleaning up
4450 # Check to see if run_command logged any errors
4451 if [ -f "$ABCDETEMPDIR/errors" ]; then
4452 log error
"The following commands failed to run:"
4453 cat "$ABCDETEMPDIR/errors"
4457 if [ "$KEEPWAVS" = "y" ];then
4461 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
4462 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
4463 ENCODED_FORMATS
=$
(grep -E "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f2 |
sort -u |
tr '\n' '|')
4464 MOVED_FORMATS
=$
(grep -E "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f3 |
sort -u |
tr '\n' '|')
4465 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
4466 log warning
"The encoded formats does not match with the moved ones"
4467 log warning
"Formats encoded: $( echo $ENCODED_FORMATS | tr "|
" " " )"
4468 log warning
"Formats moved: $( echo $MOVED_FORMATS | tr "|
" " " )"
4469 log warning
"Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
4473 if [ "$DOCLEAN" = "y" ]; then
4474 # Wipe all the evidence
4475 # Gimme gimme gimme some more time!
4477 rm -rf "$ABCDETEMPDIR"
4480 echo "Finished. Not cleaning $ABCDETEMPDIR."