StubResolver.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma warning disable CS1591
  2. #nullable enable
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using Emby.Naming.Common;
  7. namespace Emby.Naming.Video
  8. {
  9. public static class StubResolver
  10. {
  11. public static bool TryResolveFile(string path, NamingOptions options, out string? stubType)
  12. {
  13. stubType = default;
  14. if (path == null)
  15. {
  16. return false;
  17. }
  18. var extension = Path.GetExtension(path);
  19. if (!options.StubFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
  20. {
  21. return false;
  22. }
  23. path = Path.GetFileNameWithoutExtension(path);
  24. var token = Path.GetExtension(path).TrimStart('.');
  25. foreach (var rule in options.StubTypes)
  26. {
  27. if (string.Equals(rule.Token, token, StringComparison.OrdinalIgnoreCase))
  28. {
  29. stubType = rule.StubType;
  30. return true;
  31. }
  32. }
  33. return true;
  34. }
  35. }
  36. }