* don't select invalid nodes (tag links)
* test case for that
This commit is contained in:
parent
68dc5b61d0
commit
a341922a30
|
@ -55,7 +55,7 @@ public class TVDotComClient extends EpisodeListClient {
|
|||
|
||||
Document dom = HtmlUtil.getHtmlDocument(getSearchUrl(searchterm));
|
||||
|
||||
List<Node> nodes = XPathUtil.selectNodes("id('search-results')//SPAN/A", dom);
|
||||
List<Node> nodes = XPathUtil.selectNodes("id('search-results')//SPAN[@class='f-18']/A", dom);
|
||||
|
||||
List<SearchResult> searchResults = new ArrayList<SearchResult>(nodes.size());
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class TVDotComClient extends EpisodeListClient {
|
|||
URL episodeListingUrl = new URL(href.replaceFirst(Pattern.quote("summary.html?") + ".*", "episode_listings.html"));
|
||||
|
||||
searchResults.add(new HyperLink(title, episodeListingUrl));
|
||||
} catch (MalformedURLException e) {
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.WARNING, "Invalid href: " + href, e);
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ public class TVDotComClient extends EpisodeListClient {
|
|||
}
|
||||
|
||||
|
||||
private List<Episode> getEpisodeList(SearchResult searchResult, int season, Document dom) {
|
||||
private List<Episode> getEpisodeList(SearchResult searchResult, int seasonNumber, Document dom) {
|
||||
|
||||
List<Node> nodes = XPathUtil.selectNodes("id('episode-listing')/DIV/TABLE/TR/TD/ancestor::TR", dom);
|
||||
|
||||
|
@ -138,22 +138,24 @@ public class TVDotComClient extends EpisodeListClient {
|
|||
ArrayList<Episode> episodes = new ArrayList<Episode>(nodes.size());
|
||||
|
||||
for (Node node : nodes) {
|
||||
String episodeNumber = XPathUtil.selectString("./TD[1]", node);
|
||||
String episode = XPathUtil.selectString("./TD[1]", node);
|
||||
String title = XPathUtil.selectString("./TD[2]/A", node);
|
||||
String season = Integer.toString(seasonNumber);
|
||||
|
||||
try {
|
||||
// format number of episode
|
||||
int n = Integer.parseInt(episodeNumber);
|
||||
int n = Integer.parseInt(episode);
|
||||
|
||||
if (episodeOffset == null)
|
||||
episodeOffset = n - 1;
|
||||
|
||||
episodeNumber = numberFormat.format(n - episodeOffset);
|
||||
episode = numberFormat.format(n - episodeOffset);
|
||||
} catch (NumberFormatException e) {
|
||||
// episode number may be "Pilot", "Special", ...
|
||||
// episode may be "Pilot", "Special", "TV Movie" ...
|
||||
season = null;
|
||||
}
|
||||
|
||||
episodes.add(new Episode(searchResult.getName(), Integer.toString(season), episodeNumber, title));
|
||||
episodes.add(new Episode(searchResult.getName(), season, episode, title));
|
||||
}
|
||||
|
||||
return episodes;
|
||||
|
|
|
@ -44,6 +44,9 @@ public class TVDotComClientTest {
|
|||
public void search() throws Exception {
|
||||
List<SearchResult> results = tvdotcom.search("Buffy");
|
||||
|
||||
// if this fails, there is probably a problem with the xpath query
|
||||
assertEquals(10, results.size());
|
||||
|
||||
HyperLink result = (HyperLink) results.get(0);
|
||||
|
||||
assertEquals(buffySearchResult.getName(), result.getName());
|
||||
|
@ -77,7 +80,7 @@ public class TVDotComClientTest {
|
|||
assertEquals("Buffy the Vampire Slayer", first.getShowName());
|
||||
assertEquals("Unaired Pilot", first.getTitle());
|
||||
assertEquals("Pilot", first.getNumberOfEpisode());
|
||||
assertEquals("1", first.getNumberOfSeason());
|
||||
assertEquals(null, first.getNumberOfSeason());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue