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.
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 " WARNING: Deprecated. Use \"cue\" action"
50 #echo "-M Create a CUE file"
51 echo "-o <type1[,type2]...>"
52 echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
53 echo "-p Pad track numbers with 0's (if less than 10 tracks)"
54 echo "-P Use UNIX pipes to read+encode without wav files"
56 echo " Set quality level (high,medium,low)"
57 echo "-r <host1[,host2]...>"
58 echo " Also encode on these remote hosts"
59 echo "-R Use local CDDB in recursive mode"
61 echo " Show fields from the CDDB info (year,genre)"
62 echo "-S <#> Set the CD speed"
63 echo "-t <#> Start the track numbering at a given number"
64 echo "-T <#> Same as -t but modifies tag numbering"
65 echo "-U Do NOT use UNICODE (UTF8) tags and comments"
66 echo "-v Show version number and exit"
67 echo "-V Be a bit more verbose about what is happening behind the scenes"
68 echo "-x Eject CD after all tracks are read"
70 echo " Add a comment to the CD tracks"
71 echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
72 echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
74 echo "Tracks is a space-delimited list of tracks to grab."
75 echo "Ranges specified with hyphens are allowed (i.e., 1-5)."
77 #echo "Double hyphens are used to concatenate tracks"
82 echo "$@" >> "$ABCDETEMPDIR/status"
85 # log [level] [message]
87 # log outputs the right message in a common format
93 error) echo "[ERROR] abcde: $@" >&2 ;;
94 warning) echo "[WARNING] $@" >&2 ;;
95 info) echo "[INFO] $@" ;;
99 # Funtions to replace the need of seq, which is too distribution dependant.
103 while [ $i -ne `expr $2 + 1` ]
113 if echo $i | grep "[[:digit:]]" > /dev/null 2>&1 ; then
114 while [ $i -ne `expr $2 + 1` ]
121 log error "syntax error while processing track numbers"
126 # Functions to replace the need of awk {print $1} and {print $NF}
129 if [ X"$1" = "X" ]; then
130 for first in `cat`; do
141 if [ X"$1" = "X" ]; then
142 for stdin in `cat`; do
146 for last in $@ ; do :; done
151 # checkstatus [blurb]
152 # Returns "0" if the blurb was found, returns 1 if it wasn't
153 # Puts the blurb content, if available, on stdout.
154 # Otherwise, returns "".
157 # Take the last line in the status file if there's multiple matches
159 BLURB=$(egrep $PATTERN "$ABCDETEMPDIR/status" | tail -n 1)
161 if [ -z "$BLURB" ]; then
166 # See if there's a = in it
167 if [ "$(echo $BLURB | grep -c =)" != "0" ]; then
168 echo "$(echo $BLURB | cut -f2- -d=)"
174 # checkwarnings [blurb]
175 # Returns "0" if the blurb was found (meaning there was an warning),
176 # returns 1 if it wasn't (yes this is a little backwards).
177 # Does not print the blurb on stdout.
178 # Otherwise, returns "".
181 if [ -e "$ABCDETEMPDIR/warnings" ]; then :; else
184 # Take the last line in the status file if there's multiple matches
186 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/warnings" | tail -n 1)"
188 if [ -z "$BLURB" ]; then
189 # negative, we did not have a negative...
192 # affirmative, we had a negative...
197 # checkerrors [blurb]
198 # Returns "0" if the blurb was found (meaning there was an error),
199 # returns 1 if it wasn't (yes this is a little backwards).
200 # Does not print the blurb on stdout.
201 # Otherwise, returns "".
204 if [ -e "$ABCDETEMPDIR/errors" ]; then :; else
207 # Take the last line in the status file if there's multiple matches
209 BLURB="$(egrep $PATTERN "$ABCDETEMPDIR/errors" | tail -n 1)"
211 if [ -z "$BLURB" ]; then
212 # negative, we did not have a negative...
215 # affirmative, we had a negative...
221 # Finds the right pager in the system to display a file
225 # Use the debian sensible-pager wrapper to pick the pager
226 # user has requested via their $PAGER environment variable
227 if [ -x "/usr/bin/sensible-pager" ]; then
228 /usr/bin/sensible-pager "$PAGEFILE"
229 elif [ -x "$PAGER" ]; then
230 # That failed, try to load the preferred editor, starting
231 # with their PAGER variable
233 # If that fails, check for less
234 elif [ -x /usr/bin/less ]; then
235 /usr/bin/less -f "$PAGEFILE"
236 # more should be on all UNIX systems
237 elif [ -x /bin/more ]; then
238 /bin/more "$PAGEFILE"
240 # No bananas, just cat the thing
245 # run_command [blurb] [command...]
246 # Runs a command, silently if necessary, and updates the status file
251 # See if this is supposed to be silent
252 if [ "$(checkstatus encode-output)" = "loud" ]; then
256 # Special case for SMP, since
257 # encoder output is never displayed, don't mute echos
258 if [ -z "$BLURB" -a "$MAXPROCS" != "1" ]; then
267 normalize|normalize-audio)
268 if [ "$RETURN" = "2" ]; then
269 # File was already normalized.
274 if [ "$RETURN" != "0" ]; then
275 # Put an error in the errors file. For various reasons we
276 # can't capture a copy of the program's output but we can
277 # log what we attempted to execute and the error code
278 # returned by the program.
279 if [ "$BLURB" ]; then
282 echo "${TWEAK}returned code $RETURN: $@" >> "$ABCDETEMPDIR/errors"
283 return $RETURN # Do not pass go, do not update the status file
285 if [ "$BLURB" ]; then
286 echo $BLURB >> "$ABCDETEMPDIR/status"
290 # relpath() and slash() are Copyright (c) 1999 Stuart Ballard and
291 # distributed under the terms of the GNU GPL v2 or later, at your option
293 # Function to determine if a word contains a slash.
302 # Function to give the relative path from one file to another.
303 # Usage: relpath fromfile tofile
304 # eg relpath music/Artist/Album.m3u music/Artist/Album/Song.mp3
305 # (the result would be Album/Song.mp3)
306 # Output is relative path to $2 from $1 on stdout
308 # This code has the following restrictions:
309 # Multiple ////s are not collapsed into single /s, with strange effects.
310 # Absolute paths and ../s are handled wrong in FR (but they work in TO)
311 # If FR is a directory it must have a trailing /
319 /*) ;; # No processing is needed for absolute paths
321 # Loop through common prefixes, ignoring them.
322 while slash "$FR" && [ "$(echo "$FR" | cut -d/ -f1)" = "$(echo "$TO" | cut -d/ -f1)" ]
324 FR="$(echo "$FR" | cut -d/ -f2-)"
325 TO="$(echo "$TO" | cut -d/ -f2-)"
327 # Loop through directory portions left in FR, adding appropriate ../s.
330 FR="$(echo "$FR" | cut -d/ -f2-)"
341 if [ ! "$@" = "" ]; then
342 # Cut off any command-line option we added in
343 X=$(echo $@ | cut -d' ' -f2)
344 if [ "$(which $X)" = "" ]; then
346 elif [ ! -x $(which $X) ]; then
355 if [ ! "$@" = "" ]; then
356 # Cut off any command-line option we added in
357 X=$(echo $@ | cut -d' ' -f2)
358 # Test for built-in abcde.function
359 [ "$X" != "${X#abcde.}" ] && type $X >/dev/null 2>&1 && return
360 if [ "$(which $X)" = "" ]; then
361 log error "$X is not in your path." >&2
362 log info "Define the full path to the executable if it exists on your system." >&2
363 if [ -e /etc/debian_release ] ; then
365 oggenc) MISSING_PACKAGE=vorbis-tools ;;
366 lame|flac) MISSING_PACKAGE=$X ;;
368 log info "Hint: apt-get install $MISSING_PACKAGE" >&2
371 elif [ ! -x "$(which $X)" ]; then
372 log error "$X is not executable." >&2
378 # diffentries <filename> <max_value> <entry1>,<entry2>
379 # max_value: the range of entries goes from 1 to <max_value>
384 local CDDBDIFFCHOICES=$1
386 local CDDBDIFFCHOICE="$@"
387 if [ ! X"$DIFF" = "X" ]; then
388 PARSECHOICE1=$(echo $CDDBDIFFCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
389 PARSECHOICE2=$(echo $CDDBDIFFCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
390 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
391 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
392 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
393 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
395 # We parse the 2 choices to diff, store them in temporary files and diff them.
396 for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
397 do_cddbparse "$ABCDETEMPDIR/$FILENAME.$PARSECHOICE" > "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE"
399 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/$FILENAME.diff"
400 $DIFF $DIFFOPTS "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/$FILENAME.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/$FILENAME.diff"
401 if [ $(cat "$ABCDETEMPDIR/$FILENAME.diff" | wc -l) -ge 24 ]; then
402 page "$ABCDETEMPDIR/$FILENAME.diff"
404 cat "$ABCDETEMPDIR/$FILENAME.diff" >&2
408 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
413 # Finds an specific field from cddbinfo
418 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | head -n 1 | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
421 TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
424 grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | perl -p -e 's/\\n/\n/;'
430 # Get the track number we are going to use for different actions
433 if [ -n "$STARTTRACKNUMBER" ] ; then
434 # Get the trackpadding from the current track
435 CURRENTTRACKPADDING=$(echo -n $UTRACKNUM | wc -c)
436 TRACKNUM=$( printf %0.${CURRENTTRACKPADDING}d $(expr ${UTRACKNUM} + ${STARTTRACKNUMBER} - $FIRSTTRACK ))
438 TRACKNUM=${UTRACKNUM}
444 # Calculate cddb disc ids without requiring specialized helper programs.
445 # largely copied from cd-discid and musicbrainz examples. some of the steps
446 # don't make sense, but they're necessary to match the ids generated by other
449 ## FIXME ## Right now, we get 2 frames more than with cue2discid ??
450 # data@petit:~$ sh /tmp/cue2discid /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac
451 # 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
452 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2895
453 # data@petit:~$ metaflac --export-cuesheet-to=- /home/data/tmp/flac/01.Roisin_Murphy--Ruby_Blue.flac| python /home/data/sources/abcde/trunk/examples/cue2discid
454 # 980b4b0c 12 150 21685 37687 53146 80061 97782 124071 144448 160603 173208 197438 201334 2893
456 # Variables: OFFSETS, TRACKS, LEADOUT, [LEADIN]
459 if [ X"$LEADOUT" = "X" ]; then
460 log warning "Error trying to calculate disc ids without lead-out information."
464 # default to a two second lead-in
466 LEADIN=${LEADIN:=150}
468 # number of cdframes per second
471 # reset cddb checksum for cddb disc-id calululation
475 for OFFSET in $(echo $OFFSETS)
477 COOKEDOFFSETS="${COOKEDOFFSETS} $(($OFFSET + $LEADIN))"
479 OFFSETTIME=$(( ($OFFSET + $LEADIN) / $CDFRAMES ))
480 while [ $OFFSETTIME -gt 0 ]; do
481 CDDBCKSUM=$(($CDDBCKSUM + $OFFSETTIME % 10))
482 OFFSETTIME=$(($OFFSETTIME / 10))
487 COOKEDOFFSETS="${COOKEDOFFSETS:1}" # eat the leading space
489 PREGAP=$(($(echo $OFFSETS | cut -f1 -d' ')))
490 TOTALTIME=$(( (($LEADOUT + $LEADIN + $PREGAP) / $CDFRAMES) - (($LEADIN + $PREGAP) / $CDFRAMES)))
492 printf -v HEXSUM "%08lx" $(( ($CDDBCKSUM % 0xff) << 24 | $TOTALTIME << 8 | $TRACKS))
493 TRACKINFO="${HEXSUM} $((TRACKS)) ${COOKEDOFFSETS} $((($LEADOUT + $LEADIN + $IDMAGICNUM) / $CDFRAMES))"
498 if checkstatus replaygain; then :; else
499 run_command "" echo "Adding replygain information..."
500 for TMPOUTPUT in $( echo $OUTPUTTYPE | tr , \ )
504 OUTPUT=$OGGOUTPUTCONTAINER
507 OUTPUT=$FLACOUTPUTCONTAINER
515 for UTRACKNUM in $TRACKQUEUE
517 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
518 getcddbinfo TRACKNAME
520 TRACKFILE="$(mungefilename "$TRACKNAME")"
521 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
522 ALBUMFILE="$(mungefilename "$DALBUM")"
523 GENRE="$(mungegenre "$GENRE")"
524 YEAR=${CDYEAR:-$CDYEAR}
526 if [ "$ONETRACK" = "y" ]; then
527 if [ "$VARIOUSARTISTS" = "y" ]; then
528 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
530 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
533 if [ "$VARIOUSARTISTS" = "y" ]; then
534 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
536 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
539 OUTPUTFILES[$REPLAYINDEX]="$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
540 (( REPLAYINDEX = $REPLAYINDEX + 1 ))
544 run_command replaygain-flac nice $ENCNICE $METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
545 #run_command replaygain-flac true
548 run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN --album "${OUTPUTFILES[@]}"
551 run_command replaygain-mp3 nice $ENCNICE $MP3GAIN -a "${OUTPUTFILES[@]}"
554 run_command replaygain-mpc nice $ENCNICE $MPPGAIN --auto "${OUTPUTFILES[@]}"
559 if checkerrors "replaygain-.{3,6}"; then :; else
560 run_command replaygain true
565 # This code splits the a Various Artist track name from one of the following
568 # forward: Artist / Track
569 # forward-dash: Artist - Track
570 # reverse: Track / Artist
571 # reverse-dash: Track - Artist
572 # colon: Artist: Track
573 # trailing-paren: Artist (Track)
576 # VARIOUSARTISTS, VARIOUSARTISTSTYLE, TRACKNAME, TRACKARTIST
579 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
580 case "$VARIOUSARTISTSTYLE" in
582 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
583 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
584 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
587 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
588 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
589 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
592 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's- / -~-g')"
593 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
594 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
597 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's, - ,~,g')"
598 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
599 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
602 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's-: -~-g')"
603 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
604 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
607 DTITLEARTIST="$(echo "$TRACKNAME" | sed 's,^\(.*\) (\(.*\)),\1~\2,')"
608 TRACKARTIST="$(echo "$DTITLEARTIST" | cut -f2 -d~)"
609 TRACKNAME="$(echo "$DTITLEARTIST" | cut -f1 -d~)"
612 elif [ "$VARIOUSARTISTS" = "y" ] && [ "$ONETRACK" = "y" ]; then
613 TRACKARTIST="Various"
615 TRACKARTIST="$DARTIST"
620 local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
624 "classic rock") id=1 ;;
642 "industrial") id=19 ;;
643 "alternative") id=20 ;;
645 "death metal") id=22 ;;
647 "soundtrack") id=24 ;;
648 "euro-techno") id=25 ;;
652 "jazz+funk") id=29 ;;
655 "classical") id=32 ;;
656 "instrumental") id=33 ;;
660 "sound clip") id=37 ;;
663 "alt. rock") id=40 ;;
668 "meditative") id=45 ;;
669 "instrum. pop") id=46 ;;
670 "instrum. rock") id=47 ;;
674 "techno-indust.") id=51 ;;
675 "electronic") id=52 ;;
677 "eurodance") id=54 ;;
679 "southern rock") id=56 ;;
684 "christian rap") id=61 ;;
685 "pop/funk"|"pop / funk") id=62 ;;
687 "native american") id=64 ;;
690 "psychadelic") id=67 ;;
692 "showtunes") id=69 ;;
696 "acid punk") id=73 ;;
697 "acid jazz") id=74 ;;
701 "rock & roll") id=78 ;;
702 "hard rock") id=79 ;;
704 "folk/rock") id=81 ;;
705 "national folk") id=82 ;;
712 "bluegrass") id=89 ;;
713 "avantgarde") id=90 ;;
714 "gothic rock") id=91 ;;
715 "progress. rock") id=92 ;;
716 "psychadel. rock") id=93 ;;
717 "symphonic rock") id=94 ;;
718 "slow rock") id=95 ;;
721 "easy listening") id=98 ;;
727 "chamber music") id=104 ;;
729 "symphony") id=106 ;;
730 "booty bass") id=107 ;;
732 "porn groove") id=109 ;;
734 "slow jam") id=111 ;;
738 "folklore") id=115 ;;
740 "power ballad") id=117 ;;
741 "rhythmic soul") id=118 ;;
742 "freestyle") id=119 ;;
744 "punk rock") id=121 ;;
745 "drum solo") id=122 ;;
746 "a capella") id=123 ;;
747 "euro-house") id=124 ;;
748 "dance hall") id=125 ;;
750 "drum & bass") id=127 ;;
751 "club-house") id=128 ;;
752 "hardcore") id=129 ;;
756 "negerpunk") id=133 ;;
757 "polsk punk") id=134 ;;
759 "christian gangsta rap") id=136 ;;
760 "heavy metal") id=137 ;;
761 "black metal") id=138 ;;
762 "crossover") id=139 ;;
763 "contemporary christian")id=140 ;;
764 "christian rock") id=141 ;;
765 "merengue") id=142 ;;
767 "thrash metal") id=144 ;;
770 "synthpop") id=147 ;;
771 "rock/pop"|"rock / pop") id=148 ;;
778 # do_tag [tracknumber]
779 # id3 tags a filename
781 # TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC, ATOMICPARSLEY
782 # COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
785 COMMENTOUTPUT="$(eval echo ${COMMENT})"
786 if [ -z "$COMMENTOUTPUT" ]; then
787 COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
789 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
790 run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
791 # If we want to start the tracks with a given number, we need to modify the
792 # TRACKNUM value before evaluation
793 if [ -n "$STARTTRACKNUMBERTAG" ] ; then
796 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
800 # id3v2 v0.1.9 claims to have solved the -c bug, so we merge both id3 and id3v2
801 GENREID=$(do_getgenreid "${CDGENRE}")
806 # FIXME # track numbers in mp3 come with 1/10, so we cannot
807 # happily substitute them with $TRACKNUM
808 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
809 --comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
810 -a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
811 -G "$GENREID" -n "${TRACKNUM:-$1}" \
812 "${TRACKNUM:+-N $TRACKS}" \
813 "${ENCODING:+--set-encoding=$ENCODING}" \
814 "$ABCDETEMPDIR/track$1.$OUTPUT"
816 # FIXME # Still not activated...
818 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
819 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
820 -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" \
821 -y "$CDYEAR" -g "$GENREID" -k "${TRACKNUM:-$1}" \
822 "$ABCDETEMPDIR/track$1.$OUTPUT"
825 # FIXME # track numbers in mp3 come with 1/10, so we cannot
826 # happily substitute them with $TRACKNUM
827 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
828 $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
829 -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
830 -y "$CDYEAR" -g "$GENREID" \
831 -T "${TRACKNUM:-$1/$TRACKS}" \
832 "$ABCDETEMPDIR/track$1.$OUTPUT"
837 case "$OGGENCODERSYNTAX" in
839 # vorbiscomment can't do in-place modification, mv the file first
840 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" -a ! -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" ]; then
841 mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
845 # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
847 echo ARTIST="$TRACKARTIST"
849 echo TITLE="$TRACKNAME"
850 if [ -n "$CDYEAR" ]; then
853 if [ -n "$CDGENRE" ]; then
854 echo GENRE="$CDGENRE"
856 echo TRACKNUMBER=${TRACKNUM:-$1}
857 if [ -n "$DISCNUMBER" ]; then
858 echo DISCNUMBER="$DISCNUMBER"
860 echo CDDB=$CDDBDISCID
861 if [ "$(eval echo ${COMMENT})" != "" ]; then
862 case "$COMMENTOUTPUT" in
863 *=*) echo "$COMMENTOUTPUT";;
864 *) echo COMMENT="$COMMENTOUTPUT";;
867 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
868 $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
869 "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
870 # Doublecheck that the commented file was created
871 # successfully before wiping the original
872 if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
873 rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
875 mv "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
882 echo ARTIST="$TRACKARTIST"
884 echo TITLE="$TRACKNAME"
885 if [ -n "$CDYEAR" ]; then
888 if [ -n "$CDGENRE" ]; then
889 echo GENRE="$CDGENRE"
891 echo TRACKNUMBER="${TRACKNUM:-$1}"
892 if [ -n "$DISCNUMBER" ]; then
893 echo DISCNUMBER="$DISCNUMBER"
895 echo CDDB="$CDDBDISCID"
896 if [ "$(eval echo ${COMMENT})" != "" ]; then
897 case "$COMMENTOUTPUT" in
898 *=*) echo "$COMMENTOUTPUT";;
899 *) echo COMMENT="$COMMENTOUTPUT";;
902 ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="$ABCDETEMPDIR/$CUEFILE"} --import-tags-from=- "$ABCDETEMPDIR/track$1.$FLACOUTPUTCONTAINER"
905 run_command tagtrack-$OUTPUT-$1 true
908 run_command tagtrack-$OUTPUT-$1 true
911 # Use a temp-file of our choice. --overWrite seems to
912 # case core dumps with AtomicParsley 0.9.0
913 ATOMICTEMPFILE="$ABCDETEMPDIR/track$1.m4a-atomic"
916 if [ "$VARIOUSARTISTS" = "y" ]; then
920 #It has to be command file opts for AtomicParsley
921 run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $ATOMICPARSLEY $ABCDETEMPDIR/track$1.m4a --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --tracknum ${TRACKNUM:-$1} --year "$CDYEAR" --genre "$CDGENRE" --compilation $VARIOUSBOOL --comment "$COMMENTOUTPUT" --output $ATOMICTEMPFILE
922 if [ -f $ATOMICTEMPFILE ]; then
923 mv "$ATOMICTEMPFILE" "$ABCDETEMPDIR/track$1.m4a"
927 run_command tagtrack-$OUTPUT-$1 true
931 if checkerrors "tagtrack-(.{3,6})-$1"; then :; else
932 run_command tagtrack-$1 true
939 # OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
942 # The commands here don't go through run_command because they're never
943 # supposed to be silenced
944 echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
945 for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
949 case "$MP3ENCODERSYNTAX" in
954 for UTRACKNUM in $TRACKQUEUE
956 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
958 nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
960 if [ "$RETURN" != "0" ]; then
961 echo "nogap-encode: $ENCODER returned code $RETURN" >> errors
963 for UTRACKNUM in $TRACKQUEUE
965 run_command encodetrack-$OUTPUT-$UTRACKNUM true
966 #run_command encodetrack-$UTRACKNUM true
975 if checkerrors "nogap-encode"; then :; else
976 if [ ! "$KEEPWAVS" = "y" ] ; then
977 if [ ! "$KEEPWAVS" = "move" ] ; then
982 # Other encoders fall through to normal encoding as the tracks have not
983 # been entered in the status file.
986 # do_encode [tracknumber] [hostname]
987 # If no hostname is specified, encode locally
989 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
992 if [ "$USEPIPES" = "y" ]; then
995 TEMPARG="PIPE_$MP3ENCODERSYNTAX"
998 TEMPARG="PIPE_$OGGENCODERSYNTAX"
1001 TEMPARG="PIPE_$FLACENCODERSYNTAX"
1004 TEMPARG="PIPE_$SPEEXENCODER"
1007 TEMPARG="PIPE_$MPPENCODER"
1010 TEMPARG="PIPE_$MPPENCODER"
1013 IN="$( eval echo "\$$TEMPARG" )"
1015 IN="$ABCDETEMPDIR/track$1.wav"
1018 case "$MP3ENCODERSYNTAX" in
1019 # FIXME # check if mp3enc needs -if for pipes
1020 # FIXME # I have not been able to find a working mp3enc binary
1034 # We need IN to proceed, if we are not using pipes.
1035 if [ -s "$IN" -o X"$USEPIPES" = "Xy" ] ; then
1036 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1038 case "$TMPOUTPUT" in
1040 OUTPUT=$OGGOUTPUTCONTAINER
1043 OUTPUT=$FLACOUTPUTCONTAINER
1049 OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1050 if [ "$NOGAP" = "y" ] && checkstatus encodetrack-$OUTPUT-$1 ; then
1053 if [ X"$USEPIPES" = "Xy" ]; then
1055 # We need a way to store the creation of the files when using PIPES
1056 RUN_COMMAND_PIPES="run_command encodetrack-$OUTPUT-$1 true"
1057 # When pipping it does not make sense to have a higher nice for
1058 # reading than for encoding, since it will be hold by the
1059 # encoding process. Setting an effective nice, to calm down a
1060 # bit the reading process.
1061 EFFECTIVE_NICE=$READNICE
1063 run_command '' echo "Encoding track $1 of $TRACKS: $TRACKNAME..."
1064 RUN_COMMAND="run_command encodetrack-$OUTPUT-$1"
1065 EFFECTIVE_NICE=$ENCNICE
1071 case "$MP3ENCODERSYNTAX" in
1072 lame|toolame|gogo) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS "$IN" "$OUT" ;;
1073 bladeenc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER $MP3ENCODEROPTS -quit "$IN" ;;
1074 l3enc|xingmp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER "$IN" "$OUT" $MP3ENCODEROPTS ;;
1075 # FIXME # Relates to the previous FIXME since it might need the "-if" removed.
1076 mp3enc) $RUN_COMMAND nice $EFFECTIVE_NICE $MP3ENCODER -if "$IN" -of "$OUT" $MP3ENCODEROPTS ;;
1080 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1087 case "$OGGENCODERSYNTAX" in
1088 vorbize) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -w "$OUT" "$IN" ;;
1089 oggenc) $RUN_COMMAND nice $EFFECTIVE_NICE $OGGENCODER $OGGENCODEROPTS -o "$OUT" "$IN" ;;
1093 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" >/dev/null 2>&1
1100 case "$FLACENCODERSYNTAX" in
1101 flac) $RUN_COMMAND nice $EFFECTIVE_NICE $FLACENCODER -f $FLACENCODEROPTS -o "$OUT" "$IN" ;;
1106 vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1"
1107 $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1
1112 if [ "$(eval echo ${COMMENT})" != "" ]; then
1115 *) COMMENT="COMMENT=$COMMENT" ;;
1117 COMMENT="--comment \"$COMMENT\""
1119 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1120 if [ ! "$DOTAG" = "y" ]; then
1121 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" "$COMMENT" "$IN" "$OUT"
1123 $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
1127 # MPP/MP+(Musepack) format (.mpc) is done locally, with inline
1129 # I tried compiling the mppenc from corecodecs.org and got some
1130 # errors, so I have not tried it myself.
1131 ## FIXME ## Needs some cleanup to determine if an empty tag sent
1132 ## FIXME ## to the encoder ends up empty.
1133 $RUN_COMMAND nice $EFFECTIVE_NICE $MPPENCODER $MPPENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" "$IN" "$OUT"
1136 # Quick hack to avoid tagging Ogg/Speex, since there is no other way to tag than inline tagging
1137 if [ ! "$DOTAG" = "y" ]; then
1138 $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" --comment "$COMMENT" -o "$OUT" "$IN"
1141 $RUN_COMMAND nice $ENCNICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
1145 # In case of wav output we need nothing. Just keep the wavs.
1150 # Only remove .wav if the encoding succeeded
1151 if checkerrors "encodetrack-(.{3,6})-$1"; then :; else
1152 run_command encodetrack-$1 true
1153 if [ ! "$KEEPWAVS" = "y" ] ; then
1154 if [ ! "$KEEPWAVS" = "move" ] ; then
1160 run_command "" echo "HEH! The file we were about to encode disappeared:"
1161 run_command "" echo ">> $IN"
1162 run_command encodetrack-$1 false
1166 # do_preprocess [tracknumber]
1168 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1171 # IN="$ABCDETEMPDIR/track$1.wav"
1172 # # We need IN to proceed.
1173 # if [ -s "$IN" ] ; then
1174 # for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1176 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1177 # run_command '' echo "Pre-processing track $1 of $TRACKS..."
1178 # case "$POSTPROCESSFORMAT" in
1180 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $WAV_PRE $IF $OF ;;
1182 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $MP3_PRE $IF $OF ;;
1184 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $OGG_PRE $IF $OF ;;
1186 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $FLAC_PRE $IF $OF ;;
1188 # run_command preprocess-$OUTPUT-$1 nice $PRENICE $SPX_PRE $IF $OF ;;
1191 # # Only remove .wav if the encoding succeeded
1192 # if checkerrors "preprocess-(.{3,4})-$1"; then
1193 # run_command preprocess-$1 false
1195 # run_command preprocess-$1 true
1198 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1199 # echo "HEH! The file we were about to pre-process disappeared:"
1202 # run_command preprocess-$1 false
1207 # do_postprocess [tracknumber]
1209 # TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
1212 # for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
1214 # IN="$ABCDETEMPDIR/track$1.$POSTPROCESSFORMAT"
1215 # # We need IN to proceed.
1216 # if [ -s "$IN" ] ; then
1217 # #OUT="$ABCDETEMPDIR/track$1.$OUTPUT"
1218 # run_command '' echo "Post-processing track $1 of $TRACKS..."
1219 # case "$POSTPROCESSFORMAT" in
1221 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $MP3_POST $IF $OF ;;
1223 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $OGG_POST $IF $OF ;;
1225 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $FLAC_POST $IF $OF ;;
1227 # run_command postprocess-$OUTPUT-$1 nice $POSTNICE $SPX_POST $IF $OF ;;
1229 # # Only remove .wav if the encoding succeeded
1230 # if checkerrors "postprocess-(.{3,4})-$1"; then
1231 # run_command postprocess-$1 false
1233 # run_command postprocess-$1 true
1236 # if [ "$(checkstatus encode-output)" = "loud" ]; then
1237 # echo "HEH! The file we were about to post-process disappeared:"
1240 # run_command postprocess-$1 false
1255 # MP3GAIN, MP3GAINOPTS, VORBISGAIN, VORBISGAINOPTS, MPPGAIN, MPPGAINOPTS
1259 # The commands here don't go through run_command because they're never supposed to be silenced
1260 echo "Batch analizing gain in tracks: $TRACKQUEUE"
1265 for UTRACKNUM in $TRACKQUEUE
1267 MP3FILES="$TRACKFILES track$UTRACKNUM.mp3"
1269 # FIXME # Hard-coded batch option!
1270 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1272 if [ "$RETURN" != "0" ]; then
1273 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1275 for UTRACKNUM in $TRACKQUEUE
1277 echo normalizetrack-$UTRACKNUM >> status
1283 # do_batch_normalize
1285 # NORMALIZER, NORMALIZEROPTS
1286 do_batch_normalize ()
1288 # The commands here don't go through run_command because they're never supposed to be silenced
1289 echo "Batch normalizing tracks: $TRACKQUEUE"
1294 for UTRACKNUM in $TRACKQUEUE
1296 TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
1298 # XXX: Hard-coded batch option!
1299 $NORMALIZER -b $NORMALIZEROPTS $TRACKFILES
1301 if [ "$RETURN" != "0" ]; then
1302 echo "batch-normalize: $NORMALIZER returned code $RETURN" >> errors
1304 for UTRACKNUM in $TRACKQUEUE
1306 echo normalizetrack-$UTRACKNUM >> status
1312 # do_normalize [tracknumber]
1314 # TRACKS, TRACKNAME, NORMALIZER, NORMALIZEROPTS
1317 IN="$ABCDETEMPDIR/track$1.wav"
1318 if [ -e "$IN" ] ; then
1319 run_command '' echo "Normalizing track $1 of $TRACKS: $TRACKNAME..."
1320 run_command normalizetrack-$1 $NORMALIZER $NORMALIZEROPTS "$IN"
1322 if [ "$(checkstatus encode-output)" = "loud" ]; then
1323 echo "HEH! The file we were about to normalize disappeared:"
1326 run_command normalizetrack-$1 false "File $IN was not found"
1330 # do_move [tracknumber]
1331 # Deduces the outfile from environment variables
1332 # Creates directory if necessary
1334 # TRACKNUM, TRACKNAME, TRACKARTIST, DALBUM, OUTPUTFORMAT, CDGENRE, CDYEAR
1337 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1339 # For now, set OUTPUT as TMPOUTPUT, and then change it once we have
1340 # defined the OUTPUTFILE:
1343 # Create ALBUMFILE, ARTISTFILE, TRACKFILE
1344 # Munge filenames as follows:
1349 # Eat control characters
1350 ALBUMFILE="$(mungefilename "$DALBUM")"
1351 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1352 TRACKFILE="$(mungefilename "$TRACKNAME")"
1353 GENRE="$(mungegenre "$GENRE")"
1354 YEAR=${CDYEAR:-$CDYEAR}
1355 # If we want to start the tracks with a given number, we need to modify
1356 # the TRACKNUM value before evaluation
1358 # Supported variables for OUTPUTFORMAT are GENRE, YEAR, ALBUMFILE,
1359 # ARTISTFILE, TRACKFILE, and TRACKNUM.
1360 if [ "$ONETRACK" = "y" ]; then
1361 if [ "$VARIOUSARTISTS" = "y" ]; then
1362 OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\")"
1364 OUTPUTFILE="$(eval echo \""$ONETRACKOUTPUTFORMAT"\")"
1367 if [ "$VARIOUSARTISTS" = "y" ]; then
1368 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT"\")"
1370 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT"\")"
1373 if checkerrors "tagtrack-$OUTPUT-$1"; then :; else
1374 # Once we know the specific output was successful, we can change
1375 # the OUTPUT to the value containing the container
1378 OUTPUT=$OGGOUTPUTCONTAINER
1381 OUTPUT=$FLACOUTPUTCONTAINER
1387 # Check that the directory for OUTPUTFILE exists, if it doesn't, create it
1388 OUTPUTFILEDIR="$(dirname "$OUTPUTDIR/$OUTPUTFILE")"
1391 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1392 # FIXME # introduce warnings?
1395 # mkdir -p shouldn't return an error if the directory already exists
1396 mkdir -p "$OUTPUTFILEDIR"
1397 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1398 if checkstatus movetrack-output-$OUTPUT; then :; else
1399 run_command movetrack-output-$OUTPUT true
1404 # mkdir -p shouldn't return an error if the directory already exists
1405 mkdir -p "$OUTPUTFILEDIR"
1406 run_command movetrack-$1 mv "$ABCDETEMPDIR/track$1.$OUTPUT" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT"
1407 if checkstatus movetrack-output-$OUTPUT; then :; else
1408 run_command movetrack-output-$OUTPUT true
1412 # Lets move the cue file
1413 if CUEFILE=$(checkstatus cuefile) >/dev/null ; then
1414 if [ -r "$ABCDETEMPDIR/$CUEFILE" ]; then
1415 if checkstatus movecue-$OUTPUT; then :; else
1416 # Silence the Copying output since it overlaps with encoding processes...
1417 #run_command '' vecho "Copying cue file to its destination directory..."
1418 if checkstatus onetrack >/dev/null ; then
1421 if [ "$DOCLEAN" != "y" ] && [ "$FORCE" != "y" ]; then
1422 # We dont have the dir, since it was not created before.
1425 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1428 # NOTE: Creating a cue file with the 3-char-extension files is to comply with
1429 # http://brianvictor.tripod.com/mp3cue.htm#details
1430 [a-z0-9][a-z0-9][a-z0-9])
1431 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.cue"
1434 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTDIR/$OUTPUTFILE.$OUTPUT.cue"
1438 run_command movecue-$OUTPUT cp "$ABCDETEMPDIR/$CUEFILE" "$OUTPUTFILEDIR/$CUEFILE"
1440 echo movecue-$OUTPUT >> "$ABCDETEMPDIR/status"
1449 # Create the playlist if wanted
1451 # PLAYLISTFORMAT, PLAYLISTDATAPREFIX, VAPLAYLISTFORMAT, VAPLAYLISTDATAPREFIX,
1452 # VARIOUSARTISTS, OUTPUTDIR
1455 for TMPOUTPUT in $(echo $OUTPUTTYPE | tr , \ )
1459 OUTPUT=$OGGOUTPUTCONTAINER
1462 OUTPUT=$FLACOUTPUTCONTAINER
1468 # Create a playlist file for the playlist data to go into.
1469 # We used to wipe it out if it existed. Now we request permision if interactive.
1470 for LASTTRACK in $TRACKQUEUE; do :; done
1471 ALBUMFILE="$(mungefilename "$DALBUM")"
1472 ARTISTFILE="$(mungefilename "$DARTIST")"
1473 GENRE="$(mungegenre "$GENRE")"
1474 YEAR=${CDYEAR:-$CDYEAR}
1475 if [ "$VARIOUSARTISTS" = "y" ] ; then
1476 PLAYLISTFILE="$(eval echo "$VAPLAYLISTFORMAT")"
1478 PLAYLISTFILE="$(eval echo "$PLAYLISTFORMAT")"
1480 FINALPLAYLISTDIR="$(dirname "$OUTPUTDIR/$PLAYLISTFILE")"
1481 mkdir -p "$FINALPLAYLISTDIR"
1482 if [ -s "$OUTPUTDIR/$PLAYLISTFILE" ]; then
1483 echo -n "Erase, Append to, or Keep the existing playlist file? [e/a/k] (e): " >&2
1484 if [ "$INTERACTIVE" = "y" ]; then
1485 while [ "$DONE" != "y" ]; do
1487 case $ERASEPLAYLIST in
1488 e|E|a|A|k|K) DONE=y ;;
1489 "") ERASEPLAYLIST=e ; DONE=y ;;
1497 # Once we erase the playlist, we use append to create the new one.
1498 [ "$ERASEPLAYLIST" = "e" -o "$ERASEPLAYLIST" = "E" ] && rm -f "$OUTPUTDIR/$PLAYLISTFILE" && ERASEPLAYLIST=a
1500 # The playlist does not exist, so we can safelly use append to create the new list
1503 if [ "$ERASEPLAYLIST" = "a" -o "$ERASEPLAYLIST" = "A" ]; then
1504 touch "$OUTPUTDIR/$PLAYLISTFILE"
1505 for UTRACKNUM in $TRACKQUEUE
1507 # Shares some code with do_move since the filenames have to match
1508 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
1509 getcddbinfo TRACKNAME
1511 TRACKFILE="$(mungefilename "$TRACKNAME")"
1512 ARTISTFILE="$(mungefilename "$TRACKARTIST")"
1513 ALBUMFILE="$(mungefilename "$DALBUM")"
1514 # If we want to start the tracks with a given number, we need to modify the
1515 # TRACKNUM value before evaluation
1517 if [ "$VARIOUSARTISTS" = "y" ]; then
1518 OUTPUTFILE="$(eval echo \""$VAOUTPUTFORMAT\"")"
1520 OUTPUTFILE="$(eval echo \""$OUTPUTFORMAT\"")"
1522 if [ "$VARIOUSARTISTS" = "y" ]; then
1523 if [ "$VAPLAYLISTDATAPREFIX" ] ; then
1524 echo ${VAPLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1526 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1529 if [ "$PLAYLISTDATAPREFIX" ]; then
1530 echo ${PLAYLISTDATAPREFIX}$OUTPUTFILE.$OUTPUT >> "$OUTPUTDIR/$PLAYLISTFILE"
1532 relpath "$PLAYLISTFILE", "$OUTPUTFILE.$OUTPUT" >> "$OUTPUTDIR/$PLAYLISTFILE"
1537 ## this will convert the playlist to have CRLF line-endings, if specified
1538 ## (some hardware players insist on CRLF endings)
1539 if [ "$DOSPLAYLIST" = "y" ]; then
1540 awk '{substr("\r",""); printf "%s\r\n", $0}' "$OUTPUTDIR/$PLAYLISTFILE" > "$ABCDETEMPDIR/PLAYLISTFILE.tmp"
1541 # mv -f "$ABCDETEMPDIR/PLAYLISTFILE.tmp" "$OUTPUTDIR/$PLAYLISTFILE"
1542 cat "$ABCDETEMPDIR/PLAYLISTFILE.tmp" | sed 's/\//\\/' > "$OUTPUTDIR/$PLAYLISTFILE"
1544 echo "playlistcomplete" >> "$ABCDETEMPDIR/status"
1549 # This function reads a cuefile on stdin and writes an extended
1550 # cddb query on stdout. Any PREGAP for track 1 is properly
1551 # handled, although cue files embedded in FLAC files do not
1552 # appear to properly store the PREGAP setting. :(
1553 abcde.cue2discid () {
1558 while [ $val -gt 0 ] ; do
1559 ret=$(( $ret + ( $val % 10) ))
1560 val=$(( $val / 10 ))
1570 local first second third
1571 first=$(expr ${1} + 0 )
1572 second=$(expr ${2} + 0 )
1573 third=$(expr ${3} + 0 )
1575 echo $(( ((($first * 60) + $second) * 75) + $third ))
1585 while read line ; do
1588 TRACK) i=$(( i + 1 ))
1590 INDEX) if [ "$2" -eq 1 ] ; then
1592 START=$(( $LBA + $PREGAP + $OFFSET ))
1594 X=$(cddb_sum $(( $START / 75 )) )
1598 PREGAP) PREGAP=$(msf2lba $2)
1602 LEADOUT=$(( $4 / 588 ))
1605 LEADIN=$(( $3 / 588 ))
1614 LEADOUT=$(( $LEADOUT + $LEADIN ))
1616 LENGTH=$(( $LEADOUT/75 - $TRACK1/75 ))
1617 DISCID=$(( ( $N % 255 ) * 2**24 | $LENGTH * 2**8 | $TRACKS ))
1618 printf "%08x %i" $DISCID $TRACKS
1621 while [ $j -le $TRACKS ] ; do
1622 eval echo -n "\" \$TRACK$j\""
1625 echo " $(( $LEADOUT / 75 ))"
1629 # abcde.mkcue [--wholedisk]
1630 # This creates a cuefile directly from the extended discid information
1631 # The --wholedisk option controls whether we're ripping data from the
1632 # start of track one or from the start of the disk (usually, but not
1633 # always the same thing!)
1635 # Track one leadin/pregap (if any) handeling:
1636 # --wholedisk specified:
1639 # INDEX 01 <pregap value>
1640 # Remaining track index values unchanged from disc TOC
1642 # --wholedisk not specified
1644 # PREGAP <pregap value>
1646 # Remaining track index values offset by <pregap value>
1653 printf "$1%02i:%02i:%02i\n" $(($2/4500)) $((($2/75)%60)) $(($2%75))
1656 local MODE DISCID TRACKS
1660 if [ "$1" = --wholedisc ] ; then
1672 echo REM DISCID $DISCID
1673 echo FILE \"dummy.wav\" WAVE
1675 if [ $1 -ne 150 ] && [ $MODE = "PREGAP"] ; then
1682 while [ $i -le "$TRACKS" ] ; do
1683 LBA=$(( $1 - $OFFSET ))
1684 printf " TRACK %02i AUDIO\n" $i
1685 if [ $i -eq 1 -a $1 -ne 150 ] ; then
1686 if [ $MODE = PREGAP ] ; then
1687 echomsf " PREGAP " $(($OFFSET-150))
1689 echo " INDEX 00 00:00:00"
1692 echomsf " INDEX 01 " $LBA
1699 # This essentially the start of things
1702 # Query the CD to get the track info, unless the user specified -C
1703 # or we are using some actions which do not need the CDDB data at all
1704 #if [ ! X"$EXPACTIONS" = "X" ]; then
1706 #elif [ -z "$DISCID" ]; then
1707 if [ -z "$DISCID" ]; then
1708 vecho -n "Getting CD track info... "
1709 # In OSX, unmount the disc before a query
1710 if [ "$OSFLAVOUR" = "OSX" ]; then
1711 disktool -u ${CDROM#/dev/}
1713 case "$CDROMREADERSYNTAX" in
1715 if $METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" > /dev/null 2>&1 ; then
1716 case "$CUE2DISCID" in
1717 # FIXME # right now we have 2 cue2discid internal
1718 # implementations: builtin and abcde.cue2discid. Test
1719 # both of them and decide which one we want to use.
1721 #vecho "Using builtin cue2discid implementation..."
1722 CUESHEET="$(metaflac $METAFLACOPTS --export-cuesheet-to=- "$CDROM")"
1724 #TRACKS=$(echo $CUESHEET | egrep "TRACK \+[[:digit:]]\+ \+AUDIO" |wc -l)
1726 OFFSETTIMES=( $(echo "$CUESHEET" | sed -n -e's/\ *INDEX 01\ \+//p' ) )
1727 TRACKS=${#OFFSETTIMES[@]}
1729 #echo "processing offsetimes ${OFFSETTIMES[@]}"
1730 for OFFSETTIME in ${OFFSETTIMES[@]}; do
1731 OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
1732 #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
1735 LEADOUT=$(( $(echo "$CUESHEET" | grep lead-out | get_last) / 44100 * 75 ))
1736 LEADIN=$(( $(echo "$CUESHEET" | grep lead-in | get_last) / 44100 * 75 ))
1740 #vecho "Using external python cue2discid implementation..."
1741 TRACKINFO=$($METAFLAC $METAFLACOPTS --export-cuesheet-to=- "$CDROM" | $CUE2DISCID)
1745 log error "the input flac file does not contain a cuesheet."
1750 # CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1752 # if [ ! "$RET" = "0" ];then
1753 # log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1756 # TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1757 # CDPARANOIAAUDIOTRACKS="$TRACKS"
1759 # LEADOUT="$(echo "$CDPARANOIAOUTPUT" | egrep -o '^TOTAL[[:space:]]+([[:digit:]]+)' | get_last)"
1760 # OFFSETS="$(echo "$CDPARANOIAOUTPUT" | sed -n -e's/^ .* \([0-9]\+\) \[.*/\1/p')"
1764 case "$CDDBMETHOD" in
1765 cddb) TRACKINFO=$($CDDISCID "$CDROM") ;;
1766 # FIXME # musicbrainz needs a cleanup
1767 musicbrainz) TRACKINFO=$($MUSICBRAINZ -c "$CDROM" ) ;;
1771 # Make sure there's a CD in there by checking cd-discid's return code
1772 if [ ! "$?" = "0" ]; then
1773 if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
1774 log error "cuesheet information from the flac file could not be read."
1775 log error "Perhaps the flac file does not contain a cuesheet?."
1778 log error "CD could not be read. Perhaps there's no CD in the drive?"
1782 # In OSX, remount the disc again
1783 if [ "$OSFLAVOUR" = "OSX" ]; then
1784 disktool -m ${CDROM#/dev/}
1787 DISCID=$(echo $TRACKINFO | cut -f1 -d' ')
1789 TRACKINFO=$(cat "$WAVOUTPUTDIR/abcde.$DISCID/discid")
1792 # Get a full enumeration of tracks, sort it, and put it in the TRACKQUEUE.
1793 # This needs to be done now because a section of the resuming code will need
1796 # get the number of digits to pad TRACKNUM with - we'll use this later
1797 # a CD can only hold 99 tracks, but since we support a feature for starting
1798 # numbering the tracks from a given number, we might need to set it as a
1799 # variable for the user to define... or obtain it somehow.
1800 if [ "$PADTRACKS" = "y" ] ; then
1804 ABCDETEMPDIR="$WAVOUTPUTDIR/abcde.$(echo $TRACKINFO | cut -f1 -d' ')"
1805 if [ -z "$TRACKQUEUE" ]; then
1806 if [ ! "$STRIPDATATRACKS" = "n" ]; then
1807 case "$CDROMREADERSYNTAX" in
1809 if [ "$WEHAVEACD" = "y" ]; then
1810 vecho "Querying the CD for audio tracks..."
1811 CDPARANOIAOUTPUT="$( $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -Q --verbose 2>&1 )"
1813 if [ ! "$RET" = "0" ];then
1814 log warning "something went wrong while querying the CD... Maybe a DATA CD?"
1816 TRACKS="$(echo "$CDPARANOIAOUTPUT" | egrep '^[[:space:]]+[[:digit:]]' | tail -n 1 | get_first | tr -d "." | tr '\n' ' ')"
1817 CDPARANOIAAUDIOTRACKS="$TRACKS"
1819 # Previous versions of abcde would store the tracks on a file, instead of the status record.
1820 if [ -f "$ABCDETEMPDIR/cdparanoia-audio-tracks" ]; then
1821 echo cdparanoia-audio-tracks=$( cat "$ABCDETEMPDIR/cdparanoia-audio-tracks" ) >> "$ABCDETEMPDIR/status"
1822 rm -f "$ABCDETEMPDIR/cdparanoia-audio-tracks"
1824 if [ -f "$ABCDETEMPDIR/status" ] && TRACKS=$(checkstatus cdparanoia-audio-tracks); then :; else
1825 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1829 *) TRACKS=$(echo $TRACKINFO | cut -f2 -d' ') ;;
1832 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1834 if echo "$TRACKS" | grep "[[:digit:]]" > /dev/null 2>&1 ;then :;else
1835 log info "The disc does not contain any tracks. Giving up..."
1838 echo -n "Grabbing entire CD - tracks: "
1839 if [ ! "$PADTRACKS" = "y" ] ; then
1840 TRACKNUMPADDING=$(echo -n $TRACKS | wc -c | tr -d ' ')
1842 TRACKS=$(printf "%0.${TRACKNUMPADDING}d" $TRACKS)
1844 while [ "$X" -ne "$TRACKS" ]
1846 X=$(printf "%0.${TRACKNUMPADDING}d" $(expr $X + 1))
1847 TRACKQUEUE=$(echo $TRACKQUEUE $X)
1851 TRACKS=$(echo $TRACKINFO | cut -f2 -d' ')
1852 # User-supplied track queue.
1853 # Weed out non-numbers, whitespace, then sort and weed out duplicates
1854 TRACKQUEUE=$(echo $TRACKQUEUE | sed 's-[^0-9 ]--g' | tr ' ' '\n' | grep -v ^$ | sort -n | uniq | tr '\n' ' ' | sed 's- $--g')
1855 # Once cleaned, obtain the highest value in the trackqueue for number padding
1856 for LASTTRACK in $TRACKQUEUE; do :; done
1857 if [ ! "$PADTRACKS" = "y" ] ; then
1858 TRACKNUMPADDING=$(echo -n $LASTTRACK | wc -c | tr -d ' ')
1860 # Now we normalize the trackqueue
1861 for TRACK in $TRACKQUEUE ; do
1862 TRACKNUM=$(printf %0.${TRACKNUMPADDING}d $(expr ${TRACK} + 0 ))
1863 PADTRACKQUEUE=$(echo $PADTRACKQUEUE $TRACKNUM)
1865 TRACKQUEUE=$PADTRACKQUEUE
1866 echo Grabbing tracks: "$TRACKQUEUE"
1869 QUEUEDTRACKS=$(echo $TRACKQUEUE | wc -w | tr -d ' ')
1871 # We have the discid, create a temp directory after it to store all the temp
1874 if [ -e "$ABCDETEMPDIR" ]; then
1875 echo -n "abcde: attempting to resume from $ABCDETEMPDIR"
1876 # It already exists, see if it's a directory
1877 if [ ! -d "$ABCDETEMPDIR" ]; then
1878 # This is a file/socket/fifo/device/etc, not a directory
1881 echo "abcde: file $ABCDETEMPDIR already exists and does not belong to abcde." >&2
1882 echo "Please investigate, remove it, and rerun abcde." >&2
1886 # It's a directory, let's see if it's owned by us
1887 if [ ! -O "$ABCDETEMPDIR" ]; then
1888 # Nope, complain and exit
1890 echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
1891 echo "Please investigate, remove it, and rerun abcde." >&2
1895 # See if it's populated
1896 if [ ! -f "$ABCDETEMPDIR/discid" ]; then
1897 # Wipe and start fresh
1898 echo "abcde: $ABCDETEMPDIR/discid not found. Abcde must remove and recreate" >&2
1899 echo -n "this directory to continue. Continue? [y/n] (n)" >&2
1900 if [ "$INTERACTIVE" = "y" ]; then
1906 if [ "$ANSWER" != "y" ]; then
1909 rm -rf "$ABCDETEMPDIR" || exit 1
1910 mkdir -p "$ABCDETEMPDIR"
1911 if [ "$?" -gt "0" ]; then
1912 # Directory already exists or could not be created
1913 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1917 # Everything is fine. Check for ^encodetracklocation-
1918 # and encode-output entries in the status file and
1919 # remove them. These are not relevant across sessions.
1920 if [ -f "$ABCDETEMPDIR/status" ]; then
1921 mv "$ABCDETEMPDIR/status" "$ABCDETEMPDIR/status.old"
1922 grep -v ^encodetracklocation- < "$ABCDETEMPDIR/status.old" \
1923 | grep -v ^encode-output > "$ABCDETEMPDIR/status"
1925 # Remove old error messages
1926 if [ -f "$ABCDETEMPDIR/errors" ]; then
1927 rm -f "$ABCDETEMPDIR/errors"
1931 # We are starting from scratch
1932 mkdir -p "$ABCDETEMPDIR"
1933 if [ "$?" -gt "0" ]; then
1934 # Directory already exists or could not be created
1935 echo "abcde: Temp directory $ABCDETEMPDIR could not be created." >&2
1938 cat /dev/null > "$ABCDETEMPDIR/status"
1939 # Store the abcde version in the status file.
1940 echo "abcde-version=$VERSION" >> "$ABCDETEMPDIR/status"
1942 if [ X"$DOCUE" = "Xy" -a X"$WEHAVEACD" = "Xy" ]; then
1943 if checkstatus cuefile > /dev/null 2>&1 ; then :; else
1944 CUEFILE=cue-$(echo "$TRACKINFO" | cut -f1 -d' ').txt
1945 vecho "Creating cue file..."
1946 case $CDROMREADERSYNTAX in
1948 if $METAFLAC --export-cuesheet-to=- "$CDROM" > "$ABCDETEMPDIR/$CUEFILE"; then
1949 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1951 log warning "the input flac file does not contain a cuesheet."
1955 if $CUEREADER $CUEREADEROPTS > "$ABCDETEMPDIR/$CUEFILE"; then
1956 echo cuefile=$CUEFILE >> "$ABCDETEMPDIR/status"
1958 log warning "reading the CUE sheet is still considered experimental"
1959 log warning "and there was a problem with the CD reading. abcde will continue,"
1960 log warning "but consider reporting the problem to the abcde author"
1966 # If we got the CDPARANOIA status and it is not recorded, save it now
1967 if [ -n "$CDPARANOIAAUDIOTRACKS" ]; then
1968 if checkstatus cdparanoia-audio-tracks > /dev/null 2>&1; then :; else
1969 echo cdparanoia-audio-tracks=$CDPARANOIAAUDIOTRACKS >> "$ABCDETEMPDIR/status"
1973 # Create the discid file
1974 echo "$TRACKINFO" > "$ABCDETEMPDIR/discid"
1975 if checkstatus cddbmethod > /dev/null 2>&1 ; then :; else
1976 echo "cddbmethod=$CDDBMETHOD" >> "$ABCDETEMPDIR/status"
1981 # Create a proper CUE file based on the CUE file we created before.
1984 if CUEFILE_IN="$ABCDETEMPDIR"/$(checkstatus cuefile); then
1985 CUEFILE_OUT=$CUEFILE_IN.out
1986 ### FIXME ### checkstatus cddb
1987 if [ -e "$CDDBDATA" ]; then
1988 vecho "Adding metadata to the cue file..."
1989 # FIXME It doesn't preserve spaces! Why?
1990 # FIXME parse $track into PERFORMER and TITLE - abcde already has code for this?
1992 echo "PERFORMER \"$DARTIST\"" >> "$CUEFILE_OUT"
1993 echo "TITLE \"$DALBUM\"" >> "$CUEFILE_OUT"
1994 # Set IFS to <newline> to prevent read from swallowing spaces and tabs
1998 cat "$CUEFILE_IN" | while read line
2000 if echo "$line" | grep "INDEX 01" > /dev/null 2>&1 ; then
2001 # FIXME # Possible patch: remove the line above, uncomment the 2 lines below.
2002 # echo "$line" >> "$CUEFILE_OUT"
2003 # if echo "$line" | grep "^[[:space:]]*TRACK" > /dev/null 2>&1 ; then
2004 eval track="\$TRACK$n"
2006 echo " TITLE \"$track\"" >> "$CUEFILE_OUT"
2008 # FIXME # If the lines above are uncommented, remove the line below.
2009 echo "$line" >> "$CUEFILE_OUT"
2012 mv "$CUEFILE_OUT" "$CUEFILE_IN"
2013 echo "cleancuefile" >> "$ABCDETEMPDIR/status"
2019 # Parses a CDDB file and outputs the title and the track names.
2020 # Variables: CDDBFILE
2024 # List out disc title/author and contents
2025 if [ "$ONETRACK" = "y" ]; then
2026 vecho "ONETRACK mode selected: displaying only the title of the CD..."
2028 echo "---- $(grep DTITLE "${CDDBPARSEFILE}" | cut '-d=' -f2- | tr -d \\r\\n ) ----"
2029 if [ X"$SHOWCDDBYEAR" = "Xy" ]; then
2030 PARSEDYEAR=$(grep DYEAR "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2031 if [ ! X"$PARSEDYEAR" = "X" ]; then
2032 echo "Year: $PARSEDYEAR"
2035 if [ X"$SHOWCDDBGENRE" = "Xy" ]; then
2036 PARSEDGENRE=$(grep DGENRE "${CDDBPARSEFILE}" | cut '-d=' -f2-)
2037 if [ ! X"$PARSEDGENRE" = "X" ]; then
2038 echo "Genre: $PARSEDGENRE"
2041 if [ ! "$ONETRACK" = "y" ]; then
2042 for TRACK in $(f_seq_row 1 $TRACKS)
2044 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
2050 # Check for a local CDDB file, and report success
2053 if checkstatus cddb-readcomplete && checkstatus cddb-choice >/dev/null; then :; else
2055 CDDBLOCALSTATUS="notfound"
2056 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2059 if [ "$CDDBLOCALRECURSIVE" = "y" ]; then
2060 CDDBLOCALRESULTS="$(find ${CDDBLOCALDIR} -name "${CDDBDISCID}" -type f 2> /dev/null)"
2061 if [ ! "${CDDBLOCALRESULTS}" = "" ]; then
2062 if (( $(echo "${CDDBLOCALRESULTS}" | wc -l) == 1 )); then
2063 CDDBLOCALFILE="${CDDBLOCALRESULTS}"
2064 CDDBLOCALMATCH=single
2065 elif (( $(echo "${CDDBLOCALRESULTS}" | wc -l) > 1 )); then
2066 CDDBLOCALMATCH=multiple
2071 elif [ "$CDDBLOCALMATCH" = "none" ] && [ -r "${CDDBLOCALDIR}/${CDDBDISCID}" ]; then
2072 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2073 CDDBLOCALMATCH=single
2078 # If the user has selected to check a local CDDB repo, we proceed with it
2079 case $CDDBLOCALMATCH in
2081 echo "Processing multiple matching CDDB entries..." > "$ABCDETEMPDIR/cddblocalchoices"
2083 echo "$CDDBLOCALRESULTS" | while read RESULT ; do
2085 # List out disc title/author and contents
2086 CDDBLOCALREAD="$ABCDETEMPDIR/cddblocalread.$X"
2087 cat "$RESULT" > "${CDDBLOCALREAD}"
2090 do_cddbparse "${CDDBLOCALREAD}"
2092 ##FIXME## QUICK HACK !!!!
2093 if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
2094 } >> "$ABCDETEMPDIR/cddblocalchoices"
2096 if [ $(cat "$ABCDETEMPDIR/cddblocalchoices" | wc -l) -ge 24 ] && [ "$INTERACTIVE" = "y" ]; then
2097 page "$ABCDETEMPDIR/cddblocalchoices"
2099 # It's all going to fit in one page, cat it
2100 cat "$ABCDETEMPDIR/cddblocalchoices" >&2
2102 CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
2103 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2104 CDDBLOCALCHOICENUM=-1
2105 if [ "$INTERACTIVE" = "y" ]; then
2106 while [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; do
2107 echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
2108 read CDDBLOCALCHOICE
2109 [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
2110 # FIXME # Introduce diff's
2111 if echo $CDDBLOCALCHOICE | egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2112 diffentries cddblocalread "$CDDBLOCALCHOICES" "$CDDBLOCALCHOICE"
2113 elif echo $CDDBLOCALCHOICE | egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2114 # Make sure we get a valid choice
2115 CDDBLOCALCHOICENUM=$(echo $CDDBLOCALCHOICE | xargs printf %d 2>/dev/null)
2116 if [ $CDDBLOCALCHOICENUM -lt 0 ] || [ $CDDBLOCALCHOICENUM -gt $CDDBLOCALCHOICES ]; then
2117 echo "Invalid selection. Please choose a number between 0 and $CDDBLOCALCHOICES." >&2
2123 #echo "Selected ..."
2125 CDDBLOCALCHOICENUM=1
2127 if [ ! "$CDDBLOCALCHOICENUM" = "0" ]; then
2128 #echo "Using local copy of CDDB data"
2129 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2130 cat "$ABCDETEMPDIR/cddblocalread.$CDDBLOCALCHOICENUM" >> "$ABCDETEMPDIR/cddbread.1"
2131 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2132 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2133 do_cddbparse "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbchoices"
2134 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2135 CDDBLOCALSTATUS="found"
2137 #echo "Not using local copy of CDDB data"
2138 CDDBLOCALSTATUS="notfound"
2142 # List out disc title/author and contents
2143 do_cddbparse "${CDDBLOCALFILE}"
2144 #if [ "$CDROMREADERSYNTAX" = "flac" ] ; then
2145 # echo -n "Embedded cuesheet entry found, use it? [y/n] (y): " >&2
2147 echo -n "Locally cached CDDB entry found, use it? [y/n] (y): " >&2
2149 if [ "$INTERACTIVE" = "y" ]; then
2151 while [ "$USELOCALRESP" != "y" ] && [ "$USELOCALRESP" != "n" ] && [ "$USELOCALRESP" != "" ] ; do
2152 echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
2155 [ x"$USELOCALRESP" = "x" ] && USELOCALRESP="y"
2159 if [ "$USELOCALRESP" = "y" ]; then
2160 #echo "Using local copy of CDDB data"
2161 echo "# DO NOT ERASE THIS LINE! Added by abcde to imitate cddb output" > "$ABCDETEMPDIR/cddbread.1"
2162 cat "${CDDBLOCALFILE}" >> "$ABCDETEMPDIR/cddbread.1"
2163 echo 999 > "$ABCDETEMPDIR/cddbquery" # Assuming 999 isn't used by CDDB
2164 echo cddb-readcomplete >> "$ABCDETEMPDIR/status"
2165 do_cddbparse "${CDDBLOCALFILE}" > "$ABCDETEMPDIR/cddbchoices"
2166 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2167 CDDBLOCALSTATUS="single"
2169 #echo "Not using local copy of CDDB data"
2170 CDDBLOCALSTATUS="notfound"
2174 CDDBLOCALSTATUS="notfound"
2180 do_musicbrainzstat ()
2187 # Use MBE_TOCGetCDIndexId on a perl query
2194 # Perform CDDB protocol version check if it hasn't already been done
2195 if checkstatus cddb-statcomplete; then :; else
2196 if [ "$CDDBAVAIL" = "n" ]; then
2198 echo 503 > "$ABCDETEMPDIR/cddbstat"
2201 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2202 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2203 while test $rc -eq 1 -a $CDDBPROTO -ge 3; do
2204 vecho "Checking CDDB server status..."
2205 $CDDBTOOL stat $CDDBURL $CDDBUSER $CDDBHOST $CDDBPROTO > "$ABCDETEMPDIR/cddbstat"
2206 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
2207 case "$RESPONSECODE" in
2208 210) # 210 OK, status information follows (until terminating `.')
2211 501|*) # 501 Illegal CDDB protocol level: <n>.
2212 CDDBPROTO=`expr $CDDBPROTO - 1`
2216 if test $rc -eq 1; then
2220 echo cddb-statcomplete >> "$ABCDETEMPDIR/status"
2228 CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
2229 CDDBLOCALFILE="${CDDBLOCALDIR}/${CDDBDISCID}"
2231 # Perform CDDB query if it hasn't already been done
2232 if checkstatus cddb-querycomplete; then :; else
2233 if [ "$CDDBAVAIL" = "n" ]; then
2235 echo 503 > "$ABCDETEMPDIR/cddbquery"
2236 # The default CDDBLOCALSTATUS is "notfound"
2237 # This part will be triggered if the user CDDB repo does not
2238 # contain the entry, or if we are not trying to use the repo.
2240 vecho "Querying the CDDB server..."
2241 CDDBUSER=$(echo $HELLOINFO | cut -f1 -d'@')
2242 CDDBHOST=$(echo $HELLOINFO | cut -f2- -d'@')
2243 $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $TRACKINFO > "$ABCDETEMPDIR/cddbquery"
2249 # no match found in database,
2250 # wget/fetch error, or user requested not to use CDDB
2251 # Make up an error code (503) that abcde
2252 # will recognize in do_cddbread
2253 # and compensate by making a template
2254 echo 503 > "$ABCDETEMPDIR/cddbquery"
2256 *) # strange and unknown error
2257 echo ERRORCODE=$ERRORCODE
2258 echo "abcde: $CDDBTOOL returned unknown error code"
2262 echo cddb-querycomplete >> "$ABCDETEMPDIR/status"
2269 # If it's not to be used, generate a template.
2270 # Then, display it (or them) and let the user choose/edit it
2271 if checkstatus cddb-readcomplete; then :; else
2272 vecho "Obtaining CDDB results..."
2273 # If CDDB is to be used, interpret the query results and read all
2274 # the available entries.
2275 rm -f "$ABCDETEMPDIR/cddbchoices"
2276 CDDBCHOICES=1 # Overridden by multiple matches
2277 RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbquery" | cut -f1 -d' ')
2278 case "$RESPONSECODE" in
2280 # One exact match, retrieve it
2281 # 200 [section] [discid] [artist] / [title]
2282 if checkstatus cddb-read-1-complete; then :; else
2283 echo -n "Retrieving 1 CDDB match..." >> "$ABCDETEMPDIR/cddbchoices"
2284 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(cut -f2,3 -d' ' "$ABCDETEMPDIR/cddbquery") > "$ABCDETEMPDIR/cddbread.1"
2285 echo "done." >> "$ABCDETEMPDIR/cddbchoices"
2286 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2287 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2289 # List out disc title/author and contents
2290 echo ---- "$(cut '-d ' -f4- "$ABCDETEMPDIR/cddbquery")" ---- >> "$ABCDETEMPDIR/cddbchoices"
2291 for TRACK in $(f_seq_row 1 $TRACKS)
2293 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2295 echo >> "$ABCDETEMPDIR/cddbchoices"
2299 case "$RESPONSECODE" in
2300 202) echo "No CDDB match." >> "$ABCDETEMPDIR/cddbchoices" ;;
2301 403|409) echo "CDDB entry is corrupt, or the handshake failed." >> "$ABCDETEMPDIR/cddbchoices" ;;
2302 503) echo "CDDB unavailable." >> "$ABCDETEMPDIR/cddbchoices" ;;
2304 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2305 # List out disc title/author and contents of template
2306 echo ---- Unknown Artist / Unknown Album ---- >> "$ABCDETEMPDIR/cddbchoices"
2308 for TRACK in $(f_seq_row 1 $TRACKS)
2310 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2312 echo >> "$ABCDETEMPDIR/cddbchoices"
2313 echo cddb-read-0-complete >> "$ABCDETEMPDIR/status"
2314 echo cddb-choice=0 >> "$ABCDETEMPDIR/status"
2317 # Multiple exact, (possibly multiple) inexact matches
2319 if [ "$RESPONSECODE" = "211" ]; then IN=in; fi
2320 if [ "$(wc -l < "$ABCDETEMPDIR/cddbquery" | tr -d ' ')" -eq 3 ]; then
2321 echo "One ${IN}exact match:" >> "$ABCDETEMPDIR/cddbchoices"
2322 tail -n +2 "$ABCDETEMPDIR/cddbquery" | head -n 1 >> "$ABCDETEMPDIR/cddbchoices"
2323 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2325 echo "Multiple ${IN}exact matches:" >> "$ABCDETEMPDIR/cddbchoices"
2327 vecho -n "Retrieving multiple matches... "
2328 grep -v ^[.]$ "$ABCDETEMPDIR/cddbquery" | ( X=0
2329 read DISCINFO # eat top line
2333 if checkstatus cddb-read-$X-complete; then :; else
2334 $CDDBTOOL read $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST $(echo $DISCINFO | cut -f1,2 -d' ') > "$ABCDETEMPDIR/cddbread.$X"
2335 echo cddb-read-$X-complete >> "$ABCDETEMPDIR/status"
2337 # List out disc title/author and contents
2338 echo \#$X: ---- "$DISCINFO" ---- >> "$ABCDETEMPDIR/cddbchoices"
2339 for TRACK in $(f_seq_row 1 $TRACKS)
2341 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2343 echo >> "$ABCDETEMPDIR/cddbchoices"
2346 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2350 for TRACK in $(f_seq_row 1 $TRACKS)
2352 echo $TRACK: "$(grep ^TTITLE$(expr $TRACK - 1)= "$ABCDETEMPDIR/cddbread.1" | cut -f2- -d= | tr -d \\r\\n)" >> "$ABCDETEMPDIR/cddbchoices"
2354 echo >> "$ABCDETEMPDIR/cddbchoices"
2355 echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
2356 echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
2359 echo "cddb-readcomplete" >> "$ABCDETEMPDIR/status"
2366 if checkstatus cddb-edit >/dev/null; then
2367 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2368 VARIOUSARTISTS="$(checkstatus variousartists)"
2369 VARIOUSARTISTSTYLE="$(checkstatus variousartiststyle)"
2372 if [ "$INTERACTIVE" = "y" ]; then
2373 # We should show the CDDB results both when we are not using the local CDDB repo
2374 # or when we are using it but we could not find a proper match
2375 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2376 # Display the $ABCDETEMPDIR/cddbchoices file created above
2377 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2378 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2379 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2380 CHOICE=$(checkstatus cddb-choice)
2381 if [ -n "$CHOICE" ] ; then
2382 case $CDDBCHOICES in
2383 -1) if head -1 "$ABCDETEMPDIR/cddbquery" | grep "^$" > /dev/null 2>&1 ; then
2384 log error "CDDB query failed!"
2387 cat "$ABCDETEMPDIR/cddbchoices"
2390 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2392 echo "Selected: #$CHOICE"
2393 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2397 # The user has a choice to make, display the info in a pager if necessary
2398 if [ $(cat "$ABCDETEMPDIR/cddbchoices" | wc -l) -ge 24 ]; then
2399 page "$ABCDETEMPDIR/cddbchoices"
2401 # It's all going to fit in one page, cat it
2402 cat "$ABCDETEMPDIR/cddbchoices" >&2
2406 # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
2408 # I'll take CDDB read #3 for $400, Alex
2409 while [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; do
2410 echo -n "Which entry would you like abcde to use (0 for none)? [0-$CDDBCHOICES]: " >&2
2412 [ X"$CDDBCHOICE" = "X" ] && CDDBCHOICE=1
2413 if echo $CDDBCHOICE | egrep "[[:space:]]*[[:digit:]]+,[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2414 if [ ! X"$DIFF" = "X" ]; then
2415 PARSECHOICE1=$(echo $CDDBCHOICE | cut -d"," -f1 | xargs printf %d 2>/dev/null)
2416 PARSECHOICE2=$(echo $CDDBCHOICE | cut -d"," -f2 | xargs printf %d 2>/dev/null)
2417 if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
2418 [ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
2419 [ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
2420 echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
2422 # We parse the 2 choices to diff, store them in temporary files and diff them.
2423 for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
2424 do_cddbparse "$ABCDETEMPDIR/cddbread.$PARSECHOICE" > "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE"
2426 echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "$ABCDETEMPDIR/cddbread.diff"
2427 $DIFF $DIFFOPTS "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE1" "$ABCDETEMPDIR/cddbread.parsechoice.$PARSECHOICE2" >> "$ABCDETEMPDIR/cddbread.diff"
2428 if [ $(cat "$ABCDETEMPDIR/cddbread.diff" | wc -l) -ge 24 ]; then
2429 page "$ABCDETEMPDIR/cddbread.diff"
2431 cat "$ABCDETEMPDIR/cddbread.diff" >&2
2435 echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBCHOICES." >&2
2437 elif echo $CDDBCHOICE | egrep "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
2438 # Make sure we get a valid choice
2439 CDCHOICENUM=$(echo $CDDBCHOICE | xargs printf %d 2>/dev/null)
2440 if [ $CDCHOICENUM -lt 0 ] || [ $CDCHOICENUM -gt $CDDBCHOICES ]; then
2441 echo "Invalid selection. Please choose a number between 0 and $CDDBCHOICES." >&2
2445 if [ "$CDCHOICENUM" = "0" ]; then
2446 vecho "Creating empty CDDB template..."
2448 $CDDBTOOL template $(cat "$ABCDETEMPDIR/discid") > "$ABCDETEMPDIR/cddbread.0"
2450 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2451 do_cddbparse "$ABCDETEMPDIR/cddbread.$CDCHOICENUM"
2453 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2457 # We need some code to show the selected option when local repository is selected and we have found a match
2458 vecho "Using cached CDDB match..." >&2
2459 # Display the $ABCDETEMPDIR/cddbchoices file created above
2460 # Pick a pager so that if the tracks overflow the screen the user can still view everything
2461 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2462 CDDBCHOICES=$(expr $(cat "$ABCDETEMPDIR/cddbquery" | wc -l) - 2)
2463 CHOICE=$(checkstatus cddb-choice)
2464 if [ "$USELOCALRESP" = "y" ]; then :; else
2465 if [ -n "$CHOICE" ] ; then
2466 case $CDDBCHOICES in
2469 echo "Selected template."
2471 1) cat "$ABCDETEMPDIR/cddbchoices" ;;
2473 echo "Selected: #$CHOICE"
2474 do_cddbparse "$ABCDETEMPDIR/cddbread.$CHOICE"
2482 # We're noninteractive - pick the first choice.
2483 # But in case we run a previous instance and selected a choice, use it.
2484 if [ -r "$ABCDETEMPDIR/cddbchoices" ]; then
2485 # Show the choice if we are not using the locally stored one
2486 # or when the local search failed to find a match.
2487 PREVIOUSCHOICE=$(checkstatus cddb-choice)
2488 if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
2489 #if [ "$PREVIOUSCHOICE" ]; then
2490 cat "$ABCDETEMPDIR/cddbchoices"
2493 if [ ! -z "$PREVIOUSCHOICE" ] ; then
2494 CDCHOICENUM=$PREVIOUSCHOICE
2497 echo "cddb-choice=$CDCHOICENUM" >> "$ABCDETEMPDIR/status"
2499 echo "Selected: #$CDCHOICENUM ($(grep ^DTITLE= "$ABCDETEMPDIR/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n))" >&2
2504 if checkstatus cddb-choice >/dev/null; then :; else
2505 echo "abcde: internal error: cddb-choice not recorded." >&2
2508 CDDBDATA="$ABCDETEMPDIR/cddbread.$(checkstatus cddb-choice)"
2509 echo -n "Edit selected CDDB data? [y/n] (" >&2
2510 if [ "$INTERACTIVE" = "y" ]; then
2511 if [ "$UNKNOWNDISK" = "y" ]; then
2514 [ "$EDITCDDB" != "n" ] && EDITCDDB=y
2523 if [ "$EDITCDDB" = "y" ]; then
2524 CDDBDATAMD5SUM=$($MD5SUM "$CDDBDATA" | cut -d " " -f 1);
2526 # Use the debian sensible-editor wrapper to pick the editor that the
2527 # user has requested via their $EDITOR environment variable
2528 if [ -x "/usr/bin/sensible-editor" ]; then
2529 /usr/bin/sensible-editor "$CDDBDATA"
2530 elif [ -n "$EDITOR" ]; then
2531 if [ -x $(which "${EDITOR%%\ *}") ]; then
2532 # That failed, try to load the preferred editor, starting
2533 # with their EDITOR variable
2534 eval $(echo "$EDITOR") \"$CDDBDATA\"
2536 # If that fails, check for a vi
2537 elif which vi >/dev/null 2>&1; then
2539 elif [ -x /usr/bin/vim ]; then
2540 /usr/bin/vim "$CDDBDATA"
2541 elif [ -x /usr/bin/vi ]; then
2542 /usr/bin/vi "$CDDBDATA"
2543 elif [ -x /bin/vi ]; then
2545 # nano should be on all (modern, i.e., sarge) debian systems
2546 elif which nano >/dev/null 2>&1 ; then
2548 elif [ -x /usr/bin/nano ]; then
2549 /usr/bin/nano "$CDDBDATA"
2550 # mg should be on all OpenBSD systems
2551 elif which mg >/dev/null 2>&1 ; then
2553 elif [ -x /usr/bin/mg ]; then
2554 /usr/bin/mg "$CDDBDATA"
2557 log warning "no editor available. Check your EDITOR environment variable."
2559 # delete editor backup file if it exists
2560 if [ -w "$CDDBDATA~" ]; then
2565 # Some heuristics first. Look at Disc Title, and if it starts with
2566 # "Various", then we'll assume Various Artists
2567 if [ "$(grep ^DTITLE= "$CDDBDATA" | cut -f2- -d= | egrep -ci '^(various|soundtrack|varios|sonora|ost)')" != "0" ]; then
2568 echo "Looks like a Multi-Artist CD" >&2
2571 echo -n "Is the CD multi-artist? [y/n] (n): " >&2
2572 if [ "$INTERACTIVE" = "y" ]; then
2579 if [ "$VARIOUSARTISTS" = "y" ] && [ ! "$ONETRACK" = "y" ]; then
2582 # Need NUMTRACKS before cddb-tool will return it:
2583 NUMTRACKS=$(egrep '^TTITLE[0-9]+=' "$CDDBDATA" | wc -l)
2584 if [ "$(grep -c "^TTITLE.*\/" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2585 # More than 1/2 tracks contain a "/", so guess forward
2587 elif [ "$(grep -c "^TTITLE.*\-" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2588 # More than 1/2 contain a "-", so guess forward-dash
2590 elif [ "$(grep -c "^TTITLE.*(.*)" "$CDDBDATA")" -gt "$(expr $NUMTRACKS / 2 )" ]; then
2591 # More than 1/2 contain something in parens, so guess trailing-paren
2595 echo "1) Artist / Title" >&2
2596 echo "2) Artist - Title" >&2
2597 echo "3) Title / Artist" >&2
2598 echo "4) Title - Artist" >&2
2599 echo "5) Artist: Title" >&2
2600 echo "6) Title (Artist)" >&2
2601 echo "7) This is a single-artist CD" >&2
2602 echo -n "Which style of multiple artist entries is it? [1-7] ($DEFAULTSTYLE): " >&2
2603 if [ "$INTERACTIVE" = "y" ]; then
2604 read VARIOUSARTISTSTYLE
2606 echo $DEFAULTSTYLE >&2
2607 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2609 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2610 # If they press Enter, then the default style (0) was chosen
2611 while [ $VARIOUSARTISTSTYLE -lt 0 ] || [ $VARIOUSARTISTSTYLE -gt 7 ]; do
2612 echo "Invalid selection. Please choose a number between 1 and 7."
2613 echo -n "Selection [1-7]: "
2614 read VARIOUSARTISTSTYLE
2615 VARIOUSARTISTSTYLE=$(echo 0$VARIOUSARTISTSTYLE | xargs printf %d)
2617 if [ "$VARIOUSARTISTSTYLE" = "0" ]; then
2618 VARIOUSARTISTSTYLE=$DEFAULTSTYLE
2620 vecho "Selected: $VARIOUSARTISTSTYLE"
2621 case "$VARIOUSARTISTSTYLE" in
2623 VARIOUSARTISTSTYLE=forward
2626 VARIOUSARTISTSTYLE=forward-dash
2629 VARIOUSARTISTSTYLE=reverse
2632 VARIOUSARTISTSTYLE=reverse-dash
2635 VARIOUSARTISTSTYLE=colon
2638 VARIOUSARTISTSTYLE=trailing-paren
2646 echo "variousartists=$VARIOUSARTISTS" >> "$ABCDETEMPDIR/status"
2647 echo "variousartiststyle=$VARIOUSARTISTSTYLE" >> "$ABCDETEMPDIR/status"
2649 if [ "$EDITCDDB" = "y" ] && [ "$UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE" = "y" ]; then
2650 if [ "$CDDBDATAMD5SUM" != "" ] && [ "$CDDBDATAMD5SUM" != "$($MD5SUM "$CDDBDATA" | cut -d " " -f 1)" ]; then
2651 # This works but does not have the necessary error checking
2652 # yet. If you are familiar with the CDDB spec
2653 # (see http://www.freedb.org/src/latest/DBFORMAT)
2654 # and can create an error-free entry on your own, then put
2655 # UNINTENTIONALLY_ANGER_THE_FREEDB_PEOPLE=y in your
2656 # abcde.conf to enable it. Put CDDBSUBMIT=email@address in
2657 # your abcde.conf to change the email address submissions are
2660 # submit the modified file, if they want
2661 if [ "$NOSUBMIT" != "y" ]; then
2662 echo -n "Do you want to submit this entry to $CDDBSUBMIT? [y/n] (n): "
2664 while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
2665 [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
2667 echo -n 'Invalid selection. Please answer "y" or "n": '
2670 if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
2671 echo -n "Sending..."
2672 $CDDBTOOL send "$CDDBDATA" $CDDBSUBMIT
2679 # User CDDBLOCALPOLICY to find out if we store the file or not...
2680 # Cache edited CDDB entry in the user's cddb dir
2681 if [ "$CDDBCOPYLOCAL" = "y" ]; then
2682 # Make sure the cache directory exists
2683 mkdir -p $CDDBLOCALDIR
2684 cat "$CDDBDATA" | tail -n $(expr $(cat "$CDDBDATA" | wc -l ) - 1 ) > ${CDDBLOCALDIR}/$(echo "$TRACKINFO" | cut -d' ' -f1)
2687 echo "cddb-edit" >> "$ABCDETEMPDIR/status"
2690 # do_cdread [tracknumber]
2691 # do_cdread onetrack [firsttrack] [lasttrack]
2695 # The commands here don't go through run_command because they're never supposed to be silenced
2696 # return codes need to be doublechecked anyway, however
2697 if [ "$1" = "onetrack" ]; then
2698 # FIXME # Add the possibility of grabbing ranges of tracks in onetrack
2699 # FIXME # Until then, we grab the whole CD in one track, no matter what
2701 # We need the first and last track for cdda2wav
2703 LASTTRACK=$(expr $3 + 0)
2704 UTRACKNUM=$FIRSTTRACK
2705 case "$CDROMREADERSYNTAX" in
2706 flac) READTRACKNUMS="$FIRSTTRACK.1-$(($LASTTRACK + 1)).0" ;;
2709 # Add a variable to check if tracks are provided in command line and if not, use "0-" to rip the tracks
2710 READTRACKNUMS="$FIRSTTRACK-$LASTTRACK" ;;
2711 cdda2wav) READTRACKNUMS="$FIRSTTRACK+$LASTTRACK" ;;
2712 *) echo "abcde error: $CDROMREADERSYNTAX does not support ONETRACK mode"
2718 CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
2719 if [ "$USEPIPES" = "y" ]; then
2720 TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
2721 FILEARG="$( eval echo "\$$TEMPARG" )"
2723 PIPE_MESSAGE="and encoding "
2725 WAVDATA="$ABCDETEMPDIR/track$UTRACKNUM.wav"
2726 case "$CDROMREADERSYNTAX" in
2727 ## FIXME ## Find the cases for dagrab and flac, to avoid exceptions
2729 FILEARG="--output-name=$WAVDATA"
2732 FILEARG="-f $WAVDATA"
2740 if [ "$1" = "onetrack" ]; then
2741 echo "Grabbing ${PIPE_MESSAGE}tracks $UTRACKNUM - $LASTTRACK as one track ..." >&2
2743 if [ -r "$CDDBDATA" ]; then
2744 getcddbinfo TRACKNAME
2745 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM: $TRACKNAME..." >&2
2747 echo "Grabbing ${PIPE_MESSAGE}track $UTRACKNUM..." >&2
2750 case "$CDROMREADERSYNTAX" in
2751 ### FIXME ### use an exception for flac, since it uses -o
2752 ### FIXME ### Shall we just use -o $FILEARG ??
2754 # Avoid problems wit math expressions by unpadding the given UTRACKNUM
2755 STRIPTRACKNUM=$(expr $UTRACKNUM + 0)
2756 nice $READNICE $FLAC -d -f --cue=${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0} "$FILEARG" "$CDROM" ;;
2758 nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR ;;
2760 if [ "$OSFLAVOUR" = "OSX" ] ; then
2761 # Hei, we have to unmount the device before running anything like cdda2wav in OSX
2762 disktool -u ${CDROM#/dev/} 0
2763 # Also, in OSX the cdrom device for cdda2wav changes...
2764 CDDA2WAVCDROM="IODVDServices"
2765 elif [ "$OSFLAVOUR" = "FBSD" ] ; then
2766 CDDA2WAVCDROM="$CDROMID"
2768 if [ "$CDROMID" = "" ]; then
2769 CDDA2WAVCDROM="$CDROM"
2771 CDDA2WAVCDROM="$CDROMID"
2774 nice $READNICE $CDROMREADER -D $CDDA2WAVCDROM -t ${READTRACKNUMS:-$UTRACKNUM} "$FILEARG" $REDIR
2776 ## FIXME ## We have an exception for dagrab, since it uses -f
2777 ## FIXME ## Shall we just use -f $FILEARG ??
2778 dagrab) nice $READNICE $CDROMREADER -d "$CDROM" -v $UTRACKNUM "$FILEARG" $REDIR
2781 # Find the track's mounted path
2782 REALTRACKNUM=$(expr $UTRACKNUM + 0)
2783 FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
2784 FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
2785 # If the file exists, copy it
2786 if [ -e "$FILEPATH" ] ; then
2787 nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
2791 debug) nice $READNICE $CDROMREADER -$CDPARANOIACDROMBUS "$CDROM" -w $UTRACKNUM-[:1] "$FILEARG" $REDIR
2795 # If we get some error or we get some missing wav
2796 # (as long as we dont use pipes)
2797 if [ "$RETURN" != "0" -o \( ! -s "$WAVDATA" -a X"$USEPIPES" != "Xy" \) ]; then
2798 # Thank goodness errors is only machine-parseable up to the
2799 # first colon, otherwise this woulda sucked
2800 if [ "$RETURN" = "0" -a ! -s "$WAVDATA" ]; then
2801 RETURN=73 # fake a return code as cdparanoia return 0 also on aborted reads
2803 if [ "$USEPIPES" = "y" ]; then
2804 echo "readencodetrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2806 echo "readtrack-$UTRACKNUM: $CDROMREADER returned code $RETURN" >> "$ABCDETEMPDIR/errors"
2810 if [ "$USEPIPES" = "y" ]; then
2811 echo readencodetrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2813 echo readtrack-$UTRACKNUM >> "$ABCDETEMPDIR/status"
2815 if [ "$1" = "onetrack" ]; then
2816 echo onetrack >> "$ABCDETEMPDIR/status"
2822 # No values accepted, only uses env variables
2825 if "$CDSPEED" "$CDSPEEDOPTS" "$CDSPEEDVALUE" >/dev/null ; then
2826 vecho "Setting CD speed to ${CDSPEEDVALUE}x"
2828 echo "abcde: unable to set the device speed" >&2
2834 # vecho outputs a message if EXTRAVERBOSE is selected
2837 if [ x"$EXTRAVERBOSE" != "x" ]; then
2839 warning) shift ; log warning "$@" ;;
2847 # decho outputs a debug message if DEBUG is selected
2850 if [ x"$DEBUG" != "x" ]; then
2851 if echo $1 | grep "^\[" > /dev/null 2>&1 ; then
2852 DEBUGECHO=$(echo "$@" | tr -d '[]')
2853 echo "[DEBUG] $DEBUGECHO: `eval echo \\$${DEBUGECHO}`"
2860 # User-redefinable functions
2861 # Custom filename munging:
2864 #echo "$@" | sed s,:,\ -,g | tr \ /\* __+ | tr -d \'\"\?\[:cntrl:\]
2865 echo "$@" | sed s,:,\ -,g | tr \ / __ | tr -d \'\"\?\[:cntrl:\]
2868 # Custom genre munging:
2871 echo $CDGENRE | tr "[:upper:]" "[:lower:]"
2875 # Empty pre_read function, to be defined in the configuration file.
2882 # Empty post_read function, to be defined in the configuration file.
2889 # Empty post_encode function, to be defined in the configuration file.
2895 ###############################################################################
2898 # Start of execution
2899 ###############################################################################
2904 # Defaults to FreeDB, but a python musicbrainz can be used
2906 CDDBURL="http://freedb.freedb.org/~cddb/cddb.cgi"
2907 CDDBSUBMIT=freedb-submit@freedb.org
2909 HELLOINFO="$(whoami)@$(hostname)"
2911 CDDBLOCALPOLICY="always"
2912 CDDBLOCALRECURSIVE="y"
2913 CDDBLOCALDIR="$HOME/.cddb"
2916 # List of fields we parse and show during the CDDB parsing...
2917 SHOWCDDBFIELDS="year,genre"
2920 #CDROMREADERSYNTAX=cdparanoia
2921 ENCODERSYNTAX=default
2923 MP3ENCODERSYNTAX=default
2924 OGGENCODERSYNTAX=default
2925 FLACENCODERSYNTAX=default
2926 SPEEXENCODERSYNTAX=default
2927 MPPENCODERSYNTAX=default
2928 AACENCODERSYNTAX=default
2929 NORMALIZERSYNTAX=default
2930 CUEREADERSYNTAX=default
2932 OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
2933 # Use the following VAOUTPUTFORMAT to revert to 2.0.x VA format:
2934 #VAOUTPUTFORMAT=${OUTPUTFORMAT}
2935 VAOUTPUTFORMAT='Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
2936 ONETRACKOUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
2937 VAONETRACKOUTPUTFORMAT='Various-${ALBUMFILE}/${ALBUMFILE}'
2938 PLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2939 PLAYLISTDATAPREFIX=''
2940 VAPLAYLISTFORMAT='${ARTISTFILE}-${ALBUMFILE}.${OUTPUT}.m3u'
2941 VAPLAYLISTDATAPREFIX=''
2949 VARIOUSARTISTSTYLE=forward
2956 # If using scsi devices, cdda2wav needs a CDROMID, instead of a device node
2957 # i.e. CDROMID="1,0,0"
2959 # If we are using the IDE bus, we need CDPARANOIACDROMBUS defined as "d"
2960 # If we are using the ide-scsi emulation layer, we need to define a "g"
2961 CDPARANOIACDROMBUS="d"
2963 # program paths - defaults to checking your $PATH
2970 XINGMP3ENC=xingmp3enc
2987 VORBISCOMMENT=vorbiscomment
2991 CDPARANOIA=cdparanoia
2997 MUSICBRAINZ=musicbrainz-get-tracks
3001 NORMALIZE=normalize-audio
3003 VORBISGAIN=vorbisgain
3011 # Options for programs called from abcde
3046 VORBISCOMMENTOPTS="-R"
3047 METAFLACOPTS="--no-utf8-convert"
3050 # Default to one process if -j isn't specified
3053 # List of actions to perform - by default, run to completion
3054 ACTIONS=cddb,read,encode,tag,move,clean
3056 # This option is basicaly for Debian package dependencies:
3057 # List of prefered outputs - by default, run with whatever we have in the path
3058 DEFAULT_OUTPUT_BINARIES=vorbis:oggenc,flac:flac,mp3:toolame,mp3:lame,mp3:bladeenc,spx:speex,m4a:faac
3060 # List of prefered cdromreaders - by default, run whichever we have in the path
3061 DEFAULT_CDROMREADERS="cdparanoia cdda2wav"
3063 # List of quality levels associated with the encoders:
3064 DEFAULT_QUALITY_XLO="oggenc:-q -1,lame:-q 9,speex:--quality 1,m4a:"
3065 DEFAULT_QUALITY_LO="oggenc:-q 1,lame:-q 7,speex:--quality 5,m4a:"
3066 DEFAULT_QUALITY_HI="oggenc:-q 7,lame:--preset standard,speex:--quality 9,m4a:"
3067 DEFAULT_QUALITY_XHI="oggenc:-q 10,lame:--preset extreme,speex:--quality 10,m4a:"
3069 # Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
3070 # Linux/OpenBSD. ftp is user for NetBSD.
3071 # Let's use these checkings to determine the OS flavour, which will be used
3073 if [ X$(uname) = "XFreeBSD" ] ; then
3078 elif [ X$(uname) = "XDarwin" ] ; then
3081 # We should have disktool in OSX, but let's be sure...
3083 CDROMREADERSYNTAX=cddafs
3084 elif [ X$(uname) = "XOpenBSD" ] ; then
3088 elif [ X$(uname) = "XNetBSD" ] ; then
3092 elif [ X$(uname) = "SunOS" ] ; then
3100 # If CDDBAVAIL is set to n, no CDDB read is done
3101 # If USEID3 is set to n, no ID3 tagging is done
3107 # But before we get into business, let us chop off any GREP environmental
3112 if [ -z "$OUTPUTDIR" ]; then
3116 if [ -z "$WAVOUTPUTDIR" ]; then
3117 WAVOUTPUTDIR="$OUTPUTDIR"
3120 # Load system defaults
3121 if [ -r /etc/abcde.conf ]; then
3124 # Load user preference defaults
3125 if [ -r $HOME/.abcde.conf ]; then
3129 # By this time, we need some HTTPGETOPTS already defined.
3130 # If the user has defined a non-default HTTPGET method, we should not be empty.
3132 if [ "$HTTPGETOPTS" = "" ] ; then
3134 wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
3135 curl) HTTPGETOPTS="-f -s";;
3136 fetch)HTTPGETOPTS="-q -o -";;
3137 ftp) HTTPGETOPTS="-a -V -o - ";;
3138 *) log warning "HTTPGET in non-standard and HTTPGETOPTS are not defined." ;;
3142 # If the CDROM has not been set yet, find a suitable one.
3143 # If this is a devfs system, default to /dev/cdroms/cdrom0
3144 # instead of /dev/cdrom
3145 if [ "$CDROM" = "" ] ; then
3146 if [ -e /dev/cdroms/cdrom0 ]; then
3147 CDROM=/dev/cdroms/cdrom0
3148 elif [ -e /dev/cdrom ]; then
3150 elif [ -e /dev/cd0c ]; then
3152 elif [ -e /dev/acd0c ]; then
3154 elif [ -e /dev/disk1 ]; then
3159 # Parse command line options
3160 #while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPq:r:Rs:S:t:T:vVxw:W: opt ; do
3161 while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
3164 a) ACTIONS="$OPTARG" ;;
3165 A) EXPACTIONS="$OPTARG" ;;
3167 B) NOBATCHREPLAYGAIN=y ;;
3168 c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
3169 C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;