Building an AI YouTube Video Summarizer: From Video Link to Summary

Burak Odabaş - Nov 6 - - Dev Community

Hey devs! 👋 I want to share how I built an AI-powered YouTube video summarizer. Let's dive into the technical implementation!

The Process Flow

  1. Extract YouTube Video Data
  2. Get Video Transcript
  3. Process with ChatGPT
  4. Present to User

Technical Implementation

1. Fetching Video Metadata

const getVideoMetadata = async (videoUrl) => {
  try {
    const videoId = extractVideoId(videoUrl);
    const response = await youtube.videos.list({
      part: 'snippet,contentDetails',
      id: videoId
    });

    return {
      title: response.data.items[0].snippet.title,
      description: response.data.items[0].snippet.description,
      duration: response.data.items[0].contentDetails.duration
    };
  } catch (error) {
    console.error('Failed to fetch metadata:', error);
    throw error;
  }
};
Enter fullscreen mode Exit fullscreen mode

2. Getting Video Transcript

const getTranscript = async (videoId) => {
  try {
    const transcript = await YoutubeTranscript.fetchTranscript(videoId);
    return transcript.map(item => item.text).join(' ');
  } catch (error) {
    console.error('Failed to fetch transcript:', error);
    throw error;
  }
};
Enter fullscreen mode Exit fullscreen mode

3. Processing with ChatGPT

const generateSummary = async (transcript, summaryType) => {
  const prompts = {
    quick: "Provide a brief 2-3 sentence summary of the main points:",
    detailed: "Provide a detailed summary with key points and examples:",
    bullets: "List the main points as bullet points:",
  };

  try {
    const completion = await openai.createChatCompletion({
      model: "gpt-4",
      messages: [{
        role: "user",
        content: `${prompts[summaryType]} ${transcript}`
      }]
    });

    return completion.data.choices[0].message.content;
  } catch (error) {
    console.error('Failed to generate summary:', error);
    throw error;
  }
};
Enter fullscreen mode Exit fullscreen mode

4. Presenting Results

interface SummaryResult {
  metadata: VideoMetadata;
  transcript: string;
  summary: string;
}

const processVideo = async (
  videoUrl: string, 
  summaryType: 'quick' | 'detailed' | 'bullets'
): Promise<SummaryResult> => {
  const metadata = await getVideoMetadata(videoUrl);
  const transcript = await getTranscript(videoUrl);
  const summary = await generateSummary(transcript, summaryType);

  return {
    metadata,
    transcript,
    summary
  };
};
Enter fullscreen mode Exit fullscreen mode

Key Challenges Solved

  1. Rate Limiting: Implemented proper delays between API calls
  2. Error Handling: Added robust error handling for both YouTube and OpenAI APIs
  3. Prompt Engineering: Optimized prompts for different summary types
  4. Token Management: Chunking large transcripts for API limits

Results

The app is now live on the App Store, helping users save time by summarizing YouTube videos efficiently. You can check it out here: [https://apps.apple.com/us/app/video-summarize-ai-video-chat/id6692608763]

What's Next?

  • Adding support for more languages
  • Implementing timestamp-based summaries
  • Adding more summary types

Would love to hear your thoughts and suggestions in the comments!

Happy coding! 🚀

. .
Terabox Video Player