elm-twitch/indexify.js

38 lines
1017 B
JavaScript
Raw Permalink 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
2020-10-21 11:00:19 +02:00
function isDirectory(path) {
return fs.lstatSync(path).isDirectory();
}
2020-10-05 11:26:11 +02:00
let info = [];
for (let dir of fs.readdirSync(VIDEO_DIR)) {
2020-10-21 11:00:19 +02:00
if (!isDirectory(path.join(VIDEO_DIR, dir))) {
2020-10-08 16:33:30 +02:00
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))) {
2020-10-21 11:00:19 +02:00
if (!isDirectory(path.join(VIDEO_DIR, dir, subdir))) {
2020-10-05 11:26:11 +02:00
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