CoreResolutionIgnoreRule.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.IO;
  3. using Emby.Naming.Audio;
  4. using Emby.Naming.Common;
  5. using MediaBrowser.Controller;
  6. using MediaBrowser.Controller.Entities;
  7. using MediaBrowser.Controller.Resolvers;
  8. using MediaBrowser.Model.IO;
  9. namespace Emby.Server.Implementations.Library
  10. {
  11. /// <summary>
  12. /// Provides the core resolver ignore rules.
  13. /// </summary>
  14. public class CoreResolutionIgnoreRule : IResolverIgnoreRule
  15. {
  16. private readonly NamingOptions _namingOptions;
  17. private readonly IServerApplicationPaths _serverApplicationPaths;
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="CoreResolutionIgnoreRule"/> class.
  20. /// </summary>
  21. /// <param name="namingOptions">The naming options.</param>
  22. /// <param name="serverApplicationPaths">The server application paths.</param>
  23. public CoreResolutionIgnoreRule(NamingOptions namingOptions, IServerApplicationPaths serverApplicationPaths)
  24. {
  25. _namingOptions = namingOptions;
  26. _serverApplicationPaths = serverApplicationPaths;
  27. }
  28. /// <inheritdoc />
  29. public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem? parent)
  30. {
  31. // Don't ignore application folders
  32. if (fileInfo.FullName.Contains(_serverApplicationPaths.RootFolderPath, StringComparison.InvariantCulture))
  33. {
  34. return false;
  35. }
  36. // Don't ignore top level folders
  37. if (fileInfo.IsDirectory
  38. && (parent is AggregateFolder || (parent?.IsTopParent ?? false)))
  39. {
  40. return false;
  41. }
  42. if (IgnorePatterns.ShouldIgnore(fileInfo.FullName))
  43. {
  44. return true;
  45. }
  46. if (parent is null)
  47. {
  48. return false;
  49. }
  50. if (fileInfo.IsDirectory)
  51. {
  52. // Ignore extras for unsupported types
  53. return _namingOptions.AllExtrasTypesFolderNames.ContainsKey(fileInfo.Name)
  54. && parent is not UserRootFolder;
  55. }
  56. // Don't resolve theme songs
  57. return Path.GetFileNameWithoutExtension(fileInfo.Name.AsSpan()).Equals(BaseItem.ThemeSongFileName, StringComparison.Ordinal)
  58. && AudioFileParser.IsAudioFile(fileInfo.Name, _namingOptions);
  59. }
  60. }
  61. }