diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index e509f82d..504974b5 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -105,6 +105,11 @@ public class MediaDetection { } + public static List parseEpisodeNumber(File file, boolean strict) { + return new SeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, strict).match(file); + } + + public static Date parseDate(Object object) { return new DateMetric().parse(object); } diff --git a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java index aed9e237..12d2ed58 100644 --- a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java +++ b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMatcher.java @@ -4,7 +4,9 @@ package net.sourceforge.filebot.similarity; import static java.util.Arrays.*; import static java.util.Collections.*; +import static java.util.regex.Pattern.*; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -20,6 +22,7 @@ public class SeasonEpisodeMatcher { public static final SeasonEpisodeFilter DEFAULT_SANITY = new SeasonEpisodeFilter(50, 50, 1000); private SeasonEpisodePattern[] patterns; + private Pattern seasonPattern; public SeasonEpisodeMatcher(SeasonEpisodeFilter sanity, boolean strict) { @@ -86,6 +89,9 @@ public class SeasonEpisodeMatcher { if (strict) { patterns = new SeasonEpisodePattern[] { patterns[0], patterns[1], patterns[2] }; } + + // season folder pattern for complementing partial sxe info from filename + seasonPattern = compile("Season\\D?(\\d{1,2})", CASE_INSENSITIVE | UNICODE_CASE); } @@ -105,6 +111,27 @@ public class SeasonEpisodeMatcher { return match; } } + return null; + } + + + public List match(File file) { + for (SeasonEpisodePattern pattern : patterns) { + List match = pattern.match(file.getName()); + + if (!match.isEmpty()) { + // current pattern did match + for (int i = 0; i < match.size(); i++) { + if (match.get(i).season < 0) { + Matcher sm = seasonPattern.matcher(file.getPath()); + if (sm.find()) { + match.set(i, new SxE(Integer.parseInt(sm.group(1)), match.get(i).episode)); + } + } + } + return match; + } + } return null; } diff --git a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMetric.java b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMetric.java index 36275c0c..133e8391 100644 --- a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMetric.java +++ b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMetric.java @@ -44,8 +44,7 @@ public class SeasonEpisodeMetric implements SimilarityMetric { protected Collection parse(Object object) { if (object instanceof File) { - // parse file name - object = ((File) object).getName(); + return seasonEpisodeMatcher.match((File) object); } return seasonEpisodeMatcher.match(object.toString()); diff --git a/website/data/query-blacklist.txt b/website/data/query-blacklist.txt index 4308cc17..eae3c333 100644 --- a/website/data/query-blacklist.txt +++ b/website/data/query-blacklist.txt @@ -193,7 +193,7 @@ samples SBS Screenshot sd -Season.[0-9]+ +Season.?[0-9]+ sed ShareGo ShareReactor diff --git a/website/scripts/amc.groovy b/website/scripts/amc.groovy index 7f70688e..cfbc894b 100644 --- a/website/scripts/amc.groovy +++ b/website/scripts/amc.groovy @@ -45,7 +45,7 @@ def forceMovie(f) { } def forceSeries(f) { - parseEpisodeNumber(f) || parseDate(f) || tryQuietly{ ut_label } =~ /^(?i:TV|Kids.Shows)/ + parseEpisodeNumber(f) || parseDate(f) || f.path =~ /(?i:Season)\D?[0-9]{1,2}/ || tryQuietly{ ut_label } =~ /^(?i:TV|Kids.Shows)/ } def forceAnime(f) {