CoreResolutionIgnoreRule.cs 4.2 KB

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