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 🙏

© 2026 – Pkg Stats / Ryan Hefner

youtube-transcript-api-ts

v1.0.1

Published

A lightweight TypeScript library to fetch YouTube video transcripts.

Downloads

186

Readme

youtube-transcript-api-ts

npm version

View on npm

A simple, dependency-free (except axios) TypeScript library to fetch transcripts/captions for YouTube videos. This is a port of the popular Python youtube-transcript-api.

Features

  • Fetch Transcripts: Retrieve the full transcript of a YouTube video.
  • Support for Auto-Generated Captions: Works with both manually created and auto-generated (ASR) captions.
  • Language Selection: Automatically selects the most appropriate language (defaults to English).
  • Text Format: Option to retrieve the transcript as a single block of text or as a list of timestamped objects.
  • No API Key Required: Does not require a Google/YouTube Data API key.

Installation

npm install youtube-transcript-api-ts
# or
yarn add youtube-transcript-api-ts

Usage

Basic Usage (Get JSON Objects)

By default, the library returns an array of objects containing the text, duration, and offset.

import { YoutubeTranscript } from 'youtube-transcript-api-ts';

async function main() {
  try {
    const transcript = await YoutubeTranscript.fetchTranscript('dQw4w9WgXcQ');
    
    console.log(transcript);
    /* Output:
    [
      { text: 'Never gonna give you up', duration: 2.1, offset: 0.5, lang: 'en' },
      { text: 'Never gonna let you down', duration: 1.5, offset: 2.6, lang: 'en' },
      ...
    ]
    */
  } catch (e) {
    console.error('Error fetching transcript:', e);
  }
}

main();

Get Transcript as Text

If you just want the full text of the video without timestamps:

const text = await YoutubeTranscript.fetchTranscript('dQw4w9WgXcQ', { format: 'text' });
console.log(text);
// Output: "Never gonna give you up Never gonna let you down ..."

Configuration Options

You can pass a configuration object as the second argument:

YoutubeTranscript.fetchTranscript('video_id', {
  lang: 'de', // Priority language (default: 'en')
  country: 'DE', // Optional country code
  format: 'text' // Optional: 'object' (default) or 'text'
});

Error Handling

The library throws specific errors for various failure cases. You can import these error classes to handle them:

import { 
  YoutubeTranscript, 
  VideoUnavailable, 
  TranscriptsDisabled 
} from 'youtube-transcript-api-ts';

try {
  await YoutubeTranscript.fetchTranscript('invalid-id');
} catch (e) {
  if (e instanceof VideoUnavailable) {
    console.error('Video is unavailable');
  } else if (e instanceof TranscriptsDisabled) {
    console.error('Transcripts are disabled for this video');
  } else {
    console.error('Unknown error:', e);
  }
}

License

MIT