CoreResolutionIgnoreRule.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. }.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
  29. /// <summary>
  30. /// Shoulds the ignore.
  31. /// </summary>
  32. /// <param name="args">The args.</param>
  33. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  34. public bool ShouldIgnore(ItemResolveArgs args)
  35. {
  36. var filename = args.FileInfo.Name;
  37. // Handle mac .DS_Store
  38. // https://github.com/MediaBrowser/MediaBrowser/issues/427
  39. if (filename.IndexOf("._", StringComparison.OrdinalIgnoreCase) == 0)
  40. {
  41. return true;
  42. }
  43. // Ignore hidden files and folders
  44. if (args.IsHidden)
  45. {
  46. var parentFolderName = Path.GetFileName(Path.GetDirectoryName(args.Path));
  47. if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  48. {
  49. return false;
  50. }
  51. if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  52. {
  53. return false;
  54. }
  55. // Drives will sometimes be hidden
  56. if (args.Path.EndsWith(Path.VolumeSeparatorChar + "\\", StringComparison.OrdinalIgnoreCase))
  57. {
  58. return false;
  59. }
  60. // Shares will sometimes be hidden
  61. if (args.Path.StartsWith("\\", StringComparison.OrdinalIgnoreCase))
  62. {
  63. // Look for a share, e.g. \\server\movies
  64. // Is there a better way to detect if a path is a share without using native code?
  65. if (args.Path.Substring(2).Split(Path.DirectorySeparatorChar).Length == 2)
  66. {
  67. return false;
  68. }
  69. }
  70. return true;
  71. }
  72. if (args.IsDirectory)
  73. {
  74. // Ignore any folders in our list
  75. if (IgnoreFolders.ContainsKey(filename))
  76. {
  77. return true;
  78. }
  79. // Ignore trailer folders but allow it at the collection level
  80. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) &&
  81. !(args.Parent is AggregateFolder) && !(args.Parent is UserRootFolder))
  82. {
  83. return true;
  84. }
  85. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  86. {
  87. return true;
  88. }
  89. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  90. {
  91. return true;
  92. }
  93. }
  94. else
  95. {
  96. if (args.Parent != null)
  97. {
  98. // Don't resolve these into audio files
  99. if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && EntityResolutionHelper.IsAudioFile(filename))
  100. {
  101. return true;
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. }
  108. }