This commit is contained in:
Cody Robibero 2022-01-04 08:37:57 -07:00
parent 9e0958d822
commit 360fd70fc7
8 changed files with 134 additions and 132 deletions

View File

@ -83,7 +83,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
progress.Report(0); progress.Report(0);
_imageGenerator.GenerateSplashscreen(Path.Combine(_applicationPaths.DataPath, "splashscreen.webp")); _imageGenerator.Generate(GeneratedImageType.Splashscreen, Path.Combine(_applicationPaths.DataPath, "splashscreen.webp"));
return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken); return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken);
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
@ -1705,18 +1706,18 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Generates or gets the splashscreen. /// Generates or gets the splashscreen.
/// </summary> /// </summary>
/// <param name="tag">Optional. Supply the cache tag from the item object to receive strong caching headers.</param> /// <param name="tag">Supply the cache tag from the item object to receive strong caching headers.</param>
/// <param name="format">Determines the output format of the image - original,gif,jpg,png.</param> /// <param name="format">Determines the output format of the image - original,gif,jpg,png.</param>
/// <param name="maxWidth">The maximum image width to return.</param> /// <param name="maxWidth">The maximum image width to return.</param>
/// <param name="maxHeight">The maximum image height to return.</param> /// <param name="maxHeight">The maximum image height to return.</param>
/// <param name="width">The fixed image width to return.</param> /// <param name="width">The fixed image width to return.</param>
/// <param name="height">The fixed image height to return.</param> /// <param name="height">The fixed image height to return.</param>
/// <param name="quality">Optional. Quality setting, from 0-100. Defaults to 90 and should suffice in most cases.</param>
/// <param name="fillWidth">Width of box to fill.</param> /// <param name="fillWidth">Width of box to fill.</param>
/// <param name="fillHeight">Height of box to fill.</param> /// <param name="fillHeight">Height of box to fill.</param>
/// <param name="blur">Optional. Blur image.</param> /// <param name="blur">Blur image.</param>
/// <param name="backgroundColor">Optional. Apply a background color for transparent images.</param> /// <param name="backgroundColor">Apply a background color for transparent images.</param>
/// <param name="foregroundLayer">Optional. Apply a foreground layer on top of the image.</param> /// <param name="foregroundLayer">Apply a foreground layer on top of the image.</param>
/// <param name="quality">Quality setting, from 0-100.</param>
/// <response code="200">Splashscreen returned successfully.</response> /// <response code="200">Splashscreen returned successfully.</response>
/// <returns>The splashscreen.</returns> /// <returns>The splashscreen.</returns>
[HttpGet("Branding/Splashscreen")] [HttpGet("Branding/Splashscreen")]
@ -1729,12 +1730,12 @@ namespace Jellyfin.Api.Controllers
[FromQuery] int? maxHeight, [FromQuery] int? maxHeight,
[FromQuery] int? width, [FromQuery] int? width,
[FromQuery] int? height, [FromQuery] int? height,
[FromQuery] int? quality,
[FromQuery] int? fillWidth, [FromQuery] int? fillWidth,
[FromQuery] int? fillHeight, [FromQuery] int? fillHeight,
[FromQuery] int? blur, [FromQuery] int? blur,
[FromQuery] string? backgroundColor, [FromQuery] string? backgroundColor,
[FromQuery] string? foregroundLayer) [FromQuery] string? foregroundLayer,
[FromQuery, Range(0, 100)] int quality = 90)
{ {
string splashscreenPath; string splashscreenPath;
var brandingOptions = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding"); var brandingOptions = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
@ -1746,9 +1747,9 @@ namespace Jellyfin.Api.Controllers
{ {
splashscreenPath = Path.Combine(_appPaths.DataPath, "splashscreen.webp"); splashscreenPath = Path.Combine(_appPaths.DataPath, "splashscreen.webp");
if (!System.IO.File.Exists(splashscreenPath) && _imageGenerator.GetSupportedImages().Contains(GeneratedImages.Splashscreen)) if (!System.IO.File.Exists(splashscreenPath) && _imageGenerator.GetSupportedImages().Contains(GeneratedImageType.Splashscreen))
{ {
_imageGenerator.GenerateSplashscreen(splashscreenPath); _imageGenerator.Generate(GeneratedImageType.Splashscreen, splashscreenPath);
} }
} }
@ -1771,18 +1772,20 @@ namespace Jellyfin.Api.Controllers
MaxWidth = maxWidth, MaxWidth = maxWidth,
FillHeight = fillHeight, FillHeight = fillHeight,
FillWidth = fillWidth, FillWidth = fillWidth,
Quality = quality ?? 100, Quality = quality,
Width = width, Width = width,
Blur = blur, Blur = blur,
BackgroundColor = backgroundColor, BackgroundColor = backgroundColor,
ForegroundLayer = foregroundLayer, ForegroundLayer = foregroundLayer,
SupportedOutputFormats = outputFormats SupportedOutputFormats = outputFormats
}; };
return await GetImageResult( return await GetImageResult(
options, options,
cacheDuration, cacheDuration,
new Dictionary<string, string>(), ImmutableDictionary<string, string>.Empty,
Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase)); Request.Method.Equals(HttpMethods.Head, StringComparison.OrdinalIgnoreCase))
.ConfigureAwait(false);
} }
/// <summary> /// <summary>
@ -1815,7 +1818,6 @@ namespace Jellyfin.Api.Controllers
brandingOptions.SplashscreenLocation = filePath; brandingOptions.SplashscreenLocation = filePath;
_serverConfigurationManager.SaveConfiguration("branding", brandingOptions); _serverConfigurationManager.SaveConfiguration("branding", brandingOptions);
// use FileShare.None as this bypasses dotnet bug dotnet/runtime#42790 .
await using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous)) await using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous))
{ {
await memoryStream.CopyToAsync(fs, CancellationToken.None).ConfigureAwait(false); await memoryStream.CopyToAsync(fs, CancellationToken.None).ConfigureAwait(false);

View File

@ -10,13 +10,13 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Jellyfin.Drawing.Skia namespace Jellyfin.Drawing.Skia;
/// <summary>
/// The default image generator.
/// </summary>
public class DefaultImageGenerator : IImageGenerator
{ {
/// <summary>
/// The default image generator.
/// </summary>
public class DefaultImageGenerator : IImageGenerator
{
private readonly IImageEncoder _imageEncoder; private readonly IImageEncoder _imageEncoder;
private readonly IItemRepository _itemRepository; private readonly IItemRepository _itemRepository;
private readonly ILogger _logger; private readonly ILogger _logger;
@ -38,13 +38,13 @@ namespace Jellyfin.Drawing.Skia
} }
/// <inheritdoc/> /// <inheritdoc/>
public GeneratedImages[] GetSupportedImages() public IReadOnlyList<GeneratedImageType> GetSupportedImages()
{ {
return new[] { GeneratedImages.Splashscreen }; return new[] { GeneratedImageType.Splashscreen };
} }
/// <inheritdoc/> /// <inheritdoc/>
public void GenerateSplashscreen(string outputPath) public void Generate(GeneratedImageType imageTypeType, string outputPath)
{ {
var posters = GetItemsWithImageType(ImageType.Primary).Select(x => x.GetImages(ImageType.Primary).First().Path).ToList(); 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(); var landscape = GetItemsWithImageType(ImageType.Thumb).Select(x => x.GetImages(ImageType.Thumb).First().Path).ToList();
@ -52,7 +52,7 @@ namespace Jellyfin.Drawing.Skia
{ {
// Thumb images fit better because they include the title in the image but are not provided with TMDb. // 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 // 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();
} }
@ -68,16 +68,15 @@ namespace Jellyfin.Drawing.Skia
CollapseBoxSetItems = false, CollapseBoxSetItems = false,
Recursive = true, Recursive = true,
DtoOptions = new DtoOptions(false), DtoOptions = new DtoOptions(false),
ImageTypes = new ImageType[] { imageType }, ImageTypes = new[] { imageType },
Limit = 30, Limit = 30,
// todo max parental rating configurable // todo max parental rating configurable
MaxParentalRating = 10, MaxParentalRating = 10,
OrderBy = new ValueTuple<string, SortOrder>[] OrderBy = new ValueTuple<string, SortOrder>[]
{ {
new ValueTuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending) new(ItemSortBy.Random, SortOrder.Ascending)
}, },
IncludeItemTypes = new string[] { "Movie", "Series" } IncludeItemTypes = new[] { BaseItemKind.Movie, BaseItemKind.Series }
}); });
} }
}
} }

View File

@ -86,7 +86,7 @@ namespace Jellyfin.Server
serviceCollection.AddSingleton<IDeviceManager, DeviceManager>(); serviceCollection.AddSingleton<IDeviceManager, DeviceManager>();
// TODO search plugins // TODO search plugins
ServiceCollection.AddSingleton<IImageGenerator, DefaultImageGenerator>(); serviceCollection.AddSingleton<IImageGenerator, DefaultImageGenerator>();
// TODO search the assemblies instead of adding them manually? // TODO search the assemblies instead of adding them manually?
serviceCollection.AddSingleton<IWebSocketListener, SessionWebSocketListener>(); serviceCollection.AddSingleton<IWebSocketListener, SessionWebSocketListener>();

View File

@ -0,0 +1,12 @@
namespace MediaBrowser.Controller.Drawing;
/// <summary>
/// Which generated image type the <see cref="IImageGenerator"/> supports.
/// </summary>
public enum GeneratedImageType
{
/// <summary>
/// The splashscreen.
/// </summary>
Splashscreen = 0
}

View File

@ -1,13 +0,0 @@
namespace MediaBrowser.Controller.Drawing
{
/// <summary>
/// Which generated images an <see cref="IImageGenerator"/> supports.
/// </summary>
public enum GeneratedImages
{
/// <summary>
/// The splashscreen.
/// </summary>
Splashscreen
}
}

View File

@ -1,20 +1,22 @@
namespace MediaBrowser.Controller.Drawing using System.Collections.Generic;
namespace MediaBrowser.Controller.Drawing;
/// <summary>
/// Interface for an image generator.
/// </summary>
public interface IImageGenerator
{ {
/// <summary>
/// Interface for an image generator.
/// </summary>
public interface IImageGenerator
{
/// <summary> /// <summary>
/// Gets the supported generated images of the image generator. /// Gets the supported generated images of the image generator.
/// </summary> /// </summary>
/// <returns>The supported images.</returns> /// <returns>The supported generated image types.</returns>
GeneratedImages[] GetSupportedImages(); IReadOnlyList<GeneratedImageType> GetSupportedImages();
/// <summary> /// <summary>
/// Generates a splashscreen. /// Generates a splashscreen.
/// </summary> /// </summary>
/// <param name="imageTypeType">The image to generate.</param>
/// <param name="outputPath">The path where the splashscreen should be saved.</param> /// <param name="outputPath">The path where the splashscreen should be saved.</param>
void GenerateSplashscreen(string outputPath); void Generate(GeneratedImageType imageTypeType, string outputPath);
}
} }

View File

@ -1,12 +1,13 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Xml.Serialization; using System.Xml.Serialization;
#pragma warning disable CS1591 namespace MediaBrowser.Model.Branding;
namespace MediaBrowser.Model.Branding /// <summary>
/// The branding options.
/// </summary>
public class BrandingOptions
{ {
public class BrandingOptions
{
/// <summary> /// <summary>
/// Gets or sets the login disclaimer. /// Gets or sets the login disclaimer.
/// </summary> /// </summary>
@ -33,6 +34,5 @@ namespace MediaBrowser.Model.Branding
/// Gets the splashscreen url. /// Gets the splashscreen url.
/// </summary> /// </summary>
[XmlIgnore] [XmlIgnore]
public string? SplashscreenUrl => "/Branding/Splashscreen"; public string SplashscreenUrl => "/Branding/Splashscreen";
}
} }