video generation working

This commit is contained in:
Quentin Roussel
2024-08-18 14:26:06 +08:00
parent 074bcf20d7
commit abaf134c28
6 changed files with 66 additions and 9 deletions

View File

@@ -30,7 +30,7 @@ function downloadImage(time_string, filepath) {
"Sec-Fetch-Dest": "image",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-origin",
"Priority": "u=5, i",
"Priority": "i",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"TE": "trailers",
@@ -61,12 +61,12 @@ function downloadImage(time_string, filepath) {
}
export async function initImages(count) {
let files = fs.readdirSync('images/');
let files = fs.readdirSync('images/raw');
let downloaded = 0;
let i = 0;
while(downloaded < count) {
let time_string = getTimeString(i);
let filename = `images/${time_string}.png`;
let filename = `images/raw/${time_string}.png`;
if (files.includes(`${time_string}.png`)) {
downloaded++;
i++;
@@ -90,7 +90,7 @@ export async function updateImages(count) {
for (let i = count; i >= 0; i--) {
time_strings.push(getTimeString(i));
}
let files = fs.readdirSync('images/');
let files = fs.readdirSync('images/raw');
let image_count = files.length;
let updated = false;
@@ -99,12 +99,11 @@ export async function updateImages(count) {
for (let time_string of time_strings) {
if (!files.includes(`${time_string}.png`)) {
try {
await downloadImage(time_string, `images/${time_string}.png`);
await downloadImage(time_string, `images/raw/${time_string}.png`);
updated = true;
image_count++;
} catch (error) {
console.log("No more images available");
break;
console.log("Skipped image " + time_string);
}
}
}
@@ -112,7 +111,7 @@ export async function updateImages(count) {
//Remove old files
for (let file of files.sort().slice(0, image_count - count)) {
console.log(`Deleting ${file}`);
fs.unlinkSync(`images/${file}`);
fs.unlinkSync(`images/raw/${file}`);
}
return updated;