BoxSet.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using MediaBrowser.Controller.Entities.TV;
  2. using MediaBrowser.Controller.Providers;
  3. using MediaBrowser.Model.Configuration;
  4. using MediaBrowser.Model.Entities;
  5. using MediaBrowser.Model.Querying;
  6. using MediaBrowser.Model.Users;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Runtime.Serialization;
  11. using MediaBrowser.Controller.Entities.Audio;
  12. namespace MediaBrowser.Controller.Entities.Movies
  13. {
  14. /// <summary>
  15. /// Class BoxSet
  16. /// </summary>
  17. public class BoxSet : Folder, IHasTrailers, IHasKeywords, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>, IHasShares
  18. {
  19. public List<Share> Shares { get; set; }
  20. public BoxSet()
  21. {
  22. RemoteTrailers = new List<MediaUrl>();
  23. LocalTrailerIds = new List<Guid>();
  24. RemoteTrailerIds = new List<Guid>();
  25. DisplayOrder = ItemSortBy.PremiereDate;
  26. Keywords = new List<string>();
  27. Shares = new List<Share>();
  28. }
  29. protected override bool FilterLinkedChildrenPerUser
  30. {
  31. get
  32. {
  33. return true;
  34. }
  35. }
  36. public List<Guid> LocalTrailerIds { get; set; }
  37. public List<Guid> RemoteTrailerIds { get; set; }
  38. /// <summary>
  39. /// Gets or sets the remote trailers.
  40. /// </summary>
  41. /// <value>The remote trailers.</value>
  42. public List<MediaUrl> RemoteTrailers { get; set; }
  43. /// <summary>
  44. /// Gets or sets the tags.
  45. /// </summary>
  46. /// <value>The tags.</value>
  47. public List<string> Keywords { get; set; }
  48. /// <summary>
  49. /// Gets or sets the display order.
  50. /// </summary>
  51. /// <value>The display order.</value>
  52. public string DisplayOrder { get; set; }
  53. protected override bool GetBlockUnratedValue(UserPolicy config)
  54. {
  55. return config.BlockUnratedItems.Contains(UnratedItem.Movie);
  56. }
  57. public override UnratedItem GetBlockUnratedType()
  58. {
  59. return UnratedItem.Movie;
  60. }
  61. [IgnoreDataMember]
  62. public override bool IsPreSorted
  63. {
  64. get
  65. {
  66. return true;
  67. }
  68. }
  69. [IgnoreDataMember]
  70. protected override bool SupportsShortcutChildren
  71. {
  72. get
  73. {
  74. return true;
  75. }
  76. }
  77. public override bool IsAuthorizedToDelete(User user)
  78. {
  79. return true;
  80. }
  81. public override bool IsSaveLocalMetadataEnabled()
  82. {
  83. return true;
  84. }
  85. /// <summary>
  86. /// Gets the trailer ids.
  87. /// </summary>
  88. /// <returns>List&lt;Guid&gt;.</returns>
  89. public List<Guid> GetTrailerIds()
  90. {
  91. var list = LocalTrailerIds.ToList();
  92. list.AddRange(RemoteTrailerIds);
  93. return list;
  94. }
  95. /// <summary>
  96. /// Updates the official rating based on content and returns true or false indicating if it changed.
  97. /// </summary>
  98. /// <returns></returns>
  99. public bool UpdateRatingToContent()
  100. {
  101. var currentOfficialRating = OfficialRating;
  102. // Gather all possible ratings
  103. var ratings = GetRecursiveChildren()
  104. .Concat(GetLinkedChildren())
  105. .Where(i => i is Movie || i is Series || i is MusicAlbum || i is Game)
  106. .Select(i => i.OfficialRating)
  107. .Where(i => !string.IsNullOrEmpty(i))
  108. .Distinct(StringComparer.OrdinalIgnoreCase)
  109. .Select(i => new Tuple<string, int?>(i, LocalizationManager.GetRatingLevel(i)))
  110. .OrderBy(i => i.Item2 ?? 1000)
  111. .Select(i => i.Item1);
  112. OfficialRating = ratings.FirstOrDefault() ?? currentOfficialRating;
  113. return !string.Equals(currentOfficialRating ?? string.Empty, OfficialRating ?? string.Empty,
  114. StringComparison.OrdinalIgnoreCase);
  115. }
  116. public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
  117. {
  118. var children = base.GetChildren(user, includeLinkedChildren);
  119. if (string.Equals(DisplayOrder, ItemSortBy.SortName, StringComparison.OrdinalIgnoreCase))
  120. {
  121. // Sort by name
  122. return LibraryManager.Sort(children, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending);
  123. }
  124. if (string.Equals(DisplayOrder, ItemSortBy.PremiereDate, StringComparison.OrdinalIgnoreCase))
  125. {
  126. // Sort by release date
  127. return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending);
  128. }
  129. // Default sorting
  130. return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending);
  131. }
  132. public BoxSetInfo GetLookupInfo()
  133. {
  134. return GetItemLookupInfo<BoxSetInfo>();
  135. }
  136. public override bool IsVisible(User user)
  137. {
  138. var userId = user.Id.ToString("N");
  139. // Need to check Count > 0 for boxsets created prior to the introduction of Shares
  140. if (Shares.Count > 0 && Shares.Any(i => string.Equals(userId, i.UserId, StringComparison.OrdinalIgnoreCase)))
  141. {
  142. return true;
  143. }
  144. if (base.IsVisible(user))
  145. {
  146. return GetChildren(user, true).Any();
  147. }
  148. return false;
  149. }
  150. }
  151. }