AudioBookResolver.cs 1.6 KB

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