* support fanart.tv

This commit is contained in:
Reinhard Pointner 2012-07-16 02:42:15 +00:00
parent ef80b0ec10
commit dfc9f118e8
3 changed files with 162 additions and 3 deletions

View File

@ -13,3 +13,4 @@ analytics.WebPropertyID: UA-25379256-3
thetvdb.apikey: 58B4AA94C59AD656
themoviedb.apikey: 5a6edae568130bf10617b6d45be99f13
serienjunkies.apikey: 9fbhw9uebfiwvbefzuwv
fanart.tv.apikey: 780b986b22c35e6f7a134a2f392c2deb

View File

@ -6,6 +6,7 @@ import static net.sourceforge.filebot.Settings.*;
import net.sourceforge.filebot.web.AnidbClient;
import net.sourceforge.filebot.web.EpisodeListProvider;
import net.sourceforge.filebot.web.FanartTV;
import net.sourceforge.filebot.web.IMDbClient;
import net.sourceforge.filebot.web.MovieIdentificationService;
import net.sourceforge.filebot.web.OpenSubtitlesClient;
@ -29,13 +30,16 @@ public final class WebServices {
public static final TheTVDBClient TheTVDB = new TheTVDBClient(getApplicationProperty("thetvdb.apikey"));
public static final SerienjunkiesClient Serienjunkies = new SerienjunkiesClient(getApplicationProperty("serienjunkies.apikey"));
// movie dbs
public static final IMDbClient IMDb = new IMDbClient();
public static final TMDbClient TMDb = new TMDbClient(getApplicationProperty("themoviedb.apikey"));
// subtitle dbs
public static final OpenSubtitlesClient OpenSubtitles = new OpenSubtitlesClient(String.format("%s %s", getApplicationName(), getApplicationVersion()));
public static final SubsceneSubtitleClient Subscene = new SubsceneSubtitleClient();
// movie dbs
public static final IMDbClient IMDb = new IMDbClient();
public static final TMDbClient TMDb = new TMDbClient(getApplicationProperty("themoviedb.apikey"));
// fanart.tv
public static final FanartTV FanartTV = new FanartTV(Settings.getApplicationProperty("fanart.tv.apikey"));
public static EpisodeListProvider[] getEpisodeListProviders() {

View File

@ -0,0 +1,154 @@
package net.sourceforge.filebot.web;
import static net.sourceforge.filebot.web.WebRequest.*;
import static net.sourceforge.tuned.XPathUtilities.*;
import java.io.File;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import net.sourceforge.filebot.web.FanartTV.FanartDescriptor.FanartProperty;
public class FanartTV {
private String apikey;
public FanartTV(String apikey) {
this.apikey = apikey;
}
public List<FanartDescriptor> getArtwork(int tvdbid) throws Exception {
return getArtwork(tvdbid, "all", 1, 2);
}
public List<FanartDescriptor> getArtwork(int tvdbid, String type, int sort, int limit) throws Exception {
String xml = new CachedPage(getResource(tvdbid, "xml", type, sort, limit)).get();
Document dom = getDocument(xml);
List<FanartDescriptor> fanart = new ArrayList<FanartDescriptor>();
for (Node node : selectNodes("//*[@url]", dom)) {
// e.g. <seasonthumb id="3481" url="http://fanart.tv/fanart/tv/70327/seasonthumb/3481/Buffy (6).jpg" lang="en" likes="0" season="6"/>
Map<FanartProperty, String> data = new EnumMap<FanartProperty, String>(FanartProperty.class);
data.put(FanartProperty.type, node.getNodeName());
for (FanartProperty prop : FanartProperty.values()) {
String value = getAttribute(prop.name(), node);
if (value != null) {
data.put(prop, value);
}
}
fanart.add(new FanartDescriptor(data));
}
return fanart;
}
public URL getResource(int tvdbid, String format, String type, int sort, int limit) throws MalformedURLException {
// e.g. http://fanart.tv/webservice/series/780b986b22c35e6f7a134a2f392c2deb/70327/xml/all/1/2
return new URL(String.format("http://fanart.tv/webservice/series/%s/%s/%s/%s/%s/%s", apikey, tvdbid, format, type, sort, limit));
}
public static class FanartDescriptor implements Serializable {
public static enum FanartProperty {
type,
id,
url,
lang,
likes,
season
}
protected Map<FanartProperty, String> fields;
protected FanartDescriptor() {
// used by serializer
}
protected FanartDescriptor(Map<FanartProperty, String> fields) {
this.fields = new EnumMap<FanartProperty, String>(fields);
}
public String get(Object key) {
return fields.get(FanartProperty.valueOf(key.toString()));
}
public String get(FanartProperty key) {
return fields.get(key);
}
public String getType() {
return fields.get(FanartProperty.type);
}
public Integer getId() {
try {
return new Integer(fields.get(FanartProperty.id));
} catch (Exception e) {
return null;
}
}
public String getName() {
return new File(getUrl().getFile()).getName();
}
public URL getUrl() {
try {
return new URL(fields.get(FanartProperty.url));
} catch (Exception e) {
return null;
}
}
public Integer getLikes() {
try {
return new Integer(fields.get(FanartProperty.likes));
} catch (Exception e) {
return null;
}
}
public Integer getSeason() {
try {
return new Integer(fields.get(FanartProperty.season));
} catch (Exception e) {
return null;
}
}
@Override
public String toString() {
return fields.toString();
}
}
}