BoxSetResolver.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #nullable disable
  2. using System;
  3. using System.IO;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.Entities.Movies;
  6. using MediaBrowser.Controller.Library;
  7. using MediaBrowser.Model.Entities;
  8. namespace Emby.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
  35. {
  36. Path = args.Path,
  37. Name = Path.GetFileName(args.Path).Replace("[boxset]", string.Empty, StringComparison.OrdinalIgnoreCase).Trim()
  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 static 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(MetadataProvider.Tmdb, id);
  65. }
  66. }
  67. }
  68. }