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