Skip to content

feat(scanner): read sidecar subtitle languages in any position and flag SDH tracks - #2432

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
blurbery:fix/subtitle-sidecar-name-parsing
Oct 14, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
blurbery:fix/subtitle-sidecar-name-parsing

Conversation

@blurbery

@blurbery blurbery commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2261
Related issue: N/A
Validation tasks: changes #1159 C2 and C3, #1158 C2 (none run yet)

Silo takes a sidecar subtitle's language from the first word after the video's name that isn't forced, and any word shaped like a language code counts. So Movie.sdh.en.srt is stored with the language sdh, which the web app shows as Southern Kurdish, and Movie.ai.hr.srt as ai. SDH and CC sidecars are never marked hearing-impaired either, so they rank and get picked like plain dialogue tracks. That hits anyone whose subtitle downloader or release group adds these tags, and anyone moving over from Jellyfin, Emby or Plex, which all read them.

This PR reads sidecar names the way Jellyfin does for items 1 and 2 of the issue, and repairs the sidecars that earlier scans already stored.

Approach

  • The words after the video's name can come in any order. forced marks a forced track, and sdh or cc a hearing-impaired one. sdh is also the ISO 639-3 code for Southern Kurdish; as in Jellyfin and Plex, the flag wins.
  • The language is the first word whose primary language subtag is registered (new lang.RegisteredTag), so ai and other words that only look like codes are skipped: Movie.ai.hr.srt and Movie.hr.ai.srt are both Croatian. Most three-letter words are registered ISO 639-3 codes, though (sub, dub, mkv), so a language with a two-letter ISO 639-1 code wins over one that only has a three-letter code. Movie.sub.en.srt is English, while Movie.yue.srt on its own is still Cantonese.
  • hi is Hindi unless another word names a language with a two-letter code, in which case it marks the track hearing-impaired. That's Jellyfin's rule, and it keeps existing Movie.hi.srt files Hindi.
  • When two words both name a language, the first one still wins, as before. Jellyfin takes the last.
  • The parser sits in internal/naming next to the other filename parsing, so the scanner and the migration below share one rule. The scanner now stores hearing_impaired on sidecars on both the new-file and update paths. The catalog, v2 API, v3 playback, jellycompat (IsHearingImpaired), downloads and the web player already read that field, so nothing downstream needed changing.
  • Existing libraries need a repair. A scan only rewrites a file's sidecars when the video or the set of sidecar paths changes, so without one, Movie.sdh.en.srt would keep sdh until someone touched the files. A Go migration, built like the fix(scanner): canonicalize subtitle languages during ingest #1037 subtitle language backfill, re-reads language and hearing_impaired for each stored sidecar from its path. It works in batches of 5,000 rows that have sidecars and writes only rows whose values change. A row that changed after it was read is skipped and counted, so another pass picks it up. Titles and every other field are left alone. A sidecar's language and flags come only from its path, so the result is what a fresh scan would store.
  • Subtitle uploads keep their own name detection in internal/subtitles. Upload names are free-form release names read right to left with release words skipped, so the two rules differ on purpose and I haven't merged them here.

Kept out on purpose: item 3 (leftover words as the track label) and item 4 (machine-translation words, including treating mt like hi). Sidecar titles feed playback's subtitle variant matching, so changing them needs its own review. They're split into #2434 so they stay open when this closes #2261.

Clients: Apple already reads hearing_impaired. Android infers SDH only from cc or sdh in the track title, so Movie.en.hi.srt won't show as SDH there: Silo-Server/silo-android#568. The user manual shows only .en.srt in its media folder example: Silo-Server/siloserver.org#203.

Validation

  • Locally on 945965c: go test passes for the whole internal/naming, internal/scanner and internal/database packages (their Postgres tests skip without a database). On a74b508, internal/lang passed too, and so did the two subtitle backfill Postgres tests (this one and fix(scanner): canonicalize subtitle languages during ingest #1037's) against a freshly migrated local PostgreSQL 18; 945965c only changes how tl is ranked.
  • The new parseSuffix table fails on the old parser in 21 of its 33 cases. The other 12 pin behaviour that must not change, such as .hi staying Hindi and the first of two languages winning.
  • The Postgres backfill test is listed in scripts/ci/db-contracts.txt, so CI's Go DB pins job runs it against a migrated database instead of skipping it.
  • CI only: Go lint, the full Go and web test suites, the Go DB pins and integration jobs, and repository checks including verify-local-paths (which needs a newer bash than macOS ships). On a74b508, the Go DB pins job ran TestPostgresExternalSubtitleNameBackfill and it passed (run).
  • Manual: the same library before and after on local builds. The after build's startup migration repaired the stored rows without a rescan (see Evidence).
Migration timing

Local PostgreSQL 18 on an Apple M5 Pro, silo --migrate-only with the after build, 200,000 media_files rows of which 100,000 have three sidecars each.

Case Rows written Duration
Every row stale (worst case) 100,000 9.1 s (two passes, the second writes nothing)
Nothing stale 0 1.0 s (one pass)

Peak resident memory in the worst case was about 157 MB. The synthetic rows were all movie files, so this doesn't include the episode catalog refresh the trigger runs for each rewritten episode row; episode-heavy libraries will take longer.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2432/

Surface and build: web item page Subs popover at desktop and phone width, and GET /api/v2/catalog/items/{id} subtitle_tracks. Before: upstream main 6144c45. After: a74b508 on the same database, after its startup migration. The later 945965c only changes how tl is ranked, which none of these names use.

Sidecar Before After
Movie.en.srt en en
Movie.en.sdh.srt en en, hearing impaired
Movie.sdh.en.srt sdh (shown as Southern Kurdish) en, hearing impaired
Movie.en.hi.srt en en, hearing impaired
Movie.hi.srt hi (Hindi) hi (Hindi)
Movie.ai.hr.srt ai (Unknown language) hr (Croatian)

Risks

  • A remembered series subtitle choice or language preference saved against a misread sidecar (language sdh, or no hearing-impaired flag) stops matching once the sidecar is repaired. That viewer gets their defaults on the next episode until they pick again, and the defaults rank plain tracks above SDH. Only choices made on misread tracks are affected.
  • A name whose only language-like word isn't a registered code (Movie.jp.srt, Movie.pb.srt) now has no language instead of the raw word. The popover still shows the file name under "Unknown".
  • Subtitle language filters lose values like sdh and ai; those files now count under their real language.
  • Intro and credits detection includes sidecar language and flags in a season's input signature, so seasons with repaired sidecars are analysed once more. Dialogue refinement skips SDH sidecars, so an intro start can move where an SDH sidecar was the only one.
  • The migration runs once at startup (see Migration timing). The episode catalog trigger fires for each row it rewrites. A row an older node writes after the migration finishes keeps the old reading until its sidecars change, the same limit as fix(scanner): canonicalize subtitle languages during ingest #1037.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (Claude desktop app)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted. I directed the task and designed the work.
  • Adversarial review: An independent Claude Code subagent (claude-opus-5-5) reviewed the diff read-only. It found that most three-letter words are registered ISO 639-3 codes, so a label word such as sub or mkv before the language still won; that a migration pass which skipped a row changed mid-pass could finish without retrying it; and smaller comment and test gaps. All are fixed and covered by tests. It also flagged the separate upload name detection, which I kept separate for the reason above.

…ag SDH tracks

A sidecar's language was the first dot-part that was not "forced", and any
well-formed two or three letter word counted, so Movie.sdh.en.srt was stored
as language "sdh" and Movie.ai.hr.srt as "ai". SDH and CC sidecars were never
marked hearing-impaired.

naming.ParseSubtitleSuffix reads "forced", "sdh" and "cc" in any position.
The language is the first word whose primary subtag is registered, and a
language with a two-letter ISO 639-1 code wins over one that has only a
three-letter code, since many short words in file names ("sub", "dub",
"mkv") are also ISO 639-3 codes. "hi" is Hindi only when no other word names
a language (Jellyfin's rule); otherwise it marks the track hearing-impaired.
The scanner stores the flag on both the new-file and update paths.

A Go migration re-reads the language and flag of sidecars already stored,
because a rescan only rewrites sidecars when their paths or the video change.
@silo-kody

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 502ed04c-e062-419c-882b-4a2e87c6abd9
📥 Commits

Reviewing files that changed from the base of the PR and between 6144c45 and a74b508.

📒 Files selected for processing: 13
  • internal/database/external_subtitle_name_backfill.go
  • internal/database/external_subtitle_name_backfill_test.go
  • internal/database/migrate.go
  • internal/database/migrate_progress_test.go
  • internal/lang/lang.go
  • internal/lang/lang_test.go
  • internal/naming/subtitle.go
  • internal/naming/subtitle_test.go
  • internal/scanner/scanner.go
  • internal/scanner/subtitles.go
  • internal/scanner/subtitles_test.go
  • internal/scanner/types.go
  • scripts/ci/db-contracts.txt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Walkthrough

The change adds shared parsing for external subtitle filenames, carries hearing-impaired status through scanner models, and registers a database migration that repairs stored subtitle language and hearing-impaired values.

Changes: External subtitle names

Layer / File(s) Summary
Shared subtitle-name parsing
internal/lang/lang.go, internal/lang/lang_test.go, internal/naming/subtitle.go, internal/naming/subtitle_test.go
New helpers match sidecar basenames and parse language, forced, and hearing-impaired tags. RegisteredTag returns compatible tags only when their primary language is registered.
Scanner subtitle integration
internal/scanner/types.go, internal/scanner/subtitles.go, internal/scanner/scanner.go, internal/scanner/subtitles_test.go
The scanner uses shared matching and parsing. ExternalSubtitleInfo and external subtitle models now carry the hearing-impaired flag. Tests cover parsing precedence and model conversion.
Stored subtitle tag backfill
internal/database/external_subtitle_name_backfill.go, internal/database/external_subtitle_name_backfill_test.go, internal/database/migrate.go, internal/database/migrate_progress_test.go, scripts/ci/db-contracts.txt
A registered migration scans subtitle arrays in batches and updates stale language and hearing-impaired values when the stored JSON still matches the value read. Tests cover repairs, unchanged rows, idempotence, and migration registration.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~30 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Scanner
  participant SidecarSubtitleTags
  participant ParseSubtitleSuffix
  participant ExternalSubtitleInfo
  Scanner->>SidecarSubtitleTags: Match video and subtitle paths
  SidecarSubtitleTags->>ParseSubtitleSuffix: Parse matching suffix
  ParseSubtitleSuffix-->>SidecarSubtitleTags: Return language and subtitle flags
  SidecarSubtitleTags-->>Scanner: Return parsed tags
  Scanner->>ExternalSubtitleInfo: Store parsed language and flags
Loading

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to a74b5

No merge-blocking issue was identified; the subtitle parsing and stored-metadata repair appear ready for normal checks.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Direct issue #2261 remains open and specifies four coding behaviors. The PR implements language parsing in any token position, registered-language selection, forced, sdh, cc, and context-depende… Implement the remaining #2261 track-label and machine-translation behavior, propagate the resulting metadata through sidecar storage and clients, and add automated tests. Alternatively, split or update the linked issue so that the deferred …
Docstring Coverage Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 12 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Out of Scope Changes check Passed The changed code stays connected to #2261. The shared naming parser, scanner updates, migration, migration registration, and tests support sidecar language and hearing-impaired metadata. The migration…
Title check Passed The title clearly summarizes the primary changes: flexible sidecar subtitle language parsing and SDH track detection. It is concise and directly related to the changeset.
Description check Passed The description is directly related to the changeset. It explains the parsing rules, scanner updates, migration, tests, validation, risks, and deferred scope.
Full details: Linked Issues check

Explanation

Direct issue #2261 remains open and specifies four coding behaviors. The PR implements language parsing in any token position, registered-language selection, forced, sdh, cc, and context-dependent hi, scanner propagation, and stored-sidecar repair. The PR does not implement #2261 item 3: remaining filename words as a track label. ExternalSubtitleInfo.Title remains the complete filename. The PR also does not implement item 4: ai, mt, and machine recognition with the AI label and selection behavior. ParseSubtitleSuffix has no machine-translation handling.

Resolution

Implement the remaining #2261 track-label and machine-translation behavior, propagate the resulting metadata through sidecar storage and clients, and add automated tests. Alternatively, split or update the linked issue so that the deferred items are not requirements of this PR.

Full details: Docstring Coverage

Explanation

Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 12 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread internal/naming/subtitle.go Resolved
x/text canonicalizes the deprecated ISO 639-1 code "tl" to "fil", so the
sidecar parser ranked it with the three-letter-only codes: Movie.tl.en.srt
was read as English and Movie.tl.hi.srt as Hindi without the
hearing-impaired flag. Rank a word by its written spelling as well as its
canonical tag.
@silo-kody

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit b0b65de into Silo-Server:main Oct 14, 2026
28 checks passed
@blurbery
blurbery deleted the fix/subtitle-sidecar-name-parsing branch November 6, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Parse external subtitle names like Jellyfin: language in any position, SDH/CC, labels, machine translation

2 participants