BoxSetResolver.cs 2.7 KB

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