aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Naming')
-rw-r--r--Emby.Naming/Audio/AlbumParser.cs13
-rw-r--r--Emby.Naming/Common/NamingOptions.cs10
-rw-r--r--Emby.Naming/TV/SeriesResolver.cs7
-rw-r--r--Emby.Naming/Video/VideoListResolver.cs12
4 files changed, 24 insertions, 18 deletions
diff --git a/Emby.Naming/Audio/AlbumParser.cs b/Emby.Naming/Audio/AlbumParser.cs
index 86a564153..97961778f 100644
--- a/Emby.Naming/Audio/AlbumParser.cs
+++ b/Emby.Naming/Audio/AlbumParser.cs
@@ -10,7 +10,7 @@ namespace Emby.Naming.Audio
/// <summary>
/// Helper class to determine if Album is multipart.
/// </summary>
- public class AlbumParser
+ public partial class AlbumParser
{
private readonly NamingOptions _options;
@@ -23,6 +23,9 @@ namespace Emby.Naming.Audio
_options = options;
}
+ [GeneratedRegex(@"[-\.\(\)\s]+")]
+ private static partial Regex CleanRegex();
+
/// <summary>
/// Function that determines if album is multipart.
/// </summary>
@@ -42,13 +45,9 @@ namespace Emby.Naming.Audio
// Normalize
// Remove whitespace
- filename = filename.Replace('-', ' ');
- filename = filename.Replace('.', ' ');
- filename = filename.Replace('(', ' ');
- filename = filename.Replace(')', ' ');
- filename = Regex.Replace(filename, @"\s+", " ");
+ filename = CleanRegex().Replace(filename, " ");
- ReadOnlySpan<char> trimmedFilename = filename.TrimStart();
+ ReadOnlySpan<char> trimmedFilename = filename.AsSpan().TrimStart();
foreach (var prefix in _options.AlbumStackingPrefixes)
{
diff --git a/Emby.Naming/Common/NamingOptions.cs b/Emby.Naming/Common/NamingOptions.cs
index a069da102..2bd089ed8 100644
--- a/Emby.Naming/Common/NamingOptions.cs
+++ b/Emby.Naming/Common/NamingOptions.cs
@@ -318,22 +318,24 @@ namespace Emby.Naming.Common
new EpisodeExpression(@"[\._ -]()[Ee][Pp]_?([0-9]+)([^\\/]*)$"),
// <!-- foo.E01., foo.e01. -->
new EpisodeExpression(@"[^\\/]*?()\.?[Ee]([0-9]+)\.([^\\/]*)$"),
- new EpisodeExpression("(?<year>[0-9]{4})[\\.-](?<month>[0-9]{2})[\\.-](?<day>[0-9]{2})", true)
+ new EpisodeExpression(@"(?<year>[0-9]{4})[._ -](?<month>[0-9]{2})[._ -](?<day>[0-9]{2})", true)
{
DateTimeFormats = new[]
{
"yyyy.MM.dd",
"yyyy-MM-dd",
- "yyyy_MM_dd"
+ "yyyy_MM_dd",
+ "yyyy MM dd"
}
},
- new EpisodeExpression(@"(?<day>[0-9]{2})[.-](?<month>[0-9]{2})[.-](?<year>[0-9]{4})", true)
+ new EpisodeExpression(@"(?<day>[0-9]{2})[._ -](?<month>[0-9]{2})[._ -](?<year>[0-9]{4})", true)
{
DateTimeFormats = new[]
{
"dd.MM.yyyy",
"dd-MM-yyyy",
- "dd_MM_yyyy"
+ "dd_MM_yyyy",
+ "dd MM yyyy"
}
},
diff --git a/Emby.Naming/TV/SeriesResolver.cs b/Emby.Naming/TV/SeriesResolver.cs
index 307a84096..d8fa41743 100644
--- a/Emby.Naming/TV/SeriesResolver.cs
+++ b/Emby.Naming/TV/SeriesResolver.cs
@@ -7,14 +7,15 @@ namespace Emby.Naming.TV
/// <summary>
/// Used to resolve information about series from path.
/// </summary>
- public static class SeriesResolver
+ public static partial class SeriesResolver
{
/// <summary>
/// Regex that matches strings of at least 2 characters separated by a dot or underscore.
/// Used for removing separators between words, i.e turns "The_show" into "The show" while
/// preserving namings like "S.H.O.W".
/// </summary>
- private static readonly Regex _seriesNameRegex = new Regex(@"((?<a>[^\._]{2,})[\._]*)|([\._](?<b>[^\._]{2,}))", RegexOptions.Compiled);
+ [GeneratedRegex(@"((?<a>[^\._]{2,})[\._]*)|([\._](?<b>[^\._]{2,}))")]
+ private static partial Regex SeriesNameRegex();
/// <summary>
/// Resolve information about series from path.
@@ -37,7 +38,7 @@ namespace Emby.Naming.TV
if (!string.IsNullOrEmpty(seriesName))
{
- seriesName = _seriesNameRegex.Replace(seriesName, "${a} ${b}").Trim();
+ seriesName = SeriesNameRegex().Replace(seriesName, "${a} ${b}").Trim();
}
return new SeriesInfo(path)
diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs
index 6209cd46f..51f29cf08 100644
--- a/Emby.Naming/Video/VideoListResolver.cs
+++ b/Emby.Naming/Video/VideoListResolver.cs
@@ -12,9 +12,13 @@ namespace Emby.Naming.Video
/// <summary>
/// Resolves alternative versions and extras from list of video files.
/// </summary>
- public static class VideoListResolver
+ public static partial class VideoListResolver
{
- private static readonly Regex _resolutionRegex = new Regex("[0-9]{2}[0-9]+[ip]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
+ [GeneratedRegex("[0-9]{2}[0-9]+[ip]", RegexOptions.IgnoreCase)]
+ private static partial Regex ResolutionRegex();
+
+ [GeneratedRegex(@"^\[([^]]*)\]")]
+ private static partial Regex CheckMultiVersionRegex();
/// <summary>
/// Resolves alternative versions and extras from list of video files.
@@ -131,7 +135,7 @@ namespace Emby.Naming.Video
if (videos.Count > 1)
{
- var groups = videos.GroupBy(x => _resolutionRegex.IsMatch(x.Files[0].FileNameWithoutExtension)).ToList();
+ var groups = videos.GroupBy(x => ResolutionRegex().IsMatch(x.Files[0].FileNameWithoutExtension)).ToList();
videos.Clear();
foreach (var group in groups)
{
@@ -201,7 +205,7 @@ namespace Emby.Naming.Video
// The CleanStringParser should have removed common keywords etc.
return testFilename.IsEmpty
|| testFilename[0] == '-'
- || Regex.IsMatch(testFilename, @"^\[([^]]*)\]", RegexOptions.Compiled);
+ || CheckMultiVersionRegex().IsMatch(testFilename);
}
}
}