EntityResolutionHelper.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "adv_obj",
  28. "hvdvd_ts"
  29. };
  30. /// <summary>
  31. /// Determines whether a path should be resolved or ignored entirely - called before we even look at the contents
  32. /// </summary>
  33. /// <param name="path"></param>
  34. /// <returns>false if the path should be ignored</returns>
  35. public static bool ShouldResolvePath(WIN32_FIND_DATA path)
  36. {
  37. bool resolve = true;
  38. // Ignore hidden files and folders
  39. if (path.IsHidden || path.IsSystemFile)
  40. {
  41. resolve = false;
  42. }
  43. // Ignore any folders in our list
  44. else if (path.IsDirectory && IgnoreFolders.Contains(Path.GetFileName(path.Path), StringComparer.OrdinalIgnoreCase))
  45. {
  46. resolve = false;
  47. }
  48. return resolve;
  49. }
  50. /// <summary>
  51. /// Determines whether a path should be ignored based on its contents - called after the contents have been read
  52. /// </summary>
  53. public static bool ShouldResolvePathContents(ItemResolveEventArgs args)
  54. {
  55. bool resolve = true;
  56. if (args.ContainsFile(".ignore"))
  57. {
  58. // Ignore any folders containing a file called .ignore
  59. resolve = false;
  60. }
  61. else if (args.IsMetadataFolder)
  62. {
  63. // Don't retrieve these children here - we'll get them in the season resolver
  64. resolve = false;
  65. }
  66. return resolve;
  67. }
  68. }
  69. }