CoreResolutionIgnoreRule.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Controller;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Controller.Resolvers;
  7. using MediaBrowser.Model.IO;
  8. namespace Emby.Server.Implementations.Library
  9. {
  10. /// <summary>
  11. /// Provides the core resolver ignore rules.
  12. /// </summary>
  13. public class CoreResolutionIgnoreRule : IResolverIgnoreRule
  14. {
  15. private readonly ILibraryManager _libraryManager;
  16. private readonly IServerApplicationPaths _serverApplicationPaths;
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="CoreResolutionIgnoreRule"/> class.
  19. /// </summary>
  20. /// <param name="libraryManager">The library manager.</param>
  21. /// <param name="serverApplicationPaths">The server application paths.</param>
  22. public CoreResolutionIgnoreRule(ILibraryManager libraryManager, IServerApplicationPaths serverApplicationPaths)
  23. {
  24. _libraryManager = libraryManager;
  25. _serverApplicationPaths = serverApplicationPaths;
  26. }
  27. /// <inheritdoc />
  28. public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent)
  29. {
  30. // Don't ignore application folders
  31. if (fileInfo.FullName.Contains(_serverApplicationPaths.RootFolderPath, StringComparison.InvariantCulture))
  32. {
  33. return false;
  34. }
  35. // Don't ignore top level folders
  36. if (fileInfo.IsDirectory && parent is AggregateFolder)
  37. {
  38. return false;
  39. }
  40. if (IgnorePatterns.ShouldIgnore(fileInfo.FullName))
  41. {
  42. return true;
  43. }
  44. var filename = fileInfo.Name;
  45. if (fileInfo.IsDirectory)
  46. {
  47. if (parent != null)
  48. {
  49. // Ignore trailer folders but allow it at the collection level
  50. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase)
  51. && !(parent is AggregateFolder)
  52. && !(parent is UserRootFolder))
  53. {
  54. return true;
  55. }
  56. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  57. {
  58. return true;
  59. }
  60. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  61. {
  62. return true;
  63. }
  64. }
  65. }
  66. else
  67. {
  68. if (parent != null)
  69. {
  70. // Don't resolve these into audio files
  71. if (Path.GetFileNameWithoutExtension(filename.AsSpan()).Equals(BaseItem.ThemeSongFilename, StringComparison.Ordinal)
  72. && _libraryManager.IsAudioFile(filename))
  73. {
  74. return true;
  75. }
  76. }
  77. }
  78. return false;
  79. }
  80. }
  81. }