Series.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using MediaBrowser.Controller.Library;
  2. using MediaBrowser.Controller.Localization;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Model.Querying;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Runtime.Serialization;
  10. namespace MediaBrowser.Controller.Entities.TV
  11. {
  12. /// <summary>
  13. /// Class Series
  14. /// </summary>
  15. public class Series : Folder, IHasSoundtracks, IHasTrailers, IHasTags
  16. {
  17. public List<Guid> SpecialFeatureIds { get; set; }
  18. public List<Guid> SoundtrackIds { get; set; }
  19. public int SeasonCount { get; set; }
  20. public Series()
  21. {
  22. AirDays = new List<DayOfWeek>();
  23. SpecialFeatureIds = new List<Guid>();
  24. SoundtrackIds = new List<Guid>();
  25. RemoteTrailers = new List<MediaUrl>();
  26. LocalTrailerIds = new List<Guid>();
  27. Tags = new List<string>();
  28. DisplaySpecialsWithSeasons = true;
  29. }
  30. public bool DisplaySpecialsWithSeasons { get; set; }
  31. public List<Guid> LocalTrailerIds { get; set; }
  32. public List<MediaUrl> RemoteTrailers { get; set; }
  33. /// <summary>
  34. /// Gets or sets the tags.
  35. /// </summary>
  36. /// <value>The tags.</value>
  37. public List<string> Tags { get; set; }
  38. /// <summary>
  39. /// Gets or sets the status.
  40. /// </summary>
  41. /// <value>The status.</value>
  42. public SeriesStatus? Status { get; set; }
  43. /// <summary>
  44. /// Gets or sets the air days.
  45. /// </summary>
  46. /// <value>The air days.</value>
  47. public List<DayOfWeek> AirDays { get; set; }
  48. /// <summary>
  49. /// Gets or sets the air time.
  50. /// </summary>
  51. /// <value>The air time.</value>
  52. public string AirTime { get; set; }
  53. /// <summary>
  54. /// Gets or sets the date last episode added.
  55. /// </summary>
  56. /// <value>The date last episode added.</value>
  57. public DateTime DateLastEpisodeAdded { get; set; }
  58. /// <summary>
  59. /// Series aren't included directly in indices - Their Episodes will roll up to them
  60. /// </summary>
  61. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  62. [IgnoreDataMember]
  63. public override bool IncludeInIndex
  64. {
  65. get
  66. {
  67. return false;
  68. }
  69. }
  70. /// <summary>
  71. /// Gets the user data key.
  72. /// </summary>
  73. /// <returns>System.String.</returns>
  74. public override string GetUserDataKey()
  75. {
  76. return this.GetProviderId(MetadataProviders.Tvdb) ?? this.GetProviderId(MetadataProviders.Tvcom) ?? base.GetUserDataKey();
  77. }
  78. // Studio, Genre and Rating will all be the same so makes no sense to index by these
  79. protected override Dictionary<string, Func<User, IEnumerable<BaseItem>>> GetIndexByOptions()
  80. {
  81. return new Dictionary<string, Func<User, IEnumerable<BaseItem>>> {
  82. {LocalizedStrings.Instance.GetString("NoneDispPref"), null},
  83. {LocalizedStrings.Instance.GetString("PerformerDispPref"), GetIndexByPerformer},
  84. {LocalizedStrings.Instance.GetString("DirectorDispPref"), GetIndexByDirector},
  85. {LocalizedStrings.Instance.GetString("YearDispPref"), GetIndexByYear},
  86. };
  87. }
  88. /// <summary>
  89. /// Creates ResolveArgs on demand
  90. /// </summary>
  91. /// <param name="pathInfo">The path info.</param>
  92. /// <returns>ItemResolveArgs.</returns>
  93. protected internal override ItemResolveArgs CreateResolveArgs(FileSystemInfo pathInfo = null)
  94. {
  95. var args = base.CreateResolveArgs(pathInfo);
  96. Season.AddMetadataFiles(args);
  97. return args;
  98. }
  99. [IgnoreDataMember]
  100. public bool ContainsEpisodesWithoutSeasonFolders
  101. {
  102. get
  103. {
  104. return Children.OfType<Video>().Any();
  105. }
  106. }
  107. public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren, string indexBy = null)
  108. {
  109. return GetSeasons(user);
  110. }
  111. public IEnumerable<Season> GetSeasons(User user)
  112. {
  113. var seasons = base.GetChildren(user, true)
  114. .OfType<Season>();
  115. var config = user.Configuration;
  116. if (!config.DisplayMissingEpisodes && !config.DisplayUnairedEpisodes)
  117. {
  118. seasons = seasons.Where(i => !i.IsMissingOrVirtualUnaired);
  119. }
  120. else
  121. {
  122. if (!config.DisplayMissingEpisodes)
  123. {
  124. seasons = seasons.Where(i => !i.IsMissingSeason);
  125. }
  126. if (!config.DisplayUnairedEpisodes)
  127. {
  128. seasons = seasons.Where(i => !i.IsVirtualUnaired);
  129. }
  130. }
  131. return LibraryManager
  132. .Sort(seasons, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending)
  133. .Cast<Season>();
  134. }
  135. public IEnumerable<Episode> GetEpisodes(User user, int seasonNumber)
  136. {
  137. var episodes = GetRecursiveChildren(user)
  138. .OfType<Episode>();
  139. episodes = FilterEpisodesBySeason(episodes, seasonNumber, DisplaySpecialsWithSeasons);
  140. var config = user.Configuration;
  141. if (!config.DisplayMissingEpisodes)
  142. {
  143. episodes = episodes.Where(i => !i.IsMissingEpisode);
  144. }
  145. if (!config.DisplayUnairedEpisodes)
  146. {
  147. episodes = episodes.Where(i => !i.IsVirtualUnaired);
  148. }
  149. return LibraryManager.Sort(episodes, user, new[] { ItemSortBy.AiredEpisodeOrder }, SortOrder.Ascending)
  150. .Cast<Episode>();
  151. }
  152. /// <summary>
  153. /// Filters the episodes by season.
  154. /// </summary>
  155. /// <param name="episodes">The episodes.</param>
  156. /// <param name="seasonNumber">The season number.</param>
  157. /// <param name="includeSpecials">if set to <c>true</c> [include specials].</param>
  158. /// <returns>IEnumerable{Episode}.</returns>
  159. public static IEnumerable<Episode> FilterEpisodesBySeason(IEnumerable<Episode> episodes, int seasonNumber, bool includeSpecials)
  160. {
  161. if (!includeSpecials || seasonNumber < 1)
  162. {
  163. return episodes.Where(i => (i.PhysicalSeasonNumber ?? -1) == seasonNumber);
  164. }
  165. return episodes.Where(i =>
  166. {
  167. var episode = i;
  168. if (episode != null)
  169. {
  170. var currentSeasonNumber = episode.AiredSeasonNumber;
  171. return currentSeasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber;
  172. }
  173. return false;
  174. });
  175. }
  176. }
  177. }