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

211 lines
6.2 KiB

using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class BoxSet
/// </summary>
public class BoxSet : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>, IHasShares
{
public List<Share> Shares { get; set; }
public BoxSet()
{
RemoteTrailers = EmptyMediaUrlArray;
LocalTrailerIds = EmptyGuidArray;
RemoteTrailerIds = EmptyGuidArray;
DisplayOrder = ItemSortBy.PremiereDate;
Shares = new List<Share>();
}
[IgnoreDataMember]
protected override bool FilterLinkedChildrenPerUser
{
get
{
return true;
}
}
[IgnoreDataMember]
public override bool SupportsInheritedParentImages
{
get
{
return false;
}
}
public Guid[] LocalTrailerIds { get; set; }
public Guid[] RemoteTrailerIds { get; set; }
/// <summary>
/// Gets or sets the remote trailers.
/// </summary>
/// <value>The remote trailers.</value>
public MediaUrl[] RemoteTrailers { get; set; }
/// <summary>
/// Gets or sets the display order.
/// </summary>
/// <value>The display order.</value>
public string DisplayOrder { get; set; }
protected override bool GetBlockUnratedValue(UserPolicy config)
{
return config.BlockUnratedItems.Contains(UnratedItem.Movie);
}
public override double? GetDefaultPrimaryImageAspectRatio()
{
double value = 2;
value /= 3;
return value;
}
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.Movie;
}
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
{
if (IsLegacyBoxSet)
{
return base.GetNonCachedChildren(directoryService);
}
return new List<BaseItem>();
}
protected override List<BaseItem> LoadChildren()
{
if (IsLegacyBoxSet)
{
return base.LoadChildren();
}
// Save a trip to the database
return new List<BaseItem>();
}
[IgnoreDataMember]
private bool IsLegacyBoxSet
{
get
{
if (string.IsNullOrWhiteSpace(Path))
{
return false;
}
if (LinkedChildren.Length > 0)
{
return false;
}
return !FileSystem.ContainsSubPath(ConfigurationManager.ApplicationPaths.DataPath, Path);
}
}
[IgnoreDataMember]
public override bool IsPreSorted
{
get
{
return true;
}
}
public override bool IsAuthorizedToDelete(User user)
{
return true;
}
public override bool IsSaveLocalMetadataEnabled()
{
return true;
}
/// <summary>
/// Updates the official rating based on content and returns true or false indicating if it changed.
/// </summary>
/// <returns></returns>
public bool UpdateRatingToContent()
{
var currentOfficialRating = OfficialRating;
// Gather all possible ratings
var ratings = GetLinkedChildren()
.Select(i => i.OfficialRating)
.Where(i => !string.IsNullOrEmpty(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
.Select(i => new Tuple<string, int?>(i, LocalizationManager.GetRatingLevel(i)))
.OrderBy(i => i.Item2 ?? 1000)
.Select(i => i.Item1);
OfficialRating = ratings.FirstOrDefault() ?? currentOfficialRating;
return !string.Equals(currentOfficialRating ?? string.Empty, OfficialRating ?? string.Empty,
StringComparison.OrdinalIgnoreCase);
}
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren)
{
var children = base.GetChildren(user, includeLinkedChildren);
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();
}
public BoxSetInfo GetLookupInfo()
{
return GetItemLookupInfo<BoxSetInfo>();
}
public override bool IsVisible(User user)
{
var userId = user.Id.ToString("N");
// Need to check Count > 0 for boxsets created prior to the introduction of Shares
if (Shares.Count > 0 && Shares.Any(i => string.Equals(userId, i.UserId, StringComparison.OrdinalIgnoreCase)))
{
return true;
}
if (base.IsVisible(user))
{
return base.GetChildren(user, true).Count > 0;
}
return false;
}
public override bool IsVisibleStandalone(User user)
{
return IsVisible(user);
}
}
}