From 8ea81bfa68ebd02f04f7dd9032ddfd65f8f1e4d9 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 20 Mar 2012 18:18:34 +0000 Subject: [PATCH] * fix bugs in the multi-episode logic --- BuildData.groovy | 5 +++- .../filebot/similarity/EpisodeMatcher.java | 25 ++++++++++++++----- .../filebot/similarity/EpisodeMetrics.java | 5 ++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/BuildData.groovy b/BuildData.groovy index d0c3986c..31d02b98 100644 --- a/BuildData.groovy +++ b/BuildData.groovy @@ -52,7 +52,10 @@ names += anime.findResults{ it.getPrimaryTitle() } names += anime.findResults{ it.getOfficialTitle('en') } names = names.findAll{ it =~ /^[A-Z0-9]/ && it =~ /[\p{Alpha}]{3}/}.findResults{ net.sourceforge.filebot.similarity.Normalization.normalizePunctuation(it) } -names = names.sort().unique() + +def unique = new TreeSet(String.CASE_INSENSITIVE_ORDER) +unique.addAll(names) +names = unique as List gz(s_out, names) diff --git a/source/net/sourceforge/filebot/similarity/EpisodeMatcher.java b/source/net/sourceforge/filebot/similarity/EpisodeMatcher.java index 8617891d..b30c2e17 100644 --- a/source/net/sourceforge/filebot/similarity/EpisodeMatcher.java +++ b/source/net/sourceforge/filebot/similarity/EpisodeMatcher.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.IdentityHashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -49,19 +48,33 @@ public class EpisodeMatcher extends Matcher { episodeIdentifierSets.put(it.getKey(), sxe); } - for (Iterator> itr = possibleMatches.iterator(); itr.hasNext();) { - File file = itr.next().getValue(); + boolean modified = false; + for (Match it : possibleMatches) { + File file = it.getValue(); Set uniqueFiles = parseEpisodeIdentifer(file); Set uniqueEpisodes = episodeIdentifierSets.get(file); if (uniqueFiles.equals(uniqueEpisodes)) { - MultiEpisode episode = new MultiEpisode(episodeSets.get(file).toArray(new Episode[0])); - disjointMatchCollection.add(new Match(file, episode)); - itr.remove(); + Episode[] episodes = episodeSets.get(file).toArray(new Episode[0]); + Set seriesNames = new HashSet(); + for (Episode ep : episodes) { + seriesNames.add(ep.getSeriesName()); + } + + if (seriesNames.size() == 1) { + MultiEpisode episode = new MultiEpisode(episodes); + disjointMatchCollection.add(new Match(file, episode)); + modified = true; + } } } + if (modified) { + removeCollected(possibleMatches); + } + super.deepMatch(possibleMatches, level); + } diff --git a/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java b/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java index 6670c65e..61ce073b 100644 --- a/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java +++ b/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java @@ -96,8 +96,9 @@ public enum EpisodeMetrics implements SimilarityMetric { Episode e = (Episode) object; // don't use title for matching if title equals series name - if (!e.getSeriesName().toLowerCase().contains(e.getTitle().toLowerCase())) { - object = e.getTitle(); + String normalizedToken = normalizeObject(e.getTitle()); + if (normalizedToken.length() >= 3 && !normalizeObject(e.getSeriesName()).contains(normalizedToken)) { + return normalizedToken; } }