Ejemplo n.º 1
0
        public async Task <MetadataResult <TItemType> > GetMetadata(TLookupInfoType info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <TItemType>()
            {
                QueriedById    = true,
                Provider       = Constants.ProviderName,
                ResultLanguage = Constants.ProviderMetadataLanguage
            };

            var(resolveResult, kinopoiskId) = await _providerIdResolver.TryResolve(info, cancellationToken);

            if (!resolveResult)
            {
                return(result);
            }

            var film = await _apiClient.GetSingleFilm(kinopoiskId, cancellationToken);

            cancellationToken.ThrowIfCancellationRequested();

            result.Item = ConvertResponseToItem(film);
            if (result.Item != null)
            {
                result.HasMetadata = true;
            }

            var staff = await _apiClient.GetStaff(kinopoiskId, cancellationToken);

            cancellationToken.ThrowIfCancellationRequested();

            var sanitizedPersons = await SanitizeEmptyImagePersonInfos(staff.ToPersonInfos());

            foreach (var item in sanitizedPersons)
            {
                result.AddPerson(item);
            }

            var trailers = await _apiClient.GetTrailers(kinopoiskId, cancellationToken);

            var remoteTrailers = trailers.ToMediaUrls();

            if (remoteTrailers is not null)
            {
                result.Item.RemoteTrailers = remoteTrailers;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <(bool IsSuccess, int ProviderId)> TryResolveByImdbMatch(T info, ICollection <FilmSearchResponse_films> candidates, CancellationToken?ct = null)
        {
            if (info.TryGetProviderId(MetadataProvider.Imdb, out var imdbId))
            {
                _logger.LogDebug($"Trying to find result with ImdbId '{imdbId}'...");
                var index = 0;
                foreach (var candidate in candidates)
                {
                    try
                    {
                        var film = await _kinopoiskApiClient.GetSingleFilm(candidate.FilmId, ct);

                        if (imdbId == film?.ImdbId)
                        {
                            _logger.LogDebug($"Found match: {candidate.FilmId} '{film.GetLocalName()}', ImdbId '{film?.ImdbId}', setting KinopoiskProviderId to {candidate.FilmId}");
                            return(true, candidate.FilmId);
                        }

                        _logger.LogDebug($"Film {candidate.FilmId} '{film.GetLocalName()}' has ImdbId '{film?.ImdbId}', skipping, {candidates.Count - ++index} candidates left...");
                    } catch (Exception e)
                    {
                        _logger.LogError(e, $"Error while retrieving film {candidate.FilmId}");
                        continue;
                    }
                }
            }

            return(false, 0);
        }
Ejemplo n.º 3
0
        public override async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var(resolveResult, kinopoiskId) = await _providerIdResolver.TryResolve(item, cancellationToken);

            if (!resolveResult)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var film = await _apiClient.GetSingleFilm(kinopoiskId, cancellationToken);

            return(await FilterEmptyImages(film.ToRemoteImageInfos()));
        }