youtube-transcript-plus 1.0.3 → 1.0.4
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 +15 -0
- package/dist/types.d.ts +1 -0
- package/dist/youtube-transcript-plus.js +14 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,20 @@ fetchTranscript('videoId_or_URL', {
|
|
|
42
42
|
.catch(console.error);
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
### HTTP Support
|
|
46
|
+
|
|
47
|
+
You can disable HTTPS and use HTTP instead for YouTube requests by setting the `disableHttps` option to `true`. This might be necessary in certain environments where HTTPS connections are restricted.
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
fetchTranscript('videoId_or_URL', {
|
|
51
|
+
disableHttps: true, // Use HTTP instead of HTTPS
|
|
52
|
+
})
|
|
53
|
+
.then(console.log)
|
|
54
|
+
.catch(console.error);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Security Warning:** Using HTTP instead of HTTPS removes transport layer security and is not recommended for production environments. Only use this option when absolutely necessary.
|
|
58
|
+
|
|
45
59
|
### Custom Fetch Functions
|
|
46
60
|
|
|
47
61
|
You can inject custom `videoFetch` and `transcriptFetch` functions to modify the fetch behavior, such as using a proxy or custom headers.
|
|
@@ -188,6 +202,7 @@ Fetches the transcript for a YouTube video.
|
|
|
188
202
|
- **`userAgent`**: Custom User-Agent string.
|
|
189
203
|
- **`cache`**: Custom caching strategy.
|
|
190
204
|
- **`cacheTTL`**: Time-to-live for cache entries in milliseconds.
|
|
205
|
+
- **`disableHttps`**: Set to `true` to use HTTP instead of HTTPS for YouTube requests.
|
|
191
206
|
- **`videoFetch`**: Custom fetch function for the video page request.
|
|
192
207
|
- **`transcriptFetch`**: Custom fetch function for the transcript request.
|
|
193
208
|
|
package/dist/types.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ class YoutubeTranscript {
|
|
|
152
152
|
}
|
|
153
153
|
fetchTranscript(videoId) {
|
|
154
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
155
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
156
156
|
const identifier = retrieveVideoId(videoId);
|
|
157
157
|
const userAgent = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.userAgent) || DEFAULT_USER_AGENT;
|
|
158
158
|
// Use custom fetch functions if provided, otherwise use defaultFetch
|
|
@@ -167,10 +167,11 @@ class YoutubeTranscript {
|
|
|
167
167
|
return JSON.parse(cachedTranscript);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
+
const protocol = ((_f = this.config) === null || _f === void 0 ? void 0 : _f.disableHttps) ? 'http' : 'https';
|
|
170
171
|
// Fetch the video page
|
|
171
172
|
const videoPageResponse = yield videoFetch({
|
|
172
|
-
url:
|
|
173
|
-
lang: (
|
|
173
|
+
url: `${protocol}://www.youtube.com/watch?v=${identifier}`,
|
|
174
|
+
lang: (_g = this.config) === null || _g === void 0 ? void 0 : _g.lang,
|
|
174
175
|
userAgent,
|
|
175
176
|
});
|
|
176
177
|
if (!videoPageResponse.ok) {
|
|
@@ -188,31 +189,34 @@ class YoutubeTranscript {
|
|
|
188
189
|
}
|
|
189
190
|
throw new YoutubeTranscriptDisabledError(identifier);
|
|
190
191
|
}
|
|
191
|
-
const captions = (
|
|
192
|
+
const captions = (_h = (() => {
|
|
192
193
|
try {
|
|
193
194
|
return JSON.parse(splittedHTML[1].split(',"videoDetails')[0].replace('\n', ''));
|
|
194
195
|
}
|
|
195
196
|
catch (e) {
|
|
196
197
|
return undefined;
|
|
197
198
|
}
|
|
198
|
-
})()) === null ||
|
|
199
|
+
})()) === null || _h === void 0 ? void 0 : _h['playerCaptionsTracklistRenderer'];
|
|
199
200
|
if (!captions) {
|
|
200
201
|
throw new YoutubeTranscriptDisabledError(identifier);
|
|
201
202
|
}
|
|
202
203
|
if (!('captionTracks' in captions)) {
|
|
203
204
|
throw new YoutubeTranscriptNotAvailableError(identifier);
|
|
204
205
|
}
|
|
205
|
-
if (((
|
|
206
|
+
if (((_j = this.config) === null || _j === void 0 ? void 0 : _j.lang) &&
|
|
206
207
|
!captions.captionTracks.some((track) => { var _a; return track.languageCode === ((_a = this.config) === null || _a === void 0 ? void 0 : _a.lang); })) {
|
|
207
|
-
throw new YoutubeTranscriptNotAvailableLanguageError((
|
|
208
|
+
throw new YoutubeTranscriptNotAvailableLanguageError((_k = this.config) === null || _k === void 0 ? void 0 : _k.lang, captions.captionTracks.map((track) => track.languageCode), identifier);
|
|
208
209
|
}
|
|
209
|
-
const
|
|
210
|
+
const captionURL = (((_l = this.config) === null || _l === void 0 ? void 0 : _l.lang)
|
|
210
211
|
? captions.captionTracks.find((track) => { var _a; return track.languageCode === ((_a = this.config) === null || _a === void 0 ? void 0 : _a.lang); })
|
|
211
212
|
: captions.captionTracks[0]).baseUrl;
|
|
213
|
+
const transcriptURL = ((_m = this.config) === null || _m === void 0 ? void 0 : _m.disableHttps)
|
|
214
|
+
? captionURL.replace('https://', 'http://')
|
|
215
|
+
: captionURL;
|
|
212
216
|
// Fetch the transcript
|
|
213
217
|
const transcriptResponse = yield transcriptFetch({
|
|
214
218
|
url: transcriptURL,
|
|
215
|
-
lang: (
|
|
219
|
+
lang: (_o = this.config) === null || _o === void 0 ? void 0 : _o.lang,
|
|
216
220
|
userAgent,
|
|
217
221
|
});
|
|
218
222
|
if (!transcriptResponse.ok) {
|
|
@@ -230,7 +234,7 @@ class YoutubeTranscript {
|
|
|
230
234
|
});
|
|
231
235
|
});
|
|
232
236
|
// Store in cache if a strategy is provided
|
|
233
|
-
if ((
|
|
237
|
+
if ((_p = this.config) === null || _p === void 0 ? void 0 : _p.cache) {
|
|
234
238
|
yield this.config.cache.set(cacheKey, JSON.stringify(transcript), this.config.cacheTTL);
|
|
235
239
|
}
|
|
236
240
|
return transcript;
|