Series.cs 7.6 KB

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