1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-02 00:15:02 -04:00

Deal with different kinds of colon properly

This commit is contained in:
Reinhard Pointner 2016-09-26 18:53:20 +08:00
parent 41967a00b3
commit c5be87c213
4 changed files with 20 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import static java.util.regex.Pattern.*;
import static net.filebot.MediaTypes.*;
import static net.filebot.format.ExpressionFormatFunctions.*;
import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.RegularExpressions.*;
import java.io.File;
import java.io.IOException;
@ -142,8 +143,17 @@ public class ExpressionFormatMethods {
*
* e.g. "Sissi: The Young Empress" -> "Sissi - The Young Empress"
*/
public static String colon(String self, String replacement) {
return compile("\\s*[:]\\s*", UNICODE_CHARACTER_CLASS).matcher(self).replaceAll(replacement);
public static String colon(String self, String colon) {
return COLON.matcher(self).replaceAll(colon);
}
/**
* Replace colon to make the name more Windows friendly.
*
* e.g. "12:00 A.M.-1:00 A.M." -> "12.00 A.M.-1.00 A.M."
*/
public static String colon(String self, String ratio, String colon) {
return COLON.matcher(RATIO.matcher(self).replaceAll(ratio)).replaceAll(colon);
}
/**
@ -152,7 +162,7 @@ public class ExpressionFormatMethods {
* e.g. "V_MPEG4/ISO/AVC" -> "V_MPEG4.ISO.AVC"
*/
public static String slash(String self, String replacement) {
return compile("\\s*[\\\\/]+\\s*", UNICODE_CHARACTER_CLASS).matcher(self).replaceAll(replacement);
return SLASH.matcher(self).replaceAll(replacement);
}
/**

View File

@ -72,7 +72,7 @@ public enum NamingStandard {
private static String path(String... name) {
return stream(name).filter(Objects::nonNull).map(s -> {
s = s.replace(":", " - ");
s = replaceColon(s, ".", " - ");
s = replacePathSeparators(s, " ");
s = normalizeQuotationMarks(s);
s = trimTrailingPunctuation(s);

View File

@ -57,6 +57,10 @@ public class Normalization {
return SPACE.matcher(name).replaceAll(replacement);
}
public static String replaceColon(String name, String ratio, String colon) {
return COLON.matcher(RATIO.matcher(name).replaceAll(ratio)).replaceAll(colon);
}
public static String getEmbeddedChecksum(String name) {
Matcher m = EMBEDDED_CHECKSUM.matcher(name);
if (m.find()) {

View File

@ -15,6 +15,8 @@ public class RegularExpressions {
public static final Pattern SEMICOLON = compile(";", LITERAL);
public static final Pattern COMMA = compile("\\s*[,;:]\\s*", UNICODE_CHARACTER_CLASS);
public static final Pattern RATIO = compile("(?<=\\w)[:\u2236](?=\\w)", UNICODE_CHARACTER_CLASS);
public static final Pattern COLON = compile("\\s*[:]+\\s*", UNICODE_CHARACTER_CLASS);
public static final Pattern SLASH = compile("\\s*[\\\\/]+\\s*", UNICODE_CHARACTER_CLASS);
public static final Pattern SPACE = compile("\\s+", UNICODE_CHARACTER_CLASS); // French No-Break Space U+00A0