mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-26 20:16:33 +00:00
Suggestions from review
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Emby.Server.Implementations.Library;
|
||||
|
||||
/// <summary>
|
||||
/// The splashscreen post scan task.
|
||||
/// </summary>
|
||||
public class SplashscreenPostScanTask : ILibraryPostScanTask
|
||||
{
|
||||
private readonly IItemRepository _itemRepository;
|
||||
private readonly IImageEncoder _imageEncoder;
|
||||
private readonly ILogger<SplashscreenPostScanTask> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SplashscreenPostScanTask"/> class.
|
||||
/// </summary>
|
||||
/// <param name="itemRepository">Instance of the <see cref="IItemRepository"/> interface.</param>
|
||||
/// <param name="imageEncoder">Instance of the <see cref="IImageEncoder"/> interface.</param>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger{SplashscreenPostScanTask"/> interface.</param>
|
||||
public SplashscreenPostScanTask(
|
||||
IItemRepository itemRepository,
|
||||
IImageEncoder imageEncoder,
|
||||
ILogger<SplashscreenPostScanTask> logger)
|
||||
{
|
||||
_itemRepository = itemRepository;
|
||||
_imageEncoder = imageEncoder;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var posters = GetItemsWithImageType(ImageType.Primary).Select(x => x.GetImages(ImageType.Primary).First().Path).ToList();
|
||||
var backdrops = GetItemsWithImageType(ImageType.Thumb).Select(x => x.GetImages(ImageType.Thumb).First().Path).ToList();
|
||||
if (backdrops.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");
|
||||
backdrops = GetItemsWithImageType(ImageType.Backdrop).Select(x => x.GetImages(ImageType.Backdrop).First().Path).ToList();
|
||||
}
|
||||
|
||||
_imageEncoder.CreateSplashscreen(posters, backdrops);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
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 },
|
||||
Limit = 30,
|
||||
// TODO max parental rating configurable
|
||||
MaxParentalRating = 10,
|
||||
OrderBy = new ValueTuple<string, SortOrder>[]
|
||||
{
|
||||
new(ItemSortBy.Random, SortOrder.Ascending)
|
||||
},
|
||||
IncludeItemTypes = new[] { BaseItemKind.Movie, BaseItemKind.Series }
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Implementations.Library;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.Tasks;
|
||||
@@ -24,26 +21,16 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
||||
/// </summary>
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly ILocalizationManager _localization;
|
||||
private readonly IImageGenerator _imageGenerator;
|
||||
private readonly IApplicationPaths _applicationPaths;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RefreshMediaLibraryTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||
/// <param name="imageGenerator">Instance of the <see cref="IImageGenerator"/> interface.</param>
|
||||
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
|
||||
public RefreshMediaLibraryTask(
|
||||
ILibraryManager libraryManager,
|
||||
ILocalizationManager localization,
|
||||
IImageGenerator imageGenerator,
|
||||
IApplicationPaths applicationPaths)
|
||||
public RefreshMediaLibraryTask(ILibraryManager libraryManager, ILocalizationManager localization)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_localization = localization;
|
||||
_imageGenerator = imageGenerator;
|
||||
_applicationPaths = applicationPaths;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -83,8 +70,6 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
|
||||
|
||||
progress.Report(0);
|
||||
|
||||
_imageGenerator.Generate(GeneratedImageType.Splashscreen, Path.Combine(_applicationPaths.DataPath, "splashscreen.webp"));
|
||||
|
||||
return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user