private async Task RefreshFromProvider( BaseItem item, IRemoteImageProvider provider, ImageRefreshOptions refreshOptions, TypeOptions savedOptions, int backdropLimit, ICollection <ImageType> downloadedImages, RefreshResult result, CancellationToken cancellationToken) { try { if (!item.SupportsRemoteImageDownloading) { return; } if (!refreshOptions.ReplaceAllImages && refreshOptions.ReplaceImages.Length == 0 && ContainsImages(item, provider.GetSupportedImages(item).ToList(), savedOptions, backdropLimit)) { return; } _logger.LogDebug("Running {Provider} for {Item}", provider.GetType().Name, item.Path ?? item.Name); var images = await _providerManager.GetAvailableRemoteImages( item, new RemoteImageQuery(provider.Name) { IncludeAllLanguages = true, IncludeDisabledProviders = false, }, cancellationToken).ConfigureAwait(false); var list = images.ToList(); int minWidth; foreach (var imageType in _singularImages) { if (!savedOptions.IsEnabled(imageType)) { continue; } if (!item.HasImage(imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType))) { minWidth = savedOptions.GetMinWidth(imageType); var downloaded = await DownloadImage(item, provider, result, list, minWidth, imageType, cancellationToken).ConfigureAwait(false); if (downloaded) { downloadedImages.Add(imageType); } } } minWidth = savedOptions.GetMinWidth(ImageType.Backdrop); await DownloadMultiImages(item, ImageType.Backdrop, refreshOptions, backdropLimit, provider, result, list, minWidth, cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { throw; } catch (Exception ex) { result.ErrorMessage = ex.Message; _logger.LogError(ex, "Error in {Provider}", provider.Name); } }
private bool IsEnabled(TypeOptions options, ImageType type, BaseItem item) { return(options.IsEnabled(type)); }
private async Task RefreshFromProvider( BaseItem item, IDynamicImageProvider provider, ImageRefreshOptions refreshOptions, TypeOptions savedOptions, ICollection <ImageType> downloadedImages, RefreshResult result, CancellationToken cancellationToken) { try { var images = provider.GetSupportedImages(item); foreach (var imageType in images) { if (!savedOptions.IsEnabled(imageType)) { continue; } if (!item.HasImage(imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType))) { _logger.LogDebug("Running {Provider} for {Item}", provider.GetType().Name, item.Path ?? item.Name); var response = await provider.GetImage(item, imageType, cancellationToken).ConfigureAwait(false); if (response.HasImage) { if (string.IsNullOrEmpty(response.Path)) { var mimeType = response.Format.GetMimeType(); await _providerManager.SaveImage(item, response.Stream, mimeType, imageType, null, cancellationToken).ConfigureAwait(false); } else { if (response.Protocol == MediaProtocol.Http) { _logger.LogDebug("Setting image url into item {Item}", item.Id); var index = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0; item.SetImage( new ItemImageInfo { Path = response.Path, Type = imageType }, index); } else { var mimeType = MimeTypes.GetMimeType(response.Path); var stream = AsyncFile.OpenRead(response.Path); await _providerManager.SaveImage(item, stream, mimeType, imageType, null, cancellationToken).ConfigureAwait(false); } } downloadedImages.Add(imageType); result.UpdateType |= ItemUpdateType.ImageUpdate; } } } } catch (OperationCanceledException) { throw; } catch (Exception ex) { result.ErrorMessage = ex.Message; _logger.LogError(ex, "Error in {Provider}", provider.Name); } }