mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48:51 -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.w3c.dom.Node;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
import net.sourceforge.filebot.ResourceManager;
|
import net.sourceforge.filebot.ResourceManager;
|
||||||
|
|
||||||
|
|
||||||
public class IMDbClient extends AbstractEpisodeListProvider {
|
public class IMDbClient extends AbstractEpisodeListProvider {
|
||||||
|
|
||||||
private final String host = "www.imdb.com";
|
private final String host = "www.imdb.com";
|
||||||
|
private final ResultCache cache = new ResultCache(host, CacheManager.getInstance().getCache("web-datasource"));
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,14 +81,18 @@ public class IMDbClient extends AbstractEpisodeListProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Episode> getEpisodeList(SearchResult searchResult, Locale locale) throws IOException, SAXException {
|
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()));
|
Document dom = getHtmlDocument(openConnection(getEpisodeListLink(searchResult).toURL()));
|
||||||
|
|
||||||
String seriesName = normalizeName(selectString("//H1/A", dom));
|
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<Node> nodes = selectNodes("//TABLE//H3/A[preceding-sibling::text()]", dom);
|
||||||
|
episodes = new ArrayList<Episode>(nodes.size());
|
||||||
List<Episode> episodes = new ArrayList<Episode>(nodes.size());
|
|
||||||
|
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
String title = getTextContent(node);
|
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));
|
episodes.add(new Episode(seriesName, year, season, episode, title, null, null, airdate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cache.putEpisodeList(movie.getImdbId(), Locale.ROOT, episodes);
|
||||||
return episodes;
|
return episodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user