/// <inheritdoc />
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var episode     = (Episode)item;
            var series      = episode.Series;
            var imageResult = new List <RemoteImageInfo>();
            var language    = item.GetPreferredMetadataLanguage();

            if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
            {
                // Process images
                try
                {
                    string?episodeTvdbId = null;

                    if (episode.IndexNumber.HasValue && episode.ParentIndexNumber.HasValue)
                    {
                        var episodeInfo = new EpisodeInfo
                        {
                            IndexNumber        = episode.IndexNumber.Value,
                            ParentIndexNumber  = episode.ParentIndexNumber.Value,
                            SeriesProviderIds  = series.ProviderIds,
                            SeriesDisplayOrder = series.DisplayOrder
                        };

                        episodeTvdbId = await _tvdbClientManager
                                        .GetEpisodeTvdbId(episodeInfo, language, cancellationToken).ConfigureAwait(false);
                    }

                    if (string.IsNullOrEmpty(episodeTvdbId))
                    {
                        _logger.LogError(
                            "Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
                            episode.ParentIndexNumber,
                            episode.IndexNumber,
                            series.GetProviderId(TvdbPlugin.ProviderId));
                        return(imageResult);
                    }

                    var episodeResult =
                        await _tvdbClientManager
                        .GetEpisodesAsync(Convert.ToInt32(episodeTvdbId, CultureInfo.InvariantCulture), language, cancellationToken)
                        .ConfigureAwait(false);

                    var image = GetImageInfo(episodeResult.Data);
                    if (image != null)
                    {
                        imageResult.Add(image);
                    }
                }
                catch (TvDbServerException e)
                {
                    _logger.LogError(e, "Failed to retrieve episode images for series {TvDbId}", series.GetProviderId(TvdbPlugin.ProviderId));
                }
            }

            return(imageResult);
        }
Example #2
0
        private async Task <MetadataResult <Episode> > GetEpisode(EpisodeInfo searchInfo, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Episode>
            {
                QueriedById = true
            };

            var    seriesTvdbId  = searchInfo.GetProviderId(TvdbPlugin.ProviderId);
            string?episodeTvdbId = null;

            try
            {
                episodeTvdbId = await _tvdbClientManager
                                .GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken)
                                .ConfigureAwait(false);

                if (string.IsNullOrEmpty(episodeTvdbId))
                {
                    _logger.LogError(
                        "Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
                        searchInfo.ParentIndexNumber,
                        searchInfo.IndexNumber,
                        seriesTvdbId);
                    return(result);
                }

                var episodeResult = await _tvdbClientManager.GetEpisodesAsync(
                    Convert.ToInt32(episodeTvdbId, CultureInfo.InvariantCulture),
                    searchInfo.MetadataLanguage,
                    cancellationToken).ConfigureAwait(false);

                result = MapEpisodeToResult(searchInfo, episodeResult.Data);
            }
            catch (TvDbServerException e)
            {
                _logger.LogError(e, "Failed to retrieve episode with id {EpisodeTvDbId}, series id {SeriesTvdbId}", episodeTvdbId, seriesTvdbId);
            }

            return(result);
        }