Repository navigation
feat(scanner): read sidecar subtitle languages in any position and flag SDH tracks - #2432
Conversation
…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 — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
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 — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
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. SoMovie.sdh.en.srtis stored with the languagesdh, which the web app shows as Southern Kurdish, andMovie.ai.hr.srtasai. 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
forcedmarks a forced track, andsdhorcca hearing-impaired one.sdhis also the ISO 639-3 code for Southern Kurdish; as in Jellyfin and Plex, the flag wins.lang.RegisteredTag), soaiand other words that only look like codes are skipped:Movie.ai.hr.srtandMovie.hr.ai.srtare 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.srtis English, whileMovie.yue.srton its own is still Cantonese.hiis 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 existingMovie.hi.srtfiles Hindi.internal/namingnext to the other filename parsing, so the scanner and the migration below share one rule. The scanner now storeshearing_impairedon 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.Movie.sdh.en.srtwould keepsdhuntil someone touched the files. A Go migration, built like the fix(scanner): canonicalize subtitle languages during ingest #1037 subtitle language backfill, re-readslanguageandhearing_impairedfor 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.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
mtlikehi). 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 fromccorsdhin the track title, soMovie.en.hi.srtwon't show as SDH there: Silo-Server/silo-android#568. The user manual shows only.en.srtin its media folder example: Silo-Server/siloserver.org#203.Validation
go testpasses for the wholeinternal/naming,internal/scannerandinternal/databasepackages (their Postgres tests skip without a database). On a74b508,internal/langpassed 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 howtlis ranked.parseSuffixtable fails on the old parser in 21 of its 33 cases. The other 12 pin behaviour that must not change, such as.histaying Hindi and the first of two languages winning.scripts/ci/db-contracts.txt, so CI's Go DB pins job runs it against a migrated database instead of skipping it.verify-local-paths(which needs a newer bash than macOS ships). On a74b508, the Go DB pins job ranTestPostgresExternalSubtitleNameBackfilland it passed (run).Migration timing
Local PostgreSQL 18 on an Apple M5 Pro,
silo --migrate-onlywith the after build, 200,000media_filesrows of which 100,000 have three sidecars each.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 howtlis ranked, which none of these names use.Movie.en.srtMovie.en.sdh.srtMovie.sdh.en.srtMovie.en.hi.srtMovie.hi.srtMovie.ai.hr.srtRisks
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.Movie.jp.srt,Movie.pb.srt) now has no language instead of the raw word. The popover still shows the file name under "Unknown".sdhandai; those files now count under their real language.Checklist
AI Disclosure
subormkvbefore 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.