Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add feature-gated dual subtitle MVP with merged subtitle track#2549

Draft
beng1z wants to merge 4 commits intorecloudstream:masterfrom
beng1z:feat/dual-subtitles-mvp-gated
Draft

Add feature-gated dual subtitle MVP with merged subtitle track#2549
beng1z wants to merge 4 commits intorecloudstream:masterfrom
beng1z:feat/dual-subtitles-mvp-gated

Conversation

@beng1z
Copy link

@beng1z beng1z commented Mar 1, 2026

Summary

  • Add a feature-gated dual subtitle MVP (off by default).
  • Add explicit Primary / Secondary selection mode in source/subtitle dialog.
  • Implement parse-time subtitle merge into a single generated WebVTT track (no polling).
  • Block unsupported combinations (embedded secondary, embedded primary+secondary, secondary without primary) with clear user feedback.
  • Keep 403/header bugfix out of this PR scope, except dual-pipeline-required subtitle header merge.

What changed

  • IPlayer API expanded with secondary subtitle methods.
  • CS3IPlayer implements secondary state, dual merge pipeline, and merged track selection.
  • GeneratorPlayer updated for Primary/Secondary selection UX and Apply-based commit behavior.
  • Subtitle settings now include Dual subtitles (experimental) switch.
  • Added DualSubtitleComposer + unit tests.
  • Added/updated localized strings for all supported locales for the newly introduced dual subtitle keys.

AI usage disclosure

  • AI tooling was used to assist implementation and localization generation.
  • All code/resources were manually reviewed and adjusted.
  • Review feedback and requested UX constraints were applied manually.

Testing

  • Manual device test completed (dual subtitle selection, apply flow, unsupported combo blocking, layout behavior).
  • ./gradlew testStableDebugUnitTest assembleStableDebug --no-daemon passes.

Notes

  • Dual subtitles remain experimental and disabled by default.
  • Embedded-secondary scenarios are intentionally unsupported in MVP.

Deniz added 4 commits March 2, 2026 00:21
- isDualSubtitleTrackSelectionEnabled: use intermediate variable to fix
  Elvis operator precedence (?: binds lower than &&), avoiding incorrect
  evaluation when the preference key is unset.
- isDualSubtitleCombinationSupported in CS3IPlayer: accept nullable params
  and add null guards to match GeneratorPlayer's version, eliminating
  behavioral inconsistency between the two implementations.
- Faz 6: Add contentDescription to Primary/Secondary subtitle tab
  buttons in both landscape and portrait layouts
- Faz 3: Add cleanDualSubtitleCache() to delete old dual_sub_*.vtt
  files on episode change and before new merge
- Faz 5 Part 1: Add 6 new tests for DualSubtitleComposer (WebVTT
  output validity, primary/secondary-only, negative duration)
Copy link
Collaborator

@fire-light42 fire-light42 left a comment

Choose a reason for hiding this comment

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

First round of comments, for the easiest to spot issues.
I will give you more once I can properly test it as the app reliably freezes when testing it.

We will not merge anything half-finished, as to keep CloudStream maintainable. We will therefore not merge a MVP. This feature will need to be polished before getting accepted.


\n%s</string>
<string name="delete_message_series_section" formatted="true">رح كمان تمحي ل الأبد كل الحلقات اللي ب هيدا المسلسل؟
\n
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why all of these removals?

return Pair(listOf(merged.first), listOf(merged.second))
}

event(ErrorEvent(ErrorLoadingException(context.getString(R.string.subtitles_secondary_load_failed))))
Copy link
Collaborator

Choose a reason for hiding this comment

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

These events cause an error loop wherein the player goes to the next source and the subtitles are loaded again. This freezes the app.


event(ErrorEvent(ErrorLoadingException(context.getString(R.string.subtitles_secondary_load_failed))))
dualMergedTrackId = null
return Pair(emptyList(), emptyList())
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should fall back to single subtitles if an error occurs.

private fun cleanDualSubtitleCache(context: Context, exclude: File? = null) {
try {
context.cacheDir.listFiles { file ->
file.name.startsWith("dual_sub_") && file.name.endsWith(".vtt") && file != exclude
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name should be in a constant, as to prevent issues when someone in the future renames the subtitle file. The subtitle files should preferably also be in its own folder to ease future debugging.

return try {
when (subtitle.origin) {
SubtitleOrigin.URL -> {
val mergedHeaders = mutableMapOf<String, String>().apply {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why merged headers? Other subtitles do not have merged headers.

}

private fun isDualSubtitleTrackSelectionEnabled(): Boolean {
val enabled = getKey<Boolean>(SUBTITLE_DUAL_ENABLED_KEY) ?: false
Copy link
Collaborator

Choose a reason for hiding this comment

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

WET code, use the function you defined


<string name="subtitles_dual_enabled">ଡୁଆଲ୍ ସବ୍ଟାଇଟ୍ (ପରୀକ୍ଷାମୂଳକ)</string>
<string name="subtitles_edit_primary">ପ୍ରାଥମିକ</string>
<string name="subtitles_edit_secondary">ଦ୍ Secondary ିତୀୟ</string>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not translate strings using AI, let real people do the translations.

@beng1z beng1z marked this pull request as draft March 3, 2026 04:16
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.

2 participants