#!/usr/bin/env node
// Test all functions directly without MCP tools
import { YouTubeService } from '../build/services/youtube.js';
async function testAllFunctionsDirect() {
console.log('š§ Testing All YouTube Functions Directly...');
console.log('='.repeat(60));
const service = new YouTubeService();
// Test 1: Basic Transcript Function
console.log('\nš TEST 1: Basic Transcript Function');
console.log('-'.repeat(40));
try {
const transcript = await service.getTranscript('https://youtu.be/F_RyElT_gJk');
console.log('ā
SUCCESS: Transcript retrieved');
console.log(` - Video ID: ${transcript.videoId}`);
console.log(` - Segments: ${transcript.segments.length}`);
console.log(` - Duration: ${(transcript.totalDuration / 60).toFixed(1)} minutes`);
console.log(` - Sample text: "${transcript.segments[1]?.text.substring(0, 50)}..."`);
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 2: Search Transcript Function
console.log('\nš TEST 2: Search Transcript Function');
console.log('-'.repeat(40));
try {
const transcript = await service.getTranscript('https://youtu.be/F_RyElT_gJk');
const searchResults = await service.searchTranscript(transcript, {
query: 'agent',
contextWindow: 5,
caseSensitive: false
});
console.log('ā
SUCCESS: Search function works');
console.log(` - Query: "agent"`);
console.log(` - Results found: ${searchResults.length}`);
if (searchResults.length > 0) {
console.log(` - First match: "${searchResults[0].segment.text.substring(0, 50)}..."`);
}
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 3: Format Functions
console.log('\nš TEST 3: Format Functions');
console.log('-'.repeat(40));
try {
const transcript = await service.getTranscript('https://youtu.be/F_RyElT_gJk');
const textFormat = service.formatAsText(transcript);
console.log('ā
SUCCESS: Text format');
console.log(` - Length: ${textFormat.length} characters`);
const srtFormat = service.formatAsSRT(transcript);
console.log('ā
SUCCESS: SRT format');
console.log(` - Lines: ${srtFormat.split('\n').length}`);
console.log(` - Sample SRT entry: "${srtFormat.split('\n')[0]}"`);
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 4: Batch Transcripts Function
console.log('\nš TEST 4: Batch Transcripts Function');
console.log('-'.repeat(40));
try {
const urls = [
'https://youtu.be/F_RyElT_gJk',
'https://www.youtube.com/watch?v=jNQXAC9IVRw'
];
const transcripts = await service.batchTranscripts(urls, 2);
console.log('ā
SUCCESS: Batch processing works');
console.log(` - URLs processed: ${urls.length}`);
console.log(` - Transcripts retrieved: ${transcripts.length}`);
transcripts.forEach((t, i) => {
console.log(` - Video ${i + 1}: ${t.segments.length} segments`);
});
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 5: Channel Videos Function
console.log('\nšŗ TEST 5: Channel Videos Function');
console.log('-'.repeat(40));
try {
const channelUrl = 'https://www.youtube.com/@YouTube';
const videos = await service.getChannelVideos(channelUrl, 3);
console.log('ā
SUCCESS: Channel videos retrieved');
console.log(` - Channel: ${channelUrl}`);
console.log(` - Videos found: ${videos.length}`);
videos.forEach((video, i) => {
console.log(` - Video ${i + 1}: "${video.title.substring(0, 30)}..."`);
console.log(` URL: ${video.url}`);
});
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 6: Channel Video URLs Function
console.log('\nš TEST 6: Channel Video URLs Function');
console.log('-'.repeat(40));
try {
const channelUrl = 'https://www.youtube.com/@YouTube';
const urls = await service.getChannelVideoUrls(channelUrl, 3);
console.log('ā
SUCCESS: Channel video URLs retrieved');
console.log(` - Channel: ${channelUrl}`);
console.log(` - URLs found: ${urls.length}`);
urls.forEach((url, i) => {
console.log(` - URL ${i + 1}: ${url}`);
});
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 7: Playlist Info Function
console.log('\nš TEST 7: Playlist Info Function');
console.log('-'.repeat(40));
try {
const playlistUrl = 'https://www.youtube.com/playlist?list=PLirAqAtl_h2r5g8xGajEwdXd3x1sZh8hC';
const playlistInfo = await service.getPlaylistInfo(playlistUrl);
console.log('ā
SUCCESS: Playlist info retrieved');
console.log(` - Playlist ID: ${playlistInfo.id}`);
console.log(` - Video count: ${playlistInfo.videoCount}`);
console.log(` - Title: "${playlistInfo.title || 'No title'}"`);
console.log(` - Channel: "${playlistInfo.channelTitle || 'No channel info'}"`);
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 8: Playlist Videos Function
console.log('\nš¬ TEST 8: Playlist Videos Function');
console.log('-'.repeat(40));
try {
const playlistUrl = 'https://www.youtube.com/playlist?list=PLirAqAtl_h2r5g8xGajEwdXd3x1sZh8hC';
const videos = await service.getPlaylistVideos(playlistUrl, 3);
console.log('ā
SUCCESS: Playlist videos retrieved');
console.log(` - Videos found: ${videos.length}`);
videos.forEach((video, i) => {
console.log(` - Video ${i + 1}: "${video.title.substring(0, 30)}..."`);
console.log(` Position: ${video.playlistPosition}`);
console.log(` Duration: ${video.duration}`);
});
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 9: Playlist Video URLs Function
console.log('\nšÆ TEST 9: Playlist Video URLs Function');
console.log('-'.repeat(40));
try {
const playlistUrl = 'https://www.youtube.com/playlist?list=PLirAqAtl_h2r5g8xGajEwdXd3x1sZh8hC';
const urls = await service.getPlaylistVideoUrls(playlistUrl, 3);
console.log('ā
SUCCESS: Playlist video URLs retrieved');
console.log(` - URLs found: ${urls.length}`);
urls.forEach((url, i) => {
console.log(` - URL ${i + 1}: ${url}`);
});
} catch (error) {
console.log('ā FAILED:', error.message);
}
// Test 10: Channel Transcripts Function (limited test)
console.log('\nš TEST 10: Channel Transcripts Function');
console.log('-'.repeat(40));
try {
const channelUrl = 'https://www.youtube.com/@YouTube';
console.log(' - Testing with max 1 video due to potential transcript availability issues...');
const transcripts = await service.getChannelTranscripts(channelUrl, 1, 1);
console.log('ā
SUCCESS: Channel transcripts function works');
console.log(` - Transcripts retrieved: ${transcripts.length}`);
transcripts.forEach((transcript, i) => {
console.log(` - Video ${i + 1}: ${transcript.segments.length} segments`);
});
} catch (error) {
console.log('ā FAILED (Expected if videos have no transcripts):', error.message);
}
// Test 11: Playlist Transcripts Function (limited test)
console.log('\nš TEST 11: Playlist Transcripts Function');
console.log('-'.repeat(40));
try {
const playlistUrl = 'https://www.youtube.com/playlist?list=PLirAqAtl_h2r5g8xGajEwdXd3x1sZh8hC';
console.log(' - Testing with max 1 video due to potential transcript availability issues...');
const transcripts = await service.getPlaylistTranscripts(playlistUrl, 1, 1);
console.log('ā
SUCCESS: Playlist transcripts function works');
console.log(` - Transcripts retrieved: ${transcripts.length}`);
transcripts.forEach((transcript, i) => {
console.log(` - Video ${i + 1}: ${transcript.segments.length} segments`);
});
} catch (error) {
console.log('ā FAILED (Expected if videos have no transcripts):', error.message);
}
console.log('\n' + '='.repeat(60));
console.log('šÆ TESTING COMPLETE!');
console.log('='.repeat(60));
}
testAllFunctionsDirect().catch(console.error);