AudioBookResolver.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #nullable enable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using Emby.Naming.Common;
  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? Resolve(string path)
  17. {
  18. if (path.Length == 0 || Path.GetFileNameWithoutExtension(path).Length == 0)
  19. {
  20. // Return null to indicate this path will not be used, instead of stopping whole process with exception
  21. return null;
  22. }
  23. var extension = Path.GetExtension(path);
  24. // Check supported extensions
  25. if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
  26. {
  27. return null;
  28. }
  29. var container = extension.TrimStart('.');
  30. var parsingResult = new AudioBookFilePathParser(_options).Parse(path);
  31. return new AudioBookFileInfo(
  32. path,
  33. container,
  34. chapterNumber: parsingResult.ChapterNumber,
  35. partNumber: parsingResult.PartNumber);
  36. }
  37. }
  38. }