mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 08:18:52 -05:00
* cache imdb results as well
This commit is contained in:
parent
9c15137fcb
commit
715c6f8ee5
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user