mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-23 02:24:44 +01:00
Add BlurHash support to backend
This commit is contained in:
@@ -1144,12 +1144,18 @@ namespace Emby.Server.Implementations.Data
|
||||
var delimeter = "*";
|
||||
|
||||
var path = image.Path;
|
||||
var hash = image.Hash;
|
||||
|
||||
if (path == null)
|
||||
{
|
||||
path = string.Empty;
|
||||
}
|
||||
|
||||
if (hash == null)
|
||||
{
|
||||
hash = string.Empty;
|
||||
}
|
||||
|
||||
return GetPathToSave(path) +
|
||||
delimeter +
|
||||
image.DateModified.Ticks.ToString(CultureInfo.InvariantCulture) +
|
||||
@@ -1158,7 +1164,11 @@ namespace Emby.Server.Implementations.Data
|
||||
delimeter +
|
||||
image.Width.ToString(CultureInfo.InvariantCulture) +
|
||||
delimeter +
|
||||
image.Height.ToString(CultureInfo.InvariantCulture);
|
||||
image.Height.ToString(CultureInfo.InvariantCulture) +
|
||||
delimeter +
|
||||
// Replace delimiters with other characters.
|
||||
// This can be removed when we migrate to a proper DB.
|
||||
hash.Replace('*', '/').Replace('|', '\\');
|
||||
}
|
||||
|
||||
public ItemImageInfo ItemImageInfoFromValueString(string value)
|
||||
@@ -1192,6 +1202,11 @@ namespace Emby.Server.Implementations.Data
|
||||
image.Width = width;
|
||||
image.Height = height;
|
||||
}
|
||||
|
||||
if (parts.Length >= 6)
|
||||
{
|
||||
image.Hash = parts[5].Replace('/', '*').Replace('\\', '|');
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
|
||||
@@ -718,6 +718,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
if (options.EnableImages)
|
||||
{
|
||||
dto.ImageTags = new Dictionary<ImageType, string>();
|
||||
dto.ImageHashes = new Dictionary<string, string>();
|
||||
|
||||
// Prevent implicitly captured closure
|
||||
var currentItem = item;
|
||||
@@ -732,6 +733,12 @@ namespace Emby.Server.Implementations.Dto
|
||||
{
|
||||
dto.ImageTags[image.Type] = tag;
|
||||
}
|
||||
|
||||
var hash = image.Hash;
|
||||
if (hash != null && hash.Length > 0)
|
||||
{
|
||||
dto.ImageHashes[tag] = image.Hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
@@ -35,6 +36,7 @@ using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Controller.Sorting;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Drawing;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
@@ -109,6 +111,18 @@ namespace Emby.Server.Implementations.Library
|
||||
/// <value>The comparers.</value>
|
||||
private IBaseItemComparer[] Comparers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the active item repository
|
||||
/// </summary>
|
||||
/// <value>The item repository.</value>
|
||||
public IItemRepository ItemRepository { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the active image processor
|
||||
/// </summary>
|
||||
/// <value>The image processor.</value>
|
||||
public IImageProcessor ImageProcessor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when [item added].
|
||||
/// </summary>
|
||||
@@ -1817,7 +1831,19 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
public void UpdateImages(BaseItem item)
|
||||
{
|
||||
_itemRepository.SaveImages(item);
|
||||
item.ImageInfos
|
||||
.Where(i => (i.Width == 0 || i.Height == 0))
|
||||
.ToList()
|
||||
.ForEach(x =>
|
||||
{
|
||||
string blurhash = ImageProcessor.GetImageHash(x.Path);
|
||||
ImageDimensions size = ImageProcessor.GetImageDimensions(item, x, true);
|
||||
x.Width = size.Width;
|
||||
x.Height = size.Height;
|
||||
x.Hash = blurhash;
|
||||
});
|
||||
|
||||
ItemRepository.SaveImages(item);
|
||||
|
||||
RegisterItem(item);
|
||||
}
|
||||
@@ -1839,7 +1865,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
item.DateLastSaved = DateTime.UtcNow;
|
||||
|
||||
RegisterItem(item);
|
||||
UpdateImages(item);
|
||||
}
|
||||
|
||||
_itemRepository.SaveItems(itemsList, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user