#!/usr/bin/env node
// Test channel and playlist functions
import { YouTubeService } from '../build/services/youtube.js';
async function testChannelAndPlaylist() {
console.log('π§ Testing Channel and Playlist Functions...');
const service = new YouTubeService();
// Test 1: Channel Videos
console.log('\nπΊ Testing Channel Video Discovery...');
try {
const channelUrl = 'https://www.youtube.com/@YouTube';
console.log(`β³ Getting videos from: ${channelUrl}`);
const videos = await service.getChannelVideos(channelUrl, 5);
console.log('β
Channel videos retrieved:', videos.length);
if (videos.length > 0) {
console.log('Sample videos:');
videos.forEach((video, index) => {
console.log(`${index + 1}. ${video.title}`);
console.log(` URL: ${video.url}`);
console.log(` Published: ${video.publishedAt}`);
});
}
} catch (error) {
console.error('β Channel test error:', error.message);
}
// Test 2: Channel Video URLs
console.log('\nπ Testing Channel Video URLs...');
try {
const channelUrl = 'https://www.youtube.com/@YouTube';
const urls = await service.getChannelVideoUrls(channelUrl, 3);
console.log('β
Got video URLs:', urls.length);
urls.forEach((url, index) => {
console.log(`${index + 1}. ${url}`);
});
} catch (error) {
console.error('β Channel URLs error:', error.message);
}
// Test 3: Playlist Info
console.log('\nπ Testing Playlist Info...');
try {
// Use a popular public playlist
const playlistUrl = 'https://www.youtube.com/playlist?list=PLrAXtmRdnEQy6nuLMHjMZOz59M2262Ewl';
console.log(`β³ Getting playlist info: ${playlistUrl}`);
const playlistInfo = await service.getPlaylistInfo(playlistUrl);
console.log('β
Playlist info retrieved:');
console.log('- Title:', playlistInfo.title);
console.log('- Video count:', playlistInfo.videoCount);
console.log('- Channel:', playlistInfo.channelTitle);
} catch (error) {
console.error('β Playlist info error:', error.message);
}
// Test 4: Playlist Videos
console.log('\n㪠Testing Playlist Videos...');
try {
const playlistUrl = 'https://www.youtube.com/playlist?list=PLrAXtmRdnEQy6nuLMHjMZOz59M2262Ewl';
const videos = await service.getPlaylistVideos(playlistUrl, 3);
console.log('β
Playlist videos retrieved:', videos.length);
videos.forEach((video, index) => {
console.log(`${index + 1}. ${video.title}`);
console.log(` Position: ${video.playlistPosition}`);
console.log(` Duration: ${video.duration}`);
});
} catch (error) {
console.error('β Playlist videos error:', error.message);
}
// Test 5: Channel Transcripts (limited test)
console.log('\nπ Testing Channel Transcripts (limited)...');
try {
const channelUrl = 'https://www.youtube.com/@YouTube';
console.log('β³ Getting transcripts from channel (max 2 videos)...');
const transcripts = await service.getChannelTranscripts(channelUrl, 2, 1);
console.log('β
Channel transcripts retrieved:', transcripts.length);
transcripts.forEach((transcript, index) => {
console.log(`${index + 1}. Video ID: ${transcript.videoId}`);
console.log(` Segments: ${transcript.segments.length}`);
console.log(` Duration: ${(transcript.totalDuration / 60).toFixed(1)} minutes`);
});
} catch (error) {
console.error('β Channel transcripts error:', error.message);
}
console.log('\nπ― Testing Summary Complete!');
}
testChannelAndPlaylist().catch(console.error);