* make sure SxE matcher doesn't fall back on release info patterns like x264 or 720p
This commit is contained in:
parent
cf062bbe44
commit
4038e7a6af
|
@ -116,8 +116,8 @@ public class MediaDetection {
|
|||
return releaseInfo.getLanguageSuffix(getName(file));
|
||||
}
|
||||
|
||||
private static final SeasonEpisodeMatcher seasonEpisodeMatcherStrict = new SeasonEpisodeMatcherWithFilter(true);
|
||||
private static final SeasonEpisodeMatcher seasonEpisodeMatcherNonStrict = new SeasonEpisodeMatcherWithFilter(false);
|
||||
private static final SeasonEpisodeMatcher seasonEpisodeMatcherStrict = new SmartSeasonEpisodeMatcher(true);
|
||||
private static final SeasonEpisodeMatcher seasonEpisodeMatcherNonStrict = new SmartSeasonEpisodeMatcher(false);
|
||||
|
||||
public static SeasonEpisodeMatcher getSeasonEpisodeMatcher(boolean strict) {
|
||||
return strict ? seasonEpisodeMatcherStrict : seasonEpisodeMatcherNonStrict;
|
||||
|
@ -1283,33 +1283,6 @@ public class MediaDetection {
|
|||
}
|
||||
}
|
||||
|
||||
private static class SeasonEpisodeMatcherWithFilter extends SeasonEpisodeMatcher {
|
||||
|
||||
private final Pattern ignorePattern = MediaDetection.releaseInfo.getVideoFormatPattern(false);
|
||||
|
||||
public SeasonEpisodeMatcherWithFilter(boolean strict) {
|
||||
super(DEFAULT_SANITY, strict);
|
||||
}
|
||||
|
||||
protected String clean(CharSequence name) {
|
||||
return ignorePattern.matcher(name).replaceAll("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SxE> match(CharSequence name) {
|
||||
return super.match(clean(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> tokenizeTail(File file) {
|
||||
List<String> tail = super.tokenizeTail(file);
|
||||
for (int i = 0; i < tail.size(); i++) {
|
||||
tail.set(i, clean(tail.get(i)));
|
||||
}
|
||||
return tail;
|
||||
}
|
||||
}
|
||||
|
||||
public static Comparator<File> VIDEO_SIZE_ORDER = new Comparator<File>() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package net.sourceforge.filebot.media;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.sourceforge.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);
|
||||
|
||||
public SmartSeasonEpisodeMatcher(SeasonEpisodeFilter sanity, boolean strict) {
|
||||
super(sanity, strict);
|
||||
}
|
||||
|
||||
public SmartSeasonEpisodeMatcher(boolean strict) {
|
||||
super(DEFAULT_SANITY, strict);
|
||||
}
|
||||
|
||||
protected String clean(CharSequence name) {
|
||||
return ignorePattern.matcher(name).replaceAll("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SxE> match(CharSequence name) {
|
||||
return super.match(clean(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> tokenizeTail(File file) {
|
||||
List<String> tail = super.tokenizeTail(file);
|
||||
for (int i = 0; i < tail.size(); i++) {
|
||||
tail.set(i, clean(tail.get(i)));
|
||||
}
|
||||
return tail;
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import net.sourceforge.filebot.WebServices;
|
||||
import net.sourceforge.filebot.media.ReleaseInfo;
|
||||
import net.sourceforge.filebot.media.SmartSeasonEpisodeMatcher;
|
||||
import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE;
|
||||
import net.sourceforge.filebot.vfs.FileInfo;
|
||||
import net.sourceforge.filebot.web.Date;
|
||||
|
@ -43,7 +44,7 @@ import com.ibm.icu.text.Transliterator;
|
|||
public enum EpisodeMetrics implements SimilarityMetric {
|
||||
|
||||
// Match by season / episode numbers
|
||||
SeasonEpisode(new SeasonEpisodeMetric() {
|
||||
SeasonEpisode(new SeasonEpisodeMetric(new SmartSeasonEpisodeMatcher(null, false)) {
|
||||
|
||||
private final Map<Object, Collection<SxE>> transformCache = synchronizedMap(new HashMap<Object, Collection<SxE>>(64, 4));
|
||||
|
||||
|
|
|
@ -1,28 +1,32 @@
|
|||
|
||||
package net.sourceforge.filebot.similarity;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE;
|
||||
|
||||
|
||||
public class SeasonEpisodeMetric implements SimilarityMetric {
|
||||
|
||||
private final SeasonEpisodeMatcher seasonEpisodeMatcher = new SeasonEpisodeMatcher(null, false);
|
||||
|
||||
|
||||
|
||||
private SeasonEpisodeMatcher seasonEpisodeMatcher;
|
||||
|
||||
public SeasonEpisodeMetric() {
|
||||
this.seasonEpisodeMatcher = new SeasonEpisodeMatcher(null, false);
|
||||
}
|
||||
|
||||
public SeasonEpisodeMetric(SeasonEpisodeMatcher seasonEpisodeMatcher) {
|
||||
this.seasonEpisodeMatcher = seasonEpisodeMatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSimilarity(Object o1, Object o2) {
|
||||
Collection<SxE> sxeVector1 = parse(o1);
|
||||
if (sxeVector1 == null || sxeVector1.isEmpty())
|
||||
return 0;
|
||||
|
||||
|
||||
Collection<SxE> sxeVector2 = parse(o2);
|
||||
if (sxeVector2 == null || sxeVector2.isEmpty())
|
||||
return 0;
|
||||
|
||||
|
||||
float similarity = -1;
|
||||
for (SxE sxe1 : sxeVector1) {
|
||||
for (SxE sxe2 : sxeVector2) {
|
||||
|
@ -30,24 +34,23 @@ public class SeasonEpisodeMetric implements SimilarityMetric {
|
|||
// vectors have at least one perfect episode match in common (require season >= 0 as to put less trust in single-number matches)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if ((sxe1.season >= 0 && sxe1.season == sxe2.season) || (sxe1.episode >= 0 && sxe1.episode == sxe2.episode)) {
|
||||
// at least we have a partial match
|
||||
similarity = 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return similarity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected Collection<SxE> parse(Object object) {
|
||||
if (object instanceof File) {
|
||||
return seasonEpisodeMatcher.match((File) object);
|
||||
}
|
||||
|
||||
|
||||
return seasonEpisodeMatcher.match(object.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.sourceforge.filebot.similarity;
|
|||
import static java.util.Arrays.*;
|
||||
import static net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE.*;
|
||||
import static org.junit.Assert.*;
|
||||
import net.sourceforge.filebot.media.MediaDetection;
|
||||
import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -78,9 +79,6 @@ public class SeasonEpisodeMatcherTest {
|
|||
// test season digits <= 19
|
||||
assertEquals(new SxE(null, 16), matcher.match("E16").get(0));
|
||||
|
||||
// test look-ahead
|
||||
assertEquals(asList(new SxE(7, 20)), matcher.match("720p"));
|
||||
|
||||
// test ambiguous match processing
|
||||
assertEquals(asList(new SxE(1, 1), new SxE(UNDEFINED, 101)), matcher.match("Test.101"));
|
||||
|
||||
|
@ -112,4 +110,12 @@ public class SeasonEpisodeMatcherTest {
|
|||
assertEquals(new SxE(1, 4), matcher.match("1x01.1x02.1x03.1x04").get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withReleaseInfo() {
|
||||
assertEquals("[7x20]", matcher.match("720p").toString());
|
||||
|
||||
SeasonEpisodeMatcher smartMatcher = MediaDetection.getSeasonEpisodeMatcher(true);
|
||||
assertEquals(null, smartMatcher.match("720p"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue