private async Task FetchSeriesData(MetadataResult <Series> result, string metadataLanguage, Dictionary <string, string> seriesProviderIds, CancellationToken cancellationToken)
        {
            var series = result.Item;

            if (seriesProviderIds.TryGetValue(TvdbPlugin.ProviderName, out var tvdbId) && !string.IsNullOrEmpty(tvdbId))
            {
                series.SetProviderId(TvdbPlugin.ProviderName, tvdbId);
            }

            if (seriesProviderIds.TryGetValue(MetadataProvider.Imdb.ToString(), out var imdbId) && !string.IsNullOrEmpty(imdbId))
            {
                series.SetProviderId(MetadataProvider.Imdb, imdbId);
                tvdbId = await GetSeriesByRemoteId(
                    imdbId,
                    MetadataProvider.Imdb.ToString(),
                    metadataLanguage,
                    cancellationToken).ConfigureAwait(false);
            }

            if (seriesProviderIds.TryGetValue(MetadataProvider.Zap2It.ToString(), out var zap2It) && !string.IsNullOrEmpty(zap2It))
            {
                series.SetProviderId(MetadataProvider.Zap2It, zap2It);
                tvdbId = await GetSeriesByRemoteId(
                    zap2It,
                    MetadataProvider.Zap2It.ToString(),
                    metadataLanguage,
                    cancellationToken).ConfigureAwait(false);
            }

            try
            {
                var seriesResult =
                    await _tvdbClientManager
                    .GetSeriesByIdAsync(Convert.ToInt32(tvdbId, CultureInfo.InvariantCulture), metadataLanguage, cancellationToken)
                    .ConfigureAwait(false);

                MapSeriesToResult(result, seriesResult.Data, metadataLanguage);
            }
            catch (TvDbServerException e)
            {
                _logger.LogError(e, "Failed to retrieve series with id {TvdbId}", tvdbId);
                return;
            }

            cancellationToken.ThrowIfCancellationRequested();

            result.ResetPeople();

            try
            {
                var actorsResult = await _tvdbClientManager
                                   .GetActorsAsync(Convert.ToInt32(tvdbId, CultureInfo.InvariantCulture), metadataLanguage, cancellationToken).ConfigureAwait(false);

                MapActorsToResult(result, actorsResult.Data);
            }
            catch (TvDbServerException e)
            {
                _logger.LogError(e, "Failed to retrieve actors for series {TvdbId}", tvdbId);
            }
        }
Exemple #2
0
        private async Task <IEnumerable <RemoteSearchResult> > FetchSeriesSearchResult(SeriesInfo seriesInfo, CancellationToken cancellationToken)
        {
            var tvdbId = seriesInfo.GetProviderId(MetadataProvider.Tvdb);

            if (string.IsNullOrEmpty(tvdbId))
            {
                var imdbId = seriesInfo.GetProviderId(MetadataProvider.Imdb);
                if (!string.IsNullOrEmpty(imdbId))
                {
                    tvdbId = await GetSeriesByRemoteId(
                        imdbId,
                        MetadataProvider.Imdb.ToString(),
                        seriesInfo.MetadataLanguage,
                        cancellationToken).ConfigureAwait(false);
                }
            }

            if (string.IsNullOrEmpty(tvdbId))
            {
                var zap2ItId = seriesInfo.GetProviderId(MetadataProvider.Zap2It);
                if (!string.IsNullOrEmpty(zap2ItId))
                {
                    tvdbId = await GetSeriesByRemoteId(
                        zap2ItId,
                        MetadataProvider.Zap2It.ToString(),
                        seriesInfo.MetadataLanguage,
                        cancellationToken).ConfigureAwait(false);
                }
            }

            try
            {
                var seriesResult =
                    await _tvdbClientManager
                    .GetSeriesByIdAsync(Convert.ToInt32(tvdbId, CultureInfo.InvariantCulture), seriesInfo.MetadataLanguage, cancellationToken)
                    .ConfigureAwait(false);

                return(new[] { MapSeriesToRemoteSearchResult(seriesResult.Data) });
            }
            catch (TvDbServerException e)
            {
                _logger.LogError(e, "Failed to retrieve series with id {TvdbId}", tvdbId);
                return(Array.Empty <RemoteSearchResult>());
            }
        }