You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Controller/Entities/Movies/BoxSet.cs

233 lines
7.0 KiB

#nullable disable
#pragma warning disable CA1721, CA1819, CS1591
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Providers;
6 years ago
using MediaBrowser.Model.Querying;
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class BoxSet.
6 years ago
/// </summary>
public class BoxSet : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>
{
public BoxSet()
{
DisplayOrder = "PremiereDate";
6 years ago
}
[JsonIgnore]
protected override bool FilterLinkedChildrenPerUser => true;
6 years ago
[JsonIgnore]
public override bool SupportsInheritedParentImages => false;
6 years ago
[JsonIgnore]
public override bool SupportsPeople => true;
6 years ago
/// <inheritdoc />
[JsonIgnore]
public IReadOnlyList<BaseItem> LocalTrailers => GetExtras()
.Where(extra => extra.ExtraType == Model.Entities.ExtraType.Trailer)
.ToArray();
6 years ago
/// <summary>
/// Gets or sets the display order.
/// </summary>
/// <value>The display order.</value>
public string DisplayOrder { get; set; }
[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; }
protected override bool GetBlockUnratedValue(User user)
6 years ago
{
return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Movie);
6 years ago
}
public override double GetDefaultPrimaryImageAspectRatio()
=> 2.0 / 3;
6 years ago
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.Movie;
}
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
{
if (IsLegacyBoxSet)
{
return base.GetNonCachedChildren(directoryService);
}
return Enumerable.Empty<BaseItem>();
6 years ago
}
protected override List<BaseItem> LoadChildren()
{
if (IsLegacyBoxSet)
{
return base.LoadChildren();
}
// Save a trip to the database
return new List<BaseItem>();
}
public override bool IsAuthorizedToDelete(User user, List<Folder> allCollectionFolders)
6 years ago
{
return user.HasPermission(PermissionKind.IsAdministrator) || user.HasPermission(PermissionKind.EnableCollectionManagement);
6 years ago
}
public override bool IsSaveLocalMetadataEnabled()
{
return true;
}
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
6 years ago
{
var children = base.GetChildren(user, includeLinkedChildren, query);
if (string.Equals(DisplayOrder, "SortName", StringComparison.OrdinalIgnoreCase))
6 years ago
{
// Sort by name
return LibraryManager.Sort(children, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).ToList();
}
if (string.Equals(DisplayOrder, "PremiereDate", StringComparison.OrdinalIgnoreCase))
6 years ago
{
// 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();
}
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
6 years ago
{
var children = base.GetRecursiveChildren(user, query);
if (string.Equals(DisplayOrder, "PremiereDate", StringComparison.OrdinalIgnoreCase))
6 years ago
{
// 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>();
}
public override bool IsVisible(User user)
6 years ago
{
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;
}
public override bool IsVisibleStandalone(User user)
6 years ago
{
if (IsLegacyBoxSet)
{
return base.IsVisibleStandalone(user);
}
return IsVisible(user);
}
private Guid[] GetLibraryFolderIds(User user)
6 years ago
{
return LibraryManager.GetUserRootFolder().GetChildren(user, true)
.Select(i => i.Id)
.ToArray();
}
public Guid[] GetLibraryFolderIds()
{
4 years ago
var expandedFolders = new List<Guid>();
6 years ago
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)
{
if (item is BoxSet boxset)
6 years ago
{
if (!expandedFolders.Contains(item.Id))
{
expandedFolders.Add(item.Id);
return FlattenItems(boxset.GetLinkedChildren(), expandedFolders);
}
6 years ago
return Array.Empty<BaseItem>();
6 years ago
}
return new[] { item };
}
}
}