2019-12-13 19:11:37 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2018-09-12 17:26:21 +00:00
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text.RegularExpressions;
|
2019-01-13 19:17:29 +00:00
|
|
|
using Emby.Naming.Common;
|
2018-09-12 17:26:21 +00:00
|
|
|
|
|
|
|
namespace Emby.Naming.Audio
|
|
|
|
{
|
|
|
|
public class AlbumParser
|
|
|
|
{
|
|
|
|
private readonly NamingOptions _options;
|
|
|
|
|
|
|
|
public AlbumParser(NamingOptions options)
|
|
|
|
{
|
|
|
|
_options = options;
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:18:56 +00:00
|
|
|
public bool IsMultiPart(string path)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
|
|
|
var filename = Path.GetFileName(path);
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(filename))
|
|
|
|
{
|
2020-01-22 21:18:56 +00:00
|
|
|
return false;
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2019-05-10 18:37:42 +00:00
|
|
|
filename = filename.Replace('-', ' ');
|
|
|
|
filename = filename.Replace('.', ' ');
|
|
|
|
filename = filename.Replace('(', ' ');
|
|
|
|
filename = filename.Replace(')', ' ');
|
2018-09-12 17:26:21 +00:00
|
|
|
filename = Regex.Replace(filename, @"\s+", " ");
|
|
|
|
|
|
|
|
filename = filename.TrimStart();
|
|
|
|
|
|
|
|
foreach (var prefix in _options.AlbumStackingPrefixes)
|
|
|
|
{
|
2019-05-10 18:37:42 +00:00
|
|
|
if (filename.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) != 0)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
2019-05-10 18:37:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmp = filename.Substring(prefix.Length);
|
2018-09-12 17:26:21 +00:00
|
|
|
|
2019-05-10 18:37:42 +00:00
|
|
|
tmp = tmp.Trim().Split(' ').FirstOrDefault() ?? string.Empty;
|
2018-09-12 17:26:21 +00:00
|
|
|
|
2019-05-10 18:37:42 +00:00
|
|
|
if (int.TryParse(tmp, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
|
|
|
|
{
|
2020-01-22 21:18:56 +00:00
|
|
|
return true;
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:18:56 +00:00
|
|
|
return false;
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|