vidnavigator 2.1.0 → 2.2.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 +41 -8
- package/dist/index.d.ts +17 -3
- package/dist/index.js +22 -2
- package/dist/models/TikTok.d.ts +198 -0
- package/dist/models/TikTok.js +101 -2
- package/dist/webhooks.d.ts +2 -2
- package/package.json +1 -1
- package/src/index.ts +56 -2
- package/src/models/TikTok.ts +302 -1
- package/src/webhooks.ts +4 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# VidNavigator SDK for JavaScript
|
|
2
2
|
|
|
3
|
-
The official JavaScript/TypeScript SDK for the [VidNavigator Developer API](https://vidnavigator.com). Transcribe, analyze, search, and extract structured data from video and audio — YouTube, Instagram, TikTok, X/Twitter, Vimeo, Facebook, Dailymotion, Loom, and your own uploaded files.
|
|
3
|
+
The official JavaScript/TypeScript SDK for the [VidNavigator Developer API](https://vidnavigator.com). Transcribe, analyze, search, and extract structured data from video and audio — YouTube, Instagram, TikTok, X/Twitter, Vimeo, Facebook, Dailymotion, Loom, Snapchat, and your own uploaded files.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/vidnavigator)
|
|
6
6
|
[](https://github.com/vidnavigator/vidnavigator-js/blob/main/LICENSE)
|
|
@@ -9,9 +9,9 @@ The official JavaScript/TypeScript SDK for the [VidNavigator Developer API](http
|
|
|
9
9
|
|
|
10
10
|
## Why VidNavigator?
|
|
11
11
|
|
|
12
|
-
- **Multi-platform transcription** — YouTube, Instagram Reels & carousel posts, TikTok, X/Twitter, Vimeo, Facebook, Dailymotion, Loom, and more.
|
|
12
|
+
- **Multi-platform transcription** — YouTube, Instagram Reels & carousel posts, TikTok, X/Twitter, Vimeo, Facebook, Dailymotion, Loom, Snapchat, and more.
|
|
13
13
|
- **Any video length** — transcription, extraction, and tweet analysis run as background jobs, so there is no duration limit. Get the result with one `await`, or submit many jobs and collect them as they finish.
|
|
14
|
-
- **Async TikTok profile scraping and
|
|
14
|
+
- **Async TikTok profile scraping, keyword search and LIVE search** — collect public TikTok videos, or LIVE rooms with their stream URLs, in the background, then read results via cursor pagination or a signed `download_url`, optionally notified by webhook.
|
|
15
15
|
- **Instagram carousel support** — select a specific video by index, or transcribe every video in a carousel post with one call.
|
|
16
16
|
- **AI-powered analysis** — get summaries, people mentioned, places, key subjects, and direct answers to questions about any video or audio.
|
|
17
17
|
- **Structured data extraction** — define a JSON schema and receive typed, structured fields extracted from any transcript (powered by LLMs).
|
|
@@ -34,6 +34,7 @@ The official JavaScript/TypeScript SDK for the [VidNavigator Developer API](http
|
|
|
34
34
|
| Facebook | Yes | Yes | - |
|
|
35
35
|
| Dailymotion | Yes | Yes | - |
|
|
36
36
|
| Loom | Yes | Yes | - |
|
|
37
|
+
| Snapchat | Yes, when Snapchat has a transcript | Yes | Yes (highlights: `img_index`, `all_videos`) |
|
|
37
38
|
| Uploaded files | Yes | Yes | - |
|
|
38
39
|
|
|
39
40
|
> **Transcript** = fast caption/subtitle extraction. **Transcribe** = speech-to-text via AI models (works when captions are unavailable).
|
|
@@ -102,7 +103,7 @@ New in 2.0: `vn.transcribe`, `vn.extractVideo`, `vn.tweetStatement`, `vn.tiktokP
|
|
|
102
103
|
|
|
103
104
|
### 1. Get a transcript (any platform)
|
|
104
105
|
|
|
105
|
-
There is a single `getTranscript` method that auto-detects the platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, and more) from the URL.
|
|
106
|
+
There is a single `getTranscript` method that auto-detects the platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, Snapchat, and more) from the URL.
|
|
106
107
|
|
|
107
108
|
```ts
|
|
108
109
|
const { video_info, transcript } = await vn.getTranscript({
|
|
@@ -163,6 +164,7 @@ Each of these operations comes in two shapes:
|
|
|
163
164
|
| Tweet claim analysis | `await vn.tweetStatement(tweetId)` | `await vn.tweetStatement.submit(tweetId)` |
|
|
164
165
|
| TikTok profile scrape | `await vn.tiktokProfile(profileUrl)` | `await vn.tiktokProfile.submit(profileUrl)` |
|
|
165
166
|
| TikTok keyword search | `await vn.tiktokSearch(query)` | `await vn.tiktokSearch.submit(query)` |
|
|
167
|
+
| TikTok LIVE search | `await vn.tiktokLiveSearch(query)` | `await vn.tiktokLiveSearch.submit(query)` |
|
|
166
168
|
|
|
167
169
|
**Wait for the result.** The one-liner submits the job, checks on it until it finishes, and returns the result:
|
|
168
170
|
|
|
@@ -466,6 +468,31 @@ for (const result of task.results) {
|
|
|
466
468
|
- `sort_by` and `published_within` are applied by TikTok itself. If you leave out `sort_by`, results come back newest first. If you leave out `published_within` and set an `after_datetime` more than 24 hours ago, the smallest window that covers it is picked for you.
|
|
467
469
|
- `parallel_search_slices` (`2` to `4`) runs several search chains in parallel to collect more results than TikTok's single-chain limit (about 115 to 140 items). Billing grows with the number of slices, so keep it at `1` unless you need the extra results, and especially when `published_within` is set, since every slice searches the same window.
|
|
468
470
|
|
|
471
|
+
- `country` picks whose TikTok results you get (`'fr'`, `'de'`, `'jp'`, ..., default `'gb'`). `'us'` is refused: TikTok asks US visitors to log in.
|
|
472
|
+
- Billing: 1 `residential_request` per 30 videos TikTok returned (`task.stats.videos_fetched`, including the ones your filters dropped), minimum 1 per search.
|
|
473
|
+
|
|
474
|
+
### 6b. TikTok LIVE search (async)
|
|
475
|
+
|
|
476
|
+
`vn.tiktokLiveSearch()` finds TikTok LIVE rooms broadcasting right now for a keyword, with their stream URLs:
|
|
477
|
+
|
|
478
|
+
```ts
|
|
479
|
+
const task = await vn.tiktokLiveSearch({ query: 'gaming', country: 'us' });
|
|
480
|
+
|
|
481
|
+
for (const room of task.results) {
|
|
482
|
+
console.log(room.title, room.author?.unique_id, room.stats?.viewers, room.category, room.hashtags);
|
|
483
|
+
const urls = room.stream_urls;
|
|
484
|
+
if (urls) {
|
|
485
|
+
const q = urls.default_quality ?? 'hd';
|
|
486
|
+
console.log('FLV:', urls.flv[q], 'HLS:', urls.hls[q], 'audio only:', urls.audio_only);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
- Each room has the same `id`, `url`, `author` and `stats` fields as a keyword search result, plus `started_at` (a `Date`), `stats.viewers` / `stats.total_viewers`, `hashtags` (the `#tags` of the title), `category` (the LIVE's category on TikTok, e.g. `'Gaming'`) and `game_tags`.
|
|
492
|
+
- `stream_urls` holds `flv` and `hls` URLs keyed by quality (`origin`, `uhd`, `hd`, `sd`, `ld`), `default_quality`, an `audio_only` stream and `expires_at`. The URLs play while the LIVE is on. They are returned by default; pass `include_stream_urls: false` to leave them out. Not every LIVE offers HLS, so `hls` can be empty.
|
|
493
|
+
- `country` defaults to `'us'`. Results keep TikTok's ranking; a keyword with no LIVE room in that country at that moment completes with zero results.
|
|
494
|
+
- Billing: 1 `residential_request` per 30 rooms TikTok returned (`task.stats.rooms_fetched`), minimum 1 per search.
|
|
495
|
+
|
|
469
496
|
### 7. Instagram carousel posts (multiple videos)
|
|
470
497
|
|
|
471
498
|
Instagram carousel posts can contain multiple videos. You can select a specific video by index, or transcribe them all at once:
|
|
@@ -749,7 +776,7 @@ All methods return a `Promise`. Responses are automatically parsed into typed mo
|
|
|
749
776
|
|
|
750
777
|
| Member | Description |
|
|
751
778
|
|--------|-------------|
|
|
752
|
-
| `vn.transcribe`, `vn.extractVideo`, `vn.tweetStatement`, `vn.tiktokProfile`, `vn.tiktokSearch` | Call directly to submit and wait for the result. Options: `include_usage`, `timeoutMs`, `intervalMs`, `fastStart`, `signal`, `onPoll` |
|
|
779
|
+
| `vn.transcribe`, `vn.extractVideo`, `vn.tweetStatement`, `vn.tiktokProfile`, `vn.tiktokSearch`, `vn.tiktokLiveSearch` | Call directly to submit and wait for the result. Options: `include_usage`, `timeoutMs`, `intervalMs`, `fastStart`, `signal`, `onPoll` |
|
|
753
780
|
| `.submit(input, { include_usage? })` | Start the job and return a `Job` immediately |
|
|
754
781
|
| `.resume(task_id, { include_usage? })` | Get a `Job` for a job you already started (no request is made) |
|
|
755
782
|
| `job.task_id`, `job.job_type`, `job.check_status_url`, `job.webhook_url` | Job details from the submit response |
|
|
@@ -758,7 +785,7 @@ All methods return a `Promise`. Responses are automatically parsed into typed mo
|
|
|
758
785
|
| `job.result(options?)` | Wait until finished and return the result. Throws on failure or timeout; every error carries `task_id` |
|
|
759
786
|
| `job.wait(options?)` | Wait until finished and return the final task, without throwing on failure |
|
|
760
787
|
|
|
761
|
-
Results: `transcribe` → same shape as `transcribeVideo()`; `extractVideo` → `{ data, video_info, usage? }`; `tweetStatement` → `TweetStatement`; `tiktokProfile` / `tiktokSearch` → the completed task with every page of `videos` / `results`.
|
|
788
|
+
Results: `transcribe` → same shape as `transcribeVideo()`; `extractVideo` → `{ data, video_info, usage? }`; `tweetStatement` → `TweetStatement`; `tiktokProfile` / `tiktokSearch` / `tiktokLiveSearch` → the completed task with every page of `videos` / `results`.
|
|
762
789
|
|
|
763
790
|
### Webhooks
|
|
764
791
|
|
|
@@ -768,7 +795,7 @@ Results: `transcribe` → same shape as `transcribeVideo()`; `extractVideo` →
|
|
|
768
795
|
| `verifyWebhookSignature(rawBody, signatureHeader, secret, options?)` | Same check, returning `true` / `false` |
|
|
769
796
|
| `WEBHOOK_HEADERS` | Header names: `signature`, `delivery`, `event`, `taskId` |
|
|
770
797
|
|
|
771
|
-
`options`: `toleranceSeconds` (default `300`, `0` turns the check off). Event types: `transcribe.*`, `extract_video.*`, `tweet_statement.*`, `tiktok_profile.*`, `tiktok_search.*`, each with `.completed` or `.failed`.
|
|
798
|
+
`options`: `toleranceSeconds` (default `300`, `0` turns the check off). Event types: `transcribe.*`, `extract_video.*`, `tweet_statement.*`, `tiktok_profile.*`, `tiktok_search.*`, `tiktok_live_search.*`, each with `.completed` or `.failed`.
|
|
772
799
|
|
|
773
800
|
### TikTok
|
|
774
801
|
|
|
@@ -776,10 +803,13 @@ Results: `transcribe` → same shape as `transcribeVideo()`; `extractVideo` →
|
|
|
776
803
|
|--------|-------------|
|
|
777
804
|
| `tiktokProfile(urlOrInput, options?)` | Scrape a public profile and return the completed task with every video. See [Background jobs](#background-jobs) |
|
|
778
805
|
| `tiktokSearch(queryOrInput, options?)` | Keyword search returning the completed task with every result |
|
|
806
|
+
| `tiktokLiveSearch(queryOrInput, options?)` | LIVE search returning the completed task with every room and its stream URLs |
|
|
779
807
|
| `submitTikTokProfileScrape(payload)` | Lower-level: start a public TikTok profile scrape. Returns a `task_id` immediately. Options: `max_posts`, `after_datetime`, `before_datetime`, `min_likes`, `max_likes`, `webhook_url` |
|
|
780
808
|
| `getTikTokProfileScrape(task_id, query?)` | Poll task status and retrieve a page of videos. Options: `cursor`, `limit`, `include_usage` |
|
|
781
|
-
| `submitTikTokSearch(payload)` | Start an async TikTok keyword search. Returns a `task_id` immediately. Options: `max_results`, `parallel_search_slices`, `sort_by`, `published_within`, `after_datetime`, `before_datetime`, `min_likes`, `max_likes`, `min_views`, `max_views`, `webhook_url` |
|
|
809
|
+
| `submitTikTokSearch(payload)` | Start an async TikTok keyword search. Returns a `task_id` immediately. Options: `max_results`, `parallel_search_slices`, `sort_by`, `published_within`, `after_datetime`, `before_datetime`, `min_likes`, `max_likes`, `min_views`, `max_views`, `country`, `webhook_url` |
|
|
782
810
|
| `getTikTokSearch(task_id, query?)` | Poll search status and retrieve a page of results. Options: `cursor`, `limit`, `include_usage` |
|
|
811
|
+
| `submitTikTokLiveSearch(payload)` | Start an async TikTok LIVE search. Returns a `task_id` immediately. Options: `max_results`, `country`, `include_stream_urls`, `webhook_url` |
|
|
812
|
+
| `getTikTokLiveSearch(task_id, query?)` | Poll LIVE search status and retrieve a page of rooms. Options: `cursor`, `limit`, `include_usage` |
|
|
783
813
|
|
|
784
814
|
Completed profile tasks include `videos`; completed search tasks include `results`. Both include `pagination`, optional `stats`, and an optional short-lived `download_url` for retrieving the whole result as JSON. Failed tasks include `error` (`{ error, message, http_status }`); the older `error_message` string still works but is deprecated. Datetime filters use `after_datetime` and `before_datetime`, each accepting either `YYYY-MM-DD` or full ISO datetime strings with timezone; TikTok `published_at` values are parsed into JavaScript `Date` objects, and numeric counters such as `views` and `likes` are normalized to integers.
|
|
785
815
|
|
|
@@ -925,6 +955,9 @@ All API responses are parsed into typed classes with static `fromJSON()` constru
|
|
|
925
955
|
| `TikTokSearchSubmission` | Async TikTok keyword search submission: `task_id`, query, slice count, expiry, `webhook_url` |
|
|
926
956
|
| `TikTokSearchTask` | TikTok keyword search task with status, results, pagination, `download_url`, `error`, `webhook`; `stats` shows the `sort_by` / `published_within` the search ran with |
|
|
927
957
|
| `TikTokSearchResult` | Normalized TikTok keyword result, including `published_at` as a `Date` and integer counters |
|
|
958
|
+
| `TikTokLiveSearchSubmission` | Async TikTok LIVE search submission: `task_id`, query, country, `include_stream_urls`, expiry, `webhook_url` |
|
|
959
|
+
| `TikTokLiveSearchTask` | TikTok LIVE search task with status, rooms, pagination, `download_url`, `error`, `webhook`; `stats.rooms_fetched` is what is billed |
|
|
960
|
+
| `TikTokLiveRoom` | A LIVE room: author, `stats.viewers`, `hashtags`, `category`, `game_tags`, `started_at` as a `Date`, and `stream_urls` (FLV / HLS by quality, audio only) |
|
|
928
961
|
| `TweetStatement` | Structured X/Twitter claim analysis, topics, entities, tone, intent, and source text |
|
|
929
962
|
|
|
930
963
|
## Links
|
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, 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, TweetStatement, 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.2.0";
|
|
11
11
|
export interface SDKConfig {
|
|
12
12
|
apiKey: string;
|
|
13
13
|
baseURL?: string;
|
|
@@ -103,6 +103,8 @@ export type TweetStatementJob = Job<TweetStatementAsyncJob, TweetStatement>;
|
|
|
103
103
|
export type TikTokProfileJob = Job<TikTokProfileTask, TikTokProfileTask>;
|
|
104
104
|
/** `result()` resolves to the completed task with **all** pages of `results` collected. */
|
|
105
105
|
export type TikTokSearchJob = Job<TikTokSearchTask, TikTokSearchTask>;
|
|
106
|
+
/** `result()` resolves to the completed task with **all** pages of rooms collected. */
|
|
107
|
+
export type TikTokLiveSearchJob = Job<TikTokLiveSearchTask, TikTokLiveSearchTask>;
|
|
106
108
|
export type UploadFileSuccessResult = {
|
|
107
109
|
status: 'success';
|
|
108
110
|
file_id: string;
|
|
@@ -247,6 +249,12 @@ export declare class VidNavigatorClient {
|
|
|
247
249
|
* every page of `results` collected. Same shapes as {@link VidNavigatorClient.transcribe}.
|
|
248
250
|
*/
|
|
249
251
|
readonly tiktokSearch: JobOperation<string | TikTokSearchRequest, TikTokSearchTask, TikTokSearchTask>;
|
|
252
|
+
/**
|
|
253
|
+
* TikTok LIVE search, built on `POST /tiktok/live/search`: rooms broadcasting now for a keyword,
|
|
254
|
+
* with their FLV / HLS / audio-only stream URLs. The result is the completed task with every
|
|
255
|
+
* page of `results` collected. Same shapes as {@link VidNavigatorClient.transcribe}.
|
|
256
|
+
*/
|
|
257
|
+
readonly tiktokLiveSearch: JobOperation<string | TikTokLiveSearchRequest, TikTokLiveSearchTask, TikTokLiveSearchTask>;
|
|
250
258
|
constructor(config: SDKConfig);
|
|
251
259
|
private defineOperation;
|
|
252
260
|
private submitAsyncJob;
|
|
@@ -255,7 +263,7 @@ export declare class VidNavigatorClient {
|
|
|
255
263
|
private request;
|
|
256
264
|
/**
|
|
257
265
|
* Get a transcript for any supported video. The endpoint auto-detects the
|
|
258
|
-
* platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, etc.)
|
|
266
|
+
* platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, Snapchat, etc.)
|
|
259
267
|
* from `video_url`. For Instagram, use {@link VidNavigatorClient.transcribeVideo}.
|
|
260
268
|
*/
|
|
261
269
|
getTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult>;
|
|
@@ -282,6 +290,12 @@ export declare class VidNavigatorClient {
|
|
|
282
290
|
limit?: number;
|
|
283
291
|
include_usage?: boolean;
|
|
284
292
|
}): Promise<TikTokSearchTask>;
|
|
293
|
+
submitTikTokLiveSearch(payload: TikTokLiveSearchRequest): Promise<TikTokLiveSearchSubmission>;
|
|
294
|
+
getTikTokLiveSearch(task_id: string, query?: {
|
|
295
|
+
cursor?: string;
|
|
296
|
+
limit?: number;
|
|
297
|
+
include_usage?: boolean;
|
|
298
|
+
}): Promise<TikTokLiveSearchTask>;
|
|
285
299
|
getFiles(query?: {
|
|
286
300
|
limit?: number;
|
|
287
301
|
offset?: number;
|
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.2.0';
|
|
35
35
|
//endregion
|
|
36
36
|
function parseTranscribeData(inner, usage) {
|
|
37
37
|
if ('videos' in inner && 'carousel_info' in inner) {
|
|
@@ -158,6 +158,15 @@ class VidNavigatorClient {
|
|
|
158
158
|
fetchTask: (task_id) => this.getTikTokSearch(task_id, { limit: 1 }),
|
|
159
159
|
toResult: (task, options) => collectAllPages((query) => this.getTikTokSearch(task.task_id, query), (page) => page.results, (page, all) => { page.results = all; }, options.include_usage),
|
|
160
160
|
});
|
|
161
|
+
this.tiktokLiveSearch = this.defineOperation({
|
|
162
|
+
jobType: 'tiktok_live_search',
|
|
163
|
+
submit: async (input) => {
|
|
164
|
+
const sub = await this.submitTikTokLiveSearch(typeof input === 'string' ? { query: input } : input);
|
|
165
|
+
return { ...sub, job_type: 'tiktok_live_search' };
|
|
166
|
+
},
|
|
167
|
+
fetchTask: (task_id) => this.getTikTokLiveSearch(task_id, { limit: 1 }),
|
|
168
|
+
toResult: (task, options) => collectAllPages((query) => this.getTikTokLiveSearch(task.task_id, query), (page) => page.results, (page, all) => { page.results = all; }, options.include_usage),
|
|
169
|
+
});
|
|
161
170
|
}
|
|
162
171
|
defineOperation(spec) {
|
|
163
172
|
const makeJob = (info, options = {}) => new jobs_1.Job(info, () => spec.fetchTask(info.task_id, options), (task) => spec.toResult(task, options));
|
|
@@ -217,7 +226,7 @@ class VidNavigatorClient {
|
|
|
217
226
|
//region --- Transcripts ---
|
|
218
227
|
/**
|
|
219
228
|
* Get a transcript for any supported video. The endpoint auto-detects the
|
|
220
|
-
* platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, etc.)
|
|
229
|
+
* platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, Snapchat, etc.)
|
|
221
230
|
* from `video_url`. For Instagram, use {@link VidNavigatorClient.transcribeVideo}.
|
|
222
231
|
*/
|
|
223
232
|
async getTranscript(payload) {
|
|
@@ -269,6 +278,17 @@ class VidNavigatorClient {
|
|
|
269
278
|
task.usage = models_1.UsageBlock.fromJSON(response.usage);
|
|
270
279
|
return task;
|
|
271
280
|
}
|
|
281
|
+
async submitTikTokLiveSearch(payload) {
|
|
282
|
+
const response = await this.request('POST', '/tiktok/live/search', payload);
|
|
283
|
+
return models_1.TikTokLiveSearchSubmission.fromJSON(response.data);
|
|
284
|
+
}
|
|
285
|
+
async getTikTokLiveSearch(task_id, query) {
|
|
286
|
+
const response = await this.request('GET', `/tiktok/live/search/${task_id}`, undefined, buildTikTokPollParams(query));
|
|
287
|
+
const task = models_1.TikTokLiveSearchTask.fromJSON(response.data);
|
|
288
|
+
if (response.usage)
|
|
289
|
+
task.usage = models_1.UsageBlock.fromJSON(response.usage);
|
|
290
|
+
return task;
|
|
291
|
+
}
|
|
272
292
|
//endregion
|
|
273
293
|
//region --- Files ---
|
|
274
294
|
async getFiles(query) {
|
package/dist/models/TikTok.d.ts
CHANGED
|
@@ -37,6 +37,11 @@ export interface TikTokSearchRequest {
|
|
|
37
37
|
max_likes?: number;
|
|
38
38
|
min_views?: number;
|
|
39
39
|
max_views?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Two-letter country code (`'fr'`, `'de'`, `'jp'`, ...) whose TikTok results you get. Default `'gb'`.
|
|
42
|
+
* `'us'` is refused: TikTok asks US visitors to log in. The API lists the accepted codes.
|
|
43
|
+
*/
|
|
44
|
+
country?: string;
|
|
40
45
|
/**
|
|
41
46
|
* Where to POST a notification when the task finishes. Overrides the account-level default
|
|
42
47
|
* configured in Studio → API; pass an empty string to opt this task out of that default.
|
|
@@ -70,6 +75,7 @@ export interface TikTokSearchSubmissionJSON {
|
|
|
70
75
|
task_id: string;
|
|
71
76
|
task_status: 'processing';
|
|
72
77
|
query: string;
|
|
78
|
+
country?: string;
|
|
73
79
|
max_results?: number;
|
|
74
80
|
parallel_search_slices?: number;
|
|
75
81
|
filters?: Record<string, unknown>;
|
|
@@ -82,6 +88,8 @@ export declare class TikTokSearchSubmission {
|
|
|
82
88
|
task_id: string;
|
|
83
89
|
task_status: 'processing';
|
|
84
90
|
query: string;
|
|
91
|
+
/** Country whose TikTok results the search returns. */
|
|
92
|
+
country?: string;
|
|
85
93
|
max_results?: number;
|
|
86
94
|
parallel_search_slices?: number;
|
|
87
95
|
filters?: Record<string, unknown>;
|
|
@@ -207,12 +215,27 @@ export interface TikTokSearchFilters {
|
|
|
207
215
|
}
|
|
208
216
|
export interface TikTokSearchStats {
|
|
209
217
|
pages_fetched?: number;
|
|
218
|
+
/**
|
|
219
|
+
* Distinct videos TikTok returned, including those your filters dropped. Billed at
|
|
220
|
+
* 1 `residential_request` per 30, minimum 1 per search.
|
|
221
|
+
*/
|
|
222
|
+
videos_fetched?: number;
|
|
210
223
|
results_count?: number;
|
|
211
224
|
next_search_cursor?: number | null;
|
|
225
|
+
/** Slice count the search actually ran with. */
|
|
226
|
+
parallel_search_slices?: number;
|
|
212
227
|
/** Sort order the search ran with (`relevance` when `sort_by` was omitted). */
|
|
213
228
|
sort_by?: TikTokSearchSortBy;
|
|
214
229
|
/** Date window the search ran with; `all` means no window. */
|
|
215
230
|
published_within?: TikTokPublishedWithin;
|
|
231
|
+
/** Country whose TikTok results the search returned. */
|
|
232
|
+
country?: string;
|
|
233
|
+
/** Only when filters were set: videos checked against them. */
|
|
234
|
+
items_examined?: number;
|
|
235
|
+
/** Only when filters were set: videos they dropped. */
|
|
236
|
+
items_filtered_out?: number;
|
|
237
|
+
/** Only with `parallel_search_slices` > 1: videos several slices returned, counted once. */
|
|
238
|
+
items_deduplicated?: number;
|
|
216
239
|
}
|
|
217
240
|
export interface TikTokProfileTaskJSON {
|
|
218
241
|
task_id: string;
|
|
@@ -259,6 +282,7 @@ export interface TikTokSearchTaskJSON {
|
|
|
259
282
|
task_id: string;
|
|
260
283
|
task_status: 'processing' | 'completed' | 'failed';
|
|
261
284
|
query?: string;
|
|
285
|
+
country?: string;
|
|
262
286
|
parallel_search_slices?: number;
|
|
263
287
|
filters?: TikTokSearchFilters;
|
|
264
288
|
stats?: TikTokSearchStats;
|
|
@@ -276,6 +300,8 @@ export declare class TikTokSearchTask {
|
|
|
276
300
|
task_id: string;
|
|
277
301
|
task_status: 'processing' | 'completed' | 'failed';
|
|
278
302
|
query?: string;
|
|
303
|
+
/** Country whose TikTok results the search returned (`gb` by default). */
|
|
304
|
+
country?: string;
|
|
279
305
|
parallel_search_slices?: number;
|
|
280
306
|
filters?: TikTokSearchFilters;
|
|
281
307
|
stats?: TikTokSearchStats;
|
|
@@ -296,3 +322,175 @@ export declare class TikTokSearchTask {
|
|
|
296
322
|
constructor(data: TikTokSearchTaskJSON);
|
|
297
323
|
static fromJSON(json: TikTokSearchTaskJSON): TikTokSearchTask;
|
|
298
324
|
}
|
|
325
|
+
export interface TikTokLiveSearchRequest {
|
|
326
|
+
query: string;
|
|
327
|
+
/** Cap on rooms. `0` or omitted means as many as TikTok serves, about 50 per keyword. */
|
|
328
|
+
max_results?: number;
|
|
329
|
+
/** Two-letter country code whose LIVE rooms you get. Default `'us'`. The API lists the accepted codes. */
|
|
330
|
+
country?: string;
|
|
331
|
+
/**
|
|
332
|
+
* The API returns each room's playback URLs by default (FLV and HLS by quality, plus an
|
|
333
|
+
* audio-only stream). Pass `false` to leave them out.
|
|
334
|
+
*/
|
|
335
|
+
include_stream_urls?: boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Where to POST a notification when the task finishes. Overrides the account-level default
|
|
338
|
+
* configured in Studio → API; pass an empty string to opt this task out of that default.
|
|
339
|
+
* The event's `data.result` is a summary; read the rooms with `vn.tiktokLiveSearch.resume(task_id).result()`.
|
|
340
|
+
*/
|
|
341
|
+
webhook_url?: string;
|
|
342
|
+
}
|
|
343
|
+
export interface TikTokLiveSearchSubmissionJSON {
|
|
344
|
+
task_id: string;
|
|
345
|
+
task_status: 'processing';
|
|
346
|
+
query: string;
|
|
347
|
+
country?: string;
|
|
348
|
+
max_results?: number;
|
|
349
|
+
include_stream_urls?: boolean;
|
|
350
|
+
expires_at?: string;
|
|
351
|
+
check_status_url?: string;
|
|
352
|
+
message?: string;
|
|
353
|
+
webhook_url?: string | null;
|
|
354
|
+
}
|
|
355
|
+
export declare class TikTokLiveSearchSubmission {
|
|
356
|
+
task_id: string;
|
|
357
|
+
task_status: 'processing';
|
|
358
|
+
query: string;
|
|
359
|
+
country?: string;
|
|
360
|
+
max_results?: number;
|
|
361
|
+
include_stream_urls?: boolean;
|
|
362
|
+
expires_at?: string;
|
|
363
|
+
check_status_url?: string;
|
|
364
|
+
message?: string;
|
|
365
|
+
/** The URL this task's result notification will be POSTed to, or `null`. */
|
|
366
|
+
webhook_url?: string | null;
|
|
367
|
+
constructor(data: TikTokLiveSearchSubmissionJSON);
|
|
368
|
+
static fromJSON(json: TikTokLiveSearchSubmissionJSON): TikTokLiveSearchSubmission;
|
|
369
|
+
}
|
|
370
|
+
export interface TikTokLiveAuthor {
|
|
371
|
+
id?: string | null;
|
|
372
|
+
/** Username, without @. */
|
|
373
|
+
unique_id?: string | null;
|
|
374
|
+
nickname?: string | null;
|
|
375
|
+
sec_uid?: string | null;
|
|
376
|
+
followers?: number | null;
|
|
377
|
+
avatar_url?: string | null;
|
|
378
|
+
}
|
|
379
|
+
export interface TikTokLiveStats {
|
|
380
|
+
/** Watching when the search ran. */
|
|
381
|
+
viewers?: number | null;
|
|
382
|
+
/** Since the LIVE started. */
|
|
383
|
+
total_viewers?: number | null;
|
|
384
|
+
likes?: number | null;
|
|
385
|
+
comments?: number | null;
|
|
386
|
+
shares?: number | null;
|
|
387
|
+
}
|
|
388
|
+
/** Quality keys of the playback URLs: those the LIVE offers, best first. */
|
|
389
|
+
export type TikTokLiveQuality = 'origin' | 'uhd' | 'hd' | 'sd' | 'ld' | (string & {});
|
|
390
|
+
export interface TikTokLiveStreamUrlsJSON {
|
|
391
|
+
default_quality?: TikTokLiveQuality | null;
|
|
392
|
+
flv?: Record<string, string>;
|
|
393
|
+
hls?: Record<string, string>;
|
|
394
|
+
audio_only?: string | null;
|
|
395
|
+
expires_at?: string | null;
|
|
396
|
+
}
|
|
397
|
+
/** Playback URLs of a LIVE room. They stop working when the LIVE ends. */
|
|
398
|
+
export interface TikTokLiveStreamUrls {
|
|
399
|
+
/** The quality TikTok plays by default (a key of `flv`). */
|
|
400
|
+
default_quality: TikTokLiveQuality | null;
|
|
401
|
+
/** HTTP-FLV URLs keyed by quality. */
|
|
402
|
+
flv: Record<string, string>;
|
|
403
|
+
/** HLS (`.m3u8`) URLs keyed by quality, when TikTok provides them. Can be empty. */
|
|
404
|
+
hls: Record<string, string>;
|
|
405
|
+
/** HTTP-FLV URL of the audio-only stream. */
|
|
406
|
+
audio_only: string | null;
|
|
407
|
+
/** Expiry of the URL signatures. */
|
|
408
|
+
expires_at: Date | null;
|
|
409
|
+
}
|
|
410
|
+
export interface TikTokLiveRoomJSON {
|
|
411
|
+
id?: string | null;
|
|
412
|
+
title?: string | null;
|
|
413
|
+
url?: string | null;
|
|
414
|
+
started_at?: string | null;
|
|
415
|
+
author?: TikTokLiveAuthor;
|
|
416
|
+
stats?: TikTokLiveStats;
|
|
417
|
+
hashtags?: string[];
|
|
418
|
+
category?: string | null;
|
|
419
|
+
game_tags?: string[];
|
|
420
|
+
cover_url?: string | null;
|
|
421
|
+
stream_urls?: TikTokLiveStreamUrlsJSON;
|
|
422
|
+
}
|
|
423
|
+
/** A TikTok LIVE room that was broadcasting when the search ran. */
|
|
424
|
+
export declare class TikTokLiveRoom {
|
|
425
|
+
id?: string | null;
|
|
426
|
+
title?: string | null;
|
|
427
|
+
/** `https://www.tiktok.com/@username/live` */
|
|
428
|
+
url?: string | null;
|
|
429
|
+
started_at?: Date | null;
|
|
430
|
+
author?: TikTokLiveAuthor;
|
|
431
|
+
stats?: TikTokLiveStats;
|
|
432
|
+
/** `#tags` written in the title, without `#`. */
|
|
433
|
+
hashtags: string[];
|
|
434
|
+
/** The LIVE's category on TikTok, e.g. `'Gaming'`. */
|
|
435
|
+
category?: string | null;
|
|
436
|
+
game_tags: string[];
|
|
437
|
+
cover_url?: string | null;
|
|
438
|
+
/** Absent when the search was submitted with `include_stream_urls: false`. */
|
|
439
|
+
stream_urls?: TikTokLiveStreamUrls;
|
|
440
|
+
constructor(data: TikTokLiveRoomJSON);
|
|
441
|
+
static fromJSON(json: TikTokLiveRoomJSON): TikTokLiveRoom;
|
|
442
|
+
}
|
|
443
|
+
export interface TikTokLiveSearchStats {
|
|
444
|
+
/** TikTok pages fetched (up to 50 rooms each). */
|
|
445
|
+
pages_fetched?: number;
|
|
446
|
+
/**
|
|
447
|
+
* Distinct rooms TikTok returned, including any past `max_results`. Billed at
|
|
448
|
+
* 1 `residential_request` per 30, minimum 1 per search.
|
|
449
|
+
*/
|
|
450
|
+
rooms_fetched?: number;
|
|
451
|
+
results_count?: number;
|
|
452
|
+
/** Whether TikTok had more rooms when the search stopped. */
|
|
453
|
+
has_more?: boolean;
|
|
454
|
+
country?: string;
|
|
455
|
+
}
|
|
456
|
+
export interface TikTokLiveSearchTaskJSON {
|
|
457
|
+
task_id: string;
|
|
458
|
+
task_status: 'processing' | 'completed' | 'failed';
|
|
459
|
+
query?: string;
|
|
460
|
+
country?: string;
|
|
461
|
+
stats?: TikTokLiveSearchStats;
|
|
462
|
+
results?: TikTokLiveRoomJSON[];
|
|
463
|
+
pagination?: TikTokProfilePagination;
|
|
464
|
+
download_url?: string | null;
|
|
465
|
+
error_message?: string | null;
|
|
466
|
+
created_at?: string | null;
|
|
467
|
+
completed_at?: string | null;
|
|
468
|
+
expires_at?: string | null;
|
|
469
|
+
error?: AsyncJobError | null;
|
|
470
|
+
webhook?: AsyncJobWebhookStatus | null;
|
|
471
|
+
}
|
|
472
|
+
export declare class TikTokLiveSearchTask {
|
|
473
|
+
task_id: string;
|
|
474
|
+
task_status: 'processing' | 'completed' | 'failed';
|
|
475
|
+
query?: string;
|
|
476
|
+
/** Country whose LIVE rooms the search returned (`us` by default). */
|
|
477
|
+
country?: string;
|
|
478
|
+
stats?: TikTokLiveSearchStats;
|
|
479
|
+
/** Rooms in TikTok's ranking. */
|
|
480
|
+
results: TikTokLiveRoom[];
|
|
481
|
+
pagination?: TikTokProfilePagination;
|
|
482
|
+
download_url?: string | null;
|
|
483
|
+
/** @deprecated Use `error`, which carries a machine-readable code. */
|
|
484
|
+
error_message?: string | null;
|
|
485
|
+
created_at?: string | null;
|
|
486
|
+
completed_at?: string | null;
|
|
487
|
+
expires_at?: string | null;
|
|
488
|
+
/** Present when `task_status === 'failed'`: error code, message and HTTP status. */
|
|
489
|
+
error: AsyncJobError | null;
|
|
490
|
+
/** Webhook delivery state, or `null` when no webhook was configured. */
|
|
491
|
+
webhook?: AsyncJobWebhookStatus | null;
|
|
492
|
+
/** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
|
|
493
|
+
usage?: UsageBlock;
|
|
494
|
+
constructor(data: TikTokLiveSearchTaskJSON);
|
|
495
|
+
static fromJSON(json: TikTokLiveSearchTaskJSON): TikTokLiveSearchTask;
|
|
496
|
+
}
|
package/dist/models/TikTok.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TikTokSearchTask = exports.TikTokProfileTask = exports.TikTokSearchResult = exports.TikTokVideo = exports.TikTokSearchSubmission = exports.TikTokProfileScrapeSubmission = void 0;
|
|
3
|
+
exports.TikTokLiveSearchTask = exports.TikTokLiveRoom = exports.TikTokLiveSearchSubmission = exports.TikTokSearchTask = exports.TikTokProfileTask = exports.TikTokSearchResult = exports.TikTokVideo = exports.TikTokSearchSubmission = exports.TikTokProfileScrapeSubmission = void 0;
|
|
4
4
|
function toInteger(value) {
|
|
5
5
|
if (value === null || value === undefined)
|
|
6
6
|
return value;
|
|
@@ -54,13 +54,25 @@ function normalizeStats(stats) {
|
|
|
54
54
|
function normalizeSearchStats(stats) {
|
|
55
55
|
if (!stats)
|
|
56
56
|
return undefined;
|
|
57
|
-
|
|
57
|
+
const normalized = {
|
|
58
58
|
pages_fetched: toOptionalInteger(stats.pages_fetched),
|
|
59
|
+
videos_fetched: toOptionalInteger(stats.videos_fetched),
|
|
59
60
|
results_count: toOptionalInteger(stats.results_count),
|
|
60
61
|
next_search_cursor: toInteger(stats.next_search_cursor),
|
|
62
|
+
parallel_search_slices: toOptionalInteger(stats.parallel_search_slices),
|
|
61
63
|
sort_by: stats.sort_by,
|
|
62
64
|
published_within: stats.published_within,
|
|
65
|
+
country: stats.country,
|
|
66
|
+
items_examined: toOptionalInteger(stats.items_examined),
|
|
67
|
+
items_filtered_out: toOptionalInteger(stats.items_filtered_out),
|
|
68
|
+
items_deduplicated: toOptionalInteger(stats.items_deduplicated),
|
|
63
69
|
};
|
|
70
|
+
// Leave out what the API did not send (the items_* counters are conditional).
|
|
71
|
+
for (const key of Object.keys(normalized)) {
|
|
72
|
+
if (normalized[key] === undefined)
|
|
73
|
+
delete normalized[key];
|
|
74
|
+
}
|
|
75
|
+
return normalized;
|
|
64
76
|
}
|
|
65
77
|
function normalizePagination(pagination) {
|
|
66
78
|
if (!pagination)
|
|
@@ -95,6 +107,7 @@ class TikTokSearchSubmission {
|
|
|
95
107
|
this.task_id = data.task_id;
|
|
96
108
|
this.task_status = data.task_status;
|
|
97
109
|
this.query = data.query;
|
|
110
|
+
this.country = data.country;
|
|
98
111
|
this.max_results = toOptionalInteger(data.max_results);
|
|
99
112
|
this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
|
|
100
113
|
this.filters = data.filters;
|
|
@@ -190,6 +203,7 @@ class TikTokSearchTask {
|
|
|
190
203
|
this.task_id = data.task_id;
|
|
191
204
|
this.task_status = data.task_status;
|
|
192
205
|
this.query = data.query;
|
|
206
|
+
this.country = data.country;
|
|
193
207
|
this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
|
|
194
208
|
this.filters = normalizeSearchFilters(data.filters);
|
|
195
209
|
this.stats = normalizeSearchStats(data.stats);
|
|
@@ -208,3 +222,88 @@ class TikTokSearchTask {
|
|
|
208
222
|
}
|
|
209
223
|
}
|
|
210
224
|
exports.TikTokSearchTask = TikTokSearchTask;
|
|
225
|
+
class TikTokLiveSearchSubmission {
|
|
226
|
+
constructor(data) {
|
|
227
|
+
this.task_id = data.task_id;
|
|
228
|
+
this.task_status = data.task_status;
|
|
229
|
+
this.query = data.query;
|
|
230
|
+
this.country = data.country;
|
|
231
|
+
this.max_results = toOptionalInteger(data.max_results);
|
|
232
|
+
this.include_stream_urls = data.include_stream_urls;
|
|
233
|
+
this.expires_at = data.expires_at;
|
|
234
|
+
this.check_status_url = data.check_status_url;
|
|
235
|
+
this.message = data.message;
|
|
236
|
+
this.webhook_url = data.webhook_url;
|
|
237
|
+
}
|
|
238
|
+
static fromJSON(json) {
|
|
239
|
+
return new TikTokLiveSearchSubmission(json);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
exports.TikTokLiveSearchSubmission = TikTokLiveSearchSubmission;
|
|
243
|
+
/** A TikTok LIVE room that was broadcasting when the search ran. */
|
|
244
|
+
class TikTokLiveRoom {
|
|
245
|
+
constructor(data) {
|
|
246
|
+
this.id = data.id;
|
|
247
|
+
this.title = data.title;
|
|
248
|
+
this.url = data.url;
|
|
249
|
+
this.started_at = toNullableDate(data.started_at);
|
|
250
|
+
this.author = data.author
|
|
251
|
+
? { ...data.author, followers: toInteger(data.author.followers) }
|
|
252
|
+
: undefined;
|
|
253
|
+
this.stats = data.stats
|
|
254
|
+
? {
|
|
255
|
+
viewers: toInteger(data.stats.viewers),
|
|
256
|
+
total_viewers: toInteger(data.stats.total_viewers),
|
|
257
|
+
likes: toInteger(data.stats.likes),
|
|
258
|
+
comments: toInteger(data.stats.comments),
|
|
259
|
+
shares: toInteger(data.stats.shares),
|
|
260
|
+
}
|
|
261
|
+
: undefined;
|
|
262
|
+
this.hashtags = data.hashtags ?? [];
|
|
263
|
+
this.category = data.category;
|
|
264
|
+
this.game_tags = data.game_tags ?? [];
|
|
265
|
+
this.cover_url = data.cover_url;
|
|
266
|
+
if (data.stream_urls) {
|
|
267
|
+
this.stream_urls = {
|
|
268
|
+
default_quality: data.stream_urls.default_quality ?? null,
|
|
269
|
+
flv: data.stream_urls.flv ?? {},
|
|
270
|
+
hls: data.stream_urls.hls ?? {},
|
|
271
|
+
audio_only: data.stream_urls.audio_only ?? null,
|
|
272
|
+
expires_at: toNullableDate(data.stream_urls.expires_at) ?? null,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
static fromJSON(json) {
|
|
277
|
+
return new TikTokLiveRoom(json);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
exports.TikTokLiveRoom = TikTokLiveRoom;
|
|
281
|
+
class TikTokLiveSearchTask {
|
|
282
|
+
constructor(data) {
|
|
283
|
+
this.task_id = data.task_id;
|
|
284
|
+
this.task_status = data.task_status;
|
|
285
|
+
this.query = data.query;
|
|
286
|
+
this.country = data.country;
|
|
287
|
+
this.stats = data.stats
|
|
288
|
+
? {
|
|
289
|
+
...data.stats,
|
|
290
|
+
pages_fetched: toOptionalInteger(data.stats.pages_fetched),
|
|
291
|
+
rooms_fetched: toOptionalInteger(data.stats.rooms_fetched),
|
|
292
|
+
results_count: toOptionalInteger(data.stats.results_count),
|
|
293
|
+
}
|
|
294
|
+
: undefined;
|
|
295
|
+
this.results = data.results?.map(TikTokLiveRoom.fromJSON) ?? [];
|
|
296
|
+
this.pagination = normalizePagination(data.pagination);
|
|
297
|
+
this.download_url = data.download_url;
|
|
298
|
+
this.error_message = data.error_message;
|
|
299
|
+
this.created_at = data.created_at;
|
|
300
|
+
this.completed_at = data.completed_at;
|
|
301
|
+
this.expires_at = data.expires_at;
|
|
302
|
+
this.error = data.error ?? null;
|
|
303
|
+
this.webhook = data.webhook;
|
|
304
|
+
}
|
|
305
|
+
static fromJSON(json) {
|
|
306
|
+
return new TikTokLiveSearchTask(json);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
exports.TikTokLiveSearchTask = TikTokLiveSearchTask;
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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';
|
|
4
|
-
/** `data.result` of a `tiktok_profile.*` / `tiktok_search.*` event: a summary, not the
|
|
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';
|
|
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). */
|
|
7
7
|
stats?: Record<string, unknown>;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -38,6 +38,11 @@ import {
|
|
|
38
38
|
TikTokSearchSubmissionJSON,
|
|
39
39
|
TikTokSearchTask,
|
|
40
40
|
TikTokSearchTaskJSON,
|
|
41
|
+
TikTokLiveSearchRequest,
|
|
42
|
+
TikTokLiveSearchSubmission,
|
|
43
|
+
TikTokLiveSearchSubmissionJSON,
|
|
44
|
+
TikTokLiveSearchTask,
|
|
45
|
+
TikTokLiveSearchTaskJSON,
|
|
41
46
|
TweetStatement,
|
|
42
47
|
AsyncJob,
|
|
43
48
|
AsyncJobJSON,
|
|
@@ -56,7 +61,7 @@ export { Job } from './jobs';
|
|
|
56
61
|
export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
|
|
57
62
|
|
|
58
63
|
/** SDK version (keep in sync with package.json) */
|
|
59
|
-
export const SDK_VERSION = '2.
|
|
64
|
+
export const SDK_VERSION = '2.2.0';
|
|
60
65
|
|
|
61
66
|
//region --- Interfaces ---
|
|
62
67
|
export interface SDKConfig {
|
|
@@ -172,6 +177,8 @@ export type TweetStatementJob = Job<TweetStatementAsyncJob, TweetStatement>;
|
|
|
172
177
|
export type TikTokProfileJob = Job<TikTokProfileTask, TikTokProfileTask>;
|
|
173
178
|
/** `result()` resolves to the completed task with **all** pages of `results` collected. */
|
|
174
179
|
export type TikTokSearchJob = Job<TikTokSearchTask, TikTokSearchTask>;
|
|
180
|
+
/** `result()` resolves to the completed task with **all** pages of rooms collected. */
|
|
181
|
+
export type TikTokLiveSearchJob = Job<TikTokLiveSearchTask, TikTokLiveSearchTask>;
|
|
175
182
|
|
|
176
183
|
export type UploadFileSuccessResult = {
|
|
177
184
|
status: 'success';
|
|
@@ -438,6 +445,13 @@ export class VidNavigatorClient {
|
|
|
438
445
|
*/
|
|
439
446
|
readonly tiktokSearch: JobOperation<string | TikTokSearchRequest, TikTokSearchTask, TikTokSearchTask>;
|
|
440
447
|
|
|
448
|
+
/**
|
|
449
|
+
* TikTok LIVE search, built on `POST /tiktok/live/search`: rooms broadcasting now for a keyword,
|
|
450
|
+
* with their FLV / HLS / audio-only stream URLs. The result is the completed task with every
|
|
451
|
+
* page of `results` collected. Same shapes as {@link VidNavigatorClient.transcribe}.
|
|
452
|
+
*/
|
|
453
|
+
readonly tiktokLiveSearch: JobOperation<string | TikTokLiveSearchRequest, TikTokLiveSearchTask, TikTokLiveSearchTask>;
|
|
454
|
+
|
|
441
455
|
constructor(config: SDKConfig) {
|
|
442
456
|
if (!config?.apiKey) {
|
|
443
457
|
throw new Error('An API key is required to use the VidNavigator SDK.');
|
|
@@ -520,6 +534,22 @@ export class VidNavigatorClient {
|
|
|
520
534
|
options.include_usage
|
|
521
535
|
),
|
|
522
536
|
});
|
|
537
|
+
|
|
538
|
+
this.tiktokLiveSearch = this.defineOperation({
|
|
539
|
+
jobType: 'tiktok_live_search',
|
|
540
|
+
submit: async (input: string | TikTokLiveSearchRequest) => {
|
|
541
|
+
const sub = await this.submitTikTokLiveSearch(typeof input === 'string' ? { query: input } : input);
|
|
542
|
+
return { ...sub, job_type: 'tiktok_live_search' };
|
|
543
|
+
},
|
|
544
|
+
fetchTask: (task_id) => this.getTikTokLiveSearch(task_id, { limit: 1 }),
|
|
545
|
+
toResult: (task, options) =>
|
|
546
|
+
collectAllPages(
|
|
547
|
+
(query) => this.getTikTokLiveSearch(task.task_id, query),
|
|
548
|
+
(page) => page.results,
|
|
549
|
+
(page, all) => { page.results = all; },
|
|
550
|
+
options.include_usage
|
|
551
|
+
),
|
|
552
|
+
});
|
|
523
553
|
}
|
|
524
554
|
|
|
525
555
|
private defineOperation<TInput, TTask extends PollableTask, TResult>(
|
|
@@ -606,7 +636,7 @@ export class VidNavigatorClient {
|
|
|
606
636
|
//region --- Transcripts ---
|
|
607
637
|
/**
|
|
608
638
|
* Get a transcript for any supported video. The endpoint auto-detects the
|
|
609
|
-
* platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, etc.)
|
|
639
|
+
* platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, Snapchat, etc.)
|
|
610
640
|
* from `video_url`. For Instagram, use {@link VidNavigatorClient.transcribeVideo}.
|
|
611
641
|
*/
|
|
612
642
|
async getTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult> {
|
|
@@ -697,6 +727,30 @@ export class VidNavigatorClient {
|
|
|
697
727
|
if (response.usage) task.usage = UsageBlock.fromJSON(response.usage);
|
|
698
728
|
return task;
|
|
699
729
|
}
|
|
730
|
+
|
|
731
|
+
async submitTikTokLiveSearch(payload: TikTokLiveSearchRequest): Promise<TikTokLiveSearchSubmission> {
|
|
732
|
+
const response = await this.request<ApiSuccessResponse<TikTokLiveSearchSubmissionJSON>>(
|
|
733
|
+
'POST',
|
|
734
|
+
'/tiktok/live/search',
|
|
735
|
+
payload
|
|
736
|
+
);
|
|
737
|
+
return TikTokLiveSearchSubmission.fromJSON(response.data);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
async getTikTokLiveSearch(
|
|
741
|
+
task_id: string,
|
|
742
|
+
query?: { cursor?: string; limit?: number; include_usage?: boolean }
|
|
743
|
+
): Promise<TikTokLiveSearchTask> {
|
|
744
|
+
const response = await this.request<ApiSuccessResponse<TikTokLiveSearchTaskJSON>>(
|
|
745
|
+
'GET',
|
|
746
|
+
`/tiktok/live/search/${task_id}`,
|
|
747
|
+
undefined,
|
|
748
|
+
buildTikTokPollParams(query)
|
|
749
|
+
);
|
|
750
|
+
const task = TikTokLiveSearchTask.fromJSON(response.data);
|
|
751
|
+
if (response.usage) task.usage = UsageBlock.fromJSON(response.usage);
|
|
752
|
+
return task;
|
|
753
|
+
}
|
|
700
754
|
//endregion
|
|
701
755
|
|
|
702
756
|
//region --- Files ---
|
package/src/models/TikTok.ts
CHANGED
|
@@ -47,6 +47,11 @@ export interface TikTokSearchRequest {
|
|
|
47
47
|
max_likes?: number;
|
|
48
48
|
min_views?: number;
|
|
49
49
|
max_views?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Two-letter country code (`'fr'`, `'de'`, `'jp'`, ...) whose TikTok results you get. Default `'gb'`.
|
|
52
|
+
* `'us'` is refused: TikTok asks US visitors to log in. The API lists the accepted codes.
|
|
53
|
+
*/
|
|
54
|
+
country?: string;
|
|
50
55
|
/**
|
|
51
56
|
* Where to POST a notification when the task finishes. Overrides the account-level default
|
|
52
57
|
* configured in Studio → API; pass an empty string to opt this task out of that default.
|
|
@@ -110,13 +115,24 @@ function normalizeStats(stats: TikTokProfileStats | undefined): TikTokProfileSta
|
|
|
110
115
|
|
|
111
116
|
function normalizeSearchStats(stats: TikTokSearchStats | undefined): TikTokSearchStats | undefined {
|
|
112
117
|
if (!stats) return undefined;
|
|
113
|
-
|
|
118
|
+
const normalized: TikTokSearchStats = {
|
|
114
119
|
pages_fetched: toOptionalInteger(stats.pages_fetched),
|
|
120
|
+
videos_fetched: toOptionalInteger(stats.videos_fetched),
|
|
115
121
|
results_count: toOptionalInteger(stats.results_count),
|
|
116
122
|
next_search_cursor: toInteger(stats.next_search_cursor),
|
|
123
|
+
parallel_search_slices: toOptionalInteger(stats.parallel_search_slices),
|
|
117
124
|
sort_by: stats.sort_by,
|
|
118
125
|
published_within: stats.published_within,
|
|
126
|
+
country: stats.country,
|
|
127
|
+
items_examined: toOptionalInteger(stats.items_examined),
|
|
128
|
+
items_filtered_out: toOptionalInteger(stats.items_filtered_out),
|
|
129
|
+
items_deduplicated: toOptionalInteger(stats.items_deduplicated),
|
|
119
130
|
};
|
|
131
|
+
// Leave out what the API did not send (the items_* counters are conditional).
|
|
132
|
+
for (const key of Object.keys(normalized) as Array<keyof TikTokSearchStats>) {
|
|
133
|
+
if (normalized[key] === undefined) delete normalized[key];
|
|
134
|
+
}
|
|
135
|
+
return normalized;
|
|
120
136
|
}
|
|
121
137
|
|
|
122
138
|
function normalizePagination(
|
|
@@ -173,6 +189,7 @@ export interface TikTokSearchSubmissionJSON {
|
|
|
173
189
|
task_id: string;
|
|
174
190
|
task_status: 'processing';
|
|
175
191
|
query: string;
|
|
192
|
+
country?: string;
|
|
176
193
|
max_results?: number;
|
|
177
194
|
parallel_search_slices?: number;
|
|
178
195
|
filters?: Record<string, unknown>;
|
|
@@ -186,6 +203,8 @@ export class TikTokSearchSubmission {
|
|
|
186
203
|
task_id: string;
|
|
187
204
|
task_status: 'processing';
|
|
188
205
|
query: string;
|
|
206
|
+
/** Country whose TikTok results the search returns. */
|
|
207
|
+
country?: string;
|
|
189
208
|
max_results?: number;
|
|
190
209
|
parallel_search_slices?: number;
|
|
191
210
|
filters?: Record<string, unknown>;
|
|
@@ -199,6 +218,7 @@ export class TikTokSearchSubmission {
|
|
|
199
218
|
this.task_id = data.task_id;
|
|
200
219
|
this.task_status = data.task_status;
|
|
201
220
|
this.query = data.query;
|
|
221
|
+
this.country = data.country;
|
|
202
222
|
this.max_results = toOptionalInteger(data.max_results);
|
|
203
223
|
this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
|
|
204
224
|
this.filters = data.filters;
|
|
@@ -386,12 +406,27 @@ export interface TikTokSearchFilters {
|
|
|
386
406
|
|
|
387
407
|
export interface TikTokSearchStats {
|
|
388
408
|
pages_fetched?: number;
|
|
409
|
+
/**
|
|
410
|
+
* Distinct videos TikTok returned, including those your filters dropped. Billed at
|
|
411
|
+
* 1 `residential_request` per 30, minimum 1 per search.
|
|
412
|
+
*/
|
|
413
|
+
videos_fetched?: number;
|
|
389
414
|
results_count?: number;
|
|
390
415
|
next_search_cursor?: number | null;
|
|
416
|
+
/** Slice count the search actually ran with. */
|
|
417
|
+
parallel_search_slices?: number;
|
|
391
418
|
/** Sort order the search ran with (`relevance` when `sort_by` was omitted). */
|
|
392
419
|
sort_by?: TikTokSearchSortBy;
|
|
393
420
|
/** Date window the search ran with; `all` means no window. */
|
|
394
421
|
published_within?: TikTokPublishedWithin;
|
|
422
|
+
/** Country whose TikTok results the search returned. */
|
|
423
|
+
country?: string;
|
|
424
|
+
/** Only when filters were set: videos checked against them. */
|
|
425
|
+
items_examined?: number;
|
|
426
|
+
/** Only when filters were set: videos they dropped. */
|
|
427
|
+
items_filtered_out?: number;
|
|
428
|
+
/** Only with `parallel_search_slices` > 1: videos several slices returned, counted once. */
|
|
429
|
+
items_deduplicated?: number;
|
|
395
430
|
}
|
|
396
431
|
|
|
397
432
|
export interface TikTokProfileTaskJSON {
|
|
@@ -461,6 +496,7 @@ export interface TikTokSearchTaskJSON {
|
|
|
461
496
|
task_id: string;
|
|
462
497
|
task_status: 'processing' | 'completed' | 'failed';
|
|
463
498
|
query?: string;
|
|
499
|
+
country?: string;
|
|
464
500
|
parallel_search_slices?: number;
|
|
465
501
|
filters?: TikTokSearchFilters;
|
|
466
502
|
stats?: TikTokSearchStats;
|
|
@@ -479,6 +515,8 @@ export class TikTokSearchTask {
|
|
|
479
515
|
task_id: string;
|
|
480
516
|
task_status: 'processing' | 'completed' | 'failed';
|
|
481
517
|
query?: string;
|
|
518
|
+
/** Country whose TikTok results the search returned (`gb` by default). */
|
|
519
|
+
country?: string;
|
|
482
520
|
parallel_search_slices?: number;
|
|
483
521
|
filters?: TikTokSearchFilters;
|
|
484
522
|
stats?: TikTokSearchStats;
|
|
@@ -501,6 +539,7 @@ export class TikTokSearchTask {
|
|
|
501
539
|
this.task_id = data.task_id;
|
|
502
540
|
this.task_status = data.task_status;
|
|
503
541
|
this.query = data.query;
|
|
542
|
+
this.country = data.country;
|
|
504
543
|
this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
|
|
505
544
|
this.filters = normalizeSearchFilters(data.filters);
|
|
506
545
|
this.stats = normalizeSearchStats(data.stats);
|
|
@@ -519,3 +558,265 @@ export class TikTokSearchTask {
|
|
|
519
558
|
return new TikTokSearchTask(json);
|
|
520
559
|
}
|
|
521
560
|
}
|
|
561
|
+
|
|
562
|
+
// --- LIVE search ---
|
|
563
|
+
|
|
564
|
+
export interface TikTokLiveSearchRequest {
|
|
565
|
+
query: string;
|
|
566
|
+
/** Cap on rooms. `0` or omitted means as many as TikTok serves, about 50 per keyword. */
|
|
567
|
+
max_results?: number;
|
|
568
|
+
/** Two-letter country code whose LIVE rooms you get. Default `'us'`. The API lists the accepted codes. */
|
|
569
|
+
country?: string;
|
|
570
|
+
/**
|
|
571
|
+
* The API returns each room's playback URLs by default (FLV and HLS by quality, plus an
|
|
572
|
+
* audio-only stream). Pass `false` to leave them out.
|
|
573
|
+
*/
|
|
574
|
+
include_stream_urls?: boolean;
|
|
575
|
+
/**
|
|
576
|
+
* Where to POST a notification when the task finishes. Overrides the account-level default
|
|
577
|
+
* configured in Studio → API; pass an empty string to opt this task out of that default.
|
|
578
|
+
* The event's `data.result` is a summary; read the rooms with `vn.tiktokLiveSearch.resume(task_id).result()`.
|
|
579
|
+
*/
|
|
580
|
+
webhook_url?: string;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export interface TikTokLiveSearchSubmissionJSON {
|
|
584
|
+
task_id: string;
|
|
585
|
+
task_status: 'processing';
|
|
586
|
+
query: string;
|
|
587
|
+
country?: string;
|
|
588
|
+
max_results?: number;
|
|
589
|
+
include_stream_urls?: boolean;
|
|
590
|
+
expires_at?: string;
|
|
591
|
+
check_status_url?: string;
|
|
592
|
+
message?: string;
|
|
593
|
+
webhook_url?: string | null;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export class TikTokLiveSearchSubmission {
|
|
597
|
+
task_id: string;
|
|
598
|
+
task_status: 'processing';
|
|
599
|
+
query: string;
|
|
600
|
+
country?: string;
|
|
601
|
+
max_results?: number;
|
|
602
|
+
include_stream_urls?: boolean;
|
|
603
|
+
expires_at?: string;
|
|
604
|
+
check_status_url?: string;
|
|
605
|
+
message?: string;
|
|
606
|
+
/** The URL this task's result notification will be POSTed to, or `null`. */
|
|
607
|
+
webhook_url?: string | null;
|
|
608
|
+
|
|
609
|
+
constructor(data: TikTokLiveSearchSubmissionJSON) {
|
|
610
|
+
this.task_id = data.task_id;
|
|
611
|
+
this.task_status = data.task_status;
|
|
612
|
+
this.query = data.query;
|
|
613
|
+
this.country = data.country;
|
|
614
|
+
this.max_results = toOptionalInteger(data.max_results);
|
|
615
|
+
this.include_stream_urls = data.include_stream_urls;
|
|
616
|
+
this.expires_at = data.expires_at;
|
|
617
|
+
this.check_status_url = data.check_status_url;
|
|
618
|
+
this.message = data.message;
|
|
619
|
+
this.webhook_url = data.webhook_url;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
static fromJSON(json: TikTokLiveSearchSubmissionJSON): TikTokLiveSearchSubmission {
|
|
623
|
+
return new TikTokLiveSearchSubmission(json);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
export interface TikTokLiveAuthor {
|
|
628
|
+
id?: string | null;
|
|
629
|
+
/** Username, without @. */
|
|
630
|
+
unique_id?: string | null;
|
|
631
|
+
nickname?: string | null;
|
|
632
|
+
sec_uid?: string | null;
|
|
633
|
+
followers?: number | null;
|
|
634
|
+
avatar_url?: string | null;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export interface TikTokLiveStats {
|
|
638
|
+
/** Watching when the search ran. */
|
|
639
|
+
viewers?: number | null;
|
|
640
|
+
/** Since the LIVE started. */
|
|
641
|
+
total_viewers?: number | null;
|
|
642
|
+
likes?: number | null;
|
|
643
|
+
comments?: number | null;
|
|
644
|
+
shares?: number | null;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** Quality keys of the playback URLs: those the LIVE offers, best first. */
|
|
648
|
+
export type TikTokLiveQuality = 'origin' | 'uhd' | 'hd' | 'sd' | 'ld' | (string & {});
|
|
649
|
+
|
|
650
|
+
export interface TikTokLiveStreamUrlsJSON {
|
|
651
|
+
default_quality?: TikTokLiveQuality | null;
|
|
652
|
+
flv?: Record<string, string>;
|
|
653
|
+
hls?: Record<string, string>;
|
|
654
|
+
audio_only?: string | null;
|
|
655
|
+
expires_at?: string | null;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/** Playback URLs of a LIVE room. They stop working when the LIVE ends. */
|
|
659
|
+
export interface TikTokLiveStreamUrls {
|
|
660
|
+
/** The quality TikTok plays by default (a key of `flv`). */
|
|
661
|
+
default_quality: TikTokLiveQuality | null;
|
|
662
|
+
/** HTTP-FLV URLs keyed by quality. */
|
|
663
|
+
flv: Record<string, string>;
|
|
664
|
+
/** HLS (`.m3u8`) URLs keyed by quality, when TikTok provides them. Can be empty. */
|
|
665
|
+
hls: Record<string, string>;
|
|
666
|
+
/** HTTP-FLV URL of the audio-only stream. */
|
|
667
|
+
audio_only: string | null;
|
|
668
|
+
/** Expiry of the URL signatures. */
|
|
669
|
+
expires_at: Date | null;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
export interface TikTokLiveRoomJSON {
|
|
673
|
+
id?: string | null;
|
|
674
|
+
title?: string | null;
|
|
675
|
+
url?: string | null;
|
|
676
|
+
started_at?: string | null;
|
|
677
|
+
author?: TikTokLiveAuthor;
|
|
678
|
+
stats?: TikTokLiveStats;
|
|
679
|
+
hashtags?: string[];
|
|
680
|
+
category?: string | null;
|
|
681
|
+
game_tags?: string[];
|
|
682
|
+
cover_url?: string | null;
|
|
683
|
+
stream_urls?: TikTokLiveStreamUrlsJSON;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/** A TikTok LIVE room that was broadcasting when the search ran. */
|
|
687
|
+
export class TikTokLiveRoom {
|
|
688
|
+
id?: string | null;
|
|
689
|
+
title?: string | null;
|
|
690
|
+
/** `https://www.tiktok.com/@username/live` */
|
|
691
|
+
url?: string | null;
|
|
692
|
+
started_at?: Date | null;
|
|
693
|
+
author?: TikTokLiveAuthor;
|
|
694
|
+
stats?: TikTokLiveStats;
|
|
695
|
+
/** `#tags` written in the title, without `#`. */
|
|
696
|
+
hashtags: string[];
|
|
697
|
+
/** The LIVE's category on TikTok, e.g. `'Gaming'`. */
|
|
698
|
+
category?: string | null;
|
|
699
|
+
game_tags: string[];
|
|
700
|
+
cover_url?: string | null;
|
|
701
|
+
/** Absent when the search was submitted with `include_stream_urls: false`. */
|
|
702
|
+
stream_urls?: TikTokLiveStreamUrls;
|
|
703
|
+
|
|
704
|
+
constructor(data: TikTokLiveRoomJSON) {
|
|
705
|
+
this.id = data.id;
|
|
706
|
+
this.title = data.title;
|
|
707
|
+
this.url = data.url;
|
|
708
|
+
this.started_at = toNullableDate(data.started_at);
|
|
709
|
+
this.author = data.author
|
|
710
|
+
? { ...data.author, followers: toInteger(data.author.followers) }
|
|
711
|
+
: undefined;
|
|
712
|
+
this.stats = data.stats
|
|
713
|
+
? {
|
|
714
|
+
viewers: toInteger(data.stats.viewers),
|
|
715
|
+
total_viewers: toInteger(data.stats.total_viewers),
|
|
716
|
+
likes: toInteger(data.stats.likes),
|
|
717
|
+
comments: toInteger(data.stats.comments),
|
|
718
|
+
shares: toInteger(data.stats.shares),
|
|
719
|
+
}
|
|
720
|
+
: undefined;
|
|
721
|
+
this.hashtags = data.hashtags ?? [];
|
|
722
|
+
this.category = data.category;
|
|
723
|
+
this.game_tags = data.game_tags ?? [];
|
|
724
|
+
this.cover_url = data.cover_url;
|
|
725
|
+
if (data.stream_urls) {
|
|
726
|
+
this.stream_urls = {
|
|
727
|
+
default_quality: data.stream_urls.default_quality ?? null,
|
|
728
|
+
flv: data.stream_urls.flv ?? {},
|
|
729
|
+
hls: data.stream_urls.hls ?? {},
|
|
730
|
+
audio_only: data.stream_urls.audio_only ?? null,
|
|
731
|
+
expires_at: toNullableDate(data.stream_urls.expires_at) ?? null,
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
static fromJSON(json: TikTokLiveRoomJSON): TikTokLiveRoom {
|
|
737
|
+
return new TikTokLiveRoom(json);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export interface TikTokLiveSearchStats {
|
|
742
|
+
/** TikTok pages fetched (up to 50 rooms each). */
|
|
743
|
+
pages_fetched?: number;
|
|
744
|
+
/**
|
|
745
|
+
* Distinct rooms TikTok returned, including any past `max_results`. Billed at
|
|
746
|
+
* 1 `residential_request` per 30, minimum 1 per search.
|
|
747
|
+
*/
|
|
748
|
+
rooms_fetched?: number;
|
|
749
|
+
results_count?: number;
|
|
750
|
+
/** Whether TikTok had more rooms when the search stopped. */
|
|
751
|
+
has_more?: boolean;
|
|
752
|
+
country?: string;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
export interface TikTokLiveSearchTaskJSON {
|
|
756
|
+
task_id: string;
|
|
757
|
+
task_status: 'processing' | 'completed' | 'failed';
|
|
758
|
+
query?: string;
|
|
759
|
+
country?: string;
|
|
760
|
+
stats?: TikTokLiveSearchStats;
|
|
761
|
+
results?: TikTokLiveRoomJSON[];
|
|
762
|
+
pagination?: TikTokProfilePagination;
|
|
763
|
+
download_url?: string | null;
|
|
764
|
+
error_message?: string | null;
|
|
765
|
+
created_at?: string | null;
|
|
766
|
+
completed_at?: string | null;
|
|
767
|
+
expires_at?: string | null;
|
|
768
|
+
error?: AsyncJobError | null;
|
|
769
|
+
webhook?: AsyncJobWebhookStatus | null;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
export class TikTokLiveSearchTask {
|
|
773
|
+
task_id: string;
|
|
774
|
+
task_status: 'processing' | 'completed' | 'failed';
|
|
775
|
+
query?: string;
|
|
776
|
+
/** Country whose LIVE rooms the search returned (`us` by default). */
|
|
777
|
+
country?: string;
|
|
778
|
+
stats?: TikTokLiveSearchStats;
|
|
779
|
+
/** Rooms in TikTok's ranking. */
|
|
780
|
+
results: TikTokLiveRoom[];
|
|
781
|
+
pagination?: TikTokProfilePagination;
|
|
782
|
+
download_url?: string | null;
|
|
783
|
+
/** @deprecated Use `error`, which carries a machine-readable code. */
|
|
784
|
+
error_message?: string | null;
|
|
785
|
+
created_at?: string | null;
|
|
786
|
+
completed_at?: string | null;
|
|
787
|
+
expires_at?: string | null;
|
|
788
|
+
/** Present when `task_status === 'failed'`: error code, message and HTTP status. */
|
|
789
|
+
error: AsyncJobError | null;
|
|
790
|
+
/** Webhook delivery state, or `null` when no webhook was configured. */
|
|
791
|
+
webhook?: AsyncJobWebhookStatus | null;
|
|
792
|
+
/** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
|
|
793
|
+
usage?: UsageBlock;
|
|
794
|
+
|
|
795
|
+
constructor(data: TikTokLiveSearchTaskJSON) {
|
|
796
|
+
this.task_id = data.task_id;
|
|
797
|
+
this.task_status = data.task_status;
|
|
798
|
+
this.query = data.query;
|
|
799
|
+
this.country = data.country;
|
|
800
|
+
this.stats = data.stats
|
|
801
|
+
? {
|
|
802
|
+
...data.stats,
|
|
803
|
+
pages_fetched: toOptionalInteger(data.stats.pages_fetched),
|
|
804
|
+
rooms_fetched: toOptionalInteger(data.stats.rooms_fetched),
|
|
805
|
+
results_count: toOptionalInteger(data.stats.results_count),
|
|
806
|
+
}
|
|
807
|
+
: undefined;
|
|
808
|
+
this.results = data.results?.map(TikTokLiveRoom.fromJSON) ?? [];
|
|
809
|
+
this.pagination = normalizePagination(data.pagination);
|
|
810
|
+
this.download_url = data.download_url;
|
|
811
|
+
this.error_message = data.error_message;
|
|
812
|
+
this.created_at = data.created_at;
|
|
813
|
+
this.completed_at = data.completed_at;
|
|
814
|
+
this.expires_at = data.expires_at;
|
|
815
|
+
this.error = data.error ?? null;
|
|
816
|
+
this.webhook = data.webhook;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
static fromJSON(json: TikTokLiveSearchTaskJSON): TikTokLiveSearchTask {
|
|
820
|
+
return new TikTokLiveSearchTask(json);
|
|
821
|
+
}
|
|
822
|
+
}
|
package/src/webhooks.ts
CHANGED
|
@@ -13,9 +13,11 @@ export type WebhookEventType =
|
|
|
13
13
|
| 'tiktok_profile.completed'
|
|
14
14
|
| 'tiktok_profile.failed'
|
|
15
15
|
| 'tiktok_search.completed'
|
|
16
|
-
| 'tiktok_search.failed'
|
|
16
|
+
| 'tiktok_search.failed'
|
|
17
|
+
| 'tiktok_live_search.completed'
|
|
18
|
+
| 'tiktok_live_search.failed';
|
|
17
19
|
|
|
18
|
-
/** `data.result` of a `tiktok_profile.*` / `tiktok_search.*` event: a summary, not the
|
|
20
|
+
/** `data.result` of a `tiktok_profile.*` / `tiktok_search.*` / `tiktok_live_search.*` event: a summary, not the items. */
|
|
19
21
|
export interface TikTokWebhookResult {
|
|
20
22
|
/** Same fields as the task's `stats` (e.g. `videos_matched`, or `results_count` / `sort_by` for searches). */
|
|
21
23
|
stats?: Record<string, unknown>;
|