# Copyright (c) 2003-2006 Jesus Climent <jesus.climent@hispalinux.es>
# Copyright (c) 2009-2012 Colin Tuckley <colint@debian.org>
# Copyright (c) 2012- Steve McIntyre <93sam@@debian.org>
-# Copyright (c) 2015- Andrew Strong <andrew.david.strong@gmail.com>
+# Copyright (c) 2015-2016 Andrew Strong <andrew.david.strong@gmail.com>
# This code is hereby licensed for public consumption under either the
# GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
#
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-VERSION='2.8'
+VERSION='2.8.2-UNRELEASED'
usage ()
{
echo "-1 Encode the whole CD in a single file"
echo "-a <action1[,action2]...>"
echo " Actions to perform:"
-echo " cddb,read,getalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
+echo " cddb,read,getalbumart,embedalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
#echo "-A Experimental actions (retag, transcode)"
echo "-b Enable batch normalization"
+echo "-B Embed albumart (this also activates getalbumart)"
echo "-c <file>"
echo " Specify a configuration file (overrides system and user config files)"
echo "-C <discid#>"
fi
# Do we have CD-Text on the disc (and can the drive read it?)
- ${CDTEXT_READER} -J -N -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
+ (
+ cd "$ABCDETEMPDIR" && rm -f audio.* audio_*
+ ${CDTEXT_READER} -J -v titles -D ${CDDA2WAVCDROM} > "$ABCDETEMPDIR/cd-text" 2>&1
+ )
grep -a -q '^CD-Text: detected' "$ABCDETEMPDIR/cd-text"
ERRORCODE=$?
if [ $ERRORCODE -ne 0 ]; then
echo "done." >> "$ABCDETEMPDIR/cddbchoices"
echo cddb-read-1-complete >> "$ABCDETEMPDIR/status"
echo cddb-choice=1 >> "$ABCDETEMPDIR/status"
- ATITLE=$(grep -ae '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- )
+ #ATITLE=$(grep -ae '^Album title:' "${ABCDETEMPDIR}/cd-text" | cut -c14- | sed "s~'\(.*\)'.*\[from \(.*\)]$~\2 / \1~")
+ ATITLE=$(grep -ae '^DTITLE=' "${ABCDETEMPDIR}/audio.cddb" | cut -c8-)
echo "200 none ${ATITLE}" >> "$ABCDETEMPDIR/cddbquery"
# List out disc title/author and contents
- echo ---- ${ATITLE} ---- >> "$ABCDETEMPDIR/cddbchoices"
- for TRACK in $(f_seq_row 1 $TRACKS)
- do
- TRACKM1=$(($TRACK - 1))
- TITLE="$(grep -aE ^Track\ +$TRACK: "$ABCDETEMPDIR/cd-text" | tr -d \\r\\n | sed 's~^Track ..: .~~g;'"s~'$~~g")"
- echo "$TRACK: $TITLE" >> "$ABCDETEMPDIR/cddbchoices"
- sed "s~^TTITLE${TRACKM1}=.*~TTITLE${TRACKM1}=${TITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new" && \
- mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
- done
- sed "s~^DTITLE=.*~DTITLE=${ATITLE}~" "$ABCDETEMPDIR/cddbread.1" > "$ABCDETEMPDIR/cddbread.new" && \
- mv -f "$ABCDETEMPDIR/cddbread.new" "$ABCDETEMPDIR/cddbread.1"
- rm -f "$ABCDETEMPDIR/cddbread.new" # In case a sed error occurred
+ echo "---- ${ATITLE} ----" >> "$ABCDETEMPDIR/cddbchoices"
+ sed -n 's~^Track \(..:\) .\(.*\).$~\1 \2~gp;' "$ABCDETEMPDIR/cd-text" >>"$ABCDETEMPDIR/cddbchoices"
+ rm -f "$ABCDETEMPDIR/cddbread.1"
+ # XXX FIXME - this is a hack and should be replaced by proper
+ # character set tracking for the CDDB data we have.
+ if test "$CDDBPROTO" -ge 6 ; then
+ # convert to Unicode
+ iconv -f iso-8859-1 -t utf-8 <"$ABCDETEMPDIR/audio.cddb" >"$ABCDETEMPDIR/cddbread.1"
+ else
+ # copy verbatim, assuming CD-TEXT is in ISO-8859-1 format
+ # apparently icedax/cdda2wav have no support for 16-bit
+ # characters yet, either
+ cp -p "$ABCDETEMPDIR/audio.cddb" "$ABCDETEMPDIR/cddbread.1"
+ fi
+ ( cd "$ABCDETEMPDIR" && rm -f audio_* audio.* )
echo >> "$ABCDETEMPDIR/cddbchoices"
echo "cdtext-readcomplete" >> "$ABCDETEMPDIR/status"
}
fi
}
+# Optionally embed the albumart downloaded by the getalbumart fuction.
+# FIXME: It would be nice to have this also selectable from within the
+# FIXME: getalbumart function itself. Andrew
+do_embedalbumart()
+{
+ # Set variables:
+ ARTISTFILE="$(mungefilename "$TRACKARTIST")"
+ ALBUMFILE="$(mungefilename "$DALBUM")"
+ YEAR=${CDYEAR:-$CDYEAR}
+
+ # Allow for multiple output formats:
+ for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
+ do
+
+ # Find the output directory:
+ if [ "$VARIOUSARTISTS" = "y" ] ; then
+ FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
+ else
+ FINDPATH="$(eval echo "$OUTPUTFORMAT")"
+ fi
+
+ FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
+ cd "$FINALDIR"
+
+# Instructions for each format, feel free to add more. It would be nice to
+# make the backup directory selectable and perhaps also have an option for
+# the bold to simply have the image deleted. Work for another day... Andrew.
+ if [ -e "$ALBUMARTFILE" ] ; then
+ case "$OUTPUT" in
+ mp3)
+ for i in *.mp3
+ do
+ "$EYED3" --add-image "$ALBUMARTFILE":FRONT_COVER "$i"
+ done
+ mkdir "$FINALDIR"/albumart_backup
+ mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
+ vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
+ ;;
+ flac)
+ for i in *.flac
+ do
+ "$METAFLAC" --import-picture-from="$ALBUMARTFILE" "$i"
+ done
+ mkdir "$FINALDIR"/albumart_backup
+ mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
+ vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
+ ;;
+ m4a)
+ for i in *.m4a
+ do
+ "$ATOMICPARSLEY" "$i" --artwork "$ALBUMARTFILE" --overWrite
+ done
+ mkdir "$FINALDIR"/albumart_backup
+ mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
+ vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
+ ;;
+ wv)
+ for i in *.wv
+ do
+ "$WVTAG" --write-binary-tag "Cover Art (Front)=@"$ALBUMARTFILE"" "$i"
+ done
+ mkdir "$FINALDIR"/albumart_backup
+ mv "$ALBUMARTFILE" "$FINALDIR"/albumart_backup
+ vecho "Successfully embedded the album art into your $OUTPUT tracks" >&2
+ ;;
+ *) vecho "Sorry, abcde does not embed album art for the $OUTPUT container..." >&2
+ esac
+ else
+ vecho "Suitable cover image not found, no embedding done..." >&2
+ fi
+done
+}
+
# do_cdread [tracknumber]
# do_cdread onetrack [firsttrack] [lasttrack]
#
METAFLAC=metaflac
NEROAACTAG=neroAacTag
ATOMICPARSLEY=AtomicParsley
+WVTAG=wvtag
WINE=wine
CDPARANOIA=cdparanoia
esac
# Parse command line options
-while getopts 1a:bc:C:d:DefgGhj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
+while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pPr:s:S:t:T:UvVxX:w:W:z opt ; do
case "$opt" in
1) ONETRACK=y ;;
a) ACTIONS="$OPTARG" ;;
A) EXPACTIONS="$OPTARG" ;;
b) BATCHNORM=y ;;
+ B) GETALBUMART=y ; EMBEDALBUMART=y ;;
c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
C) DISCID="$( echo ${OPTARG#abcde.} | tr -d /)" ;;
d) CDROM="$OPTARG" ;;
playlist) DOCDDB=y; DOPLAYLIST=y;;
clean) DOCLEAN=y;;
getalbumart) GETALBUMART=y;;
+ embedalbumart) GETALBUMART=y; EMBEDALBUMART=y;;
esac
done
[ "$MP3ENCODERSYNTAX" = "default" ] && MP3ENCODERSYNTAX=lame
[ "$DOTAG" = "y" ] && NEEDTAGGER=y
[ "$DOREPLAYGAIN" = "y" ] && NEEDMP3GAIN=y
+ [ "$EMBEDALBUMART" = "y" ] && NEEDEYED3=y
;;
flac)
[ "$FLACENCODERSYNTAX" = "default" ] && FLACENCODERSYNTAX=flac
[ "$DOTAG" = "y" ] && NEEDMETAFLAC=y
[ "$DOREPLAYGAIN" = "y" ] && NEEDMETAFLAC=y
[ "$ONETRACK" = "y" ] && [ "$DOCUE" = "y" ] && NEEDMETAFLAC=y
+ [ "$EMBEDALBUMART" = "y" ] && NEEDMETAFLAC=y
;;
spx)
[ "$SPEEXENCODERSYNTAX" = "default" ] && SPEEXENCODERSYNTAX=speexenc
[ "$DOTAG" = "y" ]
[ "$DOREPLAYGAIN" = "y" ] && NEEDWVGAIN=y
[ "$WVENCODERSYNTAX" = "ffmpeg" ] && DOREPLAYGAIN=n
+ [ "$EMBEDALBUMART" = "y" ] && NEEDWVTAG=y
;;
ape)
[ "$APENCODERSYNTAX" = "default" ] && APENCODERSYNTAX=mac
[ "$AACENCODERSYNTAX" = "qaac" ] && NEEDWINE=y
[ "$AACENCODERSYNTAX" = "fhgaacenc" ] && NEEDWINE=y && NEEDATOMICPARSLEY=y
[ "$AACENCODERSYNTAX" = "ffmpeg" ] && [ "$DOTAG" = "y" ]
+ [ "$EMBEDALBUMART" = "y" ] && NEEDATOMICPARSLEY=y
;;
wav)
if [ "$KEEPWAVS" = "y" ]; then
${NEEDWVGAIN+WVGAIN} ${NEEDAPETAG+$APETAG} \
${NEEDCUE2DISCID+$CUE2DISCID} ${NEEDNEROAACTAG+$NEROAACTAG} \
${NEEDGLYRC+$GLYRC} ${NEEDWINE+$WINE} ${NEEDATOMICPARSLEY+$ATOMICPARSLEY} \
- ${NEEDMID3V2+$MID3V2}
+ ${NEEDMID3V2+$MID3V2} ${NEEDEYED3+$EYED3} ${NEEDWVTAG+$WVTAG}
do
checkexec "$X"
done
do_replaygain
fi
+if [ "$EMBEDALBUMART" = "y" ]; then
+ do_embedalbumart
+fi
+
# Execute the user-defined post_encode function before cleaning up
post_encode