AudioBookResolver.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using Emby.Naming.Common;
  5. using Emby.Naming.TV;
  6. using Emby.Naming.Video;
  7. namespace Emby.Naming.AudioBook
  8. {
  9. public class AudioBookResolver
  10. {
  11. private readonly NamingOptions _options;
  12. public AudioBookResolver(NamingOptions options)
  13. {
  14. _options = options;
  15. }
  16. public AudioBookFileInfo ParseFile(string path)
  17. {
  18. return Resolve(path, false);
  19. }
  20. public AudioBookFileInfo ParseDirectory(string path)
  21. {
  22. return Resolve(path, true);
  23. }
  24. public AudioBookFileInfo Resolve(string path, bool IsDirectory = false)
  25. {
  26. if (string.IsNullOrEmpty(path))
  27. {
  28. throw new ArgumentNullException("path");
  29. }
  30. if (IsDirectory)
  31. return null;
  32. var extension = Path.GetExtension(path) ?? string.Empty;
  33. // Check supported extensions
  34. if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
  35. {
  36. return null;
  37. }
  38. var container = extension.TrimStart('.');
  39. var parsingResult = new AudioBookFilePathParser(_options)
  40. .Parse(path, IsDirectory);
  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. }