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