-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-transcript.js
More file actions
73 lines (62 loc) · 2.55 KB
/
test-transcript.js
File metadata and controls
73 lines (62 loc) · 2.55 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Test script để kiểm tra transcript của video YouTube
* Video ID: J6OnBDmErUg
*/
import {
getTranscript,
getTranscriptText,
listTranscripts
} from './dist/index.mjs';
const VIDEO_ID = 'J6OnBDmErUg';
async function testTranscript() {
try {
console.log('='.repeat(60));
console.log(`Testing video: ${VIDEO_ID}`);
console.log('='.repeat(60));
console.log('');
// Bước 1: Liệt kê các transcript có sẵn
console.log('📋 Fetching available transcripts...');
const tracks = await listTranscripts(VIDEO_ID);
console.log(`\n✅ Found ${tracks.length} transcript(s):\n`);
tracks.forEach((track, index) => {
console.log(`${index + 1}. Language: ${track.language} (${track.languageCode})`);
console.log(` - Generated: ${track.isGenerated ? 'Yes ✨' : 'No 📝'}`);
console.log(` - Translatable: ${track.isTranslatable ? 'Yes' : 'No'}`);
console.log('');
});
// Bước 2: Lấy transcript mặc định (English)
console.log('-'.repeat(60));
console.log('📝 Fetching English transcript...');
const segments = await getTranscript(VIDEO_ID, {
languages: ['en']
});
console.log(`\n✅ Got ${segments.length} segments\n`);
console.log('First 5 segments:');
segments.slice(0, 5).forEach((seg, i) => {
console.log(`\n${i + 1}. [${seg.start.toFixed(2)}s] (${seg.duration.toFixed(2)}s)`);
console.log(` "${seg.text}"`);
});
// Bước 3: Lấy full text
console.log('\n' + '-'.repeat(60));
console.log('📄 Full transcript text (first 500 chars):\n');
const fullText = await getTranscriptText(VIDEO_ID);
console.log(fullText.substring(0, 500) + '...');
console.log('\n' + '='.repeat(60));
console.log('✅ TEST COMPLETED SUCCESSFULLY!');
console.log('='.repeat(60));
console.log(`\nTotal transcript length: ${fullText.length} characters`);
console.log(`Total segments: ${segments.length}`);
} catch (error) {
console.error('\n' + '='.repeat(60));
console.error('❌ ERROR:');
console.error('='.repeat(60));
console.error(`Code: ${error.code || 'UNKNOWN'}`);
console.error(`Message: ${error.message}`);
if (error.statusCode) {
console.error(`Status Code: ${error.statusCode}`);
}
console.error('\nStack:', error.stack);
process.exit(1);
}
}
testTranscript();