2021-05-20 15:28:18 -04:00
|
|
|
#nullable disable
|
|
|
|
|
2020-05-29 05:28:19 -04:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 14:23:38 -05:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2021-12-11 21:31:30 -05:00
|
|
|
using Jellyfin.Data.Enums;
|
2021-12-20 07:31:07 -05:00
|
|
|
using Jellyfin.Extensions;
|
2019-01-06 15:50:43 -05:00
|
|
|
using MediaBrowser.Common.Configuration;
|
2015-04-08 10:38:02 -04:00
|
|
|
using MediaBrowser.Controller.Drawing;
|
2019-01-13 14:23:38 -05:00
|
|
|
using MediaBrowser.Controller.Dto;
|
2014-10-29 18:01:02 -04:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2015-03-13 15:52:49 -04:00
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-11-10 22:41:55 -05:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2014-10-29 18:01:02 -04:00
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2019-01-13 14:23:38 -05:00
|
|
|
using MediaBrowser.Model.IO;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
2019-12-14 01:27:03 -05:00
|
|
|
namespace Emby.Server.Implementations.Images
|
2014-10-29 18:01:02 -04:00
|
|
|
{
|
2015-04-26 00:39:40 -04:00
|
|
|
public class DynamicImageProvider : BaseDynamicImageProvider<UserView>
|
2014-10-29 18:01:02 -04:00
|
|
|
{
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
2020-05-29 05:28:19 -04:00
|
|
|
public DynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, IUserManager userManager)
|
2015-04-08 11:45:30 -04:00
|
|
|
: base(fileSystem, providerManager, applicationPaths, imageProcessor)
|
2014-10-29 18:01:02 -04:00
|
|
|
{
|
2015-03-06 22:53:31 -05:00
|
|
|
_userManager = userManager;
|
2015-03-14 00:50:23 -04:00
|
|
|
}
|
|
|
|
|
2019-03-07 09:54:30 -05:00
|
|
|
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
|
2014-10-29 18:01:02 -04:00
|
|
|
{
|
|
|
|
var view = (UserView)item;
|
|
|
|
|
2015-03-14 00:50:23 -04:00
|
|
|
var isUsingCollectionStrip = IsUsingCollectionStrip(view);
|
2021-12-20 07:31:07 -05:00
|
|
|
var recursive = isUsingCollectionStrip && !new[] { CollectionType.BoxSets, CollectionType.Playlists }.Contains(view.ViewType ?? string.Empty, StringComparison.OrdinalIgnoreCase);
|
2015-03-14 00:50:23 -04:00
|
|
|
|
2017-08-01 12:45:57 -04:00
|
|
|
var result = view.GetItemList(new InternalItemsQuery
|
2014-10-29 18:01:02 -04:00
|
|
|
{
|
2016-03-27 17:11:27 -04:00
|
|
|
User = view.UserId.HasValue ? _userManager.GetUserById(view.UserId.Value) : null,
|
2015-03-14 00:50:23 -04:00
|
|
|
CollapseBoxSetItems = false,
|
|
|
|
Recursive = recursive,
|
2021-12-11 21:31:30 -05:00
|
|
|
ExcludeItemTypes = new[] { BaseItemKind.UserView, BaseItemKind.CollectionFolder, BaseItemKind.Person },
|
2017-05-21 03:25:49 -04:00
|
|
|
DtoOptions = new DtoOptions(false)
|
2017-05-26 02:48:54 -04:00
|
|
|
});
|
2014-10-29 18:01:02 -04:00
|
|
|
|
2017-08-01 12:45:57 -04:00
|
|
|
var items = result.Select(i =>
|
2014-11-10 22:41:55 -05:00
|
|
|
{
|
2019-03-07 09:54:30 -05:00
|
|
|
if (i is Episode episode)
|
2014-11-10 22:41:55 -05:00
|
|
|
{
|
|
|
|
var series = episode.Series;
|
|
|
|
if (series != null)
|
|
|
|
{
|
|
|
|
return series;
|
|
|
|
}
|
|
|
|
|
|
|
|
return episode;
|
|
|
|
}
|
|
|
|
|
2019-03-07 09:54:30 -05:00
|
|
|
if (i is Season season)
|
2014-11-10 22:41:55 -05:00
|
|
|
{
|
|
|
|
var series = season.Series;
|
|
|
|
if (series != null)
|
|
|
|
{
|
|
|
|
return series;
|
|
|
|
}
|
|
|
|
|
|
|
|
return season;
|
|
|
|
}
|
|
|
|
|
2019-03-07 09:54:30 -05:00
|
|
|
if (i is Audio audio)
|
2015-03-13 15:52:49 -04:00
|
|
|
{
|
2015-05-04 10:35:38 -04:00
|
|
|
var album = audio.AlbumEntity;
|
2015-03-14 00:50:23 -04:00
|
|
|
if (album != null && album.HasImage(ImageType.Primary))
|
2015-03-13 15:52:49 -04:00
|
|
|
{
|
2015-03-14 00:50:23 -04:00
|
|
|
return album;
|
2015-03-13 15:52:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:41:55 -05:00
|
|
|
return i;
|
2019-02-02 06:27:06 -05:00
|
|
|
}).GroupBy(x => x.Id)
|
|
|
|
.Select(x => x.First());
|
2014-11-10 22:41:55 -05:00
|
|
|
|
2022-01-19 20:16:36 -05:00
|
|
|
List<BaseItem> returnItems;
|
2015-03-14 00:50:23 -04:00
|
|
|
if (isUsingCollectionStrip)
|
2015-03-13 15:52:49 -04:00
|
|
|
{
|
2022-01-19 20:16:36 -05:00
|
|
|
returnItems = items
|
2018-09-12 13:26:21 -04:00
|
|
|
.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb))
|
|
|
|
.ToList();
|
2022-01-19 20:16:36 -05:00
|
|
|
returnItems.Shuffle();
|
|
|
|
return returnItems;
|
2015-03-13 15:52:49 -04:00
|
|
|
}
|
2022-10-06 15:43:44 -04:00
|
|
|
|
2022-01-19 20:16:36 -05:00
|
|
|
returnItems = items
|
2018-09-12 13:26:21 -04:00
|
|
|
.Where(i => i.HasImage(ImageType.Primary))
|
|
|
|
.ToList();
|
2022-01-19 20:16:36 -05:00
|
|
|
returnItems.Shuffle();
|
|
|
|
return returnItems;
|
2014-10-29 18:01:02 -04:00
|
|
|
}
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
protected override bool Supports(BaseItem item)
|
2014-10-29 18:01:02 -04:00
|
|
|
{
|
2019-10-20 10:08:40 -04:00
|
|
|
if (item is UserView view)
|
2014-10-29 18:01:02 -04:00
|
|
|
{
|
2016-03-27 17:11:27 -04:00
|
|
|
return IsUsingCollectionStrip(view);
|
2014-10-29 18:01:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-13 15:52:49 -04:00
|
|
|
|
2019-01-06 15:50:43 -05:00
|
|
|
private static bool IsUsingCollectionStrip(UserView view)
|
2015-03-13 15:52:49 -04:00
|
|
|
{
|
2015-03-14 00:50:23 -04:00
|
|
|
string[] collectionStripViewTypes =
|
|
|
|
{
|
|
|
|
CollectionType.Movies,
|
2017-01-11 12:56:26 -05:00
|
|
|
CollectionType.TvShows,
|
2018-09-12 13:26:21 -04:00
|
|
|
CollectionType.Playlists
|
2015-03-14 00:50:23 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty);
|
2015-03-13 15:52:49 -04:00
|
|
|
}
|
2015-03-13 16:09:07 -04:00
|
|
|
|
2019-03-07 09:54:30 -05:00
|
|
|
protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
2015-03-13 16:09:07 -04:00
|
|
|
{
|
2016-12-02 15:45:11 -05:00
|
|
|
if (itemsWithImages.Count == 0)
|
2015-03-13 16:09:07 -04:00
|
|
|
{
|
2016-12-02 15:45:11 -05:00
|
|
|
return null;
|
2015-03-13 16:09:07 -04:00
|
|
|
}
|
|
|
|
|
2016-12-02 15:45:11 -05:00
|
|
|
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
|
|
|
|
|
2017-05-19 13:09:37 -04:00
|
|
|
return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540);
|
2015-03-13 16:09:07 -04:00
|
|
|
}
|
2014-10-29 18:01:02 -04:00
|
|
|
}
|
|
|
|
}
|