aboutsummaryrefslogtreecommitdiff
path: root/scripts/ytdlp_download.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-05-19 18:22:08 +0200
committermetamuffin <metamuffin@disroot.org>2025-05-19 18:22:08 +0200
commit78ee337ee9a0880146fd663c084e5d3de7f86c76 (patch)
tree661783e09292d82ef6f4c5243dcc9ce726d766da /scripts/ytdlp_download.ts
parent51819226e6d4eb122d70b9b1897d6ce935434998 (diff)
downloadisda-78ee337ee9a0880146fd663c084e5d3de7f86c76.tar
isda-78ee337ee9a0880146fd663c084e5d3de7f86c76.tar.bz2
isda-78ee337ee9a0880146fd663c084e5d3de7f86c76.tar.zst
central config + download profiles + filter flags + other stuff
Diffstat (limited to 'scripts/ytdlp_download.ts')
-rw-r--r--scripts/ytdlp_download.ts33
1 files changed, 18 insertions, 15 deletions
diff --git a/scripts/ytdlp_download.ts b/scripts/ytdlp_download.ts
index f82e3b8..760ac26 100644
--- a/scripts/ytdlp_download.ts
+++ b/scripts/ytdlp_download.ts
@@ -1,5 +1,7 @@
+import { Config } from "./config.ts";
const ws = new WebSocket(Deno.args[0])
+let config: Config = {} as unknown as Config
export class TextLineStream extends TransformStream<string, string> {
line = "";
@@ -28,8 +30,15 @@ function key_to_url(key: string): string {
throw new Error("unknown kind");
}
-async function do_download(key: string, output: string) {
+async function do_download(key: string, data: { [key: string]: string }) {
const url = key_to_url(key)
+
+ if (!data.output) throw new Error("no output");
+ const output = data.output as string;
+ if (!data.profile) throw new Error("no profile");
+ const args = config.ytdlp_download.profiles[data.profile as string]
+ if (!args) throw new Error(`unknown profile ${data.profile}`);
+
await Deno.mkdir(output, { recursive: true })
const child = new Deno.Command("yt-dlp", {
args: [
@@ -37,16 +46,7 @@ async function do_download(key: string, output: string) {
"--progress",
"--progress-template", "%(progress)j",
"--newline",
- "--download-archive", "archive",
- "-f", "bestvideo+bestaudio",
- "--embed-metadata",
- "--embed-thumbnail",
- "--embed-info-json",
- "--embed-subs",
- "--embed-chapters",
- "--ignore-no-formats",
- "--remux", "mkv",
- "-o", "%(id)s",
+ ...args,
url
],
stdout: "piped",
@@ -68,12 +68,15 @@ async function do_download(key: string, output: string) {
}
const status = await child.status
if (!status.success) throw new Error("download failed");
-
+ ws.send(JSON.stringify({ t: "metadata", key, data: { progress: null, status: null } }))
ws.send(JSON.stringify({ t: "complete", key }))
}
ws.onerror = () => console.error("ws error")
-ws.onclose = () => console.error("ws closed")
+ws.onclose = () => {
+ console.error("ws closed")
+ Deno.exit(1)
+}
ws.onopen = () => {
console.log("ws open");
ws.send(JSON.stringify({ t: "register", name: "yt-dlp video downloader", task_kinds: ["youtube"] }))
@@ -82,10 +85,10 @@ ws.onopen = () => {
ws.onmessage = async ev => {
if (typeof ev.data != "string") return
const p = JSON.parse(ev.data)
+ if (p.t == "config") config = p.config
if (p.t == "error") console.error(`error: ${p.message}`);
if (p.t == "work") {
- if (!p.data.output) throw new Error("no output");
- await do_download(p.key, p.data.output)
+ await do_download(p.key, p.data)
ws.send(JSON.stringify({ t: "accept" }))
}
}