2
0

BoxSetResolver.cs 2.4 KB

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