"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; exports.__esModule = true; exports.GenerateScript = void 0; var transitions_json_1 = __importDefault(require("../public/assets/transitions.json")); var RenderUtils_1 = require("./RenderUtils.cjs"); var Categories_1 = require("./models/Categories.cjs"); function GenerateScript(Script) { var _a, _b, _c, _d, _e, _f; var fps = (_a = Script === null || Script === void 0 ? void 0 : Script.meta) === null || _a === void 0 ? void 0 : _a.fps; if (!fps) { Script.meta.fps = 24; fps = 24; } var durationInSec = 0; var lastDirection = false; var preloadImages = []; var preloadVideos = []; var contents = Script.transcript .sort(function (t, u) { return t.index - u.index; }) // .filter(item => (item.audioCaptionFile != undefined)) // .slice(0, 2) .map(function (section, idx, array) { section.index = section.index || idx; var text = section.text, durationMilis = section.duration, offset = section.offset, mediaAbsPaths = section.mediaAbsPaths, mediaAbsPaths = section.mediaAbsPaths, audioFullPath = section.audioFullPath, title = section.title, pointers = section.pointers; mediaAbsPaths = mediaAbsPaths || mediaAbsPaths || []; if (!durationMilis) { durationMilis = section.durationInSeconds * 1000; } if (!durationMilis) durationMilis = 10e3; // maybe required for youtube composition !!! var curDurSecs = (durationMilis / 1e3); if (curDurSecs < 3) { curDurSecs = 3; } //@ts-ignore var transitionFile = ((section === null || section === void 0 ? void 0 : section.transition_file) || transitions_json_1["default"][0].file); var transition_type = (section === null || section === void 0 ? void 0 : section.transition_type); if (transition_type && transition_type != 'none') { section.transition_duration_sec = (section === null || section === void 0 ? void 0 : section.transition_duration_sec) || 0.5; } //@ts-ignore var transitionDurationSec = ((section === null || section === void 0 ? void 0 : section.transition_duration_sec) || (transition_type && transition_type != 'none') ? 0.5 : 0); var transitionDurationFrames = transitionDurationSec * fps; var commDuration = durationInSec; //+ transitionDurationSec durationInSec = durationInSec + curDurSecs; ///+ transitionDurationSec lastDirection = !lastDirection; mediaAbsPaths.forEach(function (p) { var im = p.path; if (im.startsWith("http")) { if (im.indexOf("-video-") > -1 || im.indexOf(".mp4") > -1 || im.indexOf(".webm") > -1) { preloadVideos.push(im); // preloadVideo(im) } else { preloadImages.push(im); // preloadImage(im) } } }); var bgImagePaths = mediaAbsPaths.map(function (p) { p.path = RenderUtils_1.RenderUtils.getFileName(p === null || p === void 0 ? void 0 : p.path); return p; }); if (!offset) { offset = commDuration; } var frame = Object.assign(section, { "commulativeDurationStartSec": commDuration, "text": text, "transition_file": RenderUtils_1.RenderUtils.getFileName(transitionFile), "durationInSecs": curDurSecs, "duration": Math.ceil(curDurSecs * fps), "offset": offset * fps, "direction": lastDirection ? 'left' : 'right', "bgImagePaths": bgImagePaths, "audioPath": RenderUtils_1.RenderUtils.getFileName(audioFullPath), "textColor": '#F44336', "emphasisOnImage": (title === null || title === void 0 ? void 0 : title.length) > 0 && (pointers === null || pointers === void 0 ? void 0 : pointers.length) > 0 || Script.meta.emphasisOnImage }); return frame; }); console.log('contents', contents); var intro = { durationInFrames: 0, durationInSec: 5.433, file: Script.meta.tenantVideoConfig ? RenderUtils_1.RenderUtils.getFileName(Script.meta.tenantVideoConfig.introFile, "assets") : 'assets/music_intro.mp4' }; var ADJUST_END_DUR_SEC = 3; var outro = { durationInFrames: 0, durationInSec: 8.034 - ADJUST_END_DUR_SEC, file: Script.meta.tenantVideoConfig ? RenderUtils_1.RenderUtils.getFileName(Script.meta.tenantVideoConfig.outroFile, "assets") : 'assets/music_outro.mp4' }; if (intro && ((_c = (_b = Script === null || Script === void 0 ? void 0 : Script.meta) === null || _b === void 0 ? void 0 : _b.tenantVideoConfig) === null || _c === void 0 ? void 0 : _c.introFile)) { durationInSec += intro.durationInSec; intro.durationInFrames = Math.ceil(fps * intro.durationInSec); } if (outro && ((_e = (_d = Script === null || Script === void 0 ? void 0 : Script.meta) === null || _d === void 0 ? void 0 : _d.tenantVideoConfig) === null || _e === void 0 ? void 0 : _e.outroFile)) { durationInSec += outro.durationInSec; //hack for blank end outro.durationInSec += 30; outro.durationInFrames = Math.ceil(fps * outro.durationInSec); } // durationInSec = 10 var duration = Math.ceil(durationInSec * fps); console.log("Total Video Duration", durationInSec); //@ts-ignore var playListsIDs = Categories_1.YoutubeCategoriesConfig.GET_PLAY_LIST_IDS(((_f = Script.meta) === null || _f === void 0 ? void 0 : _f.userId) || "104349087108535511186"); return { Script: Script, contents: contents, playListsIDs: playListsIDs, duration: duration, outro: outro, intro: intro }; } exports.GenerateScript = GenerateScript;