From 90c8af354dc698f888856211cc55216381f5a723 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 15 Mar 2009 17:44:39 +0000 Subject: [PATCH] * WebRequest: try to use compression * SubsceneClient: persist languageFilterMap --- source/net/sourceforge/filebot/Settings.java | 2 +- .../filebot/ui/panel/subtitle/SubtitlePanel.java | 2 +- .../filebot/web/SubsceneSubtitleClient.java | 15 ++++++++++++--- .../net/sourceforge/filebot/web/WebRequest.java | 14 +++++++++++++- source/net/sourceforge/tuned/PreferencesMap.java | 14 +++++--------- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/source/net/sourceforge/filebot/Settings.java b/source/net/sourceforge/filebot/Settings.java index 075c2842..a3a43021 100644 --- a/source/net/sourceforge/filebot/Settings.java +++ b/source/net/sourceforge/filebot/Settings.java @@ -42,7 +42,7 @@ public final class Settings { public Settings node(String nodeName) { - return new Settings(prefs.node(nodeName.toLowerCase())); + return new Settings(prefs.node(nodeName)); } diff --git a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java index bf8b284a..feca02c6 100644 --- a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java @@ -54,7 +54,7 @@ public class SubtitlePanel extends AbstractSearchPanel languageFilterMap = new HashMap(50); + private final Map languageFilterMap = initLanguageFilterMap(); @Override @@ -86,7 +88,9 @@ public class SubsceneSubtitleClient implements SubtitleClient { // get current location String file = selectString("id('aspnetForm')/@action", dom); - searchResults.add(new HyperLink(name, new URL("http", host, file))); + if (!name.isEmpty() && !file.isEmpty()) { + searchResults.add(new HyperLink(name, new URL("http", host, file))); + } } catch (Exception e) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Cannot parse subtitle page: " + searchUrl, e); } @@ -172,13 +176,18 @@ public class SubsceneSubtitleClient implements SubtitleClient { } + protected Map initLanguageFilterMap() { + return Settings.userRoot().node("subtitles/subscene/languageFilterMap").asMap(SimpleAdapter.forClass(Integer.class)); + } + + protected Map getLanguageFilterMap(Document subtitleListDocument) { Map filters = new HashMap(50); List nodes = selectNodes("//DIV[@class='languageList']/DIV", subtitleListDocument); for (Node node : nodes) { - // select INPUT/@onclick, ditch non-number-characters + // select INPUT/@onclick, then ditch non-number-characters String filter = getAttribute("onclick", getChild("INPUT", node)).replaceAll("\\D+", ""); if (filter != null) { diff --git a/source/net/sourceforge/filebot/web/WebRequest.java b/source/net/sourceforge/filebot/web/WebRequest.java index 362be764..1f387f79 100644 --- a/source/net/sourceforge/filebot/web/WebRequest.java +++ b/source/net/sourceforge/filebot/web/WebRequest.java @@ -14,6 +14,8 @@ import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -37,12 +39,22 @@ public final class WebRequest { public static Reader getReader(URLConnection connection) throws IOException { + try { + connection.addRequestProperty("Accept-Encoding", "gzip,deflate"); + } catch (IllegalStateException e) { + // too bad, can't request gzipped document anymore + } + Charset charset = getCharset(connection.getContentType()); String encoding = connection.getContentEncoding(); + InputStream inputStream = connection.getInputStream(); - if ((encoding != null) && encoding.equalsIgnoreCase("gzip")) + if ("gzip".equalsIgnoreCase(encoding)) inputStream = new GZIPInputStream(inputStream); + else if ("deflate".equalsIgnoreCase(encoding)) { + inputStream = new InflaterInputStream(inputStream, new Inflater(true)); + } return new InputStreamReader(inputStream, charset); } diff --git a/source/net/sourceforge/tuned/PreferencesMap.java b/source/net/sourceforge/tuned/PreferencesMap.java index 4a1d6e9e..1c03500a 100644 --- a/source/net/sourceforge/tuned/PreferencesMap.java +++ b/source/net/sourceforge/tuned/PreferencesMap.java @@ -35,11 +35,7 @@ public class PreferencesMap implements Map { @Override public T get(Object key) { - if (key instanceof String) { - return adapter.get(prefs, (String) key); - } - - return null; + return adapter.get(prefs, key.toString()); } @@ -47,16 +43,16 @@ public class PreferencesMap implements Map { public T put(String key, T value) { adapter.put(prefs, key, value); + // don't know previous entry return null; } @Override public T remove(Object key) { - if (key instanceof String) { - adapter.remove(prefs, (String) key); - } + adapter.remove(prefs, key.toString()); + // don't know removed entry return null; } @@ -100,7 +96,7 @@ public class PreferencesMap implements Map { @Override - public Set> entrySet() { + public Set> entrySet() { Set> entries = new LinkedHashSet>(); for (String key : keys()) {