2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
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.
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
11 # Copyright for this work is to expire January 1, 2010, after which it
12 # shall be public domain.
16 VERSION='2.3.99-$Revision$'
20 echo "This is abcde v$VERSION."
21 echo "Usage: abcde [options] [tracks]"
23 echo "-1 Encode the whole CD in a single file"
24 echo "-a <action1[,action2]...>"
25 echo " Actions to perform:"
26 echo " cddb,read,normalize,encode,tag,move,replaygain,playlist,clean"
27 #echo "-A Experimental actions (retag, transcode)"
28 echo "-b Enable batch normalization"
29 #echo "-B Disable batch replaygain (do file by file)"
31 echo " Specify a configuration file (overrides system and user config files)"
33 echo " Specify discid to resume from (only needed if you no longer have the cd)"
35 echo " Specify CDROM device to grab (flac uses a single-track flac file)"
36 echo "-D Debugging mode (equivalent to sh -x abcde)"
37 echo "-e Erase encoded track information from status file"
38 echo "-f Force operations that otherwise are considered harmful. Read \"man abcde\""
39 echo "-g Use \"lame --nogap\" for MP3 encoding. Disables low disk and pipes flags"
40 echo "-h This help information"
41 #echo "-i Tag files while encoding, when possible (local only) -NWY-"
42 echo "-j <#> Number of encoder processes to run at once (localhost)"
43 echo "-k Keep the wav tracks for later use"
44 echo "-l Use low disk space algorithm"
45 echo "-L Use local CDDB storage directory"
46 echo "-n No lookup. Don't query CDDB, just create and use template"
47 echo "-N Noninteractive. Never prompt for anything"
48 echo "-m Modify playlist to include CRLF endings, to comply with some players"
49 echo "-M Create a CUE file"
50 echo "-o <type1[,type2]...>"
51 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
52 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
53 echo "-P Use UNIX pipes to read+encode without wav files"
54 echo "-r <host1[,host2]...>"
55 echo " Also encode on these remote hosts"
56 echo "-R Use local CDDB in recursive mode"
58 echo " Show dielfs from the CDDB info (year,genre)"
59 echo "-S <#> Set the CD speed"
60 echo "-t <#> Start the track numbering at a given number"
61 echo "-T <#> Same as -t but modifies tag numbering"
62 echo "-u Use UNICODE (UTF8) tags and comments"
63 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
64 echo "-v Show version number and exit"
65 echo "-V Be a bit more verbose about what is happening behind the scenes"
66 echo "-x Eject CD after all tracks are read"
68 echo " Add a comment to the CD tracks"
69 echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
70 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
72 echo "Tracks is a space-delimited list of tracks to grab."
73 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
75 #echo "Double hyphens are used to concatenate tracks"
80 echo "$@" >> "$ABCDETEMPDIR/status"
83 # log [level] [message]
85 # log outputs the right message in a common format
91 error) echo "[ERROR] abcde: $@" >&2 ;;
92 warning) echo "[WARNING] $@" >&2 ;;
93 info) echo "[INFO] $@" ;;
97 # Funtions to replace the need of seq, which is too distribution dependant.
101 while [ $i -ne `expr $2 + 1` ]
111 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
112 while [ $i -ne `expr $2 + 1` ]
119 log error "syntax error while processing track numbers"
124 # Functions to replace the need of awk {print $1} and {print $NF}
127 if [ X"$1" = "X" ]; then
128 for first in `cat`; do
139 if [ X"$1" = "X" ]; then
140 for stdin in `cat`; do
144 for last in $@ ; do :; done
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 "".
155 # Take the last line in the status file if there's multiple matches
157 BLURB=$(egrep $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
159 if [ -z "$BLURB" ]; then
164 # See if there's a = in it
165 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
166 echo "$(echo $BLURB | cut -f2- -d=)"
172 # checkwarnings [blurb]
173 # Returns "0" if the blurb was found (meaning there was an warning),
174 # returns 1 if it wasn't (yes this is a little backwards).
175 # Does not print the blurb on stdout.
176 # Otherwise, returns "".
179 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
182 # Take the last line in the status file if there's multiple matches
184 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
186 if [ -z "$BLURB" ]; then
187 # negative, we did not have a negative...
190 # affirmative, we had a negative...
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 "".
202 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
205 # Take the last line in the status file if there's multiple matches
207 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
209 if [ -z "$BLURB" ]; then
210 # negative, we did not have a negative...
213 # affirmative, we had a negative...
219 # Finds the right pager in the system to display a file
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
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"
238 # No bananas, just cat the thing
243 # run_command [blurb] [command...]
244 # Runs a command, silently if necessary, and updates the status file
249 # See if this is supposed to be silent
250 if [ "$(checkstatus encode-output)" = "loud" ]; then
254 # Special case for SMP, since
255 # encoder output is never displayed, don't mute echos
256 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
265 normalize|normalize-audio)
266 if [ "$RETURN" = "2" ]; then
267 # File was already normalized.
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
280 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
281 return $RETURN # Do not pass go, do not update the status file
283 if [ "$BLURB" ]; then
284 echo $BLURB >> "$ABCDETEMPDIR/status"
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
291 # Function to determine if a word contains a slash.
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
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 /
317 /*) ;; # No processing is needed for absolute paths
319 # Loop through common prefixes, ignoring them.
320 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
322 FR="$(echo "$FR" | cut -d/ -f2-)"
323 TO="$(echo "$TO" | cut -d/ -f2-)"
325 # Loop through directory portions left in FR, adding appropriate ../s.
328 FR="$(echo "$FR" | cut -d/ -f2-)"
339 if [ ! "$@" = "" ]; then
340 # Cut off any command-line option we added in
341 X=$(echo $@ | cut -d' ' -f2)
342 if [ "$(which $X)" = "" ]; then
344 elif [ ! -x $(which $X) ]; then
353 if [ ! "$@" = "" ]; then
354 # Cut off any command-line option we added in
355 X=$(echo $@ | cut -d' ' -f2)
356 if [ "$(which $X)" = "" ]; then
357 log error "$X is not in your path." >&2
358 log info "Define the full path to the executable if it exists on your system." >&2
360 elif [ ! -x "$(which $X)" ]; then
361 log error "$X is not executable." >&2
367 # diffentries <filename> <max_value> <entry1>,<entry2>
368 # max_value: the range of entries goes from 1 to <max_value>
373 local CDDBDIFFCHOICES=$1
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
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"
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"
393 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
397 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
402 # Finds an specific field from cddbinfo
407 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
410 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
416 # Get the track number we are going to use for different actions
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 ))
424 TRACKNUM=${UTRACKNUM}
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
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
442 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
445 if [ X"$LEADOUT" = "X" ]; then
446 log warning "Error trying to calculate disc ids without lead-out information."
450 # default to a two second lead-in
452 LEADIN=${LEADIN:=150}
454 # number of cdframes per second
457 # reset cddb checksum for cddb disc-id calululation
461 for OFFSET in $(echo $OFFSETS)
463 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
465 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
466 while [ $OFFSETTIME -gt 0 ]; do
467 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
468 OFFSETTIME=$(($OFFSETTIME / 10))
473 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
475 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
476 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
478 printf -v HEXSUM "%08lx" $(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
479 TRACKINFO="${HEXSUM} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
484 if checkstatus replaygain; then :; else
485 run_command "" echo "Adding replygain information..."
486 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
490 OUTPUT=$OGGOUTPUTCONTAINER
493 OUTPUT=$FLACOUTPUTCONTAINER
501 for UTRACKNUM in $TRACKQUEUE
503 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
504 getcddbinfo TRACKNAME
506 TRACKFILE="$(mungefilename "$TRACKNAME")"
507 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
508 ALBUMFILE="$(mungefilename "$DALBUM")"
510 if [ "$ONETRACK" = "y" ]; then
511 if [ "$VARIOUSARTISTS" = "y" ]; then
512 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
514 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
517 if [ "$VARIOUSARTISTS" = "y" ]; then
518 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
520 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
523 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
524 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
528 run_command replaygain-flac $METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
531 run_command replaygain-vorbis $VORBISGAIN --album "${OUTPUTFILES[@]}"
534 run_command replaygain-mp3 $MP3GAIN -a "${OUTPUTFILES[@]}"
537 run_command replaygain-mpc $MPPGAIN --auto "${OUTPUTFILES[@]}"
542 if checkerrors "replaygain-.{3,6}"; then :; else
543 run_command replaygain true
548 # This code splits the a Various Artist track name from one of the following
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)
559 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
562 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
563 case "$VARIOUSARTISTSTYLE" in
565 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
566 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
567 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
570 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
571 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
572 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
575 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
576 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
577 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
580 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
581 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
582 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
585 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
586 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
587 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
590 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
591 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
592 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
595 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
596 TRACKARTIST="Various"
598 TRACKARTIST="$DARTIST"
603 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
607 "classic rock") id=1 ;;
625 "industrial") id=19 ;;
626 "alternative") id=20 ;;
628 "death metal") id=22 ;;
630 "soundtrack") id=24 ;;
631 "euro-techno") id=25 ;;
635 "jazz+funk") id=29 ;;
638 "classical") id=32 ;;
639 "instrumental") id=33 ;;
643 "sound clip") id=37 ;;
646 "alt. rock") id=40 ;;
651 "meditative") id=45 ;;
652 "instrum. pop") id=46 ;;
653 "instrum. rock") id=47 ;;
657 "techno-indust.") id=51 ;;
658 "electronic") id=52 ;;
660 "eurodance") id=54 ;;
662 "southern rock") id=56 ;;
667 "christian rap") id=61 ;;
668 "pop/funk"|"pop / funk") id=62 ;;
670 "native american") id=64 ;;
673 "psychadelic") id=67 ;;
675 "showtunes") id=69 ;;
679 "acid punk") id=73 ;;
680 "acid jazz") id=74 ;;
684 "rock & roll") id=78 ;;
685 "hard rock") id=79 ;;
687 "folk/rock") id=81 ;;
688 "national folk") id=82 ;;
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 ;;
704 "easy listening") id=98 ;;
710 "chamber music") id=104 ;;
712 "symphony") id=106 ;;
713 "booty bass") id=107 ;;
715 "porn groove") id=109 ;;
717 "slow jam") id=111 ;;
721 "folklore") id=115 ;;
723 "power ballad") id=117 ;;
724 "rhythmic soul") id=118 ;;
725 "freestyle") id=119 ;;
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 ;;
733 "drum & bass") id=127 ;;
734 "club-house") id=128 ;;
735 "hardcore") id=129 ;;
739 "negerpunk") id=133 ;;
740 "polsk punk") id=134 ;;
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 ;;
750 "thrash metal") id=144 ;;
753 "synthpop") id=147 ;;
754 "rock/pop"|"rock / pop") id=148 ;;
761 # do_tag [tracknumber]
762 # id3 tags a filename
764 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
765 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
768 COMMENTOUTPUT="$(eval echo ${COMMENT})"
769 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
770 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
771 # If we want to start the tracks with a given number, we need to modify the
772 # TRACKNUM value before evaluation
773 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
776 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
780 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
781 GENREID=$(do_getgenreid "${CDGENRE}")
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" \
791 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
792 "${ENCODING:+--set-encoding=$ENCODING}" \
793 "$ABCDETEMPDIR/track$1.$OUTPUT"
795 # FIXME # Still not activated...
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}" \
800 "$ABCDETEMPDIR/track$1.$OUTPUT"
803 # FIXME # track numbers in mp3 come with 1/10, so we cannot
804 # happily substitute them with $TRACKNUM
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"
813 case "$OGGENCODERSYNTAX" in
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"
820 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
821 echo ARTIST="$TRACKARTIST"
823 echo TITLE="$TRACKNAME"
824 if [ -n "$CDYEAR" ]; then
827 if [ -n "$CDGENRE" ]; then
828 echo GENRE="$CDGENRE"
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";;
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"
844 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
851 echo ARTIST="$TRACKARTIST"
853 echo TITLE="$TRACKNAME"
854 if [ -n "$CDYEAR" ]; then
857 if [ -n "$CDGENRE" ]; then
858 echo GENRE="$CDGENRE"
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";;
868 ) | run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
871 run_command tagtrack-$OUTPUT-$1 true
874 run_command tagtrack-$OUTPUT-$1 true
877 run_command tagtrack-$OUTPUT-$1 true
880 run_command tagtrack-$OUTPUT-$1 true
884 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
885 run_command tagtrack-$1 true
892 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
895 # The commands here don't go through run_command because they're never supposed to be silenced
896 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
897 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
901 case "$MP3ENCODERSYNTAX" in
906 for UTRACKNUM in $TRACKQUEUE
908 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
910 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
912 if [ "$RETURN" != "0" ]; then
913 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
915 for UTRACKNUM in $TRACKQUEUE
917 run_command encodetrack-$OUTPUT-$UTRACKNUM true
918 #run_command encodetrack-$UTRACKNUM true
927 if checkerrors "nogap-encode"; then :; else
928 if [ ! "$KEEPWAVS" = "y" ] ; then
929 if [ ! "$KEEPWAVS" = "move" ] ; then
934 # Other encoders fall through to normal encoding as the tracks
935 # have not been entered in the status file.
938 # do_encode [tracknumber] [hostname]
939 # If no hostname is specified, encode locally
941 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
944 if [ "$USEPIPES" = "y" ]; then
947 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
950 TEMPARG="PIPE_$OGGENCODERSYNTAX"
953 TEMPARG="PIPE_$FLACENCODERSYNTAX"
956 TEMPARG="PIPE_$SPEEXENCODER"
959 TEMPARG="PIPE_$MPPENCODER"
962 TEMPARG="PIPE_$MPPENCODER"
965 IN="$( eval echo "\$$TEMPARG" )"
967 IN="$ABCDETEMPDIR/track$1.wav"
970 case "$MP3ENCODERSYNTAX" in
971 # FIXME # check if mp3enc needs -if for pipes
972 # FIXME # I have not been able to find a working mp3enc binary
986 # We need IN to proceed, if we are not using pipes.
987 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
988 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
992 OUTPUT=$OGGOUTPUTCONTAINER
995 OUTPUT=$FLACOUTPUTCONTAINER
1001 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1002 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1005 if [ X"$USEPIPES" = "Xy" ]; then
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"
1010 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1011 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1017 case "$MP3ENCODERSYNTAX" in
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 ;;
1026 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1033 case "$OGGENCODERSYNTAX" in
1034 vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1035 oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1039 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1046 case "$FLACENCODERSYNTAX" in
1047 flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
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
1058 if [ "$(eval echo ${COMMENT})" != "" ]; then
1061 *) COMMENT="COMMENT=$COMMENT" ;;
1063 COMMENT="--comment \"$COMMENT\""
1065 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1066 if [ ! "$DOTAG" = "y" ]; then
1067 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
1069 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1073 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
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.
1079 $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
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"
1087 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1091 # In case of wav output we need nothing. Just keep the wavs.
1096 # Only remove .wav if the encoding succeeded
1097 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1098 run_command encodetrack-$1 true
1099 if [ ! "$KEEPWAVS" = "y" ] ; then
1100 if [ ! "$KEEPWAVS" = "move" ] ; then
1106 run_command "" echo "HEH! The file we were about to encode disappeared:"
1107 run_command "" echo ">> $IN"
1108 run_command encodetrack-$1 false
1112 # do_preprocess [tracknumber]
1114 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1117 # IN="$ABCDETEMPDIR/track$1.wav"
1118 # # We need IN to proceed.
1119 # if [ -s "$IN" ] ; then
1120 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1122 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1123 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1124 # case "$POSTPROCESSFORMAT" in
1126 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1128 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1130 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1132 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1134 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1137 # # Only remove .wav if the encoding succeeded
1138 # if checkerrors "preprocess-(.{3,4})-$1"; then
1139 # run_command preprocess-$1 false
1141 # run_command preprocess-$1 true
1144 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1145 # echo "HEH! The file we were about to pre-process disappeared:"
1148 # run_command preprocess-$1 false
1153 # do_postprocess [tracknumber]
1155 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1158 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
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
1167 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1169 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1171 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1173 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1175 # # Only remove .wav if the encoding succeeded
1176 # if checkerrors "postprocess-(.{3,4})-$1"; then
1177 # run_command postprocess-$1 false
1179 # run_command postprocess-$1 true
1182 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1183 # echo "HEH! The file we were about to post-process disappeared:"
1186 # run_command postprocess-$1 false
1201 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
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"
1211 for UTRACKNUM in $TRACKQUEUE
1213 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1215 # FIXME # Hard-coded batch option!
1216 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1218 if [ "$RETURN" != "0" ]; then
1219 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1221 for UTRACKNUM in $TRACKQUEUE
1223 echo normalizetrack-$UTRACKNUM >> status
1229 # do_batch_normalize
1231 # NORMALIZER, NORMALIZEROPTS
1232 do_batch_normalize ()
1234 # The commands here don't go through run_command because they're never supposed to be silenced
1235 echo "Batch normalizing tracks: $TRACKQUEUE"
1240 for UTRACKNUM in $TRACKQUEUE
1242 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1244 # XXX: Hard-coded batch option!
1245 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1247 if [ "$RETURN" != "0" ]; then
1248 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1250 for UTRACKNUM in $TRACKQUEUE
1252 echo normalizetrack-$UTRACKNUM >> status
1258 # do_normalize [tracknumber]
1260 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
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"
1268 if [ "$(checkstatus encode-output)" = "loud" ]; then
1269 echo "HEH! The file we were about to normalize disappeared:"
1272 run_command normalizetrack-$1 false "File $IN was not found"
1276 # do_move [tracknumber]
1277 # Deduces the outfile from environment variables
1278 # Creates directory if necessary
1280 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1283 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1285 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1286 # defined the OUTPUTFILE:
1289 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1290 # Munge filenames as follows:
1295 # Eat control characters
1296 ALBUMFILE="$(mungefilename "$DALBUM")"
1297 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1298 TRACKFILE="$(mungefilename "$TRACKNAME")"
1299 GENRE="$(mungegenre "$GENRE")"
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
1304 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1305 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1306 if [ "$ONETRACK" = "y" ]; then
1307 if [ "$VARIOUSARTISTS" = "y" ]; then
1308 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1310 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1313 if [ "$VARIOUSARTISTS" = "y" ]; then
1314 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1316 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1319 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1320 # Once we know the specific output was successful, we can change
1321 # the OUTPUT to the value containing the container
1324 OUTPUT=$OGGOUTPUTCONTAINER
1327 OUTPUT=$FLACOUTPUTCONTAINER
1333 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1334 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1337 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1338 # FIXME # introduce warnings?
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
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
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
1367 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1368 # We dont have the dir, since it was not created before.
1371 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
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"
1380 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1384 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1386 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1395 # Create the playlist if wanted
1397 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1398 # VARIOUSARTISTS, OUTPUTDIR
1401 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1405 OUTPUT=$OGGOUTPUTCONTAINER
1408 OUTPUT=$FLACOUTPUTCONTAINER
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
1417 ALBUMFILE="$(mungefilename "$DALBUM")"
1418 ARTISTFILE="$(mungefilename "$DARTIST")"
1419 GENRE="$(mungegenre "$GENRE")"
1420 YEAR=${CDYEAR:-$CDYEAR}
1421 if [ "$VARIOUSARTISTS" = "y" ] ; then
1422 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1424 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1426 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1427 mkdir -p "$FINALPLAYLISTDIR"
1428 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1429 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1430 if [ "$INTERACTIVE" = "y" ]; then
1431 while [ "$DONE" != "y" ]; do
1433 case $ERASEPLAYLIST in
1434 e|E|a|A|k|K) DONE=y ;;
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
1445 # The playlist does not exist, so we can safelly use append to create the new list
1448 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1449 touch "$OUTPUTDIR/$PLAYLISTFILE"
1450 for UTRACKNUM in $TRACKQUEUE
1452 # Shares some code with do_move since the filenames have to match
1453 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1454 getcddbinfo TRACKNAME
1456 TRACKFILE="$(mungefilename "$TRACKNAME")"
1457 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1458 ALBUMFILE="$(mungefilename "$DALBUM")"
1459 # If we want to start the tracks with a given number, we need to modify the
1460 # TRACKNUM value before evaluation
1462 if [ "$VARIOUSARTISTS" = "y" ]; then
1463 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1465 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1467 if [ "$VARIOUSARTISTS" = "y" ]; then
1468 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1469 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1471 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1474 if [ "$PLAYLISTDATAPREFIX" ]; then
1475 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1477 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
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"
1486 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1487 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1489 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1494 # This essentially the start of things
1497 # Query the CD to get the track info, unless the user specified -C
1498 # or we are using some actions which do not need the CDDB data at all
1499 #if [ ! X"$EXPACTIONS" = "X" ]; then
1501 #elif [ -z "$DISCID" ]; then
1502 if [ -z "$DISCID" ]; then
1503 vecho -n "Getting CD track info... "
1504 # In OSX, unmount the disc before a query
1505 if [ "$OSFLAVOUR" = "OSX" ]; then
1506 disktool -u ${CDROM#/dev/}
1508 case "$CDROMREADERSYNTAX" in
1510 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1511 case "$CUE2DISCID" in
1513 #vecho "Using builtin cue2discid implementation..."
1514 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1516 #TRACKS=$(echo $CUESHEET | egrep "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1518 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1519 TRACKS=${#OFFSETTIMES[@]}
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} ))
1527 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) / 44100 * 75 ))
1528 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) / 44100 * 75 ))
1532 #vecho "Using external python cue2discid implementation..."
1533 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1537 log error "the input flac file does not contain a cuesheet."
1542 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1544 # if [ ! "$RET" = "0" ];then
1545 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1548 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1549 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1551 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | egrep -o '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1552 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1556 case "$CDDBMETHOD" in
1557 cddb) TRACKINFO=$($CDDISCID $CDROM) ;;
1558 # FIXME # musicbrainz needs a cleanup
1559 musicbrainz) TRACKINFO=$($MUSICBRAINZ -c $CDROM ) ;;
1563 # Make sure there's a CD in there by checking cd-discid's return code
1564 if [ ! "$?" = "0" ]; then
1565 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
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?."
1570 log error "CD could not be read. Perhaps there's no CD in the drive?"
1574 # In OSX, remount the disc again
1575 if [ "$OSFLAVOUR" = "OSX" ]; then
1576 disktool -m ${CDROM#/dev/}
1579 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1581 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
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
1588 # get the number of digits to pad TRACKNUM with - we'll use this later
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.
1592 if [ "$PADTRACKS" = "y" ] ; then
1596 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1597 if [ -z "$TRACKQUEUE" ]; then
1598 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1599 case "$CDROMREADERSYNTAX" in
1601 if [ "$WEHAVEACD" = "y" ]; then
1602 vecho "Querying the CD for audio tracks..."
1603 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1605 if [ ! "$RET" = "0" ];then
1606 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1608 TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1609 CDPARANOIAAUDIOTRACKS="$TRACKS"
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"
1616 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1617 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1621 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1624 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1626 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1627 log info "The disc does not contain any tracks. Giving up..."
1630 echo -n "Grabbing entire CD - tracks: "
1631 if [ ! "$PADTRACKS" = "y" ] ; then
1632 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1634 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1636 while [ "$X" -ne "$TRACKS" ]
1638 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1639 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1643 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
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 ' ')
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)
1657 TRACKQUEUE=$PADTRACKQUEUE
1658 echo Grabbing tracks: "$TRACKQUEUE"
1661 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1663 # We have the discid, create a temp directory after it to store all the temp
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
1673 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1674 echo "Please investigate, remove it, and rerun abcde." >&2
1678 # It's a directory, let's see if it's owned by us
1679 if [ ! -O "$ABCDETEMPDIR" ]; then
1680 # Nope, complain and exit
1682 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1683 echo "Please investigate, remove it, and rerun abcde." >&2
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
1698 if [ "$ANSWER" != "y" ]; then
1701 rm -rf "$ABCDETEMPDIR" || exit 1
1702 mkdir -p "$ABCDETEMPDIR"
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
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"
1717 # Remove old error messages
1718 if [ -f "$ABCDETEMPDIR/errors" ]; then
1719 rm -f "$ABCDETEMPDIR/errors"
1723 # We are starting from scratch
1724 mkdir -p "$ABCDETEMPDIR"
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
1730 cat /dev/null > "$ABCDETEMPDIR/status"
1731 # Store the abcde version in the status file.
1732 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
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..."
1738 case $CDROMREADERSYNTAX in
1740 if $METAFLAC --export-cuesheet-to=- $CDROM > "$ABCDETEMPDIR/$CUEFILE"; then :; else
1741 log warning "the input flac file does not contain a cuesheet."
1745 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1746 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1748 log warning "reading the CUE sheet is still considered experimental"
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"
1756 # If we got the CDPARANOIA status and it is not recorded, save it now
1757 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1758 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
1759 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1763 # Create the discid file
1764 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1765 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
1766 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
1771 # Create a proper CUE file based on the CUE file we created before.
1774 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1775 CUEFILE_OUT=$CUEFILE_IN.out
1776 ### FIXME ### checkstatus cddb
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?
1782 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1783 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1784 cat "$CUEFILE_IN" | while read line
1786 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
1787 eval track="\$TRACK$n"
1789 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1791 echo "$line" >> "$CUEFILE_OUT"
1793 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1794 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1800 # Parses a CDDB file and outputs the title and the track names.
1801 # Variables: CDDBFILE
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..."
1809 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1810 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
1811 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1812 if [ ! X"$PARSEDYEAR" = "X" ]; then
1813 echo "Year: $PARSEDYEAR"
1816 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
1817 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1818 if [ ! X"$PARSEDGENRE" = "X" ]; then
1819 echo "Genre: $PARSEDGENRE"
1822 if [ ! "$ONETRACK" = "y" ]; then
1823 for TRACK in $(f_seq_row 1 $TRACKS)
1825 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1831 # Check for a local CDDB file, and report success
1834 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
1836 CDDBLOCALSTATUS="notfound"
1837 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1840 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
1841 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
1842 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
1843 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
1844 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
1845 CDDBLOCALMATCH=single
1846 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
1847 CDDBLOCALMATCH=multiple
1852 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
1853 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1854 CDDBLOCALMATCH=single
1859 # If the user has selected to check a local CDDB repo, we proceed with it
1860 case $CDDBLOCALMATCH in
1862 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
1864 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
1866 # List out disc title/author and contents
1867 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
1868 cat "$RESULT" > "${CDDBLOCALREAD}"
1871 do_cddbparse "${CDDBLOCALREAD}"
1873 ##FIXME## QUICK HACK !!!!
1874 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
1875 } >> "$ABCDETEMPDIR/cddblocalchoices"
1877 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
1878 page "$ABCDETEMPDIR/cddblocalchoices"
1880 # It's all going to fit in one page, cat it
1881 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
1883 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
1884 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1885 CDDBLOCALCHOICENUM=-1
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
1889 read CDDBLOCALCHOICE
1890 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
1891 # FIXME # Introduce diff's
1892 if echo $CDDBLOCALCHOICE | egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
1893 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
1894 elif echo $CDDBLOCALCHOICE | egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
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
1904 #echo "Selected ..."
1906 CDDBLOCALCHOICENUM=1
1908 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
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"
1911 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
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"
1918 #echo "Not using local copy of CDDB data"
1919 CDDBLOCALSTATUS="notfound"
1923 # List out disc title/author and contents
1924 do_cddbparse "${CDDBLOCALFILE}"
1925 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1926 # echo -n "Embedded cuesheet entry found, use it? [y/n] (y): " >&2
1928 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
1930 if [ "$INTERACTIVE" = "y" ]; then
1932 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1933 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
1936 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
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"
1948 CDDBLOCALSTATUS="single"
1950 #echo "Not using local copy of CDDB data"
1951 CDDBLOCALSTATUS="notfound"
1955 CDDBLOCALSTATUS="notfound"
1961 do_musicbrainzstat ()
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
1978 echo 503 > "$ABCDETEMPDIR/cddbstat"
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 `.')
1991 501|*) # 501 Illegal CDDB protocol level: <n>.
1992 CDDBPROTO=`expr $CDDBPROTO - 1`
1996 if test $rc -eq 1; then
2000 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2008 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2009 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2011 # Perform CDDB query if it hasn't already been done
2012 if checkstatus cddb-querycomplete; then :; else
2013 if [ "$CDDBAVAIL" = "n" ]; then
2015 echo 503 > "$ABCDETEMPDIR/cddbquery"
2016 # The default CDDBLOCALSTATUS is "notfound"
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.
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"
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"
2036 *) # strange and unknown error
2037 echo ERRORCODE=$ERRORCODE
2038 echo "abcde: $CDDBTOOL returned unknown error code"
2042 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
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
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"
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)
2073 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2075 echo >> "$ABCDETEMPDIR/cddbchoices"
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" ;;
2084 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2085 # List out disc title/author and contents of template
2086 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2088 for TRACK in $(f_seq_row 1 $TRACKS)
2090 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2092 echo >> "$ABCDETEMPDIR/cddbchoices"
2093 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2094 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2097 # Multiple exact, (possibly multiple) inexact matches
2099 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2100 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
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"
2105 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2107 vecho -n "Retrieving multiple matches... "
2108 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2109 read DISCINFO # eat top line
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"
2117 # List out disc title/author and contents
2118 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2119 for TRACK in $(f_seq_row 1 $TRACKS)
2121 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2123 echo >> "$ABCDETEMPDIR/cddbchoices"
2126 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2130 for TRACK in $(f_seq_row 1 $TRACKS)
2132 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2134 echo >> "$ABCDETEMPDIR/cddbchoices"
2135 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2136 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2139 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2146 if checkstatus cddb-edit >/dev/null; then
2147 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2148 VARIOUSARTISTS="$(checkstatus variousartists)"
2149 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
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
2155 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
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
2163 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2164 log error "CDDB query failed!"
2167 cat "$ABCDETEMPDIR/cddbchoices"
2170 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2172 echo "Selected: #$CHOICE"
2173 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
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
2179 page "$ABCDETEMPDIR/cddbchoices"
2181 # It's all going to fit in one page, cat it
2182 cat "$ABCDETEMPDIR/cddbchoices" >&2
2186 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2188 # I'll take CDDB read #3 for $400, Alex
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
2192 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2193 if echo $CDDBCHOICE | egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2194 if [ ! X"$DIFF" = "X" ]; then
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)
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
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"
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"
2211 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2215 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2217 elif echo $CDDBCHOICE | egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2218 # Make sure we get a valid choice
2219 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2220 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2221 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2225 if [ "$CDCHOICENUM" = "0" ]; then
2226 vecho "Creating empty CDDB template..."
2228 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2230 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2231 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2233 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2237 # We need some code to show the selected option when local repository is selected and we have found a match
2238 vecho "Using cached CDDB match..." >&2
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
2249 echo "Selected template."
2251 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2253 echo "Selected: #$CHOICE"
2254 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
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)
2268 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2269 #if [ "$PREVIOUSCHOICE" ]; then
2270 cat "$ABCDETEMPDIR/cddbchoices"
2273 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2274 CDCHOICENUM=$PREVIOUSCHOICE
2277 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2279 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2284 if checkstatus cddb-choice >/dev/null; then :; else
2285 echo "abcde: internal error: cddb-choice not recorded." >&2
2288 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2289 echo -n "Edit selected CDDB data? [y/n] (" >&2
2290 if [ "$INTERACTIVE" = "y" ]; then
2291 if [ "$UNKNOWNDISK" = "y" ]; then
2294 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2303 if [ "$EDITCDDB" = "y" ]; then
2304 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
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
2314 eval $(echo "$EDITOR") \"$CDDBDATA\"
2316 # If that fails, check for a vi
2317 elif which vi >/dev/null 2>&1; then
2319 elif [ -x /usr/bin/vim ]; then
2320 /usr/bin/vim "$CDDBDATA"
2321 elif [ -x /usr/bin/vi ]; then
2322 /usr/bin/vi "$CDDBDATA"
2323 elif [ -x /bin/vi ]; then
2325 # nano should be on all (modern, i.e., sarge) debian systems
2326 elif which nano >/dev/null 2>&1 ; then
2328 elif [ -x /usr/bin/nano ]; then
2329 /usr/bin/nano "$CDDBDATA"
2330 # mg should be on all OpenBSD systems
2331 elif which mg >/dev/null 2>&1 ; then
2333 elif [ -x /usr/bin/mg ]; then
2334 /usr/bin/mg "$CDDBDATA"
2337 log warning "no editor available. Check your EDITOR environment variable."
2339 # delete editor backup file if it exists
2340 if [ -w "$CDDBDATA~" ]; then
2345 # Some heuristics first. Look at Disc Title, and if it starts with
2346 # "Various", then we'll assume Various Artists
2347 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2348 echo "Looks like a Multi-Artist CD" >&2
2351 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2352 if [ "$INTERACTIVE" = "y" ]; then
2359 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2362 # Need NUMTRACKS before cddb-tool will return it:
2363 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2364 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2365 # More than 1/2 tracks contain a "/", so guess forward
2367 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2368 # More than 1/2 contain a "-", so guess forward-dash
2370 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2371 # More than 1/2 contain something in parens, so guess trailing-paren
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
2386 echo $DEFAULTSTYLE >&2
2387 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
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)
2397 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2398 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2400 vecho "Selected: $VARIOUSARTISTSTYLE"
2401 case "$VARIOUSARTISTSTYLE" in
2403 VARIOUSARTISTSTYLE=forward
2406 VARIOUSARTISTSTYLE=forward-dash
2409 VARIOUSARTISTSTYLE=reverse
2412 VARIOUSARTISTSTYLE=reverse-dash
2415 VARIOUSARTISTSTYLE=colon
2418 VARIOUSARTISTSTYLE=trailing-paren
2426 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2427 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2429 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2430 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
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
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): "
2444 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2445 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2447 echo -n 'Invalid selection. Please answer "y" or "n": '
2450 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2451 echo -n "Sending..."
2452 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2459 # User CDDBLOCALPOLICY to find out if we store the file or not...
2460 # Cache edited CDDB entry in the user's cddb dir
2461 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2462 # Make sure the cache directory exists
2463 mkdir -p $CDDBLOCALDIR
2464 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2467 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2470 # do_cdread [tracknumber]
2471 # do_cdread onetrack [firsttrack] [lasttrack]
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
2477 if [ "$1" = "onetrack" ]; then
2478 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2479 # FIXME # Until then, we grab the whole CD in one track, no matter what
2481 # We need the first and last track for cdda2wav
2483 LASTTRACK=$(expr $3 + 0)
2484 UTRACKNUM=$FIRSTTRACK
2485 case "$CDROMREADERSYNTAX" in
2486 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2487 cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2488 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
2489 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2495 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2496 if [ "$USEPIPES" = "y" ]; then
2497 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
2498 FILEARG="$( eval echo "\$$TEMPARG" )"
2500 PIPE_MESSAGE="and encoding "
2502 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2503 case "$CDROMREADERSYNTAX" in
2504 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2506 FILEARG="--output-name=$WAVDATA"
2509 FILEARG="-f $WAVDATA"
2517 if [ "$1" = "onetrack" ]; then
2518 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2520 if [ -r "$CDDBDATA" ]; then
2521 getcddbinfo TRACKNAME
2522 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2524 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2527 case "$CDROMREADERSYNTAX" in
2528 ### FIXME ### use an exception for flac, since it uses -o
2529 ### FIXME ### Shall we just use -o $FILEARG ??
2531 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2532 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
2533 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2535 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
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"
2545 if [ "$CDROMID" = "" ]; then
2546 CDDA2WAVCDROM="$CDROM"
2548 CDDA2WAVCDROM="$CDROMID"
2551 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2553 ## FIXME ## We have an exception for dagrab, since it uses -f
2554 ## FIXME ## Shall we just use -f $FILEARG ??
2555 dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2558 # Find the track's mounted path
2559 REALTRACKNUM=$(expr $UTRACKNUM + 0)
2560 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
2561 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2562 # If the file exists, copy it
2563 if [ -e "$FILEPATH" ] ; then
2564 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2568 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
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
2575 # Thank goodness errors is only machine-parseable up to the
2576 # first colon, otherwise this woulda sucked
2577 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2578 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2580 if [ "$USEPIPES" = "y" ]; then
2581 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2583 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2587 if [ "$USEPIPES" = "y" ]; then
2588 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2590 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2592 if [ "$1" = "onetrack" ]; then
2593 echo onetrack >> "$ABCDETEMPDIR/status"
2599 # No values accepted, only uses env variables
2602 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
2603 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
2605 echo "abcde: unable to set the device speed" >&2
2611 # vecho outputs a message if EXTRAVERBOSE is selected
2614 if [ x"$EXTRAVERBOSE" != "x" ]; then
2616 warning) shift ; log warning "$@" ;;
2624 # decho outputs a debug message if DEBUG is selected
2627 if [ x"$DEBUG" != "x" ]; then
2628 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
2629 DEBUGECHO=$(echo "$@" | tr -d '[]')
2630 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2637 # User-redefinable functions
2638 # Custom filename munging:
2641 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2642 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
2645 # Custom genre munging:
2648 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2652 # Empty pre_read function, to be defined in the configuration file.
2659 # Empty post_read function, to be defined in the configuration file.
2665 ###############################################################################
2668 # Start of execution
2669 ###############################################################################
2674 # Defaults to FreeDB, but a python musicbrainz can be used
2676 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2677 CDDBSUBMIT=freedb-submit@freedb.org
2679 HELLOINFO="$(whoami)@$(hostname)"
2681 CDDBLOCALPOLICY="always"
2682 CDDBLOCALRECURSIVE="y"
2683 CDDBLOCALDIR="$HOME/.cddb"
2686 # List of fields we parse and show during the CDDB parsing...
2687 SHOWCDDBFIELDS="year,genre"
2690 #CDROMREADERSYNTAX=cdparanoia
2691 ENCODERSYNTAX=default
2693 MP3ENCODERSYNTAX=default
2694 OGGENCODERSYNTAX=default
2695 FLACENCODERSYNTAX=default
2696 SPEEXENCODERSYNTAX=default
2697 MPPENCODERSYNTAX=default
2698 AACENCODERSYNTAX=default
2699 NORMALIZERSYNTAX=default
2700 CUEREADERSYNTAX=default
2702 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2703 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2704 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2705 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2706 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2707 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2708 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2709 PLAYLISTDATAPREFIX=''
2710 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2711 VAPLAYLISTDATAPREFIX=''