mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-27 18:12:05 -07:00
Fix YouTube playback PR review issues
This commit is contained in:
@@ -76,6 +76,27 @@ test('mpv connection handler quits standalone youtube playback even after overla
|
||||
assert.deepEqual(calls, ['presence-refresh', 'report-stop', 'schedule', 'quit']);
|
||||
});
|
||||
|
||||
test('mpv connection handler keeps overlay-initialized non-youtube sessions alive', () => {
|
||||
const calls: string[] = [];
|
||||
const handler = createHandleMpvConnectionChangeHandler({
|
||||
reportJellyfinRemoteStopped: () => calls.push('report-stop'),
|
||||
refreshDiscordPresence: () => calls.push('presence-refresh'),
|
||||
syncOverlayMpvSubtitleSuppression: () => calls.push('sync-overlay-mpv-sub'),
|
||||
hasInitialPlaybackQuitOnDisconnectArg: () => true,
|
||||
isOverlayRuntimeInitialized: () => true,
|
||||
shouldQuitOnDisconnectWhenOverlayRuntimeInitialized: () => false,
|
||||
isQuitOnDisconnectArmed: () => true,
|
||||
scheduleQuitCheck: () => {
|
||||
calls.push('schedule');
|
||||
},
|
||||
isMpvConnected: () => false,
|
||||
quitApp: () => calls.push('quit'),
|
||||
});
|
||||
|
||||
handler({ connected: false });
|
||||
assert.deepEqual(calls, ['presence-refresh', 'report-stop']);
|
||||
});
|
||||
|
||||
test('mpv subtitle timing handler ignores blank subtitle lines', () => {
|
||||
const calls: string[] = [];
|
||||
const handler = createHandleMpvSubtitleTimingHandler({
|
||||
|
||||
@@ -36,6 +36,32 @@ test('prepare youtube playback treats matching video IDs as already loaded', asy
|
||||
assert.deepEqual(commands, []);
|
||||
});
|
||||
|
||||
test('prepare youtube playback does not mark matching target ready until tracks exist', async () => {
|
||||
const commands: Array<Array<string>> = [];
|
||||
let requestCount = 0;
|
||||
const prepare = createPrepareYoutubePlaybackInMpvHandler({
|
||||
requestPath: async () => {
|
||||
requestCount += 1;
|
||||
return 'https://www.youtube.com/watch?v=abc123';
|
||||
},
|
||||
requestProperty: async (name) => {
|
||||
if (name !== 'track-list') return null;
|
||||
return requestCount >= 3 ? [{ type: 'video', id: 1 }] : [];
|
||||
},
|
||||
sendMpvCommand: (command) => commands.push(command),
|
||||
wait: createWaitStub(),
|
||||
});
|
||||
|
||||
const ok = await prepare({
|
||||
url: 'https://www.youtube.com/watch?v=abc123',
|
||||
timeoutMs: 1500,
|
||||
pollIntervalMs: 1,
|
||||
});
|
||||
|
||||
assert.equal(ok, true);
|
||||
assert.deepEqual(commands, []);
|
||||
});
|
||||
|
||||
test('prepare youtube playback replaces media and waits for path switch', async () => {
|
||||
const commands: Array<Array<string>> = [];
|
||||
const observedPaths = [
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user