npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

youtube-transcript-node

v1.1.2

Published

This is a Node.js API which allows you to get the transcripts/subtitles for a given YouTube video. It also works for automatically generated subtitles and supports translating subtitles.

Readme

YouTube Transcript Node

This is a Node.js API which allows you to retrieve the transcript/subtitles for a given YouTube video. It also works for automatically generated subtitles, supports translating subtitles and it does not require a headless browser, like other selenium based solutions do!

Install

npm install youtube-transcript-node

API

The easiest way to get a transcript for a given video is to execute:

import { YouTubeTranscriptApi } from 'youtube-transcript-node';

const api = new YouTubeTranscriptApi();
const transcript = await api.fetch(videoId);

Note: By default, this will try to access the English transcript of the video. If your video has a different language, or you are interested in fetching a transcript in a different language, please read the section below.

Note: Pass in the video ID, NOT the video URL. For a video with the URL https://www.youtube.com/watch?v=12345 the ID is 12345.

This will return a FetchedTranscript object with a snippets array containing objects like:

{
  text: "Hey there",
  start: 0.0,
  duration: 1.54
}

Use different languages

You can add a list of preferred languages, which will be used as a fallback if the first one is not available.

const transcript = await api.fetch(videoId, ['de', 'en']);

List available transcripts

To get a list of all available transcripts for a video:

const transcriptList = await api.list(videoId);

Get specific transcript types

const transcriptList = await api.list(videoId);

// Get manually created transcripts
const transcript = transcriptList.findManuallyCreatedTranscript(['de', 'en']);

// Get automatically generated transcripts  
const transcript = transcriptList.findGeneratedTranscript(['de', 'en']);

// Get any transcript (manual first, then generated)
const transcript = transcriptList.findTranscript(['de', 'en']);

Translate transcripts

const transcriptList = await api.list(videoId);
const transcript = transcriptList.findTranscript(['en']);
const translatedTranscript = transcript.translate('de');
const fetchedTranslated = await translatedTranscript.fetch();

Preserve formatting

By default, HTML tags are stripped from the transcript. To preserve formatting:

const transcript = await api.fetch(videoId, ['en'], true);

Formatters

You can use different formatters to format the transcript output:

import { JSONFormatter, TextFormatter, WebVTTFormatter } from 'youtube-transcript-node/formatters';

const formatter = new TextFormatter();
const formattedText = formatter.formatTranscript(transcript);

Available formatters:

  • JSONFormatter - Formats as JSON
  • TextFormatter - Formats as plain text
  • PrettyPrintFormatter - Formats as pretty-printed JSON
  • WebVTTFormatter - Formats as WebVTT subtitles

Exception Handling

import { 
  TranscriptsDisabled,
  NoTranscriptFound,
  VideoUnavailable,
  InvalidVideoId 
} from 'youtube-transcript-node';

try {
  const transcript = await api.fetch(videoId);
} catch (error) {
  if (error instanceof TranscriptsDisabled) {
    // Subtitles are disabled for this video
  } else if (error instanceof NoTranscriptFound) {
    // No transcript found in requested languages
  } else if (error instanceof VideoUnavailable) {
    // Video is unavailable
  } else if (error instanceof InvalidVideoId) {
    // Invalid video ID provided
  }
}

License

MIT