2010-12-21 1 views
4

Google 정적지도 API (Google Static Map API)와 마찬가지로 앨범 아트를 이미지로 반환하는 간단한 웹 API가 있는지 알려줄 수 있습니까? 아마존의 앨범과 Last.fm의 앨범에 대해 들었습니다. 이것에 대한 API는 있지만 PHP/Perl/Ruby 등의 웹 언어가 아닌 다른 코드는 찾을 수 없습니다. 또한 REST API입니다.앨범 아트를 JPEG, PNG 등으로 가져 오기

간단한 URL이 있습니까? 쿼리 (GET) 또는이는 REST/XML 방법입니까?

답변

3

으로 할 열심히하지 않아야을 손. Album.getInfo 메서드에 대한 last.fm API 사양은 매우 간단하며 REST API임을 사용하면 훨씬 간단 해집니다. 그냥 서버에서 XML 응답을 가져 와서 구문 분석하고 이미지의 URL을 얻으십시오. 나는이 코드를 오래 전에 썼지 만 여전히 작동해야합니다 :

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

'apiKey' 란 무엇입니까? – Codevalley

+0

http://www.last.fm/api/account의 last.fm에서 가져 오는 api 키입니다. 당신은 하나의 테스트를 b25b959554ed76058ac220b7b2e0a026 사용할 수 있지만 자신의 것을 얻으십시오. –

0
+0

Java variant? – Codevalley

+0

LOL 너 농담하는거야? http://aws.amazon.com/code/Product-Advertising-API/2478 & http://aws.amazon.com/code/Product-Advertising-API/2479, 처음부터 시작할 수 있습니다 ... http://aws.amazon.com/code/Product-Advertising-API – Lazarus

+0

@Roberto 아니요, 그렇지 않습니다. 지금 클릭하면 올바른 페이지로 이동합니다. – Lazarus