TypeScript library for fetching and parsing YouTube video captions with full type safety.
npm install youtube-captions-ts
# or
yarn add youtube-captions-ts
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);
}
}
Fetches and parses captions for a YouTube video.
videoId
: YouTube video IDoptions
: Optional configuration objectlanguages
: Array of language codes (default: ['en'])- more features soon...
interface Captions {
segments: CaptionSegment[];
language: string;
videoId: string;
}
interface CaptionSegment {
text: string;
start: number;
duration: number;
}