2
0

BoxSetResolver.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. using System.Linq;
  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 ||
  33. args.ContainsFileSystemEntryByName("collection.xml"))
  34. {
  35. return new BoxSet
  36. {
  37. Path = args.Path,
  38. Name = ResolverHelper.StripBrackets(Path.GetFileName(args.Path))
  39. };
  40. }
  41. }
  42. return null;
  43. }
  44. private bool IsInvalid(string collectionType)
  45. {
  46. var validCollectionTypes = new[]
  47. {
  48. CollectionType.Movies,
  49. CollectionType.BoxSets
  50. };
  51. return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
  52. }
  53. /// <summary>
  54. /// Sets the initial item values.
  55. /// </summary>
  56. /// <param name="item">The item.</param>
  57. /// <param name="args">The args.</param>
  58. protected override void SetInitialItemValues(BoxSet item, ItemResolveArgs args)
  59. {
  60. base.SetInitialItemValues(item, args);
  61. SetProviderIdFromPath(item);
  62. }
  63. /// <summary>
  64. /// Sets the provider id from path.
  65. /// </summary>
  66. /// <param name="item">The item.</param>
  67. private void SetProviderIdFromPath(BaseItem item)
  68. {
  69. //we need to only look at the name of this actual item (not parents)
  70. var justName = Path.GetFileName(item.Path);
  71. var id = justName.GetAttributeValue("tmdbid");
  72. if (!string.IsNullOrEmpty(id))
  73. {
  74. item.SetProviderId(MetadataProviders.Tmdb, id);
  75. }
  76. }
  77. }
  78. }