1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 06:15:02 -05:00

* modified series name detection to be more lenient to allow matching of series name even if there is only 1 file per series

This commit is contained in:
Reinhard Pointner 2010-11-01 09:56:20 +00:00
parent 93869ebd62
commit 18197999ed

View File

@ -21,6 +21,7 @@ import java.util.Map.Entry;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE;
import net.sourceforge.tuned.FileUtilities; import net.sourceforge.tuned.FileUtilities;
@ -64,7 +65,7 @@ public class SeriesNameMatcher {
whitelist.addAll(deepMatchAll(names, threshold)); whitelist.addAll(deepMatchAll(names, threshold));
// 1. use pattern matching // 1. use pattern matching
seriesNames.addAll(flatMatchAll(names, threshold, Pattern.compile(join(whitelist, "|"), Pattern.CASE_INSENSITIVE))); seriesNames.addAll(flatMatchAll(names, Pattern.compile(join(whitelist, "|"), Pattern.CASE_INSENSITIVE), threshold, false));
// 2. use common word sequences // 2. use common word sequences
seriesNames.addAll(whitelist); seriesNames.addAll(whitelist);
@ -80,22 +81,31 @@ public class SeriesNameMatcher {
* @return series names that have been matched one or multiple times depending on the * @return series names that have been matched one or multiple times depending on the
* threshold * threshold
*/ */
private Collection<String> flatMatchAll(String[] names, int threshold, Pattern whitelist) { private Collection<String> flatMatchAll(String[] names, Pattern prefixPattern, int threshold, boolean strict) {
ThresholdCollection<String> results = new ThresholdCollection<String>(threshold, String.CASE_INSENSITIVE_ORDER); ThresholdCollection<String> thresholdCollection = new ThresholdCollection<String>(threshold, String.CASE_INSENSITIVE_ORDER);
for (String name : names) { for (String name : names) {
// use normalized name // use normalized name
name = normalize(name); name = normalize(name);
Matcher matcher = whitelist.matcher(name); Matcher prefix = prefixPattern.matcher(name);
int seasonEpisodePosition = seasonEpisodeMatcher.find(name, matcher.find() ? matcher.end() : 0); int sxePosition = seasonEpisodeMatcher.find(name, prefix.find() ? prefix.end() : 0);
if (seasonEpisodePosition > 0) { if (sxePosition > 0) {
results.add(name.substring(0, seasonEpisodePosition).trim()); String hit = name.substring(0, sxePosition).trim();
List<SxE> sxe = seasonEpisodeMatcher.match(name.substring(sxePosition));
if (!strict && sxe.size() == 1 && sxe.get(0).season >= 0) {
// bypass threshold if hit is likely to be genuine
thresholdCollection.addDirect(hit);
} else {
// require multiple matches, if hit might be a false match
thresholdCollection.add(hit);
}
} }
} }
return results; return thresholdCollection;
} }
@ -377,6 +387,11 @@ public class SeriesNameMatcher {
}; };
public boolean addDirect(E element) {
return heaven.add(element);
}
@Override @Override
public Iterator<E> iterator() { public Iterator<E> iterator() {
return heaven.iterator(); return heaven.iterator();