Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openspec/changes/add-jellyfin-12-support/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [x] 2.2 Floor decision on the dependabot SDK-12 PR: default is close-without-merge and stay on the 10.11.9 floor (merging = net10.0 = dropping every 10.11 user; see design). Settled 2026-10-13: no such PR can arrive (see 1.5), and the floor stays at 10.11.9; adopting the 12 SDK is Phase C, started deliberately, never from a Dependabot PR
- [x] 2.3 README declares 12.x support explicitly, backed by the 1.6 result, and documents the plugin-directory move. Site release notes carry the same. Original wording: declare 12.0 support explicitly ("runs on 10.11.x and 12.x from one release"), with migration guidance covering Jellyfin's remove-plugins-before-migrating advice (RC3 notes escalated this to "disable all external plugins") and that config + sync history survive a remove/reinstall
- [x] 2.4 Covered by 1.6 above: the smoke test was run directly against 12.0.0 stable
- [x] 2.5 Re-verified 2026-12-02 with the released v2.15.2 artifact on **12.4.0** stable (throwaway local container, removed after). `Loaded plugin: Jellyscribe 2.15.2.0`, status Active; every dashboard endpoint, both config pages, the three static assets and the injected `sidebar.js` tag answered 200, and an unauthenticated call answered 401; all seven Letterboxd and Serializd scheduled tasks ran to `Completed` with no accounts linked; no error or warning line named the plugin. Read from the server's own assemblies: `IPlaylistManager.AddItemToPlaylistAsync` on 12.4 is still `(Guid, IReadOnlyCollection<Guid>, int?, Guid)`, the shape `PlaylistManagerCompat` binds, and all 56 server types and 107 server members the plugin references exist there (matched by name and parameter count, not full signature). Still not covered: a sync with real Letterboxd or Serializd credentials on 12, a playlist actually written on 12, and a catalog install on 12

## 3. Phase C: SDK adoption / stream split (only when a 12-only API is needed or ABI breaks)

Expand Down
2 changes: 2 additions & 0 deletions openspec/changes/add-serializd-show-status/.openspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-12-02
130 changes: 130 additions & 0 deletions openspec/changes/add-serializd-show-status/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
## Context

Two entry points log TV to Serializd: `PlaybackHandler.HandleEpisodeAsync` (real time, on a finished play) and `SerializdSyncRunner.SyncOneAsync` (scheduled catch-up and "Sync TV now"). Both call `ISerializdService.LogEpisodesAsync` and `CreateEpisodeLogAsync`, record what they sent in `SerializdSyncHistory` (kinds `watched`, `log`, `showmeta`), and the runner then mirrors the series rating and favourite with `SetShowMetaAsync`. Nothing sets a show's status.

`SerializdApiClient` already reads `GET /show/{tmdbId}` to resolve season ids and episode counts, and keeps the answer in a season cache. `SerializdSeasonFallback` handles shows Serializd lists as a single season while Jellyfin has several.

Constraints:

- A Serializd failure must never affect the Letterboxd path, and a status failure must never affect the episode log.
- A cancelled token cancels waits and reads, never a write already sent.
- Every export path applies `LibraryExclusion.IsExcluded` before calling the service.
- Serializd has no documented public API. The plugin uses the endpoints the Serializd web client uses, so every new request shape has to be captured from the web client and confirmed against a live account before it is relied on.

## Goals / Non-Goals

**Goals:**

- A show appears on "Currently watching" once Jellyscribe has logged an episode of it.
- A show moves to "Watched" only when that is certain: the show has ended and the user has played every episode Serializd lists.
- Each status is sent once per user, account and show, and survives restarts.
- Shows finished before this release are picked up by the scheduled run.

**Non-Goals:**

- See the proposal's Non-goals. In addition: no change to how episodes, ratings, likes or reviews are sent.

## Decisions

### 1. A pure rule and a separate updater, called after the episode log from both entry points

Two types, so the name of each says what it does:

- `SerializdShowStatus`: static and pure. `IsFinished(...)` and the early-out `CannotBeFinished(...)` (decision 6). No I/O.
- `SerializdShowStatusUpdater`: `UpdateAsync(service, user, account, series, showTmdbId, cancellationToken)`. Reads state, calls Serializd, writes state, logs.

The updater is called after the episode log succeeded and its history rows are written. A failure inside it is logged (account named with `LogRedaction.AccountTag`) and swallowed, with one exception: an `OperationCanceledException` raised because the caller's token was cancelled is rethrown, so a server shutdown stops the work instead of running on through the remaining shows.

The updater holds a keyed lock per user, account and show (the `FilmSyncLock` pattern) around read, decide, call and write. Two playback-stopped events arriving together for one show therefore make one decision, not two.

Alternative considered: fold the status calls into `LogEpisodesAsync`. Rejected, because a status failure would then surface as a failed episode log and be retried as one.

### 2. "Currently watching" is set on the first logged episode, not on playback start

The plugin subscribes to `PlaybackStopped` and acts only on `PlayedToCompletion`. Using the same moment keeps one trigger, covers the scheduled path (which has no playback event at all), and avoids listing a show the user sampled and dropped.

Alternative considered: subscribe to `PlaybackStart`. Rejected for the reasons above and because it adds a second event path with its own duplicate handling.

### 3. "Watched" needs three things to be true

1. Jellyfin reports the series as ended (`Series.Status` is `Ended`).
2. Serializd lists at least one regular season (season number 1 or higher) for the show, and gives an episode count for every regular season.
3. For every regular season Serializd lists, the number of distinct episodes of that season the user has played in Jellyfin is at least Serializd's count.

"Played" is Jellyfin's own played flag for that user, so episodes watched before the plugin was installed count. A multi-episode file counts every episode number it covers. Specials (season 0) are ignored on both sides.

For a show Serializd lists as a single season while Jellyfin has several, condition 3 compares the total of played regular episodes with that one season's count, the same mapping `SerializdSeasonFallback` uses for logging.

A missing count, an unreadable show, or a missing series status means "not finished". The check fails closed.

Alternative considered: "every episode in the Jellyfin library is played". Rejected, because a library that holds only the first two seasons would mark a five-season show as watched.

Alternative considered: trust Jellyfin's status alone and mark any fully played show. Rejected, because a show still airing would be marked watched every time the user catches up.

### 4. Order of writes when a show is finished

Mark Watched, then remove from Currently watching. Marking first means a failure between the two leaves the show on both lists, which is harmless and is repaired on a later run; the other order could leave it on neither.

The removal is always sent for a finished show, including one the plugin never added to Currently watching. The user may have listed it by hand, and the plugin never reads status, so sending the removal is the only way to leave a finished show on one list. Task 1.2 confirms that removing a show that is not listed is harmless.

### 5. State is one value per user, account and show, in its own small store

`SerializdSyncHistory` is an append-only set of keys with no values and no timestamps, so it cannot hold a state that changes or a "last checked" time. A new `SerializdShowStatusStore` holds, per user, account and show:

- `State`: `Watching`, `WatchedPendingRemoval` or `Watched`. Absent means nothing was sent.
- `LastCheckedUtc`: when the scheduled pass last read this show from Serializd and found it not finished (decision 6).

It is a JSON dictionary persisted the way `SerializdCollectionStore` persists its own (temp file, then move), keyed by Jellyfin user id, the SHA-256 of the lower-cased email, and the show's TMDb id, so the file holds no address. One value per show makes contradictory combinations unrepresentable, and the decision is a switch:

| State | Finished? | Action | New state |
|---|---|---|---|
| none | no | add to Currently watching | `Watching` |
| none or `Watching` | yes | mark Watched | `WatchedPendingRemoval`, then continue as that row |
| `Watching` | no | nothing | `Watching` |
| `WatchedPendingRemoval` | not rechecked | remove from Currently watching | `Watched` |
| `Watched` | not rechecked | nothing, no network | `Watched` |

A state is written only after Serializd accepted the request it records. A failed request leaves the state where it was, which is what makes the next run retry exactly the step that failed.

Alternative considered: three new row kinds in `SerializdSyncHistory`. Rejected: three independent flags for one lifecycle allow combinations the table does not cover, and the rotation in decision 6 needs a timestamp the history file cannot hold.

### 6. The scheduled run also works through shows with earlier history

After its normal pass, `SerializdSyncRunner` builds a work list for the account from every show with a `watched` history row whose state is not `Watched`:

1. **Pending removals** (`WatchedPendingRemoval`): the removal is retried. No read, no recheck. This is what retries a failed removal for a show the user never plays again.
2. **Candidates** (no state, or `Watching`): checked for being finished.

For candidates, `SerializdShowStatus.CannotBeFinished` is an early-out on Jellyfin data alone: the series is not ended, or an episode of it in the library is unplayed. It can only skip work. It never declares a show finished; only `IsFinished`, the one rule in decision 3, does that, and both entry points and this pass call the same function. A test pins that every show `CannotBeFinished` skips is one `IsFinished` would reject.

Candidates that survive the early-out are read from Serializd, oldest `LastCheckedUtc` first and never-checked before any checked. A show that is read and found not finished gets `LastCheckedUtc` set to now and is not read again for 7 days. Without that, shows that can never finish (the library holds fewer episodes than Serializd lists) would be read on every run and would use up the cap ahead of shows that can.

The pass makes at most 25 Serializd show reads per account per run, stops when the token is cancelled, and stops starting new shows once it has run for 5 minutes, so a rate-limited Serializd cannot hold the scheduled task open. The first run after an upgrade therefore spreads a large library over several days.

Candidates that are not finished are left alone by this pass: it never adds a show to Currently watching, because history that may be years old says nothing about what the user is watching now. For a show it finds finished, it does both writes of decision 4.

### 7. No new setting

The account's existing enabled switch governs status as it governs episode logs. The recent direction is fewer per-account settings, and a status that follows from watch history the account already sends does not need its own consent.

Alternative considered: a per-account "Update show status" switch, on by default. Kept as an open question below.

## Risks / Trade-offs

- [The request shapes for the three writes are not yet confirmed] → Task group 1 captures them from the Serializd web client with the test account and records them here before any production code depends on them. If Serializd has no call for one of them, that part is dropped and the proposal is updated.
- [Marking a show Watched might have side effects: overwriting episode logs or ratings, or posting to followers' feeds] → Task 1.3 checks the account's diary, ratings and activity before and after on the test account. A side effect that changes user data stops the change for a decision.
- [Jellyfin's series status is wrong or stale for some shows] → A wrong "Continuing" only delays Watched. A wrong "Ended" still needs every Serializd episode played, so the worst case is a show marked Watched one season early when Serializd's listing is also behind.
- [A user set a status by hand on serializd.com] → The plugin never reads status, so it cannot tell. Adding to Currently watching a show the user already listed is expected to be a no-op (confirmed in task 1.2). The plugin never removes a show from Watched.
- [First run after upgrade marks many shows Watched at once] → Capped at 25 reads per account per run and 5 minutes (decision 6). Release notes say it will happen.
- [A show that passes the early-out but can never pass the full check uses up the cap] → Such a show is read once and then left for 7 days, and the list is ordered oldest-checked first (decision 6).
- [Two finishes of one show arrive together] → Keyed lock per user, account and show (decision 1).
- [The series rating and favourite write (`SetShowMetaAsync`) and a status write affect each other] → Task 1.3 checks both orders on the test account.

## Migration Plan

No data migration. The new store is a new file; an older build ignores it. Rolling back the release leaves the file on disk and the statuses on Serializd, both harmless.

## Open Questions

- Should accounts get an opt-out switch (decision 7)? Default answer: no.
- Should a status change appear in the dashboard's Activity list? Default answer: no, logged only.
43 changes: 43 additions & 0 deletions openspec/changes/add-serializd-show-status/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Proposal: add-serializd-show-status

## Why

Jellyscribe marks episodes watched on Serializd and writes diary logs, but it never touches a show's status. A Serializd profile has two show lists that people use to see where they are: "Currently watching" and "Watched". Today both stay empty for shows watched through Jellyfin unless the user sets them by hand on serializd.com, so the profile says less than the watch history the plugin already sent. No GitHub issue exists.

## What Changes

- When Jellyscribe logs an episode of a show for a Serializd account and that show has no status from the plugin yet, it adds the show to the account's "Currently watching" list.
- When a show has ended and the user has played every episode Serializd lists for it, Jellyscribe marks the show "Watched" on Serializd and takes it off "Currently watching".
- The scheduled Serializd sync also checks shows the account already has history for, so shows finished before this release move to "Watched" without another play.
- A status update that fails is retried on a later run. It never fails, delays, or undoes the episode log it followed.
- Status updates follow the same account rules as episode logs: only enabled accounts, and never for a show in a library the account excludes.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `serializd-sync`: gains requirements for the "Currently watching" and "Watched" show status.

## Impact

- `LetterboxdSync/Serializd/ISerializdService.cs` and `SerializdApiClient.cs`: three new operations (add to Currently watching, remove from it, mark a show Watched) and one read (the seasons Serializd lists for a show, with their episode counts).
- New `LetterboxdSync/Serializd/SerializdShowStatus.cs` (the pure rule), `SerializdShowStatusUpdater.cs` (the calls and state changes both entry points use) and `SerializdShowStatusStore.cs` (one state per user, account and show).
- `LetterboxdSync/PlaybackHandler.cs` (`HandleEpisodeAsync`) and `LetterboxdSync/Serializd/SerializdSyncRunner.cs`: call the updater after a successful episode log; the runner also runs the check for shows with earlier history.
- `LetterboxdSync/Serializd/SerializdSyncHistory.cs`: one new read, the shows an account has episode history for.
- More Serializd traffic: at most one show read per status decision, shared with the read the episode log already makes in the same run.
- Tests in `SerializdSyncRunnerTests`, `SerializdSyncRunnerCatchUpTests`, `SerializdPlaybackTests`, `SerializdApiClientTests`, and new `SerializdShowStatusTests`, `SerializdShowStatusUpdaterTests` and `SerializdShowStatusStoreTests`. A live check against the Serializd test account before the write shapes are relied on.
- Ships a minor release: version bump, `## Release notes`, `release-notes.ts` entry, README feature list.

## Non-goals

- Reading show status back from Serializd into Jellyfin.
- Setting "Currently watching" when playback starts. The plugin acts on finished plays only, so a show sampled for two minutes is not listed.
- Putting a show back on "Currently watching" after it was marked "Watched" (a rewatch leaves the status alone).
- Any other Serializd list or status (paused, dropped, custom lists).
- A new account setting. Status follows the account's existing sync switch.
- Activity rows for status changes. They are logged, not listed on the dashboard.
- Films and Letterboxd.
Loading
Loading