Ejemplo n.º 1
0
        /// <inheritdoc />
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var seriesWithPerson = _libraryManager.GetItemList(new InternalItemsQuery
            {
                IncludeItemTypes = new[] { nameof(Series) },
                PersonIds        = new[] { item.Id },
                DtoOptions       = new DtoOptions(false)
                {
                    EnableImages = false
                }
            }).Cast <Series>()
                                   .Where(i => TvdbSeriesProvider.IsValidSeries(i.ProviderIds))
                                   .ToList();

            var infos = (await Task.WhenAll(seriesWithPerson.Select(async i =>
                                                                    await GetImageFromSeriesData(i, item.Name, cancellationToken).ConfigureAwait(false)))
                         .ConfigureAwait(false))
                        .Where(i => i != null)
                        .Take(1);

            return(infos);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var season = (Season)item;
            var series = season.Series;

            if (series == null || !season.IndexNumber.HasValue || !TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
            {
                return(Array.Empty <RemoteImageInfo>());
            }

            var tvdbId       = Convert.ToInt32(series.GetProviderId(MetadataProvider.Tvdb));
            var seasonNumber = season.IndexNumber.Value;
            var language     = item.GetPreferredMetadataLanguage();
            var remoteImages = new List <RemoteImageInfo>();

            var keyTypes = _tvdbClientManager.GetImageKeyTypesForSeasonAsync(tvdbId, language, cancellationToken).ConfigureAwait(false);

            await foreach (var keyType in keyTypes)
            {
                var imageQuery = new ImagesQuery
                {
                    KeyType = keyType,
                    SubKey  = seasonNumber.ToString()
                };
                try
                {
                    var imageResults = await _tvdbClientManager
                                       .GetImagesAsync(tvdbId, imageQuery, language, cancellationToken).ConfigureAwait(false);

                    remoteImages.AddRange(GetImages(imageResults.Data, language));
                }
                catch (TvDbServerException)
                {
                    _logger.LogDebug("No images of type {KeyType} found for series {TvdbId}", keyType, tvdbId);
                }
            }

            return(remoteImages);
        }
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            if (!TvdbSeriesProvider.IsValidSeries(item.ProviderIds))
            {
                return(Array.Empty <RemoteImageInfo>());
            }

            var language        = item.GetPreferredMetadataLanguage();
            var remoteImages    = new List <RemoteImageInfo>();
            var tvdbId          = Convert.ToInt32(item.GetProviderId(MetadataProvider.Tvdb));
            var allowedKeyTypes = _tvdbClientManager.GetImageKeyTypesForSeriesAsync(tvdbId, language, cancellationToken)
                                  .ConfigureAwait(false);

            await foreach (KeyType keyType in allowedKeyTypes)
            {
                var imageQuery = new ImagesQuery
                {
                    KeyType = keyType
                };
                try
                {
                    var imageResults =
                        await _tvdbClientManager.GetImagesAsync(tvdbId, imageQuery, language, cancellationToken)
                        .ConfigureAwait(false);

                    remoteImages.AddRange(GetImages(imageResults.Data, language));
                }
                catch (TvDbServerException)
                {
                    _logger.LogDebug("No images of type {KeyType} exist for series {TvDbId}", keyType,
                                     tvdbId);
                }
            }

            return(remoteImages);
        }