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