jellyfin/MediaBrowser.Controller/Entities/Movies/BoxSet.cs

236 lines
7.0 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System;
using System.Collections.Generic;
using System.Linq;
2019-10-15 08:49:49 -07:00
using System.Text.Json.Serialization;
2020-05-20 10:07:53 -07:00
using Jellyfin.Data.Entities;
2020-05-12 19:10:35 -07:00
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Providers;
2018-12-27 16:27:57 -07:00
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class BoxSet.
2018-12-27 16:27:57 -07:00
/// </summary>
public class BoxSet : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>
{
public BoxSet()
{
RemoteTrailers = Array.Empty<MediaUrl>();
2018-12-27 14:43:48 -07:00
LocalTrailerIds = Array.Empty<Guid>();
RemoteTrailerIds = Array.Empty<Guid>();
2018-12-27 16:27:57 -07:00
DisplayOrder = ItemSortBy.PremiereDate;
}
2019-10-15 08:49:49 -07:00
[JsonIgnore]
protected override bool FilterLinkedChildrenPerUser => true;
2018-12-27 16:27:57 -07:00
2019-10-15 08:49:49 -07:00
[JsonIgnore]
public override bool SupportsInheritedParentImages => false;
2018-12-27 16:27:57 -07:00
2019-10-15 08:49:49 -07:00
[JsonIgnore]
public override bool SupportsPeople => true;
2018-12-27 16:27:57 -07:00
/// <inheritdoc />
public IReadOnlyList<Guid> LocalTrailerIds { get; set; }
/// <inheritdoc />
public IReadOnlyList<Guid> RemoteTrailerIds { get; set; }
2018-12-27 16:27:57 -07:00
/// <summary>
/// Gets or sets the display order.
/// </summary>
/// <value>The display order.</value>
public string DisplayOrder { get; set; }
2020-05-20 10:07:53 -07:00
protected override bool GetBlockUnratedValue(User user)
2018-12-27 16:27:57 -07:00
{
2020-12-13 08:15:26 -07:00
return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Movie);
2018-12-27 16:27:57 -07:00
}
public override double GetDefaultPrimaryImageAspectRatio()
=> 2.0 / 3;
2018-12-27 16:27:57 -07:00
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.Movie;
}
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
{
if (IsLegacyBoxSet)
{
return base.GetNonCachedChildren(directoryService);
}
return Enumerable.Empty<BaseItem>();
2018-12-27 16:27:57 -07:00
}
protected override List<BaseItem> LoadChildren()
{
if (IsLegacyBoxSet)
{
return base.LoadChildren();
}
// Save a trip to the database
return new List<BaseItem>();
}
2019-10-15 08:49:49 -07:00
[JsonIgnore]
2018-12-27 16:27:57 -07:00
private bool IsLegacyBoxSet
{
get
{
if (string.IsNullOrEmpty(Path))
{
return false;
}
if (LinkedChildren.Length > 0)
{
return false;
}
return !FileSystem.ContainsSubPath(ConfigurationManager.ApplicationPaths.DataPath, Path);
}
}
2019-10-15 08:49:49 -07:00
[JsonIgnore]
public override bool IsPreSorted => true;
2018-12-27 16:27:57 -07:00
2020-05-20 10:07:53 -07:00
public override bool IsAuthorizedToDelete(User user, List<Folder> allCollectionFolders)
2018-12-27 16:27:57 -07:00
{
return true;
}
public override bool IsSaveLocalMetadataEnabled()
{
return true;
}
2020-05-20 10:07:53 -07:00
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
2018-12-27 16:27:57 -07:00
{
var children = base.GetChildren(user, includeLinkedChildren, query);
if (string.Equals(DisplayOrder, ItemSortBy.SortName, StringComparison.OrdinalIgnoreCase))
{
// Sort by name
return LibraryManager.Sort(children, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).ToList();
}
if (string.Equals(DisplayOrder, ItemSortBy.PremiereDate, StringComparison.OrdinalIgnoreCase))
{
// 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 10:07:53 -07:00
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
2018-12-27 16:27:57 -07:00
{
var children = base.GetRecursiveChildren(user, query);
if (string.Equals(DisplayOrder, ItemSortBy.PremiereDate, StringComparison.OrdinalIgnoreCase))
{
// 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 10:07:53 -07:00
public override bool IsVisible(User user)
2018-12-27 16:27:57 -07: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 10:07:53 -07:00
public override bool IsVisibleStandalone(User user)
2018-12-27 16:27:57 -07:00
{
if (IsLegacyBoxSet)
{
return base.IsVisibleStandalone(user);
}
return IsVisible(user);
}
public Guid[] LibraryFolderIds { get; set; }
2020-05-20 10:07:53 -07:00
private Guid[] GetLibraryFolderIds(User user)
2018-12-27 16:27:57 -07:00
{
return LibraryManager.GetUserRootFolder().GetChildren(user, true)
.Select(i => i.Id)
.ToArray();
}
public Guid[] GetLibraryFolderIds()
{
2020-07-04 08:54:25 -07:00
var expandedFolders = new List<Guid>();
2018-12-27 16:27:57 -07: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)
{
if (item is BoxSet boxset)
2018-12-27 16:27:57 -07:00
{
if (!expandedFolders.Contains(item.Id))
{
expandedFolders.Add(item.Id);
return FlattenItems(boxset.GetLinkedChildren(), expandedFolders);
}
2018-12-27 14:43:48 -07:00
return Array.Empty<BaseItem>();
2018-12-27 16:27:57 -07:00
}
return new[] { item };
}
}
}