aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming/AudioBook/AudioBookResolver.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Naming/AudioBook/AudioBookResolver.cs')
-rw-r--r--Emby.Naming/AudioBook/AudioBookResolver.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/Emby.Naming/AudioBook/AudioBookResolver.cs b/Emby.Naming/AudioBook/AudioBookResolver.cs
new file mode 100644
index 000000000..a206ee30b
--- /dev/null
+++ b/Emby.Naming/AudioBook/AudioBookResolver.cs
@@ -0,0 +1,60 @@
+using System;
+using System.IO;
+using System.Linq;
+using Emby.Naming.Common;
+using Emby.Naming.TV;
+using Emby.Naming.Video;
+
+namespace Emby.Naming.AudioBook
+{
+ public class AudioBookResolver
+ {
+ private readonly NamingOptions _options;
+
+ public AudioBookResolver(NamingOptions options)
+ {
+ _options = options;
+ }
+
+ public AudioBookFileInfo ParseFile(string path)
+ {
+ return Resolve(path, false);
+ }
+
+ public AudioBookFileInfo ParseDirectory(string path)
+ {
+ return Resolve(path, true);
+ }
+
+ public AudioBookFileInfo Resolve(string path, bool IsDirectory = false)
+ {
+ if (string.IsNullOrEmpty(path))
+ {
+ throw new ArgumentNullException("path");
+ }
+ if (IsDirectory)
+ return null;
+
+ var extension = Path.GetExtension(path) ?? string.Empty;
+ // Check supported extensions
+ if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
+ {
+ return null;
+ }
+
+ var container = extension.TrimStart('.');
+
+ var parsingResult = new AudioBookFilePathParser(_options)
+ .Parse(path, IsDirectory);
+
+ return new AudioBookFileInfo
+ {
+ Path = path,
+ Container = container,
+ PartNumber = parsingResult.PartNumber,
+ ChapterNumber = parsingResult.ChapterNumber,
+ IsDirectory = IsDirectory
+ };
+ }
+ }
+}