@makemidas/cli 0.1.1 → 0.3.0
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/README.md +162 -13
- package/dist/api.js +188 -3
- package/dist/args.js +324 -1
- package/dist/cli.js +304 -25
- package/dist/commands.js +520 -23
- package/dist/config.js +1 -1
- package/dist/errors.js +28 -1
- package/dist/films.js +357 -0
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -25,6 +25,7 @@ export function parse(argv) {
|
|
|
25
25
|
'frame-mode': { type: 'string' },
|
|
26
26
|
audio: { type: 'boolean', default: false },
|
|
27
27
|
'quoted-credits': { type: 'string' },
|
|
28
|
+
'max-credits': { type: 'string' },
|
|
28
29
|
out: { type: 'string', short: 'o', default: '.' },
|
|
29
30
|
'no-download': { type: 'boolean', default: false },
|
|
30
31
|
force: { type: 'boolean', default: false },
|
|
@@ -34,6 +35,38 @@ export function parse(argv) {
|
|
|
34
35
|
limit: { type: 'string', default: '20' },
|
|
35
36
|
before: { type: 'string' },
|
|
36
37
|
kind: { type: 'string' },
|
|
38
|
+
lyrics: { type: 'string' },
|
|
39
|
+
title: { type: 'string' },
|
|
40
|
+
instrumental: { type: 'boolean', default: false },
|
|
41
|
+
loop: { type: 'boolean', default: false },
|
|
42
|
+
bpm: { type: 'string' },
|
|
43
|
+
voice: { type: 'string' },
|
|
44
|
+
delivery: { type: 'string' },
|
|
45
|
+
speed: { type: 'string' },
|
|
46
|
+
stability: { type: 'string' },
|
|
47
|
+
language: { type: 'string' },
|
|
48
|
+
format: { type: 'string' },
|
|
49
|
+
scale: { type: 'string' },
|
|
50
|
+
models: { type: 'string' },
|
|
51
|
+
generation: { type: 'string' },
|
|
52
|
+
yes: { type: 'boolean', short: 'y', default: false },
|
|
53
|
+
seconds: { type: 'string' },
|
|
54
|
+
brief: { type: 'string' },
|
|
55
|
+
'text-model': { type: 'string' },
|
|
56
|
+
'video-model': { type: 'string' },
|
|
57
|
+
'frame-model': { type: 'string' },
|
|
58
|
+
'speech-model': { type: 'string' },
|
|
59
|
+
'music-model': { type: 'string' },
|
|
60
|
+
'music-prompt': { type: 'string' },
|
|
61
|
+
transition: { type: 'string' },
|
|
62
|
+
brand: { type: 'string' },
|
|
63
|
+
'clip-audio': { type: 'boolean', default: false },
|
|
64
|
+
'no-write': { type: 'boolean', default: false },
|
|
65
|
+
file: { type: 'string' },
|
|
66
|
+
pieces: { type: 'boolean', default: false },
|
|
67
|
+
character: { type: 'string' },
|
|
68
|
+
'brand-logo': { type: 'boolean', default: false },
|
|
69
|
+
q: { type: 'string' },
|
|
37
70
|
},
|
|
38
71
|
});
|
|
39
72
|
}
|
|
@@ -50,6 +83,48 @@ export function intOption(value, name, min, max) {
|
|
|
50
83
|
}
|
|
51
84
|
return n;
|
|
52
85
|
}
|
|
86
|
+
export function numberOption(value, name, min, max) {
|
|
87
|
+
if (value === undefined)
|
|
88
|
+
return undefined;
|
|
89
|
+
const n = Number(value);
|
|
90
|
+
if (!value.trim() || !Number.isFinite(n) || n < min || n > max) {
|
|
91
|
+
throw usageError(`--${name} must be a number from ${min} to ${max}.`);
|
|
92
|
+
}
|
|
93
|
+
return n;
|
|
94
|
+
}
|
|
95
|
+
/** Options set on the command line, by name (booleans only when true). */
|
|
96
|
+
function given(v, names) {
|
|
97
|
+
return names.filter((name) => {
|
|
98
|
+
const value = v[name];
|
|
99
|
+
return Array.isArray(value) ? value.length > 0 : value !== undefined && value !== false;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/** Refuse options that belong to another command. */
|
|
103
|
+
function refuse(v, names, command) {
|
|
104
|
+
const wrong = given(v, names);
|
|
105
|
+
if (wrong.length) {
|
|
106
|
+
throw usageError(`${wrong.map((name) => `--${name}`).join(', ')} ${wrong.length === 1 ? 'is' : 'are'} not for \`${command}\`.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const VISUAL_OPTIONS = [
|
|
110
|
+
'aspect',
|
|
111
|
+
'resolution',
|
|
112
|
+
'count',
|
|
113
|
+
'style',
|
|
114
|
+
'enhance',
|
|
115
|
+
'ref',
|
|
116
|
+
'frame-mode',
|
|
117
|
+
'audio',
|
|
118
|
+
'brand',
|
|
119
|
+
'brand-logo',
|
|
120
|
+
'character',
|
|
121
|
+
];
|
|
122
|
+
const MUSIC_OPTIONS = ['lyrics', 'title', 'instrumental'];
|
|
123
|
+
const SFX_OPTIONS = ['loop', 'bpm'];
|
|
124
|
+
const SPEECH_OPTIONS = ['voice', 'delivery', 'speed', 'stability', 'language'];
|
|
125
|
+
function quotedCredits(v) {
|
|
126
|
+
return intOption(v['quoted-credits'], 'quoted-credits', 0, 1_000_000);
|
|
127
|
+
}
|
|
53
128
|
/** The generation request a `makemidas image|video` command line asks for. */
|
|
54
129
|
export function generationInput(kind, prompt, v) {
|
|
55
130
|
if (!prompt?.trim()) {
|
|
@@ -58,6 +133,7 @@ export function generationInput(kind, prompt, v) {
|
|
|
58
133
|
if (kind === 'image' && (v.duration || v.audio || v['frame-mode'])) {
|
|
59
134
|
throw usageError('--duration, --audio and --frame-mode are for videos.');
|
|
60
135
|
}
|
|
136
|
+
refuse(v, [...MUSIC_OPTIONS, ...SFX_OPTIONS, ...SPEECH_OPTIONS, 'scale', 'format'], kind);
|
|
61
137
|
const input = {
|
|
62
138
|
kind,
|
|
63
139
|
prompt: prompt.trim(),
|
|
@@ -66,11 +142,19 @@ export function generationInput(kind, prompt, v) {
|
|
|
66
142
|
...(v.resolution ? { resolution: v.resolution } : {}),
|
|
67
143
|
...(v.style ? { style: v.style } : {}),
|
|
68
144
|
...(v.enhance ? { enhance: true } : {}),
|
|
145
|
+
...(v.brand ? { brandId: v.brand } : {}),
|
|
146
|
+
...(v.character ? { characterId: v.character } : {}),
|
|
69
147
|
};
|
|
148
|
+
if (v['brand-logo']) {
|
|
149
|
+
if (kind !== 'image' || !v.brand) {
|
|
150
|
+
throw usageError('--brand-logo goes with --brand on images.');
|
|
151
|
+
}
|
|
152
|
+
input.brandLogo = true;
|
|
153
|
+
}
|
|
70
154
|
const count = intOption(v.count, 'count', 1, 4);
|
|
71
155
|
if (count)
|
|
72
156
|
input.count = count;
|
|
73
|
-
const quoted =
|
|
157
|
+
const quoted = quotedCredits(v);
|
|
74
158
|
if (quoted !== undefined)
|
|
75
159
|
input.quotedCredits = quoted;
|
|
76
160
|
if (kind === 'video') {
|
|
@@ -88,3 +172,242 @@ export function generationInput(kind, prompt, v) {
|
|
|
88
172
|
}
|
|
89
173
|
return input;
|
|
90
174
|
}
|
|
175
|
+
/** The `makemidas music|sfx|speech` command each audio task is run with. */
|
|
176
|
+
export const AUDIO_COMMANDS = {
|
|
177
|
+
music: 'music',
|
|
178
|
+
sfx: 'sfx',
|
|
179
|
+
speech: 'speech',
|
|
180
|
+
};
|
|
181
|
+
/** A `makemidas music|sfx|speech` request: kind audio with its task. */
|
|
182
|
+
export function audioInput(task, prompt, v) {
|
|
183
|
+
const command = AUDIO_COMMANDS[task];
|
|
184
|
+
if (!prompt?.trim()) {
|
|
185
|
+
throw usageError(task === 'speech'
|
|
186
|
+
? 'Give the text to speak: `makemidas speech "Welcome back."`.'
|
|
187
|
+
: `Give a prompt: \`makemidas ${command} "${task === 'music' ? 'lo-fi beat for studying' : 'a door creaking open'}"\`.`);
|
|
188
|
+
}
|
|
189
|
+
const others = [...VISUAL_OPTIONS, 'scale', 'format'];
|
|
190
|
+
if (task !== 'music')
|
|
191
|
+
others.push(...MUSIC_OPTIONS);
|
|
192
|
+
if (task !== 'sfx')
|
|
193
|
+
others.push(...SFX_OPTIONS);
|
|
194
|
+
if (task !== 'speech')
|
|
195
|
+
others.push(...SPEECH_OPTIONS);
|
|
196
|
+
// Only music models list track lengths; sound effects set their own.
|
|
197
|
+
if (task !== 'music')
|
|
198
|
+
others.push('duration');
|
|
199
|
+
refuse(v, others, command);
|
|
200
|
+
const input = {
|
|
201
|
+
kind: 'audio',
|
|
202
|
+
task,
|
|
203
|
+
// A voiceover reads the text as written; prompts are trimmed.
|
|
204
|
+
prompt: task === 'speech' ? prompt : prompt.trim(),
|
|
205
|
+
...(v.model ? { model: v.model } : {}),
|
|
206
|
+
};
|
|
207
|
+
if (task === 'music') {
|
|
208
|
+
if (v.lyrics !== undefined)
|
|
209
|
+
input.lyrics = v.lyrics;
|
|
210
|
+
if (v.title !== undefined)
|
|
211
|
+
input.title = v.title;
|
|
212
|
+
if (v.instrumental)
|
|
213
|
+
input.instrumental = true;
|
|
214
|
+
if (v.lyrics !== undefined && v.instrumental) {
|
|
215
|
+
throw usageError('--lyrics and --instrumental do not go together.');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (task === 'music') {
|
|
219
|
+
const seconds = intOption(v.duration, 'duration', 1, 240);
|
|
220
|
+
if (seconds)
|
|
221
|
+
input.durationSeconds = seconds;
|
|
222
|
+
}
|
|
223
|
+
if (task === 'sfx') {
|
|
224
|
+
if (v.loop)
|
|
225
|
+
input.loop = true;
|
|
226
|
+
const bpm = intOption(v.bpm, 'bpm', 40, 240);
|
|
227
|
+
if (bpm !== undefined)
|
|
228
|
+
input.bpm = bpm;
|
|
229
|
+
}
|
|
230
|
+
if (task === 'speech') {
|
|
231
|
+
if (v.delivery !== undefined && (v.speed !== undefined || v.stability !== undefined)) {
|
|
232
|
+
throw usageError('--delivery is for Gemini TTS models, --speed and --stability for ElevenLabs models; use one or the other.');
|
|
233
|
+
}
|
|
234
|
+
if (v.voice)
|
|
235
|
+
input.voice = v.voice;
|
|
236
|
+
if (v.delivery !== undefined)
|
|
237
|
+
input.delivery = v.delivery;
|
|
238
|
+
const speed = numberOption(v.speed, 'speed', 0.7, 1.2);
|
|
239
|
+
if (speed !== undefined)
|
|
240
|
+
input.speed = speed;
|
|
241
|
+
const stability = numberOption(v.stability, 'stability', 0, 1);
|
|
242
|
+
if (stability !== undefined)
|
|
243
|
+
input.stability = stability;
|
|
244
|
+
if (v.language)
|
|
245
|
+
input.language = v.language;
|
|
246
|
+
}
|
|
247
|
+
const quoted = quotedCredits(v);
|
|
248
|
+
if (quoted !== undefined)
|
|
249
|
+
input.quotedCredits = quoted;
|
|
250
|
+
return input;
|
|
251
|
+
}
|
|
252
|
+
export const DEFAULT_TRANSCRIPTION_MODEL = 'openai/whisper-large-v2';
|
|
253
|
+
const TRANSCRIPT_FORMATS = ['txt', 'srt', 'vtt', 'json'];
|
|
254
|
+
/** The one file or link a `transcribe`/`remove-bg`/`upscale…` command takes. */
|
|
255
|
+
export function sourceArg(rest, command, what) {
|
|
256
|
+
if (rest.length !== 1 || !rest[0].trim()) {
|
|
257
|
+
throw usageError(`Give one ${what}: \`makemidas ${command} <file-or-url>\`.`);
|
|
258
|
+
}
|
|
259
|
+
return rest[0];
|
|
260
|
+
}
|
|
261
|
+
/** A `makemidas transcribe` request, without the fileId the upload returns. */
|
|
262
|
+
export function transcriptionInput(v) {
|
|
263
|
+
refuse(v, [
|
|
264
|
+
...VISUAL_OPTIONS,
|
|
265
|
+
...MUSIC_OPTIONS.filter((name) => name !== 'title'),
|
|
266
|
+
...SFX_OPTIONS,
|
|
267
|
+
...SPEECH_OPTIONS,
|
|
268
|
+
'duration',
|
|
269
|
+
'scale',
|
|
270
|
+
], 'transcribe');
|
|
271
|
+
const format = (v.format ?? 'txt').toLowerCase();
|
|
272
|
+
if (!TRANSCRIPT_FORMATS.includes(format)) {
|
|
273
|
+
throw usageError('--format must be txt, srt, vtt or json.');
|
|
274
|
+
}
|
|
275
|
+
const input = {
|
|
276
|
+
kind: 'transcription',
|
|
277
|
+
model: v.model ?? DEFAULT_TRANSCRIPTION_MODEL,
|
|
278
|
+
...(v.title !== undefined ? { title: v.title } : {}),
|
|
279
|
+
};
|
|
280
|
+
const quoted = quotedCredits(v);
|
|
281
|
+
if (quoted !== undefined)
|
|
282
|
+
input.quotedCredits = quoted;
|
|
283
|
+
return { input, format };
|
|
284
|
+
}
|
|
285
|
+
/** The `makemidas …` command that runs each edit task. */
|
|
286
|
+
export const EDIT_COMMANDS = {
|
|
287
|
+
'remove-background': 'remove-bg',
|
|
288
|
+
'upscale-image': 'upscale',
|
|
289
|
+
'upscale-video': 'upscale-video',
|
|
290
|
+
};
|
|
291
|
+
const VIDEO_UPSCALE_RESOLUTIONS = ['1080P', '2K', '4K'];
|
|
292
|
+
/** A `makemidas remove-bg|upscale|upscale-video` request (kind edit). */
|
|
293
|
+
export function editInput(task, v) {
|
|
294
|
+
const command = EDIT_COMMANDS[task];
|
|
295
|
+
const others = [
|
|
296
|
+
...VISUAL_OPTIONS.filter((name) => name !== 'resolution'),
|
|
297
|
+
...MUSIC_OPTIONS,
|
|
298
|
+
...SFX_OPTIONS,
|
|
299
|
+
...SPEECH_OPTIONS,
|
|
300
|
+
'duration',
|
|
301
|
+
'format',
|
|
302
|
+
];
|
|
303
|
+
if (task !== 'upscale-image')
|
|
304
|
+
others.push('scale');
|
|
305
|
+
if (task !== 'upscale-video')
|
|
306
|
+
others.push('resolution');
|
|
307
|
+
refuse(v, others, command);
|
|
308
|
+
const input = {
|
|
309
|
+
kind: 'edit',
|
|
310
|
+
task,
|
|
311
|
+
...(v.model ? { model: v.model } : {}),
|
|
312
|
+
};
|
|
313
|
+
if (task === 'upscale-image' && v.scale !== undefined) {
|
|
314
|
+
const scale = Number(v.scale.replace(/x$/i, ''));
|
|
315
|
+
if (![1, 2, 4, 8].includes(scale)) {
|
|
316
|
+
throw usageError('--scale must be 1, 2, 4 or 8.');
|
|
317
|
+
}
|
|
318
|
+
input.upscaleFactor = scale;
|
|
319
|
+
}
|
|
320
|
+
if (task === 'upscale-video' && v.resolution !== undefined) {
|
|
321
|
+
const resolution = v.resolution.toUpperCase();
|
|
322
|
+
if (!VIDEO_UPSCALE_RESOLUTIONS.includes(resolution)) {
|
|
323
|
+
throw usageError('--resolution must be 1080P, 2K or 4K.');
|
|
324
|
+
}
|
|
325
|
+
input.resolution = resolution;
|
|
326
|
+
}
|
|
327
|
+
const quoted = quotedCredits(v);
|
|
328
|
+
if (quoted !== undefined)
|
|
329
|
+
input.quotedCredits = quoted;
|
|
330
|
+
return input;
|
|
331
|
+
}
|
|
332
|
+
/** `--models a,b[,c,d]` for `makemidas compare`. */
|
|
333
|
+
export function compareModels(value) {
|
|
334
|
+
const models = (value ?? '')
|
|
335
|
+
.split(',')
|
|
336
|
+
.map((id) => id.trim())
|
|
337
|
+
.filter(Boolean);
|
|
338
|
+
if (models.length < 2 || models.length > 4) {
|
|
339
|
+
throw usageError('Give 2 to 4 image models: `--models a,b[,c,d]`.');
|
|
340
|
+
}
|
|
341
|
+
if (new Set(models).size !== models.length) {
|
|
342
|
+
throw usageError('--models must be different models.');
|
|
343
|
+
}
|
|
344
|
+
return models;
|
|
345
|
+
}
|
|
346
|
+
export function compareOptions(v) {
|
|
347
|
+
refuse(v, [
|
|
348
|
+
'model',
|
|
349
|
+
'resolution',
|
|
350
|
+
'count',
|
|
351
|
+
'style',
|
|
352
|
+
'enhance',
|
|
353
|
+
'frame-mode',
|
|
354
|
+
'audio',
|
|
355
|
+
'duration',
|
|
356
|
+
...MUSIC_OPTIONS,
|
|
357
|
+
...SFX_OPTIONS,
|
|
358
|
+
...SPEECH_OPTIONS,
|
|
359
|
+
'scale',
|
|
360
|
+
'format',
|
|
361
|
+
], 'compare');
|
|
362
|
+
}
|
|
363
|
+
const FEEDBACK_KINDS = ['bug', 'feature', 'praise', 'other'];
|
|
364
|
+
export function feedbackKind(value) {
|
|
365
|
+
const kind = value ?? 'other';
|
|
366
|
+
if (!FEEDBACK_KINDS.includes(kind)) {
|
|
367
|
+
throw usageError('--kind must be bug, feature, praise or other.');
|
|
368
|
+
}
|
|
369
|
+
return kind;
|
|
370
|
+
}
|
|
371
|
+
// ---------------------------------------------------------------- films
|
|
372
|
+
const TRANSITIONS = ['cut', 'fade', 'crossfade'];
|
|
373
|
+
/**
|
|
374
|
+
* Film settings from the command line. `none` turns music or the brand off;
|
|
375
|
+
* a voice of `default` uses the voiceover model's own.
|
|
376
|
+
*/
|
|
377
|
+
export function filmSettings(v) {
|
|
378
|
+
const settings = {};
|
|
379
|
+
if (v.aspect)
|
|
380
|
+
settings.aspectRatio = v.aspect;
|
|
381
|
+
if (v.resolution)
|
|
382
|
+
settings.resolution = v.resolution;
|
|
383
|
+
if (v['text-model'])
|
|
384
|
+
settings.textModel = v['text-model'];
|
|
385
|
+
if (v['video-model'])
|
|
386
|
+
settings.videoModel = v['video-model'];
|
|
387
|
+
if (v['frame-model'])
|
|
388
|
+
settings.frameModel = v['frame-model'];
|
|
389
|
+
if (v['speech-model'])
|
|
390
|
+
settings.speechModel = v['speech-model'];
|
|
391
|
+
if (v.voice)
|
|
392
|
+
settings.voice = v.voice === 'default' ? null : v.voice;
|
|
393
|
+
if (v['music-model']) {
|
|
394
|
+
settings.musicModel = v['music-model'] === 'none' ? null : v['music-model'];
|
|
395
|
+
}
|
|
396
|
+
if (v['music-prompt'])
|
|
397
|
+
settings.musicPrompt = v['music-prompt'];
|
|
398
|
+
if (v.brand)
|
|
399
|
+
settings.brandId = v.brand === 'none' ? null : v.brand;
|
|
400
|
+
if (v['clip-audio'])
|
|
401
|
+
settings.clipAudio = true;
|
|
402
|
+
if (v.transition) {
|
|
403
|
+
if (!TRANSITIONS.includes(v.transition)) {
|
|
404
|
+
throw usageError(`--transition must be ${TRANSITIONS.join(', ')}.`);
|
|
405
|
+
}
|
|
406
|
+
settings.transition = v.transition;
|
|
407
|
+
}
|
|
408
|
+
return settings;
|
|
409
|
+
}
|
|
410
|
+
/** About how long the film should be, in seconds. */
|
|
411
|
+
export function filmSeconds(v) {
|
|
412
|
+
return intOption(v.seconds, 'seconds', 10, 120);
|
|
413
|
+
}
|