UNPKG

youtube-data-mcp

Version:

Extract YouTube transcripts and comments for analysis

27 lines (26 loc) 952 B
import { getVideoId } from '../utils/helpers.js'; import { fetchCommentsFromSerpApi } from '../services/serpApiService.js'; export async function getReplies({ url, limit = 100, sort = 'relevance' }) { try { // YouTube 동영상 ID 추출 const videoId = getVideoId(url); if (!videoId) { throw new Error('Invalid YouTube URL or video ID'); } // SerpAPI를 사용하여 댓글 가져오기 const result = await fetchCommentsFromSerpApi(videoId, limit, sort); return { videoId, videoTitle: result.videoTitle, comments: result.comments, commentCount: result.comments.length, nextPageToken: result.nextPageToken }; } catch (error) { console.error('Error fetching comments:', error); throw error instanceof Error ? error : new Error('Failed to fetch comments'); } }