Spaces:
Running
Running
Commit
·
9da6ee1
1
Parent(s):
8f6108e
Fixes
Browse files- app.js +64 -54
- package.json +2 -1
- server.js +6 -6
app.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
let pl = {
|
| 16 |
onLog: console.log
|
|
@@ -24,12 +28,12 @@ function render() {
|
|
| 24 |
|
| 25 |
return new Promise((resolve, reject) => {
|
| 26 |
|
| 27 |
-
if (
|
| 28 |
-
|
| 29 |
}
|
| 30 |
const SEMIBI_MEDIA_RENDERER = "../semibit-media-render-farm"
|
| 31 |
const options = {
|
| 32 |
-
cwd:
|
| 33 |
};
|
| 34 |
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
| 35 |
var script = spawn(npmCommand, ['run', 'render-build', '--', outputFile], options);
|
|
@@ -80,13 +84,13 @@ function render() {
|
|
| 80 |
})
|
| 81 |
}
|
| 82 |
|
| 83 |
-
const db = new FireStoreDB(
|
| 84 |
|
| 85 |
function modifyFiles(originalManuscript, originalManuscriptFile) {
|
| 86 |
|
| 87 |
-
let fname =
|
| 88 |
-
let fnameTarget =
|
| 89 |
-
let SequentialSceneText =
|
| 90 |
let seqScene = "";
|
| 91 |
let script = originalManuscript.transcript
|
| 92 |
for (let index = 0; index < script.length; index++) {
|
|
@@ -96,9 +100,9 @@ function modifyFiles(originalManuscript, originalManuscriptFile) {
|
|
| 96 |
}
|
| 97 |
|
| 98 |
generateSubtitles(originalManuscript)
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
}
|
| 104 |
|
|
@@ -107,18 +111,24 @@ function generateSubtitles(originalManuscript) {
|
|
| 107 |
let transcript = originalManuscript.transcript
|
| 108 |
for (let index = 0; index < transcript.length; index++) {
|
| 109 |
const section = transcript[index];
|
|
|
|
|
|
|
|
|
|
| 110 |
section.subtitles = section.text.split(".").map(t => {
|
|
|
|
|
|
|
| 111 |
return {
|
| 112 |
-
text: t,
|
| 113 |
-
expectedDurationSec:
|
| 114 |
}
|
| 115 |
})
|
|
|
|
| 116 |
}
|
| 117 |
return originalManuscript
|
| 118 |
}
|
| 119 |
|
| 120 |
function getDurationForSentenceByPhenone(text) {
|
| 121 |
-
return
|
| 122 |
}
|
| 123 |
|
| 124 |
async function extract(filePath) {
|
|
@@ -126,13 +136,13 @@ async function extract(filePath) {
|
|
| 126 |
}
|
| 127 |
|
| 128 |
async function generateOutputBundle(jobId) {
|
| 129 |
-
let outDir =
|
| 130 |
-
let outFile =
|
| 131 |
-
let manuFile =
|
| 132 |
-
|
| 133 |
-
let outputFiles =
|
| 134 |
.map(fname => {
|
| 135 |
-
const filePath =
|
| 136 |
return filePath
|
| 137 |
})
|
| 138 |
await ZipFiles(outputFiles, outFile)
|
|
@@ -162,9 +172,9 @@ async function notify(jobId, origManu, outputUrl, bundleUrl, status, time_taken)
|
|
| 162 |
const app = express()
|
| 163 |
function clear() {
|
| 164 |
const foldersToPreserve = ['assets', 'mp3'];
|
| 165 |
-
Utils.clearFolder(
|
| 166 |
-
Utils.clearFolder(
|
| 167 |
-
Utils.clearFolder(
|
| 168 |
}
|
| 169 |
app.all('/clear', async (req, res) => {
|
| 170 |
clear()
|
|
@@ -173,7 +183,7 @@ app.all('/clear', async (req, res) => {
|
|
| 173 |
|
| 174 |
app.all('/config', (req, res) => {
|
| 175 |
res.send({
|
| 176 |
-
transitions: JSON.parse(
|
| 177 |
})
|
| 178 |
})
|
| 179 |
|
|
@@ -204,28 +214,28 @@ app.all('/render', async (req, res) => {
|
|
| 204 |
let bundleUrl = req.query.fileUrl
|
| 205 |
let skipRender = req.query.skipRender
|
| 206 |
let fileName = decodeURIComponent(Utils.getFileName(bundleUrl))
|
| 207 |
-
let filePath = req.query.filePath ||
|
| 208 |
if (bundleUrl) {
|
| 209 |
console.log('Downloading remote asset bundle from', bundleUrl)
|
| 210 |
await Utils.downloadFile(bundleUrl, filePath, true)
|
| 211 |
console.log('Downloaded remote asset bundle', 'to', filePath)
|
| 212 |
}
|
| 213 |
-
if (
|
| 214 |
await extract(filePath)
|
| 215 |
-
let manuFile =
|
| 216 |
-
if (!
|
| 217 |
res.status(400)
|
| 218 |
res.send({
|
| 219 |
message: 'The asset bundle dosent contain a original_manuscript.json at root'
|
| 220 |
})
|
| 221 |
}
|
| 222 |
-
let manuObj = JSON.parse(
|
| 223 |
currentRenderJobId = manuObj.id
|
| 224 |
let jobID = manuObj.id
|
| 225 |
modifyFiles(manuObj, manuFile)
|
| 226 |
const uploader = new FileUploader('oracle', OracleStorage.semibit_media)
|
| 227 |
if (!skipRender) {
|
| 228 |
-
Utils.clearFolder(
|
| 229 |
res.writeHead(200, jobID, {
|
| 230 |
'job_id': jobID,
|
| 231 |
'content-type': 'application/json'
|
|
@@ -306,15 +316,15 @@ app.all('/render', async (req, res) => {
|
|
| 306 |
}
|
| 307 |
})
|
| 308 |
|
| 309 |
-
app.use('/public', express.static(
|
| 310 |
-
app.use('/out', express.static(
|
| 311 |
|
| 312 |
|
| 313 |
-
const uploadDir =
|
| 314 |
const oracleAPI = OracleStorage.semibit_media.url
|
| 315 |
|
| 316 |
-
if (!
|
| 317 |
-
|
| 318 |
}
|
| 319 |
|
| 320 |
app.post('/upload', async (req, res) => {
|
|
@@ -322,15 +332,15 @@ app.post('/upload', async (req, res) => {
|
|
| 322 |
const file = req.files.file;
|
| 323 |
const uploadUrl = oracleAPI + encodeURIComponent(file.name);
|
| 324 |
|
| 325 |
-
const readStream =
|
| 326 |
-
const writeStream =
|
| 327 |
readStream.pipe(writeStream);
|
| 328 |
|
| 329 |
await new Promise((resolve) => {
|
| 330 |
writeStream.on('finish', resolve);
|
| 331 |
});
|
| 332 |
|
| 333 |
-
const fileData =
|
| 334 |
|
| 335 |
await axios.put(uploadUrl, fileData);
|
| 336 |
|
|
@@ -445,24 +455,24 @@ function doRenderPoster(jobId, statusCb) {
|
|
| 445 |
})
|
| 446 |
}
|
| 447 |
|
| 448 |
-
let indexFile =
|
| 449 |
app.get('/', (req, res) => {
|
| 450 |
res.sendFile(indexFile);
|
| 451 |
});
|
| 452 |
|
| 453 |
-
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
-
|
| 458 |
|
| 459 |
// doRender()
|
| 460 |
|
| 461 |
if (process.env.MODIFY_FILES) {
|
| 462 |
let filePath = 'public/@export_607c230fef.zip'
|
| 463 |
extract(filePath).then(() => {
|
| 464 |
-
let manuFile =
|
| 465 |
-
let manuObj = JSON.parse(
|
| 466 |
modifyFiles(manuObj, manuFile)
|
| 467 |
console.log('Sequence Generated')
|
| 468 |
})
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import stream from 'stream';
|
| 3 |
+
import bodyParser from 'body-parser';
|
| 4 |
+
import { existsSync, unlinkSync, readFileSync, writeFileSync, copyFileSync, readdirSync, mkdirSync, createReadStream, createWriteStream } from 'fs';
|
| 5 |
+
import { resolve as _resolve, join } from 'path';
|
| 6 |
+
import { Utils, FileUploader, PerformanceRecorder } from 'common-utils';
|
| 7 |
+
import { ZipFiles, UnzipFiles } from 'common-utils';
|
| 8 |
+
import OracleStorage from './common-creds/oracle/storage.json' assert { type: "json" };
|
| 9 |
+
import { spawn, exec, ChildProcess } from 'child_process';
|
| 10 |
+
import { FireStoreDB } from 'multi-db-orm';
|
| 11 |
+
import { syllableCount } from 'syllable-count-english';
|
| 12 |
+
import kill from 'tree-kill';
|
| 13 |
+
import { fileURLToPath } from 'url';
|
| 14 |
+
import { dirname } from 'path';
|
| 15 |
+
|
| 16 |
+
const __filename = fileURLToPath(import.meta.url);
|
| 17 |
+
const __dirname = dirname(__filename)
|
| 18 |
|
| 19 |
let pl = {
|
| 20 |
onLog: console.log
|
|
|
|
| 28 |
|
| 29 |
return new Promise((resolve, reject) => {
|
| 30 |
|
| 31 |
+
if (existsSync(outputFile)) {
|
| 32 |
+
unlinkSync(outputFile)
|
| 33 |
}
|
| 34 |
const SEMIBI_MEDIA_RENDERER = "../semibit-media-render-farm"
|
| 35 |
const options = {
|
| 36 |
+
cwd: _resolve(SEMIBI_MEDIA_RENDERER),
|
| 37 |
};
|
| 38 |
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
| 39 |
var script = spawn(npmCommand, ['run', 'render-build', '--', outputFile], options);
|
|
|
|
| 84 |
})
|
| 85 |
}
|
| 86 |
|
| 87 |
+
const db = new FireStoreDB(join(__dirname, 'common-creds/firebase/semibitmedia.json'))
|
| 88 |
|
| 89 |
function modifyFiles(originalManuscript, originalManuscriptFile) {
|
| 90 |
|
| 91 |
+
let fname = join(__dirname, "./src/textWithBgImage/SequentialScene.orig.tsx")
|
| 92 |
+
let fnameTarget = join(__dirname, "./src/textWithBgImage/SequentialScene.tsx")
|
| 93 |
+
let SequentialSceneText = readFileSync(fname).toString()
|
| 94 |
let seqScene = "";
|
| 95 |
let script = originalManuscript.transcript
|
| 96 |
for (let index = 0; index < script.length; index++) {
|
|
|
|
| 100 |
}
|
| 101 |
|
| 102 |
generateSubtitles(originalManuscript)
|
| 103 |
+
writeFileSync(originalManuscriptFile, JSON.stringify(originalManuscript, null, 2))
|
| 104 |
|
| 105 |
+
writeFileSync(fnameTarget, SequentialSceneText.replace("{getScene(contents[0])}", seqScene));
|
| 106 |
|
| 107 |
}
|
| 108 |
|
|
|
|
| 111 |
let transcript = originalManuscript.transcript
|
| 112 |
for (let index = 0; index < transcript.length; index++) {
|
| 113 |
const section = transcript[index];
|
| 114 |
+
section.total_syllables = getDurationForSentenceByPhenone(section.text.trim())
|
| 115 |
+
let speakerSyllablesPs = section.total_syllables / section.durationInSeconds
|
| 116 |
+
let calc = 0
|
| 117 |
section.subtitles = section.text.split(".").map(t => {
|
| 118 |
+
let c = (getDurationForSentenceByPhenone(t.trim()) / speakerSyllablesPs)
|
| 119 |
+
calc += c
|
| 120 |
return {
|
| 121 |
+
text: t.trim(),
|
| 122 |
+
expectedDurationSec: c
|
| 123 |
}
|
| 124 |
})
|
| 125 |
+
section.calculate_duration_sec = calc
|
| 126 |
}
|
| 127 |
return originalManuscript
|
| 128 |
}
|
| 129 |
|
| 130 |
function getDurationForSentenceByPhenone(text) {
|
| 131 |
+
return text.length;//syllableCount(text)
|
| 132 |
}
|
| 133 |
|
| 134 |
async function extract(filePath) {
|
|
|
|
| 136 |
}
|
| 137 |
|
| 138 |
async function generateOutputBundle(jobId) {
|
| 139 |
+
let outDir = join(__dirname, 'out')
|
| 140 |
+
let outFile = join(__dirname, 'out', `${jobId}.zip`)
|
| 141 |
+
let manuFile = join(__dirname, `public/original_manuscript.json`)
|
| 142 |
+
copyFileSync(manuFile, join(__dirname, 'out', `original_manuscript.json`))
|
| 143 |
+
let outputFiles = readdirSync(outDir)
|
| 144 |
.map(fname => {
|
| 145 |
+
const filePath = join(outDir, fname);
|
| 146 |
return filePath
|
| 147 |
})
|
| 148 |
await ZipFiles(outputFiles, outFile)
|
|
|
|
| 172 |
const app = express()
|
| 173 |
function clear() {
|
| 174 |
const foldersToPreserve = ['assets', 'mp3'];
|
| 175 |
+
Utils.clearFolder(join(__dirname, "./public"), foldersToPreserve)
|
| 176 |
+
Utils.clearFolder(join(__dirname, "./out"))
|
| 177 |
+
Utils.clearFolder(join(__dirname, "./uploads"))
|
| 178 |
}
|
| 179 |
app.all('/clear', async (req, res) => {
|
| 180 |
clear()
|
|
|
|
| 183 |
|
| 184 |
app.all('/config', (req, res) => {
|
| 185 |
res.send({
|
| 186 |
+
transitions: JSON.parse(readFileSync('public/assets/transitions.json').toString())
|
| 187 |
})
|
| 188 |
})
|
| 189 |
|
|
|
|
| 214 |
let bundleUrl = req.query.fileUrl
|
| 215 |
let skipRender = req.query.skipRender
|
| 216 |
let fileName = decodeURIComponent(Utils.getFileName(bundleUrl))
|
| 217 |
+
let filePath = req.query.filePath || join(__dirname, `public/${fileName}`)
|
| 218 |
if (bundleUrl) {
|
| 219 |
console.log('Downloading remote asset bundle from', bundleUrl)
|
| 220 |
await Utils.downloadFile(bundleUrl, filePath, true)
|
| 221 |
console.log('Downloaded remote asset bundle', 'to', filePath)
|
| 222 |
}
|
| 223 |
+
if (existsSync(filePath)) {
|
| 224 |
await extract(filePath)
|
| 225 |
+
let manuFile = join(__dirname, `public/original_manuscript.json`)
|
| 226 |
+
if (!existsSync) {
|
| 227 |
res.status(400)
|
| 228 |
res.send({
|
| 229 |
message: 'The asset bundle dosent contain a original_manuscript.json at root'
|
| 230 |
})
|
| 231 |
}
|
| 232 |
+
let manuObj = JSON.parse(readFileSync(manuFile).toString())
|
| 233 |
currentRenderJobId = manuObj.id
|
| 234 |
let jobID = manuObj.id
|
| 235 |
modifyFiles(manuObj, manuFile)
|
| 236 |
const uploader = new FileUploader('oracle', OracleStorage.semibit_media)
|
| 237 |
if (!skipRender) {
|
| 238 |
+
Utils.clearFolder(join(__dirname, 'out'))
|
| 239 |
res.writeHead(200, jobID, {
|
| 240 |
'job_id': jobID,
|
| 241 |
'content-type': 'application/json'
|
|
|
|
| 316 |
}
|
| 317 |
})
|
| 318 |
|
| 319 |
+
app.use('/public', express.static(join(__dirname, 'public')));
|
| 320 |
+
app.use('/out', express.static(join(__dirname, 'out')));
|
| 321 |
|
| 322 |
|
| 323 |
+
const uploadDir = join(__dirname, 'uploads');
|
| 324 |
const oracleAPI = OracleStorage.semibit_media.url
|
| 325 |
|
| 326 |
+
if (!existsSync(uploadDir)) {
|
| 327 |
+
mkdirSync(uploadDir);
|
| 328 |
}
|
| 329 |
|
| 330 |
app.post('/upload', async (req, res) => {
|
|
|
|
| 332 |
const file = req.files.file;
|
| 333 |
const uploadUrl = oracleAPI + encodeURIComponent(file.name);
|
| 334 |
|
| 335 |
+
const readStream = createReadStream(file.path);
|
| 336 |
+
const writeStream = createWriteStream(join(uploadDir, file.name));
|
| 337 |
readStream.pipe(writeStream);
|
| 338 |
|
| 339 |
await new Promise((resolve) => {
|
| 340 |
writeStream.on('finish', resolve);
|
| 341 |
});
|
| 342 |
|
| 343 |
+
const fileData = readFileSync(join(uploadDir, file.name));
|
| 344 |
|
| 345 |
await axios.put(uploadUrl, fileData);
|
| 346 |
|
|
|
|
| 455 |
})
|
| 456 |
}
|
| 457 |
|
| 458 |
+
let indexFile = join(__dirname, 'index.html')
|
| 459 |
app.get('/', (req, res) => {
|
| 460 |
res.sendFile(indexFile);
|
| 461 |
});
|
| 462 |
|
| 463 |
+
writeFileSync(indexFile, readFileSync(indexFile).toString().replace("___ORACLE_API_BASE___", oracleAPI))
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
+
export default app
|
| 468 |
|
| 469 |
// doRender()
|
| 470 |
|
| 471 |
if (process.env.MODIFY_FILES) {
|
| 472 |
let filePath = 'public/@export_607c230fef.zip'
|
| 473 |
extract(filePath).then(() => {
|
| 474 |
+
let manuFile = join(__dirname, 'public/original_manuscript.json')
|
| 475 |
+
let manuObj = JSON.parse(readFileSync(manuFile).toString())
|
| 476 |
modifyFiles(manuObj, manuFile)
|
| 477 |
console.log('Sequence Generated')
|
| 478 |
})
|
package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"name": "semibit-media-render-farm",
|
| 3 |
"version": "1.0.0",
|
|
|
|
| 4 |
"description": "semibit media renderer",
|
| 5 |
"sideEffects": [
|
| 6 |
"*.css"
|
|
@@ -72,4 +73,4 @@
|
|
| 72 |
"zod": "^3.21.4"
|
| 73 |
},
|
| 74 |
"packageManager": "npm@8.19.4"
|
| 75 |
-
}
|
|
|
|
| 1 |
{
|
| 2 |
"name": "semibit-media-render-farm",
|
| 3 |
"version": "1.0.0",
|
| 4 |
+
"type": "module",
|
| 5 |
"description": "semibit media renderer",
|
| 6 |
"sideEffects": [
|
| 7 |
"*.css"
|
|
|
|
| 73 |
"zod": "^3.21.4"
|
| 74 |
},
|
| 75 |
"packageManager": "npm@8.19.4"
|
| 76 |
+
}
|
server.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
-
|
| 2 |
let port = process.env.PORT || 8083
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
const server =
|
| 9 |
-
const io =
|
| 10 |
|
| 11 |
const usersSubscribedToJobs = new Map();
|
| 12 |
|
|
|
|
| 1 |
+
import app from './app.js';
|
| 2 |
let port = process.env.PORT || 8083
|
| 3 |
|
| 4 |
+
import express from 'express';
|
| 5 |
+
import { createServer } from 'http';
|
| 6 |
+
import { Server } from 'socket.io';
|
| 7 |
|
| 8 |
+
const server = createServer(app);
|
| 9 |
+
const io = new Server(server);
|
| 10 |
|
| 11 |
const usersSubscribedToJobs = new Map();
|
| 12 |
|