improve reaction to image stub failures
Conflicts: MediaBrowser.Server.Implementations/Library/LibraryManager.cs
This commit is contained in:
parent
4e9cb26761
commit
5710ef6892
|
@ -480,22 +480,21 @@ namespace MediaBrowser.Providers.Manager
|
||||||
ImageType type,
|
ImageType type,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
foreach (var image in images.Where(i => i.Type == type))
|
var eligibleImages = images
|
||||||
{
|
.Where(i => i.Type == type && !(i.Width.HasValue && i.Width.Value < minWidth))
|
||||||
if (image.Width.HasValue && image.Width.Value < minWidth)
|
.ToList();
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var url = image.Url;
|
if (EnableImageStub(item, type) && eligibleImages.Count > 0)
|
||||||
|
|
||||||
if (EnableImageStub(item, type))
|
|
||||||
{
|
{
|
||||||
SaveImageStub(item, type, url);
|
SaveImageStub(item, type, eligibleImages.Select(i => i.Url));
|
||||||
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var image in eligibleImages)
|
||||||
|
{
|
||||||
|
var url = image.Url;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);
|
var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);
|
||||||
|
@ -557,18 +556,20 @@ namespace MediaBrowser.Providers.Manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveImageStub(IHasImages item, ImageType imageType, string url)
|
private void SaveImageStub(IHasImages item, ImageType imageType, IEnumerable<string> urls)
|
||||||
{
|
{
|
||||||
var newIndex = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0;
|
var newIndex = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0;
|
||||||
|
|
||||||
SaveImageStub(item, imageType, url, newIndex);
|
SaveImageStub(item, imageType, urls, newIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveImageStub(IHasImages item, ImageType imageType, string url, int newIndex)
|
private void SaveImageStub(IHasImages item, ImageType imageType, IEnumerable<string> urls, int newIndex)
|
||||||
{
|
{
|
||||||
|
var path = string.Join("|", urls.Take(1).ToArray());
|
||||||
|
|
||||||
item.SetImage(new ItemImageInfo
|
item.SetImage(new ItemImageInfo
|
||||||
{
|
{
|
||||||
Path = url,
|
Path = path,
|
||||||
Type = imageType
|
Type = imageType
|
||||||
|
|
||||||
}, newIndex);
|
}, newIndex);
|
||||||
|
@ -592,7 +593,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
|
|
||||||
if (EnableImageStub(item, imageType))
|
if (EnableImageStub(item, imageType))
|
||||||
{
|
{
|
||||||
SaveImageStub(item, imageType, url);
|
SaveImageStub(item, imageType, new[] { url });
|
||||||
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2387,9 +2387,13 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
private readonly SemaphoreSlim _dynamicImageResourcePool = new SemaphoreSlim(1,1);
|
private readonly SemaphoreSlim _dynamicImageResourcePool = new SemaphoreSlim(1,1);
|
||||||
public async Task<ItemImageInfo> ConvertImageToLocal(IHasImages item, ItemImageInfo image, int imageIndex)
|
public async Task<ItemImageInfo> ConvertImageToLocal(IHasImages item, ItemImageInfo image, int imageIndex)
|
||||||
{
|
{
|
||||||
_logger.Debug("ConvertImageToLocal item {0}", item.Id);
|
foreach (var url in image.Path.Split('|'))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.Debug("ConvertImageToLocal item {0} - image url: {1}", item.Id, url);
|
||||||
|
|
||||||
await _providerManagerFactory().SaveImage(item, image.Path, _dynamicImageResourcePool, image.Type, imageIndex, CancellationToken.None).ConfigureAwait(false);
|
await _providerManagerFactory().SaveImage(item, url, _dynamicImageResourcePool, image.Type, imageIndex, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
var newImage = item.GetImageInfo(image.Type, imageIndex);
|
var newImage = item.GetImageInfo(image.Type, imageIndex);
|
||||||
|
|
||||||
|
@ -2402,5 +2406,21 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
|
|
||||||
return item.GetImageInfo(image.Type, imageIndex);
|
return item.GetImageInfo(image.Type, imageIndex);
|
||||||
}
|
}
|
||||||
|
catch (HttpException ex)
|
||||||
|
{
|
||||||
|
if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove this image to prevent it from retrying over and over
|
||||||
|
item.RemoveImage(image);
|
||||||
|
await item.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user