From 3326a307350434b70b5ca1db5e99f8091cfc0d73 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 19 Mar 2012 17:16:27 +0000 Subject: [PATCH] * improved series lookup --- .../filebot/media/MediaDetection.java | 2 +- .../filebot/ui/rename/EpisodeListMatcher.java | 15 ++++++--------- .../sourceforge/filebot/web/AnidbClient.java | 18 ++++++++++++++---- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 7e8a8ea8..92e988f5 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -196,7 +196,7 @@ public class MediaDetection { Set filenames = new LinkedHashSet(); for (File f : files) { for (int i = 0; i < 3 && f != null; i++, f = f.getParentFile()) { - (i == 0 ? filenames : folders).add(f.getName()); + (i == 0 ? filenames : folders).add(normalizeBrackets(f.getName())); } } diff --git a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java index d1c22661..2d155665 100644 --- a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -112,19 +113,15 @@ class EpisodeListMatcher implements AutoCompleteMatcher { // allow only one select dialog at a time synchronized (this) { synchronized (selectionMemory) { - SearchResult selection = selectionMemory.get(query); - if (selection != null) { - return selection; + if (selectionMemory.containsKey(query)) { + return selectionMemory.get(query); } SwingUtilities.invokeAndWait(showSelectDialog); // cache selected value - selection = showSelectDialog.get(); - if (selection != null) { - selectionMemory.put(query, selection); - } - return selection; + selectionMemory.put(query, showSelectDialog.get()); + return showSelectDialog.get(); } } } @@ -290,7 +287,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher { if (input.size() > 0) { // only allow one fetch session at a time so later requests can make use of cached results synchronized (providerLock) { - episodes = fetchEpisodeSet(input, sortOrder, locale, selectionMemory, parent); + episodes = fetchEpisodeSet(input, sortOrder, locale, new HashMap(), parent); } } } diff --git a/source/net/sourceforge/filebot/web/AnidbClient.java b/source/net/sourceforge/filebot/web/AnidbClient.java index e369b25a..b77e322e 100644 --- a/source/net/sourceforge/filebot/web/AnidbClient.java +++ b/source/net/sourceforge/filebot/web/AnidbClient.java @@ -169,6 +169,7 @@ public class AnidbClient extends AbstractEpisodeListProvider { Map primaryTitleMap = new HashMap(); Map> officialTitleMap = new HashMap>(); + Map> synonymsTitleMap = new HashMap>(); // fetch data Scanner scanner = new Scanner(new GZIPInputStream(url.openStream()), "UTF-8"); @@ -185,11 +186,12 @@ public class AnidbClient extends AbstractEpisodeListProvider { if (type.equals("1")) { primaryTitleMap.put(aid, title); - } else if (type.equals("4")) { - Map languageTitleMap = officialTitleMap.get(aid); + } else if (type.equals("2") || type.equals("4")) { + Map> titleMap = (type.equals("4") ? officialTitleMap : synonymsTitleMap); + Map languageTitleMap = titleMap.get(aid); if (languageTitleMap == null) { languageTitleMap = new HashMap(); - officialTitleMap.put(aid, languageTitleMap); + titleMap.put(aid, languageTitleMap); } languageTitleMap.put(language, title); @@ -204,7 +206,15 @@ public class AnidbClient extends AbstractEpisodeListProvider { anime = new ArrayList(primaryTitleMap.size()); for (Entry entry : primaryTitleMap.entrySet()) { - anime.add(new AnidbSearchResult(entry.getKey(), entry.getValue(), officialTitleMap.get(entry.getKey()))); + Map localizedTitles = new HashMap(); + if (synonymsTitleMap.containsKey(entry.getKey())) { + localizedTitles.putAll(synonymsTitleMap.get(entry.getKey())); // use synonym as fallback + } + if (officialTitleMap.containsKey(entry.getKey())) { + localizedTitles.putAll(officialTitleMap.get(entry.getKey())); // primarily use official title if available + } + + anime.add(new AnidbSearchResult(entry.getKey(), entry.getValue(), localizedTitles)); } // populate cache