CoreResolutionIgnoreRule.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 != null)
  49. {
  50. // Ignore trailer folders but allow it at the collection level
  51. if (string.Equals(filename, BaseItem.TrailersFolderName, StringComparison.OrdinalIgnoreCase)
  52. && !(parent is AggregateFolder)
  53. && !(parent is UserRootFolder))
  54. {
  55. return true;
  56. }
  57. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  58. {
  59. return true;
  60. }
  61. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  62. {
  63. return true;
  64. }
  65. }
  66. }
  67. else
  68. {
  69. if (parent != null)
  70. {
  71. // Don't resolve these into audio files
  72. if (Path.GetFileNameWithoutExtension(filename.AsSpan()).Equals(BaseItem.ThemeSongFileName, StringComparison.Ordinal)
  73. && AudioFileParser.IsAudioFile(filename, _namingOptions))
  74. {
  75. return true;
  76. }
  77. }
  78. }
  79. return false;
  80. }
  81. }
  82. }