mulmocast 1.2.67 → 1.2.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/bundle.js +41 -1
- package/lib/types/type.d.ts +15 -0
- package/package.json +1 -1
package/lib/actions/bundle.js
CHANGED
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
|
+
import { GraphAILogger } from "graphai";
|
|
3
4
|
import { listLocalizedAudioPaths } from "./audio.js";
|
|
4
5
|
import { mkdir } from "../utils/file.js";
|
|
5
6
|
import { ZipBuilder } from "../utils/zip.js";
|
|
6
7
|
import { bundleTargetLang } from "../utils/const.js";
|
|
7
8
|
import { createSilentAudio } from "../utils/ffmpeg_utils.js";
|
|
9
|
+
const downloadFile = async (url, destPath) => {
|
|
10
|
+
const response = await fetch(url);
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
throw new Error(`Failed to download file from ${url}: ${response.statusText}`);
|
|
13
|
+
}
|
|
14
|
+
const buffer = await response.arrayBuffer();
|
|
15
|
+
fs.writeFileSync(destPath, Buffer.from(buffer));
|
|
16
|
+
};
|
|
17
|
+
const processBgm = async (bgm, dir, zipper) => {
|
|
18
|
+
if (!bgm) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (bgm.kind === "path") {
|
|
22
|
+
// Local file path
|
|
23
|
+
const sourcePath = path.resolve(bgm.path);
|
|
24
|
+
if (!fs.existsSync(sourcePath)) {
|
|
25
|
+
GraphAILogger.log(`BGM file not found: ${sourcePath}`);
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const fileName = path.basename(bgm.path);
|
|
29
|
+
const destPath = path.resolve(dir, fileName);
|
|
30
|
+
fs.copyFileSync(sourcePath, destPath);
|
|
31
|
+
zipper.addFile(sourcePath, fileName);
|
|
32
|
+
return fileName;
|
|
33
|
+
}
|
|
34
|
+
else if (bgm.kind === "url") {
|
|
35
|
+
// URL download
|
|
36
|
+
const fileName = path.basename(new URL(bgm.url).pathname) || "bgm.mp3";
|
|
37
|
+
const destPath = path.resolve(dir, fileName);
|
|
38
|
+
await downloadFile(bgm.url, destPath);
|
|
39
|
+
zipper.addFile(destPath);
|
|
40
|
+
return fileName;
|
|
41
|
+
}
|
|
42
|
+
// base64 or other formats are not supported
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
8
45
|
const viewJsonFileName = "mulmo_view.json";
|
|
9
46
|
const zipFileName = "mulmo.zip";
|
|
10
47
|
const imageSourceMappings = [
|
|
@@ -78,7 +115,10 @@ export const mulmoViewerBundle = async (context) => {
|
|
|
78
115
|
}
|
|
79
116
|
});
|
|
80
117
|
});
|
|
81
|
-
|
|
118
|
+
// BGM
|
|
119
|
+
const bgmFileName = await processBgm(context.studio?.script.audioParams?.bgm, dir, zipper);
|
|
120
|
+
const bundleData = { beats: resultJson, bgmSource: bgmFileName };
|
|
121
|
+
fs.writeFileSync(path.resolve(dir, viewJsonFileName), JSON.stringify(bundleData, null, 2));
|
|
82
122
|
zipper.addFile(path.resolve(dir, viewJsonFileName));
|
|
83
123
|
if (isZip) {
|
|
84
124
|
await zipper.finalize();
|
package/lib/types/type.d.ts
CHANGED
|
@@ -134,3 +134,18 @@ export type PublicAPIArgs = {
|
|
|
134
134
|
callbacks?: CallbackFunction[];
|
|
135
135
|
};
|
|
136
136
|
export type ImageType = "image" | "movie";
|
|
137
|
+
export type MulmoViewerBeat = {
|
|
138
|
+
text?: string;
|
|
139
|
+
duration?: number;
|
|
140
|
+
multiLinguals?: Record<string, string>;
|
|
141
|
+
audioSources?: Record<string, string>;
|
|
142
|
+
imageSource?: string;
|
|
143
|
+
videoSource?: string;
|
|
144
|
+
videoWithAudioSource?: string;
|
|
145
|
+
htmlImageSource?: string;
|
|
146
|
+
soundEffectSource?: string;
|
|
147
|
+
};
|
|
148
|
+
export type MulmoViewerData = {
|
|
149
|
+
beats: MulmoViewerBeat[];
|
|
150
|
+
bgmSource?: string;
|
|
151
|
+
};
|