JSPM

youtube-subtitle

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q31592F
  • License MIT

A JavaScript API for retrieving YouTube transcripts and subtitles without a headless browser.

Package Exports

  • youtube-subtitle
  • youtube-subtitle/formatters
  • youtube-subtitle/proxies

Readme

✨ YouTube Transcript API ✨

A JavaScript API and CLI for retrieving YouTube transcripts/subtitles without a headless browser. JavScript version of https://github.com/jdepoix/youtube-transcript-api This project is developed by AI

Install

npm install youtube-transcript-api

API

import { YouTubeTranscriptApi } from "youtube-transcript-api";

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

console.log(transcript.languageCode);
console.log(transcript.toRawData());

Use language priority when you want a specific transcript order:

const transcript = await api.fetch("GJLlxj_dtq8", {
  languages: ["de", "en"],
});

Preserve inline formatting tags such as <i> and <b>:

const transcript = await api.fetch("GJLlxj_dtq8", {
  preserveFormatting: true,
});

List available transcripts

const transcriptList = await api.list("GJLlxj_dtq8");

for (const transcript of transcriptList) {
  console.log(transcript.languageCode, transcript.language, transcript.isGenerated);
}

const preferred = transcriptList.findTranscript(["de", "en"]);
const manual = transcriptList.findManuallyCreatedTranscript(["de", "en"]);
const generated = transcriptList.findGeneratedTranscript(["de", "en"]);

Translate a transcript

const transcriptList = await api.list("GJLlxj_dtq8");
const transcript = transcriptList.findTranscript(["en"]);
const translatedTranscript = transcript.translate("de");
const translatedData = await translatedTranscript.fetch();

CLI

npx youtube-transcript-api GJLlxj_dtq8

Examples:

npx youtube-transcript-api GJLlxj_dtq8 --languages de en --format json
npx youtube-transcript-api GJLlxj_dtq8 --list-transcripts
npx youtube-transcript-api GJLlxj_dtq8 --translate ar

Available formats:

  • pretty
  • json
  • text
  • srt
  • webvtt

Proxy support

import {
  GenericProxyConfig,
  WebshareProxyConfig,
  YouTubeTranscriptApi,
} from "youtube-transcript-api";

const api = new YouTubeTranscriptApi({
  proxyConfig: new GenericProxyConfig({
    httpUrl: "http://user:pass@proxy:8080",
    httpsUrl: "http://user:pass@proxy:8080",
  }),
});

await api.fetch("GJLlxj_dtq8");

For rotating residential proxies with Webshare:

const api = new YouTubeTranscriptApi({
  proxyConfig: new WebshareProxyConfig({
    proxyUsername: "username",
    proxyPassword: "password",
    filterIpLocations: ["de", "us"],
  }),
});

Development

npm install
npm test

Release

The package version is managed with npm and the publish flow is driven by Git tags.

Bump the version locally with one of these commands:

npm run release:patch
npm run release:minor
npm run release:major

Each command updates package.json, creates a git commit, and creates a matching v* tag.

Publish flow:

  1. Add NPM_TOKEN to the GitHub repository secrets with publish permission for npm.
  2. Push the commit and tag with git push && git push --tags or git push --follow-tags.
  3. GitHub Actions runs tests, checks that the tag matches package.json, and publishes with npm publish.

If you need to publish manually, the package already validates itself before publish:

npm publish