Getting album art using Amazon Web Services
June 24, 2008
Ever wanted to get CD album art from within a custom Java app? Amazon Web Services are the perfect tool for the job. In fact, you can get a whole lot more than just album art – you could, if you wanted, build a full Amazon store front using there vast APIs.
But lets just dip our toe in the water and see how easy it is to get CD artwork using the Amazon Associates Web Service. Start by signing up for a free account here. Amazon will send you a access key which you’ll need when calling their web services. This key doesn’t have to be kept super secret, as it will be passed as plain text through the internet (though I chose not to include my key in the demo below).
Next, download the Java APIs here (you need to be logged in with the account you created above).
Now all you need to do is call the service with code like this (note that this is a class I created and isn’t part of the API):
public class AmazonWebServiceUtils { public static ImageIcon getAlbumArtImageIcon( String artist, String album, String accessKeyId) throws Exception { // build the search request that looks for images of music. ItemSearchRequest request = new ItemSearchRequest(); request.setSearchIndex("Music"); request.setResponseGroup(Arrays.asList("Images")); request.setArtist(artist); request.setTitle(album); // create a new amazon client using the access key. sign up for an // amazon web services account here: // https://aws-portal.amazon.com/gp/aws/developer/registration/index.html AmazonA2SClient client = new AmazonA2SClient(accessKeyId, ""); // create a search response from the search request. ItemSearchResponse response = client.itemSearch(request); // get the URL to the amazon image (if one was returned). String url = response.getItems().get(0).getItem().get(0).getLargeImage().getURL(); // create an ImageIcon from the returned URL. if the URL is null, then // the icon returned will also be null. return createImageIcon(url); } private static ImageIcon createImageIcon(String url) { ImageIcon icon = null; try { icon = url == null ? null : new ImageIcon(new URL(url)); } catch (MalformedURLException e) { // do nothing - don't care. } return icon; } }
If you look at the Javadoc for ItemSearchRequest, you’ll notice that you can easily lookup many more types of objects, like books and movies and can get more than just image data about them.
June 25, 2008 at 2:00 am
Great tip! I just tried it with Groovy and it works marvelously
July 11, 2008 at 9:49 pm
very nice tip! and very nice music taste ;)
July 12, 2008 at 1:05 am
Thanks Cristian…Avenged Sevenfold is a fantastic band!
October 29, 2009 at 12:29 am
The API link is broken. WHere can I downlod them?
October 29, 2009 at 1:32 pm
I believe this is the new link:
http://developer.amazonwebservices.com/connect/entry.jspa?externalID=132&categoryID=47
I’ve update the post.
November 24, 2009 at 5:21 am
It works this way! Thanks!
December 10, 2009 at 3:28 pm
hi,
could you tell me how to use this pls. i’m new to aws and fairly new to java.
i’ve downloaded the amazon api
but which of the amazon classes do i create a new instance off to make your methods work?
what is ItemSearchRequest,AmazonA2SClient and ItemSearchResponse? i’m getting an error on those…
cannot find symbol for all 3 of those words?
any help pls?
March 13, 2010 at 3:45 am
@andre and anyone else who will have this problem
This guide is not totally complete for those of us just starting out using amazon. There is a whole series of steps you must complete first
I ran into the exact same problem and could not figure out where to include the ItemSearchResponse from. You need to go generate some code first, see this link in the amazon docs:
http://docs.amazonwebservices.com/AWSECommerceService/2009-10-01/GSG/index.html?GettingtheToolsYouNeed.html
May 25, 2011 at 6:13 pm
I have the same problem (really newbie using AWS, i just want to get the artwork in a music player i developed in Java) and the link you posted there is no available anymore. Could you please update it?
Thanks!
November 24, 2011 at 7:11 pm
Does it cost anything to use this at Amazon. I didnt found anything about that on the website.
July 23, 2013 at 8:04 am
[…] like your question is less about Android and more about how to get album art in general. Perhaps this article on retrieving album art from Amazon will be helpful. Once you have a local copy and store it as […]
September 4, 2013 at 7:18 pm
the api link is again broken , where can i download the api??
September 11, 2013 at 7:02 am
This this really free? Will it charge me after going beyond free tier usage of AWS?