aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming/AudioBook
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Naming/AudioBook')
-rw-r--r--Emby.Naming/AudioBook/AudioBookFilePathParser.cs6
-rw-r--r--Emby.Naming/AudioBook/AudioBookListResolver.cs20
-rw-r--r--Emby.Naming/AudioBook/AudioBookNameParser.cs4
3 files changed, 15 insertions, 15 deletions
diff --git a/Emby.Naming/AudioBook/AudioBookFilePathParser.cs b/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
index 7b4429ab15..75fdedfeab 100644
--- a/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
+++ b/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
@@ -32,7 +32,7 @@ namespace Emby.Naming.AudioBook
var fileName = Path.GetFileNameWithoutExtension(path);
foreach (var expression in _options.AudioBookPartsExpressions)
{
- var match = new Regex(expression, RegexOptions.IgnoreCase).Match(fileName);
+ var match = Regex.Match(fileName, expression, RegexOptions.IgnoreCase);
if (match.Success)
{
if (!result.ChapterNumber.HasValue)
@@ -40,7 +40,7 @@ namespace Emby.Naming.AudioBook
var value = match.Groups["chapter"];
if (value.Success)
{
- if (int.TryParse(value.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
+ if (int.TryParse(value.ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
{
result.ChapterNumber = intValue;
}
@@ -52,7 +52,7 @@ namespace Emby.Naming.AudioBook
var value = match.Groups["part"];
if (value.Success)
{
- if (int.TryParse(value.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
+ if (int.TryParse(value.ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
{
result.PartNumber = intValue;
}
diff --git a/Emby.Naming/AudioBook/AudioBookListResolver.cs b/Emby.Naming/AudioBook/AudioBookListResolver.cs
index bdae20b6b2..ca304102fd 100644
--- a/Emby.Naming/AudioBook/AudioBookListResolver.cs
+++ b/Emby.Naming/AudioBook/AudioBookListResolver.cs
@@ -79,25 +79,25 @@ namespace Emby.Naming.AudioBook
{
if (group.Count() > 1 || haveChaptersOrPages)
{
- var ex = new List<AudioBookFileInfo>();
- var alt = new List<AudioBookFileInfo>();
+ List<AudioBookFileInfo>? ex = null;
+ List<AudioBookFileInfo>? alt = null;
foreach (var audioFile in group)
{
- var name = Path.GetFileNameWithoutExtension(audioFile.Path);
- if (name.Equals("audiobook", StringComparison.OrdinalIgnoreCase) ||
- name.Contains(nameParserResult.Name, StringComparison.OrdinalIgnoreCase) ||
- name.Contains(nameWithReplacedDots, StringComparison.OrdinalIgnoreCase))
+ var name = Path.GetFileNameWithoutExtension(audioFile.Path.AsSpan());
+ if (name.Equals("audiobook", StringComparison.OrdinalIgnoreCase)
+ || name.Contains(nameParserResult.Name, StringComparison.OrdinalIgnoreCase)
+ || name.Contains(nameWithReplacedDots, StringComparison.OrdinalIgnoreCase))
{
- alt.Add(audioFile);
+ (alt ??= new()).Add(audioFile);
}
else
{
- ex.Add(audioFile);
+ (ex ??= new()).Add(audioFile);
}
}
- if (ex.Count > 0)
+ if (ex is not null)
{
var extra = ex
.OrderBy(x => x.Container)
@@ -108,7 +108,7 @@ namespace Emby.Naming.AudioBook
extras.AddRange(extra);
}
- if (alt.Count > 0)
+ if (alt is not null)
{
var alternatives = alt
.OrderBy(x => x.Container)
diff --git a/Emby.Naming/AudioBook/AudioBookNameParser.cs b/Emby.Naming/AudioBook/AudioBookNameParser.cs
index 97b34199e0..5ea649dbf7 100644
--- a/Emby.Naming/AudioBook/AudioBookNameParser.cs
+++ b/Emby.Naming/AudioBook/AudioBookNameParser.cs
@@ -30,7 +30,7 @@ namespace Emby.Naming.AudioBook
AudioBookNameParserResult result = default;
foreach (var expression in _options.AudioBookNamesExpressions)
{
- var match = new Regex(expression, RegexOptions.IgnoreCase).Match(name);
+ var match = Regex.Match(name, expression, RegexOptions.IgnoreCase);
if (match.Success)
{
if (result.Name is null)
@@ -47,7 +47,7 @@ namespace Emby.Naming.AudioBook
var value = match.Groups["year"];
if (value.Success)
{
- if (int.TryParse(value.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
+ if (int.TryParse(value.ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
{
result.Year = intValue;
}