AlbumParser.cs 1.8 KB

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