aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming/Audio
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2022-01-27 14:21:53 +0100
committerShadowghost <Ghost_of_Stone@web.de>2022-02-18 22:19:24 +0100
commitca5112f45a724fa24a420fa2b62c0849f99ff756 (patch)
treef071bacdbe36bf55cc41de0cf0ae999e58d5967d /Emby.Naming/Audio
parentb92e1baa3c28870f49f82bfef9e48cd79b9b24c6 (diff)
feat(external-media): refactor external subtitle and audio provider
Diffstat (limited to 'Emby.Naming/Audio')
-rw-r--r--Emby.Naming/Audio/ExternalAudioFileInfo.cs52
-rw-r--r--Emby.Naming/Audio/ExternalAudioFilePathParser.cs59
2 files changed, 111 insertions, 0 deletions
diff --git a/Emby.Naming/Audio/ExternalAudioFileInfo.cs b/Emby.Naming/Audio/ExternalAudioFileInfo.cs
new file mode 100644
index 000000000..4d02939cb
--- /dev/null
+++ b/Emby.Naming/Audio/ExternalAudioFileInfo.cs
@@ -0,0 +1,52 @@
+namespace Emby.Naming.Audio
+{
+ /// <summary>
+ /// Class holding information about external audio files.
+ /// </summary>
+ public class ExternalAudioFileInfo
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ExternalAudioFileInfo"/> class.
+ /// </summary>
+ /// <param name="path">Path to file.</param>
+ /// <param name="isDefault">Is default.</param>
+ /// <param name="isForced">Is forced.</param>
+ public ExternalAudioFileInfo(string path, bool isDefault, bool isForced)
+ {
+ Path = path;
+ IsDefault = isDefault;
+ IsForced = isForced;
+ }
+
+ /// <summary>
+ /// Gets or sets the path.
+ /// </summary>
+ /// <value>The path.</value>
+ public string Path { get; set; }
+
+ /// <summary>
+ /// Gets or sets the language.
+ /// </summary>
+ /// <value>The language.</value>
+ public string? Language { get; set; }
+
+ /// <summary>
+ /// Gets or sets the title.
+ /// </summary>
+ /// <value>The title.</value>
+ public string? Title { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this instance is default.
+ /// </summary>
+ /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
+ public bool IsDefault { get; set; }
+
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this instance is forced.
+ /// </summary>
+ /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
+ public bool IsForced { get; set; }
+ }
+}
diff --git a/Emby.Naming/Audio/ExternalAudioFilePathParser.cs b/Emby.Naming/Audio/ExternalAudioFilePathParser.cs
new file mode 100644
index 000000000..ab5af9fc6
--- /dev/null
+++ b/Emby.Naming/Audio/ExternalAudioFilePathParser.cs
@@ -0,0 +1,59 @@
+using System;
+using System.IO;
+using System.Linq;
+using Emby.Naming.Common;
+using Jellyfin.Extensions;
+
+namespace Emby.Naming.Audio
+{
+ /// <summary>
+ /// External Audio Parser class.
+ /// </summary>
+ public class ExternalAudioFilePathParser
+ {
+ private readonly NamingOptions _options;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ExternalAudioFilePathParser"/> class.
+ /// </summary>
+ /// <param name="options"><see cref="NamingOptions"/> object containing AudioFileExtensions, ExternalAudioDefaultFlags, ExternalAudioForcedFlags and ExternalAudioFlagDelimiters.</param>
+ public ExternalAudioFilePathParser(NamingOptions options)
+ {
+ _options = options;
+ }
+
+ /// <summary>
+ /// Parse file to determine if it is a ExternalAudio and <see cref="ExternalAudioFileInfo"/>.
+ /// </summary>
+ /// <param name="path">Path to file.</param>
+ /// <returns>Returns null or <see cref="ExternalAudioFileInfo"/> object if parsing is successful.</returns>
+ public ExternalAudioFileInfo? ParseFile(string path)
+ {
+ if (path.Length == 0)
+ {
+ return null;
+ }
+
+ var extension = Path.GetExtension(path);
+ if (!_options.AudioFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase))
+ {
+ return null;
+ }
+
+ var flags = GetFileFlags(path);
+ var info = new ExternalAudioFileInfo(
+ path,
+ _options.ExternalAudioDefaultFlags.Any(i => flags.Contains(i, StringComparison.OrdinalIgnoreCase)),
+ _options.ExternalAudioForcedFlags.Any(i => flags.Contains(i, StringComparison.OrdinalIgnoreCase)));
+
+ return info;
+ }
+
+ private string[] GetFileFlags(string path)
+ {
+ var file = Path.GetFileNameWithoutExtension(path);
+
+ return file.Split(_options.ExternalAudioFlagDelimiters, StringSplitOptions.RemoveEmptyEntries);
+ }
+ }
+}