Add startup, search and play timing marks plus yt-dlp duration logs

This commit is contained in:
Claude
2026-09-30 06:41:50 +00:00
parent 7b818baf8d
commit 7781e0a116
4 changed files with 32 additions and 1 deletions

View File

@@ -143,6 +143,9 @@ const CHANNEL_LIMIT = 60;
function runYtdlp(args, { signal } = {}) {
return new Promise((resolve, reject) => {
const child = spawn(YTDLP, args, { stdio: ['ignore', 'pipe', 'pipe'] });
const t0 = Date.now();
const kind = String(args.find((a) => /^ytsearch|^https?:/.test(String(a))) || args[0] || '')
.replace(/^ytsearch\d*:.*/, 'search').replace(/^https?:\/\/[^/]+\/watch.*/, 'video').slice(0, 40);
// Kill the download when the requesting client goes away — otherwise an
// aborted/retried save leaves yt-dlp running to completion (8 copies of
// one video were found pulling in parallel after the client retried).
@@ -158,6 +161,7 @@ function runYtdlp(args, { signal } = {}) {
child.stderr.on('data', (d) => { err += d; });
child.on('error', (e) => reject(new Error('yt-dlp not found: ' + e.message)));
child.on('close', (code) => {
console.log(`[ytdlp] ${kind} ${Date.now() - t0}ms ${code === 0 ? 'ok' : 'fail'}`);
if (code !== 0) reject(new Error(err.trim() || 'yt-dlp exited with code ' + code));
else resolve(out);
});