Clean up stale Continue Watching entries
🏗️ Build Plugin / build (push) Successful in 1m43s
🧪 Test Plugin / test (push) Successful in 34s
🚀 Release Plugin / build-and-release (push) Successful in 51s
Nightly Build / nightly-build (push) Failing after 50s

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>
This commit is contained in:
2026-08-12 18:55:41 +02:00
co-authored by Claude Opus 5
parent a9db0aa09c
commit 390146e8d4
13 changed files with 766 additions and 2 deletions
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Threading;
using Jellyfin.Data.Entities;
using Jellyfin.Plugin.SRFPlay.Api.Models;
using MediaBrowser.Controller.Entities;
namespace Jellyfin.Plugin.SRFPlay.Services.Interfaces;
/// <summary>
/// Removes stale plugin-owned resume points so ended livestreams and abandoned playback
/// stop accumulating in every user's "Continue Watching" row.
/// </summary>
public interface IResumeCleanupService
{
/// <summary>
/// Scans every user's resumable items and clears the resume point of those owned by this
/// plugin that match a staleness rule. Items belonging to other plugins or to the regular
/// library are never touched.
/// </summary>
/// <param name="clearAll">
/// When true every plugin-owned resume point is cleared regardless of the staleness rules.
/// Used by the "Clear all" maintenance action.
/// </param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A summary of what was inspected and cleared.</returns>
ResumeCleanupResult Cleanup(bool clearAll, CancellationToken cancellationToken);
/// <summary>
/// Clears the resume point of a single item for the given users.
/// </summary>
/// <param name="item">The item whose resume point should be reset.</param>
/// <param name="users">The users to clear it for.</param>
/// <param name="reason">A short reason, logged for traceability.</param>
/// <returns>The number of resume points actually cleared.</returns>
int ClearResumePoint(BaseItem item, IEnumerable<User> users, string reason);
/// <summary>
/// Determines whether an item belongs to this plugin (an SRG channel item or a recording).
/// </summary>
/// <param name="item">The item to test.</param>
/// <returns>True if the item is owned by this plugin.</returns>
bool IsPluginItem(BaseItem item);
/// <summary>
/// Clears the resume point if the item is one of this plugin's livestreams and livestream
/// cleanup is enabled. Called right after playback stops so an ended broadcast never reaches
/// "Continue Watching" in the first place, instead of waiting for the nightly task.
/// </summary>
/// <param name="item">The item that just stopped playing.</param>
/// <param name="users">The users the playback was attributed to.</param>
/// <returns>The number of resume points cleared.</returns>
int ClearLiveStreamResumePoint(BaseItem item, IEnumerable<User> users);
}