From c5be87c21354acf1b42c64aa9af9746e53de56a8 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 26 Sep 2016 18:53:20 +0800 Subject: [PATCH] Deal with different kinds of colon properly --- .../filebot/format/ExpressionFormatMethods.java | 16 +++++++++++++--- source/net/filebot/media/NamingStandard.java | 2 +- source/net/filebot/similarity/Normalization.java | 4 ++++ source/net/filebot/util/RegularExpressions.java | 2 ++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/source/net/filebot/format/ExpressionFormatMethods.java b/source/net/filebot/format/ExpressionFormatMethods.java index 84c67679..119b6135 100644 --- a/source/net/filebot/format/ExpressionFormatMethods.java +++ b/source/net/filebot/format/ExpressionFormatMethods.java @@ -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); } /** diff --git a/source/net/filebot/media/NamingStandard.java b/source/net/filebot/media/NamingStandard.java index 4c4ee181..c9ede3ac 100644 --- a/source/net/filebot/media/NamingStandard.java +++ b/source/net/filebot/media/NamingStandard.java @@ -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); diff --git a/source/net/filebot/similarity/Normalization.java b/source/net/filebot/similarity/Normalization.java index 4bad36a9..de178400 100644 --- a/source/net/filebot/similarity/Normalization.java +++ b/source/net/filebot/similarity/Normalization.java @@ -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()) { diff --git a/source/net/filebot/util/RegularExpressions.java b/source/net/filebot/util/RegularExpressions.java index a8db86b9..da47fdfa 100644 --- a/source/net/filebot/util/RegularExpressions.java +++ b/source/net/filebot/util/RegularExpressions.java @@ -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