2
0

CoreResolutionIgnoreRule.cs 5.4 KB

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