EntityResolutionHelper.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using MediaBrowser.Controller.IO;
  8. using MediaBrowser.Controller.Library;
  9. using MediaBrowser.Controller.Entities.TV;
  10. namespace MediaBrowser.Controller.Resolvers
  11. {
  12. public static class EntityResolutionHelper
  13. {
  14. /// <summary>
  15. /// Any folder named in this list will be ignored - can be added to at runtime for extensibility
  16. /// </summary>
  17. public static List<string> IgnoreFolders = new List<string>()
  18. {
  19. "trailers",
  20. "bdmv",
  21. "certificate",
  22. "backup",
  23. "video_ts",
  24. "audio_ts",
  25. "ps3_update",
  26. "ps3_vprm"
  27. };
  28. /// <summary>
  29. /// Determines whether a path should be resolved or ignored entirely - called before we even look at the contents
  30. /// </summary>
  31. /// <param name="path"></param>
  32. /// <returns>false if the path should be ignored</returns>
  33. public static bool ShouldResolvePath(WIN32_FIND_DATA path)
  34. {
  35. bool resolve = true;
  36. // Ignore hidden files and folders
  37. if (path.IsHidden || path.IsSystemFile)
  38. {
  39. resolve = false;
  40. }
  41. // Ignore any folders in our list
  42. else if (path.IsDirectory && IgnoreFolders.Contains(Path.GetFileName(path.Path), StringComparer.OrdinalIgnoreCase))
  43. {
  44. resolve = false;
  45. }
  46. return resolve;
  47. }
  48. /// <summary>
  49. /// Determines whether a path should be ignored based on its contents - called after the contents have been read
  50. /// </summary>
  51. public static bool ShouldResolvePathContents(ItemResolveEventArgs args)
  52. {
  53. bool resolve = true;
  54. if (args.ContainsFile(".ignore"))
  55. {
  56. // Ignore any folders containing a file called .ignore
  57. resolve = false;
  58. }
  59. else if (args.FileInfo.cFileName.Equals("metadata", StringComparison.OrdinalIgnoreCase))
  60. {
  61. // Ignore metadata folders
  62. resolve = false;
  63. }
  64. return resolve;
  65. }
  66. }
  67. }