From ad2bbbdabbd28ef4f74b692e926a03438381fbea Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 30 Mar 2013 11:02:51 +0000 Subject: [PATCH] * OSDB: also cache negative search results --- .../sourceforge/filebot/cli/ArgumentBean.java | 2 +- .../filebot/web/OpenSubtitlesClient.java | 23 +++++++++++++++---- .../filebot/web/SubsceneSubtitleClient.java | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/source/net/sourceforge/filebot/cli/ArgumentBean.java b/source/net/sourceforge/filebot/cli/ArgumentBean.java index cea824ea..e363d55e 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentBean.java +++ b/source/net/sourceforge/filebot/cli/ArgumentBean.java @@ -190,7 +190,7 @@ public class ArgumentBean { public File getLogFile() throws IOException { - File f = new File(output, logFile).getAbsoluteFile(); + File f = new File(logFile).getAbsoluteFile(); if (!f.exists() && !f.getParentFile().mkdirs() && !f.createNewFile()) { throw new IOException("Failed to create log file: " + f); } diff --git a/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java b/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java index a3e0a9fc..707350e7 100644 --- a/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java +++ b/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java @@ -16,11 +16,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -264,10 +266,9 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS Movie entry = getCache().getData("getMovieDescriptor", hash, locale, Movie.class); if (entry == null) { hashMap.put(hash, file); // map file by hash - } else { + } else if (entry.getName().length() > 0) { result.put(file, entry); } - } } @@ -280,13 +281,25 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS int batchSize = 50; for (int bn = 0; bn < ceil((float) hashes.size() / batchSize); bn++) { List batch = hashes.subList(bn * batchSize, min((bn * batchSize) + batchSize, hashes.size())); + Set unmatchedHashes = new HashSet(batch); int minSeenCount = 20; // make sure we don't get mismatches by making sure the hash has not been confirmed numerous times for (Entry it : xmlrpc.checkMovieHash(batch, minSeenCount).entrySet()) { - result.put(hashMap.get(it.getKey()), it.getValue()); - getCache().putData("getMovieDescriptor", it.getKey(), locale, it.getValue()); + String hash = it.getKey(); + Movie movie = it.getValue(); + + result.put(hashMap.get(hash), movie); + getCache().putData("getMovieDescriptor", hash, locale, movie); + + unmatchedHashes.remove(hash); + } + + // note hashes that are not matched to any items so we can ignore them in the future + for (String hash : unmatchedHashes) { + getCache().putData("getMovieDescriptor", hash, locale, new Movie("", -1, -1, -1)); } } + } return result; @@ -357,7 +370,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS */ @SuppressWarnings("unchecked") protected synchronized Map getSubLanguageMap() throws Exception { - Cache cache = Cache.getCache("web-persistent-datasource"); + Cache cache = Cache.getCache("web-datasource-lv2"); String cacheKey = getClass().getName() + ".subLanguageMap"; Map subLanguageMap = cache.get(cacheKey, Map.class); diff --git a/source/net/sourceforge/filebot/web/SubsceneSubtitleClient.java b/source/net/sourceforge/filebot/web/SubsceneSubtitleClient.java index c7430e11..ef981ebf 100644 --- a/source/net/sourceforge/filebot/web/SubsceneSubtitleClient.java +++ b/source/net/sourceforge/filebot/web/SubsceneSubtitleClient.java @@ -126,7 +126,7 @@ public class SubsceneSubtitleClient implements SubtitleProvider { } // try cache first - Cache cache = Cache.getCache("web-persistent-datasource"); + Cache cache = Cache.getCache("web-datasource-lv2"); String cacheKey = getClass().getName() + ".languageFilter"; Map filters = cache.get(cacheKey, Map.class);