@aitofy/youtube 0.1.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.
@@ -0,0 +1,241 @@
1
+ /**
2
+ * YouTube Tools Type Definitions
3
+ */
4
+ interface YouTubeVideo {
5
+ /** Video ID (e.g., 'dQw4w9WgXcQ') */
6
+ videoId: string;
7
+ /** Video title */
8
+ title: string;
9
+ /** Video description (may be truncated) */
10
+ description?: string;
11
+ /** Published date in ISO 8601 format */
12
+ publishedAt: string;
13
+ /** Video duration in 'HH:MM:SS' or 'MM:SS' format */
14
+ duration?: string;
15
+ /** Duration in seconds */
16
+ durationSeconds?: number;
17
+ /** View count */
18
+ viewCount?: number;
19
+ /** Like count */
20
+ likeCount?: number;
21
+ /** Comment count */
22
+ commentCount?: number;
23
+ /** Thumbnail URLs */
24
+ thumbnails?: YouTubeThumbnails;
25
+ /** Channel ID */
26
+ channelId?: string;
27
+ /** Channel title/name */
28
+ channelTitle?: string;
29
+ /** Video URL */
30
+ url: string;
31
+ }
32
+ interface YouTubeThumbnails {
33
+ default?: string;
34
+ medium?: string;
35
+ high?: string;
36
+ standard?: string;
37
+ maxres?: string;
38
+ }
39
+ interface YouTubeChannel {
40
+ /** Channel ID */
41
+ channelId: string;
42
+ /** Channel name */
43
+ title: string;
44
+ /** Channel description */
45
+ description?: string;
46
+ /** Custom URL or handle (@username) */
47
+ customUrl?: string;
48
+ /** Subscriber count (may be hidden) */
49
+ subscriberCount?: number;
50
+ /** Total video count */
51
+ videoCount?: number;
52
+ /** Total view count */
53
+ viewCount?: number;
54
+ /** Channel thumbnails/avatars */
55
+ thumbnails?: YouTubeThumbnails;
56
+ /** Channel banner images */
57
+ banners?: YouTubeThumbnails;
58
+ /** Channel URL */
59
+ url: string;
60
+ /** Channel creation date */
61
+ publishedAt?: string;
62
+ }
63
+ interface TranscriptSegment {
64
+ /** Start time in seconds */
65
+ start: number;
66
+ /** Duration in seconds */
67
+ duration: number;
68
+ /** Text content */
69
+ text: string;
70
+ /** End time in seconds (start + duration) */
71
+ end?: number;
72
+ }
73
+ interface TranscriptOptions {
74
+ /** Language code (e.g., 'en', 'vi'). Auto-detect if not specified */
75
+ lang?: string;
76
+ /** Output format */
77
+ format?: 'json' | 'text' | 'srt' | 'vtt';
78
+ }
79
+ interface TranscriptInfo {
80
+ /** Available language codes */
81
+ availableLanguages: string[];
82
+ /** Whether auto-generated captions are available */
83
+ hasAutoGenerated: boolean;
84
+ /** Whether manual captions are available */
85
+ hasManual: boolean;
86
+ }
87
+ interface GetVideoInfoOptions {
88
+ /** Video ID or URL */
89
+ video: string;
90
+ }
91
+ declare class YouTubeToolsError extends Error {
92
+ code: string;
93
+ statusCode?: number | undefined;
94
+ constructor(message: string, code: string, statusCode?: number | undefined);
95
+ }
96
+ declare const ErrorCodes: {
97
+ readonly CHANNEL_NOT_FOUND: "CHANNEL_NOT_FOUND";
98
+ readonly VIDEO_NOT_FOUND: "VIDEO_NOT_FOUND";
99
+ readonly TRANSCRIPT_NOT_AVAILABLE: "TRANSCRIPT_NOT_AVAILABLE";
100
+ readonly RATE_LIMITED: "RATE_LIMITED";
101
+ readonly PARSING_ERROR: "PARSING_ERROR";
102
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
103
+ };
104
+
105
+ /**
106
+ * Get Channel Videos
107
+ *
108
+ * Sử dụng 2 methods:
109
+ * 1. RSS Feed - nhanh, stable, nhưng chỉ 15 videos
110
+ * 2. Scraping - lấy được nhiều hơn với pagination
111
+ */
112
+
113
+ interface GetChannelVideosOptions {
114
+ /** Channel ID, URL, or handle (@username) */
115
+ channel: string;
116
+ /** Maximum videos to fetch. Default: 15 (RSS), set higher to use scraping */
117
+ limit?: number;
118
+ /** Sort by: newest, oldest, popular */
119
+ sortBy?: 'newest' | 'oldest' | 'popular';
120
+ /** Content type filter */
121
+ contentType?: 'videos' | 'shorts' | 'streams';
122
+ }
123
+ /**
124
+ * Get videos from a YouTube channel
125
+ */
126
+ declare function getChannelVideos(options: GetChannelVideosOptions | string): Promise<YouTubeVideo[]>;
127
+
128
+ /**
129
+ * Get Channel Info
130
+ */
131
+
132
+ /**
133
+ * Get channel information
134
+ */
135
+ declare function getChannelInfo(channel: string): Promise<YouTubeChannel>;
136
+
137
+ /**
138
+ * YouTube Transcript Fetcher - Pure Node.js
139
+ *
140
+ * Port từ youtube-transcript-api (Python) sang TypeScript
141
+ * Sử dụng Innertube API như Python library
142
+ */
143
+
144
+ interface TranscriptTrack {
145
+ languageCode: string;
146
+ language: string;
147
+ baseUrl: string;
148
+ isGenerated: boolean;
149
+ isTranslatable: boolean;
150
+ }
151
+ interface FetchTranscriptOptions {
152
+ /** Preferred language codes in order of preference */
153
+ languages?: string[];
154
+ /** If true, prefer auto-generated over manual */
155
+ preferGenerated?: boolean;
156
+ }
157
+ /**
158
+ * Fetch available transcript tracks for a video
159
+ */
160
+ declare function listTranscripts(videoId: string): Promise<TranscriptTrack[]>;
161
+ /**
162
+ * Fetch transcript segments for a video
163
+ */
164
+ declare function getTranscript(videoId: string, options?: FetchTranscriptOptions): Promise<TranscriptSegment[]>;
165
+ /**
166
+ * Fetch transcript and format as plain text
167
+ */
168
+ declare function getTranscriptText(videoId: string, options?: FetchTranscriptOptions): Promise<string>;
169
+ /**
170
+ * Fetch transcript and format as SRT
171
+ */
172
+ declare function getTranscriptSRT(videoId: string, options?: FetchTranscriptOptions): Promise<string>;
173
+ /**
174
+ * Fetch transcript and format as WebVTT
175
+ */
176
+ declare function getTranscriptVTT(videoId: string, options?: FetchTranscriptOptions): Promise<string>;
177
+
178
+ /**
179
+ * Get Video Info
180
+ *
181
+ * Lấy thông tin chi tiết của video từ YouTube page
182
+ */
183
+
184
+ interface VideoInfo extends YouTubeVideo {
185
+ /** Video description (full) */
186
+ description: string;
187
+ /** Like count */
188
+ likeCount?: number;
189
+ /** Comment count */
190
+ commentCount?: number;
191
+ /** Video category */
192
+ category?: string;
193
+ /** Video tags */
194
+ tags?: string[];
195
+ /** Video chapters */
196
+ chapters?: VideoChapter[];
197
+ /** Is live stream */
198
+ isLive?: boolean;
199
+ /** Is upcoming premiere */
200
+ isUpcoming?: boolean;
201
+ /** Keywords */
202
+ keywords?: string[];
203
+ }
204
+ interface VideoChapter {
205
+ title: string;
206
+ startTime: number;
207
+ endTime?: number;
208
+ }
209
+ /**
210
+ * Get detailed video information
211
+ */
212
+ declare function getVideoInfo(videoIdOrUrl: string): Promise<VideoInfo>;
213
+ /**
214
+ * Get basic video info (faster, less data)
215
+ */
216
+ declare function getBasicVideoInfo(videoIdOrUrl: string): Promise<YouTubeVideo>;
217
+
218
+ /**
219
+ * Search YouTube Videos
220
+ */
221
+
222
+ interface SearchOptions {
223
+ /** Search query */
224
+ query: string;
225
+ /** Maximum results */
226
+ limit?: number;
227
+ /** Sort by */
228
+ sortBy?: 'relevance' | 'date' | 'viewCount' | 'rating';
229
+ /** Filter by upload date */
230
+ uploadDate?: 'hour' | 'today' | 'week' | 'month' | 'year';
231
+ /** Filter by duration */
232
+ duration?: 'short' | 'medium' | 'long';
233
+ /** Filter by type */
234
+ type?: 'video' | 'channel' | 'playlist';
235
+ }
236
+ /**
237
+ * Search YouTube videos
238
+ */
239
+ declare function searchVideos(queryOrOptions: string | SearchOptions): Promise<YouTubeVideo[]>;
240
+
241
+ export { ErrorCodes, type FetchTranscriptOptions, type GetChannelVideosOptions, type GetVideoInfoOptions, type SearchOptions, type TranscriptInfo, type TranscriptOptions, type TranscriptSegment, type TranscriptTrack, type VideoInfo, type YouTubeChannel, type YouTubeThumbnails, YouTubeToolsError, type YouTubeVideo, getBasicVideoInfo, getChannelInfo, getChannelVideos, getTranscript, getTranscriptSRT, getTranscriptText, getTranscriptVTT, getVideoInfo, listTranscripts, searchVideos };
@@ -0,0 +1,241 @@
1
+ /**
2
+ * YouTube Tools Type Definitions
3
+ */
4
+ interface YouTubeVideo {
5
+ /** Video ID (e.g., 'dQw4w9WgXcQ') */
6
+ videoId: string;
7
+ /** Video title */
8
+ title: string;
9
+ /** Video description (may be truncated) */
10
+ description?: string;
11
+ /** Published date in ISO 8601 format */
12
+ publishedAt: string;
13
+ /** Video duration in 'HH:MM:SS' or 'MM:SS' format */
14
+ duration?: string;
15
+ /** Duration in seconds */
16
+ durationSeconds?: number;
17
+ /** View count */
18
+ viewCount?: number;
19
+ /** Like count */
20
+ likeCount?: number;
21
+ /** Comment count */
22
+ commentCount?: number;
23
+ /** Thumbnail URLs */
24
+ thumbnails?: YouTubeThumbnails;
25
+ /** Channel ID */
26
+ channelId?: string;
27
+ /** Channel title/name */
28
+ channelTitle?: string;
29
+ /** Video URL */
30
+ url: string;
31
+ }
32
+ interface YouTubeThumbnails {
33
+ default?: string;
34
+ medium?: string;
35
+ high?: string;
36
+ standard?: string;
37
+ maxres?: string;
38
+ }
39
+ interface YouTubeChannel {
40
+ /** Channel ID */
41
+ channelId: string;
42
+ /** Channel name */
43
+ title: string;
44
+ /** Channel description */
45
+ description?: string;
46
+ /** Custom URL or handle (@username) */
47
+ customUrl?: string;
48
+ /** Subscriber count (may be hidden) */
49
+ subscriberCount?: number;
50
+ /** Total video count */
51
+ videoCount?: number;
52
+ /** Total view count */
53
+ viewCount?: number;
54
+ /** Channel thumbnails/avatars */
55
+ thumbnails?: YouTubeThumbnails;
56
+ /** Channel banner images */
57
+ banners?: YouTubeThumbnails;
58
+ /** Channel URL */
59
+ url: string;
60
+ /** Channel creation date */
61
+ publishedAt?: string;
62
+ }
63
+ interface TranscriptSegment {
64
+ /** Start time in seconds */
65
+ start: number;
66
+ /** Duration in seconds */
67
+ duration: number;
68
+ /** Text content */
69
+ text: string;
70
+ /** End time in seconds (start + duration) */
71
+ end?: number;
72
+ }
73
+ interface TranscriptOptions {
74
+ /** Language code (e.g., 'en', 'vi'). Auto-detect if not specified */
75
+ lang?: string;
76
+ /** Output format */
77
+ format?: 'json' | 'text' | 'srt' | 'vtt';
78
+ }
79
+ interface TranscriptInfo {
80
+ /** Available language codes */
81
+ availableLanguages: string[];
82
+ /** Whether auto-generated captions are available */
83
+ hasAutoGenerated: boolean;
84
+ /** Whether manual captions are available */
85
+ hasManual: boolean;
86
+ }
87
+ interface GetVideoInfoOptions {
88
+ /** Video ID or URL */
89
+ video: string;
90
+ }
91
+ declare class YouTubeToolsError extends Error {
92
+ code: string;
93
+ statusCode?: number | undefined;
94
+ constructor(message: string, code: string, statusCode?: number | undefined);
95
+ }
96
+ declare const ErrorCodes: {
97
+ readonly CHANNEL_NOT_FOUND: "CHANNEL_NOT_FOUND";
98
+ readonly VIDEO_NOT_FOUND: "VIDEO_NOT_FOUND";
99
+ readonly TRANSCRIPT_NOT_AVAILABLE: "TRANSCRIPT_NOT_AVAILABLE";
100
+ readonly RATE_LIMITED: "RATE_LIMITED";
101
+ readonly PARSING_ERROR: "PARSING_ERROR";
102
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
103
+ };
104
+
105
+ /**
106
+ * Get Channel Videos
107
+ *
108
+ * Sử dụng 2 methods:
109
+ * 1. RSS Feed - nhanh, stable, nhưng chỉ 15 videos
110
+ * 2. Scraping - lấy được nhiều hơn với pagination
111
+ */
112
+
113
+ interface GetChannelVideosOptions {
114
+ /** Channel ID, URL, or handle (@username) */
115
+ channel: string;
116
+ /** Maximum videos to fetch. Default: 15 (RSS), set higher to use scraping */
117
+ limit?: number;
118
+ /** Sort by: newest, oldest, popular */
119
+ sortBy?: 'newest' | 'oldest' | 'popular';
120
+ /** Content type filter */
121
+ contentType?: 'videos' | 'shorts' | 'streams';
122
+ }
123
+ /**
124
+ * Get videos from a YouTube channel
125
+ */
126
+ declare function getChannelVideos(options: GetChannelVideosOptions | string): Promise<YouTubeVideo[]>;
127
+
128
+ /**
129
+ * Get Channel Info
130
+ */
131
+
132
+ /**
133
+ * Get channel information
134
+ */
135
+ declare function getChannelInfo(channel: string): Promise<YouTubeChannel>;
136
+
137
+ /**
138
+ * YouTube Transcript Fetcher - Pure Node.js
139
+ *
140
+ * Port từ youtube-transcript-api (Python) sang TypeScript
141
+ * Sử dụng Innertube API như Python library
142
+ */
143
+
144
+ interface TranscriptTrack {
145
+ languageCode: string;
146
+ language: string;
147
+ baseUrl: string;
148
+ isGenerated: boolean;
149
+ isTranslatable: boolean;
150
+ }
151
+ interface FetchTranscriptOptions {
152
+ /** Preferred language codes in order of preference */
153
+ languages?: string[];
154
+ /** If true, prefer auto-generated over manual */
155
+ preferGenerated?: boolean;
156
+ }
157
+ /**
158
+ * Fetch available transcript tracks for a video
159
+ */
160
+ declare function listTranscripts(videoId: string): Promise<TranscriptTrack[]>;
161
+ /**
162
+ * Fetch transcript segments for a video
163
+ */
164
+ declare function getTranscript(videoId: string, options?: FetchTranscriptOptions): Promise<TranscriptSegment[]>;
165
+ /**
166
+ * Fetch transcript and format as plain text
167
+ */
168
+ declare function getTranscriptText(videoId: string, options?: FetchTranscriptOptions): Promise<string>;
169
+ /**
170
+ * Fetch transcript and format as SRT
171
+ */
172
+ declare function getTranscriptSRT(videoId: string, options?: FetchTranscriptOptions): Promise<string>;
173
+ /**
174
+ * Fetch transcript and format as WebVTT
175
+ */
176
+ declare function getTranscriptVTT(videoId: string, options?: FetchTranscriptOptions): Promise<string>;
177
+
178
+ /**
179
+ * Get Video Info
180
+ *
181
+ * Lấy thông tin chi tiết của video từ YouTube page
182
+ */
183
+
184
+ interface VideoInfo extends YouTubeVideo {
185
+ /** Video description (full) */
186
+ description: string;
187
+ /** Like count */
188
+ likeCount?: number;
189
+ /** Comment count */
190
+ commentCount?: number;
191
+ /** Video category */
192
+ category?: string;
193
+ /** Video tags */
194
+ tags?: string[];
195
+ /** Video chapters */
196
+ chapters?: VideoChapter[];
197
+ /** Is live stream */
198
+ isLive?: boolean;
199
+ /** Is upcoming premiere */
200
+ isUpcoming?: boolean;
201
+ /** Keywords */
202
+ keywords?: string[];
203
+ }
204
+ interface VideoChapter {
205
+ title: string;
206
+ startTime: number;
207
+ endTime?: number;
208
+ }
209
+ /**
210
+ * Get detailed video information
211
+ */
212
+ declare function getVideoInfo(videoIdOrUrl: string): Promise<VideoInfo>;
213
+ /**
214
+ * Get basic video info (faster, less data)
215
+ */
216
+ declare function getBasicVideoInfo(videoIdOrUrl: string): Promise<YouTubeVideo>;
217
+
218
+ /**
219
+ * Search YouTube Videos
220
+ */
221
+
222
+ interface SearchOptions {
223
+ /** Search query */
224
+ query: string;
225
+ /** Maximum results */
226
+ limit?: number;
227
+ /** Sort by */
228
+ sortBy?: 'relevance' | 'date' | 'viewCount' | 'rating';
229
+ /** Filter by upload date */
230
+ uploadDate?: 'hour' | 'today' | 'week' | 'month' | 'year';
231
+ /** Filter by duration */
232
+ duration?: 'short' | 'medium' | 'long';
233
+ /** Filter by type */
234
+ type?: 'video' | 'channel' | 'playlist';
235
+ }
236
+ /**
237
+ * Search YouTube videos
238
+ */
239
+ declare function searchVideos(queryOrOptions: string | SearchOptions): Promise<YouTubeVideo[]>;
240
+
241
+ export { ErrorCodes, type FetchTranscriptOptions, type GetChannelVideosOptions, type GetVideoInfoOptions, type SearchOptions, type TranscriptInfo, type TranscriptOptions, type TranscriptSegment, type TranscriptTrack, type VideoInfo, type YouTubeChannel, type YouTubeThumbnails, YouTubeToolsError, type YouTubeVideo, getBasicVideoInfo, getChannelInfo, getChannelVideos, getTranscript, getTranscriptSRT, getTranscriptText, getTranscriptVTT, getVideoInfo, listTranscripts, searchVideos };