Files
ejs/tests/download.ts
Simon Sawicki 9d273740d2 Run deno fmt
2025-08-26 01:17:12 +02:00

27 lines
816 B
TypeScript

import { exists } from "@std/fs/exists";
import { players, tests } from "./tests.ts";
import { getCachePath } from "./utils.ts";
for (const test of tests) {
const variants = test.variants ?? players.keys();
for (const variant of variants) {
const path = getCachePath(test.player, variant);
if (await exists(path)) {
continue;
}
const playerPath = players.get(variant);
const url = `https://www.youtube.com/s/player/${test.player}/${playerPath}`;
console.log("Requesting", url);
const response = await fetch(url);
if (!response.ok) {
console.error(`Failed to request ${variant} player for ${test.player}`);
continue;
}
const file = await Deno.open(path, {
createNew: true,
write: true,
});
response.body!.pipeTo(file.writable);
}
}