diff options
-rw-r--r-- | scripts/ytdlp_download.ts | 41 | ||||
-rw-r--r-- | src/webui.rs | 7 |
2 files changed, 33 insertions, 15 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" })) diff --git a/src/webui.rs b/src/webui.rs index e292676..a17f53e 100644 --- a/src/webui.rs +++ b/src/webui.rs @@ -77,6 +77,9 @@ markup::define!( span.subtitle { @s } br; } span.key { @key } + @if let Some(s) = data.get("failed").and_then(Value::as_str) { + br; span.fail_reason { "Fail reason: " @s } + } @if let Some(s) = data.get("status").and_then(Value::as_str) { pre.status { @s } } @@ -114,9 +117,7 @@ fn task_class(state: TaskState, data: &Map<String, Value>) -> &'static str { match state { TaskState::Queue => "task queue", TaskState::Loading => "task loading", - TaskState::Complete if data.get("failed").and_then(Value::as_bool).unwrap_or(false) => { - "task complete-failed" - } + TaskState::Complete if data.contains_key("failed") => "task complete-failed", TaskState::Complete => "task complete", } } |