vidnavigator 2.4.0 → 2.6.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
- import { VideoInfo, TranscriptOutput, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult, UsageData, Namespace, NamespaceRef, ExtractionSchema, UsageBlock, CarouselInfo, CarouselVideoResult, TikTokProfileScrapeRequest, TikTokProfileScrapeSubmission, TikTokProfileTask, TikTokSearchRequest, TikTokSearchSubmission, TikTokSearchTask, TikTokLiveSearchRequest, TikTokLiveSearchSubmission, TikTokLiveSearchTask, TikTokLiveRoomRequest, TikTokLiveRoomResult, TweetStatement, WatchResult, AsyncJob } from './models';
2
+ import { VideoInfo, TranscriptOutput, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult, UsageData, Namespace, NamespaceRef, ExtractionSchema, UsageBlock, CarouselInfo, CarouselVideoResult, TikTokProfileScrapeRequest, TikTokProfileScrapeSubmission, TikTokProfileTask, TikTokSearchRequest, TikTokSearchSubmission, TikTokSearchTask, TikTokLiveSearchRequest, TikTokLiveSearchSubmission, TikTokLiveSearchTask, TikTokLiveRoomRequest, TikTokLiveRoomResult, TweetStatement, WatchResult, WatchTranscriptError, VideoScene, ScenesError, FileScenesStatus, AsyncJob } from './models';
3
3
  import { Job, JobOperation, PollOptions, RunOptions, SubmitOptions } from './jobs';
4
4
  export * from './models';
5
5
  export * from './errors';
@@ -7,7 +7,7 @@ export * from './webhooks';
7
7
  export { Job } from './jobs';
8
8
  export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
9
9
  /** SDK version (keep in sync with package.json) */
10
- export declare const SDK_VERSION = "2.4.0";
10
+ export declare const SDK_VERSION = "2.6.0";
11
11
  export interface SDKConfig {
12
12
  apiKey: string;
13
13
  baseURL?: string;
@@ -62,19 +62,44 @@ export type WatchInput = {
62
62
  export type WatchVideoPayload = WatchInput & {
63
63
  include_usage?: boolean;
64
64
  };
65
- /** Input for {@link VidNavigatorClient.extractVideo}: a JSON `schema`, or a JSON/YAML `schemaFilePath`. */
65
+ /** Input for {@link VidNavigatorClient.analyze}. A plain string is treated as `video_url`. */
66
+ export type AnalyzeVideoInput = {
67
+ video_url: string;
68
+ /** Optional question about the video. */
69
+ query?: string;
70
+ /**
71
+ * Default false. `true` also reads what the video shows: the analysis is made from the
72
+ * transcript and the scenes together, and the result has `scenes` and `frames_analyzed`.
73
+ */
74
+ include_scenes?: boolean;
75
+ /** Return the transcript as a single string instead of segments. */
76
+ transcript_text?: boolean;
77
+ } & WebhookOption;
78
+ /**
79
+ * Input for {@link VidNavigatorClient.extractVideo}: a JSON Schema `schema`, or a JSON/YAML
80
+ * `schemaFilePath`, or neither with `what_to_extract`: the schema is then written from that text
81
+ * and comes back as `schema` on the result.
82
+ */
66
83
  export type ExtractVideoInput = ({
67
84
  video_url: string;
68
- schema: ExtractionSchema;
85
+ /** The fields to extract, as a standard JSON Schema. Optional when `what_to_extract` is given. */
86
+ schema?: ExtractionSchema;
87
+ /** What to extract, in plain words. Guides the extraction, or alone, writes the schema. */
69
88
  what_to_extract?: string;
70
89
  /** Speech-to-text the audio when no platform transcript exists. Default true. */
71
90
  transcribe?: boolean;
91
+ /**
92
+ * Default false. `true` also reads what the video shows: the fields are extracted from the
93
+ * transcript and the scenes together, and the result has `frames_analyzed`.
94
+ */
95
+ include_scenes?: boolean;
72
96
  } & WebhookOption) | ({
73
97
  video_url: string;
74
98
  /** Path to a JSON or YAML schema file (sent as multipart form-data). */
75
99
  schemaFilePath: string;
76
100
  what_to_extract?: string;
77
101
  transcribe?: boolean;
102
+ include_scenes?: boolean;
78
103
  } & WebhookOption);
79
104
  /** Input for {@link VidNavigatorClient.tweetStatement}. A plain string is treated as `tweet_id`. */
80
105
  export type TweetStatementInput = {
@@ -100,6 +125,8 @@ export type TranscribeVideoResult = TranscribeVideoSingleResult | TranscribeVide
100
125
  export type TranscribeAsyncJob = AsyncJob<TranscribeVideoResult>;
101
126
  /** Snapshot of a watch task. `result` is a {@link WatchResult}. */
102
127
  export type WatchAsyncJob = AsyncJob<WatchResult>;
128
+ /** Snapshot of a video analysis task. `result` has the same shape as {@link VidNavigatorClient.analyzeVideo}'s return value. */
129
+ export type AnalyzeVideoAsyncJob = AsyncJob<AnalyzeVideoResult>;
103
130
  /** Snapshot of an extraction task. `result` is the extracted object, shaped like your schema. */
104
131
  export type ExtractVideoAsyncJob = AsyncJob<Record<string, unknown>>;
105
132
  /** Snapshot of a tweet claim analysis task. `result` is a {@link TweetStatement}. */
@@ -120,6 +147,7 @@ export interface TranscribeOperation extends JobOperation<string | TranscribeInp
120
147
  submit(input: string | TranscribeInput, options?: SubmitOptions): Promise<Job<TranscribeAsyncJob, TranscribeVideoResult>>;
121
148
  }
122
149
  export type WatchJob = Job<WatchAsyncJob, WatchResult>;
150
+ export type AnalyzeVideoJob = Job<AnalyzeVideoAsyncJob, AnalyzeVideoResult>;
123
151
  export type ExtractVideoJob = Job<ExtractVideoAsyncJob, ExtractDataResult>;
124
152
  export type TweetStatementJob = Job<TweetStatementAsyncJob, TweetStatement>;
125
153
  /** `result()` resolves to the completed task with **all** pages of `videos` collected. */
@@ -146,10 +174,33 @@ export type UploadFileAcceptedResult = {
146
174
  file_info?: FileInfo;
147
175
  };
148
176
  export type UploadFileResult = UploadFileSuccessResult | UploadFileAcceptedResult;
177
+ /** Answer of {@link VidNavigatorClient.analyzeFileScenes}. */
178
+ export type AnalyzeFileScenesResult = {
179
+ file_id: string;
180
+ /** `processing`: the analysis was started, or is already running. `completed`: the scenes are already there. */
181
+ scenes_status: Extract<FileScenesStatus, 'processing' | 'completed'>;
182
+ message: string;
183
+ };
184
+ /** Answer of {@link VidNavigatorClient.getFile}. */
185
+ export type GetFileResult = {
186
+ file_info: FileInfo;
187
+ /** Present once the file has a transcript. */
188
+ transcript?: TranscriptOutput;
189
+ /** What the file shows, in chronological order. Present once `file_info.scenes_status` is `completed`. */
190
+ scenes?: VideoScene[];
191
+ };
149
192
  export interface ExtractDataResult {
150
193
  data: Record<string, unknown>;
194
+ /** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
195
+ schema?: ExtractionSchema;
151
196
  video_info?: VideoInfo;
152
197
  file_info?: FileInfo;
198
+ /** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
199
+ frames_analyzed?: number;
200
+ /** With `include_scenes: true`, when the picture could not be read: the fields were extracted from the transcript alone. */
201
+ scenes_error?: ScenesError;
202
+ /** With `include_scenes: true`, when there is no transcript: the fields were extracted from the scenes alone. */
203
+ transcript_error?: WatchTranscriptError;
153
204
  usage?: UsageBlock;
154
205
  }
155
206
  /**
@@ -198,12 +249,24 @@ export type SearchFilesResult = {
198
249
  export type AnalyzeVideoPayload = {
199
250
  video_url: string;
200
251
  query?: string;
252
+ /**
253
+ * Default false. `true` also reads what the video shows: the analysis is made from the
254
+ * transcript and the scenes together, and the result has `scenes` and `frames_analyzed`.
255
+ */
256
+ include_scenes?: boolean;
201
257
  transcript_text?: boolean;
202
258
  include_usage?: boolean;
203
259
  };
204
260
  export type AnalyzeFilePayload = {
205
261
  file_id: string;
206
262
  query?: string;
263
+ /**
264
+ * Default false. `true` analyzes the file from its transcript and its scenes together. The
265
+ * scenes are the ones kept with the file: ask for them at the upload (`include_scenes`) or with
266
+ * {@link VidNavigatorClient.analyzeFileScenes}. A file that has none is refused with
267
+ * `ScenesNotAvailableError`.
268
+ */
269
+ include_scenes?: boolean;
207
270
  transcript_text?: boolean;
208
271
  include_usage?: boolean;
209
272
  };
@@ -211,19 +274,44 @@ export type AnalyzeVideoResult = {
211
274
  video_info: VideoInfo;
212
275
  transcript: TranscriptOutput;
213
276
  transcript_analysis: AnalysisResult;
277
+ /**
278
+ * With `include_scenes: true`: what the video shows, in chronological order. Empty when the
279
+ * picture could not be read (see `scenes_error`).
280
+ */
281
+ scenes?: VideoScene[];
282
+ /** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
283
+ frames_analyzed?: number;
284
+ /** With `include_scenes: true`, when the picture could not be read: the analysis was made from the transcript alone. */
285
+ scenes_error?: ScenesError;
286
+ /** With `include_scenes: true`, when there is no transcript: the analysis was made from the scenes alone. */
287
+ transcript_error?: WatchTranscriptError;
214
288
  usage?: UsageBlock;
215
289
  };
216
290
  export type AnalyzeFileResult = {
217
291
  file_info: FileInfo;
218
292
  transcript: TranscriptOutput;
219
293
  transcript_analysis: AnalysisResult;
294
+ /** With `include_scenes: true`: what the file shows, in chronological order. */
295
+ scenes?: VideoScene[];
296
+ /** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
297
+ frames_analyzed?: number;
298
+ /** Why the scenes could not be read, when the answer carries it. A file that has no scenes at all is refused with `ScenesNotAvailableError` instead. */
299
+ scenes_error?: ScenesError;
300
+ /** With `include_scenes: true`, when the file has no speech: the analysis was made from the scenes alone. */
301
+ transcript_error?: WatchTranscriptError;
220
302
  usage?: UsageBlock;
221
303
  };
222
304
  export type ExtractVideoDataPayload = {
223
305
  video_url: string;
224
- schema: ExtractionSchema;
306
+ /** A standard JSON Schema. Optional when `what_to_extract` is given. */
307
+ schema?: ExtractionSchema;
225
308
  what_to_extract?: string;
226
309
  transcribe?: boolean;
310
+ /**
311
+ * Default false. `true` also reads what the video shows: the fields are extracted from the
312
+ * transcript and the scenes together, and the result has `frames_analyzed`.
313
+ */
314
+ include_scenes?: boolean;
227
315
  include_usage?: boolean;
228
316
  } & WebhookOption;
229
317
  export type ExtractVideoDataMultipartPayload = {
@@ -232,6 +320,7 @@ export type ExtractVideoDataMultipartPayload = {
232
320
  schemaFilePath: string;
233
321
  what_to_extract?: string;
234
322
  transcribe?: boolean;
323
+ include_scenes?: boolean;
235
324
  include_usage?: boolean;
236
325
  } & WebhookOption;
237
326
  export type TweetStatementPayload = {
@@ -239,8 +328,16 @@ export type TweetStatementPayload = {
239
328
  } & WebhookOption;
240
329
  export type ExtractFileDataPayload = {
241
330
  file_id: string;
242
- schema: ExtractionSchema;
331
+ /** A standard JSON Schema. Optional when `what_to_extract` is given. */
332
+ schema?: ExtractionSchema;
243
333
  what_to_extract?: string;
334
+ /**
335
+ * Default false. `true` extracts from the transcript of the file and its scenes together. The
336
+ * scenes are the ones kept with the file: ask for them at the upload (`include_scenes`) or with
337
+ * {@link VidNavigatorClient.analyzeFileScenes}. A file that has none is refused with
338
+ * `ScenesNotAvailableError`.
339
+ */
340
+ include_scenes?: boolean;
244
341
  include_usage?: boolean;
245
342
  };
246
343
  export type ExtractFileDataMultipartPayload = {
@@ -248,6 +345,7 @@ export type ExtractFileDataMultipartPayload = {
248
345
  /** Path to a JSON or YAML schema file. The API accepts either a raw schema or a full extraction request object. */
249
346
  schemaFilePath: string;
250
347
  what_to_extract?: string;
348
+ include_scenes?: boolean;
251
349
  include_usage?: boolean;
252
350
  };
253
351
  export declare class VidNavigatorClient {
@@ -271,9 +369,18 @@ export declare class VidNavigatorClient {
271
369
  * says why. Same shapes as {@link VidNavigatorClient.transcribe}.
272
370
  */
273
371
  readonly watch: JobOperation<string | WatchInput, WatchAsyncJob, WatchResult>;
372
+ /**
373
+ * Analysis of an online video as a background job, built on `POST /analyze/video/async`: the
374
+ * same analysis and the same result as {@link VidNavigatorClient.analyzeVideo}, without holding
375
+ * a connection open while it runs. Use it with `include_scenes: true` on a video longer than
376
+ * about 10 minutes. Same shapes as {@link VidNavigatorClient.transcribe}.
377
+ */
378
+ readonly analyze: JobOperation<string | AnalyzeVideoInput, AnalyzeVideoAsyncJob, AnalyzeVideoResult>;
274
379
  /**
275
380
  * Structured-data extraction from a video of any length, built on `POST /extract/video/async`.
276
- * The schema is validated when you submit. Same shapes as {@link VidNavigatorClient.transcribe}.
381
+ * The schema is validated when you submit. With `include_scenes: true` the fields are extracted
382
+ * from the transcript and from what the video shows. Same shapes as
383
+ * {@link VidNavigatorClient.transcribe}.
277
384
  */
278
385
  readonly extractVideo: JobOperation<ExtractVideoInput, ExtractVideoAsyncJob, ExtractDataResult>;
279
386
  /**
@@ -367,16 +474,26 @@ export declare class VidNavigatorClient {
367
474
  offset: number;
368
475
  has_more: boolean;
369
476
  }>;
477
+ /**
478
+ * A file's metadata, its transcript once it has one, and its scenes once they are analyzed.
479
+ * `file_info.scenes_status` says where the scene analysis stands; when it is `completed`, the
480
+ * result has `scenes`, as {@link VidNavigatorClient.watch} returns them for an online video.
481
+ */
370
482
  getFile(file_id: string, query?: {
371
483
  transcript_text?: boolean;
372
- }): Promise<{
373
- file_info: FileInfo;
374
- transcript?: TranscriptOutput;
375
- }>;
484
+ }): Promise<GetFileResult>;
485
+ /**
486
+ * Upload an audio or video file. With `include_scenes: true` the picture of a video file is
487
+ * analyzed as well, next to its transcription: follow `file_info.scenes_status` with
488
+ * {@link VidNavigatorClient.getFile}, which returns the scenes once it is `completed`. An audio
489
+ * file has no picture: its `scenes_status` is `failed`, with `frames_not_available`.
490
+ */
376
491
  uploadFile(options: {
377
492
  filePath: string;
378
493
  wait_for_completion?: boolean;
379
494
  namespace_ids?: string[];
495
+ /** Default false. `true` also analyzes the scenes of the file (video files only). */
496
+ include_scenes?: boolean;
380
497
  }): Promise<UploadFileResult>;
381
498
  deleteFile(file_id: string): Promise<{
382
499
  file_id: string;
@@ -393,6 +510,19 @@ export declare class VidNavigatorClient {
393
510
  file_status: string;
394
511
  message: string;
395
512
  }>;
513
+ /**
514
+ * Start the scene analysis of a file already uploaded: what its picture shows, scene by scene,
515
+ * with the text readable on screen. The scenes of a file are analyzed once and kept with it.
516
+ *
517
+ * The answer has `scenes_status` `processing` when the analysis was started or is already
518
+ * running, and `completed` when the scenes are already there (nothing new is started). Follow
519
+ * `file_info.scenes_status` with {@link VidNavigatorClient.getFile}, which returns the scenes
520
+ * once it is `completed`; `analyzeFile` and `extractFileData` read them with `include_scenes: true`.
521
+ *
522
+ * An audio file has no picture: the call throws `BadRequestError` with `error_code`
523
+ * `frames_not_available`.
524
+ */
525
+ analyzeFileScenes(file_id: string): Promise<AnalyzeFileScenesResult>;
396
526
  cancelFileUpload(file_id: string): Promise<{
397
527
  file_id: string;
398
528
  file_name: string;
@@ -417,7 +547,26 @@ export declare class VidNavigatorClient {
417
547
  namespace_ids: string[];
418
548
  namespaces: NamespaceRef[];
419
549
  }>;
550
+ /**
551
+ * Analyze an online video: a summary, the people, places and key subjects, and the answer to
552
+ * an optional `query`. With `include_scenes: true` the analysis is made from the transcript and
553
+ * from what the video shows, and the result also has `scenes` and `frames_analyzed`, as
554
+ * {@link VidNavigatorClient.watch} returns them. When the picture cannot be read, the analysis
555
+ * is made from the transcript alone and `scenes_error` says why; a video without a transcript
556
+ * is analyzed from its scenes, and `transcript_error` says why the transcript is missing.
557
+ *
558
+ * This call waits on one HTTP request. With `include_scenes` on a video longer than about
559
+ * 10 minutes, use {@link VidNavigatorClient.analyze}, which runs the same analysis as a
560
+ * background job.
561
+ */
420
562
  analyzeVideo(payload: AnalyzeVideoPayload): Promise<AnalyzeVideoResult>;
563
+ /**
564
+ * Analyze an uploaded file. With `include_scenes: true` the analysis is made from the transcript
565
+ * of the file and its scenes together, and the result also has `scenes` and `frames_analyzed`.
566
+ * The scenes are the ones kept with the file: ask for them at the upload (`include_scenes`) or
567
+ * with {@link VidNavigatorClient.analyzeFileScenes}. A file that has none is refused with
568
+ * `ScenesNotAvailableError` (HTTP 409), whose `scenes_status` says where their analysis stands.
569
+ */
421
570
  analyzeFile(payload: AnalyzeFilePayload): Promise<AnalyzeFileResult>;
422
571
  /**
423
572
  * Structured claim analysis of an X/Twitter tweet. Blocking convenience wrapper around
@@ -428,8 +577,17 @@ export declare class VidNavigatorClient {
428
577
  * Structured-data extraction from an online video. Blocking convenience wrapper around
429
578
  * {@link VidNavigatorClient.extractVideo}: submits to `POST /extract/video/async` and polls, so
430
579
  * media of any length works. The result carries the extracted `data` and the video's `video_info`.
580
+ * With `include_scenes: true` the fields are extracted from the transcript and from what the video
581
+ * shows, and the result also has `frames_analyzed`.
431
582
  */
432
583
  extractVideoData(payload: ExtractVideoDataPayload | ExtractVideoDataMultipartPayload, options?: PollOptions<ExtractVideoAsyncJob>): Promise<ExtractDataResult>;
584
+ /**
585
+ * Structured-data extraction from an uploaded file. With `include_scenes: true` the fields are
586
+ * extracted from the transcript of the file and its scenes together, and the result has
587
+ * `frames_analyzed`. The scenes are the ones kept with the file: ask for them at the upload
588
+ * (`include_scenes`) or with {@link VidNavigatorClient.analyzeFileScenes}. A file that has none
589
+ * is refused with `ScenesNotAvailableError` (HTTP 409).
590
+ */
433
591
  extractFileData(payload: ExtractFileDataPayload | ExtractFileDataMultipartPayload): Promise<ExtractDataResult>;
434
592
  /**
435
593
  * Search YouTube for videos with AI analysis and ranking.
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ __exportStar(require("./webhooks"), exports);
31
31
  var jobs_2 = require("./jobs");
32
32
  Object.defineProperty(exports, "Job", { enumerable: true, get: function () { return jobs_2.Job; } });
33
33
  /** SDK version (keep in sync with package.json) */
34
- exports.SDK_VERSION = '2.4.0';
34
+ exports.SDK_VERSION = '2.6.0';
35
35
  /**
36
36
  * A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
37
37
  * minutes at worst. A shorter configured axios timeout is raised to this for that call only.
@@ -53,6 +53,44 @@ function parseTranscribeData(inner, usage) {
53
53
  usage,
54
54
  };
55
55
  }
56
+ /**
57
+ * An extraction needs a schema (`schema` or `schemaFilePath`) or, without one, `what_to_extract`,
58
+ * from which the API writes the schema. Checked before anything is sent.
59
+ */
60
+ function checkSchemaInput(input) {
61
+ if (input.schema !== undefined && input.schemaFilePath !== undefined) {
62
+ throw new Error('Pass at most one of schema or schemaFilePath.');
63
+ }
64
+ if (input.schema === undefined && input.schemaFilePath === undefined && !input.what_to_extract?.trim()) {
65
+ throw new Error('Pass schema, schemaFilePath or what_to_extract.');
66
+ }
67
+ }
68
+ // The scene fields are set only when the response carries them, so a result asked without
69
+ // `include_scenes` keeps the shape it always had.
70
+ function pickSceneNotes(raw) {
71
+ const notes = {};
72
+ if (raw.frames_analyzed != null)
73
+ notes.frames_analyzed = raw.frames_analyzed;
74
+ if (raw.scenes_error)
75
+ notes.scenes_error = raw.scenes_error;
76
+ if (raw.transcript_error)
77
+ notes.transcript_error = raw.transcript_error;
78
+ return notes;
79
+ }
80
+ function parseScenes(raw) {
81
+ return raw ? { scenes: raw.map((scene) => models_1.VideoScene.fromJSON(scene)) } : {};
82
+ }
83
+ function parseAnalysisData(raw) {
84
+ return {
85
+ transcript: (0, models_1.transcriptFromJSON)(raw.transcript),
86
+ transcript_analysis: models_1.AnalysisResult.fromJSON(raw.transcript_analysis),
87
+ ...parseScenes(raw.scenes),
88
+ ...pickSceneNotes(raw),
89
+ };
90
+ }
91
+ function parseAnalyzeVideoData(raw, usage) {
92
+ return { video_info: models_1.VideoInfo.fromJSON(raw.video_info), ...parseAnalysisData(raw), usage };
93
+ }
56
94
  function buildAsyncJobParams(options) {
57
95
  // Like the TikTok pollers, the async job pollers take include_usage as a query string value.
58
96
  return options?.include_usage ? { include_usage: 'true' } : undefined;
@@ -138,11 +176,23 @@ class VidNavigatorClient {
138
176
  return watched;
139
177
  },
140
178
  });
179
+ this.analyze = this.defineOperation({
180
+ jobType: 'analyze_video',
181
+ submit: (input) => this.submitAsyncJob('/analyze/video/async', typeof input === 'string' ? { video_url: input } : input),
182
+ fetchTask: (task_id, options) => this.getAsyncJob(`/analyze/video/${encodeURIComponent(task_id)}`, options, (raw) => parseAnalyzeVideoData(raw)),
183
+ toResult: async (task) => ({ ...requireResult(task), usage: task.usage }),
184
+ });
141
185
  this.extractVideo = this.defineOperation({
142
186
  jobType: 'extract_video',
143
187
  submit: (input) => this.submitExtractVideo(input),
144
188
  fetchTask: (task_id, options) => this.getAsyncJob(`/extract/video/${encodeURIComponent(task_id)}`, options, (raw) => raw),
145
- toResult: async (task) => ({ data: requireResult(task), video_info: task.video_info, usage: task.usage }),
189
+ toResult: async (task) => ({
190
+ data: requireResult(task),
191
+ video_info: task.video_info,
192
+ ...pickSceneNotes(task),
193
+ ...(task.schema ? { schema: task.schema } : {}),
194
+ usage: task.usage,
195
+ }),
146
196
  });
147
197
  this.tweetStatement = this.defineOperation({
148
198
  jobType: 'tweet_statement',
@@ -202,12 +252,14 @@ class VidNavigatorClient {
202
252
  return { ...accepted, job_type: accepted.job_type ?? url.split('/')[1] };
203
253
  }
204
254
  submitExtractVideo(input) {
255
+ checkSchemaInput(input);
205
256
  if ('schemaFilePath' in input) {
206
257
  const form = new form_data_1.default();
207
258
  form.append('video_url', input.video_url);
208
259
  form.append('schema', fs_1.default.createReadStream(input.schemaFilePath));
209
260
  appendOptionalFormField(form, 'what_to_extract', input.what_to_extract);
210
261
  appendOptionalFormField(form, 'transcribe', input.transcribe);
262
+ appendOptionalFormField(form, 'include_scenes', input.include_scenes);
211
263
  appendOptionalFormField(form, 'webhook_url', input.webhook_url);
212
264
  return this.submitAsyncJob('/extract/video/async', form, form.getHeaders());
213
265
  }
@@ -361,13 +413,25 @@ class VidNavigatorClient {
361
413
  has_more: response.data.has_more,
362
414
  };
363
415
  }
416
+ /**
417
+ * A file's metadata, its transcript once it has one, and its scenes once they are analyzed.
418
+ * `file_info.scenes_status` says where the scene analysis stands; when it is `completed`, the
419
+ * result has `scenes`, as {@link VidNavigatorClient.watch} returns them for an online video.
420
+ */
364
421
  async getFile(file_id, query) {
365
422
  const response = await this.request('GET', `/file/${file_id}`, undefined, query);
366
423
  return {
367
424
  file_info: models_1.FileInfo.fromJSON(response.data.file_info),
368
425
  transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
426
+ ...parseScenes(response.data.scenes),
369
427
  };
370
428
  }
429
+ /**
430
+ * Upload an audio or video file. With `include_scenes: true` the picture of a video file is
431
+ * analyzed as well, next to its transcription: follow `file_info.scenes_status` with
432
+ * {@link VidNavigatorClient.getFile}, which returns the scenes once it is `completed`. An audio
433
+ * file has no picture: its `scenes_status` is `failed`, with `frames_not_available`.
434
+ */
371
435
  async uploadFile(options) {
372
436
  const form = new form_data_1.default();
373
437
  form.append('file', fs_1.default.createReadStream(options.filePath));
@@ -377,6 +441,7 @@ class VidNavigatorClient {
377
441
  if (options.namespace_ids?.length) {
378
442
  form.append('namespace_ids', JSON.stringify(options.namespace_ids));
379
443
  }
444
+ appendOptionalFormField(form, 'include_scenes', options.include_scenes);
380
445
  try {
381
446
  const response = await this.client.post('/upload/file', form, { headers: form.getHeaders() });
382
447
  const body = response.data;
@@ -420,6 +485,22 @@ class VidNavigatorClient {
420
485
  const response = await this.request('POST', `/file/${file_id}/retry`);
421
486
  return response.data;
422
487
  }
488
+ /**
489
+ * Start the scene analysis of a file already uploaded: what its picture shows, scene by scene,
490
+ * with the text readable on screen. The scenes of a file are analyzed once and kept with it.
491
+ *
492
+ * The answer has `scenes_status` `processing` when the analysis was started or is already
493
+ * running, and `completed` when the scenes are already there (nothing new is started). Follow
494
+ * `file_info.scenes_status` with {@link VidNavigatorClient.getFile}, which returns the scenes
495
+ * once it is `completed`; `analyzeFile` and `extractFileData` read them with `include_scenes: true`.
496
+ *
497
+ * An audio file has no picture: the call throws `BadRequestError` with `error_code`
498
+ * `frames_not_available`.
499
+ */
500
+ async analyzeFileScenes(file_id) {
501
+ const response = await this.request('POST', `/file/${file_id}/scenes`);
502
+ return response.data;
503
+ }
423
504
  async cancelFileUpload(file_id) {
424
505
  const response = await this.request('POST', `/file/${file_id}/cancel`);
425
506
  return response.data;
@@ -452,21 +533,34 @@ class VidNavigatorClient {
452
533
  }
453
534
  //endregion
454
535
  //region --- Analysis ---
536
+ /**
537
+ * Analyze an online video: a summary, the people, places and key subjects, and the answer to
538
+ * an optional `query`. With `include_scenes: true` the analysis is made from the transcript and
539
+ * from what the video shows, and the result also has `scenes` and `frames_analyzed`, as
540
+ * {@link VidNavigatorClient.watch} returns them. When the picture cannot be read, the analysis
541
+ * is made from the transcript alone and `scenes_error` says why; a video without a transcript
542
+ * is analyzed from its scenes, and `transcript_error` says why the transcript is missing.
543
+ *
544
+ * This call waits on one HTTP request. With `include_scenes` on a video longer than about
545
+ * 10 minutes, use {@link VidNavigatorClient.analyze}, which runs the same analysis as a
546
+ * background job.
547
+ */
455
548
  async analyzeVideo(payload) {
456
549
  const response = await this.request('POST', '/analyze/video', payload);
457
- return {
458
- video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
459
- transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
460
- transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
461
- usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
462
- };
550
+ return parseAnalyzeVideoData(response.data, response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined);
463
551
  }
552
+ /**
553
+ * Analyze an uploaded file. With `include_scenes: true` the analysis is made from the transcript
554
+ * of the file and its scenes together, and the result also has `scenes` and `frames_analyzed`.
555
+ * The scenes are the ones kept with the file: ask for them at the upload (`include_scenes`) or
556
+ * with {@link VidNavigatorClient.analyzeFileScenes}. A file that has none is refused with
557
+ * `ScenesNotAvailableError` (HTTP 409), whose `scenes_status` says where their analysis stands.
558
+ */
464
559
  async analyzeFile(payload) {
465
560
  const response = await this.request('POST', '/analyze/file', payload);
466
561
  return {
467
562
  file_info: models_1.FileInfo.fromJSON(response.data.file_info),
468
- transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
469
- transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
563
+ ...parseAnalysisData(response.data),
470
564
  usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
471
565
  };
472
566
  }
@@ -483,29 +577,40 @@ class VidNavigatorClient {
483
577
  * Structured-data extraction from an online video. Blocking convenience wrapper around
484
578
  * {@link VidNavigatorClient.extractVideo}: submits to `POST /extract/video/async` and polls, so
485
579
  * media of any length works. The result carries the extracted `data` and the video's `video_info`.
580
+ * With `include_scenes: true` the fields are extracted from the transcript and from what the video
581
+ * shows, and the result also has `frames_analyzed`.
486
582
  */
487
583
  async extractVideoData(payload, options) {
488
584
  const { include_usage, ...input } = payload;
489
585
  return this.extractVideo(input, { ...options, include_usage });
490
586
  }
587
+ /**
588
+ * Structured-data extraction from an uploaded file. With `include_scenes: true` the fields are
589
+ * extracted from the transcript of the file and its scenes together, and the result has
590
+ * `frames_analyzed`. The scenes are the ones kept with the file: ask for them at the upload
591
+ * (`include_scenes`) or with {@link VidNavigatorClient.analyzeFileScenes}. A file that has none
592
+ * is refused with `ScenesNotAvailableError` (HTTP 409).
593
+ */
491
594
  async extractFileData(payload) {
595
+ checkSchemaInput(payload);
596
+ let body;
492
597
  if ('schemaFilePath' in payload) {
493
598
  const form = new form_data_1.default();
494
599
  form.append('file_id', payload.file_id);
495
600
  form.append('schema', fs_1.default.createReadStream(payload.schemaFilePath));
496
601
  appendOptionalFormField(form, 'what_to_extract', payload.what_to_extract);
602
+ appendOptionalFormField(form, 'include_scenes', payload.include_scenes);
497
603
  appendOptionalFormField(form, 'include_usage', payload.include_usage);
498
- const body = await this.request('POST', '/extract/file', form, undefined, form.getHeaders());
499
- return {
500
- data: body.data,
501
- file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
502
- usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
503
- };
604
+ body = await this.request('POST', '/extract/file', form, undefined, form.getHeaders());
605
+ }
606
+ else {
607
+ body = await this.request('POST', '/extract/file', payload);
504
608
  }
505
- const body = await this.request('POST', '/extract/file', payload);
506
609
  return {
507
610
  data: body.data,
508
611
  file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
612
+ ...pickSceneNotes(body),
613
+ ...(body.schema ? { schema: body.schema } : {}),
509
614
  usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
510
615
  };
511
616
  }
@@ -1,7 +1,9 @@
1
+ import type { ExtractionSchema } from './Extraction';
1
2
  import { UsageBlock } from './Usage';
2
3
  import { VideoInfo, VideoInfoJSON } from './VideoInfo';
3
- /** Async job kinds returned by the `/transcribe/async`, `/watch/async`, `/extract/video/async` and `/tweet/statement/async` endpoints. */
4
- export type AsyncJobType = 'transcribe' | 'watch' | 'extract_video' | 'tweet_statement';
4
+ import { ScenesError, WatchTranscriptError } from './Watch';
5
+ /** Async job kinds returned by the `/transcribe/async`, `/watch/async`, `/analyze/video/async`, `/extract/video/async` and `/tweet/statement/async` endpoints. */
6
+ export type AsyncJobType = 'transcribe' | 'watch' | 'analyze_video' | 'extract_video' | 'tweet_statement';
5
7
  /** `processing` = accepted and being worked on. `completed` and `failed` are terminal. */
6
8
  export type AsyncTaskStatus = 'processing' | 'completed' | 'failed';
7
9
  /**
@@ -66,6 +68,12 @@ export interface AsyncJobJSON {
66
68
  result?: any;
67
69
  /** `extract_video` jobs, once completed: the `video_info` the synchronous endpoint returns. */
68
70
  video_info?: VideoInfoJSON;
71
+ /** `extract_video` jobs, once completed with `include_scenes`: the `frames_analyzed` the synchronous endpoint returns. */
72
+ frames_analyzed?: number;
73
+ scenes_error?: ScenesError;
74
+ transcript_error?: WatchTranscriptError;
75
+ /** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`. */
76
+ schema?: ExtractionSchema;
69
77
  error?: AsyncJobError | null;
70
78
  }
71
79
  /**
@@ -89,6 +97,14 @@ export declare class AsyncJob<TResult> {
89
97
  result: TResult | null;
90
98
  /** `extract_video` jobs, once completed: metadata of the video the data was extracted from. */
91
99
  video_info?: VideoInfo;
100
+ /** `extract_video` jobs, once completed with `include_scenes`: number of frames that were analyzed to produce the scenes. */
101
+ frames_analyzed?: number;
102
+ /** `extract_video` jobs with `include_scenes`: why the picture could not be read. The fields were then extracted from the transcript alone. */
103
+ scenes_error?: ScenesError;
104
+ /** `extract_video` jobs with `include_scenes`: why there is no transcript. The fields were then extracted from the scenes alone. */
105
+ transcript_error?: WatchTranscriptError;
106
+ /** `extract_video` jobs, once completed, when the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
107
+ schema?: ExtractionSchema;
92
108
  error: AsyncJobError | null;
93
109
  /** Per-call usage, populated only when polled with `include_usage: true` and `task_status === 'completed'`. */
94
110
  usage?: UsageBlock;
@@ -38,6 +38,10 @@ class AsyncJob {
38
38
  this.webhook = data.webhook;
39
39
  this.result = data.result !== undefined && data.result !== null ? parseResult(data.result) : null;
40
40
  this.video_info = data.video_info ? VideoInfo_1.VideoInfo.fromJSON(data.video_info) : undefined;
41
+ this.frames_analyzed = data.frames_analyzed;
42
+ this.scenes_error = data.scenes_error;
43
+ this.transcript_error = data.transcript_error;
44
+ this.schema = data.schema;
41
45
  this.error = data.error ?? null;
42
46
  }
43
47
  static fromJSON(json, parseResult) {