-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-transcript.js
More file actions
77 lines (63 loc) · 2.5 KB
/
Copy pathtest-transcript.js
File metadata and controls
77 lines (63 loc) · 2.5 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
74
75
76
77
// Test script for improved YouTube transcript extraction
// Run with: node test-transcript.js
const testVideos = [
'dQw4w9WgXcQ', // Rick Roll - has captions
'9bZkp7q19f0', // PSY - GANGNAM STYLE - has captions
'kJQP7kiw5Fk', // Luis Fonsi - Despacito - has captions
];
async function testTranscriptAPI(videoId) {
console.log(`\n🧪 Testing transcript extraction for video: ${videoId}`);
console.log(`URL: https://www.youtube.com/watch?v=${videoId}`);
try {
const response = await fetch('http://localhost:3000/api/youtube-transcript', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ videoId })
});
const data = await response.json();
console.log('Response Status:', response.status);
console.log('Response OK:', response.ok);
if (response.ok) {
console.log('✅ Success!');
console.log('Method used:', data.method);
console.log('Transcript length:', data.length);
console.log('Transcript preview:', data.transcript.substring(0, 150) + '...');
} else {
console.log('❌ Failed!');
console.log('Error:', data.error);
if (data.details) {
console.log('Details:', data.details);
}
}
return response.ok;
} catch (error) {
console.error('❌ Network error:', error.message);
return false;
}
}
async function runTests() {
console.log('🚀 Testing Improved YouTube Transcript Extraction\n');
console.log('Make sure your development server is running on http://localhost:3000\n');
let successCount = 0;
let totalTests = testVideos.length;
for (const videoId of testVideos) {
const success = await testTranscriptAPI(videoId);
if (success) successCount++;
// Wait a bit between tests to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log(`\n📊 Test Results:`);
console.log(`✅ Successful: ${successCount}/${totalTests}`);
console.log(`❌ Failed: ${totalTests - successCount}/${totalTests}`);
if (successCount === totalTests) {
console.log('\n🎉 All tests passed! The transcript extraction is working well.');
} else if (successCount > 0) {
console.log('\n⚠️ Some tests passed. The extraction works but may have limitations.');
} else {
console.log('\n💥 All tests failed. Check your server and API configuration.');
}
}
// Run tests if this file is executed directly
if (typeof window === 'undefined') {
runTests().catch(console.error);
}