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.
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"
56 echo " Set quality level (high,medium,low)"
57 echo "-r <host1[,host2]...>"
58 echo " Also encode on these remote hosts"
59 echo "-R Use local CDDB in recursive mode"
61 echo " Show fields from the CDDB info (year,genre)"
62 echo "-S <#> Set the CD speed"
63 echo "-t <#> Start the track numbering at a given number"
64 echo "-T <#> Same as -t but modifies tag numbering"
65 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
66 echo "-v Show version number and exit"
67 echo "-V Be a bit more verbose about what is happening behind the scenes"
68 echo "-x Eject CD after all tracks are read"
70 echo " Add a comment to the CD tracks"
71 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
72 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
74 echo "Tracks is a space-delimited list of tracks to grab."
75 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
77 #echo "Double hyphens are used to concatenate tracks"
82 echo "$@" >> "$ABCDETEMPDIR/status"
85 # log [level] [message]
87 # log outputs the right message in a common format
93 error
) echo "[ERROR] abcde: $@" >&2 ;;
94 warning
) echo "[WARNING] $@" >&2 ;;
95 info
) echo "[INFO] $@" ;;
99 # Funtions to replace the need of seq, which is too distribution dependant.
103 while [ $i -ne `expr $2 + 1` ]
113 if echo $i |
grep "[[:digit:]]" > /dev
/null
2>&1 ; then
114 while [ $i -ne `expr $2 + 1` ]
121 log error
"syntax error while processing track numbers"
126 # Functions to replace the need of awk {print $1} and {print $NF}
129 if [ X
"$1" = "X" ]; then
130 for first
in `cat`; do
141 if [ X
"$1" = "X" ]; then
142 for stdin
in `cat`; do
146 for last
in $@
; do :; done
151 # checkstatus [blurb]
152 # Returns "0" if the blurb was found, returns 1 if it wasn't
153 # Puts the blurb content, if available, on stdout.
154 # Otherwise, returns "".
157 # Take the last line in the status file if there's multiple matches
159 BLURB
=$
(egrep $PATTERN "$ABCDETEMPDIR/status" |
tail -n 1)
161 if [ -z "$BLURB" ]; then
166 # See if there's a = in it
167 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
168 echo "$(echo $BLURB | cut -f2- -d=)"
174 # checkwarnings [blurb]
175 # Returns "0" if the blurb was found (meaning there was an warning),
176 # returns 1 if it wasn't (yes this is a little backwards).
177 # Does not print the blurb on stdout.
178 # Otherwise, returns "".
181 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
184 # Take the last line in the status file if there's multiple matches
186 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/warnings
" | tail -n 1)"
188 if [ -z "$BLURB" ]; then
189 # negative, we did not have a negative...
192 # affirmative, we had a negative...
197 # checkerrors [blurb]
198 # Returns "0" if the blurb was found (meaning there was an error),
199 # returns 1 if it wasn't (yes this is a little backwards).
200 # Does not print the blurb on stdout.
201 # Otherwise, returns "".
204 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
207 # Take the last line in the status file if there's multiple matches
209 BLURB
="$(egrep $PATTERN "$ABCDETEMPDIR/errors
" | tail -n 1)"
211 if [ -z "$BLURB" ]; then
212 # negative, we did not have a negative...
215 # affirmative, we had a negative...
221 # Finds the right pager in the system to display a file
225 # Use the debian sensible-pager wrapper to pick the pager
226 # user has requested via their $PAGER environment variable
227 if [ -x "/usr/bin/sensible-pager" ]; then
228 /usr
/bin
/sensible-pager
"$PAGEFILE"
229 elif [ -x "$PAGER" ]; then
230 # That failed, try to load the preferred editor, starting
231 # with their PAGER variable
233 # If that fails, check for less
234 elif [ -x /usr
/bin
/less ]; then
235 /usr
/bin
/less -f "$PAGEFILE"
236 # more should be on all UNIX systems
237 elif [ -x /bin
/more ]; then
238 /bin
/more "$PAGEFILE"
240 # No bananas, just cat the thing
245 # run_command [blurb] [command...]
246 # Runs a command, silently if necessary, and updates the status file
251 # See if this is supposed to be silent
252 if [ "$(checkstatus encode-output)" = "loud" ]; then
256 # Special case for SMP, since
257 # encoder output is never displayed, don't mute echos
258 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
267 normalize|normalize-audio
)
268 if [ "$RETURN" = "2" ]; then
269 # File was already normalized.
274 if [ "$RETURN" != "0" ]; then
275 # Put an error in the errors file. For various reasons we
276 # can't capture a copy of the program's output but we can
277 # log what we attempted to execute and the error code
278 # returned by the program.
279 if [ "$BLURB" ]; then
282 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
283 return $RETURN # Do not pass go, do not update the status file
285 if [ "$BLURB" ]; then
286 echo $BLURB >> "$ABCDETEMPDIR/status"
290 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
291 # distributed under the terms of the GNU GPL v2 or later, at your option
293 # Function to determine if a word contains a slash.
302 # Function to give the relative path from one file to another.
303 # Usage: relpath fromfile tofile
304 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
305 # (the result would be Album/Song.mp3)
306 # Output is relative path to $2 from $1 on stdout
308 # This code has the following restrictions:
309 # Multiple ////s are not collapsed into single /s, with strange effects.
310 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
311 # If FR is a directory it must have a trailing /
319 /*) ;; # No processing is needed for absolute paths
321 # Loop through common prefixes, ignoring them.
322 while slash
"$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
324 FR
="$(echo "$FR" | cut -d/ -f2-)"
325 TO
="$(echo "$TO" | cut -d/ -f2-)"
327 # Loop through directory portions left in FR, adding appropriate ../s.
330 FR
="$(echo "$FR" | cut -d/ -f2-)"
341 if [ ! "$@" = "" ]; then
342 # Cut off any command-line option we added in
343 X
=$
(echo $@ | cut
-d' ' -f2)
344 if [ "$(which $X)" = "" ]; then
346 elif [ ! -x $
(which $X) ]; then
355 if [ ! "$@" = "" ]; then
356 # Cut off any command-line option we added in
357 X
=$
(echo $@ | cut
-d' ' -f2)
358 # Test for built-in abcde.function
359 [ "$X" != "${X#abcde.}" ] && type $X >/dev
/null
2>&1 && return
360 if [ "$(which $X)" = "" ]; then
361 log error
"$X is not in your path." >&2
362 log info
"Define the full path to the executable if it exists on your system." >&2
363 if [ -e /etc
/debian_release
] ; then
365 oggenc
) MISSING_PACKAGE
=vorbis-tools
;;
366 lame|flac
) MISSING_PACKAGE
=$X ;;
368 log info
"Hint: apt-get install $MISSING_PACKAGE" >&2
371 elif [ ! -x "$(which $X)" ]; then
372 log error
"$X is not executable." >&2
378 # diffentries <filename> <max_value> <entry1>,<entry2>
379 # max_value: the range of entries goes from 1 to <max_value>
384 local CDDBDIFFCHOICES
=$1
386 local CDDBDIFFCHOICE
="$@"
387 if [ ! X
"$DIFF" = "X" ]; then
388 PARSECHOICE1
=$
(echo $CDDBDIFFCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
389 PARSECHOICE2
=$
(echo $CDDBDIFFCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
390 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
391 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
392 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
393 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
395 # We parse the 2 choices to diff, store them in temporary files and diff them.
396 for PARSECHOICE
in $
(echo $CDDBDIFFCHOICE |
tr , \
); do
397 do_cddbparse
"$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
399 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
400 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
401 if [ $
(cat "$ABCDETEMPDIR/$FILENAME.diff" |
wc -l) -ge 24 ]; then
402 page
"$ABCDETEMPDIR/$FILENAME.diff"
404 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
408 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
413 # Finds an specific field from cddbinfo
418 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
421 TRACKNAME
="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
424 grep ^EXTT
$CDDBTRACKNUM= "$CDDBDATA" | cut
-f2- -d= |
tr -d \
[:cntrl
:\
] | perl
-p -e 's/\\n/\n/;'
430 # Get the track number we are going to use for different actions
433 if [ -n "$STARTTRACKNUMBER" ] ; then
434 # Get the trackpadding from the current track
435 CURRENTTRACKPADDING
=$
(echo -n $UTRACKNUM |
wc -c)
436 TRACKNUM
=$
( printf %0.
${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
438 TRACKNUM
=${UTRACKNUM}
444 # Calculate cddb disc ids without requiring specialized helper programs.
445 # largely copied from cd-discid and musicbrainz examples. some of the steps
446 # don't make sense, but they're necessary to match the ids generated by other
449 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
450 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
451 # 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
452 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
453 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
454 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
456 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
459 if [ X
"$LEADOUT" = "X" ]; then
460 log warning
"Error trying to calculate disc ids without lead-out information."
464 # default to a two second lead-in
466 LEADIN
=${LEADIN:=150}
468 # number of cdframes per second
471 # reset cddb checksum for cddb disc-id calululation
475 for OFFSET
in $
(echo $OFFSETS)
477 COOKEDOFFSETS
="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
479 OFFSETTIME
=$
(( ($OFFSET + $LEADIN) / $CDFRAMES ))
480 while [ $OFFSETTIME -gt 0 ]; do
481 CDDBCKSUM
=$
(($CDDBCKSUM + $OFFSETTIME % 10))
482 OFFSETTIME
=$
(($OFFSETTIME / 10))
487 COOKEDOFFSETS
="${COOKEDOFFSETS:1}" # eat the leading space
489 PREGAP
=$
(($
(echo $OFFSETS | cut
-f1 -d' ')))
490 TOTALTIME
=$
(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
492 printf -v HEXSUM
"%08lx" $
(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
493 TRACKINFO="${HEXSUM} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
498 if checkstatus replaygain; then :; else
499 run_command "" echo "Adding replygain information..."
500 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
504 OUTPUT=$OGGOUTPUTCONTAINER
507 OUTPUT=$FLACOUTPUTCONTAINER
515 for UTRACKNUM in $TRACKQUEUE
517 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
518 getcddbinfo TRACKNAME
520 TRACKFILE="$(mungefilename "$TRACKNAME")"
521 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
522 ALBUMFILE="$(mungefilename "$DALBUM")"
523 GENRE="$(mungegenre "$GENRE")"
524 YEAR=${CDYEAR:-$CDYEAR}
526 if [ "$ONETRACK" = "y" ]; then
527 if [ "$VARIOUSARTISTS" = "y" ]; then
528 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
530 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
533 if [ "$VARIOUSARTISTS" = "y" ]; then
534 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
536 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
539 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
540 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
544 run_command replaygain-flac nice $ENCNICE $METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
545 #run_command replaygain-flac true
548 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN --album "${OUTPUTFILES[@]}"
551 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN -a -k "${OUTPUTFILES[@]}"
554 run_command replaygain-mpc nice $ENCNICE $MPPGAIN --auto "${OUTPUTFILES[@]}"
559 if checkerrors "replaygain-.{3,6}"; then :; else
560 run_command replaygain true
565 # This code splits the a Various Artist track name from one of the following
568 # forward: Artist / Track
569 # forward-dash: Artist - Track
570 # reverse: Track / Artist
571 # reverse-dash: Track - Artist
572 # colon: Artist: Track
573 # trailing-paren: Artist (Track)
576 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
579 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
580 case "$VARIOUSARTISTSTYLE" in
582 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
583 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
584 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -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- / -~-g')"
593 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
594 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
597 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
598 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
599 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
602 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
603 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
604 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
607 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
608 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
609 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
612 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
613 TRACKARTIST="Various"
615 TRACKARTIST="$DARTIST"
620 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
624 "classic rock") id=1 ;;
642 "industrial") id=19 ;;
643 "alternative") id=20 ;;
645 "death metal") id=22 ;;
647 "soundtrack") id=24 ;;
648 "euro-techno") id
=25 ;;
652 "jazz+funk") id
=29 ;;
655 "classical") id
=32 ;;
656 "instrumental") id
=33 ;;
660 "sound clip") id
=37 ;;
663 "alt. rock") id
=40 ;;
668 "meditative") id
=45 ;;
669 "instrum. pop") id
=46 ;;
670 "instrum. rock") id
=47 ;;
674 "techno-indust.") id
=51 ;;
675 "electronic") id
=52 ;;
677 "eurodance") id
=54 ;;
679 "southern rock") id
=56 ;;
684 "christian rap") id
=61 ;;
685 "pop/funk"|
"pop / funk") id
=62 ;;
687 "native american") id
=64 ;;
690 "psychadelic") id
=67 ;;
692 "showtunes") id
=69 ;;
696 "acid punk") id
=73 ;;
697 "acid jazz") id
=74 ;;
701 "rock & roll") id
=78 ;;
702 "hard rock") id
=79 ;;
704 "folk/rock") id
=81 ;;
705 "national folk") id
=82 ;;
712 "bluegrass") id
=89 ;;
713 "avantgarde") id
=90 ;;
714 "gothic rock") id
=91 ;;
715 "progress. rock") id
=92 ;;
716 "psychadel. rock") id
=93 ;;
717 "symphonic rock") id
=94 ;;
718 "slow rock") id
=95 ;;
721 "easy listening") id
=98 ;;
727 "chamber music") id
=104 ;;
729 "symphony") id
=106 ;;
730 "booty bass") id
=107 ;;
732 "porn groove") id
=109 ;;
734 "slow jam") id
=111 ;;
738 "folklore") id
=115 ;;
740 "power ballad") id
=117 ;;
741 "rhythmic soul") id
=118 ;;
742 "freestyle") id
=119 ;;
744 "punk rock") id
=121 ;;
745 "drum solo") id
=122 ;;
746 "a capella") id
=123 ;;
747 "euro-house") id
=124 ;;
748 "dance hall") id
=125 ;;
750 "drum & bass") id
=127 ;;
751 "club-house") id
=128 ;;
752 "hardcore") id
=129 ;;
756 "negerpunk") id
=133 ;;
757 "polsk punk") id
=134 ;;
759 "christian gangsta rap") id
=136 ;;
760 "heavy metal") id
=137 ;;
761 "black metal") id
=138 ;;
762 "crossover") id
=139 ;;
763 "contemporary christian")id
=140 ;;
764 "christian rock") id
=141 ;;
765 "merengue") id
=142 ;;
767 "thrash metal") id
=144 ;;
770 "synthpop") id
=147 ;;
771 "rock/pop"|
"rock / pop") id
=148 ;;
778 # do_tag [tracknumber]
779 # id3 tags a filename
781 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC, ATOMICPARSLEY
782 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
785 COMMENTOUTPUT
="$(eval echo ${COMMENT})"
786 if [ -z "$COMMENTOUTPUT" ]; then
787 COMMENTOUTPUT
="$(getcddbinfo TRACK-INFO)"
789 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
790 run_command
'' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
791 # If we want to start the tracks with a given number, we need to modify the
792 # TRACKNUM value before evaluation
793 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
796 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
800 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
801 GENREID
=$
(do_getgenreid
"${CDGENRE}")
806 # FIXME # track numbers in mp3 come with 1/10, so we cannot
807 # happily substitute them with $TRACKNUM
808 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $TAGGER $TAGGEROPTS \
809 --comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
810 -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
811 -G "$GENREID" -n "${TRACKNUM:-$1}" \
812 "${TRACKNUM:+-N $TRACKS}" \
813 "${ENCODING:+--set-encoding=$ENCODING}" \
814 "$ABCDETEMPDIR/track$1.$OUTPUT"
816 # FIXME # Still not activated...
818 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE \
819 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
820 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" \
821 -y "$CDYEAR" -g "$GENREID" -k "${TRACKNUM:-$1}" \
822 "$ABCDETEMPDIR/track$1.$OUTPUT"
825 # FIXME # track numbers in mp3 come with 1/10, so we cannot
826 # happily substitute them with $TRACKNUM
827 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE \
828 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
829 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
830 -y "$CDYEAR" -g "$GENREID" \
831 -T "${TRACKNUM:-$1/$TRACKS}" \
832 "$ABCDETEMPDIR/track$1.$OUTPUT"
837 case "$OGGENCODERSYNTAX" in
839 # vorbiscomment can't do in-place modification, mv the file first
840 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
841 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
845 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
847 echo ARTIST
="$TRACKARTIST"
849 echo TITLE
="$TRACKNAME"
850 if [ -n "$CDYEAR" ]; then
853 if [ -n "$CDGENRE" ]; then
854 echo GENRE
="$CDGENRE"
856 echo TRACKNUMBER
=${TRACKNUM:-$1}
857 if [ -n "$DISCNUMBER" ]; then
858 echo DISCNUMBER
="$DISCNUMBER"
860 echo CDDB
=$CDDBDISCID
861 if [ "$(eval echo ${COMMENT})" != "" ]; then
862 case "$COMMENTOUTPUT" in
863 *=*) echo "$COMMENTOUTPUT";;
864 *) echo COMMENT
="$COMMENTOUTPUT";;
867 ) | run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE \
868 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
869 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
870 # Doublecheck that the commented file was created
871 # successfully before wiping the original
872 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
873 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
875 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
882 echo ARTIST
="$TRACKARTIST"
884 echo TITLE
="$TRACKNAME"
885 if [ -n "$CDYEAR" ]; then
888 if [ -n "$CDGENRE" ]; then
889 echo GENRE
="$CDGENRE"
891 echo TRACKNUMBER
="${TRACKNUM:-$1}"
892 if [ -n "$DISCNUMBER" ]; then
893 echo DISCNUMBER
="$DISCNUMBER"
895 echo CDDB
="$CDDBDISCID"
896 if [ "$(eval echo ${COMMENT})" != "" ]; then
897 case "$COMMENTOUTPUT" in
898 *=*) echo "$COMMENTOUTPUT";;
899 *) echo COMMENT
="$COMMENTOUTPUT";;
902 ) | run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
905 run_command tagtrack-
$OUTPUT-$1 true
908 run_command tagtrack-
$OUTPUT-$1 true
911 # Use a temp-file of our choice. --overWrite seems to
912 # case core dumps with AtomicParsley 0.9.0
913 ATOMICTEMPFILE
="$ABCDETEMPDIR/track$1.m4a-atomic"
916 if [ "$VARIOUSARTISTS" = "y" ]; then
920 #It has to be command file opts for AtomicParsley
921 run_command tagtrack-
$OUTPUT-$1 nice
$ENCNICE $ATOMICPARSLEY $ABCDETEMPDIR/track
$1.m4a
--artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --tracknum ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --compilation $VARIOUSBOOL --comment "$COMMENTOUTPUT" --output $ATOMICTEMPFILE
922 if [ -f $ATOMICTEMPFILE ]; then
923 mv "$ATOMICTEMPFILE" "$ABCDETEMPDIR/track$1.m4a"
927 run_command tagtrack-
$OUTPUT-$1 true
931 if checkerrors
"tagtrack-(.{3,6})-$1"; then :; else
932 run_command tagtrack-
$1 true
939 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
942 # The commands here don't go through run_command because they're never
943 # supposed to be silenced
944 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
945 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
949 case "$MP3ENCODERSYNTAX" in
954 for UTRACKNUM
in $TRACKQUEUE
956 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
958 nice
$ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
960 if [ "$RETURN" != "0" ]; then
961 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
963 for UTRACKNUM
in $TRACKQUEUE
965 run_command encodetrack-
$OUTPUT-$UTRACKNUM true
966 #run_command encodetrack-$UTRACKNUM true
975 if checkerrors
"nogap-encode"; then :; else
976 if [ ! "$KEEPWAVS" = "y" ] ; then
977 if [ ! "$KEEPWAVS" = "move" ] ; then
982 # Other encoders fall through to normal encoding as the tracks have not
983 # been entered in the status file.
986 # do_encode [tracknumber] [hostname]
987 # If no hostname is specified, encode locally
989 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
992 if [ "$USEPIPES" = "y" ]; then
995 TEMPARG
="PIPE_$MP3ENCODERSYNTAX"
998 TEMPARG
="PIPE_$OGGENCODERSYNTAX"
1001 TEMPARG
="PIPE_$FLACENCODERSYNTAX"
1004 TEMPARG
="PIPE_$SPEEXENCODER"
1007 TEMPARG
="PIPE_$MPPENCODER"
1010 TEMPARG
="PIPE_$MPPENCODER"
1013 IN
="$( eval echo "\$
$TEMPARG" )"
1015 IN
="$ABCDETEMPDIR/track$1.wav"
1018 case "$MP3ENCODERSYNTAX" in
1019 # FIXME # check if mp3enc needs -if for pipes
1020 # FIXME # I have not been able to find a working mp3enc binary
1034 # We need IN to proceed, if we are not using pipes.
1035 if [ -s "$IN" -o X
"$USEPIPES" = "Xy" ] ; then
1036 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1038 case "$TMPOUTPUT" in
1040 OUTPUT
=$OGGOUTPUTCONTAINER
1043 OUTPUT
=$FLACOUTPUTCONTAINER
1049 OUT
="$ABCDETEMPDIR/track$1.$OUTPUT"
1050 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-
$OUTPUT-$1 ; then
1053 if [ X
"$USEPIPES" = "Xy" ]; then
1055 # We need a way to store the creation of the files when using PIPES
1056 RUN_COMMAND_PIPES
="run_command encodetrack-$OUTPUT-$1 true"
1057 # When pipping it does not make sense to have a higher nice for
1058 # reading than for encoding, since it will be hold by the
1059 # encoding process. Setting an effective nice, to calm down a
1060 # bit the reading process.
1061 EFFECTIVE_NICE
=$READNICE
1063 run_command
'' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1064 RUN_COMMAND
="run_command encodetrack-$OUTPUT-$1"
1065 EFFECTIVE_NICE
=$ENCNICE
1071 case "$MP3ENCODERSYNTAX" in
1072 lame|toolame|gogo
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1073 bladeenc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1074 l3enc|xingmp3enc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1075 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1076 mp3enc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1080 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
1087 case "$OGGENCODERSYNTAX" in
1088 vorbize
) $RUN_COMMAND nice
$EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1089 oggenc
) $RUN_COMMAND nice
$EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1093 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev
/null
2>&1
1100 case "$FLACENCODERSYNTAX" in
1101 flac
) $RUN_COMMAND nice
$EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1106 vecho
"$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1107 $RUN_COMMAND nice
$DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev
/null
2>&1
1112 if [ "$(eval echo ${COMMENT})" != "" ]; then
1115 *) COMMENT
="COMMENT=$COMMENT" ;;
1117 COMMENT
="--comment \"$COMMENT\""
1119 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1120 if [ ! "$DOTAG" = "y" ]; then
1121 $RUN_COMMAND nice
$EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
1123 $RUN_COMMAND nice
$EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1127 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1129 # I tried compiling the mppenc from corecodecs.org and got some
1130 # errors, so I have not tried it myself.
1131 ## FIXME ## Needs some cleanup to determine if an empty tag sent
1132 ## FIXME ## to the encoder ends up empty.
1133 $RUN_COMMAND nice
$EFFECTIVE_NICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
1136 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1137 if [ ! "$DOTAG" = "y" ]; then
1138 $RUN_COMMAND nice
$EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
1141 $RUN_COMMAND nice
$ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1145 # In case of wav output we need nothing. Just keep the wavs.
1150 # Only remove .wav if the encoding succeeded
1151 if checkerrors
"encodetrack-(.{3,6})-$1"; then :; else
1152 run_command encodetrack-
$1 true
1153 if [ ! "$KEEPWAVS" = "y" ] ; then
1154 if [ ! "$KEEPWAVS" = "move" ] ; then
1160 run_command
"" echo "HEH! The file we were about to encode disappeared:"
1161 run_command
"" echo ">> $IN"
1162 run_command encodetrack-
$1 false
1166 # do_preprocess [tracknumber]
1168 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1171 # IN="$ABCDETEMPDIR/track$1.wav"
1172 # # We need IN to proceed.
1173 # if [ -s "$IN" ] ; then
1174 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1176 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1177 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1178 # case "$POSTPROCESSFORMAT" in
1180 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1182 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1184 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1186 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1188 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1191 # # Only remove .wav if the encoding succeeded
1192 # if checkerrors "preprocess-(.{3,4})-$1"; then
1193 # run_command preprocess-$1 false
1195 # run_command preprocess-$1 true
1198 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1199 # echo "HEH! The file we were about to pre-process disappeared:"
1202 # run_command preprocess-$1 false
1207 # do_postprocess [tracknumber]
1209 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1212 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1214 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1215 # # We need IN to proceed.
1216 # if [ -s "$IN" ] ; then
1217 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1218 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1219 # case "$POSTPROCESSFORMAT" in
1221 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1223 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1225 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1227 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1229 # # Only remove .wav if the encoding succeeded
1230 # if checkerrors "postprocess-(.{3,4})-$1"; then
1231 # run_command postprocess-$1 false
1233 # run_command postprocess-$1 true
1236 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1237 # echo "HEH! The file we were about to post-process disappeared:"
1240 # run_command postprocess-$1 false
1255 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1259 # The commands here don't go through run_command because they're never supposed to be silenced
1260 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1265 for UTRACKNUM
in $TRACKQUEUE
1267 MP3FILES
="$TRACKFILES track$UTRACKNUM.mp3"
1269 # FIXME # Hard-coded batch option!
1270 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1272 if [ "$RETURN" != "0" ]; then
1273 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1275 for UTRACKNUM
in $TRACKQUEUE
1277 echo normalizetrack-
$UTRACKNUM >> status
1283 # do_batch_normalize
1285 # NORMALIZER, NORMALIZEROPTS
1286 do_batch_normalize
()
1288 # The commands here don't go through run_command because they're never supposed to be silenced
1289 echo "Batch normalizing tracks: $TRACKQUEUE"
1294 for UTRACKNUM
in $TRACKQUEUE
1296 TRACKFILES
="$TRACKFILES track$UTRACKNUM.wav"
1298 # XXX: Hard-coded batch option!
1299 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1301 if [ "$RETURN" != "0" ]; then
1302 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1304 for UTRACKNUM
in $TRACKQUEUE
1306 echo normalizetrack-
$UTRACKNUM >> status
1312 # do_normalize [tracknumber]
1314 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1317 IN
="$ABCDETEMPDIR/track$1.wav"
1318 if [ -e "$IN" ] ; then
1319 run_command
'' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1320 run_command normalizetrack-
$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1322 if [ "$(checkstatus encode-output)" = "loud" ]; then
1323 echo "HEH! The file we were about to normalize disappeared:"
1326 run_command normalizetrack-
$1 false
"File $IN was not found"
1330 # do_move [tracknumber]
1331 # Deduces the outfile from environment variables
1332 # Creates directory if necessary
1334 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1337 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1339 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1340 # defined the OUTPUTFILE:
1343 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1344 # Munge filenames as follows:
1349 # Eat control characters
1350 ALBUMFILE
="$(mungefilename "$DALBUM")"
1351 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1352 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1353 GENRE
="$(mungegenre "$GENRE")"
1354 YEAR
=${CDYEAR:-$CDYEAR}
1355 # If we want to start the tracks with a given number, we need to modify
1356 # the TRACKNUM value before evaluation
1358 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1359 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1360 if [ "$ONETRACK" = "y" ]; then
1361 if [ "$VARIOUSARTISTS" = "y" ]; then
1362 OUTPUTFILE
="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1364 OUTPUTFILE
="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1367 if [ "$VARIOUSARTISTS" = "y" ]; then
1368 OUTPUTFILE
="$(eval echo \""$VAOUTPUTFORMAT"\")"
1370 OUTPUTFILE
="$(eval echo \""$OUTPUTFORMAT"\")"
1373 if checkerrors
"tagtrack-$OUTPUT-$1"; then :; else
1374 # Once we know the specific output was successful, we can change
1375 # the OUTPUT to the value containing the container
1378 OUTPUT
=$OGGOUTPUTCONTAINER
1381 OUTPUT
=$FLACOUTPUTCONTAINER
1387 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1388 OUTPUTFILEDIR
="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1391 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1392 # FIXME # introduce warnings?
1395 # mkdir -p shouldn't return an error if the directory already exists
1396 mkdir
-p "$OUTPUTFILEDIR"
1397 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1398 if checkstatus movetrack-output-
$OUTPUT; then :; else
1399 run_command movetrack-output-
$OUTPUT true
1404 # mkdir -p shouldn't return an error if the directory already exists
1405 mkdir
-p "$OUTPUTFILEDIR"
1406 run_command movetrack-
$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1407 if checkstatus movetrack-output-
$OUTPUT; then :; else
1408 run_command movetrack-output-
$OUTPUT true
1412 # Lets move the cue file
1413 if CUEFILE
=$
(checkstatus cuefile
) >/dev
/null
; then
1414 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1415 if checkstatus movecue-
$OUTPUT; then :; else
1416 # Silence the Copying output since it overlaps with encoding processes...
1417 #run_command '' vecho "Copying cue file to its destination directory..."
1418 if checkstatus onetrack
>/dev
/null
; then
1421 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1422 # We dont have the dir, since it was not created before.
1425 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1428 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1429 # http://brianvictor.tripod.com/mp3cue.htm#details
1430 [a-z0-9
][a-z0-9
][a-z0-9
])
1431 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1434 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1438 run_command movecue-
$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1440 echo movecue-
$OUTPUT >> "$ABCDETEMPDIR/status"
1449 # Create the playlist if wanted
1451 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1452 # VARIOUSARTISTS, OUTPUTDIR
1455 for TMPOUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
1459 OUTPUT
=$OGGOUTPUTCONTAINER
1462 OUTPUT
=$FLACOUTPUTCONTAINER
1468 # Create a playlist file for the playlist data to go into.
1469 # We used to wipe it out if it existed. Now we request permision if interactive.
1470 for LASTTRACK
in $TRACKQUEUE; do :; done
1471 ALBUMFILE
="$(mungefilename "$DALBUM")"
1472 ARTISTFILE
="$(mungefilename "$DARTIST")"
1473 GENRE
="$(mungegenre "$GENRE")"
1474 YEAR
=${CDYEAR:-$CDYEAR}
1475 if [ "$VARIOUSARTISTS" = "y" ] ; then
1476 PLAYLISTFILE
="$(eval echo "$VAPLAYLISTFORMAT")"
1478 PLAYLISTFILE
="$(eval echo "$PLAYLISTFORMAT")"
1480 FINALPLAYLISTDIR
="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1481 mkdir
-p "$FINALPLAYLISTDIR"
1482 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1483 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1484 if [ "$INTERACTIVE" = "y" ]; then
1485 while [ "$DONE" != "y" ]; do
1487 case $ERASEPLAYLIST in
1488 e|E|a|A|k|K
) DONE
=y
;;
1489 "") ERASEPLAYLIST
=e
; DONE
=y
;;
1497 # Once we erase the playlist, we use append to create the new one.
1498 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST
=a
1500 # The playlist does not exist, so we can safelly use append to create the new list
1503 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1504 touch "$OUTPUTDIR/$PLAYLISTFILE"
1505 for UTRACKNUM
in $TRACKQUEUE
1507 # Shares some code with do_move since the filenames have to match
1508 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
1509 getcddbinfo TRACKNAME
1511 TRACKFILE
="$(mungefilename "$TRACKNAME")"
1512 ARTISTFILE
="$(mungefilename "$TRACKARTIST")"
1513 ALBUMFILE
="$(mungefilename "$DALBUM")"
1514 # If we want to start the tracks with a given number, we need to modify the
1515 # TRACKNUM value before evaluation
1517 if [ "$VARIOUSARTISTS" = "y" ]; then
1518 OUTPUTFILE
="$(eval echo \""$VAOUTPUTFORMAT\"")"
1520 OUTPUTFILE
="$(eval echo \""$OUTPUTFORMAT\"")"
1522 if [ "$VARIOUSARTISTS" = "y" ]; then
1523 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1524 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1526 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1529 if [ "$PLAYLISTDATAPREFIX" ]; then
1530 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.
$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1532 relpath
"$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1537 ## this will convert the playlist to have CRLF line-endings, if specified
1538 ## (some hardware players insist on CRLF endings)
1539 if [ "$DOSPLAYLIST" = "y" ]; then
1540 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1541 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1542 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" |
sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1544 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1549 # This function reads a cuefile on stdin and writes an extended
1550 # cddb query on stdout. Any PREGAP for track 1 is properly
1551 # handled, although cue files embedded in FLAC files do not
1552 # appear to properly store the PREGAP setting. :(
1553 abcde.cue2discid
() {
1558 while [ $val -gt 0 ] ; do
1559 ret
=$
(( $ret + ( $val % 10) ))
1560 val
=$
(( $val / 10 ))
1570 local first second third
1571 first
=$
(expr ${1} + 0 )
1572 second
=$
(expr ${2} + 0 )
1573 third
=$
(expr ${3} + 0 )
1575 echo $
(( ((($first * 60) + $second) * 75) + $third ))
1585 while read line
; do
1588 TRACK
) i
=$
(( i
+ 1 ))
1590 INDEX
) if [ "$2" -eq 1 ] ; then
1592 START
=$
(( $LBA + $PREGAP + $OFFSET ))
1594 X
=$
(cddb_sum $
(( $START / 75 )) )
1598 PREGAP
) PREGAP
=$
(msf2lba
$2)
1602 LEADOUT
=$
(( $4 / 588 ))
1605 LEADIN
=$
(( $3 / 588 ))
1614 LEADOUT
=$
(( $LEADOUT + $LEADIN ))
1616 LENGTH
=$
(( $LEADOUT/75 - $TRACK1/75 ))
1617 DISCID
=$
(( ( $N % 255 ) * 2**24 |
$LENGTH * 2**8 |
$TRACKS ))
1618 printf "%08x %i" $DISCID $TRACKS
1621 while [ $j -le $TRACKS ] ; do
1622 eval echo -n "\" \$TRACK$j\""
1625 echo " $(( $LEADOUT / 75 ))"
1629 # abcde.mkcue [--wholedisk]
1630 # This creates a cuefile directly from the extended discid information
1631 # The --wholedisk option controls whether we're ripping data from the
1632 # start of track one or from the start of the disk (usually, but not
1633 # always the same thing!)
1635 # Track one leadin/pregap (if any) handeling:
1636 # --wholedisk specified:
1639 # INDEX 01 <pregap value>
1640 # Remaining track index values unchanged from disc TOC
1642 # --wholedisk not specified
1644 # PREGAP <pregap value>
1646 # Remaining track index values offset by <pregap value>
1653 printf "$1%02i:%02i:%02i\n" $
(($2/4500)) $
((($2/75)%60)) $
(($2%75))
1656 local MODE DISCID TRACKS
1660 if [ "$1" = --wholedisc ] ; then
1672 echo REM DISCID
$DISCID
1673 echo FILE
\"dummy.wav
\" WAVE
1675 if [ $1 -ne 150 ] && [ $MODE = "PREGAP"] ; then
1682 while [ $i -le "$TRACKS" ] ; do
1683 LBA
=$
(( $1 - $OFFSET ))
1684 printf " TRACK %02i AUDIO\n" $i
1685 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1686 if [ $MODE = PREGAP
] ; then
1687 echomsf
" PREGAP " $
(($OFFSET-150))
1689 echo " INDEX 00 00:00:00"
1692 echomsf
" INDEX 01 " $LBA
1699 # This essentially the start of things
1702 # Query the CD to get the track info, unless the user specified -C
1703 # or we are using some actions which do not need the CDDB data at all
1704 #if [ ! X"$EXPACTIONS" = "X" ]; then
1706 #elif [ -z "$DISCID" ]; then
1707 if [ -z "$DISCID" ]; then
1708 vecho
-n "Getting CD track info... "
1709 # In OSX, unmount the disc before a query
1710 if [ "$OSFLAVOUR" = "OSX" ]; then
1711 disktool
-u ${CDROM#/dev/}
1713 case "$CDROMREADERSYNTAX" in
1715 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev
/null
2>&1 ; then
1716 case "$CUE2DISCID" in
1717 # FIXME # right now we have 2 cue2discid internal
1718 # implementations: builtin and abcde.cue2discid. Test
1719 # both of them and decide which one we want to use.
1721 #vecho "Using builtin cue2discid implementation..."
1722 CUESHEET
="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1724 #TRACKS=$(echo $CUESHEET | egrep "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1726 OFFSETTIMES
=( $
(echo "$CUESHEET" |
sed -n -e's/\ *INDEX 01\ \+//p' ) )
1727 TRACKS
=${#OFFSETTIMES[@]}
1729 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1730 for OFFSETTIME
in ${OFFSETTIMES[@]}; do
1731 OFFSETS
="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1732 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1735 LEADOUT
=$
(( $
(echo "$CUESHEET" |
grep lead-out | get_last
) / 44100 * 75 ))
1736 LEADIN
=$
(( $
(echo "$CUESHEET" |
grep lead-in | get_last
) / 44100 * 75 ))
1740 #vecho "Using external python cue2discid implementation..."
1741 TRACKINFO
=$
($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" |
$CUE2DISCID)
1745 log error
"the input flac file does not contain a cuesheet."
1750 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1752 # if [ ! "$RET" = "0" ];then
1753 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1756 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1757 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1759 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | egrep -o '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1760 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1764 case "$CDDBMETHOD" in
1765 cddb
) TRACKINFO
=$
($CDDISCID "$CDROM") ;;
1766 # FIXME # musicbrainz needs a cleanup
1767 musicbrainz
) TRACKINFO
=$
($MUSICBRAINZ -c "$CDROM" ) ;;
1771 # Make sure there's a CD in there by checking cd-discid's return code
1772 if [ ! "$?" = "0" ]; then
1773 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1774 log error
"cuesheet information from the flac file could not be read."
1775 log error
"Perhaps the flac file does not contain a cuesheet?."
1778 log error
"CD could not be read. Perhaps there's no CD in the drive?"
1782 # In OSX, remount the disc again
1783 if [ "$OSFLAVOUR" = "OSX" ]; then
1784 disktool
-m ${CDROM#/dev/}
1787 DISCID
=$
(echo $TRACKINFO | cut
-f1 -d' ')
1789 TRACKINFO
=$
(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1792 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1793 # This needs to be done now because a section of the resuming code will need
1796 # get the number of digits to pad TRACKNUM with - we'll use this later
1797 # a CD can only hold 99 tracks, but since we support a feature for starting
1798 # numbering the tracks from a given number, we might need to set it as a
1799 # variable for the user to define... or obtain it somehow.
1800 if [ "$PADTRACKS" = "y" ] ; then
1804 ABCDETEMPDIR
="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1805 if [ -z "$TRACKQUEUE" ]; then
1806 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1807 case "$CDROMREADERSYNTAX" in
1809 if [ "$WEHAVEACD" = "y" ]; then
1810 vecho
"Querying the CD for audio tracks..."
1811 CDPARANOIAOUTPUT
="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1813 if [ ! "$RET" = "0" ];then
1814 log warning
"something went wrong while querying the CD... Maybe a DATA CD?"
1816 TRACKS
="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d ".
" | tr '\n' ' ')"
1817 CDPARANOIAAUDIOTRACKS
="$TRACKS"
1819 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1820 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1821 echo cdparanoia-audio-tracks
=$
( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1822 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1824 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS
=$
(checkstatus cdparanoia-audio-tracks
); then :; else
1825 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1829 *) TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ') ;;
1832 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1834 if echo "$TRACKS" |
grep "[[:digit:]]" > /dev
/null
2>&1 ;then :;else
1835 log info
"The disc does not contain any tracks. Giving up..."
1838 echo -n "Grabbing entire CD - tracks: "
1839 if [ ! "$PADTRACKS" = "y" ] ; then
1840 TRACKNUMPADDING
=$
(echo -n $TRACKS |
wc -c |
tr -d ' ')
1842 TRACKS
=$
(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1844 while [ "$X" -ne "$TRACKS" ]
1846 X
=$
(printf "%0.${TRACKNUMPADDING}d" $
(expr $X + 1))
1847 TRACKQUEUE
=$
(echo $TRACKQUEUE $X)
1851 TRACKS
=$
(echo $TRACKINFO | cut
-f2 -d' ')
1852 # User-supplied track queue.
1853 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1854 TRACKQUEUE
=$
(echo $TRACKQUEUE |
sed 's-[^0-9 ]--g' |
tr ' ' '\n' |
grep -v ^$ |
sort -n |
uniq |
tr '\n' ' ' |
sed 's- $--g')
1855 # Once cleaned, obtain the highest value in the trackqueue for number padding
1856 for LASTTRACK
in $TRACKQUEUE; do :; done
1857 if [ ! "$PADTRACKS" = "y" ] ; then
1858 TRACKNUMPADDING
=$
(echo -n $LASTTRACK |
wc -c |
tr -d ' ')
1860 # Now we normalize the trackqueue
1861 for TRACK
in $TRACKQUEUE ; do
1862 TRACKNUM
=$
(printf %0.
${TRACKNUMPADDING}d $
(expr ${TRACK} + 0 ))
1863 PADTRACKQUEUE
=$
(echo $PADTRACKQUEUE $TRACKNUM)
1865 TRACKQUEUE
=$PADTRACKQUEUE
1866 echo Grabbing tracks
: "$TRACKQUEUE"
1869 QUEUEDTRACKS
=$
(echo $TRACKQUEUE |
wc -w |
tr -d ' ')
1871 # We have the discid, create a temp directory after it to store all the temp
1874 if [ -e "$ABCDETEMPDIR" ]; then
1875 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1876 # It already exists, see if it's a directory
1877 if [ ! -d "$ABCDETEMPDIR" ]; then
1878 # This is a file/socket/fifo/device/etc, not a directory
1881 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1882 echo "Please investigate, remove it, and rerun abcde." >&2
1886 # It's a directory, let's see if it's writable by us
1887 if [ ! -r "$ABCDETEMPDIR" ] ||
[ ! -w "$ABCDETEMPDIR" ] ||
[ ! -x "$ABCDETEMPDIR" ]; then
1888 # Nope, complain and exit
1890 echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
1891 echo "Please investigate, remove it, and rerun abcde." >&2
1895 # See if it's populated
1896 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1897 # Wipe and start fresh
1898 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1899 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1900 if [ "$INTERACTIVE" = "y" ]; then
1906 if [ "$ANSWER" != "y" ]; then
1909 rm -rf "$ABCDETEMPDIR" ||
exit 1
1910 mkdir
-p "$ABCDETEMPDIR"
1911 if [ "$?" -gt "0" ]; then
1912 # Directory already exists or could not be created
1913 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1917 # Everything is fine. Check for ^encodetracklocation-
1918 # and encode-output entries in the status file and
1919 # remove them. These are not relevant across sessions.
1920 if [ -f "$ABCDETEMPDIR/status" ]; then
1921 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1922 grep -v ^encodetracklocation-
< "$ABCDETEMPDIR/status.old" \
1923 |
grep -v ^encode-output
> "$ABCDETEMPDIR/status"
1925 # Remove old error messages
1926 if [ -f "$ABCDETEMPDIR/errors" ]; then
1927 rm -f "$ABCDETEMPDIR/errors"
1931 # We are starting from scratch
1932 mkdir
-p "$ABCDETEMPDIR"
1933 if [ "$?" -gt "0" ]; then
1934 # Directory already exists or could not be created
1935 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1938 cat /dev
/null
> "$ABCDETEMPDIR/status"
1939 # Store the abcde version in the status file.
1940 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1942 if [ X
"$DOCUE" = "Xy" -a X
"$WEHAVEACD" = "Xy" ]; then
1943 if checkstatus cuefile
> /dev
/null
2>&1 ; then :; else
1944 CUEFILE
=cue-$
(echo "$TRACKINFO" | cut
-f1 -d' ').txt
1945 vecho
"Creating cue file..."
1946 case $CDROMREADERSYNTAX in
1948 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
1949 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1951 log warning
"the input flac file does not contain a cuesheet."
1955 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1956 echo cuefile
=$CUEFILE >> "$ABCDETEMPDIR/status"
1958 log warning
"reading the CUE sheet is still considered experimental"
1959 log warning
"and there was a problem with the CD reading. abcde will continue,"
1960 log warning
"but consider reporting the problem to the abcde author"
1966 # If we got the CDPARANOIA status and it is not recorded, save it now
1967 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1968 if checkstatus cdparanoia-audio-tracks
> /dev
/null
2>&1; then :; else
1969 echo cdparanoia-audio-tracks
=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1973 # Create the discid file
1974 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1975 if checkstatus cddbmethod
> /dev
/null
2>&1 ; then :; else
1976 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
1981 # Create a proper CUE file based on the CUE file we created before.
1984 if CUEFILE_IN
="$ABCDETEMPDIR"/$
(checkstatus cuefile
); then
1985 CUEFILE_OUT
=$CUEFILE_IN.out
1986 ### FIXME ### checkstatus cddb
1987 if [ -e "$CDDBDATA" ]; then
1988 vecho
"Adding metadata to the cue file..."
1989 # FIXME It doesn't preserve spaces! Why?
1990 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1992 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1993 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1994 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
1998 cat "$CUEFILE_IN" |
while read line
2000 if echo "$line" |
grep "INDEX 01" > /dev
/null
2>&1 ; then
2001 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2002 # echo "$line" >> "$CUEFILE_OUT"
2003 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2004 eval track
="\$TRACK$n"
2006 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2008 # FIXME # If the lines above are uncommented, remove the line below.
2009 echo "$line" >> "$CUEFILE_OUT"
2012 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2013 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2019 # Parses a CDDB file and outputs the title and the track names.
2020 # Variables: CDDBFILE
2024 # List out disc title/author and contents
2025 if [ "$ONETRACK" = "y" ]; then
2026 vecho
"ONETRACK mode selected: displaying only the title of the CD..."
2028 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2029 if [ X
"$SHOWCDDBYEAR" = "Xy" ]; then
2030 PARSEDYEAR
=$
(grep DYEAR
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
2031 if [ ! X
"$PARSEDYEAR" = "X" ]; then
2032 echo "Year: $PARSEDYEAR"
2035 if [ X
"$SHOWCDDBGENRE" = "Xy" ]; then
2036 PARSEDGENRE
=$
(grep DGENRE
"${CDDBPARSEFILE}" | cut
'-d=' -f2-)
2037 if [ ! X
"$PARSEDGENRE" = "X" ]; then
2038 echo "Genre: $PARSEDGENRE"
2041 if [ ! "$ONETRACK" = "y" ]; then
2042 for TRACK
in $
(f_seq_row
1 $TRACKS)
2044 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2050 # Check for a local CDDB file, and report success
2053 if checkstatus cddb-readcomplete
&& checkstatus cddb-choice
>/dev
/null
; then :; else
2055 CDDBLOCALSTATUS
="notfound"
2056 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
2059 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2060 CDDBLOCALRESULTS
="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2061 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2062 if (( $
(echo "${CDDBLOCALRESULTS}" |
wc -l) == 1 )); then
2063 CDDBLOCALFILE
="${CDDBLOCALRESULTS}"
2064 CDDBLOCALMATCH
=single
2065 elif (( $
(echo "${CDDBLOCALRESULTS}" |
wc -l) > 1 )); then
2066 CDDBLOCALMATCH
=multiple
2071 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2072 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
2073 CDDBLOCALMATCH
=single
2078 # If the user has selected to check a local CDDB repo, we proceed with it
2079 case $CDDBLOCALMATCH in
2081 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2083 echo "$CDDBLOCALRESULTS" |
while read RESULT
; do
2085 # List out disc title/author and contents
2086 CDDBLOCALREAD
="$ABCDETEMPDIR/cddblocalread.$X"
2087 cat "$RESULT" > "${CDDBLOCALREAD}"
2090 do_cddbparse
"${CDDBLOCALREAD}"
2092 ##FIXME## QUICK HACK !!!!
2093 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2094 } >> "$ABCDETEMPDIR/cddblocalchoices"
2096 if [ $
(cat "$ABCDETEMPDIR/cddblocalchoices" |
wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2097 page
"$ABCDETEMPDIR/cddblocalchoices"
2099 # It's all going to fit in one page, cat it
2100 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2102 CDDBLOCALCHOICES
=$
( echo "$CDDBLOCALRESULTS" |
wc -l )
2103 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2104 CDDBLOCALCHOICENUM
=-1
2105 if [ "$INTERACTIVE" = "y" ]; then
2106 while [ $CDDBLOCALCHOICENUM -lt 0 ] ||
[ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2107 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2108 read CDDBLOCALCHOICE
2109 [ x
"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE
="1"
2110 # FIXME # Introduce diff's
2111 if echo $CDDBLOCALCHOICE |
egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2112 diffentries cddblocalread
"$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2113 elif echo $CDDBLOCALCHOICE |
egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2114 # Make sure we get a valid choice
2115 CDDBLOCALCHOICENUM
=$
(echo $CDDBLOCALCHOICE |
xargs printf %d
2>/dev
/null
)
2116 if [ $CDDBLOCALCHOICENUM -lt 0 ] ||
[ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2117 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2123 #echo "Selected ..."
2125 CDDBLOCALCHOICENUM
=1
2127 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2128 #echo "Using local copy of CDDB data"
2129 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2130 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2131 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2132 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
2133 do_cddbparse
"$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2134 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2135 CDDBLOCALSTATUS
="found"
2137 #echo "Not using local copy of CDDB data"
2138 CDDBLOCALSTATUS
="notfound"
2142 # List out disc title/author and contents
2143 do_cddbparse
"${CDDBLOCALFILE}"
2144 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2145 # echo -n "Embedded cuesheet entry found, use it? [y/n] (y): " >&2
2147 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
2149 if [ "$INTERACTIVE" = "y" ]; then
2151 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2152 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2155 [ x
"$USELOCALRESP" = "x" ] && USELOCALRESP
="y"
2159 if [ "$USELOCALRESP" = "y" ]; then
2160 #echo "Using local copy of CDDB data"
2161 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2162 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2163 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2164 echo cddb-readcomplete
>> "$ABCDETEMPDIR/status"
2165 do_cddbparse
"${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2166 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2167 CDDBLOCALSTATUS
="single"
2169 #echo "Not using local copy of CDDB data"
2170 CDDBLOCALSTATUS
="notfound"
2174 CDDBLOCALSTATUS
="notfound"
2180 do_musicbrainzstat
()
2187 # Use MBE_TOCGetCDIndexId on a perl query
2194 # Perform CDDB protocol version check if it hasn't already been done
2195 if checkstatus cddb-statcomplete
; then :; else
2196 if [ "$CDDBAVAIL" = "n" ]; then
2198 echo 503 > "$ABCDETEMPDIR/cddbstat"
2201 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
2202 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
2203 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2204 vecho
"Checking CDDB server status..."
2205 $CDDBTOOL stat
$CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2206 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
2207 case "$RESPONSECODE" in
2208 210) # 210 OK, status information follows (until terminating `.')
2211 501) # 501 Illegal CDDB protocol level: <n>.
2212 CDDBPROTO
=`expr $CDDBPROTO - 1`
2214 *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
2215 # FreeDB TESTCD disc-id is used for query
2216 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
2217 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut
-f1 -d' ')
2218 case "$RESPONSECODE" in
2219 2??
) # Server responded, everything seems OK
2226 if test $rc -eq 1; then
2230 echo cddb-statcomplete
>> "$ABCDETEMPDIR/status"
2238 CDDBDISCID
=$
(echo $TRACKINFO | cut
-d' ' -f1)
2239 CDDBLOCALFILE
="${CDDBLOCALDIR}/${CDDBDISCID}"
2241 # Perform CDDB query if it hasn't already been done
2242 if checkstatus cddb-querycomplete
; then :; else
2243 if [ "$CDDBAVAIL" = "n" ]; then
2245 echo 503 > "$ABCDETEMPDIR/cddbquery"
2246 # The default CDDBLOCALSTATUS is "notfound"
2247 # This part will be triggered if the user CDDB repo does not
2248 # contain the entry, or if we are not trying to use the repo.
2250 vecho
"Querying the CDDB server..."
2251 CDDBUSER
=$
(echo $HELLOINFO | cut
-f1 -d'@')
2252 CDDBHOST
=$
(echo $HELLOINFO | cut
-f2- -d'@')
2253 $CDDBTOOL query
$CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2259 # no match found in database,
2260 # wget/fetch error, or user requested not to use CDDB
2261 # Make up an error code (503) that abcde
2262 # will recognize in do_cddbread
2263 # and compensate by making a template
2264 echo 503 > "$ABCDETEMPDIR/cddbquery"
2266 *) # strange and unknown error
2267 echo ERRORCODE
=$ERRORCODE
2268 echo "abcde: $CDDBTOOL returned unknown error code"
2272 echo cddb-querycomplete
>> "$ABCDETEMPDIR/status"
2279 # If it's not to be used, generate a template.
2280 # Then, display it (or them) and let the user choose/edit it
2281 if checkstatus cddb-readcomplete
; then :; else
2282 vecho
"Obtaining CDDB results..."
2283 # If CDDB is to be used, interpret the query results and read all
2284 # the available entries.
2285 rm -f "$ABCDETEMPDIR/cddbchoices"
2286 CDDBCHOICES
=1 # Overridden by multiple matches
2287 RESPONSECODE
=$
(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut
-f1 -d' ')
2288 case "$RESPONSECODE" in
2290 # One exact match, retrieve it
2291 # 200 [section] [discid] [artist] / [title]
2292 if checkstatus cddb-read-1-complete
; then :; else
2293 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2294 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(cut
-f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2295 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2296 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2297 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2299 # List out disc title/author and contents
2300 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery
")" ---- >> "$ABCDETEMPDIR/cddbchoices"
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"
2309 case "$RESPONSECODE" in
2310 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2311 403|
409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2312 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2314 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2315 # List out disc title/author and contents of template
2316 echo ---- Unknown Artist
/ Unknown Album
---- >> "$ABCDETEMPDIR/cddbchoices"
2318 for TRACK
in $
(f_seq_row
1 $TRACKS)
2320 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2322 echo >> "$ABCDETEMPDIR/cddbchoices"
2323 echo cddb-read-0-complete
>> "$ABCDETEMPDIR/status"
2324 echo cddb-choice
=0 >> "$ABCDETEMPDIR/status"
2327 # Multiple exact, (possibly multiple) inexact matches
2329 if [ "$RESPONSECODE" = "211" ]; then IN
=in; fi
2330 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery
" | tr -d ' ')" -eq 3 ]; then
2331 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2332 tail -n +2 "$ABCDETEMPDIR/cddbquery" |
head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2333 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2335 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2337 vecho
-n "Retrieving multiple matches... "
2338 grep -v ^
[.
]$
"$ABCDETEMPDIR/cddbquery" |
( X
=0
2339 read DISCINFO
# eat top line
2343 if checkstatus cddb-read-
$X-complete; then :; else
2344 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $
(echo $DISCINFO | cut
-f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2345 echo cddb-read-
$X-complete >> "$ABCDETEMPDIR/status"
2347 # List out disc title/author and contents
2348 echo \
#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2349 for TRACK
in $
(f_seq_row
1 $TRACKS)
2351 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.
$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2353 echo >> "$ABCDETEMPDIR/cddbchoices"
2356 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2360 for TRACK
in $
(f_seq_row
1 $TRACKS)
2362 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread
.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2364 echo >> "$ABCDETEMPDIR/cddbchoices"
2365 echo cddb-read-1-complete
>> "$ABCDETEMPDIR/status"
2366 echo cddb-choice
=1 >> "$ABCDETEMPDIR/status"
2369 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2376 if checkstatus cddb-edit
>/dev
/null
; then
2377 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2378 VARIOUSARTISTS
="$(checkstatus variousartists)"
2379 VARIOUSARTISTSTYLE
="$(checkstatus variousartiststyle)"
2382 if [ "$INTERACTIVE" = "y" ]; then
2383 # We should show the CDDB results both when we are not using the local CDDB repo
2384 # or when we are using it but we could not find a proper match
2385 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
2386 # Display the $ABCDETEMPDIR/cddbchoices file created above
2387 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2388 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2389 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2390 CHOICE
=$
(checkstatus cddb-choice
)
2391 if [ -n "$CHOICE" ] ; then
2392 case $CDDBCHOICES in
2393 -1) if head -1 "$ABCDETEMPDIR/cddbquery" |
grep "^$" > /dev
/null
2>&1 ; then
2394 log error
"CDDB query failed!"
2397 cat "$ABCDETEMPDIR/cddbchoices"
2400 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2402 echo "Selected: #$CHOICE"
2403 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
2407 # The user has a choice to make, display the info in a pager if necessary
2408 if [ $
(cat "$ABCDETEMPDIR/cddbchoices" |
wc -l) -ge 24 ]; then
2409 page
"$ABCDETEMPDIR/cddbchoices"
2411 # It's all going to fit in one page, cat it
2412 cat "$ABCDETEMPDIR/cddbchoices" >&2
2416 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2418 # I'll take CDDB read #3 for $400, Alex
2419 while [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2420 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2422 [ X
"$CDDBCHOICE" = "X" ] && CDDBCHOICE
=1
2423 if echo $CDDBCHOICE |
egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2424 if [ ! X
"$DIFF" = "X" ]; then
2425 PARSECHOICE1
=$
(echo $CDDBCHOICE | cut
-d"," -f1 |
xargs printf %d
2>/dev
/null
)
2426 PARSECHOICE2
=$
(echo $CDDBCHOICE | cut
-d"," -f2 |
xargs printf %d
2>/dev
/null
)
2427 if [ $PARSECHOICE1 -lt 1 ] ||
[ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2428 [ $PARSECHOICE2 -lt 1 ] ||
[ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2429 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2430 echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
2432 # We parse the 2 choices to diff, store them in temporary files and diff them.
2433 for PARSECHOICE
in $
(echo $CDDBCHOICE |
tr , \
); do
2434 do_cddbparse
"$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2436 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2437 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2438 if [ $
(cat "$ABCDETEMPDIR/cddbread.diff" |
wc -l) -ge 24 ]; then
2439 page
"$ABCDETEMPDIR/cddbread.diff"
2441 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2445 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2447 elif echo $CDDBCHOICE |
egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev
/null
2>&1 ; then
2448 # Make sure we get a valid choice
2449 CDCHOICENUM
=$
(echo $CDDBCHOICE |
xargs printf %d
2>/dev
/null
)
2450 if [ $CDCHOICENUM -lt 0 ] ||
[ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2451 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2455 if [ "$CDCHOICENUM" = "0" ]; then
2456 vecho
"Creating empty CDDB template..."
2458 $CDDBTOOL template $
(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2460 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2461 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2463 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2467 # We need some code to show the selected option when local repository is selected and we have found a match
2468 vecho
"Using cached CDDB match..." >&2
2469 # Display the $ABCDETEMPDIR/cddbchoices file created above
2470 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2471 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2472 CDDBCHOICES
=$
(expr $
(cat "$ABCDETEMPDIR/cddbquery" |
wc -l) - 2)
2473 CHOICE
=$
(checkstatus cddb-choice
)
2474 if [ "$USELOCALRESP" = "y" ]; then :; else
2475 if [ -n "$CHOICE" ] ; then
2476 case $CDDBCHOICES in
2479 echo "Selected template."
2481 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2483 echo "Selected: #$CHOICE"
2484 do_cddbparse
"$ABCDETEMPDIR/cddbread.$CHOICE"
2492 # We're noninteractive - pick the first choice.
2493 # But in case we run a previous instance and selected a choice, use it.
2494 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2495 # Show the choice if we are not using the locally stored one
2496 # or when the local search failed to find a match.
2497 PREVIOUSCHOICE
=$
(checkstatus cddb-choice
)
2498 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] ||
[ ! "$CDDBUSELOCAL" = "y" ]; then
2499 #if [ "$PREVIOUSCHOICE" ]; then
2500 cat "$ABCDETEMPDIR/cddbchoices"
2503 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2504 CDCHOICENUM
=$PREVIOUSCHOICE
2507 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2509 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.
$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2514 if checkstatus cddb-choice
>/dev
/null
; then :; else
2515 echo "abcde: internal error: cddb-choice not recorded." >&2
2518 CDDBDATA
="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2519 echo -n "Edit selected CDDB data? [y/n] (" >&2
2520 if [ "$INTERACTIVE" = "y" ]; then
2521 if [ "$UNKNOWNDISK" = "y" ]; then
2524 [ "$EDITCDDB" != "n" ] && EDITCDDB
=y
2533 if [ "$EDITCDDB" = "y" ]; then
2534 CDDBDATAMD5SUM
=$
($MD5SUM "$CDDBDATA" | cut
-d " " -f 1);
2536 # Use the debian sensible-editor wrapper to pick the editor that the
2537 # user has requested via their $EDITOR environment variable
2538 if [ -x "/usr/bin/sensible-editor" ]; then
2539 /usr
/bin
/sensible-editor
"$CDDBDATA"
2540 elif [ -n "$EDITOR" ]; then
2541 if [ -x $
(which "${EDITOR%%\ *}") ]; then
2542 # That failed, try to load the preferred editor, starting
2543 # with their EDITOR variable
2544 eval $
(echo "$EDITOR") \"$CDDBDATA\"
2546 # If that fails, check for a vi
2547 elif which vi
>/dev
/null
2>&1; then
2549 elif [ -x /usr
/bin
/vim
]; then
2550 /usr
/bin
/vim
"$CDDBDATA"
2551 elif [ -x /usr
/bin
/vi
]; then
2552 /usr
/bin
/vi
"$CDDBDATA"
2553 elif [ -x /bin
/vi
]; then
2555 # nano should be on all (modern, i.e., sarge) debian systems
2556 elif which nano
>/dev
/null
2>&1 ; then
2558 elif [ -x /usr
/bin
/nano
]; then
2559 /usr
/bin
/nano
"$CDDBDATA"
2560 # mg should be on all OpenBSD systems
2561 elif which mg
>/dev
/null
2>&1 ; then
2563 elif [ -x /usr
/bin
/mg
]; then
2564 /usr
/bin
/mg
"$CDDBDATA"
2567 log warning
"no editor available. Check your EDITOR environment variable."
2569 # delete editor backup file if it exists
2570 if [ -w "$CDDBDATA~" ]; then
2575 # Some heuristics first. Look at Disc Title, and if it starts with
2576 # "Various", then we'll assume Various Artists
2577 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2578 echo "Looks like a Multi-Artist CD" >&2
2581 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2582 if [ "$INTERACTIVE" = "y" ]; then
2589 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2592 # Need NUMTRACKS before cddb-tool will return it:
2593 NUMTRACKS
=$
(egrep '^TTITLE[0-9]+=' "$CDDBDATA" |
wc -l)
2594 if [ "$(grep -c "^TTITLE.
*\
/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2595 # More than 1/2 tracks contain a "/", so guess forward
2597 elif [ "$(grep -c "^TTITLE.
*\
-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2598 # More than 1/2 contain a "-", so guess forward-dash
2600 elif [ "$(grep -c "^TTITLE.
*(.
*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2601 # More than 1/2 contain something in parens, so guess trailing-paren
2605 echo "1) Artist / Title" >&2
2606 echo "2) Artist - Title" >&2
2607 echo "3) Title / Artist" >&2
2608 echo "4) Title - Artist" >&2
2609 echo "5) Artist: Title" >&2
2610 echo "6) Title (Artist)" >&2
2611 echo "7) This is a single-artist CD" >&2
2612 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2613 if [ "$INTERACTIVE" = "y" ]; then
2614 read VARIOUSARTISTSTYLE
2616 echo $DEFAULTSTYLE >&2
2617 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2619 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2620 # If they press Enter, then the default style (0) was chosen
2621 while [ $VARIOUSARTISTSTYLE -lt 0 ] ||
[ $VARIOUSARTISTSTYLE -gt 7 ]; do
2622 echo "Invalid selection. Please choose a number between 1 and 7."
2623 echo -n "Selection [1-7]: "
2624 read VARIOUSARTISTSTYLE
2625 VARIOUSARTISTSTYLE
=$
(echo 0$VARIOUSARTISTSTYLE |
xargs printf %d
)
2627 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2628 VARIOUSARTISTSTYLE
=$DEFAULTSTYLE
2630 vecho
"Selected: $VARIOUSARTISTSTYLE"
2631 case "$VARIOUSARTISTSTYLE" in
2633 VARIOUSARTISTSTYLE
=forward
2636 VARIOUSARTISTSTYLE
=forward-dash
2639 VARIOUSARTISTSTYLE
=reverse
2642 VARIOUSARTISTSTYLE
=reverse-dash
2645 VARIOUSARTISTSTYLE
=colon
2648 VARIOUSARTISTSTYLE
=trailing-paren
2656 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2657 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2659 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2660 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2661 # This works but does not have the necessary error checking
2662 # yet. If you are familiar with the CDDB spec
2663 # (see http://www.freedb.org/src/latest/DBFORMAT)
2664 # and can create an error-free entry on your own, then put
2665 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2666 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2667 # your abcde.conf to change the email address submissions are
2670 # submit the modified file, if they want
2671 if [ "$NOSUBMIT" != "y" ]; then
2672 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2674 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2675 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2677 echo -n 'Invalid selection. Please answer "y" or "n": '
2680 if [ "$YESNO" = "y" ] ||
[ "$YESNO" = "Y" ]; then
2681 echo -n "Sending..."
2682 $CDDBTOOL send
"$CDDBDATA" $CDDBSUBMIT
2689 # User CDDBLOCALPOLICY to find out if we store the file or not...
2690 # Cache edited CDDB entry in the user's cddb dir
2691 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2692 # Make sure the cache directory exists
2693 mkdir
-p $CDDBLOCALDIR
2694 cat "$CDDBDATA" |
tail -n $
(expr $
(cat "$CDDBDATA" |
wc -l ) - 1 ) > ${CDDBLOCALDIR}/$
(echo "$TRACKINFO" | cut
-d' ' -f1)
2697 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2700 # do_cdread [tracknumber]
2701 # do_cdread onetrack [firsttrack] [lasttrack]
2705 # The commands here don't go through run_command because they're never supposed to be silenced
2706 # return codes need to be doublechecked anyway, however
2707 if [ "$1" = "onetrack" ]; then
2708 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2709 # FIXME # Until then, we grab the whole CD in one track, no matter what
2711 # We need the first and last track for cdda2wav
2713 LASTTRACK
=$
(expr $3 + 0)
2714 UTRACKNUM
=$FIRSTTRACK
2715 case "$CDROMREADERSYNTAX" in
2716 flac
) READTRACKNUMS
="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2719 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
2720 READTRACKNUMS
="$FIRSTTRACK-$LASTTRACK" ;;
2721 cdda2wav
) READTRACKNUMS
="$FIRSTTRACK+$LASTTRACK" ;;
2722 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2728 CDDBTRACKNUM
=$
(expr $UTRACKNUM - 1)
2729 if [ "$USEPIPES" = "y" ]; then
2730 TEMPARG
="PIPERIPPER_$CDROMREADERSYNTAX"
2731 FILEARG
="$( eval echo "\$
$TEMPARG" )"
2733 PIPE_MESSAGE
="and encoding "
2735 WAVDATA
="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2736 case "$CDROMREADERSYNTAX" in
2737 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2739 FILEARG
="--output-name=$WAVDATA"
2742 FILEARG
="-f $WAVDATA"
2750 if [ "$1" = "onetrack" ]; then
2751 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2753 if [ -r "$CDDBDATA" ]; then
2754 getcddbinfo TRACKNAME
2755 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2757 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2760 case "$CDROMREADERSYNTAX" in
2761 ### FIXME ### use an exception for flac, since it uses -o
2762 ### FIXME ### Shall we just use -o $FILEARG ??
2764 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2765 STRIPTRACKNUM
=$
(expr $UTRACKNUM + 0)
2766 nice
$READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2768 nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2770 if [ "$OSFLAVOUR" = "OSX" ] ; then
2771 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2772 disktool
-u ${CDROM#/dev/} 0
2773 # Also, in OSX the cdrom device for cdda2wav changes...
2774 CDDA2WAVCDROM
="IODVDServices"
2775 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2776 CDDA2WAVCDROM
="$CDROMID"
2778 if [ "$CDROMID" = "" ]; then
2779 CDDA2WAVCDROM
="$CDROM"
2781 CDDA2WAVCDROM
="$CDROMID"
2784 nice
$READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2786 ## FIXME ## We have an exception for dagrab, since it uses -f
2787 ## FIXME ## Shall we just use -f $FILEARG ??
2788 dagrab
) nice
$READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG" $REDIR
2791 # Find the track's mounted path
2792 REALTRACKNUM
=$
(expr $UTRACKNUM + 0)
2793 FILEPATH
=$
(mount |
grep "$CDROM on" |
sed 's/^[^ ]* on \(.*\) (.*/\1/')
2794 FILEPATH
=$
(find "$FILEPATH" |
grep "/$REALTRACKNUM ");
2795 # If the file exists, copy it
2796 if [ -e "$FILEPATH" ] ; then
2797 nice
$READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2801 debug
) nice
$READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2805 # If we get some error or we get some missing wav
2806 # (as long as we dont use pipes)
2807 if [ "$RETURN" != "0" -o \
( ! -s "$WAVDATA" -a X
"$USEPIPES" != "Xy" \
) ]; then
2808 # Thank goodness errors is only machine-parseable up to the
2809 # first colon, otherwise this woulda sucked
2810 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2811 RETURN
=73 # fake a return code as cdparanoia return 0 also on aborted reads
2813 if [ "$USEPIPES" = "y" ]; then
2814 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2816 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2820 if [ "$USEPIPES" = "y" ]; then
2821 echo readencodetrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2823 echo readtrack-
$UTRACKNUM >> "$ABCDETEMPDIR/status"
2825 if [ "$1" = "onetrack" ]; then
2826 echo onetrack
>> "$ABCDETEMPDIR/status"
2832 # No values accepted, only uses env variables
2835 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev
/null
; then
2836 vecho
"Setting CD speed to ${CDSPEEDVALUE}x"
2838 echo "abcde: unable to set the device speed" >&2
2844 # vecho outputs a message if EXTRAVERBOSE is selected
2847 if [ x
"$EXTRAVERBOSE" != "x" ]; then
2849 warning
) shift ; log warning
"$@" ;;
2857 # decho outputs a debug message if DEBUG is selected
2860 if [ x
"$DEBUG" != "x" ]; then
2861 if echo $1 |
grep "^\[" > /dev
/null
2>&1 ; then
2862 DEBUGECHO
=$
(echo "$@" |
tr -d '[]')
2863 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2870 # User-redefinable functions
2871 # Custom filename munging:
2874 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2875 echo "$@" |
sed s
,:,\
-,g |
tr \
/ __ |
tr -d \'\"\?\
[:cntrl
:\
]
2878 # Custom genre munging:
2881 echo $CDGENRE |
tr "[:upper:]" "[:lower:]"
2885 # Empty pre_read function, to be defined in the configuration file.
2892 # Empty post_read function, to be defined in the configuration file.
2899 # Empty post_encode function, to be defined in the configuration file.
2905 ###############################################################################
2908 # Start of execution
2909 ###############################################################################
2914 # Defaults to FreeDB, but a python musicbrainz can be used
2916 CDDBURL
="http://freedb.freedb.org/~cddb/cddb.cgi"
2917 CDDBSUBMIT
=freedb-submit@freedb.org
2919 HELLOINFO
="$(whoami)@$(hostname)"
2921 CDDBLOCALPOLICY
="always"
2922 CDDBLOCALRECURSIVE
="y"
2923 CDDBLOCALDIR
="$HOME/.cddb"
2926 # List of fields we parse and show during the CDDB parsing...
2927 SHOWCDDBFIELDS
="year,genre"
2930 #CDROMREADERSYNTAX=cdparanoia
2931 ENCODERSYNTAX
=default
2933 MP3ENCODERSYNTAX
=default
2934 OGGENCODERSYNTAX
=default
2935 FLACENCODERSYNTAX
=default
2936 SPEEXENCODERSYNTAX
=default
2937 MPPENCODERSYNTAX
=default
2938 AACENCODERSYNTAX
=default
2939 NORMALIZERSYNTAX
=default
2940 CUEREADERSYNTAX
=default
2942 OUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2943 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2944 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2945 VAOUTPUTFORMAT
='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2946 ONETRACKOUTPUTFORMAT
='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2947 VAONETRACKOUTPUTFORMAT
='Various-${ALBUMFILE}/${ALBUMFILE}'
2948 PLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2949 PLAYLISTDATAPREFIX
=''
2950 VAPLAYLISTFORMAT
='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2951 VAPLAYLISTDATAPREFIX
=''
2959 VARIOUSARTISTSTYLE
=forward
2966 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2967 # i.e. CDROMID="1,0,0"
2969 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2970 # If we are using the ide-scsi emulation layer, we need to define a "g"
2971 CDPARANOIACDROMBUS
="d"
2973 # program paths - defaults to checking your $PATH
2980 XINGMP3ENC
=xingmp3enc
2997 VORBISCOMMENT
=vorbiscomment
3001 CDPARANOIA
=cdparanoia
3007 MUSICBRAINZ
=musicbrainz-get-tracks
3011 NORMALIZE
=normalize-audio
3013 VORBISGAIN
=vorbisgain
3021 # Options for programs called from abcde
3056 VORBISCOMMENTOPTS
="-R"
3057 METAFLACOPTS
="--no-utf8-convert"
3060 # Default to one process if -j isn't specified
3063 # List of actions to perform - by default, run to completion
3064 ACTIONS
=cddb
,read,encode
,tag
,move
,clean
3066 # This option is basicaly for Debian package dependencies:
3067 # List of prefered outputs - by default, run with whatever we have in the path
3068 DEFAULT_OUTPUT_BINARIES
=vorbis
:oggenc
,flac
:flac
,mp3
:toolame
,mp3
:lame
,mp3
:bladeenc
,spx
:speex
,m4a
:faac
3070 # List of prefered cdromreaders - by default, run whichever we have in the path
3071 DEFAULT_CDROMREADERS
="cdparanoia cdda2wav"
3073 # List of quality levels associated with the encoders:
3074 DEFAULT_QUALITY_XLO
="oggenc:-q -1,lame:-q 9,speex:--quality 1,m4a:"
3075 DEFAULT_QUALITY_LO
="oggenc:-q 1,lame:-q 7,speex:--quality 5,m4a:"
3076 DEFAULT_QUALITY_HI
="oggenc:-q 7,lame:--preset standard,speex:--quality 9,m4a:"
3077 DEFAULT_QUALITY_XHI
="oggenc:-q 10,lame:--preset extreme,speex:--quality 10,m4a:"
3079 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3080 # Linux/OpenBSD. ftp is user for NetBSD.
3081 # Let's use these checkings to determine the OS flavour, which will be used
3083 if [ X$
(uname
) = "XFreeBSD" ] ; then
3088 elif [ X$
(uname
) = "XDarwin" ] ; then
3091 # We should have disktool in OSX, but let's be sure...
3093 CDROMREADERSYNTAX
=cddafs
3094 elif [ X$
(uname
) = "XOpenBSD" ] ; then
3098 elif [ X$
(uname
) = "XNetBSD" ] ; then
3102 elif [ X$
(uname
) = "SunOS" ] ; then
3110 # If CDDBAVAIL is set to n, no CDDB read is done
3111 # If USEID3 is set to n, no ID3 tagging is done
3117 # But before we get into business, let us chop off any GREP environmental
3122 if [ -z "$OUTPUTDIR" ]; then
3126 if [ -z "$WAVOUTPUTDIR" ]; then
3127 WAVOUTPUTDIR
="$OUTPUTDIR"
3130 # Load system defaults
3131 if [ -r /etc
/abcde.conf
]; then
3134 # Load user preference defaults
3135 if [ -r $HOME/.abcde.conf
]; then
3139 # By this time, we need some HTTPGETOPTS already defined.
3140 # If the user has defined a non-default HTTPGET method, we should not be empty.
3142 if [ "$HTTPGETOPTS" = "" ] ; then
3144 wget
) HTTPGETOPTS
="-q -nv -e timestamping=off -O -";;
3145 curl
) HTTPGETOPTS
="-f -s";;
3146 fetch
)HTTPGETOPTS
="-q -o -";;
3147 ftp) HTTPGETOPTS
="-a -V -o - ";;
3148 *) log warning
"HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3152 # If the CDROM has not been set yet, find a suitable one.
3153 # If this is a devfs system, default to /dev/cdroms/cdrom0
3154 # instead of /dev/cdrom
3155 if [ "$CDROM" = "" ] ; then
3156 if [ -e /dev
/cdroms
/cdrom0
]; then
3157 CDROM
=/dev
/cdroms
/cdrom0
3158 elif [ -e /dev
/cdrom
]; then
3160 elif [ -e /dev
/cd0c
]; then
3162 elif [ -e /dev
/acd0c
]; then
3164 elif [ -e /dev
/disk1
]; then
3169 # Parse command line options
3170 #while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPq:r:Rs:S:t:T:vVxw:W: opt ; do
3171 while getopts 1a
:bBc
:C
:d
:Defghj
:klLmMnNo
:pPr
:s
:S
:t
:T
:UvVxX
:w
:W
:z opt
; do
3174 a
) ACTIONS
="$OPTARG" ;;
3175 A
) EXPACTIONS
="$OPTARG" ;;
3177 B
) NOBATCHREPLAYGAIN
=y
;;
3178 c
) if [ -e "$OPTARG" ] ; then .
"$OPTARG" ; else log error
"config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3179 C
) DISCID
="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
3180 d
) CDROM
="$OPTARG" ;;
3183 e
) ERASEENCODEDSTATUS
=y
;;
3184 E
) ENCODING
="$OPTARG" ;;
3188 j
) MAXPROCS
="$OPTARG" ;;
3191 L
) CDDBUSELOCAL
=y
;;
3196 o
) OUTPUTTYPE
="$OPTARG" ;;
3199 q
) QUALITYLEVEL
="$OPTARG" ;;
3200 r
) REMOTEHOSTS
="$OPTARG" ;;
3201 R
) CDDBLOCALRECURSIVE
=y
;;
3202 s
) SHOWCDDBFIELDS
="$OPTARG" ;;
3203 S
) CDSPEEDVALUE
="$OPTARG" ;;
3204 t
) STARTTRACKNUMBER
="$OPTARG" ;;
3205 T
) STARTTRACKNUMBER
="$OPTARG" ; STARTTRACKNUMBERTAG
="y" ;;
3208 echo "This is abcde v$VERSION."
3209 echo "Usage: abcde [options] [tracks]"
3210 echo "abcde -h for extra help"
3213 V
) EXTRAVERBOSE
="y" ;;
3215 X
) CUE2DISCID
="$OPTARG" ;;
3216 w
) COMMENT
="$OPTARG" ;;
3217 W
) if echo $OPTARG |
grep "[[:digit:]]" > /dev
/null
2>&1 ; then
3218 STARTTRACKNUMBER
="${OPTARG}01"
3219 STARTTRACKNUMBERTAG
="y"
3220 COMMENT
="CD${OPTARG}"
3221 DISCNUMBER
="${OPTARG}"
3223 log error
"argument of -W must be integer"
3227 z
) DEBUG
=y
; CDROMREADERSYNTAX
=debug
; EJECTCD
="n" ;;
3232 shift $
(($OPTIND - 1))
3234 # Here it comes the worse part of the whole thing. From here until we start
3235 # ripping, we have a mixture of sanity checks, verifications, default settigs
3236 # and other crazy stuff that interdepends, but hey, someone has to do it.
3238 # If NOCDDBQUERY is set, don't query the CDDB server.
3239 if [ "$NOCDDBQUERY" = "y" ]; then
3243 # If the user specified a flac file, then switch to special flac mode
3244 if echo "$CDROM" |
grep -i '.flac$' > /dev
/null
2>&1 ; then
3245 if [ ! -f "$CDROM" ]; then
3246 log error
"the defined file for FLAC ripping cannot be found" >&2
3249 vecho warning
"switching to flac CDROMREADERSYNTAX..."
3250 CDROMREADERSYNTAX
=flac
3251 # We have a builtin version of cue2discid...
3252 case "$CUE2DISCID" in
3254 *) NEEDCUE2DISCID
=y
;;
3260 # If the user provided a DISCID, disable eject
3261 if [ -n "$DISCID" ] ||
[ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD
=n
; fi
3263 # Check the available cd rippers in the system, from the ones we know.
3264 if [ "$CDROMREADERSYNTAX" = "" ]; then
3265 for DEFAULT_CDROMREADER
in $DEFAULT_CDROMREADERS; do
3266 if new_checkexec
$DEFAULT_CDROMREADER; then
3267 CDROMREADERSYNTAX
=$DEFAULT_CDROMREADER
3271 if [ "$CDROMREADERSYNTAX" = "" ]; then
3272 log error
"no cdreader found in your PATH"
3273 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
3278 # Decide if we can continue.
3279 if [ "$ONETRACK" = "y" ]; then
3280 # FIXME # remove check as soon as we find out about the other readers
3281 case "$CDROMREADERSYNTAX" in
3285 *) log error
"$CDROMREADERSYNTAX does not support ONETRACK mode"
3288 if [ "$BATCHNORM" = "y" ]; then
3289 log warning
"BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
3292 if [ "$NOGAP" = "y" ]; then
3293 log warning
"NOGAP mode is not compatible with ONETRACK mode. Disabling..."
3296 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
3297 # FIXME # allow ranges of tracks to be selected for onetrack ripping
3298 if [ $# -gt 0 ]; then
3299 log warning
"ONETRACK mode selected, grabbing all tracks..."
3302 while [ $# -gt 0 ]; do
3303 # Range parsing code courtesy of Vincent Ho
3304 # Cleaned up to use shell built-ins by Charles Steinkuehler
3305 if [ "${1#*[^0-9-]}" != "$1" ]; then
3306 log error
"syntax error while processing track numbers"
3310 while [ ${RSTART:=1} -le ${REND:=0} ] ; do
3311 TRACKQUEUE
="$TRACKQUEUE $RSTART"
3312 RSTART
=$
(( $RSTART + 1 ))
3319 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
3320 # List of experimental actions: retag,transcode
3322 # Determine what actions are to be done from $ACTIONS and set the
3323 # following environment variables for them:
3335 ## FIXME ## Lets keep compatibility with -M
3336 [ "$DOCUE" != "y" ] && DOCUE
=n
3338 for ACTION
in $
(echo $ACTIONS |
tr , \
)
3341 default
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOCLEAN
=y
;;
3342 cue
) DOCUE
=y
; MAKECUEFILE
=y
;;
3345 normalize
) DONORMALIZE
=y
; DOREAD
=y
;;
3346 # preprocess) DOPREPROCESS=y; DOREAD=y;;
3347 encode
) DOENCODE
=y
; DOREAD
=y
;;
3348 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
3349 tag
) DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
3350 move
) DOMOVE
=y
; DOTAG
=y
; DOREAD
=y
; DOENCODE
=y
; DOCDDB
=y
;;
3351 replaygain
) DOCDDB
=y
; DOREAD
=y
; DOENCODE
=y
; DOTAG
=y
; DOMOVE
=y
; DOREPLAYGAIN
=y
;;
3352 playlist
) DOCDDB
=y
; DOPLAYLIST
=y
;;
3357 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
3358 # FIXME # should we abort on error or just inform the user?
3359 log warning
"selected both normalize and replaygain actions"
3362 for SHOWCDDBFIELD
in $
(echo $SHOWCDDBFIELDS |
tr , \
); do
3363 case $SHOWCDDBFIELD in
3364 y
*|Y
*) SHOWCDDBYEAR
="y";;
3365 g
*|G
*) SHOWCDDBGENRE
="y";;
3370 # At this point a CDROM has to be defined, so we check it exists.
3371 if [ X
"$CDROM" != "X" ] ; then
3372 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
3373 if [ "$OSFLAVOUR" = "FBSD" ]; then
3374 if echo "$CDROMID" |
grep "^[0-9],[0-9],[0-9]$" >/dev
/null
2>&1 ; then :; else
3375 log error
"CDROMID not in the right format for $CDROMREADERSYNTAX"
3376 log error
"Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
3380 elif [ ! -e "$CDROM" -a X
"$DOREAD" = "Xy" ]; then
3381 log error
"CDROM device cannot be found."
3384 # avoid processing if we are not going to hit the CDROM.
3385 elif [ X
"$DOREAD" = "Xy" ]; then
3386 log error
"CDROM has not been defined or cannot be found"
3390 # USEPIPES pre-tests, before we get into more serious stuff
3391 # Not compatible with:
3392 # - multiple outputs
3394 # - lowdisk algorithm
3396 if [ X
"$USEPIPES" = "Xy" ]; then
3397 if [ $
(echo "$OUTPUTTYPE" |
tr , \ |
wc -w ) -gt 1 ]; then
3398 log error
"Unix pipes not compatible with multiple outputs"
3401 if [ X
"$DONORMALIZE" = "Xy" ]; then
3402 log error
"Unix pipes not compatible with normalizer"
3403 # FIXME # Do we need to exit or shall we just disable the mode?
3406 if [ X
"$BATCHNORM" = "Xy" ]; then
3407 log error
"Unix pipes not compatible with BATCHNORM encoding"
3410 if [ X
"$NOGAP" = "Xy" ]; then
3411 log error
"Unix pipes not compatible with NOGAP encoding"
3414 if [ X
"$DOENCODE" = "Xn" ]; then
3415 vecho warning
"Disabling Unix pipes since we are not encoding!"
3418 if [ X
"$LOWDISK" = "Xy" ]; then
3419 log error
"Unix pipes not compatible with lowdisk algorithm"
3424 # LOWDISK pre-tests, before we get into more problematic stuff
3425 # Not compatible with anything that needs all the files in the hard disc:
3428 if [ X
"$LOWDISK" = "Xy" ]; then
3429 if [ X
"$BATCHNORM" = "Xy" ]; then
3430 log error
"Unix pipes not compatible with BATCHNORM encoding"
3433 if [ X
"$NOGAP" = "Xy" ]; then
3434 log error
"Unix pipes not compatible with NOGAP encoding"
3439 # BATCHNORM pre-tests, before we get into serious problems
3440 # Not compatible with
3441 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3442 vecho warning
"Disabling BATCHNORM since we are not normalizing!"
3446 # Check the encoding format from the ones available in the system, if nothing has been configured.
3447 if [ X
"$OUTPUTTYPE" = "X" ]; then
3448 for DEFAULT_OUTPUT
in $
( echo "$DEFAULT_OUTPUT_BINARIES" |
tr , \
); do
3449 DEFAULT_OUTPUT_FORMAT
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3450 DEFAULT_OUTPUT_BINARY
="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3451 if [ -x $
(which $DEFAULT_OUTPUT_BINARY) ] ; then
3452 OUTPUTTYPE
=$DEFAULT_OUTPUT_FORMAT
3453 vecho
"No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3457 if [ X
"$OUTPUTTYPE" = "X" ]; then
3458 log error
"no encoder found in the PATH"
3459 log error
"hints: are all dependencies installed? has the \$PATH been modified?"
3464 # Decide which CDROM reader we're gonna use
3465 case "$CDROMREADERSYNTAX" in
3467 CDROMREADER
="$CDPARANOIA"
3468 CDROMREADEROPTS
="$CDPARANOIAOPTS"
3471 CDROMREADER
="$CDDA2WAV"
3472 CDROMREADEROPTS
="$CDDA2WAVOPTS"
3475 CDROMREADER
="$DAGRAB"
3476 CDROMREADEROPTS
="$DAGRABOPTS"
3479 CDROMREADER
="$CDDAFS"
3480 CDROMREADEROPTS
="$CDDAFSOPTS"
3484 CDROMREADEROPTS
="$FLACOPTS"
3488 # There's only one normalize...
3489 case "$NORMALIZERSYNTAX" in
3491 NORMALIZER
="$NORMALIZE"
3492 NORMALIZEROPTS
="$NORMALIZEOPTS"
3496 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3497 if echo "$OUTPUTTYPE" |
grep ":" > /dev
/null
2>&1 ; then
3498 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr \ \|| tr , \ | tr \| \ )"; do
3500 vorbis
:*|ogg
:*) OGGENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3501 mp3
:*) MP3ENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3502 flac
:*) FLACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3503 spx
:*) SPEEXENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3504 mpc
:*) MPPENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3505 m4a
:*) AACENCODEROPTSCLI
="$( echo $OUTPUT | cut -d: -f2- )" ;;
3508 for OUTPUT
in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
3509 TEMPOUTPUT
=$
( echo "$OUTPUT" | cut
-d: -f1 )
3510 TEMPOUTPUTTYPE
="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
3512 OUTPUTTYPE
="$TEMPOUTPUTTYPE"
3515 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
3516 # for flacs and speexenc for speex and mppenc for mpps and faac for m4as
3518 # Getting ready for multiple output changes
3519 for OUTPUT
in $
(echo $OUTPUTTYPE |
tr , \
)
3523 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX
=oggenc
3524 [ "$DOTAG" = "y" ] && NEEDCOMMENTER
=y
3525 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN
=y
3526 OGGOUTPUTCONTAINER
=ogg
3529 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX
=lame
3530 [ "$DOTAG" = "y" ] && NEEDTAGGER
=y
3531 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN
=y
3534 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX
=flac
3535 [ "$DOTAG" = "y" ] && NEEDMETAFLAC
=y
3536 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC
=y
3537 [ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC
=y
3540 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX
=speexenc
3541 # [ "$DOREPLAYGAIN" = "y" ] &&
3544 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX
=mppenc
3545 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN
=y
3548 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX
=faac
3549 [ "$DOTAG" = "y" ] && CHECKATOMICPARSLEY
=y
3552 if [ "$KEEPWAVS" = "y" ]; then
3553 vecho
"Setting the KEEPWAVS option, since the resulting wav files were requested..."
3557 *) log error
"Invalid OUTPUTTYPE defined"
3563 # decide which encoder
3564 case "$MP3ENCODERSYNTAX" in
3566 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
3570 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
3571 MP3ENCODER
="$TOOLAME"
3574 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
3578 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
3579 MP3ENCODER
="$BLADEENC"
3582 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
3586 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
3587 MP3ENCODER
="$XINGMP3ENC"
3590 MP3ENCODEROPTS
="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
3591 MP3ENCODER
="$MP3ENC"
3594 case "$OGGENCODERSYNTAX" in
3596 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
3597 OGGENCODER
="$VORBIZE"
3600 OGGENCODEROPTS
="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
3601 OGGENCODER
="$OGGENC"
3604 case "$FLACENCODERSYNTAX" in
3606 FLACENCODEROPTS
="${FLACENCODEROPTSCLI:-$FLACOPTS}"
3608 if [ "$DOREPLAYGAIN" = "y" ]; then
3609 FLACENCODEROPTS
="${FLACENCODEROPTS} --replay-gain"
3611 # FLAC streams can be encapsulated on a Ogg transport layer
3612 if echo "$FLACENCODEROPTS" |
egrep -- "(^| )--ogg($| )" > /dev
/null
2>&1 ;then
3613 log error
"FLAC on an Ogg container is not yet supported"
3614 log error
"due to problem with adding comments to such files"
3616 FLACOUTPUTCONTAINER
=ogg
3618 FLACOUTPUTCONTAINER
=flac
3622 case "$SPEEXENCODERSYNTAX" in
3624 SPEEXENCODEROPTS
="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
3625 SPEEXENCODER
="$SPEEXENC"
3628 case "$MPPENCODERSYNTAX" in
3630 MPPENCODEROPTS
="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
3631 MPPENCODER
="$MPPENC"
3634 case "$AACENCODERSYNTAX" in
3636 AACENCODEROPTS
="${AACENCODEROPTSCLI:-$AACENCOPTS}"
3637 AACENCODER
="$AACENC"
3642 if [ "$ID3TAGV" = "1" ]; then
3644 TAGGEROPTS
="$ID3OPTS"
3647 TAGGEROPTS
="$ID3V2OPTS"
3650 # NOGAP is specific to lame. Other encoders fail ...