configurable limit also up it

This commit is contained in:
Tomáš Mládek 2024-04-06 12:15:09 +02:00
parent 99d855c4d4
commit b0738d9710

View file

@ -60,6 +60,7 @@ async function processSnapshots(
videos: VideoInfo[],
snapshotsDir: string,
count: number,
sizeLimit: number,
) {
const totalDuration = videos.reduce((acc, video) => acc + video.duration, 0);
const currentHour = new Date().getHours();
@ -91,7 +92,7 @@ async function processSnapshots(
const stats = await stat(snapshotPath);
size = stats.size;
if (size < 5 * 1024) {
if (size < sizeLimit) {
logger.info(
`Snapshot ${
i + 1
@ -108,6 +109,7 @@ async function setupSnapshotServer(
videoPaths: string[],
snapshotsDir: string,
count: number,
sizeLimit: number,
) {
const app = express();
@ -116,10 +118,10 @@ async function setupSnapshotServer(
const videos = await getVideoInfo(videoPaths);
// noinspection ES6MissingAwait
processSnapshots(videos, snapshotsDir, count);
processSnapshots(videos, snapshotsDir, count, sizeLimit);
schedule.scheduleJob("0 * * * *", () =>
processSnapshots(videos, snapshotsDir, count),
processSnapshots(videos, snapshotsDir, count, sizeLimit),
);
app.get("/:magic?", async (req, res) => {
@ -171,11 +173,13 @@ program
.argument("<paths...>", "Video file paths")
.option("-d, --directory <dir>", "Directory to store snapshots", "snapshots")
.option("-c, --count <count>", "Number of snapshots to take per hour", "32")
.option("--size-limit <size>", "Size limit for snapshots in KiB", "7")
.action(async (videoPaths: string[], options) => {
await setupSnapshotServer(
videoPaths,
options.directory,
parseInt(options.count, 10),
parseInt(options.sizeLimit, 10) * 1024,
);
});