blob: f5770a278f51c6aa454bd81a0b6a37cc25e28d70 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
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 == "error") console.error(`error: ${p.message}`);
}
|