@suejon/youtube-subtitles
v0.4.2
Published
A zero dependency tool for downloading youtube subtitles.
Downloads
33
Maintainers
Readme
Youtube Subtitles
A zero dependency tool for downloading youtube subtitles.
How to install
npm install @suejon/youtube-subtitles
How to use
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
.
Fetch subtitles for a video
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"
}
Fetch available subtitle languages for a video
const languages = await get_available_languages("video_id");
Response:
["en", "fr", "es", "de", "ro", "sr", "sk", "sl", "sv", "uk"];
Feedback
If you have any open issues or feature requests, please feel free to open an issue on the github repository