SeriesResolver.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. var isTvShowsFolder = string.Equals(collectionType, CollectionType.TvShows,
  57. StringComparison.OrdinalIgnoreCase);
  58. // If there's a collection type and it's not tv, it can't be a series
  59. if (!string.IsNullOrEmpty(collectionType) &&
  60. !isTvShowsFolder &&
  61. !string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
  62. {
  63. return null;
  64. }
  65. if (TVUtils.IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger))
  66. {
  67. return new Series();
  68. }
  69. }
  70. return null;
  71. }
  72. /// <summary>
  73. /// Sets the initial item values.
  74. /// </summary>
  75. /// <param name="item">The item.</param>
  76. /// <param name="args">The args.</param>
  77. protected override void SetInitialItemValues(Series item, ItemResolveArgs args)
  78. {
  79. base.SetInitialItemValues(item, args);
  80. SetProviderIdFromPath(item, args.Path);
  81. }
  82. /// <summary>
  83. /// Sets the provider id from path.
  84. /// </summary>
  85. /// <param name="item">The item.</param>
  86. /// <param name="path">The path.</param>
  87. private void SetProviderIdFromPath(Series item, string path)
  88. {
  89. var justName = Path.GetFileName(path);
  90. var id = justName.GetAttributeValue("tvdbid");
  91. if (!string.IsNullOrEmpty(id))
  92. {
  93. item.SetProviderId(MetadataProviders.Tvdb, id);
  94. }
  95. }
  96. }
  97. }