mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Always use 1080p, add max parental rating
This commit is contained in:
parent
c934269a6e
commit
0fd4ff4451
@ -52,8 +52,6 @@ namespace Jellyfin.Api.Controllers
|
|||||||
/// Generates or gets the splashscreen.
|
/// Generates or gets the splashscreen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="darken">Darken the generated image.</param>
|
/// <param name="darken">Darken the generated image.</param>
|
||||||
/// <param name="width">The image width.</param>
|
|
||||||
/// <param name="height">The image height.</param>
|
|
||||||
/// <param name="regenerate">Whether to regenerate the image, regardless if one already exists.</param>
|
/// <param name="regenerate">Whether to regenerate the image, regardless if one already exists.</param>
|
||||||
/// <returns>The splashscreen.</returns>
|
/// <returns>The splashscreen.</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -62,11 +60,9 @@ namespace Jellyfin.Api.Controllers
|
|||||||
[ProducesImageFile]
|
[ProducesImageFile]
|
||||||
public ActionResult GetSplashscreen(
|
public ActionResult GetSplashscreen(
|
||||||
[FromQuery] bool? darken = false,
|
[FromQuery] bool? darken = false,
|
||||||
[FromQuery] int? width = 1920,
|
|
||||||
[FromQuery] int? height = 1080,
|
|
||||||
[FromQuery] bool? regenerate = false)
|
[FromQuery] bool? regenerate = false)
|
||||||
{
|
{
|
||||||
var outputPath = Path.Combine(_appPaths.DataPath, $"splashscreen-{width}x{height}-{darken}.jpg");
|
var outputPath = Path.Combine(_appPaths.DataPath, $"splashscreen-{darken}.jpg");
|
||||||
|
|
||||||
if (!System.IO.File.Exists(outputPath) || (regenerate ?? false))
|
if (!System.IO.File.Exists(outputPath) || (regenerate ?? false))
|
||||||
{
|
{
|
||||||
@ -74,11 +70,13 @@ namespace Jellyfin.Api.Controllers
|
|||||||
var landscape = GetItemsWithImageType(ImageType.Thumb).Select(x => x.GetImages(ImageType.Thumb).First().Path).ToList();
|
var landscape = GetItemsWithImageType(ImageType.Thumb).Select(x => x.GetImages(ImageType.Thumb).First().Path).ToList();
|
||||||
if (landscape.Count == 0)
|
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.");
|
_logger.LogDebug("No thumb images found. Using backdrops to generate splashscreen.");
|
||||||
landscape = GetItemsWithImageType(ImageType.Backdrop).Select(x => x.GetImages(ImageType.Backdrop).First().Path).ToList();
|
landscape = GetItemsWithImageType(ImageType.Backdrop).Select(x => x.GetImages(ImageType.Backdrop).First().Path).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
_imageEncoder.CreateSplashscreen(new SplashscreenOptions(posters, landscape, outputPath, width!.Value, height!.Value, darken!.Value));
|
_imageEncoder.CreateSplashscreen(new SplashscreenOptions(posters, landscape, outputPath, darken!.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return PhysicalFile(outputPath, MimeTypes.GetMimeType(outputPath));
|
return PhysicalFile(outputPath, MimeTypes.GetMimeType(outputPath));
|
||||||
@ -86,13 +84,16 @@ namespace Jellyfin.Api.Controllers
|
|||||||
|
|
||||||
private IReadOnlyList<BaseItem> GetItemsWithImageType(ImageType imageType)
|
private IReadOnlyList<BaseItem> GetItemsWithImageType(ImageType imageType)
|
||||||
{
|
{
|
||||||
|
// todo make included libraries configurable
|
||||||
return _itemRepository.GetItemList(new InternalItemsQuery
|
return _itemRepository.GetItemList(new InternalItemsQuery
|
||||||
{
|
{
|
||||||
CollapseBoxSetItems = false,
|
CollapseBoxSetItems = false,
|
||||||
Recursive = true,
|
Recursive = true,
|
||||||
DtoOptions = new DtoOptions(false),
|
DtoOptions = new DtoOptions(false),
|
||||||
ImageTypes = new ImageType[] { imageType },
|
ImageTypes = new ImageType[] { imageType },
|
||||||
Limit = 8,
|
Limit = 30,
|
||||||
|
// todo max parental rating configurable
|
||||||
|
MaxParentalRating = 10,
|
||||||
OrderBy = new ValueTuple<string, SortOrder>[]
|
OrderBy = new ValueTuple<string, SortOrder>[]
|
||||||
{
|
{
|
||||||
new ValueTuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending)
|
new ValueTuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending)
|
||||||
|
@ -10,14 +10,17 @@ namespace Jellyfin.Drawing.Skia
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SplashscreenBuilder
|
public class SplashscreenBuilder
|
||||||
{
|
{
|
||||||
|
private const int FinalWidth = 1920;
|
||||||
|
private const int FinalHeight = 1080;
|
||||||
|
// generated collage resolution should be higher than the final resolution
|
||||||
|
private const int WallWidth = FinalWidth * 3;
|
||||||
|
private const int WallHeight = FinalHeight * 2;
|
||||||
private const int Rows = 6;
|
private const int Rows = 6;
|
||||||
private const int Spacing = 20;
|
private const int Spacing = 20;
|
||||||
|
|
||||||
private readonly SkiaEncoder _skiaEncoder;
|
private readonly SkiaEncoder _skiaEncoder;
|
||||||
|
|
||||||
private Random? _random;
|
private Random? _random;
|
||||||
private int _finalWidth;
|
|
||||||
private int _finalHeight;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SplashscreenBuilder"/> class.
|
/// Initializes a new instance of the <see cref="SplashscreenBuilder"/> class.
|
||||||
@ -34,13 +37,11 @@ namespace Jellyfin.Drawing.Skia
|
|||||||
/// <param name="options">The options to generate the splashscreen.</param>
|
/// <param name="options">The options to generate the splashscreen.</param>
|
||||||
public void GenerateSplash(SplashscreenOptions options)
|
public void GenerateSplash(SplashscreenOptions options)
|
||||||
{
|
{
|
||||||
_finalWidth = options.Width;
|
|
||||||
_finalHeight = options.Height;
|
|
||||||
var wall = GenerateCollage(options.PortraitInputPaths, options.LandscapeInputPaths, options.ApplyFilter);
|
var wall = GenerateCollage(options.PortraitInputPaths, options.LandscapeInputPaths, options.ApplyFilter);
|
||||||
var transformed = Transform3D(wall);
|
var transformed = Transform3D(wall);
|
||||||
|
|
||||||
using var outputStream = new SKFileWStream(options.OutputPath);
|
using var outputStream = new SKFileWStream(options.OutputPath);
|
||||||
using var pixmap = new SKPixmap(new SKImageInfo(_finalWidth, _finalHeight), transformed.GetPixels());
|
using var pixmap = new SKPixmap(new SKImageInfo(FinalWidth, FinalHeight), transformed.GetPixels());
|
||||||
pixmap.Encode(outputStream, StripCollageBuilder.GetEncodedFormat(options.OutputPath), 90);
|
pixmap.Encode(outputStream, StripCollageBuilder.GetEncodedFormat(options.OutputPath), 90);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,12 +59,11 @@ namespace Jellyfin.Drawing.Skia
|
|||||||
var posterIndex = 0;
|
var posterIndex = 0;
|
||||||
var backdropIndex = 0;
|
var backdropIndex = 0;
|
||||||
|
|
||||||
// use higher resolution than final image
|
var bitmap = new SKBitmap(WallWidth, WallHeight);
|
||||||
var bitmap = new SKBitmap(_finalWidth * 3, _finalHeight * 2);
|
|
||||||
using var canvas = new SKCanvas(bitmap);
|
using var canvas = new SKCanvas(bitmap);
|
||||||
canvas.Clear(SKColors.Black);
|
canvas.Clear(SKColors.Black);
|
||||||
|
|
||||||
int posterHeight = _finalHeight * 2 / 6;
|
int posterHeight = WallHeight / 6;
|
||||||
|
|
||||||
for (int i = 0; i < Rows; i++)
|
for (int i = 0; i < Rows; i++)
|
||||||
{
|
{
|
||||||
@ -71,7 +71,7 @@ namespace Jellyfin.Drawing.Skia
|
|||||||
int currentWidthPos = i * 75;
|
int currentWidthPos = i * 75;
|
||||||
int currentHeight = i * (posterHeight + Spacing);
|
int currentHeight = i * (posterHeight + Spacing);
|
||||||
|
|
||||||
while (currentWidthPos < _finalWidth * 3)
|
while (currentWidthPos < WallWidth)
|
||||||
{
|
{
|
||||||
SKBitmap? currentImage;
|
SKBitmap? currentImage;
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ namespace Jellyfin.Drawing.Skia
|
|||||||
Color = SKColors.Black.WithAlpha(0x50),
|
Color = SKColors.Black.WithAlpha(0x50),
|
||||||
Style = SKPaintStyle.Fill
|
Style = SKPaintStyle.Fill
|
||||||
};
|
};
|
||||||
canvas.DrawRect(0, 0, _finalWidth * 3, _finalHeight * 2, paintColor);
|
canvas.DrawRect(0, 0, WallWidth, WallHeight, paintColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
@ -137,7 +137,7 @@ namespace Jellyfin.Drawing.Skia
|
|||||||
/// <returns>The transformed image.</returns>
|
/// <returns>The transformed image.</returns>
|
||||||
private SKBitmap Transform3D(SKBitmap input)
|
private SKBitmap Transform3D(SKBitmap input)
|
||||||
{
|
{
|
||||||
var bitmap = new SKBitmap(_finalWidth, _finalHeight);
|
var bitmap = new SKBitmap(FinalWidth, FinalHeight);
|
||||||
using var canvas = new SKCanvas(bitmap);
|
using var canvas = new SKCanvas(bitmap);
|
||||||
canvas.Clear(SKColors.Black);
|
canvas.Clear(SKColors.Black);
|
||||||
var matrix = new SKMatrix
|
var matrix = new SKMatrix
|
||||||
|
@ -16,13 +16,11 @@ namespace MediaBrowser.Controller.Drawing
|
|||||||
/// <param name="width">Optional. The image width.</param>
|
/// <param name="width">Optional. The image width.</param>
|
||||||
/// <param name="height">Optional. The image height.</param>
|
/// <param name="height">Optional. The image height.</param>
|
||||||
/// <param name="applyFilter">Optional. Apply a darkening filter.</param>
|
/// <param name="applyFilter">Optional. Apply a darkening filter.</param>
|
||||||
public SplashscreenOptions(IReadOnlyList<string> portraitInputPaths, IReadOnlyList<string> landscapeInputPaths, string outputPath, int width = 1920, int height = 1080, bool applyFilter = false)
|
public SplashscreenOptions(IReadOnlyList<string> portraitInputPaths, IReadOnlyList<string> landscapeInputPaths, string outputPath, bool applyFilter = false)
|
||||||
{
|
{
|
||||||
PortraitInputPaths = portraitInputPaths;
|
PortraitInputPaths = portraitInputPaths;
|
||||||
LandscapeInputPaths = landscapeInputPaths;
|
LandscapeInputPaths = landscapeInputPaths;
|
||||||
OutputPath = outputPath;
|
OutputPath = outputPath;
|
||||||
Width = width;
|
|
||||||
Height = height;
|
|
||||||
ApplyFilter = applyFilter;
|
ApplyFilter = applyFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,16 +39,6 @@ namespace MediaBrowser.Controller.Drawing
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string OutputPath { get; set; }
|
public string OutputPath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the width.
|
|
||||||
/// </summary>
|
|
||||||
public int Width { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the height.
|
|
||||||
/// </summary>
|
|
||||||
public int Height { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether to apply a darkening filter at the end.
|
/// Gets or sets a value indicating whether to apply a darkening filter at the end.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user