CoreResolutionIgnoreRule.cs 5.0 KB

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