-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (23 loc) · 812 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import fs from 'fs'
import https from 'https';
export function getFromVideoId(videoId) {
const subtitleUrl = `https://www.youtube.com/api/timedtext?lang=th&v=${videoId}`;
https.get(subtitleUrl, (response) => {
let subtitleText = '';
response.on('data', (chunk) => {
subtitleText += chunk;
});
response.on('end', () => {
const fileName = 'subtitle.txt';
fs.writeFile(fileName, subtitleText, (err) => {
if (err) {
console.error('Error saving subtitle:', err);
} else {
console.log('Subtitle downloaded successfully!');
}
});
});
}).on('error', (err) => {
console.error('Error fetching subtitle:', err);
});
}