4

Is there any simple Web API which returns album art as an image, just like the Google Static Map API (Google Static Map API? I have heard about Amazon's and Last.fm's APIs for this, but can't find any code for that (other than in web languages like PHP/Perl/Ruby etc). Moreover they are REST APIs. Any help would be appreciated.

Is there a simple URL(GET) queries or are there only REST/XML methods?

starball
  • 20,030
  • 7
  • 43
  • 238
Codevalley
  • 4,593
  • 7
  • 42
  • 56

2 Answers2

3

It shouldn't be very hard to do by hand. The last.fm api spec for Album.getInfo method is pretty straightforward and the fact that it is a REST api makes it even simpler. Just get the xml response from the server, parse it and get a url of the image. I wrote this code a while ago but it should still be working:

            String request = "http://ws.audioscrobbler.com/2.0/?method=" + method +
                    "&api_key="+apiKey;
            request += "&artist=" + artist.replaceAll(" ", "%20");
            if (method.equals("album.getinfo")) request += "&album=" + album.replaceAll(" ", "%20");
            URL url = new URL(request);
            InputStream is = url.openStream();
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = db.parse(is);

            NodeList nl = doc.getElementsByTagName("image");
            for (int i = 0; i < nl.getLength(); i++) {
                Node n = nl.item(i);
                if (n.getAttributes().item(0).getNodeValue().equals(imageSize)) {
                    Node fc = n.getFirstChild();
                    if (fc == null) return null;
                    String imgUrl = fc.getNodeValue();
                    if (imgUrl.trim().length() == 0) return null;
                    return new ImageIcon(new URL(imgUrl));
                }
            }
Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68
  • the api key you get from last.fm at http://www.last.fm/api/account. you can use the test one b25b959554ed76058ac220b7b2e0a026 but make sure to get your own. – Denis Tulskiy Dec 22 '10 at 09:25
0

Here's the Amazon API samples for C# SOAP/REST.

Lazarus
  • 41,906
  • 4
  • 43
  • 54
  • LOL You are joking right? http://aws.amazon.com/code/Product-Advertising-API/2478 & http://aws.amazon.com/code/Product-Advertising-API/2479, you could just start at the top... http://aws.amazon.com/code/Product-Advertising-API – Lazarus Dec 22 '10 at 13:49
  • @Roberto No, it isn't. Just clicked on it now and it takes you to the correct page. – Lazarus Jan 30 '18 at 08:50