2021-05-06 18:39:20 -04:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-23 19:36:27 -04:00
|
|
|
#pragma warning disable CA1721, CA1819, CS1591
|
2020-08-22 15:56:24 -04:00
|
|
|
|
2019-01-13 15:01:16 -05:00
|
|
|
using System;
|
2019-01-13 14:25:32 -05:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2019-10-15 11:49:49 -04:00
|
|
|
using System.Text.Json.Serialization;
|
2020-05-20 13:07:53 -04:00
|
|
|
using Jellyfin.Data.Entities;
|
2020-05-12 22:10:35 -04:00
|
|
|
using Jellyfin.Data.Enums;
|
2019-01-13 14:25:32 -05:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2018-12-27 18:27:57 -05:00
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities.Movies
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 18:37:52 -04:00
|
|
|
/// Class BoxSet.
|
2018-12-27 18:27:57 -05:00
|
|
|
/// </summary>
|
|
|
|
public class BoxSet : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>
|
|
|
|
{
|
|
|
|
public BoxSet()
|
|
|
|
{
|
2023-11-09 16:00:13 -05:00
|
|
|
DisplayOrder = "PremiereDate";
|
2018-12-27 18:27:57 -05:00
|
|
|
}
|
|
|
|
|
2019-10-15 11:49:49 -04:00
|
|
|
[JsonIgnore]
|
2019-01-13 15:31:14 -05:00
|
|
|
protected override bool FilterLinkedChildrenPerUser => true;
|
2018-12-27 18:27:57 -05:00
|
|
|
|
2019-10-15 11:49:49 -04:00
|
|
|
[JsonIgnore]
|
2019-01-13 15:31:14 -05:00
|
|
|
public override bool SupportsInheritedParentImages => false;
|
2018-12-27 18:27:57 -05:00
|
|
|
|
2019-10-15 11:49:49 -04:00
|
|
|
[JsonIgnore]
|
2019-01-13 15:31:14 -05:00
|
|
|
public override bool SupportsPeople => true;
|
2018-12-27 18:27:57 -05:00
|
|
|
|
2019-09-02 02:19:29 -04:00
|
|
|
/// <inheritdoc />
|
2022-01-07 16:33:31 -05:00
|
|
|
[JsonIgnore]
|
2021-12-07 09:18:17 -05:00
|
|
|
public IReadOnlyList<BaseItem> LocalTrailers => GetExtras()
|
|
|
|
.Where(extra => extra.ExtraType == Model.Entities.ExtraType.Trailer)
|
|
|
|
.ToArray();
|
2018-12-27 18:27:57 -05:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the display order.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The display order.</value>
|
|
|
|
public string DisplayOrder { get; set; }
|
|
|
|
|
2021-07-23 19:36:27 -04:00
|
|
|
[JsonIgnore]
|
|
|
|
private bool IsLegacyBoxSet
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(Path))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LinkedChildren.Length > 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !FileSystem.ContainsSubPath(ConfigurationManager.ApplicationPaths.DataPath, Path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public override bool IsPreSorted => true;
|
|
|
|
|
|
|
|
public Guid[] LibraryFolderIds { get; set; }
|
|
|
|
|
2020-05-20 13:07:53 -04:00
|
|
|
protected override bool GetBlockUnratedValue(User user)
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
2020-12-13 10:15:26 -05:00
|
|
|
return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Movie);
|
2018-12-27 18:27:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public override double GetDefaultPrimaryImageAspectRatio()
|
2019-01-07 16:10:11 -05:00
|
|
|
=> 2.0 / 3;
|
2018-12-27 18:27:57 -05:00
|
|
|
|
|
|
|
public override UnratedItem GetBlockUnratedType()
|
|
|
|
{
|
|
|
|
return UnratedItem.Movie;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
|
|
|
|
{
|
|
|
|
if (IsLegacyBoxSet)
|
|
|
|
{
|
|
|
|
return base.GetNonCachedChildren(directoryService);
|
|
|
|
}
|
2019-09-02 02:19:29 -04:00
|
|
|
|
|
|
|
return Enumerable.Empty<BaseItem>();
|
2018-12-27 18:27:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override List<BaseItem> LoadChildren()
|
|
|
|
{
|
|
|
|
if (IsLegacyBoxSet)
|
|
|
|
{
|
|
|
|
return base.LoadChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save a trip to the database
|
|
|
|
return new List<BaseItem>();
|
|
|
|
}
|
|
|
|
|
2020-05-20 13:07:53 -04:00
|
|
|
public override bool IsAuthorizedToDelete(User user, List<Folder> allCollectionFolders)
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
2023-02-13 09:42:04 -05:00
|
|
|
return user.HasPermission(PermissionKind.IsAdministrator) || user.HasPermission(PermissionKind.EnableCollectionManagement);
|
2018-12-27 18:27:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool IsSaveLocalMetadataEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-20 13:07:53 -04:00
|
|
|
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
var children = base.GetChildren(user, includeLinkedChildren, query);
|
|
|
|
|
2023-11-09 16:00:13 -05:00
|
|
|
if (string.Equals(DisplayOrder, "SortName", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
// Sort by name
|
|
|
|
return LibraryManager.Sort(children, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).ToList();
|
|
|
|
}
|
|
|
|
|
2023-11-09 16:00:13 -05:00
|
|
|
if (string.Equals(DisplayOrder, "PremiereDate", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
// Sort by release date
|
|
|
|
return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default sorting
|
|
|
|
return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending).ToList();
|
|
|
|
}
|
|
|
|
|
2020-05-20 13:07:53 -04:00
|
|
|
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
var children = base.GetRecursiveChildren(user, query);
|
|
|
|
|
2023-11-09 16:00:13 -05:00
|
|
|
if (string.Equals(DisplayOrder, "PremiereDate", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
// Sort by release date
|
|
|
|
return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BoxSetInfo GetLookupInfo()
|
|
|
|
{
|
|
|
|
return GetItemLookupInfo<BoxSetInfo>();
|
|
|
|
}
|
|
|
|
|
2020-05-20 13:07:53 -04:00
|
|
|
public override bool IsVisible(User user)
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
if (IsLegacyBoxSet)
|
|
|
|
{
|
|
|
|
return base.IsVisible(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base.IsVisible(user))
|
|
|
|
{
|
|
|
|
if (LinkedChildren.Length == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var userLibraryFolderIds = GetLibraryFolderIds(user);
|
|
|
|
var libraryFolderIds = LibraryFolderIds ?? GetLibraryFolderIds();
|
|
|
|
|
|
|
|
if (libraryFolderIds.Length == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return userLibraryFolderIds.Any(i => libraryFolderIds.Contains(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-20 13:07:53 -04:00
|
|
|
public override bool IsVisibleStandalone(User user)
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
if (IsLegacyBoxSet)
|
|
|
|
{
|
|
|
|
return base.IsVisibleStandalone(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IsVisible(user);
|
|
|
|
}
|
|
|
|
|
2020-05-20 13:07:53 -04:00
|
|
|
private Guid[] GetLibraryFolderIds(User user)
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
return LibraryManager.GetUserRootFolder().GetChildren(user, true)
|
|
|
|
.Select(i => i.Id)
|
|
|
|
.ToArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Guid[] GetLibraryFolderIds()
|
|
|
|
{
|
2020-07-04 11:54:25 -04:00
|
|
|
var expandedFolders = new List<Guid>();
|
2018-12-27 18:27:57 -05:00
|
|
|
|
|
|
|
return FlattenItems(this, expandedFolders)
|
|
|
|
.SelectMany(i => LibraryManager.GetCollectionFolders(i))
|
|
|
|
.Select(i => i.Id)
|
|
|
|
.Distinct()
|
|
|
|
.ToArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<BaseItem> FlattenItems(IEnumerable<BaseItem> items, List<Guid> expandedFolders)
|
|
|
|
{
|
|
|
|
return items
|
|
|
|
.SelectMany(i => FlattenItems(i, expandedFolders));
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<BaseItem> FlattenItems(BaseItem item, List<Guid> expandedFolders)
|
|
|
|
{
|
2021-05-05 07:37:36 -04:00
|
|
|
if (item is BoxSet boxset)
|
2018-12-27 18:27:57 -05:00
|
|
|
{
|
|
|
|
if (!expandedFolders.Contains(item.Id))
|
|
|
|
{
|
|
|
|
expandedFolders.Add(item.Id);
|
|
|
|
|
|
|
|
return FlattenItems(boxset.GetLinkedChildren(), expandedFolders);
|
|
|
|
}
|
|
|
|
|
2018-12-27 16:43:48 -05:00
|
|
|
return Array.Empty<BaseItem>();
|
2018-12-27 18:27:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return new[] { item };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|