1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-05 00:45:06 -05:00

* cache imdb results as well

This commit is contained in:
Reinhard Pointner 2011-11-14 13:36:55 +00:00
parent 9c15137fcb
commit 715c6f8ee5

View File

@ -23,12 +23,14 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import net.sf.ehcache.CacheManager;
import net.sourceforge.filebot.ResourceManager;
public class IMDbClient extends AbstractEpisodeListProvider {
private final String host = "www.imdb.com";
private final ResultCache cache = new ResultCache(host, CacheManager.getInstance().getCache("web-datasource"));
@Override
@ -79,14 +81,18 @@ public class IMDbClient extends AbstractEpisodeListProvider {
@Override
public List<Episode> getEpisodeList(SearchResult searchResult, Locale locale) throws IOException, SAXException {
Movie movie = (Movie) searchResult;
List<Episode> episodes = cache.getEpisodeList(movie.getImdbId(), Locale.ROOT);
if (episodes != null)
return episodes;
Document dom = getHtmlDocument(openConnection(getEpisodeListLink(searchResult).toURL()));
String seriesName = normalizeName(selectString("//H1/A", dom));
Date year = new Date(((Movie) searchResult).getYear(), 0, 0);
Date year = new Date(movie.getYear(), 0, 0);
List<Node> nodes = selectNodes("//TABLE//H3/A[preceding-sibling::text()]", dom);
List<Episode> episodes = new ArrayList<Episode>(nodes.size());
episodes = new ArrayList<Episode>(nodes.size());
for (Node node : nodes) {
String title = getTextContent(node);
@ -101,6 +107,7 @@ public class IMDbClient extends AbstractEpisodeListProvider {
episodes.add(new Episode(seriesName, year, season, episode, title, null, null, airdate));
}
cache.putEpisodeList(movie.getImdbId(), Locale.ROOT, episodes);
return episodes;
}