CoreResolutionIgnoreRule.cs 5.0 KB

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