Files
jellyfin-plugin-recently-ad…/Jellyfin.Plugin.RecentlyAddedGuard/PluginServiceRegistrator.cs
T
Jonas MenzelandClaude Opus 5.5 d431486095
build / build (push) Successful in 1m10s
release / release (push) Failing after 1m36s
feat: Recently Added Guard plugin for Jellyfin 12.2
Keeps Radarr/Sonarr quality upgrades out of "Recently Added" by keeping
a ledger of the first date added per logical medium (movie or episode,
identified by provider ids and the series) and restoring it on upgrades.

- core logic without Jellyfin types (Reconciler, MediaKeys, GuardProcessor)
- thread-safe ledger with atomic, debounced persistence
- event processing via channel and background worker, seed on first start
- scheduled task "Ledger synchronisieren", status API, configuration page
- xUnit tests and a Jellyfin 12.2 integration test
- Gitea workflows: build/test, release with jprm and manifest branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 23:10:02 +02:00

51 lines
2.2 KiB
C#

using System;
using System.IO;
using Jellyfin.Plugin.RecentlyAddedGuard.Core;
using Jellyfin.Plugin.RecentlyAddedGuard.Ledger;
using Jellyfin.Plugin.RecentlyAddedGuard.Services;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Plugins;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.RecentlyAddedGuard;
/// <summary>
/// Registers the plugin services with Jellyfin's DI container.
/// </summary>
public class PluginServiceRegistrator : IPluginServiceRegistrator
{
/// <inheritdoc />
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
{
// Runs before the plugin instance exists; factories are evaluated later, when the host starts.
serviceCollection.AddSingleton<CorrectionLog>();
serviceCollection.AddSingleton(sp => new LedgerStore(
Path.Combine(GetDataFolderPath(sp), LedgerStore.DefaultFileName),
sp.GetRequiredService<ILogger<LedgerStore>>()));
serviceCollection.AddSingleton(sp => new Reconciler(
sp.GetRequiredService<LedgerStore>(),
GetOptions,
TimeProvider.System,
sp.GetRequiredService<ILogger<Reconciler>>()));
serviceCollection.AddSingleton<IdentityResolver>();
serviceCollection.AddSingleton<LibraryItemDateWriter>();
serviceCollection.AddSingleton(sp => new GuardProcessor(
sp.GetRequiredService<Reconciler>(),
sp.GetRequiredService<LibraryItemDateWriter>(),
sp.GetRequiredService<CorrectionLog>(),
GetOptions,
TimeProvider.System,
sp.GetRequiredService<ILogger<GuardProcessor>>()));
serviceCollection.AddSingleton<LedgerSynchronizer>();
serviceCollection.AddHostedService<GuardHostedService>();
}
private static GuardOptions GetOptions() => Plugin.CurrentConfiguration.ToGuardOptions();
private static string GetDataFolderPath(IServiceProvider serviceProvider)
=> Plugin.Instance?.DataFolderPath
?? Path.Combine(serviceProvider.GetRequiredService<IApplicationPaths>().PluginsPath, typeof(Plugin).Assembly.GetName().Name!);
}