jellyfin/Emby.Server.Implementations/Images/CollectionFolderImageProvider.cs

102 lines
3.7 KiB
C#
Raw Normal View History

#nullable disable
#pragma warning disable CS1591
using System;
2015-07-27 07:03:34 +02:00
using System.Collections.Generic;
2015-10-26 06:29:32 +01:00
using System.IO;
2020-07-01 03:44:41 +02:00
using Jellyfin.Data.Enums;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing;
2017-05-21 09:25:49 +02:00
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
2016-09-05 22:07:36 +02:00
using MediaBrowser.Model.Querying;
2015-07-27 07:03:34 +02:00
namespace Emby.Server.Implementations.Images
2015-07-27 07:03:34 +02:00
{
public class CollectionFolderImageProvider : BaseDynamicImageProvider<CollectionFolder>
{
public CollectionFolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
{
}
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
2015-07-27 07:03:34 +02:00
{
var view = (CollectionFolder)item;
2018-09-12 19:26:21 +02:00
var viewType = view.CollectionType;
2015-07-27 07:03:34 +02:00
2021-12-12 03:31:30 +01:00
BaseItemKind[] includeItemTypes;
2015-07-27 07:03:34 +02:00
switch (viewType)
2015-07-27 07:03:34 +02:00
{
case CollectionType.movies:
includeItemTypes = new[] { BaseItemKind.Movie };
break;
case CollectionType.tvshows:
includeItemTypes = new[] { BaseItemKind.Series };
break;
case CollectionType.music:
includeItemTypes = new[] { BaseItemKind.MusicAlbum };
break;
case CollectionType.musicvideos:
includeItemTypes = new[] { BaseItemKind.MusicVideo };
break;
case CollectionType.books:
includeItemTypes = new[] { BaseItemKind.Book, BaseItemKind.AudioBook };
break;
case CollectionType.boxsets:
includeItemTypes = new[] { BaseItemKind.BoxSet };
break;
case CollectionType.homevideos:
case CollectionType.photos:
includeItemTypes = new[] { BaseItemKind.Video, BaseItemKind.Photo };
break;
default:
includeItemTypes = new[] { BaseItemKind.Video, BaseItemKind.Audio, BaseItemKind.Photo, BaseItemKind.Movie, BaseItemKind.Series };
break;
2015-07-27 07:03:34 +02:00
}
var recursive = viewType != CollectionType.playlists;
2016-09-05 22:07:36 +02:00
2018-09-12 19:26:21 +02:00
return view.GetItemList(new InternalItemsQuery
2016-09-05 22:07:36 +02:00
{
2018-09-12 19:26:21 +02:00
CollapseBoxSetItems = false,
2016-09-05 22:07:36 +02:00
Recursive = recursive,
2018-09-12 19:26:21 +02:00
DtoOptions = new DtoOptions(false),
ImageTypes = new[] { ImageType.Primary },
2018-09-12 19:26:21 +02:00
Limit = 8,
2021-12-24 22:18:24 +01:00
OrderBy = new[]
2018-09-12 19:26:21 +02:00
{
2021-12-24 22:18:24 +01:00
(ItemSortBy.Random, SortOrder.Ascending)
2018-09-12 19:26:21 +02:00
},
IncludeItemTypes = includeItemTypes
});
2016-09-05 22:07:36 +02:00
}
2018-09-12 19:26:21 +02:00
protected override bool Supports(BaseItem item)
2016-09-05 22:07:36 +02:00
{
2018-09-12 19:26:21 +02:00
return item is CollectionFolder;
2016-09-05 22:07:36 +02:00
}
protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
2016-09-05 22:07:36 +02:00
{
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
if (imageType == ImageType.Primary)
{
if (itemsWithImages.Count == 0)
{
return null;
}
2017-05-19 19:09:37 +02:00
return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540);
2016-09-05 22:07:36 +02:00
}
2017-05-19 19:09:37 +02:00
return base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex);
2016-09-05 22:07:36 +02:00
}
}
2015-07-27 07:03:34 +02:00
}