fix(mpv): stop loading the ytdl hook for media-server streams

Every URL the player opens is a media-server stream or a local file, so mpv's
bundled ytdl_hook has nothing to resolve. It still ran an on_load hook per
open and, whenever an open failed, spawned yt-dlp with the full stream URL in
its argv — access token included, readable through /proc on Linux. It also
added ~700ms to every failed open and buried the real "[stream] Failed to
open" line under three ytdl_hook errors.

mpv decides whether to load the builtin script inside mpv_initialize, so this
has to be an option set beforehand rather than a property set from Dart.
Verified against mpv 0.41: --ytdl=yes logs "Loading lua script
@ytdl_hook.lua", --ytdl=no never loads it.

Apple is deliberately excluded: the bundled libmpv is built without Lua, so
the option does not exist there and setting it would only print an mpv error
on every player init.
This commit is contained in:
edde746
2026-07-31 21:45:33 +02:00
parent 86c8011b72
commit 4fe4f7b1d7
3 changed files with 19 additions and 0 deletions
@@ -308,6 +308,12 @@ class MpvPlayerCore private constructor(
// Pause on the last frame at EOF instead of unloading the file, so a // Pause on the last frame at EOF instead of unloading the file, so a
// seek after the video ends still works (matches Linux/Windows). // seek after the video ends still works (matches Linux/Windows).
setOption("keep-open", "yes") setOption("keep-open", "yes")
// Plezy only ever opens media-server streams and local files, so
// mpv's bundled ytdl_hook has nothing to resolve: it costs an
// on_load hook per open and, on a failed open, spawns yt-dlp with
// the access token in its argv. mpv decides whether to load the
// builtin script during mpv_initialize, hence an option here.
setOption("ytdl", "no")
} }
if (displayFpsOverride != null) { if (displayFpsOverride != null) {
Log.d(TAG, "Initial display-fps-override=$displayFpsOverride") Log.d(TAG, "Initial display-fps-override=$displayFpsOverride")
+7
View File
@@ -346,6 +346,13 @@ bool MpvPlayer::Initialize() {
mpv_set_option_string(mpv_, "input-vo-keyboard", "no"); mpv_set_option_string(mpv_, "input-vo-keyboard", "no");
mpv_set_option_string(mpv_, "osc", "no"); mpv_set_option_string(mpv_, "osc", "no");
mpv_set_option_string(mpv_, "terminal", "no"); mpv_set_option_string(mpv_, "terminal", "no");
// Every URL Plezy opens is a media-server stream or a local file, never a
// site mpv's bundled ytdl_hook could resolve. Loading it costs an on_load
// hook per open and, on a failed open, spawns yt-dlp with the full stream
// URL — access token included — in its argv, where /proc exposes it. mpv
// gates loading the builtin script on this option at mpv_initialize time,
// so it has to be set here rather than from Dart.
mpv_set_option_string(mpv_, "ytdl", "no");
// Default to warn-level logging // Default to warn-level logging
mpv_request_log_messages(mpv_, "warn"); mpv_request_log_messages(mpv_, "warn");
+6
View File
@@ -570,6 +570,12 @@ bool MpvPlayer::Initialize(HWND view) {
// mpv's default handling would double-handle Play/Pause. // mpv's default handling would double-handle Play/Pause.
mpv_set_option_string(mpv_, "input-media-keys", "no"); mpv_set_option_string(mpv_, "input-media-keys", "no");
mpv_set_option_string(mpv_, "osc", "no"); mpv_set_option_string(mpv_, "osc", "no");
// Never resolve URLs through mpv's bundled ytdl_hook: Plezy only ever opens
// media-server streams and local files, the hook adds a per-open on_load
// round trip, and on a failed open it spawns yt-dlp with the access token in
// its argv. mpv decides whether to load the builtin script during
// mpv_initialize, so this must be an option, not a Dart setProperty.
mpv_set_option_string(mpv_, "ytdl", "no");
if (!audio_only_) { if (!audio_only_) {
// Let mpv use display/context detection instead of forcing HDR signaling. // Let mpv use display/context detection instead of forcing HDR signaling.