aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
diff options
context:
space:
mode:
authorWWWesten <4700006+WWWesten@users.noreply.github.com>2021-11-01 23:43:29 +0500
committerGitHub <noreply@github.com>2021-11-01 23:43:29 +0500
commit0a14279e2a21bcb9654a06a2d49e1e4f0cc5329c (patch)
treee1b1bd603b011ca98e5793e356326bf4a35a7050 /Emby.Naming/AudioBook/AudioBookFilePathParser.cs
parentf2817fef743eeb75a00782ceea363b2d3e7dc9f2 (diff)
parent76eeb8f655424d295e73ced8349c6fefee6ddb12 (diff)
Merge branch 'jellyfin:master' into master
Diffstat (limited to 'Emby.Naming/AudioBook/AudioBookFilePathParser.cs')
-rw-r--r--Emby.Naming/AudioBook/AudioBookFilePathParser.cs39
1 files changed, 16 insertions, 23 deletions
diff --git a/Emby.Naming/AudioBook/AudioBookFilePathParser.cs b/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
index 590979794..7b4429ab1 100644
--- a/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
+++ b/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
@@ -5,24 +5,30 @@ using Emby.Naming.Common;
namespace Emby.Naming.AudioBook
{
+ /// <summary>
+ /// Parser class to extract part and/or chapter number from audiobook filename.
+ /// </summary>
public class AudioBookFilePathParser
{
private readonly NamingOptions _options;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AudioBookFilePathParser"/> class.
+ /// </summary>
+ /// <param name="options">Naming options containing AudioBookPartsExpressions.</param>
public AudioBookFilePathParser(NamingOptions options)
{
_options = options;
}
- public AudioBookFilePathParserResult Parse(string path, bool IsDirectory)
+ /// <summary>
+ /// Based on regex determines if filename includes part/chapter number.
+ /// </summary>
+ /// <param name="path">Path to audiobook file.</param>
+ /// <returns>Returns <see cref="AudioBookFilePathParser"/> object.</returns>
+ public AudioBookFilePathParserResult Parse(string path)
{
- var result = Parse(path);
- return !result.Success ? new AudioBookFilePathParserResult() : result;
- }
-
- private AudioBookFilePathParserResult Parse(string path)
- {
- var result = new AudioBookFilePathParserResult();
+ AudioBookFilePathParserResult result = default;
var fileName = Path.GetFileNameWithoutExtension(path);
foreach (var expression in _options.AudioBookPartsExpressions)
{
@@ -40,6 +46,7 @@ namespace Emby.Naming.AudioBook
}
}
}
+
if (!result.PartNumber.HasValue)
{
var value = match.Groups["part"];
@@ -47,27 +54,13 @@ namespace Emby.Naming.AudioBook
{
if (int.TryParse(value.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
{
- result.ChapterNumber = intValue;
+ result.PartNumber = intValue;
}
}
}
}
}
- /*var matches = _iRegexProvider.GetRegex("\\d+", RegexOptions.IgnoreCase).Matches(fileName);
- if (matches.Count > 0)
- {
- if (!result.ChapterNumber.HasValue)
- {
- result.ChapterNumber = int.Parse(matches[0].Groups[0].Value);
- }
- if (matches.Count > 1)
- {
- result.PartNumber = int.Parse(matches[matches.Count - 1].Groups[0].Value);
- }
- }*/
- result.Success = result.PartNumber.HasValue || result.ChapterNumber.HasValue;
-
return result;
}
}