Getting album art like JPEG, PNG, etc.

Can someone tell me if there is any simple web API that returns the album art as an image, just like the Google Static Map API ( Google Static Map API ? I heard about the Amazon API and Last.fm for of this, but I can’t find any code for it (except in web languages ​​such as PHP / Perl / Ruby, etc.). In addition, they are REST APIs. Any help would be appreciated.

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

+4
source share
2 answers

This should not be very difficult to do manually. The last.fm api specification for the Album.getInfo method is pretty simple, and the fact that it is a REST api makes it even easier. Just get the xml response from the server, parse it and get the image url. I wrote this code a while ago, but it should still work:

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)); } } 
+3
source

Source: https://habr.com/ru/post/1332914/


All Articles