* WebRequest: try to use compression
* SubsceneClient: persist languageFilterMap
This commit is contained in:
parent
daa665c00e
commit
90c8af354d
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
|
|||
|
||||
@Override
|
||||
protected Settings getSettings() {
|
||||
return Settings.userRoot().node("subtitle");
|
||||
return Settings.userRoot().node("subtitles");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,9 @@ import java.util.regex.Pattern;
|
|||
import javax.swing.Icon;
|
||||
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.tuned.FileUtilities;
|
||||
import net.sourceforge.tuned.PreferencesMap.SimpleAdapter;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -40,7 +42,7 @@ public class SubsceneSubtitleClient implements SubtitleClient {
|
|||
|
||||
private static final String host = "subscene.com";
|
||||
|
||||
private final Map<String, Integer> languageFilterMap = new HashMap<String, Integer>(50);
|
||||
private final Map<String, Integer> 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<String, Integer> initLanguageFilterMap() {
|
||||
return Settings.userRoot().node("subtitles/subscene/languageFilterMap").asMap(SimpleAdapter.forClass(Integer.class));
|
||||
}
|
||||
|
||||
|
||||
protected Map<String, Integer> getLanguageFilterMap(Document subtitleListDocument) {
|
||||
Map<String, Integer> filters = new HashMap<String, Integer>(50);
|
||||
|
||||
List<Node> 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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -35,11 +35,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
|||
|
||||
@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<T> implements Map<String, T> {
|
|||
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<T> implements Map<String, T> {
|
|||
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<String, T>> entrySet() {
|
||||
public Set<Entry<String, T>> entrySet() {
|
||||
Set<Map.Entry<String, T>> entries = new LinkedHashSet<Map.Entry<String, T>>();
|
||||
|
||||
for (String key : keys()) {
|
||||
|
|
Loading…
Reference in New Issue