Clean up warnings, simplify

pull/7078/head
Joe Rogers 3 years ago
parent 29755c9384
commit ce66df2c92
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4

@ -99,7 +99,7 @@ namespace MediaBrowser.Providers.Manager
public async Task<RefreshResult> RefreshImages(
BaseItem item,
LibraryOptions libraryOptions,
List<IImageProvider> providers,
IEnumerable<IImageProvider> providers,
ImageRefreshOptions refreshOptions,
CancellationToken cancellationToken)
{
@ -159,14 +159,14 @@ namespace MediaBrowser.Providers.Manager
foreach (var imageType in images)
{
if (!IsEnabled(savedOptions, imageType))
if (!savedOptions.IsEnabled(imageType))
{
continue;
}
if (!HasImage(item, imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType)))
if (!item.HasImage(imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType)))
{
_logger.LogDebug("Running {0} for {1}", provider.GetType().Name, item.Path ?? item.Name);
_logger.LogDebug("Running {Provider} for {Item}", provider.GetType().Name, item.Path ?? item.Name);
var response = await provider.GetImage(item, imageType, cancellationToken).ConfigureAwait(false);
@ -176,7 +176,7 @@ namespace MediaBrowser.Providers.Manager
{
if (response.Protocol == MediaProtocol.Http)
{
_logger.LogDebug("Setting image url into item {0}", item.Id);
_logger.LogDebug("Setting image url into item {Item}", item.Id);
var index = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0;
item.SetImage(
new ItemImageInfo
@ -219,39 +219,6 @@ namespace MediaBrowser.Providers.Manager
}
}
private bool HasImage(BaseItem item, ImageType type)
{
return item.HasImage(type);
}
/// <summary>
/// Determines if an item already contains the given images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="images">The images.</param>
/// <param name="savedOptions">The saved options.</param>
/// <param name="backdropLimit">The backdrop limit.</param>
/// <returns><c>true</c> if the specified item contains images; otherwise, <c>false</c>.</returns>
private bool ContainsImages(BaseItem item, List<ImageType> images, TypeOptions savedOptions, int backdropLimit)
{
// Using .Any causes the creation of a DisplayClass aka. variable capture
for (var i = 0; i < _singularImages.Length; i++)
{
var type = _singularImages[i];
if (images.Contains(type) && !HasImage(item, type) && savedOptions.GetLimit(type) > 0)
{
return false;
}
}
if (images.Contains(ImageType.Backdrop) && item.GetImages(ImageType.Backdrop).Count() < backdropLimit)
{
return false;
}
return true;
}
/// <summary>
/// Refreshes from a remote provider.
/// </summary>
@ -288,7 +255,7 @@ namespace MediaBrowser.Providers.Manager
return;
}
_logger.LogDebug("Running {0} for {1}", provider.GetType().Name, item.Path ?? item.Name);
_logger.LogDebug("Running {Provider} for {Item}", provider.GetType().Name, item.Path ?? item.Name);
var images = await _providerManager.GetAvailableRemoteImages(
item,
@ -304,12 +271,12 @@ namespace MediaBrowser.Providers.Manager
foreach (var imageType in _singularImages)
{
if (!IsEnabled(savedOptions, imageType))
if (!savedOptions.IsEnabled(imageType))
{
continue;
}
if (!HasImage(item, imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType)))
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);
@ -335,9 +302,32 @@ namespace MediaBrowser.Providers.Manager
}
}
private bool IsEnabled(TypeOptions options, ImageType type)
/// <summary>
/// Determines if an item already contains the given images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="images">The images.</param>
/// <param name="savedOptions">The saved options.</param>
/// <param name="backdropLimit">The backdrop limit.</param>
/// <returns><c>true</c> if the specified item contains images; otherwise, <c>false</c>.</returns>
private bool ContainsImages(BaseItem item, List<ImageType> images, TypeOptions savedOptions, int backdropLimit)
{
return options.IsEnabled(type);
// Using .Any causes the creation of a DisplayClass aka. variable capture
for (var i = 0; i < _singularImages.Length; i++)
{
var type = _singularImages[i];
if (images.Contains(type) && !item.HasImage(type) && savedOptions.GetLimit(type) > 0)
{
return false;
}
}
if (images.Contains(ImageType.Backdrop) && item.GetImages(ImageType.Backdrop).Count() < backdropLimit)
{
return false;
}
return true;
}
private void PruneImages(BaseItem item, ItemImageInfo[] images)
@ -354,6 +344,11 @@ namespace MediaBrowser.Providers.Manager
}
catch (FileNotFoundException)
{
// nothing to do, already gone
}
catch (UnauthorizedAccessException ex)
{
_logger.LogWarning(ex, "Unable to delete {Image}", image.Path);
}
}
}
@ -380,12 +375,7 @@ namespace MediaBrowser.Providers.Manager
{
var currentImage = item.GetImageInfo(type, 0);
if (currentImage == null)
{
item.SetImagePath(type, image.FileInfo);
changed = true;
}
else if (!string.Equals(currentImage.Path, image.FileInfo.FullName, StringComparison.OrdinalIgnoreCase))
if (currentImage == null || !string.Equals(currentImage.Path, image.FileInfo.FullName, StringComparison.OrdinalIgnoreCase))
{
item.SetImagePath(type, image.FileInfo);
changed = true;
@ -493,7 +483,7 @@ namespace MediaBrowser.Providers.Manager
await _providerManager.SaveImage(
item,
stream,
response.Content.Headers.ContentType.MediaType,
response.Content.Headers.ContentType?.MediaType,
type,
null,
cancellationToken).ConfigureAwait(false);
@ -616,11 +606,11 @@ namespace MediaBrowser.Providers.Manager
await _providerManager.SaveImage(
item,
stream,
response.Content.Headers.ContentType.MediaType,
response.Content.Headers.ContentType?.MediaType,
imageType,
null,
cancellationToken).ConfigureAwait(false);
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
result.UpdateType |= ItemUpdateType.ImageUpdate;
}
catch (HttpRequestException)
{

Loading…
Cancel
Save