CoreResolutionIgnoreRule.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. // Ignore hidden files and folders
  36. if (args.IsHidden)
  37. {
  38. var parentFolderName = Path.GetFileName(Path.GetDirectoryName(args.Path));
  39. if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  40. {
  41. return false;
  42. }
  43. if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  44. {
  45. return false;
  46. }
  47. // Drives will sometimes be hidden
  48. if (args.Path.EndsWith(Path.VolumeSeparatorChar + "\\", StringComparison.OrdinalIgnoreCase))
  49. {
  50. return false;
  51. }
  52. // Shares will sometimes be hidden
  53. if (args.Path.StartsWith("\\", StringComparison.OrdinalIgnoreCase))
  54. {
  55. // Look for a share, e.g. \\server\movies
  56. // Is there a better way to detect if a path is a share without using native code?
  57. if (args.Path.Substring(2).Split(Path.DirectorySeparatorChar).Length == 2)
  58. {
  59. return false;
  60. }
  61. }
  62. return true;
  63. }
  64. if (args.IsDirectory)
  65. {
  66. var filename = args.FileInfo.Name;
  67. // Ignore any folders in our list
  68. if (IgnoreFolders.ContainsKey(filename))
  69. {
  70. return true;
  71. }
  72. // Ignore trailer folders but allow it at the collection level
  73. if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) &&
  74. !(args.Parent is AggregateFolder) && !(args.Parent is UserRootFolder))
  75. {
  76. return true;
  77. }
  78. if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
  79. {
  80. return true;
  81. }
  82. if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
  83. {
  84. return true;
  85. }
  86. }
  87. else
  88. {
  89. if (args.Parent != null)
  90. {
  91. var filename = args.FileInfo.Name;
  92. if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && EntityResolutionHelper.IsAudioFile(filename))
  93. {
  94. return true;
  95. }
  96. }
  97. }
  98. return false;
  99. }
  100. }
  101. }