< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.Movies.BoxSet
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/Movies/BoxSet.cs
Line coverage
4%
Covered lines: 3
Uncovered lines: 64
Coverable lines: 67
Total lines: 229
Line coverage: 4.4%
Branch coverage
0%
Covered branches: 0
Total branches: 30
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

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

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CA1721, CA1819, CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Collections.Immutable;
 8using System.Linq;
 9using System.Text.Json.Serialization;
 10using Jellyfin.Data;
 11using Jellyfin.Data.Enums;
 12using Jellyfin.Database.Implementations.Entities;
 13using Jellyfin.Database.Implementations.Enums;
 14using MediaBrowser.Controller.Providers;
 15using MediaBrowser.Model.Querying;
 16
 17namespace MediaBrowser.Controller.Entities.Movies
 18{
 19    /// <summary>
 20    /// Class BoxSet.
 21    /// </summary>
 22    public class BoxSet : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>
 23    {
 224        public BoxSet()
 25        {
 226            DisplayOrder = "PremiereDate";
 227        }
 28
 29        [JsonIgnore]
 030        protected override bool FilterLinkedChildrenPerUser => true;
 31
 32        [JsonIgnore]
 033        public override bool SupportsInheritedParentImages => false;
 34
 35        [JsonIgnore]
 036        public override bool SupportsPeople => true;
 37
 38        /// <inheritdoc />
 39        [JsonIgnore]
 040        public IReadOnlyList<BaseItem> LocalTrailers => GetExtras()
 041            .Where(extra => extra.ExtraType == Model.Entities.ExtraType.Trailer)
 042            .ToArray();
 43
 44        /// <summary>
 45        /// Gets or sets the display order.
 46        /// </summary>
 47        /// <value>The display order.</value>
 48        public string DisplayOrder { get; set; }
 49
 50        [JsonIgnore]
 51        private bool IsLegacyBoxSet
 52        {
 53            get
 54            {
 055                if (string.IsNullOrEmpty(Path))
 56                {
 057                    return false;
 58                }
 59
 060                if (LinkedChildren.Length > 0)
 61                {
 062                    return false;
 63                }
 64
 065                return !FileSystem.ContainsSubPath(ConfigurationManager.ApplicationPaths.DataPath, Path);
 66            }
 67        }
 68
 69        [JsonIgnore]
 070        public override bool IsPreSorted => true;
 71
 72        public Guid[] LibraryFolderIds { get; set; }
 73
 74        protected override bool GetBlockUnratedValue(User user)
 75        {
 076            return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Movie);
 77        }
 78
 79        public override double GetDefaultPrimaryImageAspectRatio()
 080            => 2.0 / 3;
 81
 82        public override UnratedItem GetBlockUnratedType()
 83        {
 084            return UnratedItem.Movie;
 85        }
 86
 87        protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
 88        {
 089            if (IsLegacyBoxSet)
 90            {
 091                return base.GetNonCachedChildren(directoryService);
 92            }
 93
 094            return Enumerable.Empty<BaseItem>();
 95        }
 96
 97        protected override IReadOnlyList<BaseItem> LoadChildren()
 98        {
 099            if (IsLegacyBoxSet)
 100            {
 0101                return base.LoadChildren();
 102            }
 103
 104            // Save a trip to the database
 0105            return [];
 106        }
 107
 108        public override bool IsAuthorizedToDelete(User user, List<Folder> allCollectionFolders)
 109        {
 0110            return user.HasPermission(PermissionKind.IsAdministrator) || user.HasPermission(PermissionKind.EnableCollect
 111        }
 112
 113        public override bool IsSaveLocalMetadataEnabled()
 114        {
 0115            return true;
 116        }
 117
 118        private IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user)
 119        {
 0120            if (!Enum.TryParse<ItemSortBy>(DisplayOrder, out var sortBy))
 121            {
 0122                sortBy = ItemSortBy.PremiereDate;
 123            }
 124
 0125            if (sortBy == ItemSortBy.Default)
 126            {
 0127              return items;
 128            }
 129
 0130            return LibraryManager.Sort(items, user, new[] { sortBy }, SortOrder.Ascending);
 131        }
 132
 133        public override IReadOnlyList<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery qu
 134        {
 0135            var children = base.GetChildren(user, includeLinkedChildren, query);
 0136            return Sort(children, user).ToArray();
 137        }
 138
 139        public override IReadOnlyList<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
 140        {
 0141            var children = base.GetRecursiveChildren(user, query);
 0142            return Sort(children, user).ToArray();
 143        }
 144
 145        public BoxSetInfo GetLookupInfo()
 146        {
 0147            return GetItemLookupInfo<BoxSetInfo>();
 148        }
 149
 150        public override bool IsVisible(User user, bool skipAllowedTagsCheck = false)
 151        {
 0152            if (IsLegacyBoxSet)
 153            {
 0154                return base.IsVisible(user, skipAllowedTagsCheck);
 155            }
 156
 0157            if (base.IsVisible(user, skipAllowedTagsCheck))
 158            {
 0159                if (LinkedChildren.Length == 0)
 160                {
 0161                    return true;
 162                }
 163
 0164                var userLibraryFolderIds = GetLibraryFolderIds(user);
 0165                var libraryFolderIds = LibraryFolderIds ?? GetLibraryFolderIds();
 166
 0167                if (libraryFolderIds.Length == 0)
 168                {
 0169                    return true;
 170                }
 171
 0172                return userLibraryFolderIds.Any(i => libraryFolderIds.Contains(i));
 173            }
 174
 0175            return false;
 176        }
 177
 178        public override bool IsVisibleStandalone(User user)
 179        {
 0180            if (IsLegacyBoxSet)
 181            {
 0182                return base.IsVisibleStandalone(user);
 183            }
 184
 0185            return IsVisible(user);
 186        }
 187
 188        private Guid[] GetLibraryFolderIds(User user)
 189        {
 0190            return LibraryManager.GetUserRootFolder().GetChildren(user, true)
 0191                .Select(i => i.Id)
 0192                .ToArray();
 193        }
 194
 195        public Guid[] GetLibraryFolderIds()
 196        {
 0197            var expandedFolders = new List<Guid>();
 198
 0199            return FlattenItems(this, expandedFolders)
 0200                .SelectMany(i => LibraryManager.GetCollectionFolders(i))
 0201                .Select(i => i.Id)
 0202                .Distinct()
 0203                .ToArray();
 204        }
 205
 206        private IEnumerable<BaseItem> FlattenItems(IEnumerable<BaseItem> items, List<Guid> expandedFolders)
 207        {
 0208            return items
 0209                .SelectMany(i => FlattenItems(i, expandedFolders));
 210        }
 211
 212        private IEnumerable<BaseItem> FlattenItems(BaseItem item, List<Guid> expandedFolders)
 213        {
 0214            if (item is BoxSet boxset)
 215            {
 0216                if (!expandedFolders.Contains(item.Id))
 217                {
 0218                    expandedFolders.Add(item.Id);
 219
 0220                    return FlattenItems(boxset.GetLinkedChildren(), expandedFolders);
 221                }
 222
 0223                return Array.Empty<BaseItem>();
 224            }
 225
 0226            return new[] { item };
 227        }
 228    }
 229}