2021-08-17 16:11:38 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2022-01-10 15:25:46 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2021-08-17 16:11:38 +00:00
|
|
|
using Jellyfin.Data.Enums;
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2022-01-10 15:25:46 +00:00
|
|
|
using MediaBrowser.Controller.Library;
|
2021-08-17 16:11:38 +00:00
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
2022-01-10 15:25:46 +00:00
|
|
|
namespace Emby.Server.Implementations.Library;
|
2022-01-04 15:37:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2022-01-10 15:25:46 +00:00
|
|
|
/// The splashscreen post scan task.
|
2022-01-04 15:37:57 +00:00
|
|
|
/// </summary>
|
2022-01-10 15:25:46 +00:00
|
|
|
public class SplashscreenPostScanTask : ILibraryPostScanTask
|
2021-08-17 16:11:38 +00:00
|
|
|
{
|
2022-01-04 15:37:57 +00:00
|
|
|
private readonly IItemRepository _itemRepository;
|
2022-01-10 15:25:46 +00:00
|
|
|
private readonly IImageEncoder _imageEncoder;
|
|
|
|
private readonly ILogger<SplashscreenPostScanTask> _logger;
|
2022-01-04 15:37:57 +00:00
|
|
|
|
2021-08-17 16:11:38 +00:00
|
|
|
/// <summary>
|
2022-01-10 15:25:46 +00:00
|
|
|
/// Initializes a new instance of the <see cref="SplashscreenPostScanTask"/> class.
|
2021-08-17 16:11:38 +00:00
|
|
|
/// </summary>
|
2022-01-04 15:37:57 +00:00
|
|
|
/// <param name="itemRepository">Instance of the <see cref="IItemRepository"/> interface.</param>
|
2022-01-10 15:25:46 +00:00
|
|
|
/// <param name="imageEncoder">Instance of the <see cref="IImageEncoder"/> interface.</param>
|
2022-01-10 15:30:55 +00:00
|
|
|
/// <param name="logger">Instance of the <see cref="ILogger{SplashscreenPostScanTask}"/> interface.</param>
|
2022-01-10 15:25:46 +00:00
|
|
|
public SplashscreenPostScanTask(
|
2022-01-04 15:37:57 +00:00
|
|
|
IItemRepository itemRepository,
|
2022-01-10 15:25:46 +00:00
|
|
|
IImageEncoder imageEncoder,
|
|
|
|
ILogger<SplashscreenPostScanTask> logger)
|
2021-08-17 16:11:38 +00:00
|
|
|
{
|
2022-01-04 15:37:57 +00:00
|
|
|
_itemRepository = itemRepository;
|
2022-01-10 15:25:46 +00:00
|
|
|
_imageEncoder = imageEncoder;
|
2022-01-04 15:37:57 +00:00
|
|
|
_logger = logger;
|
|
|
|
}
|
2021-08-17 16:11:38 +00:00
|
|
|
|
2022-01-10 15:25:46 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
2022-01-04 15:37:57 +00:00
|
|
|
{
|
|
|
|
var posters = GetItemsWithImageType(ImageType.Primary).Select(x => x.GetImages(ImageType.Primary).First().Path).ToList();
|
2022-01-10 15:25:46 +00:00
|
|
|
var backdrops = GetItemsWithImageType(ImageType.Thumb).Select(x => x.GetImages(ImageType.Thumb).First().Path).ToList();
|
|
|
|
if (backdrops.Count == 0)
|
2021-08-17 16:11:38 +00:00
|
|
|
{
|
2022-01-04 15:37:57 +00:00
|
|
|
// Thumb images fit better because they include the title in the image but are not provided with TMDb.
|
|
|
|
// Using backdrops as a fallback to generate an image at all
|
|
|
|
_logger.LogDebug("No thumb images found. Using backdrops to generate splashscreen");
|
2022-01-10 15:25:46 +00:00
|
|
|
backdrops = GetItemsWithImageType(ImageType.Backdrop).Select(x => x.GetImages(ImageType.Backdrop).First().Path).ToList();
|
2021-08-17 16:11:38 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 15:25:46 +00:00
|
|
|
_imageEncoder.CreateSplashscreen(posters, backdrops);
|
|
|
|
return Task.CompletedTask;
|
2022-01-04 15:37:57 +00:00
|
|
|
}
|
2021-08-17 16:11:38 +00:00
|
|
|
|
2022-01-04 15:37:57 +00:00
|
|
|
private IReadOnlyList<BaseItem> GetItemsWithImageType(ImageType imageType)
|
|
|
|
{
|
2022-01-10 15:25:46 +00:00
|
|
|
// TODO make included libraries configurable
|
2022-01-04 15:37:57 +00:00
|
|
|
return _itemRepository.GetItemList(new InternalItemsQuery
|
2021-08-17 16:11:38 +00:00
|
|
|
{
|
2022-01-04 15:37:57 +00:00
|
|
|
CollapseBoxSetItems = false,
|
|
|
|
Recursive = true,
|
|
|
|
DtoOptions = new DtoOptions(false),
|
|
|
|
ImageTypes = new[] { imageType },
|
|
|
|
Limit = 30,
|
2022-01-10 15:25:46 +00:00
|
|
|
// TODO max parental rating configurable
|
2022-01-04 15:37:57 +00:00
|
|
|
MaxParentalRating = 10,
|
2022-01-10 17:59:32 +00:00
|
|
|
OrderBy = new[]
|
2021-08-17 16:11:38 +00:00
|
|
|
{
|
2022-01-10 17:59:32 +00:00
|
|
|
(ItemSortBy.Random, SortOrder.Ascending)
|
2022-01-04 15:37:57 +00:00
|
|
|
},
|
|
|
|
IncludeItemTypes = new[] { BaseItemKind.Movie, BaseItemKind.Series }
|
|
|
|
});
|
2021-08-17 16:11:38 +00:00
|
|
|
}
|
|
|
|
}
|