vidnavigator 2.3.1 → 2.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/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, 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.3.1";
10
+ export declare const SDK_VERSION = "2.5.0";
11
11
  export interface SDKConfig {
12
12
  apiKey: string;
13
13
  baseURL?: string;
@@ -42,6 +42,39 @@ export type TranscribeInput = {
42
42
  /** Instagram carousel posts only: transcribe every video in the post. */
43
43
  all_videos?: boolean;
44
44
  } & WebhookOption;
45
+ /** How closely {@link VidNavigatorClient.watch} follows the picture. */
46
+ export type WatchDetail = 'low' | 'auto' | 'high';
47
+ /** Input for {@link VidNavigatorClient.watch}. A plain string is treated as `video_url`. */
48
+ export type WatchInput = {
49
+ /** `?img_index=N` selects one video of an Instagram carousel or a Snapchat highlight. */
50
+ video_url: string;
51
+ /**
52
+ * How closely the picture is followed. Default `auto`. The number of frames depends on the
53
+ * video at every level; a higher level analyzes more frames when the picture changes often.
54
+ */
55
+ detail?: WatchDetail;
56
+ /** Default true. `false` returns the scenes only: the result has no `transcript`. */
57
+ include_transcript?: boolean;
58
+ /** Return the transcript as a single string instead of segments. */
59
+ transcript_text?: boolean;
60
+ } & WebhookOption;
61
+ /** Payload of {@link VidNavigatorClient.watchVideo}: a {@link WatchInput} with `include_usage`. */
62
+ export type WatchVideoPayload = WatchInput & {
63
+ include_usage?: boolean;
64
+ };
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;
45
78
  /** Input for {@link VidNavigatorClient.extractVideo}: a JSON `schema`, or a JSON/YAML `schemaFilePath`. */
46
79
  export type ExtractVideoInput = ({
47
80
  video_url: string;
@@ -49,12 +82,18 @@ export type ExtractVideoInput = ({
49
82
  what_to_extract?: string;
50
83
  /** Speech-to-text the audio when no platform transcript exists. Default true. */
51
84
  transcribe?: boolean;
85
+ /**
86
+ * Default false. `true` also reads what the video shows: the fields are extracted from the
87
+ * transcript and the scenes together, and the result has `frames_analyzed`.
88
+ */
89
+ include_scenes?: boolean;
52
90
  } & WebhookOption) | ({
53
91
  video_url: string;
54
92
  /** Path to a JSON or YAML schema file (sent as multipart form-data). */
55
93
  schemaFilePath: string;
56
94
  what_to_extract?: string;
57
95
  transcribe?: boolean;
96
+ include_scenes?: boolean;
58
97
  } & WebhookOption);
59
98
  /** Input for {@link VidNavigatorClient.tweetStatement}. A plain string is treated as `tweet_id`. */
60
99
  export type TweetStatementInput = {
@@ -78,6 +117,10 @@ export type TranscribeVideoCarouselResult = {
78
117
  export type TranscribeVideoResult = TranscribeVideoSingleResult | TranscribeVideoCarouselResult;
79
118
  /** Snapshot of a transcription task. `result` has the same shape as {@link VidNavigatorClient.transcribe}'s return value. */
80
119
  export type TranscribeAsyncJob = AsyncJob<TranscribeVideoResult>;
120
+ /** Snapshot of a watch task. `result` is a {@link WatchResult}. */
121
+ export type WatchAsyncJob = AsyncJob<WatchResult>;
122
+ /** Snapshot of a video analysis task. `result` has the same shape as {@link VidNavigatorClient.analyzeVideo}'s return value. */
123
+ export type AnalyzeVideoAsyncJob = AsyncJob<AnalyzeVideoResult>;
81
124
  /** Snapshot of an extraction task. `result` is the extracted object, shaped like your schema. */
82
125
  export type ExtractVideoAsyncJob = AsyncJob<Record<string, unknown>>;
83
126
  /** Snapshot of a tweet claim analysis task. `result` is a {@link TweetStatement}. */
@@ -97,6 +140,8 @@ export interface TranscribeOperation extends JobOperation<string | TranscribeInp
97
140
  submit(input: SingleTranscribeInput, options?: SubmitOptions): Promise<Job<TranscribeAsyncJob, TranscribeVideoSingleResult>>;
98
141
  submit(input: string | TranscribeInput, options?: SubmitOptions): Promise<Job<TranscribeAsyncJob, TranscribeVideoResult>>;
99
142
  }
143
+ export type WatchJob = Job<WatchAsyncJob, WatchResult>;
144
+ export type AnalyzeVideoJob = Job<AnalyzeVideoAsyncJob, AnalyzeVideoResult>;
100
145
  export type ExtractVideoJob = Job<ExtractVideoAsyncJob, ExtractDataResult>;
101
146
  export type TweetStatementJob = Job<TweetStatementAsyncJob, TweetStatement>;
102
147
  /** `result()` resolves to the completed task with **all** pages of `videos` collected. */
@@ -123,10 +168,31 @@ export type UploadFileAcceptedResult = {
123
168
  file_info?: FileInfo;
124
169
  };
125
170
  export type UploadFileResult = UploadFileSuccessResult | UploadFileAcceptedResult;
171
+ /** Answer of {@link VidNavigatorClient.analyzeFileScenes}. */
172
+ export type AnalyzeFileScenesResult = {
173
+ file_id: string;
174
+ /** `processing`: the analysis was started, or is already running. `completed`: the scenes are already there. */
175
+ scenes_status: Extract<FileScenesStatus, 'processing' | 'completed'>;
176
+ message: string;
177
+ };
178
+ /** Answer of {@link VidNavigatorClient.getFile}. */
179
+ export type GetFileResult = {
180
+ file_info: FileInfo;
181
+ /** Present once the file has a transcript. */
182
+ transcript?: TranscriptOutput;
183
+ /** What the file shows, in chronological order. Present once `file_info.scenes_status` is `completed`. */
184
+ scenes?: VideoScene[];
185
+ };
126
186
  export interface ExtractDataResult {
127
187
  data: Record<string, unknown>;
128
188
  video_info?: VideoInfo;
129
189
  file_info?: FileInfo;
190
+ /** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
191
+ frames_analyzed?: number;
192
+ /** With `include_scenes: true`, when the picture could not be read: the fields were extracted from the transcript alone. */
193
+ scenes_error?: ScenesError;
194
+ /** With `include_scenes: true`, when there is no transcript: the fields were extracted from the scenes alone. */
195
+ transcript_error?: WatchTranscriptError;
130
196
  usage?: UsageBlock;
131
197
  }
132
198
  /**
@@ -175,12 +241,24 @@ export type SearchFilesResult = {
175
241
  export type AnalyzeVideoPayload = {
176
242
  video_url: string;
177
243
  query?: string;
244
+ /**
245
+ * Default false. `true` also reads what the video shows: the analysis is made from the
246
+ * transcript and the scenes together, and the result has `scenes` and `frames_analyzed`.
247
+ */
248
+ include_scenes?: boolean;
178
249
  transcript_text?: boolean;
179
250
  include_usage?: boolean;
180
251
  };
181
252
  export type AnalyzeFilePayload = {
182
253
  file_id: string;
183
254
  query?: string;
255
+ /**
256
+ * Default false. `true` analyzes the file from its transcript and its scenes together. The
257
+ * scenes are the ones kept with the file: ask for them at the upload (`include_scenes`) or with
258
+ * {@link VidNavigatorClient.analyzeFileScenes}. A file that has none is refused with
259
+ * `ScenesNotAvailableError`.
260
+ */
261
+ include_scenes?: boolean;
184
262
  transcript_text?: boolean;
185
263
  include_usage?: boolean;
186
264
  };
@@ -188,12 +266,31 @@ export type AnalyzeVideoResult = {
188
266
  video_info: VideoInfo;
189
267
  transcript: TranscriptOutput;
190
268
  transcript_analysis: AnalysisResult;
269
+ /**
270
+ * With `include_scenes: true`: what the video shows, in chronological order. Empty when the
271
+ * picture could not be read (see `scenes_error`).
272
+ */
273
+ scenes?: VideoScene[];
274
+ /** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
275
+ frames_analyzed?: number;
276
+ /** With `include_scenes: true`, when the picture could not be read: the analysis was made from the transcript alone. */
277
+ scenes_error?: ScenesError;
278
+ /** With `include_scenes: true`, when there is no transcript: the analysis was made from the scenes alone. */
279
+ transcript_error?: WatchTranscriptError;
191
280
  usage?: UsageBlock;
192
281
  };
193
282
  export type AnalyzeFileResult = {
194
283
  file_info: FileInfo;
195
284
  transcript: TranscriptOutput;
196
285
  transcript_analysis: AnalysisResult;
286
+ /** With `include_scenes: true`: what the file shows, in chronological order. */
287
+ scenes?: VideoScene[];
288
+ /** With `include_scenes: true`: number of frames that were analyzed to produce the scenes. */
289
+ frames_analyzed?: number;
290
+ /** 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. */
291
+ scenes_error?: ScenesError;
292
+ /** With `include_scenes: true`, when the file has no speech: the analysis was made from the scenes alone. */
293
+ transcript_error?: WatchTranscriptError;
197
294
  usage?: UsageBlock;
198
295
  };
199
296
  export type ExtractVideoDataPayload = {
@@ -201,6 +298,11 @@ export type ExtractVideoDataPayload = {
201
298
  schema: ExtractionSchema;
202
299
  what_to_extract?: string;
203
300
  transcribe?: boolean;
301
+ /**
302
+ * Default false. `true` also reads what the video shows: the fields are extracted from the
303
+ * transcript and the scenes together, and the result has `frames_analyzed`.
304
+ */
305
+ include_scenes?: boolean;
204
306
  include_usage?: boolean;
205
307
  } & WebhookOption;
206
308
  export type ExtractVideoDataMultipartPayload = {
@@ -209,6 +311,7 @@ export type ExtractVideoDataMultipartPayload = {
209
311
  schemaFilePath: string;
210
312
  what_to_extract?: string;
211
313
  transcribe?: boolean;
314
+ include_scenes?: boolean;
212
315
  include_usage?: boolean;
213
316
  } & WebhookOption;
214
317
  export type TweetStatementPayload = {
@@ -218,6 +321,13 @@ export type ExtractFileDataPayload = {
218
321
  file_id: string;
219
322
  schema: ExtractionSchema;
220
323
  what_to_extract?: string;
324
+ /**
325
+ * Default false. `true` extracts from the transcript of the file and its scenes together. The
326
+ * scenes are the ones kept with the file: ask for them at the upload (`include_scenes`) or with
327
+ * {@link VidNavigatorClient.analyzeFileScenes}. A file that has none is refused with
328
+ * `ScenesNotAvailableError`.
329
+ */
330
+ include_scenes?: boolean;
221
331
  include_usage?: boolean;
222
332
  };
223
333
  export type ExtractFileDataMultipartPayload = {
@@ -225,6 +335,7 @@ export type ExtractFileDataMultipartPayload = {
225
335
  /** Path to a JSON or YAML schema file. The API accepts either a raw schema or a full extraction request object. */
226
336
  schemaFilePath: string;
227
337
  what_to_extract?: string;
338
+ include_scenes?: boolean;
228
339
  include_usage?: boolean;
229
340
  };
230
341
  export declare class VidNavigatorClient {
@@ -238,9 +349,28 @@ export declare class VidNavigatorClient {
238
349
  * - `vn.transcribe.resume(task_id)` reattaches to a job you already submitted.
239
350
  */
240
351
  readonly transcribe: TranscribeOperation;
352
+ /**
353
+ * What a video shows, scene by scene, next to what it says, built on `POST /watch/async`. The
354
+ * result is a {@link WatchResult}: `scenes` (for each one its `start` and `end` in seconds, a
355
+ * `description` of the picture and the `on_screen_text`), the `transcript` and `frames_analyzed`.
356
+ * Works with every platform `getTranscript` and `transcribe` support.
357
+ *
358
+ * A video without a transcript is not an error: `transcript` is empty and `transcript_error`
359
+ * says why. Same shapes as {@link VidNavigatorClient.transcribe}.
360
+ */
361
+ readonly watch: JobOperation<string | WatchInput, WatchAsyncJob, WatchResult>;
362
+ /**
363
+ * Analysis of an online video as a background job, built on `POST /analyze/video/async`: the
364
+ * same analysis and the same result as {@link VidNavigatorClient.analyzeVideo}, without holding
365
+ * a connection open while it runs. Use it with `include_scenes: true` on a video longer than
366
+ * about 10 minutes. Same shapes as {@link VidNavigatorClient.transcribe}.
367
+ */
368
+ readonly analyze: JobOperation<string | AnalyzeVideoInput, AnalyzeVideoAsyncJob, AnalyzeVideoResult>;
241
369
  /**
242
370
  * Structured-data extraction from a video of any length, built on `POST /extract/video/async`.
243
- * The schema is validated when you submit. Same shapes as {@link VidNavigatorClient.transcribe}.
371
+ * The schema is validated when you submit. With `include_scenes: true` the fields are extracted
372
+ * from the transcript and from what the video shows. Same shapes as
373
+ * {@link VidNavigatorClient.transcribe}.
244
374
  */
245
375
  readonly extractVideo: JobOperation<ExtractVideoInput, ExtractVideoAsyncJob, ExtractDataResult>;
246
376
  /**
@@ -287,6 +417,12 @@ export declare class VidNavigatorClient {
287
417
  * submits to `POST /transcribe/async` and polls until the job finishes, so media of any length works.
288
418
  */
289
419
  transcribeVideo(payload: TranscribeVideoPayload, options?: PollOptions<TranscribeAsyncJob>): Promise<TranscribeVideoResult>;
420
+ /**
421
+ * What a video shows, scene by scene, next to what it says. Blocking convenience wrapper around
422
+ * {@link VidNavigatorClient.watch}: submits to `POST /watch/async` and polls until the job
423
+ * finishes, so media of any length works.
424
+ */
425
+ watchVideo(payload: WatchVideoPayload, options?: PollOptions<WatchAsyncJob>): Promise<WatchResult>;
290
426
  submitTikTokProfileScrape(payload: TikTokProfileScrapeRequest): Promise<TikTokProfileScrapeSubmission>;
291
427
  getTikTokProfileScrape(task_id: string, query?: {
292
428
  cursor?: string;
@@ -328,16 +464,26 @@ export declare class VidNavigatorClient {
328
464
  offset: number;
329
465
  has_more: boolean;
330
466
  }>;
467
+ /**
468
+ * A file's metadata, its transcript once it has one, and its scenes once they are analyzed.
469
+ * `file_info.scenes_status` says where the scene analysis stands; when it is `completed`, the
470
+ * result has `scenes`, as {@link VidNavigatorClient.watch} returns them for an online video.
471
+ */
331
472
  getFile(file_id: string, query?: {
332
473
  transcript_text?: boolean;
333
- }): Promise<{
334
- file_info: FileInfo;
335
- transcript?: TranscriptOutput;
336
- }>;
474
+ }): Promise<GetFileResult>;
475
+ /**
476
+ * Upload an audio or video file. With `include_scenes: true` the picture of a video file is
477
+ * analyzed as well, next to its transcription: follow `file_info.scenes_status` with
478
+ * {@link VidNavigatorClient.getFile}, which returns the scenes once it is `completed`. An audio
479
+ * file has no picture: its `scenes_status` is `failed`, with `frames_not_available`.
480
+ */
337
481
  uploadFile(options: {
338
482
  filePath: string;
339
483
  wait_for_completion?: boolean;
340
484
  namespace_ids?: string[];
485
+ /** Default false. `true` also analyzes the scenes of the file (video files only). */
486
+ include_scenes?: boolean;
341
487
  }): Promise<UploadFileResult>;
342
488
  deleteFile(file_id: string): Promise<{
343
489
  file_id: string;
@@ -354,6 +500,19 @@ export declare class VidNavigatorClient {
354
500
  file_status: string;
355
501
  message: string;
356
502
  }>;
503
+ /**
504
+ * Start the scene analysis of a file already uploaded: what its picture shows, scene by scene,
505
+ * with the text readable on screen. The scenes of a file are analyzed once and kept with it.
506
+ *
507
+ * The answer has `scenes_status` `processing` when the analysis was started or is already
508
+ * running, and `completed` when the scenes are already there (nothing new is started). Follow
509
+ * `file_info.scenes_status` with {@link VidNavigatorClient.getFile}, which returns the scenes
510
+ * once it is `completed`; `analyzeFile` and `extractFileData` read them with `include_scenes: true`.
511
+ *
512
+ * An audio file has no picture: the call throws `BadRequestError` with `error_code`
513
+ * `frames_not_available`.
514
+ */
515
+ analyzeFileScenes(file_id: string): Promise<AnalyzeFileScenesResult>;
357
516
  cancelFileUpload(file_id: string): Promise<{
358
517
  file_id: string;
359
518
  file_name: string;
@@ -378,7 +537,26 @@ export declare class VidNavigatorClient {
378
537
  namespace_ids: string[];
379
538
  namespaces: NamespaceRef[];
380
539
  }>;
540
+ /**
541
+ * Analyze an online video: a summary, the people, places and key subjects, and the answer to
542
+ * an optional `query`. With `include_scenes: true` the analysis is made from the transcript and
543
+ * from what the video shows, and the result also has `scenes` and `frames_analyzed`, as
544
+ * {@link VidNavigatorClient.watch} returns them. When the picture cannot be read, the analysis
545
+ * is made from the transcript alone and `scenes_error` says why; a video without a transcript
546
+ * is analyzed from its scenes, and `transcript_error` says why the transcript is missing.
547
+ *
548
+ * This call waits on one HTTP request. With `include_scenes` on a video longer than about
549
+ * 10 minutes, use {@link VidNavigatorClient.analyze}, which runs the same analysis as a
550
+ * background job.
551
+ */
381
552
  analyzeVideo(payload: AnalyzeVideoPayload): Promise<AnalyzeVideoResult>;
553
+ /**
554
+ * Analyze an uploaded file. With `include_scenes: true` the analysis is made from the transcript
555
+ * of the file and its scenes together, and the result also has `scenes` and `frames_analyzed`.
556
+ * The scenes are the ones kept with the file: ask for them at the upload (`include_scenes`) or
557
+ * with {@link VidNavigatorClient.analyzeFileScenes}. A file that has none is refused with
558
+ * `ScenesNotAvailableError` (HTTP 409), whose `scenes_status` says where their analysis stands.
559
+ */
382
560
  analyzeFile(payload: AnalyzeFilePayload): Promise<AnalyzeFileResult>;
383
561
  /**
384
562
  * Structured claim analysis of an X/Twitter tweet. Blocking convenience wrapper around
@@ -389,8 +567,17 @@ export declare class VidNavigatorClient {
389
567
  * Structured-data extraction from an online video. Blocking convenience wrapper around
390
568
  * {@link VidNavigatorClient.extractVideo}: submits to `POST /extract/video/async` and polls, so
391
569
  * media of any length works. The result carries the extracted `data` and the video's `video_info`.
570
+ * With `include_scenes: true` the fields are extracted from the transcript and from what the video
571
+ * shows, and the result also has `frames_analyzed`.
392
572
  */
393
573
  extractVideoData(payload: ExtractVideoDataPayload | ExtractVideoDataMultipartPayload, options?: PollOptions<ExtractVideoAsyncJob>): Promise<ExtractDataResult>;
574
+ /**
575
+ * Structured-data extraction from an uploaded file. With `include_scenes: true` the fields are
576
+ * extracted from the transcript of the file and its scenes together, and the result has
577
+ * `frames_analyzed`. The scenes are the ones kept with the file: ask for them at the upload
578
+ * (`include_scenes`) or with {@link VidNavigatorClient.analyzeFileScenes}. A file that has none
579
+ * is refused with `ScenesNotAvailableError` (HTTP 409).
580
+ */
394
581
  extractFileData(payload: ExtractFileDataPayload | ExtractFileDataMultipartPayload): Promise<ExtractDataResult>;
395
582
  /**
396
583
  * 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.3.1';
34
+ exports.SDK_VERSION = '2.5.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,32 @@ function parseTranscribeData(inner, usage) {
53
53
  usage,
54
54
  };
55
55
  }
56
+ // The scene fields are set only when the response carries them, so a result asked without
57
+ // `include_scenes` keeps the shape it always had.
58
+ function pickSceneNotes(raw) {
59
+ const notes = {};
60
+ if (raw.frames_analyzed != null)
61
+ notes.frames_analyzed = raw.frames_analyzed;
62
+ if (raw.scenes_error)
63
+ notes.scenes_error = raw.scenes_error;
64
+ if (raw.transcript_error)
65
+ notes.transcript_error = raw.transcript_error;
66
+ return notes;
67
+ }
68
+ function parseScenes(raw) {
69
+ return raw ? { scenes: raw.map((scene) => models_1.VideoScene.fromJSON(scene)) } : {};
70
+ }
71
+ function parseAnalysisData(raw) {
72
+ return {
73
+ transcript: (0, models_1.transcriptFromJSON)(raw.transcript),
74
+ transcript_analysis: models_1.AnalysisResult.fromJSON(raw.transcript_analysis),
75
+ ...parseScenes(raw.scenes),
76
+ ...pickSceneNotes(raw),
77
+ };
78
+ }
79
+ function parseAnalyzeVideoData(raw, usage) {
80
+ return { video_info: models_1.VideoInfo.fromJSON(raw.video_info), ...parseAnalysisData(raw), usage };
81
+ }
56
82
  function buildAsyncJobParams(options) {
57
83
  // Like the TikTok pollers, the async job pollers take include_usage as a query string value.
58
84
  return options?.include_usage ? { include_usage: 'true' } : undefined;
@@ -128,11 +154,32 @@ class VidNavigatorClient {
128
154
  fetchTask: (task_id, options) => this.getAsyncJob(`/transcribe/${encodeURIComponent(task_id)}`, options, (raw) => parseTranscribeData(raw)),
129
155
  toResult: async (task) => ({ ...requireResult(task), usage: task.usage }),
130
156
  });
157
+ this.watch = this.defineOperation({
158
+ jobType: 'watch',
159
+ submit: (input) => this.submitAsyncJob('/watch/async', typeof input === 'string' ? { video_url: input } : input),
160
+ fetchTask: (task_id, options) => this.getAsyncJob(`/watch/${encodeURIComponent(task_id)}`, options, (raw) => models_1.WatchResult.fromJSON(raw)),
161
+ toResult: async (task) => {
162
+ const watched = requireResult(task);
163
+ watched.usage = task.usage;
164
+ return watched;
165
+ },
166
+ });
167
+ this.analyze = this.defineOperation({
168
+ jobType: 'analyze_video',
169
+ submit: (input) => this.submitAsyncJob('/analyze/video/async', typeof input === 'string' ? { video_url: input } : input),
170
+ fetchTask: (task_id, options) => this.getAsyncJob(`/analyze/video/${encodeURIComponent(task_id)}`, options, (raw) => parseAnalyzeVideoData(raw)),
171
+ toResult: async (task) => ({ ...requireResult(task), usage: task.usage }),
172
+ });
131
173
  this.extractVideo = this.defineOperation({
132
174
  jobType: 'extract_video',
133
175
  submit: (input) => this.submitExtractVideo(input),
134
176
  fetchTask: (task_id, options) => this.getAsyncJob(`/extract/video/${encodeURIComponent(task_id)}`, options, (raw) => raw),
135
- toResult: async (task) => ({ data: requireResult(task), video_info: task.video_info, usage: task.usage }),
177
+ toResult: async (task) => ({
178
+ data: requireResult(task),
179
+ video_info: task.video_info,
180
+ ...pickSceneNotes(task),
181
+ usage: task.usage,
182
+ }),
136
183
  });
137
184
  this.tweetStatement = this.defineOperation({
138
185
  jobType: 'tweet_statement',
@@ -198,6 +245,7 @@ class VidNavigatorClient {
198
245
  form.append('schema', fs_1.default.createReadStream(input.schemaFilePath));
199
246
  appendOptionalFormField(form, 'what_to_extract', input.what_to_extract);
200
247
  appendOptionalFormField(form, 'transcribe', input.transcribe);
248
+ appendOptionalFormField(form, 'include_scenes', input.include_scenes);
201
249
  appendOptionalFormField(form, 'webhook_url', input.webhook_url);
202
250
  return this.submitAsyncJob('/extract/video/async', form, form.getHeaders());
203
251
  }
@@ -265,6 +313,17 @@ class VidNavigatorClient {
265
313
  return this.transcribe(input, { ...options, include_usage });
266
314
  }
267
315
  //endregion
316
+ //region --- Watch ---
317
+ /**
318
+ * What a video shows, scene by scene, next to what it says. Blocking convenience wrapper around
319
+ * {@link VidNavigatorClient.watch}: submits to `POST /watch/async` and polls until the job
320
+ * finishes, so media of any length works.
321
+ */
322
+ async watchVideo(payload, options) {
323
+ const { include_usage, ...input } = payload;
324
+ return this.watch(input, { ...options, include_usage });
325
+ }
326
+ //endregion
268
327
  //region --- TikTok ---
269
328
  async submitTikTokProfileScrape(payload) {
270
329
  const response = await this.request('POST', '/tiktok/profile', payload);
@@ -340,13 +399,25 @@ class VidNavigatorClient {
340
399
  has_more: response.data.has_more,
341
400
  };
342
401
  }
402
+ /**
403
+ * A file's metadata, its transcript once it has one, and its scenes once they are analyzed.
404
+ * `file_info.scenes_status` says where the scene analysis stands; when it is `completed`, the
405
+ * result has `scenes`, as {@link VidNavigatorClient.watch} returns them for an online video.
406
+ */
343
407
  async getFile(file_id, query) {
344
408
  const response = await this.request('GET', `/file/${file_id}`, undefined, query);
345
409
  return {
346
410
  file_info: models_1.FileInfo.fromJSON(response.data.file_info),
347
411
  transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
412
+ ...parseScenes(response.data.scenes),
348
413
  };
349
414
  }
415
+ /**
416
+ * Upload an audio or video file. With `include_scenes: true` the picture of a video file is
417
+ * analyzed as well, next to its transcription: follow `file_info.scenes_status` with
418
+ * {@link VidNavigatorClient.getFile}, which returns the scenes once it is `completed`. An audio
419
+ * file has no picture: its `scenes_status` is `failed`, with `frames_not_available`.
420
+ */
350
421
  async uploadFile(options) {
351
422
  const form = new form_data_1.default();
352
423
  form.append('file', fs_1.default.createReadStream(options.filePath));
@@ -356,6 +427,7 @@ class VidNavigatorClient {
356
427
  if (options.namespace_ids?.length) {
357
428
  form.append('namespace_ids', JSON.stringify(options.namespace_ids));
358
429
  }
430
+ appendOptionalFormField(form, 'include_scenes', options.include_scenes);
359
431
  try {
360
432
  const response = await this.client.post('/upload/file', form, { headers: form.getHeaders() });
361
433
  const body = response.data;
@@ -399,6 +471,22 @@ class VidNavigatorClient {
399
471
  const response = await this.request('POST', `/file/${file_id}/retry`);
400
472
  return response.data;
401
473
  }
474
+ /**
475
+ * Start the scene analysis of a file already uploaded: what its picture shows, scene by scene,
476
+ * with the text readable on screen. The scenes of a file are analyzed once and kept with it.
477
+ *
478
+ * The answer has `scenes_status` `processing` when the analysis was started or is already
479
+ * running, and `completed` when the scenes are already there (nothing new is started). Follow
480
+ * `file_info.scenes_status` with {@link VidNavigatorClient.getFile}, which returns the scenes
481
+ * once it is `completed`; `analyzeFile` and `extractFileData` read them with `include_scenes: true`.
482
+ *
483
+ * An audio file has no picture: the call throws `BadRequestError` with `error_code`
484
+ * `frames_not_available`.
485
+ */
486
+ async analyzeFileScenes(file_id) {
487
+ const response = await this.request('POST', `/file/${file_id}/scenes`);
488
+ return response.data;
489
+ }
402
490
  async cancelFileUpload(file_id) {
403
491
  const response = await this.request('POST', `/file/${file_id}/cancel`);
404
492
  return response.data;
@@ -431,21 +519,34 @@ class VidNavigatorClient {
431
519
  }
432
520
  //endregion
433
521
  //region --- Analysis ---
522
+ /**
523
+ * Analyze an online video: a summary, the people, places and key subjects, and the answer to
524
+ * an optional `query`. With `include_scenes: true` the analysis is made from the transcript and
525
+ * from what the video shows, and the result also has `scenes` and `frames_analyzed`, as
526
+ * {@link VidNavigatorClient.watch} returns them. When the picture cannot be read, the analysis
527
+ * is made from the transcript alone and `scenes_error` says why; a video without a transcript
528
+ * is analyzed from its scenes, and `transcript_error` says why the transcript is missing.
529
+ *
530
+ * This call waits on one HTTP request. With `include_scenes` on a video longer than about
531
+ * 10 minutes, use {@link VidNavigatorClient.analyze}, which runs the same analysis as a
532
+ * background job.
533
+ */
434
534
  async analyzeVideo(payload) {
435
535
  const response = await this.request('POST', '/analyze/video', payload);
436
- return {
437
- video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
438
- transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
439
- transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
440
- usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
441
- };
536
+ return parseAnalyzeVideoData(response.data, response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined);
442
537
  }
538
+ /**
539
+ * Analyze an uploaded file. With `include_scenes: true` the analysis is made from the transcript
540
+ * of the file and its scenes together, and the result also has `scenes` and `frames_analyzed`.
541
+ * The scenes are the ones kept with the file: ask for them at the upload (`include_scenes`) or
542
+ * with {@link VidNavigatorClient.analyzeFileScenes}. A file that has none is refused with
543
+ * `ScenesNotAvailableError` (HTTP 409), whose `scenes_status` says where their analysis stands.
544
+ */
443
545
  async analyzeFile(payload) {
444
546
  const response = await this.request('POST', '/analyze/file', payload);
445
547
  return {
446
548
  file_info: models_1.FileInfo.fromJSON(response.data.file_info),
447
- transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
448
- transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
549
+ ...parseAnalysisData(response.data),
449
550
  usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
450
551
  };
451
552
  }
@@ -462,29 +563,38 @@ class VidNavigatorClient {
462
563
  * Structured-data extraction from an online video. Blocking convenience wrapper around
463
564
  * {@link VidNavigatorClient.extractVideo}: submits to `POST /extract/video/async` and polls, so
464
565
  * media of any length works. The result carries the extracted `data` and the video's `video_info`.
566
+ * With `include_scenes: true` the fields are extracted from the transcript and from what the video
567
+ * shows, and the result also has `frames_analyzed`.
465
568
  */
466
569
  async extractVideoData(payload, options) {
467
570
  const { include_usage, ...input } = payload;
468
571
  return this.extractVideo(input, { ...options, include_usage });
469
572
  }
573
+ /**
574
+ * Structured-data extraction from an uploaded file. With `include_scenes: true` the fields are
575
+ * extracted from the transcript of the file and its scenes together, and the result has
576
+ * `frames_analyzed`. The scenes are the ones kept with the file: ask for them at the upload
577
+ * (`include_scenes`) or with {@link VidNavigatorClient.analyzeFileScenes}. A file that has none
578
+ * is refused with `ScenesNotAvailableError` (HTTP 409).
579
+ */
470
580
  async extractFileData(payload) {
581
+ let body;
471
582
  if ('schemaFilePath' in payload) {
472
583
  const form = new form_data_1.default();
473
584
  form.append('file_id', payload.file_id);
474
585
  form.append('schema', fs_1.default.createReadStream(payload.schemaFilePath));
475
586
  appendOptionalFormField(form, 'what_to_extract', payload.what_to_extract);
587
+ appendOptionalFormField(form, 'include_scenes', payload.include_scenes);
476
588
  appendOptionalFormField(form, 'include_usage', payload.include_usage);
477
- const body = await this.request('POST', '/extract/file', form, undefined, form.getHeaders());
478
- return {
479
- data: body.data,
480
- file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
481
- usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
482
- };
589
+ body = await this.request('POST', '/extract/file', form, undefined, form.getHeaders());
590
+ }
591
+ else {
592
+ body = await this.request('POST', '/extract/file', payload);
483
593
  }
484
- const body = await this.request('POST', '/extract/file', payload);
485
594
  return {
486
595
  data: body.data,
487
596
  file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
597
+ ...pickSceneNotes(body),
488
598
  usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
489
599
  };
490
600
  }
@@ -1,7 +1,8 @@
1
1
  import { UsageBlock } from './Usage';
2
2
  import { VideoInfo, VideoInfoJSON } from './VideoInfo';
3
- /** Async job kinds returned by the `/transcribe/async`, `/extract/video/async` and `/tweet/statement/async` endpoints. */
4
- export type AsyncJobType = 'transcribe' | 'extract_video' | 'tweet_statement';
3
+ import { ScenesError, WatchTranscriptError } from './Watch';
4
+ /** Async job kinds returned by the `/transcribe/async`, `/watch/async`, `/analyze/video/async`, `/extract/video/async` and `/tweet/statement/async` endpoints. */
5
+ export type AsyncJobType = 'transcribe' | 'watch' | 'analyze_video' | 'extract_video' | 'tweet_statement';
5
6
  /** `processing` = accepted and being worked on. `completed` and `failed` are terminal. */
6
7
  export type AsyncTaskStatus = 'processing' | 'completed' | 'failed';
7
8
  /**
@@ -66,6 +67,10 @@ export interface AsyncJobJSON {
66
67
  result?: any;
67
68
  /** `extract_video` jobs, once completed: the `video_info` the synchronous endpoint returns. */
68
69
  video_info?: VideoInfoJSON;
70
+ /** `extract_video` jobs, once completed with `include_scenes`: the `frames_analyzed` the synchronous endpoint returns. */
71
+ frames_analyzed?: number;
72
+ scenes_error?: ScenesError;
73
+ transcript_error?: WatchTranscriptError;
69
74
  error?: AsyncJobError | null;
70
75
  }
71
76
  /**
@@ -89,6 +94,12 @@ export declare class AsyncJob<TResult> {
89
94
  result: TResult | null;
90
95
  /** `extract_video` jobs, once completed: metadata of the video the data was extracted from. */
91
96
  video_info?: VideoInfo;
97
+ /** `extract_video` jobs, once completed with `include_scenes`: number of frames that were analyzed to produce the scenes. */
98
+ frames_analyzed?: number;
99
+ /** `extract_video` jobs with `include_scenes`: why the picture could not be read. The fields were then extracted from the transcript alone. */
100
+ scenes_error?: ScenesError;
101
+ /** `extract_video` jobs with `include_scenes`: why there is no transcript. The fields were then extracted from the scenes alone. */
102
+ transcript_error?: WatchTranscriptError;
92
103
  error: AsyncJobError | null;
93
104
  /** Per-call usage, populated only when polled with `include_usage: true` and `task_status === 'completed'`. */
94
105
  usage?: UsageBlock;
@@ -38,6 +38,9 @@ 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;
41
44
  this.error = data.error ?? null;
42
45
  }
43
46
  static fromJSON(json, parseResult) {