UNPKG

clip-creator

Version:

An open-source CLI tool for generating AI-powered video clips using FreeSound, GROQ, and Pexels. Create engaging content effortlessly with customizable features and high-quality assets.

3 lines 114 kB
#!/usr/bin/env node /*! For license information please see cli.js.LICENSE.txt */ (()=>{var t={521:t=>{t.exports={CATEGORIES:["Science & Technology","Sports & Fitness","Government & Politics","Entertainment & Celebrities","Education & Learning","Video Games & Esports","Travel & Tourism","Health & Wellness","World News","Business & Finance","Lifestyle & Culture","Art & Design","Environment & Sustainability","Food & Cooking"],TONES:["Professional/Formal","Friendly/Casual","Inspirational/Motivational","Humorous/Witty","Empathetic/Compassionate","Analytical/Data-Driven","Persuasive/Argumentative","Informative/Educational","Storytelling/Narrative","Neutral/Objective","Authoritative/Expert","Curious/Exploratory"],LEGIBLE_FONTS:["Standard","Big","Slant","Banner","ANSI Shadow","Rounded","Mini"]}},245:(t,e,r)=>{"use strict";function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(){o=function(){return e};var t,e={},r=Object.prototype,i=r.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function p(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),c=new A(n||[]);return a(i,"_invoke",{value:P(t,r,c)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=p;var d="suspendedStart",y="suspendedYield",v="executing",g="completed",m={};function w(){}function b(){}function x(){}var E={};f(E,s,(function(){return this}));var S=Object.getPrototypeOf,k=S&&S(S(F([])));k&&k!==r&&i.call(k,s)&&(E=k);var O=x.prototype=w.prototype=Object.create(E);function L(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function j(t,e){function r(o,a,c,s){var u=h(t[o],t,a);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==n(f)&&i.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,c,s)}),(function(t){r("throw",t,c,s)})):e.resolve(f).then((function(t){l.value=t,c(l)}),(function(t){return r("throw",t,c,s)}))}s(u.arg)}var o;a(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function P(e,r,n){var o=d;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var s=_(c,n);if(s){if(s===m)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===d)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var u=h(e,r,n);if("normal"===u.type){if(o=n.done?g:y,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=g,n.method="throw",n.arg=u.arg)}}}function _(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,_(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function I(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function F(e){if(e||""===e){var r=e[s];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(i.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(n(e)+" is not iterable")}return b.prototype=x,a(O,"constructor",{value:x,configurable:!0}),a(x,"constructor",{value:b,configurable:!0}),b.displayName=f(x,l,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,f(t,l,"GeneratorFunction")),t.prototype=Object.create(O),t},e.awrap=function(t){return{__await:t}},L(j.prototype),f(j.prototype,u,(function(){return this})),e.AsyncIterator=j,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new j(p(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(O),f(O,l,"Generator"),f(O,s,(function(){return this})),f(O,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=F,A.prototype={constructor:A,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var r in this)"t"===r.charAt(0)&&i.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=i.call(a,"catchLoc"),u=i.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),I(r),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:F(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},e}function i(t,e,r,n,o,i,a){try{var c=t[i](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function a(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function c(t){i(a,n,o,c,s,"next",t)}function s(t){i(a,n,o,c,s,"throw",t)}c(void 0)}))}}function c(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function s(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?c(Object(r),!0).forEach((function(e){l(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function u(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,f(n.key),n)}}function l(t,e,r){return(e=f(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function f(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}var p=r(928),h=r(896),d=r(23).promisify,y=r(203).Stream,v=r(903).v4,g=r(856),m=r(452).path,w=r(626),b=d(y.pipeline);g.setFfmpegPath(m);var x=function(){return t=function t(e){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),l(this,"CATEGORY_MAPPINGS",{"Science & Technology":["electronic futuristic","ambient digital"],"Sports & Fitness":["energetic upbeat","fast rhythmic"],"Government & Politics":["serious news","dramatic orchestral"],"Entertainment & Celebrities":["trendy upbeat","pop dance"],"Education & Learning":["calm acoustic","soft background"],"Video Games & Esports":["retro chiptune","intense cinematic"],"Travel & Tourism":["adventure nature","world upbeat"],"Health & Wellness":["meditation relaxing","calm ambient"],"World News":["news background","broadcast serious"],"Business & Finance":["corporate serious","tech background"],"Lifestyle & Culture":["lo-fi chill","smooth modern"],"Art & Design":["creative atmospheric","abstract instrumental"],"Environment & Sustainability":["nature sounds","peaceful ambient"],"Food & Cooking":["warm jazzy","cozy kitchen"]}),!e.freeSoundKey)throw new Error("FreeSound API key is required");this.config=s(s({},t.DEFAULT_CONFIG),e),this.logger=new w,this.ensureTempDirectory(),this.FREESOUND_API_URL="https://freesound.org/apiv2/search/text/"},e=[{key:"getSearchTerms",value:function(t){return this.CATEGORY_MAPPINGS[t]||["background music","cinematic instrumental"]}},{key:"ensureTempDirectory",value:function(){h.existsSync(this.config.outputDir)||h.mkdirSync(this.config.outputDir,{recursive:!0})}},{key:"getAudioDuration",value:function(t){return new Promise((function(e,r){g.ffprobe(t,(function(t,n){t?r(t):e(n.format.duration)}))}))}},{key:"applyFadeEffects",value:function(t,e,r,n){var i=this;return new Promise(function(){var c=a(o().mark((function a(c,s){var u,l;return o().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,i.getAudioDuration(t);case 2:u=o.sent,l=u-n,g(t).toFormat("mp3").audioCodec("libmp3lame").audioFrequency(44100).audioChannels(2).audioFilters(["afade=t=in:st=0:d=".concat(r),"afade=t=out:st=".concat(l,":d=").concat(n),"volume=".concat(i.config.volume)]).output(e).on("end",(function(){return c(e)})).on("error",(function(t){i.logger.error("FFmpeg error:",t.message),s(t)})).run();case 5:case"end":return o.stop()}}),a)})));return function(t,e){return c.apply(this,arguments)}}())}},{key:"generateMusic",value:(n=a(o().mark((function t(e){var r,n,i,a,c,s,u,l,f,d,y;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=3,n=0,i=this.getSearchTerms(e.category);case 3:if(!(n<r)){t.next=47;break}return t.prev=4,a=i[n]||"background music cinematic instrumental",this.logger.terminal().cyan('[INFO] 🎵 Searching for: "'.concat(a,'" (Attempt ').concat(n+1,")\n")),t.next=9,fetch("".concat(this.FREESOUND_API_URL,"?").concat(new URLSearchParams({query:a,filter:"duration:[60 TO *]",sort:"rating_desc",fields:"id,name,previews,duration,username"})),{headers:{Authorization:"Token ".concat(this.config.freeSoundKey)}});case 9:if((c=t.sent).ok){t.next=12;break}throw new Error("API request failed: ".concat(c.status));case 12:return t.next=14,c.json();case 14:if((s=t.sent).results&&0!==s.results.length){t.next=17;break}throw new Error("No results found");case 17:return u=s.results[Math.floor(Math.random()*s.results.length)],this.logger.terminal().magenta('[INFO] 🎶 Found track: "'.concat(u.name,'" by ').concat(u.username,"\n")),l=v(),f=p.join(this.config.outputDir,"".concat(l,"_raw.").concat(this.config.outputFormat)),d=p.join(this.config.outputDir,"".concat(l,".").concat(this.config.outputFormat)),this.logger.terminal().brightBlue('🎵 Downloading "'.concat(u.name,'" by ').concat(u.username,". Please wait...")),t.next=25,fetch(u.previews["preview-lq-mp3"]);case 25:if((y=t.sent).ok){t.next=28;break}throw new Error("Audio download failed: ".concat(y.status));case 28:if(y.body){t.next=30;break}throw new Error("Audio response body is empty or undefined.");case 30:return t.next=32,b(y.body,h.createWriteStream(f));case 32:return this.logger.terminal().yellow("[INFO] 🎚️ Applying FadeIn and FadeOut effects...\n"),t.next=35,this.applyFadeEffects(f,d,this.config.fadeInDuration,this.config.fadeOutDuration);case 35:return h.unlinkSync(f),t.abrupt("return",d);case 39:if(t.prev=39,t.t0=t.catch(4),this.logger.error("Attempt ".concat(n+1," failed: ").concat(t.t0.message)),!(++n>=r)){t.next=45;break}throw new Error("Max retries reached. Failed to generate music.");case 45:t.next=3;break;case 47:case"end":return t.stop()}}),t,this,[[4,39]])}))),function(t){return n.apply(this,arguments)})}],e&&u(t.prototype,e),r&&u(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,r,n}();l(x,"DEFAULT_CONFIG",{volume:.3,outputFormat:"mp3",outputDir:p.join(process.cwd(),"clip-creator-generated","audio"),fadeInDuration:2,fadeOutDuration:4}),t.exports={AudioManager:x}},925:(t,e,r)=>{"use strict";function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}var o;function i(){i=function(){return e};var t,e={},r=Object.prototype,o=r.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function p(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),c=new A(n||[]);return a(i,"_invoke",{value:P(t,r,c)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=p;var d="suspendedStart",y="suspendedYield",v="executing",g="completed",m={};function w(){}function b(){}function x(){}var E={};f(E,s,(function(){return this}));var S=Object.getPrototypeOf,k=S&&S(S(F([])));k&&k!==r&&o.call(k,s)&&(E=k);var O=x.prototype=w.prototype=Object.create(E);function L(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function j(t,e){function r(i,a,c,s){var u=h(t[i],t,a);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==n(f)&&o.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,c,s)}),(function(t){r("throw",t,c,s)})):e.resolve(f).then((function(t){l.value=t,c(l)}),(function(t){return r("throw",t,c,s)}))}s(u.arg)}var i;a(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function P(e,r,n){var o=d;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var s=_(c,n);if(s){if(s===m)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===d)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var u=h(e,r,n);if("normal"===u.type){if(o=n.done?g:y,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=g,n.method="throw",n.arg=u.arg)}}}function _(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,_(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function I(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function F(e){if(e||""===e){var r=e[s];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,a=function r(){for(;++i<e.length;)if(o.call(e,i))return r.value=e[i],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(n(e)+" is not iterable")}return b.prototype=x,a(O,"constructor",{value:x,configurable:!0}),a(x,"constructor",{value:b,configurable:!0}),b.displayName=f(x,l,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,f(t,l,"GeneratorFunction")),t.prototype=Object.create(O),t},e.awrap=function(t){return{__await:t}},L(j.prototype),f(j.prototype,u,(function(){return this})),e.AsyncIterator=j,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new j(p(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(O),f(O,l,"Generator"),f(O,s,(function(){return this})),f(O,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=F,A.prototype={constructor:A,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var r in this)"t"===r.charAt(0)&&o.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=o.call(a,"catchLoc"),u=o.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),I(r),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:F(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},e}function a(t,e,r,n,o,i,a){try{var c=t[i](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function c(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,u(n.key),n)}}function s(t,e,r){return(e=u(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}var l=r(904).Groq,f=r(626),p=r(569).z,h=p.object({id:p.number().int().positive(),text:p.string().min(10),duration:p.literal(5),description:p.string().min(5),transition:p.enum(["fade","slideLeft","slideRight","dissolve","circleWipe","pixelize","panLeft","panRight","scaleUp","scaleDown","rotate","directionalWipe"])}),d=p.object({segments:p.array(h).min(1)}),y=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),!e)throw new Error("API key is required to use the PromptGenerator");this.API_KEY=e,this.logger=new f,this.groq=r||new l({apiKey:this.API_KEY,timeout:3e4})}return e=t,r=[{key:"shouldRetry",value:function(t){return["Invalid JSON response","Empty response from model","Unexpected end of JSON input","400"].some((function(e){return t.message.includes(e)}))}},{key:"validateConfig",value:function(t){var e=["duration","category","tone"].filter((function(e){return!t[e]}));if(e.length>0)throw new Error("Missing required fields: ".concat(e.join(", ")))}},{key:"validateResponse",value:function(t){var e,r=null===(e=t.choices[0])||void 0===e||null===(e=e.message)||void 0===e||null===(e=e.content)||void 0===e?void 0:e.trim();if(!r||"{}"===r)throw new Error("Empty response from model");try{var n=JSON.parse(r),o=d.safeParse(n);if(!o.success)throw this.logger.error("Validation errors: ".concat(o.error.format())),new Error("Invalid JSON structure");return this.logger.terminal().green("[INFO] ✍️ The script from the LLM has been successfully generated.\n"),o.data}catch(t){throw this.logger.error("JSON parsing failed:",t.message),new Error("Invalid JSON response: ".concat(t.message))}}},{key:"delay",value:function(t){return new Promise((function(e){return setTimeout(e,t)}))}},{key:"generateScript",value:(o=i().mark((function e(r){var n,o,a=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>1&&void 0!==a[1]?a[1]:0,e.prev=1,this.validateConfig(r),e.next=5,this.groq.chat.completions.create({messages:[{role:"system",content:t.SYSTEM_PROMPT},{role:"user",content:t.generateUserPrompt(r)}],model:"llama3-70b-8192",temperature:1.5,max_completion_tokens:1024,stream:!1,stop:null,response_format:{type:"json_object"}});case 5:return o=e.sent,e.abrupt("return",this.validateResponse(o));case 9:if(e.prev=9,e.t0=e.catch(1),this.logger.error("Attempt ".concat(n+1," failed: ").concat(e.t0.message)),!(this.shouldRetry(e.t0)&&n<t.MAX_RETRIES)){e.next=18;break}return e.next=15,this.delay(1e3*(n+1));case 15:return e.abrupt("return",this.generateScript(r,n+1));case 18:throw new Error(t.LLM_ERROR_MESSAGE);case 19:case"end":return e.stop()}}),e,this,[[1,9]])})),s=function(){var t=this,e=arguments;return new Promise((function(r,n){var i=o.apply(t,e);function c(t){a(i,r,n,c,s,"next",t)}function s(t){a(i,r,n,c,s,"throw",t)}c(void 0)}))},function(t){return s.apply(this,arguments)})}],n=[{key:"generateUserPrompt",value:function(t){var e,r=Math.floor(t.duration/this.SEGMENT_DURATION);return"Create a ".concat(t.duration,"-second ").concat(t.category," video about: ").concat(t.topic,"\n \n Requirements:\n 1. Target audience: ").concat(t.category," viewers\n 2. Tone: ").concat(t.tone,"\n 3. Include specific visual references\n 4. Key elements: ").concat((null==t||null===(e=t.keyTerms)||void 0===e?void 0:e.join(", "))||"None provided","\n 5. Transitions: Vary between segments\n 6. Accuracy: ").concat(t.requireFactChecking?"Verify all facts":"Basic factual correctness","\n \n Output: Strict JSON format with ").concat(r," segments")}}],r&&c(e.prototype,r),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,n,o,s}();o=y,s(y,"SEGMENT_DURATION",5),s(y,"MAX_RETRIES",3),s(y,"LLM_ERROR_MESSAGE","Failed to generate valid response from AI model. Please try again later."),s(y,"SYSTEM_PROMPT","You are a professional video script writer for social media shorts. \n Generate a script with these exact requirements:\n - Exactly ".concat(o.SEGMENT_DURATION," seconds per segment\n - Structured format: [Segment X - Timestamp]\n - Fields for each segment:\n * id: Sequential number\n * text: Concise, factual on-screen text/narration (Min 10 words). Ensure the text flows logically from the previous segment and transitions seamlessly into the next.\n * duration: ").concat(o.SEGMENT_DURATION,' seconds\n * description: Visual context matching the text\n * transition: One of: "fade", "slideLeft","slideRight","dissolve", "circleWipe","pixelize","panLeft","panRight","scaleUp","scaleDown","rotate","directionalWipe"\n \n Content Guidelines:\n - When specific terms are provided: \n * Maintain factual accuracy\n * Include relevant statistics/dates\n * Contextualize importance\n - Ensure logical continuity between segments by maintaining a cohesive narrative or flow of ideas.\n - Verify all factual claims against known information\n - For political content: Maintain neutral tone\n \n Output MUST be parseable JSON with exact structure:\n {\n "segments": [\n {\n "id": 1,\n "text": "Segment text",\n "duration": 5,\n "description": "Optional visual description",\n "transition": "fade"\n }\n // Additional segments...\n ]\n }')),t.exports={PromptGenerator:y}},43:(t,e,r)=>{"use strict";function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(){o=function(){return e};var t,e={},r=Object.prototype,i=r.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function p(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),c=new A(n||[]);return a(i,"_invoke",{value:P(t,r,c)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=p;var d="suspendedStart",y="suspendedYield",v="executing",g="completed",m={};function w(){}function b(){}function x(){}var E={};f(E,s,(function(){return this}));var S=Object.getPrototypeOf,k=S&&S(S(F([])));k&&k!==r&&i.call(k,s)&&(E=k);var O=x.prototype=w.prototype=Object.create(E);function L(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function j(t,e){function r(o,a,c,s){var u=h(t[o],t,a);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==n(f)&&i.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,c,s)}),(function(t){r("throw",t,c,s)})):e.resolve(f).then((function(t){l.value=t,c(l)}),(function(t){return r("throw",t,c,s)}))}s(u.arg)}var o;a(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function P(e,r,n){var o=d;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var s=_(c,n);if(s){if(s===m)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===d)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var u=h(e,r,n);if("normal"===u.type){if(o=n.done?g:y,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=g,n.method="throw",n.arg=u.arg)}}}function _(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,_(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function I(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function F(e){if(e||""===e){var r=e[s];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(i.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(n(e)+" is not iterable")}return b.prototype=x,a(O,"constructor",{value:x,configurable:!0}),a(x,"constructor",{value:b,configurable:!0}),b.displayName=f(x,l,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,f(t,l,"GeneratorFunction")),t.prototype=Object.create(O),t},e.awrap=function(t){return{__await:t}},L(j.prototype),f(j.prototype,u,(function(){return this})),e.AsyncIterator=j,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new j(p(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(O),f(O,l,"Generator"),f(O,s,(function(){return this})),f(O,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=F,A.prototype={constructor:A,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var r in this)"t"===r.charAt(0)&&i.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=i.call(a,"catchLoc"),u=i.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),I(r),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:F(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},e}function i(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return a(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function c(t,e,r,n,o,i,a){try{var c=t[i](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function s(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){c(i,n,o,a,s,"next",t)}function s(t){c(i,n,o,a,s,"throw",t)}a(void 0)}))}}function u(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function l(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?u(Object(r),!0).forEach((function(e){p(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function f(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,h(n.key),n)}}function p(t,e,r){return(e=h(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function h(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}var d=r(452).path,y=r(856),v=r(657).createClient,g=r(928),m=r(896),w=r(903).v4,b=r(626),x=r(949);r(818).config({path:g.resolve(__dirname,"../../.env")}),y.setFfmpegPath(d);var E=function(){return t=function t(e){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=l(l({},t.DEFAULT_CONFIG),e),this.logger=new b,this.tempDir=g.join(this.config.outputDir,"temp"),!e.pexelsKey)throw new Error("Pexels API key is required to generate media-based videos");if(this.config.fps<=0||this.config.fps>60)throw new Error("Invalid FPS value: ".concat(this.config.fps));e.pexelsKey&&(this.pexelsClient=v(e.pexelsKey)),this.TRANSITION_DURATION=.5,this.TRANSITION_MAPPING={fade:"fade",dissolve:"fadeblack",slideLeft:"slideleft",slideRight:"slideright",circleWipe:"circleopen",pixelize:"pixelize"},this.ffmpegBaseOptions=["-hide_banner","-loglevel error","-y"],this.ensureDirectories()},e=[{key:"ensureDirectories",value:function(){[this.config.outputDir,this.tempDir].forEach((function(t){m.existsSync(t)||m.mkdirSync(t,{recursive:!0})}))}},{key:"generateVideo",value:(d=s(o().mark((function t(e,r){var n,a,c,s=this;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,Promise.all(e.map((function(t){return s.createSegment(t)})));case 3:return n=t.sent,t.next=6,this.combineVideosWithTransitions(n,e);case 6:return a=t.sent,c=g.join(this.config.outputDir,"final_".concat(w(),".mp4")),t.next=10,this.combineVideoAndAudio(r,a,c);case 10:return t.next=12,this.cleanup([].concat(i(n),[a]));case 12:return t.abrupt("return",c);case 15:throw t.prev=15,t.t0=t.catch(0),this.logger.error("Failed to generate video: ".concat(t.t0.message)),t.t0;case 19:case"end":return t.stop()}}),t,this,[[0,15]])}))),function(t,e){return d.apply(this,arguments)})},{key:"createSegment",value:(h=s(o().mark((function t(e){var r;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=g.join(this.tempDir,"segment_".concat(w(),".mp4")),t.abrupt("return",this.createMediaSegment(e,r));case 2:case"end":return t.stop()}}),t,this)}))),function(t){return h.apply(this,arguments)})},{key:"findSuitableVideo",value:(p=s(o().mark((function t(e){var r,n,i,a,c,s,u;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:t.prev=0,r=[e.description,e.text,"background","nature","landscape","abstract","minimalist"],n={size:"medium",per_page:15,orientation:this.config.width>=this.config.height?"landscape":"portrait"},i=0,a=r;case 4:if(!(i<a.length)){t.next=22;break}return c=a[i],t.prev=6,t.next=9,this.pexelsClient.videos.search(l({query:c},n));case 9:if(!((s=t.sent).videos&&s.videos.length>0)){t.next=14;break}if(!(u=s.videos[0].video_files.find((function(t){return"hd"===t.quality})))){t.next=14;break}return t.abrupt("return",{videoFile:u,query:c});case 14:t.next=19;break;case 16:t.prev=16,t.t0=t.catch(6),this.logger.error("Search failed for query '".concat(c,"': ").concat(t.t0.message));case 19:i++,t.next=4;break;case 22:t.next=28;break;case 24:throw t.prev=24,t.t1=t.catch(0),this.logger.error("Error while searching for query '".concat(query,"': ").concat(t.t1)),new Error("No suitable media found after multiple searches. Please try again with different parameters.");case 28:case"end":return t.stop()}}),t,this,[[0,24],[6,16]])}))),function(t){return p.apply(this,arguments)})},{key:"createMediaSegment",value:(u=s(o().mark((function t(e,r){var n,i,a,c,s,u,l,f,p,h,d=this;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,this.pexelsClient){t.next=3;break}throw new Error("Pexels client not initialized");case 3:return t.next=5,this.findSuitableVideo(e);case 5:return n=t.sent,i=n.videoFile,t.next=9,fetch(i.link);case 9:if((a=t.sent).ok){t.next=12;break}throw new Error("Failed to download video. HTTP Status: ".concat(a.status));case 12:if((c=x.fileSync({postfix:".mp4",discardDescriptor:!0})).name){t.next=15;break}throw new Error("Failed to create temporary video file");case 15:return t.next=17,a.arrayBuffer();case 17:if(s=t.sent,m.writeFileSync(c.name,Buffer.from(s)),u=Math.floor(this.config.width/(.6*this.config.fontSize)),(l=e.text).length>u&&(f=l.split(" "),p=Math.ceil(f.length/2),l="".concat(f.slice(0,p).join(" "),"\n").concat(f.slice(p).join(" "))),(h=x.fileSync({postfix:".txt",discardDescriptor:!0})).name){t.next=25;break}throw new Error("Failed to create temporary text file");case 25:return m.writeFileSync(h.name,l),t.abrupt("return",new Promise((function(t,n){try{var o=g.resolve(d.config.font);if(!o)throw new Error("Font file not found. Please check your configuration.");var i=.025*d.config.height;y(c.name).inputOptions(d.ffmpegBaseOptions).videoFilters([{filter:"drawtext",options:{textfile:h.name,fontfile:o,fontsize:d.config.fontSize||24,fontcolor:"black",box:1,boxcolor:"white@0.9",boxborderw:i,x:"(w-text_w)/2",y:"(h-text_h)/2",borderw:2,bordercolor:"black@0.2",enable:"between(t,0,".concat(e.duration,")")}}]).outputOptions(["-t ".concat(e.duration),"-c:v libx264","-preset medium","-crf 23"]).on("end",(function(){h.removeCallback(),c.removeCallback(),t(r)})).on("error",(function(t,e,r){d.logger.error("Segmentation error: ".concat(t)),d.logger.error("Ffmpeg error: ".concat(r)),h.removeCallback(),c.removeCallback(),n(new Error("FFmpeg failed: ".concat(t.message)))})).save(r)}catch(t){d.logger.error("Unexpected FFmpeg error: ".concat(t)),n(t)}})));case 29:throw t.prev=29,t.t0=t.catch(0),this.logger.error("createMediaSegment error: ".concat(t.t0)),t.t0;case 33:case"end":return t.stop()}}),t,this,[[0,29]])}))),function(t,e){return u.apply(this,arguments)})},{key:"combineVideosWithTransitions",value:(c=s(o().mark((function t(e,r){var n,i,a,c,s,u,l,f=this;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,this.logger.terminal().brightBlue("[INFO] ✂️ Combining multiple video clips with transitions...\n"),n=g.join(this.tempDir,"with_transitions_".concat(w(),".mp4")),Array.isArray(e)&&0!==e.length){t.next=5;break}throw new Error("First argument must be a non-empty array of video file paths");case 5:if(r.length===e.length){t.next=7;break}throw new Error("Transitions array length must match number of videos");case 7:if(i=y(),a="",c=0,s=this.TRANSITION_DURATION,e.forEach((function(t,e){i.input(t);var n=r[e].duration;if(a+="[".concat(e,":v]trim=duration=").concat(n,",")+"fps=fps=".concat(f.config.fps,",")+"scale=w=".concat(f.config.width,":h=").concat(f.config.height,":force_original_aspect_ratio=decrease,")+"pad=".concat(f.config.width,":").concat(f.config.height,":(ow-iw)/2:(oh-ih)/2,setsar=1,")+"format=yuv420p[vid".concat(e,"]; "),0===e)u="vid".concat(e),c=n;else{var o=r[e-1].transition||"fade",l=f.TRANSITION_MAPPING[o]||"fade",p=c-s;p<0&&(f.logger.warn("Negative offset clamped to 0 for segment ".concat(e)),p=0),a+="[".concat(u,"][vid").concat(e,"]")+"xfade=transition=".concat(l,":")+"duration=".concat(s,":")+"offset=".concat(p,"[xfade").concat(e,"]; "),u="xfade".concat(e),c+=n-s}})),a+="[".concat(u,"]format=yuv420p[outv]"),!(l=a.split("; ").filter((function(t){return""!==t.trim()}))).some((function(t){return!/^\[.+\]/.test(t)}))){t.next=16;break}throw new Error("Invalid filter syntax: "+l.join("\n"));case 16:return t.abrupt("return",new Promise((function(t,e){i.complexFilter(l,"outv").outputOptions(["-t ".concat(c),"-movflags +faststart","-c:v libx264","-r ".concat(f.config.fps)]).on("end",(function(){t(n)})).on("error",(function(t,r,n){f.logger.error("FFmpeg failed: ".concat(t.message)),f.logger.error("Error details: ".concat(n)),e(new Error("Video combining failed: ".concat(t.message)))})).save(n)})));case 19:t.prev=19,t.t0=t.catch(0),this.logger.error("Sync Error: ".concat(t.t0.message)),reject(t.t0);case 23:case"end":return t.stop()}}),t,this,[[0,19]])}))),function(t,e){return c.apply(this,arguments)})},{key:"combineVideoAndAudio",value:(a=s(o().mark((function t(e,r){var n,i,a=this,c=arguments;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=c.length>2&&void 0!==c[2]?c[2]:g.join(process.cwd(),"output.mp4"),i=function(t,e){if(null==t||!t.endsWith("video"===e?".mp4":".mp3"))throw new Error("Invalid ".concat(e," file format"));if(!m.existsSync(t))throw new Error("".concat(e," file not found"))},t.prev=2,this.logger.terminal().cyan("[INFO] 🎧 Adding the selected audio track to the video...\n"),i(e,"audio"),i(r,"video"),t.abrupt("return",new Promise((function(t,o){y().input(r).input(e).outputOptions(["-map 0:v","-map 1:a","-c:v copy","-c:a aac","-shortest","-movflags +faststart"]).on("end",(function(){t(n)})).on("error",(function(t,e,r){a.logger.error("Error mergin audio into video: ".concat(t.message)),o(new Error(["FFmpeg error: ".concat(t.message),"Stderr: ".concat(r)].join("\n")))})).save(n)})));case 9:throw t.prev=9,t.t0=t.catch(2),new Error("Combination failed: ".concat(t.t0.message));case 12:case"end":return t.stop()}}),t,this,[[2,9]])}))),function(t,e){return a.apply(this,arguments)})},{key:"cleanup",value:(n=s(o().mark((function t(e){var r=this;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Promise.all(e.map((function(t){return m.promises.unlink(t).catch((function(e){return r.logger.error("Failed to delete ".concat(t,": ").concat(e.message))}))})));case 2:case"end":return t.stop()}}),t)}))),function(t){return n.apply(this,arguments)})}],e&&f(t.prototype,e),r&&f(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,r,n,a,c,u,p,h,d}();p(E,"DEFAULT_CONFIG",{width:720,height:1280,fps:30,outputDir:g.join(process.cwd(),"clip-creator-generated"),fontSize:32,font:g.resolve(__dirname,"./assets/fonts/OpenSans-Regular.ttf")}),t.exports={VideoGenerator:E}},954:(t,e,r)=>{function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(){"use strict";o=function(){return e};var t,e={},r=Object.prototype,i=r.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function p(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),c=new A(n||[]);return a(i,"_invoke",{value:P(t,r,c)}),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=p;var d="suspendedStart",y="suspendedYield",v="executing",g="completed",m={};function w(){}function b(){}function x(){}var E={};f(E,s,(function(){return this}));var S=Object.getPrototypeOf,k=S&&S(S(F([])));k&&k!==r&&i.call(k,s)&&(E=k);var O=x.prototype=w.prototype=Object.create(E);function L(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function j(t,e){function r(o,a,c,s){var u=h(t[o],t,a);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==n(f)&&i.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,c,s)}),(function(t){r("throw",t,c,s)})):e.resolve(f).then((function(t){l.value=t,c(l)}),(function(t){return r("throw",t,c,s)}))}s(u.arg)}var o;a(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function P(e,r,n){var o=d;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var s=_(c,n);if(s){if(s===m)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===d)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var u=h(e,r,n);if("normal"===u.type){if(o=n.done?g:y,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=g,n.method="throw",n.arg=u.arg)}}}function _(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,_(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function I(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function F(e){if(e||""===e){var r=e[s];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(i.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(n(e)+" is not iterable")}return b.prototype=x,a(O,"constructor",{value:x,configurable:!0}),a(x,"constructor",{value:b,configurable:!0}),b.displayName=f(x,l,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,f(t,l,"GeneratorFunction")),t.prototype=Object.create(O),t},e.awrap=function(t){return{__await:t}},L(j.prototype),f(j.prototype,u,(function(){return this})),e.AsyncIterator=j,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new j(p(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(O),f(O,l,"Generator"),f(O,s,(function(){return this})),f(O,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for