#!/usr/bin/env node
// Test the YouTubeService class directly without MCP
import { YouTubeService } from '../build/services/youtube.js';
async function testYouTubeService() {
console.log('š§ Testing YouTubeService class...');
const service = new YouTubeService();
console.log('ā
YouTubeService created');
// Test video URLs
const testUrls = [
'https://www.youtube.com/watch?v=jNQXAC9IVRw', // "Me at the zoo" - first YouTube video
'https://youtu.be/jNQXAC9IVRw', // Short URL format
];
for (const url of testUrls) {
console.log(`\nā³ Testing URL: ${url}`);
try {
const transcript = await service.getTranscript(url);
console.log('ā
Transcript retrieved successfully');
console.log('Video ID:', transcript.videoId);
console.log('Language:', transcript.language);
console.log('Segments:', transcript.segments.length);
console.log('Duration:', transcript.totalDuration);
if (transcript.segments.length > 0) {
console.log('First segment:', transcript.segments[0]);
// Test format methods
console.log('\nā³ Testing format methods...');
const textFormat = service.formatAsText(transcript);
console.log('ā
Text format length:', textFormat.length);
const srtFormat = service.formatAsSRT(transcript);
console.log('ā
SRT format length:', srtFormat.length);
// Test search functionality
if (transcript.segments.length > 5) {
console.log('\nā³ Testing search functionality...');
const searchResults = await service.searchTranscript(transcript, {
query: 'the',
contextWindow: 10,
caseSensitive: false
});
console.log('ā
Search results:', searchResults.length);
}
}
} catch (error) {
console.error('ā Error for', url, ':', error.message);
}
}
// Test channel functionality
console.log('\nā³ Testing channel functionality...');
try {
const channelUrl = 'https://www.youtube.com/@YouTube';
const videos = await service.getChannelVideos(channelUrl, 5);
console.log('ā
Channel videos retrieved:', videos.length);
if (videos.length > 0) {
console.log('First video:', videos[0].title);
}
} catch (error) {
console.error('ā Channel test error:', error.message);
}
}
testYouTubeService().catch(console.error);