示例#1
0
        /// <summary>
        /// Processes the images.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="images">The images.</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Task.</returns>
        private async Task ProcessImages(BaseItem item, List <RemoteImageInfo> images, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var eligiblePosters = images
                                  .Where(i => i.Type == ImageType.Primary)
                                  .ToList();

            //        poster
            if (eligiblePosters.Count > 0 && !item.HasImage(ImageType.Primary))
            {
                var poster = eligiblePosters[0];

                var url = poster.Url;

                var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
                {
                    Url = url,
                    CancellationToken = cancellationToken
                }).ConfigureAwait(false);

                await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(url), ImageType.Primary, null, url, cancellationToken)
                .ConfigureAwait(false);
            }

            cancellationToken.ThrowIfCancellationRequested();

            var eligibleBackdrops = images
                                    .Where(i => i.Type == ImageType.Backdrop && i.Width.HasValue && i.Width.Value >= ConfigurationManager.Configuration.MinMovieBackdropDownloadWidth)
                                    .ToList();

            var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;

            // backdrops - only download if earlier providers didn't find any (fanart)
            if (eligibleBackdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit)
            {
                for (var i = 0; i < eligibleBackdrops.Count; i++)
                {
                    var url = eligibleBackdrops[i].Url;

                    if (!item.ContainsImageWithSourceUrl(url))
                    {
                        var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
                        {
                            Url = url,
                            CancellationToken = cancellationToken
                        }).ConfigureAwait(false);

                        await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(url), ImageType.Backdrop, item.BackdropImagePaths.Count, url, cancellationToken)
                        .ConfigureAwait(false);
                    }

                    if (item.BackdropImagePaths.Count >= backdropLimit)
                    {
                        break;
                    }
                }
            }
        }
示例#2
0
        private async Task DownloadImages(BaseItem item, List <RemoteImageInfo> images, int backdropLimit, CancellationToken cancellationToken)
        {
            if (!item.HasImage(ImageType.Primary))
            {
                var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);

                if (image != null)
                {
                    await _providerManager.SaveImage(item, image.Url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Primary, null, cancellationToken)
                    .ConfigureAwait(false);
                }
            }

            if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !item.HasImage(ImageType.Banner))
            {
                var image = images.FirstOrDefault(i => i.Type == ImageType.Banner);

                if (image != null)
                {
                    await _providerManager.SaveImage(item, image.Url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Banner, null, cancellationToken)
                    .ConfigureAwait(false);
                }
            }

            if (ConfigurationManager.Configuration.DownloadSeriesImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit)
            {
                var bdNo = item.BackdropImagePaths.Count;

                foreach (var backdrop in images.Where(i => i.Type == ImageType.Backdrop &&
                                                      (!i.Width.HasValue ||
                                                       i.Width.Value >= ConfigurationManager.Configuration.MinSeriesBackdropDownloadWidth)))
                {
                    var url = backdrop.Url;

                    if (item.ContainsImageWithSourceUrl(url))
                    {
                        continue;
                    }

                    await _providerManager.SaveImage(item, url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, bdNo, cancellationToken).ConfigureAwait(false);

                    bdNo++;

                    if (item.BackdropImagePaths.Count >= backdropLimit)
                    {
                        break;
                    }
                }
            }
        }
        private async Task DownloadImages(BaseItem item, List<RemoteImageInfo> images, int backdropLimit, CancellationToken cancellationToken)
        {
            if (!item.LockedFields.Contains(MetadataFields.Images))
            {
                if (!item.HasImage(ImageType.Primary))
                {
                    var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);

                    if (image != null)
                    {
                        await _providerManager.SaveImage(item, image.Url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Primary, null, cancellationToken)
                            .ConfigureAwait(false);
                    }
                }

                if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !item.HasImage(ImageType.Banner))
                {
                    var image = images.FirstOrDefault(i => i.Type == ImageType.Banner);

                    if (image != null)
                    {
                        await _providerManager.SaveImage(item, image.Url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Banner, null, cancellationToken)
                            .ConfigureAwait(false);
                    }
                }
            }

            if (ConfigurationManager.Configuration.DownloadSeriesImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit && !item.LockedFields.Contains(MetadataFields.Backdrops))
            {
                foreach (var backdrop in images.Where(i => i.Type == ImageType.Backdrop && 
                    (!i.Width.HasValue || 
                    i.Width.Value >= ConfigurationManager.Configuration.TvOptions.MinBackdropWidth)))
                {
                    var url = backdrop.Url;

                    if (item.ContainsImageWithSourceUrl(url))
                    {
                        continue;
                    }

                    await _providerManager.SaveImage(item, url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, null, cancellationToken).ConfigureAwait(false);

                    if (item.BackdropImagePaths.Count >= backdropLimit) break;
                }
            }
        }
        /// <summary>
        /// Processes the images.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="images">The images.</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Task.</returns>
        private async Task ProcessImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var eligiblePosters = images
                .Where(i => i.Type == ImageType.Primary)
                .ToList();

            //        poster
            if (eligiblePosters.Count > 0 && !item.HasImage(ImageType.Primary) && !item.LockedFields.Contains(MetadataFields.Images))
            {
                var poster = eligiblePosters[0];

                var url = poster.Url;

                var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
                {
                    Url = url,
                    CancellationToken = cancellationToken

                }).ConfigureAwait(false);

                await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(url), ImageType.Primary, null, url, cancellationToken)
                                    .ConfigureAwait(false);
            }

            cancellationToken.ThrowIfCancellationRequested();

            var eligibleBackdrops = images
                .Where(i => i.Type == ImageType.Backdrop && i.Width.HasValue && i.Width.Value >= ConfigurationManager.Configuration.MinMovieBackdropDownloadWidth)
                .ToList();

            var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;

            // backdrops - only download if earlier providers didn't find any (fanart)
            if (eligibleBackdrops.Count > 0 &&
                ConfigurationManager.Configuration.DownloadMovieImages.Backdrops &&
                item.BackdropImagePaths.Count < backdropLimit &&
                !item.LockedFields.Contains(MetadataFields.Backdrops))
            {
                for (var i = 0; i < eligibleBackdrops.Count; i++)
                {
                    var url = eligibleBackdrops[i].Url;

                    if (!item.ContainsImageWithSourceUrl(url))
                    {
                        var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
                        {
                            Url = url,
                            CancellationToken = cancellationToken

                        }).ConfigureAwait(false);

                        await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(url), ImageType.Backdrop, null, url, cancellationToken)
                          .ConfigureAwait(false);
                    }

                    if (item.BackdropImagePaths.Count >= backdropLimit)
                    {
                        break;
                    }
                }
            }
        }
        private async Task DownloadImages(BaseItem item, List<RemoteImageInfo> images, int backdropLimit, CancellationToken cancellationToken)
        {
            if (!item.HasImage(ImageType.Primary))
            {
                await SaveImage(item, images, ImageType.Primary, cancellationToken).ConfigureAwait(false);
            }

            if (ConfigurationManager.Configuration.DownloadSeasonImages.Banner && !item.HasImage(ImageType.Banner))
            {
                await SaveImage(item, images, ImageType.Banner, cancellationToken).ConfigureAwait(false);
            }

            if (ConfigurationManager.Configuration.DownloadSeasonImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit)
            {
                foreach (var backdrop in images.Where(i => i.Type == ImageType.Backdrop))
                {
                    var url = backdrop.Url;

                    if (item.ContainsImageWithSourceUrl(url))
                    {
                        continue;
                    }

                    await _providerManager.SaveImage(item, url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, null, cancellationToken).ConfigureAwait(false);

                    if (item.BackdropImagePaths.Count >= backdropLimit) break;
                }
            }
        }