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

yt-transcript-api

v1.0.8

Published

A lightweight JavaScript API and CLI for retrieving YouTube video transcripts and subtitles (including auto-generated and translated ones). No headless browsers required.

Downloads

152

Readme


Author: Chintamani Pala


Features

  • Fetch YouTube video transcripts (captions/subtitles) via API or CLI.
  • Supports auto-generated and manually created transcripts.
  • Supports translation (where available).
  • No browser automation or scraping required.
  • Proxy support for bypassing IP blocks.
  • Multiple output formats: JSON, text, SRT, WebVTT, pretty-print.

Installation

npm install yt-transcript-api

Or clone this repository and install dependencies:

git clone https://github.com/chintamani-pala/yt-transcript-api.git
cd yt-transcript-api
npm install

Usage

Fetch Transcript (Default Language)

const { YouTubeTranscriptApi } = require('yt-transcript-api');
const ytt_api = new YouTubeTranscriptApi();
const video_id = '0Okxsszt624';

(async () => {
    const transcript = await ytt_api.fetch(video_id);
    console.log(transcript);
})();

Fetch Transcript (Specific Language)

(async () => {
    const transcript = await ytt_api.fetch(video_id, ["en"]);
    console.log(transcript);
})();

Fetch Transcript (Unavailable Language)

(async () => {
    try {
        await ytt_api.fetch(video_id, ["zz"]);
    } catch (err) {
        console.error("Transcript not found for requested language.");
    }
})();

List Available Transcripts

(async () => {
    const list = await ytt_api.list(video_id);
    console.log(list);
})();

Save Transcript to File

const fs = require('fs');
(async () => {
    const transcript = await ytt_api.fetch(video_id, ["en"]);
    fs.writeFileSync("transcript.json", JSON.stringify(transcript, null, 2));
})();

Format Transcript as JSON (Pretty)

const { formatters } = require('yt-transcript-api');
(async () => {
    const transcript = await ytt_api.fetch(video_id, ["en"]);
    const json = new formatters.JSONFormatter().formatTranscript(transcript, { space: 2 });
    console.log(json);
})();

Format Transcript as SRT

const { formatters } = require('yt-transcript-api');
(async () => {
    const transcript = await ytt_api.fetch(video_id, ["en"]);
    const srt = new formatters.SRTFormatter().formatTranscript(transcript);
    console.log(srt);
})();

Format Transcript as Text

const { formatters } = require('yt-transcript-api');
(async () => {
    const transcript = await ytt_api.fetch(video_id, ["en"]);
    const text = new formatters.TextFormatter().formatTranscript(transcript);
    console.log(text);
})();

Format Transcript as Pretty Print

const { formatters } = require('yt-transcript-api');
(async () => {
    const transcript = await ytt_api.fetch(video_id, ["en"]);
    const pretty = new formatters.PrettyPrintFormatter().formatTranscript(transcript);
    console.log(pretty);
})();

Format Transcript as WebVTT

const { formatters } = require('yt-transcript-api');
(async () => {
    const transcript = await ytt_api.fetch(video_id, ["en"]);
    const vtt = new formatters.WebVTTFormatter().formatTranscript(transcript);
    console.log(vtt);
})();

Error Handling: Invalid Video ID

(async () => {
    try {
        await ytt_api.fetch("invalid_video_id");
    } catch (err) {
        console.error("Invalid video ID.");
    }
})();

Using a Proxy

const { YouTubeTranscriptApi, GenericProxyConfig } = require('yt-transcript-api');
const proxyConfig = new GenericProxyConfig("http://proxy:8080");
const ytt_api = new YouTubeTranscriptApi({ proxy: proxyConfig });
(async () => {
    const transcript = await ytt_api.fetch(video_id, ["en"]);
    console.log(transcript);
})();

CLI Usage

Fetch transcript and print as JSON:

npx yt-transcript-api 0Okxsszt624 --languages en --format json

Fetch transcript in a different language:

npx yt-transcript-api 0Okxsszt624 --languages es --format text

Use a proxy:

npx yt-transcript-api 0Okxsszt624 --languages en --proxy http://proxy:8080

API Exports

  • YouTubeTranscriptApi - Main API class
  • YouTubeTranscriptCli - CLI class
  • TranscriptListFetcher - Fetches transcript lists
  • ProxyConfig, GenericProxyConfig, WebshareProxyConfig, InvalidProxyConfig - Proxy support
  • formatters - Output formatters (JSON, SRT, WebVTT, etc.)
  • errors - Custom error classes
  • settings - Internal constants

CLI Options

| Option / Flag | Description | |------------------------------|---------------------------------------------------------------------------------------------| | --videoIds <ids> | Comma-separated list of YouTube video IDs, or provide as positional arguments. | | --format <type> | Output format: json, pretty, text, srt, webvtt. Default: pretty. | | --languages <codes> | Comma-separated language codes (e.g. en,hi). | | --excludeManuallyCreated | Exclude manually created transcripts. | | --excludeGenerated | Exclude auto-generated transcripts. | | --httpProxy <url> | Use an HTTP proxy server (e.g. http://proxy:8080). | | --httpsProxy <url> | Use an HTTPS proxy server. | | --webshareProxyUsername <u>| Username for Webshare proxy authentication. | | --webshareProxyPassword <p>| Password for Webshare proxy authentication. | | --preserveFormatting | Preserve original transcript formatting (where available). |

Note:

  • Video IDs can be provided as a comma-separated list with --video-ids or as positional arguments.
  • Language codes can be provided as a comma-separated list with --languages.

Supported Output Formats

  • json: Raw transcript as JSON
  • text: Plain text transcript
  • srt: SubRip subtitle format
  • webvtt: Web Video Text Tracks format
  • pretty: Human-readable pretty print

Contributing

Contributions are welcome! To contribute:

  • Fork the repository and create your branch.
  • Make your changes with clear commit messages.
  • Ensure all tests pass (npm test).
  • Submit a pull request describing your changes.

For major changes, please open an issue first to discuss what you would like to change.


Support / Contact

  • For bug reports or feature requests, please open an issue on GitHub.
  • For questions, suggestions, or sponsorship, contact the author via GitHub or use the GitHub Sponsor button.

License

MIT


Author

Chintamani Pala