Files
plezy/lib/screens/video_player/parts/errors.dart
T
edde746 369c6279d6 fix(i18n): translate the player, downloads and server-setup text left in English
A Portuguese user reported "Skip Intro" rendering in English on Android TV.
The locale files were not the problem - all 22 were structurally complete.
skip_marker_button.dart simply never imported strings.g.dart and assigned
'Skip Intro' / 'Skip Credits' / 'Next Episode' as plain literals. An audit of
lib/ found ~120 more sites in the same state, in four shapes that need
different fixes:

A literal in a file that never imported the i18n layer is the easy one -
skip_marker_button, performance_stats, track_label_builder and codec_utils all
render text with no `t` in the file at all. TrackLabelBuilder._compose now takes
a fallbackLabel builder instead of an English fallbackPrefix, so the caller
supplies t.audioTracks.track / t.videoControls.subtitleTrack and every unnamed
audio and subtitle row in the track menus is localized.

English reaching the user through an exception message is the widest one, and
it needs care: MediaServerException.message feeds both toString() - logs and
Sentry grouping - and verbatim UI display. Localizing it in place would make
bug-report logs follow the user's locale and split one Sentry issue into 22.
The MediaServer and Seerr families instead gain a nullable `display` alongside
the English `message`, and the six screens that print these errors read
`display ?? message`. PlaybackException keeps the opposite rule, because it
already carries a PlaybackFailureReason for logic and classifyPlaybackFailure
already builds it from t.messages: its stragglers are localized at the throw
site. That also removes the literal "Exception: " prefix Live TV users saw on
a tune failure, since PlaybackException.toString() returns the bare message.

Localized parts hand-concatenated with bare English are the shape no search for
Text('...') can find: '${t.common.pause} auto-scroll' on the home carousel,
'${day} at ${time}' on the Live TV schedule row, and an actor-screen count that
hand-rolled its plural as `n == 1 ? 'title' : 'titles'` - wrong for ru and pl
regardless of translation, now a real Slang plural.

Finally a literal assigned to provider state that a widget renders later:
DownloadProgress.errorMessage, and the four background_downloader notification
bodies, which sit inside a plugin config call where no widget-shaped search
reaches them.

Two things surfaced while converting. track_chapter_controls compared a track
label against 'Audio Track N' to swap in a localized version; once the builder
localized its own fallback that branch became unreachable, so it and the
orphaned _joinTrackLabel are gone. And discovery_view's PeerError fallback arm
looks like a leak but is not - its producers already localize, and a test says
so - so it stays as it is.

All 21 non-base locales are translated, including the 21 keys left empty by
earlier commits that were falling back to English. No locale has an empty value.

scripts/check_hardcoded_strings.py guards the three shapes a structural check
can see, and runs in ci_checks.sh after translation hygiene. Its first draft
passed its own tests while missing this very bug, because 'Skip Intro' is bound
to a local rather than handed to Text(); the name-bound rule that closes that
gap is restricted to phrase-shaped literals, or it cannot tell copy from the
identifiers this codebase binds constantly ('cast_row', 'auto', 'liveTv'). It
cannot see English inside a throw or assigned to a provider field - neither is
distinguishable from a log message without dataflow analysis - and the docstring
says so. label: and actionLabel: are deliberately unscanned: here they name a
diagnostic operation, and a check that is chronically red is a check that gets
switched off.

One commit rather than one per area: the keys, the 22 locale files and the
generated output are a single unit, and any partial split fails the repo's own
unused-key scan on the way through.

close #1856
2026-08-10 15:32:43 +02:00

131 lines
5.4 KiB
Dart

part of '../../video_player_screen.dart';
extension _VideoPlayerErrorMethods on VideoPlayerScreenState {
String _safePlaybackErrorMessage(Object error) {
final raw = error.toString();
final redacted = LogRedactionManager.redact(raw);
if (raw.contains('No client registered')) {
return t.messages.errorLoading(error: t.messages.serverUnavailableForProfile);
}
return t.messages.errorLoading(error: redacted);
}
void _onPlayerError(PlayerError err) {
appLogger.e('[Player ERROR] ${err.message}');
if (!mounted || _isExiting.value) return;
// A sidecar subtitle fetch can also log a status, but it never raises the
// end-file error this handler is wired to, so a latched status belongs to
// the primary media open.
final action = resolvePlaybackFailureAction(
cause: err.cause,
fatalHttpStatuses: _fatalHttpStatuses,
isLive: widget.isLive,
liveRetrying: _live.retrying,
liveFallbackLevel: _live.fallbackLevel,
liveRetryFailed: _live.retryFailed,
);
switch (action) {
// Both dialogs are unrecoverable until the server side changes, so they
// replace the snackbar rather than joining it.
case PlaybackFailureAction.serverLimitDialog:
_hasFatalPlaybackError = true;
_progressTracker?.stopTracking();
unawaited(_showServerLimitDialog());
case PlaybackFailureAction.mediaUnreadableDialog:
_hasFatalPlaybackError = true;
_progressTracker?.stopTracking();
unawaited(_showMediaUnreadableDialog());
case PlaybackFailureAction.serverBusyDialog:
_hasFatalPlaybackError = true;
_progressTracker?.stopTracking();
unawaited(_showServerBusyDialog());
// The bounded retry operation owns errors raised while applying/opening
// its replacement stream. Do not let the same error close the route.
case PlaybackFailureAction.ignore:
return;
case PlaybackFailureAction.liveRetry:
_live.fallbackLevel++;
_live.retrying = true;
appLogger.w('Live stream failed, retrying with fallback level ${_live.fallbackLevel}');
unawaited(_retryLiveStream());
case PlaybackFailureAction.liveInterrupted:
showGlobalErrorSnackBar(t.messages.liveStreamInterrupted);
case PlaybackFailureAction.fatal:
_hasFatalPlaybackError = true;
_progressTracker?.stopTracking();
showGlobalErrorSnackBar(_redactPlayerError(_lastLogError ?? err.message));
unawaited(_handleBackButton());
}
}
void _onPlayerLog(PlayerLog log) {
final status = PlayerError.httpStatusFromLog(log.text);
if (status != null && fatalPlaybackHttpStatuses.contains(status)) _fatalHttpStatuses.add(status);
// An open the server answers with 503 never fails on its own: ffmpeg's
// reconnect loop retries 503 forever and mpv just reports buffering
// (#1830). Bound it. Live TV stays out — its ladder owns retries there.
// A sidecar subtitle fetch shares this log stream and could arm the
// watchdog too, but a first frame disarms it, so that only matters when
// the primary media is itself stuck.
if (status == 503 && !widget.isLive && !_hasRenderedFirstFrame && !_hasFatalPlaybackError) {
_http503Watchdog.onOpenPhase503();
}
if (log.level == PlayerLogLevel.error || log.level == PlayerLogLevel.fatal) {
appLogger.e('[Player LOG ERROR] [${log.prefix}] ${log.text}');
_lastLogError = _redactPlayerError(log.text.trim());
}
}
/// The open-phase 503 watchdog's deadline passed with no first frame: the
/// server is still refusing the stream. Synthesize the error the reconnect
/// loop will never raise on its own so the normal failure policy runs.
void _onOpenHttp503Persistent() {
if (!mounted || _isExiting.value || _hasRenderedFirstFrame || _hasFatalPlaybackError) return;
appLogger.w(
'Server kept answering the stream with HTTP 503 for '
'${openHttp503Patience.inSeconds}s without a first frame — giving up on this open',
);
_onPlayerError(PlayerError(t.messages.serverBusyTitle, cause: PlayerError.serverHttp503));
}
String _redactPlayerError(String message) => LogRedactionManager.redact(message);
Future<void> _showServerLimitDialog() async {
if (!mounted) return;
await showServerLimitDialog(context);
if (mounted) unawaited(_handleBackButton());
}
Future<void> _showMediaUnreadableDialog() async {
if (!mounted) return;
await showMediaUnreadableDialog(context);
if (mounted) unawaited(_handleBackButton());
}
Future<void> _showServerBusyDialog() async {
if (!mounted) return;
// The reconnect loop is still running behind the modal; pause so a server
// that recovers mid-dialog cannot start playing under it. Best-effort —
// the route is left on dialog close either way.
unawaited(player?.pause().catchError((_) {}));
await showServerBusyDialog(context);
if (mounted) unawaited(_handleBackButton());
}
/// Handle notification when native player switched from ExoPlayer to MPV
Future<void> _onBackendSwitched() async {
_playerBackendLabel = 'mpv';
_recordLifecycleState('backend_switched', action: 'mpv_fallback');
_toastController.show(
Symbols.swap_horiz_rounded,
t.messages.switchingToCompatiblePlayer,
duration: const Duration(seconds: 2),
);
await _trackManager?.onBackendSwitched();
}
}