CoreResolutionIgnoreRule.cs 2.6 KB

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