A zero dependency tool for downloading youtube subtitles.
npm install @suejon/youtube-subtitles
The video_id
can be found in the url of the video. For example, in the url https://www.youtube.com/watch?v=abcdef
, the video_id
is abcdef
.
Here is an example of fetching chinese subtitles for a video:
const subtitles = await get_subtitles_for_video("video_id", "cn");
If the language is not specified, it defaults to english ("en"). Valid codes are in the ISO 639-1 format.
The subtitles will be an array of objects, each object representing the subtitle text including the start
time when they should be displayed and the dur
ation they should be displayed for (in seconds). Each object has the following structure:
{
start: 241,
dur: 6,
text: "one of the great fish of the world to"
}
const languages = await get_available_languages("video_id");
Response:
["en", "fr", "es", "de", "ro", "sr", "sk", "sl", "sv", "uk"];
If you have any open issues or feature requests, please feel free to open an issue on the github repository