From e266ad51c52763f11a2eab9ac86f638542a4ddb0 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Sat, 28 Mar 2020 14:17:33 +0100 Subject: [PATCH] Simplify logic; remove unnecessary methods --- Emby.Server.Implementations/Dto/DtoService.cs | 4 +-- .../UserLibrary/UserLibraryService.cs | 5 +-- MediaBrowser.Controller/Entities/BaseItem.cs | 32 +++---------------- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index a10e17f6ad..f8cf00cb3b 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1057,13 +1057,13 @@ namespace Emby.Server.Implementations.Dto if (options.ContainsField(ItemFields.SpecialFeatureCount)) { 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)) { 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) { diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index a55b0253ac..21d2fc9923 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -361,7 +361,8 @@ namespace MediaBrowser.Api.UserLibrary var dtoOptions = GetDtoOptions(_authContext, request); - var dtos = item.GetDisplayExtras() + var dtos = item + .GetExtras(BaseItem.DisplayExtraTypes) .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)); return dtos.ToArray(); @@ -380,7 +381,7 @@ namespace MediaBrowser.Api.UserLibrary 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)) .ToArray(); diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 66917e4428..2424293fe1 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -2895,14 +2895,13 @@ namespace MediaBrowser.Controller.Entities /// Get all extras with specific types that are associated with this item. /// /// The types of extras to retrieve. - /// If true, include extras whose type could not be determined. /// An enumerable containing the extras. - public IEnumerable GetExtras(IReadOnlyCollection extraTypes, bool includeUnknownTypes) + public IEnumerable GetExtras(IReadOnlyCollection extraTypes) { return ExtraIds .Select(LibraryManager.GetItemById) .Where(i => i != null) - .Where(i => i.HasExtraType(extraTypes, includeUnknownTypes)); + .Where(i => extraTypes.Contains(i.ExtraType)); } public IEnumerable GetTrailers() @@ -2913,29 +2912,6 @@ namespace MediaBrowser.Controller.Entities return Array.Empty(); } - /// - /// 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 . - /// - /// An IEnumerable containing the extra items. - public IEnumerable GetDisplayExtras() - { - return GetExtras(DisplayExtraTypes, true); - } - - /// - /// Check if this item is an extra with a type that matches a given set. - /// - /// The types of extras to match with. - /// If true, include extras whose type could not be determined. - /// True if this item matches, otherwise false. - public bool HasExtraType(IReadOnlyCollection extraTypes, bool includeUnknownTypes) - { - return - (includeUnknownTypes && (ExtraType == null || ExtraType == 0)) - || (ExtraType.HasValue && extraTypes.Contains(ExtraType.Value)); - } - public virtual bool IsHD => Height >= 720; public bool IsShortcut { get; set; } @@ -2956,8 +2932,10 @@ namespace MediaBrowser.Controller.Entities /// /// Extra types that should be counted and displayed as "Special Features" in the UI. /// - public static readonly IReadOnlyCollection DisplayExtraTypes = new HashSet + public static readonly IReadOnlyCollection DisplayExtraTypes = new HashSet { + null, + 0, Model.Entities.ExtraType.BehindTheScenes, Model.Entities.ExtraType.Clip, Model.Entities.ExtraType.DeletedScene,