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/README.md +226 -35
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +17 -4
- package/dist/http.js +5 -0
- package/dist/index.d.ts +194 -7
- package/dist/index.js +127 -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/TikTok.d.ts +5 -4
- package/dist/models/Usage.d.ts +1 -1
- package/dist/models/Watch.d.ts +60 -0
- package/dist/models/Watch.js +37 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/dist/webhooks.d.ts +3 -3
- package/package.json +39 -39
- package/src/errors.ts +29 -0
- package/src/http.ts +14 -0
- package/src/index.ts +1477 -1198
- package/src/models/AsyncJob.ts +16 -2
- package/src/models/Extraction.ts +57 -52
- package/src/models/FileInfo.ts +19 -0
- package/src/models/TikTok.ts +5 -4
- package/src/models/Usage.ts +1 -0
- package/src/models/Watch.ts +85 -0
- package/src/models/index.ts +1 -0
- package/src/webhooks.ts +6 -2
package/src/models/AsyncJob.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { UsageBlock } from './Usage';
|
|
2
2
|
import { VideoInfo, VideoInfoJSON } from './VideoInfo';
|
|
3
|
+
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
3
4
|
|
|
4
|
-
/** Async job kinds returned by the `/transcribe/async`, `/extract/video/async` and `/tweet/statement/async` endpoints. */
|
|
5
|
-
export type AsyncJobType = 'transcribe' | 'extract_video' | 'tweet_statement';
|
|
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';
|
|
6
7
|
|
|
7
8
|
/** `processing` = accepted and being worked on. `completed` and `failed` are terminal. */
|
|
8
9
|
export type AsyncTaskStatus = 'processing' | 'completed' | 'failed';
|
|
@@ -86,6 +87,10 @@ export interface AsyncJobJSON {
|
|
|
86
87
|
result?: any;
|
|
87
88
|
/** `extract_video` jobs, once completed: the `video_info` the synchronous endpoint returns. */
|
|
88
89
|
video_info?: VideoInfoJSON;
|
|
90
|
+
/** `extract_video` jobs, once completed with `include_scenes`: the `frames_analyzed` the synchronous endpoint returns. */
|
|
91
|
+
frames_analyzed?: number;
|
|
92
|
+
scenes_error?: ScenesError;
|
|
93
|
+
transcript_error?: WatchTranscriptError;
|
|
89
94
|
error?: AsyncJobError | null;
|
|
90
95
|
}
|
|
91
96
|
|
|
@@ -110,6 +115,12 @@ export class AsyncJob<TResult> {
|
|
|
110
115
|
result: TResult | null;
|
|
111
116
|
/** `extract_video` jobs, once completed: metadata of the video the data was extracted from. */
|
|
112
117
|
video_info?: VideoInfo;
|
|
118
|
+
/** `extract_video` jobs, once completed with `include_scenes`: number of frames that were analyzed to produce the scenes. */
|
|
119
|
+
frames_analyzed?: number;
|
|
120
|
+
/** `extract_video` jobs with `include_scenes`: why the picture could not be read. The fields were then extracted from the transcript alone. */
|
|
121
|
+
scenes_error?: ScenesError;
|
|
122
|
+
/** `extract_video` jobs with `include_scenes`: why there is no transcript. The fields were then extracted from the scenes alone. */
|
|
123
|
+
transcript_error?: WatchTranscriptError;
|
|
113
124
|
error: AsyncJobError | null;
|
|
114
125
|
/** Per-call usage, populated only when polled with `include_usage: true` and `task_status === 'completed'`. */
|
|
115
126
|
usage?: UsageBlock;
|
|
@@ -127,6 +138,9 @@ export class AsyncJob<TResult> {
|
|
|
127
138
|
this.webhook = data.webhook;
|
|
128
139
|
this.result = data.result !== undefined && data.result !== null ? parseResult(data.result) : null;
|
|
129
140
|
this.video_info = data.video_info ? VideoInfo.fromJSON(data.video_info) : undefined;
|
|
141
|
+
this.frames_analyzed = data.frames_analyzed;
|
|
142
|
+
this.scenes_error = data.scenes_error;
|
|
143
|
+
this.transcript_error = data.transcript_error;
|
|
130
144
|
this.error = data.error ?? null;
|
|
131
145
|
}
|
|
132
146
|
|
package/src/models/Extraction.ts
CHANGED
|
@@ -1,52 +1,57 @@
|
|
|
1
|
-
import { FileInfoJSON } from './FileInfo';
|
|
2
|
-
import { VideoInfoJSON } from './VideoInfo';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
| '
|
|
7
|
-
| '
|
|
8
|
-
| '
|
|
9
|
-
| '
|
|
10
|
-
| '
|
|
11
|
-
| '
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
1
|
+
import { FileInfoJSON } from './FileInfo';
|
|
2
|
+
import { VideoInfoJSON } from './VideoInfo';
|
|
3
|
+
import { ScenesError, WatchTranscriptError } from './Watch';
|
|
4
|
+
|
|
5
|
+
export type ExtractionFieldType =
|
|
6
|
+
| 'String'
|
|
7
|
+
| 'Number'
|
|
8
|
+
| 'Boolean'
|
|
9
|
+
| 'Integer'
|
|
10
|
+
| 'Object'
|
|
11
|
+
| 'Array'
|
|
12
|
+
| 'Enum';
|
|
13
|
+
|
|
14
|
+
export interface ExtractionField {
|
|
15
|
+
type: ExtractionFieldType;
|
|
16
|
+
description: string;
|
|
17
|
+
properties?: Record<string, ExtractionField>;
|
|
18
|
+
items?: ExtractionField;
|
|
19
|
+
enum?: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Custom schema: field name -> field definition */
|
|
23
|
+
export type ExtractionSchema = Record<string, ExtractionField>;
|
|
24
|
+
|
|
25
|
+
export interface ExtractionTokenUsageJSON {
|
|
26
|
+
prompt_tokens?: number;
|
|
27
|
+
completion_tokens?: number;
|
|
28
|
+
total_tokens?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ExtractionResponseJSON {
|
|
32
|
+
status: 'success';
|
|
33
|
+
data: Record<string, unknown>;
|
|
34
|
+
video_info?: VideoInfoJSON;
|
|
35
|
+
file_info?: FileInfoJSON;
|
|
36
|
+
/** With `include_scenes`: number of frames that were analyzed to produce the scenes. */
|
|
37
|
+
frames_analyzed?: number;
|
|
38
|
+
scenes_error?: ScenesError;
|
|
39
|
+
transcript_error?: WatchTranscriptError;
|
|
40
|
+
usage?: ExtractionTokenUsageJSON;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class ExtractionTokenUsage {
|
|
44
|
+
prompt_tokens?: number;
|
|
45
|
+
completion_tokens?: number;
|
|
46
|
+
total_tokens?: number;
|
|
47
|
+
|
|
48
|
+
constructor(data: ExtractionTokenUsageJSON) {
|
|
49
|
+
this.prompt_tokens = data.prompt_tokens;
|
|
50
|
+
this.completion_tokens = data.completion_tokens;
|
|
51
|
+
this.total_tokens = data.total_tokens;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static fromJSON(json: ExtractionTokenUsageJSON): ExtractionTokenUsage {
|
|
55
|
+
return new ExtractionTokenUsage(json);
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/models/FileInfo.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { NamespaceRef, NamespaceRefJSON } from './Namespace';
|
|
2
|
+
import { ScenesError } from './Watch';
|
|
2
3
|
|
|
3
4
|
export type FileStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Where the scene analysis of a file stands. `none`: never asked for. `completed`: the scenes are
|
|
8
|
+
* returned by `getFile()`. `failed`: see `scenes_error`.
|
|
9
|
+
*/
|
|
10
|
+
export type FileScenesStatus = 'none' | 'processing' | 'completed' | 'failed';
|
|
11
|
+
|
|
5
12
|
export interface FileInfoJSON {
|
|
6
13
|
id: string;
|
|
7
14
|
name: string;
|
|
@@ -14,6 +21,9 @@ export interface FileInfoJSON {
|
|
|
14
21
|
original_file_date?: string;
|
|
15
22
|
has_transcript?: boolean;
|
|
16
23
|
error_message?: string;
|
|
24
|
+
scenes_status?: FileScenesStatus;
|
|
25
|
+
frames_analyzed?: number;
|
|
26
|
+
scenes_error?: ScenesError;
|
|
17
27
|
namespace_ids?: string[];
|
|
18
28
|
namespaces?: NamespaceRefJSON[];
|
|
19
29
|
}
|
|
@@ -33,6 +43,12 @@ export class FileInfo {
|
|
|
33
43
|
original_file_date?: string;
|
|
34
44
|
has_transcript?: boolean;
|
|
35
45
|
error_message?: string;
|
|
46
|
+
/** Where the scene analysis of the file stands. */
|
|
47
|
+
scenes_status?: FileScenesStatus;
|
|
48
|
+
/** Number of frames that were analyzed to produce the scenes. Present when `scenes_status` is `completed`. */
|
|
49
|
+
frames_analyzed?: number;
|
|
50
|
+
/** Present when `scenes_status` is `failed`. `frames_not_available` means the file has no picture (an audio file). */
|
|
51
|
+
scenes_error?: ScenesError;
|
|
36
52
|
namespace_ids?: string[];
|
|
37
53
|
namespaces?: NamespaceRef[];
|
|
38
54
|
|
|
@@ -48,6 +64,9 @@ export class FileInfo {
|
|
|
48
64
|
this.original_file_date = data.original_file_date;
|
|
49
65
|
this.has_transcript = data.has_transcript;
|
|
50
66
|
this.error_message = data.error_message;
|
|
67
|
+
this.scenes_status = data.scenes_status;
|
|
68
|
+
this.frames_analyzed = data.frames_analyzed;
|
|
69
|
+
this.scenes_error = data.scenes_error;
|
|
51
70
|
this.namespace_ids = data.namespace_ids;
|
|
52
71
|
this.namespaces = data.namespaces?.map(NamespaceRef.fromJSON);
|
|
53
72
|
}
|
package/src/models/TikTok.ts
CHANGED
|
@@ -407,8 +407,9 @@ export interface TikTokSearchFilters {
|
|
|
407
407
|
export interface TikTokSearchStats {
|
|
408
408
|
pages_fetched?: number;
|
|
409
409
|
/**
|
|
410
|
-
* Distinct videos TikTok returned, including those your filters dropped.
|
|
411
|
-
* 1 `residential_request` per 30, minimum 1 per search
|
|
410
|
+
* Distinct videos TikTok returned, including those your filters dropped. For information:
|
|
411
|
+
* billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search)
|
|
412
|
+
* and `pages_fetched` (at least 1 per 5).
|
|
412
413
|
*/
|
|
413
414
|
videos_fetched?: number;
|
|
414
415
|
results_count?: number;
|
|
@@ -921,8 +922,8 @@ export interface TikTokLiveSearchStats {
|
|
|
921
922
|
/** TikTok pages fetched (up to 50 rooms each). */
|
|
922
923
|
pages_fetched?: number;
|
|
923
924
|
/**
|
|
924
|
-
* Distinct rooms TikTok returned, including any past `max_results`.
|
|
925
|
-
* 1 `residential_request` per 30, minimum 1 per search.
|
|
925
|
+
* Distinct rooms TikTok returned, including any past `max_results`. For information:
|
|
926
|
+
* billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search).
|
|
926
927
|
*/
|
|
927
928
|
rooms_fetched?: number;
|
|
928
929
|
results_count?: number;
|
package/src/models/Usage.ts
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { UsageBlock } from './Usage';
|
|
2
|
+
import { VideoInfo, VideoInfoJSON } from './VideoInfo';
|
|
3
|
+
import { transcriptFromJSON, TranscriptOutput, TranscriptOutputJSON } from './TranscriptSegment';
|
|
4
|
+
|
|
5
|
+
export interface VideoSceneJSON {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
description?: string;
|
|
9
|
+
on_screen_text?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** What a video, or an uploaded file, shows between `start` and `end`. */
|
|
13
|
+
export class VideoScene {
|
|
14
|
+
/** Start of the scene, in seconds from the beginning of the video. */
|
|
15
|
+
start: number;
|
|
16
|
+
/** End of the scene, in seconds: the start of the next scene, or the end of the video. */
|
|
17
|
+
end: number;
|
|
18
|
+
/** What is visible: people, setting, action, objects. */
|
|
19
|
+
description: string;
|
|
20
|
+
/** Text readable on screen (captions, titles, signs), verbatim. Empty when there is none. */
|
|
21
|
+
on_screen_text: string;
|
|
22
|
+
|
|
23
|
+
constructor(data: VideoSceneJSON) {
|
|
24
|
+
this.start = data.start;
|
|
25
|
+
this.end = data.end;
|
|
26
|
+
this.description = data.description ?? '';
|
|
27
|
+
this.on_screen_text = data.on_screen_text ?? '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static fromJSON(json: VideoSceneJSON): VideoScene {
|
|
31
|
+
return new VideoScene(json);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Why a video or a file came back without a transcript (e.g. `transcript_not_available`). */
|
|
36
|
+
export interface WatchTranscriptError {
|
|
37
|
+
error?: string;
|
|
38
|
+
message?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Why the scenes of a video or a file could not be had (e.g. `frames_not_available`). */
|
|
42
|
+
export interface ScenesError {
|
|
43
|
+
error?: string;
|
|
44
|
+
message?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface WatchResultJSON {
|
|
48
|
+
video_info: VideoInfoJSON;
|
|
49
|
+
transcript?: TranscriptOutputJSON;
|
|
50
|
+
transcript_error?: WatchTranscriptError;
|
|
51
|
+
scenes?: VideoSceneJSON[];
|
|
52
|
+
frames_analyzed?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A watched video: its metadata, what it says and what it shows.
|
|
57
|
+
*
|
|
58
|
+
* `transcript` is left out when the request set `include_transcript: false`, and empty when the
|
|
59
|
+
* video has none; `transcript_error` then says why. The scenes are returned in both cases.
|
|
60
|
+
*/
|
|
61
|
+
export class WatchResult {
|
|
62
|
+
video_info: VideoInfo;
|
|
63
|
+
/** What is said: segments, or one string with `transcript_text: true`. */
|
|
64
|
+
transcript?: TranscriptOutput;
|
|
65
|
+
/** Present only when the transcript could not be had, for instance on a video without speech. */
|
|
66
|
+
transcript_error?: WatchTranscriptError;
|
|
67
|
+
/** What is shown, in chronological order. */
|
|
68
|
+
scenes: VideoScene[];
|
|
69
|
+
/** Number of frames of the video that were analyzed to produce the scenes. */
|
|
70
|
+
frames_analyzed?: number;
|
|
71
|
+
/** Per-call usage, populated when requested with include_usage. */
|
|
72
|
+
usage?: UsageBlock;
|
|
73
|
+
|
|
74
|
+
constructor(data: WatchResultJSON) {
|
|
75
|
+
this.video_info = VideoInfo.fromJSON(data.video_info ?? {});
|
|
76
|
+
this.transcript = transcriptFromJSON(data.transcript);
|
|
77
|
+
this.transcript_error = data.transcript_error;
|
|
78
|
+
this.scenes = (data.scenes ?? []).map((scene) => VideoScene.fromJSON(scene));
|
|
79
|
+
this.frames_analyzed = data.frames_analyzed;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static fromJSON(json: WatchResultJSON): WatchResult {
|
|
83
|
+
return new WatchResult(json);
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/models/index.ts
CHANGED
package/src/webhooks.ts
CHANGED
|
@@ -6,6 +6,10 @@ import { VidNavigatorError, WebhookSignatureError } from './errors';
|
|
|
6
6
|
export type WebhookEventType =
|
|
7
7
|
| 'transcribe.completed'
|
|
8
8
|
| 'transcribe.failed'
|
|
9
|
+
| 'watch.completed'
|
|
10
|
+
| 'watch.failed'
|
|
11
|
+
| 'analyze_video.completed'
|
|
12
|
+
| 'analyze_video.failed'
|
|
9
13
|
| 'extract_video.completed'
|
|
10
14
|
| 'extract_video.failed'
|
|
11
15
|
| 'tweet_statement.completed'
|
|
@@ -38,8 +42,8 @@ export interface WebhookEvent {
|
|
|
38
42
|
job_type?: string;
|
|
39
43
|
check_status_url?: string;
|
|
40
44
|
/**
|
|
41
|
-
* Raw (unparsed) result of the completed job. For transcription, extraction and tweet
|
|
42
|
-
* is the same data the job's `result()` parses. For TikTok tasks it is a summary only,
|
|
45
|
+
* Raw (unparsed) result of the completed job. For transcription, watch, analysis, extraction and tweet
|
|
46
|
+
* jobs it is the same data the job's `result()` parses. For TikTok tasks it is a summary only,
|
|
43
47
|
* {@link TikTokWebhookResult} (a scrape can hold thousands of videos); fetch the videos with
|
|
44
48
|
* `vn.tiktokProfile.resume(task_id).result()`. Omitted when `result_truncated` is true.
|
|
45
49
|
*/
|