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.
@@ -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);
@@ -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
  }
@@ -216,8 +216,9 @@ export interface TikTokSearchFilters {
216
216
  export interface TikTokSearchStats {
217
217
  pages_fetched?: number;
218
218
  /**
219
- * Distinct videos TikTok returned, including those your filters dropped. Billed at
220
- * 1 `residential_request` per 30, minimum 1 per search.
219
+ * Distinct videos TikTok returned, including those your filters dropped. For information:
220
+ * billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search)
221
+ * and `pages_fetched` (at least 1 per 5).
221
222
  */
222
223
  videos_fetched?: number;
223
224
  results_count?: number;
@@ -561,8 +562,8 @@ export interface TikTokLiveSearchStats {
561
562
  /** TikTok pages fetched (up to 50 rooms each). */
562
563
  pages_fetched?: number;
563
564
  /**
564
- * Distinct rooms TikTok returned, including any past `max_results`. Billed at
565
- * 1 `residential_request` per 30, minimum 1 per search.
565
+ * Distinct rooms TikTok returned, including any past `max_results`. For information:
566
+ * billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search).
566
567
  */
567
568
  rooms_fetched?: number;
568
569
  results_count?: number;
@@ -1,6 +1,6 @@
1
1
  export type UnlimitedOrNumber = number | 'unlimited';
2
2
  /** Meters that can appear in a per-call {@link UsageBlock}. */
3
- export type UsageServiceType = 'standard_request' | 'residential_request' | 'transcription_hour' | 'analysis_request' | 'search_request' | 'scene_analysis_hour';
3
+ export type UsageServiceType = 'standard_request' | 'residential_request' | 'transcription_hour' | 'frame_analysis' | 'analysis_request' | 'search_request' | 'scene_analysis_hour';
4
4
  export interface UsageTokens {
5
5
  prompt_tokens?: number;
6
6
  completion_tokens?: number;
@@ -0,0 +1,60 @@
1
+ import { UsageBlock } from './Usage';
2
+ import { VideoInfo, VideoInfoJSON } from './VideoInfo';
3
+ import { TranscriptOutput, TranscriptOutputJSON } from './TranscriptSegment';
4
+ export interface VideoSceneJSON {
5
+ start: number;
6
+ end: number;
7
+ description?: string;
8
+ on_screen_text?: string;
9
+ }
10
+ /** What a video, or an uploaded file, shows between `start` and `end`. */
11
+ export declare class VideoScene {
12
+ /** Start of the scene, in seconds from the beginning of the video. */
13
+ start: number;
14
+ /** End of the scene, in seconds: the start of the next scene, or the end of the video. */
15
+ end: number;
16
+ /** What is visible: people, setting, action, objects. */
17
+ description: string;
18
+ /** Text readable on screen (captions, titles, signs), verbatim. Empty when there is none. */
19
+ on_screen_text: string;
20
+ constructor(data: VideoSceneJSON);
21
+ static fromJSON(json: VideoSceneJSON): VideoScene;
22
+ }
23
+ /** Why a video or a file came back without a transcript (e.g. `transcript_not_available`). */
24
+ export interface WatchTranscriptError {
25
+ error?: string;
26
+ message?: string;
27
+ }
28
+ /** Why the scenes of a video or a file could not be had (e.g. `frames_not_available`). */
29
+ export interface ScenesError {
30
+ error?: string;
31
+ message?: string;
32
+ }
33
+ export interface WatchResultJSON {
34
+ video_info: VideoInfoJSON;
35
+ transcript?: TranscriptOutputJSON;
36
+ transcript_error?: WatchTranscriptError;
37
+ scenes?: VideoSceneJSON[];
38
+ frames_analyzed?: number;
39
+ }
40
+ /**
41
+ * A watched video: its metadata, what it says and what it shows.
42
+ *
43
+ * `transcript` is left out when the request set `include_transcript: false`, and empty when the
44
+ * video has none; `transcript_error` then says why. The scenes are returned in both cases.
45
+ */
46
+ export declare class WatchResult {
47
+ video_info: VideoInfo;
48
+ /** What is said: segments, or one string with `transcript_text: true`. */
49
+ transcript?: TranscriptOutput;
50
+ /** Present only when the transcript could not be had, for instance on a video without speech. */
51
+ transcript_error?: WatchTranscriptError;
52
+ /** What is shown, in chronological order. */
53
+ scenes: VideoScene[];
54
+ /** Number of frames of the video that were analyzed to produce the scenes. */
55
+ frames_analyzed?: number;
56
+ /** Per-call usage, populated when requested with include_usage. */
57
+ usage?: UsageBlock;
58
+ constructor(data: WatchResultJSON);
59
+ static fromJSON(json: WatchResultJSON): WatchResult;
60
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WatchResult = exports.VideoScene = void 0;
4
+ const VideoInfo_1 = require("./VideoInfo");
5
+ const TranscriptSegment_1 = require("./TranscriptSegment");
6
+ /** What a video, or an uploaded file, shows between `start` and `end`. */
7
+ class VideoScene {
8
+ constructor(data) {
9
+ this.start = data.start;
10
+ this.end = data.end;
11
+ this.description = data.description ?? '';
12
+ this.on_screen_text = data.on_screen_text ?? '';
13
+ }
14
+ static fromJSON(json) {
15
+ return new VideoScene(json);
16
+ }
17
+ }
18
+ exports.VideoScene = VideoScene;
19
+ /**
20
+ * A watched video: its metadata, what it says and what it shows.
21
+ *
22
+ * `transcript` is left out when the request set `include_transcript: false`, and empty when the
23
+ * video has none; `transcript_error` then says why. The scenes are returned in both cases.
24
+ */
25
+ class WatchResult {
26
+ constructor(data) {
27
+ this.video_info = VideoInfo_1.VideoInfo.fromJSON(data.video_info ?? {});
28
+ this.transcript = (0, TranscriptSegment_1.transcriptFromJSON)(data.transcript);
29
+ this.transcript_error = data.transcript_error;
30
+ this.scenes = (data.scenes ?? []).map((scene) => VideoScene.fromJSON(scene));
31
+ this.frames_analyzed = data.frames_analyzed;
32
+ }
33
+ static fromJSON(json) {
34
+ return new WatchResult(json);
35
+ }
36
+ }
37
+ exports.WatchResult = WatchResult;
@@ -11,3 +11,4 @@ export * from './TranscriptSegment';
11
11
  export * from './TweetStatement';
12
12
  export * from './VideoInfo';
13
13
  export * from './Usage';
14
+ export * from './Watch';
@@ -27,3 +27,4 @@ __exportStar(require("./TranscriptSegment"), exports);
27
27
  __exportStar(require("./TweetStatement"), exports);
28
28
  __exportStar(require("./VideoInfo"), exports);
29
29
  __exportStar(require("./Usage"), exports);
30
+ __exportStar(require("./Watch"), exports);
@@ -1,6 +1,6 @@
1
1
  import { AsyncJobError } from './models';
2
2
  /** Event types delivered to a `webhook_url` when an async job reaches a terminal state. */
3
- export type WebhookEventType = 'transcribe.completed' | 'transcribe.failed' | 'extract_video.completed' | 'extract_video.failed' | 'tweet_statement.completed' | 'tweet_statement.failed' | 'tiktok_profile.completed' | 'tiktok_profile.failed' | 'tiktok_search.completed' | 'tiktok_search.failed' | 'tiktok_live_search.completed' | 'tiktok_live_search.failed';
3
+ export type WebhookEventType = 'transcribe.completed' | 'transcribe.failed' | 'watch.completed' | 'watch.failed' | 'analyze_video.completed' | 'analyze_video.failed' | 'extract_video.completed' | 'extract_video.failed' | 'tweet_statement.completed' | 'tweet_statement.failed' | 'tiktok_profile.completed' | 'tiktok_profile.failed' | 'tiktok_search.completed' | 'tiktok_search.failed' | 'tiktok_live_search.completed' | 'tiktok_live_search.failed';
4
4
  /** `data.result` of a `tiktok_profile.*` / `tiktok_search.*` / `tiktok_live_search.*` event: a summary, not the items. */
5
5
  export interface TikTokWebhookResult {
6
6
  /** Same fields as the task's `stats` (e.g. `videos_matched`, or `results_count` / `sort_by` for searches). */
@@ -21,8 +21,8 @@ export interface WebhookEvent {
21
21
  job_type?: string;
22
22
  check_status_url?: string;
23
23
  /**
24
- * Raw (unparsed) result of the completed job. For transcription, extraction and tweet jobs it
25
- * is the same data the job's `result()` parses. For TikTok tasks it is a summary only,
24
+ * Raw (unparsed) result of the completed job. For transcription, watch, analysis, extraction and tweet
25
+ * jobs it is the same data the job's `result()` parses. For TikTok tasks it is a summary only,
26
26
  * {@link TikTokWebhookResult} (a scrape can hold thousands of videos); fetch the videos with
27
27
  * `vn.tiktokProfile.resume(task_id).result()`. Omitted when `result_truncated` is true.
28
28
  */
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
- {
2
- "name": "vidnavigator",
3
- "version": "2.3.1",
4
- "description": "Official JavaScript SDK for the VidNavigator Developer API",
5
- "author": "VidNavigator",
6
- "license": "Apache-2.0",
7
- "homepage": "https://vidnavigator.com",
8
- "main": "dist/index.js",
9
- "types": "dist/index.d.ts",
10
- "files": [
11
- "dist",
12
- "src"
13
- ],
14
- "scripts": {
15
- "build": "tsc",
16
- "prepublishOnly": "npm run build"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/vidnavigator/vidnavigator-js.git"
21
- },
22
- "keywords": [
23
- "vidnavigator",
24
- "sdk",
25
- "api",
26
- "video",
27
- "transcription",
28
- "analysis"
29
- ],
30
- "dependencies": {
31
- "axios": "^1.6.0",
32
- "form-data": "^4.0.0"
33
- },
34
- "devDependencies": {
35
- "@types/node": "^20.4.2",
36
- "typescript": "^5.1.3",
37
- "@types/form-data": "^2.5.0"
38
- }
39
- }
1
+ {
2
+ "name": "vidnavigator",
3
+ "version": "2.5.0",
4
+ "description": "Official JavaScript SDK for the VidNavigator Developer API",
5
+ "author": "VidNavigator",
6
+ "license": "Apache-2.0",
7
+ "homepage": "https://vidnavigator.com",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "src"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/vidnavigator/vidnavigator-js.git"
21
+ },
22
+ "keywords": [
23
+ "vidnavigator",
24
+ "sdk",
25
+ "api",
26
+ "video",
27
+ "transcription",
28
+ "analysis"
29
+ ],
30
+ "dependencies": {
31
+ "axios": "^1.6.0",
32
+ "form-data": "^4.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^20.4.2",
36
+ "typescript": "^5.1.3",
37
+ "@types/form-data": "^2.5.0"
38
+ }
39
+ }
package/src/errors.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Custom exception classes for VidNavigator SDK.
3
3
  */
4
+ import { FileScenesStatus, ScenesError } from './models';
4
5
 
5
6
  /**
6
7
  * Base class for all VidNavigator SDK errors.
@@ -181,6 +182,34 @@ export class TooManyActiveJobsError extends RateLimitExceededError {
181
182
  }
182
183
  }
183
184
 
185
+ /**
186
+ * Raised when `include_scenes` was asked on an uploaded file that has no scenes to read
187
+ * (HTTP 409, `scenes_not_available`). `scenes_status` says where their analysis stands: `none`
188
+ * (never asked for: start it with `analyzeFileScenes(file_id)`), `processing` (call again once
189
+ * `getFile()` reports `completed`) or `failed` (see `scenes_error`).
190
+ */
191
+ export class ScenesNotAvailableError extends VidNavigatorError {
192
+ public readonly scenes_status?: Exclude<FileScenesStatus, 'completed'>;
193
+ /** Present when `scenes_status` is `failed`, e.g. `frames_not_available` for an audio file. */
194
+ public readonly scenes_error?: ScenesError;
195
+
196
+ constructor(
197
+ message: string,
198
+ status_code?: number,
199
+ error_code?: string,
200
+ error_message?: string,
201
+ details?: any,
202
+ scenes_status?: Exclude<FileScenesStatus, 'completed'>,
203
+ scenes_error?: ScenesError
204
+ ) {
205
+ super(message, status_code, error_code, error_message, details);
206
+ this.name = 'ScenesNotAvailableError';
207
+ this.scenes_status = scenes_status;
208
+ this.scenes_error = scenes_error;
209
+ Object.setPrototypeOf(this, ScenesNotAvailableError.prototype);
210
+ }
211
+ }
212
+
184
213
  /**
185
214
  * Raised when waiting for a job exceeds `timeoutMs`. Always carries `task_id`: the job keeps
186
215
  * running server-side and its result stays readable for 1 hour after it finishes, so resume it
package/src/http.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  SystemOverloadError,
16
16
  InsufficientCreditsError,
17
17
  TooManyActiveJobsError,
18
+ ScenesNotAvailableError,
18
19
  } from './errors';
19
20
 
20
21
  export function parseApiErrorPayload(data: any): {
@@ -50,6 +51,19 @@ export function buildApiError(status: number, data: any, fallbackMessage?: strin
50
51
  return new AccessDeniedError(message, status, errorCode, errorMessage, details);
51
52
  case 404:
52
53
  return new NotFoundError(message, status, errorCode, errorMessage, details);
54
+ case 409:
55
+ if (errorCode === 'scenes_not_available') {
56
+ return new ScenesNotAvailableError(
57
+ message,
58
+ status,
59
+ errorCode,
60
+ errorMessage,
61
+ details,
62
+ data?.scenes_status,
63
+ data?.scenes_error
64
+ );
65
+ }
66
+ return new VidNavigatorError(message, status, errorCode, errorMessage, details);
53
67
  case 413:
54
68
  return new StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
55
69
  case 429: