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