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