+ echo "get-album-art=none" >> "${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:
+ ALBUMFILE="$(mungealbumname "$DALBUM")"
+ ARTISTFILE="$(mungeartistname "$DARTIST")"
+ GENRE="$(mungegenre "$GENRE")"
+ YEAR=${CDYEAR:-$CDYEAR}
+
+ # Allow for multiple output formats:
+ for OUTPUT in $(echo "$OUTPUTTYPE" | tr , \ )
+ do
+ # Find the output directory for multi track encodes:
+ if [ "$ONETRACK" != "y" ] ; then
+ if [ "$VARIOUSARTISTS" = "y" ] ; then
+ FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
+ else
+ FINDPATH="$(eval echo "$OUTPUTFORMAT")"
+ fi
+ fi
+ # Find the output directory for single track encodes:
+ if [ "$ONETRACK" = "y" ] ; then
+ if [ "$VARIOUSARTISTS" = "y" ] ; then
+ FINDPATH="$(eval echo "$VAONETRACKOUTPUTFORMAT")"
+ else
+ FINDPATH="$(eval echo "$ONETRACKOUTPUTFORMAT")"
+ fi
+ 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
+ ;;
+ ogg)
+ # ----------------
+ # This technique is drawn from 2 sources (the first link being the primary source):
+ # 1. https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
+ # 2. https://github.com/acabal/scripts/blob/master/ogg-cover-art
+ # In abcde a few steps are used in this sequence:
+ #
+ # 1. Create a 'legal' header for the cover art image
+ # 2. Makes a copy of the existing tags
+ # 3. base64 the cover art image
+ # 4. Copy the original tags + the base64 image back to the original ogg file
+ #
+ # Might need some fine tuning but it is a start for abcde 2.8.2 Andrew.
+ # FIXME: I am not sure if there is a maximum size for images converted in this
+ # way, but this could be perhaps handled by CONVERTOPTS called from do_getalbumart.
+ # ----------------
+ # First some variables we can reuse:
+ # Use MIMETYPECOVER to allow use of either png or the more common jpeg:
+ MIMETYPECOVER=$(file -b --mime-type "$ALBUMARTFILE")
+ EXPORTTAGS="${ABCDETEMPDIR}/export_ogg_tags"
+ BUILDHEADER="${ABCDETEMPDIR}/build_header"
+ # Now build the header, gory details are here:
+ # https://xiph.org/flac/format.html#metadata_block_picture
+ # Picture Type:
+ printf "0: %.8x" 3 | xxd -r -g0 > "$BUILDHEADER"
+ # Mime type length
+ printf "0: %.8x" $(echo -n "$MIMETYPECOVER" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
+ # Mime type:
+ echo -n "$MIMETYPECOVER" >> "$BUILDHEADER"
+ # Description length. FIXME: I have used 'Cover Image' but I am not sure
+ # if this is better left as an empty field. Andrew
+ printf "0: %.8x" $(echo -n "Cover Image" | wc -c) | xxd -r -g0 >> "$BUILDHEADER"
+ # Description:
+ echo -n "Cover Image" >> "$BUILDHEADER"
+ # Picture width:
+ printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
+ # Picture height:
+ printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
+ # Picture color depth:
+ printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
+ # Picture color count:
+ printf "0: %.8x" 0 | xxd -r -g0 >> "$BUILDHEADER"
+ # Image file size:
+ printf "0: %.8x" $(wc -c "$ALBUMARTFILE" | cut --delimiter=' ' --fields=1) | xxd -r -g0 >> "$BUILDHEADER"
+ # cat the image file:
+ cat "$ALBUMARTFILE" >> "$BUILDHEADER"
+ # Now process each ogg file by first exporting the original tags then
+ # appending the cover image and finally copying the whole thing back
+ # to the original image:
+ for i in *.ogg
+ do
+ # Make a backup of the existing tags:
+ "$VORBISCOMMENT" --list --raw "$i" > "EXPORTTAGS"
+ # base64 the file and then mix it all together with the exported tags:
+ echo "metadata_block_picture=$(base64 --wrap=0 < "$BUILDHEADER")" >> "EXPORTTAGS"
+ # Update the original ogg file with exported tags and the appended base64'd image:
+ "$VORBISCOMMENT" --write --raw --commentfile "EXPORTTAGS" "$i"
+ # Delete the EXPORTTAGS file ready to be recreated for the next file in the loop,
+ # note that the header file BUILDHEADER will be reused for each file in the loop:
+ rm "EXPORTTAGS"
+ 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