* adjusted to changes in TV.com's html (episode list page)

This commit is contained in:
Reinhard Pointner 2009-04-04 20:19:03 +00:00
parent 7e6f485882
commit 335cd401e1
3 changed files with 19 additions and 23 deletions

View File

@ -164,15 +164,11 @@ public class EpisodeFormatBindingBean {
private String getMediaInfo(StreamKind streamKind, int streamNumber, String... keys) { private String getMediaInfo(StreamKind streamKind, int streamNumber, String... keys) {
MediaInfo mediaInfo = getMediaInfo(); for (String key : keys) {
String value = getMediaInfo().get(streamKind, streamNumber, key);
if (mediaInfo != null) {
for (String key : keys) { if (value.length() > 0) {
String value = mediaInfo.get(streamKind, streamNumber, key); return value;
if (value.length() > 0) {
return value;
}
} }
} }

View File

@ -89,7 +89,7 @@ public class TVDotComClient implements EpisodeListProvider {
Document dom = getHtmlDocument(getEpisodeListLink(searchResult, 1).toURL()); Document dom = getHtmlDocument(getEpisodeListLink(searchResult, 1).toURL());
// seasons are ordered in reverse, first element is latest season // seasons are ordered in reverse, first element is latest season
String latestSeasonString = selectString("id('eps_table')//*[starts-with(text(),'Season:')]/*[1]/text()", dom); String latestSeasonString = selectString("id('episode_list_header')//*[contains(@class, 'number')]", dom);
if (latestSeasonString.isEmpty()) { if (latestSeasonString.isEmpty()) {
// assume single season series // assume single season series
@ -138,33 +138,33 @@ public class TVDotComClient implements EpisodeListProvider {
} }
private List<Episode> getEpisodeList(SearchResult searchResult, int seasonNumber, Document dom) { private List<Episode> getEpisodeList(SearchResult searchResult, int season, Document dom) {
List<Node> nodes = selectNodes("id('eps_table')//TD[@class='ep_title']/parent::TR", dom); List<Node> nodes = selectNodes("id('episode_listing')//*[@class='episode']", dom);
Integer episodeOffset = null; Integer episodeOffset = null;
ArrayList<Episode> episodes = new ArrayList<Episode>(nodes.size()); List<Episode> episodes = new ArrayList<Episode>(nodes.size());
for (Node node : nodes) { for (Node node : nodes) {
String episode = selectString("./TD[1]", node); String episodeNumber = selectString("./*[@class='number']", node);
String title = selectString("./TD[2]//A", node); String title = selectString("./*[@class='title']", node);
String season = String.valueOf(seasonNumber); String seasonNumber = String.valueOf(season);
try { try {
// convert the absolute episode number to the season episode number // convert the absolute episode number to the season episode number
int n = Integer.parseInt(episode); int n = Integer.parseInt(episodeNumber);
if (episodeOffset == null) if (episodeOffset == null)
episodeOffset = n - 1; episodeOffset = (n <= 1) ? 0 : n - 1;
episode = String.valueOf(n - episodeOffset); episodeNumber = String.valueOf(n - episodeOffset);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// episode may be "Pilot", "Special", "TV Movie" ... // episode may be "Pilot", "Special", "TV Movie" ...
season = null; seasonNumber = null;
} }
episodes.add(new Episode(searchResult.getName(), season, episode, title)); episodes.add(new Episode(searchResult.getName(), seasonNumber, episodeNumber, title));
} }
return episodes; return episodes;

View File

@ -79,8 +79,8 @@ public class TVDotComClientTest {
assertEquals("Buffy the Vampire Slayer", first.getSeriesName()); assertEquals("Buffy the Vampire Slayer", first.getSeriesName());
assertEquals("Unaired Pilot", first.getTitle()); assertEquals("Unaired Pilot", first.getTitle());
assertEquals("Pilot", first.getEpisodeNumber()); assertEquals("0", first.getEpisodeNumber());
assertEquals(null, first.getSeasonNumber()); assertEquals("1", first.getSeasonNumber());
} }