AlbumParser.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7. using Emby.Naming.Common;
  8. namespace Emby.Naming.Audio
  9. {
  10. public class AlbumParser
  11. {
  12. private readonly NamingOptions _options;
  13. public AlbumParser(NamingOptions options)
  14. {
  15. _options = options;
  16. }
  17. public bool IsMultiPart(string path)
  18. {
  19. var filename = Path.GetFileName(path);
  20. if (string.IsNullOrEmpty(filename))
  21. {
  22. return false;
  23. }
  24. // TODO: Move this logic into options object
  25. // Even better, remove the prefixes and come up with regexes
  26. // But Kodi documentation seems to be weak for audio
  27. // Normalize
  28. // Remove whitespace
  29. filename = filename.Replace('-', ' ');
  30. filename = filename.Replace('.', ' ');
  31. filename = filename.Replace('(', ' ');
  32. filename = filename.Replace(')', ' ');
  33. filename = Regex.Replace(filename, @"\s+", " ");
  34. filename = filename.TrimStart();
  35. foreach (var prefix in _options.AlbumStackingPrefixes)
  36. {
  37. if (filename.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) != 0)
  38. {
  39. continue;
  40. }
  41. var tmp = filename.Substring(prefix.Length);
  42. tmp = tmp.Trim().Split(' ').FirstOrDefault() ?? string.Empty;
  43. if (int.TryParse(tmp, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
  44. {
  45. return true;
  46. }
  47. }
  48. return false;
  49. }
  50. }
  51. }