CoreResolutionIgnoreRule.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 && parent is AggregateFolder)
  38. {
  39. return false;
  40. }
  41. if (IgnorePatterns.ShouldIgnore(fileInfo.FullName))
  42. {
  43. return true;
  44. }
  45. var filename = fileInfo.Name;
  46. if (fileInfo.IsDirectory)
  47. {
  48. if (parent is not null)
  49. {
  50. // Ignore extras folders but allow it at the collection level
  51. if (_namingOptions.AllExtrasTypesFolderNames.ContainsKey(filename)
  52. && parent is not AggregateFolder
  53. && parent is not UserRootFolder)
  54. {
  55. return true;
  56. }
  57. }
  58. }
  59. else
  60. {
  61. if (parent is not null)
  62. {
  63. // Don't resolve these into audio files
  64. if (Path.GetFileNameWithoutExtension(filename.AsSpan()).Equals(BaseItem.ThemeSongFileName, StringComparison.Ordinal)
  65. && AudioFileParser.IsAudioFile(filename, _namingOptions))
  66. {
  67. return true;
  68. }
  69. }
  70. }
  71. return false;
  72. }
  73. }
  74. }