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