2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot.web;
|
2009-01-04 13:28:28 -05:00
|
|
|
|
2013-09-11 13:22:00 -04:00
|
|
|
import static java.util.Arrays.*;
|
2014-04-19 02:30:29 -04:00
|
|
|
import static net.filebot.util.XPathUtilities.*;
|
|
|
|
import static net.filebot.web.EpisodeUtilities.*;
|
|
|
|
import static net.filebot.web.WebRequest.*;
|
2009-01-04 13:28:28 -05:00
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
2013-10-15 03:12:42 -04:00
|
|
|
import java.io.IOException;
|
2011-12-20 09:09:18 -05:00
|
|
|
import java.io.Serializable;
|
2011-12-20 08:00:38 -05:00
|
|
|
import java.net.MalformedURLException;
|
2009-01-04 13:28:28 -05:00
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.EnumMap;
|
|
|
|
import java.util.EnumSet;
|
2011-11-04 05:11:11 -04:00
|
|
|
import java.util.LinkedHashMap;
|
2009-01-04 13:28:28 -05:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
2011-12-30 05:35:26 -05:00
|
|
|
import java.util.Map.Entry;
|
2009-01-04 13:28:28 -05:00
|
|
|
import java.util.Random;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import javax.swing.Icon;
|
2009-07-13 08:41:19 -04:00
|
|
|
|
2014-04-19 02:30:29 -04:00
|
|
|
import net.filebot.Cache;
|
|
|
|
import net.filebot.ResourceManager;
|
|
|
|
import net.filebot.util.FileUtilities;
|
|
|
|
import net.filebot.web.TheTVDBClient.BannerDescriptor.BannerProperty;
|
|
|
|
import net.filebot.web.TheTVDBClient.SeriesInfo.SeriesProperty;
|
2009-01-04 13:28:28 -05:00
|
|
|
|
2012-07-25 00:34:20 -04:00
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
|
2011-08-08 13:37:45 -04:00
|
|
|
public class TheTVDBClient extends AbstractEpisodeListProvider {
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-11-13 13:22:50 -05:00
|
|
|
private final String host = "www.thetvdb.com";
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
private final Map<MirrorType, String> mirrors = new EnumMap<MirrorType, String>(MirrorType.class);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-11-13 13:22:50 -05:00
|
|
|
private final String apikey;
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
public TheTVDBClient(String apikey) {
|
2009-01-24 19:08:57 -05:00
|
|
|
if (apikey == null)
|
|
|
|
throw new NullPointerException("apikey must not be null");
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
this.apikey = apikey;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "TheTVDB";
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Override
|
|
|
|
public Icon getIcon() {
|
|
|
|
return ResourceManager.getIcon("search.thetvdb");
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Override
|
|
|
|
public boolean hasSingleSeasonSupport() {
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Override
|
2011-08-08 13:37:45 -04:00
|
|
|
public boolean hasLocaleSupport() {
|
|
|
|
return true;
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-07-14 10:54:07 -04:00
|
|
|
public String getLanguageCode(Locale locale) {
|
|
|
|
String code = locale.getLanguage();
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-07-14 10:54:07 -04:00
|
|
|
// Java language code => TheTVDB language code
|
|
|
|
if (code.equals("iw")) // Hebrew
|
|
|
|
return "he";
|
|
|
|
if (code.equals("hi")) // Hungarian
|
|
|
|
return "hu";
|
|
|
|
if (code.equals("in")) // Indonesian
|
|
|
|
return "id";
|
|
|
|
if (code.equals("ro")) // Russian
|
|
|
|
return "ru";
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-07-14 10:54:07 -04:00
|
|
|
return code;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-08-08 13:37:45 -04:00
|
|
|
@Override
|
2011-11-26 04:44:49 -05:00
|
|
|
public ResultCache getCache() {
|
2012-07-25 00:34:20 -04:00
|
|
|
return new ResultCache(host, Cache.getCache("web-datasource"));
|
2011-11-26 04:44:49 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-11-26 04:44:49 -05:00
|
|
|
@Override
|
2012-07-14 10:54:07 -04:00
|
|
|
public List<SearchResult> fetchSearchResult(String query, Locale locale) throws Exception {
|
2010-11-09 03:04:12 -05:00
|
|
|
// perform online search
|
2013-10-15 03:12:42 -04:00
|
|
|
Document dom = getXmlResource(MirrorType.SEARCH, "/api/GetSeries.php?seriesname=" + encode(query, true) + "&language=" + getLanguageCode(locale));
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
List<Node> nodes = selectNodes("Data/Series", dom);
|
2011-11-04 05:11:11 -04:00
|
|
|
Map<Integer, TheTVDBSearchResult> resultSet = new LinkedHashMap<Integer, TheTVDBSearchResult>();
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
for (Node node : nodes) {
|
2011-11-04 05:11:11 -04:00
|
|
|
int sid = getIntegerContent("seriesid", node);
|
2009-02-21 07:48:52 -05:00
|
|
|
String seriesName = getTextContent("SeriesName", node);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2014-08-15 04:16:30 -04:00
|
|
|
List<String> aliasNames = new ArrayList<String>();
|
2013-09-06 03:55:13 -04:00
|
|
|
for (Node aliasNode : selectNodes("AliasNames", node)) {
|
2014-08-15 04:16:30 -04:00
|
|
|
for (String aliasName : getTextContent(aliasNode).split("\\|")) {
|
|
|
|
if (aliasName.trim().length() > 0) {
|
|
|
|
aliasNames.add(aliasName.trim());
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
}
|
|
|
|
|
2011-11-04 05:11:11 -04:00
|
|
|
if (!resultSet.containsKey(sid)) {
|
2013-09-06 03:55:13 -04:00
|
|
|
resultSet.put(sid, new TheTVDBSearchResult(seriesName, aliasNames.toArray(new String[0]), sid));
|
2011-11-04 05:11:11 -04:00
|
|
|
}
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-11-04 05:11:11 -04:00
|
|
|
return new ArrayList<SearchResult>(resultSet.values());
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Override
|
2012-07-14 10:54:07 -04:00
|
|
|
public List<Episode> fetchEpisodeList(SearchResult searchResult, SortOrder sortOrder, Locale locale) throws Exception {
|
2011-08-08 13:37:45 -04:00
|
|
|
TheTVDBSearchResult series = (TheTVDBSearchResult) searchResult;
|
2014-07-24 08:10:59 -04:00
|
|
|
Document dom = getXmlResource(MirrorType.XML, "/api/" + apikey + "/series/" + series.getSeriesId() + "/all/" + getLanguageCode(locale) + ".xml");
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
// we could get the series name from the search result, but the language may not match the given parameter
|
2013-10-16 06:29:51 -04:00
|
|
|
String seriesName = selectString("Data/Series/SeriesName", dom);
|
2014-04-19 01:39:52 -04:00
|
|
|
SimpleDate seriesStartDate = SimpleDate.parse(selectString("Data/Series/FirstAired", dom), "yyyy-MM-dd");
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-10-16 06:29:51 -04:00
|
|
|
List<Node> nodes = selectNodes("Data/Episode", dom);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-11-26 04:44:49 -05:00
|
|
|
List<Episode> episodes = new ArrayList<Episode>(nodes.size());
|
2010-02-03 16:36:04 -05:00
|
|
|
List<Episode> specials = new ArrayList<Episode>(5);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
for (Node node : nodes) {
|
|
|
|
String episodeName = getTextContent("EpisodeName", node);
|
2010-11-15 05:06:24 -05:00
|
|
|
String dvdSeasonNumber = getTextContent("DVD_season", node);
|
|
|
|
String dvdEpisodeNumber = getTextContent("DVD_episodenumber", node);
|
2010-11-09 03:04:12 -05:00
|
|
|
Integer absoluteNumber = getIntegerContent("absolute_number", node);
|
2014-04-19 01:39:52 -04:00
|
|
|
SimpleDate airdate = SimpleDate.parse(getTextContent("FirstAired", node), "yyyy-MM-dd");
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
// default numbering
|
|
|
|
Integer episodeNumber = getIntegerContent("EpisodeNumber", node);
|
|
|
|
Integer seasonNumber = getIntegerContent("SeasonNumber", node);
|
2014-07-24 07:31:03 -04:00
|
|
|
SortOrder order = SortOrder.Airdate;
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2010-11-15 05:06:24 -05:00
|
|
|
if (seasonNumber == null || seasonNumber == 0) {
|
2010-02-03 16:36:04 -05:00
|
|
|
// handle as special episode
|
2010-10-24 08:10:30 -04:00
|
|
|
Integer airsBefore = getIntegerContent("airsbefore_season", node);
|
|
|
|
if (airsBefore != null) {
|
2010-02-03 16:36:04 -05:00
|
|
|
seasonNumber = airsBefore;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-10-23 10:09:41 -04:00
|
|
|
// use given episode number as special number or count specials by ourselves
|
|
|
|
Integer specialNumber = (episodeNumber != null) ? episodeNumber : filterBySeason(specials, seasonNumber).size() + 1;
|
2014-07-24 07:31:03 -04:00
|
|
|
specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, episodeName, null, specialNumber, order, locale, airdate, searchResult));
|
2010-02-03 16:36:04 -05:00
|
|
|
} else {
|
|
|
|
// handle as normal episode
|
2012-02-13 04:54:57 -05:00
|
|
|
if (sortOrder == SortOrder.Absolute) {
|
|
|
|
if (absoluteNumber != null) {
|
|
|
|
episodeNumber = absoluteNumber;
|
|
|
|
seasonNumber = null;
|
2014-07-24 07:31:03 -04:00
|
|
|
order = SortOrder.Absolute;
|
2012-02-13 04:54:57 -05:00
|
|
|
}
|
|
|
|
} else if (sortOrder == SortOrder.DVD) {
|
|
|
|
try {
|
2014-07-24 07:31:03 -04:00
|
|
|
int eno = new Float(dvdEpisodeNumber).intValue();
|
|
|
|
int sno = new Float(dvdSeasonNumber).intValue();
|
|
|
|
|
|
|
|
// require both values to be successfully read
|
|
|
|
episodeNumber = eno;
|
|
|
|
seasonNumber = sno;
|
|
|
|
order = SortOrder.DVD;
|
2012-02-13 04:54:57 -05:00
|
|
|
} catch (Exception e) {
|
|
|
|
// ignore, fallback to default numbering
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2014-07-24 07:31:03 -04:00
|
|
|
episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, episodeName, absoluteNumber, null, order, locale, airdate, searchResult));
|
2010-02-03 16:36:04 -05:00
|
|
|
}
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2010-11-15 05:06:24 -05:00
|
|
|
// episodes my not be ordered by DVD episode number
|
|
|
|
sortEpisodes(episodes);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2010-02-03 16:36:04 -05:00
|
|
|
// add specials at the end
|
|
|
|
episodes.addAll(specials);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
return episodes;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-07-14 10:54:07 -04:00
|
|
|
public TheTVDBSearchResult lookupByID(int id, Locale locale) throws Exception {
|
|
|
|
TheTVDBSearchResult cachedItem = getCache().getData("lookupByID", id, locale, TheTVDBSearchResult.class);
|
2012-01-01 22:07:09 -05:00
|
|
|
if (cachedItem != null) {
|
|
|
|
return cachedItem;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-10-20 09:10:21 -04:00
|
|
|
Document dom = getXmlResource(MirrorType.XML, "/api/" + apikey + "/series/" + id + "/all/" + getLanguageCode(locale) + ".xml");
|
|
|
|
String name = selectString("//SeriesName", dom);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-10-20 09:10:21 -04:00
|
|
|
TheTVDBSearchResult series = new TheTVDBSearchResult(name, id);
|
|
|
|
getCache().putData("lookupByID", id, locale, series);
|
|
|
|
return series;
|
2011-12-12 09:06:26 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-07-14 10:54:07 -04:00
|
|
|
public TheTVDBSearchResult lookupByIMDbID(int imdbid, Locale locale) throws Exception {
|
2014-05-26 12:47:04 -04:00
|
|
|
if (imdbid <= 0) {
|
|
|
|
throw new IllegalArgumentException("id must not be " + imdbid);
|
|
|
|
}
|
|
|
|
|
2012-07-14 10:54:07 -04:00
|
|
|
TheTVDBSearchResult cachedItem = getCache().getData("lookupByIMDbID", imdbid, locale, TheTVDBSearchResult.class);
|
2012-01-01 22:07:09 -05:00
|
|
|
if (cachedItem != null) {
|
|
|
|
return cachedItem;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-10-15 03:12:42 -04:00
|
|
|
Document dom = getXmlResource(null, "/api/GetSeriesByRemoteID.php?imdbid=" + imdbid + "&language=" + getLanguageCode(locale));
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-13 20:19:36 -05:00
|
|
|
String id = selectString("//seriesid", dom);
|
|
|
|
String name = selectString("//SeriesName", dom);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-13 20:19:36 -05:00
|
|
|
if (id == null || id.isEmpty() || name == null || name.isEmpty())
|
|
|
|
return null;
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-01-01 22:07:09 -05:00
|
|
|
TheTVDBSearchResult series = new TheTVDBSearchResult(name, Integer.parseInt(id));
|
2012-07-14 10:54:07 -04:00
|
|
|
getCache().putData("lookupByIMDbID", imdbid, locale, series);
|
2012-01-01 22:07:09 -05:00
|
|
|
return series;
|
2011-12-13 20:19:36 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Override
|
|
|
|
public URI getEpisodeListLink(SearchResult searchResult) {
|
2012-02-13 04:54:57 -05:00
|
|
|
return URI.create("http://" + host + "/?tab=seasonall&id=" + ((TheTVDBSearchResult) searchResult).getSeriesId());
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-10-15 03:12:42 -04:00
|
|
|
protected String getMirror(MirrorType mirrorType) throws IOException {
|
2009-01-04 13:28:28 -05:00
|
|
|
synchronized (mirrors) {
|
|
|
|
if (mirrors.isEmpty()) {
|
2011-12-20 09:09:18 -05:00
|
|
|
// try cache first
|
|
|
|
try {
|
|
|
|
@SuppressWarnings("unchecked")
|
2012-07-25 00:34:20 -04:00
|
|
|
Map<MirrorType, String> cachedMirrors = getCache().getData("mirrors", null, null, Map.class);
|
2011-12-20 09:09:18 -05:00
|
|
|
if (cachedMirrors != null) {
|
|
|
|
mirrors.putAll(cachedMirrors);
|
|
|
|
return mirrors.get(mirrorType);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.getMessage(), e);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
// initialize mirrors
|
2013-10-15 03:12:42 -04:00
|
|
|
Document dom = getXmlResource(null, "/api/" + apikey + "/mirrors.xml");
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
// all mirrors by type
|
|
|
|
Map<MirrorType, List<String>> mirrorListMap = new EnumMap<MirrorType, List<String>>(MirrorType.class);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
// initialize mirror list per type
|
|
|
|
for (MirrorType type : MirrorType.values()) {
|
|
|
|
mirrorListMap.put(type, new ArrayList<String>(5));
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
// traverse all mirrors
|
|
|
|
for (Node node : selectNodes("Mirrors/Mirror", dom)) {
|
|
|
|
// mirror data
|
2009-02-21 07:48:52 -05:00
|
|
|
String mirror = getTextContent("mirrorpath", node);
|
|
|
|
int typeMask = Integer.parseInt(getTextContent("typemask", node));
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
// add mirror to the according type lists
|
|
|
|
for (MirrorType type : MirrorType.fromTypeMask(typeMask)) {
|
|
|
|
mirrorListMap.get(type).add(mirror);
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
// put random entry from each type list into mirrors
|
|
|
|
Random random = new Random();
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
for (MirrorType type : MirrorType.values()) {
|
|
|
|
List<String> list = mirrorListMap.get(type);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
if (!list.isEmpty()) {
|
|
|
|
mirrors.put(type, list.get(random.nextInt(list.size())));
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-01-01 22:07:09 -05:00
|
|
|
getCache().putData("mirrors", null, null, mirrors);
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
return mirrors.get(mirrorType);
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-10-15 03:12:42 -04:00
|
|
|
protected Document getXmlResource(final MirrorType mirrorType, final String path) throws IOException {
|
|
|
|
CachedXmlResource resource = new CachedXmlResource(path) {
|
|
|
|
|
|
|
|
protected URL getResourceLocation(String path) throws IOException {
|
|
|
|
return getResourceURL(mirrorType, path);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// fetch data or retrieve from cache
|
2013-10-16 06:29:51 -04:00
|
|
|
try {
|
|
|
|
return resource.getDocument();
|
|
|
|
} catch (FileNotFoundException e) {
|
2013-10-20 22:30:11 -04:00
|
|
|
throw new FileNotFoundException("Resource not found: " + getResourceURL(mirrorType, path)); // simplify error message
|
2013-10-16 06:29:51 -04:00
|
|
|
}
|
2013-10-15 03:12:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected URL getResourceURL(MirrorType mirrorType, String path) throws IOException {
|
2013-03-25 05:35:17 -04:00
|
|
|
if (mirrorType != null) {
|
|
|
|
// use mirror
|
|
|
|
String mirror = getMirror(mirrorType);
|
|
|
|
if (mirror != null && mirror.length() > 0) {
|
|
|
|
return new URL(mirror + path);
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-03-25 05:35:17 -04:00
|
|
|
// use default server
|
|
|
|
return new URL("http", host, path);
|
2009-07-13 08:41:19 -04:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
protected static enum MirrorType {
|
2013-03-09 07:33:02 -05:00
|
|
|
XML(1), BANNER(2), ZIP(4), SEARCH(1);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
private final int bitMask;
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
private MirrorType(int bitMask) {
|
|
|
|
this.bitMask = bitMask;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
public static EnumSet<MirrorType> fromTypeMask(int typeMask) {
|
|
|
|
// initialize enum set with all types
|
|
|
|
EnumSet<MirrorType> enumSet = EnumSet.allOf(MirrorType.class);
|
|
|
|
for (MirrorType type : values()) {
|
|
|
|
if ((typeMask & type.bitMask) == 0) {
|
|
|
|
// remove types that are not set
|
|
|
|
enumSet.remove(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return enumSet;
|
|
|
|
};
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-02-14 09:16:13 -05:00
|
|
|
public SeriesInfo getSeriesInfoByID(int thetvdbid, Locale locale) throws Exception {
|
|
|
|
return getSeriesInfo(new TheTVDBSearchResult(null, thetvdbid), locale);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-01-02 10:27:20 -05:00
|
|
|
public SeriesInfo getSeriesInfoByIMDbID(int imdbid, Locale locale) throws Exception {
|
|
|
|
return getSeriesInfo(lookupByIMDbID(imdbid, locale), locale);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-02-08 07:24:36 -05:00
|
|
|
public SeriesInfo getSeriesInfoByName(String name, Locale locale) throws Exception {
|
|
|
|
for (SearchResult it : search(name, locale)) {
|
|
|
|
if (name.equalsIgnoreCase(it.getName())) {
|
|
|
|
return getSeriesInfo((TheTVDBSearchResult) it, locale);
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-02-08 07:24:36 -05:00
|
|
|
return null;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 03:31:57 -05:00
|
|
|
public SeriesInfo getSeriesInfo(TheTVDBSearchResult searchResult, Locale locale) throws Exception {
|
2011-12-21 00:54:30 -05:00
|
|
|
// check cache first
|
2012-01-01 22:07:09 -05:00
|
|
|
SeriesInfo cachedItem = getCache().getData("seriesInfo", searchResult.seriesId, locale, SeriesInfo.class);
|
2011-12-21 00:54:30 -05:00
|
|
|
if (cachedItem != null) {
|
|
|
|
return cachedItem;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-10-15 03:12:42 -04:00
|
|
|
Document dom = getXmlResource(MirrorType.XML, "/api/" + apikey + "/series/" + searchResult.seriesId + "/" + getLanguageCode(locale) + ".xml");
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
Node node = selectNode("//Series", dom);
|
|
|
|
Map<SeriesProperty, String> fields = new EnumMap<SeriesProperty, String>(SeriesProperty.class);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
// remember banner mirror
|
2013-10-15 03:12:42 -04:00
|
|
|
fields.put(SeriesProperty.BannerMirror, getResourceURL(MirrorType.BANNER, "/banners/").toString());
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
// copy values from xml
|
|
|
|
for (SeriesProperty key : SeriesProperty.values()) {
|
|
|
|
String value = getTextContent(key.name(), node);
|
|
|
|
if (value != null && value.length() > 0) {
|
|
|
|
fields.put(key, value);
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
SeriesInfo seriesInfo = new SeriesInfo(fields);
|
2012-01-01 22:07:09 -05:00
|
|
|
getCache().putData("seriesInfo", searchResult.seriesId, locale, seriesInfo);
|
2011-12-21 00:54:30 -05:00
|
|
|
return seriesInfo;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public static class SeriesInfo implements Serializable {
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public static enum SeriesProperty {
|
2013-07-13 06:01:33 -04:00
|
|
|
id, Actors, Airs_DayOfWeek, Airs_Time, ContentRating, FirstAired, Genre, IMDB_ID, Language, Network, Overview, Rating, RatingCount, Runtime, SeriesName, Status, BannerMirror, banner, fanart, poster
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
protected Map<SeriesProperty, String> fields;
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
protected SeriesInfo() {
|
|
|
|
// used by serializer
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
protected SeriesInfo(Map<SeriesProperty, String> fields) {
|
|
|
|
this.fields = new EnumMap<SeriesProperty, String>(fields);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String get(Object key) {
|
|
|
|
return fields.get(SeriesProperty.valueOf(key.toString()));
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String get(SeriesProperty key) {
|
|
|
|
return fields.get(key);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-28 19:51:00 -05:00
|
|
|
public Integer getId() {
|
2011-12-21 00:54:30 -05:00
|
|
|
// e.g. 80348
|
2011-12-28 19:51:00 -05:00
|
|
|
try {
|
|
|
|
return Integer.parseInt(get(SeriesProperty.id));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public List<String> getActors() {
|
|
|
|
// e.g. |Zachary Levi|Adam Baldwin|Yvonne Strzechowski|
|
2011-12-21 03:31:57 -05:00
|
|
|
return split(get(SeriesProperty.Actors));
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-29 11:23:56 -05:00
|
|
|
public List<String> getGenres() {
|
2011-12-21 03:31:57 -05:00
|
|
|
// e.g. |Comedy|
|
|
|
|
return split(get(SeriesProperty.Genre));
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 03:31:57 -05:00
|
|
|
protected List<String> split(String values) {
|
|
|
|
List<String> items = new ArrayList<String>();
|
2011-12-28 19:51:00 -05:00
|
|
|
if (values != null && values.length() > 0) {
|
|
|
|
for (String it : values.split("[|]")) {
|
|
|
|
it = it.trim();
|
|
|
|
if (it.length() > 0) {
|
|
|
|
items.add(it);
|
|
|
|
}
|
2011-12-21 03:31:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return items;
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String getAirDayOfWeek() {
|
|
|
|
// e.g. Monday
|
|
|
|
return get(SeriesProperty.Airs_DayOfWeek);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String getAirTime() {
|
|
|
|
// e.g. 8:00 PM
|
|
|
|
return get(SeriesProperty.Airs_Time);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2014-04-19 01:39:52 -04:00
|
|
|
public SimpleDate getFirstAired() {
|
2011-12-21 00:54:30 -05:00
|
|
|
// e.g. 2007-09-24
|
2014-04-19 01:39:52 -04:00
|
|
|
return SimpleDate.parse(get(SeriesProperty.FirstAired), "yyyy-MM-dd");
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String getContentRating() {
|
|
|
|
// e.g. TV-PG
|
|
|
|
return get(SeriesProperty.ContentRating);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-02-16 08:34:04 -05:00
|
|
|
public String getCertification() {
|
|
|
|
return getContentRating(); // another getter for compability reasons
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-28 19:51:00 -05:00
|
|
|
public Integer getImdbId() {
|
2011-12-21 00:54:30 -05:00
|
|
|
// e.g. tt0934814
|
2011-12-28 19:51:00 -05:00
|
|
|
try {
|
|
|
|
return Integer.parseInt(get(SeriesProperty.IMDB_ID).substring(2));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public Locale getLanguage() {
|
|
|
|
// e.g. en
|
2011-12-28 19:51:00 -05:00
|
|
|
try {
|
|
|
|
return new Locale(get(SeriesProperty.Language));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String getOverview() {
|
|
|
|
// e.g. Zachary Levi (Less Than Perfect) plays Chuck...
|
|
|
|
return get(SeriesProperty.Overview);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-28 19:51:00 -05:00
|
|
|
public Double getRating() {
|
2011-12-21 00:54:30 -05:00
|
|
|
// e.g. 9.0
|
2011-12-28 19:51:00 -05:00
|
|
|
try {
|
|
|
|
return Double.parseDouble(get(SeriesProperty.Rating));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-28 19:51:00 -05:00
|
|
|
public Integer getRatingCount() {
|
2011-12-21 00:54:30 -05:00
|
|
|
// e.g. 696
|
2011-12-28 19:51:00 -05:00
|
|
|
try {
|
|
|
|
return Integer.parseInt(get(SeriesProperty.RatingCount));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String getRuntime() {
|
|
|
|
// e.g. 30
|
|
|
|
return get(SeriesProperty.Runtime);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 03:31:57 -05:00
|
|
|
public String getName() {
|
2011-12-21 00:54:30 -05:00
|
|
|
// e.g. Chuck
|
|
|
|
return get(SeriesProperty.SeriesName);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-22 14:36:31 -05:00
|
|
|
public String getNetwork() {
|
|
|
|
// e.g. CBS
|
|
|
|
return get(SeriesProperty.Network);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String getStatus() {
|
|
|
|
// e.g. Continuing
|
|
|
|
return get(SeriesProperty.Status);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-22 14:36:31 -05:00
|
|
|
public URL getBannerMirrorUrl() {
|
|
|
|
try {
|
|
|
|
return new URL(get(BannerProperty.BannerMirror));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public URL getBannerUrl() throws MalformedURLException {
|
2011-12-22 14:36:31 -05:00
|
|
|
try {
|
|
|
|
return new URL(getBannerMirrorUrl(), get(SeriesProperty.banner));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-22 14:36:31 -05:00
|
|
|
public URL getFanartUrl() {
|
|
|
|
try {
|
|
|
|
return new URL(getBannerMirrorUrl(), get(SeriesProperty.fanart));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-28 19:51:00 -05:00
|
|
|
public URL getPosterUrl() {
|
2011-12-22 14:36:31 -05:00
|
|
|
try {
|
|
|
|
return new URL(getBannerMirrorUrl(), get(SeriesProperty.poster));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-21 00:54:30 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return fields.toString();
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
/**
|
|
|
|
* Search for a series banner matching the given parameters
|
|
|
|
*
|
|
|
|
* @see http://thetvdb.com/wiki/index.php/API:banners.xml
|
|
|
|
*/
|
2011-12-30 05:35:26 -05:00
|
|
|
public BannerDescriptor getBanner(TheTVDBSearchResult series, Map<?, ?> filterDescriptor) throws Exception {
|
|
|
|
EnumMap<BannerProperty, String> filter = new EnumMap<BannerProperty, String>(BannerProperty.class);
|
|
|
|
for (Entry<?, ?> it : filterDescriptor.entrySet()) {
|
|
|
|
if (it.getValue() != null) {
|
|
|
|
filter.put(BannerProperty.valueOf(it.getKey().toString()), it.getValue().toString());
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
// search for a banner matching the selector
|
2011-12-28 20:31:11 -05:00
|
|
|
for (BannerDescriptor it : getBannerList(series)) {
|
2011-12-30 05:35:26 -05:00
|
|
|
if (it.fields.entrySet().containsAll(filter.entrySet())) {
|
|
|
|
return it;
|
2011-12-19 21:37:36 -05:00
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
return null;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-28 20:31:11 -05:00
|
|
|
public List<BannerDescriptor> getBannerList(TheTVDBSearchResult series) throws Exception {
|
2011-12-20 09:09:18 -05:00
|
|
|
// check cache first
|
2012-01-01 22:07:09 -05:00
|
|
|
BannerDescriptor[] cachedList = getCache().getData("banners", series.seriesId, null, BannerDescriptor[].class);
|
2011-12-20 09:09:18 -05:00
|
|
|
if (cachedList != null) {
|
2011-12-21 00:54:30 -05:00
|
|
|
return asList(cachedList);
|
2011-12-20 09:09:18 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2013-10-15 03:12:42 -04:00
|
|
|
Document dom = getXmlResource(MirrorType.XML, "/api/" + apikey + "/series/" + series.seriesId + "/banners.xml");
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
List<Node> nodes = selectNodes("//Banner", dom);
|
2011-12-20 08:00:38 -05:00
|
|
|
List<BannerDescriptor> banners = new ArrayList<BannerDescriptor>();
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
for (Node node : nodes) {
|
|
|
|
try {
|
2011-12-21 00:54:30 -05:00
|
|
|
Map<BannerProperty, String> item = new EnumMap<BannerProperty, String>(BannerProperty.class);
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
// insert banner mirror
|
2013-10-15 03:12:42 -04:00
|
|
|
item.put(BannerProperty.BannerMirror, getResourceURL(MirrorType.BANNER, "/banners/").toString());
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
// copy values from xml
|
|
|
|
for (BannerProperty key : BannerProperty.values()) {
|
|
|
|
String value = getTextContent(key.name(), node);
|
|
|
|
if (value != null && value.length() > 0) {
|
2011-12-21 00:54:30 -05:00
|
|
|
item.put(key, value);
|
2011-12-19 21:37:36 -05:00
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
banners.add(new BannerDescriptor(item));
|
2011-12-19 21:37:36 -05:00
|
|
|
} catch (Exception e) {
|
|
|
|
// log and ignore
|
|
|
|
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Invalid banner descriptor", e);
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2012-01-01 22:07:09 -05:00
|
|
|
getCache().putData("banners", series.seriesId, null, banners.toArray(new BannerDescriptor[0]));
|
2011-12-19 21:37:36 -05:00
|
|
|
return banners;
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 09:09:18 -05:00
|
|
|
public static class BannerDescriptor implements Serializable {
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public static enum BannerProperty {
|
2013-07-13 06:01:33 -04:00
|
|
|
id, BannerMirror, BannerPath, BannerType, BannerType2, Season, Colors, Language, Rating, RatingCount, SeriesName, ThumbnailPath, VignettePath
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
protected Map<BannerProperty, String> fields;
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 09:09:18 -05:00
|
|
|
protected BannerDescriptor() {
|
|
|
|
// used by serializer
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
protected BannerDescriptor(Map<BannerProperty, String> fields) {
|
|
|
|
this.fields = new EnumMap<BannerProperty, String>(fields);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String get(Object key) {
|
|
|
|
return fields.get(BannerProperty.valueOf(key.toString()));
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public String get(BannerProperty key) {
|
|
|
|
return fields.get(key);
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
public URL getBannerMirrorUrl() throws MalformedURLException {
|
2011-12-30 05:35:26 -05:00
|
|
|
try {
|
|
|
|
return new URL(get(BannerProperty.BannerMirror));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public URL getUrl() throws MalformedURLException {
|
2011-12-30 05:35:26 -05:00
|
|
|
try {
|
|
|
|
return new URL(getBannerMirrorUrl(), get(BannerProperty.BannerPath));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public String getExtension() {
|
2011-12-21 00:54:30 -05:00
|
|
|
return FileUtilities.getExtension(get(BannerProperty.BannerPath));
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-30 05:35:26 -05:00
|
|
|
public Integer getId() {
|
|
|
|
try {
|
|
|
|
return new Integer(get(BannerProperty.id));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public String getBannerType() {
|
2011-12-21 00:54:30 -05:00
|
|
|
return get(BannerProperty.BannerType);
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public String getBannerType2() {
|
2011-12-21 00:54:30 -05:00
|
|
|
return get(BannerProperty.BannerType2);
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public Integer getSeason() {
|
|
|
|
try {
|
2011-12-21 00:54:30 -05:00
|
|
|
return new Integer(get(BannerProperty.Season));
|
2011-12-20 08:00:38 -05:00
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-19 21:37:36 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public String getColors() {
|
2011-12-21 00:54:30 -05:00
|
|
|
return get(BannerProperty.Colors);
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public Locale getLocale() {
|
2011-12-30 05:35:26 -05:00
|
|
|
try {
|
|
|
|
return new Locale(get(BannerProperty.Language));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-30 05:35:26 -05:00
|
|
|
public Double getRating() {
|
|
|
|
try {
|
|
|
|
return new Double(get(BannerProperty.Rating));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-30 05:35:26 -05:00
|
|
|
public Integer getRatingCount() {
|
|
|
|
try {
|
|
|
|
return new Integer(get(BannerProperty.RatingCount));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public boolean hasSeriesName() {
|
2011-12-21 00:54:30 -05:00
|
|
|
return Boolean.parseBoolean(get(BannerProperty.SeriesName));
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public URL getThumbnailUrl() throws MalformedURLException {
|
2011-12-30 05:35:26 -05:00
|
|
|
try {
|
|
|
|
return new URL(getBannerMirrorUrl(), get(BannerProperty.ThumbnailPath));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
public URL getVignetteUrl() throws MalformedURLException {
|
2011-12-30 05:35:26 -05:00
|
|
|
try {
|
|
|
|
return new URL(getBannerMirrorUrl(), get(BannerProperty.VignettePath));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-20 08:00:38 -05:00
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return fields.toString();
|
2011-12-19 21:37:36 -05:00
|
|
|
}
|
|
|
|
}
|
2013-09-06 03:55:13 -04:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|