diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index 5f8153d6..19c01309 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -170,7 +170,7 @@ public class CmdlineOperations implements CmdlineInterface { List> matches = new ArrayList>(); // auto-determine optimal batch sets - for (Entry, Set> sameSeriesGroup : mapSeriesNamesByFiles(mediaFiles, locale, db != AniDB, db == AniDB).entrySet()) { + for (Entry, Set> sameSeriesGroup : mapSeriesNamesByFiles(mediaFiles, locale, db == AniDB).entrySet()) { List> batchSets = new ArrayList>(); if (sameSeriesGroup.getValue() != null && sameSeriesGroup.getValue().size() > 0) { @@ -187,7 +187,7 @@ public class CmdlineOperations implements CmdlineInterface { // auto-detect series name if not given if (query == null) { // detect series name by common word sequence - seriesNames = detectSeriesNames(batch, db != AniDB, db == AniDB, locale); + seriesNames = detectSeriesNames(batch, db == AniDB, locale); log.config("Auto-detected query: " + seriesNames); } else { // use --q option diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index 3108d7bc..94edd7a9 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -204,19 +204,19 @@ public abstract class ScriptShellBaseClass extends Script { } public String detectSeriesName(Object files) throws Exception { - return detectSeriesName(files, true, false); + return detectSeriesName(files, false); } public String detectAnimeName(Object files) throws Exception { - return detectSeriesName(files, false, true); + return detectSeriesName(files, true); } - public String detectSeriesName(Object files, boolean useSeriesIndex, boolean useAnimeIndex) throws Exception { + public String detectSeriesName(Object files, boolean anime) throws Exception { List input = FileUtilities.asFileList(files); if (input.isEmpty()) return null; - List names = MediaDetection.detectSeriesNames(input, useSeriesIndex, useAnimeIndex, Locale.ENGLISH); + List names = MediaDetection.detectSeriesNames(input, anime, Locale.ENGLISH); return names == null || names.isEmpty() ? null : names.get(0); } diff --git a/source/net/filebot/media/AutoDetection.java b/source/net/filebot/media/AutoDetection.java index 77a66ac7..102383c9 100644 --- a/source/net/filebot/media/AutoDetection.java +++ b/source/net/filebot/media/AutoDetection.java @@ -98,9 +98,9 @@ public class AutoDetection { } private List detectSeries(File f, boolean anime) throws Exception { - List names = detectSeriesNames(singleton(f), !anime, anime, locale); + List names = detectSeriesNames(singleton(f), anime, locale); if (names.isEmpty()) { - names = detectSeriesNames(getVideoFiles(f.getParentFile()), !anime, anime, locale); + names = detectSeriesNames(getVideoFiles(f.getParentFile()), anime, locale); } return names; } diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index d00c38af..ae8ebd23 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -181,14 +181,14 @@ public class MediaDetection { return getDateMatcher().match(object.toString()); } - public static Map, Set> mapSeriesNamesByFiles(Collection files, Locale locale, boolean useSeriesIndex, boolean useAnimeIndex) throws Exception { + public static Map, Set> mapSeriesNamesByFiles(Collection files, Locale locale, boolean anime) throws Exception { // map series names by folder Map> seriesNamesByFolder = new HashMap>(); Map> filesByFolder = mapByFolder(files); for (Entry> it : filesByFolder.entrySet()) { Set namesForFolder = new TreeSet(getLenientCollator(locale)); - namesForFolder.addAll(detectSeriesNames(it.getValue(), useSeriesIndex, useAnimeIndex, locale)); + namesForFolder.addAll(detectSeriesNames(it.getValue(), anime, locale)); seriesNamesByFolder.put(it.getKey(), namesForFolder); } @@ -317,14 +317,8 @@ public class MediaDetection { return match; } - public static List detectSeriesNames(Collection files, boolean useSeriesIndex, boolean useAnimeIndex, Locale locale) throws Exception { - List> index = new ArrayList>(); - if (useSeriesIndex) - index.addAll(getSeriesIndex()); - if (useAnimeIndex) - index.addAll(getAnimeIndex()); - - return detectSeriesNames(files, index, locale); + public static List detectSeriesNames(Collection files, boolean anime, Locale locale) throws Exception { + return detectSeriesNames(files, anime ? getAnimeIndex() : getSeriesIndex(), locale); } public static List detectSeriesNames(Collection files, List> index, Locale locale) throws Exception { @@ -1065,11 +1059,11 @@ public class MediaDetection { return map; } - public static Map> mapBySeriesName(Collection files, boolean useSeriesIndex, boolean useAnimeIndex, Locale locale) throws Exception { + public static Map> mapBySeriesName(Collection files, boolean anime, Locale locale) throws Exception { Map> result = new TreeMap>(String.CASE_INSENSITIVE_ORDER); for (File f : files) { - List names = detectSeriesNames(singleton(f), useSeriesIndex, useAnimeIndex, locale); + List names = detectSeriesNames(singleton(f), anime, locale); String key = names.isEmpty() ? "" : names.get(0); List value = result.get(key); diff --git a/source/net/filebot/subtitle/SubtitleUtilities.java b/source/net/filebot/subtitle/SubtitleUtilities.java index eb35071f..ac8e1b3a 100644 --- a/source/net/filebot/subtitle/SubtitleUtilities.java +++ b/source/net/filebot/subtitle/SubtitleUtilities.java @@ -97,7 +97,7 @@ public final class SubtitleUtilities { Map> subtitlesByFile = new HashMap>(); for (List byMediaFolder : mapByMediaFolder(fileSet).values()) { - for (Entry> bySeries : mapBySeriesName(byMediaFolder, true, false, Locale.ENGLISH).entrySet()) { + for (Entry> bySeries : mapBySeriesName(byMediaFolder, false, Locale.ENGLISH).entrySet()) { // allow early abort if (Thread.interrupted()) throw new InterruptedException(); diff --git a/source/net/filebot/ui/rename/EpisodeListMatcher.java b/source/net/filebot/ui/rename/EpisodeListMatcher.java index fd937e9a..89a5edbf 100644 --- a/source/net/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/filebot/ui/rename/EpisodeListMatcher.java @@ -54,9 +54,7 @@ import net.filebot.web.SortOrder; class EpisodeListMatcher implements AutoCompleteMatcher { private EpisodeListProvider provider; - - private boolean useAnimeIndex; - private boolean useSeriesIndex; + private boolean anime; // remember user selections private TypedCache persistentSelectionMemory; @@ -64,10 +62,9 @@ class EpisodeListMatcher implements AutoCompleteMatcher { // only allow one fetch session at a time so later requests can make use of cached results private final Object providerLock = new Object(); - public EpisodeListMatcher(EpisodeListProvider provider, boolean useSeriesIndex, boolean useAnimeIndex) { + public EpisodeListMatcher(EpisodeListProvider provider, boolean anime) { this.provider = provider; - this.useSeriesIndex = useSeriesIndex; - this.useAnimeIndex = useAnimeIndex; + this.anime = anime; this.persistentSelectionMemory = Cache.getCache("selection_" + provider.getName(), CacheType.Persistent).cast(SearchResult.class); } @@ -214,14 +211,14 @@ class EpisodeListMatcher implements AutoCompleteMatcher { @Override public List> call() throws Exception { - return matchEpisodeSet(singletonList(file), detectSeriesNames(singleton(file), useSeriesIndex, useAnimeIndex, locale), sortOrder, strict, locale, autodetection, selectionMemory, inputMemory, parent); + return matchEpisodeSet(singletonList(file), detectSeriesNames(singleton(file), anime, locale), sortOrder, strict, locale, autodetection, selectionMemory, inputMemory, parent); } }); } } } else { // in non-strict mode use the complicated (more powerful but also more error prone) match-batch-by-batch logic - for (Entry, Set> sameSeriesGroup : mapSeriesNamesByFiles(mediaFiles, locale, useSeriesIndex, useAnimeIndex).entrySet()) { + for (Entry, Set> sameSeriesGroup : mapSeriesNamesByFiles(mediaFiles, locale, anime).entrySet()) { final List> batchSets = new ArrayList>(); final Collection queries = sameSeriesGroup.getValue(); @@ -307,7 +304,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher { // require user input if auto-detection has failed or has been disabled if (episodes.isEmpty() && !strict) { - List detectedSeriesNames = detectSeriesNames(files, useSeriesIndex, useAnimeIndex, locale); + List detectedSeriesNames = detectSeriesNames(files, anime, locale); String parentPathHint = normalizePathSeparators(getRelativePathTail(files.get(0).getParentFile(), 2).getPath()); String suggestion = detectedSeriesNames.size() > 0 ? join(detectedSeriesNames, "; ") : normalizePunctuation(getName(files.get(0))); diff --git a/source/net/filebot/ui/rename/Preset.java b/source/net/filebot/ui/rename/Preset.java index 5df268bf..4ae08b80 100644 --- a/source/net/filebot/ui/rename/Preset.java +++ b/source/net/filebot/ui/rename/Preset.java @@ -99,7 +99,7 @@ public class Preset { EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database); if (sdb != null) { - return new EpisodeListMatcher(sdb, sdb != WebServices.AniDB, sdb == WebServices.AniDB); + return new EpisodeListMatcher(sdb, sdb == WebServices.AniDB); } MusicIdentificationService adb = WebServices.getMusicIdentificationService(database); diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 8b8b61db..37feeb8c 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -432,7 +432,7 @@ public class RenamePanel extends JComponent { // create actions for match popup episode list completion for (EpisodeListProvider db : WebServices.getEpisodeListProviders()) { - actionPopup.add(new AutoCompleteAction(db.getName(), db.getIcon(), new EpisodeListMatcher(db, db != WebServices.AniDB, db == WebServices.AniDB))); + actionPopup.add(new AutoCompleteAction(db.getName(), db.getIcon(), new EpisodeListMatcher(db, db == WebServices.AniDB))); } actionPopup.addSeparator(); diff --git a/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java b/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java index 1ebff998..733c6685 100644 --- a/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java +++ b/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java @@ -1,5 +1,6 @@ package net.filebot.ui.subtitle.upload; +import static java.util.Collections.*; import static net.filebot.Logging.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.util.ui.SwingUI.*; @@ -11,7 +12,6 @@ import java.awt.event.ActionEvent; import java.io.File; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map; @@ -162,7 +162,7 @@ public class SubtitleUploadDialog extends JDialog { mapping.setState(Status.Identifying); try { if (MediaDetection.isEpisode(mapping.getVideo().getPath(), true)) { - List seriesNames = MediaDetection.detectSeriesNames(Collections.singleton(mapping.getVideo()), true, false, Locale.ENGLISH); + List seriesNames = MediaDetection.detectSeriesNames(singleton(mapping.getVideo()), false, Locale.ENGLISH); NAMES: for (String name : seriesNames) { List options = WebServices.TheTVDB.search(name, Locale.ENGLISH); for (SearchResult entry : options) { diff --git a/test/net/filebot/media/MediaDetectionTest.java b/test/net/filebot/media/MediaDetectionTest.java index 945d5b01..5b6ec36f 100644 --- a/test/net/filebot/media/MediaDetectionTest.java +++ b/test/net/filebot/media/MediaDetectionTest.java @@ -23,7 +23,7 @@ public class MediaDetectionTest { @Test public void detectSeriesName() throws Exception { - assertEquals("[]", MediaDetection.detectSeriesNames(singleton(new File("Movie/LOTR.2001.AVC-1080")), true, false, Locale.ENGLISH).toString()); + assertEquals("[]", MediaDetection.detectSeriesNames(singleton(new File("Movie/LOTR.2001.AVC-1080")), false, Locale.ENGLISH).toString()); } }