From 38bbaaf5d8809832d42ddd336fc1b96f7e4a5287 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 7 Aug 2011 07:22:07 +0000 Subject: [PATCH] + updated Serienjunkies support (support episode airdate and website links) --- .../filebot/web/SerienjunkiesClient.java | 94 +++++++++++-------- .../sourceforge/filebot/web/WebRequest.java | 12 ++- .../filebot/web/SerienjunkiesClientTest.java | 5 +- 3 files changed, 69 insertions(+), 42 deletions(-) diff --git a/source/net/sourceforge/filebot/web/SerienjunkiesClient.java b/source/net/sourceforge/filebot/web/SerienjunkiesClient.java index af1d4220..a457d28a 100644 --- a/source/net/sourceforge/filebot/web/SerienjunkiesClient.java +++ b/source/net/sourceforge/filebot/web/SerienjunkiesClient.java @@ -10,7 +10,6 @@ import java.io.Reader; import java.io.Serializable; import java.net.URI; import java.net.URL; -import java.security.GeneralSecurityException; import java.util.AbstractList; import java.util.ArrayList; import java.util.Arrays; @@ -51,7 +50,25 @@ public class SerienjunkiesClient implements EpisodeListProvider { @Override - public List search(String query) throws Exception { + public String getName() { + return "Serienjunkies"; + } + + + @Override + public Icon getIcon() { + return ResourceManager.getIcon("search.serienjunkies"); + } + + + @Override + public boolean hasSingleSeasonSupport() { + return true; + } + + + @Override + public List search(String query) throws IOException { // normalize query = query.toLowerCase(); @@ -103,7 +120,7 @@ public class SerienjunkiesClient implements EpisodeListProvider { } - protected List getSeriesTitles() throws Exception { + protected List getSeriesTitles() throws IOException { // try cache first List seriesList = cache.getSeriesList(); if (seriesList != null) @@ -118,11 +135,12 @@ public class SerienjunkiesClient implements EpisodeListProvider { for (Object element : list) { JSONObject obj = (JSONObject) element; - String sid = (String) obj.get("id"); + Integer sid = new Integer((String) obj.get("id")); + String link = (String) obj.get("link"); String mainTitle = (String) obj.get("short"); String germanTitle = (String) obj.get("short_german"); - seriesList.add(new SerienjunkiesSearchResult(Integer.parseInt(sid), mainTitle, germanTitle != null && germanTitle.length() > 0 ? germanTitle : null)); + seriesList.add(new SerienjunkiesSearchResult(sid, link, mainTitle, germanTitle != null && germanTitle.length() > 0 ? germanTitle : null)); } // populate cache @@ -133,7 +151,7 @@ public class SerienjunkiesClient implements EpisodeListProvider { @Override - public List getEpisodeList(SearchResult searchResult) throws Exception { + public List getEpisodeList(SearchResult searchResult) throws IOException { SerienjunkiesSearchResult series = (SerienjunkiesSearchResult) searchResult; // try cache first @@ -150,11 +168,12 @@ public class SerienjunkiesClient implements EpisodeListProvider { for (int i = 0; i < list.size(); i++) { JSONObject obj = (JSONObject) list.get(i); - String season = (String) obj.get("season"); - String episode = (String) obj.get("episode"); + Integer season = new Integer((String) obj.get("season")); + Integer episode = new Integer((String) obj.get("episode")); String title = (String) obj.get("german"); + Date airdate = Date.parse((String) ((JSONObject) obj.get("airdates")).get("premiere"), "yyyy-MM-dd"); - episodes.add(new Episode(series.getName(), new Integer(season), new Integer(episode), title, i + 1, null, null)); + episodes.add(new Episode(series.getName(), season, episode, title, i + 1, null, airdate)); } // populate cache @@ -167,7 +186,20 @@ public class SerienjunkiesClient implements EpisodeListProvider { } - private Object request(String resource) throws IOException, GeneralSecurityException { + @Override + public List getEpisodeList(SearchResult searchResult, int season) throws IOException { + List all = getEpisodeList(searchResult); + List eps = filterBySeason(all, season); + + if (eps.isEmpty()) { + throw new SeasonOutOfBoundsException(searchResult.getName(), season, getLastSeason(all)); + } + + return eps; + } + + + protected Object request(String resource) throws IOException { URL url = new URL("https", host, resource); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); @@ -184,45 +216,27 @@ public class SerienjunkiesClient implements EpisodeListProvider { } - @Override - public List getEpisodeList(SearchResult searchResult, int season) throws Exception { - return null; - } - - @Override public URI getEpisodeListLink(SearchResult searchResult) { - return null; + return getEpisodeListLink(searchResult, "alle-serien-staffeln"); } @Override public URI getEpisodeListLink(SearchResult searchResult, int season) { - return null; + return getEpisodeListLink(searchResult, "season" + season); } - @Override - public String getName() { - return "Serienjunkies"; - } - - - @Override - public Icon getIcon() { - return ResourceManager.getIcon("search.serienjunkies"); - } - - - @Override - public boolean hasSingleSeasonSupport() { - return false; + public URI getEpisodeListLink(SearchResult searchResult, String page) { + return URI.create(String.format("http://www.serienjunkies.de/%s/%s.html", ((SerienjunkiesSearchResult) searchResult).getLink(), page)); } public static class SerienjunkiesSearchResult extends SearchResult implements Serializable { protected int sid; + protected String link; protected String mainTitle; protected String germanTitle; @@ -232,21 +246,27 @@ public class SerienjunkiesClient implements EpisodeListProvider { } - public SerienjunkiesSearchResult(int sid, String mainTitle, String germanTitle) { + public SerienjunkiesSearchResult(int sid, String link, String mainTitle, String germanTitle) { this.sid = sid; + this.link = link; this.mainTitle = mainTitle; this.germanTitle = germanTitle; } + @Override + public String getName() { + return germanTitle != null ? germanTitle : mainTitle; // prefer german title + } + + public int getSeriesId() { return sid; } - @Override - public String getName() { - return germanTitle != null ? germanTitle : mainTitle; // prefer german title + public String getLink() { + return link; } diff --git a/source/net/sourceforge/filebot/web/WebRequest.java b/source/net/sourceforge/filebot/web/WebRequest.java index ee9239e6..117986b1 100644 --- a/source/net/sourceforge/filebot/web/WebRequest.java +++ b/source/net/sourceforge/filebot/web/WebRequest.java @@ -226,7 +226,7 @@ public final class WebRequest { } - public static SSLSocketFactory createIgnoreCertificateSocketFactory() throws GeneralSecurityException { + public static SSLSocketFactory createIgnoreCertificateSocketFactory() { // create a trust manager that does not validate certificate chains TrustManager trustAnyCertificate = new X509TrustManager() { @@ -243,9 +243,13 @@ public final class WebRequest { } }; - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, new TrustManager[] { trustAnyCertificate }, new SecureRandom()); - return sc.getSocketFactory(); + try { + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, new TrustManager[] { trustAnyCertificate }, new SecureRandom()); + return sc.getSocketFactory(); + } catch (GeneralSecurityException e) { + throw new RuntimeException(e); + } } diff --git a/test/net/sourceforge/filebot/web/SerienjunkiesClientTest.java b/test/net/sourceforge/filebot/web/SerienjunkiesClientTest.java index f8465c4d..cc58bfe6 100644 --- a/test/net/sourceforge/filebot/web/SerienjunkiesClientTest.java +++ b/test/net/sourceforge/filebot/web/SerienjunkiesClientTest.java @@ -26,6 +26,7 @@ public class SerienjunkiesClientTest { SerienjunkiesSearchResult first = (SerienjunkiesSearchResult) results.get(0); assertEquals(34, first.getSeriesId()); + assertEquals("Alias", first.getLink()); assertEquals("Alias - Die Agentin", first.getName()); assertEquals("Alias", first.getMainTitle()); assertEquals("Alias - Die Agentin", first.getGermanTitle()); @@ -34,7 +35,7 @@ public class SerienjunkiesClientTest { @Test public void getEpisodeListAll() throws Exception { - List list = serienjunkies.getEpisodeList(new SerienjunkiesSearchResult(260, "Grey's Anatomy", null)); + List list = serienjunkies.getEpisodeList(new SerienjunkiesSearchResult(260, "greys-anatomy", "Grey's Anatomy", null)); // check ordinary episode Episode eps = list.get(0); @@ -43,6 +44,7 @@ public class SerienjunkiesClientTest { assertEquals("1", eps.getEpisode().toString()); assertEquals("1", eps.getSeason().toString()); assertEquals("1", eps.getAbsolute().toString()); + assertEquals("2005-03-27", eps.airdate().toString()); // check umlaut in title eps = list.get(2); @@ -50,6 +52,7 @@ public class SerienjunkiesClientTest { assertEquals("1", eps.getSeason().toString()); assertEquals("3", eps.getEpisode().toString()); assertEquals("3", eps.getAbsolute().toString()); + assertEquals("2005-04-10", eps.airdate().toString()); }