Refactor ClutterBracketPattern
This commit is contained in:
parent
32c40157a4
commit
91ed090da1
|
@ -36,6 +36,7 @@ import java.util.function.Function;
|
|||
import java.util.function.IntFunction;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.tukaani.xz.XZInputStream;
|
||||
|
||||
|
@ -181,9 +182,10 @@ public class ReleaseInfo {
|
|||
}
|
||||
|
||||
return items.stream().map(it -> {
|
||||
it = strict ? clean(it, stopwords[b]) : substringBefore(it, stopwords[b]);
|
||||
it = normalizePunctuation(clean(it, blacklist[b]));
|
||||
return it;
|
||||
String head = strict ? clean(it, stopwords[b]) : substringBefore(it, stopwords[b]);
|
||||
String norm = normalizePunctuation(clean(head, blacklist[b]));
|
||||
// debug.finest(format("CLEAN: %s => %s => %s", it, head, norm));
|
||||
return norm;
|
||||
}).filter(s -> s.length() > 0).collect(toList());
|
||||
}
|
||||
|
||||
|
@ -310,8 +312,15 @@ public class ReleaseInfo {
|
|||
|
||||
public Pattern getClutterBracketPattern(boolean strict) {
|
||||
// match patterns like [Action, Drama] or {ENG-XViD-MP3-DVDRiP} etc
|
||||
String contentFilter = strict ? "[\\p{Space}\\p{Punct}&&[^\\[\\]]]" : "\\p{Alpha}";
|
||||
return compile("(?:\\[([^\\[\\]]+?" + contentFilter + "[^\\[\\]]+?)\\])|(?:\\{([^\\{\\}]+?" + contentFilter + "[^\\{\\}]+?)\\})|(?:\\(([^\\(\\)]+?" + contentFilter + "[^\\(\\)]+?)\\))");
|
||||
String brackets = "()[]{}";
|
||||
String contains = strict ? "[[^a-z0-9]&&[^" + quote(brackets) + "]]" : "\\p{Alpha}";
|
||||
|
||||
return IntStream.range(0, brackets.length() / 2).map(i -> i * 2).mapToObj(i -> {
|
||||
String open = quote(brackets.substring(i, i + 1));
|
||||
String close = quote(brackets.substring(i + 1, i + 2));
|
||||
String notOpenClose = "[^" + open + close + "]+?";
|
||||
return open + "(" + notOpenClose + contains + notOpenClose + ")" + close;
|
||||
}).collect(collectingAndThen(joining("|"), pattern -> compile(pattern, CASE_INSENSITIVE)));
|
||||
}
|
||||
|
||||
public Pattern getReleaseGroupPattern(boolean strict) throws Exception {
|
||||
|
|
|
@ -1,31 +1,34 @@
|
|||
|
||||
package net.filebot.media;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class ReleaseInfoTest {
|
||||
|
||||
ReleaseInfo info = new ReleaseInfo();
|
||||
|
||||
@Test
|
||||
public void getVideoSource() {
|
||||
ReleaseInfo info = new ReleaseInfo();
|
||||
File f = new File("Jurassic.Park[1993]DvDrip-aXXo.avi");
|
||||
|
||||
assertEquals("DVDRip", info.getVideoSource(f.getName()));
|
||||
assertEquals("DVDRip", info.getVideoSource("Jurassic.Park[1993]DvDrip-aXXo"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getReleaseGroup() throws Exception {
|
||||
ReleaseInfo info = new ReleaseInfo();
|
||||
File f = new File("Jurassic.Park[1993]DvDrip-aXXo.avi");
|
||||
assertEquals("aXXo", info.getReleaseGroup("Jurassic.Park[1993]DvDrip-aXXo"));
|
||||
}
|
||||
|
||||
assertEquals("aXXo", info.getReleaseGroup(f.getName()));
|
||||
@Test
|
||||
public void getClutterBracketPattern() throws Exception {
|
||||
assertEquals("John [2016] (ENG)", clean(info.getClutterBracketPattern(true), "John [2016] [Action, Drama] (ENG)"));
|
||||
assertEquals("John [2016] ", clean(info.getClutterBracketPattern(false), "John [2016] [Action, Drama] (ENG)"));
|
||||
}
|
||||
|
||||
private static String clean(Pattern p, String s) {
|
||||
return p.matcher(s).replaceAll("");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue