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