aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming/Audio
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/Audio
parentc32d8656382a0eacb301692e0084377fc433ae9b (diff)
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'Emby.Naming/Audio')
-rw-r--r--Emby.Naming/Audio/AlbumParser.cs65
-rw-r--r--Emby.Naming/Audio/AudioFileParser.cs23
-rw-r--r--Emby.Naming/Audio/MultiPartResult.cs22
3 files changed, 110 insertions, 0 deletions
diff --git a/Emby.Naming/Audio/AlbumParser.cs b/Emby.Naming/Audio/AlbumParser.cs
new file mode 100644
index 0000000000..c88631a0c8
--- /dev/null
+++ b/Emby.Naming/Audio/AlbumParser.cs
@@ -0,0 +1,65 @@
+using Emby.Naming.Common;
+using Emby.Naming.Video;
+using System;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+
+namespace Emby.Naming.Audio
+{
+ public class AlbumParser
+ {
+ private readonly NamingOptions _options;
+
+ public AlbumParser(NamingOptions options)
+ {
+ _options = options;
+ }
+
+ public MultiPartResult ParseMultiPart(string path)
+ {
+ var result = new MultiPartResult();
+
+ var filename = Path.GetFileName(path);
+
+ if (string.IsNullOrEmpty(filename))
+ {
+ return result;
+ }
+
+ // TODO: Move this logic into options object
+ // Even better, remove the prefixes and come up with regexes
+ // But Kodi documentation seems to be weak for audio
+
+ // Normalize
+ // Remove whitespace
+ filename = filename.Replace("-", " ");
+ filename = filename.Replace(".", " ");
+ filename = filename.Replace("(", " ");
+ filename = filename.Replace(")", " ");
+ filename = Regex.Replace(filename, @"\s+", " ");
+
+ filename = filename.TrimStart();
+
+ foreach (var prefix in _options.AlbumStackingPrefixes)
+ {
+ if (filename.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) == 0)
+ {
+ var tmp = filename.Substring(prefix.Length);
+
+ tmp = tmp.Trim().Split(' ').FirstOrDefault() ?? string.Empty;
+
+ int val;
+ if (int.TryParse(tmp, NumberStyles.Integer, CultureInfo.InvariantCulture, out val))
+ {
+ result.IsMultiPart = true;
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/Emby.Naming/Audio/AudioFileParser.cs b/Emby.Naming/Audio/AudioFileParser.cs
new file mode 100644
index 0000000000..20016915ae
--- /dev/null
+++ b/Emby.Naming/Audio/AudioFileParser.cs
@@ -0,0 +1,23 @@
+using System;
+using System.IO;
+using System.Linq;
+using Emby.Naming.Common;
+
+namespace Emby.Naming.Audio
+{
+ public class AudioFileParser
+ {
+ private readonly NamingOptions _options;
+
+ public AudioFileParser(NamingOptions options)
+ {
+ _options = options;
+ }
+
+ public bool IsAudioFile(string path)
+ {
+ var extension = Path.GetExtension(path) ?? string.Empty;
+ return _options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
+ }
+ }
+}
diff --git a/Emby.Naming/Audio/MultiPartResult.cs b/Emby.Naming/Audio/MultiPartResult.cs
new file mode 100644
index 0000000000..fae0ae4d81
--- /dev/null
+++ b/Emby.Naming/Audio/MultiPartResult.cs
@@ -0,0 +1,22 @@
+
+namespace Emby.Naming.Audio
+{
+ public class MultiPartResult
+ {
+ /// <summary>
+ /// Gets or sets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name { get; set; }
+ /// <summary>
+ /// Gets or sets the part.
+ /// </summary>
+ /// <value>The part.</value>
+ public string Part { get; set; }
+ /// <summary>
+ /// Gets or sets a value indicating whether this instance is multi part.
+ /// </summary>
+ /// <value><c>true</c> if this instance is multi part; otherwise, <c>false</c>.</value>
+ public bool IsMultiPart { get; set; }
+ }
+}