CoreResolutionIgnoreRule.cs 3.6 KB

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