Skip to content

TypeScript library for fetching and parsing YouTube video captions with full type safety.

License

Notifications You must be signed in to change notification settings

stavkamil/youtube-captions-ts

Repository files navigation

Youtube Captions TS Logo

TypeScript library for fetching and parsing YouTube video captions with full type safety.

npm install size downloads

Installation

npm install youtube-captions-ts
# or
yarn add youtube-captions-ts

Quick Start

import { fetcher } from 'youtube-captions-ts';

async function getCaptions() {
  try {
    const captions = await fetcher.getCaptions('YOUTUBE_VIDEO_ID');
    console.log(captions);
  } catch (error) {
    console.error('Error fetching captions:', error);
  }
}

API Reference

getCaptions(videoId: string, options?: CaptionsOptions): Promise

Fetches and parses captions for a YouTube video.

Parameters

  • videoId: YouTube video ID
  • options: Optional configuration object
    • languages: Array of language codes (default: ['en'])
    • more features soon...

Return Type

interface Captions {
  segments: CaptionSegment[];
  language: string;
  videoId: string;
}

interface CaptionSegment {
  text: string;
  start: number;
  duration: number;
}

About

TypeScript library for fetching and parsing YouTube video captions with full type safety.

Topics

Resources

License

Stars

Watchers

Forks