@coursebuilder/core
Version:
Core package for Course Builder
164 lines (159 loc) • 4.91 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/inngest/video-processing/utils.ts
var utils_exports = {};
__export(utils_exports, {
mergeSrtWithScreenshots: () => mergeSrtWithScreenshots
});
module.exports = __toCommonJS(utils_exports);
var import_srt_parser_2 = __toESM(require("srt-parser-2"), 1);
async function mergeSrtWithScreenshots(srt, muxPlaybackId) {
let parser = new import_srt_parser_2.default();
let result = parser.fromSrt(srt);
let timesWithWords = result.filter((x) => {
for (let word of triggerWords) {
if (x.text.toLowerCase().includes(word)) {
return true;
}
}
return false;
});
let timesWithWordsScreenshots = [];
let screenshotNumber = 1;
for (let time of timesWithWords) {
try {
const startTime = time.startTime.split(",")[0];
const [hours, minutes, seconds] = startTime?.split(":").map(Number);
const totalSeconds = hours * 3600 + minutes * 60 + seconds;
const muxThumbnailUrl = `https://image.mux.com/${muxPlaybackId}/thumbnail.png?width=800&height=600`;
timesWithWordsScreenshots.push({
...time,
screenshot: muxThumbnailUrl + `&time=${totalSeconds}`
});
} catch (e) {
console.log(e);
}
screenshotNumber++;
}
let resultWithScreenshots = result.map((x) => {
let found = timesWithWordsScreenshots.find((y) => y.startTime === x.startTime);
if (found) {
return {
...x,
screenshot: found.screenshot
};
}
return x;
});
let withTimes = resultWithScreenshots.map((line) => {
return {
...line,
totalSeconds: line.endSeconds - line.startSeconds
};
});
let timeLimitInSeconds = 20;
let currentTimeInSeconds = 0;
let transcribedSentencesCount = 0;
let arrayByTimes = [];
let tempArray = [];
withTimes.forEach((x, i) => {
if (currentTimeInSeconds + x.totalSeconds >= timeLimitInSeconds) {
arrayByTimes.push(tempArray);
tempArray = [];
currentTimeInSeconds = 0;
transcribedSentencesCount = 0;
}
if (currentTimeInSeconds === 0) {
if (x.screenshot) {
tempArray.push(`[${formatMdTimeString(x.startTime.split(",")[0])}] ${x.text}

`);
} else {
tempArray.push(`[${formatMdTimeString(x.startTime.split(",")[0])}] ${x.text}`);
}
} else {
if (x.screenshot) {
tempArray.push(`${x.text}

`);
} else {
tempArray.push(`${x.text}`);
}
}
currentTimeInSeconds += x.totalSeconds;
transcribedSentencesCount++;
});
arrayByTimes.push(tempArray);
let transcript = [
...arrayByTimes.map((x) => x.join(" ")).flat().join("\n\n")
].join("");
return {
transcriptWithScreenshots: transcript,
resultWithScreenshots
};
}
__name(mergeSrtWithScreenshots, "mergeSrtWithScreenshots");
function formatMdTimeString(str) {
let [h, m, s] = str.split(":");
if (h == "00") {
return `${m}:${s}`;
}
return `${h}:${m}:${s}`;
}
__name(formatMdTimeString, "formatMdTimeString");
var triggerWords = [
"here",
"have",
"there",
"this",
"that",
"see",
"these",
"look",
"show",
"watch",
"notice",
"line",
"where",
"say",
"go",
"do",
"can",
"hover",
"click",
"function",
"component",
"variable"
];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
mergeSrtWithScreenshots
});
//# sourceMappingURL=utils.cjs.map