SeriesResolver.cs 4.0 KB

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