CoreResolutionIgnoreRule.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.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. /// <summary>
  18. /// Any folder named in this list will be ignored
  19. /// </summary>
  20. private static readonly string[] _ignoreFolders =
  21. {
  22. "metadata",
  23. "ps3_update",
  24. "ps3_vprm",
  25. "extrafanart",
  26. "extrathumbs",
  27. ".actors",
  28. ".wd_tv",
  29. // Synology
  30. "@eaDir",
  31. "eaDir",
  32. "#recycle",
  33. // Qnap
  34. "@Recycle",
  35. ".@__thumb",
  36. "$RECYCLE.BIN",
  37. "System Volume Information",
  38. ".grab",
  39. };
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="CoreResolutionIgnoreRule"/> class.
  42. /// </summary>
  43. /// <param name="libraryManager">The library manager.</param>
  44. public CoreResolutionIgnoreRule(ILibraryManager libraryManager)
  45. {
  46. _libraryManager = libraryManager;
  47. }
  48. /// <inheritdoc />
  49. public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent)
  50. {
  51. // Don't ignore top level folders
  52. if (fileInfo.IsDirectory && parent is AggregateFolder)
  53. {
  54. return false;
  55. }
  56. var filename = fileInfo.Name;
  57. // Ignore hidden files on UNIX
  58. if (Environment.OSVersion.Platform != PlatformID.Win32NT
  59. && filename[0] == '.')
  60. {
  61. return true;
  62. }
  63. if (fileInfo.IsDirectory)
  64. {
  65. // Ignore any folders in our list
  66. if (_ignoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase))
  67. {
  68. return true;
  69. }
  70. if (parent != null)
  71. {
  72. // Ignore trailer folders but allow it at the collection level
  73. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase)
  74. && !(parent is AggregateFolder)
  75. && !(parent is UserRootFolder))
  76. {
  77. return true;
  78. }
  79. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  80. {
  81. return true;
  82. }
  83. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  84. {
  85. return true;
  86. }
  87. }
  88. }
  89. else
  90. {
  91. if (parent != null)
  92. {
  93. // Don't resolve these into audio files
  94. if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename)
  95. && _libraryManager.IsAudioFile(filename))
  96. {
  97. return true;
  98. }
  99. }
  100. // Ignore samples
  101. Match m = Regex.Match(filename, @"\bsample\b", RegexOptions.IgnoreCase);
  102. return m.Success;
  103. }
  104. return false;
  105. }
  106. }
  107. }