#!/usr/bin/env node
// Test the fixed youtube-transcript-api implementation
const TranscriptClient = require('youtube-transcript-api');
async function testFixedAPI() {
console.log('🔧 Testing fixed youtube-transcript-api implementation...');
const client = new TranscriptClient();
console.log('✅ Client created');
try {
console.log('⏳ Waiting for client ready...');
await client.ready;
console.log('✅ Client ready resolved');
// Test with the user's video
const testVideoId = 'F_RyElT_gJk';
// Retry logic similar to our service
let attempts = 0;
const maxAttempts = 10;
while (attempts < maxAttempts) {
try {
console.log(`⏳ Attempt ${attempts + 1}: Getting transcript for ${testVideoId}...`);
const result = await client.getTranscript(testVideoId);
console.log('✅ Success! Got result:', 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('Result structure:', result);
}
break;
} catch (error) {
if (error.message === 'client not fully initialized!' && attempts < maxAttempts - 1) {
attempts++;
const delay = 200 * Math.pow(1.5, attempts);
console.log(`❌ Not initialized, waiting ${delay.toFixed(0)}ms...`);
await new Promise(resolve => setTimeout(resolve, delay));
continue;
} else {
console.log('❌ Final error:', error.message);
break;
}
}
}
} catch (error) {
console.error('❌ Setup error:', error.message);
}
}
testFixedAPI().catch(console.error);