Files
jellyfin-jellyfin-1/MediaBrowser.Server.Implementations/Photos/PhotoAlbumImageProvider.cs

50 lines
1.8 KiB
C#
Raw Normal View History

2015-05-13 10:43:34 -04:00
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
2014-10-29 18:01:02 -04:00
using MediaBrowser.Controller.Providers;
2014-08-11 22:59:51 -04:00
using System.Collections.Generic;
2015-10-26 01:29:32 -04:00
using System.IO;
2014-08-11 22:59:51 -04:00
using System.Linq;
using System.Threading.Tasks;
2015-10-04 00:23:11 -04:00
using CommonIO;
2015-10-28 12:42:04 -04:00
using MediaBrowser.Model.Entities;
2014-08-11 22:59:51 -04:00
2014-10-19 23:04:45 -04:00
namespace MediaBrowser.Server.Implementations.Photos
2014-08-11 22:59:51 -04:00
{
2015-05-13 10:43:34 -04:00
public class PhotoAlbumImageProvider : BaseDynamicImageProvider<PhotoAlbum>
2015-05-10 17:56:13 -04:00
{
2015-05-13 10:43:34 -04:00
public PhotoAlbumImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor)
: base(fileSystem, providerManager, applicationPaths, imageProcessor)
2015-05-10 17:56:13 -04:00
{
}
2014-10-19 23:04:45 -04:00
2015-05-13 10:43:34 -04:00
protected override Task<List<BaseItem>> GetItemsWithImages(IHasImages item)
2015-05-10 17:56:13 -04:00
{
2015-05-13 10:43:34 -04:00
var photoAlbum = (PhotoAlbum)item;
2015-10-30 12:45:22 -04:00
var items = GetFinalItems(photoAlbum.Children.ToList());
2014-10-19 23:04:45 -04:00
2015-05-13 10:43:34 -04:00
return Task.FromResult(items);
2015-05-10 17:56:13 -04:00
}
2015-10-26 01:29:32 -04:00
2015-10-28 12:42:04 -04:00
protected override async Task<string> CreateImage(IHasImages item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
2015-10-26 01:29:32 -04:00
{
2015-10-28 12:42:04 -04:00
var image = itemsWithImages
.Where(i => i.HasImage(ImageType.Primary) && i.GetImageInfo(ImageType.Primary, 0).IsLocalFile && Path.HasExtension(i.GetImagePath(ImageType.Primary)))
.Select(i => i.GetImagePath(ImageType.Primary))
.FirstOrDefault();
2015-10-26 01:29:32 -04:00
2015-10-28 12:42:04 -04:00
if (string.IsNullOrWhiteSpace(image))
2015-10-26 01:29:32 -04:00
{
return null;
}
2015-10-28 12:42:04 -04:00
var ext = Path.GetExtension(image);
2015-10-26 01:29:32 -04:00
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ext);
2015-10-28 12:42:04 -04:00
File.Copy(image, outputPath);
2015-10-26 01:29:32 -04:00
return outputPath;
}
2015-05-10 17:56:13 -04:00
}
2014-08-11 22:59:51 -04:00
}