aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
diff options
context:
space:
mode:
authorstefan <stefan@hegedues.at>2018-09-12 19:26:21 +0200
committerstefan <stefan@hegedues.at>2018-09-12 19:26:21 +0200
commit48facb797ed912e4ea6b04b17d1ff190ac2daac4 (patch)
tree8dae77a31670a888d733484cb17dd4077d5444e8 /Emby.Naming/AudioBook/AudioBookFilePathParser.cs
parentc32d8656382a0eacb301692e0084377fc433ae9b (diff)
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'Emby.Naming/AudioBook/AudioBookFilePathParser.cs')
-rw-r--r--Emby.Naming/AudioBook/AudioBookFilePathParser.cs81
1 files changed, 81 insertions, 0 deletions
diff --git a/Emby.Naming/AudioBook/AudioBookFilePathParser.cs b/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
new file mode 100644
index 000000000..b4805edd2
--- /dev/null
+++ b/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using Emby.Naming.Common;
+using Emby.Naming.TV;
+
+namespace Emby.Naming.AudioBook
+{
+ public class AudioBookFilePathParser
+ {
+ private readonly NamingOptions _options;
+
+ public AudioBookFilePathParser(NamingOptions options)
+ {
+ _options = options;
+ }
+
+ public AudioBookFilePathParserResult Parse(string path, bool IsDirectory)
+ {
+ AudioBookFilePathParserResult result = Parse(path);
+ return !result.Success ? new AudioBookFilePathParserResult() : result;
+ }
+
+ private AudioBookFilePathParserResult Parse(string path)
+ {
+ var result = new AudioBookFilePathParserResult();
+ var fileName = Path.GetFileNameWithoutExtension(path);
+ foreach (var expression in _options.AudioBookPartsExpressions)
+ {
+ var match = new Regex(expression, RegexOptions.IgnoreCase).Match(fileName);
+ if (match.Success)
+ {
+ if (!result.ChapterNumber.HasValue)
+ {
+ var value = match.Groups["chapter"];
+ if (value.Success)
+ {
+ int intValue;
+ if (int.TryParse(value.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out intValue))
+ {
+ result.ChapterNumber = intValue;
+ }
+ }
+ }
+ if (!result.PartNumber.HasValue)
+ {
+ var value = match.Groups["part"];
+ if (value.Success)
+ {
+ int intValue;
+ if (int.TryParse(value.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out intValue))
+ {
+ result.ChapterNumber = 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;
+ }
+ }
+}