< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.InternalItemsQuery
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/InternalItemsQuery.cs
Line coverage
74%
Covered lines: 74
Uncovered lines: 25
Coverable lines: 99
Total lines: 484
Line coverage: 74.7%
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 1/23/2026 - 12:11:06 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: 4635/4/2026 - 12:15:16 AM Line coverage: 74.7% (74/99) Branch coverage: 38.7% (12/31) Total lines: 484 1/23/2026 - 12:11:06 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: 4635/4/2026 - 12:15:16 AM Line coverage: 74.7% (74/99) Branch coverage: 38.7% (12/31) Total lines: 484

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        {
 55421            AlbumArtistIds = [];
 55422            AlbumIds = [];
 55423            AncestorIds = [];
 55424            ArtistIds = [];
 55425            BlockUnratedItems = [];
 55426            BoxSetLibraryFolders = [];
 55427            ChannelIds = [];
 55428            ContributingArtistIds = [];
 55429            DtoOptions = new DtoOptions();
 55430            EnableTotalRecordCount = true;
 55431            ExcludeArtistIds = [];
 55432            ExcludeInheritedTags = [];
 55433            IncludeInheritedTags = [];
 55434            ExcludeItemIds = [];
 55435            ExcludeItemTypes = [];
 55436            ExcludeTags = [];
 55437            GenreIds = [];
 55438            Genres = [];
 55439            GroupByPresentationUniqueKey = true;
 55440            ImageTypes = [];
 55441            IncludeItemTypes = [];
 55442            ItemIds = [];
 55443            OwnerIds = [];
 55444            ExtraTypes = [];
 55445            MediaTypes = [];
 55446            OfficialRatings = [];
 55447            OrderBy = [];
 55448            OwnerIds = [];
 55449            PersonIds = [];
 55450            PersonTypes = [];
 55451            PresetViews = [];
 55452            SeriesStatuses = [];
 55453            SourceTypes = [];
 55454            StudioIds = [];
 55455            Tags = [];
 55456            TopParentIds = [];
 55457            TrailerTypes = [];
 55458            VideoTypes = [];
 55459            Years = [];
 55460            SkipDeserialization = false;
 55461        }
 62
 63        public InternalItemsQuery(User? user)
 264            : this()
 65        {
 266            if (user is not null)
 67            {
 268                SetUser(user);
 69            }
 270        }
 71
 72        public bool Recursive { get; set; }
 73
 74        public int? StartIndex { get; set; }
 75
 76        public int? Limit { get; set; }
 77
 78        public User? User { get; set; }
 79
 80        public bool? IsFolder { get; set; }
 81
 82        public bool? IsFavorite { get; set; }
 83
 84        public bool? IsFavoriteOrLiked { get; set; }
 85
 86        public bool? IsLiked { get; set; }
 87
 88        public bool? IsPlayed { get; set; }
 89
 90        public bool? IsResumable { get; set; }
 91
 92        public bool? IncludeItemsByName { get; set; }
 93
 94        public MediaType[] MediaTypes { get; set; }
 95
 96        public BaseItemKind[] IncludeItemTypes { get; set; }
 97
 98        public BaseItemKind[] ExcludeItemTypes { get; set; }
 99
 100        public string[] ExcludeTags { get; set; }
 101
 102        public string[] ExcludeInheritedTags { get; set; }
 103
 104        public string[] IncludeInheritedTags { get; set; }
 105
 106        public IReadOnlyList<string> Genres { get; set; }
 107
 108        public bool? IsSpecialSeason { get; set; }
 109
 110        public bool? IsMissing { get; set; }
 111
 112        public bool? IsUnaired { get; set; }
 113
 114        public bool? CollapseBoxSetItems { get; set; }
 115
 116        /// <summary>
 117        /// Gets or sets the item types that should be collapsed into box sets.
 118        /// When empty, all types are collapsed. When set, only items of these types are replaced by their parent box se
 119        /// </summary>
 120        public BaseItemKind[] CollapseBoxSetItemTypes { get; set; } = [];
 121
 122        public string? NameStartsWithOrGreater { get; set; }
 123
 124        public string? NameStartsWith { get; set; }
 125
 126        public string? NameLessThan { get; set; }
 127
 128        public string? NameContains { get; set; }
 129
 130        public string? MinSortName { get; set; }
 131
 132        public string? PresentationUniqueKey { get; set; }
 133
 134        public string? Path { get; set; }
 135
 136        public string? Name { get; set; }
 137
 138        public bool? UseRawName { get; set; }
 139
 140        public string? Person { get; set; }
 141
 142        public Guid[] PersonIds { get; set; }
 143
 144        public Guid[] ItemIds { get; set; }
 145
 146        public Guid[] OwnerIds { get; set; }
 147
 148        public ExtraType[] ExtraTypes { get; set; }
 149
 150        public Guid[] ExcludeItemIds { get; set; }
 151
 152        public Guid? AdjacentTo { get; set; }
 153
 154        public string[] PersonTypes { get; set; }
 155
 156        public bool? Is3D { get; set; }
 157
 158        public bool? IsHD { get; set; }
 159
 160        public bool? IsLocked { get; set; }
 161
 162        public bool? IsPlaceHolder { get; set; }
 163
 164        public bool? HasImdbId { get; set; }
 165
 166        public bool? HasOverview { get; set; }
 167
 168        public bool? HasTmdbId { get; set; }
 169
 170        public bool? HasOfficialRating { get; set; }
 171
 172        public bool? HasTvdbId { get; set; }
 173
 174        public bool? HasThemeSong { get; set; }
 175
 176        public bool? HasThemeVideo { get; set; }
 177
 178        public bool? HasSubtitles { get; set; }
 179
 180        public bool? HasSpecialFeature { get; set; }
 181
 182        public bool? HasTrailer { get; set; }
 183
 184        public bool? HasParentalRating { get; set; }
 185
 186        public Guid[] StudioIds { get; set; }
 187
 188        public IReadOnlyList<Guid> GenreIds { get; set; }
 189
 190        public ImageType[] ImageTypes { get; set; }
 191
 192        public VideoType[] VideoTypes { get; set; }
 193
 194        public UnratedItem[] BlockUnratedItems { get; set; }
 195
 196        public int[] Years { get; set; }
 197
 198        public string[] Tags { get; set; }
 199
 200        public string[] OfficialRatings { get; set; }
 201
 202        public DateTime? MinPremiereDate { get; set; }
 203
 204        public DateTime? MaxPremiereDate { get; set; }
 205
 206        public DateTime? MinStartDate { get; set; }
 207
 208        public DateTime? MaxStartDate { get; set; }
 209
 210        public DateTime? MinEndDate { get; set; }
 211
 212        public DateTime? MaxEndDate { get; set; }
 213
 214        public bool? IsAiring { get; set; }
 215
 216        public bool? IsMovie { get; set; }
 217
 218        public bool? IsSports { get; set; }
 219
 220        public bool? IsKids { get; set; }
 221
 222        public bool? IsNews { get; set; }
 223
 224        public bool? IsSeries { get; set; }
 225
 226        public int? MinIndexNumber { get; set; }
 227
 228        /// <summary>
 229        /// Gets or sets the minimum ParentIndexNumber and IndexNumber.
 230        /// </summary>
 231        /// <remarks>
 232        /// It produces this where clause:
 233        /// <para>(ParentIndexNumber = X and IndexNumber >= Y) or ParentIndexNumber > X.
 234        /// </para>
 235        /// </remarks>
 236        public (int ParentIndexNumber, int IndexNumber)? MinParentAndIndexNumber { get; set; }
 237
 238        public int? AiredDuringSeason { get; set; }
 239
 240        public double? MinCriticRating { get; set; }
 241
 242        public double? MinCommunityRating { get; set; }
 243
 244        public IReadOnlyList<Guid> ChannelIds { get; set; }
 245
 246        public int? ParentIndexNumber { get; set; }
 247
 248        public int? ParentIndexNumberNotEquals { get; set; }
 249
 250        public int? IndexNumber { get; set; }
 251
 252        public ParentalRatingScore? MinParentalRating { get; set; }
 253
 254        public ParentalRatingScore? MaxParentalRating { get; set; }
 255
 256        public bool? HasDeadParentId { get; set; }
 257
 258        public bool? IsVirtualItem { get; set; }
 259
 260        public Guid ParentId { get; set; }
 261
 262        public BaseItemKind? ParentType { get; set; }
 263
 264        public Guid[] AncestorIds { get; set; }
 265
 266        public Guid[] TopParentIds { get; set; }
 267
 268        public CollectionType?[] PresetViews { get; set; }
 269
 270        public TrailerType[] TrailerTypes { get; set; }
 271
 272        public SourceType[] SourceTypes { get; set; }
 273
 274        public SeriesStatus[] SeriesStatuses { get; set; }
 275
 276        public string? ExternalSeriesId { get; set; }
 277
 278        public string? ExternalId { get; set; }
 279
 280        public Guid[] AlbumIds { get; set; }
 281
 282        public Guid[] ArtistIds { get; set; }
 283
 284        public Guid[] ExcludeArtistIds { get; set; }
 285
 286        public string? AncestorWithPresentationUniqueKey { get; set; }
 287
 288        public string? SeriesPresentationUniqueKey { get; set; }
 289
 290        public bool GroupByPresentationUniqueKey { get; set; }
 291
 292        public bool GroupBySeriesPresentationUniqueKey { get; set; }
 293
 294        public bool EnableTotalRecordCount { get; set; }
 295
 296        public bool ForceDirect { get; set; }
 297
 298        public Dictionary<string, string>? ExcludeProviderIds { get; set; }
 299
 300        public bool EnableGroupByMetadataKey { get; set; }
 301
 302        public bool? HasChapterImages { get; set; }
 303
 304        public IReadOnlyList<(ItemSortBy OrderBy, SortOrder SortOrder)> OrderBy { get; set; }
 305
 306        public DateTime? MinDateCreated { get; set; }
 307
 308        public DateTime? MinDateLastSaved { get; set; }
 309
 310        public DateTime? MinDateLastSavedForUser { get; set; }
 311
 312        public DtoOptions DtoOptions { get; set; }
 313
 314        public string? HasNoAudioTrackWithLanguage { get; set; }
 315
 316        public string? HasNoInternalSubtitleTrackWithLanguage { get; set; }
 317
 318        public string? HasNoExternalSubtitleTrackWithLanguage { get; set; }
 319
 320        public string? HasNoSubtitleTrackWithLanguage { get; set; }
 321
 322        public bool? IsDeadArtist { get; set; }
 323
 324        public bool? IsDeadStudio { get; set; }
 325
 326        public bool? IsDeadGenre { get; set; }
 327
 328        public bool? IsDeadPerson { get; set; }
 329
 330        /// <summary>
 331        /// Gets or sets a value indicating whether album sub-folders should be returned if they exist.
 332        /// </summary>
 333        public bool? DisplayAlbumFolders { get; set; }
 334
 335        public BaseItem? Parent
 336        {
 337            set
 338            {
 257339                if (value is null)
 340                {
 57341                    ParentId = Guid.Empty;
 57342                    ParentType = null;
 343                }
 344                else
 345                {
 200346                    ParentId = value.Id;
 200347                    ParentType = value.GetBaseItemKind();
 348                }
 200349            }
 350        }
 351
 352        public Dictionary<string, string>? HasAnyProviderId { get; set; }
 353
 354        public Guid[] AlbumArtistIds { get; set; }
 355
 356        public Guid[] BoxSetLibraryFolders { get; set; }
 357
 358        public Guid[] ContributingArtistIds { get; set; }
 359
 360        public bool? HasAired { get; set; }
 361
 362        public bool? HasOwnerId { get; set; }
 363
 364        /// <summary>
 365        /// Gets or sets a value indicating whether to include items with an OwnerId
 366        /// (additional parts, alternate versions) that are normally excluded from general queries.
 367        /// </summary>
 368        public bool IncludeOwnedItems { get; set; }
 369
 370        public bool? Is4K { get; set; }
 371
 372        public int? MaxHeight { get; set; }
 373
 374        public int? MaxWidth { get; set; }
 375
 376        public int? MinHeight { get; set; }
 377
 378        public int? MinWidth { get; set; }
 379
 380        public string? SearchTerm { get; set; }
 381
 382        public string? SeriesTimerId { get; set; }
 383
 384        public bool SkipDeserialization { get; set; }
 385
 386        public bool IncludeExtras { get; set; }
 387
 388        public void SetUser(User user)
 389        {
 2390            var maxRating = user.MaxParentalRatingScore;
 2391            if (maxRating.HasValue)
 392            {
 0393                MaxParentalRating = new(maxRating.Value, user.MaxParentalRatingSubScore);
 394            }
 395
 2396            var other = UnratedItem.Other.ToString();
 2397            BlockUnratedItems = user.GetPreference(PreferenceKind.BlockUnratedItems)
 2398                .Where(i => i != other)
 2399                .Select(e => Enum.Parse<UnratedItem>(e, true)).ToArray();
 400
 2401            ExcludeInheritedTags = user.GetPreference(PreferenceKind.BlockedTags)
 2402                .Where(tag => !string.IsNullOrWhiteSpace(tag))
 2403                .Select(tag => tag.RemoveDiacritics().ToLowerInvariant())
 2404                .ToArray();
 405
 2406            IncludeInheritedTags = user.GetPreference(PreferenceKind.AllowedTags)
 2407                .Where(tag => !string.IsNullOrWhiteSpace(tag))
 2408                .Select(tag => tag.RemoveDiacritics().ToLowerInvariant())
 2409                .ToArray();
 410
 2411            User = user;
 2412        }
 413
 414        public void ApplyFilters(ItemFilter[] filters)
 415        {
 416            static void ThrowConflictingFilters()
 417                => throw new ArgumentException("Conflicting filters", nameof(filters));
 418
 9419            foreach (var filter in filters)
 420            {
 421                switch (filter)
 422                {
 423                    case ItemFilter.IsFolder:
 1424                        if (filters.Contains(ItemFilter.IsNotFolder))
 425                        {
 1426                            ThrowConflictingFilters();
 427                        }
 428
 0429                        IsFolder = true;
 0430                        break;
 431                    case ItemFilter.IsNotFolder:
 0432                        if (filters.Contains(ItemFilter.IsFolder))
 433                        {
 0434                            ThrowConflictingFilters();
 435                        }
 436
 0437                        IsFolder = false;
 0438                        break;
 439                    case ItemFilter.IsUnplayed:
 0440                        if (filters.Contains(ItemFilter.IsPlayed))
 441                        {
 0442                            ThrowConflictingFilters();
 443                        }
 444
 0445                        IsPlayed = false;
 0446                        break;
 447                    case ItemFilter.IsPlayed:
 1448                        if (filters.Contains(ItemFilter.IsUnplayed))
 449                        {
 1450                            ThrowConflictingFilters();
 451                        }
 452
 0453                        IsPlayed = true;
 0454                        break;
 455                    case ItemFilter.IsFavorite:
 0456                        IsFavorite = true;
 0457                        break;
 458                    case ItemFilter.IsResumable:
 0459                        IsResumable = true;
 0460                        break;
 461                    case ItemFilter.Likes:
 1462                        if (filters.Contains(ItemFilter.Dislikes))
 463                        {
 1464                            ThrowConflictingFilters();
 465                        }
 466
 0467                        IsLiked = true;
 0468                        break;
 469                    case ItemFilter.Dislikes:
 0470                        if (filters.Contains(ItemFilter.Likes))
 471                        {
 0472                            ThrowConflictingFilters();
 473                        }
 474
 0475                        IsLiked = false;
 0476                        break;
 477                    case ItemFilter.IsFavoriteOrLikes:
 0478                        IsFavoriteOrLiked = true;
 479                        break;
 480                }
 481            }
 0482        }
 483    }
 484}