Extracts video subtitles from YouTube using the yt-dlp.
Install the package using the following command:
yarn add @os-team/youtube-captions
The library uses yt-dlp, so you need to install it in one of the following ways.
Example for getting subtitles for the video:
import { getCaptions, getLanguages } from '@os-team/youtube-captions';
const youtubeId = 'R7p-nPg8t_g';
const languages = getLanguages(youtubeId); // ['en', 'de', 'pl', 'pt', 'es']
const captions = await getCaptions(youtubeId, 'en'); // [{ start: 0, end: 1000, text: 'subtitle' }]
The start
and end
fields are measured in milliseconds.