BoxSet.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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, 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. 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 display order.
  44. /// </summary>
  45. /// <value>The display order.</value>
  46. public string DisplayOrder { get; set; }
  47. protected override bool GetBlockUnratedValue(UserPolicy config)
  48. {
  49. return config.BlockUnratedItems.Contains(UnratedItem.Movie);
  50. }
  51. public override UnratedItem GetBlockUnratedType()
  52. {
  53. return UnratedItem.Movie;
  54. }
  55. [IgnoreDataMember]
  56. public override bool IsPreSorted
  57. {
  58. get
  59. {
  60. return true;
  61. }
  62. }
  63. [IgnoreDataMember]
  64. protected override bool SupportsShortcutChildren
  65. {
  66. get
  67. {
  68. return true;
  69. }
  70. }
  71. public override bool IsAuthorizedToDelete(User user)
  72. {
  73. return true;
  74. }
  75. public override bool IsSaveLocalMetadataEnabled()
  76. {
  77. return true;
  78. }
  79. /// <summary>
  80. /// Gets the trailer ids.
  81. /// </summary>
  82. /// <returns>List&lt;Guid&gt;.</returns>
  83. public List<Guid> GetTrailerIds()
  84. {
  85. var list = LocalTrailerIds.ToList();
  86. list.AddRange(RemoteTrailerIds);
  87. return list;
  88. }
  89. /// <summary>
  90. /// Updates the official rating based on content and returns true or false indicating if it changed.
  91. /// </summary>
  92. /// <returns></returns>
  93. public bool UpdateRatingToContent()
  94. {
  95. var currentOfficialRating = OfficialRating;
  96. // Gather all possible ratings
  97. var ratings = GetRecursiveChildren()
  98. .Concat(GetLinkedChildren())
  99. .Where(i => i is Movie || i is Series || i is MusicAlbum || i is Game)
  100. .Select(i => i.OfficialRating)
  101. .Where(i => !string.IsNullOrEmpty(i))
  102. .Distinct(StringComparer.OrdinalIgnoreCase)
  103. .Select(i => new Tuple<string, int?>(i, LocalizationManager.GetRatingLevel(i)))
  104. .OrderBy(i => i.Item2 ?? 1000)
  105. .Select(i => i.Item1);
  106. OfficialRating = ratings.FirstOrDefault() ?? currentOfficialRating;
  107. return !string.Equals(currentOfficialRating ?? string.Empty, OfficialRating ?? string.Empty,
  108. StringComparison.OrdinalIgnoreCase);
  109. }
  110. public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
  111. {
  112. var children = base.GetChildren(user, includeLinkedChildren);
  113. if (string.Equals(DisplayOrder, ItemSortBy.SortName, StringComparison.OrdinalIgnoreCase))
  114. {
  115. // Sort by name
  116. return LibraryManager.Sort(children, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending);
  117. }
  118. if (string.Equals(DisplayOrder, ItemSortBy.PremiereDate, StringComparison.OrdinalIgnoreCase))
  119. {
  120. // Sort by release date
  121. return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending);
  122. }
  123. // Default sorting
  124. return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending);
  125. }
  126. public BoxSetInfo GetLookupInfo()
  127. {
  128. return GetItemLookupInfo<BoxSetInfo>();
  129. }
  130. public override bool IsVisible(User user)
  131. {
  132. var userId = user.Id.ToString("N");
  133. // Need to check Count > 0 for boxsets created prior to the introduction of Shares
  134. if (Shares.Count > 0 && Shares.Any(i => string.Equals(userId, i.UserId, StringComparison.OrdinalIgnoreCase)))
  135. {
  136. return true;
  137. }
  138. if (base.IsVisible(user))
  139. {
  140. return GetChildren(user, true).Any();
  141. }
  142. return false;
  143. }
  144. }
  145. }