parent
0fd4ff4451
commit
3fb3ee074a
@ -1,105 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Jellyfin.Api.Attributes;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Net;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Splashscreen controller.
|
||||
/// </summary>
|
||||
[Route("Splashscreen")]
|
||||
public class SplashscreenController : BaseJellyfinApiController
|
||||
{
|
||||
private readonly IImageEncoder _imageEncoder;
|
||||
private readonly IItemRepository _itemRepository;
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SplashscreenController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="imageEncoder">Instance of the <see cref="IImageEncoder"/> interface.</param>
|
||||
/// <param name="itemRepository">Instance of the <see cref="IItemRepository"/> interface.</param>
|
||||
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
public SplashscreenController(
|
||||
IImageEncoder imageEncoder,
|
||||
IItemRepository itemRepository,
|
||||
IApplicationPaths applicationPaths,
|
||||
ILogger<SplashscreenController> logger)
|
||||
{
|
||||
_imageEncoder = imageEncoder;
|
||||
_itemRepository = itemRepository;
|
||||
_appPaths = applicationPaths;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates or gets the splashscreen.
|
||||
/// </summary>
|
||||
/// <param name="darken">Darken the generated image.</param>
|
||||
/// <param name="regenerate">Whether to regenerate the image, regardless if one already exists.</param>
|
||||
/// <returns>The splashscreen.</returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesImageFile]
|
||||
public ActionResult GetSplashscreen(
|
||||
[FromQuery] bool? darken = false,
|
||||
[FromQuery] bool? regenerate = false)
|
||||
{
|
||||
var outputPath = Path.Combine(_appPaths.DataPath, $"splashscreen-{darken}.jpg");
|
||||
|
||||
if (!System.IO.File.Exists(outputPath) || (regenerate ?? false))
|
||||
{
|
||||
var posters = GetItemsWithImageType(ImageType.Primary).Select(x => x.GetImages(ImageType.Primary).First().Path).ToList();
|
||||
var landscape = GetItemsWithImageType(ImageType.Thumb).Select(x => x.GetImages(ImageType.Thumb).First().Path).ToList();
|
||||
if (landscape.Count == 0)
|
||||
{
|
||||
// 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.");
|
||||
landscape = GetItemsWithImageType(ImageType.Backdrop).Select(x => x.GetImages(ImageType.Backdrop).First().Path).ToList();
|
||||
}
|
||||
|
||||
_imageEncoder.CreateSplashscreen(new SplashscreenOptions(posters, landscape, outputPath, darken!.Value));
|
||||
}
|
||||
|
||||
return PhysicalFile(outputPath, MimeTypes.GetMimeType(outputPath));
|
||||
}
|
||||
|
||||
private IReadOnlyList<BaseItem> GetItemsWithImageType(ImageType imageType)
|
||||
{
|
||||
// todo make included libraries configurable
|
||||
return _itemRepository.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
CollapseBoxSetItems = false,
|
||||
Recursive = true,
|
||||
DtoOptions = new DtoOptions(false),
|
||||
ImageTypes = new ImageType[] { imageType },
|
||||
Limit = 30,
|
||||
// todo max parental rating configurable
|
||||
MaxParentalRating = 10,
|
||||
OrderBy = new ValueTuple<string, SortOrder>[]
|
||||
{
|
||||
new ValueTuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending)
|
||||
},
|
||||
IncludeItemTypes = new string[] { "Movie", "Series" }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Drawing.Skia
|
||||
{
|
||||
/// <summary>
|
||||
/// The default image generator.
|
||||
/// </summary>
|
||||
public class DefaultImageGenerator : IImageGenerator
|
||||
{
|
||||
private readonly IImageEncoder _imageEncoder;
|
||||
private readonly IItemRepository _itemRepository;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DefaultImageGenerator"/> class.
|
||||
/// </summary>
|
||||
/// <param name="imageEncoder">Instance of the <see cref="IImageEncoder"/> interface.</param>
|
||||
/// <param name="itemRepository">Instance of the <see cref="IItemRepository"/> interface.</param>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
public DefaultImageGenerator(
|
||||
IImageEncoder imageEncoder,
|
||||
IItemRepository itemRepository,
|
||||
ILogger<DefaultImageGenerator> logger)
|
||||
{
|
||||
_imageEncoder = imageEncoder;
|
||||
_itemRepository = itemRepository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public GeneratedImages[] GetSupportedImages()
|
||||
{
|
||||
return new[] { GeneratedImages.Splashscreen };
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void GenerateSplashscreen(SplashscreenOptions generationOptions)
|
||||
{
|
||||
var posters = GetItemsWithImageType(ImageType.Primary).Select(x => x.GetImages(ImageType.Primary).First().Path).ToList();
|
||||
var landscape = GetItemsWithImageType(ImageType.Thumb).Select(x => x.GetImages(ImageType.Thumb).First().Path).ToList();
|
||||
if (landscape.Count == 0)
|
||||
{
|
||||
// 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.");
|
||||
landscape = GetItemsWithImageType(ImageType.Backdrop).Select(x => x.GetImages(ImageType.Backdrop).First().Path).ToList();
|
||||
}
|
||||
|
||||
var splashBuilder = new SplashscreenBuilder((SkiaEncoder)_imageEncoder);
|
||||
splashBuilder.GenerateSplash(posters, landscape, generationOptions.OutputPath, generationOptions.ApplyFilter);
|
||||
}
|
||||
|
||||
private IReadOnlyList<BaseItem> GetItemsWithImageType(ImageType imageType)
|
||||
{
|
||||
// todo make included libraries configurable
|
||||
return _itemRepository.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
CollapseBoxSetItems = false,
|
||||
Recursive = true,
|
||||
DtoOptions = new DtoOptions(false),
|
||||
ImageTypes = new ImageType[] { imageType },
|
||||
Limit = 30,
|
||||
// todo max parental rating configurable
|
||||
MaxParentalRating = 10,
|
||||
OrderBy = new ValueTuple<string, SortOrder>[]
|
||||
{
|
||||
new ValueTuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending)
|
||||
},
|
||||
IncludeItemTypes = new string[] { "Movie", "Series" }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
namespace MediaBrowser.Controller.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Which generated images an <see cref="IImageGenerator"/> supports.
|
||||
/// </summary>
|
||||
public enum GeneratedImages
|
||||
{
|
||||
/// <summary>
|
||||
/// The splashscreen.
|
||||
/// </summary>
|
||||
Splashscreen
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace MediaBrowser.Controller.Drawing
|
||||
{
|
||||
public interface IImageGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the supported generated images of the image generator.
|
||||
/// </summary>
|
||||
/// <returns>The supported images.</returns>
|
||||
GeneratedImages[] GetSupportedImages();
|
||||
|
||||
/// <summary>
|
||||
/// Generates a splashscreen.
|
||||
/// </summary>
|
||||
/// <param name="generationOptions">The options used to generate the splashscreen.</param>
|
||||
void GenerateSplashscreen(SplashscreenOptions generationOptions);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue