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:
@@ -159,6 +159,7 @@ extension _VideoPlayerEpisodeNavigationMethods on VideoPlayerScreenState {
|
||||
hasCommittedSelection: committedSubtitleSelection != null,
|
||||
committedTrack: committedSubtitleSelection?.primaryTrack,
|
||||
nativeTrack: currentPlayer.state.track.subtitle,
|
||||
declinedPreference: committedSubtitleSelection?.declinedPreference,
|
||||
);
|
||||
final secondarySubtitlePreference = followServerSelections
|
||||
? null
|
||||
@@ -771,7 +772,11 @@ extension _VideoPlayerEpisodeNavigationMethods on VideoPlayerScreenState {
|
||||
plexClient: plexClient,
|
||||
getProfileSettings: () => userProfileProvider.profileSettings,
|
||||
preferredAudioTrack: currentAudioTrack,
|
||||
preferredSubtitleTrack: SubtitlePreference.trackOrNull(subtitleSelection.primaryTrack),
|
||||
// A declined carry stays alive for the native passes: freezing the
|
||||
// resolver's off verdict here would turn a metadata mismatch into a
|
||||
// navigation-priority off that no late track can undo (#1785).
|
||||
preferredSubtitleTrack:
|
||||
subtitleSelection.declinedPreference ?? SubtitlePreference.trackOrNull(subtitleSelection.primaryTrack),
|
||||
preferredSecondarySubtitleTrack: SubtitlePreference.trackOrNull(subtitleSelection.secondaryTrack),
|
||||
);
|
||||
_trackManager = trackManager;
|
||||
|
||||
@@ -414,6 +414,7 @@ extension _VideoPlayerPlaybackServiceMethods on VideoPlayerScreenState {
|
||||
mediaInfo: mediaInfo,
|
||||
canReportPlayback: () => _hasRenderedFirstFrame && !_hasFatalPlaybackError,
|
||||
hasRenderedPlayback: () => _hasRenderedFirstFrame,
|
||||
subtitleOffIsDeliberate: () => _playbackSession?.subtitleSelection.declinedPreference == null,
|
||||
onPausedKeepalive: mediaClient is PlexClient && effectivePlayMethod == 'Transcode'
|
||||
? () => mediaClient.pingTranscodeSession(_playbackTranscodeSessionId)
|
||||
: null,
|
||||
|
||||
@@ -346,7 +346,10 @@ extension _VideoPlayerPlaybackStartMethods on VideoPlayerScreenState {
|
||||
plexClient: mediaClient is PlexClient ? mediaClient : null,
|
||||
getProfileSettings: () => context.read<UserProfileProvider>().profileSettings,
|
||||
preferredAudioTrack: _preferredAudioTrack,
|
||||
preferredSubtitleTrack: SubtitlePreference.trackOrNull(subtitleSelection.primaryTrack),
|
||||
// Same rule as the reload flow: a declined preference is retried by
|
||||
// the native passes instead of being frozen into off (#1785).
|
||||
preferredSubtitleTrack:
|
||||
subtitleSelection.declinedPreference ?? SubtitlePreference.trackOrNull(subtitleSelection.primaryTrack),
|
||||
preferredSecondarySubtitleTrack: SubtitlePreference.trackOrNull(subtitleSelection.secondaryTrack),
|
||||
);
|
||||
|
||||
|
||||
@@ -152,10 +152,15 @@ bool playerChromeStartsVisible({required bool isTv}) => !isTv;
|
||||
/// committed semantic choice — a [SubtitleIntent] — may cross the item
|
||||
/// boundary; native state is a fallback for sessions created before
|
||||
/// source-backed selection was recorded.
|
||||
///
|
||||
/// [declinedPreference] is the committed selection's unserved carry: its off
|
||||
/// is fallout from a metadata mismatch, not a viewer choice, so it must not
|
||||
/// harden into an explicit off on the next item (#1785).
|
||||
SubtitlePreference? subtitlePreferenceForItemChange({
|
||||
required bool hasCommittedSelection,
|
||||
required SubtitleTrack? committedTrack,
|
||||
required SubtitleTrack? nativeTrack,
|
||||
SubtitlePreference? declinedPreference,
|
||||
}) {
|
||||
SubtitlePreference? normalize(SubtitleTrack? track, {required bool preserveOff}) {
|
||||
if (track == null) return null;
|
||||
@@ -169,6 +174,15 @@ SubtitlePreference? subtitlePreferenceForItemChange({
|
||||
return normalize(nativeTrack, preserveOff: true);
|
||||
}
|
||||
|
||||
final committedIsOff = committedTrack == null || committedTrack.id == SubtitleTrack.off.id;
|
||||
if (declinedPreference != null && committedIsOff) {
|
||||
// Live native state wins — a late native pass may have served the
|
||||
// declined carry — otherwise the declined preference itself keeps
|
||||
// crossing item boundaries until the viewer or a richer catalog
|
||||
// settles it.
|
||||
return normalize(nativeTrack, preserveOff: false) ?? SubtitlePreference.demoteToIntent(declinedPreference);
|
||||
}
|
||||
|
||||
if (committedTrack == null) return const SubtitlePreference.off();
|
||||
|
||||
final committedPreference = normalize(committedTrack, preserveOff: true);
|
||||
@@ -176,6 +190,39 @@ SubtitlePreference? subtitlePreferenceForItemChange({
|
||||
return normalize(nativeTrack, preserveOff: false);
|
||||
}
|
||||
|
||||
/// Builds the committed [PlaybackSubtitleSelection] for a user's subtitle
|
||||
/// pick in one slot, leaving the other slot untouched.
|
||||
///
|
||||
/// [sourceTrack] and [sidecar] are null when the pick has no source-catalog
|
||||
/// identity — items without subtitle rows, or a native track the identity
|
||||
/// matcher cannot map. The raw native [track] is committed then (without
|
||||
/// source ids), so the session still reflects what is on screen and the next
|
||||
/// item boundary demotes it to a semantic intent instead of hardening the
|
||||
/// stale previous selection into an explicit off (#1785).
|
||||
PlaybackSubtitleSelection subtitleSelectionForUserPick({
|
||||
required PlaybackSubtitleSelection currentSelection,
|
||||
required bool isPrimarySlot,
|
||||
required SubtitleTrack track,
|
||||
MediaSubtitleTrack? sourceTrack,
|
||||
PlaybackSubtitleSidecar? sidecar,
|
||||
}) {
|
||||
final resolvedTrack = sourceTrack == null
|
||||
? track
|
||||
: PlaybackSubtitleResolver.subtitleTrackForSource(sourceTrack, sidecar: sidecar);
|
||||
return PlaybackSubtitleSelection(
|
||||
primaryTrack: isPrimarySlot ? resolvedTrack : currentSelection.primaryTrack,
|
||||
primarySourceStreamId: isPrimarySlot ? sourceTrack?.id : currentSelection.primarySourceStreamId,
|
||||
primarySidecar: isPrimarySlot ? sidecar : currentSelection.primarySidecar,
|
||||
secondaryTrack: isPrimarySlot ? currentSelection.secondaryTrack : resolvedTrack,
|
||||
secondarySourceStreamId: isPrimarySlot ? currentSelection.secondarySourceStreamId : sourceTrack?.id,
|
||||
secondarySidecar: isPrimarySlot ? currentSelection.secondarySidecar : sidecar,
|
||||
// A primary pick is a decision that retires any unresolved carry; a
|
||||
// secondary-only change must not relabel the primary's declined off as
|
||||
// deliberate (that would persist -1 and harden the next boundary).
|
||||
declinedPreference: isPrimarySlot ? null : currentSelection.declinedPreference,
|
||||
);
|
||||
}
|
||||
|
||||
/// The in-place media-source transitions a [VideoPlayerScreenState] can run.
|
||||
/// They are mutually exclusive by construction — entry points bail while a
|
||||
/// transition is in flight.
|
||||
@@ -1878,10 +1925,13 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
if (track.id == SubtitleTrack.off.id) {
|
||||
_updatePlaybackSessionSubtitleSelection(session, switch (slot) {
|
||||
_SubtitleSelectionSlot.primary => const PlaybackSubtitleSelection.off(),
|
||||
// Dropping only the secondary must not relabel the primary's
|
||||
// declined off as deliberate.
|
||||
_SubtitleSelectionSlot.secondary => PlaybackSubtitleSelection(
|
||||
primaryTrack: currentSelection.primaryTrack,
|
||||
primarySourceStreamId: currentSelection.primarySourceStreamId,
|
||||
primarySidecar: currentSelection.primarySidecar,
|
||||
declinedPreference: currentSelection.declinedPreference,
|
||||
),
|
||||
});
|
||||
if (mounted) _setPlayerState(() {});
|
||||
@@ -1890,7 +1940,6 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
|
||||
final info = _currentMediaInfo;
|
||||
final currentPlayer = player;
|
||||
if (info == null || currentPlayer == null) return;
|
||||
|
||||
MediaSubtitleTrack? sourceTrack;
|
||||
final currentSourceId = switch (slot) {
|
||||
@@ -1901,41 +1950,44 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
_SubtitleSelectionSlot.primary => currentSelection.primarySidecar,
|
||||
_SubtitleSelectionSlot.secondary => currentSelection.secondarySidecar,
|
||||
};
|
||||
if (sourceStreamId != null) {
|
||||
for (final candidate in info.subtitleTracks) {
|
||||
if (candidate.id == sourceStreamId) {
|
||||
sourceTrack = candidate;
|
||||
break;
|
||||
if (info != null) {
|
||||
if (sourceStreamId != null) {
|
||||
for (final candidate in info.subtitleTracks) {
|
||||
if (candidate.id == sourceStreamId) {
|
||||
sourceTrack = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (track.isExternal && currentSourceId != null && currentSidecar?.track.uri == track.uri) {
|
||||
for (final candidate in info.subtitleTracks) {
|
||||
if (candidate.id == currentSourceId) {
|
||||
sourceTrack = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (track.isExternal && currentSourceId != null && currentSidecar?.track.uri == track.uri) {
|
||||
for (final candidate in info.subtitleTracks) {
|
||||
if (candidate.id == currentSourceId) {
|
||||
sourceTrack = candidate;
|
||||
break;
|
||||
}
|
||||
if (sourceTrack == null && currentPlayer != null) {
|
||||
sourceTrack = findPlexTrackForMpvSubtitle(
|
||||
track,
|
||||
info.subtitleTracks,
|
||||
allMpvTracks: currentPlayer.state.tracks.subtitle,
|
||||
);
|
||||
}
|
||||
}
|
||||
sourceTrack ??= findPlexTrackForMpvSubtitle(
|
||||
track,
|
||||
info.subtitleTracks,
|
||||
allMpvTracks: currentPlayer.state.tracks.subtitle,
|
||||
);
|
||||
if (sourceTrack == null) return;
|
||||
|
||||
final sidecar = _sidecarForSourceStreamId(session, sourceTrack.id);
|
||||
final resolvedTrack = PlaybackSubtitleResolver.subtitleTrackForSource(sourceTrack, sidecar: sidecar);
|
||||
final selection = PlaybackSubtitleSelection(
|
||||
primaryTrack: slot == _SubtitleSelectionSlot.primary ? resolvedTrack : currentSelection.primaryTrack,
|
||||
primarySourceStreamId: slot == _SubtitleSelectionSlot.primary
|
||||
? sourceTrack.id
|
||||
: currentSelection.primarySourceStreamId,
|
||||
primarySidecar: slot == _SubtitleSelectionSlot.primary ? sidecar : currentSelection.primarySidecar,
|
||||
secondaryTrack: slot == _SubtitleSelectionSlot.secondary ? resolvedTrack : currentSelection.secondaryTrack,
|
||||
secondarySourceStreamId: slot == _SubtitleSelectionSlot.secondary
|
||||
? sourceTrack.id
|
||||
: currentSelection.secondarySourceStreamId,
|
||||
secondarySidecar: slot == _SubtitleSelectionSlot.secondary ? sidecar : currentSelection.secondarySidecar,
|
||||
// No source identity (no catalog, or a native track the identity matcher
|
||||
// cannot map) still commits the raw pick: an uncommitted selection reads
|
||||
// as the session's previous choice — usually the initial off — and the
|
||||
// next episode boundary would harden that into an explicit off while the
|
||||
// viewer visibly watches with subtitles on (#1785). The raw track carries
|
||||
// no source ids, so it demotes to a semantic intent at the boundary.
|
||||
final sidecar = sourceTrack == null ? null : _sidecarForSourceStreamId(session, sourceTrack.id);
|
||||
final selection = subtitleSelectionForUserPick(
|
||||
currentSelection: currentSelection,
|
||||
isPrimarySlot: slot == _SubtitleSelectionSlot.primary,
|
||||
track: track,
|
||||
sourceTrack: sourceTrack,
|
||||
sidecar: sidecar,
|
||||
);
|
||||
_updatePlaybackSessionSubtitleSelection(session, selection);
|
||||
if (mounted) _setPlayerState(() {});
|
||||
|
||||
@@ -87,6 +87,14 @@ class PlaybackProgressTracker {
|
||||
/// must not turn an unrendered native clock position into watched progress.
|
||||
final bool Function()? hasRenderedPlayback;
|
||||
|
||||
/// Whether an off subtitle state is a real decision (viewer or server)
|
||||
/// rather than the fallout of a declined cross-item carry. When false, the
|
||||
/// off state is not reported as an explicit `-1` stream index — persisting
|
||||
/// it would make Jellyfin hand the off back as this item's default on every
|
||||
/// later open, latching a metadata mismatch into a server-side choice
|
||||
/// (#1785). Callers default to deliberate.
|
||||
final bool Function()? subtitleOffIsDeliberate;
|
||||
|
||||
/// Timer for periodic progress updates
|
||||
Timer? _progressTimer;
|
||||
|
||||
@@ -166,6 +174,7 @@ class PlaybackProgressTracker {
|
||||
this.onPausedKeepalive,
|
||||
this.canReportPlayback,
|
||||
this.hasRenderedPlayback,
|
||||
this.subtitleOffIsDeliberate,
|
||||
this.updateInterval = const Duration(seconds: 10),
|
||||
}) : assert(!isOffline || offlineWatchService != null, 'offlineWatchService is required when isOffline is true'),
|
||||
assert(isOffline || client != null, 'client is required when isOffline is false') {
|
||||
@@ -605,7 +614,11 @@ class PlaybackProgressTracker {
|
||||
|
||||
int? _currentSubtitleStreamIndex(MediaSourceInfo info) {
|
||||
final track = player.state.track.subtitle;
|
||||
if (track == null || track.id == 'no') return -1;
|
||||
if (track == null || track.id == 'no') {
|
||||
// An off that merely fell out of a declined carry is withheld rather
|
||||
// than persisted as an explicit -1 (see [subtitleOffIsDeliberate]).
|
||||
return (subtitleOffIsDeliberate?.call() ?? true) ? -1 : null;
|
||||
}
|
||||
|
||||
if (track.isExternal && track.uri != null) {
|
||||
for (final mediaTrack in info.subtitleTracks) {
|
||||
|
||||
@@ -45,6 +45,14 @@ class PlaybackSubtitleSelection {
|
||||
final PlaybackSubtitleSidecar? secondarySidecar;
|
||||
final List<PlaybackSubtitleSidecar> preloadedSidecars;
|
||||
|
||||
/// The primary preference the resolver could not serve when this selection
|
||||
/// is off. Distinguishes "the carried choice declined and the ladder fell
|
||||
/// through" from a deliberate off (#1785): the open flow hands the declined
|
||||
/// preference back to the track manager so late-arriving native tracks may
|
||||
/// still serve it, and progress reports must not persist the fallout as an
|
||||
/// explicit server-side off. A user or server decision leaves this null.
|
||||
final SubtitlePreference? declinedPreference;
|
||||
|
||||
const PlaybackSubtitleSelection({
|
||||
required this.primaryTrack,
|
||||
this.primarySourceStreamId,
|
||||
@@ -53,9 +61,10 @@ class PlaybackSubtitleSelection {
|
||||
this.secondarySourceStreamId,
|
||||
this.secondarySidecar,
|
||||
this.preloadedSidecars = const [],
|
||||
this.declinedPreference,
|
||||
});
|
||||
|
||||
const PlaybackSubtitleSelection.off({this.preloadedSidecars = const []})
|
||||
const PlaybackSubtitleSelection.off({this.preloadedSidecars = const [], this.declinedPreference})
|
||||
: primaryTrack = SubtitleTrack.off,
|
||||
primarySourceStreamId = null,
|
||||
primarySidecar = null,
|
||||
@@ -192,13 +201,25 @@ class PlaybackSubtitleResolver {
|
||||
);
|
||||
final primaryResult = service.selectSubtitleTrack(availableTracks, primaryPreference, selectedAudio);
|
||||
final primary = primaryResult?.track;
|
||||
// A non-off preference that still lands on off (or resolves to a track
|
||||
// this catalog cannot back) was declined, not chosen — keep it on the
|
||||
// selection so the open flow can retry it against native tracks (#1785).
|
||||
final declinedPreference = primaryPreference != null && primaryPreference is! SubtitleOffPreference
|
||||
? primaryPreference
|
||||
: null;
|
||||
if (primary == null || primary.id == SubtitleTrack.off.id) {
|
||||
return PlaybackSubtitleSelection.off(preloadedSidecars: preloadedSidecars);
|
||||
return PlaybackSubtitleSelection.off(
|
||||
preloadedSidecars: preloadedSidecars,
|
||||
declinedPreference: declinedPreference,
|
||||
);
|
||||
}
|
||||
|
||||
final primaryCandidate = candidates.where((candidate) => candidate.track.id == primary.id).firstOrNull;
|
||||
if (primaryCandidate == null) {
|
||||
return PlaybackSubtitleSelection.off(preloadedSidecars: preloadedSidecars);
|
||||
return PlaybackSubtitleSelection.off(
|
||||
preloadedSidecars: preloadedSidecars,
|
||||
declinedPreference: declinedPreference,
|
||||
);
|
||||
}
|
||||
|
||||
_SubtitleCandidate? secondaryCandidate;
|
||||
|
||||
@@ -347,47 +347,100 @@ MediaSubtitleTrack? findPlexTrackForMpvSubtitle(
|
||||
///
|
||||
/// Identity matching ([findPlexTrackForMpvSubtitle]) answers "which row IS
|
||||
/// this track"; this answers "which row of a DIFFERENT item serves the same
|
||||
/// intent". Language and effective forced-ness are hard requirements: the
|
||||
/// intent's class is preserved or the match declines, so the selection ladder
|
||||
/// can fall back to the server's own per-item choice (#1716/#1717).
|
||||
/// intent". Effective forced-ness is a hard requirement, and so is language
|
||||
/// when both sides declare one: the intent's class is preserved or the match
|
||||
/// declines, so the selection ladder can fall back to the server's own
|
||||
/// per-item choice (#1716/#1717).
|
||||
///
|
||||
/// When language metadata is missing on either side, a unique real title
|
||||
/// match may vouch for the row instead (#1785) — untagged tracks whose only
|
||||
/// signal is a title like "Swedish" are common, and declining them turned the
|
||||
/// viewer's subtitles off on every episode advance. Codec/external parity is
|
||||
/// never sufficient evidence on its own (an arbitrary untagged row would
|
||||
/// reintroduce the #1716 wrong-track class); it only breaks ties WITHIN the
|
||||
/// title-matched set, and a residual tie declines rather than guesses.
|
||||
MediaSubtitleTrack? findSourceTrackForIntent(SubtitleIntent intent, List<MediaSubtitleTrack> sourceTracks) {
|
||||
MediaSubtitleTrack? bestMatch;
|
||||
var bestScore = -1;
|
||||
for (final row in sourceTracks) {
|
||||
if (!_languagesMatch(intent.language, row.languageCode ?? row.language)) continue;
|
||||
if (row.effectiveForced != intent.forced) continue;
|
||||
|
||||
var score = 0;
|
||||
if (_subtitleCodecsMatch(intent.codec, row.codec)) score += 5;
|
||||
score += _titleScore(intent.title, row.title, row.displayTitle);
|
||||
if (intent.isExternal == row.isExternal) score += 1;
|
||||
if (score > bestScore) {
|
||||
bestScore = score;
|
||||
bestMatch = row;
|
||||
}
|
||||
}
|
||||
return bestMatch;
|
||||
return _findTrackForIntent(
|
||||
intent,
|
||||
sourceTracks,
|
||||
isSelectable: (_) => true,
|
||||
language: (row) => row.languageCode ?? row.language,
|
||||
effectiveForced: (row) => row.effectiveForced,
|
||||
titleScore: (row) => _titleScore(intent.title, row.title, row.displayTitle),
|
||||
codec: (row) => row.codec,
|
||||
isExternal: (row) => row.isExternal,
|
||||
);
|
||||
}
|
||||
|
||||
/// Native-track twin of [findSourceTrackForIntent], for catalogs the source
|
||||
/// side cannot describe (legacy offline sidecars) and late-arriving tracks.
|
||||
SubtitleTrack? findNativeTrackForIntent(SubtitleIntent intent, List<SubtitleTrack> tracks) {
|
||||
SubtitleTrack? bestMatch;
|
||||
var bestScore = -1;
|
||||
for (final track in tracks) {
|
||||
if (track.id == SubtitleTrack.auto.id || track.id == SubtitleTrack.off.id) continue;
|
||||
if (!_languagesMatch(intent.language, track.language)) continue;
|
||||
if (track.effectiveForced != intent.forced) continue;
|
||||
return _findTrackForIntent(
|
||||
intent,
|
||||
tracks,
|
||||
isSelectable: (track) => track.id != SubtitleTrack.auto.id && track.id != SubtitleTrack.off.id,
|
||||
language: (track) => track.language,
|
||||
effectiveForced: (track) => track.effectiveForced,
|
||||
titleScore: (track) => _titleScore(intent.title, track.title, null),
|
||||
codec: (track) => track.codec,
|
||||
isExternal: (track) => track.isExternal,
|
||||
);
|
||||
}
|
||||
|
||||
/// Shared scorer behind [findSourceTrackForIntent]/[findNativeTrackForIntent].
|
||||
///
|
||||
/// Score bands keep the evidence classes strictly ordered: a language-parity
|
||||
/// match starts at 10 while a title-evidence match tops out at 9
|
||||
/// (codec 5 + title 3 + external 1), so the two can never tie and language
|
||||
/// always outranks a title coincidence.
|
||||
T? _findTrackForIntent<T extends Object>(
|
||||
SubtitleIntent intent,
|
||||
List<T> candidates, {
|
||||
required bool Function(T) isSelectable,
|
||||
required String? Function(T) language,
|
||||
required bool Function(T) effectiveForced,
|
||||
required int Function(T) titleScore,
|
||||
required String? Function(T) codec,
|
||||
required bool Function(T) isExternal,
|
||||
}) {
|
||||
T? bestMatch;
|
||||
var bestScore = -1;
|
||||
var bestIsTitleEvidence = false;
|
||||
var bestIsAmbiguous = false;
|
||||
for (final candidate in candidates) {
|
||||
if (!isSelectable(candidate)) continue;
|
||||
if (effectiveForced(candidate) != intent.forced) continue;
|
||||
|
||||
final candidateLanguage = language(candidate);
|
||||
final candidateTitleScore = titleScore(candidate);
|
||||
final hasLanguageParity = intent.language != null && candidateLanguage != null;
|
||||
var score = 0;
|
||||
if (_subtitleCodecsMatch(intent.codec, track.codec)) score += 5;
|
||||
score += _titleScore(intent.title, track.title, null);
|
||||
if (intent.isExternal == track.isExternal) score += 1;
|
||||
if (hasLanguageParity) {
|
||||
// A declared language on both sides stays authoritative: a
|
||||
// contradiction declines no matter what the title says.
|
||||
if (!_languagesMatch(intent.language, candidateLanguage)) continue;
|
||||
score += 10;
|
||||
} else if (candidateTitleScore < 3) {
|
||||
// Language evidence is missing on at least one side; only a real
|
||||
// title match may serve the intent then.
|
||||
continue;
|
||||
}
|
||||
if (_subtitleCodecsMatch(intent.codec, codec(candidate))) score += 5;
|
||||
score += candidateTitleScore;
|
||||
if (intent.isExternal == isExternal(candidate)) score += 1;
|
||||
if (score > bestScore) {
|
||||
bestScore = score;
|
||||
bestMatch = track;
|
||||
bestMatch = candidate;
|
||||
bestIsTitleEvidence = !hasLanguageParity;
|
||||
bestIsAmbiguous = false;
|
||||
} else if (score == bestScore && bestIsTitleEvidence) {
|
||||
// Only title-evidence matches can tie (their band never reaches a
|
||||
// language-parity score). Two rows the tiebreakers cannot separate
|
||||
// mean the catalog cannot say which one the viewer meant.
|
||||
bestIsAmbiguous = true;
|
||||
}
|
||||
}
|
||||
if (bestIsTitleEvidence && bestIsAmbiguous) return null;
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user