const ws = new WebSocket(Deno.args[0]) const root = Deno.args[1] async function traverse(path: string) { console.log(`> ${path}`); for await (const e of Deno.readDir(path)) { if (e.isDirectory) await traverse(path + "/" + e.name) else if (e.isFile) mark_complete(e.name) } } let counter = 0; function mark_complete(name: string) { // TODO other platforms const r = /([A-Za-z0-9-_]{11})\.mkv/g.exec(name) if (!r) return const id = r[1] counter += 1 ws.send(JSON.stringify({ t: "complete", key: `youtube:${id}`, force: true })) } ws.onerror = () => console.error("ws error") ws.onclose = () => console.error("ws closed") ws.onopen = async () => { console.log("ws open"); ws.send(JSON.stringify({ t: "register", name: "complete from files", task_kinds: [] })) await traverse(root) ws.send(JSON.stringify({ t: "save" })) console.log(`done, ${counter} tasks marked as complete`); setTimeout(() => Deno.exit(0), 200) // not sure if websockets are flushed since they're instant } ws.onmessage = ev => { if (typeof ev.data != "string") return const p = JSON.parse(ev.data) if (p.t == "config") return if (p.t == "error") console.error(`error: ${p.message}`); }