UNPKG

short-video-maker

Version:

Creates short videos for TikTok, Instagram Reels, and YouTube Shorts using the Model Context Protocol (MCP) and a REST API.

82 lines (81 loc) 3.84 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /* eslint-disable @typescript-eslint/no-unused-vars */ const path_1 = __importDefault(require("path")); const fs_extra_1 = __importDefault(require("fs-extra")); const Kokoro_1 = require("./short-creator/libraries/Kokoro"); const Remotion_1 = require("./short-creator/libraries/Remotion"); const Whisper_1 = require("./short-creator/libraries/Whisper"); const FFmpeg_1 = require("./short-creator/libraries/FFmpeg"); const Pexels_1 = require("./short-creator/libraries/Pexels"); const config_1 = require("./config"); const ShortCreator_1 = require("./short-creator/ShortCreator"); const logger_1 = require("./logger"); const server_1 = require("./server/server"); const music_1 = require("./short-creator/music"); async function main() { const config = new config_1.Config(); try { config.ensureConfig(); } catch (err) { logger_1.logger.error(err, "Error in config"); process.exit(1); } const musicManager = new music_1.MusicManager(config); try { logger_1.logger.debug("checking music files"); musicManager.ensureMusicFilesExist(); } catch (error) { logger_1.logger.error(error, "Missing music files"); process.exit(1); } logger_1.logger.debug("initializing remotion"); const remotion = await Remotion_1.Remotion.init(config); logger_1.logger.debug("initializing kokoro"); const kokoro = await Kokoro_1.Kokoro.init(config.kokoroModelPrecision); logger_1.logger.debug("initializing whisper"); const whisper = await Whisper_1.Whisper.init(config); logger_1.logger.debug("initializing ffmpeg"); const ffmpeg = await FFmpeg_1.FFMpeg.init(); const pexelsApi = new Pexels_1.PexelsAPI(config.pexelsApiKey); logger_1.logger.debug("initializing the short creator"); const shortCreator = new ShortCreator_1.ShortCreator(config, remotion, kokoro, whisper, ffmpeg, pexelsApi, musicManager); if (!config.runningInDocker) { // the project is running with npm - we need to check if the installation is correct if (fs_extra_1.default.existsSync(config.installationSuccessfulPath)) { logger_1.logger.info("the installation is successful - starting the server"); } else { logger_1.logger.info("testing if the installation was successful - this may take a while..."); try { const audioBuffer = (await kokoro.generate("hi", "af_heart")).audio; await ffmpeg.createMp3DataUri(audioBuffer); await pexelsApi.findVideo(["dog"], 2.4); const testVideoPath = path_1.default.join(config.tempDirPath, "test.mp4"); await remotion.testRender(testVideoPath); fs_extra_1.default.rmSync(testVideoPath, { force: true }); fs_extra_1.default.writeFileSync(config.installationSuccessfulPath, "ok", { encoding: "utf-8", }); logger_1.logger.info("the installation was successful - starting the server"); } catch (error) { logger_1.logger.fatal(error, "The environment is not set up correctly - please follow the instructions in the README.md file https://github.com/gyoridavid/short-video-maker"); process.exit(1); } } } logger_1.logger.debug("initializing the server"); const server = new server_1.Server(config, shortCreator); const app = server.start(); // todo add shutdown handler } main().catch((error) => { logger_1.logger.error(error, "Error starting server"); });