BoxSet.cs 5.5 KB

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