You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/Emby.Naming/Audio/AlbumParser.cs

70 lines
1.9 KiB

4 years ago
#nullable enable
#pragma warning disable CS1591
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Emby.Naming.Common;
namespace Emby.Naming.Audio
{
public class AlbumParser
{
private readonly NamingOptions _options;
public AlbumParser(NamingOptions options)
{
_options = options;
}
public bool IsMultiPart(string path)
{
var filename = Path.GetFileName(path);
4 years ago
if (path.Length == 0)
{
return false;
}
// 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+", " ");
4 years ago
ReadOnlySpan<char> trimmedFilename = filename.TrimStart();
foreach (var prefix in _options.AlbumStackingPrefixes)
{
4 years ago
if (!trimmedFilename.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
{
continue;
}
4 years ago
var tmp = trimmedFilename.Slice(prefix.Length).Trim();
4 years ago
int index = tmp.IndexOf(' ');
if (index != -1)
{
tmp = tmp.Slice(0, index);
}
if (int.TryParse(tmp, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
return true;
}
}
return false;
}
}
}