diff options
Diffstat (limited to 'scripts/ytdlp_download.ts')
-rw-r--r-- | scripts/ytdlp_download.ts | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/scripts/ytdlp_download.ts b/scripts/ytdlp_download.ts index 184f2f5..bc9afd7 100644 --- a/scripts/ytdlp_download.ts +++ b/scripts/ytdlp_download.ts @@ -55,23 +55,40 @@ async function do_download(key: string, data: { [key: string]: string }) { url ], stdout: "piped", - stderr: "inherit", + stderr: "piped", cwd: output }).spawn() - const lines = child.stdout.pipeThrough(new TextDecoderStream()).pipeThrough(new TextLineStream()) - for await (const line of lines) { - if (!line.length) continue - const k = JSON.parse(line) - ws.send(JSON.stringify({ - t: "metadata", key, data: { - progress: (k._percent ?? 0) / 100, - status: k._default_template?.trim() ?? "" + let fail_reason = "unknown" + + Promise.all([ + (async () => { + const lines = child.stderr.pipeThrough(new TextDecoderStream()).pipeThrough(new TextLineStream()) + for await (const line of lines) { + if (!line.length) continue + if (line.includes("members-only content")) fail_reason = "members_only" + if (line.includes("Sign in to confirm") && line.includes(" not a bot")) fail_reason = "bot" + if (line.includes("Sign in to confirm your age")) fail_reason = "age_restricted" + console.error("ytdlp: " + line); } - })) - } + })(), + (async () => { + const lines = child.stdout.pipeThrough(new TextDecoderStream()).pipeThrough(new TextLineStream()) + for await (const line of lines) { + if (!line.length) continue + const k = JSON.parse(line) + ws.send(JSON.stringify({ + t: "metadata", key, data: { + progress: (k._percent ?? 0) / 100, + status: k._default_template?.trim() ?? "" + } + })) + } + })() + ]) + const status = await child.status - if (!status.success) ws.send(JSON.stringify({ t: "metadata", key, data: { failed: true } })) + if (!status.success) ws.send(JSON.stringify({ t: "metadata", key, data: { failed: fail_reason } })) ws.send(JSON.stringify({ t: "metadata", key, data: { progress: null, status: null } })) ws.send(JSON.stringify({ t: "complete", key })) ws.send(JSON.stringify({ t: "save" })) |