2 # Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
3 # Copyright (c) 2003-2005 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
8 # along with this program; if not, write to the Free Software
9 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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"
57 #echo "-R Add replaygain values to the tag info (only for vorbis,flac,mp3)"
59 echo " Show dielfs from the CDDB info (year,genre)"
60 echo "-S <#> Set the CD speed"
61 echo "-t <#> Start the track numbering at a given number"
62 echo "-T <#> Same as -t but modifies tag numbering"
63 echo "-u Use UNICODE 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 -q "[[:digit:]]" ; 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 # chechwarnings [blurb]
173 # Returns "0" if the blurb was found (meaning there was an warning),
174 # returns 1 if it wasn't (yes this is a little backwards).
175 # Does not print the blurb on stdout.
176 # Otherwise, returns "".
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 the command-line options we just added in
341 X=$(echo $@ | cut -d' ' -f2)
342 if [ "$(which $X)" = "" ]; then
343 log error "$X is not in your path." >&2
345 elif [ ! -x $(which $X) ]; then
346 log error "$X is not executable." >&2
352 # diffentries <filename> <max_value> <entry1>,<entry2>
357 local CDDBDIFFCHOICES=$1
359 local CDDBDIFFCHOICE="$@"
360 if [ ! X"$DIFF" = "X" ]; then
361 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
362 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
363 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
364 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
365 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
366 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
368 # We parse the 2 choices to diff, store them in temporary files and diff them.
369 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
370 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
372 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
373 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
374 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
375 page "$ABCDETEMPDIR/$FILENAME.diff"
377 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
381 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
386 # Finds an specific field from cddbinfo
391 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
394 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
400 # Get the track number we are going to use for different actions
403 if [ -n "$STARTTRACKNUMBER" ] ; then
404 # Get the trackpadding from the current track
405 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
406 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
408 TRACKNUM=${UTRACKNUM}
414 if checkstatus replaygain; then :; else
415 run_command "" echo "Adding replygain information..."
416 for OUTPUT in $( echo $OUTPUTTYPE | tr , \ )
420 OUTPUT=$OGGOUTPUTCONTAINER
423 OUTPUT=$FLACOUTPUTCONTAINER
428 for UTRACKNUM in $TRACKQUEUE
430 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
431 do_getcddbinfo TRACKNAME
433 TRACKFILE="$(mungefilename "$TRACKNAME")"
434 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
435 ALBUMFILE="$(mungefilename "$DALBUM")"
437 if [ "$VARIOUSARTISTS" = "y" ]; then
438 OUTPUTFILE="$(eval echo $VAOUTPUTFORMAT)"
440 OUTPUTFILE="$(eval echo $OUTPUTFORMAT)"
442 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
443 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
447 run_command replaygain-flac $METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
450 run_command replaygain-vorbis $VORBISGAIN --album "${OUTPUTFILES[@]}"
453 run_command replaygain-mp3 $MP3GAIN -a "${OUTPUTFILES[@]}"
456 run_command replaygain-mpc $MPPGAIN --auto "${OUTPUTFILES[@]}"
461 if checkerrors "replaygain-.{3,6}"; then :; else
462 run_command replaygain true
467 # This code splits the a Various Artist track name from one of the following
470 # forward: Artist / Track
471 # forward-dash: Artist - Track
472 # reverse: Track / Artist
473 # reverse-dash: Track - Artist
474 # colon: Artist: Track
475 # trailing-paren: Artist (Track)
478 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
481 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
482 case "$VARIOUSARTISTSTYLE" in
484 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
485 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
486 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
489 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
490 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
491 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
494 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
495 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
496 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
499 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
500 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
501 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
504 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
505 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
506 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
509 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
510 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
511 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
514 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
515 TRACKARTIST="Various"
517 TRACKARTIST="$DARTIST"
522 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
526 "classic rock") id=1 ;;
544 "industrial") id=19 ;;
545 "alternative") id=20 ;;
547 "death metal") id=22 ;;
549 "soundtrack") id=24 ;;
550 "euro-techno") id=25 ;;
554 "jazz+funk") id=29 ;;
557 "classical") id=32 ;;
558 "instrumental") id=33 ;;
562 "sound clip") id=37 ;;
565 "alt. rock") id=40 ;;
570 "meditative") id=45 ;;
571 "instrum. pop") id=46 ;;
572 "instrum. rock") id=47 ;;
576 "techno-indust.") id=51 ;;
577 "electronic") id=52 ;;
579 "eurodance") id=54 ;;
581 "southern rock") id=56 ;;
586 "christian rap") id=61 ;;
587 "pop/funk"|"pop / funk") id=62 ;;
589 "native american") id=64 ;;
592 "psychadelic") id=67 ;;
594 "showtunes") id=69 ;;
598 "acid punk") id=73 ;;
599 "acid jazz") id=74 ;;
603 "rock & roll") id=78 ;;
604 "hard rock") id=79 ;;
606 "folk/rock") id=81 ;;
607 "national folk") id=82 ;;
614 "bluegrass") id=89 ;;
615 "avantgarde") id=90 ;;
616 "gothic rock") id=91 ;;
617 "progress. rock") id=92 ;;
618 "psychadel. rock") id=93 ;;
619 "symphonic rock") id=94 ;;
620 "slow rock") id=95 ;;
623 "easy listening") id=98 ;;
629 "chamber music") id=104 ;;
631 "symphony") id=106 ;;
632 "booty bass") id=107 ;;
634 "porn groove") id=109 ;;
636 "slow jam") id=111 ;;
640 "folklore") id=115 ;;
642 "power ballad") id=117 ;;
643 "rhythmic soul") id=118 ;;
644 "freestyle") id=119 ;;
646 "punk rock") id=121 ;;
647 "drum solo") id=122 ;;
648 "a capella") id=123 ;;
649 "euro-house") id=124 ;;
650 "dance hall") id=125 ;;
652 "drum & bass") id=127 ;;
653 "club-house") id=128 ;;
654 "hardcore") id=129 ;;
658 "negerpunk") id=133 ;;
659 "polsk punk") id=134 ;;
661 "christian gangsta rap") id=136 ;;
662 "heavy metal") id=137 ;;
663 "black metal") id=138 ;;
664 "crossover") id=139 ;;
665 "contemporary christian")id=140 ;;
666 "christian rock") id=141 ;;
667 "merengue") id=142 ;;
669 "thrash metal") id=144 ;;
672 "synthpop") id=147 ;;
673 "rock/pop"|"rock / pop") id=148 ;;
680 # do_tag [tracknumber]
681 # id3 tags a filename
683 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
684 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
687 COMMENTOUTPUT="$(eval echo ${COMMENT})"
688 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
689 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
690 # If we want to start the tracks with a given number, we need to modify the
691 # TRACKNUM value before evaluation
692 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
695 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
699 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
700 GENREID=$(do_getgenreid "${CDGENRE}")
705 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
706 run_command tagtrack-$OUTPUT-$1 $TAGGER $TAGGEROPTS --commen=::"$COMMENTOUTPUT" \
707 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
708 -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
709 "${ENCODING:+--set-encoding=$ENCODING}"
710 "$ABCDETEMPDIR/track$1.$OUTPUT"
713 # FIXME # track numbers in mp3 come with 1/10, so we cannot happily substitute them with $TRACKNUM
714 run_command tagtrack-$OUTPUT-$1 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
715 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
716 -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
717 "$ABCDETEMPDIR/track$1.$OUTPUT"
722 case "$OGGENCODERSYNTAX" in
724 # vorbiscomment can't do in-place modification, mv the file first
725 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
726 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
729 # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
730 echo ARTIST="$TRACKARTIST"
732 echo TITLE="$TRACKNAME"
733 if [ -n "$CDYEAR" ]; then
736 if [ -n "$CDGENRE" ]; then
737 echo GENRE="$CDGENRE"
739 echo TRACKNUMBER=${TRACKNUM:-$1}
740 echo CDDB=$CDDBDISCID
741 if [ "$(eval echo ${COMMENT})" != "" ]; then
742 case "$COMMENTOUTPUT" in
743 *=*) echo "$COMMENTOUTPUT";;
744 *) echo COMMENT="$COMMENTOUTPUT";;
747 ) | run_command tagtrack-$OUTPUT-$1 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
748 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
749 # Doublecheck that the commented file was created successfully before wiping the original
750 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
751 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
753 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
760 echo ARTIST="$TRACKARTIST"
762 echo TITLE="$TRACKNAME"
763 if [ -n "$CDYEAR" ]; then
766 if [ -n "$CDGENRE" ]; then
767 echo GENRE="$CDGENRE"
769 echo TRACKNUMBER="${TRACKNUM:-$1}"
770 echo CDDB="$CDDBDISCID"
771 if [ "$(eval echo ${COMMENT})" != "" ]; then
772 case "$COMMENTOUTPUT" in
773 *=*) echo "$COMMENTOUTPUT";;
774 *) echo COMMENT="$COMMENTOUTPUT";;
777 ) | run_command tagtrack-$OUTPUT-$1 $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
780 run_command tagtrack-$OUTPUT-$1 true
783 run_command tagtrack-$OUTPUT-$1 true
786 run_command tagtrack-$OUTPUT-$1 true
789 run_command tagtrack-$OUTPUT-$1 true
793 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
794 run_command tagtrack-$1 true
801 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
804 # The commands here don't go through run_command because they're never supposed to be silenced
805 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
806 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
810 case "$MP3ENCODERSYNTAX" in
815 for UTRACKNUM in $TRACKQUEUE
817 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
819 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
821 if [ "$RETURN" != "0" ]; then
822 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
824 for UTRACKNUM in $TRACKQUEUE
826 run_command encodetrack-$OUTPUT-$UTRACKNUM true
827 #run_command encodetrack-$UTRACKNUM true
836 if checkerrors "nogap-encode"; then :; else
837 if [ ! "$KEEPWAVS" = "y" ] ; then
838 if [ ! "$KEEPWAVS" = "move" ] ; then
843 # Other encoders fall through to normal encoding as the tracks
844 # have not been entered in the status file.
847 # do_encode [tracknumber] [hostname]
848 # If no hostname is specified, encode locally
850 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
853 if [ "$USEPIPES" = "y" ]; then
856 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
859 TEMPARG="PIPE_$OGGENCODERSYNTAX"
862 TEMPARG="PIPE_$FLACENCODERSYNTAX"
865 TEMPARG="PIPE_$SPEEXENCODER"
868 TEMPARG="PIPE_$MPPENCODER"
871 TEMPARG="PIPE_$MPPENCODER"
874 IN="$( eval echo "\$$TEMPARG" )"
876 IN="$ABCDETEMPDIR/track$1.wav"
879 case "$MP3ENCODERSYNTAX" in
880 # FIXME # check if mp3enc needs -if for pipes
881 # FIXME # I have not been able to find a working mp3enc binary
895 # We need IN to proceed, if we are not using pipes.
896 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
897 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
901 OUT="$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
902 OUTPUT=$OGGOUTPUTCONTAINER
905 OUT="$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
906 OUTPUT=$FLACOUTPUTCONTAINER
909 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
912 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
915 if [ X"$USEPIPES" = "Xy" ]; then
917 # We need a way to store the creation of the files when using PIPES
918 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
920 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
921 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
927 case "$MP3ENCODERSYNTAX" in
928 lame|gogo) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
929 bladeenc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
930 l3enc|xingmp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
931 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
932 mp3enc) $RUN_COMMAND nice $ENCNICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
936 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
943 case "$OGGENCODERSYNTAX" in
944 vorbize) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
945 oggenc) $RUN_COMMAND nice $ENCNICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
949 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
956 case "$FLACENCODERSYNTAX" in
957 flac) $RUN_COMMAND nice $ENCNICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
962 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
963 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
968 if [ "$(eval echo ${COMMENT})" != "" ]; then
971 *) COMMENT="COMMENT=$COMMENT" ;;
973 COMMENT="--comment \"$COMMENT\""
975 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
976 if [ ! "$DOTAG" = "y" ]; then
977 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
979 $RUN_COMMAND nice $ENCNICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
983 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
985 # I tried compiling the mppenc from corecodecs.org and got some
986 # errors, so I have not tried it myself.
987 ## FIXME ## Needs some cleanup to determine if an empty tag sent
988 ## FIXME ## to the encoder ends up empty.
989 $RUN_COMMAND nice $ENCNICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
992 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
993 if [ ! "$DOTAG" = "y" ]; then
994 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
997 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1001 # In case of wav output we need nothing. Just keep the wavs.
1006 # Only remove .wav if the encoding succeeded
1007 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1008 run_command encodetrack-$1 true
1009 if [ ! "$KEEPWAVS" = "y" ] ; then
1010 if [ ! "$KEEPWAVS" = "move" ] ; then
1016 run_command "" echo "HEH! The file we were about to encode disappeared:"
1017 run_command "" echo ">> $IN"
1018 run_command encodetrack-$1 false
1022 # do_preprocess [tracknumber]
1024 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1027 # IN="$ABCDETEMPDIR/track$1.wav"
1028 # # We need IN to proceed.
1029 # if [ -s "$IN" ] ; then
1030 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1032 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1033 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1034 # case "$POSTPROCESSFORMAT" in
1036 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1038 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1040 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1042 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1044 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1047 # # Only remove .wav if the encoding succeeded
1048 # if checkerrors "preprocess-(.{3,4})-$1"; then
1049 # run_command preprocess-$1 false
1051 # run_command preprocess-$1 true
1054 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1055 # echo "HEH! The file we were about to pre-process disappeared:"
1058 # run_command preprocess-$1 false
1063 # do_postprocess [tracknumber]
1065 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1068 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1070 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1071 # # We need IN to proceed.
1072 # if [ -s "$IN" ] ; then
1073 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1074 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1075 # case "$POSTPROCESSFORMAT" in
1077 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1079 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1081 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1083 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1085 # # Only remove .wav if the encoding succeeded
1086 # if checkerrors "postprocess-(.{3,4})-$1"; then
1087 # run_command postprocess-$1 false
1089 # run_command postprocess-$1 true
1092 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1093 # echo "HEH! The file we were about to post-process disappeared:"
1096 # run_command postprocess-$1 false
1111 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1115 # The commands here don't go through run_command because they're never supposed to be silenced
1116 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1121 for UTRACKNUM in $TRACKQUEUE
1123 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1125 # FIXME # Hard-coded batch option!
1126 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1128 if [ "$RETURN" != "0" ]; then
1129 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1131 for UTRACKNUM in $TRACKQUEUE
1133 echo normalizetrack-$UTRACKNUM >> status
1139 # do_batch_normalize
1141 # NORMALIZER, NORMALIZEROPTS
1142 do_batch_normalize ()
1144 # The commands here don't go through run_command because they're never supposed to be silenced
1145 echo "Batch normalizing tracks: $TRACKQUEUE"
1150 for UTRACKNUM in $TRACKQUEUE
1152 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1154 # XXX: Hard-coded batch option!
1155 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1157 if [ "$RETURN" != "0" ]; then
1158 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1160 for UTRACKNUM in $TRACKQUEUE
1162 echo normalizetrack-$UTRACKNUM >> status
1168 # do_normalize [tracknumber]
1170 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1173 IN="$ABCDETEMPDIR/track$1.wav"
1174 if [ -e "$IN" ] ; then
1175 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1176 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1178 if [ "$(checkstatus encode-output)" = "loud" ]; then
1179 echo "HEH! The file we were about to normalize disappeared:"
1182 run_command normalizetrack-$1 false "File $IN was not found"
1186 # do_move [tracknumber]
1187 # Deduces the outfile from environment variables
1188 # Creates directory if necessary
1190 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1193 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1195 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1196 # Munge filenames as follows:
1201 # Eat control characters
1202 ALBUMFILE="$(mungefilename "$DALBUM")"
1203 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1204 TRACKFILE="$(mungefilename "$TRACKNAME")"
1205 GENRE="$(mungegenre "$GENRE")"
1206 YEAR="$(echo $CDYEAR)"
1207 # If we want to start the tracks with a given number, we need to modify the
1208 # TRACKNUM value before evaluation
1210 # Supported variables for OUTPUTFORMAT are GENRE, ALBUMFILE, ARTISTFILE,
1211 # TRACKFILE, and TRACKNUM.
1212 if [ "$VARIOUSARTISTS" = "y" ]; then
1213 OUTPUTFILE="$(eval echo "$VAOUTPUTFORMAT")"
1215 OUTPUTFILE="$(eval echo "$OUTPUTFORMAT")"
1217 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1218 # Once we know the specific output was successful, we can change the OUTPUT to the value containing the container
1221 OUTPUT=$OGGOUTPUTCONTAINER
1224 OUTPUT=$FLACOUTPUTCONTAINER
1227 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1228 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1231 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1232 # FIXME # introduce warnings?
1235 # mkdir -p shouldn't return an error if the directory already exists
1236 mkdir -p "$OUTPUTFILEDIR"
1237 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1238 if checkstatus movetrack-output-$OUTPUT; then :; else
1239 run_command movetrack-output-$OUTPUT true
1244 # mkdir -p shouldn't return an error if the directory already exists
1245 mkdir -p "$OUTPUTFILEDIR"
1246 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1247 if checkstatus movetrack-output-$OUTPUT; then :; else
1248 run_command movetrack-output-$OUTPUT true
1252 # Lets move the cue file
1253 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1254 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1255 if checkstatus movecue-$OUTPUT; then :; else
1256 # Silence the Copying output since it overlaps with encoding processes...
1257 #run_command '' vecho "Copying cue file to its destination directory..."
1258 if checkstatus onetrack >/dev/null ; then
1261 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1262 # We dont have the dir, since it was not created before.
1265 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1268 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1269 # http://brianvictor.tripod.com/mp3cue.htm#details
1270 [a-z0-9][a-z0-9][a-z0-9])
1271 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1274 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1278 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1280 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1289 # Create the playlist if wanted
1291 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1292 # VARIOUSARTISTS, OUTPUTDIR
1295 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1299 OUTPUT=$OGGOUTPUTCONTAINER
1302 OUTPUT=$FLACOUTPUTCONTAINER
1305 # Create a playlist file for the playlist data to go into.
1306 # We used to wipe it out if it existed. Now we request permision if interactive.
1307 for LASTTRACK in $TRACKQUEUE; do :; done
1308 ALBUMFILE="$(mungefilename "$DALBUM")"
1309 ARTISTFILE="$(mungefilename "$DARTIST")"
1310 GENRE=$(mungegenre "$GENRE")
1311 YEAR=${CDYEAR:-$CDYEAR}
1312 if [ "$VARIOUSARTISTS" = "y" ] ; then
1313 PLAYLISTFILE=$(eval echo $VAPLAYLISTFORMAT)
1315 PLAYLISTFILE=$(eval echo $PLAYLISTFORMAT)
1317 FINALPLAYLISTDIR=$(dirname "$OUTPUTDIR/$PLAYLISTFILE")
1318 mkdir -p "$FINALPLAYLISTDIR"
1319 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1320 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1321 if [ "$INTERACTIVE" = "y" ]; then
1322 while [ "$DONE" != "y" ]; do
1324 case $ERASEPLAYLIST in
1325 e|E|a|A|k|K) DONE=y ;;
1333 # Once we erase the playlist, we use append to create the new one.
1334 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1336 # The playlist does not exist, so we can safelly use append to create the new list
1339 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1340 touch "$OUTPUTDIR/$PLAYLISTFILE"
1341 for UTRACKNUM in $TRACKQUEUE
1343 # Shares some code with do_move since the filenames have to match
1344 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1345 do_getcddbinfo TRACKNAME
1347 TRACKFILE="$(mungefilename "$TRACKNAME")"
1348 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1349 ALBUMFILE="$(mungefilename "$DALBUM")"
1350 # If we want to start the tracks with a given number, we need to modify the
1351 # TRACKNUM value before evaluation
1353 if [ "$VARIOUSARTISTS" = "y" ]; then
1354 OUTPUTFILE=$(eval echo $VAOUTPUTFORMAT)
1356 OUTPUTFILE=$(eval echo $OUTPUTFORMAT)
1358 if [ "$VARIOUSARTISTS" = "y" ]; then
1359 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1360 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1362 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1365 if [ "$PLAYLISTDATAPREFIX" ]; then
1366 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1368 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1373 ## this will convert the playlist to have CRLF line-endings, if specified
1374 ## (some hardware players insist on CRLF endings)
1375 if [ "$DOSPLAYLIST" = "y" ]; then
1376 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1377 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1378 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1380 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1385 # This essentially the start of things
1388 # Query the CD to get the track info, unless the user specified -C
1389 # or we are using some actions which do not need the CDDB data at all
1390 #if [ ! X"$EXPACTIONS" = "X" ]; then
1392 #elif [ -z "$DISCID" ]; then
1393 if [ -z "$DISCID" ]; then
1394 vecho -n "Getting CD track info... "
1395 # In OSX, unmount the disc before a query
1396 if [ "$OSFLAVOUR" = "OSX" ]; then
1397 disktool -u ${CDROM#/dev/}
1399 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1400 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM > /dev/null 2>&1 ; then
1401 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- $CDROM | $CUE2DISCID)
1403 log error "the input flac file does not contain a cuesheet."
1407 case "$CDDBMETHOD" in
1408 cddb) TRACKINFO=$($CDDISCID $CDROM) ;;
1409 # FIXME # musicbrainz needs a cleanup
1410 musicbrainz) TRACKINFO=$($MUSICBRAINZ -c $CDROM ) ;;
1413 # Make sure there's a CD in there by checking cd-discid's return code
1414 if [ ! "$?" = "0" ]; then
1415 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1416 log error "cuesheet information from the flac file could not be read."
1417 log error "Perhaps the flac file does not contain a cuesheet?."
1420 log error "CD could not be read. Perhaps there's no CD in the drive?"
1424 # In OSX, remount the disc again
1425 if [ "$OSFLAVOUR" = "OSX" ]; then
1426 disktool -m ${CDROM#/dev/}
1429 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1431 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1434 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1435 # This needs to be done now because a section of the resuming code will need
1438 # get the number of digits to pad TRACKNUM with - we'll use this later
1439 # a CD can only hold 99 tracks, but since we support a feature for starting
1440 # numbering the tracks from a given number, we might need to set it as a
1441 # variable for the user to define... or obtain it somehow.
1442 if [ "$PADTRACKS" = "y" ] ; then
1446 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1447 if [ -z "$TRACKQUEUE" ]; then
1448 if [ ! "$STRIPDATATRACKS" = "y" ]; then
1449 case "$CDROMREADERSYNTAX" in
1451 if [ "$WEHAVEACD" = "y" ]; then
1452 vecho "Querying the CD for audio tracks..."
1453 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -Q --verbose 2>&1 )"
1455 if [ ! "$RET" = "0" ];then
1456 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1458 TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1459 CDPARANOIAAUDIOTRACKS="$TRACKS"
1461 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1462 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1463 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1464 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1466 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1467 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1471 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1474 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1476 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1477 log info "The disc does not contain any tracks. Giving up..."
1480 echo -n "Grabbing entire CD - tracks: "
1481 if [ ! "$PADTRACKS" = "y" ] ; then
1482 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1484 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1486 while [ "$X" -ne "$TRACKS" ]
1488 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1489 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1493 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1494 # User-supplied track queue.
1495 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1496 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1497 # Once cleaned, obtain the highest value in the trackqueue for number padding
1498 for LASTTRACK in $TRACKQUEUE; do :; done
1499 if [ ! "$PADTRACKS" = "y" ] ; then
1500 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1502 # Now we normalize the trackqueue
1503 for TRACK in $TRACKQUEUE ; do
1504 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1505 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1507 TRACKQUEUE=$PADTRACKQUEUE
1508 echo Grabbing tracks: "$TRACKQUEUE"
1511 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1513 # We have the discid, create a temp directory after it to store all the temp
1516 if [ -e "$ABCDETEMPDIR" ]; then
1517 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1518 # It already exists, see if it's a directory
1519 if [ ! -d "$ABCDETEMPDIR" ]; then
1520 # This is a file/socket/fifo/device/etc, not a directory
1523 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1524 echo "Please investigate, remove it, and rerun abcde." >&2
1528 # It's a directory, let's see if it's owned by us
1529 if [ ! -O "$ABCDETEMPDIR" ]; then
1530 # Nope, complain and exit
1532 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1533 echo "Please investigate, remove it, and rerun abcde." >&2
1537 # See if it's populated
1538 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1539 # Wipe and start fresh
1540 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1541 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1542 if [ "$INTERACTIVE" = "y" ]; then
1548 if [ "$ANSWER" != "y" ]; then
1551 rm -rf "$ABCDETEMPDIR" || exit 1
1552 mkdir -p "$ABCDETEMPDIR"
1553 if [ "$?" -gt "0" ]; then
1554 # Directory already exists or could not be created
1555 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1559 # Everything is fine. Check for ^encodetracklocation-
1560 # and encode-output entries in the status file and
1561 # remove them. These are not relevant across sessions.
1562 if [ -f "$ABCDETEMPDIR/status" ]; then
1563 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1564 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1565 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1567 # Remove old error messages
1568 if [ -f "$ABCDETEMPDIR/errors" ]; then
1569 rm -f "$ABCDETEMPDIR/errors"
1573 # We are starting from scratch
1574 mkdir -p "$ABCDETEMPDIR"
1575 if [ "$?" -gt "0" ]; then
1576 # Directory already exists or could not be created
1577 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1580 cat /dev/null > "$ABCDETEMPDIR/status"
1581 # Store the abcde version in the status file.
1582 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1584 if [ X"$MAKECUEFILE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1585 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1586 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1587 vecho "Creating cue file..."
1588 case $CDROMREADERSYNTAX in
1590 if $METAFLAC --export-cuesheet-to=- $CDROM > "$ABCDETEMPDIR/$CUEFILE"; then :; else
1591 log warning "the input flac file does not contain a cuesheet."
1595 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1596 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1598 log warning "reading the CUE sheet with mkcue is still considered experimental"
1599 log warning "and there was a problem with the CD reading. abcde will continue,"
1600 log warning "but consider reporting the problem to the abcde author"
1606 # If we got the CDPARANOIA status and it is not recorded, save it now
1607 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1608 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
1609 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1613 # Create the discid file
1614 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1615 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
1616 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
1621 # Create a proper CUE file based on the CUE file we created before.
1624 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1625 CUEFILE_OUT=$CUEFILE_IN.out
1626 ### FIXME ### checkstatus cddb
1627 if [ -e "$CDDBDATA" ]; then
1628 vecho "Adding metadata to the cue file..."
1629 # FIXME It doesn't preserve spaces! Why?
1630 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1632 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1633 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1634 cat "$CUEFILE_IN" | while read line
1636 if echo "$line" | grep -q "INDEX"
1638 eval track="\$TRACK$n"
1640 echo "TITLE \"$track\"" >> "$CUEFILE_OUT"
1642 echo "$line" >> "$CUEFILE_OUT"
1644 mv "$CUEFILE_OUT" "$CUEFILE_IN"
1645 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
1651 # Parses a CDDB file and outputs the title and the track names.
1652 # Variables: CDDBFILE
1656 # List out disc title/author and contents
1657 if [ "$ONETRACK" = "y" ]; then
1658 vecho "ONETRACK mode selected: displaying only the title of the CD..."
1660 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
1661 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
1662 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1663 if [ ! X"$PARSEDYEAR" = "X" ]; then
1664 echo "Year: $PARSEDYEAR"
1667 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
1668 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
1669 if [ ! X"$PARSEDGENRE" = "X" ]; then
1670 echo "Genre: $PARSEDGENRE"
1673 if [ ! "$ONETRACK" = "y" ]; then
1674 for TRACK in $(f_seq_row 1 $TRACKS)
1676 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
1682 # Check for a local CDDB file, and report success
1685 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
1687 CDDBLOCALSTATUS="notfound"
1688 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1691 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
1692 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
1693 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
1694 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
1695 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
1696 CDDBLOCALMATCH=single
1697 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
1698 CDDBLOCALMATCH=multiple
1703 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
1704 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1705 CDDBLOCALMATCH=single
1710 # If the user has selected to check a local CDDB repo, we proceed with it
1711 case $CDDBLOCALMATCH in
1713 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
1715 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
1717 # List out disc title/author and contents
1718 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
1719 cat "$RESULT" > "${CDDBLOCALREAD}"
1722 do_cddbparse "${CDDBLOCALREAD}"
1724 } >> "$ABCDETEMPDIR/cddblocalchoices"
1726 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ]; then
1727 page "$ABCDETEMPDIR/cddblocalchoices"
1729 # It's all going to fit in one page, cat it
1730 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
1732 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
1733 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
1734 CDDBLOCALCHOICENUM=-1
1735 if [ "$INTERACTIVE" = "y" ]; then
1736 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
1737 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
1738 read CDDBLOCALCHOICE
1739 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
1740 # FIXME # Introduce diff's
1741 if echo $CDDBLOCALCHOICE | egrep -q "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" ; then
1742 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
1743 elif echo $CDDBLOCALCHOICE | egrep -q "[[:space:]]*[[:digit:]]+[[:space:]]*" ; then
1744 # Make sure we get a valid choice
1745 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
1746 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
1747 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
1756 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
1757 #echo "Using local copy of CDDB data"
1758 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1759 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
1760 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1761 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
1762 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
1763 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1764 CDDBLOCALSTATUS="found"
1766 #echo "Not using local copy of CDDB data"
1767 CDDBLOCALSTATUS="notfound"
1771 # List out disc title/author and contents
1772 do_cddbparse "${CDDBLOCALFILE}"
1773 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1774 echo -n "Embedded cuesheet entry found, use it? [y/n] (y): " >&2
1776 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
1778 if [ "$INTERACTIVE" = "y" ]; then
1780 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
1781 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
1784 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
1788 if [ "$USELOCALRESP" = "y" ]; then
1789 #echo "Using local copy of CDDB data"
1790 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
1791 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
1792 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
1793 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
1794 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
1795 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1796 CDDBLOCALSTATUS="single"
1798 #echo "Not using local copy of CDDB data"
1799 CDDBLOCALSTATUS="notfound"
1803 CDDBLOCALSTATUS="notfound"
1809 do_musicbrainzstat ()
1822 # Perform CDDB protocol version check if it hasn't already been done
1823 if checkstatus cddb-statcomplete; then :; else
1824 if [ "$CDDBAVAIL" = "n" ]; then
1826 echo 503 > "$ABCDETEMPDIR/cddbstat"
1829 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1830 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1831 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
1832 vecho "Checking CDDB server status..."
1833 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
1834 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
1835 case "$RESPONSECODE" in
1836 210) # 210 OK, status information follows (until terminating `.')
1839 501|*) # 501 Illegal CDDB protocol level: <n>.
1840 CDDBPROTO=`expr $CDDBPROTO - 1`
1844 if test $rc -eq 1; then
1848 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
1856 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
1857 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
1859 # Perform CDDB query if it hasn't already been done
1860 if checkstatus cddb-querycomplete; then :; else
1861 if [ "$CDDBAVAIL" = "n" ]; then
1863 echo 503 > "$ABCDETEMPDIR/cddbquery"
1864 # The default CDDBLOCALSTATUS is "notfound"
1865 # This part will be triggered if the user CDDB repo does not
1866 # contain the entry, or if we are not trying to use the repo.
1868 vecho "Querying the CDDB server..."
1869 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
1870 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
1871 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
1877 # no match found in database,
1878 # wget/fetch error, or user requested not to use CDDB
1879 # Make up an error code (503) that abcde
1880 # will recognize in do_cddbread
1881 # and compensate by making a template
1882 echo 503 > "$ABCDETEMPDIR/cddbquery"
1884 *) # strange and unknown error
1885 echo ERRORCODE=$ERRORCODE
1886 echo "abcde: $CDDBTOOL returned unknown error code"
1890 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
1897 # If it's not to be used, generate a template.
1898 # Then, display it (or them) and let the user choose/edit it
1899 if checkstatus cddb-readcomplete; then :; else
1900 vecho "Obtaining CDDB results..."
1901 # If CDDB is to be used, interpret the query results and read all
1902 # the available entries.
1903 rm -f "$ABCDETEMPDIR/cddbchoices"
1904 CDDBCHOICES=1 # Overridden by multiple matches
1905 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
1906 case "$RESPONSECODE" in
1908 # One exact match, retrieve it
1909 # 200 [section] [discid] [artist] / [title]
1910 if checkstatus cddb-read-1-complete; then :; else
1911 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
1912 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
1913 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
1914 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1915 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1917 # List out disc title/author and contents
1918 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
1919 for TRACK in $(f_seq_row 1 $TRACKS)
1921 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1923 echo >> "$ABCDETEMPDIR/cddbchoices"
1927 case "$RESPONSECODE" in
1928 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
1929 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
1930 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
1932 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
1933 # List out disc title/author and contents of template
1934 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
1936 for TRACK in $(f_seq_row 1 $TRACKS)
1938 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1940 echo >> "$ABCDETEMPDIR/cddbchoices"
1941 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
1942 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
1945 # Multiple exact, (possibly multiple) inexact matches
1947 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
1948 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
1949 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
1950 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
1951 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1953 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
1955 vecho -n "Retrieving multiple matches... "
1956 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
1957 read DISCINFO # eat top line
1961 if checkstatus cddb-read-$X-complete; then :; else
1962 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
1963 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
1965 # List out disc title/author and contents
1966 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
1967 for TRACK in $(f_seq_row 1 $TRACKS)
1969 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1971 echo >> "$ABCDETEMPDIR/cddbchoices"
1974 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
1978 for TRACK in $(f_seq_row 1 $TRACKS)
1980 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
1982 echo >> "$ABCDETEMPDIR/cddbchoices"
1983 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
1984 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
1987 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
1994 if checkstatus cddb-edit >/dev/null; then
1995 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
1996 VARIOUSARTISTS="$(checkstatus variousartists)"
1997 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2000 if [ "$INTERACTIVE" = "y" ]; then
2001 # We should show the CDDB results both when we are not using the local CDDB repo
2002 # or when we are using it but we could not find a proper match
2003 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2004 # Display the $ABCDETEMPDIR/cddbchoices file created above
2005 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2006 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2007 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2008 CHOICE=$(checkstatus cddb-choice)
2009 if [ -n "$CHOICE" ] ; then
2010 case $CDDBCHOICES in
2011 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep -q "^$" ; then
2012 log error "CDDB query failed!"
2015 cat "$ABCDETEMPDIR/cddbchoices"
2018 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2020 echo "Selected: #$CHOICE"
2021 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2025 # The user has a choice to make, display the info in a pager if necessary
2026 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2027 page "$ABCDETEMPDIR/cddbchoices"
2029 # It's all going to fit in one page, cat it
2030 cat "$ABCDETEMPDIR/cddbchoices" >&2
2034 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2036 # I'll take CDDB read #3 for $400, Alex
2037 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2038 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2040 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2041 if echo $CDDBCHOICE | egrep -q "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" ; then
2042 if [ ! X"$DIFF" = "X" ]; then
2043 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2044 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2045 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2046 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2047 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2048 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
2050 # We parse the 2 choices to diff, store them in temporary files and diff them.
2051 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2052 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2054 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2055 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2056 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2057 page "$ABCDETEMPDIR/cddbread.diff"
2059 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2063 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2065 elif echo $CDDBCHOICE | egrep -q "[[:space:]]*[[:digit:]]+[[:space:]]*" ; then
2066 # Make sure we get a valid choice
2067 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2068 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2069 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2073 if [ "$CDCHOICENUM" = "0" ]; then
2074 vecho "Creating empty CDDB template..."
2076 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2078 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2079 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2081 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2085 # We need some code to show the selected option when local repository is selected and we have found a match
2086 vecho "Using cached CDDB match..." >&2
2087 # Display the $ABCDETEMPDIR/cddbchoices file created above
2088 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2089 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2090 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2091 CHOICE=$(checkstatus cddb-choice)
2092 if [ "$USELOCALRESP" = "y" ]; then :; else
2093 if [ -n "$CHOICE" ] ; then
2094 case $CDDBCHOICES in
2097 echo "Selected template."
2099 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2101 echo "Selected: #$CHOICE"
2102 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2110 # We're noninteractive - pick the first choice.
2111 # But in case we run a previous instance and selected a choice, use it.
2112 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2113 # Show the choice if we are not using the locally stored one
2114 # or when the local search failed to find a match.
2115 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2116 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2117 #if [ "$PREVIOUSCHOICE" ]; then
2118 cat "$ABCDETEMPDIR/cddbchoices"
2121 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2122 CDCHOICENUM=$PREVIOUSCHOICE
2125 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2127 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2132 if checkstatus cddb-choice >/dev/null; then :; else
2133 echo "abcde: internal error: cddb-choice not recorded." >&2
2136 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2137 echo -n "Edit selected CDDB data? [y/n] (" >&2
2138 if [ "$INTERACTIVE" = "y" ]; then
2139 if [ "$UNKNOWNDISK" = "y" ]; then
2142 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2151 if [ "$EDITCDDB" = "y" ]; then
2152 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2154 # Use the debian sensible-editor wrapper to pick the editor that the
2155 # user has requested via their $EDITOR environment variable
2156 if [ -x "/usr/bin/sensible-editor" ]; then
2157 /usr/bin/sensible-editor "$CDDBDATA"
2158 elif [ -n "$EDITOR" ]; then
2159 if [ -x $(which "${EDITOR%%\ *}") ]; then
2160 # That failed, try to load the preferred editor, starting
2161 # with their EDITOR variable
2162 eval $(echo "$EDITOR") \"$CDDBDATA\"
2164 # If that fails, check for a vi
2165 elif which vi >/dev/null 2>&1; then
2167 elif [ -x /usr/bin/vim ]; then
2168 /usr/bin/vim "$CDDBDATA"
2169 elif [ -x /usr/bin/vi ]; then
2170 /usr/bin/vi "$CDDBDATA"
2171 elif [ -x /bin/vi ]; then
2173 # nano should be on all (modern, i.e., sarge) debian systems
2174 elif which nano >/dev/null 2>&1 ; then
2176 elif [ -x /usr/bin/nano ]; then
2177 /usr/bin/nano "$CDDBDATA"
2178 # mg should be on all OpenBSD systems
2179 elif which mg >/dev/null 2>&1 ; then
2181 elif [ -x /usr/bin/mg ]; then
2182 /usr/bin/mg "$CDDBDATA"
2185 log warning "no editor available. Check your EDITOR environment variable."
2187 # delete editor backup file if it exists
2188 if [ -w "$CDDBDATA~" ]; then
2193 # Some heuristics first. Look at Disc Title, and if it starts with
2194 # "Various", then we'll assume Various Artists
2195 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2196 echo "Looks like a Multi-Artist CD" >&2
2199 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2200 if [ "$INTERACTIVE" = "y" ]; then
2207 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2210 # Need NUMTRACKS before cddb-tool will return it:
2211 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2212 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2213 # More than 1/2 tracks contain a "/", so guess forward
2215 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2216 # More than 1/2 contain a "-", so guess forward-dash
2218 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2219 # More than 1/2 contain something in parens, so guess trailing-paren
2223 echo "1) Artist / Title" >&2
2224 echo "2) Artist - Title" >&2
2225 echo "3) Title / Artist" >&2
2226 echo "4) Title - Artist" >&2
2227 echo "5) Artist: Title" >&2
2228 echo "6) Title (Artist)" >&2
2229 echo "7) This is a single-artist CD" >&2
2230 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2231 if [ "$INTERACTIVE" = "y" ]; then
2232 read VARIOUSARTISTSTYLE
2234 echo $DEFAULTSTYLE >&2
2235 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2237 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2238 # If they press Enter, then the default style (0) was chosen
2239 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2240 echo "Invalid selection. Please choose a number between 1 and 7."
2241 echo -n "Selection [1-7]: "
2242 read VARIOUSARTISTSTYLE
2243 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2245 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2246 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2248 vecho "Selected: $VARIOUSARTISTSTYLE"
2249 case "$VARIOUSARTISTSTYLE" in
2251 VARIOUSARTISTSTYLE=forward
2254 VARIOUSARTISTSTYLE=forward-dash
2257 VARIOUSARTISTSTYLE=reverse
2260 VARIOUSARTISTSTYLE=reverse-dash
2263 VARIOUSARTISTSTYLE=colon
2266 VARIOUSARTISTSTYLE=trailing-paren
2274 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2275 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2277 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2278 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2279 # This works but does not have the necessary error checking
2280 # yet. If you are familiar with the CDDB spec
2281 # (see http://www.freedb.org/src/latest/DBFORMAT)
2282 # and can create an error-free entry on your own, then put
2283 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2284 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2285 # your abcde.conf to change the email address submissions are
2288 # submit the modified file, if they want
2289 if [ "$NOSUBMIT" != "y" ]; then
2290 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2292 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2293 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2295 echo -n 'Invalid selection. Please answer "y" or "n": '
2298 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2299 echo -n "Sending..."
2300 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2307 # User CDDBLOCALPOLICY to find out if we store the file or not...
2308 # Cache edited CDDB entry in the user's cddb dir
2309 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2310 # Make sure the cache directory exists
2311 mkdir -p $CDDBLOCALDIR
2312 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2315 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2318 # do_cdread [tracknumber]
2319 # do_cdread onetrack [firsttrack] [lasttrack]
2323 # The commands here don't go through run_command because they're never supposed to be silenced
2324 # return codes need to be doublechecked anyway, however
2325 if [ "$1" = "onetrack" ]; then
2326 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2327 # FIXME # Until then, we grab the whole CD in one track, no matter what
2329 # We need the first and last track for cdda2wav
2331 LASTTRACK=$(expr $3 + 0)
2332 UTRACKNUM=$FIRSTTRACK
2333 case "$CDROMREADERSYNTAX" in
2334 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2335 cdparanoia) READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2336 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
2337 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2343 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2344 if [ "$USEPIPES" = "y" ]; then
2345 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
2346 FILEARG="$( eval echo "\$$TEMPARG" )"
2348 PIPE_MESSAGE="and encoding "
2350 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2351 case "$CDROMREADERSYNTAX" in
2352 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2354 FILEARG="--output-name=$WAVDATA"
2357 FILEARG="-f $WAVDATA"
2365 if [ "$1" = "onetrack" ]; then
2366 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2368 if [ -r "$CDDBDATA" ]; then
2369 do_getcddbinfo TRACKNAME
2370 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2372 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2375 case "$CDROMREADERSYNTAX" in
2376 ### FIXME ### use an exception for flac, since it uses -o
2377 ### FIXME ### Shall we just use -o $FILEARG ??
2379 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2380 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
2381 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2383 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2385 if [ "$OSFLAVOUR" = "OSX" ] ; then
2386 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2387 disktool -u ${CDROM#/dev/} 0
2388 # Also, in OSX the cdrom device for cdda2wav changes...
2389 CDDA2WAVCDROM="IODVDServices"
2390 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2391 CDDA2WAVCDROM="$CDROMID"
2393 if [ "$CDROMID" = "" ]; then
2394 CDDA2WAVCDROM="$CDROM"
2396 CDDA2WAVCDROM="$CDROMID"
2399 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2401 ## FIXME ## We have an exception for dagrab, since it uses -f
2402 ## FIXME ## Shall we just use -f $FILEARG ??
2403 dagrab) nice $READNICE $CDROMREADER -d $CDROM -v $UTRACKNUM "$FILEARG" $REDIR
2406 # Find the track's mounted path
2407 REALTRACKNUM=$(expr $UTRACKNUM + 0)
2408 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
2409 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2410 # If the file exists, copy it
2411 if [ -e "$FILEPATH" ] ; then
2412 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2416 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS $CDROM -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2420 # If we get some error or we get some missing wav
2421 # (as long as we dont use pipes)
2422 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
2423 # Thank goodness errors is only machine-parseable up to the
2424 # first colon, otherwise this woulda sucked
2425 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2426 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2428 if [ "$USEPIPES" = "y" ]; then
2429 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2431 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2435 if [ "$USEPIPES" = "y" ]; then
2436 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2438 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2440 if [ "$1" = "onetrack" ]; then
2441 echo onetrack >> "$ABCDETEMPDIR/status"
2447 # No values accepted, only uses env variables
2450 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
2451 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
2453 echo "abcde: unable to set the device speed" >&2
2459 # vecho outputs a message if EXTRAVERBOSE is selected
2462 if [ x"$EXTRAVERBOSE" != "x" ]; then
2464 warning) shift ; log warning "$@" ;;
2472 # decho outputs a debug message if DEBUG is selected
2475 if [ x"$DEBUG" != "x" ]; then
2476 if echo $1 | grep -q "^\[" ; then
2477 DEBUGECHO=$(echo "$@" | tr -d '[]')
2478 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2485 # User-redefinable functions
2486 # Custom filename munging:
2489 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2490 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
2493 # Custom genre munging:
2496 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2500 # Empty pre_read function, to be defined in the configuration file.
2507 # Empty post_read function, to be defined in the configuration file.
2513 ###############################################################################
2516 # Start of execution
2517 ###############################################################################
2522 # Defaults to FreeDB, but a python musicbrainz can be used
2524 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2525 CDDBSUBMIT=freedb-submit@freedb.org
2527 HELLOINFO="$(whoami)@$(hostname)"
2529 CDDBLOCALPOLICY="always"
2530 CDDBLOCALRECURSIVE="y"
2531 CDDBLOCALDIR="$HOME/.cddb"
2534 # List of fields we parse and show during the CDDB parsing...
2535 SHOWCDDBFIELDS="year,genre"
2538 #CDROMREADERSYNTAX=cdparanoia
2539 ENCODERSYNTAX=default
2541 MP3ENCODERSYNTAX=default
2542 OGGENCODERSYNTAX=default
2543 FLACENCODERSYNTAX=default
2544 SPEEXENCODERSYNTAX=default
2545 MPPENCODERSYNTAX=default
2546 AACENCODERSYNTAX=default
2547 NORMALIZERSYNTAX=default
2548 CUEREADERSYNTAX=default
2550 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2551 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2552 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2553 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2554 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2555 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2556 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2557 PLAYLISTDATAPREFIX=''
2558 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2559 VAPLAYLISTDATAPREFIX=''
2567 VARIOUSARTISTSTYLE=forward
2573 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2574 # i.e. CDROMID="1,0,0"
2576 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2577 # If we are using the ide-scsi emulation layer, we need to define a "g"
2578 CDPARANOIACDROMBUS="d"
2580 # program paths - defaults to checking your $PATH
2587 XINGMP3ENC=xingmp3enc
2604 CDPARANOIA=cdparanoia
2610 MUSICBRAINZ=musicbrainz-get-tracks
2614 VORBISCOMMENT=vorbiscomment
2616 NORMALIZE=normalize-audio
2618 VORBISGAIN=vorbisgain
2624 CUE2DISCID=cue2discid
2626 # Options for programs called from abcde
2661 VORBISCOMMENTOPTS="-R"
2662 METAFLACOPTS="--no-utf8-convert"
2665 # Default to one process if -j isn't specified
2668 # List of actions to perform - by default, run to completion
2669 ACTIONS=cddb,read,encode,tag,move,clean
2671 # This option is basicaly for Debian package dependencies:
2672 # List of prefered outputs - by default, run with whatever we have in the path
2673 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:lame,mp3:bladeenc,spx:speex
2675 # List of prefered cdromreaders - by default, run whichever we have in the path
2676 DEFAULT_CDROMREADERS="cdparanoia cdda2wav"
2678 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for Linux/OpenBSD/NetBSD.
2679 # Let's use these checkings to determine the OS flavour, which will be used later
2680 if [ X$(uname) = "XFreeBSD" ] ; then
2685 elif [ X$(uname) = "XDarwin" ] ; then
2688 # We should have disktool in OSX, but let's be sure...
2690 CDROMREADERSYNTAX=cddafs
2691 elif [ X$(uname) = "XOpenBSD" ] ; then
2694 elif [ X$(uname) = "XNetBSD" ] ; then
2701 # If CDDBAVAIL is set to n, no CDDB read is done
2702 # If USEID3 is set to n, no ID3 tagging is done
2707 if [ -z "$OUTPUTDIR" ]; then
2711 if [ -z "$WAVOUTPUTDIR" ]; then
2712 WAVOUTPUTDIR="$OUTPUTDIR"
2715 # Load system defaults
2716 if [ -r /etc/abcde.conf ]; then
2719 # Load user preference defaults
2720 if [ -r $HOME/.abcde.conf ]; then
2724 # By this time, we need some HTTPGETOPTS already defined.
2725 # If the user has defined a non-default HTTPGET method, we should not be empty.
2727 if [ "$HTTPGETOPTS" = "" ] ; then
2729 wget) HTTPGETOPTS="-q -O -";;
2730 curl) HTTPGETOPTS="-f -s";;
2731 fetch)HTTPGETOPTS="-q -o -";;
2732 ftp) HTTPGETOPTS="-q -o -";;
2733 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
2737 # If the CDROM has not been set yet, find a suitable one.
2738 # If this is a devfs system, default to /dev/cdroms/cdrom0
2739 # instead of /dev/cdrom
2740 if [ "$CDROM" = "" ] ; then
2741 if [ -e /dev/cdroms/cdrom0 ]; then
2742 CDROM=/dev/cdroms/cdrom0
2743 elif [ -e /dev/cdrom ]; then
2745 elif [ -e /dev/cd0c ]; then
2747 elif [ -e /dev/acd0c ]; then
2749 elif [ -e /dev/disk1 ]; then
2754 # Parse command line options
2755 #while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
2756 while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:uvVxw:W:z opt ; do
2759 a) ACTIONS="$OPTARG" ;;
2760 A) EXPACTIONS="$OPTARG" ;;
2762 B) NOBATCHREPLAYGAIN=y ;;
2763 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
2764 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
2765 d) CDROM="$OPTARG" ;;
2767 e) ERASEENCODEDSTATUS=y ;;
2769 e) ERASEENCODEDSTATUS=y ;;
2770 E) ENCODING="$OPTARG" ;;
2774 j) MAXPROCS="$OPTARG" ;;
2777 L) CDDBUSELOCAL=y ;;
2782 o) OUTPUTTYPE="$OPTARG" ;;
2785 r) REMOTEHOSTS="$OPTARG" ;;
2786 R) DOREPLAYGAIN=y ;;
2787 s) SHOWCDDBFIELDS="$OPTARG" ;;
2788 S) CDSPEEDVALUE="$OPTARG" ;;
2789 t) STARTTRACKNUMBER="$OPTARG" ;;
2790 T) STARTTRACKNUMBER="$OPTARG" ; STARTTRACKNUMBERTAG="y" ;;
2793 echo "This is abcde v$VERSION."
2794 echo "Usage: abcde [options] [tracks]"
2795 echo "abcde -h for extra help"
2798 V) EXTRAVERBOSE="y" ;;
2800 w) COMMENT="$OPTARG" ;;
2801 W) if echo $OPTARG | grep -q "[[:digit:]]" ; then
2802 STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
2804 log error "argument of -W must be integer"
2808 z) DEBUG=y ; CDROMREADERSYNTAX=debug ; EJECTCD="n" ;;
2813 shift $(($OPTIND - 1))
2815 # If the user specified a flac file, then switch to special flac mode
2816 if echo $CDROM | grep -i -q '.flac$'; then
2817 vecho warning "abcde: switching to flac CDROMREADERSYNTAX..."
2818 CDROMREADERSYNTAX=flac
2819 # Added a need on CUE2DISCID until we manage to convert the python script to bash.
2825 # If the user provided a DISCID, disable eject
2826 if [ -n "$DISCID" ] || [ "$CDROMREADERSYNTAX" = "flac" ]; then EJECTCD=n ; fi
2828 # Check the available cd rippers in the system, from the ones we know.
2829 if [ "$CDROMREADERSYNTAX" = "" ]; then
2830 for DEFAULT_CDROMREADER in $DEFAULT_CDROMREADERS; do
2831 if [ -x $( which $DEFAULT_CDROMREADER ) ]; then
2832 CDROMREADERSYNTAX=$DEFAULT_CDROMREADER
2836 if [ "$CDROMREADERSYNTAX" = "" ]; then
2837 log error "no cdreader found in your PATH"
2838 log error "hints: are all dependencies installed? has the \$PATH been modified?"
2843 # Decide if we can continue.
2844 if [ "$ONETRACK" = "y" ]; then
2845 # FIXME # remove check as soon as we find out about the other readers
2846 case "$CDROMREADERSYNTAX" in
2850 *) log error "$CDROMREADERSYNTAX does not support ONETRACK mode"
2853 if [ "$BATCHNORM" = "y" ]; then
2854 log warning "BATCHNORM mode is not compatible with ONETRACK mode. Disabling..."
2857 if [ "$NOGAP" = "y" ]; then
2858 log warning "NOGAP mode is not compatible with ONETRACK mode. Disabling..."
2861 # It does not matter how many tracks we want. In ONETRACK mode we grab them all
2862 # FIXME # allow ranges of tracks to be selected for onetrack ripping
2863 if [ $# -gt 0 ]; then
2864 log warning "ONETRACK mode selected, grabbing all tracks..."
2867 while [ $# -gt 0 ]; do
2868 # Range parsing code courtesy of Vincent Ho
2869 RSTART=$(echo $1 | cut -f1 -d-)
2870 REND=$(echo $1 | cut -f2 -d-)
2871 if [ "$RSTART" = "$REND" ]; then
2874 NEWTRACKS=$(f_seq_line $RSTART $REND)
2876 TRACKQUEUE=$(echo "$TRACKQUEUE" "$NEWTRACKS")
2881 # List of valid actions: cddb,read,normalize,encode,tag,move,playlist,clean
2882 # List of experimental actions: retag,transcode
2884 # Determine what actions are to be done from $ACTIONS and set the
2885 # following environment variables for them:
2898 for ACTION in $(echo $ACTIONS | tr , \ )
2903 normalize) DONORMALIZE=y; DOREAD=y;;
2904 # preprocess) DOPREPROCESS=y; DOREAD=y;;
2905 encode) DOENCODE=y; DOREAD=y;;
2906 # postprocess) DOPREPROCESS=y; DOENCODE=y; DOREAD=y;;
2907 tag) DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2908 move) DOMOVE=y; DOTAG=y; DOREAD=y; DOENCODE=y; DOCDDB=y;;
2909 replaygain) DOCDDB=y; DOREAD=y; DOENCODE=y; DOTAG=y; DOMOVE=y; DOREPLAYGAIN=y;;
2910 playlist) DOCDDB=y; DOPLAYLIST=y;;
2915 if [ "$DONORMALIZE" = "y" ] && [ "$DOREPLAYGAIN" = "y" ]; then
2916 # FIXME # should we abort on error or just inform the user?
2917 log warning "selected both normalize and replaygain actions"
2920 for SHOWCDDBFIELD in $(echo $SHOWCDDBFIELDS | tr , \ ); do
2921 case $SHOWCDDBFIELD in
2922 y*|Y*) SHOWCDDBYEAR="y";;
2923 g*|G*) SHOWCDDBGENRE="y";;
2930 # At this point a CDROM has to be defined, so we check it exists.
2931 if [ X"$CDROM" != "X" ] ; then
2932 if [ "$CDROMREADERSYNTAX" = "cdda2wav" ] && [ "$NEEDCDROMID" = "y" ] ; then
2933 if [ "$OSFLAVOUR" = "FBSD" ]; then
2934 if ! echo "$CDROMID" | grep "^[0-9],[0-9],[0-9]$" >/dev/null 2>&1 ; then
2935 log error "CDROMID not in the right format for $CDROMREADERSYNTAX"
2936 log error "Use \"cdrecord -scanbus\" to obtain a adecuate ID an set CDROMID accordingly"
2940 elif [ ! -e "$CDROM" -a X"$DOREAD" = "Xy" ]; then
2941 log error "CDROM device cannot be found."
2944 # avoid processing if we are not going to hit the CDROM.
2945 elif [ X"$DOREAD" = "Xy" ]; then
2946 log error "CDROM has not been defined or cannot be found"
2950 # USEPIPES pre-tests, before we get into more serious stuff
2951 # Not compatible with:
2952 # - multiple outputs
2954 # - lowdisk algorithm
2956 if [ X"$USEPIPES" = "Xy" ]; then
2957 if [ $(echo "$OUTPUTTYPE" | tr , \ | wc -w ) -gt 1 ]; then
2958 log error "Unix pipes not compatible with multiple outputs"
2961 if [ X"$DONORMALIZE" = "Xy" ]; then
2962 log error "Unix pipes not compatible with normalizer"
2963 # FIXME # Do we need to exit or shall we just disable the mode?
2966 if [ X"$BATCHNORM" = "Xy" ]; then
2967 log error "Unix pipes not compatible with BATCHNORM encoding"
2970 if [ X"$NOGAP" = "Xy" ]; then
2971 log error "Unix pipes not compatible with NOGAP encoding"
2974 if [ X"$DOENCODE" = "Xn" ]; then
2975 vecho warning "Disabling Unix pipes since we are not encoding!"
2978 if [ X"$LOWDISK" = "Xy" ]; then
2979 log error "Unix pipes not compatible with lowdisk algorithm"
2984 # LOWDISK pre-tests, before we get into more problematic stuff
2985 # Not compatible with anything that needs all the files in the hard disc:
2988 if [ X"$LOWDISK" = "Xy" ]; then
2989 if [ X"$BATCHNORM" = "Xy" ]; then
2990 log error "Unix pipes not compatible with BATCHNORM encoding"
2993 if [ X"$NOGAP" = "Xy" ]; then
2994 log error "Unix pipes not compatible with NOGAP encoding"
2999 # BATCHNORM pre-tests, before we get into serious problems
3000 # Not compatible with
3001 if [ "$BATCHNORM" = "y" ] && [ "$DONORMALIZE" = "n" ]; then
3002 vecho warning "Disabling BATCHNORM since we are not normalizing!"
3006 # Check the encoding format from the ones available in the system, if nothing has been configured in the system.
3007 if [ X"$OUTPUTTYPE" = "X" ]; then
3008 for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
3009 DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
3010 DEFAULT_OUTPUT_BINARY="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 2)"
3011 if [ -x $(which $DEFAULT_OUTPUT_BINARY) ] ; then
3012 OUTPUTTYPE=$DEFAULT_OUTPUT_FORMAT
3013 vecho "No default output type defined. Autoselecting $OUTPUTTYPE..." >&2
3017 if [ X"$OUTPUTTYPE" = "X" ]; then
3018 log error "no encoder found in the PATH"
3019 log error "hints: are all dependencies installed? has the \$PATH been modified?"
3024 # Decide which CDROM reader we're gonna use
3025 case "$CDROMREADERSYNTAX" in
3027 CDROMREADER="$CDPARANOIA"
3028 CDROMREADEROPTS="$CDPARANOIAOPTS"
3031 CDROMREADER="$CDDA2WAV"
3032 CDROMREADEROPTS="$CDDA2WAVOPTS"
3035 CDROMREADER="$DAGRAB"
3036 CDROMREADEROPTS="$DAGRABOPTS"
3039 CDROMREADER="$CDDAFS"
3040 CDROMREADEROPTS="$CDDAFSOPTS"
3044 CDROMREADEROPTS="$FLACOPTS"
3048 # There's only one normalize...
3049 case "$NORMALIZERSYNTAX" in
3051 NORMALIZER="$NORMALIZE"
3052 NORMALIZEROPTS="$NORMALIZEOPTS"
3056 # Allow -o OUTPUT(1):OPTIONS(1),...,OUTPUT(N):OPTIONS(N) mode of operation
3057 if echo "$OUTPUTTYPE" | grep ":" > /dev/null 2>&1 ; then
3058 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
3060 vorbis:*|ogg:*) OGGENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3061 mp3:*) MP3ENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3062 flac:*) FLACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3063 spx:*) SPEEXENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3064 mpc:*) MPPENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3065 m4a:*) AACENCODEROPTSCLI="$( echo $OUTPUT | cut -d: -f2- )" ;;
3068 for OUTPUT in "$(echo "$OUTPUTTYPE" | tr , \ )"; do
3069 TEMPOUTPUT=$( echo "$OUTPUT" | cut -d: -f1 )
3070 TEMPOUTPUTTYPE="${TEMPOUTPUTTYPE:+$TEMPOUTPUTTYPE,}$TEMPOUTPUT"
3072 OUTPUTTYPE="$TEMPOUTPUTTYPE"
3075 # If nothing has been specified, use oggenc for oggs and lame for mp3s and flac
3076 # for flacs and speexenc for speex and mppenc for mpps and faac for m4as
3078 # Getting ready for multiple output changes
3079 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
3083 [ "$OGGENCODERSYNTAX" = "default" ] && OGGENCODERSYNTAX=oggenc
3084 [ "$DOTAG" = "y" ] && NEEDCOMMENTER=y
3085 [ "$DOREPLAYGAIN" = "y" ] && NEEDVORBISGAIN=y
3086 OGGOUTPUTCONTAINER=ogg
3089 [ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
3090 [ "$DOTAG" = "y" ] && NEEDTAGGER=y
3091 [ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
3094 [ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
3095 [ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
3096 [ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
3099 [ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
3100 # [ "$DOREPLAYGAIN" = "y" ] &&
3103 [ "$MPPENCODERSYNTAX" = "default" ] && MPPENCODERSYNTAX=mppenc
3104 [ "$DOREPLAYGAIN" = "y" ] && NEEDMPPGAIN=y
3107 [ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
3110 if [ "$KEEPWAVS" = "y" ]; then
3111 vecho "Unsetting the KEEPWAVS option, since the resulting wav files were requested..."
3115 *) log error "Invalid OUTPUTTYPE defined"
3121 # decide which encoder
3122 case "$MP3ENCODERSYNTAX" in
3124 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$LAMEOPTS}"
3128 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$TOOLAMEOPTS}"
3129 MP3ENCODER="$TOOLAME"
3132 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$GOGOOPTS}"
3136 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$BLADEENCOPTS}"
3137 MP3ENCODER="$BLADEENC"
3140 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$L3ENCOPTS}"
3144 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$XINGMP3ENCOPTS}"
3145 MP3ENCODER="$XINGMP3ENC"
3148 MP3ENCODEROPTS="${MP3ENCODEROPTSCLI:-$MP3ENCOPTS}"
3149 MP3ENCODER="$MP3ENC"
3152 case "$OGGENCODERSYNTAX" in
3154 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$VORBIZEOPTS}"
3155 OGGENCODER="$VORBIZE"
3158 OGGENCODEROPTS="${OGGENCODEROPTSCLI:-$OGGENCOPTS}"
3159 OGGENCODER="$OGGENC"
3162 case "$FLACENCODERSYNTAX" in
3164 FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
3166 # FLAC streams can be encapsulated on a Ogg transport layer
3167 if echo "$FLACENCODEROPTS" | egrep -q -- "(^| )--ogg($| )" ;then
3168 log error "FLAC on an Ogg container is not yet supported"
3169 log error "due to problem with adding comments to such files"
3171 FLACOUTPUTCONTAINER=ogg
3173 FLACOUTPUTCONTAINER=flac
3177 case "$SPEEXENCODERSYNTAX" in
3179 SPEEXENCODEROPTS="${SPEEXENCODEROPTSCLI:-$SPEEXENCOPTS}"
3180 SPEEXENCODER="$SPEEXENC"
3183 case "$MPPENCODERSYNTAX" in
3185 MPPENCODEROPTS="${MPPENCODEROPTSCLI:-$MPPENCOPTS}"
3186 MPPENCODER="$MPPENC"
3189 case "$AACENCODERSYNTAX" in
3191 AACENCODEROPTS="${AACENCODEROPTSCLI:-$AACENCOPTS}"
3192 AACENCODER="$AACENC"
3197 if [ "$ID3TAGV" = "1" ]; then
3199 TAGGEROPTS="$ID3OPTS"
3202 TAGGEROPTS="$ID3V2OPTS"
3205 # Specific for NOGAP is the use of lame. Another encoder fails...
3206 if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
3207 log warning "the NOGAP option is specific of lame. Deactivating..."
3212 case "$CUEREADERSYNTAX" in
3214 CUEREADEROPTS="${CDROM}"
3219 # which information retrieval tool are we using?
3225 # Check if both OGGEOUTPUTCONTAINER and FLACOUTPUTCONTAINER are the same, and differentiante them
3226 if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ]; then
3227 log error "FLAC on an Ogg container is not yet supported"
3228 log error "due to problem with adding comments to such files"
3230 OGGOUTPUTCONTAINER=ogg.ogg
3231 FLACOUTPUTCONTAINER=flac.ogg
3232 vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
3235 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
3237 if [ "$ENCNICE" ]; then
3238 ENCNICE="-n $ENCNICE"
3240 if [ "$READNICE" ]; then
3241 READNICE="-n $READNICE"
3243 if [ "$DISTMP3NICE" ]; then
3244 DISTMP3NICE="-n $DISTMP3NICE"
3247 # Don't check for stuff if it's not needed