Skip to content

iOS/tvOS in-player subtitle search (provider parity with Android/web) - #45

Merged
Quick104 merged 2 commits into
mainfrom
feature/subtitle-search
Jul 2, 2026
Merged

Quick104 merged 2 commits into
mainfrom
feature/subtitle-search

Conversation

@Quick104

@Quick104 Quick104 commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Search external subtitle providers (OpenSubtitles / SubDL / Subsource) from inside the player and download a result mid-playback — parity with the Android and web clients.

  • POST /subtitles/search + /subtitles/download wire types and ContinuumAI methods (synchronous two-call API, no job machinery; per-provider soft failures surface as warnings).
  • SubtitleSearchMenu: one-tap language pick (preferred language floats to top, no free-text field), score/provider/HI-badged results; iOS sheet + tvOS focus panel following the SubtitleTranslateMenu idioms.
  • Downloaded tracks reuse the AI-subtitle sidecar handoff (re-list → position → synthesized combined-index stream URL → register + auto-select) with no session restart; the subtitle_ready websocket echo is a no-op via the existing combined-index de-dupe.
  • Entry points in TrackSelectionSheet (iOS) and the TVPlayerInfoHUD Subtitles pane (tvOS), gated on an active server session (hidden for offline/local playback); tvOS Back is inert while a download is in flight.

Testing

  • iOS + tvOS builds green; focused tests for the wire contract (snake_case decode, download body echo, score tiers) pass.
  • Remaining: live-server validation and a tvOS d-pad pass on device.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added in-player subtitle provider search and download on iOS and tvOS.
    • Added “Search Subtitles…” alongside existing subtitle tools in the track selection UI and tvOS subtitles HUD.
    • Search UI shows relevance tiers, provider info, warnings, and prioritizes the preferred language.
  • Bug Fixes
    • Improved resilience when decoding search results and handling optional fields.
    • Downloaded subtitles are added and selected without restarting playback.
  • Tests
    • Added coverage for subtitle search/download request/response decoding and scoring boundaries.

Search external subtitle providers (OpenSubtitles/SubDL/Subsource) from
the player and download a result mid-playback:

- POST /subtitles/search + /subtitles/download wire types and ContinuumAI
  methods (synchronous, no job machinery; warnings surface per-provider
  soft failures)
- SubtitleSearchMenu: one-tap language pick (preferred floats to top, no
  free-text field), score/provider/HI-badged results; iOS sheet + tvOS
  focus panel following the SubtitleTranslateMenu idioms
- Downloaded track reuses the AI-subtitle sidecar handoff (re-list ->
  position -> synthesized combined-index stream URL -> register + auto-
  select) with no session restart; the subtitle_ready websocket echo is
  a no-op via the existing combined-index de-dupe
- Entries in TrackSelectionSheet (iOS) and TVPlayerInfoHUD Subtitles pane
  (tvOS), gated on an active server session (hidden offline/local); tvOS
  Back is inert while a download is in flight
- Focused tests for the wire contract (snake_case decode, download body
  echo, score tiers)

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dfec7c10-e9f4-4b2a-a40a-a183d9d4c23f

📥 Commits

Reviewing files that changed from the base of the PR and between 3625980 and f3de1b9.

📒 Files selected for processing (4)
  • iosApp/Tests/SubtitleSearchModelTests.swift
  • iosApp/iosApp/Networking/SubtitleSearchModels.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/Sheets/SubtitleSearchMenu.swift
🚧 Files skipped from review as they are similar to previous changes (3)
  • iosApp/iosApp/Networking/SubtitleSearchModels.swift
  • iosApp/iosApp/Screens/Player/Sheets/SubtitleSearchMenu.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift

📝 Walkthrough

Walkthrough

This PR adds in-player subtitle provider search and download support. It introduces new wire models and network calls, adds PlayerViewModel search/download orchestration, wires a new SubtitleSearchMenu into iOS and tvOS player UI, and adds contract tests.

Changes

Subtitle Provider Search Feature

Layer / File(s) Summary
Search/download data models and networking calls
iosApp/iosApp/Networking/SubtitleSearchModels.swift, iosApp/iosApp/Networking/ContinuumAI.swift
Adds SubtitleSearchBody, SubtitleSearchResult, SubtitleSearchResponse, SubtitleDownloadBody, SubtitleDownloadResponse, and SubtitleSearchScoreTier, plus ContinuumAI.searchSubtitles(_:) and downloadSubtitle(_:) posting to the new endpoints.
PlayerViewModel search/download orchestration
iosApp/iosApp/Screens/Player/PlayerViewModel.swift
Adds subtitleSearchAvailable, searchSubtitles(languages:), and downloadSearchedSubtitle(_:) that download a result and register it via the existing sidecar/AI subtitle handoff.
SubtitleSearchMenu SwiftUI view (iOS/tvOS)
iosApp/iosApp/Screens/Player/Sheets/SubtitleSearchMenu.swift
New phase-driven (picking/searching/results/failed) menu with language selection, per-platform layouts, result rows with download actions, and shared score/provider badge helpers.
TrackSelectionSheet integration
iosApp/iosApp/Screens/Player/Sheets/TrackSelectionSheet.swift
Adds "Search Subtitles…" entries via a generalized MenuEntryRow, overlay dimming, and sheet/menu presentation for SubtitleSearchMenu on both platforms.
TVPlayerInfoHUD integration
iosApp/iosApp/Screens/Player/tvOS/TVPlayerInfoHUD.swift
Extends tab availability and SubtitlesPane with a new .search option, overlay gating, and a "Search Subtitles…" row opening the menu.
Model unit tests
iosApp/Tests/SubtitleSearchModelTests.swift
Adds tests for search response decoding, tolerant defaults, download body encoding, download response decoding, and score tier boundaries.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • Silo-Server/silo-apple#42: Extends TVPlayerInfoHUD.swift’s subtitles focus flow with the .search option and overlay state used by this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: in-player subtitle search on iOS/tvOS with provider parity context.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/subtitle-search

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36259803c3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +29 to +30
struct SubtitleSearchResult: Codable, Identifiable, Equatable {
let id: String

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Key search rows by provider and subtitle id

When two providers return the same provider-local subtitle id, this Identifiable conformance exposes only id to SwiftUI ForEach(results), and the menu also uses that same value for download state and tvOS focus. In that case SwiftUI can coalesce distinct provider results and show the spinner/disabled state on the wrong row, even though the download API requires the (provider, subtitleId) pair. Use a composite identity such as provider plus id for result identity/state.

Useful? React with 👍 / 👎.

)
return false
}
guard let context = makeSubtitleHandoffContext(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Revalidate the playback item before handoff

If a subtitle download is in flight and playback advances or the user dismisses the menu and starts another item before the awaits return, fileId still refers to the old media file but makeSubtitleHandoffContext() reads the current active session. That can synthesize and auto-select a /stream/{session}/subtitles/{position} URL for the new session using the old file's downloaded-subtitle position, yielding a wrong or invalid subtitle track. Capture/recheck the session or current file id before registering the descriptor.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
iosApp/iosApp/Screens/Player/Sheets/SubtitleSearchMenu.swift (1)

58-59: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

searchTask isn't cancelled on dismiss paths that bypass backToLanguages().

Both the tvOS backdrop tap (onDismiss(), Line 266) and the iOS "Done" toolbar button (onDismiss(), Line 557) close the menu directly without cancelling searchTask. If a search is in-flight (.searching phase), the task keeps running and later mutates @State on an already-dismissed view.

♻️ Proposed fix
     var body: some View {
         `#if` os(tvOS)
         tvOSPanel
         `#else`
         phoneList
         `#endif`
     }
+    .onDisappear { searchTask?.cancel() }

Also applies to: 145-165

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/iosApp/Screens/Player/Sheets/SubtitleSearchMenu.swift` around lines 58
- 59, searchTask is only cancelled through backToLanguages(), but the direct
dismiss paths in SubtitleSearchMenu’s onDismiss handlers can bypass that cleanup
and leave the in-flight search mutating state after dismissal. Update the
dismissal flow so every path that closes the sheet/menu also cancels searchTask
before exiting, and make sure the existing backToLanguages()/onDismiss logic in
SubtitleSearchMenu covers both the tvOS backdrop tap and the iOS Done button.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@iosApp/iosApp/Screens/Player/Sheets/SubtitleSearchMenu.swift`:
- Around line 239-248: The tvOS empty-results state is missing an initial focus
target because focusFirstRow() only assigns results.first?.id in the .results
phase, which is nil when tvResultRows shows the "back-to-languages" fallback
row. Update focusFirstRow() in SubtitleSearchMenu to detect an empty results
list and set focusedRowID to the fallback row’s id (the same identifier used by
tvResultRows for the back-to-languages row), so on empty searches and when
.onChange(of: phase) runs, a valid row is focused instead of leaving focus
empty.

---

Nitpick comments:
In `@iosApp/iosApp/Screens/Player/Sheets/SubtitleSearchMenu.swift`:
- Around line 58-59: searchTask is only cancelled through backToLanguages(), but
the direct dismiss paths in SubtitleSearchMenu’s onDismiss handlers can bypass
that cleanup and leave the in-flight search mutating state after dismissal.
Update the dismissal flow so every path that closes the sheet/menu also cancels
searchTask before exiting, and make sure the existing
backToLanguages()/onDismiss logic in SubtitleSearchMenu covers both the tvOS
backdrop tap and the iOS Done button.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a5b4dfa-4ae2-4f44-b0ec-bd7cc0e0e996

📥 Commits

Reviewing files that changed from the base of the PR and between 41ab13c and 3625980.

📒 Files selected for processing (7)
  • iosApp/Tests/SubtitleSearchModelTests.swift
  • iosApp/iosApp/Networking/ContinuumAI.swift
  • iosApp/iosApp/Networking/SubtitleSearchModels.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/Sheets/SubtitleSearchMenu.swift
  • iosApp/iosApp/Screens/Player/Sheets/TrackSelectionSheet.swift
  • iosApp/iosApp/Screens/Player/tvOS/TVPlayerInfoHUD.swift

- Key search-result UI identity on the composite provider:id pair
  (uniqueKey) instead of the provider-local id, which can collide across
  providers — coalesced ForEach rows and misplaced spinner/disabled
  state (Codex)
- Revalidate the current media file after the download awaits so a
  mid-download item change can't register the old file's listing
  position against the new session (Codex)
- tvOS: focus the "Choose another language" fallback row when a search
  returns no results, so the remote isn't left unfocused (CodeRabbit)

Co-Authored-By: Claude Fable 5 <[email protected]>
@Quick104

Quick104 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Addressed all three review findings in f3de1b9:

  • Composite result identity (Codex): SubtitleSearchResult no longer conforms to Identifiable on the provider-local id; all UI identity (ForEach, tvOS focus keys, download-in-flight tracking) now keys on a composite uniqueKey (provider:id), mirroring Android's download key. Added a unit test for cross-provider id collisions.
  • Handoff revalidation (Codex): downloadSearchedSubtitle re-checks currentSelectedVersion?.fileId after the download/listing awaits and skips the live handoff if playback moved to a different file — the download is still persisted server-side and picked up by the next session of that file.
  • Empty-results focus (CodeRabbit): focusFirstRow() now falls back to the back-to-languages row when the result set is empty, so the tvOS remote always has a focus target.

SiloTV build green, all 6 model tests pass.

@Quick104
Quick104 merged commit 19f864f into main Jul 2, 2026
1 check was pending
@Quick104
Quick104 deleted the feature/subtitle-search branch July 2, 2026 16:28
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