From 857a550939c95e3584ca52b532b4b96c7080aaf7 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 9 Dec 2008 18:49:02 +0000 Subject: [PATCH] * account for latest tv.com stupidity: "reverse episode lists" * account for another tv.com disimprovement: "no season drop-down" --- .../filebot/web/TVDotComClient.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/source/net/sourceforge/filebot/web/TVDotComClient.java b/source/net/sourceforge/filebot/web/TVDotComClient.java index 322fe363..1383b768 100644 --- a/source/net/sourceforge/filebot/web/TVDotComClient.java +++ b/source/net/sourceforge/filebot/web/TVDotComClient.java @@ -10,6 +10,7 @@ import java.net.URL; import java.net.URLEncoder; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.concurrent.Callable; @@ -18,7 +19,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.regex.Pattern; import javax.swing.Icon; @@ -67,7 +67,7 @@ public class TVDotComClient implements EpisodeListClient { String href = XPathUtil.selectString("@href", node); try { - URL episodeListingUrl = new URL(href.replaceFirst(Pattern.quote("summary.html?") + ".*", "episode_listings.html")); + URL episodeListingUrl = new URL(href.replaceFirst("summary.html\\?.*", "episode_listings.html")); searchResults.add(new HyperLink(title, episodeListingUrl)); } catch (Exception e) { @@ -85,7 +85,16 @@ public class TVDotComClient implements EpisodeListClient { // get document for season 1 Document dom = HtmlUtil.getHtmlDocument(getEpisodeListLink(searchResult, 1)); - int seasonCount = XPathUtil.selectInteger("count(id('eps_table')//SELECT[@name='season']/OPTION[text() != 'All Seasons'])", dom); + // seasons are ordered in reverse, first element is latest season + String latestSeasonString = XPathUtil.selectString("id('eps_table')//*[starts-with(text(),'Season:')]/*[1]/text()", dom); + + if (latestSeasonString.isEmpty()) { + // assume single season series + latestSeasonString = "1"; + } + + // strip unexpected characters from season string (e.g. "7..."); + int seasonCount = Integer.valueOf(latestSeasonString.replaceAll("\\D+", "")); // we're going to fetch the episode list for each season on multiple threads List>> futures = new ArrayList>>(seasonCount); @@ -130,6 +139,9 @@ public class TVDotComClient implements EpisodeListClient { List nodes = XPathUtil.selectNodes("id('eps_table')//TD[@class='ep_title']/parent::TR", dom); + // episodes are ordered in reverse ... we definitely don't want that! + Collections.reverse(nodes); + NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH); numberFormat.setMinimumIntegerDigits(Math.max(Integer.toString(nodes.size()).length(), 2)); numberFormat.setGroupingUsed(false);