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