elm-twitch/indexify.js

34 lines
900 B
JavaScript
Raw Normal View History

2020-10-05 11:26:11 +02:00
const fs = require('fs');
const path = require('path');
const VIDEO_DIR = "videos";
const DESCRIPTION_FILE = "description.json";
2020-10-08 16:33:30 +02:00
const INDEX_FILE = "index.json";
2020-10-05 11:26:11 +02:00
let info = [];
for (let dir of fs.readdirSync(VIDEO_DIR)) {
2020-10-08 16:33:30 +02:00
if (dir === INDEX_FILE) {
continue;
}
2020-10-05 11:26:11 +02:00
let description = JSON.parse(fs.readFileSync(path.join(VIDEO_DIR, dir, DESCRIPTION_FILE)));
description.url = dir + "/";
description.videos = [];
for (let subdir of fs.readdirSync(path.join(VIDEO_DIR, dir))) {
if (subdir === DESCRIPTION_FILE) {
continue;
}
let subdescription = JSON.parse(fs.readFileSync(path.join(VIDEO_DIR, dir, subdir, DESCRIPTION_FILE)));
subdescription.url = subdir + "/";
description.videos.push(subdescription);
}
info.push(description);
}
2020-10-08 16:33:30 +02:00
fs.writeFileSync(path.join(VIDEO_DIR, INDEX_FILE), JSON.stringify(info));
2020-10-05 11:26:11 +02:00