transcribe-so 0.1.0 → 0.2.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/CHANGELOG.md +73 -0
- package/README.md +109 -8
- package/SKILL.md +92 -11
- package/dist/index.js +625 -171
- package/dist/index.js.map +1 -1
- package/examples/ig-caption.sh +35 -0
- package/examples/who-said-what.sh +33 -0
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var import_yargs = __toESM(require("yargs"));
|
|
|
28
28
|
var import_helpers = require("yargs/helpers");
|
|
29
29
|
|
|
30
30
|
// src/version.ts
|
|
31
|
-
var CLI_VERSION = true ? "0.
|
|
31
|
+
var CLI_VERSION = true ? "0.2.0" : "0.0.0-dev";
|
|
32
32
|
|
|
33
33
|
// src/commands/core.ts
|
|
34
34
|
var import_crypto = require("crypto");
|
|
@@ -42,7 +42,12 @@ var EXIT = {
|
|
|
42
42
|
AUTH: 3,
|
|
43
43
|
PAYMENT: 4,
|
|
44
44
|
TRANSIENT: 5,
|
|
45
|
-
BUDGET: 6
|
|
45
|
+
BUDGET: 6,
|
|
46
|
+
// Server-side ceiling: the API refused with 402 `max_charge_exceeded`
|
|
47
|
+
// because `max_charge_usd` was below the computed charge. Distinct from
|
|
48
|
+
// 4 (the account cannot pay) and from 6 (the CLI's own local `--max-usd`
|
|
49
|
+
// refusal, decided before any request that could charge).
|
|
50
|
+
MAX_CHARGE: 7
|
|
46
51
|
};
|
|
47
52
|
function printJson(value) {
|
|
48
53
|
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
@@ -89,6 +94,78 @@ function getConfig(argv) {
|
|
|
89
94
|
return { apiKey, apiUrl: rawUrl };
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
// src/catalog.ts
|
|
98
|
+
var SOURCES = ["youtube", "platform_url", "external_url", "upload"];
|
|
99
|
+
var TRANSCRIPT_FORMATS = ["txt", "md"];
|
|
100
|
+
var SUBTITLE_FORMATS = ["srt", "vtt", "vtt-karaoke", "json"];
|
|
101
|
+
var SUBTITLE_PRESETS = [
|
|
102
|
+
"youtube",
|
|
103
|
+
"tiktok-shorts",
|
|
104
|
+
"instagram-reels",
|
|
105
|
+
"netflix",
|
|
106
|
+
"podcast",
|
|
107
|
+
"broadcast"
|
|
108
|
+
];
|
|
109
|
+
var SUBTITLE_MODES = ["auto", "word", "sentence"];
|
|
110
|
+
var SUBTITLE_SOURCES = ["auto", "generated", "materialized"];
|
|
111
|
+
var RESULT_INCLUDE_SECTIONS = [
|
|
112
|
+
"chapters",
|
|
113
|
+
"acts",
|
|
114
|
+
"sections",
|
|
115
|
+
"qna",
|
|
116
|
+
"segments",
|
|
117
|
+
"posting_chapters",
|
|
118
|
+
"all"
|
|
119
|
+
];
|
|
120
|
+
var CAPTION_DESTINATIONS = {
|
|
121
|
+
instagram: "instagram_caption",
|
|
122
|
+
x: "x",
|
|
123
|
+
threads: "threads",
|
|
124
|
+
linkedin: "linkedin",
|
|
125
|
+
youtube: "youtube",
|
|
126
|
+
spotify: "spotify",
|
|
127
|
+
apple_podcasts: "apple_podcasts",
|
|
128
|
+
markdown: "markdown",
|
|
129
|
+
plain: "plain"
|
|
130
|
+
};
|
|
131
|
+
var CAPTION_DESTINATION_NAMES = Object.keys(CAPTION_DESTINATIONS);
|
|
132
|
+
var CAPTION_VARIANTS = [
|
|
133
|
+
"standard",
|
|
134
|
+
"highlights",
|
|
135
|
+
"clips",
|
|
136
|
+
"quoted_sections",
|
|
137
|
+
"show_notes",
|
|
138
|
+
"original"
|
|
139
|
+
];
|
|
140
|
+
function captionFormatFor(destination) {
|
|
141
|
+
const format = CAPTION_DESTINATIONS[destination];
|
|
142
|
+
if (!format) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`unknown caption destination "${destination}"; expected one of: ${CAPTION_DESTINATION_NAMES.join(", ")}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return format;
|
|
148
|
+
}
|
|
149
|
+
function notReadyRecovery(reason, id) {
|
|
150
|
+
switch (reason) {
|
|
151
|
+
case "transcription_processing":
|
|
152
|
+
return `Still processing. Wait for it: transcribe-so wait ${id}`;
|
|
153
|
+
case "transcription_failed":
|
|
154
|
+
return `The transcription failed; there is nothing to wait for. A retry is a NEW paid attempt: transcribe-so retry ${id} --yes --max-charge-usd <n>`;
|
|
155
|
+
case "transcription_cancelled":
|
|
156
|
+
return `The transcription was cancelled; there is no transcript and waiting will not produce one.`;
|
|
157
|
+
case "not_started":
|
|
158
|
+
return `This row is a quote (status=quoted) that was never started. Start a job with: transcribe-so create ... (the quote's transcription_id is not a job id)`;
|
|
159
|
+
case "artifact_missing":
|
|
160
|
+
return `Completed, but the artifact was never generated. Retrying the same call will not help.`;
|
|
161
|
+
default:
|
|
162
|
+
return `Not ready (reason=${reason ?? "unknown"}).`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function isWaitableNotReady(reason) {
|
|
166
|
+
return reason === "transcription_processing";
|
|
167
|
+
}
|
|
168
|
+
|
|
92
169
|
// src/api.ts
|
|
93
170
|
var ApiError = class extends Error {
|
|
94
171
|
constructor(status, rawText, retryAfterSeconds) {
|
|
@@ -109,7 +186,16 @@ var ApiError = class extends Error {
|
|
|
109
186
|
get code() {
|
|
110
187
|
return this.envelope?.error?.code ?? "unknown_error";
|
|
111
188
|
}
|
|
189
|
+
// Only set on 409 `not_ready` (transcript / timestamps). Decides whether
|
|
190
|
+
// waiting can possibly help.
|
|
191
|
+
get reason() {
|
|
192
|
+
return this.envelope?.error?.reason;
|
|
193
|
+
}
|
|
112
194
|
};
|
|
195
|
+
function isPermanentRateLimit(err) {
|
|
196
|
+
if (err.code !== "rate_limited") return false;
|
|
197
|
+
return !(err.retryAfterSeconds !== null && Number.isFinite(err.retryAfterSeconds));
|
|
198
|
+
}
|
|
113
199
|
function exitCodeFor(err) {
|
|
114
200
|
switch (err.code) {
|
|
115
201
|
case "unauthenticated":
|
|
@@ -119,7 +205,18 @@ function exitCodeFor(err) {
|
|
|
119
205
|
case "insufficient_funds":
|
|
120
206
|
case "spend_cap_exceeded":
|
|
121
207
|
return EXIT.PAYMENT;
|
|
208
|
+
// Also a 402, but the opposite remedy: nothing was held or charged and
|
|
209
|
+
// the account is fine. Raising the ceiling is the user's call, never the
|
|
210
|
+
// agent's, so it gets its own code instead of reading as "top up".
|
|
211
|
+
case "max_charge_exceeded":
|
|
212
|
+
return EXIT.MAX_CHARGE;
|
|
213
|
+
// A 429 with a Retry-After is a real throttle: wait it out. Without one it
|
|
214
|
+
// is an exhausted allowance that never refills on its own - the
|
|
215
|
+
// regeneration cap ("Regeneration limit reached (10). Re-transcribe to
|
|
216
|
+
// reset.") is the live example - so it gets the plain error code and
|
|
217
|
+
// agents stop looping.
|
|
122
218
|
case "rate_limited":
|
|
219
|
+
return isPermanentRateLimit(err) ? EXIT.ERROR : EXIT.TRANSIENT;
|
|
123
220
|
case "internal_error":
|
|
124
221
|
return EXIT.TRANSIENT;
|
|
125
222
|
// Not transient on a CLI timescale: the daily Q&A allowance frees up in
|
|
@@ -132,7 +229,7 @@ function exitCodeFor(err) {
|
|
|
132
229
|
if (err.status === 429 || err.status >= 500) return EXIT.TRANSIENT;
|
|
133
230
|
return EXIT.ERROR;
|
|
134
231
|
}
|
|
135
|
-
function handleFailure(err) {
|
|
232
|
+
function handleFailure(err, ctx = {}) {
|
|
136
233
|
if (err instanceof ApiError) {
|
|
137
234
|
if (err.envelope !== null) {
|
|
138
235
|
process.stdout.write(err.rawText.endsWith("\n") ? err.rawText : err.rawText + "\n");
|
|
@@ -149,9 +246,23 @@ function handleFailure(err) {
|
|
|
149
246
|
}
|
|
150
247
|
process.stderr.write(`${err.message}
|
|
151
248
|
`);
|
|
152
|
-
if (err.code === "not_ready") {
|
|
249
|
+
if (err.code === "not_ready" && !ctx.suppressNotReadyHint) {
|
|
250
|
+
process.stderr.write(
|
|
251
|
+
`Hint: ${notReadyRecovery(err.reason, ctx.id ?? "<id>")}
|
|
252
|
+
`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
if (isPermanentRateLimit(err)) {
|
|
153
256
|
process.stderr.write(
|
|
154
|
-
"Hint:
|
|
257
|
+
"Hint: this allowance does not refill on a CLI timescale (no Retry-After was sent). Re-transcribe to reset; retrying will not help.\n"
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
if (err.code === "max_charge_exceeded") {
|
|
261
|
+
const charge = err.envelope?.error?.charge_usd;
|
|
262
|
+
const ceiling = err.envelope?.error?.max_charge_usd ?? "not sent";
|
|
263
|
+
process.stderr.write(
|
|
264
|
+
`Hint: nothing was charged and no job started. The real charge is $${charge} against a ceiling of $${ceiling}. Report the price and ask the user before raising --max-charge-usd; do not raise it on your own.
|
|
265
|
+
`
|
|
155
266
|
);
|
|
156
267
|
}
|
|
157
268
|
process.exit(exitCodeFor(err));
|
|
@@ -172,6 +283,9 @@ var TranscribeAPI = class {
|
|
|
172
283
|
this.apiKey = config.apiKey;
|
|
173
284
|
this.apiUrl = config.apiUrl;
|
|
174
285
|
}
|
|
286
|
+
get baseUrl() {
|
|
287
|
+
return this.apiUrl;
|
|
288
|
+
}
|
|
175
289
|
buildUrl(path, query) {
|
|
176
290
|
const url = new URL(`${this.apiUrl}/api/v1${path}`);
|
|
177
291
|
for (const [key, value] of Object.entries(query ?? {})) {
|
|
@@ -251,6 +365,161 @@ var TranscribeAPI = class {
|
|
|
251
365
|
}
|
|
252
366
|
};
|
|
253
367
|
|
|
368
|
+
// src/commands/upload.ts
|
|
369
|
+
var import_child_process = require("child_process");
|
|
370
|
+
var import_fs = require("fs");
|
|
371
|
+
var import_path = require("path");
|
|
372
|
+
var CONTENT_TYPE_ALLOWLIST = [
|
|
373
|
+
"audio/mpeg",
|
|
374
|
+
"audio/mp3",
|
|
375
|
+
"audio/wav",
|
|
376
|
+
"audio/m4a",
|
|
377
|
+
"audio/mp4",
|
|
378
|
+
"audio/x-m4a",
|
|
379
|
+
"audio/aac",
|
|
380
|
+
"audio/ogg",
|
|
381
|
+
"audio/webm",
|
|
382
|
+
"audio/flac",
|
|
383
|
+
"video/mp4",
|
|
384
|
+
"video/webm",
|
|
385
|
+
"video/quicktime",
|
|
386
|
+
"video/x-msvideo"
|
|
387
|
+
];
|
|
388
|
+
var EXTENSION_MAP = {
|
|
389
|
+
".mp3": "audio/mpeg",
|
|
390
|
+
".mpga": "audio/mpeg",
|
|
391
|
+
".wav": "audio/wav",
|
|
392
|
+
".m4a": "audio/m4a",
|
|
393
|
+
".aac": "audio/aac",
|
|
394
|
+
".ogg": "audio/ogg",
|
|
395
|
+
".oga": "audio/ogg",
|
|
396
|
+
".flac": "audio/flac",
|
|
397
|
+
".webm": "video/webm",
|
|
398
|
+
".mp4": "video/mp4",
|
|
399
|
+
".mov": "video/quicktime",
|
|
400
|
+
".avi": "video/x-msvideo"
|
|
401
|
+
};
|
|
402
|
+
var WARN_BYTES = 50 * 1024 * 1024;
|
|
403
|
+
var HARD_LIMIT_BYTES = 500 * 1024 * 1024;
|
|
404
|
+
function resolveContentType(file, override) {
|
|
405
|
+
if (override) {
|
|
406
|
+
if (!CONTENT_TYPE_ALLOWLIST.includes(override)) {
|
|
407
|
+
failLocal(
|
|
408
|
+
EXIT.USAGE,
|
|
409
|
+
"unsupported_content_type",
|
|
410
|
+
`--content-type ${override} is not accepted by the API. Allowed: ${CONTENT_TYPE_ALLOWLIST.join(", ")}`
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
return override;
|
|
414
|
+
}
|
|
415
|
+
const ext = (0, import_path.extname)(file).toLowerCase();
|
|
416
|
+
const type = EXTENSION_MAP[ext];
|
|
417
|
+
if (!type) {
|
|
418
|
+
failLocal(
|
|
419
|
+
EXIT.USAGE,
|
|
420
|
+
"unsupported_content_type",
|
|
421
|
+
`Cannot map extension "${ext}" to an accepted content type. Pass --content-type with one of: ${CONTENT_TYPE_ALLOWLIST.join(", ")}`
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
return type;
|
|
425
|
+
}
|
|
426
|
+
function probeDurationSeconds(file) {
|
|
427
|
+
const probe = (0, import_child_process.spawnSync)(
|
|
428
|
+
"ffprobe",
|
|
429
|
+
[
|
|
430
|
+
"-v",
|
|
431
|
+
"error",
|
|
432
|
+
"-show_entries",
|
|
433
|
+
"format=duration",
|
|
434
|
+
"-of",
|
|
435
|
+
"default=noprint_wrappers=1:nokey=1",
|
|
436
|
+
file
|
|
437
|
+
],
|
|
438
|
+
{ encoding: "utf8" }
|
|
439
|
+
);
|
|
440
|
+
if (probe.error || probe.status !== 0) return null;
|
|
441
|
+
const seconds = parseFloat(probe.stdout.trim());
|
|
442
|
+
return Number.isFinite(seconds) && seconds > 0 ? seconds : null;
|
|
443
|
+
}
|
|
444
|
+
async function upload(argv) {
|
|
445
|
+
const file = argv.file;
|
|
446
|
+
let size;
|
|
447
|
+
try {
|
|
448
|
+
size = (0, import_fs.statSync)(file).size;
|
|
449
|
+
} catch {
|
|
450
|
+
failLocal(EXIT.USAGE, "file_not_found", `File not found: ${file}`);
|
|
451
|
+
}
|
|
452
|
+
if (size > HARD_LIMIT_BYTES) {
|
|
453
|
+
failLocal(
|
|
454
|
+
EXIT.ERROR,
|
|
455
|
+
"file_too_large_for_presigned",
|
|
456
|
+
`${file} is ${(size / (1024 * 1024)).toFixed(0)} MB; the CLI's single-shot presigned upload is capped at 500 MB. Use a resumable tus upload (POST /api/v1/uploads/tus with any tus 1.0 client) or upload via https://transcribe.so instead.`
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
if (size > WARN_BYTES) {
|
|
460
|
+
process.stderr.write(
|
|
461
|
+
`warning: ${(size / (1024 * 1024)).toFixed(0)} MB single-shot upload; the presigned URL expires in 900s. For flaky networks prefer the resumable tus flow (POST /api/v1/uploads/tus) or the web app.
|
|
462
|
+
`
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
const contentType = resolveContentType(file, argv.contentType);
|
|
466
|
+
let durationSeconds = argv.duration;
|
|
467
|
+
if (durationSeconds === void 0) {
|
|
468
|
+
const probed = probeDurationSeconds(file);
|
|
469
|
+
if (probed === null) {
|
|
470
|
+
failLocal(
|
|
471
|
+
EXIT.USAGE,
|
|
472
|
+
"duration_required",
|
|
473
|
+
"Duration is required for uploads and ffprobe is not available (or could not read this file). Either pass --duration <seconds> or install ffmpeg so ffprobe is on PATH."
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
durationSeconds = probed;
|
|
477
|
+
process.stderr.write(`ffprobe duration: ${durationSeconds.toFixed(1)}s
|
|
478
|
+
`);
|
|
479
|
+
}
|
|
480
|
+
const api = new TranscribeAPI(getConfig({ allowCustomHost: argv.allowCustomHost }));
|
|
481
|
+
try {
|
|
482
|
+
const res = await api.request("/uploads", {
|
|
483
|
+
method: "POST",
|
|
484
|
+
body: {
|
|
485
|
+
filename: (0, import_path.basename)(file),
|
|
486
|
+
content_type: contentType,
|
|
487
|
+
file_size: size
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
const uploadUrl = res.json.upload_url;
|
|
491
|
+
process.stderr.write(`uploading ${(0, import_path.basename)(file)} (${size} bytes)...
|
|
492
|
+
`);
|
|
493
|
+
const putResponse = await fetch(uploadUrl, {
|
|
494
|
+
method: "PUT",
|
|
495
|
+
headers: { "Content-Type": contentType },
|
|
496
|
+
body: (0, import_fs.readFileSync)(file)
|
|
497
|
+
});
|
|
498
|
+
if (!putResponse.ok) {
|
|
499
|
+
const text = await putResponse.text();
|
|
500
|
+
printJson({
|
|
501
|
+
error: {
|
|
502
|
+
code: "upload_put_failed",
|
|
503
|
+
message: `PUT to presigned URL failed with ${putResponse.status}: ${text.slice(0, 300)}`
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
process.stderr.write(`upload PUT failed (${putResponse.status})
|
|
507
|
+
`);
|
|
508
|
+
process.exit(EXIT.TRANSIENT);
|
|
509
|
+
}
|
|
510
|
+
printJson({
|
|
511
|
+
upload_id: res.json.upload_id,
|
|
512
|
+
duration_seconds: durationSeconds,
|
|
513
|
+
filename: (0, import_path.basename)(file),
|
|
514
|
+
file_size: size,
|
|
515
|
+
content_type: contentType,
|
|
516
|
+
next: `transcribe-so create --source upload --upload-id ${res.json.upload_id} --duration ${durationSeconds}`
|
|
517
|
+
});
|
|
518
|
+
} catch (err) {
|
|
519
|
+
handleFailure(err);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
254
523
|
// src/commands/core.ts
|
|
255
524
|
var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
256
525
|
function apiFor(argv) {
|
|
@@ -259,13 +528,15 @@ function apiFor(argv) {
|
|
|
259
528
|
function printRaw(rawText) {
|
|
260
529
|
process.stdout.write(rawText.endsWith("\n") ? rawText : rawText + "\n");
|
|
261
530
|
}
|
|
262
|
-
function buildCreateBody(argv) {
|
|
531
|
+
function buildCreateBody(argv, withCeiling = false) {
|
|
263
532
|
const body = { source: argv.source };
|
|
264
533
|
if (argv.url !== void 0) body.url = argv.url;
|
|
265
534
|
if (argv.uploadId !== void 0) body.upload_id = argv.uploadId;
|
|
266
535
|
if (argv.duration !== void 0) body.duration_seconds = argv.duration;
|
|
267
536
|
if (argv.language !== void 0) body.language = argv.language;
|
|
268
537
|
if (argv.callbackUrl !== void 0) body.callback_url = argv.callbackUrl;
|
|
538
|
+
if (withCeiling && argv.maxChargeUsd !== void 0)
|
|
539
|
+
body.max_charge_usd = argv.maxChargeUsd;
|
|
269
540
|
return body;
|
|
270
541
|
}
|
|
271
542
|
async function authStatus(argv) {
|
|
@@ -317,7 +588,7 @@ async function create(argv) {
|
|
|
317
588
|
try {
|
|
318
589
|
const res = await apiFor(argv).request("/transcriptions", {
|
|
319
590
|
method: "POST",
|
|
320
|
-
body: buildCreateBody(argv),
|
|
591
|
+
body: buildCreateBody(argv, true),
|
|
321
592
|
idempotencyKey: argv.idempotencyKey ?? (0, import_crypto.randomUUID)()
|
|
322
593
|
});
|
|
323
594
|
printRaw(res.rawText);
|
|
@@ -336,7 +607,12 @@ async function waitLoop(api, id, opts) {
|
|
|
336
607
|
}
|
|
337
608
|
const window = Math.min(45, Math.max(1, remaining));
|
|
338
609
|
const res = await api.request(`/transcriptions/${id}/wait`, {
|
|
339
|
-
query: {
|
|
610
|
+
query: {
|
|
611
|
+
timeout: window,
|
|
612
|
+
include: opts.include,
|
|
613
|
+
segments_offset: opts.segmentsOffset,
|
|
614
|
+
segments_limit: opts.segmentsLimit
|
|
615
|
+
}
|
|
340
616
|
});
|
|
341
617
|
last = { body: res.json, rawText: res.rawText };
|
|
342
618
|
const status = res.json?.status;
|
|
@@ -366,9 +642,12 @@ async function wait(argv) {
|
|
|
366
642
|
try {
|
|
367
643
|
const result2 = await waitLoop(api, argv.id, {
|
|
368
644
|
timeoutSec: argv.timeout,
|
|
369
|
-
include: argv.include
|
|
645
|
+
include: argv.include,
|
|
646
|
+
segmentsOffset: argv.segmentsOffset,
|
|
647
|
+
segmentsLimit: argv.segmentsLimit
|
|
370
648
|
});
|
|
371
649
|
printRaw(result2.rawText);
|
|
650
|
+
noteSegmentsWindow(result2.body, argv.id);
|
|
372
651
|
if (result2.notAJob) {
|
|
373
652
|
process.stderr.write(
|
|
374
653
|
`id ${argv.id} is a quote row (status=quoted), not a started job; pass the id from the create 202 response
|
|
@@ -390,16 +669,40 @@ async function wait(argv) {
|
|
|
390
669
|
handleFailure(err);
|
|
391
670
|
}
|
|
392
671
|
}
|
|
672
|
+
function noteSegmentsWindow(body, id) {
|
|
673
|
+
const meta = body?.segments_meta;
|
|
674
|
+
if (!meta) return;
|
|
675
|
+
process.stderr.write(
|
|
676
|
+
`segments window: offset=${meta.offset} limit=${meta.limit} of ${meta.total} total, has_more=${meta.has_more}
|
|
677
|
+
`
|
|
678
|
+
);
|
|
679
|
+
if (meta.has_more) {
|
|
680
|
+
process.stderr.write(
|
|
681
|
+
`this is a PARTIAL transcript; continue with --segments-offset ${meta.offset + meta.limit}, or get the whole thing as text with: transcribe-so transcript ${id}
|
|
682
|
+
`
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
393
686
|
async function result(argv) {
|
|
394
687
|
try {
|
|
395
688
|
const res = await apiFor(argv).request(`/transcriptions/${argv.id}/result`, {
|
|
396
|
-
query: {
|
|
689
|
+
query: {
|
|
690
|
+
include: argv.include,
|
|
691
|
+
segments_offset: argv.segmentsOffset,
|
|
692
|
+
segments_limit: argv.segmentsLimit
|
|
693
|
+
}
|
|
397
694
|
});
|
|
398
695
|
printRaw(res.rawText);
|
|
696
|
+
noteSegmentsWindow(res.json, argv.id);
|
|
399
697
|
} catch (err) {
|
|
400
698
|
handleFailure(err);
|
|
401
699
|
}
|
|
402
700
|
}
|
|
701
|
+
function resolveRunCeiling(argv) {
|
|
702
|
+
if (argv.serverCeiling === false) return void 0;
|
|
703
|
+
if (argv.maxChargeUsd !== void 0) return argv.maxChargeUsd;
|
|
704
|
+
return argv.maxUsd;
|
|
705
|
+
}
|
|
403
706
|
async function run(argv) {
|
|
404
707
|
const api = apiFor(argv);
|
|
405
708
|
try {
|
|
@@ -427,9 +730,15 @@ async function run(argv) {
|
|
|
427
730
|
);
|
|
428
731
|
process.exit(EXIT.BUDGET);
|
|
429
732
|
}
|
|
733
|
+
const ceiling = resolveRunCeiling(argv);
|
|
734
|
+
const createBody = ceiling === void 0 ? body : { ...body, max_charge_usd: ceiling };
|
|
735
|
+
if (ceiling !== void 0) {
|
|
736
|
+
process.stderr.write(`server-side charge ceiling: $${ceiling}
|
|
737
|
+
`);
|
|
738
|
+
}
|
|
430
739
|
const createRes = await api.request("/transcriptions", {
|
|
431
740
|
method: "POST",
|
|
432
|
-
body,
|
|
741
|
+
body: createBody,
|
|
433
742
|
idempotencyKey: argv.idempotencyKey ?? (0, import_crypto.randomUUID)()
|
|
434
743
|
});
|
|
435
744
|
const id = createRes.json?.id;
|
|
@@ -462,6 +771,7 @@ async function run(argv) {
|
|
|
462
771
|
query: { include: argv.include }
|
|
463
772
|
});
|
|
464
773
|
printRaw(resultRes.rawText);
|
|
774
|
+
noteSegmentsWindow(resultRes.json, id);
|
|
465
775
|
} catch (err) {
|
|
466
776
|
handleFailure(err);
|
|
467
777
|
}
|
|
@@ -502,6 +812,7 @@ async function retry(argv) {
|
|
|
502
812
|
try {
|
|
503
813
|
const res = await apiFor(argv).request(`/transcriptions/${argv.id}/retry`, {
|
|
504
814
|
method: "POST",
|
|
815
|
+
body: argv.maxChargeUsd !== void 0 ? { max_charge_usd: argv.maxChargeUsd } : void 0,
|
|
505
816
|
idempotencyKey: argv.idempotencyKey ?? (0, import_crypto.randomUUID)()
|
|
506
817
|
});
|
|
507
818
|
printRaw(res.rawText);
|
|
@@ -509,11 +820,63 @@ async function retry(argv) {
|
|
|
509
820
|
handleFailure(err);
|
|
510
821
|
}
|
|
511
822
|
}
|
|
823
|
+
async function capabilities(argv) {
|
|
824
|
+
const api = apiFor(argv);
|
|
825
|
+
try {
|
|
826
|
+
const [meRes, pipelinesRes] = await Promise.all([
|
|
827
|
+
api.request("/me"),
|
|
828
|
+
api.request("/pipelines")
|
|
829
|
+
]);
|
|
830
|
+
let apiVersion = null;
|
|
831
|
+
try {
|
|
832
|
+
const specRes = await fetch(`${api.baseUrl}/openapi.json`, {
|
|
833
|
+
headers: { Accept: "application/json" }
|
|
834
|
+
});
|
|
835
|
+
if (specRes.ok) {
|
|
836
|
+
const spec = await specRes.json();
|
|
837
|
+
apiVersion = spec?.info?.version ?? null;
|
|
838
|
+
}
|
|
839
|
+
} catch {
|
|
840
|
+
apiVersion = null;
|
|
841
|
+
}
|
|
842
|
+
printJson({
|
|
843
|
+
cli_version: CLI_VERSION,
|
|
844
|
+
api_url: api.baseUrl,
|
|
845
|
+
api_version: apiVersion,
|
|
846
|
+
account: meRes.json,
|
|
847
|
+
pipelines: pipelinesRes.json?.pipelines ?? pipelinesRes.json,
|
|
848
|
+
formats: {
|
|
849
|
+
sources: SOURCES,
|
|
850
|
+
result_include: RESULT_INCLUDE_SECTIONS,
|
|
851
|
+
transcript_formats: TRANSCRIPT_FORMATS,
|
|
852
|
+
subtitles: {
|
|
853
|
+
formats: SUBTITLE_FORMATS,
|
|
854
|
+
presets: SUBTITLE_PRESETS,
|
|
855
|
+
modes: SUBTITLE_MODES,
|
|
856
|
+
sources: SUBTITLE_SOURCES
|
|
857
|
+
},
|
|
858
|
+
captions: {
|
|
859
|
+
destinations: CAPTION_DESTINATION_NAMES,
|
|
860
|
+
destination_to_api_format: CAPTION_DESTINATIONS,
|
|
861
|
+
variants: CAPTION_VARIANTS
|
|
862
|
+
},
|
|
863
|
+
upload_content_types: CONTENT_TYPE_ALLOWLIST
|
|
864
|
+
},
|
|
865
|
+
exit_codes: EXIT
|
|
866
|
+
});
|
|
867
|
+
} catch (err) {
|
|
868
|
+
handleFailure(err);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
512
871
|
|
|
513
872
|
// src/commands/artifacts.ts
|
|
873
|
+
var import_fs2 = require("fs");
|
|
514
874
|
function apiFor2(argv) {
|
|
515
875
|
return new TranscribeAPI(getConfig({ allowCustomHost: argv.allowCustomHost }));
|
|
516
876
|
}
|
|
877
|
+
function writeRaw(raw) {
|
|
878
|
+
process.stdout.write(raw.endsWith("\n") ? raw : raw + "\n");
|
|
879
|
+
}
|
|
517
880
|
async function subtitles(argv) {
|
|
518
881
|
try {
|
|
519
882
|
const raw = await apiFor2(argv).requestRaw(
|
|
@@ -526,177 +889,154 @@ async function subtitles(argv) {
|
|
|
526
889
|
source: argv.source
|
|
527
890
|
}
|
|
528
891
|
);
|
|
529
|
-
|
|
892
|
+
writeRaw(raw);
|
|
530
893
|
} catch (err) {
|
|
531
|
-
handleFailure(err);
|
|
894
|
+
handleFailure(err, { id: argv.id });
|
|
532
895
|
}
|
|
533
896
|
}
|
|
534
|
-
async function
|
|
897
|
+
async function transcript(argv) {
|
|
898
|
+
const api = apiFor2(argv);
|
|
899
|
+
const waitSeconds = argv.waitSeconds ?? 0;
|
|
900
|
+
const deadline = Date.now() + waitSeconds * 1e3;
|
|
901
|
+
const query = {
|
|
902
|
+
format: argv.format,
|
|
903
|
+
// Both default to true server-side; only send the negation so the
|
|
904
|
+
// request stays a plain GET of the documented default otherwise.
|
|
905
|
+
speaker_labels: argv.speakerLabels === false ? false : void 0,
|
|
906
|
+
timestamps: argv.timestamps === false ? false : void 0
|
|
907
|
+
};
|
|
908
|
+
for (; ; ) {
|
|
909
|
+
try {
|
|
910
|
+
const raw = await api.requestRaw(`/transcriptions/${argv.id}/transcript`, query);
|
|
911
|
+
if (argv.out) {
|
|
912
|
+
(0, import_fs2.writeFileSync)(argv.out, raw.endsWith("\n") ? raw : raw + "\n");
|
|
913
|
+
process.stderr.write(`wrote ${argv.out}
|
|
914
|
+
`);
|
|
915
|
+
} else {
|
|
916
|
+
writeRaw(raw);
|
|
917
|
+
}
|
|
918
|
+
return;
|
|
919
|
+
} catch (err) {
|
|
920
|
+
if (!(err instanceof ApiError) || err.code !== "not_ready") handleFailure(err, { id: argv.id });
|
|
921
|
+
const apiErr = err;
|
|
922
|
+
const remainingMs = deadline - Date.now();
|
|
923
|
+
if (!isWaitableNotReady(apiErr.reason) || remainingMs <= 0) {
|
|
924
|
+
handleFailure(apiErr, { id: argv.id });
|
|
925
|
+
}
|
|
926
|
+
const retryAfter = apiErr.retryAfterSeconds && Number.isFinite(apiErr.retryAfterSeconds) ? Math.max(1, apiErr.retryAfterSeconds) : 15;
|
|
927
|
+
const sleepSec = Math.min(retryAfter, Math.ceil(remainingMs / 1e3));
|
|
928
|
+
process.stderr.write(
|
|
929
|
+
`not ready (status=${apiErr.envelope?.error?.status ?? "?"}); retrying in ${sleepSec}s (${Math.ceil(remainingMs / 1e3)}s of --wait-seconds left)
|
|
930
|
+
`
|
|
931
|
+
);
|
|
932
|
+
await sleep(sleepSec * 1e3);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
async function captions(argv) {
|
|
937
|
+
const api = apiFor2(argv);
|
|
938
|
+
let format;
|
|
535
939
|
try {
|
|
536
|
-
|
|
537
|
-
if (argv.topK !== void 0) body.top_k = argv.topK;
|
|
538
|
-
const res = await apiFor2(argv).request(`/transcriptions/${argv.id}/ask`, {
|
|
539
|
-
method: "POST",
|
|
540
|
-
body
|
|
541
|
-
});
|
|
542
|
-
process.stdout.write(res.rawText.endsWith("\n") ? res.rawText : res.rawText + "\n");
|
|
940
|
+
format = captionFormatFor(argv.for);
|
|
543
941
|
} catch (err) {
|
|
544
|
-
handleFailure(err);
|
|
942
|
+
handleFailure(err, { id: argv.id });
|
|
545
943
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
];
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
".aac": "audio/aac",
|
|
574
|
-
".ogg": "audio/ogg",
|
|
575
|
-
".oga": "audio/ogg",
|
|
576
|
-
".flac": "audio/flac",
|
|
577
|
-
".webm": "video/webm",
|
|
578
|
-
".mp4": "video/mp4",
|
|
579
|
-
".mov": "video/quicktime",
|
|
580
|
-
".avi": "video/x-msvideo"
|
|
581
|
-
};
|
|
582
|
-
var WARN_BYTES = 50 * 1024 * 1024;
|
|
583
|
-
var HARD_LIMIT_BYTES = 500 * 1024 * 1024;
|
|
584
|
-
function resolveContentType(file, override) {
|
|
585
|
-
if (override) {
|
|
586
|
-
if (!CONTENT_TYPE_ALLOWLIST.includes(override)) {
|
|
587
|
-
failLocal(
|
|
588
|
-
EXIT.USAGE,
|
|
589
|
-
"unsupported_content_type",
|
|
590
|
-
`--content-type ${override} is not accepted by the API. Allowed: ${CONTENT_TYPE_ALLOWLIST.join(", ")}`
|
|
944
|
+
const query = {
|
|
945
|
+
format,
|
|
946
|
+
variant: argv.variant,
|
|
947
|
+
cta: argv.cta ? true : void 0
|
|
948
|
+
};
|
|
949
|
+
const emit = (body, rawText) => {
|
|
950
|
+
if (argv.json) {
|
|
951
|
+
writeRaw(rawText);
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
const text = body?.text;
|
|
955
|
+
if (typeof text !== "string") {
|
|
956
|
+
printJson({
|
|
957
|
+
error: {
|
|
958
|
+
code: "cli_error",
|
|
959
|
+
message: "the API response carried no `text` field; re-run with --json to see it"
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
process.exit(EXIT.ERROR);
|
|
963
|
+
}
|
|
964
|
+
writeRaw(text);
|
|
965
|
+
const warnings = Array.isArray(body?.warnings) ? body.warnings : [];
|
|
966
|
+
for (const warning of warnings) process.stderr.write(`warning: ${warning}
|
|
967
|
+
`);
|
|
968
|
+
if (body?.ok_to_paste === false) {
|
|
969
|
+
process.stderr.write(
|
|
970
|
+
"warning: ok_to_paste=false - this output violates a hard platform rule; review before posting\n"
|
|
591
971
|
);
|
|
592
972
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
973
|
+
};
|
|
974
|
+
let regenerated = false;
|
|
975
|
+
for (; ; ) {
|
|
976
|
+
try {
|
|
977
|
+
const res = await api.request(`/transcriptions/${argv.id}/timestamps`, { query });
|
|
978
|
+
emit(res.json, res.rawText);
|
|
979
|
+
return;
|
|
980
|
+
} catch (err) {
|
|
981
|
+
if (!(err instanceof ApiError) || err.code !== "not_ready") handleFailure(err, { id: argv.id });
|
|
982
|
+
const apiErr = err;
|
|
983
|
+
if (apiErr.reason === "artifact_missing" && argv.regenerate && !regenerated) {
|
|
984
|
+
regenerated = true;
|
|
985
|
+
process.stderr.write(
|
|
986
|
+
`curated cache missing; regenerating once (POST /timestamps/regenerate, 30-90s)...
|
|
987
|
+
`
|
|
988
|
+
);
|
|
989
|
+
try {
|
|
990
|
+
await api.request(`/transcriptions/${argv.id}/timestamps/regenerate`, {
|
|
991
|
+
method: "POST"
|
|
992
|
+
});
|
|
993
|
+
} catch (regenErr) {
|
|
994
|
+
handleFailure(regenErr, { id: argv.id });
|
|
995
|
+
}
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
if (apiErr.reason === "artifact_missing") {
|
|
999
|
+
process.stderr.write(
|
|
1000
|
+
`Recovery: POST ${api.buildUrl(`/transcriptions/${argv.id}/timestamps/regenerate`)} once (or re-run with --regenerate), then retry this command.
|
|
1001
|
+
`
|
|
1002
|
+
);
|
|
1003
|
+
} else {
|
|
1004
|
+
process.stderr.write(`Recovery: ${notReadyRecovery(apiErr.reason, argv.id)}
|
|
1005
|
+
`);
|
|
1006
|
+
}
|
|
1007
|
+
handleFailure(apiErr, { id: argv.id, suppressNotReadyHint: true });
|
|
1008
|
+
}
|
|
603
1009
|
}
|
|
604
|
-
return type;
|
|
605
1010
|
}
|
|
606
|
-
function
|
|
607
|
-
const
|
|
608
|
-
"ffprobe",
|
|
609
|
-
[
|
|
610
|
-
"-v",
|
|
611
|
-
"error",
|
|
612
|
-
"-show_entries",
|
|
613
|
-
"format=duration",
|
|
614
|
-
"-of",
|
|
615
|
-
"default=noprint_wrappers=1:nokey=1",
|
|
616
|
-
file
|
|
617
|
-
],
|
|
618
|
-
{ encoding: "utf8" }
|
|
619
|
-
);
|
|
620
|
-
if (probe.error || probe.status !== 0) return null;
|
|
621
|
-
const seconds = parseFloat(probe.stdout.trim());
|
|
622
|
-
return Number.isFinite(seconds) && seconds > 0 ? seconds : null;
|
|
623
|
-
}
|
|
624
|
-
async function upload(argv) {
|
|
625
|
-
const file = argv.file;
|
|
626
|
-
let size;
|
|
1011
|
+
async function search(argv) {
|
|
1012
|
+
const path = argv.id !== void 0 ? `/transcriptions/${argv.id}/search` : "/search";
|
|
627
1013
|
try {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
`${file} is ${(size / (1024 * 1024)).toFixed(0)} MB; the CLI's single-shot presigned upload is capped at 500 MB. Use a resumable tus upload (POST /api/v1/uploads/tus with any tus 1.0 client) or upload via https://transcribe.so instead.`
|
|
637
|
-
);
|
|
638
|
-
}
|
|
639
|
-
if (size > WARN_BYTES) {
|
|
640
|
-
process.stderr.write(
|
|
641
|
-
`warning: ${(size / (1024 * 1024)).toFixed(0)} MB single-shot upload; the presigned URL expires in 900s. For flaky networks prefer the resumable tus flow (POST /api/v1/uploads/tus) or the web app.
|
|
1014
|
+
const res = await apiFor2(argv).request(path, {
|
|
1015
|
+
query: { q: argv.q, limit: argv.limit, offset: argv.offset }
|
|
1016
|
+
});
|
|
1017
|
+
writeRaw(res.rawText);
|
|
1018
|
+
if (res.json?.has_more) {
|
|
1019
|
+
const next = (res.json.offset ?? 0) + (res.json.limit ?? 0);
|
|
1020
|
+
process.stderr.write(
|
|
1021
|
+
`more hits available; continue with --offset ${next} (offset is capped at 1000 - narrow the query instead of deep-paging)
|
|
642
1022
|
`
|
|
643
|
-
);
|
|
644
|
-
}
|
|
645
|
-
const contentType = resolveContentType(file, argv.contentType);
|
|
646
|
-
let durationSeconds = argv.duration;
|
|
647
|
-
if (durationSeconds === void 0) {
|
|
648
|
-
const probed = probeDurationSeconds(file);
|
|
649
|
-
if (probed === null) {
|
|
650
|
-
failLocal(
|
|
651
|
-
EXIT.USAGE,
|
|
652
|
-
"duration_required",
|
|
653
|
-
"Duration is required for uploads and ffprobe is not available (or could not read this file). Either pass --duration <seconds> or install ffmpeg so ffprobe is on PATH."
|
|
654
1023
|
);
|
|
655
1024
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
`);
|
|
1025
|
+
} catch (err) {
|
|
1026
|
+
handleFailure(err, { id: argv.id });
|
|
659
1027
|
}
|
|
660
|
-
|
|
1028
|
+
}
|
|
1029
|
+
async function ask(argv) {
|
|
661
1030
|
try {
|
|
662
|
-
const
|
|
1031
|
+
const body = { question: argv.question };
|
|
1032
|
+
if (argv.topK !== void 0) body.top_k = argv.topK;
|
|
1033
|
+
const res = await apiFor2(argv).request(`/transcriptions/${argv.id}/ask`, {
|
|
663
1034
|
method: "POST",
|
|
664
|
-
body
|
|
665
|
-
filename: (0, import_path.basename)(file),
|
|
666
|
-
content_type: contentType,
|
|
667
|
-
file_size: size
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
const uploadUrl = res.json.upload_url;
|
|
671
|
-
process.stderr.write(`uploading ${(0, import_path.basename)(file)} (${size} bytes)...
|
|
672
|
-
`);
|
|
673
|
-
const putResponse = await fetch(uploadUrl, {
|
|
674
|
-
method: "PUT",
|
|
675
|
-
headers: { "Content-Type": contentType },
|
|
676
|
-
body: (0, import_fs.readFileSync)(file)
|
|
677
|
-
});
|
|
678
|
-
if (!putResponse.ok) {
|
|
679
|
-
const text = await putResponse.text();
|
|
680
|
-
printJson({
|
|
681
|
-
error: {
|
|
682
|
-
code: "upload_put_failed",
|
|
683
|
-
message: `PUT to presigned URL failed with ${putResponse.status}: ${text.slice(0, 300)}`
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
process.stderr.write(`upload PUT failed (${putResponse.status})
|
|
687
|
-
`);
|
|
688
|
-
process.exit(EXIT.TRANSIENT);
|
|
689
|
-
}
|
|
690
|
-
printJson({
|
|
691
|
-
upload_id: res.json.upload_id,
|
|
692
|
-
duration_seconds: durationSeconds,
|
|
693
|
-
filename: (0, import_path.basename)(file),
|
|
694
|
-
file_size: size,
|
|
695
|
-
content_type: contentType,
|
|
696
|
-
next: `transcribe-so create --source upload --upload-id ${res.json.upload_id} --duration ${durationSeconds}`
|
|
1035
|
+
body
|
|
697
1036
|
});
|
|
1037
|
+
writeRaw(res.rawText);
|
|
698
1038
|
} catch (err) {
|
|
699
|
-
handleFailure(err);
|
|
1039
|
+
handleFailure(err, { id: argv.id });
|
|
700
1040
|
}
|
|
701
1041
|
}
|
|
702
1042
|
|
|
@@ -740,7 +1080,29 @@ function sourceOptions(y) {
|
|
|
740
1080
|
return true;
|
|
741
1081
|
});
|
|
742
1082
|
}
|
|
743
|
-
|
|
1083
|
+
function maxChargeOption(y) {
|
|
1084
|
+
return y.option("max-charge-usd", {
|
|
1085
|
+
describe: "Server-side charge ceiling in USD. The API refuses with 402 max_charge_exceeded (exit 7) before holding anything if the computed charge is higher. A plan-covered job charges $0 and passes any ceiling, including 0.",
|
|
1086
|
+
type: "number"
|
|
1087
|
+
}).check((argv) => {
|
|
1088
|
+
if (argv.maxChargeUsd !== void 0 && (!Number.isFinite(argv.maxChargeUsd) || argv.maxChargeUsd < 0)) {
|
|
1089
|
+
throw new Error("--max-charge-usd must be a finite number >= 0");
|
|
1090
|
+
}
|
|
1091
|
+
return true;
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
function segmentWindowOptions(y) {
|
|
1095
|
+
return y.option("segments-offset", {
|
|
1096
|
+
describe: "First segment to return, 0-based (only with --include segments|all)",
|
|
1097
|
+
type: "number"
|
|
1098
|
+
}).option("segments-limit", {
|
|
1099
|
+
describe: "How many segments to return (1-1000). Read segments_meta.has_more; for the whole transcript use `transcript <id>`, which is never capped.",
|
|
1100
|
+
type: "number"
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).scriptName("transcribe-so").usage(
|
|
1104
|
+
"$0 <command> [options]\n\nPure-JSON stdout, except the three raw-output commands (subtitles, transcript,\ncaptions) which print a body you can pipe to a file; progress goes to stderr."
|
|
1105
|
+
).option("allow-custom-host", {
|
|
744
1106
|
describe: "Allow sending the API key to a non-default TRANSCRIBE_API_URL host (refused otherwise)",
|
|
745
1107
|
type: "boolean",
|
|
746
1108
|
default: false,
|
|
@@ -774,7 +1136,10 @@ var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)
|
|
|
774
1136
|
).command(
|
|
775
1137
|
"create",
|
|
776
1138
|
"Submit a transcription (charges the wallet; prints the 202 body)",
|
|
777
|
-
(y) => sourceOptions(y).example(
|
|
1139
|
+
(y) => maxChargeOption(sourceOptions(y)).example(
|
|
1140
|
+
'$0 create --source youtube --url "https://youtu.be/x" --max-charge-usd 2',
|
|
1141
|
+
"Refuse server-side (exit 7) if the charge would exceed $2"
|
|
1142
|
+
).example(
|
|
778
1143
|
'$0 create --source youtube --url "https://youtu.be/jNQXAC9IVRw"',
|
|
779
1144
|
"Transcribe a YouTube video"
|
|
780
1145
|
).example(
|
|
@@ -785,7 +1150,7 @@ var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)
|
|
|
785
1150
|
).command(
|
|
786
1151
|
"wait <id>",
|
|
787
1152
|
"Long-poll until the transcription completes or fails (server-side windows)",
|
|
788
|
-
(y) => y.positional("id", { describe: "Transcription id from the create 202", type: "number" }).option("timeout", {
|
|
1153
|
+
(y) => segmentWindowOptions(y).positional("id", { describe: "Transcription id from the create 202", type: "number" }).option("timeout", {
|
|
789
1154
|
describe: "Overall seconds to keep waiting",
|
|
790
1155
|
type: "number",
|
|
791
1156
|
default: 1800
|
|
@@ -794,12 +1159,19 @@ var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)
|
|
|
794
1159
|
).command(
|
|
795
1160
|
"result <id>",
|
|
796
1161
|
"Fetch the result of a completed transcription",
|
|
797
|
-
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("include", { describe: INCLUDE_DESCRIBE, type: "string" }).example("$0 result 4821", "Chapters, sections and Q&A").example("$0 result 4821 --include segments | jq -r '.segments[].text'", "
|
|
1162
|
+
(y) => segmentWindowOptions(y).positional("id", { describe: "Transcription id", type: "number" }).option("include", { describe: INCLUDE_DESCRIBE, type: "string" }).example("$0 result 4821", "Chapters, sections and Q&A").example("$0 result 4821 --include segments | jq -r '.segments[].text'", "One window of verbatim text").example(
|
|
1163
|
+
"$0 result 4821 --include segments --segments-offset 1000 --segments-limit 1000",
|
|
1164
|
+
"The next window (see segments_meta)"
|
|
1165
|
+
),
|
|
798
1166
|
result
|
|
799
1167
|
).command(
|
|
800
1168
|
"run",
|
|
801
1169
|
"quote, then create, wait, and fetch the result in one command (requires --max-usd)",
|
|
802
|
-
(y) => sourceOptions(y).option("
|
|
1170
|
+
(y) => maxChargeOption(sourceOptions(y)).option("server-ceiling", {
|
|
1171
|
+
describe: "Also send --max-usd (or --max-charge-usd) to the API as max_charge_usd, so the ceiling is enforced at the wallet hold too. Default true; --no-server-ceiling opts out.",
|
|
1172
|
+
type: "boolean",
|
|
1173
|
+
default: true
|
|
1174
|
+
}).option("max-usd", {
|
|
803
1175
|
describe: "Hard budget: refuse (exit 6) if the quote exceeds this many USD. Required; there is no default.",
|
|
804
1176
|
type: "number",
|
|
805
1177
|
demandOption: true
|
|
@@ -842,7 +1214,7 @@ var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)
|
|
|
842
1214
|
).command(
|
|
843
1215
|
"retry <id>",
|
|
844
1216
|
"Retry a failed transcription (charges again from scratch)",
|
|
845
|
-
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("yes", {
|
|
1217
|
+
(y) => maxChargeOption(y).positional("id", { describe: "Transcription id", type: "number" }).option("yes", {
|
|
846
1218
|
describe: "Required confirmation flag; retry re-charges the wallet from scratch",
|
|
847
1219
|
type: "boolean",
|
|
848
1220
|
default: false
|
|
@@ -852,7 +1224,7 @@ var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)
|
|
|
852
1224
|
}).check((argv) => {
|
|
853
1225
|
if (!argv.yes) throw new Error("retry re-charges from scratch; re-run with --yes to confirm");
|
|
854
1226
|
return true;
|
|
855
|
-
}).example("$0 retry 4821 --yes", "Re-run failed job 4821"),
|
|
1227
|
+
}).example("$0 retry 4821 --yes --max-charge-usd 2", "Re-run failed job 4821, capped at $2"),
|
|
856
1228
|
retry
|
|
857
1229
|
).command(
|
|
858
1230
|
"upload <file>",
|
|
@@ -872,7 +1244,7 @@ var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)
|
|
|
872
1244
|
upload
|
|
873
1245
|
).command(
|
|
874
1246
|
"subtitles <id>",
|
|
875
|
-
"Print the raw subtitle file (SRT/VTT/JSON) to stdout -
|
|
1247
|
+
"Print the raw subtitle file (SRT/VTT/JSON) to stdout - a raw-output command",
|
|
876
1248
|
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("format", {
|
|
877
1249
|
describe: "Subtitle format",
|
|
878
1250
|
type: "string",
|
|
@@ -891,6 +1263,88 @@ var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)
|
|
|
891
1263
|
choices: ["auto", "generated", "materialized"]
|
|
892
1264
|
}).example("$0 subtitles 4821 > talk.srt", "Save the SRT").example("$0 subtitles 4821 --format vtt --preset tiktok-shorts > talk.vtt", "Vertical-video VTT"),
|
|
893
1265
|
subtitles
|
|
1266
|
+
).command(
|
|
1267
|
+
"transcript <id>",
|
|
1268
|
+
"Print the COMPLETE transcript as raw text or Markdown (never capped) - a raw-output command",
|
|
1269
|
+
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("format", {
|
|
1270
|
+
describe: "txt (transcript only) or md (title + chapter list + turns)",
|
|
1271
|
+
type: "string",
|
|
1272
|
+
choices: [...TRANSCRIPT_FORMATS],
|
|
1273
|
+
default: "txt"
|
|
1274
|
+
}).option("speaker-labels", {
|
|
1275
|
+
describe: "Prefix each turn with its speaker label (default true; --no-speaker-labels to drop)",
|
|
1276
|
+
type: "boolean",
|
|
1277
|
+
default: true
|
|
1278
|
+
}).option("timestamps", {
|
|
1279
|
+
describe: "Prefix each turn with its clock time (default true; --no-timestamps to drop)",
|
|
1280
|
+
type: "boolean",
|
|
1281
|
+
default: true
|
|
1282
|
+
}).option("out", { describe: "Write to this file instead of stdout", type: "string" }).option("wait-seconds", {
|
|
1283
|
+
describe: "If the job is still processing (409 not_ready reason=transcription_processing), keep retrying on Retry-After for up to this many seconds. Default 0 = fail immediately. Every other not_ready reason exits non-zero without waiting.",
|
|
1284
|
+
type: "number",
|
|
1285
|
+
default: 0
|
|
1286
|
+
}).check((argv) => {
|
|
1287
|
+
if (!Number.isFinite(argv.waitSeconds) || argv.waitSeconds < 0) {
|
|
1288
|
+
throw new Error("--wait-seconds must be a finite number >= 0");
|
|
1289
|
+
}
|
|
1290
|
+
return true;
|
|
1291
|
+
}).example("$0 transcript 4821 > talk.txt", "Whole transcript as text").example("$0 transcript 4821 --format md --out talk.md", "Timestamped Markdown export").example("$0 transcript 4821 --no-timestamps --no-speaker-labels", "Prose only"),
|
|
1292
|
+
transcript
|
|
1293
|
+
).command(
|
|
1294
|
+
"captions <id>",
|
|
1295
|
+
"Paste-ready captions/timestamps for one destination - prints the text raw (--json for the envelope)",
|
|
1296
|
+
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("for", {
|
|
1297
|
+
describe: "Destination platform",
|
|
1298
|
+
type: "string",
|
|
1299
|
+
choices: CAPTION_DESTINATION_NAMES,
|
|
1300
|
+
default: "youtube"
|
|
1301
|
+
}).option("variant", {
|
|
1302
|
+
describe: "Content: standard (chapter list), highlights (5-item text outline), clips (3 video ideas), quoted_sections (verbatim quotes), show_notes, original",
|
|
1303
|
+
type: "string",
|
|
1304
|
+
choices: [...CAPTION_VARIANTS],
|
|
1305
|
+
default: "standard"
|
|
1306
|
+
}).option("cta", {
|
|
1307
|
+
describe: "Append the transcribe.so CTA footer (quoted_sections only). Off by default: the caption belongs to the user.",
|
|
1308
|
+
type: "boolean",
|
|
1309
|
+
default: false
|
|
1310
|
+
}).option("json", {
|
|
1311
|
+
describe: "Print the full JSON envelope (warnings, ok_to_paste, thread[], constraints) instead of the raw text",
|
|
1312
|
+
type: "boolean",
|
|
1313
|
+
default: false
|
|
1314
|
+
}).option("regenerate", {
|
|
1315
|
+
describe: "On 409 not_ready reason=artifact_missing, POST /timestamps/regenerate ONCE (30-90s) and retry. Without it the command prints the recovery and exits non-zero. Not free of side effects: it regenerates and REPLACES all four cached caption/chapter variants and burns 1 of the 10 regenerations allowed per transcription.",
|
|
1316
|
+
type: "boolean",
|
|
1317
|
+
default: false
|
|
1318
|
+
}).example("$0 captions 4821 --for instagram --variant highlights", "IG caption outline").example("$0 captions 4821 --for youtube > chapters.txt", "YouTube chapter list").example("$0 captions 4821 --for x --variant quoted_sections --json | jq -r '.thread[]'", "Pre-split X thread"),
|
|
1319
|
+
captions
|
|
1320
|
+
).command(
|
|
1321
|
+
"search <q>",
|
|
1322
|
+
'Search transcript segments ("who said X, and when") across the library or one transcription',
|
|
1323
|
+
(y) => y.positional("q", { describe: "Search terms (2-200 chars, case-insensitive substring)", type: "string" }).option("id", {
|
|
1324
|
+
describe: "Restrict to one transcription id (404s if it is not yours)",
|
|
1325
|
+
type: "number"
|
|
1326
|
+
}).option("limit", { describe: "Hits per page, 1-100 (default 20)", type: "number" }).option("offset", { describe: "0-based offset, max 1000", type: "number" }).check((argv) => {
|
|
1327
|
+
if (typeof argv.q !== "string" || argv.q.length < 2) {
|
|
1328
|
+
throw new Error("<q> must be at least 2 characters");
|
|
1329
|
+
}
|
|
1330
|
+
if (argv.limit !== void 0) {
|
|
1331
|
+
if (!Number.isInteger(argv.limit) || argv.limit < 1 || argv.limit > 100) {
|
|
1332
|
+
throw new Error("--limit must be an integer between 1 and 100");
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
if (argv.offset !== void 0) {
|
|
1336
|
+
if (!Number.isInteger(argv.offset) || argv.offset < 0 || argv.offset > 1e3) {
|
|
1337
|
+
throw new Error("--offset must be an integer between 0 and 1000");
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
return true;
|
|
1341
|
+
}).example(`$0 search "pricing" | jq -r '.hits[] | "\\(.speaker): \\(.text)"'`, "Who said it").example('$0 search "pricing" --id 4821', "Within one transcription"),
|
|
1342
|
+
search
|
|
1343
|
+
).command(
|
|
1344
|
+
"capabilities",
|
|
1345
|
+
"One JSON object: this account (/me), the pipeline catalog (/pipelines), every format enum this CLI accepts, and the exit codes",
|
|
1346
|
+
(y) => y.example("$0 capabilities | jq .formats.captions.destinations", "Valid `captions --for` values"),
|
|
1347
|
+
capabilities
|
|
894
1348
|
).command(
|
|
895
1349
|
"ask <id>",
|
|
896
1350
|
"Ask a question about one completed transcription (cited answer; daily Q&A allowance)",
|