vidnavigator 2.4.0 → 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/README.md +137 -20
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +17 -4
- package/dist/http.js +5 -0
- package/dist/index.d.ts +155 -7
- package/dist/index.js +106 -17
- package/dist/models/AsyncJob.d.ts +13 -2
- package/dist/models/AsyncJob.js +3 -0
- package/dist/models/Extraction.d.ts +5 -0
- package/dist/models/FileInfo.d.ts +15 -0
- package/dist/models/FileInfo.js +3 -0
- package/dist/models/Watch.d.ts +7 -2
- package/dist/models/Watch.js +1 -1
- package/dist/webhooks.d.ts +3 -3
- package/package.json +1 -1
- package/src/errors.ts +29 -0
- package/src/http.ts +14 -0
- package/src/index.ts +261 -47
- package/src/models/AsyncJob.ts +16 -2
- package/src/models/Extraction.ts +57 -52
- package/src/models/FileInfo.ts +19 -0
- package/src/models/Watch.ts +8 -2
- package/src/webhooks.ts +4 -2
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.
|
|
10
|
+
export declare const SDK_VERSION = "2.5.0";
|
|
11
11
|
export interface SDKConfig {
|
|
12
12
|
apiKey: string;
|
|
13
13
|
baseURL?: string;
|
|
@@ -62,6 +62,19 @@ export type WatchInput = {
|
|
|
62
62
|
export type WatchVideoPayload = WatchInput & {
|
|
63
63
|
include_usage?: boolean;
|
|
64
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;
|
|
65
78
|
/** Input for {@link VidNavigatorClient.extractVideo}: a JSON `schema`, or a JSON/YAML `schemaFilePath`. */
|
|
66
79
|
export type ExtractVideoInput = ({
|
|
67
80
|
video_url: string;
|
|
@@ -69,12 +82,18 @@ export type ExtractVideoInput = ({
|
|
|
69
82
|
what_to_extract?: string;
|
|
70
83
|
/** Speech-to-text the audio when no platform transcript exists. Default true. */
|
|
71
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;
|
|
72
90
|
} & WebhookOption) | ({
|
|
73
91
|
video_url: string;
|
|
74
92
|
/** Path to a JSON or YAML schema file (sent as multipart form-data). */
|
|
75
93
|
schemaFilePath: string;
|
|
76
94
|
what_to_extract?: string;
|
|
77
95
|
transcribe?: boolean;
|
|
96
|
+
include_scenes?: boolean;
|
|
78
97
|
} & WebhookOption);
|
|
79
98
|
/** Input for {@link VidNavigatorClient.tweetStatement}. A plain string is treated as `tweet_id`. */
|
|
80
99
|
export type TweetStatementInput = {
|
|
@@ -100,6 +119,8 @@ export type TranscribeVideoResult = TranscribeVideoSingleResult | TranscribeVide
|
|
|
100
119
|
export type TranscribeAsyncJob = AsyncJob<TranscribeVideoResult>;
|
|
101
120
|
/** Snapshot of a watch task. `result` is a {@link WatchResult}. */
|
|
102
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>;
|
|
103
124
|
/** Snapshot of an extraction task. `result` is the extracted object, shaped like your schema. */
|
|
104
125
|
export type ExtractVideoAsyncJob = AsyncJob<Record<string, unknown>>;
|
|
105
126
|
/** Snapshot of a tweet claim analysis task. `result` is a {@link TweetStatement}. */
|
|
@@ -120,6 +141,7 @@ export interface TranscribeOperation extends JobOperation<string | TranscribeInp
|
|
|
120
141
|
submit(input: string | TranscribeInput, options?: SubmitOptions): Promise<Job<TranscribeAsyncJob, TranscribeVideoResult>>;
|
|
121
142
|
}
|
|
122
143
|
export type WatchJob = Job<WatchAsyncJob, WatchResult>;
|
|
144
|
+
export type AnalyzeVideoJob = Job<AnalyzeVideoAsyncJob, AnalyzeVideoResult>;
|
|
123
145
|
export type ExtractVideoJob = Job<ExtractVideoAsyncJob, ExtractDataResult>;
|
|
124
146
|
export type TweetStatementJob = Job<TweetStatementAsyncJob, TweetStatement>;
|
|
125
147
|
/** `result()` resolves to the completed task with **all** pages of `videos` collected. */
|
|
@@ -146,10 +168,31 @@ export type UploadFileAcceptedResult = {
|
|
|
146
168
|
file_info?: FileInfo;
|
|
147
169
|
};
|
|
148
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
|
+
};
|
|
149
186
|
export interface ExtractDataResult {
|
|
150
187
|
data: Record<string, unknown>;
|
|
151
188
|
video_info?: VideoInfo;
|
|
152
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;
|
|
153
196
|
usage?: UsageBlock;
|
|
154
197
|
}
|
|
155
198
|
/**
|
|
@@ -198,12 +241,24 @@ export type SearchFilesResult = {
|
|
|
198
241
|
export type AnalyzeVideoPayload = {
|
|
199
242
|
video_url: string;
|
|
200
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;
|
|
201
249
|
transcript_text?: boolean;
|
|
202
250
|
include_usage?: boolean;
|
|
203
251
|
};
|
|
204
252
|
export type AnalyzeFilePayload = {
|
|
205
253
|
file_id: string;
|
|
206
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;
|
|
207
262
|
transcript_text?: boolean;
|
|
208
263
|
include_usage?: boolean;
|
|
209
264
|
};
|
|
@@ -211,12 +266,31 @@ export type AnalyzeVideoResult = {
|
|
|
211
266
|
video_info: VideoInfo;
|
|
212
267
|
transcript: TranscriptOutput;
|
|
213
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;
|
|
214
280
|
usage?: UsageBlock;
|
|
215
281
|
};
|
|
216
282
|
export type AnalyzeFileResult = {
|
|
217
283
|
file_info: FileInfo;
|
|
218
284
|
transcript: TranscriptOutput;
|
|
219
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;
|
|
220
294
|
usage?: UsageBlock;
|
|
221
295
|
};
|
|
222
296
|
export type ExtractVideoDataPayload = {
|
|
@@ -224,6 +298,11 @@ export type ExtractVideoDataPayload = {
|
|
|
224
298
|
schema: ExtractionSchema;
|
|
225
299
|
what_to_extract?: string;
|
|
226
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;
|
|
227
306
|
include_usage?: boolean;
|
|
228
307
|
} & WebhookOption;
|
|
229
308
|
export type ExtractVideoDataMultipartPayload = {
|
|
@@ -232,6 +311,7 @@ export type ExtractVideoDataMultipartPayload = {
|
|
|
232
311
|
schemaFilePath: string;
|
|
233
312
|
what_to_extract?: string;
|
|
234
313
|
transcribe?: boolean;
|
|
314
|
+
include_scenes?: boolean;
|
|
235
315
|
include_usage?: boolean;
|
|
236
316
|
} & WebhookOption;
|
|
237
317
|
export type TweetStatementPayload = {
|
|
@@ -241,6 +321,13 @@ export type ExtractFileDataPayload = {
|
|
|
241
321
|
file_id: string;
|
|
242
322
|
schema: ExtractionSchema;
|
|
243
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;
|
|
244
331
|
include_usage?: boolean;
|
|
245
332
|
};
|
|
246
333
|
export type ExtractFileDataMultipartPayload = {
|
|
@@ -248,6 +335,7 @@ export type ExtractFileDataMultipartPayload = {
|
|
|
248
335
|
/** Path to a JSON or YAML schema file. The API accepts either a raw schema or a full extraction request object. */
|
|
249
336
|
schemaFilePath: string;
|
|
250
337
|
what_to_extract?: string;
|
|
338
|
+
include_scenes?: boolean;
|
|
251
339
|
include_usage?: boolean;
|
|
252
340
|
};
|
|
253
341
|
export declare class VidNavigatorClient {
|
|
@@ -271,9 +359,18 @@ export declare class VidNavigatorClient {
|
|
|
271
359
|
* says why. Same shapes as {@link VidNavigatorClient.transcribe}.
|
|
272
360
|
*/
|
|
273
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>;
|
|
274
369
|
/**
|
|
275
370
|
* Structured-data extraction from a video of any length, built on `POST /extract/video/async`.
|
|
276
|
-
* The schema is validated when you submit.
|
|
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}.
|
|
277
374
|
*/
|
|
278
375
|
readonly extractVideo: JobOperation<ExtractVideoInput, ExtractVideoAsyncJob, ExtractDataResult>;
|
|
279
376
|
/**
|
|
@@ -367,16 +464,26 @@ export declare class VidNavigatorClient {
|
|
|
367
464
|
offset: number;
|
|
368
465
|
has_more: boolean;
|
|
369
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
|
+
*/
|
|
370
472
|
getFile(file_id: string, query?: {
|
|
371
473
|
transcript_text?: boolean;
|
|
372
|
-
}): Promise<
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
+
*/
|
|
376
481
|
uploadFile(options: {
|
|
377
482
|
filePath: string;
|
|
378
483
|
wait_for_completion?: boolean;
|
|
379
484
|
namespace_ids?: string[];
|
|
485
|
+
/** Default false. `true` also analyzes the scenes of the file (video files only). */
|
|
486
|
+
include_scenes?: boolean;
|
|
380
487
|
}): Promise<UploadFileResult>;
|
|
381
488
|
deleteFile(file_id: string): Promise<{
|
|
382
489
|
file_id: string;
|
|
@@ -393,6 +500,19 @@ export declare class VidNavigatorClient {
|
|
|
393
500
|
file_status: string;
|
|
394
501
|
message: string;
|
|
395
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>;
|
|
396
516
|
cancelFileUpload(file_id: string): Promise<{
|
|
397
517
|
file_id: string;
|
|
398
518
|
file_name: string;
|
|
@@ -417,7 +537,26 @@ export declare class VidNavigatorClient {
|
|
|
417
537
|
namespace_ids: string[];
|
|
418
538
|
namespaces: NamespaceRef[];
|
|
419
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
|
+
*/
|
|
420
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
|
+
*/
|
|
421
560
|
analyzeFile(payload: AnalyzeFilePayload): Promise<AnalyzeFileResult>;
|
|
422
561
|
/**
|
|
423
562
|
* Structured claim analysis of an X/Twitter tweet. Blocking convenience wrapper around
|
|
@@ -428,8 +567,17 @@ export declare class VidNavigatorClient {
|
|
|
428
567
|
* Structured-data extraction from an online video. Blocking convenience wrapper around
|
|
429
568
|
* {@link VidNavigatorClient.extractVideo}: submits to `POST /extract/video/async` and polls, so
|
|
430
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`.
|
|
431
572
|
*/
|
|
432
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
|
+
*/
|
|
433
581
|
extractFileData(payload: ExtractFileDataPayload | ExtractFileDataMultipartPayload): Promise<ExtractDataResult>;
|
|
434
582
|
/**
|
|
435
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.
|
|
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;
|
|
@@ -138,11 +164,22 @@ class VidNavigatorClient {
|
|
|
138
164
|
return watched;
|
|
139
165
|
},
|
|
140
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
|
+
});
|
|
141
173
|
this.extractVideo = this.defineOperation({
|
|
142
174
|
jobType: 'extract_video',
|
|
143
175
|
submit: (input) => this.submitExtractVideo(input),
|
|
144
176
|
fetchTask: (task_id, options) => this.getAsyncJob(`/extract/video/${encodeURIComponent(task_id)}`, options, (raw) => raw),
|
|
145
|
-
toResult: async (task) => ({
|
|
177
|
+
toResult: async (task) => ({
|
|
178
|
+
data: requireResult(task),
|
|
179
|
+
video_info: task.video_info,
|
|
180
|
+
...pickSceneNotes(task),
|
|
181
|
+
usage: task.usage,
|
|
182
|
+
}),
|
|
146
183
|
});
|
|
147
184
|
this.tweetStatement = this.defineOperation({
|
|
148
185
|
jobType: 'tweet_statement',
|
|
@@ -208,6 +245,7 @@ class VidNavigatorClient {
|
|
|
208
245
|
form.append('schema', fs_1.default.createReadStream(input.schemaFilePath));
|
|
209
246
|
appendOptionalFormField(form, 'what_to_extract', input.what_to_extract);
|
|
210
247
|
appendOptionalFormField(form, 'transcribe', input.transcribe);
|
|
248
|
+
appendOptionalFormField(form, 'include_scenes', input.include_scenes);
|
|
211
249
|
appendOptionalFormField(form, 'webhook_url', input.webhook_url);
|
|
212
250
|
return this.submitAsyncJob('/extract/video/async', form, form.getHeaders());
|
|
213
251
|
}
|
|
@@ -361,13 +399,25 @@ class VidNavigatorClient {
|
|
|
361
399
|
has_more: response.data.has_more,
|
|
362
400
|
};
|
|
363
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
|
+
*/
|
|
364
407
|
async getFile(file_id, query) {
|
|
365
408
|
const response = await this.request('GET', `/file/${file_id}`, undefined, query);
|
|
366
409
|
return {
|
|
367
410
|
file_info: models_1.FileInfo.fromJSON(response.data.file_info),
|
|
368
411
|
transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
|
|
412
|
+
...parseScenes(response.data.scenes),
|
|
369
413
|
};
|
|
370
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
|
+
*/
|
|
371
421
|
async uploadFile(options) {
|
|
372
422
|
const form = new form_data_1.default();
|
|
373
423
|
form.append('file', fs_1.default.createReadStream(options.filePath));
|
|
@@ -377,6 +427,7 @@ class VidNavigatorClient {
|
|
|
377
427
|
if (options.namespace_ids?.length) {
|
|
378
428
|
form.append('namespace_ids', JSON.stringify(options.namespace_ids));
|
|
379
429
|
}
|
|
430
|
+
appendOptionalFormField(form, 'include_scenes', options.include_scenes);
|
|
380
431
|
try {
|
|
381
432
|
const response = await this.client.post('/upload/file', form, { headers: form.getHeaders() });
|
|
382
433
|
const body = response.data;
|
|
@@ -420,6 +471,22 @@ class VidNavigatorClient {
|
|
|
420
471
|
const response = await this.request('POST', `/file/${file_id}/retry`);
|
|
421
472
|
return response.data;
|
|
422
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
|
+
}
|
|
423
490
|
async cancelFileUpload(file_id) {
|
|
424
491
|
const response = await this.request('POST', `/file/${file_id}/cancel`);
|
|
425
492
|
return response.data;
|
|
@@ -452,21 +519,34 @@ class VidNavigatorClient {
|
|
|
452
519
|
}
|
|
453
520
|
//endregion
|
|
454
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
|
+
*/
|
|
455
534
|
async analyzeVideo(payload) {
|
|
456
535
|
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
|
-
};
|
|
536
|
+
return parseAnalyzeVideoData(response.data, response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined);
|
|
463
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
|
+
*/
|
|
464
545
|
async analyzeFile(payload) {
|
|
465
546
|
const response = await this.request('POST', '/analyze/file', payload);
|
|
466
547
|
return {
|
|
467
548
|
file_info: models_1.FileInfo.fromJSON(response.data.file_info),
|
|
468
|
-
|
|
469
|
-
transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
|
|
549
|
+
...parseAnalysisData(response.data),
|
|
470
550
|
usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
|
|
471
551
|
};
|
|
472
552
|
}
|
|
@@ -483,29 +563,38 @@ class VidNavigatorClient {
|
|
|
483
563
|
* Structured-data extraction from an online video. Blocking convenience wrapper around
|
|
484
564
|
* {@link VidNavigatorClient.extractVideo}: submits to `POST /extract/video/async` and polls, so
|
|
485
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`.
|
|
486
568
|
*/
|
|
487
569
|
async extractVideoData(payload, options) {
|
|
488
570
|
const { include_usage, ...input } = payload;
|
|
489
571
|
return this.extractVideo(input, { ...options, include_usage });
|
|
490
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
|
+
*/
|
|
491
580
|
async extractFileData(payload) {
|
|
581
|
+
let body;
|
|
492
582
|
if ('schemaFilePath' in payload) {
|
|
493
583
|
const form = new form_data_1.default();
|
|
494
584
|
form.append('file_id', payload.file_id);
|
|
495
585
|
form.append('schema', fs_1.default.createReadStream(payload.schemaFilePath));
|
|
496
586
|
appendOptionalFormField(form, 'what_to_extract', payload.what_to_extract);
|
|
587
|
+
appendOptionalFormField(form, 'include_scenes', payload.include_scenes);
|
|
497
588
|
appendOptionalFormField(form, 'include_usage', payload.include_usage);
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
|
|
503
|
-
};
|
|
589
|
+
body = await this.request('POST', '/extract/file', form, undefined, form.getHeaders());
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
body = await this.request('POST', '/extract/file', payload);
|
|
504
593
|
}
|
|
505
|
-
const body = await this.request('POST', '/extract/file', payload);
|
|
506
594
|
return {
|
|
507
595
|
data: body.data,
|
|
508
596
|
file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
|
|
597
|
+
...pickSceneNotes(body),
|
|
509
598
|
usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
|
|
510
599
|
};
|
|
511
600
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { UsageBlock } from './Usage';
|
|
2
2
|
import { VideoInfo, VideoInfoJSON } from './VideoInfo';
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
package/dist/models/AsyncJob.js
CHANGED
|
@@ -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) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FileInfoJSON } from './FileInfo';
|
|
2
2
|
import { VideoInfoJSON } from './VideoInfo';
|
|
3
|
+
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
3
4
|
export type ExtractionFieldType = 'String' | 'Number' | 'Boolean' | 'Integer' | 'Object' | 'Array' | 'Enum';
|
|
4
5
|
export interface ExtractionField {
|
|
5
6
|
type: ExtractionFieldType;
|
|
@@ -20,6 +21,10 @@ export interface ExtractionResponseJSON {
|
|
|
20
21
|
data: Record<string, unknown>;
|
|
21
22
|
video_info?: VideoInfoJSON;
|
|
22
23
|
file_info?: FileInfoJSON;
|
|
24
|
+
/** With `include_scenes`: number of frames that were analyzed to produce the scenes. */
|
|
25
|
+
frames_analyzed?: number;
|
|
26
|
+
scenes_error?: ScenesError;
|
|
27
|
+
transcript_error?: WatchTranscriptError;
|
|
23
28
|
usage?: ExtractionTokenUsageJSON;
|
|
24
29
|
}
|
|
25
30
|
export declare class ExtractionTokenUsage {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { NamespaceRef, NamespaceRefJSON } from './Namespace';
|
|
2
|
+
import { ScenesError } from './Watch';
|
|
2
3
|
export type FileStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
4
|
+
/**
|
|
5
|
+
* Where the scene analysis of a file stands. `none`: never asked for. `completed`: the scenes are
|
|
6
|
+
* returned by `getFile()`. `failed`: see `scenes_error`.
|
|
7
|
+
*/
|
|
8
|
+
export type FileScenesStatus = 'none' | 'processing' | 'completed' | 'failed';
|
|
3
9
|
export interface FileInfoJSON {
|
|
4
10
|
id: string;
|
|
5
11
|
name: string;
|
|
@@ -12,6 +18,9 @@ export interface FileInfoJSON {
|
|
|
12
18
|
original_file_date?: string;
|
|
13
19
|
has_transcript?: boolean;
|
|
14
20
|
error_message?: string;
|
|
21
|
+
scenes_status?: FileScenesStatus;
|
|
22
|
+
frames_analyzed?: number;
|
|
23
|
+
scenes_error?: ScenesError;
|
|
15
24
|
namespace_ids?: string[];
|
|
16
25
|
namespaces?: NamespaceRefJSON[];
|
|
17
26
|
}
|
|
@@ -30,6 +39,12 @@ export declare class FileInfo {
|
|
|
30
39
|
original_file_date?: string;
|
|
31
40
|
has_transcript?: boolean;
|
|
32
41
|
error_message?: string;
|
|
42
|
+
/** Where the scene analysis of the file stands. */
|
|
43
|
+
scenes_status?: FileScenesStatus;
|
|
44
|
+
/** Number of frames that were analyzed to produce the scenes. Present when `scenes_status` is `completed`. */
|
|
45
|
+
frames_analyzed?: number;
|
|
46
|
+
/** Present when `scenes_status` is `failed`. `frames_not_available` means the file has no picture (an audio file). */
|
|
47
|
+
scenes_error?: ScenesError;
|
|
33
48
|
namespace_ids?: string[];
|
|
34
49
|
namespaces?: NamespaceRef[];
|
|
35
50
|
constructor(data: FileInfoJSON);
|
package/dist/models/FileInfo.js
CHANGED
|
@@ -18,6 +18,9 @@ class FileInfo {
|
|
|
18
18
|
this.original_file_date = data.original_file_date;
|
|
19
19
|
this.has_transcript = data.has_transcript;
|
|
20
20
|
this.error_message = data.error_message;
|
|
21
|
+
this.scenes_status = data.scenes_status;
|
|
22
|
+
this.frames_analyzed = data.frames_analyzed;
|
|
23
|
+
this.scenes_error = data.scenes_error;
|
|
21
24
|
this.namespace_ids = data.namespace_ids;
|
|
22
25
|
this.namespaces = data.namespaces?.map(Namespace_1.NamespaceRef.fromJSON);
|
|
23
26
|
}
|