From 836286581b293826dd981125cbc6cd3ec3cd2cee Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 13 Aug 2014 18:07:21 +0000 Subject: [PATCH] * improve handling of absolute-numbered files in Strict Mode --- source/net/filebot/cli/CmdlineOperations.java | 3 +- source/net/filebot/media/MediaDetection.java | 15 +++++++ .../filebot/similarity/EpisodeMatcher.java | 2 +- .../similarity/StrictEpisodeMetrics.java | 41 ------------------- .../filebot/ui/rename/EpisodeListMatcher.java | 5 +-- 5 files changed, 19 insertions(+), 47 deletions(-) delete mode 100644 source/net/filebot/similarity/StrictEpisodeMetrics.java diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index 03be2c90..d29adb68 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -53,7 +53,6 @@ import net.filebot.media.MediaDetection; import net.filebot.media.XattrMetaInfoProvider; import net.filebot.similarity.CommonSequenceMatcher; import net.filebot.similarity.EpisodeMatcher; -import net.filebot.similarity.EpisodeMetrics; import net.filebot.similarity.Match; import net.filebot.similarity.NameSimilarityMetric; import net.filebot.similarity.SeriesNameMatcher; @@ -269,7 +268,7 @@ public class CmdlineOperations implements CmdlineInterface { // in strict mode sanity check the result and only pass back good matches List> validMatches = new ArrayList>(); for (Match it : matches) { - if (EpisodeMetrics.EpisodeIdentifier.getSimilarity(it.getValue(), it.getCandidate()) >= 1) { + if (isEpisodeNumberMatch(it.getValue(), (Episode) it.getCandidate())) { validMatches.add(it); } } diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index 295e9d31..da6b2d65 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -46,6 +46,7 @@ import net.filebot.format.MediaBindingBean; import net.filebot.similarity.CommonSequenceMatcher; import net.filebot.similarity.DateMatcher; import net.filebot.similarity.DateMetric; +import net.filebot.similarity.EpisodeMetrics; import net.filebot.similarity.MetricAvg; import net.filebot.similarity.NameSimilarityMetric; import net.filebot.similarity.NumericSimilarityMetric; @@ -736,6 +737,20 @@ public class MediaDetection { return result; } + public static boolean isEpisodeNumberMatch(File f, Episode e) { + float similarity = EpisodeMetrics.EpisodeIdentifier.getSimilarity(f, e); + if (similarity >= 1) { + return true; + } else if (similarity >= 0.5 && e.getSeason() == null && e.getEpisode() != null && e.getSpecial() == null) { + for (SxE it : parseEpisodeNumber(f, false)) { + if (it.season < 0 && it.episode == e.getEpisode()) { + return true; + } + } + } + return false; + } + public static List parseMovieYear(String name) { List years = new ArrayList(); for (String it : name.split("\\D+")) { diff --git a/source/net/filebot/similarity/EpisodeMatcher.java b/source/net/filebot/similarity/EpisodeMatcher.java index 66b0d627..b48999ca 100644 --- a/source/net/filebot/similarity/EpisodeMatcher.java +++ b/source/net/filebot/similarity/EpisodeMatcher.java @@ -22,7 +22,7 @@ public class EpisodeMatcher extends Matcher { public EpisodeMatcher(Collection values, Collection candidates, boolean strict) { // use strict matcher as to force a result from the final top similarity set - super(values, candidates, strict, strict ? StrictEpisodeMetrics.defaultSequence(false) : EpisodeMetrics.defaultSequence(false)); + super(values, candidates, strict, EpisodeMetrics.defaultSequence(false)); } @Override diff --git a/source/net/filebot/similarity/StrictEpisodeMetrics.java b/source/net/filebot/similarity/StrictEpisodeMetrics.java deleted file mode 100644 index 14bcfa4a..00000000 --- a/source/net/filebot/similarity/StrictEpisodeMetrics.java +++ /dev/null @@ -1,41 +0,0 @@ - -package net.filebot.similarity; - - -import static java.lang.Math.*; - - -public enum StrictEpisodeMetrics implements SimilarityMetric { - - FileName(EpisodeMetrics.FileName, 1), // only allow 0 or 1 - EpisodeIdentifier(EpisodeMetrics.EpisodeIdentifier, 1), // only allow 0 or 1 - SubstringFields(EpisodeMetrics.SubstringFields, 2), // allow 0 or .5 or 1 - Name(EpisodeMetrics.Name, 2); // allow 0 or .5 or 1 - - // inner metric - private final SimilarityMetric metric; - private final float floorFactor; - - - private StrictEpisodeMetrics(SimilarityMetric metric, float floorFactor) { - this.metric = metric; - this.floorFactor = floorFactor; - } - - - @Override - public float getSimilarity(Object o1, Object o2) { - return (float) (floor(metric.getSimilarity(o1, o2) * floorFactor) / floorFactor); - } - - - public static SimilarityMetric[] defaultSequence(boolean includeFileMetrics) { - // use SEI for matching and SN for excluding false positives - if (includeFileMetrics) { - return new SimilarityMetric[] { FileName, EpisodeIdentifier, SubstringFields, Name }; - } else { - return new SimilarityMetric[] { EpisodeIdentifier, SubstringFields, Name }; - } - } - -} diff --git a/source/net/filebot/ui/rename/EpisodeListMatcher.java b/source/net/filebot/ui/rename/EpisodeListMatcher.java index 06ae7885..f8461ce0 100644 --- a/source/net/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/filebot/ui/rename/EpisodeListMatcher.java @@ -39,7 +39,6 @@ import net.filebot.Analytics; import net.filebot.Settings; import net.filebot.similarity.CommonSequenceMatcher; import net.filebot.similarity.EpisodeMatcher; -import net.filebot.similarity.EpisodeMetrics; import net.filebot.similarity.Match; import net.filebot.ui.SelectDialog; import net.filebot.web.Episode; @@ -193,7 +192,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher { if (strict) { // in strict mode simply process file-by-file (ignoring all files that don't contain clear SxE patterns) for (final File file : mediaFiles) { - if (parseEpisodeNumber(file, true) != null || parseDate(file) != null) { + if (parseEpisodeNumber(file, false) != null || parseDate(file) != null) { tasks.add(new Callable>>() { @Override @@ -321,7 +320,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher { EpisodeMatcher matcher = new EpisodeMatcher(filesPerType, episodes, strict); for (Match it : matcher.match()) { // in strict mode sanity check the result and only pass back good matches - if (!strict || EpisodeMetrics.EpisodeIdentifier.getSimilarity(it.getValue(), it.getCandidate()) >= 1) { + if (!strict || isEpisodeNumberMatch(it.getValue(), (Episode) it.getCandidate())) { matches.add(new Match(it.getValue(), ((Episode) it.getCandidate()).clone())); } }