@makemidas/cli 0.3.1 → 0.5.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/dist/films.js CHANGED
@@ -15,7 +15,7 @@ const WORKING = new Set(['making_frames', 'making_film', 'assembling']);
15
15
  const POLL_SECONDS = { assembling: 8, other: 15 };
16
16
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
17
17
  const short = (id) => id.slice(0, 8);
18
- function need(value, what) {
18
+ export function need(value, what) {
19
19
  if (!value)
20
20
  throw new CliError(`Give ${what}.`, EXIT.USAGE, 'usage');
21
21
  return value;
@@ -64,24 +64,35 @@ export function nextHint(film) {
64
64
  }
65
65
  /** A project as a few lines of text. */
66
66
  export function describeFilm(film) {
67
+ const style = film.settings?.style === 'social' ? ' · social video' : '';
67
68
  const lines = [
68
- `${film.title} (${film.id}) · ${film.stage} · ${film.shots.length} shot${film.shots.length === 1 ? '' : 's'} · ${film.seconds} s`,
69
+ `${film.title} (${film.id}) · ${film.stage} · ${film.shots.length} shot${film.shots.length === 1 ? '' : 's'} · ${film.seconds} s${style}`,
69
70
  ];
71
+ if (film.titleCard)
72
+ lines.push(` ${pieceMark('title card', film.titleCard)}`);
70
73
  for (const shot of film.shots) {
74
+ const talking = shot.type === 'talking';
71
75
  const parts = [
72
76
  pieceMark('frame', shot.frame),
73
- pieceMark('clip', shot.clip),
74
77
  ...(shot.voiceover ? [pieceMark('voice', shot.voice)] : []),
78
+ pieceMark(talking ? 'avatar' : 'clip', shot.clip),
75
79
  ].join(' ');
76
- lines.push(` ${shot.position + 1}. ${shot.duration}s [${parts}] ${shot.description || shot.prompt.slice(0, 80)}`);
80
+ lines.push(` ${shot.position + 1}. ${shot.seconds ?? shot.duration}s [${parts}] ${talking ? '(talking) ' : ''}${shot.description || shot.prompt.slice(0, 80)}`);
77
81
  if (shot.error)
78
82
  lines.push(` error: ${shot.error}`);
79
83
  }
84
+ if (film.endCard)
85
+ lines.push(` ${pieceMark('end card', film.endCard)}`);
80
86
  if (film.assembly?.status === 'failed') {
81
87
  lines.push(` assembly failed: ${film.assembly.error ?? 'unknown error'}`);
82
88
  }
83
89
  if (film.filmUrl)
84
90
  lines.push(` film: ${film.filmUrl}`);
91
+ if (film.subtitlesUrl)
92
+ lines.push(` subtitles: ${film.subtitlesUrl}`);
93
+ if (film.share) {
94
+ lines.push(` share link: ${film.share.status === 'live' && film.share.url ? film.share.url : film.share.status === 'pending' ? 'waiting for review' : 'refused for this render'}`);
95
+ }
85
96
  lines.push(`Next: ${nextHint(film)}`);
86
97
  lines.push(`Web: ${film.webUrl}`);
87
98
  return lines;
@@ -143,15 +154,24 @@ function settle(film, waited) {
143
154
  throw new CliError(`Still working (${film.next}). Run \`makemidas film get ${film.id} --wait\` later.`, EXIT.NOT_READY, 'not_ready');
144
155
  }
145
156
  }
146
- /** Save the assembled film as `<dir>/film-<id>.mp4`. */
157
+ /** Save the assembled film as `<dir>/film-<id>.mp4`, and its subtitles as `.srt`. */
147
158
  async function saveFilm(api, film, save) {
148
159
  if (!save.out || !film.filmUrl)
149
160
  return [];
150
161
  const dir = resolve(save.out);
151
162
  await mkdir(dir, { recursive: true });
163
+ const files = [];
152
164
  const { bytes } = await api.download(film.filmUrl);
153
165
  const file = join(dir, `film-${short(film.id)}.mp4`);
154
- return (await writeOutput(file, bytes, save.force)) ? [file] : [];
166
+ if (await writeOutput(file, bytes, save.force))
167
+ files.push(file);
168
+ if (film.subtitlesUrl) {
169
+ const srt = await api.download(film.subtitlesUrl);
170
+ const subtitles = join(dir, `film-${short(film.id)}.srt`);
171
+ if (await writeOutput(subtitles, srt.bytes, save.force))
172
+ files.push(subtitles);
173
+ }
174
+ return files;
155
175
  }
156
176
  const EXT = {
157
177
  'video/mp4': 'mp4',
@@ -184,8 +204,13 @@ async function savePieces(api, film, save) {
184
204
  };
185
205
  const timeline = film.timeline;
186
206
  const clips = [];
187
- for (const [i, clip] of timeline.clips.entries()) {
188
- clips.push({ ...clip, file: await fetchTo(clip.url, `clip-${i + 1}`) });
207
+ for (const clip of timeline.clips) {
208
+ const name = clip.kind === 'title_card'
209
+ ? 'title-card'
210
+ : clip.kind === 'end_card'
211
+ ? 'end-card'
212
+ : `clip-${film.shots.findIndex((shot) => shot.id === clip.shotId) + 1}`;
213
+ clips.push({ ...clip, file: await fetchTo(clip.url, name) });
189
214
  }
190
215
  const voiceover = [];
191
216
  for (const line of timeline.voiceover) {
@@ -0,0 +1,232 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { askYesNo, report, saveOutputs, waitFor, } from "./commands.js";
3
+ import { CliError, EXIT } from "./errors.js";
4
+ import { formatBytes, log, print, printJson } from "./output.js";
5
+ /*
6
+ * HTML templates (quote cards, OG images, lower thirds, title cards…), your
7
+ * own HTML and CSS rendered to an image or a CSS-animated video, templates
8
+ * you save with fill-in fields, and the asset library's uploads.
9
+ */
10
+ const CATEGORIES = ['social', 'web', 'promo', 'video', 'custom'];
11
+ function need(value, usage) {
12
+ if (!value?.trim()) {
13
+ throw new CliError(`Give ${usage}.`, EXIT.USAGE, 'usage');
14
+ }
15
+ return value.trim();
16
+ }
17
+ /** A file's text; `-` reads stdin. */
18
+ export async function readText(path, what) {
19
+ if (path === '-') {
20
+ const chunks = [];
21
+ for await (const chunk of process.stdin)
22
+ chunks.push(chunk);
23
+ return Buffer.concat(chunks).toString('utf8');
24
+ }
25
+ try {
26
+ return await readFile(path, 'utf8');
27
+ }
28
+ catch {
29
+ throw new CliError(`Can't read ${what} ${path}`, EXIT.USAGE, 'invalid_file');
30
+ }
31
+ }
32
+ function fieldLine(field) {
33
+ const extra = [
34
+ field.type,
35
+ field.options?.length ? `one of ${field.options.join('|')}` : '',
36
+ field.maxLength ? `max ${field.maxLength}` : '',
37
+ field.backgrounds?.length ? `or background:${field.backgrounds.join('|')}` : '',
38
+ field.brand ? `brand: ${field.brand}` : '',
39
+ ]
40
+ .filter(Boolean)
41
+ .join(', ');
42
+ const fallback = field.default ? ` default: ${JSON.stringify(field.default)}` : '';
43
+ return ` --set ${field.id}=… ${field.label} (${extra})${fallback}`;
44
+ }
45
+ // ---------------------------------------------------------------- listing
46
+ export async function templatesList(api, g, category) {
47
+ if (category && !CATEGORIES.includes(category)) {
48
+ throw new CliError(`The category must be ${CATEGORIES.join(', ')}.`, EXIT.USAGE, 'usage');
49
+ }
50
+ const { templates, quota } = await api.templates(category);
51
+ if (g.json)
52
+ return printJson({ templates, quota });
53
+ for (const t of templates) {
54
+ const sizes = t.saved && t.canvas
55
+ ? `${t.canvas.width}x${t.canvas.height}`
56
+ : t.sizes.map((s) => s.id).join(',');
57
+ const video = t.video ? ` · video ${t.video.formats.join('/')}` : '';
58
+ print(`${t.id.padEnd(24)} ${t.category.padEnd(7)} ${sizes}${video} ${t.name}`);
59
+ }
60
+ log(`${quota.freeLeft} of ${quota.freePerDay} free images left today (UTC), then ${quota.creditsPerImage} credit each. Fields: makemidas template <id>`);
61
+ }
62
+ export async function templateShow(api, g, id) {
63
+ const template = await api.template(need(id, 'a template id: `makemidas template <id>`'));
64
+ if (g.json)
65
+ return printJson(template);
66
+ print(`${template.name} (${template.id}) · ${template.category}`);
67
+ if (template.description)
68
+ print(template.description);
69
+ const sizes = template.saved && template.canvas
70
+ ? `${template.canvas.width}x${template.canvas.height} (any --width/--height)`
71
+ : template.sizes.map((s) => `${s.id} ${s.width}x${s.height}`).join(', ');
72
+ print(`Sizes: ${sizes}${template.transparent ? ' · transparent' : ''}`);
73
+ if (template.video) {
74
+ print(`Video: ${template.video.minSeconds}-${template.video.maxSeconds} s (default ${template.video.defaultSeconds}), ${template.video.formats.join(' or ')}, 1 credit per started ${template.video.creditsPerSeconds} s`);
75
+ }
76
+ print('Fields:');
77
+ for (const field of template.fields)
78
+ print(fieldLine(field));
79
+ print(`Render: makemidas render ${template.id} --set <field>=<value>${template.video ? ' [--video]' : ''}`);
80
+ }
81
+ // ---------------------------------------------------------------- render
82
+ /** Upload local images named in `--set` to the asset library. */
83
+ async function uploadFieldFiles(api, files) {
84
+ const values = {};
85
+ for (const [field, path] of Object.entries(files)) {
86
+ log(`Uploading ${path} to your asset library…`);
87
+ const { asset } = await api.uploadAsset(path);
88
+ values[field] = { assetId: asset.id };
89
+ }
90
+ return values;
91
+ }
92
+ /** Render a template or a page; save the image or video and report it. */
93
+ export async function render(api, g, request, save, wait) {
94
+ const uploaded = request.files ? await uploadFieldFiles(api, request.files) : {};
95
+ const input = Object.keys(uploaded).length
96
+ ? { ...request.input, values: { ...request.input.values, ...uploaded } }
97
+ : request.input;
98
+ log(request.video ? 'Rendering the video…' : 'Rendering…');
99
+ const result = request.video ? await api.videoRender(input) : await api.render(input);
100
+ let generation = result.generation;
101
+ if (generation.status === 'running' && wait.wait) {
102
+ generation = await waitFor(api, generation, wait.timeoutMin);
103
+ }
104
+ const files = await saveOutputs(api, generation, save);
105
+ if (!g.json && result.quota) {
106
+ log(result.credits
107
+ ? `${result.credits} credit (no free renders left today).`
108
+ : `Free: ${result.quota.freeLeft} of ${result.quota.freePerDay} free renders left today.`);
109
+ }
110
+ report(g, generation, files);
111
+ }
112
+ /** `makemidas render <templateId> --set …`. */
113
+ export function templateRender(templateId, values, options, brandId) {
114
+ return {
115
+ templateId: need(templateId, 'a template id: `makemidas render quote-card --set quote="…"`'),
116
+ ...(Object.keys(values).length ? { values } : {}),
117
+ ...(brandId !== undefined ? { brandId } : {}),
118
+ ...options,
119
+ };
120
+ }
121
+ /** `makemidas html <page.html>`: your own page, no template. */
122
+ export async function htmlRender(file, css, transparent, options) {
123
+ const html = await readText(need(file, 'an HTML file (or - for stdin): `makemidas html page.html`'), 'the page');
124
+ if (!html.trim())
125
+ throw new CliError('The page is empty.', EXIT.USAGE, 'usage');
126
+ return {
127
+ html,
128
+ ...(css ? { css: await readText(css, 'the stylesheet') } : {}),
129
+ ...(transparent ? { transparent: true } : {}),
130
+ ...options,
131
+ };
132
+ }
133
+ // ---------------------------------------------------------------- saved templates
134
+ /** Ask before deleting, as `makemidas delete` does. */
135
+ async function confirmDelete(opts, what, note) {
136
+ if (opts.yes)
137
+ return;
138
+ if (!opts.interactive) {
139
+ throw new CliError(`Deleting ${what} can't be undone. Run again with --yes to confirm.`, EXIT.USAGE, 'confirmation_required');
140
+ }
141
+ const confirm = opts.confirm ?? askYesNo;
142
+ if (!(await confirm(`Delete ${what} for good? ${note}`))) {
143
+ throw new CliError('Not deleted.', EXIT.USAGE, 'cancelled');
144
+ }
145
+ }
146
+ /** The body of `template save|update`, read from the files given. */
147
+ export async function savedTemplateInput(files, rest) {
148
+ const input = { ...rest };
149
+ if (files.html)
150
+ input.html = await readText(files.html, 'the page');
151
+ if (files.css)
152
+ input.css = await readText(files.css, 'the stylesheet');
153
+ if (files.fields) {
154
+ let fields;
155
+ try {
156
+ fields = JSON.parse(await readText(files.fields, 'the fields file'));
157
+ }
158
+ catch (error) {
159
+ if (error instanceof CliError)
160
+ throw error;
161
+ throw new CliError(`${files.fields} is not valid JSON.`, EXIT.USAGE, 'invalid_file');
162
+ }
163
+ const list = Array.isArray(fields) ? fields : fields?.fields;
164
+ if (!Array.isArray(list)) {
165
+ throw new CliError(`${files.fields} must hold a list of fields (or { "fields": [...] }).`, EXIT.USAGE, 'invalid_file');
166
+ }
167
+ input.fields = list;
168
+ }
169
+ return input;
170
+ }
171
+ function showSaved(g, template, verb) {
172
+ if (g.json)
173
+ return printJson(template);
174
+ print(`${verb} ${template.name} (${template.id}), ${template.fields.length} field${template.fields.length === 1 ? '' : 's'}.`);
175
+ print(`Render: makemidas render ${template.id}${template.fields.map((f) => ` --set ${f.id}=…`).join('')}`);
176
+ }
177
+ export async function templateSave(api, g, input) {
178
+ if (!input.html) {
179
+ throw new CliError('Give the page: `makemidas template save page.html --name "Launch card"`.', EXIT.USAGE, 'usage');
180
+ }
181
+ if (!input.name) {
182
+ throw new CliError('Name it with --name.', EXIT.USAGE, 'usage');
183
+ }
184
+ showSaved(g, await api.saveTemplate(input), 'Saved');
185
+ }
186
+ export async function templateUpdate(api, g, id, input) {
187
+ const templateId = need(id, 'a saved template id: `makemidas template update <id> page.html`');
188
+ if (!Object.keys(input).length) {
189
+ throw new CliError('Say what to change: a page file, --css, --fields, --name, --description, --width and --height.', EXIT.USAGE, 'usage');
190
+ }
191
+ showSaved(g, await api.updateTemplate(templateId, input), 'Updated');
192
+ }
193
+ export async function templateDelete(api, g, id, opts) {
194
+ const templateId = need(id, 'a saved template id: `makemidas template delete <id>`');
195
+ await confirmDelete(opts, `the template ${templateId}`, 'Images made from it stay.');
196
+ await api.deleteTemplate(templateId);
197
+ if (g.json)
198
+ printJson({ id: templateId, deleted: true });
199
+ else
200
+ print(`Deleted template ${templateId}.`);
201
+ }
202
+ // ---------------------------------------------------------------- assets
203
+ export async function assetUpload(api, g, sources, opts) {
204
+ if (!sources.length) {
205
+ throw new CliError('Give one or more files or links: `makemidas assets upload logo.png`.', EXIT.USAGE, 'usage');
206
+ }
207
+ if (opts.name && sources.length > 1) {
208
+ throw new CliError('--name goes with one file.', EXIT.USAGE, 'usage');
209
+ }
210
+ const saved = [];
211
+ for (const source of sources) {
212
+ log(`Uploading ${source}…`);
213
+ const result = await api.uploadAsset(source, opts);
214
+ saved.push(result);
215
+ if (!g.json) {
216
+ print(`${result.asset.id} ${result.asset.kind.padEnd(5)} ${formatBytes(result.asset.size).padStart(8)} ${result.asset.name}${result.deduped ? ' (already kept)' : ''}`);
217
+ }
218
+ }
219
+ if (g.json)
220
+ printJson({ assets: saved.map((s) => ({ ...s.asset, deduped: s.deduped })) });
221
+ else
222
+ log('Use one with --ref asset:<id>, or in a template with --set <field>=asset:<id>.');
223
+ }
224
+ export async function assetDelete(api, g, id, opts) {
225
+ const assetId = need(id, 'an asset id: `makemidas assets delete <id>`');
226
+ await confirmDelete(opts, `the asset ${assetId}`, 'Generations made with it stay.');
227
+ await api.deleteAsset(assetId);
228
+ if (g.json)
229
+ printJson({ id: assetId, deleted: true });
230
+ else
231
+ print(`Deleted asset ${assetId}.`);
232
+ }
package/fonts/OFL.txt ADDED
@@ -0,0 +1,93 @@
1
+ Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@makemidas/cli",
3
- "version": "0.3.1",
4
- "description": "AI image and video generation CLI for AI agents (Claude Code, Cursor, Codex) and people: Nano Banana, GPT Image, Seedream, Seedance, Kling, Veo and more through MakeMidas.",
3
+ "version": "0.5.0",
4
+ "description": "AI image, video and audio generation CLI for AI agents (Claude Code, Cursor, Codex) and people: Nano Banana, GPT Image, Seedream, Seedance, Kling, Veo, Suno and more, plus talking avatars, HTML templates and short films, through MakeMidas.",
5
5
  "keywords": [
6
6
  "ai-image-generator",
7
7
  "ai-video-generator",
@@ -21,7 +21,10 @@
21
21
  "veo",
22
22
  "kling",
23
23
  "gemini-cli",
24
- "openclaw"
24
+ "openclaw",
25
+ "talking-avatar",
26
+ "html-to-image",
27
+ "ai-video-ads"
25
28
  ],
26
29
  "homepage": "https://makemidas.com/developers",
27
30
  "repository": {
@@ -37,7 +40,8 @@
37
40
  "makemidas": "dist/cli.js"
38
41
  },
39
42
  "files": [
40
- "dist"
43
+ "dist",
44
+ "fonts"
41
45
  ],
42
46
  "engines": {
43
47
  "node": ">=20"