|
@@ -2,8 +2,8 @@
|
|
using MediaBrowser.Common.Extensions;
|
|
using MediaBrowser.Common.Extensions;
|
|
using MediaBrowser.Common.IO;
|
|
using MediaBrowser.Common.IO;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Entities;
|
|
-using MediaBrowser.Controller.Library;
|
|
|
|
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;
|
|
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Photos
|
|
namespace MediaBrowser.Server.Implementations.Photos
|
|
{
|
|
{
|
|
- public abstract class BaseDynamicImageProvider<T> : IHasChangeMonitor, IForcedProvider, ICustomMetadataProvider<T>
|
|
|
|
|
|
+ public abstract class BaseDynamicImageProvider<T> : IHasChangeMonitor, IForcedProvider, IDynamicImageProvider, IHasOrder
|
|
where T : IHasMetadata
|
|
where T : IHasMetadata
|
|
{
|
|
{
|
|
protected IFileSystem FileSystem { get; private set; }
|
|
protected IFileSystem FileSystem { get; private set; }
|
|
@@ -29,81 +29,51 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|
FileSystem = fileSystem;
|
|
FileSystem = fileSystem;
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<ItemUpdateType> FetchAsync(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
|
|
|
|
|
+ public virtual bool Supports(IHasImages item)
|
|
{
|
|
{
|
|
- if (!Supports(item))
|
|
|
|
- {
|
|
|
|
- return ItemUpdateType.None;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var primaryResult = await FetchAsync(item, ImageType.Primary, options, cancellationToken).ConfigureAwait(false);
|
|
|
|
- var thumbResult = await FetchAsync(item, ImageType.Thumb, options, cancellationToken).ConfigureAwait(false);
|
|
|
|
-
|
|
|
|
- return primaryResult | thumbResult;
|
|
|
|
|
|
+ return item is T;
|
|
}
|
|
}
|
|
|
|
|
|
- protected virtual bool Supports(IHasImages item)
|
|
|
|
- {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected abstract Task<List<BaseItem>> GetItemsWithImages(IHasImages item);
|
|
|
|
-
|
|
|
|
- private const string Version = "3";
|
|
|
|
- protected string GetConfigurationCacheKey(List<BaseItem> items)
|
|
|
|
|
|
+ public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
{
|
|
{
|
|
- return (Version + "_" + string.Join(",", items.Select(i => i.Id.ToString("N")).ToArray())).GetMD5().ToString("N");
|
|
|
|
|
|
+ return new List<ImageType>
|
|
|
|
+ {
|
|
|
|
+ ImageType.Primary,
|
|
|
|
+ ImageType.Thumb
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
- protected async Task<ItemUpdateType> FetchAsync(IHasImages item, ImageType imageType, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
|
|
|
|
|
+ public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
var items = await GetItemsWithImages(item).ConfigureAwait(false);
|
|
var items = await GetItemsWithImages(item).ConfigureAwait(false);
|
|
var cacheKey = GetConfigurationCacheKey(items);
|
|
var cacheKey = GetConfigurationCacheKey(items);
|
|
|
|
|
|
- if (!HasChanged(item, imageType, cacheKey))
|
|
|
|
|
|
+ var result = await FetchAsyncInternal(item, items, type, cacheKey, cancellationToken).ConfigureAwait(false);
|
|
|
|
+
|
|
|
|
+ return new DynamicImageResponse
|
|
{
|
|
{
|
|
- return ItemUpdateType.None;
|
|
|
|
- }
|
|
|
|
|
|
+ HasImage = result != null,
|
|
|
|
+ Stream = result,
|
|
|
|
+ InternalCacheKey = cacheKey,
|
|
|
|
+ Format = ImageFormat.Png
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
|
|
- return await FetchAsyncInternal(item, items, imageType, cacheKey, options, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
+ protected abstract Task<List<BaseItem>> GetItemsWithImages(IHasImages item);
|
|
|
|
+
|
|
|
|
+ private const string Version = "3";
|
|
|
|
+ protected string GetConfigurationCacheKey(List<BaseItem> items)
|
|
|
|
+ {
|
|
|
|
+ return (Version + "_" + string.Join(",", items.Select(i => i.Id.ToString("N")).ToArray())).GetMD5().ToString("N");
|
|
}
|
|
}
|
|
|
|
|
|
- protected async Task<ItemUpdateType> FetchAsyncInternal(IHasImages item,
|
|
|
|
|
|
+ protected Task<Stream> FetchAsyncInternal(IHasImages item,
|
|
List<BaseItem> itemsWithImages,
|
|
List<BaseItem> itemsWithImages,
|
|
- ImageType imageType,
|
|
|
|
- string cacheKey,
|
|
|
|
- MetadataRefreshOptions options,
|
|
|
|
|
|
+ ImageType imageType,
|
|
|
|
+ string cacheKey,
|
|
CancellationToken cancellationToken)
|
|
CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
- var stream = await CreateImageAsync(item, itemsWithImages, imageType, 0).ConfigureAwait(false);
|
|
|
|
-
|
|
|
|
- if (stream == null)
|
|
|
|
- {
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return ItemUpdateType.ImageUpdate;
|
|
|
|
|
|
+ return CreateImageAsync(item, itemsWithImages, imageType, 0);
|
|
}
|
|
}
|
|
|
|
|
|
protected Task<Stream> GetThumbCollage(List<BaseItem> items)
|
|
protected Task<Stream> GetThumbCollage(List<BaseItem> items)
|
|
@@ -137,9 +107,9 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|
get { return "Dynamic Image Provider"; }
|
|
get { return "Dynamic Image Provider"; }
|
|
}
|
|
}
|
|
|
|
|
|
- public async Task<Stream> CreateImageAsync(IHasImages item,
|
|
|
|
|
|
+ public async Task<Stream> CreateImageAsync(IHasImages item,
|
|
List<BaseItem> itemsWithImages,
|
|
List<BaseItem> itemsWithImages,
|
|
- ImageType imageType,
|
|
|
|
|
|
+ ImageType imageType,
|
|
int imageIndex)
|
|
int imageIndex)
|
|
{
|
|
{
|
|
if (itemsWithImages.Count == 0)
|
|
if (itemsWithImages.Count == 0)
|
|
@@ -209,5 +179,14 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|
|
|
|
|
return weekNo;
|
|
return weekNo;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public int Order
|
|
|
|
+ {
|
|
|
|
+ get
|
|
|
|
+ {
|
|
|
|
+ // Run before the default image provider which will download placeholders
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|