SeriesResolver.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using MediaBrowser.Controller.Entities.TV;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Controller.Resolvers;
  4. using MediaBrowser.Model.Entities;
  5. using System;
  6. using System.IO;
  7. namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
  8. {
  9. /// <summary>
  10. /// Class SeriesResolver
  11. /// </summary>
  12. public class SeriesResolver : FolderResolver<Series>
  13. {
  14. /// <summary>
  15. /// Gets the priority.
  16. /// </summary>
  17. /// <value>The priority.</value>
  18. public override ResolverPriority Priority
  19. {
  20. get
  21. {
  22. return ResolverPriority.Second;
  23. }
  24. }
  25. /// <summary>
  26. /// Resolves the specified args.
  27. /// </summary>
  28. /// <param name="args">The args.</param>
  29. /// <returns>Series.</returns>
  30. protected override Series Resolve(ItemResolveArgs args)
  31. {
  32. if (args.IsDirectory)
  33. {
  34. var collectionType = args.GetCollectionType();
  35. // If there's a collection type and it's not tv, it can't be a series
  36. if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
  37. {
  38. if (args.HasParent<Series>())
  39. {
  40. return null;
  41. }
  42. return new Series
  43. {
  44. Path = args.Path,
  45. Name = Path.GetFileName(args.Path)
  46. };
  47. }
  48. }
  49. return null;
  50. }
  51. /// <summary>
  52. /// Sets the initial item values.
  53. /// </summary>
  54. /// <param name="item">The item.</param>
  55. /// <param name="args">The args.</param>
  56. protected override void SetInitialItemValues(Series item, ItemResolveArgs args)
  57. {
  58. base.SetInitialItemValues(item, args);
  59. SetProviderIdFromPath(item, args.Path);
  60. }
  61. /// <summary>
  62. /// Sets the provider id from path.
  63. /// </summary>
  64. /// <param name="item">The item.</param>
  65. /// <param name="path">The path.</param>
  66. private void SetProviderIdFromPath(Series item, string path)
  67. {
  68. var justName = Path.GetFileName(path);
  69. var id = justName.GetAttributeValue("tvdbid");
  70. if (!string.IsNullOrEmpty(id))
  71. {
  72. item.SetProviderId(MetadataProviders.Tvdb, id);
  73. }
  74. }
  75. }
  76. }