CoreResolutionIgnoreRule.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using MediaBrowser.Model.Extensions;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Controller.Resolvers;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using MediaBrowser.Controller.IO;
  10. using MediaBrowser.Model.IO;
  11. using MediaBrowser.Model.Logging;
  12. namespace Emby.Server.Implementations.Library
  13. {
  14. /// <summary>
  15. /// Provides the core resolver ignore rules
  16. /// </summary>
  17. public class CoreResolutionIgnoreRule : IResolverIgnoreRule
  18. {
  19. private readonly IFileSystem _fileSystem;
  20. private readonly ILibraryManager _libraryManager;
  21. private readonly ILogger _logger;
  22. /// <summary>
  23. /// Any folder named in this list will be ignored - can be added to at runtime for extensibility
  24. /// </summary>
  25. public static readonly List<string> IgnoreFolders = new List<string>
  26. {
  27. "metadata",
  28. "ps3_update",
  29. "ps3_vprm",
  30. "extrafanart",
  31. "extrathumbs",
  32. ".actors",
  33. ".wd_tv",
  34. // Synology
  35. "@eaDir",
  36. "eaDir",
  37. "#recycle",
  38. // Qnap
  39. "@Recycle"
  40. };
  41. public CoreResolutionIgnoreRule(IFileSystem fileSystem, ILibraryManager libraryManager, ILogger logger)
  42. {
  43. _fileSystem = fileSystem;
  44. _libraryManager = libraryManager;
  45. _logger = logger;
  46. }
  47. /// <summary>
  48. /// Shoulds the ignore.
  49. /// </summary>
  50. /// <param name="fileInfo">The file information.</param>
  51. /// <param name="parent">The parent.</param>
  52. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  53. public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent)
  54. {
  55. // Don't ignore top level folders
  56. if (fileInfo.IsDirectory && parent is AggregateFolder)
  57. {
  58. return false;
  59. }
  60. var filename = fileInfo.Name;
  61. var isHidden = fileInfo.IsHidden;
  62. var path = fileInfo.FullName;
  63. // Handle mac .DS_Store
  64. // https://github.com/MediaBrowser/MediaBrowser/issues/427
  65. if (filename.IndexOf("._", StringComparison.OrdinalIgnoreCase) == 0)
  66. {
  67. return true;
  68. }
  69. // Ignore hidden files and folders
  70. if (isHidden)
  71. {
  72. if (parent == null)
  73. {
  74. var parentFolderName = Path.GetFileName(_fileSystem.GetDirectoryName(path));
  75. if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  76. {
  77. return false;
  78. }
  79. if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  80. {
  81. return false;
  82. }
  83. }
  84. // Sometimes these are marked hidden
  85. if (_fileSystem.IsRootPath(path))
  86. {
  87. return false;
  88. }
  89. return true;
  90. }
  91. if (fileInfo.IsDirectory)
  92. {
  93. // Ignore any folders in our list
  94. if (IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase))
  95. {
  96. return true;
  97. }
  98. if (parent != null)
  99. {
  100. // Ignore trailer folders but allow it at the collection level
  101. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) &&
  102. !(parent is AggregateFolder) && !(parent is UserRootFolder))
  103. {
  104. return true;
  105. }
  106. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  107. {
  108. return true;
  109. }
  110. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  111. {
  112. return true;
  113. }
  114. }
  115. }
  116. else
  117. {
  118. if (parent != null)
  119. {
  120. // Don't resolve these into audio files
  121. if (string.Equals(_fileSystem.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename))
  122. {
  123. return true;
  124. }
  125. }
  126. // Ignore samples
  127. var sampleFilename = " " + filename.Replace(".", " ", StringComparison.OrdinalIgnoreCase)
  128. .Replace("-", " ", StringComparison.OrdinalIgnoreCase)
  129. .Replace("_", " ", StringComparison.OrdinalIgnoreCase)
  130. .Replace("!", " ", StringComparison.OrdinalIgnoreCase);
  131. if (sampleFilename.IndexOf(" sample ", StringComparison.OrdinalIgnoreCase) != -1)
  132. {
  133. return true;
  134. }
  135. }
  136. return false;
  137. }
  138. }
  139. }