fix(player): carry a picked subtitle language across episodes with sparse tags
The cross-item subtitle intent required declared languages on both sides, and a null on either side counted as a contradiction. Any untagged track - common when a title like "Swedish" is the only signal - declined on every episode advance, fell to the server's per-item priority, and turned the viewer's subtitles off (a 2.11.0 regression from the #1716/#1717 hard gates). A unique real title match now vouches for a row when language evidence is missing on either side. Declared languages that disagree still decline no matter what the title says, forced-class parity is untouched, codec and external parity only break ties within the title-matched set, and a residual tie declines rather than guesses, so the wrong-track class of #1716 stays closed. A decline is also no longer laundered into a viewer decision: the resolver keeps the unserved preference on the selection, the open flow hands it to the track manager instead of a navigation-priority off (late native tracks may carry the container tags the server rows lack), the next episode boundary re-carries it instead of hardening it into an explicit off, and progress reports withhold the -1 subtitle index that would otherwise come back as the item's server-side default forever. A pick the screen could not map to a source row (no subtitle catalog, or an identity-matcher miss) previously never reached the committed session selection at all, so the next episode carried the stale off while the picked track was visibly on screen. Such picks now commit the raw native track without source ids and demote to a semantic intent at the boundary. close #1785
This commit is contained in:
@@ -6,6 +6,8 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plezy/focus/focusable_button.dart';
|
||||
import 'package:plezy/providers/playback_state_provider.dart';
|
||||
import 'package:plezy/mpv/mpv.dart';
|
||||
import 'package:plezy/media/media_source_info.dart';
|
||||
import 'package:plezy/services/playback_subtitle_resolver.dart';
|
||||
import 'package:plezy/screens/video_player_screen.dart';
|
||||
import 'package:plezy/services/settings_service.dart';
|
||||
import 'package:plezy/services/subtitle_preference.dart';
|
||||
@@ -117,6 +119,146 @@ void main() {
|
||||
expect((result! as SubtitleIntentPreference).intent.language, 'eng');
|
||||
});
|
||||
|
||||
test('a declined committed off re-carries the declined preference (#1785)', () {
|
||||
const declined = SubtitlePreference.intent(
|
||||
SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'srt'),
|
||||
);
|
||||
|
||||
// The committed off is fallout from a declined carry: with the player
|
||||
// also off, the declined preference itself keeps crossing boundaries.
|
||||
expect(
|
||||
subtitlePreferenceForItemChange(
|
||||
hasCommittedSelection: true,
|
||||
committedTrack: SubtitleTrack.off,
|
||||
nativeTrack: SubtitleTrack.off,
|
||||
declinedPreference: declined,
|
||||
),
|
||||
declined,
|
||||
);
|
||||
});
|
||||
|
||||
test('live native state outranks a declined carry after a late rescue (#1785)', () {
|
||||
const declined = SubtitlePreference.intent(
|
||||
SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'srt'),
|
||||
);
|
||||
|
||||
final result = subtitlePreferenceForItemChange(
|
||||
hasCommittedSelection: true,
|
||||
committedTrack: SubtitleTrack.off,
|
||||
nativeTrack: const SubtitleTrack(id: '5', language: 'swe', title: 'Swedish', codec: 'srt'),
|
||||
declinedPreference: declined,
|
||||
);
|
||||
|
||||
expect(result, isA<SubtitleIntentPreference>());
|
||||
expect((result! as SubtitleIntentPreference).intent.language, 'swe');
|
||||
});
|
||||
|
||||
test('a declined stale source reference crosses the boundary as its intent (#1785)', () {
|
||||
const declined = SubtitlePreference.track(
|
||||
SubtitleTrack(id: 'source:9', title: 'Swedish', language: 'swe', codec: 'srt'),
|
||||
);
|
||||
|
||||
final result = subtitlePreferenceForItemChange(
|
||||
hasCommittedSelection: true,
|
||||
committedTrack: SubtitleTrack.off,
|
||||
nativeTrack: SubtitleTrack.off,
|
||||
declinedPreference: declined,
|
||||
);
|
||||
|
||||
expect(result, isA<SubtitleIntentPreference>());
|
||||
expect((result! as SubtitleIntentPreference).intent.language, 'swe');
|
||||
});
|
||||
|
||||
test('a pick without source identity is committed raw and carries as an intent (#1785)', () {
|
||||
// The identity matcher failed (or the item has no subtitle rows): the
|
||||
// committed selection must still reflect the pick on screen, not the
|
||||
// session's previous choice.
|
||||
const picked = SubtitleTrack(id: '3', title: 'Swedish', language: 'swe', codec: 'srt');
|
||||
|
||||
final selection = subtitleSelectionForUserPick(
|
||||
currentSelection: const PlaybackSubtitleSelection.off(),
|
||||
isPrimarySlot: true,
|
||||
track: picked,
|
||||
);
|
||||
|
||||
expect(selection.primaryTrack, picked);
|
||||
expect(selection.primarySourceStreamId, isNull);
|
||||
expect(selection.primarySidecar, isNull);
|
||||
|
||||
// Next episode boundary: the raw commit demotes to a semantic intent
|
||||
// instead of hardening the stale off.
|
||||
final carried = subtitlePreferenceForItemChange(
|
||||
hasCommittedSelection: true,
|
||||
committedTrack: selection.primaryTrack,
|
||||
nativeTrack: picked,
|
||||
);
|
||||
expect(carried, isA<SubtitleIntentPreference>());
|
||||
expect((carried! as SubtitleIntentPreference).intent.language, 'swe');
|
||||
});
|
||||
|
||||
test('a source-backed pick keeps its source identity in the committed selection', () {
|
||||
final sourceTrack = MediaSubtitleTrack(
|
||||
id: 7,
|
||||
languageCode: 'swe',
|
||||
title: 'Swedish',
|
||||
codec: 'srt',
|
||||
selected: false,
|
||||
forced: false,
|
||||
);
|
||||
|
||||
final selection = subtitleSelectionForUserPick(
|
||||
currentSelection: const PlaybackSubtitleSelection.off(),
|
||||
isPrimarySlot: true,
|
||||
track: const SubtitleTrack(id: '3', title: 'Swedish', language: 'swe', codec: 'srt'),
|
||||
sourceTrack: sourceTrack,
|
||||
);
|
||||
|
||||
expect(selection.primaryTrack.id, 'source:7');
|
||||
expect(selection.primarySourceStreamId, 7);
|
||||
});
|
||||
|
||||
test('a secondary-slot pick leaves the committed primary untouched', () {
|
||||
const primary = SubtitleTrack(id: 'source:4', title: 'Swedish', language: 'swe', codec: 'srt');
|
||||
const secondaryPick = SubtitleTrack(id: '5', title: 'English', language: 'eng', codec: 'srt');
|
||||
|
||||
final selection = subtitleSelectionForUserPick(
|
||||
currentSelection: const PlaybackSubtitleSelection(primaryTrack: primary, primarySourceStreamId: 4),
|
||||
isPrimarySlot: false,
|
||||
track: secondaryPick,
|
||||
);
|
||||
|
||||
expect(selection.primaryTrack, primary);
|
||||
expect(selection.primarySourceStreamId, 4);
|
||||
expect(selection.secondaryTrack, secondaryPick);
|
||||
expect(selection.secondarySourceStreamId, isNull);
|
||||
});
|
||||
|
||||
test('a secondary-only change keeps the primary declined carry alive (#1785)', () {
|
||||
const declined = SubtitlePreference.intent(
|
||||
SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'srt'),
|
||||
);
|
||||
const current = PlaybackSubtitleSelection.off(declinedPreference: declined);
|
||||
|
||||
final selection = subtitleSelectionForUserPick(
|
||||
currentSelection: current,
|
||||
isPrimarySlot: false,
|
||||
track: const SubtitleTrack(id: '5', title: 'English', language: 'eng', codec: 'srt'),
|
||||
);
|
||||
|
||||
// The primary off stays fallout, not a decision: -1 must remain withheld
|
||||
// and the next boundary must still re-carry the intent.
|
||||
expect(selection.primaryTrack.id, SubtitleTrack.off.id);
|
||||
expect(selection.declinedPreference, declined);
|
||||
|
||||
// A primary decision retires the carry.
|
||||
final decided = subtitleSelectionForUserPick(
|
||||
currentSelection: selection,
|
||||
isPrimarySlot: true,
|
||||
track: const SubtitleTrack(id: '3', title: 'Swedish', language: 'swe', codec: 'srt'),
|
||||
);
|
||||
expect(decided.declinedPreference, isNull);
|
||||
});
|
||||
|
||||
testWidgets('initialization ownership serializes rollback, retry, and route removal', (tester) async {
|
||||
final failedDispose = Completer<void>();
|
||||
final replacementInitialize = Completer<bool>();
|
||||
|
||||
@@ -703,6 +703,55 @@ void main() {
|
||||
expect(progressSelection.subtitleStreamIndex, -1);
|
||||
});
|
||||
|
||||
test('an off that fell out of a declined carry is not persisted as -1 (#1785)', () async {
|
||||
final client = _FakePlexClient();
|
||||
const selectedAudio = AudioTrack(id: 'audio_1', language: 'jpn');
|
||||
const subtitlesOff = SubtitleTrack(id: 'no');
|
||||
final player = _FakePlayer(
|
||||
position: const Duration(seconds: 5),
|
||||
duration: const Duration(seconds: 100),
|
||||
tracks: const Tracks(
|
||||
audio: [
|
||||
AudioTrack(id: 'audio_0', language: 'eng'),
|
||||
selectedAudio,
|
||||
],
|
||||
subtitle: [SubtitleTrack(id: 'text_0', language: 'eng')],
|
||||
),
|
||||
track: const TrackSelection(audio: selectedAudio, subtitle: subtitlesOff),
|
||||
);
|
||||
final mediaInfo = MediaSourceInfo(
|
||||
videoUrl: '',
|
||||
audioTracks: [
|
||||
MediaAudioTrack(id: 1, languageCode: 'eng', selected: false),
|
||||
MediaAudioTrack(id: 2, languageCode: 'jpn', selected: true),
|
||||
],
|
||||
subtitleTracks: [MediaSubtitleTrack(id: 3, languageCode: 'eng', selected: false, forced: false)],
|
||||
chapters: const [],
|
||||
mediaSourceId: 'source-1',
|
||||
);
|
||||
final tracker = PlaybackProgressTracker(
|
||||
client: client,
|
||||
metadata: _meta(ratingKey: '42'),
|
||||
player: player,
|
||||
isOffline: false,
|
||||
mediaInfo: mediaInfo,
|
||||
subtitleOffIsDeliberate: () => false,
|
||||
);
|
||||
addTearDown(tracker.dispose);
|
||||
|
||||
await tracker.sendProgress('playing');
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
await tracker.sendProgress('playing');
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
final progressSelection = client.playbackStreamSelections[1];
|
||||
// Withheld, so the server keeps whatever it knew — an explicit -1
|
||||
// would come back as this item's default and latch the fallout.
|
||||
expect(progressSelection.subtitleStreamIndex, isNull);
|
||||
// The audio selection is still reported normally.
|
||||
expect(progressSelection.audioStreamIndex, 2);
|
||||
});
|
||||
|
||||
test('stopped reports only resolve media source and do not include selected streams', () async {
|
||||
final client = _FakePlexClient();
|
||||
const selectedAudio = AudioTrack(id: 'audio_1', language: 'jpn');
|
||||
|
||||
@@ -548,6 +548,65 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('issue #1785 declined-carry surfacing', () {
|
||||
const swedishIntent = SubtitlePreference.intent(
|
||||
SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'srt'),
|
||||
);
|
||||
|
||||
MediaSubtitleTrack untaggedRow(int id, {String? title, String codec = 'srt'}) =>
|
||||
MediaSubtitleTrack(id: id, title: title, codec: codec, selected: false, forced: false);
|
||||
|
||||
test('an untagged catalog row with the matching title still serves the carry', () {
|
||||
final result = PlaybackSubtitleResolver.resolve(
|
||||
metadata: metadata,
|
||||
mediaInfo: _mediaInfo([untaggedRow(3, title: 'English'), untaggedRow(4, title: 'Swedish')]),
|
||||
sidecars: const [],
|
||||
preferredSubtitleTrack: swedishIntent,
|
||||
preserveSourceIdentity: false,
|
||||
);
|
||||
|
||||
expect(result.primarySourceStreamId, 4);
|
||||
expect(result.declinedPreference, isNull);
|
||||
});
|
||||
|
||||
test('a carry no row can serve is kept as declined, not converted to off', () {
|
||||
final result = PlaybackSubtitleResolver.resolve(
|
||||
metadata: metadata,
|
||||
mediaInfo: _mediaInfo([_sourceSubtitle(3, language: 'eng')]),
|
||||
sidecars: const [],
|
||||
preferredSubtitleTrack: swedishIntent,
|
||||
preserveSourceIdentity: false,
|
||||
);
|
||||
|
||||
expect(result.isOff, isTrue);
|
||||
expect(result.declinedPreference, swedishIntent);
|
||||
});
|
||||
|
||||
test('an explicit off carry is a decision, never a decline', () {
|
||||
final result = PlaybackSubtitleResolver.resolve(
|
||||
metadata: metadata,
|
||||
mediaInfo: _mediaInfo([_sourceSubtitle(3, language: 'eng')]),
|
||||
sidecars: const [],
|
||||
preferredSubtitleTrack: const SubtitlePreference.off(),
|
||||
preserveSourceIdentity: false,
|
||||
);
|
||||
|
||||
expect(result.isOff, isTrue);
|
||||
expect(result.declinedPreference, isNull);
|
||||
});
|
||||
|
||||
test('a ladder off with no carry at all is a decision, never a decline', () {
|
||||
final result = PlaybackSubtitleResolver.resolve(
|
||||
metadata: metadata,
|
||||
mediaInfo: _mediaInfo([_sourceSubtitle(3, language: 'eng')]),
|
||||
sidecars: const [],
|
||||
);
|
||||
|
||||
expect(result.isOff, isTrue);
|
||||
expect(result.declinedPreference, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
test('selected embedded subtitle keeps sidecars out of the open', () {
|
||||
final result = PlaybackSubtitleResolver.resolve(
|
||||
metadata: metadata,
|
||||
|
||||
@@ -1137,10 +1137,74 @@ void main() {
|
||||
expect(findSourceTrackForIntent(fullIntent, rows)?.id, 2);
|
||||
});
|
||||
|
||||
test('language-less intents decline', () {
|
||||
test('language-less intent declines when no row carries a matching title', () {
|
||||
const intent = SubtitleIntent(forced: false, title: 'French', codec: 'srt');
|
||||
expect(findSourceTrackForIntent(intent, [_plexSub(1, languageCode: 'fre')]), isNull);
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// #1785 — missing language tags must not turn the carry off when a
|
||||
// unique real title identifies the row; codec parity alone is never
|
||||
// evidence, and ambiguity declines rather than guesses.
|
||||
// ============================================================
|
||||
|
||||
test('title-only intent matches the row with the same title when tags are missing (#1785)', () {
|
||||
const intent = SubtitleIntent(forced: false, title: 'Swedish', codec: 'subrip');
|
||||
final rows = [_plexSub(1, title: 'English', codec: 'subrip'), _plexSub(2, title: 'Swedish', codec: 'subrip')];
|
||||
expect(findSourceTrackForIntent(intent, rows)?.id, 2);
|
||||
});
|
||||
|
||||
test('tagged intent reaches an untagged row through its title (#1785)', () {
|
||||
const intent = SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'subrip');
|
||||
expect(findSourceTrackForIntent(intent, [_plexSub(1, title: 'Swedish', codec: 'subrip')])?.id, 1);
|
||||
});
|
||||
|
||||
test('title-only intent reaches a tagged row through its title (#1785)', () {
|
||||
const intent = SubtitleIntent(forced: false, title: 'Swedish', codec: 'subrip');
|
||||
final rows = [
|
||||
_plexSub(1, languageCode: 'eng', title: 'English'),
|
||||
_plexSub(2, languageCode: 'swe', title: 'Swedish'),
|
||||
];
|
||||
expect(findSourceTrackForIntent(intent, rows)?.id, 2);
|
||||
});
|
||||
|
||||
test('declared languages stay authoritative over a coincidental title', () {
|
||||
const intent = SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'subrip');
|
||||
expect(findSourceTrackForIntent(intent, [_plexSub(1, languageCode: 'eng', title: 'Swedish')]), isNull);
|
||||
});
|
||||
|
||||
test('codec parity alone never vouches for an untagged row', () {
|
||||
const intent = SubtitleIntent(forced: false, title: 'Swedish', codec: 'subrip');
|
||||
expect(findSourceTrackForIntent(intent, [_plexSub(1, codec: 'subrip')]), isNull);
|
||||
});
|
||||
|
||||
test('an ambiguous same-title untagged pair declines rather than guesses', () {
|
||||
const intent = SubtitleIntent(forced: false, title: 'Swedish', codec: 'subrip');
|
||||
final rows = [_plexSub(1, title: 'Swedish', codec: 'subrip'), _plexSub(2, title: 'Swedish', codec: 'subrip')];
|
||||
expect(findSourceTrackForIntent(intent, rows), isNull);
|
||||
});
|
||||
|
||||
test('codec separates same-titled untagged rows before declining', () {
|
||||
const intent = SubtitleIntent(forced: false, title: 'Swedish', codec: 'ass');
|
||||
final rows = [_plexSub(1, title: 'Swedish', codec: 'subrip'), _plexSub(2, title: 'Swedish', codec: 'ass')];
|
||||
expect(findSourceTrackForIntent(intent, rows)?.id, 2);
|
||||
});
|
||||
|
||||
test('forced parity still gates title-evidence matches', () {
|
||||
const intent = SubtitleIntent(forced: false, title: 'Swedish', codec: 'subrip');
|
||||
expect(findSourceTrackForIntent(intent, [_plexSub(1, title: 'Swedish Forced', codec: 'subrip')]), isNull);
|
||||
});
|
||||
|
||||
test('a language-parity match outranks a title-evidence match', () {
|
||||
const intent = SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'subrip');
|
||||
final rows = [
|
||||
// Title-evidence candidate (untagged, matching title + codec).
|
||||
_plexSub(1, title: 'Swedish', codec: 'subrip'),
|
||||
// Language-parity candidate with a non-matching title.
|
||||
_plexSub(2, languageCode: 'swe', title: 'Svenska full'),
|
||||
];
|
||||
expect(findSourceTrackForIntent(intent, rows)?.id, 2);
|
||||
});
|
||||
});
|
||||
|
||||
group('findNativeTrackForIntent', () {
|
||||
@@ -1167,6 +1231,21 @@ void main() {
|
||||
final forcedOnly = [_sub('1', lang: 'fre', title: 'FR Forced', codec: 'ass')];
|
||||
expect(findNativeTrackForIntent(fullIntent, forcedOnly), isNull);
|
||||
});
|
||||
|
||||
test('an untagged native track with the matching title serves the intent (#1785)', () {
|
||||
// The server catalog may lack tags while mpv reads them from the
|
||||
// container — and vice versa: a tagged intent must still reach an
|
||||
// untagged native track through its title.
|
||||
const intent = SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'subrip');
|
||||
final tracks = [SubtitleTrack.auto, SubtitleTrack.off, _sub('3', title: 'Swedish', codec: 'subrip')];
|
||||
expect(findNativeTrackForIntent(intent, tracks)?.id, '3');
|
||||
});
|
||||
|
||||
test('an ambiguous untagged native pair declines rather than guesses', () {
|
||||
const intent = SubtitleIntent(forced: false, title: 'Swedish', codec: 'subrip');
|
||||
final tracks = [_sub('1', title: 'Swedish', codec: 'subrip'), _sub('2', title: 'Swedish', codec: 'subrip')];
|
||||
expect(findNativeTrackForIntent(intent, tracks), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('selectSubtitleTrack - intent preferences (#1716/#1717)', () {
|
||||
|
||||
Reference in New Issue
Block a user