Simplify logic; remove unnecessary methods
This commit is contained in:
parent
ea306e8f6d
commit
e266ad51c5
|
@ -1057,13 +1057,13 @@ namespace Emby.Server.Implementations.Dto
|
||||||
if (options.ContainsField(ItemFields.SpecialFeatureCount))
|
if (options.ContainsField(ItemFields.SpecialFeatureCount))
|
||||||
{
|
{
|
||||||
allExtras = item.GetExtras().ToArray();
|
allExtras = item.GetExtras().ToArray();
|
||||||
dto.SpecialFeatureCount = allExtras.Count(i => i.HasExtraType(BaseItem.DisplayExtraTypes, true));
|
dto.SpecialFeatureCount = allExtras.Count(i => BaseItem.DisplayExtraTypes.Contains(i.ExtraType));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.ContainsField(ItemFields.LocalTrailerCount))
|
if (options.ContainsField(ItemFields.LocalTrailerCount))
|
||||||
{
|
{
|
||||||
allExtras = allExtras ?? item.GetExtras().ToArray();
|
allExtras = allExtras ?? item.GetExtras().ToArray();
|
||||||
dto.LocalTrailerCount = allExtras.Count(i => i.HasExtraType(new[] { ExtraType.Trailer }, false));
|
dto.LocalTrailerCount = allExtras.Count(i => i.ExtraType == ExtraType.Trailer);
|
||||||
|
|
||||||
if (item is IHasTrailers hasTrailers)
|
if (item is IHasTrailers hasTrailers)
|
||||||
{
|
{
|
||||||
|
|
|
@ -361,7 +361,8 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
|
|
||||||
var dtoOptions = GetDtoOptions(_authContext, request);
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
||||||
|
|
||||||
var dtos = item.GetDisplayExtras()
|
var dtos = item
|
||||||
|
.GetExtras(BaseItem.DisplayExtraTypes)
|
||||||
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item));
|
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item));
|
||||||
|
|
||||||
return dtos.ToArray();
|
return dtos.ToArray();
|
||||||
|
@ -380,7 +381,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
|
|
||||||
var dtoOptions = GetDtoOptions(_authContext, request);
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
||||||
|
|
||||||
var dtosExtras = item.GetExtras(new[] { ExtraType.Trailer }, false)
|
var dtosExtras = item.GetExtras(new ExtraType?[] { ExtraType.Trailer })
|
||||||
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item))
|
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
|
|
@ -2895,14 +2895,13 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// Get all extras with specific types that are associated with this item.
|
/// Get all extras with specific types that are associated with this item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="extraTypes">The types of extras to retrieve.</param>
|
/// <param name="extraTypes">The types of extras to retrieve.</param>
|
||||||
/// <param name="includeUnknownTypes">If true, include extras whose type could not be determined.</param>
|
|
||||||
/// <returns>An enumerable containing the extras.</returns>
|
/// <returns>An enumerable containing the extras.</returns>
|
||||||
public IEnumerable<BaseItem> GetExtras(IReadOnlyCollection<ExtraType> extraTypes, bool includeUnknownTypes)
|
public IEnumerable<BaseItem> GetExtras(IReadOnlyCollection<ExtraType?> extraTypes)
|
||||||
{
|
{
|
||||||
return ExtraIds
|
return ExtraIds
|
||||||
.Select(LibraryManager.GetItemById)
|
.Select(LibraryManager.GetItemById)
|
||||||
.Where(i => i != null)
|
.Where(i => i != null)
|
||||||
.Where(i => i.HasExtraType(extraTypes, includeUnknownTypes));
|
.Where(i => extraTypes.Contains(i.ExtraType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<BaseItem> GetTrailers()
|
public IEnumerable<BaseItem> GetTrailers()
|
||||||
|
@ -2913,29 +2912,6 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return Array.Empty<BaseItem>();
|
return Array.Empty<BaseItem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get all extras associated with this item that should be displayed as "Special Features" in the UI. This is
|
|
||||||
/// all extras with either an unknown type, or a type contained in <see cref="DisplayExtraTypes"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>An IEnumerable containing the extra items.</returns>
|
|
||||||
public IEnumerable<BaseItem> GetDisplayExtras()
|
|
||||||
{
|
|
||||||
return GetExtras(DisplayExtraTypes, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if this item is an extra with a type that matches a given set.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="extraTypes">The types of extras to match with.</param>
|
|
||||||
/// <param name="includeUnknownTypes">If true, include extras whose type could not be determined.</param>
|
|
||||||
/// <returns>True if this item matches, otherwise false.</returns>
|
|
||||||
public bool HasExtraType(IReadOnlyCollection<ExtraType> extraTypes, bool includeUnknownTypes)
|
|
||||||
{
|
|
||||||
return
|
|
||||||
(includeUnknownTypes && (ExtraType == null || ExtraType == 0))
|
|
||||||
|| (ExtraType.HasValue && extraTypes.Contains(ExtraType.Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool IsHD => Height >= 720;
|
public virtual bool IsHD => Height >= 720;
|
||||||
|
|
||||||
public bool IsShortcut { get; set; }
|
public bool IsShortcut { get; set; }
|
||||||
|
@ -2956,8 +2932,10 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extra types that should be counted and displayed as "Special Features" in the UI.
|
/// Extra types that should be counted and displayed as "Special Features" in the UI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly IReadOnlyCollection<ExtraType> DisplayExtraTypes = new HashSet<ExtraType>
|
public static readonly IReadOnlyCollection<ExtraType?> DisplayExtraTypes = new HashSet<ExtraType?>
|
||||||
{
|
{
|
||||||
|
null,
|
||||||
|
0,
|
||||||
Model.Entities.ExtraType.BehindTheScenes,
|
Model.Entities.ExtraType.BehindTheScenes,
|
||||||
Model.Entities.ExtraType.Clip,
|
Model.Entities.ExtraType.Clip,
|
||||||
Model.Entities.ExtraType.DeletedScene,
|
Model.Entities.ExtraType.DeletedScene,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user