diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 65711e89d8..a10e17f6ad 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1056,30 +1056,19 @@ namespace Emby.Server.Implementations.Dto if (options.ContainsField(ItemFields.SpecialFeatureCount)) { - if (allExtras == null) - { - allExtras = item.GetExtras().ToArray(); - } - - dto.SpecialFeatureCount = allExtras.Count(i => i.ExtraType.HasValue && BaseItem.DisplayExtraTypes.Contains(i.ExtraType.Value)); + allExtras = item.GetExtras().ToArray(); + dto.SpecialFeatureCount = allExtras.Count(i => i.HasExtraType(BaseItem.DisplayExtraTypes, true)); } if (options.ContainsField(ItemFields.LocalTrailerCount)) { - int trailerCount = 0; - if (allExtras == null) - { - allExtras = item.GetExtras().ToArray(); - } - - trailerCount += allExtras.Count(i => i.ExtraType.HasValue && i.ExtraType.Value == ExtraType.Trailer); + allExtras = allExtras ?? item.GetExtras().ToArray(); + dto.LocalTrailerCount = allExtras.Count(i => i.HasExtraType(new[] { ExtraType.Trailer }, false)); if (item is IHasTrailers hasTrailers) { - trailerCount += hasTrailers.GetTrailerCount(); + dto.LocalTrailerCount += hasTrailers.GetTrailerCount(); } - - dto.LocalTrailerCount = trailerCount; } // Add EpisodeInfo diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index 2ec08f5787..a55b0253ac 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -380,7 +380,7 @@ namespace MediaBrowser.Api.UserLibrary var dtoOptions = GetDtoOptions(_authContext, request); - var dtosExtras = item.GetExtras(new[] { ExtraType.Trailer }) + var dtosExtras = item.GetExtras(new[] { ExtraType.Trailer }, false) .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)) .ToArray(); diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index a9ec19e2fd..2a941a684a 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -2878,14 +2878,30 @@ namespace MediaBrowser.Controller.Entities /// The remote trailers. public IReadOnlyList RemoteTrailers { get; set; } + /// + /// Get all extras associated with this item, sorted by . + /// + /// An enumerable containing the items. public IEnumerable GetExtras() { - return ExtraIds.Select(LibraryManager.GetItemById).Where(i => i != null).OrderBy(i => i.SortName); + return ExtraIds + .Select(LibraryManager.GetItemById) + .Where(i => i != null) + .OrderBy(i => i.SortName); } - public IEnumerable GetExtras(IReadOnlyCollection extraTypes) + /// + /// 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) { - return ExtraIds.Select(LibraryManager.GetItemById).Where(i => i?.ExtraType != null && extraTypes.Contains(i.ExtraType.Value)); + return ExtraIds + .Select(LibraryManager.GetItemById) + .Where(i => i != null) + .Where(i => i.HasExtraType(extraTypes, includeUnknownTypes)); } public IEnumerable GetTrailers() @@ -2896,9 +2912,27 @@ 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); + 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; @@ -2918,8 +2952,18 @@ namespace MediaBrowser.Controller.Entities return RunTimeTicks ?? 0; } - // Possible types of extra videos - public static readonly IReadOnlyCollection DisplayExtraTypes = new[] { Model.Entities.ExtraType.BehindTheScenes, Model.Entities.ExtraType.Clip, Model.Entities.ExtraType.DeletedScene, Model.Entities.ExtraType.Interview, Model.Entities.ExtraType.Sample, Model.Entities.ExtraType.Scene }; + /// + /// Extra types that should be counted and displayed as "Special Features" in the UI. + /// + public static readonly IReadOnlyCollection DisplayExtraTypes = new HashSet + { + Model.Entities.ExtraType.BehindTheScenes, + Model.Entities.ExtraType.Clip, + Model.Entities.ExtraType.DeletedScene, + Model.Entities.ExtraType.Interview, + Model.Entities.ExtraType.Sample, + Model.Entities.ExtraType.Scene + }; public virtual bool SupportsExternalTransfer => false;