Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

fix: wait for yt-dlp output before parsing

wulien51650db28c88
diff --git a/apps/daemon/src/creator/article/source-extractor.ts b/apps/daemon/src/creator/article/source-extractor.ts
index fa3d15e9..ee1779b7 100644
--- a/apps/daemon/src/creator/article/source-extractor.ts
+++ b/apps/daemon/src/creator/article/source-extractor.ts
@@ -229,7 +229,7 @@ function runYtDlp(
child.stdout?.on('data', chunk => { stdout += String(chunk); });
child.stderr?.on('data', chunk => { stderr += String(chunk); });
child.once('error', reject);
- child.once('exit', code => {
+ child.once('close', code => {
if (code === 0 && stdout.trim()) resolve(stdout);
else reject(new CreatorExecutorError(
'creator_source_unavailable',
diff --git a/apps/daemon/src/creator/cover/executor.ts b/apps/daemon/src/creator/cover/executor.ts
index 2907aefd..4ca7b2c0 100644
--- a/apps/daemon/src/creator/cover/executor.ts
+++ b/apps/daemon/src/creator/cover/executor.ts
@@ -211,7 +211,7 @@ function runYtDlp(
for (const line of lines) reportYtDlpRetry(line, stage);
});
child.once('error', reject);
- child.once('exit', code => {
+ child.once('close', code => {
if (pendingStderr) reportYtDlpRetry(pendingStderr, stage);
if (code === 0 && stdout.trim()) {
resolve(stdout);
diff --git a/apps/daemon/src/creator/download/executor.ts b/apps/daemon/src/creator/download/executor.ts
index f6b6e5f9..c8a97ecc 100644
--- a/apps/daemon/src/creator/download/executor.ts
+++ b/apps/daemon/src/creator/download/executor.ts
@@ -866,7 +866,7 @@ function run(
settled = true;
rejectPromise(error);
});
- child.once('exit', code => {
+ child.once('close', code => {
if (settled) return;
settled = true;
if (stdoutBuffer) onLine?.(stdoutBuffer);
diff --git a/apps/desktop/test/release-runtime-regressions.test.mjs b/apps/desktop/test/release-runtime-regressions.test.mjs
index 72e595d3..f20a392d 100644
--- a/apps/desktop/test/release-runtime-regressions.test.mjs
+++ b/apps/desktop/test/release-runtime-regressions.test.mjs
@@ -137,4 +137,17 @@ describe('Desktop release runtime regressions', () => {
);
expect(source).not.toContain("join(binDir, 'yt-dlp.cmd')");
});
+
+ it('waits for yt-dlp stdio to close before parsing JSON output', () => {
+ const sources = [
+ '../../daemon/src/creator/download/executor.ts',
+ '../../daemon/src/creator/cover/executor.ts',
+ '../../daemon/src/creator/article/source-extractor.ts'
+ ].map(path => readFileSync(new URL(path, import.meta.url), 'utf8'));
+
+ for (const source of sources) {
+ expect(source).toContain("child.once('close', code => {");
+ expect(source).not.toContain("child.once('exit', code => {");
+ }
+ });
});