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