mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-11 04:19:26 -07:00
Fix launcher backend parsing and yt-dlp overrides
This commit is contained in:
@@ -48,6 +48,37 @@ async function withFakeYtDlp<T>(
|
||||
});
|
||||
}
|
||||
|
||||
async function withFakeYtDlpCommand<T>(
|
||||
payload: unknown,
|
||||
fn: () => Promise<T>,
|
||||
options: { rawScript?: boolean } = {},
|
||||
): Promise<T> {
|
||||
return await withTempDir(async (root) => {
|
||||
const binDir = path.join(root, 'bin');
|
||||
fs.mkdirSync(binDir, { recursive: true });
|
||||
makeFakeYtDlpScript(binDir, payload, options.rawScript === true);
|
||||
const originalPath = process.env.PATH;
|
||||
const originalCommand = process.env.SUBMINER_YTDLP_BIN;
|
||||
process.env.PATH = '';
|
||||
process.env.SUBMINER_YTDLP_BIN =
|
||||
process.platform === 'win32' ? path.join(binDir, 'yt-dlp.cmd') : path.join(binDir, 'yt-dlp');
|
||||
try {
|
||||
return await fn();
|
||||
} finally {
|
||||
if (originalPath === undefined) {
|
||||
delete process.env.PATH;
|
||||
} else {
|
||||
process.env.PATH = originalPath;
|
||||
}
|
||||
if (originalCommand === undefined) {
|
||||
delete process.env.SUBMINER_YTDLP_BIN;
|
||||
} else {
|
||||
process.env.SUBMINER_YTDLP_BIN = originalCommand;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
test('probeYoutubeTracks prefers srv3 over vtt for automatic captions', async () => {
|
||||
await withFakeYtDlp(
|
||||
{
|
||||
@@ -69,6 +100,28 @@ test('probeYoutubeTracks prefers srv3 over vtt for automatic captions', async ()
|
||||
);
|
||||
});
|
||||
|
||||
test('probeYoutubeTracks honors SUBMINER_YTDLP_BIN when yt-dlp is not on PATH', async () => {
|
||||
if (process.platform === 'win32') {
|
||||
return;
|
||||
}
|
||||
|
||||
await withFakeYtDlpCommand(
|
||||
{
|
||||
id: 'abc123',
|
||||
title: 'Example',
|
||||
subtitles: {
|
||||
ja: [{ ext: 'vtt', url: 'https://example.com/ja.vtt', name: 'Japanese manual' }],
|
||||
},
|
||||
},
|
||||
async () => {
|
||||
const result = await probeYoutubeTracks('https://www.youtube.com/watch?v=abc123');
|
||||
assert.equal(result.videoId, 'abc123');
|
||||
assert.equal(result.tracks[0]?.downloadUrl, 'https://example.com/ja.vtt');
|
||||
assert.equal(result.tracks[0]?.fileExtension, 'vtt');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('probeYoutubeTracks keeps preferring srt for manual captions', async () => {
|
||||
await withFakeYtDlp(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user