BoxSetResolver.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Entities.Movies;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Model.Entities;
  6. using System;
  7. using System.IO;
  8. namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
  9. {
  10. /// <summary>
  11. /// Class BoxSetResolver
  12. /// </summary>
  13. public class BoxSetResolver : FolderResolver<BoxSet>
  14. {
  15. /// <summary>
  16. /// Resolves the specified args.
  17. /// </summary>
  18. /// <param name="args">The args.</param>
  19. /// <returns>BoxSet.</returns>
  20. protected override BoxSet Resolve(ItemResolveArgs args)
  21. {
  22. // It's a boxset if all of the following conditions are met:
  23. // Is a Directory
  24. // Contains [boxset] in the path
  25. if (args.IsDirectory)
  26. {
  27. var filename = Path.GetFileName(args.Path);
  28. if (string.IsNullOrEmpty(filename))
  29. {
  30. return null;
  31. }
  32. // This is a bit of a one-off but it's here to combat MCM's over-aggressive placement of collection.xml files where they don't belong, including in series folders.
  33. if (args.ContainsMetaFileByName("series.xml"))
  34. {
  35. return null;
  36. }
  37. if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 || args.ContainsFileSystemEntryByName("collection.xml"))
  38. {
  39. return new BoxSet { Path = args.Path };
  40. }
  41. }
  42. return null;
  43. }
  44. /// <summary>
  45. /// Sets the initial item values.
  46. /// </summary>
  47. /// <param name="item">The item.</param>
  48. /// <param name="args">The args.</param>
  49. protected override void SetInitialItemValues(BoxSet item, ItemResolveArgs args)
  50. {
  51. base.SetInitialItemValues(item, args);
  52. SetProviderIdFromPath(item);
  53. }
  54. /// <summary>
  55. /// Sets the provider id from path.
  56. /// </summary>
  57. /// <param name="item">The item.</param>
  58. private void SetProviderIdFromPath(BaseItem item)
  59. {
  60. //we need to only look at the name of this actual item (not parents)
  61. var justName = Path.GetFileName(item.Path);
  62. var id = justName.GetAttributeValue("tmdbid");
  63. if (!string.IsNullOrEmpty(id))
  64. {
  65. item.SetProviderId(MetadataProviders.Tmdb, id);
  66. }
  67. }
  68. }
  69. }