#
# $Id$
-VERSION='2.3.99-$Revision$'
+VERSION='2.3.99.8'
usage ()
{
echo "-N Noninteractive. Never prompt for anything"
echo "-m Modify playlist to include CRLF endings, to comply with some players"
echo " WARNING: Deprecated. Use \"cue\" action"
-echo "-M Create a CUE file"
+#echo "-M Create a CUE file"
echo "-o <type1[,type2]...>"
echo " Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis"
echo "-p Pad track numbers with 0's (if less than 10 tracks)"
echo "-P Use UNIX pipes to read+encode without wav files"
+echo "-q <level>"
+echo " Set quality level (high,medium,low)"
echo "-r <host1[,host2]...>"
echo " Also encode on these remote hosts"
echo "-R Use local CDDB in recursive mode"
echo "-s <field>"
-echo " Show dielfs from the CDDB info (year,genre)"
+echo " Show fields from the CDDB info (year,genre)"
echo "-S <#> Set the CD speed"
echo "-t <#> Start the track numbering at a given number"
echo "-T <#> Same as -t but modifies tag numbering"
echo "-x Eject CD after all tracks are read"
echo "-w <comment>"
echo " Add a comment to the CD tracks"
-echo "-W <#> Contatenate CDs: -T #01 -w \"CD #\""
+echo "-W <#> Concatenate CDs: -T #01 -w \"CD #\""
echo "-z Use debug CDROMREADERSYNTAX option (needs cdparanoia)"
echo ""
echo "Tracks is a space-delimited list of tracks to grab."
if [ "$(which $X)" = "" ]; then
log error "$X is not in your path." >&2
log info "Define the full path to the executable if it exists on your system." >&2
+ if [ -e /etc/debian_release ] ; then
+ case $X in
+ oggenc) MISSING_PACKAGE=vorbis-tools ;;
+ lame|flac) MISSING_PACKAGE=$X ;;
+ esac
+ log info "Hint: apt-get install $MISSING_PACKAGE" >&2
+ fi
exit 1
elif [ ! -x "$(which $X)" ]; then
log error "$X is not executable." >&2
if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBDIFFCHOICES ] || \
[ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBDIFFCHOICES ] || \
[ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
- echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
+ echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
else
# We parse the 2 choices to diff, store them in temporary files and diff them.
for PARSECHOICE in $(echo $CDDBDIFFCHOICE | tr , \ ); do
TRACKNAME)
TRACKNAME="$(grep ^TTITLE$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | sed 's/\ \+$//')"
;;
+ TRACK-INFO)
+ grep ^EXTT$CDDBTRACKNUM= "$CDDBDATA" | cut -f2- -d= | tr -d \[:cntrl:\] | perl -p -e 's/\\n/\n/;'
+ ;;
esac
}
TRACKFILE="$(mungefilename "$TRACKNAME")"
ARTISTFILE="$(mungefilename "$TRACKARTIST")"
ALBUMFILE="$(mungefilename "$DALBUM")"
+ GENRE="$(mungegenre "$GENRE")"
+ YEAR=${CDYEAR:-$CDYEAR}
gettracknum
if [ "$ONETRACK" = "y" ]; then
if [ "$VARIOUSARTISTS" = "y" ]; then
case "$OUTPUT" in
flac)
run_command replaygain-flac nice $ENCNICE $METAFLAC --add-replay-gain "${OUTPUTFILES[@]}"
+ #run_command replaygain-flac true
;;
vorbis|ogg)
run_command replaygain-vorbis nice $ENCNICE $VORBISGAIN --album "${OUTPUTFILES[@]}"
;;
mp3)
- run_command replaygain-mp3 nice $ENCNICE $MP3GAIN -a "${OUTPUTFILES[@]}"
+ run_command replaygain-mp3 nice $ENCNICE $MP3GAIN -a -k "${OUTPUTFILES[@]}"
;;
mpc)
run_command replaygain-mpc nice $ENCNICE $MPPGAIN --auto "${OUTPUTFILES[@]}"
# do_tag [tracknumber]
# id3 tags a filename
# variables used:
-# TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC,
+# TRACKS, TRACKNAME, TRACKARTIST, TAGGER, TAGGEROPTS, VORBISCOMMENT, METAFLAC, ATOMICPARSLEY
# COMMENT, DALBUM, DARTIST, CDYEAR, CDGENRE (and temporarily) ID3TAGV
do_tag ()
{
COMMENTOUTPUT="$(eval echo ${COMMENT})"
+ if [ -z "$COMMENTOUTPUT" ]; then
+ COMMENTOUTPUT="$(getcddbinfo TRACK-INFO)"
+ fi
CDDBDISCID=$(echo $TRACKINFO | cut -d' ' -f1)
run_command '' echo "Tagging track $1 of $TRACKS: $TRACKNAME..."
# If we want to start the tracks with a given number, we need to modify the
run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS \
--comment=::"$COMMENTOUTPUT" -A "$DALBUM" \
-a "$TRACKARTIST" -t "$TRACKNAME" -Y "$CDYEAR" \
- -G "$GENREID" -n "${TRACKNUM:-$1}" "${TRACKNUM:+-N $TRACKS}" \
+ -G "$GENREID" -n "${TRACKNUM:-$1}" \
+ "${TRACKNUM:+-N $TRACKS}" \
"${ENCODING:+--set-encoding=$ENCODING}" \
"$ABCDETEMPDIR/track$1.$OUTPUT"
;;
# FIXME # Still not activated...
id3ed)
- run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
- -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" -y "$CDYEAR" \
- -g "$GENREID" -k "${TRACKNUM:-$1}" \
+ run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
+ $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
+ -a "$DALBUM" -n "$TRACKARTIST" -s "$TRACKNAME" \
+ -y "$CDYEAR" -g "$GENREID" -k "${TRACKNUM:-$1}" \
"$ABCDETEMPDIR/track$1.$OUTPUT"
;;
*)
# FIXME # track numbers in mp3 come with 1/10, so we cannot
# happily substitute them with $TRACKNUM
- run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
- -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" \
- -g "$GENREID" -T "${TRACKNUM:-$1/$TRACKS}" \
+ run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
+ $TAGGER $TAGGEROPTS -c "$COMMENTOUTPUT" \
+ -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
+ -y "$CDYEAR" -g "$GENREID" \
+ -T "${TRACKNUM:-$1/$TRACKS}" \
"$ABCDETEMPDIR/track$1.$OUTPUT"
;;
esac
mv "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
fi
(
- # These are from http://www.xiph.org/ogg/vorbis/doc/v-comment.html
+ # These are from
+ # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
+
echo ARTIST="$TRACKARTIST"
echo ALBUM="$DALBUM"
echo TITLE="$TRACKNAME"
echo GENRE="$CDGENRE"
fi
echo TRACKNUMBER=${TRACKNUM:-$1}
+ if [ -n "$DISCNUMBER" ]; then
+ echo DISCNUMBER="$DISCNUMBER"
+ fi
echo CDDB=$CDDBDISCID
if [ "$(eval echo ${COMMENT})" != "" ]; then
case "$COMMENTOUTPUT" in
*) echo COMMENT="$COMMENTOUTPUT";;
esac
fi
- ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
+ ) | run_command tagtrack-$OUTPUT-$1 nice $ENCNICE \
+ $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
"$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER" "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER"
- # Doublecheck that the commented file was created successfully before wiping the original
+ # Doublecheck that the commented file was created
+ # successfully before wiping the original
if [ -f "$ABCDETEMPDIR/track$1.$OGGOUTPUTCONTAINER" ]; then
rm -f "$ABCDETEMPDIR/track$1.uncommented.$OGGOUTPUTCONTAINER"
else
echo GENRE="$CDGENRE"
fi
echo TRACKNUMBER="${TRACKNUM:-$1}"
+ if [ -n "$DISCNUMBER" ]; then
+ echo DISCNUMBER="$DISCNUMBER"
+ fi
echo CDDB="$CDDBDISCID"
if [ "$(eval echo ${COMMENT})" != "" ]; then
case "$COMMENTOUTPUT" in
run_command tagtrack-$OUTPUT-$1 true
;;
m4a)
- run_command tagtrack-$OUTPUT-$1 true
+ # Use a temp-file of our choice. --overWrite seems to
+ # case core dumps with AtomicParsley 0.9.0
+ ATOMICTEMPFILE="$ABCDETEMPDIR/track$1.m4a-atomic"
+
+ VARIOUSBOOL="false"
+ if [ "$VARIOUSARTISTS" = "y" ]; then
+ VARIOUSBOOL="true"
+ fi
+
+ #It has to be command file opts for AtomicParsley
+ 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
+ if [ -f $ATOMICTEMPFILE ]; then
+ mv "$ATOMICTEMPFILE" "$ABCDETEMPDIR/track$1.m4a"
+ fi
;;
wav)
run_command tagtrack-$OUTPUT-$1 true
# OUTPUTTYPE, {FOO}ENCODERSYNTAX, ENCNICE, ENCODER, ENCODEROPTS
do_nogap_encode ()
{
- # The commands here don't go through run_command because they're never supposed to be silenced
+ # The commands here don't go through run_command because they're never
+ # supposed to be silenced
echo "Encoding gapless MP3 tracks: $TRACKQUEUE"
for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
do
fi
fi
fi
- # Other encoders fall through to normal encoding as the tracks
- # have not been entered in the status file.
+ # Other encoders fall through to normal encoding as the tracks have not
+ # been entered in the status file.
}
# do_encode [tracknumber] [hostname]
read ERASEPLAYLIST
case $ERASEPLAYLIST in
e|E|a|A|k|K) DONE=y ;;
+ "") ERASEPLAYLIST=e ; DONE=y ;;
*) ;;
esac
done
echo REM DISCID $DISCID
echo FILE \"dummy.wav\" WAVE
- if [ $1 -ne 150 ] ; then
- if [ $MODE = PREGAP ] ; then
- OFFSET=$1
- else
- OFFSET=150
- fi
+ if [ $1 -ne 150 ] && [ $MODE = "PREGAP"] ; then
+ OFFSET=$1
+ else
+ OFFSET=150
fi
i=1
exit 1
fi
echo -n .
- # It's a directory, let's see if it's owned by us
- if [ ! -O "$ABCDETEMPDIR" ]; then
+ # It's a directory, let's see if it's writable by us
+ if [ ! -r "$ABCDETEMPDIR" ] || [ ! -w "$ABCDETEMPDIR" ] || [ ! -x "$ABCDETEMPDIR" ]; then
# Nope, complain and exit
echo >&2
- echo "abcde: directory $ABCDETEMPDIR already exists and is not owned by you." >&2
+ echo "abcde: directory $ABCDETEMPDIR already exists and is not writeable." >&2
echo "Please investigate, remove it, and rerun abcde." >&2
exit 1
fi
RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
case "$RESPONSECODE" in
210) # 210 OK, status information follows (until terminating `.')
- rc=0;
+ rc=0
;;
- 501|*) # 501 Illegal CDDB protocol level: <n>.
+ 501) # 501 Illegal CDDB protocol level: <n>.
CDDBPROTO=`expr $CDDBPROTO - 1`
;;
+ *) # Try a cddb query, since freedb2.org doesn't support the stat or ver commands
+ # FreeDB TESTCD disc-id is used for query
+ $CDDBTOOL query $CDDBURL $CDDBPROTO $CDDBUSER $CDDBHOST 03015501 1 296 344 > "$ABCDETEMPDIR/cddbstat"
+ RESPONSECODE=$(head -n 1 "$ABCDETEMPDIR/cddbstat" | cut -f1 -d' ')
+ case "$RESPONSECODE" in
+ 2??) # Server responded, everything seems OK
+ rc=0
+ ;;
+ esac
+ ;;
esac
done
if test $rc -eq 1; then
if [ $PARSECHOICE1 -lt 1 ] || [ $PARSECHOICE1 -gt $CDDBCHOICES ] || \
[ $PARSECHOICE2 -lt 1 ] || [ $PARSECHOICE2 -gt $CDDBCHOICES ] || \
[ $PARSECHOICE1 -eq $PARSECHOICE2 ]; then
- echo "Invalid diff range. Please select two coma-separated numbers between 1 and $CDDBCHOICES" >&2
+ echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBCHOICES" >&2
else
# We parse the 2 choices to diff, store them in temporary files and diff them.
for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
:
}
+# post_encode
+# Empty post_encode function, to be defined in the configuration file.
+post_encode ()
+{
+:
+}
+
###############################################################################
# End of functions
#
ID3=id3
ID3V2=id3v2
EYED3=eyeD3
+VORBISCOMMENT=vorbiscomment
+METAFLAC=metaflac
+AACTAG=faac
+
CDPARANOIA=cdparanoia
CDDA2WAV=cdda2wav
DAGRAB=dagrab
EJECT=eject
MD5SUM=md5sum
DISTMP3=distmp3
-VORBISCOMMENT=vorbiscomment
-METAFLAC=metaflac
NORMALIZE=normalize-audio
CDSPEED=eject
VORBISGAIN=vorbisgain
# List of prefered cdromreaders - by default, run whichever we have in the path
DEFAULT_CDROMREADERS="cdparanoia cdda2wav"
+# List of quality levels associated with the encoders:
+DEFAULT_QUALITY_XLO="oggenc:-q -1,lame:-q 9,speex:--quality 1,m4a:"
+DEFAULT_QUALITY_LO="oggenc:-q 1,lame:-q 7,speex:--quality 5,m4a:"
+DEFAULT_QUALITY_HI="oggenc:-q 7,lame:--preset standard,speex:--quality 9,m4a:"
+DEFAULT_QUALITY_XHI="oggenc:-q 10,lame:--preset extreme,speex:--quality 10,m4a:"
+
# Asume fetch if under FreeBSD. curl is used for Mac OS X. wget is used for
# Linux/OpenBSD. ftp is user for NetBSD.
# Let's use these checkings to determine the OS flavour, which will be used
USEID3=y
USEID3V2=y
+# There we go..
+# But before we get into business, let us chop off any GREP environmental
+# variables.
+GREP_OPTIONS=""
+GREP_COLOR=""
+
if [ -z "$OUTPUTDIR" ]; then
OUTPUTDIR=$(pwd)
fi
if [ "$HTTPGETOPTS" = "" ] ; then
case $HTTPGET in
- wget) HTTPGETOPTS="-q -O -";;
+ wget) HTTPGETOPTS="-q -nv -e timestamping=off -O -";;
curl) HTTPGETOPTS="-f -s";;
fetch)HTTPGETOPTS="-q -o -";;
ftp) HTTPGETOPTS="-a -V -o - ";;
fi
# Parse command line options
-#while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPr:Rs:S:t:T:vVxw:W: opt ; do
+#while getopts 1a:bc:C:d:Dehj:klLmMnNo:pPq:r:Rs:S:t:T:vVxw:W: opt ; do
while getopts 1a:bBc:C:d:Defghj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
case "$opt" in
1) ONETRACK=y ;;
o) OUTPUTTYPE="$OPTARG" ;;
p) PADTRACKS=y ;;
P) USEPIPES=y ;;
+ q) QUALITYLEVEL="$OPTARG" ;;
r) REMOTEHOSTS="$OPTARG" ;;
R) CDDBLOCALRECURSIVE=y ;;
s) SHOWCDDBFIELDS="$OPTARG" ;;
X) CUE2DISCID="$OPTARG" ;;
w) COMMENT="$OPTARG" ;;
W) if echo $OPTARG | grep "[[:digit:]]" > /dev/null 2>&1 ; then
- STARTTRACKNUMBER="${OPTARG}01" ; STARTTRACKNUMBERTAG="y" ; COMMENT="CD${OPTARG}"
+ STARTTRACKNUMBER="${OPTARG}01"
+ STARTTRACKNUMBERTAG="y"
+ COMMENT="CD${OPTARG}"
+ DISCNUMBER="${OPTARG}"
else
log error "argument of -W must be integer"
exit 1
else
while [ $# -gt 0 ]; do
# Range parsing code courtesy of Vincent Ho
- RSTART=$(echo $1 | cut -f1 -d-)
- REND=$(echo $1 | cut -f2 -d-)
- if [ "$RSTART" = "$REND" ]; then
- NEWTRACKS="$RSTART"
- else
- NEWTRACKS=$(f_seq_line $RSTART $REND)
- fi
- TRACKQUEUE=$(echo "$TRACKQUEUE" "$NEWTRACKS")
+ # Cleaned up to use shell built-ins by Charles Steinkuehler
+ if [ "${1#*[^0-9-]}" != "$1" ]; then
+ log error "syntax error while processing track numbers"
+ else
+ RSTART=${1%%-*}
+ REND=${1##*-}
+ while [ ${RSTART:=1} -le ${REND:=0} ] ; do
+ TRACKQUEUE="$TRACKQUEUE $RSTART"
+ RSTART=$(( $RSTART + 1 ))
+ done
+ fi
shift
done
fi
DOREPLAYGAIN=n
DOPLAYLIST=n
DOCLEAN=n
-DOCUE=n
+## FIXME ## Lets keep compatibility with -M
+[ "$DOCUE" != "y" ] && DOCUE=n
for ACTION in $(echo $ACTIONS | tr , \ )
do
BATCHNORM=n
fi
-# Check the encoding format from the ones available in the system, if nothing has been configured in the system.
+# Check the encoding format from the ones available in the system, if nothing has been configured.
if [ X"$OUTPUTTYPE" = "X" ]; then
for DEFAULT_OUTPUT in $( echo "$DEFAULT_OUTPUT_BINARIES" | tr , \ ); do
DEFAULT_OUTPUT_FORMAT="$(echo $DEFAULT_OUTPUT | cut -d ":" -f 1)"
;;
m4a)
[ "$AACENCODERSYNTAX" = "default" ] && AACENCODERSYNTAX=faac
+ [ "$DOTAG" = "y" ] && CHECKATOMICPARSLEY=y
;;
wav)
if [ "$KEEPWAVS" = "y" ]; then
flac)
FLACENCODEROPTS="${FLACENCODEROPTSCLI:-$FLACOPTS}"
FLACENCODER="$FLAC"
+ if [ "$DOREPLAYGAIN" = "y" ]; then
+ FLACENCODEROPTS="${FLACENCODEROPTS} --replay-gain"
+ fi
# FLAC streams can be encapsulated on a Ogg transport layer
if echo "$FLACENCODEROPTS" | egrep -- "(^| )--ogg($| )" > /dev/null 2>&1 ;then
log error "FLAC on an Ogg container is not yet supported"
TAGGEROPTS="$ID3V2OPTS"
fi
-# Specific for NOGAP is the use of lame. Another encoder fails...
+# NOGAP is specific to lame. Other encoders fail ...
if [ "$NOGAP" = "y" ] && [ ! "$MP3ENCODER" = "lame" ]; then
- log warning "the NOGAP option is specific of lame. Deactivating..."
+ log warning "the NOGAP option is specific to lame. Deactivating..."
NOGAP=n
fi
for X in $CDROMREADER $CDDISCID ${NEEDTAGGER+$TAGGER} $MP3ENCODER \
$OGGENCODER $FLACENCODER $SPEEXENCODER $MPPENCODER \
$AACENCODER \
+ ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
${NEEDHTTPGET+$HTTPGET} ${NEEDDISTMP3+$DISTMP3} \
${NEEDCOMMENTER+$VORBISCOMMENT} ${NEEDMETAFLAC+$METAFLAC} \
${NEEDNORMALIZER+$NORMALIZER} ${NEEDEJECT+$EJECT} \
checkexec "$X"
done
+if [ "$CHECKATOMICPARSLEY" = "y" ]; then
+ if ! new_checkexec "$ATOMICPARSLEY"; then
+ echo "WARNING: $ATOMICPARSLEY Not Found Not Post-Tagging!"
+ DOTAG='n'
+ else
+ echo "Using $ATOMICPARSLEY To Tag AAC Tracks."
+ fi
+fi
+
# And last but not least, check if we can diff between files. We do not abort,
# since diffing is not critical...
if [ -x $(which $DIFF) ]; then :; else
# Here it used to say:
# One thousand lines in, we can start doing stuff with things
-# Well, right now we are at line 3306 ;)
+# Well, right now we are at line 3737 ;)
# Export needed things so they can be read in this subshell
export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
do_replaygain
fi
+# Execute the user-defined post_encode function before cleaning up
+post_encode
+
# Check to see if run_command logged any errors
if [ -f "$ABCDETEMPDIR/errors" ]; then
log error "The following commands failed to run:"