< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.Item.ItemCountBuilder
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/Item/ItemCountBuilder.cs
Line coverage
90%
Covered lines: 30
Uncovered lines: 3
Coverable lines: 33
Total lines: 96
Line coverage: 90.9%
Branch coverage
87%
Covered branches: 21
Total branches: 24
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/29/2026 - 12:17:11 AM Line coverage: 90.9% (30/33) Branch coverage: 87.5% (21/24) Total lines: 96 10/29/2026 - 12:17:11 AM Line coverage: 90.9% (30/33) Branch coverage: 87.5% (21/24) Total lines: 96

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Build(...)87.5%252489.65%
SetEpisodeCount(...)100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/Item/ItemCountBuilder.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using Jellyfin.Data.Enums;
 4using MediaBrowser.Controller.Persistence;
 5using MediaBrowser.Model.Dto;
 6
 7namespace Jellyfin.Server.Implementations.Item;
 8
 9/// <summary>
 10/// Turns per-type counts into an <see cref="ItemCounts"/>.
 11/// </summary>
 12internal static class ItemCountBuilder
 13{
 14    /// <summary>
 15    /// Builds the counts of one by-name item.
 16    /// </summary>
 17    /// <param name="itemTypeLookup">The item type lookup.</param>
 18    /// <param name="counts">The counted items, by type name. A type may repeat.</param>
 19    /// <returns>The counts.</returns>
 20    public static ItemCounts Build(IItemTypeLookup itemTypeLookup, IEnumerable<(string Type, int Count)> counts)
 21    {
 5722        ArgumentNullException.ThrowIfNull(itemTypeLookup);
 5723        ArgumentNullException.ThrowIfNull(counts);
 24
 5725        var lookup = itemTypeLookup.BaseItemKindNames;
 5726        var result = new ItemCounts();
 27
 24428        foreach (var (type, count) in counts)
 29        {
 30            // Accumulated rather than assigned: a caller may group by something finer than the
 31            // type and hand the same type over more than once.
 6532            if (string.Equals(type, lookup[BaseItemKind.MusicAlbum], StringComparison.Ordinal))
 33            {
 834                result.AlbumCount += count;
 35            }
 5736            else if (string.Equals(type, lookup[BaseItemKind.MusicArtist], StringComparison.Ordinal))
 37            {
 138                result.ArtistCount += count;
 39            }
 5640            else if (string.Equals(type, lookup[BaseItemKind.Episode], StringComparison.Ordinal))
 41            {
 842                result.EpisodeCount += count;
 43            }
 4844            else if (string.Equals(type, lookup[BaseItemKind.Movie], StringComparison.Ordinal))
 45            {
 2946                result.MovieCount += count;
 47            }
 1948            else if (string.Equals(type, lookup[BaseItemKind.MusicVideo], StringComparison.Ordinal))
 49            {
 050                result.MusicVideoCount += count;
 51            }
 1952            else if (string.Equals(type, lookup[BaseItemKind.LiveTvProgram], StringComparison.Ordinal))
 53            {
 054                result.ProgramCount += count;
 55            }
 1956            else if (string.Equals(type, lookup[BaseItemKind.Series], StringComparison.Ordinal))
 57            {
 758                result.SeriesCount += count;
 59            }
 1260            else if (string.Equals(type, lookup[BaseItemKind.Audio], StringComparison.Ordinal))
 61            {
 1062                result.SongCount += count;
 63            }
 264            else if (string.Equals(type, lookup[BaseItemKind.Trailer], StringComparison.Ordinal))
 65            {
 066                result.TrailerCount += count;
 67            }
 268            else if (string.Equals(type, lookup[BaseItemKind.BoxSet], StringComparison.Ordinal))
 69            {
 170                result.BoxSetCount += count;
 71            }
 172            else if (string.Equals(type, lookup[BaseItemKind.Book], StringComparison.Ordinal))
 73            {
 174                result.BookCount += count;
 75            }
 76        }
 77
 5778        result.ItemCount = result.TotalItemCount();
 79
 5780        return result;
 81    }
 82
 83    /// <summary>
 84    /// Replaces the episode count, which both by-name paths decide separately from the other
 85    /// types because a genre or studio is usually written on the series rather than its episodes.
 86    /// </summary>
 87    /// <param name="counts">The counts to update.</param>
 88    /// <param name="episodeCount">The episode count.</param>
 89    public static void SetEpisodeCount(ItemCounts counts, int episodeCount)
 90    {
 2891        ArgumentNullException.ThrowIfNull(counts);
 92
 2893        counts.EpisodeCount = episodeCount;
 2894        counts.ItemCount = counts.TotalItemCount();
 2895    }
 96}