* fixed messed up file<->episode matching when matching an episode that is represented multiple files in different formats/extensions.

This commit is contained in:
Reinhard Pointner 2011-07-04 01:14:54 +00:00
parent bf7ab1c52d
commit ac774306f4
3 changed files with 28 additions and 30 deletions

View File

@ -2,7 +2,7 @@
<project name="FileBot" default="fatjar">
<property name="title" value="${ant.project.name}" />
<property name="version" value="1.96.470" />
<property name="version" value="1.96.471" />
<tstamp>
<format property="today" pattern="yyyy-MM-dd" />

View File

@ -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<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
// group by subtitles first and then by files in general
for (List<File> filesPerType : mapByFileType(mediaFiles, VIDEO_FILES, SUBTITLE_FILES).values()) {
Matcher<File, Episode> matcher = new Matcher<File, Episode>(filesPerType, episodes, MatchSimilarityMetric.defaultSequence());
for (List<File> filesPerType : mapByExtension(mediaFiles).values()) {
Matcher<File, Episode> matcher = new Matcher<File, Episode>(filesPerType, episodes, false, MatchSimilarityMetric.defaultSequence());
matches.addAll(matcher.match());
}
@ -186,28 +184,4 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
return matches;
}
protected Map<FileFilter, List<File>> mapByFileType(Collection<File> files, FileFilter... filters) {
// initialize map, keep filter order
Map<FileFilter, List<File>> map = new LinkedHashMap<FileFilter, List<File>>(filters.length);
// initialize value lists
for (FileFilter filter : filters) {
map.put(filter, new ArrayList<File>());
}
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;
}
}

View File

@ -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<String, List<File>> mapByExtension(Iterable<File> files) {
HashMap<String, List<File>> map = new HashMap<String, List<File>>();
for (File file : files) {
String key = getExtension(file);
if (key != null) {
key = key.toLowerCase();
}
List<File> valueList = map.get(key);
if (valueList == null) {
valueList = new ArrayList<File>();
map.put(key, valueList);
}
valueList.add(file);
}
return map;
}
/**
* Invalid file name characters: \, /, :, *, ?, ", <, >, |, \r and \n
*/