< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Plugins.Tmdb.TV.TmdbSeasonProvider
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs
Line coverage
50%
Covered lines: 3
Uncovered lines: 3
Coverable lines: 6
Total lines: 135
Line coverage: 50%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

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

File(s)

/srv/git/jellyfin/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4using System.Linq;
 5using System.Net.Http;
 6using System.Threading;
 7using System.Threading.Tasks;
 8using Jellyfin.Data.Enums;
 9using Jellyfin.Extensions;
 10using MediaBrowser.Common.Net;
 11using MediaBrowser.Controller.Entities;
 12using MediaBrowser.Controller.Entities.TV;
 13using MediaBrowser.Controller.Providers;
 14using MediaBrowser.Model.Entities;
 15using MediaBrowser.Model.Providers;
 16
 17namespace MediaBrowser.Providers.Plugins.Tmdb.TV
 18{
 19    /// <summary>
 20    /// TV season provider powered by TheMovieDb.
 21    /// </summary>
 22    public class TmdbSeasonProvider : IRemoteMetadataProvider<Season, SeasonInfo>
 23    {
 24        private readonly IHttpClientFactory _httpClientFactory;
 25        private readonly TmdbClientManager _tmdbClientManager;
 26
 27        /// <summary>
 28        /// Initializes a new instance of the <see cref="TmdbSeasonProvider"/> class.
 29        /// </summary>
 30        /// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param>
 31        /// <param name="tmdbClientManager">The <see cref="TmdbClientManager"/>.</param>
 32        public TmdbSeasonProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
 33        {
 2234            _httpClientFactory = httpClientFactory;
 2235            _tmdbClientManager = tmdbClientManager;
 2236        }
 37
 38        /// <inheritdoc />
 039        public string Name => TmdbUtils.ProviderName;
 40
 41        /// <inheritdoc />
 42        public async Task<MetadataResult<Season>> GetMetadata(SeasonInfo info, CancellationToken cancellationToken)
 43        {
 44            var result = new MetadataResult<Season>();
 45
 46            info.SeriesProviderIds.TryGetValue(MetadataProvider.Tmdb.ToString(), out string? seriesTmdbId);
 47
 48            var seasonNumber = info.IndexNumber;
 49
 50            if (string.IsNullOrWhiteSpace(seriesTmdbId) || !seasonNumber.HasValue)
 51            {
 52                return result;
 53            }
 54
 55            var seasonResult = await _tmdbClientManager
 56                .GetSeasonAsync(Convert.ToInt32(seriesTmdbId, CultureInfo.InvariantCulture), seasonNumber.Value, info.Me
 57                .ConfigureAwait(false);
 58
 59            if (seasonResult is null)
 60            {
 61                return result;
 62            }
 63
 64            result.HasMetadata = true;
 65            result.Item = new Season
 66            {
 67                IndexNumber = seasonNumber,
 68                Overview = seasonResult.Overview
 69            };
 70
 71            if (Plugin.Instance.Configuration.ImportSeasonName)
 72            {
 73                result.Item.Name = seasonResult.Name;
 74            }
 75
 76            result.Item.TrySetProviderId(MetadataProvider.Tvdb, seasonResult.ExternalIds.TvdbId);
 77
 78            // TODO why was this disabled?
 79            var credits = seasonResult.Credits;
 80            if (credits?.Cast is not null)
 81            {
 82                var cast = credits.Cast.OrderBy(c => c.Order).Take(Plugin.Instance.Configuration.MaxCastMembers).ToList(
 83                for (var i = 0; i < cast.Count; i++)
 84                {
 85                    result.AddPerson(new PersonInfo
 86                    {
 87                        Name = cast[i].Name.Trim(),
 88                        Role = cast[i].Character,
 89                        Type = PersonKind.Actor,
 90                        SortOrder = cast[i].Order
 91                    });
 92                }
 93            }
 94
 95            if (credits?.Crew is not null)
 96            {
 97                foreach (var person in credits.Crew)
 98                {
 99                    // Normalize this
 100                    var type = TmdbUtils.MapCrewToPersonType(person);
 101
 102                    if (!TmdbUtils.WantedCrewKinds.Contains(type)
 103                        && !TmdbUtils.WantedCrewTypes.Contains(person.Job ?? string.Empty, StringComparison.OrdinalIgnor
 104                    {
 105                        continue;
 106                    }
 107
 108                    result.AddPerson(new PersonInfo
 109                    {
 110                        Name = person.Name.Trim(),
 111                        Role = person.Job,
 112                        Type = type
 113                    });
 114                }
 115            }
 116
 117            result.Item.PremiereDate = seasonResult.AirDate;
 118            result.Item.ProductionYear = seasonResult.AirDate?.Year;
 119
 120            return result;
 121        }
 122
 123        /// <inheritdoc />
 124        public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeasonInfo searchInfo, CancellationToken cancellat
 125        {
 0126            return Task.FromResult(Enumerable.Empty<RemoteSearchResult>());
 127        }
 128
 129        /// <inheritdoc />
 130        public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
 131        {
 0132            return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
 133        }
 134    }
 135}