Album art (Part 2 of3)
authorAndrew Strong <andrew.david.strong@gmail.com>
Sat, 2 May 2015 10:12:27 +0000 (20:12 +1000)
committerAndrew Strong <andrew.david.strong@gmail.com>
Sat, 2 May 2015 10:12:27 +0000 (20:12 +1000)
Major enhancements of the new getalbumart function which for the
most part will require ImageMagick:

 1.The use of ImageMagick's 'identify' to give a user configurable
   commandline description of the album art
 2.The use of ImageMagick's 'display' to give a user configurable
   visual display of the album art
 3.The ability to manually download a different image using either
   URL or local path
 4.The ability to convert image formats, or to simply modify the
   downloaded album art, using ImageMagick's 'convert'

More detail on these options and on getalbumart in general will
come in the final commit of the album art updates. Thanks to
Richard for all of his hard work on this!!

abcde
abcde.conf

diff --git a/abcde b/abcde
index 704f4c3..0546c14 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -2983,10 +2983,6 @@ do_getalbumart()
        # set variables
        ALBUMFILE="$(mungefilename "$DALBUM")"
        ARTISTFILE="$(mungefilename "$DARTIST")"
-       # cover file name
-       if [ x"$ALBUMARTFILE" = "x" ]; then
-               ALBUMARTFILE="cover.jpg"
-       fi
        # have we got a musicbrainz mbid or amazon asin?
        case "$CDDBMETHOD" in
                musicbrainz)
@@ -3028,6 +3024,61 @@ do_getalbumart()
                        ALBUMARTURL="glyrc"
                fi
        fi
+       if [ "$INTERACTIVE" = "y" ]; then
+               if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
+                       # display properties of coverart when identify is available
+                       if new_checkexec $IDENTIFY; then
+                               $IDENTIFY $IDENTIFYOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2
+                       fi
+                       # display coverart when DISPLAY is set and display command is available
+                       if new_checkexec $DISPLAYCMD && [ "$DISPLAY" != "" ]; then
+                               $DISPLAYCMD $DISPLAYCMDOPTS "$ABCDETEMPDIR/$ALBUMARTFILE" >&2 &
+                       fi
+               else
+                       # nothing downloaded yet
+                       vecho "automatic album art downloading failed" >&2
+               fi
+               # see if the user can find a better album art manually
+               echo -n "Do you want to enter URL or local path for the album art [y/N]? " >&2
+               read YESNO
+               while [ "$YESNO" != "y" ] && [ "$YESNO" != "n" ] && [ "$YESNO" != "Y" ] && \
+                       [ "$YESNO" != "N" ] && [ "$YESNO" != "" ]
+               do
+                       echo -n 'Invalid selection. Please answer "y" or "n": ' >&2
+                       read YESNO
+               done
+               if [ "$YESNO" = "y" ] || [ "$YESNO" = "Y" ]; then
+                       echo -n "Enter URL or local path (ENTER to cancel) :" >&2
+                       read ALBUMARTURL
+                       if [ ! -z "$ALBUMARTURL" ]; then
+                               if [[ ${ALBUMARTURL} =~ (https?|ftp|file)://.* ]]; then
+                                       $HTTPGET "$ALBUMARTURL" > "$ABCDETEMPDIR/$ALBUMARTFILE"
+                                       if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
+                                               vecho "unable to download $ALBUMARTURL" >&2
+                                       fi
+                               else # it's a local path
+                                       cp "$ALBUMARTURL" "$ABCDETEMPDIR/$ALBUMARTFILE"
+                                       if [ ! -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
+                                               vecho "unable to copy $ALBUMARTURL to $ABCDETEMPDIR/$ALBUMARTFILE" >&2
+                                       fi
+                               fi
+                       fi
+               fi
+       fi
+       # convert to ALBUMARTTYPE if ImageMagick is available, if not assume correct type
+       if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ] && new_checkexec $IDENTIFY; then
+               ALBUMARTURLTYPE=$($IDENTIFY "$ABCDETEMPDIR/$ALBUMARTFILE" | cut -d' ' -f2)
+               if [ "$ALBUMARTURLTYPE" != "$ALBUMARTTYPE" -o "$ALBUMARTALWAYSCONVERT" = "y" ]; then
+                       if new_checkexec $CONVERT; then
+                               mv "$ABCDETEMPDIR/$ALBUMARTFILE" "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
+                               $CONVERT "$ABCDETEMPDIR/$ALBUMARTFILE.tmp" $CONVERTOPTS "$ABCDETEMPDIR/$ALBUMARTFILE"
+                               rm -f "$ABCDETEMPDIR/$ALBUMARTFILE.tmp"
+                       else
+                               rm -f "$ABCDETEMPDIR/$ALBUMARTFILE"
+                               vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
+                       fi
+               fi
+       fi
        # copy to target directories
        if [ -s "$ABCDETEMPDIR/$ALBUMARTFILE" ]; then
                for OUTPUT in $(echo $OUTPUTTYPE | tr , \ )
@@ -3406,6 +3457,9 @@ MKTOC=cdrdao
 DIFF=diff
 CUE2DISCID=builtin
 GLYRC=glyrc
+IDENTIFY=identify
+CONVERT=convert
+DISPLAYCMD=display
 
 # Options for programs called from abcde
 # mp3
@@ -3464,7 +3518,15 @@ MKTOCOPTS=""
 VORBISCOMMENTOPTS="-R"
 METAFLACOPTS="--no-utf8-convert"
 DIFFOPTS=
-GLYRCOPTS="--formats jpg;jpeg"
+GLYRCOPTS=
+IDENTIFYOPTS=
+CONVERTOPTS=
+DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
+
+# Defaults for album art downloads
+ALBUMARTFILE="cover.jpg"
+ALBUMARTTYPE="JPEG"
+ALBUMARTALWAYSCONVERT="n"
 
 # Default to one process if -j isn't specified
 MAXPROCS=1
index ac12778..f55e34d 100644 (file)
 #WVGAIN=wvgain
 #APETAG=apetag
 #GLYRC=glyrc
+#IDENTIFY=identify
+#CONVERT=convert
+#DISPLAYCMD=display
 
 # Options to call programs with:
 
 
 # album art download options (see glyrc's help for details with more detailed 
 # examples here: https://github.com/sahib/glyr/wiki/Commandline-arguments).
+# For example use '--formats jpg;jpeg' to only search for JPEG images
 # These options: '--from <provider>' and '--lang <langcode>' might also be useful
-#GLYRCOPTS="--formats jpg;jpeg"
+#GLYRCOPTS=
 #ALBUMARTFILE="cover.jpg"
+#ALBUMARTTYPE="JPEG"
+
+# Options for ImageMagick commands used by album art processing when available
+# For example: CONVERTOPTS="-colorspace RGB -resize 600x600>"
+# to make the image RGB and fit inside 600x600 while keeping the aspect ratio
+#IDENTIFYOPTS=
+#CONVERTOPTS=
+#DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
+# By default convert is only called when the image type is different from
+# ALBUMARTTYPE, use ALBUMARTALWAYSCONVERT="y" to always call convert
+#ALBUMARTALWAYSCONVERT="n"
 
 # Custom filename munging:
 # By default, abcde will do the following to CDDB data to get a useful