aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-10-26 18:50:19 -0400
committerLuke <luke.pulverenti@gmail.com>2015-10-26 18:50:19 -0400
commit35778ebc02e5931142a1fe31a256b7488a07c5c2 (patch)
treeced0290be8820f5e507b51ca4c5165212b1879d1 /MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs
parentc0dc8d055bfd4d2f58591083beb9e9128357aad6 (diff)
parent8d77308593c3b16b733b0109323770d9dfe7e166 (diff)
Merge pull request #1222 from MediaBrowser/dev
3.0.5768.7
Diffstat (limited to 'MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs73
1 files changed, 53 insertions, 20 deletions
diff --git a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs
index 4b7e1c3a7..2402d3ec1 100644
--- a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs
+++ b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs
@@ -13,6 +13,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using CommonIO;
namespace MediaBrowser.Server.Implementations.Photos
{
@@ -32,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Photos
ImageProcessor = imageProcessor;
}
- public virtual bool Supports(IHasImages item)
+ protected virtual bool Supports(IHasImages item)
{
return true;
}
@@ -91,11 +92,11 @@ namespace MediaBrowser.Server.Implementations.Photos
string cacheKey,
CancellationToken cancellationToken)
{
- var outputPath = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid() + ".png");
- Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
- var imageCreated = await CreateImage(item, itemsWithImages, outputPath, imageType, 0).ConfigureAwait(false);
+ var outputPathWithoutExtension = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid().ToString("N"));
+ FileSystem.CreateDirectory(Path.GetDirectoryName(outputPathWithoutExtension));
+ string outputPath = await CreateImage(item, itemsWithImages, outputPathWithoutExtension, imageType, 0).ConfigureAwait(false);
- if (!imageCreated)
+ if (string.IsNullOrWhiteSpace(outputPath))
{
return ItemUpdateType.None;
}
@@ -116,7 +117,7 @@ namespace MediaBrowser.Server.Implementations.Photos
return parts.GetMD5().ToString("N");
}
- protected Task<bool> CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
+ protected Task<string> CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
{
return CreateCollage(primaryItem, items, outputPath, 640, 360);
}
@@ -124,28 +125,43 @@ namespace MediaBrowser.Server.Implementations.Photos
protected virtual IEnumerable<string> GetStripCollageImagePaths(IHasImages primaryItem, IEnumerable<BaseItem> items)
{
return items
- .Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb))
+ .Select(i =>
+ {
+ var image = i.GetImageInfo(ImageType.Primary, 0);
+
+ if (image != null && image.IsLocalFile)
+ {
+ return image.Path;
+ }
+ image = i.GetImageInfo(ImageType.Thumb, 0);
+
+ if (image != null && image.IsLocalFile)
+ {
+ return image.Path;
+ }
+ return null;
+ })
.Where(i => !string.IsNullOrWhiteSpace(i));
}
- protected Task<bool> CreatePosterCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
+ protected Task<string> CreatePosterCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
{
return CreateCollage(primaryItem, items, outputPath, 400, 600);
}
- protected Task<bool> CreateSquareCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
+ protected Task<string> CreateSquareCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
{
return CreateCollage(primaryItem, items, outputPath, 600, 600);
}
- protected Task<bool> CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath, int width, int height)
+ protected Task<string> CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath, int width, int height)
{
return CreateCollage(primaryItem, items, outputPath, width, height);
}
- private Task<bool> CreateCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath, int width, int height)
+ private async Task<string> CreateCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath, int width, int height)
{
- Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
+ FileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
var options = new ImageCollageOptions
{
@@ -157,11 +173,16 @@ namespace MediaBrowser.Server.Implementations.Photos
if (options.InputPaths.Length == 0)
{
- return Task.FromResult(false);
+ return null;
+ }
+
+ if (!ImageProcessor.SupportsImageCollageCreation)
+ {
+ return null;
}
- ImageProcessor.CreateImageCollage(options);
- return Task.FromResult(true);
+ await ImageProcessor.CreateImageCollage(options).ConfigureAwait(false);
+ return outputPath;
}
public string Name
@@ -169,17 +190,19 @@ namespace MediaBrowser.Server.Implementations.Photos
get { return "Dynamic Image Provider"; }
}
- protected virtual async Task<bool> CreateImage(IHasImages item,
+ protected virtual async Task<string> CreateImage(IHasImages item,
List<BaseItem> itemsWithImages,
- string outputPath,
+ string outputPathWithoutExtension,
ImageType imageType,
int imageIndex)
{
if (itemsWithImages.Count == 0)
{
- return false;
+ return null;
}
+ string outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
+
if (imageType == ImageType.Thumb)
{
return await CreateThumbCollage(item, itemsWithImages, outputPath).ConfigureAwait(false);
@@ -191,7 +214,7 @@ namespace MediaBrowser.Server.Implementations.Photos
{
return await CreateSquareCollage(item, itemsWithImages, outputPath).ConfigureAwait(false);
}
- if (item is PhotoAlbum || item is Playlist)
+ if (item is Playlist)
{
return await CreateSquareCollage(item, itemsWithImages, outputPath).ConfigureAwait(false);
}
@@ -247,6 +270,11 @@ namespace MediaBrowser.Server.Implementations.Photos
if (image != null)
{
+ if (!image.IsLocalFile)
+ {
+ return false;
+ }
+
if (!FileSystem.ContainsSubPath(item.GetInternalMetadataPath(), image.Path))
{
return false;
@@ -268,6 +296,11 @@ namespace MediaBrowser.Server.Implementations.Photos
if (image != null)
{
+ if (!image.IsLocalFile)
+ {
+ return false;
+ }
+
if (!FileSystem.ContainsSubPath(item.GetInternalMetadataPath(), image.Path))
{
return false;
@@ -294,7 +327,7 @@ namespace MediaBrowser.Server.Implementations.Photos
var random = DateTime.Now.DayOfYear % MaxImageAgeDays;
return items
- .OrderBy(i => (random + "" + items.IndexOf(i)).GetMD5())
+ .OrderBy(i => (random + string.Empty + items.IndexOf(i)).GetMD5())
.Take(limit)
.OrderBy(i => i.Name)
.ToList();