aboutsummaryrefslogtreecommitdiff
path: root/scripts/enqueue.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/enqueue.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/enqueue.ts')
-rw-r--r--scripts/enqueue.ts57
1 files changed, 39 insertions, 18 deletions
diff --git a/scripts/enqueue.ts b/scripts/enqueue.ts
index 8d19e53..5dfb6b7 100644
--- a/scripts/enqueue.ts
+++ b/scripts/enqueue.ts
@@ -1,38 +1,59 @@
+import { Config, EnqueueTask } from "./config.ts";
const ws = new WebSocket(Deno.args[0])
-const file = await Deno.readTextFile(Deno.args[1])
-const outdir = Deno.args.length >= 3 ? Deno.args[2] : "."
-const note_filter = Deno.args.length >= 4 ? Deno.args[3] : ""
-const requeue = Deno.env.has("REQUEUE")
+let config: Config = {} as unknown as Config
-function run_enqueue() {
- let kind = "http"
+async function run_enqueue(eqt: EnqueueTask) {
+ const file = await Deno.readTextFile(eqt.list_file)
for (const line of file.split("\n")) {
if (!line.trim().length) continue
- else if (line.startsWith("[") && line.endsWith("]"))
- kind = line.substring(1, line.length - 1)
- else {
- const [name, rest] = line.split("=", 2)
- const [id, note] = rest.split(";", 2)
- if (note_filter.length && note != note_filter) continue
- const key = `${kind}:${id}`;
- ws.send(JSON.stringify({ t: "metadata", key, data: { output: outdir + "/" + name, title: name } }))
- ws.send(JSON.stringify({ t: "enqueue", key, ignore_complete: requeue }))
- }
+ let [name, rest] = line.split("=", 2)
+ let [id, flags_raw] = rest.split(";", 2)
+ let flags = flags_raw.split(" ")
+
+ if (eqt.filter && !flags.includes(eqt.filter)) continue
+ name = name.trim()
+ id = id.trim()
+ flags = flags.filter(e => e.length && e != eqt.filter)
+
+ const key = `${eqt.kind}:${id}`;
+ ws.send(JSON.stringify({
+ t: "metadata", key, data: {
+ ...eqt.data,
+ output: (eqt.data.output ?? ".") + "/" + name,
+ title: name,
+ flags,
+ }
+ }))
+ ws.send(JSON.stringify({ t: "enqueue", key, ignore_complete: !(eqt.oneshot ?? false) }))
}
ws.send(JSON.stringify({ t: "save" }))
console.log("done");
+ setTimeout(() => run_enqueue(eqt), eqt.interval * 1000)
+}
+
+let started = false;
+function start() {
+ started = true
+ for (const t of config.enqueue)
+ run_enqueue(t)
}
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: "enqueuer", task_kinds: [] }))
- run_enqueue()
}
ws.onmessage = ev => {
if (typeof ev.data != "string") return
const p = JSON.parse(ev.data)
+ if (p.t == "config") {
+ config = p.config
+ if (!started) start()
+ }
if (p.t == "error") console.error(`error: ${p.message}`);
}