< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.InternalItemsQuery
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/InternalItemsQuery.cs
Line coverage
73%
Covered lines: 71
Uncovered lines: 25
Coverable lines: 96
Total lines: 463
Line coverage: 73.9%
Branch coverage
38%
Covered branches: 12
Total branches: 31
Branch coverage: 38.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/26/2025 - 12:10:47 AM Line coverage: 98.4% (64/65) Branch coverage: 83.3% (5/6) Total lines: 39012/29/2025 - 12:13:19 AM Line coverage: 98.4% (64/65) Branch coverage: 83.3% (5/6) Total lines: 3923/14/2026 - 12:13:58 AM Line coverage: 73.9% (71/96) Branch coverage: 38.7% (12/31) Total lines: 463 12/26/2025 - 12:10:47 AM Line coverage: 98.4% (64/65) Branch coverage: 83.3% (5/6) Total lines: 39012/29/2025 - 12:13:19 AM Line coverage: 98.4% (64/65) Branch coverage: 83.3% (5/6) Total lines: 3923/14/2026 - 12:13:58 AM Line coverage: 73.9% (71/96) Branch coverage: 38.7% (12/31) Total lines: 463

Coverage delta

Coverage delta 45 -45

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
.ctor(...)100%22100%
set_Parent(...)100%22100%
SetUser(...)50%2294.11%
ApplyFilters(...)28%3152522.58%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Entities/InternalItemsQuery.cs

#LineLine coverage
 1#pragma warning disable CA1044, CA1819, CA2227, CS1591
 2
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using Diacritics.Extensions;
 7using Jellyfin.Data;
 8using Jellyfin.Data.Enums;
 9using Jellyfin.Database.Implementations.Entities;
 10using Jellyfin.Database.Implementations.Enums;
 11using MediaBrowser.Controller.Dto;
 12using MediaBrowser.Model.Entities;
 13using MediaBrowser.Model.Querying;
 14
 15namespace MediaBrowser.Controller.Entities
 16{
 17    public class InternalItemsQuery
 18    {
 19        public InternalItemsQuery()
 20        {
 45121            AlbumArtistIds = Array.Empty<Guid>();
 45122            AlbumIds = Array.Empty<Guid>();
 45123            AncestorIds = Array.Empty<Guid>();
 45124            ArtistIds = Array.Empty<Guid>();
 45125            BlockUnratedItems = Array.Empty<UnratedItem>();
 45126            BoxSetLibraryFolders = Array.Empty<Guid>();
 45127            ChannelIds = Array.Empty<Guid>();
 45128            ContributingArtistIds = Array.Empty<Guid>();
 45129            DtoOptions = new DtoOptions();
 45130            EnableTotalRecordCount = true;
 45131            ExcludeArtistIds = Array.Empty<Guid>();
 45132            ExcludeInheritedTags = Array.Empty<string>();
 45133            IncludeInheritedTags = Array.Empty<string>();
 45134            ExcludeItemIds = Array.Empty<Guid>();
 45135            ExcludeItemTypes = Array.Empty<BaseItemKind>();
 45136            ExcludeTags = Array.Empty<string>();
 45137            GenreIds = Array.Empty<Guid>();
 45138            Genres = Array.Empty<string>();
 45139            GroupByPresentationUniqueKey = true;
 45140            ImageTypes = Array.Empty<ImageType>();
 45141            IncludeItemTypes = Array.Empty<BaseItemKind>();
 45142            ItemIds = Array.Empty<Guid>();
 45143            MediaTypes = Array.Empty<MediaType>();
 45144            OfficialRatings = Array.Empty<string>();
 45145            OrderBy = Array.Empty<(ItemSortBy, SortOrder)>();
 45146            PersonIds = Array.Empty<Guid>();
 45147            PersonTypes = Array.Empty<string>();
 45148            PresetViews = Array.Empty<CollectionType?>();
 45149            SeriesStatuses = Array.Empty<SeriesStatus>();
 45150            SourceTypes = Array.Empty<SourceType>();
 45151            StudioIds = Array.Empty<Guid>();
 45152            Tags = Array.Empty<string>();
 45153            TopParentIds = Array.Empty<Guid>();
 45154            TrailerTypes = Array.Empty<TrailerType>();
 45155            VideoTypes = Array.Empty<VideoType>();
 45156            Years = Array.Empty<int>();
 45157            SkipDeserialization = false;
 45158        }
 59
 60        public InternalItemsQuery(User? user)
 261            : this()
 62        {
 263            if (user is not null)
 64            {
 265                SetUser(user);
 66            }
 267        }
 68
 69        public bool Recursive { get; set; }
 70
 71        public int? StartIndex { get; set; }
 72
 73        public int? Limit { get; set; }
 74
 75        public User? User { get; set; }
 76
 77        public bool? IsFolder { get; set; }
 78
 79        public bool? IsFavorite { get; set; }
 80
 81        public bool? IsFavoriteOrLiked { get; set; }
 82
 83        public bool? IsLiked { get; set; }
 84
 85        public bool? IsPlayed { get; set; }
 86
 87        public bool? IsResumable { get; set; }
 88
 89        public bool? IncludeItemsByName { get; set; }
 90
 91        public MediaType[] MediaTypes { get; set; }
 92
 93        public BaseItemKind[] IncludeItemTypes { get; set; }
 94
 95        public BaseItemKind[] ExcludeItemTypes { get; set; }
 96
 97        public string[] ExcludeTags { get; set; }
 98
 99        public string[] ExcludeInheritedTags { get; set; }
 100
 101        public string[] IncludeInheritedTags { get; set; }
 102
 103        public IReadOnlyList<string> Genres { get; set; }
 104
 105        public bool? IsSpecialSeason { get; set; }
 106
 107        public bool? IsMissing { get; set; }
 108
 109        public bool? IsUnaired { get; set; }
 110
 111        public bool? CollapseBoxSetItems { get; set; }
 112
 113        public string? NameStartsWithOrGreater { get; set; }
 114
 115        public string? NameStartsWith { get; set; }
 116
 117        public string? NameLessThan { get; set; }
 118
 119        public string? NameContains { get; set; }
 120
 121        public string? MinSortName { get; set; }
 122
 123        public string? PresentationUniqueKey { get; set; }
 124
 125        public string? Path { get; set; }
 126
 127        public string? Name { get; set; }
 128
 129        public bool? UseRawName { get; set; }
 130
 131        public string? Person { get; set; }
 132
 133        public Guid[] PersonIds { get; set; }
 134
 135        public Guid[] ItemIds { get; set; }
 136
 137        public Guid[] ExcludeItemIds { get; set; }
 138
 139        public Guid? AdjacentTo { get; set; }
 140
 141        public string[] PersonTypes { get; set; }
 142
 143        public bool? Is3D { get; set; }
 144
 145        public bool? IsHD { get; set; }
 146
 147        public bool? IsLocked { get; set; }
 148
 149        public bool? IsPlaceHolder { get; set; }
 150
 151        public bool? HasImdbId { get; set; }
 152
 153        public bool? HasOverview { get; set; }
 154
 155        public bool? HasTmdbId { get; set; }
 156
 157        public bool? HasOfficialRating { get; set; }
 158
 159        public bool? HasTvdbId { get; set; }
 160
 161        public bool? HasThemeSong { get; set; }
 162
 163        public bool? HasThemeVideo { get; set; }
 164
 165        public bool? HasSubtitles { get; set; }
 166
 167        public bool? HasSpecialFeature { get; set; }
 168
 169        public bool? HasTrailer { get; set; }
 170
 171        public bool? HasParentalRating { get; set; }
 172
 173        public Guid[] StudioIds { get; set; }
 174
 175        public IReadOnlyList<Guid> GenreIds { get; set; }
 176
 177        public ImageType[] ImageTypes { get; set; }
 178
 179        public VideoType[] VideoTypes { get; set; }
 180
 181        public UnratedItem[] BlockUnratedItems { get; set; }
 182
 183        public int[] Years { get; set; }
 184
 185        public string[] Tags { get; set; }
 186
 187        public string[] OfficialRatings { get; set; }
 188
 189        public DateTime? MinPremiereDate { get; set; }
 190
 191        public DateTime? MaxPremiereDate { get; set; }
 192
 193        public DateTime? MinStartDate { get; set; }
 194
 195        public DateTime? MaxStartDate { get; set; }
 196
 197        public DateTime? MinEndDate { get; set; }
 198
 199        public DateTime? MaxEndDate { get; set; }
 200
 201        public bool? IsAiring { get; set; }
 202
 203        public bool? IsMovie { get; set; }
 204
 205        public bool? IsSports { get; set; }
 206
 207        public bool? IsKids { get; set; }
 208
 209        public bool? IsNews { get; set; }
 210
 211        public bool? IsSeries { get; set; }
 212
 213        public int? MinIndexNumber { get; set; }
 214
 215        /// <summary>
 216        /// Gets or sets the minimum ParentIndexNumber and IndexNumber.
 217        /// </summary>
 218        /// <remarks>
 219        /// It produces this where clause:
 220        /// <para>(ParentIndexNumber = X and IndexNumber >= Y) or ParentIndexNumber > X.
 221        /// </para>
 222        /// </remarks>
 223        public (int ParentIndexNumber, int IndexNumber)? MinParentAndIndexNumber { get; set; }
 224
 225        public int? AiredDuringSeason { get; set; }
 226
 227        public double? MinCriticRating { get; set; }
 228
 229        public double? MinCommunityRating { get; set; }
 230
 231        public IReadOnlyList<Guid> ChannelIds { get; set; }
 232
 233        public int? ParentIndexNumber { get; set; }
 234
 235        public int? ParentIndexNumberNotEquals { get; set; }
 236
 237        public int? IndexNumber { get; set; }
 238
 239        public ParentalRatingScore? MinParentalRating { get; set; }
 240
 241        public ParentalRatingScore? MaxParentalRating { get; set; }
 242
 243        public bool? HasDeadParentId { get; set; }
 244
 245        public bool? IsVirtualItem { get; set; }
 246
 247        public Guid ParentId { get; set; }
 248
 249        public BaseItemKind? ParentType { get; set; }
 250
 251        public Guid[] AncestorIds { get; set; }
 252
 253        public Guid[] TopParentIds { get; set; }
 254
 255        public CollectionType?[] PresetViews { get; set; }
 256
 257        public TrailerType[] TrailerTypes { get; set; }
 258
 259        public SourceType[] SourceTypes { get; set; }
 260
 261        public SeriesStatus[] SeriesStatuses { get; set; }
 262
 263        public string? ExternalSeriesId { get; set; }
 264
 265        public string? ExternalId { get; set; }
 266
 267        public Guid[] AlbumIds { get; set; }
 268
 269        public Guid[] ArtistIds { get; set; }
 270
 271        public Guid[] ExcludeArtistIds { get; set; }
 272
 273        public string? AncestorWithPresentationUniqueKey { get; set; }
 274
 275        public string? SeriesPresentationUniqueKey { get; set; }
 276
 277        public bool GroupByPresentationUniqueKey { get; set; }
 278
 279        public bool GroupBySeriesPresentationUniqueKey { get; set; }
 280
 281        public bool EnableTotalRecordCount { get; set; }
 282
 283        public bool ForceDirect { get; set; }
 284
 285        public Dictionary<string, string>? ExcludeProviderIds { get; set; }
 286
 287        public bool EnableGroupByMetadataKey { get; set; }
 288
 289        public bool? HasChapterImages { get; set; }
 290
 291        public IReadOnlyList<(ItemSortBy OrderBy, SortOrder SortOrder)> OrderBy { get; set; }
 292
 293        public DateTime? MinDateCreated { get; set; }
 294
 295        public DateTime? MinDateLastSaved { get; set; }
 296
 297        public DateTime? MinDateLastSavedForUser { get; set; }
 298
 299        public DtoOptions DtoOptions { get; set; }
 300
 301        public string? HasNoAudioTrackWithLanguage { get; set; }
 302
 303        public string? HasNoInternalSubtitleTrackWithLanguage { get; set; }
 304
 305        public string? HasNoExternalSubtitleTrackWithLanguage { get; set; }
 306
 307        public string? HasNoSubtitleTrackWithLanguage { get; set; }
 308
 309        public bool? IsDeadArtist { get; set; }
 310
 311        public bool? IsDeadStudio { get; set; }
 312
 313        public bool? IsDeadGenre { get; set; }
 314
 315        public bool? IsDeadPerson { get; set; }
 316
 317        /// <summary>
 318        /// Gets or sets a value indicating whether album sub-folders should be returned if they exist.
 319        /// </summary>
 320        public bool? DisplayAlbumFolders { get; set; }
 321
 322        public BaseItem? Parent
 323        {
 324            set
 325            {
 266326                if (value is null)
 327                {
 60328                    ParentId = Guid.Empty;
 60329                    ParentType = null;
 330                }
 331                else
 332                {
 206333                    ParentId = value.Id;
 206334                    ParentType = value.GetBaseItemKind();
 335                }
 206336            }
 337        }
 338
 339        public Dictionary<string, string>? HasAnyProviderId { get; set; }
 340
 341        public Guid[] AlbumArtistIds { get; set; }
 342
 343        public Guid[] BoxSetLibraryFolders { get; set; }
 344
 345        public Guid[] ContributingArtistIds { get; set; }
 346
 347        public bool? HasAired { get; set; }
 348
 349        public bool? HasOwnerId { get; set; }
 350
 351        public bool? Is4K { get; set; }
 352
 353        public int? MaxHeight { get; set; }
 354
 355        public int? MaxWidth { get; set; }
 356
 357        public int? MinHeight { get; set; }
 358
 359        public int? MinWidth { get; set; }
 360
 361        public string? SearchTerm { get; set; }
 362
 363        public string? SeriesTimerId { get; set; }
 364
 365        public bool SkipDeserialization { get; set; }
 366
 367        public void SetUser(User user)
 368        {
 2369            var maxRating = user.MaxParentalRatingScore;
 2370            if (maxRating.HasValue)
 371            {
 0372                MaxParentalRating = new(maxRating.Value, user.MaxParentalRatingSubScore);
 373            }
 374
 2375            var other = UnratedItem.Other.ToString();
 2376            BlockUnratedItems = user.GetPreference(PreferenceKind.BlockUnratedItems)
 2377                .Where(i => i != other)
 2378                .Select(e => Enum.Parse<UnratedItem>(e, true)).ToArray();
 379
 2380            ExcludeInheritedTags = user.GetPreference(PreferenceKind.BlockedTags)
 2381                .Where(tag => !string.IsNullOrWhiteSpace(tag))
 2382                .Select(tag => tag.RemoveDiacritics().ToLowerInvariant())
 2383                .ToArray();
 384
 2385            IncludeInheritedTags = user.GetPreference(PreferenceKind.AllowedTags)
 2386                .Where(tag => !string.IsNullOrWhiteSpace(tag))
 2387                .Select(tag => tag.RemoveDiacritics().ToLowerInvariant())
 2388                .ToArray();
 389
 2390            User = user;
 2391        }
 392
 393        public void ApplyFilters(ItemFilter[] filters)
 394        {
 395            static void ThrowConflictingFilters()
 396                => throw new ArgumentException("Conflicting filters", nameof(filters));
 397
 9398            foreach (var filter in filters)
 399            {
 400                switch (filter)
 401                {
 402                    case ItemFilter.IsFolder:
 1403                        if (filters.Contains(ItemFilter.IsNotFolder))
 404                        {
 1405                            ThrowConflictingFilters();
 406                        }
 407
 0408                        IsFolder = true;
 0409                        break;
 410                    case ItemFilter.IsNotFolder:
 0411                        if (filters.Contains(ItemFilter.IsFolder))
 412                        {
 0413                            ThrowConflictingFilters();
 414                        }
 415
 0416                        IsFolder = false;
 0417                        break;
 418                    case ItemFilter.IsUnplayed:
 0419                        if (filters.Contains(ItemFilter.IsPlayed))
 420                        {
 0421                            ThrowConflictingFilters();
 422                        }
 423
 0424                        IsPlayed = false;
 0425                        break;
 426                    case ItemFilter.IsPlayed:
 1427                        if (filters.Contains(ItemFilter.IsUnplayed))
 428                        {
 1429                            ThrowConflictingFilters();
 430                        }
 431
 0432                        IsPlayed = true;
 0433                        break;
 434                    case ItemFilter.IsFavorite:
 0435                        IsFavorite = true;
 0436                        break;
 437                    case ItemFilter.IsResumable:
 0438                        IsResumable = true;
 0439                        break;
 440                    case ItemFilter.Likes:
 1441                        if (filters.Contains(ItemFilter.Dislikes))
 442                        {
 1443                            ThrowConflictingFilters();
 444                        }
 445
 0446                        IsLiked = true;
 0447                        break;
 448                    case ItemFilter.Dislikes:
 0449                        if (filters.Contains(ItemFilter.Likes))
 450                        {
 0451                            ThrowConflictingFilters();
 452                        }
 453
 0454                        IsLiked = false;
 0455                        break;
 456                    case ItemFilter.IsFavoriteOrLikes:
 0457                        IsFavoriteOrLiked = true;
 458                        break;
 459                }
 460            }
 0461        }
 462    }
 463}