BoxSetResolver.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. if (filename.IndexOf("[boxset]", StringComparison.OrdinalIgnoreCase) != -1 || args.ContainsFileSystemEntryByName("collection.xml"))
  33. {
  34. return new BoxSet { Path = args.Path };
  35. }
  36. }
  37. return null;
  38. }
  39. /// <summary>
  40. /// Sets the initial item values.
  41. /// </summary>
  42. /// <param name="item">The item.</param>
  43. /// <param name="args">The args.</param>
  44. protected override void SetInitialItemValues(BoxSet item, ItemResolveArgs args)
  45. {
  46. base.SetInitialItemValues(item, args);
  47. SetProviderIdFromPath(item);
  48. }
  49. /// <summary>
  50. /// Sets the provider id from path.
  51. /// </summary>
  52. /// <param name="item">The item.</param>
  53. private void SetProviderIdFromPath(BaseItem item)
  54. {
  55. //we need to only look at the name of this actual item (not parents)
  56. var justName = Path.GetFileName(item.Path);
  57. var id = justName.GetAttributeValue("tmdbid");
  58. if (!string.IsNullOrEmpty(id))
  59. {
  60. item.SetProviderId(MetadataProviders.Tmdb, id);
  61. }
  62. }
  63. }
  64. }