vidnavigator 2.0.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 +45 -13
- package/dist/index.d.ts +18 -5
- package/dist/index.js +24 -5
- package/dist/models/AsyncJob.d.ts +5 -0
- package/dist/models/AsyncJob.js +2 -0
- package/dist/models/TikTok.d.ts +198 -0
- package/dist/models/TikTok.js +101 -2
- package/dist/webhooks.d.ts +4 -2
- package/package.json +39 -39
- package/src/index.ts +1135 -1082
- package/src/models/AsyncJob.ts +6 -0
- package/src/models/TikTok.ts +302 -1
- package/src/webhooks.ts +6 -2
package/src/index.ts
CHANGED
|
@@ -1,1082 +1,1135 @@
|
|
|
1
|
-
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
-
import FormData from 'form-data';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import {
|
|
5
|
-
VideoInfo,
|
|
6
|
-
VideoInfoJSON,
|
|
7
|
-
TranscriptSegmentJSON,
|
|
8
|
-
TranscriptOutput,
|
|
9
|
-
transcriptFromJSON,
|
|
10
|
-
FileInfo,
|
|
11
|
-
FileInfoJSON,
|
|
12
|
-
AnalysisResult,
|
|
13
|
-
AnalysisResultJSON,
|
|
14
|
-
VideoSearchResult,
|
|
15
|
-
VideoSearchResultJSON,
|
|
16
|
-
FileSearchResult,
|
|
17
|
-
FileSearchResultJSON,
|
|
18
|
-
UsageData,
|
|
19
|
-
UsageDataJSON,
|
|
20
|
-
Namespace,
|
|
21
|
-
NamespaceJSON,
|
|
22
|
-
NamespaceRef,
|
|
23
|
-
NamespaceRefJSON,
|
|
24
|
-
ExtractionSchema,
|
|
25
|
-
UsageBlock,
|
|
26
|
-
UsageBlockJSON,
|
|
27
|
-
CarouselInfo,
|
|
28
|
-
CarouselInfoJSON,
|
|
29
|
-
CarouselVideoResult,
|
|
30
|
-
CarouselVideoResultJSON,
|
|
31
|
-
TikTokProfileScrapeRequest,
|
|
32
|
-
TikTokProfileScrapeSubmission,
|
|
33
|
-
TikTokProfileScrapeSubmissionJSON,
|
|
34
|
-
TikTokProfileTask,
|
|
35
|
-
TikTokProfileTaskJSON,
|
|
36
|
-
TikTokSearchRequest,
|
|
37
|
-
TikTokSearchSubmission,
|
|
38
|
-
TikTokSearchSubmissionJSON,
|
|
39
|
-
TikTokSearchTask,
|
|
40
|
-
TikTokSearchTaskJSON,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
export type
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
type
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
export type
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
export
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
query: string;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
export type
|
|
251
|
-
|
|
252
|
-
query?: string;
|
|
253
|
-
transcript_text?: boolean;
|
|
254
|
-
include_usage?: boolean;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
export type
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
export type
|
|
265
|
-
|
|
266
|
-
transcript: TranscriptOutput;
|
|
267
|
-
transcript_analysis: AnalysisResult;
|
|
268
|
-
usage?: UsageBlock;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
export type
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
export type
|
|
298
|
-
file_id: string;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
* `POST /
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
*
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
*
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
),
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
(
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
async
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
async
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
async
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}>
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
const response = await this.request<
|
|
891
|
-
ApiSuccessResponse<{
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
file_info
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
//
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
*
|
|
992
|
-
*
|
|
993
|
-
*
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
}
|
|
1
|
+
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import FormData from 'form-data';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import {
|
|
5
|
+
VideoInfo,
|
|
6
|
+
VideoInfoJSON,
|
|
7
|
+
TranscriptSegmentJSON,
|
|
8
|
+
TranscriptOutput,
|
|
9
|
+
transcriptFromJSON,
|
|
10
|
+
FileInfo,
|
|
11
|
+
FileInfoJSON,
|
|
12
|
+
AnalysisResult,
|
|
13
|
+
AnalysisResultJSON,
|
|
14
|
+
VideoSearchResult,
|
|
15
|
+
VideoSearchResultJSON,
|
|
16
|
+
FileSearchResult,
|
|
17
|
+
FileSearchResultJSON,
|
|
18
|
+
UsageData,
|
|
19
|
+
UsageDataJSON,
|
|
20
|
+
Namespace,
|
|
21
|
+
NamespaceJSON,
|
|
22
|
+
NamespaceRef,
|
|
23
|
+
NamespaceRefJSON,
|
|
24
|
+
ExtractionSchema,
|
|
25
|
+
UsageBlock,
|
|
26
|
+
UsageBlockJSON,
|
|
27
|
+
CarouselInfo,
|
|
28
|
+
CarouselInfoJSON,
|
|
29
|
+
CarouselVideoResult,
|
|
30
|
+
CarouselVideoResultJSON,
|
|
31
|
+
TikTokProfileScrapeRequest,
|
|
32
|
+
TikTokProfileScrapeSubmission,
|
|
33
|
+
TikTokProfileScrapeSubmissionJSON,
|
|
34
|
+
TikTokProfileTask,
|
|
35
|
+
TikTokProfileTaskJSON,
|
|
36
|
+
TikTokSearchRequest,
|
|
37
|
+
TikTokSearchSubmission,
|
|
38
|
+
TikTokSearchSubmissionJSON,
|
|
39
|
+
TikTokSearchTask,
|
|
40
|
+
TikTokSearchTaskJSON,
|
|
41
|
+
TikTokLiveSearchRequest,
|
|
42
|
+
TikTokLiveSearchSubmission,
|
|
43
|
+
TikTokLiveSearchSubmissionJSON,
|
|
44
|
+
TikTokLiveSearchTask,
|
|
45
|
+
TikTokLiveSearchTaskJSON,
|
|
46
|
+
TweetStatement,
|
|
47
|
+
AsyncJob,
|
|
48
|
+
AsyncJobJSON,
|
|
49
|
+
AsyncJobAccepted,
|
|
50
|
+
AsyncJobAcceptedJSON,
|
|
51
|
+
TikTokProfilePagination,
|
|
52
|
+
} from './models';
|
|
53
|
+
import { VidNavigatorError, PaymentRequiredError } from './errors';
|
|
54
|
+
import { buildApiError } from './http';
|
|
55
|
+
import { Job, JobInfo, JobOperation, PollableTask, PollOptions, RunOptions, SubmitOptions } from './jobs';
|
|
56
|
+
|
|
57
|
+
export * from './models';
|
|
58
|
+
export * from './errors';
|
|
59
|
+
export * from './webhooks';
|
|
60
|
+
export { Job } from './jobs';
|
|
61
|
+
export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
|
|
62
|
+
|
|
63
|
+
/** SDK version (keep in sync with package.json) */
|
|
64
|
+
export const SDK_VERSION = '2.2.0';
|
|
65
|
+
|
|
66
|
+
//region --- Interfaces ---
|
|
67
|
+
export interface SDKConfig {
|
|
68
|
+
apiKey: string;
|
|
69
|
+
baseURL?: string;
|
|
70
|
+
axiosConfig?: AxiosRequestConfig;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface ApiSuccessResponse<T> {
|
|
74
|
+
status: 'success';
|
|
75
|
+
data: T;
|
|
76
|
+
usage?: UsageBlockJSON;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type TranscriptRequestPayload = {
|
|
80
|
+
video_url: string;
|
|
81
|
+
language?: string;
|
|
82
|
+
metadata_only?: boolean;
|
|
83
|
+
fallback_to_metadata?: boolean;
|
|
84
|
+
transcript_text?: boolean;
|
|
85
|
+
include_usage?: boolean;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type TranscribeVideoPayload = {
|
|
89
|
+
video_url: string;
|
|
90
|
+
transcript_text?: boolean;
|
|
91
|
+
all_videos?: boolean;
|
|
92
|
+
include_usage?: boolean;
|
|
93
|
+
} & WebhookOption;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Where to POST a notification when an async job finishes. Overrides the account-level default
|
|
97
|
+
* configured in Studio → API; pass an empty string to opt this job out of that default.
|
|
98
|
+
* Must be a publicly reachable https URL. This is a pass-through: polling always works either way.
|
|
99
|
+
*/
|
|
100
|
+
export type WebhookOption = { webhook_url?: string };
|
|
101
|
+
|
|
102
|
+
/** Input for {@link VidNavigatorClient.transcribe}. A plain string is treated as `video_url`. */
|
|
103
|
+
export type TranscribeInput = {
|
|
104
|
+
video_url: string;
|
|
105
|
+
transcript_text?: boolean;
|
|
106
|
+
/** Instagram carousel posts only: transcribe every video in the post. */
|
|
107
|
+
all_videos?: boolean;
|
|
108
|
+
} & WebhookOption;
|
|
109
|
+
|
|
110
|
+
/** Input for {@link VidNavigatorClient.extractVideo}: a JSON `schema`, or a JSON/YAML `schemaFilePath`. */
|
|
111
|
+
export type ExtractVideoInput =
|
|
112
|
+
| ({
|
|
113
|
+
video_url: string;
|
|
114
|
+
schema: ExtractionSchema;
|
|
115
|
+
what_to_extract?: string;
|
|
116
|
+
/** Speech-to-text the audio when no platform transcript exists. Default true. */
|
|
117
|
+
transcribe?: boolean;
|
|
118
|
+
} & WebhookOption)
|
|
119
|
+
| ({
|
|
120
|
+
video_url: string;
|
|
121
|
+
/** Path to a JSON or YAML schema file (sent as multipart form-data). */
|
|
122
|
+
schemaFilePath: string;
|
|
123
|
+
what_to_extract?: string;
|
|
124
|
+
transcribe?: boolean;
|
|
125
|
+
} & WebhookOption);
|
|
126
|
+
|
|
127
|
+
/** Input for {@link VidNavigatorClient.tweetStatement}. A plain string is treated as `tweet_id`. */
|
|
128
|
+
export type TweetStatementInput = { tweet_id: string } & WebhookOption;
|
|
129
|
+
|
|
130
|
+
export type TranscriptResult = {
|
|
131
|
+
video_info: VideoInfo;
|
|
132
|
+
transcript: TranscriptOutput;
|
|
133
|
+
usage?: UsageBlock;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export type TranscribeVideoSingleResult = {
|
|
137
|
+
video_info: VideoInfo;
|
|
138
|
+
transcript: TranscriptOutput;
|
|
139
|
+
usage?: UsageBlock;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export type TranscribeVideoCarouselResult = {
|
|
143
|
+
carousel_info: CarouselInfo;
|
|
144
|
+
videos: CarouselVideoResult[];
|
|
145
|
+
usage?: UsageBlock;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export type TranscribeVideoResult = TranscribeVideoSingleResult | TranscribeVideoCarouselResult;
|
|
149
|
+
|
|
150
|
+
/** Snapshot of a transcription task. `result` has the same shape as {@link VidNavigatorClient.transcribe}'s return value. */
|
|
151
|
+
export type TranscribeAsyncJob = AsyncJob<TranscribeVideoResult>;
|
|
152
|
+
|
|
153
|
+
/** Snapshot of an extraction task. `result` is the extracted object, shaped like your schema. */
|
|
154
|
+
export type ExtractVideoAsyncJob = AsyncJob<Record<string, unknown>>;
|
|
155
|
+
|
|
156
|
+
/** Snapshot of a tweet claim analysis task. `result` is a {@link TweetStatement}. */
|
|
157
|
+
export type TweetStatementAsyncJob = AsyncJob<TweetStatement>;
|
|
158
|
+
|
|
159
|
+
export type TranscribeJob = Job<TranscribeAsyncJob, TranscribeVideoResult>;
|
|
160
|
+
|
|
161
|
+
/** Input that always yields a single-video result (the carousel shape needs `all_videos: true`). */
|
|
162
|
+
type SingleTranscribeInput = string | (TranscribeInput & { all_videos?: false });
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* {@link JobOperation} for transcription, typed so that a plain URL (or `all_videos` left off)
|
|
166
|
+
* resolves to {@link TranscribeVideoSingleResult}.
|
|
167
|
+
*/
|
|
168
|
+
export interface TranscribeOperation extends JobOperation<string | TranscribeInput, TranscribeAsyncJob, TranscribeVideoResult> {
|
|
169
|
+
(input: SingleTranscribeInput, options?: RunOptions<TranscribeAsyncJob>): Promise<TranscribeVideoSingleResult>;
|
|
170
|
+
(input: string | TranscribeInput, options?: RunOptions<TranscribeAsyncJob>): Promise<TranscribeVideoResult>;
|
|
171
|
+
submit(input: SingleTranscribeInput, options?: SubmitOptions): Promise<Job<TranscribeAsyncJob, TranscribeVideoSingleResult>>;
|
|
172
|
+
submit(input: string | TranscribeInput, options?: SubmitOptions): Promise<Job<TranscribeAsyncJob, TranscribeVideoResult>>;
|
|
173
|
+
}
|
|
174
|
+
export type ExtractVideoJob = Job<ExtractVideoAsyncJob, ExtractDataResult>;
|
|
175
|
+
export type TweetStatementJob = Job<TweetStatementAsyncJob, TweetStatement>;
|
|
176
|
+
/** `result()` resolves to the completed task with **all** pages of `videos` collected. */
|
|
177
|
+
export type TikTokProfileJob = Job<TikTokProfileTask, TikTokProfileTask>;
|
|
178
|
+
/** `result()` resolves to the completed task with **all** pages of `results` collected. */
|
|
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>;
|
|
182
|
+
|
|
183
|
+
export type UploadFileSuccessResult = {
|
|
184
|
+
status: 'success';
|
|
185
|
+
file_id: string;
|
|
186
|
+
file_name: string;
|
|
187
|
+
file_status: 'processing' | 'completed';
|
|
188
|
+
message: string;
|
|
189
|
+
file_info: FileInfo;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export type UploadFileAcceptedResult = {
|
|
193
|
+
status: 'accepted';
|
|
194
|
+
file_id: string;
|
|
195
|
+
file_name: string;
|
|
196
|
+
file_status: 'processing';
|
|
197
|
+
message: string;
|
|
198
|
+
note?: string;
|
|
199
|
+
file_info?: FileInfo;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export type UploadFileResult = UploadFileSuccessResult | UploadFileAcceptedResult;
|
|
203
|
+
|
|
204
|
+
export interface ExtractDataResult {
|
|
205
|
+
data: Record<string, unknown>;
|
|
206
|
+
video_info?: VideoInfo;
|
|
207
|
+
file_info?: FileInfo;
|
|
208
|
+
usage?: UsageBlock;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export type YouTubeSearchFocus = 'relevance' | 'popularity' | 'brevity';
|
|
212
|
+
|
|
213
|
+
export type SearchYouTubePayload = {
|
|
214
|
+
query: string;
|
|
215
|
+
use_enhanced_search?: boolean;
|
|
216
|
+
start_year?: number;
|
|
217
|
+
end_year?: number;
|
|
218
|
+
focus?: YouTubeSearchFocus;
|
|
219
|
+
duration?: number;
|
|
220
|
+
max_results?: number;
|
|
221
|
+
include_usage?: boolean;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export type SearchYouTubeResult = {
|
|
225
|
+
results: VideoSearchResult[];
|
|
226
|
+
query: string;
|
|
227
|
+
total_found: number;
|
|
228
|
+
explanation?: string;
|
|
229
|
+
usage?: UsageBlock;
|
|
230
|
+
/** Present when a 402 partial-results response is returned. */
|
|
231
|
+
status?: 'success' | 'partial';
|
|
232
|
+
/** Present on partial results (e.g. `insufficient_credits_video_search`). */
|
|
233
|
+
error_code?: string;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export type SearchFilesPayload = {
|
|
237
|
+
query: string;
|
|
238
|
+
namespace_ids?: string[];
|
|
239
|
+
include_usage?: boolean;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export type SearchFilesResult = {
|
|
243
|
+
results: FileSearchResult[];
|
|
244
|
+
query: string;
|
|
245
|
+
total_found: number;
|
|
246
|
+
explanation?: string;
|
|
247
|
+
usage?: UsageBlock;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export type AnalyzeVideoPayload = {
|
|
251
|
+
video_url: string;
|
|
252
|
+
query?: string;
|
|
253
|
+
transcript_text?: boolean;
|
|
254
|
+
include_usage?: boolean;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export type AnalyzeFilePayload = {
|
|
258
|
+
file_id: string;
|
|
259
|
+
query?: string;
|
|
260
|
+
transcript_text?: boolean;
|
|
261
|
+
include_usage?: boolean;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export type AnalyzeVideoResult = {
|
|
265
|
+
video_info: VideoInfo;
|
|
266
|
+
transcript: TranscriptOutput;
|
|
267
|
+
transcript_analysis: AnalysisResult;
|
|
268
|
+
usage?: UsageBlock;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export type AnalyzeFileResult = {
|
|
272
|
+
file_info: FileInfo;
|
|
273
|
+
transcript: TranscriptOutput;
|
|
274
|
+
transcript_analysis: AnalysisResult;
|
|
275
|
+
usage?: UsageBlock;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export type ExtractVideoDataPayload = {
|
|
279
|
+
video_url: string;
|
|
280
|
+
schema: ExtractionSchema;
|
|
281
|
+
what_to_extract?: string;
|
|
282
|
+
transcribe?: boolean;
|
|
283
|
+
include_usage?: boolean;
|
|
284
|
+
} & WebhookOption;
|
|
285
|
+
|
|
286
|
+
export type ExtractVideoDataMultipartPayload = {
|
|
287
|
+
video_url: string;
|
|
288
|
+
/** Path to a JSON or YAML schema file. The API accepts either a raw schema or a full extraction request object. */
|
|
289
|
+
schemaFilePath: string;
|
|
290
|
+
what_to_extract?: string;
|
|
291
|
+
transcribe?: boolean;
|
|
292
|
+
include_usage?: boolean;
|
|
293
|
+
} & WebhookOption;
|
|
294
|
+
|
|
295
|
+
export type TweetStatementPayload = { tweet_id: string } & WebhookOption;
|
|
296
|
+
|
|
297
|
+
export type ExtractFileDataPayload = {
|
|
298
|
+
file_id: string;
|
|
299
|
+
schema: ExtractionSchema;
|
|
300
|
+
what_to_extract?: string;
|
|
301
|
+
include_usage?: boolean;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export type ExtractFileDataMultipartPayload = {
|
|
305
|
+
file_id: string;
|
|
306
|
+
/** Path to a JSON or YAML schema file. The API accepts either a raw schema or a full extraction request object. */
|
|
307
|
+
schemaFilePath: string;
|
|
308
|
+
what_to_extract?: string;
|
|
309
|
+
include_usage?: boolean;
|
|
310
|
+
};
|
|
311
|
+
//endregion
|
|
312
|
+
|
|
313
|
+
function parseTranscribeData(
|
|
314
|
+
inner:
|
|
315
|
+
| { video_info: VideoInfoJSON; transcript: TranscriptSegmentJSON[] | string }
|
|
316
|
+
| { carousel_info: CarouselInfoJSON; videos: CarouselVideoResultJSON[] },
|
|
317
|
+
usage?: UsageBlock
|
|
318
|
+
): TranscribeVideoResult {
|
|
319
|
+
if ('videos' in inner && 'carousel_info' in inner) {
|
|
320
|
+
return {
|
|
321
|
+
carousel_info: CarouselInfo.fromJSON(inner.carousel_info),
|
|
322
|
+
videos: inner.videos.map((v) => CarouselVideoResult.fromJSON(v)),
|
|
323
|
+
usage,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
const single = inner as { video_info: VideoInfoJSON; transcript: TranscriptSegmentJSON[] | string };
|
|
327
|
+
return {
|
|
328
|
+
video_info: VideoInfo.fromJSON(single.video_info),
|
|
329
|
+
transcript: transcriptFromJSON(single.transcript)!,
|
|
330
|
+
usage,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function buildAsyncJobParams(options?: SubmitOptions): Record<string, string> | undefined {
|
|
335
|
+
// Like the TikTok pollers, the async job pollers take include_usage as a query string value.
|
|
336
|
+
return options?.include_usage ? { include_usage: 'true' } : undefined;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function requireResult<T>(task: AsyncJob<T>): T {
|
|
340
|
+
if (task.result === null) {
|
|
341
|
+
const err = new VidNavigatorError(`Task ${task.task_id} completed without a result`);
|
|
342
|
+
err.task_id = task.task_id;
|
|
343
|
+
throw err;
|
|
344
|
+
}
|
|
345
|
+
return task.result;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** TikTok results are paginated; fetch every page of a completed task and merge the items. */
|
|
349
|
+
async function collectAllPages<TTask extends { pagination?: TikTokProfilePagination }, TItem>(
|
|
350
|
+
fetchPage: (query: { cursor?: string; limit: number; include_usage?: boolean }) => Promise<TTask>,
|
|
351
|
+
items: (task: TTask) => TItem[],
|
|
352
|
+
setItems: (task: TTask, all: TItem[]) => void,
|
|
353
|
+
include_usage?: boolean
|
|
354
|
+
): Promise<TTask> {
|
|
355
|
+
const first = await fetchPage({ limit: TIKTOK_PAGE_SIZE, include_usage });
|
|
356
|
+
const all = [...items(first)];
|
|
357
|
+
let cursor = first.pagination?.next_cursor ?? undefined;
|
|
358
|
+
while (cursor) {
|
|
359
|
+
const page = await fetchPage({ limit: TIKTOK_PAGE_SIZE, cursor });
|
|
360
|
+
all.push(...items(page));
|
|
361
|
+
cursor = page.pagination?.next_cursor ?? undefined;
|
|
362
|
+
}
|
|
363
|
+
setItems(first, all);
|
|
364
|
+
if (first.pagination) {
|
|
365
|
+
first.pagination = { ...first.pagination, limit: all.length, has_next: false, next_cursor: null };
|
|
366
|
+
}
|
|
367
|
+
return first;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const TIKTOK_PAGE_SIZE = 500;
|
|
371
|
+
|
|
372
|
+
interface OperationSpec<TInput, TTask extends PollableTask, TResult> {
|
|
373
|
+
jobType: string;
|
|
374
|
+
submit: (input: TInput) => Promise<JobInfo>;
|
|
375
|
+
fetchTask: (task_id: string, options: SubmitOptions) => Promise<TTask>;
|
|
376
|
+
toResult: (task: TTask, options: SubmitOptions) => Promise<TResult>;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function appendOptionalFormField(form: FormData, name: string, value: string | number | boolean | undefined): void {
|
|
380
|
+
if (value !== undefined) {
|
|
381
|
+
form.append(name, String(value));
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function buildTikTokPollParams(query?: {
|
|
386
|
+
cursor?: string;
|
|
387
|
+
limit?: number;
|
|
388
|
+
include_usage?: boolean;
|
|
389
|
+
}): Record<string, string | number> | undefined {
|
|
390
|
+
if (!query) return undefined;
|
|
391
|
+
const params: Record<string, string | number> = {};
|
|
392
|
+
if (query.cursor !== undefined) params.cursor = query.cursor;
|
|
393
|
+
if (query.limit !== undefined) params.limit = query.limit;
|
|
394
|
+
// The TikTok pollers expect include_usage as a query string value.
|
|
395
|
+
if (query.include_usage) params.include_usage = 'true';
|
|
396
|
+
return params;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const _deprecationWarned = new Set<string>();
|
|
400
|
+
|
|
401
|
+
function warnDeprecated(oldName: string, newName: string): void {
|
|
402
|
+
if (_deprecationWarned.has(oldName)) return;
|
|
403
|
+
_deprecationWarned.add(oldName);
|
|
404
|
+
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
|
|
405
|
+
console.warn(
|
|
406
|
+
`[vidnavigator] ${oldName}() is deprecated and will be removed in a future release; use ${newName}() instead.`
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export class VidNavigatorClient {
|
|
412
|
+
private client: AxiosInstance;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Speech-to-text transcription of any length (Instagram, TikTok, X, Facebook, Vimeo, ...),
|
|
416
|
+
* built on `POST /transcribe/async`.
|
|
417
|
+
*
|
|
418
|
+
* - `await vn.transcribe(url)` submits, polls, and returns the result.
|
|
419
|
+
* - `await vn.transcribe.submit(url)` returns a {@link Job} handle right away.
|
|
420
|
+
* - `vn.transcribe.resume(task_id)` reattaches to a job you already submitted.
|
|
421
|
+
*/
|
|
422
|
+
readonly transcribe: TranscribeOperation;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Structured-data extraction from a video of any length, built on `POST /extract/video/async`.
|
|
426
|
+
* The schema is validated when you submit. Same shapes as {@link VidNavigatorClient.transcribe}.
|
|
427
|
+
*/
|
|
428
|
+
readonly extractVideo: JobOperation<ExtractVideoInput, ExtractVideoAsyncJob, ExtractDataResult>;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Structured claim analysis of an X/Twitter tweet (attached media of any length), built on
|
|
432
|
+
* `POST /tweet/statement/async`. Same shapes as {@link VidNavigatorClient.transcribe}.
|
|
433
|
+
*/
|
|
434
|
+
readonly tweetStatement: JobOperation<string | TweetStatementInput, TweetStatementAsyncJob, TweetStatement>;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* TikTok profile scrape, built on `POST /tiktok/profile`. The result is the completed task with
|
|
438
|
+
* every page of `videos` collected. Same shapes as {@link VidNavigatorClient.transcribe}.
|
|
439
|
+
*/
|
|
440
|
+
readonly tiktokProfile: JobOperation<string | TikTokProfileScrapeRequest, TikTokProfileTask, TikTokProfileTask>;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* TikTok keyword search, built on `POST /tiktok/search`. The result is the completed task with
|
|
444
|
+
* every page of `results` collected. Same shapes as {@link VidNavigatorClient.transcribe}.
|
|
445
|
+
*/
|
|
446
|
+
readonly tiktokSearch: JobOperation<string | TikTokSearchRequest, TikTokSearchTask, TikTokSearchTask>;
|
|
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
|
+
|
|
455
|
+
constructor(config: SDKConfig) {
|
|
456
|
+
if (!config?.apiKey) {
|
|
457
|
+
throw new Error('An API key is required to use the VidNavigator SDK.');
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
this.client = axios.create({
|
|
461
|
+
baseURL: config.baseURL ?? 'https://api.vidnavigator.com/v1',
|
|
462
|
+
headers: {
|
|
463
|
+
'X-API-Key': config.apiKey,
|
|
464
|
+
'User-Agent': `vidnavigator-js/${SDK_VERSION}`,
|
|
465
|
+
},
|
|
466
|
+
...config.axiosConfig,
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
this.transcribe = this.defineOperation({
|
|
470
|
+
jobType: 'transcribe',
|
|
471
|
+
submit: (input: string | TranscribeInput) =>
|
|
472
|
+
this.submitAsyncJob('/transcribe/async', typeof input === 'string' ? { video_url: input } : input),
|
|
473
|
+
fetchTask: (task_id, options) =>
|
|
474
|
+
this.getAsyncJob(`/transcribe/${encodeURIComponent(task_id)}`, options, (raw) => parseTranscribeData(raw)),
|
|
475
|
+
toResult: async (task) => ({ ...requireResult(task), usage: task.usage }),
|
|
476
|
+
}) as TranscribeOperation;
|
|
477
|
+
|
|
478
|
+
this.extractVideo = this.defineOperation({
|
|
479
|
+
jobType: 'extract_video',
|
|
480
|
+
submit: (input: ExtractVideoInput) => this.submitExtractVideo(input),
|
|
481
|
+
fetchTask: (task_id, options) =>
|
|
482
|
+
this.getAsyncJob(
|
|
483
|
+
`/extract/video/${encodeURIComponent(task_id)}`,
|
|
484
|
+
options,
|
|
485
|
+
(raw) => raw as Record<string, unknown>
|
|
486
|
+
),
|
|
487
|
+
toResult: async (task) => ({ data: requireResult(task), video_info: task.video_info, usage: task.usage }),
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
this.tweetStatement = this.defineOperation({
|
|
491
|
+
jobType: 'tweet_statement',
|
|
492
|
+
submit: (input: string | TweetStatementInput) =>
|
|
493
|
+
this.submitAsyncJob('/tweet/statement/async', typeof input === 'string' ? { tweet_id: input } : input),
|
|
494
|
+
fetchTask: (task_id, options) =>
|
|
495
|
+
this.getAsyncJob(`/tweet/statement/${encodeURIComponent(task_id)}`, options, (raw) =>
|
|
496
|
+
TweetStatement.fromJSON(raw)
|
|
497
|
+
),
|
|
498
|
+
toResult: async (task) => {
|
|
499
|
+
const statement = requireResult(task);
|
|
500
|
+
statement.usage = task.usage;
|
|
501
|
+
return statement;
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
this.tiktokProfile = this.defineOperation({
|
|
506
|
+
jobType: 'tiktok_profile',
|
|
507
|
+
submit: async (input: string | TikTokProfileScrapeRequest) => {
|
|
508
|
+
const sub = await this.submitTikTokProfileScrape(typeof input === 'string' ? { profile_url: input } : input);
|
|
509
|
+
return { ...sub, job_type: 'tiktok_profile' };
|
|
510
|
+
},
|
|
511
|
+
// Status polls ask for one video only; the full result is paged in once the task completes.
|
|
512
|
+
fetchTask: (task_id) => this.getTikTokProfileScrape(task_id, { limit: 1 }),
|
|
513
|
+
toResult: (task, options) =>
|
|
514
|
+
collectAllPages(
|
|
515
|
+
(query) => this.getTikTokProfileScrape(task.task_id, query),
|
|
516
|
+
(page) => page.videos,
|
|
517
|
+
(page, all) => { page.videos = all; },
|
|
518
|
+
options.include_usage
|
|
519
|
+
),
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
this.tiktokSearch = this.defineOperation({
|
|
523
|
+
jobType: 'tiktok_search',
|
|
524
|
+
submit: async (input: string | TikTokSearchRequest) => {
|
|
525
|
+
const sub = await this.submitTikTokSearch(typeof input === 'string' ? { query: input } : input);
|
|
526
|
+
return { ...sub, job_type: 'tiktok_search' };
|
|
527
|
+
},
|
|
528
|
+
fetchTask: (task_id) => this.getTikTokSearch(task_id, { limit: 1 }),
|
|
529
|
+
toResult: (task, options) =>
|
|
530
|
+
collectAllPages(
|
|
531
|
+
(query) => this.getTikTokSearch(task.task_id, query),
|
|
532
|
+
(page) => page.results,
|
|
533
|
+
(page, all) => { page.results = all; },
|
|
534
|
+
options.include_usage
|
|
535
|
+
),
|
|
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
|
+
});
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
private defineOperation<TInput, TTask extends PollableTask, TResult>(
|
|
556
|
+
spec: OperationSpec<TInput, TTask, TResult>
|
|
557
|
+
): JobOperation<TInput, TTask, TResult> {
|
|
558
|
+
const makeJob = (info: JobInfo, options: SubmitOptions = {}) =>
|
|
559
|
+
new Job<TTask, TResult>(
|
|
560
|
+
info,
|
|
561
|
+
() => spec.fetchTask(info.task_id, options),
|
|
562
|
+
(task) => spec.toResult(task, options)
|
|
563
|
+
);
|
|
564
|
+
const submit = async (input: TInput, options?: SubmitOptions) => makeJob(await spec.submit(input), options);
|
|
565
|
+
const run = async (input: TInput, options: RunOptions<TTask> = {}) => {
|
|
566
|
+
const { include_usage, ...pollOptions } = options;
|
|
567
|
+
const job = await submit(input, { include_usage });
|
|
568
|
+
return job.result(pollOptions);
|
|
569
|
+
};
|
|
570
|
+
return Object.assign(run, {
|
|
571
|
+
submit,
|
|
572
|
+
resume: (task_id: string, options?: SubmitOptions) =>
|
|
573
|
+
makeJob({ task_id, job_type: spec.jobType }, options),
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
private async submitAsyncJob(url: string, body: unknown, headers?: Record<string, string>): Promise<JobInfo> {
|
|
578
|
+
const response = await this.request<ApiSuccessResponse<AsyncJobAcceptedJSON>>('POST', url, body, undefined, headers);
|
|
579
|
+
const accepted = AsyncJobAccepted.fromJSON(response.data);
|
|
580
|
+
return { ...accepted, job_type: accepted.job_type ?? url.split('/')[1] };
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
private submitExtractVideo(input: ExtractVideoInput): Promise<JobInfo> {
|
|
584
|
+
if ('schemaFilePath' in input) {
|
|
585
|
+
const form = new FormData();
|
|
586
|
+
form.append('video_url', input.video_url);
|
|
587
|
+
form.append('schema', fs.createReadStream(input.schemaFilePath));
|
|
588
|
+
appendOptionalFormField(form, 'what_to_extract', input.what_to_extract);
|
|
589
|
+
appendOptionalFormField(form, 'transcribe', input.transcribe);
|
|
590
|
+
appendOptionalFormField(form, 'webhook_url', input.webhook_url);
|
|
591
|
+
return this.submitAsyncJob('/extract/video/async', form, form.getHeaders());
|
|
592
|
+
}
|
|
593
|
+
return this.submitAsyncJob('/extract/video/async', input);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
private async getAsyncJob<T>(
|
|
597
|
+
url: string,
|
|
598
|
+
options: SubmitOptions | undefined,
|
|
599
|
+
parseResult: (raw: any) => T
|
|
600
|
+
): Promise<AsyncJob<T>> {
|
|
601
|
+
const response = await this.request<ApiSuccessResponse<AsyncJobJSON>>(
|
|
602
|
+
'GET',
|
|
603
|
+
url,
|
|
604
|
+
undefined,
|
|
605
|
+
buildAsyncJobParams(options)
|
|
606
|
+
);
|
|
607
|
+
const job = AsyncJob.fromJSON(response.data, parseResult);
|
|
608
|
+
if (response.usage) job.usage = UsageBlock.fromJSON(response.usage);
|
|
609
|
+
return job;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
private async request<T>(
|
|
613
|
+
method: 'GET' | 'POST' | 'DELETE' | 'PUT',
|
|
614
|
+
url: string,
|
|
615
|
+
data?: any,
|
|
616
|
+
params?: any,
|
|
617
|
+
extraHeaders?: any
|
|
618
|
+
): Promise<T> {
|
|
619
|
+
try {
|
|
620
|
+
const response = await this.client.request<T>({
|
|
621
|
+
method,
|
|
622
|
+
url,
|
|
623
|
+
data,
|
|
624
|
+
params,
|
|
625
|
+
headers: extraHeaders,
|
|
626
|
+
});
|
|
627
|
+
return response.data;
|
|
628
|
+
} catch (error: any) {
|
|
629
|
+
if (axios.isAxiosError(error) && error.response) {
|
|
630
|
+
throw buildApiError(error.response.status, error.response.data, error.message);
|
|
631
|
+
}
|
|
632
|
+
throw new VidNavigatorError(error.message);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
//region --- Transcripts ---
|
|
637
|
+
/**
|
|
638
|
+
* Get a transcript for any supported video. The endpoint auto-detects the
|
|
639
|
+
* platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, Snapchat, etc.)
|
|
640
|
+
* from `video_url`. For Instagram, use {@link VidNavigatorClient.transcribeVideo}.
|
|
641
|
+
*/
|
|
642
|
+
async getTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult> {
|
|
643
|
+
const response = await this.request<
|
|
644
|
+
ApiSuccessResponse<{
|
|
645
|
+
video_info: VideoInfoJSON;
|
|
646
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
647
|
+
}>
|
|
648
|
+
>('POST', '/transcript', payload);
|
|
649
|
+
|
|
650
|
+
return {
|
|
651
|
+
video_info: VideoInfo.fromJSON(response.data.video_info),
|
|
652
|
+
transcript: transcriptFromJSON(response.data.transcript)!,
|
|
653
|
+
usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* @deprecated There is now a single `/transcript` endpoint that auto-detects the
|
|
659
|
+
* platform. Use {@link VidNavigatorClient.getTranscript} instead. This alias
|
|
660
|
+
* forwards to `getTranscript` and will be removed in a future release.
|
|
661
|
+
*/
|
|
662
|
+
async getYouTubeTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult> {
|
|
663
|
+
warnDeprecated('getYouTubeTranscript', 'getTranscript');
|
|
664
|
+
return this.getTranscript(payload);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Speech-to-text transcription. Blocking convenience wrapper around {@link VidNavigatorClient.transcribe}:
|
|
669
|
+
* submits to `POST /transcribe/async` and polls until the job finishes, so media of any length works.
|
|
670
|
+
*/
|
|
671
|
+
async transcribeVideo(
|
|
672
|
+
payload: TranscribeVideoPayload,
|
|
673
|
+
options?: PollOptions<TranscribeAsyncJob>
|
|
674
|
+
): Promise<TranscribeVideoResult> {
|
|
675
|
+
const { include_usage, ...input } = payload;
|
|
676
|
+
return this.transcribe(input, { ...options, include_usage });
|
|
677
|
+
}
|
|
678
|
+
//endregion
|
|
679
|
+
|
|
680
|
+
//region --- TikTok ---
|
|
681
|
+
async submitTikTokProfileScrape(
|
|
682
|
+
payload: TikTokProfileScrapeRequest
|
|
683
|
+
): Promise<TikTokProfileScrapeSubmission> {
|
|
684
|
+
const response = await this.request<ApiSuccessResponse<TikTokProfileScrapeSubmissionJSON>>(
|
|
685
|
+
'POST',
|
|
686
|
+
'/tiktok/profile',
|
|
687
|
+
payload
|
|
688
|
+
);
|
|
689
|
+
return TikTokProfileScrapeSubmission.fromJSON(response.data);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
async getTikTokProfileScrape(
|
|
693
|
+
task_id: string,
|
|
694
|
+
query?: { cursor?: string; limit?: number; include_usage?: boolean }
|
|
695
|
+
): Promise<TikTokProfileTask> {
|
|
696
|
+
const response = await this.request<ApiSuccessResponse<TikTokProfileTaskJSON>>(
|
|
697
|
+
'GET',
|
|
698
|
+
`/tiktok/profile/${task_id}`,
|
|
699
|
+
undefined,
|
|
700
|
+
buildTikTokPollParams(query)
|
|
701
|
+
);
|
|
702
|
+
const task = TikTokProfileTask.fromJSON(response.data);
|
|
703
|
+
if (response.usage) task.usage = UsageBlock.fromJSON(response.usage);
|
|
704
|
+
return task;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
async submitTikTokSearch(payload: TikTokSearchRequest): Promise<TikTokSearchSubmission> {
|
|
708
|
+
const response = await this.request<ApiSuccessResponse<TikTokSearchSubmissionJSON>>(
|
|
709
|
+
'POST',
|
|
710
|
+
'/tiktok/search',
|
|
711
|
+
payload
|
|
712
|
+
);
|
|
713
|
+
return TikTokSearchSubmission.fromJSON(response.data);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
async getTikTokSearch(
|
|
717
|
+
task_id: string,
|
|
718
|
+
query?: { cursor?: string; limit?: number; include_usage?: boolean }
|
|
719
|
+
): Promise<TikTokSearchTask> {
|
|
720
|
+
const response = await this.request<ApiSuccessResponse<TikTokSearchTaskJSON>>(
|
|
721
|
+
'GET',
|
|
722
|
+
`/tiktok/search/${task_id}`,
|
|
723
|
+
undefined,
|
|
724
|
+
buildTikTokPollParams(query)
|
|
725
|
+
);
|
|
726
|
+
const task = TikTokSearchTask.fromJSON(response.data);
|
|
727
|
+
if (response.usage) task.usage = UsageBlock.fromJSON(response.usage);
|
|
728
|
+
return task;
|
|
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
|
+
}
|
|
754
|
+
//endregion
|
|
755
|
+
|
|
756
|
+
//region --- Files ---
|
|
757
|
+
async getFiles(query?: {
|
|
758
|
+
limit?: number;
|
|
759
|
+
offset?: number;
|
|
760
|
+
status?: 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
761
|
+
namespace_id?: string;
|
|
762
|
+
}): Promise<{
|
|
763
|
+
files: FileInfo[];
|
|
764
|
+
total_count: number;
|
|
765
|
+
limit: number;
|
|
766
|
+
offset: number;
|
|
767
|
+
has_more: boolean;
|
|
768
|
+
}> {
|
|
769
|
+
const response = await this.request<
|
|
770
|
+
ApiSuccessResponse<{
|
|
771
|
+
files: FileInfoJSON[];
|
|
772
|
+
total_count: number;
|
|
773
|
+
limit: number;
|
|
774
|
+
offset: number;
|
|
775
|
+
has_more: boolean;
|
|
776
|
+
}>
|
|
777
|
+
>('GET', '/files', undefined, query);
|
|
778
|
+
|
|
779
|
+
return {
|
|
780
|
+
files: response.data.files.map(FileInfo.fromJSON),
|
|
781
|
+
total_count: response.data.total_count,
|
|
782
|
+
limit: response.data.limit,
|
|
783
|
+
offset: response.data.offset,
|
|
784
|
+
has_more: response.data.has_more,
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
async getFile(
|
|
789
|
+
file_id: string,
|
|
790
|
+
query?: { transcript_text?: boolean }
|
|
791
|
+
): Promise<{ file_info: FileInfo; transcript?: TranscriptOutput }> {
|
|
792
|
+
const response = await this.request<
|
|
793
|
+
ApiSuccessResponse<{
|
|
794
|
+
file_info: FileInfoJSON;
|
|
795
|
+
transcript?: TranscriptSegmentJSON[] | string;
|
|
796
|
+
}>
|
|
797
|
+
>('GET', `/file/${file_id}`, undefined, query);
|
|
798
|
+
|
|
799
|
+
return {
|
|
800
|
+
file_info: FileInfo.fromJSON(response.data.file_info),
|
|
801
|
+
transcript: transcriptFromJSON(response.data.transcript),
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
async uploadFile(options: {
|
|
806
|
+
filePath: string;
|
|
807
|
+
wait_for_completion?: boolean;
|
|
808
|
+
namespace_ids?: string[];
|
|
809
|
+
}): Promise<UploadFileResult> {
|
|
810
|
+
const form = new FormData();
|
|
811
|
+
form.append('file', fs.createReadStream(options.filePath));
|
|
812
|
+
if (options.wait_for_completion) {
|
|
813
|
+
form.append('wait_for_completion', 'true');
|
|
814
|
+
}
|
|
815
|
+
if (options.namespace_ids?.length) {
|
|
816
|
+
form.append('namespace_ids', JSON.stringify(options.namespace_ids));
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
try {
|
|
820
|
+
const response = await this.client.post<{
|
|
821
|
+
status: 'success' | 'accepted';
|
|
822
|
+
file_id: string;
|
|
823
|
+
file_name: string;
|
|
824
|
+
file_status: 'processing' | 'completed';
|
|
825
|
+
message: string;
|
|
826
|
+
note?: string;
|
|
827
|
+
data?: { file_info: FileInfoJSON };
|
|
828
|
+
}>('/upload/file', form, { headers: form.getHeaders() });
|
|
829
|
+
|
|
830
|
+
const body = response.data;
|
|
831
|
+
const fileInfo = body.data?.file_info ? FileInfo.fromJSON(body.data.file_info) : undefined;
|
|
832
|
+
if (body.status === 'accepted') {
|
|
833
|
+
return {
|
|
834
|
+
status: 'accepted',
|
|
835
|
+
file_id: body.file_id,
|
|
836
|
+
file_name: body.file_name,
|
|
837
|
+
file_status: body.file_status as 'processing',
|
|
838
|
+
message: body.message,
|
|
839
|
+
note: body.note,
|
|
840
|
+
file_info: fileInfo,
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
return {
|
|
844
|
+
status: 'success',
|
|
845
|
+
file_id: body.file_id,
|
|
846
|
+
file_name: body.file_name,
|
|
847
|
+
file_status: body.file_status,
|
|
848
|
+
message: body.message,
|
|
849
|
+
file_info: fileInfo!,
|
|
850
|
+
};
|
|
851
|
+
} catch (error: any) {
|
|
852
|
+
if (axios.isAxiosError(error) && error.response) {
|
|
853
|
+
throw buildApiError(error.response.status, error.response.data, error.message);
|
|
854
|
+
}
|
|
855
|
+
throw new VidNavigatorError(error.message);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
async deleteFile(file_id: string): Promise<{ file_id: string; file_name: string; message: string }> {
|
|
860
|
+
const response = await this.request<
|
|
861
|
+
ApiSuccessResponse<{ file_id: string; file_name: string; message: string }>
|
|
862
|
+
>('DELETE', `/file/${file_id}/delete`);
|
|
863
|
+
return response.data;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
async getFileUrl(file_id: string): Promise<{ file_id: string; file_url: string }> {
|
|
867
|
+
const response = await this.request<
|
|
868
|
+
ApiSuccessResponse<{ file_id: string; file_url: string }>
|
|
869
|
+
>('GET', `/file/${file_id}/url`);
|
|
870
|
+
return response.data;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
async retryFileProcessing(
|
|
874
|
+
file_id: string
|
|
875
|
+
): Promise<{ file_id: string; file_name: string; file_status: string; message: string }> {
|
|
876
|
+
const response = await this.request<
|
|
877
|
+
ApiSuccessResponse<{
|
|
878
|
+
file_id: string;
|
|
879
|
+
file_name: string;
|
|
880
|
+
file_status: string;
|
|
881
|
+
message: string;
|
|
882
|
+
}>
|
|
883
|
+
>('POST', `/file/${file_id}/retry`);
|
|
884
|
+
return response.data;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
async cancelFileUpload(
|
|
888
|
+
file_id: string
|
|
889
|
+
): Promise<{ file_id: string; file_name: string; message: string }> {
|
|
890
|
+
const response = await this.request<
|
|
891
|
+
ApiSuccessResponse<{ file_id: string; file_name: string; message: string }>
|
|
892
|
+
>('POST', `/file/${file_id}/cancel`);
|
|
893
|
+
return response.data;
|
|
894
|
+
}
|
|
895
|
+
//endregion
|
|
896
|
+
|
|
897
|
+
//region --- Namespaces ---
|
|
898
|
+
async getNamespaces(): Promise<Namespace[]> {
|
|
899
|
+
const response = await this.request<ApiSuccessResponse<NamespaceJSON[]>>('GET', '/namespaces');
|
|
900
|
+
return response.data.map((n) => Namespace.fromJSON(n));
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
async createNamespace(payload: { name: string }): Promise<Namespace> {
|
|
904
|
+
const response = await this.request<ApiSuccessResponse<NamespaceJSON>>('POST', '/namespaces', payload);
|
|
905
|
+
return Namespace.fromJSON(response.data);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
async updateNamespace(namespace_id: string, payload: { name: string }): Promise<{ message: string }> {
|
|
909
|
+
const body = await this.request<{ status: string; message: string }>(
|
|
910
|
+
'PUT',
|
|
911
|
+
`/namespaces/${namespace_id}`,
|
|
912
|
+
payload
|
|
913
|
+
);
|
|
914
|
+
return { message: body.message };
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
async deleteNamespace(namespace_id: string): Promise<{ message: string }> {
|
|
918
|
+
const body = await this.request<{ status: string; message: string }>(
|
|
919
|
+
'DELETE',
|
|
920
|
+
`/namespaces/${namespace_id}`
|
|
921
|
+
);
|
|
922
|
+
return { message: body.message };
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
async updateFileNamespaces(
|
|
926
|
+
file_id: string,
|
|
927
|
+
payload: { namespace_ids: string[] }
|
|
928
|
+
): Promise<{ message: string; namespace_ids: string[]; namespaces: NamespaceRef[] }> {
|
|
929
|
+
const body = await this.request<{
|
|
930
|
+
status: string;
|
|
931
|
+
message: string;
|
|
932
|
+
data: { namespace_ids: string[]; namespaces: NamespaceRefJSON[] };
|
|
933
|
+
}>('PUT', `/file/${file_id}/namespaces`, payload);
|
|
934
|
+
return {
|
|
935
|
+
message: body.message,
|
|
936
|
+
namespace_ids: body.data.namespace_ids,
|
|
937
|
+
namespaces: body.data.namespaces.map(NamespaceRef.fromJSON),
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
//endregion
|
|
941
|
+
|
|
942
|
+
//region --- Analysis ---
|
|
943
|
+
async analyzeVideo(payload: AnalyzeVideoPayload): Promise<AnalyzeVideoResult> {
|
|
944
|
+
const response = await this.request<
|
|
945
|
+
ApiSuccessResponse<{
|
|
946
|
+
video_info: VideoInfoJSON;
|
|
947
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
948
|
+
transcript_analysis: AnalysisResultJSON;
|
|
949
|
+
}>
|
|
950
|
+
>('POST', '/analyze/video', payload);
|
|
951
|
+
|
|
952
|
+
return {
|
|
953
|
+
video_info: VideoInfo.fromJSON(response.data.video_info),
|
|
954
|
+
transcript: transcriptFromJSON(response.data.transcript)!,
|
|
955
|
+
transcript_analysis: AnalysisResult.fromJSON(response.data.transcript_analysis),
|
|
956
|
+
usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
async analyzeFile(payload: AnalyzeFilePayload): Promise<AnalyzeFileResult> {
|
|
961
|
+
const response = await this.request<
|
|
962
|
+
ApiSuccessResponse<{
|
|
963
|
+
file_info: FileInfoJSON;
|
|
964
|
+
transcript: TranscriptSegmentJSON[] | string;
|
|
965
|
+
transcript_analysis: AnalysisResultJSON;
|
|
966
|
+
}>
|
|
967
|
+
>('POST', '/analyze/file', payload);
|
|
968
|
+
|
|
969
|
+
return {
|
|
970
|
+
file_info: FileInfo.fromJSON(response.data.file_info),
|
|
971
|
+
transcript: transcriptFromJSON(response.data.transcript)!,
|
|
972
|
+
transcript_analysis: AnalysisResult.fromJSON(response.data.transcript_analysis),
|
|
973
|
+
usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Structured claim analysis of an X/Twitter tweet. Blocking convenience wrapper around
|
|
979
|
+
* {@link VidNavigatorClient.tweetStatement}: submits to `POST /tweet/statement/async` and polls.
|
|
980
|
+
*/
|
|
981
|
+
async getTweetStatement(
|
|
982
|
+
payload: TweetStatementPayload,
|
|
983
|
+
options?: RunOptions<TweetStatementAsyncJob>
|
|
984
|
+
): Promise<TweetStatement> {
|
|
985
|
+
return this.tweetStatement(payload, options);
|
|
986
|
+
}
|
|
987
|
+
//endregion
|
|
988
|
+
|
|
989
|
+
//region --- Extraction ---
|
|
990
|
+
/**
|
|
991
|
+
* Structured-data extraction from an online video. Blocking convenience wrapper around
|
|
992
|
+
* {@link VidNavigatorClient.extractVideo}: submits to `POST /extract/video/async` and polls, so
|
|
993
|
+
* media of any length works. The result carries the extracted `data` and the video's `video_info`.
|
|
994
|
+
*/
|
|
995
|
+
async extractVideoData(
|
|
996
|
+
payload: ExtractVideoDataPayload | ExtractVideoDataMultipartPayload,
|
|
997
|
+
options?: PollOptions<ExtractVideoAsyncJob>
|
|
998
|
+
): Promise<ExtractDataResult> {
|
|
999
|
+
const { include_usage, ...input } = payload;
|
|
1000
|
+
return this.extractVideo(input as ExtractVideoInput, { ...options, include_usage });
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
async extractFileData(
|
|
1004
|
+
payload: ExtractFileDataPayload | ExtractFileDataMultipartPayload
|
|
1005
|
+
): Promise<ExtractDataResult> {
|
|
1006
|
+
if ('schemaFilePath' in payload) {
|
|
1007
|
+
const form = new FormData();
|
|
1008
|
+
form.append('file_id', payload.file_id);
|
|
1009
|
+
form.append('schema', fs.createReadStream(payload.schemaFilePath));
|
|
1010
|
+
appendOptionalFormField(form, 'what_to_extract', payload.what_to_extract);
|
|
1011
|
+
appendOptionalFormField(form, 'include_usage', payload.include_usage);
|
|
1012
|
+
|
|
1013
|
+
const body = await this.request<{
|
|
1014
|
+
status: 'success';
|
|
1015
|
+
data: Record<string, unknown>;
|
|
1016
|
+
file_info?: FileInfoJSON;
|
|
1017
|
+
usage?: UsageBlockJSON;
|
|
1018
|
+
}>('POST', '/extract/file', form, undefined, form.getHeaders());
|
|
1019
|
+
return {
|
|
1020
|
+
data: body.data,
|
|
1021
|
+
file_info: body.file_info ? FileInfo.fromJSON(body.file_info) : undefined,
|
|
1022
|
+
usage: body.usage ? UsageBlock.fromJSON(body.usage) : undefined,
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const body = await this.request<{
|
|
1027
|
+
status: 'success';
|
|
1028
|
+
data: Record<string, unknown>;
|
|
1029
|
+
file_info?: FileInfoJSON;
|
|
1030
|
+
usage?: UsageBlockJSON;
|
|
1031
|
+
}>('POST', '/extract/file', payload);
|
|
1032
|
+
return {
|
|
1033
|
+
data: body.data,
|
|
1034
|
+
file_info: body.file_info ? FileInfo.fromJSON(body.file_info) : undefined,
|
|
1035
|
+
usage: body.usage ? UsageBlock.fromJSON(body.usage) : undefined,
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
//endregion
|
|
1039
|
+
|
|
1040
|
+
//region --- Search ---
|
|
1041
|
+
/**
|
|
1042
|
+
* Search YouTube for videos with AI analysis and ranking.
|
|
1043
|
+
*
|
|
1044
|
+
* If the account runs out of `residential_request` credits mid-search, the API
|
|
1045
|
+
* returns HTTP 402 with `status: "partial"` and the videos analysed so far. The
|
|
1046
|
+
* SDK surfaces that partial payload (results, `status: "partial"`, `error_code`,
|
|
1047
|
+
* and `usage` when requested) instead of throwing.
|
|
1048
|
+
*/
|
|
1049
|
+
async searchYouTube(payload: SearchYouTubePayload): Promise<SearchYouTubeResult> {
|
|
1050
|
+
let response: {
|
|
1051
|
+
status?: 'success' | 'partial';
|
|
1052
|
+
error_code?: string;
|
|
1053
|
+
data: {
|
|
1054
|
+
results: VideoSearchResultJSON[];
|
|
1055
|
+
query: string;
|
|
1056
|
+
total_found: number;
|
|
1057
|
+
explanation?: string;
|
|
1058
|
+
};
|
|
1059
|
+
usage?: UsageBlockJSON;
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
try {
|
|
1063
|
+
response = await this.request('POST', '/youtube/search', payload);
|
|
1064
|
+
} catch (error: any) {
|
|
1065
|
+
const body = error?.details;
|
|
1066
|
+
if (error instanceof PaymentRequiredError && body?.status === 'partial' && body?.data) {
|
|
1067
|
+
response = body;
|
|
1068
|
+
} else {
|
|
1069
|
+
throw error;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
return {
|
|
1074
|
+
results: (response.data.results ?? []).map(VideoSearchResult.fromJSON),
|
|
1075
|
+
query: response.data.query,
|
|
1076
|
+
total_found: response.data.total_found,
|
|
1077
|
+
explanation: response.data.explanation,
|
|
1078
|
+
usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
|
|
1079
|
+
status: response.status,
|
|
1080
|
+
error_code: response.error_code,
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/**
|
|
1085
|
+
* @deprecated `/search/video` moved to `/youtube/search`. Use
|
|
1086
|
+
* {@link VidNavigatorClient.searchYouTube} instead. This alias forwards to
|
|
1087
|
+
* `searchYouTube` and will be removed in a future release.
|
|
1088
|
+
*/
|
|
1089
|
+
async searchVideos(payload: SearchYouTubePayload): Promise<SearchYouTubeResult> {
|
|
1090
|
+
warnDeprecated('searchVideos', 'searchYouTube');
|
|
1091
|
+
return this.searchYouTube(payload);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
async searchFiles(payload: SearchFilesPayload): Promise<SearchFilesResult> {
|
|
1095
|
+
const response = await this.request<
|
|
1096
|
+
ApiSuccessResponse<{
|
|
1097
|
+
results: FileSearchResultJSON[];
|
|
1098
|
+
query: string;
|
|
1099
|
+
total_found: number;
|
|
1100
|
+
explanation?: string;
|
|
1101
|
+
}>
|
|
1102
|
+
>('POST', '/search/file', payload);
|
|
1103
|
+
|
|
1104
|
+
return {
|
|
1105
|
+
results: response.data.results.map(FileSearchResult.fromJSON),
|
|
1106
|
+
query: response.data.query,
|
|
1107
|
+
total_found: response.data.total_found,
|
|
1108
|
+
explanation: response.data.explanation,
|
|
1109
|
+
usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
//endregion
|
|
1113
|
+
|
|
1114
|
+
//region --- System ---
|
|
1115
|
+
async getUsage(): Promise<UsageData> {
|
|
1116
|
+
const response = await this.request<ApiSuccessResponse<UsageDataJSON>>('GET', '/usage');
|
|
1117
|
+
return UsageData.fromJSON(response.data);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
async healthCheck(): Promise<{
|
|
1121
|
+
status?: string;
|
|
1122
|
+
message?: string;
|
|
1123
|
+
version?: string;
|
|
1124
|
+
endpoints?: Array<{
|
|
1125
|
+
path?: string;
|
|
1126
|
+
method?: string;
|
|
1127
|
+
description?: string;
|
|
1128
|
+
auth_required?: boolean;
|
|
1129
|
+
}>;
|
|
1130
|
+
}> {
|
|
1131
|
+
const response = await this.client.get('/health');
|
|
1132
|
+
return response.data;
|
|
1133
|
+
}
|
|
1134
|
+
//endregion
|
|
1135
|
+
}
|