SeriesResolver.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Common.IO;
  3. using MediaBrowser.Controller.Entities.Audio;
  4. using MediaBrowser.Controller.Entities.TV;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Controller.Resolvers;
  7. using MediaBrowser.Model.Entities;
  8. using MediaBrowser.Model.Logging;
  9. using System;
  10. using System.IO;
  11. namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
  12. {
  13. /// <summary>
  14. /// Class SeriesResolver
  15. /// </summary>
  16. public class SeriesResolver : FolderResolver<Series>
  17. {
  18. private readonly IFileSystem _fileSystem;
  19. private readonly ILogger _logger;
  20. public SeriesResolver(IFileSystem fileSystem, ILogger logger)
  21. {
  22. _fileSystem = fileSystem;
  23. _logger = logger;
  24. }
  25. /// <summary>
  26. /// Gets the priority.
  27. /// </summary>
  28. /// <value>The priority.</value>
  29. public override ResolverPriority Priority
  30. {
  31. get
  32. {
  33. return ResolverPriority.Second;
  34. }
  35. }
  36. /// <summary>
  37. /// Resolves the specified args.
  38. /// </summary>
  39. /// <param name="args">The args.</param>
  40. /// <returns>Series.</returns>
  41. protected override Series Resolve(ItemResolveArgs args)
  42. {
  43. if (args.IsDirectory)
  44. {
  45. // Avoid expensive tests against VF's and all their children by not allowing this
  46. if (args.Parent == null || args.Parent.IsRoot)
  47. {
  48. return null;
  49. }
  50. // Optimization to avoid running these tests against Seasons
  51. if (args.Parent is Series || args.Parent is Season || args.Parent is MusicArtist || args.Parent is MusicAlbum)
  52. {
  53. return null;
  54. }
  55. var collectionType = args.GetCollectionType();
  56. // If there's a collection type and it's not tv, it can't be a series
  57. if (!string.IsNullOrEmpty(collectionType) &&
  58. !string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) &&
  59. !string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
  60. {
  61. return null;
  62. }
  63. if (TVUtils.IsSeriesFolder(args.Path, string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase), args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger))
  64. {
  65. return new Series();
  66. }
  67. }
  68. return null;
  69. }
  70. /// <summary>
  71. /// Sets the initial item values.
  72. /// </summary>
  73. /// <param name="item">The item.</param>
  74. /// <param name="args">The args.</param>
  75. protected override void SetInitialItemValues(Series item, ItemResolveArgs args)
  76. {
  77. base.SetInitialItemValues(item, args);
  78. SetProviderIdFromPath(item, args.Path);
  79. }
  80. /// <summary>
  81. /// Sets the provider id from path.
  82. /// </summary>
  83. /// <param name="item">The item.</param>
  84. /// <param name="path">The path.</param>
  85. private void SetProviderIdFromPath(Series item, string path)
  86. {
  87. var justName = Path.GetFileName(path);
  88. var id = justName.GetAttributeValue("tvdbid");
  89. if (!string.IsNullOrEmpty(id))
  90. {
  91. item.SetProviderId(MetadataProviders.Tvdb, id);
  92. }
  93. }
  94. }
  95. }