AudioBookResolver.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using Emby.Naming.Common;
  6. namespace Emby.Naming.AudioBook
  7. {
  8. public class AudioBookResolver
  9. {
  10. private readonly NamingOptions _options;
  11. public AudioBookResolver(NamingOptions options)
  12. {
  13. _options = options;
  14. }
  15. public AudioBookFileInfo ParseFile(string path)
  16. {
  17. return Resolve(path, false);
  18. }
  19. public AudioBookFileInfo ParseDirectory(string path)
  20. {
  21. return Resolve(path, true);
  22. }
  23. public AudioBookFileInfo Resolve(string path, bool isDirectory = false)
  24. {
  25. if (string.IsNullOrEmpty(path))
  26. {
  27. throw new ArgumentNullException(nameof(path));
  28. }
  29. // TODO
  30. if (isDirectory)
  31. {
  32. return null;
  33. }
  34. var extension = Path.GetExtension(path);
  35. // Check supported extensions
  36. if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
  37. {
  38. return null;
  39. }
  40. var container = extension.TrimStart('.');
  41. var parsingResult = new AudioBookFilePathParser(_options).Parse(path);
  42. return new AudioBookFileInfo
  43. {
  44. Path = path,
  45. Container = container,
  46. PartNumber = parsingResult.PartNumber,
  47. ChapterNumber = parsingResult.ChapterNumber,
  48. IsDirectory = isDirectory
  49. };
  50. }
  51. }
  52. }