Livestreams and ended broadcasts accumulated in every user's resume row
because Jellyfin saves a playback position for channel items regardless
of whether the position means anything. A livestream has nothing to
return to, so the entry stayed pinned forever.
Two parts:
- PlaybackResumeGuard, an IHostedService on ISessionManager.PlaybackStopped.
Jellyfin saves the resume point before raising the event, so the guard
zeroes it afterwards for livestreams. Stops new entries at the source.
- ResumeCleanupService plus a daily 4 AM task (after the 3 AM expiration
check) for the existing backlog. Clears livestreams, resume points older
than N days, positions under N seconds and playback past N% of runtime,
each threshold configurable.
Only plugin-owned items are touched, matched by the SRF provider ID with a
fallback to the owning channel ID so recordings are covered too. Clearing
sets PlaybackPositionTicks to 0 and leaves Played false: nothing is deleted
and the item stays unwatched.
Config page gains the thresholds plus "Clean Up Stale Entries Now" and
"Clear All SRF Play Entries" buttons, backed by MaintenanceController
under RequiresElevation.
Also folds the duplicated urn.Contains("livestream") check in
MediaSourceFactory and RecordingService into UrnHelper.IsLivestreamUrn.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using System.Threading;
|
|
using Jellyfin.Plugin.SRFPlay.Api.Models;
|
|
using Jellyfin.Plugin.SRFPlay.Services.Interfaces;
|
|
using MediaBrowser.Common.Api;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Jellyfin.Plugin.SRFPlay.Controllers;
|
|
|
|
/// <summary>
|
|
/// Administrative maintenance actions for the SRF Play plugin.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("Plugins/SRFPlay/Maintenance")]
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
|
public class MaintenanceController : ControllerBase
|
|
{
|
|
private readonly ILogger<MaintenanceController> _logger;
|
|
private readonly IResumeCleanupService _resumeCleanupService;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="MaintenanceController"/> class.
|
|
/// </summary>
|
|
/// <param name="logger">The logger.</param>
|
|
/// <param name="resumeCleanupService">The resume cleanup service.</param>
|
|
public MaintenanceController(
|
|
ILogger<MaintenanceController> logger,
|
|
IResumeCleanupService resumeCleanupService)
|
|
{
|
|
_logger = logger;
|
|
_resumeCleanupService = resumeCleanupService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clears stale SRF Play resume points from every user's "Continue Watching" row.
|
|
/// </summary>
|
|
/// <param name="clearAll">
|
|
/// When true, clears every SRF Play resume point instead of only the stale ones.
|
|
/// </param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <returns>A summary of what was inspected and cleared.</returns>
|
|
[HttpPost("ResumePoints/Cleanup")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
public ActionResult<ResumeCleanupResult> CleanupResumePoints(
|
|
[FromQuery] bool clearAll,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
_logger.LogInformation("Manual Continue Watching cleanup requested (clearAll: {ClearAll})", clearAll);
|
|
return Ok(_resumeCleanupService.Cleanup(clearAll, cancellationToken));
|
|
}
|
|
}
|