diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index cbcaee1a..0857fb62 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -196,8 +196,9 @@ public class CmdlineOperations implements CmdlineInterface { // filter episodes episodes = applyExpressionFilter(episodes, filter); - matches.addAll(matchEpisodes(filter(batch, VIDEO_FILES), episodes, strict)); - matches.addAll(matchEpisodes(filter(batch, SUBTITLE_FILES), episodes, strict)); + for (List filesPerType : mapByMediaExtension(filter(batch, VIDEO_FILES, SUBTITLE_FILES)).values()) { + matches.addAll(matchEpisodes(filesPerType, episodes, strict)); + } } } diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 3835de1d..daa6c218 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -972,6 +972,37 @@ public class MediaDetection { return mediaFolders; } + public static Map> mapByMediaExtension(Iterable files) { + Map> map = new LinkedHashMap>(); + + for (File file : files) { + String key = getExtension(file); + + // allow extended extensions for subtitles files, for example name.eng.srt => map by en.srt + if (key != null && SUBTITLE_FILES.accept(file)) { + Locale locale = releaseInfo.getLanguageSuffix(getName(file)); + if (locale != null) { + key = locale.getLanguage() + '.' + key; + } + } + + // normalize to lower-case + if (key != null) { + key = key.toLowerCase(); + } + + List valueList = map.get(key); + if (valueList == null) { + valueList = new ArrayList(); + map.put(key, valueList); + } + + valueList.add(file); + } + + return map; + } + public static Map> mapBySeriesName(Collection files, boolean useSeriesIndex, boolean useAnimeIndex, Locale locale) throws Exception { Map> result = new TreeMap>(String.CASE_INSENSITIVE_ORDER); diff --git a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java index 908dce7f..22c3d681 100644 --- a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java @@ -299,7 +299,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher { List> matches = new ArrayList>(); // group by subtitles first and then by files in general - for (List filesPerType : mapByExtension(files).values()) { + for (List filesPerType : mapByMediaExtension(files).values()) { EpisodeMatcher matcher = new EpisodeMatcher(filesPerType, episodes, false); for (Match it : matcher.match()) { matches.add(new Match(it.getValue(), ((Episode) it.getCandidate()).clone()));