mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-30 06:12:06 -07:00
fix: lazily resolve youtube playback socket path
This commit is contained in:
5
changes/252-youtube-playback-socket-path.md
Normal file
5
changes/252-youtube-playback-socket-path.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
type: fixed
|
||||||
|
area: main
|
||||||
|
|
||||||
|
- Resolve the YouTube playback socket path lazily so startup honors CLI and config overrides.
|
||||||
|
- Add regression coverage for the lazy socket-path lookup during Windows mpv startup.
|
||||||
@@ -1003,7 +1003,7 @@ const youtubePlaybackRuntime = createYoutubePlaybackRuntime({
|
|||||||
mpvYtdlFormat: YOUTUBE_MPV_YTDL_FORMAT,
|
mpvYtdlFormat: YOUTUBE_MPV_YTDL_FORMAT,
|
||||||
autoLaunchTimeoutMs: YOUTUBE_MPV_AUTO_LAUNCH_TIMEOUT_MS,
|
autoLaunchTimeoutMs: YOUTUBE_MPV_AUTO_LAUNCH_TIMEOUT_MS,
|
||||||
connectTimeoutMs: YOUTUBE_MPV_CONNECT_TIMEOUT_MS,
|
connectTimeoutMs: YOUTUBE_MPV_CONNECT_TIMEOUT_MS,
|
||||||
socketPath: appState.mpvSocketPath,
|
getSocketPath: () => appState.mpvSocketPath,
|
||||||
getMpvConnected: () => Boolean(appState.mpvClient?.connected),
|
getMpvConnected: () => Boolean(appState.mpvClient?.connected),
|
||||||
invalidatePendingAutoplayReadyFallbacks: () =>
|
invalidatePendingAutoplayReadyFallbacks: () =>
|
||||||
autoplayReadyGate.invalidatePendingAutoplayReadyFallbacks(),
|
autoplayReadyGate.invalidatePendingAutoplayReadyFallbacks(),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ test('youtube playback runtime resets flow ownership after a successful run', as
|
|||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
let appOwnedFlowInFlight = false;
|
let appOwnedFlowInFlight = false;
|
||||||
let timeoutCallback: (() => void) | null = null;
|
let timeoutCallback: (() => void) | null = null;
|
||||||
|
let socketPath = '/tmp/mpv.sock';
|
||||||
|
|
||||||
const runtime = createYoutubePlaybackRuntime({
|
const runtime = createYoutubePlaybackRuntime({
|
||||||
platform: 'linux',
|
platform: 'linux',
|
||||||
@@ -13,7 +14,7 @@ test('youtube playback runtime resets flow ownership after a successful run', as
|
|||||||
mpvYtdlFormat: 'bestvideo+bestaudio',
|
mpvYtdlFormat: 'bestvideo+bestaudio',
|
||||||
autoLaunchTimeoutMs: 2_000,
|
autoLaunchTimeoutMs: 2_000,
|
||||||
connectTimeoutMs: 1_000,
|
connectTimeoutMs: 1_000,
|
||||||
socketPath: '/tmp/mpv.sock',
|
getSocketPath: () => socketPath,
|
||||||
getMpvConnected: () => true,
|
getMpvConnected: () => true,
|
||||||
invalidatePendingAutoplayReadyFallbacks: () => {
|
invalidatePendingAutoplayReadyFallbacks: () => {
|
||||||
calls.push('invalidate-autoplay');
|
calls.push('invalidate-autoplay');
|
||||||
@@ -78,3 +79,70 @@ test('youtube playback runtime resets flow ownership after a successful run', as
|
|||||||
scheduledCallback();
|
scheduledCallback();
|
||||||
assert.equal(runtime.getQuitOnDisconnectArmed(), true);
|
assert.equal(runtime.getQuitOnDisconnectArmed(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('youtube playback runtime resolves the socket path lazily for windows startup', async () => {
|
||||||
|
const calls: string[] = [];
|
||||||
|
let socketPath = '/tmp/initial.sock';
|
||||||
|
|
||||||
|
const runtime = createYoutubePlaybackRuntime({
|
||||||
|
platform: 'win32',
|
||||||
|
directPlaybackFormat: 'best',
|
||||||
|
mpvYtdlFormat: 'bestvideo+bestaudio',
|
||||||
|
autoLaunchTimeoutMs: 2_000,
|
||||||
|
connectTimeoutMs: 1_000,
|
||||||
|
getSocketPath: () => socketPath,
|
||||||
|
getMpvConnected: () => false,
|
||||||
|
invalidatePendingAutoplayReadyFallbacks: () => {
|
||||||
|
calls.push('invalidate-autoplay');
|
||||||
|
},
|
||||||
|
setAppOwnedFlowInFlight: (next) => {
|
||||||
|
calls.push(`app-owned:${next}`);
|
||||||
|
},
|
||||||
|
ensureYoutubePlaybackRuntimeReady: async () => {
|
||||||
|
calls.push('ensure-runtime-ready');
|
||||||
|
},
|
||||||
|
resolveYoutubePlaybackUrl: async (url, format) => {
|
||||||
|
calls.push(`resolve:${url}:${format}`);
|
||||||
|
return 'https://example.com/direct';
|
||||||
|
},
|
||||||
|
launchWindowsMpv: (_playbackUrl, args) => {
|
||||||
|
calls.push(`launch:${args.join(' ')}`);
|
||||||
|
return { ok: true, mpvPath: '/usr/bin/mpv' };
|
||||||
|
},
|
||||||
|
waitForYoutubeMpvConnected: async (timeoutMs) => {
|
||||||
|
calls.push(`wait-connected:${timeoutMs}`);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
prepareYoutubePlaybackInMpv: async ({ url }) => {
|
||||||
|
calls.push(`prepare:${url}`);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
runYoutubePlaybackFlow: async ({ url, mode }) => {
|
||||||
|
calls.push(`run-flow:${url}:${mode}`);
|
||||||
|
},
|
||||||
|
logInfo: (message) => {
|
||||||
|
calls.push(`info:${message}`);
|
||||||
|
},
|
||||||
|
logWarn: (message) => {
|
||||||
|
calls.push(`warn:${message}`);
|
||||||
|
},
|
||||||
|
schedule: (callback) => {
|
||||||
|
calls.push('schedule-arm');
|
||||||
|
callback();
|
||||||
|
return 1 as never;
|
||||||
|
},
|
||||||
|
clearScheduled: () => {
|
||||||
|
calls.push('clear-scheduled');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
socketPath = '/tmp/updated.sock';
|
||||||
|
|
||||||
|
await runtime.runYoutubePlaybackFlow({
|
||||||
|
url: 'https://youtu.be/demo',
|
||||||
|
mode: 'download',
|
||||||
|
source: 'initial',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.ok(calls.some((entry) => entry.includes('--input-ipc-server=/tmp/updated.sock')));
|
||||||
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export type YoutubePlaybackRuntimeDeps = {
|
|||||||
mpvYtdlFormat: string;
|
mpvYtdlFormat: string;
|
||||||
autoLaunchTimeoutMs: number;
|
autoLaunchTimeoutMs: number;
|
||||||
connectTimeoutMs: number;
|
connectTimeoutMs: number;
|
||||||
socketPath: string;
|
getSocketPath: () => string;
|
||||||
getMpvConnected: () => boolean;
|
getMpvConnected: () => boolean;
|
||||||
invalidatePendingAutoplayReadyFallbacks: () => void;
|
invalidatePendingAutoplayReadyFallbacks: () => void;
|
||||||
setAppOwnedFlowInFlight: (next: boolean) => void;
|
setAppOwnedFlowInFlight: (next: boolean) => void;
|
||||||
@@ -76,6 +76,7 @@ export function createYoutubePlaybackRuntime(deps: YoutubePlaybackRuntimeDeps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (deps.platform === 'win32' && !deps.getMpvConnected()) {
|
if (deps.platform === 'win32' && !deps.getMpvConnected()) {
|
||||||
|
const socketPath = deps.getSocketPath();
|
||||||
const launchResult = deps.launchWindowsMpv(playbackUrl, [
|
const launchResult = deps.launchWindowsMpv(playbackUrl, [
|
||||||
'--pause=yes',
|
'--pause=yes',
|
||||||
'--ytdl=yes',
|
'--ytdl=yes',
|
||||||
@@ -87,7 +88,7 @@ export function createYoutubePlaybackRuntime(deps: YoutubePlaybackRuntimeDeps) {
|
|||||||
'--secondary-sub-visibility=no',
|
'--secondary-sub-visibility=no',
|
||||||
'--alang=ja,jp,jpn,japanese,en,eng,english,enus,en-us',
|
'--alang=ja,jp,jpn,japanese,en,eng,english,enus,en-us',
|
||||||
'--slang=ja,jp,jpn,japanese,en,eng,english,enus,en-us',
|
'--slang=ja,jp,jpn,japanese,en,eng,english,enus,en-us',
|
||||||
`--input-ipc-server=${deps.socketPath}`,
|
`--input-ipc-server=${socketPath}`,
|
||||||
]);
|
]);
|
||||||
launchedWindowsMpv = launchResult.ok;
|
launchedWindowsMpv = launchResult.ok;
|
||||||
if (launchResult.ok && launchResult.mpvPath) {
|
if (launchResult.ok && launchResult.mpvPath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user