Skip to main content

Overview

Learn how to build a complete video analysis pipeline using ScriptBase.

Basic Workflow

  1. Get video metadata
  2. Extract transcript
  3. Analyze content
  4. Store results

Example: Video Summarizer

async function analyzeVideo(videoId: string) {
  const apiKey = process.env.YT_API_KEY;

  // 1. Get video metadata
  const videoResponse = await fetch(
    `https://api.scriptbase.app/api/v1/videos/${videoId}?includeTranscript=true`,
    { headers: { 'X-API-Key': apiKey } }
  );
  
  const { data: video } = await videoResponse.json();

  // 2. Analyze the content
  const analysis = {
    title: video.title,
    channel: video.channel.name,
    duration: video.duration,
    views: video.viewCount,
    transcript: video.transcript.content,
    wordCount: video.transcript.content.split(' ').length,
    // Add your analysis logic here
  };

  return analysis;
}

Advanced: Batch Channel Analysis

Analyze all videos from a channel:
async function analyzeChannel(channelId: string) {
  const apiKey = process.env.YT_API_KEY;

  // 1. Get all videos from channel
  const batchResponse = await fetch(
    'https://api.scriptbase.app/api/v1/videos/batch',
    {
      method: 'POST',
      headers: {
        'X-API-Key': apiKey,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        channelId,
        limit: 50
      })
    }
  );

  const { data } = await batchResponse.json();
  
  // 2. Analyze each video
  const analyses = [];
  for (const video of data.results) {
    // Fetch transcript separately if not included
    const transcript = await getTranscript(video.id);
    analyses.push({
      id: video.id,
      title: video.title,
      views: video.viewCount,
      hasTranscript: !!transcript
    });
  }

  return analyses;
}
See Batch Processing Guide for handling large datasets.