mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 18:08:53 -07:00
Convert non-local image to local before computing blurhash
This commit is contained in:
parent
ed791dee46
commit
9208acd5ae
@ -1840,7 +1840,7 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return image.Path != null && !image.IsLocalFile;
|
||||
}
|
||||
|
||||
public void UpdateImages(BaseItem item, bool forceUpdate = false)
|
||||
@ -1850,7 +1850,7 @@ namespace Emby.Server.Implementations.Library
|
||||
throw new ArgumentNullException(nameof(item));
|
||||
}
|
||||
|
||||
var outdated = forceUpdate ? item.ImageInfos.Where(i => i.IsLocalFile).ToArray() : item.ImageInfos.Where(ImageNeedsRefresh).ToArray();
|
||||
var outdated = forceUpdate ? item.ImageInfos.Where(i => i.Path != null).ToArray() : item.ImageInfos.Where(ImageNeedsRefresh).ToArray();
|
||||
if (outdated.Length == 0)
|
||||
{
|
||||
RegisterItem(item);
|
||||
@ -1859,26 +1859,46 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
foreach (var img in outdated)
|
||||
{
|
||||
ImageDimensions size = _imageProcessor.GetImageDimensions(item, img);
|
||||
img.Width = size.Width;
|
||||
img.Height = size.Height;
|
||||
var image = img;
|
||||
if (!img.IsLocalFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
var index = item.GetImageIndex(img);
|
||||
image = ConvertImageToLocal(item, img, index).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
_logger.LogWarning("Cannot get image index for {0}", img.Path);
|
||||
continue;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
_logger.LogWarning("Cannot fetch image from {0}", img.Path);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ImageDimensions size = _imageProcessor.GetImageDimensions(item, image);
|
||||
image.Width = size.Width;
|
||||
image.Height = size.Height;
|
||||
try
|
||||
{
|
||||
img.BlurHash = _imageProcessor.GetImageBlurHash(img.Path);
|
||||
image.BlurHash = _imageProcessor.GetImageBlurHash(image.Path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Cannot compute blurhash for {0}", img.Path);
|
||||
img.BlurHash = string.Empty;
|
||||
_logger.LogError(ex, "Cannot compute blurhash for {0}", image.Path);
|
||||
image.BlurHash = string.Empty;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
img.DateModified = _fileSystem.GetLastWriteTimeUtc(img.Path);
|
||||
image.DateModified = _fileSystem.GetLastWriteTimeUtc(image.Path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Cannot update DateModified for {0}", img.Path);
|
||||
_logger.LogError(ex, "Cannot update DateModified for {0}", image.Path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2375,6 +2375,46 @@ namespace MediaBrowser.Controller.Entities
|
||||
.ElementAtOrDefault(imageIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes image index for given image or raises if no matching image found.
|
||||
/// </summary>
|
||||
/// <param name="image">Image to compute index for.</param>
|
||||
/// <exception cref="ArgumentException">Image index cannot be computed as no matching image found.
|
||||
/// </exception>
|
||||
/// <returns>Image index.</returns>
|
||||
public int GetImageIndex(ItemImageInfo image)
|
||||
{
|
||||
if (image == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(image));
|
||||
}
|
||||
|
||||
if (image.Type == ImageType.Chapter)
|
||||
{
|
||||
var chapters = ItemRepository.GetChapters(this);
|
||||
for (var i = 0; i < chapters.Count; i++)
|
||||
{
|
||||
if (chapters[i].ImagePath == image.Path)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException("No chapter index found for image path", image.Path);
|
||||
}
|
||||
|
||||
var images = GetImages(image.Type).ToArray();
|
||||
for (var i = 0; i < images.Length; i++)
|
||||
{
|
||||
if (images[i].Path == image.Path)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException("No image index found for image path", image.Path);
|
||||
}
|
||||
|
||||
public IEnumerable<ItemImageInfo> GetImages(ImageType imageType)
|
||||
{
|
||||
if (imageType == ImageType.Chapter)
|
||||
|
Loading…
Reference in New Issue
Block a user