#!/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);