abcde: Downloading Album Art...
I have been associated with the commandline audio cd ripper abcde for many years now, first as a user, then as a writer of sample ~/.abcde.conf files and finally as one of several developers with commit access to the abcde source. If I am remembered at all for this long association I hope that it will be because I facilitated the introduction of automated and semi-automated album art downloading to abcde. Not my work: the original idea and patches came from Johannes Gernemann and further enhancements came from Richard, but I was privileged to work with these fine scripters and finally commit their work to abcde.
I wrote the documentation for these commits (and this page is heavily based on the documentation in the abcde source, particularly the FAQ doc) but I soon realised that downloading album art from within abcde would benefit from expanded documentation. Hence the creation of this page where I aim to explore a little deeper the possibilities inherent in the new abcde function getalbumart(). In this exploration I aim to increase my own knowledge of this amazing function and hopefully allow others to benefit from my exploration.
- The Basics... Getting the album art downloaded with no fuss.
- Getting started... A few simple pointers to get right at the beginning, particularly the correct version of abcde to use!
- Setting the CDDBMETHOD... Deciding where the cd info should come from, very important when also searching for album art.
- Running getalbumart... The required commandlines and conf file settings to get it all running.
- Going a little deeper...
- Magic with ImageMagick... Using getalbumart with the extra functionality provided by ImageMagick.
- A plethora of options... How to use the many, many options available with getalbumart and ImageMagick.
- Options for glyrc... Some suggested options for the music related metadata search engine glyrc.
- Options for identify... Suggested options for ImageMagick's identify utility.
- Options for display... Suggested options for ImageMagick's display utility.
- Options for convert... Suggested options for ImageMagick's convert utility.
- Embeding the image... For those who also wish to embed the album art withing their encoded files.
- Embedding for mp3 files... A post_encode function to embed the album art in mp3 files.
- Embedding for flac files... A post_encode function to embed the album art in flac files.
- Embedding for m4a/neroAacEnc files... A post_encode function to embed the album art in m4a files encoded with neroAacEnc.
- Embedding for m4a with AtomicParsley... A post_encode function to embed album art in m4a files using AtomicParsley.
Remember to send me an email if you have any comment on this page or wish to suggest any improvements, I have included an email link at the base of this page and I am always ready to chat to abcde enthusiasts! Perhaps also consider dropping in on the new Freenode IRC channel: #abcde and we can chat in realtime :).
The Basics...
Here I will show how to get the most basic level of functionality which I suspect will be enough to keep most people happy. It does not take much preparation at all to get a matching album art image named "cover.jpg" placed in with your encoded files to be read by your hardware device or shown by software applications such as vlc or audacious..
Getting started...
To get the best possible experience downloading album art with abcde I would advise you have organised the following:
- You should install latest version of abcde, as I write this page this means using abcde 2.7 and greater. The functionality of downloading album art is not included in abcde version 2.6 and earlier.
- It is highly recommended that you make use of Steve McIntyre's
abcde-musicbrainz-toolwhich will allow interrogation of the MusicBrainz database. This is included with the abcde source and together with its related Perl packages it is the recommended tool for CDDB enquiries. - You will need to install the music related meta data search application
glyras abcde will use its commandline toolglyrcas a 3rd line downloader for the album art.
And this is all that is needed to get basic album art downloading with abcde! There are enough sane defaults in place so that further fine tuning is not really necessary. However downloading album art is not an abcde default so a few more steps are required.
Setting the CDDBMETHOD...
The most important setting is to select the appropriate CDDBMETHOD and to understand the importance of this it is necessary to know a little about how getalbumart works. There are three methods in descending order that getalbumart uses:
- If CDDBMETHOD is musicbrainz the album art is downloaded from coverartarchive by MBID (MusicBrainz Identifier). This is a 36 character Universally unique identifier that is placed on each entity in the musicbrainz database. This gives a very high chance of a successful match.
- If the first method fails, download is tried from amazon by ASIN (Amazon Standard Identification Number), a standard number given by Amazon to identify its products.
- If the first and second methods fail or if CDDBMETHOD is 'cddb' the album art will be downloaded using
glyrcwith search by artist + album title
Hence the importance of using MusicBrainz, this way you are much more likely to get an appropriate image (This is not to downplay glyrc, in my experience this application does absolutely amazing work and has been very effective in accurately finding the correct album art). MusicBrainz is not the default and so must be set your ~/.abcde.conf file, also give the correct location of glyrc if it is not in your $PATH:
CDDBMETHOD=musicbrainz GLYRC=glyrc
This is sufficient setup to now look at using the appropriate commands to download our album art!
Running getalbumart...
You can run getalbumart from the abcde commandline with a command similar to the following:
abcde -o mp3:-V2 -a default,playlist,getalbumart
or you can simply use the '-G' commandline option. My own practise is to have an ~/.abcde.conf file especially set for mp3 encoding with lame and call this as follows:
abcde -c ~/.abcde.conf_mp3 -G
Perhaps this will also work for you? There are many choices to make and it is simply a matter of finding the workflow that suits you the best. Another alternative is to set album art downloading permanently in your ~/.abcde.conf file as follows:
ACTIONS=cddb,read,getalbumart,encode,tag,move,playlist,clean
There are several other options that can be set in an ~/.abcde.conf file which I will now discuss.
Going a little deeper...
We move a little deeper now into this amazing function and illustrate the many other options that can be tweaked in downloading images. The possibilities are extended greatly if you have installed ImageMagick and you are running abcde in interactive mode (this is the default).
Magic with ImageMagick...
Now the getalbumart will work perfectly well without ImageMagick installed and in fact if you have set abcde to run in non-interactive mode your album art will be downloaded with no intervention from you at all. However if you have ImageMagick installed several other aspects of getalbumart will spring into life, in the following order:
- The
identifyutility will be used to give a commandline readout of the selected image. - The
displayutility will be used to give a visual representation of the selected image in a user selected window size (the default window size will be 512x512, maintaining aspect ratio).) - There will be then a commandline option to dowload an alternative image either from an online or local source.
- The
convertutility will then optionally convert the downloaded image to the format of your choice.
All of these options are configurable by the user with options set in the ~/.abcde.conf file as I detail below.
A plethora of options...
Anybody remember the Three Amigos? Well in fact there are a plethora of options that can be set for downloading album art with abcde. These are set in your ~/.abcde.conf file as follows:
# Specify the path to the application. In most cases the application # should be in your $PATH as I illustrate below, otherwise you will # need to specify the full path. For example: /usr/bin/glyrc #GLYRC=glyrc #IDENTIFY=identify #CONVERT=convert #DISPLAYCMD=display # 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= #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"
Remember that to use these options you should remove the '#' mark at the front of the line. The existing defaults will work fine but at the risk of 'gilding the lily' I have investigated a little further with a few suggested options below.
Options for glyrc...
glyrc is the third option when downloading album art but it is a strong option with the possibility of adding your own options. Full options are given here and my own options are:
GLYRCOPTS="--qsratio 1.0 --from all;-slothradio; --lang en"
This sets the quality to speed weighting at the maximum quality ration (default is 0.85), the next option excludes slothradio from the album art search as it has been a little unpredictable for me and I specify an English language code. I used to also specify a fascinating screen-filling verbosity level: --verbosity 4 which shows all of the network connections, but this has been problematic from within abcde. If you successfully use other options please let me know and I will test and publish the options with suitable acknowledgement.
Options for identify...
In abcde 2.7 ImageMagick's identify is passed without any options and gives a simple commandline readout before those who have the display utility also installed see a graphical display of the image. A sample readout is:
cover.jpg JPEG 1394x1394 1394x1394+0+0 8-bit sRGB 306KB 0.020u 0:00.019
and this gives (in order): the filename, the image type, width and height, geometry, colour depth, colour space, filesize and both user time and elapsed time. Probably enough for our purposes but as with all of the ImageMagick utilities there are many, many options that could be used by the compulsive commandline user. On my own system I use the following simple option in my ~/.abcde.conf file:
IDENTIFYOPTS="-verbose"
This will exhaustively analyse the album art and produce a truly impressive report on the image that I plan to eventually pare down with the use of the -format option (when I eventually learn how to use it properly!). I would be more than happy to hear from those who have produced a better set of options for identify and I will publish those options here.
Options for convert...
You may possible have no need for any extra options with ImageMagick's convert utility. By default the end format of the album art is set in abcde and convert will only spring into action if the downloaded image is not a JPEG:
ALBUMARTFILE="cover.jpg" ALBUMARTTYPE="JPEG" # By default convert is only called when the image type is different from # ALBUMARTTYPE, use ALBUMARTALWAYSCONVERT="y" to always call convert ALBUMARTALWAYSCONVERT="n"
So if you start downloading PNG or BMP files these will automagically be converted to JPEG with no intervention required by you. But I use convert for a slightly different purpose which is to optimise the often blown out size of album art files by setting the following:
ALBUMARTALWAYSCONVERT="y" CONVERTOPTS="-strip -interlace Plane -gaussian-blur 0.05 -quality 85%"
I am not nearly clever enough to have come up with these options which can be seen, along with some discussion, here. These options can radically decrease image size with little or no loss in observable JPEG quality and are ideal if you are considering embeding the album art into your encoded files. Do you use other options? PLease let me know and will test them out and publish here, with suitable acknowledgement.
Options for display...
The good news is that with the display utility the hard lifting has already been done and the following options are hard-wired within abcde:
DISPLAYCMDOPTS="-resize 512x512 -title abcde_album_art"
The resize command does not actually alter the size of the image, it simply gives it a frame to be displayed in while preserving aspect ratio. The title option just gives a name to the image window and of course can be altered to whatever you feel is suitable. The usual encyclopaedic options can be found here but I confess that in this case the default options are enough for me. Let me know if there are some options that you feel are useful...
Embeding the image...
It was a good choice to make the default action in abcde when downloading images simply to place an image named 'cover.jpg' in with the encoded files. Applications such as Audacious and vlc understand this and many hardware players will do the same. However if you wish to actually embed the album art in the encoded file this can be done using the post_encode function of abcde as I illustrate below. I would love to improve on this work so please let me know if you can do better than my own fumbling efforts here :).
Embedding for mp3 files...
I wrote the following function for mp3 encoded files and also included it in the abcde FAQ document. I have tested it extensively and it works very nicely, simply place it in your ~/.abcde.conf file, make sure you are using eyeD3 to tag and all will be well!
#--------------------------------------------------------------------------#
# A post_encode function to embed album art downloaded with abcde 2.7 #
# and greater using the new getalbumart function. OUTPUTTYPE must be #
# mp3 and and tagging is with eyeD3. To use this function copy the #
# entire code block and paste it into your ~/.abcde.conf file. #
# #
# abcde: Downloading Album Art... #
# http://www.andrews-corner.org/getalbumart.html #
#--------------------------------------------------------------------------#
post_encode ()
{
ARTISTFILE="$(mungefilename "$TRACKARTIST")"
ALBUMFILE="$(mungefilename "$DALBUM")"
if [ "$VARIOUSARTISTS" = "y" ] ; then
FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
else
FINDPATH="$(eval echo "$OUTPUTFORMAT")"
fi
FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
cd "$FINALDIR"
if [ "$OUTPUTTYPE" = "mp3" ] && [ "$TAGGER" = "$EYED3" ] ; then
vecho "Preparing to embed the album art..." >&2
else
vecho "Not embedding album art, you need mp3 output and eyeD3 tagging..." >&2
return 1
fi
if [ -e "cover.jpg" ] ; then
for i in *.mp3
do
eyeD3 --add-image cover.jpg:FRONT_COVER "$i"
done
mkdir backup
mv cover.jpg backup
vecho "Your files have had the album art embedded..." >&2
else
vecho "No album art found so no image embedded..." >&2
fi
}
Feel free to suggest a more elegant implementation and I will publish it here as well as altering the syntax in the abcde FAQ document. And now something similar for flac encoded files.
Embedding for flac files...
The post_encode function worked so nicely for mp3 encoded files that I simply reworked it a little and tested it for flac files. The following post_encode function should be placed in your ~/.abcde.conf file and should reliably embed the album art into your flac files:
#--------------------------------------------------------------------------#
# A post_encode function to embed album art downloaded with abcde 2.7 #
# and greater using the new getalbumart function. OUTPUTTYPE must be #
# flac and and tagging is with metaflac. To use this function copy the #
# entire code block and paste it into your ~/.abcde.conf file. #
# #
# abcde: Downloading Album Art... #
# http://www.andrews-corner.org/getalbumart.html #
#--------------------------------------------------------------------------#
post_encode ()
{
ARTISTFILE="$(mungefilename "$TRACKARTIST")"
ALBUMFILE="$(mungefilename "$DALBUM")"
if [ "$VARIOUSARTISTS" = "y" ] ; then
FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
else
FINDPATH="$(eval echo "$OUTPUTFORMAT")"
fi
FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
cd "$FINALDIR"
if [ "$OUTPUTTYPE" = "flac" ] ; then
vecho "Preparing to embed the album art..." >&2
else
vecho "Not embedding album art, you need flac output.." >&2
return 1
fi
if [ -e "cover.jpg" ] ; then
for i in *.flac
do
metaflac --import-picture-from=cover.jpg "$i"
done
mkdir backup
mv cover.jpg backup
vecho "Your files have had the album art embedded..." >&2
else
vecho "No album art found so no image embedded..." >&2
fi
}
Embedding for m4a/neroAacEnc files...
This is a post_encode function for the neroAacEnc encoder that produces m4a files tagged with neroAacTag. I have tested it thoroughly and it has worked consistently and predictably. The images show in Audacious and vlc under Linux but I have not tested further than this. Please let me know of any improvements you can produce with this function and its reasonably primitive error checking!
#--------------------------------------------------------------------------#
# A post_encode function to embed album art downloaded with abcde 2.7 #
# and greater using the new getalbumart function. OUTPUTTYPE should be #
# m4a, AACENCODERSYNTAX should be neroAacEnc and tagging should be with #
# neroAacTag. To use this function copy the entire code block and paste #
# it into your ~/.abcde.conf file. #
# #
# abcde: Downloading Album Art... #
# http://www.andrews-corner.org/getalbumart.html #
#--------------------------------------------------------------------------#
post_encode ()
{
ARTISTFILE="$(mungefilename "$TRACKARTIST")"
ALBUMFILE="$(mungefilename "$DALBUM")"
if [ "$VARIOUSARTISTS" = "y" ] ; then
FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
else
FINDPATH="$(eval echo "$OUTPUTFORMAT")"
fi
FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
cd "$FINALDIR"
if [ "$OUTPUTTYPE" = "m4a" ] && [ "$AACENCODERSYNTAX" = "neroAacEnc" ] ; then
vecho "Preparing to embed the album art..." >&2
else
vecho "Not embedding album art, you need m4a output and neroAacEnc encoding..." >&2
return 1
fi
if [ -e "cover.jpg" ] ; then
for i in *.m4a
do
$NEROAACTAG "$i" -add-cover:front:cover.jpg
done
mkdir backup
mv cover.jpg backup
vecho "Your files have had the album art embedded..." >&2
else
vecho "No album art found so no image embedded..." >&2
fi
}
Embedding for m4a with AtomicParsley...
I have held off publishing this method with AtomicParsey as proper checks for AtomicParsley were introduced in abcde 2.7.1 and I am aware that this is not in wide circulation yet, so bear in mind that this function does not check for the presence of AtomicParsley but will fail without it! You would be best as well to download the newest AtomicParsley to avoid an older issue with seg faults with the overwrite function used here. I use this post_encode function extensively with qaac and abcde.
#--------------------------------------------------------------------------#
# A post_encode function to embed album art downloaded with abcde 2.7 #
# and greater using the new getalbumart function. OUTPUTTYPE should be #
# m4a and you will need to have a modern copy of AtomicParsley installed. #
# To use this function copy the entire code block and paste it into #
# your ~/.abcde.conf file. #
# #
# abcde: Downloading Album Art... #
# http://www.andrews-corner.org/getalbumart.html #
#--------------------------------------------------------------------------#
post_encode ()
{
ARTISTFILE="$(mungefilename "$TRACKARTIST")"
ALBUMFILE="$(mungefilename "$DALBUM")"
if [ "$VARIOUSARTISTS" = "y" ] ; then
FINDPATH="$(eval echo "$VAOUTPUTFORMAT")"
else
FINDPATH="$(eval echo "$OUTPUTFORMAT")"
fi
FINALDIR="$(dirname "$OUTPUTDIR/$FINDPATH")"
cd "$FINALDIR"
# No checking here for the presence of AtomicParsley, abcde 2.7.1
# and later have this functionality but this post_encode function
# is aimed at 2.7.0...
if [ "$OUTPUTTYPE" = "m4a" ] ; then
vecho "Preparing to embed the album art..." >&2
else
vecho "Not embedding album art, you need m4a output and AtomicParsley.." >&2
return 1
fi
if [ -e "cover.jpg" ] ; then
for i in *.m4a
do
AtomicParsley "$i" --artwork cover.jpg --overWrite
done
rm cover.jpg
vecho "Your files have had the album art embedded..." >&2
else
vecho "No album art found so no image embedded..." >&2
fi
}
That is as far as I have experimented with album art embedding, let me know of any experimentation you have tried with other formats! Currently I am working on the slightly more involved process of embedding images into ogg files.
And in conclusion...
I have enjoyed delving a little deeper into abcde to write this page, hopefully you have enjoyed coming along with me? Please feel free to use the email address at the base of this page to pass on your thoughts about this page, any corrections, praise or condemnation. If you are feeling especially generous perhaps you could also assist me keep this page alive by assisting with the hosting bills for this site, if not please feel free to utilise this page in any way you see fit and remember: "Have Fun!".