r237@frost: data | 2005-12-22 12:46:47 +0200
[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:"
dba06003 26echo " cddb,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]...>"
dba06003 51echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). 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 ;;
dba06003 736 m4a)
737 run_command tagtrack-$OUTPUT-$1 true
738 ;;
b69a8bb4 739 wav)
740 run_command tagtrack-$OUTPUT-$1 true
741 ;;
c9c2ca27 742 esac
c9c2ca27 743 done
33bc33c3 744 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
1a064efb 745 run_command tagtrack-$1 true
746 fi
747
c9c2ca27 748}
749
0709e644 750# do_nogap_encode
c9c2ca27 751# variables used:
752# OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
0709e644 753do_nogap_encode ()
c9c2ca27 754{
755 # The commands here don't go through run_command because they're never supposed to be silenced
0709e644 756 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
757 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
758 do
759 case "$OUTPUT" in
760 mp3)
761 case "$MP3ENCODERSYNTAX" in
762 lame)
763 (
764 cd "$ABCDETEMPDIR"
765 TRACKFILES=
c9c2ca27 766 for UTRACKNUM in $TRACKQUEUE
767 do
0709e644 768 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
c9c2ca27 769 done
0709e644 770 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
771 RETURN=$?
772 if [ "$RETURN" != "0" ]; then
773 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
774 else
775 for UTRACKNUM in $TRACKQUEUE
776 do
777 run_command encodetrack-$OUTPUT-$UTRACKNUM true
778 #run_command encodetrack-$UTRACKNUM true
779 done
780 fi
781 )
782 ;;
783 esac
c9c2ca27 784 ;;
785 esac
0709e644 786 done
787 if checkerrors "nogap-encode"; then :; else
788 if [ ! "$KEEPWAVS" = "y" ] ; then
789 if [ ! "$KEEPWAVS" = "move" ] ; then
790 rm -f "$IN"
791 fi
792 fi
793 fi
c9c2ca27 794 # Other encoders fall through to normal encoding as the tracks
795 # have not been entered in the status file.
796}
797
798# do_encode [tracknumber] [hostname]
799# If no hostname is specified, encode locally
800# variables used:
801# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
802do_encode ()
803{
0a3a2dcc 804 if [ "$USEPIPES" = "y" ]; then
805 case "$OUTPUT" in
806 mp3)
807 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
808 ;;
b82e2042 809 vorbis|ogg)
0a3a2dcc 810 TEMPARG="PIPE_$OGGENCODERSYNTAX"
811 ;;
812 flac)
813 TEMPARG="PIPE_$FLACENCODERSYNTAX"
814 ;;
815 spx)
816 TEMPARG="PIPE_$SPEEXENCODER"
817 ;;
818 mpc)
819 TEMPARG="PIPE_$MPPENCODER"
820 ;;
dba06003 821 m4a)
822 TEMPARG="PIPE_$MPPENCODER"
823 ;;
0a3a2dcc 824 esac
a9a23379 825 IN="$( eval echo "\$$TEMPARG" )"
0a3a2dcc 826 else
827 IN="$ABCDETEMPDIR/track$1.wav"
828 case "$OUTPUT" in
829 mp3)
830 case "$MP3ENCODERSYNTAX" in
831 # FIXME # check if mp3enc needs -if for pipes
cb801544 832 # FIXME # I have not been able to find a working mp3enc binary
0a3a2dcc 833 mp3enc)
834 FILEARG="-if $IN"
835 ;;
836 *)
03308bc7 837 FILEARG="$IN"
0a3a2dcc 838 ;;
839 esac
840 ;;
841 *)
03308bc7 842 FILEARG="$IN"
0a3a2dcc 843 ;;
844 esac
845 fi
846 # We need IN to proceed, if we are not using pipes.
847 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
c9c2ca27 848 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
849 do
b82e2042 850 case "$OUTPUT" in
851 vorbis|ogg)
852 OUT="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
a9b99f53 853 OUTPUT=$OGGOUTPUTCONTAINER
b82e2042 854 ;;
855 flac)
856 OUT="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
a9b99f53 857 OUTPUT=$FLACOUTPUTCONTAINER
b82e2042 858 ;;
859 *)
860 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
861 ;;
862 esac
a9b99f53 863 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
864 continue
865 fi
0a3a2dcc 866 if [ X"$USEPIPES" = "Xy" ]; then
867 RUN_COMMAND=""
a40a6c27 868 # We need a way to store the creation of the files when using PIPES
869 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
0a3a2dcc 870 else
871 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
872 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
873 fi
c9c2ca27 874 case "$OUTPUT" in
875 mp3)
876 case "$2" in
877 %local*%)
878 case "$MP3ENCODERSYNTAX" in
0a3a2dcc 879 lame|gogo) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
880 bladeenc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
881 l3enc|xingmp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
882 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
883 mp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
c9c2ca27 884 esac
885 ;;
886 *)
0a3a2dcc 887 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
c9c2ca27 888 ;;
889 esac
890 ;;
b82e2042 891 vorbis|ogg)
c9c2ca27 892 case "$2" in
893 %local*%)
894 case "$OGGENCODERSYNTAX" in
0a3a2dcc 895 vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
896 oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
c9c2ca27 897 esac
898 ;;
899 *)
0a3a2dcc 900 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
c9c2ca27 901 ;;
902 esac
903 ;;
904 flac)
c9c2ca27 905 case "$2" in
535944df 906 %local*%)
c9c2ca27 907 case "$FLACENCODERSYNTAX" in
cb414c1e 908 flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
c9c2ca27 909 esac
535944df 910 ;;
911 *)
912 vecho -n "DISTMP3:"
913 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
914 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
c9c2ca27 915 ;;
916 esac
917 ;;
918 spx)
919 if [ "$(eval echo ${COMMENT})" != "" ]; then
920 case "$COMMENT" in
921 *=*) ;;
922 *) COMMENT="COMMENT=$COMMENT" ;;
923 esac
924 COMMENT="--comment \"$COMMENT\""
925 fi
926 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
927 if [ ! "$DOTAG" = "y" ]; then
0a3a2dcc 928 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
c9c2ca27 929 else
0a3a2dcc 930 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
c9c2ca27 931 fi
932 ;;
99d009fa 933 mpc)
934 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
935 # tagging.
936 # I tried compiling the mppenc from corecodecs.org and got some
937 # errors, so I have not tried it myself.
938 ## FIXME ## Needs some cleanup to determine if an empty tag sent
939 ## FIXME ## to the encoder ends up empty.
0a3a2dcc 940 $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
99d009fa 941 ;;
dba06003 942 m4a)
943 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
944 if [ ! "$DOTAG" = "y" ]; then
945 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
946
947 else
948 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
949 fi
950 ;;
b69a8bb4 951 wav)
952 # In case of wav output we need nothing. Just keep the wavs.
b69a8bb4 953 ;;
c9c2ca27 954 esac
a40a6c27 955 $RUN_COMMAND_PIPES
c9c2ca27 956 done
957 # Only remove .wav if the encoding succeeded
33bc33c3 958 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
c9c2ca27 959 run_command encodetrack-$1 true
960 if [ ! "$KEEPWAVS" = "y" ] ; then
b69a8bb4 961 if [ ! "$KEEPWAVS" = "move" ] ; then
962 rm -f "$IN"
963 fi
c9c2ca27 964 fi
965 fi
966 else
1a064efb 967 run_command "" echo "HEH! The file we were about to encode disappeared:"
968 run_command "" echo ">> $IN"
c9c2ca27 969 run_command encodetrack-$1 false
970 fi
971}
972
99d009fa 973# do_preprocess [tracknumber]
974# variables used:
975# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
976#do_preprocess ()
977#{
978# IN="$ABCDETEMPDIR/track$1.wav"
979# # We need IN to proceed.
980# if [ -s "$IN" ] ; then
981# for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
982# do
983# #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
984# run_command '' echo "Pre-processing track $1 of $TRACKS..."
985# case "$POSTPROCESSFORMAT" in
986# all|wav*)
987# run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
988# mp3)
989# run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
990# ogg)
991# run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
992# flac)
993# run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
994# spx)
995# run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
996# esac
997# done
998# # Only remove .wav if the encoding succeeded
999# if checkerrors "preprocess-(.{3,4})-$1"; then
1000# run_command preprocess-$1 false
1001# else
1002# run_command preprocess-$1 true
1003# fi
1004# else
1005# if [ "$(checkstatus encode-output)" = "loud" ]; then
1006# echo "HEH! The file we were about to pre-process disappeared:"
1007# echo ">> $IN"
1008# fi
1009# run_command preprocess-$1 false
1010# fi
1011#}
1012
1013
1014# do_postprocess [tracknumber]
1015# variables used:
1016# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1017#do_postprocess ()
1018#{
1019# for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1020# do
1021# IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1022# # We need IN to proceed.
1023# if [ -s "$IN" ] ; then
1024# #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1025# run_command '' echo "Post-processing track $1 of $TRACKS..."
1026# case "$POSTPROCESSFORMAT" in
1027# mp3)
1028# run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1029# ogg)
1030# run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1031# flac)
1032# run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1033# spx)
1034# run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1035# esac
1036# # Only remove .wav if the encoding succeeded
1037# if checkerrors "postprocess-(.{3,4})-$1"; then
1038# run_command postprocess-$1 false
1039# else
1040# run_command postprocess-$1 true
1041# fi
1042# else
1043# if [ "$(checkstatus encode-output)" = "loud" ]; then
1044# echo "HEH! The file we were about to post-process disappeared:"
1045# echo ">> $IN"
1046# fi
1047# run_command postprocess-$1 false
1048# fi
1049# done
1050#}
1051
79c8f4d0 1052# do_single_gain
1053# variables used:
1054# FIXME #
1055do_single_gain ()
1056{
1057:
1058}
1059
99d009fa 1060# do_batch_gain
1061# variables used:
cb414c1e 1062# MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
79c8f4d0 1063# FIXME #
99d009fa 1064do_batch_gain ()
1065{
1066 # The commands here don't go through run_command because they're never supposed to be silenced
1067 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1068 (
1069 cd "$ABCDETEMPDIR"
1070 BLURB=
1071 TRACKFILES=
1072 for UTRACKNUM in $TRACKQUEUE
1073 do
1074 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1075 done
cb801544 1076 # FIXME # Hard-coded batch option!
99d009fa 1077 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1078 RETURN=$?
1079 if [ "$RETURN" != "0" ]; then
1080 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1081 else
1082 for UTRACKNUM in $TRACKQUEUE
1083 do
1084 echo normalizetrack-$UTRACKNUM >> status
1085 done
1086 fi
1087 )
1088}
1089
c9c2ca27 1090# do_batch_normalize
1091# variables used:
1092# NORMALIZER, NORMALIZEROPTS
1093do_batch_normalize ()
1094{
1095 # The commands here don't go through run_command because they're never supposed to be silenced
1096 echo "Batch normalizing tracks: $TRACKQUEUE"
1097 (
1098 cd "$ABCDETEMPDIR"
1099 BLURB=
1100 TRACKFILES=
1101 for UTRACKNUM in $TRACKQUEUE
1102 do
1103 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1104 done
1105 # XXX: Hard-coded batch option!
1106 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1107 RETURN=$?
1108 if [ "$RETURN" != "0" ]; then
1109 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1110 else
1111 for UTRACKNUM in $TRACKQUEUE
1112 do
1113 echo normalizetrack-$UTRACKNUM >> status
1114 done
1115 fi
1116 )
1117}
1118
1119# do_normalize [tracknumber]
1120# variables used:
1121# TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1122do_normalize ()
1123{
1124 IN="$ABCDETEMPDIR/track$1.wav"
1125 if [ -e "$IN" ] ; then
1126 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1127 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1128 else
1129 if [ "$(checkstatus encode-output)" = "loud" ]; then
1130 echo "HEH! The file we were about to normalize disappeared:"
1131 echo ">> $IN"
1132 fi
1133 run_command normalizetrack-$1 false "File $IN was not found"
1134 fi
1135}
1136
1137# do_move [tracknumber]
1138# Deduces the outfile from environment variables
1139# Creates directory if necessary
1140# variables used:
99d009fa 1141# TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
c9c2ca27 1142do_move ()
1143{
1144 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1145 do
1146 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1147 # Munge filenames as follows:
1148 # ' ' -> '_'
1149 # '/' -> '_'
1150 # ''' -> ''
1151 # '?' -> ''
1152 # Eat control characters
fe4d186c 1153 ALBUMFILE="$(mungefilename "$DALBUM")"
1154 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1155 TRACKFILE="$(mungefilename "$TRACKNAME")"
1156 GENRE="$(mungegenre "$GENRE")"
1157 YEAR="$(echo $CDYEAR)"
99d009fa 1158 # If we want to start the tracks with a given number, we need to modify the
1159 # TRACKNUM value before evaluation
c0fc2e81 1160 do_gettracknum
99d009fa 1161 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1162 # TRACKFILE, and TRACKNUM.
c9c2ca27 1163 if [ "$VARIOUSARTISTS" = "y" ]; then
fe4d186c 1164 OUTPUTFILE="$(eval echo "$VAOUTPUTFORMAT")"
1165 else
1166 OUTPUTFILE="$(eval echo "$OUTPUTFORMAT")"
c9c2ca27 1167 fi
1a064efb 1168 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1169 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1170 case $OUTPUT in
1171 vorbis|ogg)
1172 OUTPUT=$OGGOUTPUTCONTAINER
1173 ;;
1174 flac)
1175 OUTPUT=$FLACOUTPUTCONTAINER
1176 ;;
1177 esac
1178 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
fe4d186c 1179 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
75c2c424 1180 case $OUTPUT in
1181 wav)
1182 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
cb801544 1183 # FIXME # introduce warnings?
75c2c424 1184 :
1185 else
1186 # mkdir -p shouldn't return an error if the directory already exists
1187 mkdir -p "$OUTPUTFILEDIR"
1188 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1189 if checkstatus movetrack-output-$OUTPUT; then :; else
1190 run_command movetrack-output-$OUTPUT true
1191 fi
1192 fi
1193 ;;
1194 *)
1195 # mkdir -p shouldn't return an error if the directory already exists
1196 mkdir -p "$OUTPUTFILEDIR"
1197 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1198 if checkstatus movetrack-output-$OUTPUT; then :; else
1199 run_command movetrack-output-$OUTPUT true
1200 fi
1201 ;;
1202 esac
1a064efb 1203 # Lets move the cue file
1204 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1205 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1206 if checkstatus movecue-$OUTPUT; then :; else
1207 # Silence the Copying output since it overlaps with encoding processes...
1208 #run_command '' vecho "Copying cue file to its destination directory..."
1209 if checkstatus onetrack >/dev/null ; then
1210 case $OUTPUT in
75c2c424 1211 wav)
1212 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1213 # We dont have the dir, since it was not created before.
1214 :
1215 else
1216 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1217 fi
1218 ;;
1a064efb 1219 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1220 # http://brianvictor.tripod.com/mp3cue.htm#details
1221 [a-z0-9][a-z0-9][a-z0-9])
1222 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1223 ;;
1224 *)
1225 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1226 ;;
1227 esac
1228 else
1229 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1230 fi
1231 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
3416c114 1232 fi
b82e2042 1233 fi
1234 fi
1235 fi
c9c2ca27 1236 done
1237}
1238
1239# do_playlist
1240# Create the playlist if wanted
1241# Variables used:
1242# PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1243# VARIOUSARTISTS, OUTPUTDIR
1244do_playlist ()
1245{
1246 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1247 do
0705fcef 1248 case $OUTPUT in
1249 vorbis|ogg)
1250 OUTPUT=$OGGOUTPUTCONTAINER
1251 ;;
1252 flac)
1253 OUTPUT=$FLACOUTPUTCONTAINER
1254 ;;
1255 esac
c9c2ca27 1256 # Create a playlist file for the playlist data to go into.
1257 # We used to wipe it out if it existed. Now we request permision if interactive.
1258 for LASTTRACK in $TRACKQUEUE; do :; done
fe4d186c 1259 ALBUMFILE="$(mungefilename "$DALBUM")"
1260 ARTISTFILE="$(mungefilename "$DARTIST")"
7acef70b 1261 GENRE=$(mungegenre "$GENRE")
76448acf 1262 YEAR=${CDYEAR:-$CDYEAR}
c9c2ca27 1263 if [ "$VARIOUSARTISTS" = "y" ] ; then
1264 PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
1265 else
1266 PLAYLISTFILE=$(eval echo $PLAYLISTFORMAT)
1267 fi
1268 FINALPLAYLISTDIR=$(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1269 mkdir -p "$FINALPLAYLISTDIR"
1270 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
99d009fa 1271 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
c9c2ca27 1272 if [ "$INTERACTIVE" = "y" ]; then
99d009fa 1273 while [ "$DONE" != "y" ]; do
1274 read ERASEPLAYLIST
1275 case $ERASEPLAYLIST in
1276 e|E|a|A|k|K) DONE=y ;;
1277 *) ;;
1278 esac
1279 done
c9c2ca27 1280 else
99d009fa 1281 echo e >&2
1282 ERASEPLAYLIST=e
c9c2ca27 1283 fi
40c61684 1284 # Once we erase the playlist, we use append to create the new one.
1285 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1286 else
1287 # The playlist does not exist, so we can safelly use append to create the new list
1288 ERASEPLAYLIST=a
c9c2ca27 1289 fi
99d009fa 1290 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1291 touch "$OUTPUTDIR/$PLAYLISTFILE"
1292 for UTRACKNUM in $TRACKQUEUE
1293 do
1294 # Shares some code with do_move since the filenames have to match
1295 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
c0fc2e81 1296 do_getcddbinfo TRACKNAME
99d009fa 1297 splitvarious
fe4d186c 1298 TRACKFILE="$(mungefilename "$TRACKNAME")"
1299 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1300 ALBUMFILE="$(mungefilename "$DALBUM")"
99d009fa 1301 # If we want to start the tracks with a given number, we need to modify the
1302 # TRACKNUM value before evaluation
00840d9a 1303 do_gettracknum
99d009fa 1304 if [ "$VARIOUSARTISTS" = "y" ]; then
1305 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
c9c2ca27 1306 else
99d009fa 1307 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
c9c2ca27 1308 fi
99d009fa 1309 if [ "$VARIOUSARTISTS" = "y" ]; then
1310 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1311 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1312 else
1313 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1314 fi
1315 else
1316 if [ "$PLAYLISTDATAPREFIX" ]; then
1317 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1318 else
1319 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1320 fi
1321 fi
1322 done
1323 fi
c9c2ca27 1324 ## this will convert the playlist to have CRLF line-endings, if specified
1325 ## (some hardware players insist on CRLF endings)
1326 if [ "$DOSPLAYLIST" = "y" ]; then
1327 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
99d009fa 1328# mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1329 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
c9c2ca27 1330 fi
1331 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1332 done
1333}
1334
1335# do_discid
1336# This essentially the start of things
1337do_discid ()
1338{
1339 # Query the CD to get the track info, unless the user specified -C
12c5d978 1340 # or we are using some actions which do not need the CDDB data at all
1341 #if [ ! X"$EXPACTIONS" = "X" ]; then
1342 # :
1343 #elif [ -z "$DISCID" ]; then
c9c2ca27 1344 if [ -z "$DISCID" ]; then
9f659ada 1345 vecho -n "Getting CD track info... "
b82e2042 1346 # In OSX, unmount the disc before a query
f97e22a3 1347 if [ "$OSFLAVOUR" = "OSX" ]; then
1348 disktool -u ${CDROM#/dev/}
1349 fi
1b94d6b7 1350 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1351 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM | $CUE2DISCID)
1352 else
dba06003 1353 case "$CDDBMETHOD" in
1354 cddb) TRACKINFO=$($CDDISCID $CDROM) ;;
1355 # FIXME # musicbrainz needs a cleanup
1356 musicbrainz) TRACKINFO=$($MUSICBRAINZ -c $CDROM ) ;;
1357 esac
1b94d6b7 1358 fi
c9c2ca27 1359 # Make sure there's a CD in there by checking cd-discid's return code
1b94d6b7 1360 if [ ! "$?" = "0" ]; then
1361 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
535944df 1362 log error "cuesheet information from the flac file could not be read."
1363 log error "Perhaps the flac file does not contain a cuesheet?."
1b94d6b7 1364 exit 1
1365 else
535944df 1366 log error "CD could not be read. Perhaps there's no CD in the drive?"
1b94d6b7 1367 exit 1
1368 fi
c9c2ca27 1369 fi
b82e2042 1370 # In OSX, remount the disc again
1371 if [ "$OSFLAVOUR" = "OSX" ]; then
1372 disktool -m ${CDROM#/dev/}
1373 fi
99d009fa 1374 WEHAVEACD=y
70da1809 1375 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
c9c2ca27 1376 else
1377 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1378 fi
1379
1380 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1381 # This needs to be done now because a section of the resuming code will need
1382 # it later.
1383
1384 # get the number of digits to pad TRACKNUM with - we'll use this later
12c5d978 1385 # a CD can only hold 99 tracks, but since we support a feature for starting
1386 # numbering the tracks from a given number, we might need to set it as a
1387 # variable for the user to define... or obtain it somehow.
c9c2ca27 1388 if [ "$PADTRACKS" = "y" ] ; then
1389 TRACKNUMPADDING=2
1390 fi
1391
99d009fa 1392 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
c9c2ca27 1393 if [ -z "$TRACKQUEUE" ]; then
99d009fa 1394 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1395 case "$CDROMREADERSYNTAX" in
1396 cdparanoia|debug)
1397 if [ "$WEHAVEACD" = "y" ]; then
1398 vecho "Querying the CD for audio tracks..."
c008b56d 1399 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
09a85005 1400 RET=$?
1401 if [ ! "$RET" = "0" ];then
535944df 1402 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
09a85005 1403 fi
79558516 1404 TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
99d009fa 1405 CDPARANOIAAUDIOTRACKS="$TRACKS"
1406 else
9cf8eb81 1407 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1408 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1409 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1410 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1411 fi
088b03ff 1412 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
99d009fa 1413 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1414 fi
1415 fi
1416 ;;
1417 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1418 esac
1419 else
1420 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1421 fi
bef9c2d8 1422 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
535944df 1423 log info "The disc does not contain any tracks. Giving up..."
09a85005 1424 exit 0
1425 fi
c9c2ca27 1426 echo -n "Grabbing entire CD - tracks: "
1427 if [ ! "$PADTRACKS" = "y" ] ; then
1428 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1429 fi
1430 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1431 X=0
1432 while [ "$X" -ne "$TRACKS" ]
1433 do
1434 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
0709e644 1435 TRACKQUEUE=$(echo $TRACKQUEUE $X)
c9c2ca27 1436 done
1437 echo $TRACKQUEUE
1438 else
99d009fa 1439 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
c9c2ca27 1440 # User-supplied track queue.
1441 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1442 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1443 # Once cleaned, obtain the highest value in the trackqueue for number padding
1444 for LASTTRACK in $TRACKQUEUE; do :; done
1445 if [ ! "$PADTRACKS" = "y" ] ; then
1446 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1447 fi
1448 # Now we normalize the trackqueue
1449 for TRACK in $TRACKQUEUE ; do
1450 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1451 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1452 done
1453 TRACKQUEUE=$PADTRACKQUEUE
1454 echo Grabbing tracks: "$TRACKQUEUE"
1455 fi
1456
c9c2ca27 1457 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1458
1459 # We have the discid, create a temp directory after it to store all the temp
1460 # info
1461
c9c2ca27 1462 if [ -e "$ABCDETEMPDIR" ]; then
1463 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1464 # It already exists, see if it's a directory
1465 if [ ! -d "$ABCDETEMPDIR" ]; then
1466 # This is a file/socket/fifo/device/etc, not a directory
1467 # Complain and exit
1468 echo >&2
1469 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1470 echo "Please investigate, remove it, and rerun abcde." >&2
1471 exit 1
1472 fi
1473 echo -n .
1474 # It's a directory, let's see if it's owned by us
1475 if [ ! -O "$ABCDETEMPDIR" ]; then
1476 # Nope, complain and exit
1477 echo >&2
1478 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1479 echo "Please investigate, remove it, and rerun abcde." >&2
1480 exit 1
1481 fi
1482 echo .
1483 # See if it's populated
1484 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1485 # Wipe and start fresh
1486 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1487 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1488 if [ "$INTERACTIVE" = "y" ]; then
1489 read ANSWER
1490 else
1491 echo y >&2
1492 ANSWER=y
1493 fi
1494 if [ "$ANSWER" != "y" ]; then
1495 exit 1
1496 fi
1497 rm -rf "$ABCDETEMPDIR" || exit 1
1498 mkdir "$ABCDETEMPDIR"
1499 if [ "$?" -gt "0" ]; then
1500 # Directory already exists or could not be created
1501 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1502 exit 1
1503 fi
1504 else
1505 # Everything is fine. Check for ^encodetracklocation-
1506 # and encode-output entries in the status file and
1507 # remove them. These are not relevant across sessions.
1508 if [ -f "$ABCDETEMPDIR/status" ]; then
1509 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1510 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1511 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1512 fi
1513 # Remove old error messages
1514 if [ -f "$ABCDETEMPDIR/errors" ]; then
1515 rm -f "$ABCDETEMPDIR/errors"
1516 fi
1517 fi
1518 else
1519 # We are starting from scratch
1520 mkdir "$ABCDETEMPDIR"
1521 if [ "$?" -gt "0" ]; then
1522 # Directory already exists or could not be created
1523 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1524 exit 1
1525 fi
1526 cat /dev/null > "$ABCDETEMPDIR/status"
9cf8eb81 1527 # Store the abcde version in the status file.
1528 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
c9c2ca27 1529 fi
b82e2042 1530 if [ X"$MAKECUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1531 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1532 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1533 vecho "Creating cue file..."
411ef0b0 1534 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1535 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1536 else
535944df 1537 log warning "reading the CUE sheet with mkcue is still considered experimental"
1538 log warning "and there was a problem with the CD reading. abcde will continue,"
1539 log warning "but consider reporting the problem to the abcde author"
411ef0b0 1540 fi
24f444d7 1541 fi
1542 fi
99d009fa 1543 # If we got the CDPARANOIA status and it is not recorded, save it now
c7ea851d 1544 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
088b03ff 1545 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
79558516 1546 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
99d009fa 1547 fi
1548 fi
1549
c9c2ca27 1550 # Create the discid file
1551 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
dba06003 1552 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
1553 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
1554 fi
c9c2ca27 1555}
1556
79c8f4d0 1557# do_cleancue
1558# Create a proper CUE file based on the CUE file we created before.
1559do_cleancue()
f97e22a3 1560{
b82e2042 1561 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1562 CUEFILE_OUT=$CUEFILE_IN.out
79c8f4d0 1563 ### FIXME ### checkstatus cddb
b82e2042 1564 if [ -e "$CDDBDATA" ]; then
1565 vecho "Adding metadata to the cue file..."
1566 # FIXME It doesn't preserve spaces! Why?
1567 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1568 n=1
1569 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1570 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1571 cat "$CUEFILE_IN" | while read line
1572 do
1573 if echo "$line" | grep -q "INDEX"
1574 then
1575 eval track="\$TRACK$n"
1576 n=$(expr $n + 1)
1577 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1578 fi
1579 echo "$line" >> "$CUEFILE_OUT"
1580 done
1581 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1582 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
79c8f4d0 1583 fi
1584 fi
f97e22a3 1585}
1586
c9c2ca27 1587# do_cddbparse
1588# Parses a CDDB file and outputs the title and the track names.
1589# Variables: CDDBFILE
1590do_cddbparse ()
1591{
1592 CDDBPARSEFILE="$1"
1593 # List out disc title/author and contents
1594 if [ "$ONETRACK" = "y" ]; then
1595 vecho "ONETRACK mode selected: displaying only the title of the CD..."
1596 fi
1597 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
9ff5088c 1598 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
1599 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
913e4339 1600 if [ ! X"$PARSEDYEAR" = "X" ]; then
f75dae43 1601 echo "Year: $PARSEDYEAR"
9ff5088c 1602 fi
1603 fi
1604 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
1605 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
913e4339 1606 if [ ! X"$PARSEDGENRE" = "X" ]; then
f75dae43 1607 echo "Genre: $PARSEDGENRE"
9ff5088c 1608 fi
1609 fi
99d009fa 1610 if [ ! "$ONETRACK" = "y" ]; then
c9c2ca27 1611 for TRACK in $(f_seq_row 1 $TRACKS)
1612 do
1613 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1614 done
1615 fi
1616}
1617
1618# do_localcddb
1619# Check for a local CDDB file, and report success
1620do_localcddb ()
1621{
1622 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
1623
1624 CDDBLOCALSUCCESS="n"
1625 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1626 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1627 USELOCALRESP="y"
1628
1629 # If the user has selected to check a local CDDB repo, we proceed with it
04609998 1630 if [ -r "${CDDBLOCALFILE}" ]; then
1631 # List out disc title/author and contents
1632 do_cddbparse "${CDDBLOCALFILE}"
1633 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): "
1634 if [ "$INTERACTIVE" = "y" ]; then
1635 read USELOCALRESP
1636 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1637 echo -n 'Invalid selection. Please answer "y" or "n": '
c9c2ca27 1638 read USELOCALRESP
04609998 1639 done
1640 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
1641 else
1642 echo "y" >&2
1643 fi
1644 if [ "$USELOCALRESP" = "y" ]; then
786d4b2e 1645 #echo "Using local copy of CDDB data"
0709e644 1646 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1647 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
04609998 1648 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1649 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
1650 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1651 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1652 CDDBLOCALSUCCESS="y"
c9c2ca27 1653 else
04609998 1654 #echo "Not using local copy of CDDB data"
c9c2ca27 1655 CDDBLOCALSUCCESS="n"
1656 fi
04609998 1657 else
1658 CDDBLOCALSUCCESS="n"
c9c2ca27 1659 fi
1660 fi
1661}
1662
dba06003 1663do_musicbrainzstat ()
1664{
1665 :
1666}
1667
1668do_musizbrainz ()
1669{
1670 :
1671}
1672
c9c2ca27 1673# do_cddbstat
1674do_cddbstat ()
1675{
1676 # Perform CDDB protocol version check if it hasn't already been done
1677 if checkstatus cddb-statcomplete; then :; else
1678 if [ "$CDDBAVAIL" = "n" ]; then
1679 ERRORCODE=no_query
1680 echo 503 > "$ABCDETEMPDIR/cddbstat"
1681 else
1682 rc=1
1683 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1684 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1685 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1686 vecho "Checking CDDB server status..."
1687 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1688 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
1689 case "$RESPONSECODE" in
1690 210) # 210 OK, status information follows (until terminating `.')
1691 rc=0;
1692 ;;
1693 501|*) # 501 Illegal CDDB protocol level: <n>.
1694 CDDBPROTO=`expr $CDDBPROTO - 1`
1695 ;;
1696 esac
1697 done
1698 if test $rc -eq 1; then
1699 CDDBAVAIL="n"
1700 fi
1701 fi
1702 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
1703 fi
1704}
1705
1706
1707# do_cddbquery
1708do_cddbquery ()
1709{
1710 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1711 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1712
1713 # Perform CDDB query if it hasn't already been done
1714 if checkstatus cddb-querycomplete; then :; else
1715 if [ "$CDDBAVAIL" = "n" ]; then
1716 ERRORCODE=no_query
1717 echo 503 > "$ABCDETEMPDIR/cddbquery"
1718 # The default CDDBLOCALSUCCESS is "n"
1719 # This part will be triggered if the user CDDB repo does not
1720 # contain the entry, or if we are not trying to use the repo.
1721 else
1722 vecho "Querying the CDDB server..."
1723 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1724 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1725 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1726 ERRORCODE=$?
1727 case $ERRORCODE in
1728 0) # success
1729 ;;
1730 12|13|14)
1731 # no match found in database,
1732 # wget/fetch error, or user requested not to use CDDB
1733 # Make up an error code (503) that abcde
1734 # will recognize in do_cddbread
1735 # and compensate by making a template
1736 echo 503 > "$ABCDETEMPDIR/cddbquery"
1737 ;;
1738 *) # strange and unknown error
1739 echo ERRORCODE=$ERRORCODE
1740 echo "abcde: $CDDBTOOL returned unknown error code"
1741 ;;
1742 esac
1743 fi
1744 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
1745 fi
1746}
1747
1748# do_cddbread
1749do_cddbread ()
1750{
1751 # If it's not to be used, generate a template.
1752 # Then, display it (or them) and let the user choose/edit it
1753 if checkstatus cddb-readcomplete; then :; else
1754 vecho "Obtaining CDDB results..."
1755 # If CDDB is to be used, interpret the query results and read all
1756 # the available entries.
1757 rm -f "$ABCDETEMPDIR/cddbchoices"
1758 CDDBCHOICES=1 # Overridden by multiple matches
1759 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
1760 case "$RESPONSECODE" in
1761 200)
1762 # One exact match, retrieve it
1763 # 200 [section] [discid] [artist] / [title]
1764 if checkstatus cddb-read-1-complete; then :; else
1765 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1766 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1767 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1768 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1769 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1770 fi
1771 # List out disc title/author and contents
1772 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1773 for TRACK in $(f_seq_row 1 $TRACKS)
1774 do
1775 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1776 done
1777 echo >> "$ABCDETEMPDIR/cddbchoices"
1778 ;;
1779 202|403|409|503)
1780 # No match
1781 case "$RESPONSECODE" in
1782 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1783 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1784 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1785 esac
99d009fa 1786 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
c9c2ca27 1787 # List out disc title/author and contents of template
1788 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
1789 UNKNOWNDISK=y
1790 for TRACK in $(f_seq_row 1 $TRACKS)
1791 do
99d009fa 1792 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
c9c2ca27 1793 done
1794 echo >> "$ABCDETEMPDIR/cddbchoices"
99d009fa 1795 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
1796 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
c9c2ca27 1797 ;;
1798 210|211)
1799 # Multiple exact, (possibly multiple) inexact matches
1800 IN=
1801 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
b82e2042 1802 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
c9c2ca27 1803 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1804 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1805 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1806 else
1807 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1808 fi
99d009fa 1809 vecho -n "Retrieving multiple matches... "
c9c2ca27 1810 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
1811 read DISCINFO # eat top line
1812 while read DISCINFO
1813 do
1814 X=$(expr $X + 1)
1815 if checkstatus cddb-read-$X-complete; then :; else
1816 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1817 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
1818 fi
1819 # List out disc title/author and contents
1820 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1821 for TRACK in $(f_seq_row 1 $TRACKS)
1822 do
1823 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1824 done
1825 echo >> "$ABCDETEMPDIR/cddbchoices"
1826 done )
99d009fa 1827 vecho "done."
c9c2ca27 1828 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1829 ;;
1830 999)
1831 # Using local copy.
1832 for TRACK in $(f_seq_row 1 $TRACKS)
1833 do
1834 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1835 done
1836 echo >> "$ABCDETEMPDIR/cddbchoices"
1837 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1838 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1839 ;;
1840 esac
1841 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1842 fi
1843}
1844
1845# do_cddbedit
1846do_cddbedit ()
1847{
1848 if checkstatus cddb-edit >/dev/null; then
1849 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1850 VARIOUSARTISTS="$(checkstatus variousartists)"
1851 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
1852 return 0
1853 fi
1854 if [ "$INTERACTIVE" = "y" ]; then
1855 # We should show the CDDB results both when we are not using the local CDDB repo
1856 # or when we are using it but we could not find a proper match
1857 if [ "$CDDBUSELOCAL" = "y" ] && [ ! "$CDDBLOCALSUCCESS" = "y" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1858 # Display the $ABCDETEMPDIR/cddbchoices file created above
1859 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1860 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1861 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1862 CHOICE=$(checkstatus cddb-choice)
1863 if [ -n "$CHOICE" ] ; then
1864 case $CDDBCHOICES in
dba06003 1865 -1) log error "CDDB query failed!"
1866 exit 1
1867 ;;
c9c2ca27 1868 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1869 *)
1870 echo "Selected: #$CHOICE"
1871 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1872 ;;
1873 esac
1874 else
1875 # The user has a choice to make, display the info in a pager if necessary
1876 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
913e4339 1877 page "$ABCDETEMPDIR/cddbchoices"
c9c2ca27 1878 else
1879 # It's all going to fit in one page, cat it
1880 cat "$ABCDETEMPDIR/cddbchoices" >&2
1881 fi
1882
9ff5088c 1883 CDDBCHOICENUM=""
913e4339 1884 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
f75dae43 1885 CDCHOICENUM=-1
c9c2ca27 1886 # I'll take CDDB read #3 for $400, Alex
9ff5088c 1887 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
1888 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
c9c2ca27 1889 read CDDBCHOICE
9ff5088c 1890 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
f0582268 1891 if echo $CDDBCHOICE | egrep -q "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" ; then
9ff5088c 1892 if [ ! X"$DIFF" = "X" ]; then
f0582268 1893 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
1894 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
913e4339 1895 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
1896 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
1897 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
1898 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
1899 else
913e4339 1900 # We parse the 2 choices to diff, store them in temporary files and diff them.
1901 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
1902 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
1903 done
1904 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
1905 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
1906 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
1907 page "$ABCDETEMPDIR/cddbread.diff"
1908 else
1909 cat "$ABCDETEMPDIR/cddbread.diff" >&2
1910 fi
1911 fi
9ff5088c 1912 else
1913 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
1914 fi
f0582268 1915 elif echo $CDDBCHOICE | egrep -q "[[:space:]]*[[:digit:]]+[[:space:]]*" ; then
1916 # Make sure we get a valid choice
1917 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
9ff5088c 1918 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
9ff5088c 1919 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
1920 fi
1921 fi
c9c2ca27 1922 done
99d009fa 1923 if [ "$CDCHOICENUM" = "0" ]; then
1924 vecho "Creating empty CDDB template..."
1925 UNKNOWNDISK=y
b82e2042 1926 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
99d009fa 1927 else
03308bc7 1928 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
99d009fa 1929 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
1930 fi
c9c2ca27 1931 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1932 fi
1933 fi
1934 else
1935 # We need some code to show the selected option when local repository is selected and we have found a match
9f659ada 1936 vecho "Using cached CDDB match..." >&2
c9c2ca27 1937 # Display the $ABCDETEMPDIR/cddbchoices file created above
1938 # Pick a pager so that if the tracks overflow the screen the user can still view everything
1939 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1940 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1941 CHOICE=$(checkstatus cddb-choice)
1942 if [ "$USELOCALRESP" = "y" ]; then :; else
1943 if [ -n "$CHOICE" ] ; then
1944 case $CDDBCHOICES in
04609998 1945 0)
1946 UNKNOWNDISK=y
1947 echo "Selected template."
1948 ;;
c9c2ca27 1949 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
1950 *)
1951 echo "Selected: #$CHOICE"
1952 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
1953 ;;
1954 esac
1955 fi
1956 fi
1957 fi
1958 fi
1959 else
1960 # We're noninteractive - pick the first choice.
1961 # But in case we run a previous instance and selected a choice, use it.
1962 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
1963 # Show the choice if we are not using the locally stored one
1964 # or when the local search failed to find a match.
1965 PREVIOUSCHOICE=$(checkstatus cddb-choice)
1966 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSUCCESS" = "n" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
1967 #if [ "$PREVIOUSCHOICE" ]; then
1968 cat "$ABCDETEMPDIR/cddbchoices"
1969 #fi
1970 fi
1971 if [ ! -z "$PREVIOUSCHOICE" ] ; then
1972 CDCHOICENUM=$PREVIOUSCHOICE
1973 else
1974 CDCHOICENUM=1
1975 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
1976 fi
03308bc7 1977 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
c9c2ca27 1978 fi
1979 fi
1980
1981 # sanity check
1982 if checkstatus cddb-choice >/dev/null; then :; else
1983 echo "abcde: internal error: cddb-choice not recorded." >&2
1984 exit 1
1985 fi
1986 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
9f659ada 1987 echo -n "Edit selected CDDB data? [y/n] (" >&2
c9c2ca27 1988 if [ "$INTERACTIVE" = "y" ]; then
1989 if [ "$UNKNOWNDISK" = "y" ]; then
1990 echo -n "y): " >&2
1991 read EDITCDDB
1992 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
1993 else
1994 echo -n "n): " >&2
1995 read EDITCDDB
1996 fi
1997 else
1998 echo "n): n" >&2
1999 EDITCDDB=n
2000 fi
2001 if [ "$EDITCDDB" = "y" ]; then
2002 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2003
2004 # Use the debian sensible-editor wrapper to pick the editor that the
2005 # user has requested via their $EDITOR environment variable
2006 if [ -x "/usr/bin/sensible-editor" ]; then
2007 /usr/bin/sensible-editor "$CDDBDATA"
2008 elif [ -n "$EDITOR" ]; then
2009 if [ -x $(which "${EDITOR%%\ *}") ]; then
2010 # That failed, try to load the preferred editor, starting
2011 # with their EDITOR variable
03308bc7 2012 eval $(echo "$EDITOR") \"$CDDBDATA\"
c9c2ca27 2013 fi
2014 # If that fails, check for a vi
2994a485 2015 elif which vi >/dev/null 2>&1; then
2016 vi "$CDDBDATA"
fd34b28b 2017 elif [ -x /usr/bin/vim ]; then
2018 /usr/bin/vim "$CDDBDATA"
c9c2ca27 2019 elif [ -x /usr/bin/vi ]; then
2020 /usr/bin/vi "$CDDBDATA"
fd34b28b 2021 elif [ -x /bin/vi ]; then
2022 /bin/vi "$CDDBDATA"
c9c2ca27 2023 # nano should be on all (modern, i.e., sarge) debian systems
2994a485 2024 elif which nano >/dev/null 2>&1 ; then
2025 nano "$CDDBDATA"
c9c2ca27 2026 elif [ -x /usr/bin/nano ]; then
2027 /usr/bin/nano "$CDDBDATA"
2028 # mg should be on all OpenBSD systems
2994a485 2029 elif which mg >/dev/null 2>&1 ; then
2030 mg "$CDDBDATA"
c9c2ca27 2031 elif [ -x /usr/bin/mg ]; then
2032 /usr/bin/mg "$CDDBDATA"
2033 # bomb out
2034 else
535944df 2035 log warning "no editor available. Check your EDITOR environment variable."
c9c2ca27 2036 fi
2037 # delete editor backup file if it exists
2038 if [ -w "$CDDBDATA~" ]; then
2039 rm -f "$CDDBDATA~"
2040 fi
2041 fi
2042
2043 # Some heuristics first. Look at Disc Title, and if it starts with
2044 # "Various", then we'll assume Various Artists
c81531ac 2045 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
c9c2ca27 2046 echo "Looks like a Multi-Artist CD" >&2
2047 VARIOUSARTISTS=y
2048 else
2049 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2050 if [ "$INTERACTIVE" = "y" ]; then
2051 read VARIOUSARTISTS
2052 else
2053 echo n >&2
2054 VARIOUSARTISTS=n
2055 fi
2056 fi
2057 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2058 # Set a default
2059 DEFAULTSTYLE=1
2060 # Need NUMTRACKS before cddb-tool will return it:
99d009fa 2061 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
c9c2ca27 2062 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2063 # More than 1/2 tracks contain a "/", so guess forward
2064 DEFAULTSTYLE=1
2065 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2066 # More than 1/2 contain a "-", so guess forward-dash
2067 DEFAULTSTYLE=2
2068 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2069 # More than 1/2 contain something in parens, so guess trailing-paren
2070 DEFAULTSTYLE=6
2071 fi
2072
2073 echo "1) Artist / Title" >&2
2074 echo "2) Artist - Title" >&2
2075 echo "3) Title / Artist" >&2
2076 echo "4) Title - Artist" >&2
2077 echo "5) Artist: Title" >&2
2078 echo "6) Title (Artist)" >&2
2079 echo "7) This is a single-artist CD" >&2
2080 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2081 if [ "$INTERACTIVE" = "y" ]; then
2082 read VARIOUSARTISTSTYLE
2083 else
2084 echo $DEFAULTSTYLE >&2
2085 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2086 fi
2087 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2088 # If they press Enter, then the default style (0) was chosen
2089 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2090 echo "Invalid selection. Please choose a number between 1 and 7."
2091 echo -n "Selection [1-7]: "
2092 read VARIOUSARTISTSTYLE
2093 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2094 done
2095 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2096 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2097 fi
99d009fa 2098 vecho "Selected: $VARIOUSARTISTSTYLE"
c9c2ca27 2099 case "$VARIOUSARTISTSTYLE" in
2100 1) # Artist / Title
2101 VARIOUSARTISTSTYLE=forward
2102 ;;
2103 2) # Artist - Title
2104 VARIOUSARTISTSTYLE=forward-dash
2105 ;;
2106 3) # Title / Artist
2107 VARIOUSARTISTSTYLE=reverse
2108 ;;
2109 4) # Title - Artist
2110 VARIOUSARTISTSTYLE=reverse-dash
2111 ;;
2112 5) # Artist: Title
2113 VARIOUSARTISTSTYLE=colon
2114 ;;
2115 6) # Title (Artist)
2116 VARIOUSARTISTSTYLE=trailing-paren
2117 ;;
2118 7) # Single Artist
2119 VARIOUSARTISTS=n
2120 ;;
2121 esac
2122 fi
2123
2124 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2125 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2126
2127 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
a9a23379 2128 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
c9c2ca27 2129 # This works but does not have the necessary error checking
2130 # yet. If you are familiar with the CDDB spec
2131 # (see http://www.freedb.org/src/latest/DBFORMAT)
2132 # and can create an error-free entry on your own, then put
2133 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2134 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2135 # your abcde.conf to change the email address submissions are
2136 # sent to.
2137
2138 # submit the modified file, if they want
2139 if [ "$NOSUBMIT" != "y" ]; then
2140 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2141 read YESNO
2142 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2143 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2144 do
2145 echo -n 'Invalid selection. Please answer "y" or "n": '
2146 read YESNO
2147 done
2148 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2149 echo -n "Sending..."
2150 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2151 echo "done."
2152 fi
2153 fi
2154 fi
2155 fi
2156 # Make sure the cache directory exists
2157 mkdir -p $CDDBLOCALDIR
2158 # Cache edited CDDB entry in the user's cddb dir
2159 if [ "$CDDBCOPYLOCAL" = "y" ] || [ "$COPYCDDBLOCAL" = "Y" ]; then
2160 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2161 fi
2162
2163 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2164}
2165
c9c2ca27 2166# do_cdread [tracknumber]
d5200e72 2167# do_cdread onetrack [firsttrack] [lasttrack]
c9c2ca27 2168#
2169do_cdread ()
2170{
2171 # The commands here don't go through run_command because they're never supposed to be silenced
2172 # return codes need to be doublechecked anyway, however
d5200e72 2173 if [ "$1" = "onetrack" ]; then
2174 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
c7ea851d 2175 # FIXME # Until then, we grab the whole CD in one track, no matter what
2176 # the user said
d5200e72 2177 # We need the first and last track for cdda2wav
2178 FIRSTTRACK=$2
2179 LASTTRACK=$3
1366e842 2180 UTRACKNUM=$FIRSTTRACK
dba06003 2181 case "$CDROMREADERSYNTAX" in
2182 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2183 cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2184 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTRACK" ;;
2185 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2186 exit 1 ;;
2187 esac
d5200e72 2188 else
2189 UTRACKNUM=$1
2190 fi
c9c2ca27 2191 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
49c04b11 2192 if [ "$USEPIPES" = "y" ]; then
a2881eba 2193 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
a9a23379 2194 FILEARG="$( eval echo "\$$TEMPARG" )"
49c04b11 2195 REDIR=""
0a3a2dcc 2196 PIPE_MESSAGE="and encoding "
49c04b11 2197 else
0a3a2dcc 2198 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
49c04b11 2199 case "$CDROMREADERSYNTAX" in
1b94d6b7 2200 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2201 flac)
2202 FILEARG="--output-name=$WAVDATA"
2203 ;;
49c04b11 2204 dagrab)
2205 FILEARG="-f $WAVDATA"
2206 ;;
2207 *)
03308bc7 2208 FILEARG="$WAVDATA"
49c04b11 2209 ;;
2210 esac
2211 REDIR=">&2"
2212 fi
efc6de2f 2213 if [ "$1" = "onetrack" ]; then
b82e2042 2214 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
0a3a2dcc 2215 else
efc6de2f 2216 if [ -r "$CDDBDATA" ]; then
c0fc2e81 2217 do_getcddbinfo TRACKNAME
efc6de2f 2218 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2219 else
2220 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2221 fi
0a3a2dcc 2222 fi
c9c2ca27 2223 case "$CDROMREADERSYNTAX" in
1b94d6b7 2224 ### FIXME ### use an exception for flac, since it uses -o
2225 ### FIXME ### Shall we just use -o $FILEARG ??
2226 flac)
2227 nice $READNICE $FLAC -d --cue=${READTRACKNUMS:-$UTRACKNUM.1-$(($UTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
1366e842 2228 cdparanoia)
dba06003 2229 echo "nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;" > /tmp/log
c008b56d 2230 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
c9c2ca27 2231 cdda2wav)
2232 if [ "$OSFLAVOUR" = "OSX" ] ; then
2233 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2234 disktool -u ${CDROM#/dev/} 0
2235 # Also, in OSX the cdrom device for cdda2wav changes...
2236 CDDA2WAVCDROM="IODVDServices"
2237 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2238 CDDA2WAVCDROM="$CDROMID"
2239 else
2240 if [ "$CDROMID" = "" ]; then
2241 CDDA2WAVCDROM="$CDROM"
2242 else
2243 CDDA2WAVCDROM="$CDROMID"
2244 fi
2245 fi
03308bc7 2246 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
c7ea851d 2247 ;;
2248 ## FIXME ## We have an exception for dagrab, since it uses -f
2249 ## FIXME ## Shall we just use -f $FILEARG ??
03308bc7 2250 dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
c9c2ca27 2251 ;;
c9c2ca27 2252 cddafs)
2253 # Find the track's mounted path
2254 REALTRACKNUM=$(expr $UTRACKNUM + 0)
47589f71 2255 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
c9c2ca27 2256 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2257 # If the file exists, copy it
2258 if [ -e "$FILEPATH" ] ; then
03308bc7 2259 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
c9c2ca27 2260 else
2261 false
2262 fi ;;
c008b56d 2263 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
c7ea851d 2264 ;;
c9c2ca27 2265 esac
2266 RETURN=$?
c7ea851d 2267 # If we get some error or we get some missing wav
2268 # (as long as we dont use pipes)
2269 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
c9c2ca27 2270 # Thank goodness errors is only machine-parseable up to the
2271 # first colon, otherwise this woulda sucked
93415558 2272 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2273 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2274 fi
49c04b11 2275 if [ "$USEPIPES" = "y" ]; then
2276 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2277 else
2278 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2279 fi
c9c2ca27 2280 return $RETURN
2281 else
49c04b11 2282 if [ "$USEPIPES" = "y" ]; then
2283 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2284 else
2285 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
3416c114 2286 if [ "$1" = "onetrack" ]; then
2287 echo onetrack >> "$ABCDETEMPDIR/status"
2288 fi
49c04b11 2289 fi
c9c2ca27 2290 fi
2291}
2292
99d009fa 2293# do_cdspeed
2294# No values accepted, only uses env variables
c9c2ca27 2295do_cdspeed ()
2296{
2297 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
2298 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
2299 else
2300 echo "abcde: unable to set the device speed" >&2
2301 fi
2302}
2303
2304# vecho [message]
2305#
2306# vecho outputs a message if EXTRAVERBOSE is selected
2307vecho ()
2308{
2309if [ x"$EXTRAVERBOSE" != "x" ]; then
535944df 2310 case $1 in
2311 warning) log warning "$@" ;;
2312 *) echo "$@" ;;
2313 esac
c9c2ca27 2314fi
2315}
2316
0709e644 2317# decho [message]
2318#
2319# decho outputs a debug message if DEBUG is selected
2320decho ()
2321{
2322if [ x"$DEBUG" != "x" ]; then
c1bbe6c3 2323 if echo $1 | grep -q "^\[" ; then
2324 DEBUGECHO=$(echo "$@" | tr -d '[]')
2325 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2326 else
2327 echo "[DEBUG] $1"
2328 fi
0709e644 2329fi
2330}
2331
b7f1cc84 2332# User-redefinable functions
2333# Custom filename munging:
2334mungefilename ()
2335{
eb1474fe 2336 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2337 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
b7f1cc84 2338}
2339
2340# Custom genre munging:
2341mungegenre ()
2342{
2343 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2344}
2345
2346# pre_read
2347# Empty pre_read function, to be defined in the configuration file.
2348pre_read ()
2349{
2350:
2351}
2352
65f3ebb1 2353# post_read
2354# Empty post_read function, to be defined in the configuration file.
2355post_read ()
2356{
2357:
2358}
2359
a2052a00 2360###############################################################################
b7f1cc84 2361# End of functions
2362#
c9c2ca27 2363# Start of execution
a2052a00 2364###############################################################################
c9c2ca27 2365
2366# Builtin defaults
dba06003 2367
2368# CDDB
2369# Defaults to FreeDB, but a python musicbrainz can be used
2370CDDBMETHOD=cddb
c9c2ca27 2371CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2372CDDBSUBMIT=freedb-submit@freedb.org
2373CDDBPROTO=5
2374HELLOINFO="$(whoami)@$(hostname)"
9ff5088c 2375CDDBCOPYLOCAL="n"
2376CDDBLOCALDIR="$HOME/.cddb"
2377CDDBUSELOCAL="n"
2378
2379# List of fields we parse and show during the CDDB parsing...
2380SHOWCDDBFIELDS="year,genre"
2381
c9c2ca27 2382INTERACTIVE=y
dba06003 2383#CDROMREADERSYNTAX=cdparanoia
c9c2ca27 2384ENCODERSYNTAX=default
2385
2386MP3ENCODERSYNTAX=default
2387OGGENCODERSYNTAX=default
2388FLACENCODERSYNTAX=default
2389SPEEXENCODERSYNTAX=default
99d009fa 2390MPPENCODERSYNTAX=default
dba06003 2391AACENCODERSYNTAX=default
72d7162b 2392NORMALIZERSYNTAX=default
411ef0b0 2393CUEREADERSYNTAX=default
c9c2ca27 2394
2395OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2396# Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2397#VAOUTPUTFORMAT=${OUTPUTFORMAT}
2398VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2399ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2400VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2401PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2402PLAYLISTDATAPREFIX=''
2403VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2404VAPLAYLISTDATAPREFIX=''
2405DOSPLAYLIST=n
2406COMMENT=''
2407ID3TAGV=2
2408ENCNICE=10
2409READNICE=10
2410DISTMP3NICE=10
2411VARIOUSARTISTS=n
2412VARIOUSARTISTSTYLE=forward
c9c2ca27 2413KEEPWAVS=n
2414PADTRACKS=n
0709e644 2415NOGAP=n
2416BATCHNORM=n
c9c2ca27 2417
2418# If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2419# i.e. CDROMID="1,0,0"
2420CDROMID=""
c008b56d 2421# If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2422# If we are using the ide-scsi emulation layer, we need to define a "g"
2423CDPARANOIACDROMBUS="d"
c9c2ca27 2424
2425# program paths - defaults to checking your $PATH
2426# mp3
2427LAME=lame
0709e644 2428TOOLAME=toolame
c9c2ca27 2429GOGO=gogo
2430BLADEENC=bladeenc
2431L3ENC=l3enc
2432XINGMP3ENC=xingmp3enc
2433MP3ENC=mp3enc
2434# ogg
2435VORBIZE=vorbize
2436OGGENC=oggenc
2437# flac
2438FLAC=flac
2439# speex
2440SPEEXENC=speexenc
99d009fa 2441# mpp (Musepack)
2442MPPENC=mppenc
dba06003 2443# m4a
2444AACENC=faac
c9c2ca27 2445
2446ID3=id3
2447ID3V2=id3v2
a9a23379 2448EYED3=eyeD3
c9c2ca27 2449CDPARANOIA=cdparanoia
2450CDDA2WAV=cdda2wav
2451DAGRAB=dagrab
2452CDDAFS=cp
2453CDDISCID=cd-discid
2454CDDBTOOL=cddb-tool
dba06003 2455MUSICBRAINZ=musicbrainz-get-tracks
c9c2ca27 2456EJECT=eject
2457MD5SUM=md5sum
2458DISTMP3=distmp3
2459VORBISCOMMENT=vorbiscomment
2460METAFLAC=metaflac
72d7162b 2461NORMALIZE=normalize-audio
c9c2ca27 2462CDSPEED=eject
12c5d978 2463VORBISGAIN=vorbisgain
6fba8f12 2464MP3GAIN=mp3gain
cb414c1e 2465MPPGAIN=replaygain
24f444d7 2466MKCUE=mkcue
9ff5088c 2467MKTOC=cdrdao
2468DIFF=diff
1b94d6b7 2469CUE2DISCID=cue2discid
c9c2ca27 2470
2471# Options for programs called from abcde
2472# mp3
2473LAMEOPTS=
0709e644 2474TOOLAMEOPTS=
c9c2ca27 2475GOGOOPTS=
2476BLADEENCOPTS=
2477L3ENCOPTS=
2478XINGMP3ENCOPTS=
2479MP3ENCOPTS=
2480# ogg
2481VORBIZEOPTS=
2482OGGENCOPTS=
2483# flac
cb414c1e 2484FLACOPTS=
c9c2ca27 2485# speex
2486SPEEXENCOPTS=
9f659ada 2487# mpc
2488MPPENCOPTS=
dba06003 2489# m4a
2490AACENCOPTS=
c9c2ca27 2491
2492ID3OPTS=
2493ID3V2OPTS=
2494CDPARANOIAOPTS=
2495CDDA2WAVOPTS=
2496DAGRABOPTS=
2497CDDAFSOPTS="-f"
2498CDDBTOOLOPTS=
2499EJECTOPTS=
2500DISTMP3OPTS=
2501NORMALIZEOPTS=
2502CDSPEEDOPTS="-x"
2503CDSPEEDVALUE=
24f444d7 2504MKCUEOPTS=
9ff5088c 2505MKTOCOPTS=""
b33dc0c1 2506VORBISCOMMENTOPTS="-R"
2507METAFLACOPTS="--no-utf8-convert"
c1bbe6c3 2508DIFFOPTS=
c9c2ca27 2509
2510# Default to one process if -j isn't specified
2511MAXPROCS=1
2512
2513# List of actions to perform - by default, run to completion
2514ACTIONS=cddb,read,encode,tag,move,clean
2515
dba06003 2516# This option is basicaly for Debian package dependencies:
b82e2042 2517# List of prefered outputs - by default, run with whatever we have in the path
b82e2042 2518DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex
2519
dba06003 2520# List of prefered cdromreaders - by default, run whichever we have in the path
2521DEFAULT_CDROMREADERS="cdparanoia cdda2wav"
2522
c9c2ca27 2523# Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2524# Let's use these checkings to determine the OS flavour, which will be used later
2525if [ X$(uname) = "XFreeBSD" ] ; then
2526 HTTPGET=fetch
a9a23379 2527 MD5SUM=md5
c9c2ca27 2528 NEEDCDROMID=y
2529 OSFLAVOUR=FBSD
2530elif [ X$(uname) = "XDarwin" ] ; then
2531 HTTPGET=curl
2532 OSFLAVOUR=OSX
2533 # We should have disktool in OSX, but let's be sure...
2534 NEEDDISKTOOL=y
f97e22a3 2535 CDROMREADERSYNTAX=cddafs
c9c2ca27 2536elif [ X$(uname) = "XOpenBSD" ] ; then
2537 HTTPGET=wget
2538 MD5SUM=md5
a9a23379 2539elif [ X$(uname) = "XNetBSD" ] ; then
2540 HTTPGET=ftp
2541 MD5SUM=md5
c9c2ca27 2542else
2543 HTTPGET=wget
2544fi
2545
2546# If CDDBAVAIL is set to n, no CDDB read is done
2547# If USEID3 is set to n, no ID3 tagging is done
2548CDDBAVAIL=y
2549USEID3=y
24f444d7 2550USEID3V2=y
c9c2ca27 2551
2552if [ -z "$OUTPUTDIR" ]; then
2553 OUTPUTDIR=$(pwd)
2554fi
2555
2556if [ -z "$WAVOUTPUTDIR" ]; then
2557 WAVOUTPUTDIR="$OUTPUTDIR"
2558fi
2559
2560# Load system defaults
2561if [ -r /etc/abcde.conf ]; then
2562 . /etc/abcde.conf
2563fi
2564# Load user preference defaults
2565if [ -r $HOME/.abcde.conf ]; then
2566 . $HOME/.abcde.conf
2567fi
2568
2569# By this time, we need some HTTPGETOPTS already defined.
b7f1cc84 2570# If the user has defined a non-default HTTPGET method, we should not be empty.
c9c2ca27 2571
2572if [ "$HTTPGETOPTS" = "" ] ; then
2573 case $HTTPGET in
2574 wget) HTTPGETOPTS="-q -O -";;
2575 curl) HTTPGETOPTS="-f -s";;
2576 fetch)HTTPGETOPTS="-q -o -";;
a9a23379 2577 ftp) HTTPGETOPTS="-q -o -";;
535944df 2578 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
c9c2ca27 2579 esac
2580fi
2581
2582# If the CDROM has not been set yet, find a suitable one.
2583# If this is a devfs system, default to /dev/cdroms/cdrom0
2584# instead of /dev/cdrom
2585if [ "$CDROM" = "" ] ; then
2586 if [ -e /dev/cdroms/cdrom0 ]; then
2587 CDROM=/dev/cdroms/cdrom0
2588 elif [ -e /dev/cdrom ]; then
2589 CDROM=/dev/cdrom
2590 elif [ -e /dev/cd0c ]; then
2591 CDROM=/dev/cd0c
2592 elif [ -e /dev/acd0c ]; then
2593 CDROM=/dev/acd0c
2594 elif [ -e /dev/disk1 ]; then
2595 CDROM=/dev/disk1
2596 fi
2597fi
2598
2599# Parse command line options
50042502 2600#while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
73b0af6e 2601while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:uvVxw:W:z opt ; do
c9c2ca27 2602 case "$opt" in
2603 1) ONETRACK=y ;;
2604 a) ACTIONS="$OPTARG" ;;
a9a23379 2605 A) EXPACTIONS="$OPTARG" ;;
0709e644 2606 b) BATCHNORM=y ;;
6fba8f12 2607 B) NOBATCHREPLAYGAIN=y ;;
535944df 2608 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
70da1809 2609 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
c9c2ca27 2610 d) CDROM="$OPTARG" ;;
2611 D) set -x ;;
bef9c2d8 2612 e) ERASEENCODEDSTATUS=y ;;
c9c2ca27 2613 h) usage; exit ;;
b33dc0c1 2614 e) ERASEENCODEDSTATUS=y ;;
a9a23379 2615 E) ENCODING="$OPTARG" ;;
75c2c424 2616 f) FORCE=y ;;
0709e644 2617 g) NOGAP=y ;;
c9c2ca27 2618 i) INLINETAG=y ;;
2619 j) MAXPROCS="$OPTARG" ;;
2620 k) KEEPWAVS=y ;;
2621 l) LOWDISK=y ;;
b7f1cc84 2622 L) CDDBUSELOCAL=y ;;
2623 n) CDDBAVAIL=n ;;
2624 N) INTERACTIVE=n ;;
c9c2ca27 2625 m) DOSPLAYLIST=y ;;
b82e2042 2626 M) MAKECUEFILE=y ;;
c9c2ca27 2627 o) OUTPUTTYPE="$OPTARG" ;;
b7f1cc84 2628 p) PADTRACKS=y ;;
2629 P) USEPIPES=y ;;
c9c2ca27 2630 r) REMOTEHOSTS="$OPTARG" ;;
6fba8f12 2631 R) DOREPLAYGAIN=y ;;
9ff5088c 2632 s) SHOWCDDBFIELDS="$OPTARG" ;;
c9c2ca27 2633 S) CDSPEEDVALUE="$OPTARG" ;;
79e3928b 2634 t) STARTTRACKNUMBER="$OPTARG" ;;
2635 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
73b0af6e 2636 u) CDDBPROTO=6 ;;
c9c2ca27 2637 v)
2638 echo "This is abcde v$VERSION."
2639 echo "Usage: abcde [options] [tracks]"
2640 echo "abcde -h for extra help"
2641 exit
2642 ;;
2643 V) EXTRAVERBOSE="y" ;;
2644 x) EJECTCD="y" ;;
79e3928b 2645 w) COMMENT="$OPTARG" ;;
bef9c2d8 2646 W) if echo $OPTARG | grep -q "[[:digit:]]" ; then
2647 STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
2648 else
535944df 2649 log error "argument of -W must be integer"
bef9c2d8 2650 exit 1
2651 fi
2652 ;;
0709e644 2653 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
c9c2ca27 2654 ?) usage; exit ;;
2655 esac
2656done
2657
2658shift $(($OPTIND - 1))
2659
1b94d6b7 2660# If the user specified a flac file, then switch to special flac mode
2661if echo $CDROM | grep -i -q '.flac$'; then
2662 vecho "abcde: switching to flac CDROMREADERSYNTAX..."
2663 CDROMREADERSYNTAX=flac
2664 if [ "$EJECTCD" = "y" ];then
2665 vecho "abcde: CDROM flac mode, deactivating EJECTCD..."
2666 EJECTCD=n
2667 fi
2668fi
2669
5ddcb883 2670# If the user provided a DISCID, disable eject
2671if [ -n "$DISCID" ]; then EJECTCD=n ; fi
2672
dba06003 2673# Check the available cd rippers in the system, from the ones we know.
2674if [ "$CDROMREADERSYNTAX" = "" ]; then
2675 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
2676 if [ -x $( which $DEFAULT_CDROMREADER ) ]; then
2677 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
2678 break
2679 fi
2680 done
2681 if [ "$CDROMREADERSYNTAX" = "" ]; then
2682 log error "no cdreader found in your PATH"
2683 log error "hints: are all dependencies installed? has the \$PATH been modified?"
2684 exit 1
2685 fi
2686fi
2687
d5200e72 2688# Decide if we can continue.
2689if [ "$ONETRACK" = "y" ]; then
2690 # FIXME # remove check as soon as we find out about the other readers
99d009fa 2691 case "$CDROMREADERSYNTAX" in
1b94d6b7 2692 flac) ;;
b82e2042 2693 cdparanoia) ;;
2694 cdda2wav) ;;
535944df 2695 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
b82e2042 2696 exit 1 ;;
99d009fa 2697 esac
0709e644 2698 if [ "$BATCHNORM" = "y" ]; then
535944df 2699 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
0709e644 2700 BATCHNORM=n
2701 fi
2702 if [ "$NOGAP" = "y" ]; then
535944df 2703 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
0709e644 2704 NOGAP=n
99d009fa 2705 fi
2706 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
d5200e72 2707 # FIXME # allow ranges of tracks to be selected for onetrack ripping
c9c2ca27 2708 if [ $# -gt 0 ]; then
535944df 2709 log warning "ONETRACK mode selected, grabbing all tracks..."
c9c2ca27 2710 fi
2711else
2712 while [ $# -gt 0 ]; do
2713 # Range parsing code courtesy of Vincent Ho
2714 RSTART=$(echo $1 | cut -f1 -d-)
2715 REND=$(echo $1 | cut -f2 -d-)
2716 if [ "$RSTART" = "$REND" ]; then
2717 NEWTRACKS="$RSTART"
2718 else
2719 NEWTRACKS=$(f_seq_line $RSTART $REND)
2720 fi
2721 TRACKQUEUE=$(echo "$TRACKQUEUE" "$NEWTRACKS")
c9c2ca27 2722 shift
2723 done
2724fi
2725
b7f1cc84 2726# List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2727# List of experimental actions: retag,transcode
2728
2729# Determine what actions are to be done from $ACTIONS and set the
2730# following environment variables for them:
2731DOCDDB=n
2732DOREAD=n
2733DONORMALIZE=n
2734DOPREPROCESS=n
2735DOENCODE=n
2736DOPOSTPROCESS=n
2737DOTAG=n
2738DOMOVE=n
00840d9a 2739DOREPLAYGAIN=n
b7f1cc84 2740DOPLAYLIST=n
2741DOCLEAN=n
2742
2743for ACTION in $(echo $ACTIONS | tr , \ )
2744do
2745 case $ACTION in
24f444d7 2746 cddb) DOCDDB=y;;
2747 read) DOREAD=y;;
2748 normalize) DONORMALIZE=y; DOREAD=y;;
2749# preprocess) DOPREPROCESS=y; DOREAD=y;;
2750 encode) DOENCODE=y; DOREAD=y;;
2751# postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2752 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2753 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
00840d9a 2754 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
24f444d7 2755 playlist) DOCDDB=y; DOPLAYLIST=y;;
2756 clean) DOCLEAN=y;;
b7f1cc84 2757 esac
2758done
2759
1750d493 2760if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2761 # FIXME # should we abort on error or just inform the user?
6fba8f12 2762 log warning "selected both normalize and replaygain actions"
1750d493 2763fi
2764
9ff5088c 2765for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
2766 case $SHOWCDDBFIELD in
2767 y*|Y*) SHOWCDDBYEAR="y";;
2768 g*|G*) SHOWCDDBGENRE="y";;
2769 *) ;;
2770 esac
2771done
b7f1cc84 2772
9ff5088c 2773# Sanity checks:
b82e2042 2774
c9c2ca27 2775# At this point a CDROM has to be defined, so we check it exists.
6c124acf 2776if [ X"$CDROM" != "X" ] ; then
c9c2ca27 2777 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2778 if [ "$OSFLAVOUR" = "FBSD" ]; then
2779 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
535944df 2780 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
2781 log error "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
c9c2ca27 2782 exit 1
8fc41c4f 2783 fi
c9c2ca27 2784 fi
c81531ac 2785 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
535944df 2786 log error "CDROM device cannot be found."
c9c2ca27 2787 exit 1
2788 fi
6c124acf 2789# avoid processing if we are not going to hit the CDROM.
c81531ac 2790elif [ X"$DOREAD" = "Xy" ]; then
535944df 2791 log error "CDROM has not been defined or cannot be found"
c9c2ca27 2792 exit 1
2793fi
2794
c7ea851d 2795# USEPIPES pre-tests, before we get into more serious stuff
2796# Not compatible with:
d5200e72 2797# - multiple outputs
2798# - normalize
c7ea851d 2799# - lowdisk algorithm
d5200e72 2800# - anything else?
c7ea851d 2801if [ X"$USEPIPES" = "Xy" ]; then
b82e2042 2802 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
535944df 2803 log error "Unix pipes not compatible with multiple outputs"
d5200e72 2804 exit 1
2805 fi
c7ea851d 2806 if [ X"$DONORMALIZE" = "Xy" ]; then
535944df 2807 log error "Unix pipes not compatible with normalizer"
d5200e72 2808 # FIXME # Do we need to exit or shall we just disable the mode?
2809 exit 1
2810 fi
0709e644 2811 if [ X"$BATCHNORM" = "Xy" ]; then
535944df 2812 log error "Unix pipes not compatible with BATCHNORM encoding"
0709e644 2813 exit 1
2814 fi
2815 if [ X"$NOGAP" = "Xy" ]; then
535944df 2816 log error "Unix pipes not compatible with NOGAP encoding"
0709e644 2817 exit 1
2818 fi
c7ea851d 2819 if [ X"$DOENCODE" = "Xn" ]; then
535944df 2820 vecho warning "Disabling Unix pipes since we are not encoding!"
d5200e72 2821 USEPIPES=n
2822 fi
c7ea851d 2823 if [ X"$LOWDISK" = "Xy" ]; then
535944df 2824 log error "Unix pipes not compatible with lowdisk algorithm"
c7ea851d 2825 exit 1
2826 fi
d5200e72 2827fi
2828
0709e644 2829# LOWDISK pre-tests, before we get into more problematic stuff
2830# Not compatible with anything that needs all the files in the hard disc:
2831# - BATCHNORM
2832# - NOGAP lame mode
2833if [ X"$LOWDISK" = "Xy" ]; then
2834 if [ X"$BATCHNORM" = "Xy" ]; then
535944df 2835 log error "Unix pipes not compatible with BATCHNORM encoding"
0709e644 2836 exit 1
2837 fi
2838 if [ X"$NOGAP" = "Xy" ]; then
535944df 2839 log error "Unix pipes not compatible with NOGAP encoding"
0709e644 2840 exit 1
2841 fi
2842fi
2843
535944df 2844# BATCHNORM pre-tests, before we get into serious problems
2845# Not compatible with
2846if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
2847 vecho warning "Disabling BATCHNORM since we are not normalizing!"
2848 BATCHNORM=n
2849fi
2850
9ff5088c 2851# Check the encoding format from the ones available in the system, if nothing has been configured in the system.
2852if [ X"$OUTPUTTYPE" = "X" ]; then
2853 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
2854 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
2855 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
2856 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
2857 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
2858 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
2859 break
2860 fi
2861 done
2862 if [ X"$OUTPUTTYPE" = "X" ]; then
535944df 2863 log error "no encoder found in the PATH"
2864 log error "hints: are all dependencies installed? has the \$PATH been modified?"
9ff5088c 2865 exit 1
2866 fi
2867fi
2868
c9c2ca27 2869# Decide which CDROM reader we're gonna use
2870case "$CDROMREADERSYNTAX" in
2871 cdparanoia|debug)
2872 CDROMREADER="$CDPARANOIA"
2873 CDROMREADEROPTS="$CDPARANOIAOPTS"
2874 ;;
2875 cdda2wav)
2876 CDROMREADER="$CDDA2WAV"
2877 CDROMREADEROPTS="$CDDA2WAVOPTS"
2878 ;;
2879 dagrab)
2880 CDROMREADER="$DAGRAB"
2881 CDROMREADEROPTS="$DAGRABOPTS"
2882 ;;
2883 cddafs)
2884 CDROMREADER="$CDDAFS"
2885 CDROMREADEROPTS="$CDDAFSOPTS"
2886 ;;
1b94d6b7 2887 flac)
2888 CDROMREADER="$FLAC"
2889 CDROMREADEROPTS="$FLACOPTS"
2890 ;;
c9c2ca27 2891esac
2892
2893# There's only one normalize...
2894case "$NORMALIZERSYNTAX" in
2895 default|normalize)
2896 NORMALIZER="$NORMALIZE"
2897 NORMALIZEROPTS="$NORMALIZEOPTS"
2898 ;;
2899esac
2900
24f444d7 2901# Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
b82e2042 2902if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
cd4b63fa 2903 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
24f444d7 2904 case "$OUTPUT" in
b82e2042 2905 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
24f444d7 2906 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2907 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2908 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
2909 mpc:*) MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
dba06003 2910 m4a:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
24f444d7 2911 esac
2912 done
cd4b63fa 2913 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
24f444d7 2914 TEMPOUTPUT=$( echo "$OUTPUT" | cut -d: -f1 )
2915 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
2916 done
2917 OUTPUTTYPE="$TEMPOUTPUTTYPE"
24f444d7 2918fi
2919
dba06003 2920# If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
2921# for flacs and speexenc for speex and mppenc for mpps and faac for m4as
c9c2ca27 2922
2923# Getting ready for multiple output changes
2924for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
2925do
2926 case $OUTPUT in
b82e2042 2927 vorbis|ogg)
2928 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
2929 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
6fba8f12 2930 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
b82e2042 2931 OGGOUTPUTCONTAINER=ogg
2932 ;;
2933 mp3)
2934 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
2935 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
6fba8f12 2936 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
b82e2042 2937 ;;
2938 flac)
2939 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
2940 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
6fba8f12 2941 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
b82e2042 2942 ;;
2943 spx)
2944 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
cb414c1e 2945# [ "$DOREPLAYGAIN" = "y" ] &&
b82e2042 2946 ;;
2947 mpc)
2948 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
cb414c1e 2949 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN=y
b82e2042 2950 ;;
dba06003 2951 m4a)
2952 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
2953 ;;
b69a8bb4 2954 wav)
389564c2 2955 if [ "$KEEPWAVS" = "y" ]; then
2956 vecho "Unsetting the KEEPWAVS option, since the resulting wav files were requested..."
2957 fi
b69a8bb4 2958 KEEPWAVS=move
2959 ;;
535944df 2960 *) log error "Invalid OUTPUTTYPE defined"
24f444d7 2961 exit 1
c9c2ca27 2962 ;;
c9c2ca27 2963 esac
2964done
2965
2966# decide which encoder
2967case "$MP3ENCODERSYNTAX" in
2968 lame)
24f444d7 2969 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
c9c2ca27 2970 MP3ENCODER="$LAME"
2971 ;;
0709e644 2972 toolame)
2973 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
2974 MP3ENCODER="$TOOLAME"
2975 ;;
c9c2ca27 2976 gogo)
24f444d7 2977 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
c9c2ca27 2978 MP3ENCODER="$GOGO"
2979 ;;
2980 bladeenc)
24f444d7 2981 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
c9c2ca27 2982 MP3ENCODER="$BLADEENC"
2983 ;;
2984 l3enc)
24f444d7 2985 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
c9c2ca27 2986 MP3ENCODER="$L3ENC"
2987 ;;
2988 xingmp3enc)
24f444d7 2989 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
c9c2ca27 2990 MP3ENCODER="$XINGMP3ENC"
2991 ;;
2992 mp3enc)
24f444d7 2993 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
c9c2ca27 2994 MP3ENCODER="$MP3ENC"
2995 ;;
2996esac
2997case "$OGGENCODERSYNTAX" in
2998 vorbize)
24f444d7 2999 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
c9c2ca27 3000 OGGENCODER="$VORBIZE"
3001 ;;
3002 oggenc)
24f444d7 3003 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
c9c2ca27 3004 OGGENCODER="$OGGENC"
3005 ;;
3006esac
3007case "$FLACENCODERSYNTAX" in
3008 flac)
24f444d7 3009 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
c81531ac 3010 FLACENCODER="$FLAC"
b82e2042 3011 # FLAC streams can be encapsulated on a Ogg transport layer
c81531ac 3012 if echo "$FLACENCODEROPTS" | egrep -q -- "(^| )--ogg($| )" ;then
535944df 3013 log error "FLAC on an Ogg container is not yet supported"
3014 log error "due to problem with adding comments to such files"
b82e2042 3015 exit 1
3016 FLACOUTPUTCONTAINER=ogg
3017 else
3018 FLACOUTPUTCONTAINER=flac
c81531ac 3019 fi
c9c2ca27 3020 ;;
3021esac
3022case "$SPEEXENCODERSYNTAX" in
3023 speexenc)
24f444d7 3024 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
c9c2ca27 3025 SPEEXENCODER="$SPEEXENC"
3026 ;;
3027esac
99d009fa 3028case "$MPPENCODERSYNTAX" in
3029 mppenc)
24f444d7 3030 MPPENCODEROPTS="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
99d009fa 3031 MPPENCODER="$MPPENC"
3032 ;;
3033esac
dba06003 3034case "$AACENCODERSYNTAX" in
3035 faac)
3036 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
3037 AACENCODER="$AACENC"
3038 ;;
3039esac
c9c2ca27 3040# and which tagger
3041
3042if [ "$ID3TAGV" = "1" ]; then
3043 TAGGER="$ID3"
3044 TAGGEROPTS="$ID3OPTS"
3045else
3046 TAGGER="$ID3V2"
3047 TAGGEROPTS="$ID3V2OPTS"
3048fi
3049
0709e644 3050# Specific for NOGAP is the use of lame. Another encoder fails...
3051if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
535944df 3052 log warning "the NOGAP option is specific of lame. Deactivating..."
0709e644 3053 NOGAP=n
3054fi
3055
411ef0b0 3056# Options for mkcue
3057case "$CUEREADERSYNTAX" in
3058 default|mkcue)
3059 CUEREADEROPTS="${CDROM}"
3060 CUEREADER="$MKCUE"
3061 ;;
3062esac
3063
b82e2042 3064# Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
3065if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
535944df 3066 log error "FLAC on an Ogg container is not yet supported"
3067 log error "due to problem with adding comments to such files"
b82e2042 3068 exit 1
3069 OGGOUTPUTCONTAINER=ogg.ogg
3070 FLACOUTPUTCONTAINER=flac.ogg
535944df 3071 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
b82e2042 3072fi
3073
c9c2ca27 3074# Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
3075
3076if [ "$ENCNICE" ]; then
3077 ENCNICE="-n $ENCNICE"
3078fi
3079if [ "$READNICE" ]; then
3080 READNICE="-n $READNICE"
3081fi
3082if [ "$DISTMP3NICE" ]; then
3083 DISTMP3NICE="-n $DISTMP3NICE"
3084fi
3085
3086# Don't check for stuff if it's not needed
bef9c2d8 3087if [ "$REMOTEHOSTS" ]; then
3088 NEEDDISTMP3=y
3089fi
3090if [ "$DONORMALIZE" = "y" ]; then
3091 NEEDNORMALIZER=y
3092fi
3093if [ "$EJECTCD" = "y" ]; then
3094 NEEDEJECT=y
3095fi
3096if [ ! "$CDDBAVAIL" = "n" ] && [ "$DOCDDB" = "y" ]; then
dba06003 3097 if [ "$CDDBMETHOD" = "cddb" ]; then
3098 NEEDHTTPGET=y
3099 elif [ "$CDDBMETHOD" = "musicbrainz" ]; then
3100 :
3101 fi
bef9c2d8 3102fi
411ef0b0 3103if [ "$MAKECUEFILE" = "y" ]; then
3104 NEEDCUEREADER=y
bef9c2d8 3105fi
c9c2ca27 3106
3107if [ X"$CDSPEEDVALUE" != "X" ]; then
3108 case "$CDROMREADERSYNTAX" in
3109 cdparanoia|debug) CDROMREADEROPTS="$CDPARANOIAOPTS -S $CDSPEEDVALUE" ;;
1b94d6b7 3110 ### FIXME ### translate "cue2discid" from python to bash
3111 flac) NEEDMETAFLAC=y ; NEEDCUE2DISCID=y ;;
c9c2ca27 3112 *) NEEDCDSPEED=y ;;
3113 esac
3114fi
3115
c1bbe6c3 3116###USEPIPESSUPPORT###
3117
c7ea851d 3118# Rippers with USEPIPE support
3119# FIXME # Include here all the rippers we can figure out support pipes
a2881eba 3120PIPERIPPER_cdparanoia="-"
c1bbe6c3 3121PIPERIPPER_debug="-"
a2881eba 3122PIPERIPPER_flac="-c "
c7ea851d 3123
3124# Encoders with USEPIPE support
3125# FIXME # Include here all the encoders we can figure out support pipes
3126PIPE_lame="-"
5a433968 3127PIPE_bladeenc="-"
c7ea851d 3128PIPE_oggenc="-"
a2881eba 3129PIPE_flac="-"
c7ea851d 3130
3131# Figure out if we can use pipes with the ripper/encoder combination
3132# exit otherwise
3133if [ "$USEPIPES" = "y" ]; then
a2881eba 3134 PIPERIPPERSVARCHECK="PIPERIPPER_${CDROMREADERSYNTAX}"
c7ea851d 3135 case "$OUTPUT" in
3136 mp3)
3137 PIPEENCODERSVARCHECK="PIPE_$MP3ENCODERSYNTAX" ;;
b82e2042 3138 vorbis|ogg)
c7ea851d 3139 PIPEENCODERSVARCHECK="PIPE_$OGGENCODERSYNTAX" ;;
3140 flac)
3416c114 3141 PIPEENCODERSVARCHECK="PIPE_$FLACENCODERSYNTAX" ;;
c7ea851d 3142 spx)
6c124acf 3143 PIPEENCODERSVARCHECK="PIPE_$SPEEXENCODER" ;;
c7ea851d 3144 mpc)
3145 PIPEENCODERSVARCHECK="PIPE_$MPPENCODER" ;;
3146 esac
c1bbe6c3 3147 decho "PIPERIPPERSVARCHECK: $( eval echo "\$$PIPERIPPERSVARCHECK" )"
3148 if [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "$" ] || \
3149 [ "$( eval echo "\$$PIPERIPPERSVARCHECK" )" = "" ] ; then
535944df 3150 log error "no support for pipes with given ripper"
3151 log error "read the USEPIPES file from the source tarball to get help."
3152 log error "On a Debian system, it is under /usr/share/doc/abcde/USEPIPES.gz"
c7ea851d 3153 exit 1;
3154 fi
c1bbe6c3 3155 decho "PIPEENCODERSVARCHECK: $( eval echo "\$$PIPEENCODERSVARCHECK" )"
3156 if [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "$" ] || \
3157 [ "$( eval echo "\$$PIPEENCODERSVARCHECK" )" = "" ] ; then
535944df 3158 log error "no support for pipes with given encoder"
3159 log error "read the USEPIPES file from the source tarball to help"
3160 log error "on a Debian system, read /usr/share/doc/abcde/USEPIPES.gz"
c7ea851d 3161 exit 1;
3162 fi
3163fi
3164
c9c2ca27 3165# Make sure a buncha things exist
3166for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
99d009fa 3167 $OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
3168 ${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
3169 ${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
3170 ${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
12c5d978 3171 ${NEEDDISKTOOL+disktool} ${NEEDCDSPEED+$CDSPEED} \
6fba8f12 3172 ${NEEDVORBISGAIN+$VORBISGAIN} ${NEEDMP3GAIN+$MP3GAIN} \
cb414c1e 3173 ${NEEDMPPGAIN+$MPPGAIN} \
6fba8f12 3174 ${NEEDCUEREADER+$CUEREADER} ${NEEDCUE2DISCID+$CUE2DISCID}
c9c2ca27 3175do
3176 # Cut off the command-line options we just added in
3177 X=$(echo $X | cut -d' ' -f2)
3178 if [ "$(which $X)" = "" ]; then
535944df 3179 log error "$X is not in your path." >&2
c9c2ca27 3180 exit 1
3181 elif [ ! -x $(which $X) ]; then
535944df 3182 log error "$X is not executable." >&2
c9c2ca27 3183 exit 1
3184 fi
3185done
3186
3187CDROMREADER="$CDROMREADER $CDROMREADEROPTS"
3188CDDBTOOL="$CDDBTOOL $CDDBTOOLOPTS"
3189HTTPGET="$HTTPGET $HTTPGETOPTS"
3190
9ff5088c 3191# And last but not least, check if we can diff between files
3192if [ -x $(which $DIFF) ]; then :; else
535944df 3193 vecho warning "Disabling diff since we cannot find it in the \$PATH..."
9ff5088c 3194 DIFF=""
3195fi
3196
12c5d978 3197# Here it used to say:
3198# One thousand lines in, we can start doing stuff with things
5895f404 3199# Well, right now we are at line 2736 ;)
c9c2ca27 3200
3201# Export needed things so they can be read in this subshell
3202export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
3203export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
3204
3205# User-definable function to set some things. Use it for
3206# - closing the CD tray with eject -t
3207# - set the CD speed value with eject -x
3208vecho -n "Executing customizable pre-read function... "
3209
3210pre_read # Execute the user-defined pre-read funtion. Close the CD with it.
3211
3212vecho "done."
3213
dba06003 3214case "$CDDBMETHOD" in
3215 cddb)
3216 do_discid # Get ABCDETEMPDIR created and status file initialized
3217 ;;
3218 musicbrainz)
3219 do_musicbrainz
3220 ;;
3221esac
c9c2ca27 3222
3223if [ "$DOCDDB" = "y" ]; then
3224 if [ $CDDBUSELOCAL = "y" ]; then
3225 do_localcddb
3226 fi
b7f1cc84 3227 if checkstatus cddb-choice > /dev/null; then
3228 :
3229 else
3230 if [ ! "$CDDBLOCALSUCCESS" = "y" ] ; then
dba06003 3231 case "$CDDBMETHOD" in
3232 cddb)
3233 do_cddbstat
3234 do_cddbquery
3235 do_cddbread
3236 ;;
3237 musicbrainz)
3238 do_musicbrainz
3239 ;;
3240 esac
b7f1cc84 3241 fi
c9c2ca27 3242 fi
3243 do_cddbedit
3244
fe4d186c 3245 eval "$($CDDBTOOL parse "$CDDBDATA")"
c9c2ca27 3246fi
3247
3248# Before reading tracks, we set the speed of the device
3249
3250if [ X"$CDSPEEDVALUE" != "X" ]; then
3251 case "$CDROMREADERSYNTAX" in
1b94d6b7 3252 cdparanoia|debug) ;;
3253 flac) ;;
c9c2ca27 3254 *) do_cdspeed ;;
3255 esac
3256fi
3257
bef9c2d8 3258# Define the first and last track, since we might need them later in several places
3259FIRSTTRACK=$( get_first $TRACKQUEUE )
3260LASTTRACK=$( get_last $TRACKQUEUE )
3261
3262if [ -f "$ABCDETEMPDIR/status" ] && [ X"$ERASEENCODEDSTATUS" = "Xy" ]; then
3263 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
3264 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
3265 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
3266fi
3267
c9c2ca27 3268# Create playlist if needed (backgroundable) and start reading in tracks
3269
3270(
99d009fa 3271
d5200e72 3272if [ ! "$ONETRACK" = "y" ]; then
c9c2ca27 3273 if [ "$DOPLAYLIST" = "y" ]; then
3274 echo Creating playlist... >&2
3275 do_playlist
3276 fi
3277fi
3278
3279# For the lowdisk option, only one program is running at once so the encoder
3280# can be unsilenced right away.
3281if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
3282 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3283fi
3284
3285if [ "$ONETRACK" = "y" ]; then
c9c2ca27 3286 TRACKS="$FIRSTTRACK"
c9c2ca27 3287 if checkstatus readtrack-$FIRSTTRACK; then :; else
a2881eba 3288 if [ "$USEPIPES" = "y" ]; then
3289 do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
3290 else
3291 do_cdread onetrack $FIRSTTRACK $LASTTRACK
3292 fi
c9c2ca27 3293 fi
3294else
3295 for UTRACKNUM in $TRACKQUEUE
3296 do
3297 if [ "$DOREAD" = "y" ]; then
49c04b11 3298 if [ "$USEPIPES" = "y" ]; then
3299 if checkstatus readencodetrack-$UTRACKNUM; then :; else
69ff9575 3300 # Read, pipe, shut up!
3301 do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
49c04b11 3302 fi
3303 else
3304 if checkstatus readtrack-$UTRACKNUM; then :; else
3305 do_cdread $UTRACKNUM
3306 fi
c9c2ca27 3307 if [ "$?" != "0" ]; then
3308 # CD read failed - don't give the goahead to
3309 # the encoder
3310 echo NO
3311 exit
3312 fi
3313 fi
3314 fi
0709e644 3315 if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ]; then
c9c2ca27 3316 :
3317 else
5ddcb883 3318 # If we are not reading, set the encode output to loud already, so
3319 # that we can see the output of the first track.
3320 if [ "$MAXPROCS" = "1" ] && [ ! "$DOREAD" = "y" ]; then
3321 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3322 fi
c9c2ca27 3323 echo NEXTTRACK # Get the encoder machine churning again
3324 if [ "$DOREAD" = "y" ]; then
3325 if [ "$LOWDISK" = "y" ] && [ "$DOENCODE" = "y" ]; then
3326 until checkstatus encodetrack-$UTRACKNUM
3327 do
3328 if checkerrors encodetrack-$UTRACKNUM; then
3329 break
3330 fi
3331 sleep 2
3332 done
3333 fi
3334 fi
3335 fi
3336 done
3337fi
3338
3339# Now that we're done the encoding can be loud again -
3340# if we're not using SMP.
3341if [ "$MAXPROCS" = "1" ]; then
3342 echo "encode-output=loud" >> "$ABCDETEMPDIR/status"
3343fi
3344
3345# All tracks read, start encoding.
0709e644 3346if [ "$NOGAP" = "y" ] || [ "$BATCHNORM" = "y" ] || [ "$ONETRACK" = "y" ]; then
c9c2ca27 3347 echo NEXTTRACK
3348fi
3349
65f3ebb1 3350# Execute the user-defined post_read funtion before ejecting CD
3351post_read
3352
c9c2ca27 3353# We are now finished with the cdrom - it can be safely ejected. Note that
3354# abcde will not have completed yet.
3355if [ "$EJECTCD" = "y" ] && [ -x $(which $EJECT) ]; then
3356 # We check if the disk we are processing is actually the disk inside the
3357 # CD tray. If not, we do not eject the CD, since it might be so that the
3358 # user ejected it manually.
3359 #CURRENTTRACKINFO=$($CDDISCID $CDROM)
3360 #if if [ "$?" != "1" ] && [ "$CURRENTTRACKINFO" = "$TRACKINFO" ] ; then
3361 # More FreeBSD bits.
3362 if [ X"$(uname)" = X"FreeBSD" ] ; then
3363 # FreeBSD eject uses the EJECT environment variable to name the CDROM
3364 # but in this script EJECT is in the envionment and names the program
3365 eject=$EJECT
3366 unset EJECT
3367 # The FreeBSD eject needs "adc0" not "/dev/adc0c"
3368 cd="$(echo $CDROM | sed -e 's=.*/==;s=[a-h]$==;')"
3369 $eject $EJECTOPTS $cd
3370 elif [ X"$(uname)" = X"Darwin" ] ; then
3371 disktool -e ${CDROM#/dev/} 0
3372 else
3373 $EJECT $EJECTOPTS $CDROM
3374 fi
3375 #fi
3376fi
3377
3378) | (
3379
99d009fa 3380## Do we need to pre-process
3381#if [ x"$PREPROCESS" = "x" ] ; then
3382# cat
3383#else
3384# for PRETRACKNUM in $TRACKQUEUE
3385# do
3386# read GOAHEAD
3387# if [ "$GOAHEAD" = "NO" ]; then break; fi
3388# PREPROCEED=
3389# until [ $PREPROCEED ]
3390# do
3391# if checkstatus readtrack-$PRETRACKNUM; then PREPROCEED=y; break; fi
3392# # all locations are working, wait and try again later
3393# if [ ! $PREPROCEED ]; then sleep 3; fi
3394# done
3395# ( do_preprocess $PRETRACKNUM
3396# echo "NEXTTRACK"
3397# ) &
3398# done
3399#fi
3400#
3401#) | (
3402
0709e644 3403# In BATCHNORM and/or NOGAP modes, we want all tracks to be read first.
3404#BACK
3405if [ "$BATCHNORM" = "y" ] || [ "$NOGAP" = "y" ]; then
c9c2ca27 3406 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
3407 if [ "$GOAHEAD" = "NO" ]; then break; fi
3408 for LASTTRACK in $TRACKQUEUE; do :; done
3409 if checkstatus readtrack-$LASTTRACK; then
0709e644 3410 if [ "$DONORMALIZE" = "y" ] && [ "$BATCHNORM" = "y" ]; then
c9c2ca27 3411 if checkstatus normalizetrack-$LASTTRACK; then :; else do_batch_normalize; fi
0709e644 3412 if checkerrors batch-normalize; then exit 1; fi
c9c2ca27 3413 fi
0709e644 3414 if [ "$DOENCODE" = "y" ] && [ "$NOGAP" = "y" ]; then
3415 if [ "$DONORMALIZE" = "y" ]; then
3416 for UTRACKNUM in $TRACKQUEUE
3417 do
3418 if checkstatus readtrack-$UTRACKNUM; then
3419 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
3420 fi
3421 done
0709e644 3422 fi
535944df 3423 if checkstatus encodetrack-$LASTTRACK; then :; else do_nogap_encode; fi
3424 if checkerrors nogap-encode; then exit 1; fi
c9c2ca27 3425 fi
3426 fi
3427fi
3428
3429# If we are using ONETRACK, we can proceed with the normal encoding using just the $FIRSTTRACK as TRACKQUEUE
3430if [ "$ONETRACK" = "y" ] ; then
bef9c2d8 3431 TRACKQUEUE="$FIRSTTRACK"
c9c2ca27 3432 TRACKS="$FIRSTTRACK"
3433fi
3434
3435# Do the encoding, including parallelization of remote encoding
3436# Figure out where each track is going to be encoded
3437ENCODELOCATIONS="$(echo $REMOTEHOSTS | tr , ' ')"
3438if [ "$MAXPROCS" != "0" ]; then
3439 for NUM in $(f_seq_row 1 "$MAXPROCS")
3440 do
3441 ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
3442 done
3443fi
3444# Strip whitespace
3445ENCODELOCATIONS=$(echo $ENCODELOCATIONS)
3446for UTRACKNUM in $TRACKQUEUE
3447do
3448 # Wait for our cue
3449 read GOAHEAD # For blocking - will contain either "NO" or "NEXTTRACK"
3450 if [ "$GOAHEAD" = "NO" ]; then break; fi
3451 # find out where this track is to be encoded
49c04b11 3452 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
c9c2ca27 3453 # Make sure we have a place to encode this, if not, exit stage right
3454 if [ -z "$ENCODELOCATIONS" ]; then
3455 continue
3456 fi
3457 PROCEED=
3458 until [ $PROCEED ]
3459 do
3460 for LOCATION in $ENCODELOCATIONS
3461 do
3462 PREVIOUSTRACK="$(checkstatus encodetracklocation-$LOCATION)"
3463 # check first if a track has ever been assigned to this location
3464 if [ -z "$PREVIOUSTRACK" ]; then PROCEED=y; break; fi
3465 # If it errored out, rebuild $ENCODELOCATIONS without this location in it
3466 if checkerrors encodetrack-$PREVIOUSTRACK; then
3467 for TEMPLOCATION in $ENCODELOCATIONS
3468 do
3469 if [ "$TEMPLOCATION" != "$LOCATION" ]; then
3470 TEMPENCODELOCATIONS="$TEMPENCODELOCATIONS $TEMPLOCATION"
3471 fi
3472 done
3473 ENCODELOCATIONS=$(echo $TEMPENCODELOCATIONS)
3474 ABORT=y
3475 PROCEED=y
3476 break
3477 fi
3478 # We're still here, this location must have been previously assigned,
3479 # and last completed without error - check if it's done with the
3480 # previous track yet
3481 if checkstatus encodetrack-$PREVIOUSTRACK; then PROCEED=y; break; fi
3482 done
3483 # all locations are working, wait and try again later
3484 if [ ! $PROCEED ]; then sleep 3; fi
3485 done
3486 # Record the location we're about to encode the next track at
3487 echo "encodetracklocation-$LOCATION=$UTRACKNUM" >> "$ABCDETEMPDIR/status"
3488 fi
3489 # Don't proceed with the rest of the loop if we can't encode
3490 if [ "$ABORT" ]; then continue; fi
3491 # Set TRACKNUM, TRACKNAME
3492 if [ -e "$CDDBDATA" ]; then
3493 if [ "$ONETRACK" = "y" ]; then
3494 TRACKNAME="$DALBUM"
3495 TRACKNUM="$FIRSTTRACK"
3496 splitvarious
3497 else
c9c2ca27 3498 TRACKNUM=$UTRACKNUM
eb1474fe 3499 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
c0fc2e81 3500 do_getcddbinfo TRACKNAME
c9c2ca27 3501 splitvarious
3502 fi
3503 fi
3504 # You can't encode a file which needs to be normalized before finishing
3505 # You can't tag a file before it's finished encoding -
3506 # thus all of this is backgrounded together
3507 (
3508 if [ "$DONORMALIZE" = "y" ]; then
3509 if checkstatus readtrack-$UTRACKNUM; then
3510 if checkstatus normalizetrack-$UTRACKNUM; then :; else do_normalize $UTRACKNUM; fi
3511 fi
3512 fi
c7ea851d 3513 if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
c9c2ca27 3514 if checkstatus readtrack-$UTRACKNUM; then
3515 #if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION; fi
3516 if [ "$DONORMALIZE" = "y" ]; then
3517 if checkstatus normalizetrack-$UTRACKNUM; then
3518 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
3519 fi
3520 else
3521 if checkstatus encodetrack-$UTRACKNUM; then :; else do_encode $UTRACKNUM $LOCATION $OUTPUT; fi
3522 fi
3523 fi
3524 fi
efc6de2f 3525 if [ "$DOTAG" = "y" ]; then
3526 if checkstatus encodetrack-$UTRACKNUM; then
c9c2ca27 3527 if checkstatus tagtrack-$UTRACKNUM; then :; else do_tag $UTRACKNUM; fi
3528 fi
b82e2042 3529 # Lets tag the cue file
3530 if checkstatus cleancuefile >/dev/null; then :; else
3531 if checkstatus cuefile >/dev/null ; then
3532 do_cleancue
3533 fi
3534 fi
c9c2ca27 3535 fi
3536 if [ "$DOMOVE" = "y" ]; then
3537 if checkstatus tagtrack-$UTRACKNUM; then
3538 if checkstatus movetrack-$UTRACKNUM; then :; else do_move $UTRACKNUM; fi
3539 fi
3540 fi
3541 ) &
3542done
79c8f4d0 3543
79c8f4d0 3544
c9c2ca27 3545# Go through it again and make sure there's no distmp3 stragglers, otherwise
3546# we'll delete the files they're working on
c7ea851d 3547## FIXME ## Check also for files which are encoded using PIPEs.
3548if [ "$DOENCODE" = "y" -a "$USEPIPES" != "y" ]; then
c9c2ca27 3549 PROCEED=
3550 until [ $PROCEED ]
3551 do
3552 PROCEED=y
3553 for LOCATION in $ENCODELOCATIONS
3554 do
3555 CHECKTRACK="$(checkstatus encodetracklocation-$LOCATION)"
3556 # "How can he give us a status update, if he's DEAD?"
3557 if checkstatus encodetrack-$CHECKTRACK; then
3558 continue
3559 fi
3560 # Nothing to see here please go quietly back to your homes
3561 if [ -z "$CHECKTRACK" ]; then continue; fi
3562 # You're still here? Maybe there is something...
3563 if checkstatus encodetrack-$CHECKTRACK; then :; else PROCEED= ; break; fi
3564 done
3565 # hold up
3566 if [ ! $PROCEED ]; then sleep 5; fi
3567 done
3568fi
3569# If the above didn't catch the stragglers, this will
3570wait
6fba8f12 3571if [ "$DOREPLAYGAIN" = "y" ]; then
c0fc2e81 3572 do_replaygain
3573fi
3a74cce2 3574
c9c2ca27 3575# Check to see if run_command logged any errors
3576if [ -f "$ABCDETEMPDIR/errors" ]; then
535944df 3577 log error "The following commands failed to run:"
c9c2ca27 3578 cat "$ABCDETEMPDIR/errors"
3579 # Don't clean up
3580 DOCLEAN=n
3581fi
3582if [ "$KEEPWAVS" = "y" ];then
3583 # Don't clean up
3584 DOCLEAN=n
3585fi
75c2c424 3586# Check if we have moved all the formats we had previously encoded, if we are not using the FORCE.
81d2dc20 3587if [ "$DOCLEAN" = "y" ] && [ ! "$FORCE" = "y" ]; then
cb801544 3588 ENCODED_FORMATS=$(egrep "^encodetrack-(.{3,6})-(.{1,2})$" "$ABCDETEMPDIR/status" | cut -d"-" -f2 | sort -u | tr '\n' '|')
81d2dc20 3589 MOVED_FORMATS=$(egrep "^movetrack-output-(.{3,6})$" "$ABCDETEMPDIR/status" | cut -d"-" -f3 | sort -u | tr '\n' '|')
75c2c424 3590 if [ "$ENCODED_FORMATS" != "$MOVED_FORMATS" ]; then
70da1809 3591 log warning "The encoded formats does not match with the moved ones"
3592 log warning "Formats encoded: $( echo $ENCODED_FORMATS | tr "|" " " )"
3593 log warning "Formats moved: $( echo $MOVED_FORMATS | tr "|" " " )"
3594 log warning "Use \"abcde -a clean -f -C $DISCID\" to force the removal of the remaining data."
81d2dc20 3595 DOCLEAN=n
cb801544 3596 fi
75c2c424 3597fi
c9c2ca27 3598if [ "$DOCLEAN" = "y" ]; then
3599 # Wipe all the evidence
3600 # Gimme gimme gimme some more time!
3601 sleep 5
3602 rm -rf "$ABCDETEMPDIR"
3603 echo "Finished."
3604else
3605 echo "Finished. Not cleaning $ABCDETEMPDIR."
3606fi
3607)
3608exit 0
d5200e72 3609
3610# b:is_bash
3611# vim:tabstop=4