|
@@ -6,7 +6,6 @@ using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.Playlists;
|
|
using MediaBrowser.Controller.Playlists;
|
|
using MediaBrowser.Controller.Providers;
|
|
using MediaBrowser.Controller.Providers;
|
|
-using MediaBrowser.Model.Drawing;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
using MediaBrowser.Model.Entities;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
@@ -79,56 +78,23 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|
string cacheKey,
|
|
string cacheKey,
|
|
CancellationToken cancellationToken)
|
|
CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
- var stream = CreateImageAsync(item, itemsWithImages, imageType, 0);
|
|
|
|
|
|
+ var outputPath = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid() + ".png");
|
|
|
|
+ Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
|
|
|
+ var imageCreated = CreateImage(item, itemsWithImages, outputPath, imageType, 0);
|
|
|
|
|
|
- if (stream == null)
|
|
|
|
|
|
+ if (!imageCreated)
|
|
{
|
|
{
|
|
return ItemUpdateType.None;
|
|
return ItemUpdateType.None;
|
|
}
|
|
}
|
|
|
|
|
|
- if (stream is MemoryStream)
|
|
|
|
- {
|
|
|
|
- using (stream)
|
|
|
|
- {
|
|
|
|
- stream.Position = 0;
|
|
|
|
-
|
|
|
|
- await ProviderManager.SaveImage(item, stream, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- using (var ms = new MemoryStream())
|
|
|
|
- {
|
|
|
|
- await stream.CopyToAsync(ms).ConfigureAwait(false);
|
|
|
|
-
|
|
|
|
- ms.Position = 0;
|
|
|
|
-
|
|
|
|
- await ProviderManager.SaveImage(item, ms, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ await ProviderManager.SaveImage(item, outputPath, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
return ItemUpdateType.ImageUpdate;
|
|
return ItemUpdateType.ImageUpdate;
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
|
|
|
|
- {
|
|
|
|
- var items = await GetItemsWithImages(item).ConfigureAwait(false);
|
|
|
|
- var cacheKey = GetConfigurationCacheKey(items, item.Name);
|
|
|
|
-
|
|
|
|
- var result = CreateImageAsync(item, items, type, 0);
|
|
|
|
-
|
|
|
|
- return new DynamicImageResponse
|
|
|
|
- {
|
|
|
|
- HasImage = result != null,
|
|
|
|
- Stream = result,
|
|
|
|
- InternalCacheKey = cacheKey,
|
|
|
|
- Format = ImageFormat.Png
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
protected abstract Task<List<BaseItem>> GetItemsWithImages(IHasImages item);
|
|
protected abstract Task<List<BaseItem>> GetItemsWithImages(IHasImages item);
|
|
|
|
|
|
- private const string Version = "20";
|
|
|
|
|
|
+ private const string Version = "27";
|
|
protected string GetConfigurationCacheKey(List<BaseItem> items, string itemName)
|
|
protected string GetConfigurationCacheKey(List<BaseItem> items, string itemName)
|
|
{
|
|
{
|
|
var parts = Version + "_" + (itemName ?? string.Empty) + "_" +
|
|
var parts = Version + "_" + (itemName ?? string.Empty) + "_" +
|
|
@@ -137,39 +103,35 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|
return parts.GetMD5().ToString("N");
|
|
return parts.GetMD5().ToString("N");
|
|
}
|
|
}
|
|
|
|
|
|
- protected Stream GetThumbCollage(IHasImages primaryItem, List<BaseItem> items)
|
|
|
|
|
|
+ protected void CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
|
|
{
|
|
{
|
|
- return GetThumbCollage(primaryItem, items, 960, 540, true, primaryItem.Name);
|
|
|
|
|
|
+ CreateCollage(primaryItem, items, outputPath, 960, 540, true, primaryItem.Name);
|
|
}
|
|
}
|
|
|
|
|
|
- protected virtual IEnumerable<String> GetStripCollageImagePaths(IHasImages primaryItem, IEnumerable<BaseItem> items)
|
|
|
|
|
|
+ protected virtual IEnumerable<string> GetStripCollageImagePaths(IHasImages primaryItem, IEnumerable<BaseItem> items)
|
|
{
|
|
{
|
|
return items
|
|
return items
|
|
.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb))
|
|
.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb))
|
|
.Where(i => !string.IsNullOrWhiteSpace(i));
|
|
.Where(i => !string.IsNullOrWhiteSpace(i));
|
|
}
|
|
}
|
|
|
|
|
|
- protected Stream GetPosterCollage(IHasImages primaryItem, List<BaseItem> items)
|
|
|
|
|
|
+ protected void CreatePosterCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
|
|
{
|
|
{
|
|
- var path = CreateCollage(primaryItem, items, 600, 900, true, primaryItem.Name);
|
|
|
|
- return FileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
|
|
|
+ CreateCollage(primaryItem, items, outputPath, 600, 900, true, primaryItem.Name);
|
|
}
|
|
}
|
|
|
|
|
|
- protected Stream GetSquareCollage(IHasImages primaryItem, List<BaseItem> items)
|
|
|
|
|
|
+ protected void CreateSquareCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
|
|
{
|
|
{
|
|
- var path = CreateCollage(primaryItem, items, 800, 800, true, primaryItem.Name);
|
|
|
|
- return FileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
|
|
|
+ CreateCollage(primaryItem, items, outputPath, 800, 800, true, primaryItem.Name);
|
|
}
|
|
}
|
|
|
|
|
|
- protected Stream GetThumbCollage(IHasImages primaryItem, List<BaseItem> items, int width, int height, bool drawText, string text)
|
|
|
|
|
|
+ protected void CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath, int width, int height, bool drawText, string text)
|
|
{
|
|
{
|
|
- var path = CreateCollage(primaryItem, items, width, height, drawText, text);
|
|
|
|
- return FileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
|
|
|
+ CreateCollage(primaryItem, items, outputPath, width, height, drawText, text);
|
|
}
|
|
}
|
|
|
|
|
|
- private string CreateCollage(IHasImages primaryItem, List<BaseItem> items, int width, int height, bool drawText, string text)
|
|
|
|
|
|
+ private void CreateCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath, int width, int height, bool drawText, string text)
|
|
{
|
|
{
|
|
- var outputPath = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid() + ".png");
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
|
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
|
|
|
|
|
var options = new ImageCollageOptions
|
|
var options = new ImageCollageOptions
|
|
@@ -182,8 +144,6 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|
};
|
|
};
|
|
|
|
|
|
ImageProcessor.CreateImageCollage(options);
|
|
ImageProcessor.CreateImageCollage(options);
|
|
-
|
|
|
|
- return outputPath;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public string Name
|
|
public string Name
|
|
@@ -191,26 +151,35 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|
get { return "Dynamic Image Provider"; }
|
|
get { return "Dynamic Image Provider"; }
|
|
}
|
|
}
|
|
|
|
|
|
- protected virtual Stream CreateImageAsync(IHasImages item,
|
|
|
|
|
|
+ protected virtual bool CreateImage(IHasImages item,
|
|
List<BaseItem> itemsWithImages,
|
|
List<BaseItem> itemsWithImages,
|
|
|
|
+ string outputPath,
|
|
ImageType imageType,
|
|
ImageType imageType,
|
|
int imageIndex)
|
|
int imageIndex)
|
|
{
|
|
{
|
|
if (itemsWithImages.Count == 0)
|
|
if (itemsWithImages.Count == 0)
|
|
{
|
|
{
|
|
- return null;
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
if (imageType == ImageType.Thumb)
|
|
if (imageType == ImageType.Thumb)
|
|
{
|
|
{
|
|
- return GetThumbCollage(item, itemsWithImages);
|
|
|
|
|
|
+ CreateThumbCollage(item, itemsWithImages, outputPath);
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
if (imageType == ImageType.Primary)
|
|
if (imageType == ImageType.Primary)
|
|
{
|
|
{
|
|
- return item is PhotoAlbum || item is Playlist ?
|
|
|
|
- GetSquareCollage(item, itemsWithImages) :
|
|
|
|
- GetPosterCollage(item, itemsWithImages);
|
|
|
|
|
|
+ if (item is PhotoAlbum || item is Playlist)
|
|
|
|
+ {
|
|
|
|
+ CreateSquareCollage(item, itemsWithImages, outputPath);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ CreatePosterCollage(item, itemsWithImages, outputPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
throw new ArgumentException("Unexpected image type");
|
|
throw new ArgumentException("Unexpected image type");
|