diff --git a/source/net/filebot/media/SmartSeasonEpisodeMatcher.java b/source/net/filebot/media/SmartSeasonEpisodeMatcher.java index 47d1b635..25d0d9c6 100644 --- a/source/net/filebot/media/SmartSeasonEpisodeMatcher.java +++ b/source/net/filebot/media/SmartSeasonEpisodeMatcher.java @@ -9,7 +9,7 @@ import net.filebot.similarity.SeasonEpisodeMatcher; public class SmartSeasonEpisodeMatcher extends SeasonEpisodeMatcher { // make sure certain patterns like x264 or 720p will never be interpreted as SxE numbers - private Pattern ignorePattern = new ReleaseInfo().getVideoFormatPattern(false); + private final Pattern ignorePattern = new ReleaseInfo().getVideoFormatPattern(false); public SmartSeasonEpisodeMatcher(SeasonEpisodeFilter sanity, boolean strict) { super(sanity, strict); diff --git a/source/net/filebot/similarity/EpisodeMatcher.java b/source/net/filebot/similarity/EpisodeMatcher.java index 30cb7d8c..3bd50741 100644 --- a/source/net/filebot/similarity/EpisodeMatcher.java +++ b/source/net/filebot/similarity/EpisodeMatcher.java @@ -13,6 +13,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import net.filebot.media.SmartSeasonEpisodeMatcher; import net.filebot.similarity.SeasonEpisodeMatcher.SxE; import net.filebot.web.Episode; import net.filebot.web.MultiEpisode; @@ -48,8 +49,14 @@ public class EpisodeMatcher extends Matcher { boolean modified = false; for (Match it : possibleMatches) { File file = it.getValue(); - Set uniqueFiles = parseEpisodeIdentifer(file); - Set uniqueEpisodes = episodeIdentifierSets.get(file); + + Set uniqueFiles = normalizeIdentifierSet(parseEpisodeIdentifer(file)); + if (uniqueFiles.size() < 2) + continue; + + Set uniqueEpisodes = normalizeIdentifierSet(episodeIdentifierSets.get(file)); + if (uniqueEpisodes.size() < 2) + continue; if (uniqueFiles.equals(uniqueEpisodes)) { Episode[] episodes = episodeSets.get(file).toArray(new Episode[0]); @@ -70,7 +77,7 @@ public class EpisodeMatcher extends Matcher { } - private final SeasonEpisodeMatcher seasonEpisodeMatcher = new SeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, false); + private final SeasonEpisodeMatcher seasonEpisodeMatcher = new SmartSeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, false); private final Map> transformCache = synchronizedMap(new HashMap>(64, 4)); private Set parseEpisodeIdentifer(File file) { @@ -90,6 +97,20 @@ public class EpisodeMatcher extends Matcher { return result; } + private Set normalizeIdentifierSet(Set numbers) { + // SxE 1x01 => 101 + // Absolute 101 => 101 + Set identifier = new HashSet(numbers.size()); + for (SxE it : numbers) { + if (it.season > 0 && it.episode > 0 && it.episode < 100) { + identifier.add(it.season * 100 + it.episode); + } else if (it.season < 0 && it.episode > 0) { + identifier.add(it.episode); + } + } + return identifier; + } + private boolean isMultiEpisode(Episode[] episodes) { // sanity check that there is valid episode data for at least two episodes if (episodes.length < 2)