r187@frost: data | 2005-10-06 15:41:10 +0300
[clinton/abcde.git] / abcde
CommitLineData
c9c2ca27 1#!/bin/sh
2# Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
5895f404 3# Copyright (c) 2003-2005 Jesus Climent <jesus.climent@hispalinux.es>
c9c2ca27 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.
6#
7# You should have received a copy of the GNU General Public License
8# along with this program; if not, write to the Free Software
9# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
10#
11# Copyright for this work is to expire January 1, 2010, after which it
12# shall be public domain.
13
d823b8fc 14VERSION="2.3.99"
c9c2ca27 15
16usage ()
17{
18echo "This is abcde v$VERSION."
19echo "Usage: abcde [options] [tracks]"
20echo "Options:"
ad8b6531 21echo "-1 Encode the whole CD in a single file"
22echo "-a <action1[,action2]...>"
23echo " Actions to perform (cddb,read,normalize,encode,tag,move,playlist,clean)"
9a0af871 24#echo "-A Experimental actions (retag, transcode)"
0709e644 25echo "-b Enable batch normalization"
ad8b6531 26echo "-c <file>"
27echo " Specify a configuration file (overrides system and user config files)"
28echo "-C <discid#>"
29echo " Specify discid to resume from (only needed if you no longer have the cd)"
30echo "-d <device>"
1b94d6b7 31echo " Specify CDROM device to grab (flac uses a single-track flac file)"
ad8b6531 32echo "-D Debugging mode (equivalent to sh -x abcde)"
bef9c2d8 33echo "-e Erase encoded track information from status file"
a9a23379 34#echo "-E Set the encoding information for the tags"
75c2c424 35echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
0709e644 36#echo "-g "
ad8b6531 37echo "-h This help information"
c9c2ca27 38#echo "-i Tag files while encoding, when possible (local only) -NWY-"
ad8b6531 39echo "-j <#> Number of encoder processes to run at once (localhost)"
40echo "-k Keep the wav tracks for later use"
41echo "-l Use low disk space algorithm"
42echo "-L Use local CDDB storage directory"
43echo "-n No lookup. Don't query CDDB, just create and use template"
44echo "-N Noninteractive. Never prompt for anything"
45echo "-m Modify playlist to include CRLF endings, to comply with some players"
24f444d7 46echo "-M Create a CUE file"
ad8b6531 47echo "-o <type1[,type2]...>"
b69a8bb4 48echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav). Defaults to vorbis"
ad8b6531 49echo "-p Pad track numbers with 0's (if less than 10 tracks)"
d5200e72 50echo "-P Use UNIX pipes to read+encode without wav files"
ad8b6531 51echo "-r <host1[,host2]...>"
52echo " Also encode on these remote hosts"
b82e2042 53echo "-R Add replaygain values to the tag info (only for vorbis,flac)"
9ff5088c 54echo "-s <field>"
55echo " Show dielfs from the CDDB info (year,genre)"
ad8b6531 56echo "-S <#> Set the CD speed"
ad8b6531 57echo "-t <#> Start the track numbering at a given number"
58echo "-T <#> Same as -t but modifies tag numbering"
59echo "-v Show version number and exit"
60echo "-V Be a bit more verbose about what is happening behind the scenes"
61echo "-x Eject CD after all tracks are read"
62echo "-w <comment>"
63echo " Add a comment to the CD tracks"
64echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
cb801544 65echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
ad8b6531 66echo ""
c9c2ca27 67echo "Tracks is a space-delimited list of tracks to grab."
6119aaa1 68echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
69echo ""
efc6de2f 70#echo "Double hyphens are used to concatenate tracks"
c9c2ca27 71}
72
73# Funtions to replace the need of seq, which is too distribution dependant.
74f_seq_row ()
75{
76 i=$1
77 while [ $i -ne `expr $2 + 1` ]
78 do
79 echo $i
80 i=`expr $i + 1`
81 done
82}
83
84f_seq_line ()
85{
86 i=$1
00840d9a 87 if echo i | grep -q "[[:digit:]]" ; then
88 while [ $i -ne `expr $2 + 1` ]
89 do
90 printf $i" "
91 i=`expr $i + 1`
92 done
93 echo
94 else
95 echo "abcde: syntax error while processing track numbers" >&2
96 exit 1
97 fi
c9c2ca27 98}
99
bef9c2d8 100# Functions to replace the need of awk {print $1} and {print $NF}
101get_first()
102{
103if [ X"$1" = "X" ]; then
104 for first in `cat`; do
105 break
106 done
107else
108 first=$1
109fi
110echo $first
111}
112
113get_last()
114{
115if [ X"$1" = "X" ]; then
116 for stdin in `cat`; do
117 last=$stdin
118 done
119else
120 for last in $@ ; do :; done
121fi
122echo $last
123}
124
c9c2ca27 125# checkstatus [blurb]
126# Returns "0" if the blurb was found, returns 1 if it wasn't
127# Puts the blurb content, if available, on stdout.
128# Otherwise, returns "".
129checkstatus ()
130{
131 # Take the last line in the status file if there's multiple matches
132 PATTERN="^$1(=.*)?$"
133 BLURB=$(egrep $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
134
135 if [ -z "$BLURB" ]; then
136 # No matches found
137 return 1
138 else
139 # Matches found
140 # See if there's a = in it
141 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
142 echo "$(echo $BLURB | cut -f2- -d=)"
143 fi
144 return 0
145 fi
146}
147
cb801544 148# chechwarnings [blurb]
149# Returns "0" if the blurb was found (meaning there was an warning),
150# returns 1 if it wasn't (yes this is a little backwards).
151# Does not print the blurb on stdout.
152# Otherwise, returns "".
153checkwarnings ()
154{
155 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
156 return 1
157 fi
158 # Take the last line in the status file if there's multiple matches
159 PATTERN="^$1(:.*)?$"
160 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
161
162 if [ -z "$BLURB" ]; then
163 # negative, we did not have a negative...
164 return 1
165 else
166 # affirmative, we had a negative...
167 return 0
168 fi
169}
170
c9c2ca27 171# checkerrors [blurb]
172# Returns "0" if the blurb was found (meaning there was an error),
173# returns 1 if it wasn't (yes this is a little backwards).
174# Does not print the blurb on stdout.
175# Otherwise, returns "".
176checkerrors ()
177{
99d009fa 178 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
c9c2ca27 179 return 1
180 fi
181 # Take the last line in the status file if there's multiple matches
182 PATTERN="^$1(:.*)?$"
03308bc7 183 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
c9c2ca27 184
185 if [ -z "$BLURB" ]; then
186 # negative, we did not have a negative...
187 return 1
188 else
189 # affirmative, we had a negative...
190 return 0
191 fi
192}
193
913e4339 194# page [file]
195# Finds the right pager in the system to display a file
196page ()
197{
198 PAGEFILE="$1"
199 # Use the debian sensible-pager wrapper to pick the pager
200 # user has requested via their $PAGER environment variable
201 if [ -x "/usr/bin/sensible-pager" ]; then
202 /usr/bin/sensible-pager "$PAGEFILE"
203 elif [ -x "$PAGER" ]; then
204 # That failed, try to load the preferred editor, starting
205 # with their PAGER variable
206 $PAGER "$PAGEFILE"
207 # If that fails, check for less
208 elif [ -x /usr/bin/less ]; then
209 /usr/bin/less -f "$PAGEFILE"
210 # more should be on all UNIX systems
211 elif [ -x /bin/more ]; then
212 /bin/more "$PAGEFILE"
213 else
214 # No bananas, just cat the thing
215 cat "$PAGEFILE" >&2
216 fi
217}
218
c9c2ca27 219# run_command [blurb] [command...]
220# Runs a command, silently if necessary, and updates the status file
221run_command ()
222{
223 BLURB="$1"
224 shift
225 # See if this is supposed to be silent
226 if [ "$(checkstatus encode-output)" = "loud" ]; then
227 "$@" >&2
228 RETURN=$?
229 else
230 # Special case for SMP, since
231 # encoder output is never displayed, don't mute echos
232 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
233 "$@" >&2
234 RETURN=$?
235 else
236 "$@" >/dev/null 2>&1
237 RETURN=$?
238 fi
239 fi
240 case "$1" in
1a064efb 241 normalize|normalize-audio)
c9c2ca27 242 if [ "$RETURN" = "2" ]; then
243 # File was already normalized.
244 RETURN=0
245 fi
246 ;;
247 esac
248 if [ "$RETURN" != "0" ]; then
249 # Put an error in the errors file. For various reasons we
250 # can't capture a copy of the program's output but we can
251 # log what we attempted to execute and the error code
252 # returned by the program.
253 if [ "$BLURB" ]; then
254 TWEAK="$BLURB: "
255 fi
256 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
257 return $RETURN # Do not pass go, do not update the status file
258 fi
259 if [ "$BLURB" ]; then
260 echo $BLURB >> "$ABCDETEMPDIR/status"
261 fi
262}
263
264# relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
265# distributed under the terms of the GNU GPL v2 or later, at your option
266
267# Function to determine if a word contains a slash.
268slash ()
269{
270 case "$1" in
271 */*) return 0;;
272 *) return 1;;
273 esac
274}
275
276# Function to give the relative path from one file to another.
277# Usage: relpath fromfile tofile
278# eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
279# (the result would be Album/Song.mp3)
280# Output is relative path to $2 from $1 on stdout
281
282# This code has the following restrictions:
283# Multiple ////s are not collapsed into single /s, with strange effects.
284# Absolute paths and ../s are handled wrong in FR (but they work in TO)
285# If FR is a directory it must have a trailing /
286
287relpath ()
288{
289 FR="$1"
290 TO="$2"
291
292 case "$TO" in
293 /*) ;; # No processing is needed for absolute paths
294 *)
295 # Loop through common prefixes, ignoring them.
296 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
297 do
298 FR="$(echo "$FR" | cut -d/ -f2-)"
299 TO="$(echo "$TO" | cut -d/ -f2-)"
300 done
301 # Loop through directory portions left in FR, adding appropriate ../s.
302 while slash "$FR"
303 do
304 FR="$(echo "$FR" | cut -d/ -f2-)"
305 TO="../$TO"
306 done
6c124acf 307 ;;
c9c2ca27 308 esac
309
310 echo $TO
311}
312
cbdb0706 313# do_getcddbinfo
314# Finds an specific field from cddbinfo
315#
316# TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
317# TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
318# TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
319
9c4b8a8e 320do_getcddbinfo()
cbdb0706 321{
c0fc2e81 322 case $1 in
323 TRACKNAME1)
324 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
325 ;;
326 TRACKNAME)
327 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
328 ;;
329 esac
330}
331
332# do_gettracknum
333# Get the track number we are going to use for different actions
9c4b8a8e 334do_gettracknum()
c0fc2e81 335{
336 if [ -n "$STARTTRACKNUMBER" ] ; then
337 # Get the trackpadding from the current track
338 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
339 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
340 else
341 TRACKNUM=${UTRACKNUM}
342 fi
343}
344
9c4b8a8e 345do_replaygain()
c0fc2e81 346{
00840d9a 347 if checkstatus replaygain; then :; else
1b94d6b7 348 run_command "" echo "Adding replygain information..."
00840d9a 349 for OUTPUT in $( echo $OUTPUTTYPE | tr , \ )
350 # THE OUTPUT NEEDS TO BE CORRECTED WITH THE CONTAINER?
c0fc2e81 351 do
b1d7b11a 352 case $OUTPUT in
353 vorbis|ogg)
354 OUTPUT=$OGGOUTPUTCONTAINER
355 ;;
356 flac)
357 OUTPUT=$FLACOUTPUTCONTAINER
358 ;;
359 esac
00840d9a 360 OUTPUTFILES=""
361 for UTRACKNUM in $TRACKQUEUE
362 do
363 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
364 do_getcddbinfo TRACKNAME
365 splitvarious
fe4d186c 366 TRACKFILE="$(mungefilename "$TRACKNAME")"
367 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
368 ALBUMFILE="$(mungefilename "$DALBUM")"
00840d9a 369 do_gettracknum
370 if [ "$VARIOUSARTISTS" = "y" ]; then
371 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
372 else
373 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
374 fi
375 OUTPUTFILES="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT $OUTPUTFILES"
376 done
377 case "$OUTPUT" in
b1d7b11a 378 flac)
379 run_command replaygain-flac $METAFLAC --add-replay-gain $OUTPUTFILES
380 ;;
381 vorbis|ogg)
382 run_command replaygain-vorbis $VORBISGAIN --album $OUTPUTFILES
383 ;;
00840d9a 384 *);;
385 esac
c0fc2e81 386 done
33bc33c3 387 if checkerrors replaygain-.{3,6}; then :; else
1750d493 388 run_command replaygain true
389 fi
00840d9a 390 fi
cbdb0706 391}
392
c9c2ca27 393# This code splits the a Various Artist track name from one of the following
394# forms:
395#
396# forward: Artist / Track
397# forward-dash: Artist - Track
398# reverse: Track / Artist
399# reverse-dash: Track - Artist
400# colon: Artist: Track
401# trailing-paren: Artist (Track)
402#
403# variables used:
404# VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
405splitvarious ()
406{
407 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
408 case "$VARIOUSARTISTSTYLE" in
409 forward)
fe4d186c 410 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
411 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
412 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
c9c2ca27 413 ;;
414 forward-dash)
fe4d186c 415 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
416 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
417 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
c9c2ca27 418 ;;
419 reverse)
fe4d186c 420 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
421 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
422 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
c9c2ca27 423 ;;
424 reverse-dash)
fe4d186c 425 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
426 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
427 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
c9c2ca27 428 ;;
429 colon)
fe4d186c 430 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
431 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
432 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
c9c2ca27 433 ;;
434 trailing-paren)
fe4d186c 435 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
436 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
437 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
c9c2ca27 438 ;;
439 esac
a9a23379 440 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
c9c2ca27 441 TRACKARTIST="Various"
442 else
eb1474fe 443 TRACKARTIST="$DARTIST"
c9c2ca27 444 fi
445}
446
2994a485 447do_getgenreid () {
448local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
449local id=""
450 case ${genre} in
451 "blues") id=0 ;;
452 "classic rock") id=1 ;;
453 "country") id=2 ;;
454 "dance") id=3 ;;
455 "disco") id=4 ;;
456 "funk") id=5 ;;
457 "grunge") id=6 ;;
458 "hip-hop") id=7 ;;
459 "jazz") id=8 ;;
460 "metal") id=9 ;;
461 "new age") id=10 ;;
462 "oldies") id=11 ;;
463 "other") id=12 ;;
464 "pop") id=13 ;;
465 "r&b") id=14 ;;
466 "rap") id=15 ;;
467 "reggae") id=16 ;;
468 "rock") id=17 ;;
469 "techno") id=18 ;;
470 "industrial") id=19 ;;
471 "alternative") id=20 ;;
472 "ska") id=21 ;;
473 "death metal") id=22 ;;
474 "pranks") id=23 ;;
475 "soundtrack") id=24 ;;
476 "euro-techno") id=25 ;;
477 "ambient") id=26 ;;
478 "trip-hop") id=27 ;;
479 "vocal") id=28 ;;
480 "jazz+funk") id=29 ;;
481 "fusion") id=30 ;;
482 "trance") id=31 ;;
483 "classical") id=32 ;;
484 "instrumental") id=33 ;;
485 "acid") id=34 ;;
486 "house") id=35 ;;
487 "game") id=36 ;;
488 "sound clip") id=37 ;;
489 "gospel") id=38 ;;
490 "noise") id=39 ;;
491 "alt. rock") id=40 ;;
492 "bass") id=41 ;;
493 "soul") id=42 ;;
494 "punk") id=43 ;;
495 "space") id=44 ;;
496 "meditative") id=45 ;;
497 "instrum. pop") id=46 ;;
498 "instrum. rock") id=47 ;;
499 "ethnic") id=48 ;;
500 "gothic") id=49 ;;
501 "darkwave") id=50 ;;
502 "techno-indust.") id=51 ;;
503 "electronic") id=52 ;;
504 "pop-folk") id=53 ;;
505 "eurodance") id=54 ;;
506 "dream") id=55 ;;
507 "southern rock") id=56 ;;
508 "comedy") id=57 ;;
509 "cult") id=58 ;;
510 "gangsta") id=59 ;;
511 "top 40") id=60 ;;
512 "christian rap") id=61 ;;
a9a23379 513 "pop/funk"|"pop / funk") id=62 ;;
2994a485 514 "jungle") id=63 ;;
515 "native american") id=64 ;;
516 "cabaret") id=65 ;;
517 "new wave") id=66 ;;
518 "psychadelic") id=67 ;;
519 "rave") id=68 ;;
520 "showtunes") id=69 ;;
521 "trailer") id=70 ;;
522 "lo-fi") id=71 ;;
523 "tribal") id=72 ;;
524 "acid punk") id=73 ;;
525 "acid jazz") id=74 ;;
526 "polka") id=75 ;;
527 "retro") id=76 ;;
528 "musical") id=77 ;;
529 "rock & roll") id=78 ;;
530 "hard rock") id=79 ;;
531 "folk") id=80 ;;
532 "folk/rock") id=81 ;;
533 "national folk") id=82 ;;
534 "swing") id=83 ;;
535 "fusion") id=84 ;;
536 "bebob") id=85 ;;
537 "latin") id=86 ;;
538 "revival") id=87 ;;
539 "celtic") id=88 ;;
540 "bluegrass") id=89 ;;
541 "avantgarde") id=90 ;;
542 "gothic rock") id=91 ;;
543 "progress. rock") id=92 ;;
544 "psychadel. rock") id=93 ;;
545 "symphonic rock") id=94 ;;
546 "slow rock") id=95 ;;
547 "big band") id=96 ;;
548 "chorus") id=97 ;;
549 "easy listening") id=98 ;;
550 "acoustic") id=99 ;;
551 "humour") id=100 ;;
552 "speech") id=101 ;;
553 "chanson") id=102 ;;
554 "opera") id=103 ;;
555 "chamber music") id=104 ;;
556 "sonata") id=105 ;;
557 "symphony") id=106 ;;
558 "booty bass") id=107 ;;
559 "primus") id=108 ;;
560 "porn groove") id=109 ;;
561 "satire") id=110 ;;
562 "slow jam") id=111 ;;
563 "club") id=112 ;;
564 "tango") id=113 ;;
565 "samba") id=114 ;;
566 "folklore") id=115 ;;
567 "ballad") id=116 ;;
568 "power ballad") id=117 ;;
569 "rhythmic soul") id=118 ;;
570 "freestyle") id=119 ;;
571 "duet") id=120 ;;
572 "punk rock") id=121 ;;
573 "drum solo") id=122 ;;
574 "a capella") id=123 ;;
575 "euro-house") id=124 ;;
576 "dance hall") id=125 ;;
577 "goa") id=126 ;;
578 "drum & bass") id=127 ;;
579 "club-house") id=128 ;;
580 "hardcore") id=129 ;;
581 "terror") id=130 ;;
582 "indie") id=131 ;;
583 "britpop") id=132 ;;
584 "negerpunk") id=133 ;;
585 "polsk punk") id=134 ;;
586 "beat") id=135 ;;
587 "christian gangsta rap") id=136 ;;
588 "heavy metal") id=137 ;;
589 "black metal") id=138 ;;
590 "crossover") id=139 ;;
591 "contemporary christian")id=140 ;;
592 "christian rock") id=141 ;;
593 "merengue") id=142 ;;
594 "salsa") id=143 ;;
595 "thrash metal") id=144 ;;
596 "anime") id=145 ;;
597 "jpop") id=146 ;;
598 "synthpop") id=147 ;;
a9a23379 599 "rock/pop"|"rock / pop") id=148 ;;
2994a485 600 *) return 1 ;;
601 esac
602echo ${id}
603return 0
604}
605
c9c2ca27 606# do_tag [tracknumber]
607# id3 tags a filename
608# variables used:
609# TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
610# COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
611do_tag ()
612{
613 COMMENTOUTPUT="$(eval echo ${COMMENT})"
d823b8fc 614 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
c9c2ca27 615 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
79e3928b 616 # If we want to start the tracks with a given number, we need to modify the
617 # TRACKNUM value before evaluation
c0fc2e81 618 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
619 do_gettracknum
79e3928b 620 fi
c9c2ca27 621 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
622 do
1a064efb 623 case "$OUTPUT" in
624 mp3)
625 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
626 GENREID=$(do_getgenreid "${CDGENRE}")
627
628 case "$ID3SYNTAX" in
629 id3);;
630 eyed3)
631 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
632 run_command tagtrack-$OUTPUT-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
633 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
634 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
635 "${ENCODING:+--set-encoding=$ENCODING}"
636 "$ABCDETEMPDIR/track$1.$OUTPUT"
637 ;;
638 *)
639 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
640 run_command tagtrack-$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
641 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
642 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
643 "$ABCDETEMPDIR/track$1.$OUTPUT"
644 ;;
645 esac
646 ;;
647 vorbis|ogg)
648 case "$OGGENCODERSYNTAX" in
649 vorbize|oggenc)
650 # vorbiscomment can't do in-place modification, mv the file first
651 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
652 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
653 fi
654 (
655 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
656 echo ARTIST="$TRACKARTIST"
657 echo ALBUM="$DALBUM"
658 echo TITLE="$TRACKNAME"
659 if [ -n "$CDYEAR" ]; then
660 echo DATE="$CDYEAR"
661 fi
662 if [ -n "$CDGENRE" ]; then
663 echo GENRE="$CDGENRE"
664 fi
665 echo TRACKNUMBER=${TRACKNUM:-$1}
666 echo CDDB=$CDDBDISCID
667 if [ "$(eval echo ${COMMENT})" != "" ]; then
668 case "$COMMENTOUTPUT" in
669 *=*) echo "$COMMENTOUTPUT";;
670 *) echo COMMENT="$COMMENTOUTPUT";;
671 esac
672 fi
673 ) | run_command tagtrack-$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
674 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
675 # Doublecheck that the commented file was created successfully before wiping the original
676 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
677 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
678 else
679 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
680 fi
681 ;;
682 esac
683 ;;
684 flac)
685 (
686 echo ARTIST="$TRACKARTIST"
687 echo ALBUM="$DALBUM"
688 echo TITLE="$TRACKNAME"
689 if [ -n "$CDYEAR" ]; then
690 echo DATE="$CDYEAR"
691 fi
692 if [ -n "$CDGENRE" ]; then
693 echo GENRE="$CDGENRE"
694 fi
695 echo TRACKNUMBER="${TRACKNUM:-$1}"
696 echo CDDB="$CDDBDISCID"
697 if [ "$(eval echo ${COMMENT})" != "" ]; then
698 case "$COMMENTOUTPUT" in
699 *=*) echo "$COMMENTOUTPUT";;
700 *) echo COMMENT="$COMMENTOUTPUT";;
701 esac
702 fi
703 ) | run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
704 ;;
705 spx)
706 run_command tagtrack-$OUTPUT-$1 true
707 ;;
708 mpc)
709 run_command tagtrack-$OUTPUT-$1 true
710 ;;
b69a8bb4 711 wav)
712 run_command tagtrack-$OUTPUT-$1 true
713 ;;
c9c2ca27 714 esac
c9c2ca27 715 done
33bc33c3 716 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1a064efb 717 run_command tagtrack-$1 true
718 fi
719
c9c2ca27 720}
721
0709e644 722# do_nogap_encode
c9c2ca27 723# variables used:
724# OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
0709e644 725do_nogap_encode ()
c9c2ca27 726{
727 # The commands here don't go through run_command because they're never supposed to be silenced
0709e644 728 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
729 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
730 do
731 case "$OUTPUT" in
732 mp3)
733 case "$MP3ENCODERSYNTAX" in
734 lame)
735 (
736 cd "$ABCDETEMPDIR"
737 TRACKFILES=
c9c2ca27 738 for UTRACKNUM in $TRACKQUEUE
739 do
0709e644 740 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
c9c2ca27 741 done
0709e644 742 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
743 RETURN=$?
744 if [ "$RETURN" != "0" ]; then
745 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
746 else
747 for UTRACKNUM in $TRACKQUEUE
748 do
749 run_command encodetrack-$OUTPUT-$UTRACKNUM true
750 #run_command encodetrack-$UTRACKNUM true
751 done
752 fi
753 )
754 ;;
755 esac
c9c2ca27 756 ;;
757 esac
0709e644 758 done
759 if checkerrors "nogap-encode"; then :; else
760 if [ ! "$KEEPWAVS" = "y" ] ; then
761 if [ ! "$KEEPWAVS" = "move" ] ; then
762 rm -f "$IN"
763 fi
764 fi
765 fi
c9c2ca27 766 # Other encoders fall through to normal encoding as the tracks
767 # have not been entered in the status file.
768}
769
770# do_encode [tracknumber] [hostname]
771# If no hostname is specified, encode locally
772# variables used:
773# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
774do_encode ()
775{
0a3a2dcc 776 if [ "$USEPIPES" = "y" ]; then
777 case "$OUTPUT" in
778 mp3)
779 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
780 ;;
b82e2042 781 vorbis|ogg)
0a3a2dcc 782 TEMPARG="PIPE_$OGGENCODERSYNTAX"
783 ;;
784 flac)
785 TEMPARG="PIPE_$FLACENCODERSYNTAX"
786 ;;
787 spx)
788 TEMPARG="PIPE_$SPEEXENCODER"
789 ;;
790 mpc)
791 TEMPARG="PIPE_$MPPENCODER"
792 ;;
793 esac
a9a23379 794 IN="$( eval echo "\$$TEMPARG" )"
0a3a2dcc 795 else
796 IN="$ABCDETEMPDIR/track$1.wav"
797 case "$OUTPUT" in
798 mp3)
799 case "$MP3ENCODERSYNTAX" in
800 # FIXME # check if mp3enc needs -if for pipes
cb801544 801 # FIXME # I have not been able to find a working mp3enc binary
0a3a2dcc 802 mp3enc)
803 FILEARG="-if $IN"
804 ;;
805 *)
03308bc7 806 FILEARG="$IN"
0a3a2dcc 807 ;;
808 esac
809 ;;
810 *)
03308bc7 811 FILEARG="$IN"
0a3a2dcc 812 ;;
813 esac
814 fi
815 # We need IN to proceed, if we are not using pipes.
816 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
c9c2ca27 817 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
818 do
0709e644 819 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
820 continue
821 fi
b82e2042 822 case "$OUTPUT" in
823 vorbis|ogg)
824 OUT="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
825 ;;
826 flac)
827 OUT="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
828 ;;
829 *)
830 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
831 ;;
832 esac
0a3a2dcc 833 if [ X"$USEPIPES" = "Xy" ]; then
834 RUN_COMMAND=""
835 else
836 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
837 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
838 fi
c9c2ca27 839 case "$OUTPUT" in
840 mp3)
841 case "$2" in
842 %local*%)
843 case "$MP3ENCODERSYNTAX" in
0a3a2dcc 844 lame|gogo) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
845 bladeenc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
846 l3enc|xingmp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
847 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
848 mp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
c9c2ca27 849 esac
850 ;;
851 *)
0a3a2dcc 852 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
c9c2ca27 853 ;;
854 esac
855 ;;
b82e2042 856 vorbis|ogg)
c9c2ca27 857 case "$2" in
858 %local*%)
859 case "$OGGENCODERSYNTAX" in
0a3a2dcc 860 vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
861 oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
c9c2ca27 862 esac
863 ;;
864 *)
0a3a2dcc 865 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
c9c2ca27 866 ;;
867 esac
868 ;;
869 flac)
c9c2ca27 870 case "$2" in
871 %local*%)
872 case "$FLACENCODERSYNTAX" in
6119aaa1 873 flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER $FLACENCODEROPTS -o "$OUT" "$IN" ;;
c9c2ca27 874 esac
875 ;;
876
877 *)
878 echo -n "DISTMP3:"
879 echo "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
0a3a2dcc 880 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
c9c2ca27 881 ;;
882 esac
883 ;;
884 spx)
885 if [ "$(eval echo ${COMMENT})" != "" ]; then
886 case "$COMMENT" in
887 *=*) ;;
888 *) COMMENT="COMMENT=$COMMENT" ;;
889 esac
890 COMMENT="--comment \"$COMMENT\""
891 fi
892 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
893 if [ ! "$DOTAG" = "y" ]; then
0a3a2dcc 894 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
c9c2ca27 895 else
0a3a2dcc 896 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
c9c2ca27 897 fi
898 ;;
99d009fa 899 mpc)
900 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
901 # tagging.
902 # I tried compiling the mppenc from corecodecs.org and got some
903 # errors, so I have not tried it myself.
904 ## FIXME ## Needs some cleanup to determine if an empty tag sent
905 ## FIXME ## to the encoder ends up empty.
0a3a2dcc 906 $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
99d009fa 907 ;;
b69a8bb4 908 wav)
909 # In case of wav output we need nothing. Just keep the wavs.
910 run_command encodetrack-$OUTPUT-$1 true
911 ;;
c9c2ca27 912 esac
913 done
914 # Only remove .wav if the encoding succeeded
33bc33c3 915 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
c9c2ca27 916 run_command encodetrack-$1 true
917 if [ ! "$KEEPWAVS" = "y" ] ; then
b69a8bb4 918 if [ ! "$KEEPWAVS" = "move" ] ; then
919 rm -f "$IN"
920 fi
c9c2ca27 921 fi
922 fi
923 else
1a064efb 924 run_command "" echo "HEH! The file we were about to encode disappeared:"
925 run_command "" echo ">> $IN"
c9c2ca27 926 run_command encodetrack-$1 false
927 fi
928}
929
99d009fa 930# do_preprocess [tracknumber]
931# variables used:
932# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
933#do_preprocess ()
934#{
935# IN="$ABCDETEMPDIR/track$1.wav"
936# # We need IN to proceed.
937# if [ -s "$IN" ] ; then
938# for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
939# do
940# #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
941# run_command '' echo "Pre-processing track $1 of $TRACKS..."
942# case "$POSTPROCESSFORMAT" in
943# all|wav*)
944# run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
945# mp3)
946# run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
947# ogg)
948# run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
949# flac)
950# run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
951# spx)
952# run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
953# esac
954# done
955# # Only remove .wav if the encoding succeeded
956# if checkerrors "preprocess-(.{3,4})-$1"; then
957# run_command preprocess-$1 false
958# else
959# run_command preprocess-$1 true
960# fi
961# else
962# if [ "$(checkstatus encode-output)" = "loud" ]; then
963# echo "HEH! The file we were about to pre-process disappeared:"
964# echo ">> $IN"
965# fi
966# run_command preprocess-$1 false
967# fi
968#}
969
970
971# do_postprocess [tracknumber]
972# variables used:
973# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
974#do_postprocess ()
975#{
976# for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
977# do
978# IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
979# # We need IN to proceed.
980# if [ -s "$IN" ] ; then
981# #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
982# run_command '' echo "Post-processing track $1 of $TRACKS..."
983# case "$POSTPROCESSFORMAT" in
984# mp3)
985# run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
986# ogg)
987# run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
988# flac)
989# run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
990# spx)
991# run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
992# esac
993# # Only remove .wav if the encoding succeeded
994# if checkerrors "postprocess-(.{3,4})-$1"; then
995# run_command postprocess-$1 false
996# else
997# run_command postprocess-$1 true
998# fi
999# else
1000# if [ "$(checkstatus encode-output)" = "loud" ]; then
1001# echo "HEH! The file we were about to post-process disappeared:"
1002# echo ">> $IN"
1003# fi
1004# run_command postprocess-$1 false
1005# fi
1006# done
1007#}
1008
79c8f4d0 1009# do_single_gain
1010# variables used:
1011# FIXME #
1012do_single_gain ()
1013{
1014:
1015}
1016
99d009fa 1017# do_batch_gain
1018# variables used:
1019# MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS
79c8f4d0 1020# FIXME #
99d009fa 1021do_batch_gain ()
1022{
1023 # The commands here don't go through run_command because they're never supposed to be silenced
1024 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1025 (
1026 cd "$ABCDETEMPDIR"
1027 BLURB=
1028 TRACKFILES=
1029 for UTRACKNUM in $TRACKQUEUE
1030 do
1031 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1032 done
cb801544 1033 # FIXME # Hard-coded batch option!
99d009fa 1034 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1035 RETURN=$?
1036 if [ "$RETURN" != "0" ]; then
1037 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1038 else
1039 for UTRACKNUM in $TRACKQUEUE
1040 do
1041 echo normalizetrack-$UTRACKNUM >> status
1042 done
1043 fi
1044 )
1045}
1046
c9c2ca27 1047# do_batch_normalize
1048# variables used:
1049# NORMALIZER, NORMALIZEROPTS
1050do_batch_normalize ()
1051{
1052 # The commands here don't go through run_command because they're never supposed to be silenced
1053 echo "Batch normalizing tracks: $TRACKQUEUE"
1054 (
1055 cd "$ABCDETEMPDIR"
1056 BLURB=
1057 TRACKFILES=
1058 for UTRACKNUM in $TRACKQUEUE
1059 do
1060 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1061 done
1062 # XXX: Hard-coded batch option!
1063 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1064 RETURN=$?
1065 if [ "$RETURN" != "0" ]; then
1066 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1067 else
1068 for UTRACKNUM in $TRACKQUEUE
1069 do
1070 echo normalizetrack-$UTRACKNUM >> status
1071 done
1072 fi
1073 )
1074}
1075
1076# do_normalize [tracknumber]
1077# variables used:
1078# TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1079do_normalize ()
1080{
1081 IN="$ABCDETEMPDIR/track$1.wav"
1082 if [ -e "$IN" ] ; then
1083 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1084 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1085 else
1086 if [ "$(checkstatus encode-output)" = "loud" ]; then
1087 echo "HEH! The file we were about to normalize disappeared:"
1088 echo ">> $IN"
1089 fi
1090 run_command normalizetrack-$1 false "File $IN was not found"
1091 fi
1092}
1093
1094# do_move [tracknumber]
1095# Deduces the outfile from environment variables
1096# Creates directory if necessary
1097# variables used:
99d009fa 1098# TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
c9c2ca27 1099do_move ()
1100{
1101 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1102 do
1103 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1104 # Munge filenames as follows:
1105 # ' ' -> '_'
1106 # '/' -> '_'
1107 # ''' -> ''
1108 # '?' -> ''
1109 # Eat control characters
fe4d186c 1110 ALBUMFILE="$(mungefilename "$DALBUM")"
1111 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1112 TRACKFILE="$(mungefilename "$TRACKNAME")"
1113 GENRE="$(mungegenre "$GENRE")"
1114 YEAR="$(echo $CDYEAR)"
99d009fa 1115 # If we want to start the tracks with a given number, we need to modify the
1116 # TRACKNUM value before evaluation
c0fc2e81 1117 do_gettracknum
99d009fa 1118 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1119 # TRACKFILE, and TRACKNUM.
c9c2ca27 1120 if [ "$VARIOUSARTISTS" = "y" ]; then
fe4d186c 1121 OUTPUTFILE="$(eval echo "$VAOUTPUTFORMAT")"
1122 else
1123 OUTPUTFILE="$(eval echo "$OUTPUTFORMAT")"
c9c2ca27 1124 fi
1a064efb 1125 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1126 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1127 case $OUTPUT in
1128 vorbis|ogg)
1129 OUTPUT=$OGGOUTPUTCONTAINER
1130 ;;
1131 flac)
1132 OUTPUT=$FLACOUTPUTCONTAINER
1133 ;;
1134 esac
1135 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
fe4d186c 1136 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
75c2c424 1137 case $OUTPUT in
1138 wav)
1139 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
cb801544 1140 # FIXME # introduce warnings?
75c2c424 1141 :
1142 else
1143 # mkdir -p shouldn't return an error if the directory already exists
1144 mkdir -p "$OUTPUTFILEDIR"
1145 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1146 if checkstatus movetrack-output-$OUTPUT; then :; else
1147 run_command movetrack-output-$OUTPUT true
1148 fi
1149 fi
1150 ;;
1151 *)
1152 # mkdir -p shouldn't return an error if the directory already exists
1153 mkdir -p "$OUTPUTFILEDIR"
1154 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1155 if checkstatus movetrack-output-$OUTPUT; then :; else
1156 run_command movetrack-output-$OUTPUT true
1157 fi
1158 ;;
1159 esac
1a064efb 1160 # Lets move the cue file
1161 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1162 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1163 if checkstatus movecue-$OUTPUT; then :; else
1164 # Silence the Copying output since it overlaps with encoding processes...
1165 #run_command '' vecho "Copying cue file to its destination directory..."
1166 if checkstatus onetrack >/dev/null ; then
1167 case $OUTPUT in
75c2c424 1168 wav)
1169 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1170 # We dont have the dir, since it was not created before.
1171 :
1172 else
1173 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1174 fi
1175 ;;
1a064efb 1176 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1177 # http://brianvictor.tripod.com/mp3cue.htm#details
1178 [a-z0-9][a-z0-9][a-z0-9])
1179 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1180 ;;
1181 *)
1182 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1183 ;;
1184 esac
1185 else
1186 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1187 fi
1188 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
3416c114 1189 fi
b82e2042 1190 fi
1191 fi
1192 fi
c9c2ca27 1193 done
1194}
1195
1196# do_playlist
1197# Create the playlist if wanted
1198# Variables used:
1199# PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1200# VARIOUSARTISTS, OUTPUTDIR
1201do_playlist ()
1202{
1203 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1204 do
0705fcef 1205 case $OUTPUT in
1206 vorbis|ogg)
1207 OUTPUT=$OGGOUTPUTCONTAINER
1208 ;;
1209 flac)
1210 OUTPUT=$FLACOUTPUTCONTAINER
1211 ;;
1212 esac
c9c2ca27 1213 # Create a playlist file for the playlist data to go into.
1214 # We used to wipe it out if it existed. Now we request permision if interactive.
1215 for LASTTRACK in $TRACKQUEUE; do :; done
fe4d186c 1216 ALBUMFILE="$(mungefilename "$DALBUM")"
1217 ARTISTFILE="$(mungefilename "$DARTIST")"
7acef70b 1218 GENRE=$(mungegenre "$GENRE")
76448acf 1219 YEAR=${CDYEAR:-$CDYEAR}
c9c2ca27 1220 if [ "$VARIOUSARTISTS" = "y" ] ; then
1221 PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
1222 else
1223 PLAYLISTFILE=$(eval echo $PLAYLISTFORMAT)
1224 fi
1225 FINALPLAYLISTDIR=$(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1226 mkdir -p "$FINALPLAYLISTDIR"
1227 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
99d009fa 1228 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
c9c2ca27 1229 if [ "$INTERACTIVE" = "y" ]; then
99d009fa 1230 while [ "$DONE" != "y" ]; do
1231 read ERASEPLAYLIST
1232 case $ERASEPLAYLIST in
1233 e|E|a|A|k|K) DONE=y ;;
1234 *) ;;
1235 esac
1236 done
c9c2ca27 1237 else
99d009fa 1238 echo e >&2
1239 ERASEPLAYLIST=e
c9c2ca27 1240 fi
40c61684 1241 # Once we erase the playlist, we use append to create the new one.
1242 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1243 else
1244 # The playlist does not exist, so we can safelly use append to create the new list
1245 ERASEPLAYLIST=a
c9c2ca27 1246 fi
99d009fa 1247 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1248 touch "$OUTPUTDIR/$PLAYLISTFILE"
1249 for UTRACKNUM in $TRACKQUEUE
1250 do
1251 # Shares some code with do_move since the filenames have to match
1252 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
c0fc2e81 1253 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2 -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')
1254 do_getcddbinfo TRACKNAME
99d009fa 1255 splitvarious
fe4d186c 1256 TRACKFILE="$(mungefilename "$TRACKNAME")"
1257 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1258 ALBUMFILE="$(mungefilename "$DALBUM")"
99d009fa 1259 # If we want to start the tracks with a given number, we need to modify the
1260 # TRACKNUM value before evaluation
00840d9a 1261 do_gettracknum
99d009fa 1262 if [ "$VARIOUSARTISTS" = "y" ]; then
1263 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
c9c2ca27 1264 else
99d009fa 1265 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
c9c2ca27 1266 fi
99d009fa 1267 if [ "$VARIOUSARTISTS" = "y" ]; then
1268 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1269 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1270 else
1271 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1272 fi
1273 else
1274 if [ "$PLAYLISTDATAPREFIX" ]; then
1275 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1276 else
1277 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1278 fi
1279 fi
1280 done
1281 fi
c9c2ca27 1282 ## this will convert the playlist to have CRLF line-endings, if specified
1283 ## (some hardware players insist on CRLF endings)
1284 if [ "$DOSPLAYLIST" = "y" ]; then
1285 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
99d009fa 1286# mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1287 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
c9c2ca27 1288 fi
1289 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1290 done
1291}
1292
1293# do_discid
1294# This essentially the start of things
1295do_discid ()
1296{
1297 # Query the CD to get the track info, unless the user specified -C
12c5d978 1298 # or we are using some actions which do not need the CDDB data at all
1299 #if [ ! X"$EXPACTIONS" = "X" ]; then
1300 # :
1301 #elif [ -z "$DISCID" ]; then
c9c2ca27 1302 if [ -z "$DISCID" ]; then
9f659ada 1303 vecho -n "Getting CD track info... "
b82e2042 1304 # In OSX, unmount the disc before a query
f97e22a3 1305 if [ "$OSFLAVOUR" = "OSX" ]; then
1306 disktool -u ${CDROM#/dev/}
1307 fi
1b94d6b7 1308 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1309 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM | $CUE2DISCID)
1310 else
1311 TRACKINFO=$($CDDISCID $CDROM)
1312 fi
c9c2ca27 1313 # Make sure there's a CD in there by checking cd-discid's return code
1b94d6b7 1314 if [ ! "$?" = "0" ]; then
1315 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1316 echo "abcde error: cuesheet information from the flac file could not be read." >&2
1317 echo "abcde error: Perhaps the flac file does not contain a cuesheet?." >&2
1318 exit 1
1319 else
1320 echo "abcde error: CD could not be read. Perhaps there's no CD in the drive?" >&2
1321 exit 1
1322 fi
c9c2ca27 1323 fi
b82e2042 1324 # In OSX, remount the disc again
1325 if [ "$OSFLAVOUR" = "OSX" ]; then
1326 disktool -m ${CDROM#/dev/}
1327 fi
99d009fa 1328 WEHAVEACD=y
c9c2ca27 1329 else
1330 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1331 fi
1332
1333 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1334 # This needs to be done now because a section of the resuming code will need
1335 # it later.
1336
1337 # get the number of digits to pad TRACKNUM with - we'll use this later
12c5d978 1338 # a CD can only hold 99 tracks, but since we support a feature for starting
1339 # numbering the tracks from a given number, we might need to set it as a
1340 # variable for the user to define... or obtain it somehow.
c9c2ca27 1341 if [ "$PADTRACKS" = "y" ] ; then
1342 TRACKNUMPADDING=2
1343 fi
1344
99d009fa 1345 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
c9c2ca27 1346 if [ -z "$TRACKQUEUE" ]; then
99d009fa 1347 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1348 case "$CDROMREADERSYNTAX" in
1349 cdparanoia|debug)
1350 if [ "$WEHAVEACD" = "y" ]; then
1351 vecho "Querying the CD for audio tracks..."
c008b56d 1352 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
09a85005 1353 RET=$?
1354 if [ ! "$RET" = "0" ];then
1355 echo "Warning: Something went wrong while querying the CD... Maybe a DATA CD?"
1356 fi
79558516 1357 TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
99d009fa 1358 CDPARANOIAAUDIOTRACKS="$TRACKS"
1359 else
088b03ff 1360 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
99d009fa 1361 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1362 fi
1363 fi
1364 ;;
1365 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1366 esac
1367 else
1368 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1369 fi
bef9c2d8 1370 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
09a85005 1371 echo "The disc does not contain any tracks. Giving up..."
1372 exit 0
1373 fi
c9c2ca27 1374 echo -n "Grabbing entire CD - tracks: "
1375 if [ ! "$PADTRACKS" = "y" ] ; then
1376 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1377 fi
1378 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1379 X=0
1380 while [ "$X" -ne "$TRACKS" ]
1381 do
1382 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
0709e644 1383 TRACKQUEUE=$(echo $TRACKQUEUE $X)
c9c2ca27 1384 done
1385 echo $TRACKQUEUE
1386 else
99d009fa 1387 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
c9c2ca27 1388 # User-supplied track queue.
1389 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1390 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1391 # Once cleaned, obtain the highest value in the trackqueue for number padding
1392 for LASTTRACK in $TRACKQUEUE; do :; done
1393 if [ ! "$PADTRACKS" = "y" ] ; then
1394 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1395 fi
1396 # Now we normalize the trackqueue
1397 for TRACK in $TRACKQUEUE ; do
1398 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1399 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1400 done
1401 TRACKQUEUE=$PADTRACKQUEUE
1402 echo Grabbing tracks: "$TRACKQUEUE"
1403 fi
1404
c9c2ca27 1405 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1406
1407 # We have the discid, create a temp directory after it to store all the temp
1408 # info
1409
c9c2ca27 1410 if [ -e "$ABCDETEMPDIR" ]; then
1411 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1412 # It already exists, see if it's a directory
1413 if [ ! -d "$ABCDETEMPDIR" ]; then
1414 # This is a file/socket/fifo/device/etc, not a directory
1415 # Complain and exit
1416 echo >&2
1417 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1418 echo "Please investigate, remove it, and rerun abcde." >&2
1419 exit 1
1420 fi
1421 echo -n .
1422 # It's a directory, let's see if it's owned by us
1423 if [ ! -O "$ABCDETEMPDIR" ]; then
1424 # Nope, complain and exit
1425 echo >&2
1426 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1427 echo "Please investigate, remove it, and rerun abcde." >&2
1428 exit 1
1429 fi
1430 echo .
1431 # See if it's populated
1432 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1433 # Wipe and start fresh
1434 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1435 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1436 if [ "$INTERACTIVE" = "y" ]; then
1437 read ANSWER
1438 else
1439 echo y >&2
1440 ANSWER=y
1441 fi
1442 if [ "$ANSWER" != "y" ]; then
1443 exit 1
1444 fi
1445 rm -rf "$ABCDETEMPDIR" || exit 1
1446 mkdir "$ABCDETEMPDIR"
1447 if [ "$?" -gt "0" ]; then
1448 # Directory already exists or could not be created
1449 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1450 exit 1
1451 fi
1452 else
1453 # Everything is fine. Check for ^encodetracklocation-
1454 # and encode-output entries in the status file and
1455 # remove them. These are not relevant across sessions.
1456 if [ -f "$ABCDETEMPDIR/status" ]; then
1457 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1458 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1459 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1460 fi
1461 # Remove old error messages
1462 if [ -f "$ABCDETEMPDIR/errors" ]; then
1463 rm -f "$ABCDETEMPDIR/errors"
1464 fi
1465 fi
1466 else
1467 # We are starting from scratch
1468 mkdir "$ABCDETEMPDIR"
1469 if [ "$?" -gt "0" ]; then
1470 # Directory already exists or could not be created
1471 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1472 exit 1
1473 fi
1474 cat /dev/null > "$ABCDETEMPDIR/status"
1475 fi
b82e2042 1476 if [ X"$MAKECUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1477 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1478 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1479 vecho "Creating cue file..."
411ef0b0 1480 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1481 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1482 else
1483 echo "abcde: reading the CUE sheet with mkcue is still considered experimental"
1484 echo "abcde: and there was a problem with the CD reading. abcde will continue,"
1485 echo "abcde: but consider reporting the problem to the abcde author"
1486 fi
24f444d7 1487 fi
1488 fi
99d009fa 1489 # If we got the CDPARANOIA status and it is not recorded, save it now
c7ea851d 1490 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
088b03ff 1491 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
79558516 1492 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
99d009fa 1493 fi
1494 fi
1495
c9c2ca27 1496 # Create the discid file
1497 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
c9c2ca27 1498}
1499
79c8f4d0 1500# do_cleancue
1501# Create a proper CUE file based on the CUE file we created before.
1502do_cleancue()
f97e22a3 1503{
b82e2042 1504 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1505 CUEFILE_OUT=$CUEFILE_IN.out
79c8f4d0 1506 ### FIXME ### checkstatus cddb
b82e2042 1507 if [ -e "$CDDBDATA" ]; then
1508 vecho "Adding metadata to the cue file..."
1509 # FIXME It doesn't preserve spaces! Why?
1510 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1511 n=1
1512 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1513 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1514 cat "$CUEFILE_IN" | while read line
1515 do
1516 if echo "$line" | grep -q "INDEX"
1517 then
1518 eval track="\$TRACK$n"
1519 n=$(expr $n + 1)
1520 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1521 fi
1522 echo "$line" >> "$CUEFILE_OUT"
1523 done
1524 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1525 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
79c8f4d0 1526 fi
1527 fi
f97e22a3 1528}
1529
c9c2ca27 1530# do_cddbparse
1531# Parses a CDDB file and outputs the title and the track names.
1532# Variables: CDDBFILE
1533do_cddbparse ()
1534{
1535 CDDBPARSEFILE="$1"
1536 # List out disc title/author and contents
1537 if [ "$ONETRACK" = "y" ]; then
1538 vecho "ONETRACK mode selected: displaying only the title of the CD..."
1539 fi
1540 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
9ff5088c 1541 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
1542 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
913e4339 1543 if [ ! X"$PARSEDYEAR" = "X" ]; then
f75dae43 1544 echo "Year: $PARSEDYEAR"
9ff5088c 1545 fi
1546 fi
1547 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
1548 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
913e4339 1549 if [ ! X"$PARSEDGENRE" = "X" ]; then
f75dae43 1550 echo "Genre: $PARSEDGENRE"
9ff5088c 1551 fi
1552 fi
99d009fa 1553 if [ ! "$ONETRACK" = "y" ]; then
c9c2ca27 1554 for TRACK in $(f_seq_row 1 $TRACKS)
1555 do
1556 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1557 done
1558 fi
1559}
1560
1561# do_localcddb
1562# Check for a local CDDB file, and report success
1563do_localcddb ()
1564{
1565 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
1566
1567 CDDBLOCALSUCCESS="n"
1568 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1569 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1570 USELOCALRESP="y"
1571
1572 # If the user has selected to check a local CDDB repo, we proceed with it
04609998 1573 if [ -r "${CDDBLOCALFILE}" ]; then
1574 # List out disc title/author and contents
1575 do_cddbparse "${CDDBLOCALFILE}"
1576 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1577 if [ "$INTERACTIVE" = "y" ]; then
1578 read USELOCALRESP
1579 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1580 echo -n 'Invalid selection. Please answer "y" or "n": '
c9c2ca27 1581 read USELOCALRESP
04609998 1582 done
1583 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
1584 else
1585 echo "y" >&2
1586 fi
1587 if [ "$USELOCALRESP" = "y" ]; then
786d4b2e 1588 #echo "Using local copy of CDDB data"
0709e644 1589 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1590 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
04609998 1591 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1592 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
1593 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1594 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1595 CDDBLOCALSUCCESS="y"
c9c2ca27 1596 else
04609998 1597 #echo "Not using local copy of CDDB data"
c9c2ca27 1598 CDDBLOCALSUCCESS="n"
1599 fi
04609998 1600 else
1601 CDDBLOCALSUCCESS="n"
c9c2ca27 1602 fi
1603 fi
1604}
1605
1606# do_cddbstat
1607do_cddbstat ()
1608{
1609 # Perform CDDB protocol version check if it hasn't already been done
1610 if checkstatus cddb-statcomplete; then :; else
1611 if [ "$CDDBAVAIL" = "n" ]; then
1612 ERRORCODE=no_query
1613 echo 503 > "$ABCDETEMPDIR/cddbstat"
1614 else
1615 rc=1
1616 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1617 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1618 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1619 vecho "Checking CDDB server status..."
1620 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1621 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
1622 case "$RESPONSECODE" in
1623 210) # 210 OK, status information follows (until terminating `.')
1624 rc=0;
1625 ;;
1626 501|*) # 501 Illegal CDDB protocol level: <n>.
1627 CDDBPROTO=`expr $CDDBPROTO - 1`
1628 ;;
1629 esac
1630 done
1631 if test $rc -eq 1; then
1632 CDDBAVAIL="n"
1633 fi
1634 fi
1635 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
1636 fi
1637}
1638
1639
1640# do_cddbquery
1641do_cddbquery ()
1642{
1643 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1644 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1645
1646 # Perform CDDB query if it hasn't already been done
1647 if checkstatus cddb-querycomplete; then :; else
1648 if [ "$CDDBAVAIL" = "n" ]; then
1649 ERRORCODE=no_query
1650 echo 503 > "$ABCDETEMPDIR/cddbquery"
1651 # The default CDDBLOCALSUCCESS is "n"
1652 # This part will be triggered if the user CDDB repo does not
1653 # contain the entry, or if we are not trying to use the repo.
1654 else
1655 vecho "Querying the CDDB server..."
1656 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1657 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1658 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1659 ERRORCODE=$?
1660 case $ERRORCODE in
1661 0) # success
1662 ;;
1663 12|13|14)
1664 # no match found in database,
1665 # wget/fetch error, or user requested not to use CDDB
1666 # Make up an error code (503) that abcde
1667 # will recognize in do_cddbread
1668 # and compensate by making a template
1669 echo 503 > "$ABCDETEMPDIR/cddbquery"
1670 ;;
1671 *) # strange and unknown error
1672 echo ERRORCODE=$ERRORCODE
1673 echo "abcde: $CDDBTOOL returned unknown error code"
1674 ;;
1675 esac
1676 fi
1677 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
1678 fi
1679}
1680
1681# do_cddbread
1682do_cddbread ()
1683{
1684 # If it's not to be used, generate a template.
1685 # Then, display it (or them) and let the user choose/edit it
1686 if checkstatus cddb-readcomplete; then :; else
1687 vecho "Obtaining CDDB results..."
1688 # If CDDB is to be used, interpret the query results and read all
1689 # the available entries.
1690 rm -f "$ABCDETEMPDIR/cddbchoices"
1691 CDDBCHOICES=1 # Overridden by multiple matches
1692 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
1693 case "$RESPONSECODE" in
1694 200)
1695 # One exact match, retrieve it
1696 # 200 [section] [discid] [artist] / [title]
1697 if checkstatus cddb-read-1-complete; then :; else
1698 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1699 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1700 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1701 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1702 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1703 fi
1704 # List out disc title/author and contents
1705 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1706 for TRACK in $(f_seq_row 1 $TRACKS)
1707 do
1708 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1709 done
1710 echo >> "$ABCDETEMPDIR/cddbchoices"
1711 ;;
1712 202|403|409|503)
1713 # No match
1714 case "$RESPONSECODE" in
1715 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1716 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1717 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1718 esac
99d009fa 1719 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
c9c2ca27 1720 # List out disc title/author and contents of template
1721 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
1722 UNKNOWNDISK=y
1723 for TRACK in $(f_seq_row 1 $TRACKS)
1724 do
99d009fa 1725 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
c9c2ca27 1726 done
1727 echo >> "$ABCDETEMPDIR/cddbchoices"
99d009fa 1728 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
1729 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
c9c2ca27 1730 ;;
1731 210|211)
1732 # Multiple exact, (possibly multiple) inexact matches
1733 IN=
1734 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
b82e2042 1735 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
c9c2ca27 1736 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1737 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1738 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1739 else
1740 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1741 fi
99d009fa 1742 vecho -n "Retrieving multiple matches... "
c9c2ca27 1743 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
1744 read DISCINFO # eat top line
1745 while read DISCINFO
1746 do
1747 X=$(expr $X + 1)
1748 if checkstatus cddb-read-$X-complete; then :; else
1749 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1750 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
1751 fi
1752 # List out disc title/author and contents
1753 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1754 for TRACK in $(f_seq_row 1 $TRACKS)
1755 do
1756 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1757 done
1758 echo >> "$ABCDETEMPDIR/cddbchoices"
1759 done )
99d009fa 1760 vecho "done."
c9c2ca27 1761 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1762 ;;
1763 999)
1764 # Using local copy.
1765 for TRACK in $(f_seq_row 1 $TRACKS)
1766 do
1767 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1768 done
1769 echo >> "$ABCDETEMPDIR/cddbchoices"
1770 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1771 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1772 ;;
1773 esac
1774 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1775 fi
1776}
1777
1778# do_cddbedit
1779do_cddbedit ()
1780{
1781 if checkstatus cddb-edit >/dev/null; then
1782 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1783 VARIOUSARTISTS="$(checkstatus variousartists)"
1784 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
1785 return 0
1786 fi
1787 if [ "$INTERACTIVE" = "y" ]; then
1788 # We should show the CDDB results both when we are not using the local CDDB repo
1789 # or when we are using it but we could not find a proper match
1790 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1791 # Display the $ABCDETEMPDIR/cddbchoices file created above
1792 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1793 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1794 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1795 CHOICE=$(checkstatus cddb-choice)
1796 if [ -n "$CHOICE" ] ; then
1797 case $CDDBCHOICES in
1798 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1799 *)
1800 echo "Selected: #$CHOICE"
1801 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1802 ;;
1803 esac
1804 else
1805 # The user has a choice to make, display the info in a pager if necessary
1806 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
913e4339 1807 page "$ABCDETEMPDIR/cddbchoices"
c9c2ca27 1808 else
1809 # It's all going to fit in one page, cat it
1810 cat "$ABCDETEMPDIR/cddbchoices" >&2
1811 fi
1812
9ff5088c 1813 CDDBCHOICENUM=""
913e4339 1814 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
f75dae43 1815 CDCHOICENUM=-1
c9c2ca27 1816 # I'll take CDDB read #3 for $400, Alex
9ff5088c 1817 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1818 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
c9c2ca27 1819 read CDDBCHOICE
9ff5088c 1820 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
1821 if echo $CDDBCHOICE | egrep -q "[[:digit:]]+,[[:digit:]]+" ; then
1822 if [ ! X"$DIFF" = "X" ]; then
9ff5088c 1823 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1)
1824 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2)
913e4339 1825 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1826 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1827 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1828 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1829 else
1830
1831 # We parse the 2 choices to diff, store them in temporary files and diff them.
1832 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
1833 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1834 done
1835 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1836 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1837 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
1838 page "$ABCDETEMPDIR/cddbread.diff"
1839 else
1840 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1841 fi
1842 fi
9ff5088c 1843 else
1844 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1845 fi
1846 else
1847 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
1848 # Make sure we get a valid choice
1849 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
1850 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1851 fi
1852 fi
c9c2ca27 1853 done
99d009fa 1854 if [ "$CDCHOICENUM" = "0" ]; then
1855 vecho "Creating empty CDDB template..."
1856 UNKNOWNDISK=y
b82e2042 1857 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
99d009fa 1858 else
03308bc7 1859 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
99d009fa 1860 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1861 fi
c9c2ca27 1862 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1863 fi
1864 fi
1865 else
1866 # We need some code to show the selected option when local repository is selected and we have found a match
9f659ada 1867 vecho "Using cached CDDB match..." >&2
c9c2ca27 1868 # Display the $ABCDETEMPDIR/cddbchoices file created above
1869 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1870 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1871 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1872 CHOICE=$(checkstatus cddb-choice)
1873 if [ "$USELOCALRESP" = "y" ]; then :; else
1874 if [ -n "$CHOICE" ] ; then
1875 case $CDDBCHOICES in
04609998 1876 0)
1877 UNKNOWNDISK=y
1878 echo "Selected template."
1879 ;;
c9c2ca27 1880 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1881 *)
1882 echo "Selected: #$CHOICE"
1883 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1884 ;;
1885 esac
1886 fi
1887 fi
1888 fi
1889 fi
1890 else
1891 # We're noninteractive - pick the first choice.
1892 # But in case we run a previous instance and selected a choice, use it.
1893 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1894 # Show the choice if we are not using the locally stored one
1895 # or when the local search failed to find a match.
1896 PREVIOUSCHOICE=$(checkstatus cddb-choice)
1897 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1898 #if [ "$PREVIOUSCHOICE" ]; then
1899 cat "$ABCDETEMPDIR/cddbchoices"
1900 #fi
1901 fi
1902 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1903 CDCHOICENUM=$PREVIOUSCHOICE
1904 else
1905 CDCHOICENUM=1
1906 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1907 fi
03308bc7 1908 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
c9c2ca27 1909 fi
1910 fi
1911
1912 # sanity check
1913 if checkstatus cddb-choice >/dev/null; then :; else
1914 echo "abcde: internal error: cddb-choice not recorded." >&2
1915 exit 1
1916 fi
1917 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
9f659ada 1918 echo -n "Edit selected CDDB data? [y/n] (" >&2
c9c2ca27 1919 if [ "$INTERACTIVE" = "y" ]; then
1920 if [ "$UNKNOWNDISK" = "y" ]; then
1921 echo -n "y): " >&2
1922 read EDITCDDB
1923 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
1924 else
1925 echo -n "n): " >&2
1926 read EDITCDDB
1927 fi
1928 else
1929 echo "n): n" >&2
1930 EDITCDDB=n
1931 fi
1932 if [ "$EDITCDDB" = "y" ]; then
1933 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
1934
1935 # Use the debian sensible-editor wrapper to pick the editor that the
1936 # user has requested via their $EDITOR environment variable
1937 if [ -x "/usr/bin/sensible-editor" ]; then
1938 /usr/bin/sensible-editor "$CDDBDATA"
1939 elif [ -n "$EDITOR" ]; then
1940 if [ -x $(which "${EDITOR%%\ *}") ]; then
1941 # That failed, try to load the preferred editor, starting
1942 # with their EDITOR variable
03308bc7 1943 eval $(echo "$EDITOR") \"$CDDBDATA\"
c9c2ca27 1944 fi
1945 # If that fails, check for a vi
2994a485 1946 elif which vi >/dev/null 2>&1; then
1947 vi "$CDDBDATA"
fd34b28b 1948 elif [ -x /usr/bin/vim ]; then
1949 /usr/bin/vim "$CDDBDATA"
c9c2ca27 1950 elif [ -x /usr/bin/vi ]; then
1951 /usr/bin/vi "$CDDBDATA"
fd34b28b 1952 elif [ -x /bin/vi ]; then
1953 /bin/vi "$CDDBDATA"
c9c2ca27 1954 # nano should be on all (modern, i.e., sarge) debian systems
2994a485 1955 elif which nano >/dev/null 2>&1 ; then
1956 nano "$CDDBDATA"
c9c2ca27 1957 elif [ -x /usr/bin/nano ]; then
1958 /usr/bin/nano "$CDDBDATA"
1959 # mg should be on all OpenBSD systems
2994a485 1960 elif which mg >/dev/null 2>&1 ; then
1961 mg "$CDDBDATA"
c9c2ca27 1962 elif [ -x /usr/bin/mg ]; then
1963 /usr/bin/mg "$CDDBDATA"
1964 # bomb out
1965 else
1966 echo "No editor available. Check your EDITOR environment variable." >&2
1967 fi
1968 # delete editor backup file if it exists
1969 if [ -w "$CDDBDATA~" ]; then
1970 rm -f "$CDDBDATA~"
1971 fi
1972 fi
1973
1974 # Some heuristics first. Look at Disc Title, and if it starts with
1975 # "Various", then we'll assume Various Artists
c81531ac 1976 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
c9c2ca27 1977 echo "Looks like a Multi-Artist CD" >&2
1978 VARIOUSARTISTS=y
1979 else
1980 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
1981 if [ "$INTERACTIVE" = "y" ]; then
1982 read VARIOUSARTISTS
1983 else
1984 echo n >&2
1985 VARIOUSARTISTS=n
1986 fi
1987 fi
1988 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
1989 # Set a default
1990 DEFAULTSTYLE=1
1991 # Need NUMTRACKS before cddb-tool will return it:
99d009fa 1992 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
c9c2ca27 1993 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1994 # More than 1/2 tracks contain a "/", so guess forward
1995 DEFAULTSTYLE=1
1996 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
1997 # More than 1/2 contain a "-", so guess forward-dash
1998 DEFAULTSTYLE=2
1999 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2000 # More than 1/2 contain something in parens, so guess trailing-paren
2001 DEFAULTSTYLE=6
2002 fi
2003
2004 echo "1) Artist / Title" >&2
2005 echo "2) Artist - Title" >&2
2006 echo "3) Title / Artist" >&2
2007 echo "4) Title - Artist" >&2
2008 echo "5) Artist: Title" >&2
2009 echo "6) Title (Artist)" >&2
2010 echo "7) This is a single-artist CD" >&2
2011 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2012 if [ "$INTERACTIVE" = "y" ]; then
2013 read VARIOUSARTISTSTYLE
2014 else
2015 echo $DEFAULTSTYLE >&2
2016 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2017 fi
2018 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2019 # If they press Enter, then the default style (0) was chosen
2020 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2021 echo "Invalid selection. Please choose a number between 1 and 7."
2022 echo -n "Selection [1-7]: "
2023 read VARIOUSARTISTSTYLE
2024 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2025 done
2026 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2027 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2028 fi
99d009fa 2029 vecho "Selected: $VARIOUSARTISTSTYLE"
c9c2ca27 2030 case "$VARIOUSARTISTSTYLE" in
2031 1) # Artist / Title
2032 VARIOUSARTISTSTYLE=forward
2033 ;;
2034 2) # Artist - Title
2035 VARIOUSARTISTSTYLE=forward-dash
2036 ;;
2037 3) # Title / Artist
2038 VARIOUSARTISTSTYLE=reverse
2039 ;;
2040 4) # Title - Artist
2041 VARIOUSARTISTSTYLE=reverse-dash
2042 ;;
2043 5) # Artist: Title
2044 VARIOUSARTISTSTYLE=colon
2045 ;;
2046 6) # Title (Artist)
2047 VARIOUSARTISTSTYLE=trailing-paren
2048 ;;
2049 7) # Single Artist
2050 VARIOUSARTISTS=n
2051 ;;
2052 esac
2053 fi
2054
2055 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2056 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2057
2058 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
a9a23379 2059 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
c9c2ca27 2060 # This works but does not have the necessary error checking
2061 # yet. If you are familiar with the CDDB spec
2062 # (see http://www.freedb.org/src/latest/DBFORMAT)
2063 # and can create an error-free entry on your own, then put
2064 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2065 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2066 # your abcde.conf to change the email address submissions are
2067 # sent to.
2068
2069 # submit the modified file, if they want
2070 if [ "$NOSUBMIT" != "y" ]; then
2071 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2072 read YESNO
2073 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2074 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2075 do
2076 echo -n 'Invalid selection. Please answer "y" or "n": '
2077 read YESNO
2078 done
2079 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2080 echo -n "Sending..."
2081 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2082 echo "done."
2083 fi
2084 fi
2085 fi
2086 fi
2087 # Make sure the cache directory exists
2088 mkdir -p $CDDBLOCALDIR
2089 # Cache edited CDDB entry in the user's cddb dir
2090 if [ "$CDDBCOPYLOCAL" = "y" ] || [ "$COPYCDDBLOCAL" = "Y" ]; then
2091 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2092 fi
2093
2094 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2095}
2096
c9c2ca27 2097# do_cdread [tracknumber]
d5200e72 2098# do_cdread onetrack [firsttrack] [lasttrack]
c9c2ca27 2099#
2100do_cdread ()
2101{
2102 # The commands here don't go through run_command because they're never supposed to be silenced
2103 # return codes need to be doublechecked anyway, however
d5200e72 2104 if [ "$1" = "onetrack" ]; then
2105 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
c7ea851d 2106 # FIXME # Until then, we grab the whole CD in one track, no matter what
2107 # the user said
d5200e72 2108 # We need the first and last track for cdda2wav
2109 FIRSTTRACK=$2
2110 LASTTRACK=$3
1366e842 2111 UTRACKNUM=$FIRSTTRACK
d5200e72 2112 case "$CDROMREADERSYNTAX" in
1b94d6b7 2113 ### FIXME ### How are we calculating the tracks in flac mode?
2114 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
1366e842 2115 cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2116 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
d5200e72 2117 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2118 exit 1 ;;
2119 esac
2120 else
2121 UTRACKNUM=$1
2122 fi
c9c2ca27 2123 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
49c04b11 2124 if [ "$USEPIPES" = "y" ]; then
2125 TEMPARG="PIPE_$CDROMREADERSYNTAX"
a9a23379 2126 FILEARG="$( eval echo "\$$TEMPARG" )"
49c04b11 2127 REDIR=""
0a3a2dcc 2128 PIPE_MESSAGE="and encoding "
49c04b11 2129 else
0a3a2dcc 2130 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
49c04b11 2131 case "$CDROMREADERSYNTAX" in
1b94d6b7 2132 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2133 flac)
2134 FILEARG="--output-name=$WAVDATA"
2135 ;;
49c04b11 2136 dagrab)
2137 FILEARG="-f $WAVDATA"
2138 ;;
2139 *)
03308bc7 2140 FILEARG="$WAVDATA"
49c04b11 2141 ;;
2142 esac
2143 REDIR=">&2"
2144 fi
efc6de2f 2145 if [ "$1" = "onetrack" ]; then
b82e2042 2146 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
0a3a2dcc 2147 else
efc6de2f 2148 if [ -r "$CDDBDATA" ]; then
c0fc2e81 2149 #TRACKNAME=$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2 -d= | tr -d \[:cntrl:\])
2150 do_getcddbinfo TRACKNAME
efc6de2f 2151 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2152 else
2153 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2154 fi
0a3a2dcc 2155 fi
c9c2ca27 2156 case "$CDROMREADERSYNTAX" in
1b94d6b7 2157 ### FIXME ### use an exception for flac, since it uses -o
2158 ### FIXME ### Shall we just use -o $FILEARG ??
2159 flac)
2160 nice $READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
1366e842 2161 cdparanoia)
c008b56d 2162 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
c9c2ca27 2163 cdda2wav)
2164 if [ "$OSFLAVOUR" = "OSX" ] ; then
2165 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2166 disktool -u ${CDROM#/dev/} 0
2167 # Also, in OSX the cdrom device for cdda2wav changes...
2168 CDDA2WAVCDROM="IODVDServices"
2169 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2170 CDDA2WAVCDROM="$CDROMID"
2171 else
2172 if [ "$CDROMID" = "" ]; then
2173 CDDA2WAVCDROM="$CDROM"
2174 else
2175 CDDA2WAVCDROM="$CDROMID"
2176 fi
2177 fi
03308bc7 2178 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
c7ea851d 2179 ;;
2180 ## FIXME ## We have an exception for dagrab, since it uses -f
2181 ## FIXME ## Shall we just use -f $FILEARG ??
03308bc7 2182 dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
c9c2ca27 2183 ;;
c9c2ca27 2184 cddafs)
2185 # Find the track's mounted path
2186 REALTRACKNUM=$(expr $UTRACKNUM + 0)
47589f71 2187 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
c9c2ca27 2188 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2189 # If the file exists, copy it
2190 if [ -e "$FILEPATH" ] ; then
03308bc7 2191 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
c9c2ca27 2192 else
2193 false
2194 fi ;;
c008b56d 2195 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
c7ea851d 2196 ;;
c9c2ca27 2197 esac
2198 RETURN=$?
c7ea851d 2199 # If we get some error or we get some missing wav
2200 # (as long as we dont use pipes)
2201 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
c9c2ca27 2202 # Thank goodness errors is only machine-parseable up to the
2203 # first colon, otherwise this woulda sucked
93415558 2204 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2205 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2206 fi
49c04b11 2207 if [ "$USEPIPES" = "y" ]; then
2208 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2209 else
2210 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2211 fi
c9c2ca27 2212 return $RETURN
2213 else
49c04b11 2214 if [ "$USEPIPES" = "y" ]; then
2215 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2216 else
2217 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3416c114 2218 if [ "$1" = "onetrack" ]; then
2219 echo onetrack >> "$ABCDETEMPDIR/status"
2220 fi
49c04b11 2221 fi
c9c2ca27 2222 fi
2223}
2224
99d009fa 2225# do_cdspeed
2226# No values accepted, only uses env variables
c9c2ca27 2227do_cdspeed ()
2228{
2229 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
2230 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
2231 else
2232 echo "abcde: unable to set the device speed" >&2
2233 fi
2234}
2235
2236# vecho [message]
2237#
2238# vecho outputs a message if EXTRAVERBOSE is selected
2239vecho ()
2240{
2241if [ x"$EXTRAVERBOSE" != "x" ]; then
2242 echo $@
2243fi
2244}
2245
0709e644 2246# decho [message]
2247#
2248# decho outputs a debug message if DEBUG is selected
2249decho ()
2250{
2251if [ x"$DEBUG" != "x" ]; then
2252 DEBUGECHO=$(echo "$@" | tr -d '[]')
2253 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2254fi
2255}
2256
b7f1cc84 2257# User-redefinable functions
2258# Custom filename munging:
2259mungefilename ()
2260{
eb1474fe 2261 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2262 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
b7f1cc84 2263}
2264
2265# Custom genre munging:
2266mungegenre ()
2267{
2268 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2269}
2270
2271# pre_read
2272# Empty pre_read function, to be defined in the configuration file.
2273pre_read ()
2274{
2275:
2276}
2277
65f3ebb1 2278# post_read
2279# Empty post_read function, to be defined in the configuration file.
2280post_read ()
2281{
2282:
2283}
2284
a2052a00 2285###############################################################################
b7f1cc84 2286# End of functions
2287#
c9c2ca27 2288# Start of execution
a2052a00 2289###############################################################################
c9c2ca27 2290
2291# Builtin defaults
2292CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2293CDDBSUBMIT=freedb-submit@freedb.org
2294CDDBPROTO=5
2295HELLOINFO="$(whoami)@$(hostname)"
9ff5088c 2296CDDBCOPYLOCAL="n"
2297CDDBLOCALDIR="$HOME/.cddb"
2298CDDBUSELOCAL="n"
2299
2300# List of fields we parse and show during the CDDB parsing...
2301SHOWCDDBFIELDS="year,genre"
2302
c9c2ca27 2303INTERACTIVE=y
2304CDROMREADERSYNTAX=cdparanoia
c9c2ca27 2305ENCODERSYNTAX=default
2306
2307MP3ENCODERSYNTAX=default
2308OGGENCODERSYNTAX=default
2309FLACENCODERSYNTAX=default
2310SPEEXENCODERSYNTAX=default
99d009fa 2311MPPENCODERSYNTAX=default
72d7162b 2312NORMALIZERSYNTAX=default
411ef0b0 2313CUEREADERSYNTAX=default
c9c2ca27 2314
2315OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2316# Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2317#VAOUTPUTFORMAT=${OUTPUTFORMAT}
2318VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2319ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2320VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2321PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2322PLAYLISTDATAPREFIX=''
2323VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2324VAPLAYLISTDATAPREFIX=''
2325DOSPLAYLIST=n
2326COMMENT=''
2327ID3TAGV=2
2328ENCNICE=10
2329READNICE=10
2330DISTMP3NICE=10
2331VARIOUSARTISTS=n
2332VARIOUSARTISTSTYLE=forward
c9c2ca27 2333KEEPWAVS=n
2334PADTRACKS=n
0709e644 2335NOGAP=n
2336BATCHNORM=n
c9c2ca27 2337
2338# If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2339# i.e. CDROMID="1,0,0"
2340CDROMID=""
c008b56d 2341# If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2342# If we are using the ide-scsi emulation layer, we need to define a "g"
2343CDPARANOIACDROMBUS="d"
c9c2ca27 2344
2345# program paths - defaults to checking your $PATH
2346# mp3
2347LAME=lame
0709e644 2348TOOLAME=toolame
c9c2ca27 2349GOGO=gogo
2350BLADEENC=bladeenc
2351L3ENC=l3enc
2352XINGMP3ENC=xingmp3enc
2353MP3ENC=mp3enc
2354# ogg
2355VORBIZE=vorbize
2356OGGENC=oggenc
2357# flac
2358FLAC=flac
2359# speex
2360SPEEXENC=speexenc
99d009fa 2361# mpp (Musepack)
2362MPPENC=mppenc
c9c2ca27 2363
2364ID3=id3
2365ID3V2=id3v2
a9a23379 2366EYED3=eyeD3
c9c2ca27 2367CDPARANOIA=cdparanoia
2368CDDA2WAV=cdda2wav
2369DAGRAB=dagrab
2370CDDAFS=cp
2371CDDISCID=cd-discid
2372CDDBTOOL=cddb-tool
2373EJECT=eject
2374MD5SUM=md5sum
2375DISTMP3=distmp3
2376VORBISCOMMENT=vorbiscomment
2377METAFLAC=metaflac
72d7162b 2378NORMALIZE=normalize-audio
c9c2ca27 2379CDSPEED=eject
12c5d978 2380VORBISGAIN=vorbisgain
24f444d7 2381MKCUE=mkcue
9ff5088c 2382MKTOC=cdrdao
2383DIFF=diff
1b94d6b7 2384CUE2DISCID=cue2discid
c9c2ca27 2385
2386# Options for programs called from abcde
2387# mp3
2388LAMEOPTS=
0709e644 2389TOOLAMEOPTS=
c9c2ca27 2390GOGOOPTS=
2391BLADEENCOPTS=
2392L3ENCOPTS=
2393XINGMP3ENCOPTS=
2394MP3ENCOPTS=
2395# ogg
2396VORBIZEOPTS=
2397OGGENCOPTS=
2398# flac
6119aaa1 2399FLACOPTS="-f"
c9c2ca27 2400# speex
2401SPEEXENCOPTS=
9f659ada 2402# mpc
2403MPPENCOPTS=
c9c2ca27 2404
2405ID3OPTS=
2406ID3V2OPTS=
2407CDPARANOIAOPTS=
2408CDDA2WAVOPTS=
2409DAGRABOPTS=
2410CDDAFSOPTS="-f"
2411CDDBTOOLOPTS=
2412EJECTOPTS=
2413DISTMP3OPTS=
2414NORMALIZEOPTS=
2415CDSPEEDOPTS="-x"
2416CDSPEEDVALUE=
24f444d7 2417MKCUEOPTS=
9ff5088c 2418MKTOCOPTS=""
b33dc0c1 2419VORBISCOMMENTOPTS="-R"
2420METAFLACOPTS="--no-utf8-convert"
c9c2ca27 2421
2422# Default to one process if -j isn't specified
2423MAXPROCS=1
2424
2425# List of actions to perform - by default, run to completion
2426ACTIONS=cddb,read,encode,tag,move,clean
2427
b82e2042 2428# List of prefered outputs - by default, run with whatever we have in the path
2429# This option is basicaly for Debian package dependencies
2430DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex
2431
c9c2ca27 2432# Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2433# Let's use these checkings to determine the OS flavour, which will be used later
2434if [ X$(uname) = "XFreeBSD" ] ; then
2435 HTTPGET=fetch
a9a23379 2436 MD5SUM=md5
c9c2ca27 2437 NEEDCDROMID=y
2438 OSFLAVOUR=FBSD
2439elif [ X$(uname) = "XDarwin" ] ; then
2440 HTTPGET=curl
2441 OSFLAVOUR=OSX
2442 # We should have disktool in OSX, but let's be sure...
2443 NEEDDISKTOOL=y
f97e22a3 2444 CDROMREADERSYNTAX=cddafs
c9c2ca27 2445elif [ X$(uname) = "XOpenBSD" ] ; then
2446 HTTPGET=wget
2447 MD5SUM=md5
a9a23379 2448elif [ X$(uname) = "XNetBSD" ] ; then
2449 HTTPGET=ftp
2450 MD5SUM=md5
c9c2ca27 2451else
2452 HTTPGET=wget
2453fi
2454
2455# If CDDBAVAIL is set to n, no CDDB read is done
2456# If USEID3 is set to n, no ID3 tagging is done
2457CDDBAVAIL=y
2458USEID3=y
24f444d7 2459USEID3V2=y
c9c2ca27 2460
2461if [ -z "$OUTPUTDIR" ]; then
2462 OUTPUTDIR=$(pwd)
2463fi
2464
2465if [ -z "$WAVOUTPUTDIR" ]; then
2466 WAVOUTPUTDIR="$OUTPUTDIR"
2467fi
2468
2469# Load system defaults
2470if [ -r /etc/abcde.conf ]; then
2471 . /etc/abcde.conf
2472fi
2473# Load user preference defaults
2474if [ -r $HOME/.abcde.conf ]; then
2475 . $HOME/.abcde.conf
2476fi
2477
2478# By this time, we need some HTTPGETOPTS already defined.
b7f1cc84 2479# If the user has defined a non-default HTTPGET method, we should not be empty.
c9c2ca27 2480
2481if [ "$HTTPGETOPTS" = "" ] ; then
2482 case $HTTPGET in
2483 wget) HTTPGETOPTS="-q -O -";;
2484 curl) HTTPGETOPTS="-f -s";;
2485 fetch)HTTPGETOPTS="-q -o -";;
a9a23379 2486 ftp) HTTPGETOPTS="-q -o -";;
c9c2ca27 2487 *) echo "abcde warning: HTTPGET in non-standard and HTTPGETOPTS are not defined." >&2 ;;
2488 esac
2489fi
2490
2491# If the CDROM has not been set yet, find a suitable one.
2492# If this is a devfs system, default to /dev/cdroms/cdrom0
2493# instead of /dev/cdrom
2494if [ "$CDROM" = "" ] ; then
2495 if [ -e /dev/cdroms/cdrom0 ]; then
2496 CDROM=/dev/cdroms/cdrom0
2497 elif [ -e /dev/cdrom ]; then
2498 CDROM=/dev/cdrom
2499 elif [ -e /dev/cd0c ]; then
2500 CDROM=/dev/cd0c
2501 elif [ -e /dev/acd0c ]; then
2502 CDROM=/dev/acd0c
2503 elif [ -e /dev/disk1 ]; then
2504 CDROM=/dev/disk1
2505 fi
2506fi
2507
2508# Parse command line options
9ff5088c 2509#while getopts 1a:A:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
0709e644 2510while getopts 1a:bc:C:d:Defghj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W:z opt ; do
c9c2ca27 2511 case "$opt" in
2512 1) ONETRACK=y ;;
2513 a) ACTIONS="$OPTARG" ;;
a9a23379 2514 A) EXPACTIONS="$OPTARG" ;;
0709e644 2515 b) BATCHNORM=y ;;
c9c2ca27 2516 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else echo "abcde error: config file \"$OPTARG\" cannot be found." >&2 ; exit 1 ; fi ;;
2517 C) DISCID="${OPTARG#abcde.}" ;;
2518 d) CDROM="$OPTARG" ;;
2519 D) set -x ;;
bef9c2d8 2520 e) ERASEENCODEDSTATUS=y ;;
c9c2ca27 2521 h) usage; exit ;;
b33dc0c1 2522 e) ERASEENCODEDSTATUS=y ;;
a9a23379 2523 E) ENCODING="$OPTARG" ;;
75c2c424 2524 f) FORCE=y ;;
0709e644 2525 g) NOGAP=y ;;
c9c2ca27 2526 i) INLINETAG=y ;;
2527 j) MAXPROCS="$OPTARG" ;;
2528 k) KEEPWAVS=y ;;
2529 l) LOWDISK=y ;;
b7f1cc84 2530 L) CDDBUSELOCAL=y ;;
2531 n) CDDBAVAIL=n ;;
2532 N) INTERACTIVE=n ;;
c9c2ca27 2533 m) DOSPLAYLIST=y ;;
b82e2042 2534 M) MAKECUEFILE=y ;;
c9c2ca27 2535 o) OUTPUTTYPE="$OPTARG" ;;
b7f1cc84 2536 p) PADTRACKS=y ;;
2537 P) USEPIPES=y ;;
c9c2ca27 2538 r) REMOTEHOSTS="$OPTARG" ;;
12c5d978 2539 R) REPLAYGAIN=y ;;
9ff5088c 2540 s) SHOWCDDBFIELDS="$OPTARG" ;;
c9c2ca27 2541 S) CDSPEEDVALUE="$OPTARG" ;;
79e3928b 2542# t) PREPROCESSFORMATS="$OPTARG"
2543# PREPROCESS=y ;;
2544# T) POSTPROCESSFORMATS="$OPTARG" ;;
2545 t) STARTTRACKNUMBER="$OPTARG" ;;
2546 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
c9c2ca27 2547 v)
2548 echo "This is abcde v$VERSION."
2549 echo "Usage: abcde [options] [tracks]"
2550 echo "abcde -h for extra help"
2551 exit
2552 ;;
2553 V) EXTRAVERBOSE="y" ;;
2554 x) EJECTCD="y" ;;
79e3928b 2555 w) COMMENT="$OPTARG" ;;
bef9c2d8 2556 W) if echo $OPTARG | grep -q "[[:digit:]]" ; then
2557 STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
2558 else
2559 echo "abcde error: argument of -W must be integer"
2560 exit 1
2561 fi
2562 ;;
0709e644 2563 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
c9c2ca27 2564 ?) usage; exit ;;
2565 esac
2566done
2567
2568shift $(($OPTIND - 1))
2569
1b94d6b7 2570# If the user specified a flac file, then switch to special flac mode
2571if echo $CDROM | grep -i -q '.flac$'; then
2572 vecho "abcde: switching to flac CDROMREADERSYNTAX..."
2573 CDROMREADERSYNTAX=flac
2574 if [ "$EJECTCD" = "y" ];then
2575 vecho "abcde: CDROM flac mode, deactivating EJECTCD..."
2576 EJECTCD=n
2577 fi
2578fi
2579
d5200e72 2580# Decide if we can continue.
2581if [ "$ONETRACK" = "y" ]; then
2582 # FIXME # remove check as soon as we find out about the other readers
99d009fa 2583 case "$CDROMREADERSYNTAX" in
1b94d6b7 2584 flac) ;;
b82e2042 2585 cdparanoia) ;;
2586 cdda2wav) ;;
2587 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2588 exit 1 ;;
99d009fa 2589 esac
0709e644 2590 if [ "$BATCHNORM" = "y" ]; then
2591 echo "abcde warning: BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
2592 BATCHNORM=n
2593 fi
2594 if [ "$NOGAP" = "y" ]; then
2595 echo "abcde warning: NOGAP mode is not compatible with ONETRACK mode. Disabling..."
2596 NOGAP=n
99d009fa 2597 fi
2598 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
d5200e72 2599 # FIXME # allow ranges of tracks to be selected for onetrack ripping
c9c2ca27 2600 if [ $# -gt 0 ]; then
d5200e72 2601 vecho "abcde warning: ONETRACK mode selected, grabbing all tracks..."
c9c2ca27 2602 fi
2603else
2604 while [ $# -gt 0 ]; do
2605 # Range parsing code courtesy of Vincent Ho
2606 RSTART=$(echo $1 | cut -f1 -d-)
2607 REND=$(echo $1 | cut -f2 -d-)
2608 if [ "$RSTART" = "$REND" ]; then
2609 NEWTRACKS="$RSTART"
2610 else
2611 NEWTRACKS=$(f_seq_line $RSTART $REND)
2612 fi
2613 TRACKQUEUE=$(echo "$TRACKQUEUE" "$NEWTRACKS")
c9c2ca27 2614 shift
2615 done
2616fi
2617
b7f1cc84 2618# List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2619# List of experimental actions: retag,transcode
2620
2621# Determine what actions are to be done from $ACTIONS and set the
2622# following environment variables for them:
2623DOCDDB=n
2624DOREAD=n
2625DONORMALIZE=n
2626DOPREPROCESS=n
2627DOENCODE=n
2628DOPOSTPROCESS=n
2629DOTAG=n
2630DOMOVE=n
00840d9a 2631DOREPLAYGAIN=n
b7f1cc84 2632DOPLAYLIST=n
2633DOCLEAN=n
2634
2635for ACTION in $(echo $ACTIONS | tr , \ )
2636do
2637 case $ACTION in
24f444d7 2638 cddb) DOCDDB=y;;
2639 read) DOREAD=y;;
2640 normalize) DONORMALIZE=y; DOREAD=y;;
2641# preprocess) DOPREPROCESS=y; DOREAD=y;;
2642 encode) DOENCODE=y; DOREAD=y;;
2643# postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2644 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2645 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
00840d9a 2646 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
24f444d7 2647 playlist) DOCDDB=y; DOPLAYLIST=y;;
2648 clean) DOCLEAN=y;;
b7f1cc84 2649 esac
2650done
2651
1750d493 2652if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2653 # FIXME # should we abort on error or just inform the user?
2654 :
2655fi
2656
9ff5088c 2657for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
2658 case $SHOWCDDBFIELD in
2659 y*|Y*) SHOWCDDBYEAR="y";;
2660 g*|G*) SHOWCDDBGENRE="y";;
2661 *) ;;
2662 esac
2663done
b7f1cc84 2664
9ff5088c 2665# Sanity checks:
b82e2042 2666
c9c2ca27 2667# At this point a CDROM has to be defined, so we check it exists.
6c124acf 2668if [ X"$CDROM" != "X" ] ; then
c9c2ca27 2669 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2670 if [ "$OSFLAVOUR" = "FBSD" ]; then
2671 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
2672 echo "abcde error: CDROMID not in the right format for $CDROMREADERSYNTAX"
2673 echo "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2674 exit 1
8fc41c4f 2675 fi
c9c2ca27 2676 fi
c81531ac 2677 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
c9c2ca27 2678 echo "abcde error: CDROM device cannot be found." >&2
2679 exit 1
2680 fi
6c124acf 2681# avoid processing if we are not going to hit the CDROM.
c81531ac 2682elif [ X"$DOREAD" = "Xy" ]; then
c9c2ca27 2683 echo "abcde error: CDROM has not been defined or cannot be found" >&2
2684 exit 1
2685fi
2686
c7ea851d 2687# USEPIPES pre-tests, before we get into more serious stuff
2688# Not compatible with:
d5200e72 2689# - multiple outputs
2690# - normalize
c7ea851d 2691# - lowdisk algorithm
d5200e72 2692# - anything else?
c7ea851d 2693if [ X"$USEPIPES" = "Xy" ]; then
b82e2042 2694 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
2695 echo "abcde error: Unix pipes not compatible with multiple outputs" >&2
d5200e72 2696 exit 1
2697 fi
c7ea851d 2698 if [ X"$DONORMALIZE" = "Xy" ]; then
d5200e72 2699 echo "abcde error: Unix pipes not compatible with normalizer"
2700 # FIXME # Do we need to exit or shall we just disable the mode?
2701 exit 1
2702 fi
0709e644 2703 if [ X"$BATCHNORM" = "Xy" ]; then
2704 echo "abcde error: Unix pipes not compatible with BATCHNORM encoding"
2705 exit 1
2706 fi
2707 if [ X"$NOGAP" = "Xy" ]; then
2708 echo "abcde error: Unix pipes not compatible with NOGAP encoding"
2709 exit 1
2710 fi
c7ea851d 2711 if [ X"$DOENCODE" = "Xn" ]; then
d5200e72 2712 vecho "Disabling Unix pipes since we are not encoding!"
2713 USEPIPES=n
2714 fi
c7ea851d 2715 if [ X"$LOWDISK" = "Xy" ]; then
2716 vecho "abcde error: Unix pipes not compatible with lowdisk algorithm"
2717 exit 1
2718 fi
d5200e72 2719fi
2720
0709e644 2721# LOWDISK pre-tests, before we get into more problematic stuff
2722# Not compatible with anything that needs all the files in the hard disc:
2723# - BATCHNORM
2724# - NOGAP lame mode
2725if [ X"$LOWDISK" = "Xy" ]; then
2726 if [ X"$BATCHNORM" = "Xy" ]; then
2727 echo "abcde error: Unix pipes not compatible with BATCHNORM encoding"
2728 exit 1
2729 fi
2730 if [ X"$NOGAP" = "Xy" ]; then
2731 echo "abcde error: Unix pipes not compatible with NOGAP encoding"
2732 exit 1
2733 fi
2734fi
2735
9ff5088c 2736# Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2737if [ X"$OUTPUTTYPE" = "X" ]; then
2738 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
2739 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2740 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2741 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
2742 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
2743 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2744 break
2745 fi
2746 done
2747 if [ X"$OUTPUTTYPE" = "X" ]; then
2748 echo "abcde error: no encoder found in the PATH" >&2
2749 echo "hits: are all dependencies installed? has the \$PATH been modified?" >&2
2750 exit 1
2751 fi
2752fi
2753
c9c2ca27 2754# Decide which CDROM reader we're gonna use
2755case "$CDROMREADERSYNTAX" in
2756 cdparanoia|debug)
2757 CDROMREADER="$CDPARANOIA"
2758 CDROMREADEROPTS="$CDPARANOIAOPTS"
2759 ;;
2760 cdda2wav)
2761 CDROMREADER="$CDDA2WAV"
2762 CDROMREADEROPTS="$CDDA2WAVOPTS"
2763 ;;
2764 dagrab)
2765 CDROMREADER="$DAGRAB"
2766 CDROMREADEROPTS="$DAGRABOPTS"
2767 ;;
2768 cddafs)
2769 CDROMREADER="$CDDAFS"
2770 CDROMREADEROPTS="$CDDAFSOPTS"
2771 ;;
1b94d6b7 2772 flac)
2773 CDROMREADER="$FLAC"
2774 CDROMREADEROPTS="$FLACOPTS"
2775 ;;
c9c2ca27 2776esac
2777
2778# There's only one normalize...
2779case "$NORMALIZERSYNTAX" in
2780 default|normalize)
2781 NORMALIZER="$NORMALIZE"
2782 NORMALIZEROPTS="$NORMALIZEOPTS"
2783 ;;
2784esac
2785
24f444d7 2786# Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
b82e2042 2787if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
cd4b63fa 2788 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
24f444d7 2789 case "$OUTPUT" in
b82e2042 2790 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
24f444d7 2791 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2792 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2793 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2794 mpc:*) MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2795 esac
2796 done
cd4b63fa 2797 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
24f444d7 2798 TEMPOUTPUT=$( echo "$OUTPUT" | cut -d: -f1 )
2799 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2800 done
2801 OUTPUTTYPE="$TEMPOUTPUTTYPE"
24f444d7 2802fi
2803
99d009fa 2804# If nothing has been specified, use oggenc for oggs and lame for mp3s and flac for flacs and speexenc for speex and mppenc for mpps
c9c2ca27 2805
2806# Getting ready for multiple output changes
2807for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
2808do
2809 case $OUTPUT in
b82e2042 2810 vorbis|ogg)
2811 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
2812 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
2813 [ "$REPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
2814 OGGOUTPUTCONTAINER=ogg
2815 ;;
2816 mp3)
2817 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
2818 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
0709e644 2819 #[ "$NOGAP" = "y" ]
b82e2042 2820 ;;
2821 flac)
2822 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
1b94d6b7 2823 [ "$REPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
b82e2042 2824 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
2825 ;;
2826 spx)
2827 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
2828 ;;
2829 mpc)
2830 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
2831 ;;
b69a8bb4 2832 wav)
389564c2 2833 if [ "$KEEPWAVS" = "y" ]; then
2834 vecho "Unsetting the KEEPWAVS option, since the resulting wav files were requested..."
2835 fi
b69a8bb4 2836 KEEPWAVS=move
2837 ;;
24f444d7 2838 *) echo "abcde error: Invalid OUTPUTTYPE defined" >&2
2839 exit 1
c9c2ca27 2840 ;;
c9c2ca27 2841 esac
2842done
2843
2844# decide which encoder
2845case "$MP3ENCODERSYNTAX" in
2846 lame)
24f444d7 2847 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
c9c2ca27 2848 MP3ENCODER="$LAME"
2849 ;;
0709e644 2850 toolame)
2851 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
2852 MP3ENCODER="$TOOLAME"
2853 ;;
c9c2ca27 2854 gogo)
24f444d7 2855 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
c9c2ca27 2856 MP3ENCODER="$GOGO"
2857 ;;
2858 bladeenc)
24f444d7 2859 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
c9c2ca27 2860 MP3ENCODER="$BLADEENC"
2861 ;;
2862 l3enc)
24f444d7 2863 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
c9c2ca27 2864 MP3ENCODER="$L3ENC"
2865 ;;
2866 xingmp3enc)
24f444d7 2867 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
c9c2ca27 2868 MP3ENCODER="$XINGMP3ENC"
2869 ;;
2870 mp3enc)
24f444d7 2871 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
c9c2ca27 2872 MP3ENCODER="$MP3ENC"
2873 ;;
2874esac
2875case "$OGGENCODERSYNTAX" in
2876 vorbize)
24f444d7 2877 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
c9c2ca27 2878 OGGENCODER="$VORBIZE"
2879 ;;
2880 oggenc)
24f444d7 2881 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
c9c2ca27 2882 OGGENCODER="$OGGENC"
2883 ;;
2884esac
2885case "$FLACENCODERSYNTAX" in
2886 flac)
24f444d7 2887 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
c81531ac 2888 FLACENCODER="$FLAC"
b82e2042 2889 # FLAC streams can be encapsulated on a Ogg transport layer
c81531ac 2890 if echo "$FLACENCODEROPTS" | egrep -q -- "(^| )--ogg($| )" ;then
b82e2042 2891 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2892 echo " due to problem with adding comments to such files" >&2
2893 exit 1
2894 FLACOUTPUTCONTAINER=ogg
2895 else
2896 FLACOUTPUTCONTAINER=flac
c81531ac 2897 fi
c9c2ca27 2898 ;;
2899esac
2900case "$SPEEXENCODERSYNTAX" in
2901 speexenc)
24f444d7 2902 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
c9c2ca27 2903 SPEEXENCODER="$SPEEXENC"
2904 ;;
2905esac
99d009fa 2906case "$MPPENCODERSYNTAX" in
2907 mppenc)
24f444d7 2908 MPPENCODEROPTS="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
99d009fa 2909 MPPENCODER="$MPPENC"
2910 ;;
2911esac
24f444d7 2912
c9c2ca27 2913# and which tagger
2914
2915if [ "$ID3TAGV" = "1" ]; then
2916 TAGGER="$ID3"
2917 TAGGEROPTS="$ID3OPTS"
2918else
2919 TAGGER="$ID3V2"
2920 TAGGEROPTS="$ID3V2OPTS"
2921fi
2922
0709e644 2923# Specific for NOGAP is the use of lame. Another encoder fails...
2924if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
2925 "abcde warning: the NOGAP option is specific of lame. Deactivating..."
2926 NOGAP=n
2927fi
2928
411ef0b0 2929# Options for mkcue
2930case "$CUEREADERSYNTAX" in
2931 default|mkcue)
2932 CUEREADEROPTS="${CDROM}"
2933 CUEREADER="$MKCUE"
2934 ;;
2935esac
2936
b82e2042 2937# Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
2938if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
2939 echo "abcde error: FLAC on an Ogg container is not yet supported" >&2
2940 echo " due to problem with adding comments to such files" >&2
2941 exit 1
2942 OGGOUTPUTCONTAINER=ogg.ogg
2943 FLACOUTPUTCONTAINER=flac.ogg
2944 vecho "abcde warning: modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
2945fi
2946
c9c2ca27 2947# Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
2948
2949if [ "$ENCNICE" ]; then
2950 ENCNICE="-n $ENCNICE"
2951fi
2952if [ "$READNICE" ]; then
2953 READNICE="-n $READNICE"
2954fi
2955if [ "$DISTMP3NICE" ]; then
2956 DISTMP3NICE="-n $DISTMP3NICE"
2957fi
2958
2959# Don't check for stuff if it's not needed
bef9c2d8 2960if [ "$REMOTEHOSTS" ]; then
2961 NEEDDISTMP3=y
2962fi
2963if [ "$DONORMALIZE" = "y" ]; then
2964 NEEDNORMALIZER=y
2965fi
2966if [ "$EJECTCD" = "y" ]; then
2967 NEEDEJECT=y
2968fi
2969if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
2970 NEEDHTTPGET=y
2971fi
411ef0b0 2972if [ "$MAKECUEFILE" = "y" ]; then
2973 NEEDCUEREADER=y
bef9c2d8 2974fi
c9c2ca27 2975
2976if [ X"$CDSPEEDVALUE" != "X" ]; then
2977 case "$CDROMREADERSYNTAX" in
2978 cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
1b94d6b7 2979 ### FIXME ### translate "cue2discid" from python to bash
2980 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ;;
c9c2ca27 2981 *) NEEDCDSPEED=y ;;
2982 esac
2983fi
2984
c7ea851d 2985# Rippers with USEPIPE support
2986# FIXME # Include here all the rippers we can figure out support pipes
2987PIPE_cdparanoia="-"
1b94d6b7 2988PIPE_flac="-c "
c7ea851d 2989
2990# Encoders with USEPIPE support
2991# FIXME # Include here all the encoders we can figure out support pipes
2992PIPE_lame="-"
5a433968 2993PIPE_bladeenc="-"
c7ea851d 2994PIPE_oggenc="-"
2995
2996# Figure out if we can use pipes with the ripper/encoder combination
2997# exit otherwise
2998if [ "$USEPIPES" = "y" ]; then
2999 PIPERIPPERSVARCHECK="PIPE_${CDROMREADER}"
3000 case "$OUTPUT" in
3001 mp3)
3002 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
b82e2042 3003 vorbis|ogg)
c7ea851d 3004 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
3005 flac)
3416c114 3006 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
c7ea851d 3007 spx)
6c124acf 3008 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
c7ea851d 3009 mpc)
3010 PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
3011 esac
a9a23379 3012 if [ ! -n "$( eval echo "\$$PIPERIPPERSVARCHECK" )" ] ; then
c7ea851d 3013 echo "abcde error: no support for pipes with given ripper" >&2
01904e3c 3014 echo "read the USEPIPES file from the source tarball to get help." >&2
3015 echo "On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz" >&2
c7ea851d 3016 exit 1;
3017 fi
a9a23379 3018 if [ ! -n "$( eval echo "\$$PIPEENCODERSVARCHECK" )" ] ; then
c7ea851d 3019 echo "abcde error: no support for pipes with given encoder" >&2
3020 echo "read the USEPIPES file from the source tarball to help" >&2
3021 echo "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz" >&2
3022 exit 1;
3023 fi
3024fi
3025
c9c2ca27 3026# Make sure a buncha things exist
3027for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
99d009fa 3028 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3029 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3030 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3031 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
12c5d978 3032 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
1b94d6b7 3033 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDCUEREADER+$CUEREADER} \
3034 ${NEEDCUE2DISCID+$CUE2DISCID}
c9c2ca27 3035do
3036 # Cut off the command-line options we just added in
3037 X=$(echo $X | cut -d' ' -f2)
3038 if [ "$(which $X)" = "" ]; then
3039 echo "abcde error: $X is not in your path." >&2
3040 exit 1
3041 elif [ ! -x $(which $X) ]; then
3042 echo "abcde error: $X is not executable." >&2
3043 exit 1
3044 fi
3045done
3046
3047CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
3048CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
3049HTTPGET="$HTTPGET $HTTPGETOPTS"
3050
9ff5088c 3051# And last but not least, check if we can diff between files
3052if [ -x $(which $DIFF) ]; then :; else
3053 vecho "[WAR] Disabling diff since we cannot find it in the \$PATH..."
3054 DIFF=""
3055fi
3056
12c5d978 3057# Here it used to say:
3058# One thousand lines in, we can start doing stuff with things
5895f404 3059# Well, right now we are at line 2736 ;)
c9c2ca27 3060
3061# Export needed things so they can be read in this subshell
3062export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
3063export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
3064
3065# User-definable function to set some things. Use it for
3066# - closing the CD tray with eject -t
3067# - set the CD speed value with eject -x
3068vecho -n "Executing customizable pre-read function... "
3069
3070pre_read # Execute the user-defined pre-read funtion. Close the CD with it.
3071
3072vecho "done."
3073
3074do_discid # Get ABCDETEMPDIR created and status file initialized
3075
3076if [ "$DOCDDB" = "y" ]; then
3077 if [ $CDDBUSELOCAL = "y" ]; then
3078 do_localcddb
3079 fi
b7f1cc84 3080 if checkstatus cddb-choice > /dev/null; then
3081 :
3082 else
3083 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
3084 do_cddbstat
3085 do_cddbquery
3086 do_cddbread
3087 fi
c9c2ca27 3088 fi
3089 do_cddbedit
3090
fe4d186c 3091 eval "$($CDDBTOOL parse "$CDDBDATA")"
c9c2ca27 3092fi
3093
3094# Before reading tracks, we set the speed of the device
3095
3096if [ X"$CDSPEEDVALUE" != "X" ]; then
3097 case "$CDROMREADERSYNTAX" in
1b94d6b7 3098 cdparanoia|debug) ;;
3099 flac) ;;
c9c2ca27 3100 *) do_cdspeed ;;
3101 esac
3102fi
3103
bef9c2d8 3104# Define the first and last track, since we might need them later in several places
3105FIRSTTRACK=$( get_first $TRACKQUEUE )
3106LASTTRACK=$( get_last $TRACKQUEUE )
3107
3108if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
3109 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3110 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
3111 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
3112fi
3113
c9c2ca27 3114# Create playlist if needed (backgroundable) and start reading in tracks
3115
3116(
99d009fa 3117
d5200e72 3118if [ ! "$ONETRACK" = "y" ]; then
c9c2ca27 3119 if [ "$DOPLAYLIST" = "y" ]; then
3120 echo Creating playlist... >&2
3121 do_playlist
3122 fi
3123fi
3124
3125# For the lowdisk option, only one program is running at once so the encoder
3126# can be unsilenced right away.
3127if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
3128 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3129fi
3130
3131if [ "$ONETRACK" = "y" ]; then
c9c2ca27 3132 TRACKS="$FIRSTTRACK"
c9c2ca27 3133 if checkstatus readtrack-$FIRSTTRACK; then :; else
bef9c2d8 3134 do_cdread onetrack $FIRSTTRACK $LASTTRACK
c9c2ca27 3135 fi
3136else
3137 for UTRACKNUM in $TRACKQUEUE
3138 do
3139 if [ "$DOREAD" = "y" ]; then
49c04b11 3140 if [ "$USEPIPES" = "y" ]; then
3141 if checkstatus readencodetrack-$UTRACKNUM; then :; else
69ff9575 3142 # Read, pipe, shut up!
3143 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
49c04b11 3144 fi
3145 else
3146 if checkstatus readtrack-$UTRACKNUM; then :; else
3147 do_cdread $UTRACKNUM
3148 fi
c9c2ca27 3149 if [ "$?" != "0" ]; then
3150 # CD read failed - don't give the goahead to
3151 # the encoder
3152 echo NO
3153 exit
3154 fi
3155 fi
3156 fi
0709e644 3157 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
c9c2ca27 3158 :
3159 else
3160 echo NEXTTRACK # Get the encoder machine churning again
3161 if [ "$DOREAD" = "y" ]; then
3162 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3163 until checkstatus encodetrack-$UTRACKNUM
3164 do
3165 if checkerrors encodetrack-$UTRACKNUM; then
3166 break
3167 fi
3168 sleep 2
3169 done
3170 fi
3171 fi
3172 fi
3173 done
3174fi
3175
3176# Now that we're done the encoding can be loud again -
3177# if we're not using SMP.
3178if [ "$MAXPROCS" = "1" ]; then
3179 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3180fi
3181
3182# All tracks read, start encoding.
0709e644 3183if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
c9c2ca27 3184 echo NEXTTRACK
3185fi
3186
65f3ebb1 3187# Execute the user-defined post_read funtion before ejecting CD
3188post_read
3189
c9c2ca27 3190# We are now finished with the cdrom - it can be safely ejected. Note that
3191# abcde will not have completed yet.
3192if [ "$EJECTCD" = "y" ] && [ -x $(which $EJECT) ]; then
3193 # We check if the disk we are processing is actually the disk inside the
3194 # CD tray. If not, we do not eject the CD, since it might be so that the
3195 # user ejected it manually.
3196 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3197 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3198 # More FreeBSD bits.
3199 if [ X"$(uname)" = X"FreeBSD" ] ; then
3200 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3201 # but in this script EJECT is in the envionment and names the program
3202 eject=$EJECT
3203 unset EJECT
3204 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3205 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3206 $eject $EJECTOPTS $cd
3207 elif [ X"$(uname)" = X"Darwin" ] ; then
3208 disktool -e ${CDROM#/dev/} 0
3209 else
3210 $EJECT $EJECTOPTS $CDROM
3211 fi
3212 #fi
3213fi
3214
3215) | (
3216
99d009fa 3217## Do we need to pre-process
3218#if [ x"$PREPROCESS" = "x" ] ; then
3219# cat
3220#else
3221# for PRETRACKNUM in $TRACKQUEUE
3222# do
3223# read GOAHEAD
3224# if [ "$GOAHEAD" = "NO" ]; then break; fi
3225# PREPROCEED=
3226# until [ $PREPROCEED ]
3227# do
3228# if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3229# # all locations are working, wait and try again later
3230# if [ ! $PREPROCEED ]; then sleep 3; fi
3231# done
3232# ( do_preprocess $PRETRACKNUM
3233# echo "NEXTTRACK"
3234# ) &
3235# done
3236#fi
3237#
3238#) | (
3239
0709e644 3240# In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
3241#BACK
3242if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
c9c2ca27 3243 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
3244 if [ "$GOAHEAD" = "NO" ]; then break; fi
3245 for LASTTRACK in $TRACKQUEUE; do :; done
3246 if checkstatus readtrack-$LASTTRACK; then
0709e644 3247 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
c9c2ca27 3248 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
0709e644 3249 if checkerrors batch-normalize; then exit 1; fi
c9c2ca27 3250 fi
0709e644 3251 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
3252 if [ "$DONORMALIZE" = "y" ]; then
3253 for UTRACKNUM in $TRACKQUEUE
3254 do
3255 if checkstatus readtrack-$UTRACKNUM; then
3256 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
3257 fi
3258 done
3259 else
3260 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
3261 if checkerrors nogap-encode; then exit 1; fi
3262 fi
c9c2ca27 3263 fi
3264 fi
3265fi
3266
3267# If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3268if [ "$ONETRACK" = "y" ] ; then
bef9c2d8 3269 TRACKQUEUE="$FIRSTTRACK"
c9c2ca27 3270 TRACKS="$FIRSTTRACK"
3271fi
3272
3273# Do the encoding, including parallelization of remote encoding
3274# Figure out where each track is going to be encoded
3275ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
3276if [ "$MAXPROCS" != "0" ]; then
3277 for NUM in $(f_seq_row 1 "$MAXPROCS")
3278 do
3279 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
3280 done
3281fi
3282# Strip whitespace
3283ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
3284for UTRACKNUM in $TRACKQUEUE
3285do
3286 # Wait for our cue
3287 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
3288 if [ "$GOAHEAD" = "NO" ]; then break; fi
3289 # find out where this track is to be encoded
49c04b11 3290 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
c9c2ca27 3291 # Make sure we have a place to encode this, if not, exit stage right
3292 if [ -z "$ENCODELOCATIONS" ]; then
3293 continue
3294 fi
3295 PROCEED=
3296 until [ $PROCEED ]
3297 do
3298 for LOCATION in $ENCODELOCATIONS
3299 do
3300 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
3301 # check first if a track has ever been assigned to this location
3302 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
3303 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3304 if checkerrors encodetrack-$PREVIOUSTRACK; then
3305 for TEMPLOCATION in $ENCODELOCATIONS
3306 do
3307 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3308 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
3309 fi
3310 done
3311 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
3312 ABORT=y
3313 PROCEED=y
3314 break
3315 fi
3316 # We're still here, this location must have been previously assigned,
3317 # and last completed without error - check if it's done with the
3318 # previous track yet
3319 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
3320 done
3321 # all locations are working, wait and try again later
3322 if [ ! $PROCEED ]; then sleep 3; fi
3323 done
3324 # Record the location we're about to encode the next track at
3325 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3326 fi
3327 # Don't proceed with the rest of the loop if we can't encode
3328 if [ "$ABORT" ]; then continue; fi
3329 # Set TRACKNUM, TRACKNAME
3330 if [ -e "$CDDBDATA" ]; then
3331 if [ "$ONETRACK" = "y" ]; then
3332 TRACKNAME="$DALBUM"
3333 TRACKNUM="$FIRSTTRACK"
3334 splitvarious
3335 else
3336# TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${UTRACKNUM} + 0))
3337 TRACKNUM=$UTRACKNUM
eb1474fe 3338 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
c0fc2e81 3339 #TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
3340 do_getcddbinfo TRACKNAME
c9c2ca27 3341 splitvarious
3342 fi
3343 fi
3344 # You can't encode a file which needs to be normalized before finishing
3345 # You can't tag a file before it's finished encoding -
3346 # thus all of this is backgrounded together
3347 (
3348 if [ "$DONORMALIZE" = "y" ]; then
3349 if checkstatus readtrack-$UTRACKNUM; then
3350 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
3351 fi
3352 fi
c7ea851d 3353 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
c9c2ca27 3354 if checkstatus readtrack-$UTRACKNUM; then
3355 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3356 if [ "$DONORMALIZE" = "y" ]; then
3357 if checkstatus normalizetrack-$UTRACKNUM; then
3358 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
3359 fi
3360 else
3361 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
3362 fi
3363 fi
3364 fi
efc6de2f 3365 if [ "$DOTAG" = "y" ]; then
3366 if checkstatus encodetrack-$UTRACKNUM; then
c9c2ca27 3367 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
3368 fi
b82e2042 3369 # Lets tag the cue file
3370 if checkstatus cleancuefile >/dev/null; then :; else
3371 if checkstatus cuefile >/dev/null ; then
3372 do_cleancue
3373 fi
3374 fi
c9c2ca27 3375 fi
3376 if [ "$DOMOVE" = "y" ]; then
3377 if checkstatus tagtrack-$UTRACKNUM; then
3378 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
3379 fi
3380 fi
3381 ) &
3382done
79c8f4d0 3383
79c8f4d0 3384
c9c2ca27 3385# Go through it again and make sure there's no distmp3 stragglers, otherwise
3386# we'll delete the files they're working on
c7ea851d 3387## FIXME ## Check also for files which are encoded using PIPEs.
3388if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
c9c2ca27 3389 PROCEED=
3390 until [ $PROCEED ]
3391 do
3392 PROCEED=y
3393 for LOCATION in $ENCODELOCATIONS
3394 do
3395 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
3396 # "How can he give us a status update, if he's DEAD?"
3397 if checkstatus encodetrack-$CHECKTRACK; then
3398 continue
3399 fi
3400 # Nothing to see here please go quietly back to your homes
3401 if [ -z "$CHECKTRACK" ]; then continue; fi
3402 # You're still here? Maybe there is something...
3403 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
3404 done
3405 # hold up
3406 if [ ! $PROCEED ]; then sleep 5; fi
3407 done
3408fi
3409# If the above didn't catch the stragglers, this will
3410wait
1b94d6b7 3411if [ "$REPLAYGAIN" = "y" ]; then
c0fc2e81 3412 do_replaygain
3413fi
c9c2ca27 3414# Check to see if run_command logged any errors
3415if [ -f "$ABCDETEMPDIR/errors" ]; then
3416 echo "The following commands failed to run:"
3417 cat "$ABCDETEMPDIR/errors"
3418 # Don't clean up
3419 DOCLEAN=n
3420fi
3421if [ "$KEEPWAVS" = "y" ];then
3422 # Don't clean up
3423 DOCLEAN=n
3424fi
75c2c424 3425# Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
81d2dc20 3426if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
cb801544 3427 ENCODED_FORMATS=$(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
81d2dc20 3428 MOVED_FORMATS=$(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
0709e644 3429 decho [ENCODED_FORMATS]
3430 decho [MOVED_FORMATS]
75c2c424 3431 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
3432 echo "Not all encoded formats have been requested to be moved."
3433 echo "Use \"-a clean -f -C $DISCID\" to force the removal of the remaining data."
81d2dc20 3434 DOCLEAN=n
cb801544 3435 fi
75c2c424 3436fi
c9c2ca27 3437if [ "$DOCLEAN" = "y" ]; then
3438 # Wipe all the evidence
3439 # Gimme gimme gimme some more time!
3440 sleep 5
3441 rm -rf "$ABCDETEMPDIR"
3442 echo "Finished."
3443else
3444 echo "Finished. Not cleaning $ABCDETEMPDIR."
3445fi
3446)
3447exit 0
d5200e72 3448
3449# b:is_bash
3450# vim:tabstop=4