vidnavigator 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -40
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +17 -4
- package/dist/http.js +5 -0
- package/dist/index.d.ts +169 -11
- package/dist/index.js +122 -17
- package/dist/models/AsyncJob.d.ts +18 -2
- package/dist/models/AsyncJob.js +4 -0
- package/dist/models/Extraction.d.ts +29 -6
- 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 +5 -3
- package/package.json +1 -1
- package/src/errors.ts +29 -0
- package/src/http.ts +14 -0
- package/src/index.ts +293 -51
- package/src/models/AsyncJob.ts +22 -2
- package/src/models/Extraction.ts +68 -52
- package/src/models/FileInfo.ts +19 -0
- package/src/models/Watch.ts +8 -2
- package/src/webhooks.ts +6 -2
package/src/models/Extraction.ts
CHANGED
|
@@ -1,52 +1,68 @@
|
|
|
1
|
-
import { FileInfoJSON } from './FileInfo';
|
|
2
|
-
import { VideoInfoJSON } from './VideoInfo';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export interface ExtractionField {
|
|
14
|
-
type
|
|
15
|
-
description
|
|
16
|
-
properties?: Record<string, ExtractionField>;
|
|
17
|
-
items?: ExtractionField;
|
|
18
|
-
enum?: string
|
|
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
|
+
/** JSON Schema types a property of an extraction schema can have. */
|
|
6
|
+
export type ExtractionFieldType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* One property of an extraction schema, in standard JSON Schema. Give it a `type` and a
|
|
10
|
+
* `description` (what to put in it); `enum` restricts it to a list of values. Other JSON Schema
|
|
11
|
+
* keywords are accepted (`$ref`, `format`, `minimum`, ...).
|
|
12
|
+
*/
|
|
13
|
+
export interface ExtractionField {
|
|
14
|
+
type?: ExtractionFieldType | Array<ExtractionFieldType | 'null'>;
|
|
15
|
+
description?: string;
|
|
16
|
+
properties?: Record<string, ExtractionField>;
|
|
17
|
+
items?: ExtractionField;
|
|
18
|
+
enum?: Array<string | number | boolean | null>;
|
|
19
|
+
[keyword: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The fields to extract, as a standard JSON Schema whose root is an object, for example what
|
|
24
|
+
* `zod-to-json-schema` or Pydantic's `model_json_schema()` produce. At most 10 fields per level
|
|
25
|
+
* and 3 levels of nesting.
|
|
26
|
+
*/
|
|
27
|
+
export interface ExtractionSchema {
|
|
28
|
+
type: 'object';
|
|
29
|
+
properties: Record<string, ExtractionField>;
|
|
30
|
+
required?: string[];
|
|
31
|
+
[keyword: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ExtractionTokenUsageJSON {
|
|
35
|
+
prompt_tokens?: number;
|
|
36
|
+
completion_tokens?: number;
|
|
37
|
+
total_tokens?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ExtractionResponseJSON {
|
|
41
|
+
status: 'success';
|
|
42
|
+
data: Record<string, unknown>;
|
|
43
|
+
video_info?: VideoInfoJSON;
|
|
44
|
+
file_info?: FileInfoJSON;
|
|
45
|
+
/** With `include_scenes`: number of frames that were analyzed to produce the scenes. */
|
|
46
|
+
frames_analyzed?: number;
|
|
47
|
+
scenes_error?: ScenesError;
|
|
48
|
+
transcript_error?: WatchTranscriptError;
|
|
49
|
+
/** When the request had no schema: the schema written from `what_to_extract`, to pass as `schema` next time. */
|
|
50
|
+
schema?: ExtractionSchema;
|
|
51
|
+
usage?: ExtractionTokenUsageJSON;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class ExtractionTokenUsage {
|
|
55
|
+
prompt_tokens?: number;
|
|
56
|
+
completion_tokens?: number;
|
|
57
|
+
total_tokens?: number;
|
|
58
|
+
|
|
59
|
+
constructor(data: ExtractionTokenUsageJSON) {
|
|
60
|
+
this.prompt_tokens = data.prompt_tokens;
|
|
61
|
+
this.completion_tokens = data.completion_tokens;
|
|
62
|
+
this.total_tokens = data.total_tokens;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static fromJSON(json: ExtractionTokenUsageJSON): ExtractionTokenUsage {
|
|
66
|
+
return new ExtractionTokenUsage(json);
|
|
67
|
+
}
|
|
68
|
+
}
|
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/Watch.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface VideoSceneJSON {
|
|
|
9
9
|
on_screen_text?: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
/** What a video shows between `start` and `end`. */
|
|
12
|
+
/** What a video, or an uploaded file, shows between `start` and `end`. */
|
|
13
13
|
export class VideoScene {
|
|
14
14
|
/** Start of the scene, in seconds from the beginning of the video. */
|
|
15
15
|
start: number;
|
|
@@ -32,12 +32,18 @@ export class VideoScene {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/** Why a
|
|
35
|
+
/** Why a video or a file came back without a transcript (e.g. `transcript_not_available`). */
|
|
36
36
|
export interface WatchTranscriptError {
|
|
37
37
|
error?: string;
|
|
38
38
|
message?: string;
|
|
39
39
|
}
|
|
40
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
|
+
|
|
41
47
|
export interface WatchResultJSON {
|
|
42
48
|
video_info: VideoInfoJSON;
|
|
43
49
|
transcript?: TranscriptOutputJSON;
|
package/src/webhooks.ts
CHANGED
|
@@ -8,6 +8,8 @@ export type WebhookEventType =
|
|
|
8
8
|
| 'transcribe.failed'
|
|
9
9
|
| 'watch.completed'
|
|
10
10
|
| 'watch.failed'
|
|
11
|
+
| 'analyze_video.completed'
|
|
12
|
+
| 'analyze_video.failed'
|
|
11
13
|
| 'extract_video.completed'
|
|
12
14
|
| 'extract_video.failed'
|
|
13
15
|
| 'tweet_statement.completed'
|
|
@@ -40,8 +42,8 @@ export interface WebhookEvent {
|
|
|
40
42
|
job_type?: string;
|
|
41
43
|
check_status_url?: string;
|
|
42
44
|
/**
|
|
43
|
-
* Raw (unparsed) result of the completed job. For transcription, watch, extraction and tweet
|
|
44
|
-
* it 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,
|
|
45
47
|
* {@link TikTokWebhookResult} (a scrape can hold thousands of videos); fetch the videos with
|
|
46
48
|
* `vn.tiktokProfile.resume(task_id).result()`. Omitted when `result_truncated` is true.
|
|
47
49
|
*/
|
|
@@ -50,6 +52,8 @@ export interface WebhookEvent {
|
|
|
50
52
|
result_truncated?: boolean;
|
|
51
53
|
/** `extract_video.completed` only: raw `video_info` of the video. Sent even when `result_truncated` is true. */
|
|
52
54
|
video_info?: Record<string, unknown>;
|
|
55
|
+
/** `extract_video.completed` only, when the request had no schema: the schema written from `what_to_extract`. */
|
|
56
|
+
schema?: Record<string, unknown>;
|
|
53
57
|
error?: AsyncJobError | null;
|
|
54
58
|
};
|
|
55
59
|
}
|