Skip to content

feat(subtitles): auto-download a Plex subtitle when the item has none - #3027

Open
infixlabs wants to merge 2 commits into
edde746:mainfrom
infixlabs:feat/auto-download-subtitles
Open

infixlabs wants to merge 2 commits into
edde746:mainfrom
infixlabs:feat/auto-download-subtitles

Conversation

@infixlabs

Copy link
Copy Markdown

The second half of #2346. Stacked on #3026 — review that one first; this branch contains its commit because GitHub cannot base a cross-fork PR on another fork branch. I will rebase to a single commit once #3026 lands or closes.

What it does

Opt-in, Plex only. When an item carries no subtitle in the preferred language, search the server's online providers once and apply what comes back.

Deliberately silent

It runs without anyone pressing anything, often on a TV across the room, so a failure leaves playback exactly as it was and says so only in the log. The manual search sheet stays the place to find out what a provider does or does not have.

A spinner shows while the search, the server-side download and the metadata poll run — together that is seconds, and a viewer who asked for subtitles is otherwise watching an unsubtitled picture with no idea anything is coming. Success gets no toast: the subtitles are the confirmation and they arrive at the same moment.

Ranking, and why not score

Provider score alone picked wrong. Target (1985) returned a confidently-scored subtitle for an entirely different film with the same title. Score now only breaks ties between results that already agree on stronger evidence:

  1. perfectMatch — comes from matching the file, not its name, so a shared title cannot fool it.
  2. The language actually asked for, when the result declares one.
  3. Full dialogue over forced or hearing-impaired. Both stay eligible, just behind.

Covered by test/services/subtitle_auto_download_test.dart, including the Target case.

The defect you found in #2346

Auto-download could override an explicit off. It could. The viewer turns subtitles off while the server is still fetching; applying then switches them back on, and because the apply path writes the stream selection, it persists that to the server as their choice. The live player track is now checked immediately before applying — read off the player, not from a carried preference, so any route that turned them off counts — and their newer decision wins.

One attempt per item, claimed before any network call so a search that throws does not re-run on the next rebuild.

Verified

flutter analyze lib test     No issues found!
scripts/codegen.sh --check   exit 0
scripts/run_tests.sh         8446 passed, 7 skipped, exit 0
dart format                  clean (generated files untouched)

10 files on top of #3026, +410/-15. English strings only.

Not verified by me: Plex only, and only against my own PMS providers. Jellyfin and Emby are gated out at the entry point (capabilities.externalSubtitleSearch).

🤖 Generated with Claude Code

https://claude.ai/code/session_01PQ9KU5JXvzTB7tkYyeDEut

infixlabs and others added 2 commits November 9, 2026 18:07
Adds a "Always Show Subtitles" setting that turns subtitles on when neither
the server nor a carried preference selects one, and a preferred subtitle
language that the fallback and the search sheet share.

Why not Plex's own per-user autoSelectSubtitle: it is a server-side account
setting, so it cannot differ between two devices on the same account. A
viewer who wants subtitles on the living-room TV and off on their phone has
no way to express that today.

The fallback runs where the ladder would otherwise return off - Plex's "rows
exist, none selected" case and the final priority - and prefers full
dialogue over a forced-only row, since signs-and-songs is not what "always
show subtitles" means.

It is a fallback, never a choice: the pick is reported through
`isForcedFallback` so it is not carried across an item boundary, where a
carried selection would match at navigation priority and be written back to
the server as the viewer's explicit choice. Each item derives its own.

`resolveSubtitleSearchLanguageCode` moves out of the search sheet into
`subtitle_language.dart` so both callers read the same preference, and
`subtitleLanguageMatches` moves to `language_codes.dart` - selection and the
fallback must agree, and neither may prefix-compare (`est` is not `es`).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PQ9KU5JXvzTB7tkYyeDEut
The second half of edde746#2346, stacked on the always-on setting. Opt-in, Plex
only: when an item carries no subtitle in the preferred language, search the
server's online providers once and apply what comes back.

Deliberately silent. This runs without anyone pressing anything, often on a
TV across the room, so a failure leaves playback exactly as it was and says
so only in the log. The manual search sheet remains the way to get feedback
about what a provider does or does not have. A spinner shows while the
search, the server-side download and the poll run, because a viewer who
asked for subtitles is otherwise watching an unsubtitled picture with no
idea anything is coming. Success needs no toast - the subtitles are the
confirmation, and they arrive at the same moment.

Ranking does not trust provider score alone: a confidently-scored result for
an entirely different film sharing the title ("Target", 1985) beat the right
one. Score now only breaks ties between results that already agree on
`perfectMatch` (which comes from the file, not its name), then the language
actually asked for, then full dialogue over forced or hearing-impaired.

The viewer may turn subtitles off while the server is still fetching.
Applying then would switch them back on and, because the apply path writes
the stream selection, persist that to the server as their choice - so the
live player track is checked before applying and their newer decision wins.

One attempt per item, claimed before any network call so a search that
throws does not re-run on the next rebuild.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PQ9KU5JXvzTB7tkYyeDEut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant