package com.namelessdev.mpdroid.cover;

import de.umass.lastfm.Album;
import de.umass.lastfm.ImageSize;

public class LastFMCover implements ICoverRetriever {

	public String[] getCoverUrl(String artist, String album, String path, String filename) throws Exception {
		String key = "7fb78a81b20bee7cb6e8fad4cbcb3694";
		
		Album albumObj = Album.getInfo(artist, album, key);
		if(albumObj == null) {
			return null;
		}else{
			return new String[] { albumObj.getImageURL(ImageSize.MEGA) };
		}
	}

	@Override
	public boolean isCoverLocal() {
		return false;
	}

	@Override
	public String getName() {
		return "LastFM";
	}
}

@@ -44,65 +44,172 @@
 ort 
-de.umass.lastfm.Album;%0Aimport de.umass.lastfm.ImageSize;%0A
+android.util.Log;%0Aimport org.xmlpull.v1.XmlPullParser;%0Aimport org.xmlpull.v1.XmlPullParserFactory;%0A%0Aimport java.io.StringReader;%0A%0A/**%0A * Fetch cover from LastFM%0A */
 %0Apub
@@ -234,441 +234,1837 @@
 ver 
-implements ICoverRetriever %7B%0A%0A%09public String%5B%5D getCoverUrl(String artist, String album, String path, String filename) throws Exception %7B%0A%09%09String key = %227fb78a81b20bee7cb6e8fad4cbcb3694%22;%0A%09%09%0A%09%09Album albumObj = Album.getInfo(artist, album, key);%0A%09%09if(albumObj == null) %7B%0A%09%09%09return null;%0A%09%09%7Delse%7B%0A%09%09%09return new String%5B%5D %7B albumObj.getImageURL(ImageSize.MEGA) %7D;%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public boolean isCoverLocal() %7B%0A%09%09return false;%0A%09%7D%0A%0A%09
+extends AbstractWebCover %7B%0A%0A    private static String KEY = %227fb78a81b20bee7cb6e8fad4cbcb3694%22;%0A    private static final String URL = %22http://ws.audioscrobbler.com/2.0/%22;%0A%0A    @Override%0A    public String%5B%5D getCoverUrl(String artist, String album, String path, String filename) throws Exception %7B%0A%0A        String response;%0A        String request;%0A        String sizeAttribute = null;%0A        String imageUrl;%0A        XmlPullParserFactory factory;%0A        XmlPullParser xpp;%0A        int eventType;%0A%0A        try %7B%0A            request = URL + %22?method=album.getInfo&artist=%22 + artist + %22&album=%22 + album + %22&api_key=%22 + KEY;%0A            response = executeGetRequest(request);%0A%0A            factory = XmlPullParserFactory.newInstance();%0A            factory.setNamespaceAware(true);%0A            xpp = factory.newPullParser();%0A%0A            xpp.setInput(new StringReader(response));%0A            eventType = xpp.getEventType();%0A%0A            while (eventType != XmlPullParser.END_DOCUMENT) %7B%0A                if (eventType == XmlPullParser.START_TAG) %7B%0A                    if (xpp.getName().equals(%22image%22)) %7B%0A                        sizeAttribute = xpp.getAttributeValue(null, %22size%22);%0A                    %7D%0A                %7D else if (eventType == XmlPullParser.TEXT) %7B%0A                    if (sizeAttribute != null && sizeAttribute.equals(%22mega%22)) %7B%0A                        imageUrl = xpp.getText();%0A                        if (imageUrl != null && imageUrl.length() %3E 0) %7B%0A                            return new String%5B%5D%7BimageUrl%7D;%0A                        %7D%0A                    %7D%0A                %7D%0A                eventType = xpp.next();%0A            %7D%0A        %7D catch (Exception e)%0A%0A        %7B%0A            Log.e(LastFMCover.class.toString(), %22Failed to get cover URL from LastFM :%22 + e);%0A        %7D%0A%0A        return new String%5B0%5D;%0A    %7D%0A%0A    
 @Ove
@@ -2069,17 +2069,21 @@
 verride%0A
-%09
+%0A    
 public S
@@ -2104,10 +2104,16 @@
 ) %7B%0A
-%09%09
+        
 retu
@@ -2129,9 +2129,12 @@
 M%22;%0A
-%09
+    
 %7D%0A%7D%0A

Improve coverart fetching - Replace the whole LastFM project by a single class.