vidnavigator 2.2.0 → 2.3.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 CHANGED
@@ -12,6 +12,7 @@ The official JavaScript/TypeScript SDK for the [VidNavigator Developer API](http
12
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
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
+ - **TikTok LIVE room** — check one room or streamer right away, with its latest comments, pinned comment and top viewers.
15
16
  - **Instagram carousel support** — select a specific video by index, or transcribe every video in a carousel post with one call.
16
17
  - **AI-powered analysis** — get summaries, people mentioned, places, key subjects, and direct answers to questions about any video or audio.
17
18
  - **Structured data extraction** — define a JSON schema and receive typed, structured fields extracted from any transcript (powered by LLMs).
@@ -493,6 +494,27 @@ for (const room of task.results) {
493
494
  - `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
495
  - Billing: 1 `residential_request` per 30 rooms TikTok returned (`task.stats.rooms_fetched`), minimum 1 per search.
495
496
 
497
+ ### 6c. TikTok LIVE room (sync)
498
+
499
+ `vn.getTikTokLiveRoom()` returns one LIVE room right away, no job: by `room_id`, `username` or `url` (exactly one). Use it to check whether someone is live, to follow a room found by LIVE search, or to read its latest comments:
500
+
501
+ ```ts
502
+ const { room, comments } = await vn.getTikTokLiveRoom({ username: 'tiktok', include_comments: true });
503
+
504
+ console.log(room.status, room.title, room.stats?.viewers, room.stats?.new_followers);
505
+ if (room.isLive) {
506
+ for (const c of comments ?? []) console.log(c.created_at, c.author?.unique_id, c.text);
507
+ } else {
508
+ console.log('ended at', room.ended_at);
509
+ }
510
+ ```
511
+
512
+ - `room_id`: a LIVE room id, as a string (room ids have more digits than a JavaScript number holds). `username`: the streamer, with or without `@`: their current LIVE, or their last one when they are offline. `url`: `https://www.tiktok.com/@username/live`, the profile URL, or a room's `share_url`.
513
+ - The room (`TikTokLiveRoomDetail`) has the LIVE search room fields plus `status` (`'live'` / `'ended'`, also `room.isLive`), `ended_at`, `stats.new_followers`, `author.bio`, `author.following`, `share_url`, `chat_enabled`, `subscribers_only`, `age_restricted` and `products` (items on sale). It has no likes, comment count or share count: LIVE search returns those.
514
+ - `include_comments: true` adds `comments` (newest first, up to `comments_limit`, max 50; TikTok keeps only about the last 50 of a LIVE), `pinned_comment`, `intro` and `top_viewers`. An ended room has no comments.
515
+ - A room or account that does not exist throws `NotFoundError` (`error_code` `'live_not_found'`). The call usually takes a few seconds; a shorter `axiosConfig.timeout` is raised to two minutes for it.
516
+ - Billing: 1 `residential_request` per room, 2 with `include_comments` (1 when the room has ended). Not billed when the room is not found.
517
+
496
518
  ### 7. Instagram carousel posts (multiple videos)
497
519
 
498
520
  Instagram carousel posts can contain multiple videos. You can select a specific video by index, or transcribe them all at once:
@@ -810,6 +832,7 @@ Results: `transcribe` → same shape as `transcribeVideo()`; `extractVideo` →
810
832
  | `getTikTokSearch(task_id, query?)` | Poll search status and retrieve a page of results. Options: `cursor`, `limit`, `include_usage` |
811
833
  | `submitTikTokLiveSearch(payload)` | Start an async TikTok LIVE search. Returns a `task_id` immediately. Options: `max_results`, `country`, `include_stream_urls`, `webhook_url` |
812
834
  | `getTikTokLiveSearch(task_id, query?)` | Poll LIVE search status and retrieve a page of rooms. Options: `cursor`, `limit`, `include_usage` |
835
+ | `getTikTokLiveRoom(payload)` | One LIVE room right away, by `room_id`, `username` or `url`. Options: `include_comments`, `comments_limit`, `include_stream_urls`, `include_usage` |
813
836
 
814
837
  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.
815
838
 
@@ -958,6 +981,7 @@ All API responses are parsed into typed classes with static `fromJSON()` constru
958
981
  | `TikTokLiveSearchSubmission` | Async TikTok LIVE search submission: `task_id`, query, country, `include_stream_urls`, expiry, `webhook_url` |
959
982
  | `TikTokLiveSearchTask` | TikTok LIVE search task with status, rooms, pagination, `download_url`, `error`, `webhook`; `stats.rooms_fetched` is what is billed |
960
983
  | `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) |
984
+ | `TikTokLiveRoomDetail` | A `TikTokLiveRoom` from `getTikTokLiveRoom`: `status` / `isLive`, `ended_at`, `stats.new_followers`, `author.bio`, `share_url`, `chat_enabled`, `subscribers_only`, `products` |
961
985
  | `TweetStatement` | Structured X/Twitter claim analysis, topics, entities, tone, intent, and source text |
962
986
 
963
987
  ## 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, TikTokLiveSearchRequest, TikTokLiveSearchSubmission, TikTokLiveSearchTask, 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, TikTokLiveRoomRequest, TikTokLiveRoomResult, 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.2.0";
10
+ export declare const SDK_VERSION = "2.3.0";
11
11
  export interface SDKConfig {
12
12
  apiKey: string;
13
13
  baseURL?: string;
@@ -296,6 +296,17 @@ export declare class VidNavigatorClient {
296
296
  limit?: number;
297
297
  include_usage?: boolean;
298
298
  }): Promise<TikTokLiveSearchTask>;
299
+ /**
300
+ * One TikTok LIVE room, right away (`POST /tiktok/live/room`, no job): by `room_id`, `username`
301
+ * or `url`, exactly one. The room says whether it is live or ended (and when), its viewers and new
302
+ * followers, the streamer's bio, and more. With `include_comments: true` the result also has the
303
+ * latest comments (up to 50), the pinned comment, the intro and the top viewers.
304
+ *
305
+ * The room has no likes, comment count or share count: TikTok gives those to LIVE search only.
306
+ * A room or account that does not exist throws `NotFoundError` (`error_code` `live_not_found`)
307
+ * and is not billed. Billing: 1 `residential_request`, 2 with `include_comments`.
308
+ */
309
+ getTikTokLiveRoom(payload: TikTokLiveRoomRequest): Promise<TikTokLiveRoomResult>;
299
310
  getFiles(query?: {
300
311
  limit?: number;
301
312
  offset?: number;
package/dist/index.js CHANGED
@@ -31,7 +31,12 @@ __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.2.0';
34
+ exports.SDK_VERSION = '2.3.0';
35
+ /**
36
+ * A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
37
+ * minutes at worst. A shorter configured axios timeout is raised to this for that call only.
38
+ */
39
+ const LIVE_ROOM_TIMEOUT_MS = 120000;
35
40
  //endregion
36
41
  function parseTranscribeData(inner, usage) {
37
42
  if ('videos' in inner && 'carousel_info' in inner) {
@@ -205,7 +210,11 @@ class VidNavigatorClient {
205
210
  job.usage = models_1.UsageBlock.fromJSON(response.usage);
206
211
  return job;
207
212
  }
208
- async request(method, url, data, params, extraHeaders) {
213
+ async request(method, url, data, params, extraHeaders, minTimeoutMs) {
214
+ // A call known to run long raises a configured timeout, never lowers it
215
+ // (0 / unset means no timeout at all).
216
+ const configured = this.client.defaults.timeout;
217
+ const timeout = minTimeoutMs && configured ? Math.max(configured, minTimeoutMs) : undefined;
209
218
  try {
210
219
  const response = await this.client.request({
211
220
  method,
@@ -213,6 +222,7 @@ class VidNavigatorClient {
213
222
  data,
214
223
  params,
215
224
  headers: extraHeaders,
225
+ ...(timeout !== undefined ? { timeout } : {}),
216
226
  });
217
227
  return response.data;
218
228
  }
@@ -289,6 +299,35 @@ class VidNavigatorClient {
289
299
  task.usage = models_1.UsageBlock.fromJSON(response.usage);
290
300
  return task;
291
301
  }
302
+ /**
303
+ * One TikTok LIVE room, right away (`POST /tiktok/live/room`, no job): by `room_id`, `username`
304
+ * or `url`, exactly one. The room says whether it is live or ended (and when), its viewers and new
305
+ * followers, the streamer's bio, and more. With `include_comments: true` the result also has the
306
+ * latest comments (up to 50), the pinned comment, the intro and the top viewers.
307
+ *
308
+ * The room has no likes, comment count or share count: TikTok gives those to LIVE search only.
309
+ * A room or account that does not exist throws `NotFoundError` (`error_code` `live_not_found`)
310
+ * and is not billed. Billing: 1 `residential_request`, 2 with `include_comments`.
311
+ */
312
+ async getTikTokLiveRoom(payload) {
313
+ const targets = ['room_id', 'username', 'url'].filter((key) => payload?.[key]);
314
+ if (targets.length !== 1) {
315
+ throw new errors_1.VidNavigatorError('Pass exactly one of room_id, username or url');
316
+ }
317
+ let body = payload;
318
+ const roomId = payload.room_id;
319
+ if (typeof roomId === 'number') {
320
+ if (!Number.isSafeInteger(roomId)) {
321
+ throw new errors_1.VidNavigatorError('room_id has more digits than a JavaScript number holds: pass it as a string');
322
+ }
323
+ body = { ...payload, room_id: String(roomId) };
324
+ }
325
+ const response = await this.request('POST', '/tiktok/live/room', body, undefined, undefined, LIVE_ROOM_TIMEOUT_MS);
326
+ const result = (0, models_1.tiktokLiveRoomResultFromJSON)(response.data);
327
+ if (response.usage)
328
+ result.usage = models_1.UsageBlock.fromJSON(response.usage);
329
+ return result;
330
+ }
292
331
  //endregion
293
332
  //region --- Files ---
294
333
  async getFiles(query) {
@@ -440,6 +440,123 @@ export declare class TikTokLiveRoom {
440
440
  constructor(data: TikTokLiveRoomJSON);
441
441
  static fromJSON(json: TikTokLiveRoomJSON): TikTokLiveRoom;
442
442
  }
443
+ /** Exactly one of `room_id`, `username` or `url`. */
444
+ export interface TikTokLiveRoomRequest {
445
+ /**
446
+ * A LIVE room ID, e.g. the `id` of a LIVE search room. Pass it as a string: room IDs have more
447
+ * digits than a JavaScript number holds.
448
+ */
449
+ room_id?: string;
450
+ /** The streamer, with or without `@`: their current LIVE, or their last one when they are offline. */
451
+ username?: string;
452
+ /** `https://www.tiktok.com/@username/live`, the profile URL, or a room's `share_url`. */
453
+ url?: string;
454
+ /**
455
+ * Also return the latest comments (up to 50, newest first), the pinned comment, the intro and the
456
+ * top viewers. Bills 2 `residential_request` instead of 1. Default `false`.
457
+ */
458
+ include_comments?: boolean;
459
+ /** At most this many comments, 1-50 (default 50). */
460
+ comments_limit?: number;
461
+ /** Playback URLs are returned by default; pass `false` to leave them out. */
462
+ include_stream_urls?: boolean;
463
+ /** Add the `usage` block to the result. */
464
+ include_usage?: boolean;
465
+ }
466
+ export interface TikTokLiveRoomAuthor extends TikTokLiveAuthor {
467
+ bio?: string | null;
468
+ /** Accounts the streamer follows. */
469
+ following?: number | null;
470
+ }
471
+ /** A single room's counters. Likes, comments and shares come with LIVE search only. */
472
+ export interface TikTokLiveRoomStats {
473
+ /** Watching now (0 once the LIVE has ended). */
474
+ viewers?: number | null;
475
+ /** Since the LIVE started. */
476
+ total_viewers?: number | null;
477
+ /** Followers the streamer gained during this LIVE. */
478
+ new_followers?: number | null;
479
+ }
480
+ export interface TikTokLiveRoomDetailJSON extends TikTokLiveRoomJSON {
481
+ author?: TikTokLiveRoomAuthor;
482
+ stats?: TikTokLiveRoomStats;
483
+ status?: 'live' | 'ended' | 'unknown';
484
+ ended_at?: string | null;
485
+ share_url?: string | null;
486
+ age_restricted?: boolean;
487
+ subscribers_only?: boolean;
488
+ chat_enabled?: boolean;
489
+ products?: number;
490
+ }
491
+ /** One LIVE room, as `getTikTokLiveRoom` returns it. */
492
+ export declare class TikTokLiveRoomDetail extends TikTokLiveRoom {
493
+ author?: TikTokLiveRoomAuthor;
494
+ stats?: TikTokLiveRoomStats;
495
+ /** `'live'` while broadcasting, `'ended'` once finished. */
496
+ status?: 'live' | 'ended' | 'unknown';
497
+ ended_at?: Date | null;
498
+ /** The room's share link; it can be passed back as `url`. */
499
+ share_url?: string | null;
500
+ age_restricted?: boolean;
501
+ /** Only the streamer's paying subscribers can watch. */
502
+ subscribers_only?: boolean;
503
+ chat_enabled?: boolean;
504
+ /** Products on sale in the LIVE. */
505
+ products?: number;
506
+ constructor(data: TikTokLiveRoomDetailJSON);
507
+ get isLive(): boolean;
508
+ static fromJSON(json: TikTokLiveRoomDetailJSON): TikTokLiveRoomDetail;
509
+ }
510
+ export interface TikTokLiveCommentJSON {
511
+ id?: string | null;
512
+ text?: string | null;
513
+ language?: string | null;
514
+ created_at?: string | null;
515
+ author?: TikTokLiveAuthor;
516
+ author_is_follower?: boolean;
517
+ author_is_moderator?: boolean;
518
+ author_is_subscriber?: boolean;
519
+ }
520
+ /** A comment posted in a LIVE's chat. */
521
+ export interface TikTokLiveComment {
522
+ id?: string | null;
523
+ text?: string | null;
524
+ /** ISO 639-1 code TikTok detected, or `null`. */
525
+ language?: string | null;
526
+ created_at?: Date | null;
527
+ author?: TikTokLiveAuthor;
528
+ author_is_follower?: boolean;
529
+ author_is_moderator?: boolean;
530
+ /** A paying subscriber of the streamer. */
531
+ author_is_subscriber?: boolean;
532
+ }
533
+ /** One of a LIVE's top viewers, ranked by the gifts they sent. */
534
+ export interface TikTokLiveTopViewer {
535
+ rank?: number | null;
536
+ score?: number | null;
537
+ user?: TikTokLiveAuthor;
538
+ }
539
+ export interface TikTokLiveRoomResultJSON {
540
+ room: TikTokLiveRoomDetailJSON;
541
+ comments?: TikTokLiveCommentJSON[];
542
+ pinned_comment?: TikTokLiveCommentJSON | null;
543
+ intro?: string | null;
544
+ top_viewers?: TikTokLiveTopViewer[];
545
+ }
546
+ export interface TikTokLiveRoomResult {
547
+ room: TikTokLiveRoomDetail;
548
+ /** Latest comments, newest first (TikTok keeps about the last 50). Only with `include_comments`. */
549
+ comments?: TikTokLiveComment[];
550
+ /** The comment the streamer pinned. Only with `include_comments`. */
551
+ pinned_comment?: TikTokLiveComment | null;
552
+ /** The LIVE's intro text. Only with `include_comments`. */
553
+ intro?: string | null;
554
+ /** Top viewers by gifts sent. Only with `include_comments`. */
555
+ top_viewers?: TikTokLiveTopViewer[];
556
+ /** Present when called with `include_usage: true`. */
557
+ usage?: UsageBlock;
558
+ }
559
+ export declare function tiktokLiveRoomResultFromJSON(json: TikTokLiveRoomResultJSON): TikTokLiveRoomResult;
443
560
  export interface TikTokLiveSearchStats {
444
561
  /** TikTok pages fetched (up to 50 rooms each). */
445
562
  pages_fetched?: number;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TikTokLiveSearchTask = exports.TikTokLiveRoom = exports.TikTokLiveSearchSubmission = exports.TikTokSearchTask = exports.TikTokProfileTask = exports.TikTokSearchResult = exports.TikTokVideo = exports.TikTokSearchSubmission = exports.TikTokProfileScrapeSubmission = void 0;
3
+ exports.TikTokLiveSearchTask = exports.TikTokLiveRoomDetail = exports.TikTokLiveRoom = exports.TikTokLiveSearchSubmission = exports.TikTokSearchTask = exports.TikTokProfileTask = exports.TikTokSearchResult = exports.TikTokVideo = exports.TikTokSearchSubmission = exports.TikTokProfileScrapeSubmission = void 0;
4
+ exports.tiktokLiveRoomResultFromJSON = tiktokLiveRoomResultFromJSON;
4
5
  function toInteger(value) {
5
6
  if (value === null || value === undefined)
6
7
  return value;
@@ -278,6 +279,61 @@ class TikTokLiveRoom {
278
279
  }
279
280
  }
280
281
  exports.TikTokLiveRoom = TikTokLiveRoom;
282
+ /** One LIVE room, as `getTikTokLiveRoom` returns it. */
283
+ class TikTokLiveRoomDetail extends TikTokLiveRoom {
284
+ constructor(data) {
285
+ super(data);
286
+ this.author = data.author
287
+ ? { ...data.author, followers: toInteger(data.author.followers), following: toInteger(data.author.following) }
288
+ : undefined;
289
+ this.stats = data.stats
290
+ ? {
291
+ viewers: toInteger(data.stats.viewers),
292
+ total_viewers: toInteger(data.stats.total_viewers),
293
+ new_followers: toInteger(data.stats.new_followers),
294
+ }
295
+ : undefined;
296
+ this.status = data.status;
297
+ this.ended_at = toNullableDate(data.ended_at);
298
+ this.share_url = data.share_url;
299
+ this.age_restricted = data.age_restricted;
300
+ this.subscribers_only = data.subscribers_only;
301
+ this.chat_enabled = data.chat_enabled;
302
+ this.products = toOptionalInteger(data.products);
303
+ }
304
+ get isLive() {
305
+ return this.status === 'live';
306
+ }
307
+ static fromJSON(json) {
308
+ return new TikTokLiveRoomDetail(json);
309
+ }
310
+ }
311
+ exports.TikTokLiveRoomDetail = TikTokLiveRoomDetail;
312
+ function liveCommentFromJSON(json) {
313
+ return {
314
+ ...json,
315
+ created_at: toNullableDate(json.created_at),
316
+ author: json.author ? { ...json.author, followers: toInteger(json.author.followers) } : undefined,
317
+ };
318
+ }
319
+ function tiktokLiveRoomResultFromJSON(json) {
320
+ const result = { room: TikTokLiveRoomDetail.fromJSON(json.room) };
321
+ if (json.comments !== undefined)
322
+ result.comments = (json.comments ?? []).map(liveCommentFromJSON);
323
+ if (json.pinned_comment !== undefined) {
324
+ result.pinned_comment = json.pinned_comment ? liveCommentFromJSON(json.pinned_comment) : null;
325
+ }
326
+ if (json.intro !== undefined)
327
+ result.intro = json.intro;
328
+ if (json.top_viewers !== undefined) {
329
+ result.top_viewers = (json.top_viewers ?? []).map((v) => ({
330
+ ...v,
331
+ rank: toInteger(v.rank),
332
+ score: toInteger(v.score),
333
+ }));
334
+ }
335
+ return result;
336
+ }
281
337
  class TikTokLiveSearchTask {
282
338
  constructor(data) {
283
339
  this.task_id = data.task_id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vidnavigator",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Official JavaScript SDK for the VidNavigator Developer API",
5
5
  "author": "VidNavigator",
6
6
  "license": "Apache-2.0",
package/src/index.ts CHANGED
@@ -43,6 +43,10 @@ import {
43
43
  TikTokLiveSearchSubmissionJSON,
44
44
  TikTokLiveSearchTask,
45
45
  TikTokLiveSearchTaskJSON,
46
+ TikTokLiveRoomRequest,
47
+ TikTokLiveRoomResult,
48
+ TikTokLiveRoomResultJSON,
49
+ tiktokLiveRoomResultFromJSON,
46
50
  TweetStatement,
47
51
  AsyncJob,
48
52
  AsyncJobJSON,
@@ -61,7 +65,13 @@ export { Job } from './jobs';
61
65
  export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
62
66
 
63
67
  /** SDK version (keep in sync with package.json) */
64
- export const SDK_VERSION = '2.2.0';
68
+ export const SDK_VERSION = '2.3.0';
69
+
70
+ /**
71
+ * A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
72
+ * minutes at worst. A shorter configured axios timeout is raised to this for that call only.
73
+ */
74
+ const LIVE_ROOM_TIMEOUT_MS = 120_000;
65
75
 
66
76
  //region --- Interfaces ---
67
77
  export interface SDKConfig {
@@ -614,8 +624,13 @@ export class VidNavigatorClient {
614
624
  url: string,
615
625
  data?: any,
616
626
  params?: any,
617
- extraHeaders?: any
627
+ extraHeaders?: any,
628
+ minTimeoutMs?: number
618
629
  ): Promise<T> {
630
+ // A call known to run long raises a configured timeout, never lowers it
631
+ // (0 / unset means no timeout at all).
632
+ const configured = this.client.defaults.timeout;
633
+ const timeout = minTimeoutMs && configured ? Math.max(configured, minTimeoutMs) : undefined;
619
634
  try {
620
635
  const response = await this.client.request<T>({
621
636
  method,
@@ -623,6 +638,7 @@ export class VidNavigatorClient {
623
638
  data,
624
639
  params,
625
640
  headers: extraHeaders,
641
+ ...(timeout !== undefined ? { timeout } : {}),
626
642
  });
627
643
  return response.data;
628
644
  } catch (error: any) {
@@ -751,6 +767,44 @@ export class VidNavigatorClient {
751
767
  if (response.usage) task.usage = UsageBlock.fromJSON(response.usage);
752
768
  return task;
753
769
  }
770
+
771
+ /**
772
+ * One TikTok LIVE room, right away (`POST /tiktok/live/room`, no job): by `room_id`, `username`
773
+ * or `url`, exactly one. The room says whether it is live or ended (and when), its viewers and new
774
+ * followers, the streamer's bio, and more. With `include_comments: true` the result also has the
775
+ * latest comments (up to 50), the pinned comment, the intro and the top viewers.
776
+ *
777
+ * The room has no likes, comment count or share count: TikTok gives those to LIVE search only.
778
+ * A room or account that does not exist throws `NotFoundError` (`error_code` `live_not_found`)
779
+ * and is not billed. Billing: 1 `residential_request`, 2 with `include_comments`.
780
+ */
781
+ async getTikTokLiveRoom(payload: TikTokLiveRoomRequest): Promise<TikTokLiveRoomResult> {
782
+ const targets = (['room_id', 'username', 'url'] as const).filter((key) => payload?.[key]);
783
+ if (targets.length !== 1) {
784
+ throw new VidNavigatorError('Pass exactly one of room_id, username or url');
785
+ }
786
+ let body: TikTokLiveRoomRequest = payload;
787
+ const roomId: unknown = payload.room_id;
788
+ if (typeof roomId === 'number') {
789
+ if (!Number.isSafeInteger(roomId)) {
790
+ throw new VidNavigatorError(
791
+ 'room_id has more digits than a JavaScript number holds: pass it as a string'
792
+ );
793
+ }
794
+ body = { ...payload, room_id: String(roomId) };
795
+ }
796
+ const response = await this.request<ApiSuccessResponse<TikTokLiveRoomResultJSON>>(
797
+ 'POST',
798
+ '/tiktok/live/room',
799
+ body,
800
+ undefined,
801
+ undefined,
802
+ LIVE_ROOM_TIMEOUT_MS
803
+ );
804
+ const result = tiktokLiveRoomResultFromJSON(response.data);
805
+ if (response.usage) result.usage = UsageBlock.fromJSON(response.usage);
806
+ return result;
807
+ }
754
808
  //endregion
755
809
 
756
810
  //region --- Files ---
@@ -738,6 +738,185 @@ export class TikTokLiveRoom {
738
738
  }
739
739
  }
740
740
 
741
+ // --- LIVE room ---
742
+
743
+ /** Exactly one of `room_id`, `username` or `url`. */
744
+ export interface TikTokLiveRoomRequest {
745
+ /**
746
+ * A LIVE room ID, e.g. the `id` of a LIVE search room. Pass it as a string: room IDs have more
747
+ * digits than a JavaScript number holds.
748
+ */
749
+ room_id?: string;
750
+ /** The streamer, with or without `@`: their current LIVE, or their last one when they are offline. */
751
+ username?: string;
752
+ /** `https://www.tiktok.com/@username/live`, the profile URL, or a room's `share_url`. */
753
+ url?: string;
754
+ /**
755
+ * Also return the latest comments (up to 50, newest first), the pinned comment, the intro and the
756
+ * top viewers. Bills 2 `residential_request` instead of 1. Default `false`.
757
+ */
758
+ include_comments?: boolean;
759
+ /** At most this many comments, 1-50 (default 50). */
760
+ comments_limit?: number;
761
+ /** Playback URLs are returned by default; pass `false` to leave them out. */
762
+ include_stream_urls?: boolean;
763
+ /** Add the `usage` block to the result. */
764
+ include_usage?: boolean;
765
+ }
766
+
767
+ export interface TikTokLiveRoomAuthor extends TikTokLiveAuthor {
768
+ bio?: string | null;
769
+ /** Accounts the streamer follows. */
770
+ following?: number | null;
771
+ }
772
+
773
+ /** A single room's counters. Likes, comments and shares come with LIVE search only. */
774
+ export interface TikTokLiveRoomStats {
775
+ /** Watching now (0 once the LIVE has ended). */
776
+ viewers?: number | null;
777
+ /** Since the LIVE started. */
778
+ total_viewers?: number | null;
779
+ /** Followers the streamer gained during this LIVE. */
780
+ new_followers?: number | null;
781
+ }
782
+
783
+ export interface TikTokLiveRoomDetailJSON extends TikTokLiveRoomJSON {
784
+ author?: TikTokLiveRoomAuthor;
785
+ stats?: TikTokLiveRoomStats;
786
+ status?: 'live' | 'ended' | 'unknown';
787
+ ended_at?: string | null;
788
+ share_url?: string | null;
789
+ age_restricted?: boolean;
790
+ subscribers_only?: boolean;
791
+ chat_enabled?: boolean;
792
+ products?: number;
793
+ }
794
+
795
+ /** One LIVE room, as `getTikTokLiveRoom` returns it. */
796
+ export class TikTokLiveRoomDetail extends TikTokLiveRoom {
797
+ declare author?: TikTokLiveRoomAuthor;
798
+ declare stats?: TikTokLiveRoomStats;
799
+ /** `'live'` while broadcasting, `'ended'` once finished. */
800
+ status?: 'live' | 'ended' | 'unknown';
801
+ ended_at?: Date | null;
802
+ /** The room's share link; it can be passed back as `url`. */
803
+ share_url?: string | null;
804
+ age_restricted?: boolean;
805
+ /** Only the streamer's paying subscribers can watch. */
806
+ subscribers_only?: boolean;
807
+ chat_enabled?: boolean;
808
+ /** Products on sale in the LIVE. */
809
+ products?: number;
810
+
811
+ constructor(data: TikTokLiveRoomDetailJSON) {
812
+ super(data);
813
+ this.author = data.author
814
+ ? { ...data.author, followers: toInteger(data.author.followers), following: toInteger(data.author.following) }
815
+ : undefined;
816
+ this.stats = data.stats
817
+ ? {
818
+ viewers: toInteger(data.stats.viewers),
819
+ total_viewers: toInteger(data.stats.total_viewers),
820
+ new_followers: toInteger(data.stats.new_followers),
821
+ }
822
+ : undefined;
823
+ this.status = data.status;
824
+ this.ended_at = toNullableDate(data.ended_at);
825
+ this.share_url = data.share_url;
826
+ this.age_restricted = data.age_restricted;
827
+ this.subscribers_only = data.subscribers_only;
828
+ this.chat_enabled = data.chat_enabled;
829
+ this.products = toOptionalInteger(data.products);
830
+ }
831
+
832
+ get isLive(): boolean {
833
+ return this.status === 'live';
834
+ }
835
+
836
+ static fromJSON(json: TikTokLiveRoomDetailJSON): TikTokLiveRoomDetail {
837
+ return new TikTokLiveRoomDetail(json);
838
+ }
839
+ }
840
+
841
+ export interface TikTokLiveCommentJSON {
842
+ id?: string | null;
843
+ text?: string | null;
844
+ language?: string | null;
845
+ created_at?: string | null;
846
+ author?: TikTokLiveAuthor;
847
+ author_is_follower?: boolean;
848
+ author_is_moderator?: boolean;
849
+ author_is_subscriber?: boolean;
850
+ }
851
+
852
+ /** A comment posted in a LIVE's chat. */
853
+ export interface TikTokLiveComment {
854
+ id?: string | null;
855
+ text?: string | null;
856
+ /** ISO 639-1 code TikTok detected, or `null`. */
857
+ language?: string | null;
858
+ created_at?: Date | null;
859
+ author?: TikTokLiveAuthor;
860
+ author_is_follower?: boolean;
861
+ author_is_moderator?: boolean;
862
+ /** A paying subscriber of the streamer. */
863
+ author_is_subscriber?: boolean;
864
+ }
865
+
866
+ /** One of a LIVE's top viewers, ranked by the gifts they sent. */
867
+ export interface TikTokLiveTopViewer {
868
+ rank?: number | null;
869
+ score?: number | null;
870
+ user?: TikTokLiveAuthor;
871
+ }
872
+
873
+ export interface TikTokLiveRoomResultJSON {
874
+ room: TikTokLiveRoomDetailJSON;
875
+ comments?: TikTokLiveCommentJSON[];
876
+ pinned_comment?: TikTokLiveCommentJSON | null;
877
+ intro?: string | null;
878
+ top_viewers?: TikTokLiveTopViewer[];
879
+ }
880
+
881
+ export interface TikTokLiveRoomResult {
882
+ room: TikTokLiveRoomDetail;
883
+ /** Latest comments, newest first (TikTok keeps about the last 50). Only with `include_comments`. */
884
+ comments?: TikTokLiveComment[];
885
+ /** The comment the streamer pinned. Only with `include_comments`. */
886
+ pinned_comment?: TikTokLiveComment | null;
887
+ /** The LIVE's intro text. Only with `include_comments`. */
888
+ intro?: string | null;
889
+ /** Top viewers by gifts sent. Only with `include_comments`. */
890
+ top_viewers?: TikTokLiveTopViewer[];
891
+ /** Present when called with `include_usage: true`. */
892
+ usage?: UsageBlock;
893
+ }
894
+
895
+ function liveCommentFromJSON(json: TikTokLiveCommentJSON): TikTokLiveComment {
896
+ return {
897
+ ...json,
898
+ created_at: toNullableDate(json.created_at),
899
+ author: json.author ? { ...json.author, followers: toInteger(json.author.followers) } : undefined,
900
+ };
901
+ }
902
+
903
+ export function tiktokLiveRoomResultFromJSON(json: TikTokLiveRoomResultJSON): TikTokLiveRoomResult {
904
+ const result: TikTokLiveRoomResult = { room: TikTokLiveRoomDetail.fromJSON(json.room) };
905
+ if (json.comments !== undefined) result.comments = (json.comments ?? []).map(liveCommentFromJSON);
906
+ if (json.pinned_comment !== undefined) {
907
+ result.pinned_comment = json.pinned_comment ? liveCommentFromJSON(json.pinned_comment) : null;
908
+ }
909
+ if (json.intro !== undefined) result.intro = json.intro;
910
+ if (json.top_viewers !== undefined) {
911
+ result.top_viewers = (json.top_viewers ?? []).map((v) => ({
912
+ ...v,
913
+ rank: toInteger(v.rank),
914
+ score: toInteger(v.score),
915
+ }));
916
+ }
917
+ return result;
918
+ }
919
+
741
920
  export interface TikTokLiveSearchStats {
742
921
  /** TikTok pages fetched (up to 50 rooms each). */
743
922
  pages_fetched?: number;