2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
4 # This code is hereby licensed for public consumption under either the
5 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
7 # You should have received a copy of the GNU General Public License along
8 # with this program; if not, write to the Free Software Foundation, Inc.,
9 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
16 VERSION
='2.3.99-$Revision$'
20 echo "This is abcde v$VERSION."
21 echo "Usage: abcde [options] [tracks]"
23 echo "-1 Encode the whole CD in a single file"
24 echo "-a <action1[,action2]...>"
25 echo " Actions to perform:"
26 echo " cddb,read,normalize,encode,tag,move,replaygain,playlist,clean"
27 #echo "-A Experimental actions (retag, transcode)"
28 echo "-b Enable batch normalization"
29 #echo "-B Disable batch replaygain (do file by file)"
31 echo " Specify a configuration file (overrides system and user config files)"
33 echo " Specify discid to resume from (only needed if you no longer have the cd)"
35 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
36 echo "-D Debugging mode (equivalent to sh -x abcde)"
37 echo "-e Erase encoded track information from status file"
38 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
39 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
40 echo "-h This help information"
41 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
42 echo "-j <#> Number of encoder processes to run at once (localhost)"
43 echo "-k Keep the wav tracks for later use"
44 echo "-l Use low disk space algorithm"
45 echo "-L Use local CDDB storage directory"
46 echo "-n No lookup. Don't query CDDB, just create and use template"
47 echo "-N Noninteractive. Never prompt for anything"
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 "-o <type1[,type2]...>"
52 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
53 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
54 echo "-P Use UNIX pipes to read+encode without wav files"
55 echo "-r <host1[,host2]...>"
56 echo " Also encode on these remote hosts"
57 echo "-R Use local CDDB in recursive mode"
59 echo " Show dielfs from the CDDB info (year,genre)"
60 echo "-S <#> Set the CD speed"
61 echo "-t <#> Start the track numbering at a given number"
62 echo "-T <#> Same as -t but modifies tag numbering"
63 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
64 echo "-v Show version number and exit"
65 echo "-V Be a bit more verbose about what is happening behind the scenes"
66 echo "-x Eject CD after all tracks are read"
68 echo " Add a comment to the CD tracks"
69 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
70 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
72 echo "Tracks is a space-delimited list of tracks to grab."
73 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
75 #echo "Double hyphens are used to concatenate tracks"
80 echo "$@" >> "$ABCDETEMPDIR/status"
83 # log [level] [message]
85 # log outputs the right message in a common format
91 error
) echo "[ERROR] abcde: $@" >&2 ;;
92 warning
) echo "[WARNING] $@" >&2 ;;
93 info
) echo "[INFO] $@" ;;
97 # Funtions to replace the need of seq, which is too distribution dependant.
101 while [ $i -ne `expr $2 + 1` ]
111 if echo $i |
grep "[[:digit:]]" > /dev
/null
2>&1 ; then
112 while [ $i -ne `expr $2 + 1` ]
119 log error
"syntax error while processing track numbers"
124 # Functions to replace the need of awk {print $1} and {print $NF}
127 if [ X
"$1" = "X" ]; then
128 for first
in `cat`; do
139 if [ X
"$1" = "X" ]; then
140 for stdin
in `cat`; do
144 for last
in $@
; do :; done
149 # checkstatus [blurb]
150 # Returns "0" if the blurb was found, returns 1 if it wasn't
151 # Puts the blurb content, if available, on stdout.
152 # Otherwise, returns "".
155 # Take the last line in the status file if there's multiple matches
157 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
159 if [ -z "$BLURB" ]; then
164 # See if there's a = in it
165 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
166 echo "$(echo $BLURB | cut -f2- -d=)"
172 # checkwarnings [blurb]
173 # Returns "0" if the blurb was found (meaning there was an warning),
174 # returns 1 if it wasn't (yes this is a little backwards).
175 # Does not print the blurb on stdout.
176 # Otherwise, returns "".
179 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
182 # Take the last line in the status file if there's multiple matches
184 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
186 if [ -z "$BLURB" ]; then
187 # negative, we did not have a negative...
190 # affirmative, we had a negative...
195 # checkerrors [blurb]
196 # Returns "0" if the blurb was found (meaning there was an error),
197 # returns 1 if it wasn't (yes this is a little backwards).
198 # Does not print the blurb on stdout.
199 # Otherwise, returns "".
202 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
205 # Take the last line in the status file if there's multiple matches
207 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
209 if [ -z "$BLURB" ]; then
210 # negative, we did not have a negative...
213 # affirmative, we had a negative...
219 # Finds the right pager in the system to display a file
223 # Use the debian sensible-pager wrapper to pick the pager
224 # user has requested via their $PAGER environment variable
225 if [ -x "/usr/bin/sensible-pager" ]; then
226 /usr
/bin
/sensible-pager
"$PAGEFILE"
227 elif [ -x "$PAGER" ]; then
228 # That failed, try to load the preferred editor, starting
229 # with their PAGER variable
231 # If that fails, check for less
232 elif [ -x /usr
/bin
/less ]; then
233 /usr
/bin
/less -f "$PAGEFILE"
234 # more should be on all UNIX systems
235 elif [ -x /bin
/more ]; then
236 /bin
/more "$PAGEFILE"
238 # No bananas, just cat the thing
243 # run_command [blurb] [command...]
244 # Runs a command, silently if necessary, and updates the status file
249 # See if this is supposed to be silent
250 if [ "$(checkstatus encode-output)" = "loud" ]; then
254 # Special case for SMP, since
255 # encoder output is never displayed, don't mute echos
256 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
265 normalize|normalize-audio
)
266 if [ "$RETURN" = "2" ]; then
267 # File was already normalized.
272 if [ "$RETURN" != "0" ]; then
273 # Put an error in the errors file. For various reasons we
274 # can't capture a copy of the program's output but we can
275 # log what we attempted to execute and the error code
276 # returned by the program.
277 if [ "$BLURB" ]; then
280 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
281 return $RETURN # Do not pass go, do not update the status file
283 if [ "$BLURB" ]; then
284 echo $BLURB >> "$ABCDETEMPDIR/status"
288 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
289 # distributed under the terms of the GNU GPL v2 or later, at your option
291 # Function to determine if a word contains a slash.
300 # Function to give the relative path from one file to another.
301 # Usage: relpath fromfile tofile
302 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
303 # (the result would be Album/Song.mp3)
304 # Output is relative path to $2 from $1 on stdout
306 # This code has the following restrictions:
307 # Multiple ////s are not collapsed into single /s, with strange effects.
308 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
309 # If FR is a directory it must have a trailing /
317 /*) ;; # No processing is needed for absolute paths
319 # Loop through common prefixes, ignoring them.
320 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
322 FR
="$(echo "$FR" | cut -d/ -f2-)"
323 TO
="$(echo "$TO" | cut -d/ -f2-)"
325 # Loop through directory portions left in FR, adding appropriate ../s.
328 FR
="$(echo "$FR" | cut -d/ -f2-)"
339 if [ ! "$@" = "" ]; then
340 # Cut off any command-line option we added in
341 X
=$
(echo $@ | cut
-d' ' -f2)
342 if [ "$(which $X)" = "" ]; then
344 elif [ ! -x $
(which $X) ]; then
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X
=$
(echo $@ | cut
-d' ' -f2)
356 # Test for built-in abcde.function
357 [ "$X" != "${X#abcde.}" ] && type $X >/dev
/null
2>&1 && return
358 if [ "$(which $X)" = "" ]; then
359 log error
"$X is not in your path." >&2
360 log info
"Define the full path to the executable if it exists on your system." >&2
362 elif [ ! -x "$(which $X)" ]; then
363 log error
"$X is not executable." >&2
369 # diffentries <filename> <max_value> <entry1>,<entry2>
370 # max_value: the range of entries goes from 1 to <max_value>
375 local CDDBDIFFCHOICES
=$1
377 local CDDBDIFFCHOICE
="$@"
378 if [ ! X
"$DIFF" = "X" ]; then
379 PARSECHOICE1
=$
(echo $CDDBDIFFCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
380 PARSECHOICE2
=$
(echo $CDDBDIFFCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
381 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
382 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
383 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
384 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
386 # We parse the 2 choices to diff, store them in temporary files and diff them.
387 for PARSECHOICE
in $
(echo $CDDBDIFFCHOICE |
tr , \
); do
388 do_cddbparse
"$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
390 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
391 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
392 if [ $
(cat "$ABCDETEMPDIR/$FILENAME.diff" |
wc -l) -ge 24 ]; then
393 page
"$ABCDETEMPDIR/$FILENAME.diff"
395 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
399 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
404 # Finds an specific field from cddbinfo
409 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
412 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
418 # Get the track number we are going to use for different actions
421 if [ -n "$STARTTRACKNUMBER" ] ; then
422 # Get the trackpadding from the current track
423 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
424 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
426 TRACKNUM
=${UTRACKNUM}
432 # Calculate cddb disc ids without requiring specialized helper programs.
433 # largely copied from cd-discid and musicbrainz examples. some of the steps
434 # don't make sense, but they're necessary to match the ids generated by other
437 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
438 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
439 # 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
440 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
441 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
442 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
444 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
447 if [ X
"$LEADOUT" = "X" ]; then
448 log warning
"Error trying to calculate disc ids without lead-out information."
452 # default to a two second lead-in
454 LEADIN
=${LEADIN:=150}
456 # number of cdframes per second
459 # reset cddb checksum for cddb disc-id calululation
463 for OFFSET
in $
(echo $OFFSETS)
465 COOKEDOFFSETS
="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
467 OFFSETTIME
=$
(( ($OFFSET + $LEADIN) / $CDFRAMES ))
468 while [ $OFFSETTIME -gt 0 ]; do
469 CDDBCKSUM
=$
(($CDDBCKSUM + $OFFSETTIME % 10))
470 OFFSETTIME
=$
(($OFFSETTIME / 10))
475 COOKEDOFFSETS
="${COOKEDOFFSETS:1}" # eat the leading space
477 PREGAP
=$
(($
(echo $OFFSETS | cut
-f1 -d' ')))
478 TOTALTIME
=$
(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
480 printf -v HEXSUM
"%08lx" $
(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
481 TRACKINFO="${HEXSUM} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
486 if checkstatus replaygain; then :; else
487 run_command "" echo "Adding replygain information..."
488 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
492 OUTPUT=$OGGOUTPUTCONTAINER
495 OUTPUT=$FLACOUTPUTCONTAINER
503 for UTRACKNUM in $TRACKQUEUE
505 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
506 getcddbinfo TRACKNAME
508 TRACKFILE="$(mungefilename "$TRACKNAME")"
509 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
510 ALBUMFILE="$(mungefilename "$DALBUM")"
512 if [ "$ONETRACK" = "y" ]; then
513 if [ "$VARIOUSARTISTS" = "y" ]; then
514 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
516 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
519 if [ "$VARIOUSARTISTS" = "y" ]; then
520 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
522 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
525 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
526 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
530 run_command replaygain-flac nice $ENCNICE $METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
533 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN --album "${OUTPUTFILES[@]}"
536 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN -a "${OUTPUTFILES[@]}"
539 run_command replaygain-mpc nice $ENCNICE $MPPGAIN --auto "${OUTPUTFILES[@]}"
544 if checkerrors "replaygain-.{3,6}"; then :; else
545 run_command replaygain true
550 # This code splits the a Various Artist track name from one of the following
553 # forward: Artist / Track
554 # forward-dash: Artist - Track
555 # reverse: Track / Artist
556 # reverse-dash: Track - Artist
557 # colon: Artist: Track
558 # trailing-paren: Artist (Track)
561 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
564 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
565 case "$VARIOUSARTISTSTYLE" in
567 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
568 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
569 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
572 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
573 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
574 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
577 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
578 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
579 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
582 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
583 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
584 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
587 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
588 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
589 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
592 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
593 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
594 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
597 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
598 TRACKARTIST="Various"
600 TRACKARTIST="$DARTIST"
605 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
609 "classic rock") id=1 ;;
627 "industrial") id=19 ;;
628 "alternative") id=20 ;;
630 "death metal") id=22 ;;
632 "soundtrack") id=24 ;;
633 "euro-techno") id
=25 ;;
637 "jazz+funk") id
=29 ;;
640 "classical") id
=32 ;;
641 "instrumental") id
=33 ;;
645 "sound clip") id
=37 ;;
648 "alt. rock") id
=40 ;;
653 "meditative") id
=45 ;;
654 "instrum. pop") id
=46 ;;
655 "instrum. rock") id
=47 ;;
659 "techno-indust.") id
=51 ;;
660 "electronic") id
=52 ;;
662 "eurodance") id
=54 ;;
664 "southern rock") id
=56 ;;
669 "christian rap") id
=61 ;;
670 "pop/funk"|
"pop / funk") id
=62 ;;
672 "native american") id
=64 ;;
675 "psychadelic") id
=67 ;;
677 "showtunes") id
=69 ;;
681 "acid punk") id
=73 ;;
682 "acid jazz") id
=74 ;;
686 "rock & roll") id
=78 ;;
687 "hard rock") id
=79 ;;
689 "folk/rock") id
=81 ;;
690 "national folk") id
=82 ;;
697 "bluegrass") id
=89 ;;
698 "avantgarde") id
=90 ;;
699 "gothic rock") id
=91 ;;
700 "progress. rock") id
=92 ;;
701 "psychadel. rock") id
=93 ;;
702 "symphonic rock") id
=94 ;;
703 "slow rock") id
=95 ;;
706 "easy listening") id
=98 ;;
712 "chamber music") id
=104 ;;
714 "symphony") id
=106 ;;
715 "booty bass") id
=107 ;;
717 "porn groove") id
=109 ;;
719 "slow jam") id
=111 ;;
723 "folklore") id
=115 ;;
725 "power ballad") id
=117 ;;
726 "rhythmic soul") id
=118 ;;
727 "freestyle") id
=119 ;;
729 "punk rock") id
=121 ;;
730 "drum solo") id
=122 ;;
731 "a capella") id
=123 ;;
732 "euro-house") id
=124 ;;
733 "dance hall") id
=125 ;;
735 "drum & bass") id
=127 ;;
736 "club-house") id
=128 ;;
737 "hardcore") id
=129 ;;
741 "negerpunk") id
=133 ;;
742 "polsk punk") id
=134 ;;
744 "christian gangsta rap") id
=136 ;;
745 "heavy metal") id
=137 ;;
746 "black metal") id
=138 ;;
747 "crossover") id
=139 ;;
748 "contemporary christian")id
=140 ;;
749 "christian rock") id
=141 ;;
750 "merengue") id
=142 ;;
752 "thrash metal") id
=144 ;;
755 "synthpop") id
=147 ;;
756 "rock/pop"|
"rock / pop") id
=148 ;;
763 # do_tag [tracknumber]
764 # id3 tags a filename
766 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
767 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
770 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
771 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
772 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
773 # If we want to start the tracks with a given number, we need to modify the
774 # TRACKNUM value before evaluation
775 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
778 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
782 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
783 GENREID
=$
(do_getgenreid
"${CDGENRE}")
788 # FIXME # track numbers in mp3 come with 1/10, so we cannot
789 # happily substitute them with $TRACKNUM
790 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $TAGGER $TAGGEROPTS \
791 --comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
792 -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
793 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
794 "${ENCODING:+--set-encoding=$ENCODING}" \
795 "$ABCDETEMPDIR/track$1.$OUTPUT"
797 # FIXME # Still not activated...
799 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
800 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" -y "$CDYEAR" \
801 -g "$GENREID" -k "${TRACKNUM:-$1}" \
802 "$ABCDETEMPDIR/track$1.$OUTPUT"
805 # FIXME # track numbers in mp3 come with 1/10, so we cannot
806 # happily substitute them with $TRACKNUM
807 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
808 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
809 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
810 "$ABCDETEMPDIR/track$1.$OUTPUT"
815 case "$OGGENCODERSYNTAX" in
817 # vorbiscomment can't do in-place modification, mv the file first
818 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
819 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
822 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
823 echo ARTIST
="$TRACKARTIST"
825 echo TITLE
="$TRACKNAME"
826 if [ -n "$CDYEAR" ]; then
829 if [ -n "$CDGENRE" ]; then
830 echo GENRE
="$CDGENRE"
832 echo TRACKNUMBER
=${TRACKNUM:-$1}
833 echo CDDB
=$CDDBDISCID
834 if [ "$(eval echo ${COMMENT})" != "" ]; then
835 case "$COMMENTOUTPUT" in
836 *=*) echo "$COMMENTOUTPUT";;
837 *) echo COMMENT
="$COMMENTOUTPUT";;
840 ) | run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
841 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
842 # Doublecheck that the commented file was created successfully before wiping the original
843 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
844 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
846 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
853 echo ARTIST
="$TRACKARTIST"
855 echo TITLE
="$TRACKNAME"
856 if [ -n "$CDYEAR" ]; then
859 if [ -n "$CDGENRE" ]; then
860 echo GENRE
="$CDGENRE"
862 echo TRACKNUMBER
="${TRACKNUM:-$1}"
863 echo CDDB
="$CDDBDISCID"
864 if [ "$(eval echo ${COMMENT})" != "" ]; then
865 case "$COMMENTOUTPUT" in
866 *=*) echo "$COMMENTOUTPUT";;
867 *) echo COMMENT
="$COMMENTOUTPUT";;
870 ) | run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
873 run_command tagtrack-
$OUTPUT-$1 true
876 run_command tagtrack-
$OUTPUT-$1 true
879 run_command tagtrack-
$OUTPUT-$1 true
882 run_command tagtrack-
$OUTPUT-$1 true
886 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
887 run_command tagtrack-
$1 true
894 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
897 # The commands here don't go through run_command because they're never supposed to be silenced
898 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
899 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
903 case "$MP3ENCODERSYNTAX" in
908 for UTRACKNUM
in $TRACKQUEUE
910 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
912 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
914 if [ "$RETURN" != "0" ]; then
915 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
917 for UTRACKNUM
in $TRACKQUEUE
919 run_command encodetrack-
$OUTPUT-$UTRACKNUM true
920 #run_command encodetrack-$UTRACKNUM true
929 if checkerrors
"nogap-encode"; then :; else
930 if [ ! "$KEEPWAVS" = "y" ] ; then
931 if [ ! "$KEEPWAVS" = "move" ] ; then
936 # Other encoders fall through to normal encoding as the tracks
937 # have not been entered in the status file.
940 # do_encode [tracknumber] [hostname]
941 # If no hostname is specified, encode locally
943 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
946 if [ "$USEPIPES" = "y" ]; then
949 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
952 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
955 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
958 TEMPARG
="PIPE_$SPEEXENCODER"
961 TEMPARG
="PIPE_$MPPENCODER"
964 TEMPARG
="PIPE_$MPPENCODER"
967 IN
="$( eval echo "\$
$TEMPARG" )"
969 IN
="$ABCDETEMPDIR/track$1.wav"
972 case "$MP3ENCODERSYNTAX" in
973 # FIXME # check if mp3enc needs -if for pipes
974 # FIXME # I have not been able to find a working mp3enc binary
988 # We need IN to proceed, if we are not using pipes.
989 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
990 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
994 OUTPUT
=$OGGOUTPUTCONTAINER
997 OUTPUT
=$FLACOUTPUTCONTAINER
1003 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
1004 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-
$OUTPUT-$1 ; then
1007 if [ X
"$USEPIPES" = "Xy" ]; then
1009 # We need a way to store the creation of the files when using PIPES
1010 RUN_COMMAND_PIPES
="run_command encodetrack-$OUTPUT-$1 true"
1011 # When pipping it does not make sense to have a higher nice for
1012 # reading than for encoding, since it will be hold by the
1013 # encoding process. Setting an effective nice, to calm down a
1014 # bit the reading process.
1015 EFFECTIVE_NICE
=$READNICE
1017 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1018 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
1019 EFFECTIVE_NICE
=$ENCNICE
1025 case "$MP3ENCODERSYNTAX" in
1026 lame|toolame|gogo
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1027 bladeenc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1028 l3enc|xingmp3enc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1029 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1030 mp3enc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1034 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
1041 case "$OGGENCODERSYNTAX" in
1042 vorbize
) $RUN_COMMAND nice
$EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1043 oggenc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1047 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
1054 case "$FLACENCODERSYNTAX" in
1055 flac
) $RUN_COMMAND nice
$EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1060 vecho
"$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1061 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
1066 if [ "$(eval echo ${COMMENT})" != "" ]; then
1069 *) COMMENT
="COMMENT=$COMMENT" ;;
1071 COMMENT
="--comment \"$COMMENT\""
1073 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1074 if [ ! "$DOTAG" = "y" ]; then
1075 $RUN_COMMAND nice
$EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
1077 $RUN_COMMAND nice
$EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1081 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1083 # I tried compiling the mppenc from corecodecs.org and got some
1084 # errors, so I have not tried it myself.
1085 ## FIXME ## Needs some cleanup to determine if an empty tag sent
1086 ## FIXME ## to the encoder ends up empty.
1087 $RUN_COMMAND nice
$EFFECTIVE_NICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
1090 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1091 if [ ! "$DOTAG" = "y" ]; then
1092 $RUN_COMMAND nice
$EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
1095 $RUN_COMMAND nice
$ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1099 # In case of wav output we need nothing. Just keep the wavs.
1104 # Only remove .wav if the encoding succeeded
1105 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
1106 run_command encodetrack-
$1 true
1107 if [ ! "$KEEPWAVS" = "y" ] ; then
1108 if [ ! "$KEEPWAVS" = "move" ] ; then
1114 run_command
"" echo "HEH! The file we were about to encode disappeared:"
1115 run_command
"" echo ">> $IN"
1116 run_command encodetrack-
$1 false
1120 # do_preprocess [tracknumber]
1122 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1125 # IN="$ABCDETEMPDIR/track$1.wav"
1126 # # We need IN to proceed.
1127 # if [ -s "$IN" ] ; then
1128 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1130 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1131 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1132 # case "$POSTPROCESSFORMAT" in
1134 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1136 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1138 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1140 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1142 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1145 # # Only remove .wav if the encoding succeeded
1146 # if checkerrors "preprocess-(.{3,4})-$1"; then
1147 # run_command preprocess-$1 false
1149 # run_command preprocess-$1 true
1152 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1153 # echo "HEH! The file we were about to pre-process disappeared:"
1156 # run_command preprocess-$1 false
1161 # do_postprocess [tracknumber]
1163 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1166 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1168 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1169 # # We need IN to proceed.
1170 # if [ -s "$IN" ] ; then
1171 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1172 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1173 # case "$POSTPROCESSFORMAT" in
1175 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1177 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1179 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1181 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1183 # # Only remove .wav if the encoding succeeded
1184 # if checkerrors "postprocess-(.{3,4})-$1"; then
1185 # run_command postprocess-$1 false
1187 # run_command postprocess-$1 true
1190 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1191 # echo "HEH! The file we were about to post-process disappeared:"
1194 # run_command postprocess-$1 false
1209 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1213 # The commands here don't go through run_command because they're never supposed to be silenced
1214 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1219 for UTRACKNUM
in $TRACKQUEUE
1221 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1223 # FIXME # Hard-coded batch option!
1224 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1226 if [ "$RETURN" != "0" ]; then
1227 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1229 for UTRACKNUM
in $TRACKQUEUE
1231 echo normalizetrack-
$UTRACKNUM >> status
1237 # do_batch_normalize
1239 # NORMALIZER, NORMALIZEROPTS
1240 do_batch_normalize
()
1242 # The commands here don't go through run_command because they're never supposed to be silenced
1243 echo "Batch normalizing tracks: $TRACKQUEUE"
1248 for UTRACKNUM
in $TRACKQUEUE
1250 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1252 # XXX: Hard-coded batch option!
1253 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1255 if [ "$RETURN" != "0" ]; then
1256 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1258 for UTRACKNUM
in $TRACKQUEUE
1260 echo normalizetrack-
$UTRACKNUM >> status
1266 # do_normalize [tracknumber]
1268 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1271 IN
="$ABCDETEMPDIR/track$1.wav"
1272 if [ -e "$IN" ] ; then
1273 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1274 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1276 if [ "$(checkstatus encode-output)" = "loud" ]; then
1277 echo "HEH! The file we were about to normalize disappeared:"
1280 run_command normalizetrack-
$1 false
"File $IN was not found"
1284 # do_move [tracknumber]
1285 # Deduces the outfile from environment variables
1286 # Creates directory if necessary
1288 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1291 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1293 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1294 # defined the OUTPUTFILE:
1297 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1298 # Munge filenames as follows:
1303 # Eat control characters
1304 ALBUMFILE
="$(mungefilename "$DALBUM")"
1305 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1306 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1307 GENRE
="$(mungegenre "$GENRE")"
1308 YEAR
=${CDYEAR:-$CDYEAR}
1309 # If we want to start the tracks with a given number, we need to modify
1310 # the TRACKNUM value before evaluation
1312 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1313 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1314 if [ "$ONETRACK" = "y" ]; then
1315 if [ "$VARIOUSARTISTS" = "y" ]; then
1316 OUTPUTFILE
="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1318 OUTPUTFILE
="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1321 if [ "$VARIOUSARTISTS" = "y" ]; then
1322 OUTPUTFILE
="$(eval echo \""$VAOUTPUTFORMAT"\")"
1324 OUTPUTFILE
="$(eval echo \""$OUTPUTFORMAT"\")"
1327 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1328 # Once we know the specific output was successful, we can change
1329 # the OUTPUT to the value containing the container
1332 OUTPUT
=$OGGOUTPUTCONTAINER
1335 OUTPUT
=$FLACOUTPUTCONTAINER
1341 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1342 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1345 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1346 # FIXME # introduce warnings?
1349 # mkdir -p shouldn't return an error if the directory already exists
1350 mkdir
-p "$OUTPUTFILEDIR"
1351 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1352 if checkstatus movetrack-output-
$OUTPUT; then :; else
1353 run_command movetrack-output-
$OUTPUT true
1358 # mkdir -p shouldn't return an error if the directory already exists
1359 mkdir
-p "$OUTPUTFILEDIR"
1360 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1361 if checkstatus movetrack-output-
$OUTPUT; then :; else
1362 run_command movetrack-output-
$OUTPUT true
1366 # Lets move the cue file
1367 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1368 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1369 if checkstatus movecue-
$OUTPUT; then :; else
1370 # Silence the Copying output since it overlaps with encoding processes...
1371 #run_command '' vecho "Copying cue file to its destination directory..."
1372 if checkstatus onetrack
>/dev
/null
; then
1375 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1376 # We dont have the dir, since it was not created before.
1379 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1382 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1383 # http://brianvictor.tripod.com/mp3cue.htm#details
1384 [a-z0-9
][a-z0-9
][a-z0-9
])
1385 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1388 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1392 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1394 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1403 # Create the playlist if wanted
1405 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1406 # VARIOUSARTISTS, OUTPUTDIR
1409 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1413 OUTPUT
=$OGGOUTPUTCONTAINER
1416 OUTPUT
=$FLACOUTPUTCONTAINER
1422 # Create a playlist file for the playlist data to go into.
1423 # We used to wipe it out if it existed. Now we request permision if interactive.
1424 for LASTTRACK
in $TRACKQUEUE; do :; done
1425 ALBUMFILE
="$(mungefilename "$DALBUM")"
1426 ARTISTFILE
="$(mungefilename "$DARTIST")"
1427 GENRE
="$(mungegenre "$GENRE")"
1428 YEAR
=${CDYEAR:-$CDYEAR}
1429 if [ "$VARIOUSARTISTS" = "y" ] ; then
1430 PLAYLISTFILE
="$(eval echo "$VAPLAYLISTFORMAT")"
1432 PLAYLISTFILE
="$(eval echo "$PLAYLISTFORMAT")"
1434 FINALPLAYLISTDIR
="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1435 mkdir
-p "$FINALPLAYLISTDIR"
1436 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1437 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1438 if [ "$INTERACTIVE" = "y" ]; then
1439 while [ "$DONE" != "y" ]; do
1441 case $ERASEPLAYLIST in
1442 e|E|a|A|k|K
) DONE
=y
;;
1450 # Once we erase the playlist, we use append to create the new one.
1451 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1453 # The playlist does not exist, so we can safelly use append to create the new list
1456 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1457 touch "$OUTPUTDIR/$PLAYLISTFILE"
1458 for UTRACKNUM
in $TRACKQUEUE
1460 # Shares some code with do_move since the filenames have to match
1461 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1462 getcddbinfo TRACKNAME
1464 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1465 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1466 ALBUMFILE
="$(mungefilename "$DALBUM")"
1467 # If we want to start the tracks with a given number, we need to modify the
1468 # TRACKNUM value before evaluation
1470 if [ "$VARIOUSARTISTS" = "y" ]; then
1471 OUTPUTFILE
="$(eval echo \""$VAOUTPUTFORMAT\"")"
1473 OUTPUTFILE
="$(eval echo \""$OUTPUTFORMAT\"")"
1475 if [ "$VARIOUSARTISTS" = "y" ]; then
1476 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1477 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1479 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1482 if [ "$PLAYLISTDATAPREFIX" ]; then
1483 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1485 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1490 ## this will convert the playlist to have CRLF line-endings, if specified
1491 ## (some hardware players insist on CRLF endings)
1492 if [ "$DOSPLAYLIST" = "y" ]; then
1493 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1494 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1495 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1497 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1502 # This function reads a cuefile on stdin and writes an extended
1503 # cddb query on stdout. Any PREGAP for track 1 is properly
1504 # handled, although cue files embedded in FLAC files do not
1505 # appear to properly store the PREGAP setting. :(
1506 abcde.cue2discid
() {
1511 while [ $val -gt 0 ] ; do
1512 ret
=$
(( $ret + ( $val % 10) ))
1513 val
=$
(( $val / 10 ))
1524 echo $
(( ((($1 * 60) + $2) * 75) + $3 ))
1534 while read line
; do
1537 TRACK
) i
=$
(( i
+ 1 ))
1539 INDEX
) if [ "$2" -eq 1 ] ; then
1541 START
=$
(( $LBA + $PREGAP + $OFFSET ))
1543 X
=$
(cddb_sum $
(( $START / 75 )) )
1547 PREGAP
) PREGAP
=$
(msf2lba
$2)
1551 LEADOUT
=$
(( $4 / 588 ))
1554 LEADIN
=$
(( $3 / 588 ))
1563 LEADOUT
=$
(( $LEADOUT + $LEADIN ))
1565 LENGTH
=$
(( $LEADOUT/75 - $TRACK1/75 ))
1566 DISCID
=$
(( ( $N % 255 ) * 2**24 |
$LENGTH * 2**8 |
$TRACKS ))
1567 printf "%08x %i" $DISCID $TRACKS
1570 while [ $j -le $TRACKS ] ; do
1571 eval echo -n "\" \$TRACK$j\""
1574 echo " $(( $LEADOUT / 75 ))"
1578 # abcde.mkcue [--wholedisk]
1579 # This creates a cuefile directly from the extended discid information
1580 # The --wholedisk option controls whether we're ripping data from the
1581 # start of track one or from the start of the disk (usually, but not
1582 # always the same thing!)
1584 # Track one leadin/pregap (if any) handeling:
1585 # --wholedisk specified:
1588 # INDEX 01 <pregap value>
1589 # Remaining track index values unchanged from disc TOC
1591 # --wholedisk not specified
1593 # PREGAP <pregap value>
1595 # Remaining track index values offset by <pregap value>
1602 printf "$1%02i:%02i:%02i\n" $
(($2/4500)) $
((($2/75)%60)) $
(($2%75))
1605 local MODE DISCID TRACKS
1609 if [ "$1" = --wholedisc ] ; then
1621 echo REM DISCID
$DISCID
1622 echo FILE
\"dummy.wav
\" WAVE
1624 if [ $1 -ne 150 ] ; then
1625 if [ $MODE = PREGAP
] ; then
1633 while [ $i -le "$TRACKS" ] ; do
1634 LBA
=$
(( $1 - $OFFSET ))
1635 printf " TRACK %02i AUDIO\n" $i
1636 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1637 if [ $MODE = PREGAP
] ; then
1638 echomsf
" PREGAP " $
(($OFFSET-150))
1640 echo " INDEX 00 00:00:00"
1643 echomsf
" INDEX 01 " $LBA
1650 # This essentially the start of things
1653 # Query the CD to get the track info, unless the user specified -C
1654 # or we are using some actions which do not need the CDDB data at all
1655 #if [ ! X"$EXPACTIONS" = "X" ]; then
1657 #elif [ -z "$DISCID" ]; then
1658 if [ -z "$DISCID" ]; then
1659 vecho
-n "Getting CD track info... "
1660 # In OSX, unmount the disc before a query
1661 if [ "$OSFLAVOUR" = "OSX" ]; then
1662 disktool
-u ${CDROM#/dev/}
1664 case "$CDROMREADERSYNTAX" in
1666 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev
/null
2>&1 ; then
1667 case "$CUE2DISCID" in
1668 # FIXME # right now we have 2 cue2discid internal
1669 # implementations: builtin and abcde.cue2discid. Test
1670 # both of them and decide which one we want to use.
1672 #vecho "Using builtin cue2discid implementation..."
1673 CUESHEET
="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1675 #TRACKS=$(echo $CUESHEET | egrep "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1677 OFFSETTIMES
=( $
(echo "$CUESHEET" |
sed -n -e's/\ *INDEX 01\ \+//p' ) )
1678 TRACKS
=${#OFFSETTIMES[@]}
1680 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1681 for OFFSETTIME
in ${OFFSETTIMES[@]}; do
1682 OFFSETS
="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1683 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1686 LEADOUT
=$
(( $
(echo "$CUESHEET" |
grep lead-out | get_last
) / 44100 * 75 ))
1687 LEADIN
=$
(( $
(echo "$CUESHEET" |
grep lead-in | get_last
) / 44100 * 75 ))
1691 #vecho "Using external python cue2discid implementation..."
1692 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" |
$CUE2DISCID)
1696 log error
"the input flac file does not contain a cuesheet."
1701 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1703 # if [ ! "$RET" = "0" ];then
1704 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1707 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1708 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1710 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | egrep -o '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1711 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1715 case "$CDDBMETHOD" in
1716 cddb
) TRACKINFO
=$
($CDDISCID "$CDROM") ;;
1717 # FIXME # musicbrainz needs a cleanup
1718 musicbrainz
) TRACKINFO
=$
($MUSICBRAINZ -c "$CDROM" ) ;;
1722 # Make sure there's a CD in there by checking cd-discid's return code
1723 if [ ! "$?" = "0" ]; then
1724 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1725 log error
"cuesheet information from the flac file could not be read."
1726 log error
"Perhaps the flac file does not contain a cuesheet?."
1729 log error
"CD could not be read. Perhaps there's no CD in the drive?"
1733 # In OSX, remount the disc again
1734 if [ "$OSFLAVOUR" = "OSX" ]; then
1735 disktool
-m ${CDROM#/dev/}
1738 DISCID
=$
(echo $TRACKINFO | cut
-f1 -d' ')
1740 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1743 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1744 # This needs to be done now because a section of the resuming code will need
1747 # get the number of digits to pad TRACKNUM with - we'll use this later
1748 # a CD can only hold 99 tracks, but since we support a feature for starting
1749 # numbering the tracks from a given number, we might need to set it as a
1750 # variable for the user to define... or obtain it somehow.
1751 if [ "$PADTRACKS" = "y" ] ; then
1755 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1756 if [ -z "$TRACKQUEUE" ]; then
1757 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1758 case "$CDROMREADERSYNTAX" in
1760 if [ "$WEHAVEACD" = "y" ]; then
1761 vecho
"Querying the CD for audio tracks..."
1762 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1764 if [ ! "$RET" = "0" ];then
1765 log warning
"something went wrong while querying the CD... Maybe a DATA CD?"
1767 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1768 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1770 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1771 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1772 echo cdparanoia-audio-tracks
=$
( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1773 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1775 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1776 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1780 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1783 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1785 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1786 log info
"The disc does not contain any tracks. Giving up..."
1789 echo -n "Grabbing entire CD - tracks: "
1790 if [ ! "$PADTRACKS" = "y" ] ; then
1791 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1793 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1795 while [ "$X" -ne "$TRACKS" ]
1797 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1798 TRACKQUEUE
=$
(echo $TRACKQUEUE $X)
1802 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1803 # User-supplied track queue.
1804 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1805 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1806 # Once cleaned, obtain the highest value in the trackqueue for number padding
1807 for LASTTRACK
in $TRACKQUEUE; do :; done
1808 if [ ! "$PADTRACKS" = "y" ] ; then
1809 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1811 # Now we normalize the trackqueue
1812 for TRACK
in $TRACKQUEUE ; do
1813 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1814 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1816 TRACKQUEUE
=$PADTRACKQUEUE
1817 echo Grabbing tracks
: "$TRACKQUEUE"
1820 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1822 # We have the discid, create a temp directory after it to store all the temp
1825 if [ -e "$ABCDETEMPDIR" ]; then
1826 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1827 # It already exists, see if it's a directory
1828 if [ ! -d "$ABCDETEMPDIR" ]; then
1829 # This is a file/socket/fifo/device/etc, not a directory
1832 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1833 echo "Please investigate, remove it, and rerun abcde." >&2
1837 # It's a directory, let's see if it's owned by us
1838 if [ ! -O "$ABCDETEMPDIR" ]; then
1839 # Nope, complain and exit
1841 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1842 echo "Please investigate, remove it, and rerun abcde." >&2
1846 # See if it's populated
1847 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1848 # Wipe and start fresh
1849 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1850 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1851 if [ "$INTERACTIVE" = "y" ]; then
1857 if [ "$ANSWER" != "y" ]; then
1860 rm -rf "$ABCDETEMPDIR" ||
exit 1
1861 mkdir
-p "$ABCDETEMPDIR"
1862 if [ "$?" -gt "0" ]; then
1863 # Directory already exists or could not be created
1864 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1868 # Everything is fine. Check for ^encodetracklocation-
1869 # and encode-output entries in the status file and
1870 # remove them. These are not relevant across sessions.
1871 if [ -f "$ABCDETEMPDIR/status" ]; then
1872 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1873 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1874 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1876 # Remove old error messages
1877 if [ -f "$ABCDETEMPDIR/errors" ]; then
1878 rm -f "$ABCDETEMPDIR/errors"
1882 # We are starting from scratch
1883 mkdir
-p "$ABCDETEMPDIR"
1884 if [ "$?" -gt "0" ]; then
1885 # Directory already exists or could not be created
1886 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1889 cat /dev
/null
> "$ABCDETEMPDIR/status"
1890 # Store the abcde version in the status file.
1891 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1893 if [ X
"$DOCUE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1894 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1895 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1896 vecho
"Creating cue file..."
1897 case $CDROMREADERSYNTAX in
1899 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
1900 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1902 log warning
"the input flac file does not contain a cuesheet."
1906 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1907 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1909 log warning
"reading the CUE sheet is still considered experimental"
1910 log warning
"and there was a problem with the CD reading. abcde will continue,"
1911 log warning
"but consider reporting the problem to the abcde author"
1917 # If we got the CDPARANOIA status and it is not recorded, save it now
1918 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1919 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
1920 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1924 # Create the discid file
1925 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1926 if checkstatus cddbmethod
> /dev
/null
2>&1 ; then :; else
1927 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
1932 # Create a proper CUE file based on the CUE file we created before.
1935 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1936 CUEFILE_OUT
=$CUEFILE_IN.out
1937 ### FIXME ### checkstatus cddb
1938 if [ -e "$CDDBDATA" ]; then
1939 vecho
"Adding metadata to the cue file..."
1940 # FIXME It doesn't preserve spaces! Why?
1941 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1943 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1944 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1945 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
1949 cat "$CUEFILE_IN" |
while read line
1951 if echo "$line" |
grep "INDEX 01" > /dev
/null
2>&1 ; then
1952 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
1953 # echo "$line" >> "$CUEFILE_OUT"
1954 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
1955 eval track
="\$TRACK$n"
1957 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
1959 # FIXME # If the lines above are uncommented, remove the line below.
1960 echo "$line" >> "$CUEFILE_OUT"
1963 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1964 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1970 # Parses a CDDB file and outputs the title and the track names.
1971 # Variables: CDDBFILE
1975 # List out disc title/author and contents
1976 if [ "$ONETRACK" = "y" ]; then
1977 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
1979 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1980 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
1981 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1982 if [ ! X
"$PARSEDYEAR" = "X" ]; then
1983 echo "Year: $PARSEDYEAR"
1986 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
1987 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
1988 if [ ! X
"$PARSEDGENRE" = "X" ]; then
1989 echo "Genre: $PARSEDGENRE"
1992 if [ ! "$ONETRACK" = "y" ]; then
1993 for TRACK
in $
(f_seq_row
1 $TRACKS)
1995 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2001 # Check for a local CDDB file, and report success
2004 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
2006 CDDBLOCALSTATUS
="notfound"
2007 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
2010 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2011 CDDBLOCALRESULTS
="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2012 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2013 if (( $
(echo "${CDDBLOCALRESULTS}" |
wc -l) == 1 )); then
2014 CDDBLOCALFILE
="${CDDBLOCALRESULTS}"
2015 CDDBLOCALMATCH
=single
2016 elif (( $
(echo "${CDDBLOCALRESULTS}" |
wc -l) > 1 )); then
2017 CDDBLOCALMATCH
=multiple
2022 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2023 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
2024 CDDBLOCALMATCH
=single
2029 # If the user has selected to check a local CDDB repo, we proceed with it
2030 case $CDDBLOCALMATCH in
2032 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2034 echo "$CDDBLOCALRESULTS" |
while read RESULT
; do
2036 # List out disc title/author and contents
2037 CDDBLOCALREAD
="$ABCDETEMPDIR/cddblocalread.$X"
2038 cat "$RESULT" > "${CDDBLOCALREAD}"
2041 do_cddbparse
"${CDDBLOCALREAD}"
2043 ##FIXME## QUICK HACK !!!!
2044 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2045 } >> "$ABCDETEMPDIR/cddblocalchoices"
2047 if [ $
(cat "$ABCDETEMPDIR/cddblocalchoices" |
wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2048 page
"$ABCDETEMPDIR/cddblocalchoices"
2050 # It's all going to fit in one page, cat it
2051 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2053 CDDBLOCALCHOICES
=$
( echo "$CDDBLOCALRESULTS" |
wc -l )
2054 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2055 CDDBLOCALCHOICENUM
=-1
2056 if [ "$INTERACTIVE" = "y" ]; then
2057 while [ $CDDBLOCALCHOICENUM -lt 0 ] ||
[ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2058 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2059 read CDDBLOCALCHOICE
2060 [ x
"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE
="1"
2061 # FIXME # Introduce diff's
2062 if echo $CDDBLOCALCHOICE |
egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2063 diffentries cddblocalread
"$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2064 elif echo $CDDBLOCALCHOICE |
egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2065 # Make sure we get a valid choice
2066 CDDBLOCALCHOICENUM
=$
(echo $CDDBLOCALCHOICE |
xargs printf %d
2>/dev
/null
)
2067 if [ $CDDBLOCALCHOICENUM -lt 0 ] ||
[ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2068 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2074 #echo "Selected ..."
2076 CDDBLOCALCHOICENUM
=1
2078 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2079 #echo "Using local copy of CDDB data"
2080 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2081 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2082 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2083 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
2084 do_cddbparse
"$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2085 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2086 CDDBLOCALSTATUS
="found"
2088 #echo "Not using local copy of CDDB data"
2089 CDDBLOCALSTATUS
="notfound"
2093 # List out disc title/author and contents
2094 do_cddbparse
"${CDDBLOCALFILE}"
2095 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2096 # echo -n "Embedded cuesheet entry found, use it? [y/n] (y): " >&2
2098 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
2100 if [ "$INTERACTIVE" = "y" ]; then
2102 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2103 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2106 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
2110 if [ "$USELOCALRESP" = "y" ]; then
2111 #echo "Using local copy of CDDB data"
2112 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2113 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2114 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2115 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
2116 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2117 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2118 CDDBLOCALSTATUS
="single"
2120 #echo "Not using local copy of CDDB data"
2121 CDDBLOCALSTATUS
="notfound"
2125 CDDBLOCALSTATUS
="notfound"
2131 do_musicbrainzstat
()
2138 # Use MBE_TOCGetCDIndexId on a perl query
2145 # Perform CDDB protocol version check if it hasn't already been done
2146 if checkstatus cddb-statcomplete
; then :; else
2147 if [ "$CDDBAVAIL" = "n" ]; then
2149 echo 503 > "$ABCDETEMPDIR/cddbstat"
2152 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
2153 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
2154 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2155 vecho
"Checking CDDB server status..."
2156 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2157 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
2158 case "$RESPONSECODE" in
2159 210) # 210 OK, status information follows (until terminating `.')
2162 501|
*) # 501 Illegal CDDB protocol level: <n>.
2163 CDDBPROTO
=`expr $CDDBPROTO - 1`
2167 if test $rc -eq 1; then
2171 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
2179 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
2180 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
2182 # Perform CDDB query if it hasn't already been done
2183 if checkstatus cddb-querycomplete
; then :; else
2184 if [ "$CDDBAVAIL" = "n" ]; then
2186 echo 503 > "$ABCDETEMPDIR/cddbquery"
2187 # The default CDDBLOCALSTATUS is "notfound"
2188 # This part will be triggered if the user CDDB repo does not
2189 # contain the entry, or if we are not trying to use the repo.
2191 vecho
"Querying the CDDB server..."
2192 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
2193 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
2194 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2200 # no match found in database,
2201 # wget/fetch error, or user requested not to use CDDB
2202 # Make up an error code (503) that abcde
2203 # will recognize in do_cddbread
2204 # and compensate by making a template
2205 echo 503 > "$ABCDETEMPDIR/cddbquery"
2207 *) # strange and unknown error
2208 echo ERRORCODE
=$ERRORCODE
2209 echo "abcde: $CDDBTOOL returned unknown error code"
2213 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
2220 # If it's not to be used, generate a template.
2221 # Then, display it (or them) and let the user choose/edit it
2222 if checkstatus cddb-readcomplete
; then :; else
2223 vecho
"Obtaining CDDB results..."
2224 # If CDDB is to be used, interpret the query results and read all
2225 # the available entries.
2226 rm -f "$ABCDETEMPDIR/cddbchoices"
2227 CDDBCHOICES
=1 # Overridden by multiple matches
2228 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
2229 case "$RESPONSECODE" in
2231 # One exact match, retrieve it
2232 # 200 [section] [discid] [artist] / [title]
2233 if checkstatus cddb-read-1-complete
; then :; else
2234 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2235 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2236 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2237 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2238 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2240 # List out disc title/author and contents
2241 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2242 for TRACK
in $
(f_seq_row
1 $TRACKS)
2244 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2246 echo >> "$ABCDETEMPDIR/cddbchoices"
2250 case "$RESPONSECODE" in
2251 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2252 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2253 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2255 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2256 # List out disc title/author and contents of template
2257 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
2259 for TRACK
in $
(f_seq_row
1 $TRACKS)
2261 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2263 echo >> "$ABCDETEMPDIR/cddbchoices"
2264 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
2265 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
2268 # Multiple exact, (possibly multiple) inexact matches
2270 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
2271 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
2272 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2273 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2274 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2276 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2278 vecho
-n "Retrieving multiple matches... "
2279 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
2280 read DISCINFO
# eat top line
2284 if checkstatus cddb-read-
$X-complete; then :; else
2285 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2286 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
2288 # List out disc title/author and contents
2289 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2290 for TRACK
in $
(f_seq_row
1 $TRACKS)
2292 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2294 echo >> "$ABCDETEMPDIR/cddbchoices"
2297 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2301 for TRACK
in $
(f_seq_row
1 $TRACKS)
2303 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2305 echo >> "$ABCDETEMPDIR/cddbchoices"
2306 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2307 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2310 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2317 if checkstatus cddb-edit
>/dev
/null
; then
2318 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2319 VARIOUSARTISTS
="$(checkstatus variousartists)"
2320 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
2323 if [ "$INTERACTIVE" = "y" ]; then
2324 # We should show the CDDB results both when we are not using the local CDDB repo
2325 # or when we are using it but we could not find a proper match
2326 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
2327 # Display the $ABCDETEMPDIR/cddbchoices file created above
2328 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2329 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2330 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2331 CHOICE
=$
(checkstatus cddb-choice
)
2332 if [ -n "$CHOICE" ] ; then
2333 case $CDDBCHOICES in
2334 -1) if head -1 "$ABCDETEMPDIR/cddbquery" |
grep "^$" > /dev
/null
2>&1 ; then
2335 log error
"CDDB query failed!"
2338 cat "$ABCDETEMPDIR/cddbchoices"
2341 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2343 echo "Selected: #$CHOICE"
2344 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
2348 # The user has a choice to make, display the info in a pager if necessary
2349 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
2350 page
"$ABCDETEMPDIR/cddbchoices"
2352 # It's all going to fit in one page, cat it
2353 cat "$ABCDETEMPDIR/cddbchoices" >&2
2357 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2359 # I'll take CDDB read #3 for $400, Alex
2360 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2361 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2363 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
2364 if echo $CDDBCHOICE |
egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2365 if [ ! X
"$DIFF" = "X" ]; then
2366 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
2367 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
2368 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2369 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2370 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2371 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
2373 # We parse the 2 choices to diff, store them in temporary files and diff them.
2374 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
2375 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2377 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2378 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2379 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
2380 page
"$ABCDETEMPDIR/cddbread.diff"
2382 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2386 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2388 elif echo $CDDBCHOICE |
egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2389 # Make sure we get a valid choice
2390 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
2391 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2392 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2396 if [ "$CDCHOICENUM" = "0" ]; then
2397 vecho
"Creating empty CDDB template..."
2399 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2401 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2402 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2404 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2408 # We need some code to show the selected option when local repository is selected and we have found a match
2409 vecho
"Using cached CDDB match..." >&2
2410 # Display the $ABCDETEMPDIR/cddbchoices file created above
2411 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2412 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2413 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2414 CHOICE
=$
(checkstatus cddb-choice
)
2415 if [ "$USELOCALRESP" = "y" ]; then :; else
2416 if [ -n "$CHOICE" ] ; then
2417 case $CDDBCHOICES in
2420 echo "Selected template."
2422 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2424 echo "Selected: #$CHOICE"
2425 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
2433 # We're noninteractive - pick the first choice.
2434 # But in case we run a previous instance and selected a choice, use it.
2435 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2436 # Show the choice if we are not using the locally stored one
2437 # or when the local search failed to find a match.
2438 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
2439 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
2440 #if [ "$PREVIOUSCHOICE" ]; then
2441 cat "$ABCDETEMPDIR/cddbchoices"
2444 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2445 CDCHOICENUM
=$PREVIOUSCHOICE
2448 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2450 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2455 if checkstatus cddb-choice
>/dev
/null
; then :; else
2456 echo "abcde: internal error: cddb-choice not recorded." >&2
2459 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2460 echo -n "Edit selected CDDB data? [y/n] (" >&2
2461 if [ "$INTERACTIVE" = "y" ]; then
2462 if [ "$UNKNOWNDISK" = "y" ]; then
2465 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
2474 if [ "$EDITCDDB" = "y" ]; then
2475 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
2477 # Use the debian sensible-editor wrapper to pick the editor that the
2478 # user has requested via their $EDITOR environment variable
2479 if [ -x "/usr/bin/sensible-editor" ]; then
2480 /usr
/bin
/sensible-editor
"$CDDBDATA"
2481 elif [ -n "$EDITOR" ]; then
2482 if [ -x $
(which "${EDITOR%%\ *}") ]; then
2483 # That failed, try to load the preferred editor, starting
2484 # with their EDITOR variable
2485 eval $
(echo "$EDITOR") \"$CDDBDATA\"
2487 # If that fails, check for a vi
2488 elif which vi
>/dev
/null
2>&1; then
2490 elif [ -x /usr
/bin
/vim
]; then
2491 /usr
/bin
/vim
"$CDDBDATA"
2492 elif [ -x /usr
/bin
/vi
]; then
2493 /usr
/bin
/vi
"$CDDBDATA"
2494 elif [ -x /bin
/vi
]; then
2496 # nano should be on all (modern, i.e., sarge) debian systems
2497 elif which nano
>/dev
/null
2>&1 ; then
2499 elif [ -x /usr
/bin
/nano
]; then
2500 /usr
/bin
/nano
"$CDDBDATA"
2501 # mg should be on all OpenBSD systems
2502 elif which mg
>/dev
/null
2>&1 ; then
2504 elif [ -x /usr
/bin
/mg
]; then
2505 /usr
/bin
/mg
"$CDDBDATA"
2508 log warning
"no editor available. Check your EDITOR environment variable."
2510 # delete editor backup file if it exists
2511 if [ -w "$CDDBDATA~" ]; then
2516 # Some heuristics first. Look at Disc Title, and if it starts with
2517 # "Various", then we'll assume Various Artists
2518 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2519 echo "Looks like a Multi-Artist CD" >&2
2522 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2523 if [ "$INTERACTIVE" = "y" ]; then
2530 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2533 # Need NUMTRACKS before cddb-tool will return it:
2534 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
2535 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2536 # More than 1/2 tracks contain a "/", so guess forward
2538 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2539 # More than 1/2 contain a "-", so guess forward-dash
2541 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2542 # More than 1/2 contain something in parens, so guess trailing-paren
2546 echo "1) Artist / Title" >&2
2547 echo "2) Artist - Title" >&2
2548 echo "3) Title / Artist" >&2
2549 echo "4) Title - Artist" >&2
2550 echo "5) Artist: Title" >&2
2551 echo "6) Title (Artist)" >&2
2552 echo "7) This is a single-artist CD" >&2
2553 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2554 if [ "$INTERACTIVE" = "y" ]; then
2555 read VARIOUSARTISTSTYLE
2557 echo $DEFAULTSTYLE >&2
2558 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2560 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2561 # If they press Enter, then the default style (0) was chosen
2562 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2563 echo "Invalid selection. Please choose a number between 1 and 7."
2564 echo -n "Selection [1-7]: "
2565 read VARIOUSARTISTSTYLE
2566 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2568 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2569 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2571 vecho
"Selected: $VARIOUSARTISTSTYLE"
2572 case "$VARIOUSARTISTSTYLE" in
2574 VARIOUSARTISTSTYLE
=forward
2577 VARIOUSARTISTSTYLE
=forward-dash
2580 VARIOUSARTISTSTYLE
=reverse
2583 VARIOUSARTISTSTYLE
=reverse-dash
2586 VARIOUSARTISTSTYLE
=colon
2589 VARIOUSARTISTSTYLE
=trailing-paren
2597 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2598 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2600 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2601 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2602 # This works but does not have the necessary error checking
2603 # yet. If you are familiar with the CDDB spec
2604 # (see http://www.freedb.org/src/latest/DBFORMAT)
2605 # and can create an error-free entry on your own, then put
2606 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2607 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2608 # your abcde.conf to change the email address submissions are
2611 # submit the modified file, if they want
2612 if [ "$NOSUBMIT" != "y" ]; then
2613 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2615 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2616 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2618 echo -n 'Invalid selection. Please answer "y" or "n": '
2621 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2622 echo -n "Sending..."
2623 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2630 # User CDDBLOCALPOLICY to find out if we store the file or not...
2631 # Cache edited CDDB entry in the user's cddb dir
2632 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2633 # Make sure the cache directory exists
2634 mkdir
-p $CDDBLOCALDIR
2635 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2638 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2641 # do_cdread [tracknumber]
2642 # do_cdread onetrack [firsttrack] [lasttrack]
2646 # The commands here don't go through run_command because they're never supposed to be silenced
2647 # return codes need to be doublechecked anyway, however
2648 if [ "$1" = "onetrack" ]; then
2649 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2650 # FIXME # Until then, we grab the whole CD in one track, no matter what
2652 # We need the first and last track for cdda2wav
2654 LASTTRACK
=$
(expr $3 + 0)
2655 UTRACKNUM
=$FIRSTTRACK
2656 case "$CDROMREADERSYNTAX" in
2657 flac
) READTRACKNUMS
="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2660 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
2661 READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
2662 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTTRACK" ;;
2663 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2669 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2670 if [ "$USEPIPES" = "y" ]; then
2671 TEMPARG
="PIPERIPPER_$CDROMREADERSYNTAX"
2672 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2674 PIPE_MESSAGE
="and encoding "
2676 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2677 case "$CDROMREADERSYNTAX" in
2678 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2680 FILEARG
="--output-name=$WAVDATA"
2683 FILEARG
="-f $WAVDATA"
2691 if [ "$1" = "onetrack" ]; then
2692 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2694 if [ -r "$CDDBDATA" ]; then
2695 getcddbinfo TRACKNAME
2696 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2698 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2701 case "$CDROMREADERSYNTAX" in
2702 ### FIXME ### use an exception for flac, since it uses -o
2703 ### FIXME ### Shall we just use -o $FILEARG ??
2705 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2706 STRIPTRACKNUM
=$
(expr $UTRACKNUM + 0)
2707 nice
$READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2709 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2711 if [ "$OSFLAVOUR" = "OSX" ] ; then
2712 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2713 disktool
-u ${CDROM#/dev/} 0
2714 # Also, in OSX the cdrom device for cdda2wav changes...
2715 CDDA2WAVCDROM
="IODVDServices"
2716 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2717 CDDA2WAVCDROM
="$CDROMID"
2719 if [ "$CDROMID" = "" ]; then
2720 CDDA2WAVCDROM
="$CDROM"
2722 CDDA2WAVCDROM
="$CDROMID"
2725 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2727 ## FIXME ## We have an exception for dagrab, since it uses -f
2728 ## FIXME ## Shall we just use -f $FILEARG ??
2729 dagrab
) nice
$READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG" $REDIR
2732 # Find the track's mounted path
2733 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2734 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2735 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2736 # If the file exists, copy it
2737 if [ -e "$FILEPATH" ] ; then
2738 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2742 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2746 # If we get some error or we get some missing wav
2747 # (as long as we dont use pipes)
2748 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2749 # Thank goodness errors is only machine-parseable up to the
2750 # first colon, otherwise this woulda sucked
2751 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2752 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2754 if [ "$USEPIPES" = "y" ]; then
2755 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2757 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2761 if [ "$USEPIPES" = "y" ]; then
2762 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2764 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2766 if [ "$1" = "onetrack" ]; then
2767 echo onetrack
>> "$ABCDETEMPDIR/status"
2773 # No values accepted, only uses env variables
2776 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2777 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2779 echo "abcde: unable to set the device speed" >&2
2785 # vecho outputs a message if EXTRAVERBOSE is selected
2788 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2790 warning
) shift ; log warning
"$@" ;;
2798 # decho outputs a debug message if DEBUG is selected
2801 if [ x
"$DEBUG" != "x" ]; then
2802 if echo $1 |
grep "^\[" > /dev
/null
2>&1 ; then
2803 DEBUGECHO
=$
(echo "$@" |
tr -d '[]')
2804 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2811 # User-redefinable functions
2812 # Custom filename munging:
2815 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2816 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2819 # Custom genre munging:
2822 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2826 # Empty pre_read function, to be defined in the configuration file.
2833 # Empty post_read function, to be defined in the configuration file.
2839 ###############################################################################
2842 # Start of execution
2843 ###############################################################################
2848 # Defaults to FreeDB, but a python musicbrainz can be used
2850 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2851 CDDBSUBMIT
=freedb-submit@freedb.org
2853 HELLOINFO
="$(whoami)@$(hostname)"
2855 CDDBLOCALPOLICY
="always"
2856 CDDBLOCALRECURSIVE
="y"
2857 CDDBLOCALDIR
="$HOME/.cddb"
2860 # List of fields we parse and show during the CDDB parsing...
2861 SHOWCDDBFIELDS
="year,genre"
2864 #CDROMREADERSYNTAX=cdparanoia
2865 ENCODERSYNTAX
=default
2867 MP3ENCODERSYNTAX
=default
2868 OGGENCODERSYNTAX
=default
2869 FLACENCODERSYNTAX
=default
2870 SPEEXENCODERSYNTAX
=default
2871 MPPENCODERSYNTAX
=default
2872 AACENCODERSYNTAX
=default
2873 NORMALIZERSYNTAX
=default
2874 CUEREADERSYNTAX
=default
2876 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2877 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2878 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2879 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2880 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2881 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2882 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2883 PLAYLISTDATAPREFIX
=''
2884 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2885 VAPLAYLISTDATAPREFIX
=''
2893 VARIOUSARTISTSTYLE
=forward
2900 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2901 # i.e. CDROMID="1,0,0"
2903 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2904 # If we are using the ide-scsi emulation layer, we need to define a "g"
2905 CDPARANOIACDROMBUS
="d"
2907 # program paths - defaults to checking your $PATH
2914 XINGMP3ENC
=xingmp3enc
2931 CDPARANOIA
=cdparanoia
2937 MUSICBRAINZ
=musicbrainz-get-tracks
2941 VORBISCOMMENT
=vorbiscomment
2943 NORMALIZE
=normalize-audio
2945 VORBISGAIN
=vorbisgain
2953 # Options for programs called from abcde
2988 VORBISCOMMENTOPTS
="-R"
2989 METAFLACOPTS
="--no-utf8-convert"
2992 # Default to one process if -j isn't specified
2995 # List of actions to perform - by default, run to completion
2996 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
2998 # This option is basicaly for Debian package dependencies:
2999 # List of prefered outputs - by default, run with whatever we have in the path
3000 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:toolame
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
,m4a
:faac
3002 # List of prefered cdromreaders - by default, run whichever we have in the path
3003 DEFAULT_CDROMREADERS
="cdparanoia cdda2wav"
3005 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3006 # Linux/OpenBSD. ftp is user for NetBSD.
3007 # Let's use these checkings to determine the OS flavour, which will be used
3009 if [ X$
(uname
) = "XFreeBSD" ] ; then
3014 elif [ X$
(uname
) = "XDarwin" ] ; then
3017 # We should have disktool in OSX, but let's be sure...
3019 CDROMREADERSYNTAX
=cddafs
3020 elif [ X$
(uname
) = "XOpenBSD" ] ; then
3024 elif [ X$
(uname
) = "XNetBSD" ] ; then
3028 elif [ X$
(uname
) = "SunOS" ] ; then
3036 # If CDDBAVAIL is set to n, no CDDB read is done
3037 # If USEID3 is set to n, no ID3 tagging is done
3042 if [ -z "$OUTPUTDIR" ]; then
3046 if [ -z "$WAVOUTPUTDIR" ]; then
3047 WAVOUTPUTDIR
="$OUTPUTDIR"
3050 # Load system defaults
3051 if [ -r /etc
/abcde.conf
]; then
3054 # Load user preference defaults
3055 if [ -r $HOME/.abcde.conf
]; then
3059 # By this time, we need some HTTPGETOPTS already defined.
3060 # If the user has defined a non-default HTTPGET method, we should not be empty.
3062 if [ "$HTTPGETOPTS" = "" ] ; then
3064 wget
) HTTPGETOPTS
="-q -O -";;
3065 curl
) HTTPGETOPTS
="-f -s";;
3066 fetch
)HTTPGETOPTS
="-q -o -";;
3067 ftp) HTTPGETOPTS
="-a -V -o - ";;
3068 *) log warning
"HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3072 # If the CDROM has not been set yet, find a suitable one.
3073 # If this is a devfs system, default to /dev/cdroms/cdrom0
3074 # instead of /dev/cdrom
3075 if [ "$CDROM" = "" ] ; then
3076 if [ -e /dev
/cdroms
/cdrom0
]; then
3077 CDROM
=/dev
/cdroms
/cdrom0
3078 elif [ -e /dev
/cdrom
]; then
3080 elif [ -e /dev
/cd0c
]; then
3082 elif [ -e /dev
/acd0c
]; then
3084 elif [ -e /dev
/disk1
]; then
3089 # Parse command line options
3090 #while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
3091 while getopts 1a
:bBc
:C
:d
:Defghj
:klLmMnNo
:pPr
:s
:S
:t
:T
:UvVxX
:w
:W
:z opt
; do
3094 a
) ACTIONS
="$OPTARG" ;;
3095 A
) EXPACTIONS
="$OPTARG" ;;
3097 B
) NOBATCHREPLAYGAIN
=y
;;
3098 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else log error
"config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3099 C
) DISCID
="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3100 d
) CDROM
="$OPTARG" ;;
3103 e
) ERASEENCODEDSTATUS
=y
;;
3104 E
) ENCODING
="$OPTARG" ;;
3108 j
) MAXPROCS
="$OPTARG" ;;
3111 L
) CDDBUSELOCAL
=y
;;
3116 o
) OUTPUTTYPE
="$OPTARG" ;;
3119 r
) REMOTEHOSTS
="$OPTARG" ;;
3120 R
) CDDBLOCALRECURSIVE
=y
;;
3121 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
3122 S
) CDSPEEDVALUE
="$OPTARG" ;;
3123 t
) STARTTRACKNUMBER
="$OPTARG" ;;
3124 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
3127 echo "This is abcde v$VERSION."
3128 echo "Usage: abcde [options] [tracks]"
3129 echo "abcde -h for extra help"
3132 V
) EXTRAVERBOSE
="y" ;;
3134 X
) CUE2DISCID
="$OPTARG" ;;
3135 w
) COMMENT
="$OPTARG" ;;
3136 W
) if echo $OPTARG |
grep "[[:digit:]]" > /dev
/null
2>&1 ; then
3137 STARTTRACKNUMBER
="${OPTARG}01" ; STARTTRACKNUMBERTAG
="y" ; COMMENT
="CD${OPTARG}"
3139 log error
"argument of -W must be integer"
3143 z
) DEBUG
=y
; CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
3148 shift $
(($OPTIND - 1))
3150 # Here it comes the worse part of the whole thing. From here until we start
3151 # ripping, we have a mixture of sanity checks, verifications, default settigs
3152 # and other crazy stuff that interdepends, but hey, someone has to do it.
3154 # If NOCDDBQUERY is set, don't query the CDDB server.
3155 if [ "$NOCDDBQUERY" = "y" ]; then
3159 # If the user specified a flac file, then switch to special flac mode
3160 if echo "$CDROM" |
grep -i '.flac$' > /dev
/null
2>&1 ; then
3161 if [ ! -f "$CDROM" ]; then
3162 log error
"the defined file for FLAC ripping cannot be found" >&2
3165 vecho warning
"switching to flac CDROMREADERSYNTAX..."
3166 CDROMREADERSYNTAX
=flac
3167 # We have a builtin version of cue2discid...
3168 case "$CUE2DISCID" in
3170 *) NEEDCUE2DISCID
=y
;;
3176 # If the user provided a DISCID, disable eject
3177 if [ -n "$DISCID" ] ||
[ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD
=n
; fi
3179 # Check the available cd rippers in the system, from the ones we know.
3180 if [ "$CDROMREADERSYNTAX" = "" ]; then
3181 for DEFAULT_CDROMREADER
in $DEFAULT_CDROMREADERS; do
3182 if new_checkexec
$DEFAULT_CDROMREADER; then
3183 CDROMREADERSYNTAX
=$DEFAULT_CDROMREADER
3187 if [ "$CDROMREADERSYNTAX" = "" ]; then
3188 log error
"no cdreader found in your PATH"
3189 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
3194 # Decide if we can continue.
3195 if [ "$ONETRACK" = "y" ]; then
3196 # FIXME # remove check as soon as we find out about the other readers
3197 case "$CDROMREADERSYNTAX" in
3201 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
3204 if [ "$BATCHNORM" = "y" ]; then
3205 log warning
"BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3208 if [ "$NOGAP" = "y" ]; then
3209 log warning
"NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3212 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3213 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3214 if [ $# -gt 0 ]; then
3215 log warning
"ONETRACK mode selected, grabbing all tracks..."
3218 while [ $# -gt 0 ]; do
3219 # Range parsing code courtesy of Vincent Ho
3220 RSTART
=$
(echo $1 | cut
-f1 -d-)
3221 REND
=$
(echo $1 | cut
-f2 -d-)
3222 if [ "$RSTART" = "$REND" ]; then
3225 NEWTRACKS
=$
(f_seq_line
$RSTART $REND)
3227 TRACKQUEUE
=$
(echo "$TRACKQUEUE" "$NEWTRACKS")
3232 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3233 # List of experimental actions: retag,transcode
3235 # Determine what actions are to be done from $ACTIONS and set the
3236 # following environment variables for them:
3250 for ACTION
in $
(echo $ACTIONS |
tr , \
)
3253 default
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOCLEAN
=y
;;
3254 cue
) DOCUE
=y
; MAKECUEFILE
=y
;;
3257 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
3258 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3259 encode
) DOENCODE
=y
; DOREAD
=y
;;
3260 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3261 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
3262 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
3263 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
3264 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
3269 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3270 # FIXME # should we abort on error or just inform the user?
3271 log warning
"selected both normalize and replaygain actions"
3274 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
3275 case $SHOWCDDBFIELD in
3276 y
*|Y
*) SHOWCDDBYEAR
="y";;
3277 g
*|G
*) SHOWCDDBGENRE
="y";;
3282 # At this point a CDROM has to be defined, so we check it exists.
3283 if [ X
"$CDROM" != "X" ] ; then
3284 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
3285 if [ "$OSFLAVOUR" = "FBSD" ]; then
3286 if echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then :; else
3287 log error
"CDROMID not in the right format for $CDROMREADERSYNTAX"
3288 log error
"Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
3292 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
3293 log error
"CDROM device cannot be found."
3296 # avoid processing if we are not going to hit the CDROM.
3297 elif [ X
"$DOREAD" = "Xy" ]; then
3298 log error
"CDROM has not been defined or cannot be found"
3302 # USEPIPES pre-tests, before we get into more serious stuff
3303 # Not compatible with:
3304 # - multiple outputs
3306 # - lowdisk algorithm
3308 if [ X
"$USEPIPES" = "Xy" ]; then
3309 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
3310 log error
"Unix pipes not compatible with multiple outputs"
3313 if [ X
"$DONORMALIZE" = "Xy" ]; then
3314 log error
"Unix pipes not compatible with normalizer"
3315 # FIXME # Do we need to exit or shall we just disable the mode?
3318 if [ X
"$BATCHNORM" = "Xy" ]; then
3319 log error
"Unix pipes not compatible with BATCHNORM encoding"
3322 if [ X
"$NOGAP" = "Xy" ]; then
3323 log error
"Unix pipes not compatible with NOGAP encoding"
3326 if [ X
"$DOENCODE" = "Xn" ]; then
3327 vecho warning
"Disabling Unix pipes since we are not encoding!"
3330 if [ X
"$LOWDISK" = "Xy" ]; then
3331 log error
"Unix pipes not compatible with lowdisk algorithm"
3336 # LOWDISK pre-tests, before we get into more problematic stuff
3337 # Not compatible with anything that needs all the files in the hard disc:
3340 if [ X
"$LOWDISK" = "Xy" ]; then
3341 if [ X
"$BATCHNORM" = "Xy" ]; then
3342 log error
"Unix pipes not compatible with BATCHNORM encoding"
3345 if [ X
"$NOGAP" = "Xy" ]; then
3346 log error
"Unix pipes not compatible with NOGAP encoding"
3351 # BATCHNORM pre-tests, before we get into serious problems
3352 # Not compatible with
3353 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3354 vecho warning
"Disabling BATCHNORM since we are not normalizing!"
3358 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
3359 if [ X
"$OUTPUTTYPE" = "X" ]; then
3360 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
3361 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3362 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3363 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
3364 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
3365 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3369 if [ X
"$OUTPUTTYPE" = "X" ]; then
3370 log error
"no encoder found in the PATH"
3371 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
3376 # Decide which CDROM reader we're gonna use
3377 case "$CDROMREADERSYNTAX" in
3379 CDROMREADER
="$CDPARANOIA"
3380 CDROMREADEROPTS
="$CDPARANOIAOPTS"
3383 CDROMREADER
="$CDDA2WAV"
3384 CDROMREADEROPTS
="$CDDA2WAVOPTS"
3387 CDROMREADER
="$DAGRAB"
3388 CDROMREADEROPTS
="$DAGRABOPTS"
3391 CDROMREADER
="$CDDAFS"
3392 CDROMREADEROPTS
="$CDDAFSOPTS"
3396 CDROMREADEROPTS
="$FLACOPTS"
3400 # There's only one normalize...
3401 case "$NORMALIZERSYNTAX" in
3403 NORMALIZER
="$NORMALIZE"
3404 NORMALIZEROPTS
="$NORMALIZEOPTS"
3408 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3409 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
3410 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr \ \|| tr , \ | tr \| \ )"; do
3412 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3413 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3414 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3415 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3416 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3417 m4a
:*) AACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3420 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
3421 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
3422 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
3424 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
3427 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
3428 # for flacs and speexenc for speex and mppenc for mpps and faac for m4as
3430 # Getting ready for multiple output changes
3431 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
3435 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
3436 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
3437 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
3438 OGGOUTPUTCONTAINER
=ogg
3441 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
3442 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
3443 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN
=y
3446 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
3447 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
3448 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
3449 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC
=y
3452 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
3453 # [ "$DOREPLAYGAIN" = "y" ] &&
3456 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
3457 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN
=y
3460 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX
=faac
3463 if [ "$KEEPWAVS" = "y" ]; then
3464 vecho
"Setting the KEEPWAVS option, since the resulting wav files were requested..."
3468 *) log error
"Invalid OUTPUTTYPE defined"
3474 # decide which encoder
3475 case "$MP3ENCODERSYNTAX" in
3477 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
3481 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
3482 MP3ENCODER
="$TOOLAME"
3485 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
3489 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
3490 MP3ENCODER
="$BLADEENC"
3493 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
3497 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
3498 MP3ENCODER
="$XINGMP3ENC"
3501 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
3502 MP3ENCODER
="$MP3ENC"
3505 case "$OGGENCODERSYNTAX" in
3507 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
3508 OGGENCODER
="$VORBIZE"
3511 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
3512 OGGENCODER
="$OGGENC"
3515 case "$FLACENCODERSYNTAX" in
3517 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
3519 # FLAC streams can be encapsulated on a Ogg transport layer
3520 if echo "$FLACENCODEROPTS" |
egrep -- "(^| )--ogg($| )" > /dev
/null
2>&1 ;then
3521 log error
"FLAC on an Ogg container is not yet supported"
3522 log error
"due to problem with adding comments to such files"
3524 FLACOUTPUTCONTAINER
=ogg
3526 FLACOUTPUTCONTAINER
=flac
3530 case "$SPEEXENCODERSYNTAX" in
3532 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
3533 SPEEXENCODER
="$SPEEXENC"
3536 case "$MPPENCODERSYNTAX" in
3538 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
3539 MPPENCODER
="$MPPENC"
3542 case "$AACENCODERSYNTAX" in
3544 AACENCODEROPTS
="${AACENCODEROPTSCLI:-$AACENCOPTS}"
3545 AACENCODER
="$AACENC"
3550 if [ "$ID3TAGV" = "1" ]; then
3552 TAGGEROPTS
="$ID3OPTS"
3555 TAGGEROPTS
="$ID3V2OPTS"
3558 # Specific for NOGAP is the use of lame. Another encoder fails...
3559 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
3560 log warning
"the NOGAP option is specific of lame. Deactivating..."
3565 case "$CUEREADERSYNTAX" in
3567 CUEREADEROPTS
="${CDROM}"
3572 # which information retrieval tool are we using?
3578 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
3579 if [ X
"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X
"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
3580 log error
"FLAC on an Ogg container is not yet supported"
3581 log error
"due to problem with adding comments to such files"
3583 OGGOUTPUTCONTAINER
=ogg.ogg
3584 FLACOUTPUTCONTAINER
=flac.ogg
3585 vecho warning
"modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
3588 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
3590 if [ "$ENCNICE" ]; then
3591 ENCNICE
="-n $ENCNICE"
3593 if [ "$READNICE" ]; then
3594 READNICE
="-n $READNICE"
3596 if [ "$DISTMP3NICE" ]; then
3597 DISTMP3NICE
="-n $DISTMP3NICE"
3600 # Don't check for stuff if it's not needed
3601 if [ "$REMOTEHOSTS" ]; then
3604 if [ "$DONORMALIZE" = "y" ]; then
3607 if [ "$EJECTCD" = "y" ]; then
3610 if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
3611 if [ "$CDDBMETHOD" = "cddb" ]; then
3613 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
3617 if [ "$DOCUE" = "y" ]; then
3621 if [ X
"$CDSPEEDVALUE" != "X" ] && [ "$DOREAD" = "y" ]; then
3622 case "$CDROMREADERSYNTAX" in
3623 cdparanoia|debug
) CDROMREADEROPTS
="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
3624 ### FIXME ### translate "cue2discid" from python to bash
3625 flac
) NEEDMETAFLAC
=y
; NEEDCUE2DISCID
=y
; CDSPEEDVALUE
="" ;;
3630 ###USEPIPESSUPPORT###
3632 # Rippers with USEPIPE support
3633 # FIXME # Include here all the rippers we can figure out support pipes
3634 PIPERIPPER_cdparanoia
="-"
3635 PIPERIPPER_debug
="-"
3636 PIPERIPPER_flac
="-c "
3638 # Encoders with USEPIPE support
3639 # FIXME # Include here all the encoders we can figure out support pipes
3645 # Figure out if we can use pipes with the ripper/encoder combination
3647 if [ "$USEPIPES" = "y" ]; then
3648 PIPERIPPERSVARCHECK
="PIPERIPPER_${CDROMREADERSYNTAX}"
3651 PIPEENCODERSVARCHECK
="PIPE_$MP3ENCODERSYNTAX" ;;
3653 PIPEENCODERSVARCHECK
="PIPE_$OGGENCODERSYNTAX" ;;
3655 PIPEENCODERSVARCHECK
="PIPE_$FLACENCODERSYNTAX" ;;
3657 PIPEENCODERSVARCHECK
="PIPE_$SPEEXENCODER" ;;
3659 PIPEENCODERSVARCHECK
="PIPE_$MPPENCODER" ;;
3661 decho
"PIPERIPPERSVARCHECK: $( eval echo "\$
$PIPERIPPERSVARCHECK" )"
3662 if [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "$" ] || \
3663 [ "$( eval echo "\$
$PIPERIPPERSVARCHECK" )" = "" ] ; then
3664 log error
"no support for pipes with given ripper"
3665 log error
"read the USEPIPES file from the source tarball to get help."
3666 log error
"On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
3669 decho
"PIPEENCODERSVARCHECK: $( eval echo "\$
$PIPEENCODERSVARCHECK" )"
3670 if [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "$" ] || \
3671 [ "$( eval echo "\$
$PIPEENCODERSVARCHECK" )" = "" ] ; then
3672 log error
"no support for pipes with given encoder"
3673 log error
"read the USEPIPES file from the source tarball to help"
3674 log error
"on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
3679 # Make sure a buncha things exist
3680 for X
in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
3681 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3683 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3684 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3685 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
3686 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
3687 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
3688 ${NEEDMPPGAIN+$MPPGAIN} ${NEEDCUEREADER+$CUEREADER} \
3689 ${NEEDCUE2DISCID+$CUE2DISCID}
3694 # And last but not least, check if we can diff between files. We do not abort,
3695 # since diffing is not critical...
3696 if [ -x $
(which $DIFF) ]; then :; else
3697 vecho warning
"Disabling diff since we cannot find it in the \$PATH..."
3701 ## Now that we have metaflac, check if we need cue2discid
3702 #case $CDROMREADERSYNTAX in
3704 # TRACKINFO=$($METAFLAC --show-tag=CDDB $CDROM | cut -d"=" -f2 | egrep "[a-f0-9]{8}")
3705 # if [ "$TRACKINFO" = "" ]; then
3706 # checkexec ${NEEDCUE2DISCID+$CUE2DISCID}
3711 CDROMREADER
="$CDROMREADER $CDROMREADEROPTS"
3712 CDDBTOOL
="$CDDBTOOL $CDDBTOOLOPTS"
3713 HTTPGET
="$HTTPGET $HTTPGETOPTS"
3715 # Here it used to say:
3716 # One thousand lines in, we can start doing stuff with things
3717 # Well, right now we are at line 3306 ;)
3719 # Export needed things so they can be read in this subshell
3720 export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
3721 export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
3723 if [ "$DOREAD" = "y" ]; then
3724 # User-definable function to set some things. Use it for
3725 # - closing the CD tray with eject -t
3726 # - set the CD speed value with eject -x
3727 vecho
-n "Executing customizable pre-read function... "
3729 pre_read
# Execute the user-defined pre-read funtion. Close the CD with it.
3734 case "$CDDBMETHOD" in
3736 do_discid
# Get ABCDETEMPDIR created and status file initialized
3743 if [ "$DOCDDB" = "y" ]; then
3744 # start with a sane default:
3745 CDDBLOCALSTATUS
=notfound
3746 if [ $CDDBUSELOCAL = "y" ]; then
3749 if checkstatus cddb-choice
> /dev
/null
; then
3752 if [ "$CDDBLOCALSTATUS" = "notfound" ] ; then
3753 case "$CDDBMETHOD" in
3767 eval "$($CDDBTOOL parse "$CDDBDATA")"
3770 # Before reading tracks, we set the speed of the device
3772 if [ X
"$CDSPEEDVALUE" != "X" ]; then
3773 case "$CDROMREADERSYNTAX" in
3774 cdparanoia|debug
) ;;
3780 # Define the first and last track, since we might need them later in several places
3781 FIRSTTRACK
=$
( get_first
$TRACKQUEUE )
3782 LASTTRACK
=$
( get_last
$TRACKQUEUE )
3784 if [ -f "$ABCDETEMPDIR/status" ] && [ X
"$ERASEENCODEDSTATUS" = "Xy" ]; then
3785 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3786 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
3787 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
3790 if checkstatus onetrack
; then ONETRACK
=y
; fi
3792 if [ "$ONETRACK" = "y" ]; then
3793 # Reuse the CUEFILE in case we created it (now or in a previous run)
3794 if CUEFILE
=$
(checkstatus cuefile
); then
3799 # Create playlist if needed (backgroundable) and start reading in tracks
3803 if [ ! "$ONETRACK" = "y" ]; then
3804 if [ "$DOPLAYLIST" = "y" ]; then
3805 echo Creating playlist...
>&2
3810 # For the lowdisk option, only one program is running at once so the encoder
3811 # can be unsilenced right away.
3812 if [ "$LOWDISK" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3813 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3816 if [ "$ONETRACK" = "y" ]; then
3817 TRACKS
="$FIRSTTRACK"
3818 if [ "$USEPIPES" = "y" ]; then
3819 if checkstatus readencodetrack-
$FIRSTTRACK; then :; else
3820 do_cdread onetrack
$FIRSTTRACK $LASTTRACK | do_encode
$FIRSTTRACK %local0
% > /dev
/null
2>&1
3823 if checkstatus readtrack-
$FIRSTTRACK; then :; else
3824 do_cdread onetrack
$FIRSTTRACK $LASTTRACK
3828 for UTRACKNUM
in $TRACKQUEUE
3830 if [ "$DOREAD" = "y" ]; then
3831 if [ "$USEPIPES" = "y" ]; then
3832 if checkstatus readencodetrack-
$UTRACKNUM; then :; else
3833 # Read, pipe, shut up!
3834 do_cdread
$UTRACKNUM | do_encode
$UTRACKNUM %local0
% > /dev
/null
2>&1
3837 if checkstatus readtrack-
$UTRACKNUM; then :; else
3838 do_cdread
$UTRACKNUM
3840 if [ "$?" != "0" ]; then
3841 # CD read failed - don't give the goahead to
3848 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ]; then
3851 # If we are not reading, set the encode output to loud already, so
3852 # that we can see the output of the first track.
3853 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
3854 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3856 echo NEXTTRACK
# Get the encoder machine churning again
3857 if [ "$DOREAD" = "y" ]; then
3858 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3859 until checkstatus encodetrack-
$UTRACKNUM
3861 if checkerrors encodetrack-
$UTRACKNUM; then
3872 # Now that we're done the encoding can be loud again -
3873 # if we're not using SMP.
3874 if [ "$MAXPROCS" = "1" ]; then
3875 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3878 # All tracks read, start encoding.
3879 if [ "$NOGAP" = "y" ] ||
[ "$BATCHNORM" = "y" ] ||
[ "$ONETRACK" = "y" ]; then
3883 # Execute the user-defined post_read funtion before ejecting CD
3886 # We are now finished with the cdrom - it can be safely ejected. Note that
3887 # abcde will not have completed yet.
3888 if [ "$EJECTCD" = "y" ] && [ -x $
(which $EJECT) ]; then
3889 # We check if the disk we are processing is actually the disk inside the
3890 # CD tray. If not, we do not eject the CD, since it might be so that the
3891 # user ejected it manually.
3892 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3893 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3894 # More FreeBSD bits.
3895 if [ X
"$(uname)" = X
"FreeBSD" ] ; then
3896 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3897 # but in this script EJECT is in the envionment and names the program
3900 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3901 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3902 $eject $EJECTOPTS $cd
3903 elif [ X
"$(uname)" = X
"Darwin" ] ; then
3904 disktool
-e ${CDROM#/dev/} 0
3906 $EJECT $EJECTOPTS "$CDROM"
3913 ## Do we need to pre-process
3914 #if [ x"$PREPROCESS" = "x" ] ; then
3917 # for PRETRACKNUM in $TRACKQUEUE
3920 # if [ "$GOAHEAD" = "NO" ]; then break; fi
3922 # until [ $PREPROCEED ]
3924 # if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3925 # # all locations are working, wait and try again later
3926 # if [ ! $PREPROCEED ]; then sleep 3; fi
3928 # ( do_preprocess $PRETRACKNUM
3936 # In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
3938 if [ "$BATCHNORM" = "y" ] ||
[ "$NOGAP" = "y" ]; then
3939 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3940 if [ "$GOAHEAD" = "NO" ]; then break; fi
3941 for LASTTRACK
in $TRACKQUEUE; do :; done
3942 if checkstatus readtrack-
$LASTTRACK; then
3943 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
3944 if checkstatus normalizetrack-
$LASTTRACK; then :; else do_batch_normalize
; fi
3945 if checkerrors batch-normalize
; then exit 1; fi
3947 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
3948 if [ "$DONORMALIZE" = "y" ]; then
3949 for UTRACKNUM
in $TRACKQUEUE
3951 if checkstatus readtrack-
$UTRACKNUM; then
3952 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
3956 if checkstatus encodetrack-
$LASTTRACK; then :; else do_nogap_encode
; fi
3957 if checkerrors nogap-encode
; then exit 1; fi
3962 # If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3963 if [ "$ONETRACK" = "y" ] ; then
3964 TRACKQUEUE
="$FIRSTTRACK"
3965 TRACKS
="$FIRSTTRACK"
3968 # Do the encoding, including parallelization of remote encoding
3969 # Figure out where each track is going to be encoded
3970 ENCODELOCATIONS
="$(echo $REMOTEHOSTS | tr , ' ')"
3971 if [ "$MAXPROCS" != "0" ]; then
3972 for NUM
in $
(f_seq_row
1 "$MAXPROCS")
3974 ENCODELOCATIONS
="$ENCODELOCATIONS %local$NUM%"
3978 ENCODELOCATIONS
=$
(echo $ENCODELOCATIONS)
3979 for UTRACKNUM
in $TRACKQUEUE
3982 read GOAHEAD
# For blocking - will contain either "NO" or "NEXTTRACK"
3983 if [ "$GOAHEAD" = "NO" ]; then break; fi
3984 # find out where this track is to be encoded
3985 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
3986 # Make sure we have a place to encode this, if not, exit stage right
3987 if [ -z "$ENCODELOCATIONS" ]; then
3993 for LOCATION
in $ENCODELOCATIONS
3995 PREVIOUSTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
3996 # check first if a track has ever been assigned to this location
3997 if [ -z "$PREVIOUSTRACK" ]; then PROCEED
=y
; break; fi
3998 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3999 if checkerrors encodetrack-
$PREVIOUSTRACK; then
4000 for TEMPLOCATION
in $ENCODELOCATIONS
4002 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
4003 TEMPENCODELOCATIONS
="$TEMPENCODELOCATIONS $TEMPLOCATION"
4006 ENCODELOCATIONS
=$
(echo $TEMPENCODELOCATIONS)
4011 # We're still here, this location must have been previously assigned,
4012 # and last completed without error - check if it's done with the
4013 # previous track yet
4014 if checkstatus encodetrack-
$PREVIOUSTRACK; then PROCEED
=y
; break; fi
4016 # all locations are working, wait and try again later
4017 if [ ! $PROCEED ]; then sleep 3; fi
4019 # Record the location we're about to encode the next track at
4020 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
4022 # Don't proceed with the rest of the loop if we can't encode
4023 if [ "$ABORT" ]; then continue; fi
4024 ## FIXME ## Add here
4025 ## run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
4026 # Set TRACKNUM, TRACKNAME
4027 if [ -e "$CDDBDATA" ]; then
4028 if [ "$ONETRACK" = "y" ]; then
4030 TRACKNUM
="$FIRSTTRACK"
4034 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
4035 getcddbinfo TRACKNAME
4039 # You can't encode a file which needs to be normalized before finishing
4040 # You can't tag a file before it's finished encoding -
4041 # thus all of this is backgrounded together
4043 if [ "$DONORMALIZE" = "y" ]; then
4044 if checkstatus readtrack-
$UTRACKNUM; then
4045 if checkstatus normalizetrack-
$UTRACKNUM; then :; else do_normalize
$UTRACKNUM; fi
4048 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
4049 if checkstatus readtrack-
$UTRACKNUM; then
4050 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
4051 if [ "$DONORMALIZE" = "y" ]; then
4052 if checkstatus normalizetrack-
$UTRACKNUM; then
4053 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
4056 if checkstatus encodetrack-
$UTRACKNUM; then :; else do_encode
$UTRACKNUM $LOCATION $OUTPUT; fi
4060 if [ "$DOTAG" = "y" ]; then
4061 if checkstatus encodetrack-
$UTRACKNUM; then
4062 if checkstatus tagtrack-
$UTRACKNUM; then :; else do_tag
$UTRACKNUM; fi
4064 # Lets tag the cue file
4065 if checkstatus cleancuefile
>/dev
/null
; then :; else
4066 if checkstatus cuefile
>/dev
/null
; then
4071 if [ "$DOMOVE" = "y" ]; then
4072 if checkstatus tagtrack-
$UTRACKNUM; then
4073 if checkstatus movetrack-
$UTRACKNUM; then :; else do_move
$UTRACKNUM; fi
4080 # Go through it again and make sure there's no distmp3 stragglers, otherwise
4081 # we'll delete the files they're working on
4082 # Do NOT play ball if there is no ball to play (so ABORT if needed)
4083 ## FIXME ## Check also for files which are encoded using PIPEs.
4084 if [ "$DOENCODE" = "y" ] && [ "$USEPIPES" != "y" ] && [ ! "$ABORT" ]; then
4089 for LOCATION
in $ENCODELOCATIONS
4091 CHECKTRACK
="$(checkstatus encodetracklocation-$LOCATION)"
4092 # "How can he give us a status update, if he's DEAD?"
4093 if checkstatus encodetrack-
$CHECKTRACK; then
4096 # Nothing to see here please go quietly back to your homes
4097 if [ -z "$CHECKTRACK" ]; then continue; fi
4098 # You're still here? Maybe there is something...
4099 if checkstatus encodetrack-
$CHECKTRACK; then :; else PROCEED
= ; break; fi
4102 if [ ! $PROCEED ]; then sleep 5; fi
4105 # If the above didn't catch the stragglers, this will
4107 if [ "$DOREPLAYGAIN" = "y" ]; then
4111 # Check to see if run_command logged any errors
4112 if [ -f "$ABCDETEMPDIR/errors" ]; then
4113 log error
"The following commands failed to run:"
4114 cat "$ABCDETEMPDIR/errors"
4118 if [ "$KEEPWAVS" = "y" ];then
4122 # Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
4123 if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
4124 ENCODED_FORMATS
=$
(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f2 |
sort -u |
tr '\n' '|')
4125 MOVED_FORMATS
=$
(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut
-d"-" -f3 |
sort -u |
tr '\n' '|')
4126 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
4127 log warning
"The encoded formats does not match with the moved ones"
4128 log warning
"Formats encoded: $( echo $ENCODED_FORMATS | tr "|
" " " )"
4129 log warning
"Formats moved: $( echo $MOVED_FORMATS | tr "|
" " " )"
4130 log warning
"Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
4134 if [ "$DOCLEAN" = "y" ]; then
4135 # Wipe all the evidence
4136 # Gimme gimme gimme some more time!
4138 rm -rf "$ABCDETEMPDIR"
4141 echo "Finished. Not cleaning $ABCDETEMPDIR."