#!/usr/bin/env node
// Test the youtube-transcript-api library directly
const TranscriptClient = require('youtube-transcript-api');
async function testAPI() {
console.log('🔧 Testing youtube-transcript-api library...');
const client = new TranscriptClient();
console.log('✅ Client created');
console.log('Client ready type:', typeof client.ready);
// Test video ID that should have transcripts
const testVideoId = 'jNQXAC9IVRw'; // "Me at the zoo" - first YouTube video
try {
console.log('⏳ Waiting for client ready...');
await client.ready;
console.log('✅ Client ready resolved');
// Try multiple times with increasing delays to handle race conditions
for (let attempt = 1; attempt <= 3; attempt++) {
console.log(`⏳ Attempt ${attempt}: Getting transcript...`);
try {
const result = await client.getTranscript(testVideoId);
console.log('✅ Transcript retrieved successfully');
console.log('Result structure:', Object.keys(result));
if (result.tracks && result.tracks[0] && result.tracks[0].transcript) {
console.log('✅ Found transcript with', result.tracks[0].transcript.length, 'segments');
console.log('First segment:', result.tracks[0].transcript[0]);
} else {
console.log('❌ Unexpected result structure:', result);
}
return; // Success, exit the retry loop
} catch (error) {
console.error(`❌ Attempt ${attempt} failed:`, error.message);
if (attempt < 3) {
console.log(`⏳ Waiting ${attempt * 1000}ms before retry...`);
await new Promise(resolve => setTimeout(resolve, attempt * 1000));
} else {
throw error; // Final attempt failed
}
}
}
} catch (error) {
console.error('❌ Final error:', error.message);
console.error('Full error:', error);
}
}
testAPI().catch(console.error);