jellyfin/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs

118 lines
3.9 KiB
C#
Raw Normal View History

2015-07-26 22:03:34 -07:00
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Server.Implementations.Photos;
using MoreLinq;
using System;
using System.Collections.Generic;
2015-10-25 22:29:32 -07:00
using System.IO;
2015-07-26 22:03:34 -07:00
using System.Linq;
using System.Threading.Tasks;
2015-10-03 21:23:11 -07:00
using CommonIO;
2015-07-26 22:03:34 -07:00
namespace MediaBrowser.Server.Implementations.UserViews
{
public class CollectionFolderImageProvider : BaseDynamicImageProvider<CollectionFolder>
{
public CollectionFolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
{
}
public override IEnumerable<ImageType> GetSupportedImages(IHasImages item)
{
return new List<ImageType>
{
ImageType.Primary
};
}
protected override async Task<List<BaseItem>> GetItemsWithImages(IHasImages item)
{
var view = (CollectionFolder)item;
var recursive = !new[] { CollectionType.Playlists, CollectionType.Channels }.Contains(view.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
var result = await view.GetItems(new InternalItemsQuery
{
CollapseBoxSetItems = false,
Recursive = recursive,
ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Playlist" }
}).ConfigureAwait(false);
var items = result.Items.Select(i =>
{
var episode = i as Episode;
if (episode != null)
{
var series = episode.Series;
if (series != null)
{
return series;
}
var episodeSeason = episode.Season;
if (episodeSeason != null)
{
return episodeSeason;
}
return episode;
}
var season = i as Season;
if (season != null)
{
var series = season.Series;
if (series != null)
{
return series;
}
return season;
}
var audio = i as Audio;
if (audio != null)
{
var album = audio.AlbumEntity;
if (album != null && album.HasImage(ImageType.Primary))
{
return album;
}
}
return i;
}).DistinctBy(i => i.Id);
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)).ToList(), 8);
}
2015-10-13 22:02:30 -07:00
protected override bool Supports(IHasImages item)
2015-07-26 22:03:34 -07:00
{
return item is CollectionFolder;
}
2015-10-25 22:29:32 -07:00
protected override async Task<string> CreateImage(IHasImages item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
2015-07-26 22:03:34 -07:00
{
2015-10-25 22:29:32 -07:00
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
2015-07-26 22:03:34 -07:00
if (imageType == ImageType.Primary)
{
if (itemsWithImages.Count == 0)
{
2015-10-25 22:29:32 -07:00
return null;
2015-07-26 22:03:34 -07:00
}
2015-08-14 10:24:07 -07:00
return await CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540).ConfigureAwait(false);
2015-07-26 22:03:34 -07:00
}
return await base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex).ConfigureAwait(false);
}
}
}