diff options
author | metamuffin <metamuffin@disroot.org> | 2025-05-19 18:22:08 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-05-19 18:22:08 +0200 |
commit | 78ee337ee9a0880146fd663c084e5d3de7f86c76 (patch) | |
tree | 661783e09292d82ef6f4c5243dcc9ce726d766da /scripts/ytdlp_flatten.ts | |
parent | 51819226e6d4eb122d70b9b1897d6ce935434998 (diff) | |
download | isda-78ee337ee9a0880146fd663c084e5d3de7f86c76.tar isda-78ee337ee9a0880146fd663c084e5d3de7f86c76.tar.bz2 isda-78ee337ee9a0880146fd663c084e5d3de7f86c76.tar.zst |
central config + download profiles + filter flags + other stuff
Diffstat (limited to 'scripts/ytdlp_flatten.ts')
-rw-r--r-- | scripts/ytdlp_flatten.ts | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/scripts/ytdlp_flatten.ts b/scripts/ytdlp_flatten.ts index 84bbc8f..6d246da 100644 --- a/scripts/ytdlp_flatten.ts +++ b/scripts/ytdlp_flatten.ts @@ -1,6 +1,7 @@ +import { Config } from "./config.ts"; const ws = new WebSocket(Deno.args[0]) - +let config: Config = {} as unknown as Config function key_to_url(key: string): [string, string] { const [kind, id] = key.split(":", 2) @@ -8,13 +9,16 @@ function key_to_url(key: string): [string, string] { throw new Error("unknown kind"); } -async function flat_playlist(url: string, kind: string, output: string) { - console.log(output, url); +async function flat_playlist(url: string, kind: string, data: { [key: string]: unknown }) { + const flags = (data.flags as string[]) ?? [] + if (!(flags instanceof Array)) throw new Error("flags is not an array"); + const filter_parts = flags.map(e => config.ytdlp_flatten.filters[e]).join(" & ") + const filter_args = flags.length ? ["--match-filter", filter_parts] : [] const o = await new Deno.Command("yt-dlp", { args: [ "--flat-playlist", "--print-json", - "--match-filter", "availability=public & live_status=not_live", + ...filter_args, url ], stdout: "piped", @@ -29,11 +33,11 @@ async function flat_playlist(url: string, kind: string, output: string) { t: "metadata", key, data: { + ...data, title: ob.title, subtitle: `by ${ob.playlist_uploader}; duration ${ob.duration_string}`, - description: ob.description, thumbnail: ob.thumbnails[0]?.url, - output, + // description: ob.description, } })) ws.send(JSON.stringify({ t: "enqueue", key })) @@ -42,7 +46,10 @@ async function flat_playlist(url: string, kind: string, output: string) { } 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 playlist flattener", task_kinds: ["youtube-channel"] })) @@ -51,11 +58,12 @@ 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") { const [outkind, url] = key_to_url(p.key) if (!p.data.output) throw new Error("no output"); - await flat_playlist(url, outkind, p.data.output) + await flat_playlist(url, outkind, p.data) ws.send(JSON.stringify({ t: "complete", key: p.key })) ws.send(JSON.stringify({ t: "save" })) ws.send(JSON.stringify({ t: "accept" })) |