CoreResolutionIgnoreRule.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. public CoreResolutionIgnoreRule(ILibraryManager libraryManager)
  41. {
  42. _libraryManager = libraryManager;
  43. }
  44. /// <inheritdoc />
  45. public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent)
  46. {
  47. // Don't ignore top level folders
  48. if (fileInfo.IsDirectory && parent is AggregateFolder)
  49. {
  50. return false;
  51. }
  52. var filename = fileInfo.Name;
  53. // Ignore hidden files on UNIX
  54. if (Environment.OSVersion.Platform != PlatformID.Win32NT
  55. && filename[0] == '.')
  56. {
  57. return true;
  58. }
  59. if (fileInfo.IsDirectory)
  60. {
  61. // Ignore any folders in our list
  62. if (_ignoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase))
  63. {
  64. return true;
  65. }
  66. if (parent != null)
  67. {
  68. // Ignore trailer folders but allow it at the collection level
  69. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase)
  70. && !(parent is AggregateFolder)
  71. && !(parent is UserRootFolder))
  72. {
  73. return true;
  74. }
  75. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  76. {
  77. return true;
  78. }
  79. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  80. {
  81. return true;
  82. }
  83. }
  84. }
  85. else
  86. {
  87. if (parent != null)
  88. {
  89. // Don't resolve these into audio files
  90. if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename)
  91. && _libraryManager.IsAudioFile(filename))
  92. {
  93. return true;
  94. }
  95. }
  96. // Ignore samples
  97. Match m = Regex.Match(filename, @"\bsample\b", RegexOptions.IgnoreCase);
  98. return m.Success;
  99. }
  100. return false;
  101. }
  102. }
  103. }