stophy 0.1.1 → 0.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 +25 -18
- package/dist/index.cjs +180 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -84
- package/dist/index.d.ts +85 -84
- package/dist/index.js +180 -85
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ type ErrorResponse = {
|
|
|
8
8
|
/**
|
|
9
9
|
* Machine-readable error code.
|
|
10
10
|
*/
|
|
11
|
-
code?:
|
|
11
|
+
code?: "UNAUTHORIZED" | "INSUFFICIENT_CREDITS" | "BAD_REQUEST" | "INVALID_INPUT" | "NOT_FOUND" | "CONCURRENCY_LIMITED" | "INTERNAL_ERROR";
|
|
12
12
|
/**
|
|
13
13
|
* Human-readable error message.
|
|
14
14
|
*/
|
|
@@ -45,7 +45,7 @@ type TranscriptResult = {
|
|
|
45
45
|
};
|
|
46
46
|
type VideoDetails = {
|
|
47
47
|
id: string;
|
|
48
|
-
type?:
|
|
48
|
+
type?: "video";
|
|
49
49
|
videoUrl: string;
|
|
50
50
|
title: string | null;
|
|
51
51
|
author?: string | null;
|
|
@@ -65,7 +65,7 @@ type VideoDetails = {
|
|
|
65
65
|
};
|
|
66
66
|
type RelatedVideo = {
|
|
67
67
|
id: string;
|
|
68
|
-
type?:
|
|
68
|
+
type?: "video";
|
|
69
69
|
videoUrl: string;
|
|
70
70
|
title?: string | null;
|
|
71
71
|
author?: string | null;
|
|
@@ -131,7 +131,7 @@ type LiveChatData = {
|
|
|
131
131
|
*/
|
|
132
132
|
type VideoData = VideoDetailsData | TranscriptResult | CommentsData | LiveChatData;
|
|
133
133
|
type SearchVideo = {
|
|
134
|
-
type:
|
|
134
|
+
type: "video";
|
|
135
135
|
id: string;
|
|
136
136
|
videoUrl: string;
|
|
137
137
|
title: string;
|
|
@@ -151,7 +151,7 @@ type SearchVideo = {
|
|
|
151
151
|
thumbnails: Array<Thumbnail>;
|
|
152
152
|
};
|
|
153
153
|
type SearchShort = {
|
|
154
|
-
type:
|
|
154
|
+
type: "short";
|
|
155
155
|
id: string;
|
|
156
156
|
shortUrl: string;
|
|
157
157
|
title: string;
|
|
@@ -168,7 +168,7 @@ type SearchShort = {
|
|
|
168
168
|
thumbnails: Array<Thumbnail>;
|
|
169
169
|
};
|
|
170
170
|
type SearchPlaylist = {
|
|
171
|
-
type:
|
|
171
|
+
type: "playlist";
|
|
172
172
|
id: string;
|
|
173
173
|
playlistUrl: string;
|
|
174
174
|
title: string;
|
|
@@ -179,7 +179,7 @@ type SearchPlaylist = {
|
|
|
179
179
|
thumbnails: Array<Thumbnail>;
|
|
180
180
|
};
|
|
181
181
|
type SearchChannel = {
|
|
182
|
-
type:
|
|
182
|
+
type: "channel";
|
|
183
183
|
id: string;
|
|
184
184
|
channelUrl: string;
|
|
185
185
|
name: string;
|
|
@@ -191,13 +191,13 @@ type SearchChannel = {
|
|
|
191
191
|
thumbnails: Array<Thumbnail>;
|
|
192
192
|
};
|
|
193
193
|
type SearchItem = ({
|
|
194
|
-
type?:
|
|
194
|
+
type?: "video";
|
|
195
195
|
} & SearchVideo) | ({
|
|
196
|
-
type?:
|
|
196
|
+
type?: "short";
|
|
197
197
|
} & SearchShort) | ({
|
|
198
|
-
type?:
|
|
198
|
+
type?: "playlist";
|
|
199
199
|
} & SearchPlaylist) | ({
|
|
200
|
-
type?:
|
|
200
|
+
type?: "channel";
|
|
201
201
|
} & SearchChannel);
|
|
202
202
|
type SearchData = {
|
|
203
203
|
items: Array<SearchItem>;
|
|
@@ -254,7 +254,7 @@ type ChannelData = {
|
|
|
254
254
|
};
|
|
255
255
|
type PlaylistMeta = {
|
|
256
256
|
id: string;
|
|
257
|
-
type?:
|
|
257
|
+
type?: "playlist";
|
|
258
258
|
playlistUrl: string;
|
|
259
259
|
title?: string | null;
|
|
260
260
|
author?: string | null;
|
|
@@ -265,7 +265,7 @@ type PlaylistMeta = {
|
|
|
265
265
|
};
|
|
266
266
|
type PlaylistItem = {
|
|
267
267
|
id: string;
|
|
268
|
-
type?:
|
|
268
|
+
type?: "video";
|
|
269
269
|
videoUrl: string;
|
|
270
270
|
title?: string | null;
|
|
271
271
|
author?: string | null;
|
|
@@ -332,7 +332,7 @@ type GetVideoData = {
|
|
|
332
332
|
/**
|
|
333
333
|
* The type of data to retrieve.
|
|
334
334
|
*/
|
|
335
|
-
type:
|
|
335
|
+
type: "details" | "transcript" | "comments" | "replies" | "livechat";
|
|
336
336
|
/**
|
|
337
337
|
* Full YouTube video URL. Not required when type is replies.
|
|
338
338
|
*/
|
|
@@ -340,11 +340,11 @@ type GetVideoData = {
|
|
|
340
340
|
/**
|
|
341
341
|
* Comment sort order. Only applies when type is comments.
|
|
342
342
|
*/
|
|
343
|
-
sortBy?:
|
|
343
|
+
sortBy?: "latest" | "top";
|
|
344
344
|
/**
|
|
345
345
|
* Live chat mode. Only applies when type is livechat: 'top' = Top chat (moderated, default), 'live' = all messages. Applied on the first call; later polls keep the chosen mode.
|
|
346
346
|
*/
|
|
347
|
-
chatType?:
|
|
347
|
+
chatType?: "top" | "live";
|
|
348
348
|
/**
|
|
349
349
|
* Pagination token. Required when type is replies (use the repliesToken from a comment item); for livechat, pass the continuationToken from a previous livechat response to poll for new messages.
|
|
350
350
|
*/
|
|
@@ -352,7 +352,7 @@ type GetVideoData = {
|
|
|
352
352
|
};
|
|
353
353
|
path?: never;
|
|
354
354
|
query?: never;
|
|
355
|
-
url:
|
|
355
|
+
url: "/v1/video";
|
|
356
356
|
};
|
|
357
357
|
type GetVideoErrors = {
|
|
358
358
|
/**
|
|
@@ -385,7 +385,7 @@ type GetVideoResponses = {
|
|
|
385
385
|
success: true;
|
|
386
386
|
requestId: string;
|
|
387
387
|
data: VideoData;
|
|
388
|
-
cacheState:
|
|
388
|
+
cacheState: "hit" | "miss";
|
|
389
389
|
creditsUsed: number;
|
|
390
390
|
creditsRemaining: number;
|
|
391
391
|
};
|
|
@@ -400,23 +400,23 @@ type SearchVideosData = {
|
|
|
400
400
|
/**
|
|
401
401
|
* Filter by content type.
|
|
402
402
|
*/
|
|
403
|
-
type?:
|
|
403
|
+
type?: "video" | "short" | "channel" | "playlist" | "movie";
|
|
404
404
|
/**
|
|
405
405
|
* Sort order. Defaults to relevance.
|
|
406
406
|
*/
|
|
407
|
-
sortBy?:
|
|
407
|
+
sortBy?: "relevance" | "popularity" | "date" | "rating";
|
|
408
408
|
/**
|
|
409
409
|
* Filter by upload date.
|
|
410
410
|
*/
|
|
411
|
-
uploadDate?:
|
|
411
|
+
uploadDate?: "today" | "week" | "month" | "year";
|
|
412
412
|
/**
|
|
413
413
|
* Duration filter. Not applicable when type is short.
|
|
414
414
|
*/
|
|
415
|
-
duration?:
|
|
415
|
+
duration?: "short" | "medium" | "long";
|
|
416
416
|
/**
|
|
417
417
|
* Filter by video features.
|
|
418
418
|
*/
|
|
419
|
-
features?: Array<
|
|
419
|
+
features?: Array<"live" | "4k" | "hd" | "subtitles" | "creativeCommons" | "360" | "vr180" | "3d" | "hdr" | "location" | "purchased">;
|
|
420
420
|
/**
|
|
421
421
|
* Token from a previous response to fetch the next page.
|
|
422
422
|
*/
|
|
@@ -424,7 +424,7 @@ type SearchVideosData = {
|
|
|
424
424
|
};
|
|
425
425
|
path?: never;
|
|
426
426
|
query?: never;
|
|
427
|
-
url:
|
|
427
|
+
url: "/v1/search";
|
|
428
428
|
};
|
|
429
429
|
type SearchVideosErrors = {
|
|
430
430
|
/**
|
|
@@ -457,7 +457,7 @@ type SearchVideosResponses = {
|
|
|
457
457
|
success: true;
|
|
458
458
|
requestId: string;
|
|
459
459
|
data: SearchData;
|
|
460
|
-
cacheState:
|
|
460
|
+
cacheState: "hit" | "miss";
|
|
461
461
|
creditsUsed: number;
|
|
462
462
|
creditsRemaining: number;
|
|
463
463
|
};
|
|
@@ -472,7 +472,7 @@ type GetChannelData = {
|
|
|
472
472
|
/**
|
|
473
473
|
* Content tab to fetch. Defaults to video.
|
|
474
474
|
*/
|
|
475
|
-
tab?:
|
|
475
|
+
tab?: "video" | "short" | "playlist" | "about";
|
|
476
476
|
/**
|
|
477
477
|
* Token from a previous response to fetch the next page.
|
|
478
478
|
*/
|
|
@@ -480,11 +480,11 @@ type GetChannelData = {
|
|
|
480
480
|
/**
|
|
481
481
|
* Sort order for the selected tab.
|
|
482
482
|
*/
|
|
483
|
-
sortBy?:
|
|
483
|
+
sortBy?: "latest" | "popular" | "oldest";
|
|
484
484
|
};
|
|
485
485
|
path?: never;
|
|
486
486
|
query?: never;
|
|
487
|
-
url:
|
|
487
|
+
url: "/v1/channel";
|
|
488
488
|
};
|
|
489
489
|
type GetChannelErrors = {
|
|
490
490
|
/**
|
|
@@ -517,7 +517,7 @@ type GetChannelResponses = {
|
|
|
517
517
|
success: true;
|
|
518
518
|
requestId: string;
|
|
519
519
|
data: ChannelData;
|
|
520
|
-
cacheState:
|
|
520
|
+
cacheState: "hit" | "miss";
|
|
521
521
|
creditsUsed: number;
|
|
522
522
|
creditsRemaining: number;
|
|
523
523
|
};
|
|
@@ -536,7 +536,7 @@ type GetPlaylistData = {
|
|
|
536
536
|
};
|
|
537
537
|
path?: never;
|
|
538
538
|
query?: never;
|
|
539
|
-
url:
|
|
539
|
+
url: "/v1/playlist";
|
|
540
540
|
};
|
|
541
541
|
type GetPlaylistErrors = {
|
|
542
542
|
/**
|
|
@@ -569,7 +569,7 @@ type GetPlaylistResponses = {
|
|
|
569
569
|
success: true;
|
|
570
570
|
requestId: string;
|
|
571
571
|
data: PlaylistData;
|
|
572
|
-
cacheState:
|
|
572
|
+
cacheState: "hit" | "miss";
|
|
573
573
|
creditsUsed: number;
|
|
574
574
|
creditsRemaining: number;
|
|
575
575
|
};
|
|
@@ -592,7 +592,7 @@ type GetSuggestionsData = {
|
|
|
592
592
|
*/
|
|
593
593
|
gl?: string;
|
|
594
594
|
};
|
|
595
|
-
url:
|
|
595
|
+
url: "/v1/suggest";
|
|
596
596
|
};
|
|
597
597
|
type GetSuggestionsErrors = {
|
|
598
598
|
/**
|
|
@@ -621,7 +621,7 @@ type GetSuggestionsResponses = {
|
|
|
621
621
|
success: true;
|
|
622
622
|
requestId: string;
|
|
623
623
|
data: SuggestData;
|
|
624
|
-
cacheState:
|
|
624
|
+
cacheState: "hit" | "miss";
|
|
625
625
|
creditsUsed: number;
|
|
626
626
|
creditsRemaining: number;
|
|
627
627
|
};
|
|
@@ -631,7 +631,7 @@ type GetCreditsData = {
|
|
|
631
631
|
body?: never;
|
|
632
632
|
path?: never;
|
|
633
633
|
query?: never;
|
|
634
|
-
url:
|
|
634
|
+
url: "/v1/credits";
|
|
635
635
|
};
|
|
636
636
|
type GetCreditsErrors = {
|
|
637
637
|
/**
|
|
@@ -658,7 +658,7 @@ type GetLogsData = {
|
|
|
658
658
|
/**
|
|
659
659
|
* Time window: 'today', the last 7 days, or the last 30 days.
|
|
660
660
|
*/
|
|
661
|
-
days?:
|
|
661
|
+
days?: "today" | "7" | "30";
|
|
662
662
|
/**
|
|
663
663
|
* Filter logs to a single endpoint, e.g. /video.
|
|
664
664
|
*/
|
|
@@ -668,7 +668,7 @@ type GetLogsData = {
|
|
|
668
668
|
*/
|
|
669
669
|
page?: number;
|
|
670
670
|
};
|
|
671
|
-
url:
|
|
671
|
+
url: "/v1/logs";
|
|
672
672
|
};
|
|
673
673
|
type GetLogsErrors = {
|
|
674
674
|
/**
|
|
@@ -695,13 +695,13 @@ type GetUsageData = {
|
|
|
695
695
|
/**
|
|
696
696
|
* Time window: 'today', the last 7 days, or the last 30 days.
|
|
697
697
|
*/
|
|
698
|
-
days?:
|
|
698
|
+
days?: "today" | "7" | "30";
|
|
699
699
|
/**
|
|
700
700
|
* Timezone offset in minutes used to bucket activity into days. Defaults to UTC.
|
|
701
701
|
*/
|
|
702
702
|
tz?: string;
|
|
703
703
|
};
|
|
704
|
-
url:
|
|
704
|
+
url: "/v1/usage";
|
|
705
705
|
};
|
|
706
706
|
type GetUsageErrors = {
|
|
707
707
|
/**
|
|
@@ -722,57 +722,42 @@ type GetUsageResponses = {
|
|
|
722
722
|
};
|
|
723
723
|
type GetUsageResponse = GetUsageResponses[keyof GetUsageResponses];
|
|
724
724
|
type ClientOptions = {
|
|
725
|
-
baseUrl:
|
|
725
|
+
baseUrl: "https://api.stophy.dev" | (string & {});
|
|
726
726
|
};
|
|
727
727
|
|
|
728
|
-
|
|
729
|
-
type
|
|
730
|
-
|
|
728
|
+
type ChannelBody = GetChannelData["body"];
|
|
729
|
+
type ChannelOptions = Omit<ChannelBody, "channelUrl">;
|
|
730
|
+
|
|
731
|
+
type PlaylistBody = GetPlaylistData["body"];
|
|
732
|
+
type PlaylistOptions = Omit<PlaylistBody, "playlistUrl">;
|
|
733
|
+
|
|
734
|
+
type SearchBody = SearchVideosData["body"];
|
|
735
|
+
type SearchOptions = Omit<SearchBody, "q">;
|
|
736
|
+
|
|
737
|
+
type SuggestQuery = GetSuggestionsData["query"];
|
|
738
|
+
type SuggestOptions = Omit<SuggestQuery, "q">;
|
|
739
|
+
|
|
740
|
+
type VideoResponseFor<T> = Omit<GetVideoResponse, "data"> & {
|
|
741
|
+
data: T;
|
|
731
742
|
};
|
|
743
|
+
type CommentsOptions = Pick<GetVideoData["body"], "sortBy" | "continuationToken">;
|
|
744
|
+
type LiveChatOptions = Pick<GetVideoData["body"], "chatType" | "continuationToken">;
|
|
732
745
|
|
|
733
746
|
interface StophyOptions {
|
|
734
|
-
/**
|
|
735
|
-
apiKey
|
|
736
|
-
/** Defaults to `https://api.stophy.dev`. */
|
|
747
|
+
/** Defaults to `STOPHY_API_KEY`. */
|
|
748
|
+
apiKey?: string;
|
|
749
|
+
/** Defaults to `STOPHY_BASE_URL` or `https://api.stophy.dev`. */
|
|
737
750
|
baseUrl?: string;
|
|
738
|
-
/** Bring your own `fetch` (handy for tests or non-global runtimes). */
|
|
739
751
|
fetch?: typeof globalThis.fetch;
|
|
740
|
-
/** Sent with every request. */
|
|
741
752
|
headers?: Record<string, string>;
|
|
742
|
-
/**
|
|
743
|
-
* Retry attempts for transient failures (network errors and
|
|
744
|
-
* 429/500/502/503/504). Set to `0` to disable. Defaults to `2`.
|
|
745
|
-
*/
|
|
746
753
|
maxRetries?: number;
|
|
747
|
-
/** Base delay for backoff, in ms. Defaults to `500`. */
|
|
748
754
|
retryInitialDelayMs?: number;
|
|
749
755
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
readonly code?: ErrorResponse["code"];
|
|
753
|
-
readonly status: number;
|
|
754
|
-
readonly requestId?: string;
|
|
755
|
-
readonly details?: unknown;
|
|
756
|
-
constructor(message: string, opts: {
|
|
757
|
-
status: number;
|
|
758
|
-
code?: ErrorResponse["code"];
|
|
759
|
-
requestId?: string;
|
|
760
|
-
details?: unknown;
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Stophy API client — YouTube context API for AI agents.
|
|
765
|
-
*
|
|
766
|
-
* ```ts
|
|
767
|
-
* const stophy = new Stophy({ apiKey: process.env.STOPHY_API_KEY! });
|
|
768
|
-
* const { data } = await stophy.video({ type: "transcript", videoUrl });
|
|
769
|
-
* ```
|
|
770
|
-
*/
|
|
756
|
+
type StophyClientInput = StophyOptions | string;
|
|
757
|
+
/** Typed client for the Stophy API. */
|
|
771
758
|
declare class Stophy {
|
|
772
|
-
/** The underlying fetch client, if you need lower-level access. */
|
|
773
759
|
readonly client: Client;
|
|
774
|
-
constructor(
|
|
775
|
-
/** Video details, transcript, comments, replies, or live chat — pick with `type`. */
|
|
760
|
+
constructor(input?: StophyClientInput);
|
|
776
761
|
video(body: GetVideoData["body"] & {
|
|
777
762
|
type: "details";
|
|
778
763
|
}): Promise<VideoResponseFor<VideoDetailsData>>;
|
|
@@ -786,20 +771,36 @@ declare class Stophy {
|
|
|
786
771
|
type: "livechat";
|
|
787
772
|
}): Promise<VideoResponseFor<LiveChatData>>;
|
|
788
773
|
video(body: GetVideoData["body"]): Promise<GetVideoResponse>;
|
|
789
|
-
|
|
774
|
+
videoDetails(videoUrl: string): Promise<VideoResponseFor<VideoDetailsData>>;
|
|
775
|
+
transcript(videoUrl: string): Promise<VideoResponseFor<TranscriptResult>>;
|
|
776
|
+
comments(videoUrl: string, options?: CommentsOptions): Promise<VideoResponseFor<CommentsData>>;
|
|
777
|
+
replies(continuationToken: string): Promise<VideoResponseFor<CommentsData>>;
|
|
778
|
+
liveChat(videoUrl: string, options?: LiveChatOptions): Promise<VideoResponseFor<LiveChatData>>;
|
|
790
779
|
search(body: SearchVideosData["body"]): Promise<SearchVideosResponse>;
|
|
791
|
-
|
|
780
|
+
search(query: string, options?: SearchOptions): Promise<SearchVideosResponse>;
|
|
792
781
|
channel(body: GetChannelData["body"]): Promise<GetChannelResponse>;
|
|
793
|
-
|
|
782
|
+
channel(channelUrl: string, options?: ChannelOptions): Promise<GetChannelResponse>;
|
|
794
783
|
playlist(body: GetPlaylistData["body"]): Promise<GetPlaylistResponse>;
|
|
795
|
-
|
|
784
|
+
playlist(playlistUrl: string, options?: PlaylistOptions): Promise<GetPlaylistResponse>;
|
|
796
785
|
suggest(query: GetSuggestionsData["query"]): Promise<GetSuggestionsResponse>;
|
|
797
|
-
|
|
786
|
+
suggest(query: string, options?: SuggestOptions): Promise<GetSuggestionsResponse>;
|
|
798
787
|
credits(): Promise<GetCreditsResponse>;
|
|
799
|
-
/** Recent API request logs. */
|
|
800
788
|
logs(query?: GetLogsData["query"]): Promise<GetLogsResponse>;
|
|
801
|
-
/** Daily credit and request counts. */
|
|
802
789
|
usage(query?: GetUsageData["query"]): Promise<GetUsageResponse>;
|
|
803
790
|
}
|
|
804
791
|
|
|
805
|
-
|
|
792
|
+
/** Thrown when the Stophy API responds with a non-success status. */
|
|
793
|
+
declare class StophyError extends Error {
|
|
794
|
+
readonly code?: ErrorResponse["code"];
|
|
795
|
+
readonly status: number;
|
|
796
|
+
readonly requestId?: string;
|
|
797
|
+
readonly details?: unknown;
|
|
798
|
+
constructor(message: string, options: {
|
|
799
|
+
status: number;
|
|
800
|
+
code?: ErrorResponse["code"];
|
|
801
|
+
requestId?: string;
|
|
802
|
+
details?: unknown;
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
export { type ChannelData, type ChannelLink, type ChannelOptions, type ChannelProfile, type ClientOptions, type Comment, type CommentsData, type CommentsOptions, type ContentItem, type CreditsData, type EmptyState, type ErrorResponse, type GetChannelData, type GetChannelError, type GetChannelErrors, type GetChannelResponse, type GetChannelResponses, type GetCreditsData, type GetCreditsError, type GetCreditsErrors, type GetCreditsResponse, type GetCreditsResponses, type GetLogsData, type GetLogsError, type GetLogsErrors, type GetLogsResponse, type GetLogsResponses, type GetPlaylistData, type GetPlaylistError, type GetPlaylistErrors, type GetPlaylistResponse, type GetPlaylistResponses, type GetSuggestionsData, type GetSuggestionsError, type GetSuggestionsErrors, type GetSuggestionsResponse, type GetSuggestionsResponses, type GetUsageData, type GetUsageError, type GetUsageErrors, type GetUsageResponse, type GetUsageResponses, type GetVideoData, type GetVideoError, type GetVideoErrors, type GetVideoResponse, type GetVideoResponses, type LiveChatData, type LiveChatMessage, type LiveChatOptions, type LogEntry, type LogsData, type PlaylistData, type PlaylistItem, type PlaylistMeta, type PlaylistOptions, type RelatedVideo, type SearchChannel, type SearchData, type SearchItem, type SearchOptions, type SearchPlaylist, type SearchShort, type SearchVideo, type SearchVideosData, type SearchVideosError, type SearchVideosErrors, type SearchVideosResponse, type SearchVideosResponses, Stophy, type StophyClientInput, StophyError, type StophyOptions, type SuggestData, type SuggestOptions, type Thumbnail, type TranscriptLanguage, type TranscriptResult, type TranscriptSegment, type UsageData, type UsageItem, type VideoData, type VideoDetails, type VideoDetailsData, Stophy as default };
|