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-scraper

v1.0.0

Published

![NPM Version](https://img.shields.io/npm/v/youtube-transcript-api) ![License](https://img.shields.io/npm/l/youtube-transcript-api) ![Downloads](https://img.shields.io/npm/dm/youtube-transcript-api)

Downloads

103

Readme

Youtube Transcript API

NPM Version License Downloads

A robust, dependency-light Node.js library to fetch transcripts/subtitles for YouTube videos.

This library is a faithful port of the popular Python youtube-transcript-api. It allows you to retrieve transcripts without an API key, supports multiple languages, and offers optional proxy support for heavy usage.

🚀 Features

  • Zero Configuration: Works out of the box for standard usage.
  • No API Key Required: Scrapes the video page just like a web browser.
  • Multi-Language Support: Automatically finds transcripts in your preferred language(s).
  • Auto-Generated Captions: Falls back to auto-generated captions if manual ones aren't available.
  • Optional Proxy Support: Easily integrate your own proxy (HTTP/HTTPS) to avoid rate limits during high-volume scraping.
  • Lightweight: Minimal dependencies (node-fetch, @xmldom/xmldom, https-proxy-agent).

📦 Installation

npm install youtube-transcript-api

🛠 Usage

1. Basic Usage (No Proxy Needed)

For most use cases, you don't need any special configuration. Just pass the video ID or URL.

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

// Fetch transcript for a video
try {
  const transcript = await YoutubeTranscript.fetchTranscript('dQw4w9WgXcQ');
  
  console.log(transcript[0]); 
  // { text: "We're no strangers to love", start: 0.1, duration: 2.3 }
  
} catch (error) {
  console.error(error);
}

2. Language Preference

You can specify a list of preferred languages. The API will try them in order.

const options = {
  lang: ['de', 'es', 'en'] // Try German, then Spanish, then English
};

const transcript = await YoutubeTranscript.fetchTranscript('dQw4w9WgXcQ', options);

3. Using a Proxy (Optional)

If you are scraping thousands of videos and hitting rate limits (HTTP 429), you can provide a proxy URL. The library handles the connection details for you.

Note: We do not provide free proxies. You must supply your own proxy string from a provider like Webshare, BrightData, etc.

const options = {
  // Format: protocol://user:pass@host:port
  proxy: 'http://myuser:[email protected]:8080' 
};

try {
  const transcript = await YoutubeTranscript.fetchTranscript('dQw4w9WgXcQ', options);
  console.log('Fetched via proxy!');
} catch (error) {
  console.error('Proxy failed:', error);
}

📚 API Reference

YoutubeTranscript.fetchTranscript(videoId, options?)

Parameters

| Param | Type | Description | | :--- | :--- | :--- | | videoId | string | The YouTube Video ID (e.g., dQw4w9WgXcQ) or full URL. | | options | object | Optional configuration object. |

Options Object

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | lang | string[] | ['en'] | Priority list of language codes to search for. | | proxy | string | undefined | Proxy connection string (e.g., http://user:pass@host:port). |

Return Value

Returns a Promise that resolves to an array of TranscriptItem objects:

interface TranscriptItem {
  text: string;     // The subtitle text content
  start: number;    // Start time in seconds (float)
  duration: number; // Duration in seconds (float)
}

⚠️ Error Handling

The library throws specific error classes to help you handle different failure scenarios.

import { 
  YoutubeTranscript, 
  YoutubeTranscriptError, 
  VideoUnavailableError, 
  TranscriptDisabledError 
} from 'youtube-transcript-api';

try {
  await YoutubeTranscript.fetchTranscript(videoId);
} catch (error) {
  if (error instanceof VideoUnavailableError) {
    console.error("Video is private or deleted.");
  } else if (error instanceof TranscriptDisabledError) {
    console.error("Transcripts are disabled for this video.");
  } else {
    console.error("General error:", error.message);
  }
}

📄 License

MIT © Zach Godsell