| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CA1721, CA1819, CS1591 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Collections.Immutable; |
| | 8 | | using System.Linq; |
| | 9 | | using System.Text.Json.Serialization; |
| | 10 | | using Jellyfin.Data; |
| | 11 | | using Jellyfin.Data.Enums; |
| | 12 | | using Jellyfin.Database.Implementations.Entities; |
| | 13 | | using Jellyfin.Database.Implementations.Enums; |
| | 14 | | using MediaBrowser.Controller.Providers; |
| | 15 | | using MediaBrowser.Model.Querying; |
| | 16 | |
|
| | 17 | | namespace MediaBrowser.Controller.Entities.Movies |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Class BoxSet. |
| | 21 | | /// </summary> |
| | 22 | | public class BoxSet : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo> |
| | 23 | | { |
| 2 | 24 | | public BoxSet() |
| | 25 | | { |
| 2 | 26 | | DisplayOrder = "PremiereDate"; |
| 2 | 27 | | } |
| | 28 | |
|
| | 29 | | [JsonIgnore] |
| 0 | 30 | | protected override bool FilterLinkedChildrenPerUser => true; |
| | 31 | |
|
| | 32 | | [JsonIgnore] |
| 0 | 33 | | public override bool SupportsInheritedParentImages => false; |
| | 34 | |
|
| | 35 | | [JsonIgnore] |
| 0 | 36 | | public override bool SupportsPeople => true; |
| | 37 | |
|
| | 38 | | /// <inheritdoc /> |
| | 39 | | [JsonIgnore] |
| 0 | 40 | | public IReadOnlyList<BaseItem> LocalTrailers => GetExtras() |
| 0 | 41 | | .Where(extra => extra.ExtraType == Model.Entities.ExtraType.Trailer) |
| 0 | 42 | | .ToArray(); |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Gets or sets the display order. |
| | 46 | | /// </summary> |
| | 47 | | /// <value>The display order.</value> |
| | 48 | | public string DisplayOrder { get; set; } |
| | 49 | |
|
| | 50 | | [JsonIgnore] |
| | 51 | | private bool IsLegacyBoxSet |
| | 52 | | { |
| | 53 | | get |
| | 54 | | { |
| 0 | 55 | | if (string.IsNullOrEmpty(Path)) |
| | 56 | | { |
| 0 | 57 | | return false; |
| | 58 | | } |
| | 59 | |
|
| 0 | 60 | | if (LinkedChildren.Length > 0) |
| | 61 | | { |
| 0 | 62 | | return false; |
| | 63 | | } |
| | 64 | |
|
| 0 | 65 | | return !FileSystem.ContainsSubPath(ConfigurationManager.ApplicationPaths.DataPath, Path); |
| | 66 | | } |
| | 67 | | } |
| | 68 | |
|
| | 69 | | [JsonIgnore] |
| 0 | 70 | | public override bool IsPreSorted => true; |
| | 71 | |
|
| | 72 | | public Guid[] LibraryFolderIds { get; set; } |
| | 73 | |
|
| | 74 | | protected override bool GetBlockUnratedValue(User user) |
| | 75 | | { |
| 0 | 76 | | return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Movie); |
| | 77 | | } |
| | 78 | |
|
| | 79 | | public override double GetDefaultPrimaryImageAspectRatio() |
| 0 | 80 | | => 2.0 / 3; |
| | 81 | |
|
| | 82 | | public override UnratedItem GetBlockUnratedType() |
| | 83 | | { |
| 0 | 84 | | return UnratedItem.Movie; |
| | 85 | | } |
| | 86 | |
|
| | 87 | | protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService) |
| | 88 | | { |
| 0 | 89 | | if (IsLegacyBoxSet) |
| | 90 | | { |
| 0 | 91 | | return base.GetNonCachedChildren(directoryService); |
| | 92 | | } |
| | 93 | |
|
| 0 | 94 | | return Enumerable.Empty<BaseItem>(); |
| | 95 | | } |
| | 96 | |
|
| | 97 | | protected override IReadOnlyList<BaseItem> LoadChildren() |
| | 98 | | { |
| 0 | 99 | | if (IsLegacyBoxSet) |
| | 100 | | { |
| 0 | 101 | | return base.LoadChildren(); |
| | 102 | | } |
| | 103 | |
|
| | 104 | | // Save a trip to the database |
| 0 | 105 | | return []; |
| | 106 | | } |
| | 107 | |
|
| | 108 | | public override bool IsAuthorizedToDelete(User user, List<Folder> allCollectionFolders) |
| | 109 | | { |
| 0 | 110 | | return user.HasPermission(PermissionKind.IsAdministrator) || user.HasPermission(PermissionKind.EnableCollect |
| | 111 | | } |
| | 112 | |
|
| | 113 | | public override bool IsSaveLocalMetadataEnabled() |
| | 114 | | { |
| 0 | 115 | | return true; |
| | 116 | | } |
| | 117 | |
|
| | 118 | | private IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user) |
| | 119 | | { |
| 0 | 120 | | if (!Enum.TryParse<ItemSortBy>(DisplayOrder, out var sortBy)) |
| | 121 | | { |
| 0 | 122 | | sortBy = ItemSortBy.PremiereDate; |
| | 123 | | } |
| | 124 | |
|
| 0 | 125 | | if (sortBy == ItemSortBy.Default) |
| | 126 | | { |
| 0 | 127 | | return items; |
| | 128 | | } |
| | 129 | |
|
| 0 | 130 | | return LibraryManager.Sort(items, user, new[] { sortBy }, SortOrder.Ascending); |
| | 131 | | } |
| | 132 | |
|
| | 133 | | public override IReadOnlyList<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery qu |
| | 134 | | { |
| 0 | 135 | | var children = base.GetChildren(user, includeLinkedChildren, query); |
| 0 | 136 | | return Sort(children, user).ToArray(); |
| | 137 | | } |
| | 138 | |
|
| | 139 | | public override IReadOnlyList<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query) |
| | 140 | | { |
| 0 | 141 | | var children = base.GetRecursiveChildren(user, query); |
| 0 | 142 | | return Sort(children, user).ToArray(); |
| | 143 | | } |
| | 144 | |
|
| | 145 | | public BoxSetInfo GetLookupInfo() |
| | 146 | | { |
| 0 | 147 | | return GetItemLookupInfo<BoxSetInfo>(); |
| | 148 | | } |
| | 149 | |
|
| | 150 | | public override bool IsVisible(User user, bool skipAllowedTagsCheck = false) |
| | 151 | | { |
| 0 | 152 | | if (IsLegacyBoxSet) |
| | 153 | | { |
| 0 | 154 | | return base.IsVisible(user, skipAllowedTagsCheck); |
| | 155 | | } |
| | 156 | |
|
| 0 | 157 | | if (base.IsVisible(user, skipAllowedTagsCheck)) |
| | 158 | | { |
| 0 | 159 | | if (LinkedChildren.Length == 0) |
| | 160 | | { |
| 0 | 161 | | return true; |
| | 162 | | } |
| | 163 | |
|
| 0 | 164 | | var userLibraryFolderIds = GetLibraryFolderIds(user); |
| 0 | 165 | | var libraryFolderIds = LibraryFolderIds ?? GetLibraryFolderIds(); |
| | 166 | |
|
| 0 | 167 | | if (libraryFolderIds.Length == 0) |
| | 168 | | { |
| 0 | 169 | | return true; |
| | 170 | | } |
| | 171 | |
|
| 0 | 172 | | return userLibraryFolderIds.Any(i => libraryFolderIds.Contains(i)); |
| | 173 | | } |
| | 174 | |
|
| 0 | 175 | | return false; |
| | 176 | | } |
| | 177 | |
|
| | 178 | | public override bool IsVisibleStandalone(User user) |
| | 179 | | { |
| 0 | 180 | | if (IsLegacyBoxSet) |
| | 181 | | { |
| 0 | 182 | | return base.IsVisibleStandalone(user); |
| | 183 | | } |
| | 184 | |
|
| 0 | 185 | | return IsVisible(user); |
| | 186 | | } |
| | 187 | |
|
| | 188 | | private Guid[] GetLibraryFolderIds(User user) |
| | 189 | | { |
| 0 | 190 | | return LibraryManager.GetUserRootFolder().GetChildren(user, true) |
| 0 | 191 | | .Select(i => i.Id) |
| 0 | 192 | | .ToArray(); |
| | 193 | | } |
| | 194 | |
|
| | 195 | | public Guid[] GetLibraryFolderIds() |
| | 196 | | { |
| 0 | 197 | | var expandedFolders = new List<Guid>(); |
| | 198 | |
|
| 0 | 199 | | return FlattenItems(this, expandedFolders) |
| 0 | 200 | | .SelectMany(i => LibraryManager.GetCollectionFolders(i)) |
| 0 | 201 | | .Select(i => i.Id) |
| 0 | 202 | | .Distinct() |
| 0 | 203 | | .ToArray(); |
| | 204 | | } |
| | 205 | |
|
| | 206 | | private IEnumerable<BaseItem> FlattenItems(IEnumerable<BaseItem> items, List<Guid> expandedFolders) |
| | 207 | | { |
| 0 | 208 | | return items |
| 0 | 209 | | .SelectMany(i => FlattenItems(i, expandedFolders)); |
| | 210 | | } |
| | 211 | |
|
| | 212 | | private IEnumerable<BaseItem> FlattenItems(BaseItem item, List<Guid> expandedFolders) |
| | 213 | | { |
| 0 | 214 | | if (item is BoxSet boxset) |
| | 215 | | { |
| 0 | 216 | | if (!expandedFolders.Contains(item.Id)) |
| | 217 | | { |
| 0 | 218 | | expandedFolders.Add(item.Id); |
| | 219 | |
|
| 0 | 220 | | return FlattenItems(boxset.GetLinkedChildren(), expandedFolders); |
| | 221 | | } |
| | 222 | |
|
| 0 | 223 | | return Array.Empty<BaseItem>(); |
| | 224 | | } |
| | 225 | |
|
| 0 | 226 | | return new[] { item }; |
| | 227 | | } |
| | 228 | | } |
| | 229 | | } |