import ffmpeg from "fluent-ffmpeg"; import { Event, getCurrentEvent, loadEvents } from "setlist"; const commandBase = ffmpeg() .input("rtsp://stream.furality.online/live/club") .seekInput("0:01") .audioCodec("copy") .videoCodec("copy") .outputOption("-y"); async function runCommand(event: Event) { const eventEnd = new Date(event.end); const now = new Date(); const secondsUntilEventEnd = Math.max( 0, Math.floor((eventEnd.getTime() - now.getTime()) / 1000) ); const command = commandBase.clone().duration(secondsUntilEventEnd); const filename = event.name.replace(/ /g, "_"); console.log(`Saving ${secondsUntilEventEnd}s of 1440p to ${filename}.mkv`); console.log(process.cwd()); command.save(`./output/${filename}.mkv`); await new Promise((res) => { // command.on("start", console.log); command.on("error", (err) => { throw err; }); command.on("end", (cmd) => { console.log(cmd); res(); }); }); console.log("Command Done"); } async function main() { while (true) { await loadEvents(); // find next const event = getCurrentEvent(); if (!event?.name) { console.error("No more sets!"); process.exit(0); } await runCommand(event); // sleep 5s await new Promise((res) => setTimeout(res, 5000)); } } main();