Fix YouTube playback PR review issues

This commit is contained in:
2026-03-25 16:25:57 -07:00
committed by sudacode
parent c95518e94a
commit 58304757aa
7 changed files with 158 additions and 23 deletions

View File

@@ -95,16 +95,27 @@ export function createPrepareYoutubePlaybackInMpvHandler(deps: YoutubePlaybackLa
// Ignore transient path request failures and continue with bootstrap commands.
}
if (pathMatchesYoutubeTarget(previousPath, targetUrl)) {
return true;
const alreadyTarget = pathMatchesYoutubeTarget(previousPath, targetUrl);
if (alreadyTarget) {
if (!deps.requestProperty) {
return true;
}
try {
const trackList = await deps.requestProperty('track-list');
if (hasPlayableMediaTracks(trackList)) {
return true;
}
} catch {
// Keep polling; mpv can report the target path before tracks are ready.
}
} else {
deps.sendMpvCommand(['set_property', 'pause', 'yes']);
deps.sendMpvCommand(['set_property', 'sub-auto', 'no']);
deps.sendMpvCommand(['set_property', 'sid', 'no']);
deps.sendMpvCommand(['set_property', 'secondary-sid', 'no']);
deps.sendMpvCommand(['loadfile', targetUrl, 'replace']);
}
deps.sendMpvCommand(['set_property', 'pause', 'yes']);
deps.sendMpvCommand(['set_property', 'sub-auto', 'no']);
deps.sendMpvCommand(['set_property', 'sid', 'no']);
deps.sendMpvCommand(['set_property', 'secondary-sid', 'no']);
deps.sendMpvCommand(['loadfile', targetUrl, 'replace']);
const deadline = now() + timeoutMs;
while (now() < deadline) {
await deps.wait(pollIntervalMs);