CoreResolutionIgnoreRule.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Controller.Resolvers;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. namespace MediaBrowser.Server.Implementations.Library
  9. {
  10. /// <summary>
  11. /// Provides the core resolver ignore rules
  12. /// </summary>
  13. public class CoreResolutionIgnoreRule : IResolverIgnoreRule
  14. {
  15. /// <summary>
  16. /// Any folder named in this list will be ignored - can be added to at runtime for extensibility
  17. /// </summary>
  18. private static readonly Dictionary<string,string> IgnoreFolders = new List<string>
  19. {
  20. "metadata",
  21. "certificate",
  22. "backup",
  23. "ps3_update",
  24. "ps3_vprm",
  25. "adv_obj",
  26. "extrafanart",
  27. "extrathumbs",
  28. ".actors"
  29. }.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
  30. /// <summary>
  31. /// Shoulds the ignore.
  32. /// </summary>
  33. /// <param name="args">The args.</param>
  34. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  35. public bool ShouldIgnore(ItemResolveArgs args)
  36. {
  37. var filename = args.FileInfo.Name;
  38. // Handle mac .DS_Store
  39. // https://github.com/MediaBrowser/MediaBrowser/issues/427
  40. if (filename.IndexOf("._", StringComparison.OrdinalIgnoreCase) == 0)
  41. {
  42. return true;
  43. }
  44. // Ignore hidden files and folders
  45. if (args.IsHidden)
  46. {
  47. var parentFolderName = Path.GetFileName(Path.GetDirectoryName(args.Path));
  48. if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  49. {
  50. return false;
  51. }
  52. if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  53. {
  54. return false;
  55. }
  56. // Drives will sometimes be hidden
  57. if (args.Path.EndsWith(Path.VolumeSeparatorChar + "\\", StringComparison.OrdinalIgnoreCase))
  58. {
  59. return false;
  60. }
  61. // Shares will sometimes be hidden
  62. if (args.Path.StartsWith("\\", StringComparison.OrdinalIgnoreCase))
  63. {
  64. // Look for a share, e.g. \\server\movies
  65. // Is there a better way to detect if a path is a share without using native code?
  66. if (args.Path.Substring(2).Split(Path.DirectorySeparatorChar).Length == 2)
  67. {
  68. return false;
  69. }
  70. }
  71. return true;
  72. }
  73. if (args.IsDirectory)
  74. {
  75. // Ignore any folders in our list
  76. if (IgnoreFolders.ContainsKey(filename))
  77. {
  78. return true;
  79. }
  80. // Ignore trailer folders but allow it at the collection level
  81. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) &&
  82. !(args.Parent is AggregateFolder) && !(args.Parent is UserRootFolder))
  83. {
  84. return true;
  85. }
  86. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  87. {
  88. return true;
  89. }
  90. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  91. {
  92. return true;
  93. }
  94. }
  95. else
  96. {
  97. if (args.Parent != null)
  98. {
  99. // Don't resolve these into audio files
  100. if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && EntityResolutionHelper.IsAudioFile(filename))
  101. {
  102. return true;
  103. }
  104. }
  105. }
  106. return false;
  107. }
  108. }
  109. }