From ac774306f40c2b9e1aa45d12dae072e7bbe94bff Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 4 Jul 2011 01:14:54 +0000 Subject: [PATCH] * fixed messed up file<->episode matching when matching an episode that is represented multiple files in different formats/extensions. --- build.xml | 2 +- .../ui/panel/rename/EpisodeListMatcher.java | 32 ++----------------- .../net/sourceforge/tuned/FileUtilities.java | 24 ++++++++++++++ 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/build.xml b/build.xml index 3fc36ec3..992bb7f2 100644 --- a/build.xml +++ b/build.xml @@ -2,7 +2,7 @@ - + diff --git a/source/net/sourceforge/filebot/ui/panel/rename/EpisodeListMatcher.java b/source/net/sourceforge/filebot/ui/panel/rename/EpisodeListMatcher.java index 6af67499..7da64ba5 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/EpisodeListMatcher.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/EpisodeListMatcher.java @@ -3,19 +3,17 @@ package net.sourceforge.filebot.ui.panel.rename; import static net.sourceforge.filebot.MediaTypes.*; +import static net.sourceforge.tuned.FileUtilities.*; import static net.sourceforge.tuned.ui.TunedUtilities.*; import java.io.File; -import java.io.FileFilter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; @@ -169,8 +167,8 @@ class EpisodeListMatcher implements AutoCompleteMatcher { List> matches = new ArrayList>(); // group by subtitles first and then by files in general - for (List filesPerType : mapByFileType(mediaFiles, VIDEO_FILES, SUBTITLE_FILES).values()) { - Matcher matcher = new Matcher(filesPerType, episodes, MatchSimilarityMetric.defaultSequence()); + for (List filesPerType : mapByExtension(mediaFiles).values()) { + Matcher matcher = new Matcher(filesPerType, episodes, false, MatchSimilarityMetric.defaultSequence()); matches.addAll(matcher.match()); } @@ -186,28 +184,4 @@ class EpisodeListMatcher implements AutoCompleteMatcher { return matches; } - - protected Map> mapByFileType(Collection files, FileFilter... filters) { - // initialize map, keep filter order - Map> map = new LinkedHashMap>(filters.length); - - // initialize value lists - for (FileFilter filter : filters) { - map.put(filter, new ArrayList()); - } - - for (File file : files) { - for (FileFilter filter : filters) { - if (filter.accept(file)) { - map.get(filter).add(file); - - // put each value into one group only - break; - } - } - } - - return map; - } - } diff --git a/source/net/sourceforge/tuned/FileUtilities.java b/source/net/sourceforge/tuned/FileUtilities.java index 44a8e811..7c3d3575 100644 --- a/source/net/sourceforge/tuned/FileUtilities.java +++ b/source/net/sourceforge/tuned/FileUtilities.java @@ -9,9 +9,11 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -195,6 +197,28 @@ public final class FileUtilities { } + public static Map> mapByExtension(Iterable files) { + HashMap> map = new HashMap>(); + + for (File file : files) { + String key = getExtension(file); + 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; + } + + /** * Invalid file name characters: \, /, :, *, ?, ", <, >, |, \r and \n */