< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Plugins.Tmdb.BoxSets.TmdbBoxSetProvider
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetProvider.cs
Line coverage
6%
Covered lines: 4
Uncovered lines: 58
Coverable lines: 62
Total lines: 150
Line coverage: 6.4%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 5/16/2026 - 12:15:55 AM Line coverage: 6.7% (4/59) Branch coverage: 0% (0/20) Total lines: 14810/29/2026 - 12:17:11 AM Line coverage: 6.4% (4/62) Branch coverage: 0% (0/20) Total lines: 150 5/16/2026 - 12:15:55 AM Line coverage: 6.7% (4/59) Branch coverage: 0% (0/20) Total lines: 14810/29/2026 - 12:17:11 AM Line coverage: 6.4% (4/62) Branch coverage: 0% (0/20) Total lines: 150

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%210%
GetSearchResults()0%110100%
GetMetadata()0%110100%
GetImageResponse(...)100%210%

File(s)

/srv/git/jellyfin/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetProvider.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Globalization;
 3using System.Linq;
 4using System.Net.Http;
 5using System.Threading;
 6using System.Threading.Tasks;
 7using MediaBrowser.Common.Net;
 8using MediaBrowser.Controller.Entities.Movies;
 9using MediaBrowser.Controller.Library;
 10using MediaBrowser.Controller.Providers;
 11using MediaBrowser.Model.Entities;
 12using MediaBrowser.Model.Providers;
 13
 14namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
 15{
 16    /// <summary>
 17    /// BoxSet provider powered by TMDb.
 18    /// </summary>
 19    public class TmdbBoxSetProvider : IRemoteMetadataProvider<BoxSet, BoxSetInfo>
 20    {
 21        private readonly IHttpClientFactory _httpClientFactory;
 22        private readonly TmdbClientManager _tmdbClientManager;
 23        private readonly ILibraryManager _libraryManager;
 24
 25        /// <summary>
 26        /// Initializes a new instance of the <see cref="TmdbBoxSetProvider"/> class.
 27        /// </summary>
 28        /// <param name="libraryManager">The <see cref="ILibraryManager"/>.</param>
 29        /// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param>
 30        /// <param name="tmdbClientManager">The <see cref="TmdbClientManager"/>.</param>
 31        public TmdbBoxSetProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager, ILibraryMan
 32        {
 2733            _httpClientFactory = httpClientFactory;
 2734            _tmdbClientManager = tmdbClientManager;
 2735            _libraryManager = libraryManager;
 2736        }
 37
 38        /// <inheritdoc />
 039        public string Name => TmdbUtils.ProviderName;
 40
 41        /// <inheritdoc />
 42        public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(BoxSetInfo searchInfo, CancellationToken can
 43        {
 044            searchInfo.TryGetTmdbId(out var tmdbId);
 045            var language = searchInfo.MetadataLanguage;
 46
 047            if (tmdbId > 0)
 48            {
 049                var collection = await _tmdbClientManager.GetCollectionAsync(tmdbId, language, TmdbUtils.GetImageLanguag
 50
 051                if (collection is null)
 52                {
 053                    return Enumerable.Empty<RemoteSearchResult>();
 54                }
 55
 056                var result = new RemoteSearchResult
 057                {
 058                    Name = collection.Name,
 059                    SearchProviderName = Name
 060                };
 61
 062                if (collection.Images is not null)
 63                {
 064                    result.ImageUrl = _tmdbClientManager.GetPosterUrl(collection.PosterPath);
 65                }
 66
 067                result.SetProviderId(MetadataProvider.Tmdb, collection.Id.ToString(CultureInfo.InvariantCulture));
 68
 069                return [result];
 70            }
 71
 072            var collectionSearchResults = await _tmdbClientManager.SearchCollectionAsync(searchInfo.Name, language, sear
 073            if (collectionSearchResults is null)
 74            {
 075                return [];
 76            }
 77
 078            var collections = new RemoteSearchResult[collectionSearchResults.Count];
 079            for (var i = 0; i < collectionSearchResults.Count; i++)
 80            {
 081                var result = collectionSearchResults[i];
 082                var collection = new RemoteSearchResult
 083                {
 084                    Name = result.Name,
 085                    SearchProviderName = Name,
 086                    ImageUrl = _tmdbClientManager.GetPosterUrl(result.PosterPath)
 087                };
 088                collection.SetProviderId(MetadataProvider.Tmdb, result.Id.ToString(CultureInfo.InvariantCulture));
 89
 090                collections[i] = collection;
 91            }
 92
 093            return collections;
 094        }
 95
 96        /// <inheritdoc />
 97        public async Task<MetadataResult<BoxSet>> GetMetadata(BoxSetInfo info, CancellationToken cancellationToken)
 98        {
 099            info.TryGetTmdbId(out var tmdbId);
 0100            var language = info.MetadataLanguage;
 101
 102            // We don't already have an Id, need to fetch it
 0103            if (tmdbId <= 0)
 104            {
 105                // ParseName is required here.
 106                // Caller provides the filename with extension stripped and NOT the parsed filename
 0107                var parsedName = _libraryManager.ParseName(info.Name);
 0108                var cleanedName = TmdbUtils.CleanName(parsedName.Name);
 0109                var searchResults = await _tmdbClientManager.SearchCollectionAsync(cleanedName, language, info.MetadataC
 110
 0111                if (searchResults is not null && searchResults.Count > 0)
 112                {
 0113                    tmdbId = searchResults[0].Id;
 114                }
 115            }
 116
 0117            var result = new MetadataResult<BoxSet>
 0118            {
 0119                ResultLanguage = language
 0120            };
 121
 0122            if (tmdbId > 0)
 123            {
 0124                var collection = await _tmdbClientManager.GetCollectionAsync(tmdbId, language, TmdbUtils.GetImageLanguag
 125
 0126                if (collection is not null)
 127                {
 0128                    var item = new BoxSet
 0129                    {
 0130                        Name = collection.Name,
 0131                        Overview = collection.Overview
 0132                    };
 133
 0134                    item.SetProviderId(MetadataProvider.Tmdb, collection.Id.ToString(CultureInfo.InvariantCulture));
 135
 0136                    result.HasMetadata = true;
 0137                    result.Item = item;
 138                }
 139            }
 140
 0141            return result;
 0142        }
 143
 144        /// <inheritdoc />
 145        public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
 146        {
 0147            return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
 148        }
 149    }
 150}