# YouTube Subtitles Scraper (`scrapemamba/youtube-subtitles-scraper`) Actor

YouTube transcript extractor — get YouTube captions and transcript text from URLs or IDs. Bulk extract YouTube transcript data for NLP, with optional per-cue rows. Public captions only.

- **URL**: https://apify.com/scrapemamba/youtube-subtitles-scraper.md
- **Developed by:** [Scrape Mamba](https://apify.com/scrapemamba) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.99 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## YouTube Subtitles Scraper — Transcripts & Captions at Scale

Extract **YouTube captions** and transcript text from watch URLs or video IDs. Get tracks, timed cues, availability flags, and a joined text preview into an Apify Dataset — built for NLP, search indexes, and compliance archives, not one-off “copy transcript” clicks.

**[Run YouTube Subtitles Scraper on Apify](https://apify.com/scrapemamba/youtube-subtitles-scraper)** · Built by **ScrapeMamba** · Public captions only · Not a media downloader

***

### Why this Actor?

Phone “Show transcript” works for one video. Catalogs, warehouses, and weekly jobs need batch automation: many IDs, exportable JSON/CSV, and schedules. This Actor is the suite’s **YouTube transcript extractor** — same `videoId` keys as Video, Search, and Related scrapers.

- Batch `videoIds` in one run
- Preferred caption `lang` (default `en`)
- Optional `expandCues` for one Dataset row per cue
- `text` preview truncated to **2000** characters; full cues stay on the subtitles row
- Clear signals when tracks exist but timed cues are withheld (`cuesError`)

***

### Key features

- Bulk **YouTube transcript** / caption extraction
- Tracks metadata + timed cues when available
- Optional flat cue rows for warehouses that prefer timestamp tables
- Per-video error isolation
- Fits after Search / Video / Related shortlisting

***

### What you can scrape

#### Subtitles row (`type: "subtitles"`)

| Group | Fields |
|---|---|
| Identity | `videoId`, `lang` |
| Availability | `isAvailable`, `source`, `trackCount`, `cueCount` |
| Content | `tracks`, `cues`, `text` (preview ≤ 2000 chars) |
| Diagnostics | `cuesError` / related flags, `raw`, `error` |

#### Cue row (`type: "cue"`, when `expandCues: true`)

`videoId`, `id`, `start`, `duration`, `text`, `language`, `languageCode`

***

### Use cases

- **NLP / topic models** — Speech text beside video metadata
- **Content research** — Quote mining and theme extraction
- **Compliance archives** — Periodic public caption snapshots
- **Search indexes** — Index spoken content for internal discovery
- **Accessibility audits** — Check which catalog IDs expose captions

***

### Example output

```json
{
  "type": "subtitles",
  "videoId": "dQw4w9WgXcQ",
  "lang": "en",
  "isAvailable": true,
  "source": "youtube",
  "trackCount": 1,
  "cueCount": 180,
  "text": "We're no strangers to love…",
  "tracks": [{ "languageCode": "en", "name": "English" }],
  "cues": [
    { "start": 0.0, "duration": 3.5, "text": "We're no strangers to love" }
  ]
}
```

With `expandCues: true`, each cue also becomes its own Dataset row (`type: "cue"`).

***

### How to use

1. Open **[YouTube Subtitles Scraper](https://apify.com/scrapemamba/youtube-subtitles-scraper)**
2. Pass one known-captioned public video; keep `expandCues: false` for the first run
3. Scale the `videoIds` list once the schema looks right

#### Input example

```json
{
  "videoIds": ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"],
  "lang": "en",
  "expandCues": false
}
```

#### API (Node.js)

```javascript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('scrapemamba/youtube-subtitles-scraper').call({
  videoIds: ['dQw4w9WgXcQ'],
  lang: 'en',
  expandCues: false,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

#### Local run

```bash
cd youtube-subtitles-scraper-js
cp .env.example .env
npm install
node src/main.js
```

***

### Input parameters

| Parameter | Required | Default | Description |
|---|---|---|---|
| `videoIds` | Yes | — | Watch URLs, Shorts, `youtu.be`, embeds, or 11-character IDs. Free users limited to **200** videos per run; paying users uncapped. |
| `lang` | No | `"en"` | Preferred caption language code |
| `expandCues` | No | `false` | If true, also push one Dataset row per cue (multiplies billable rows) |

***

### Output

Default runs produce one `type: "subtitles"` row per video. `expandCues: true` adds `type: "cue"` rows. API failures become `type: "error"` while other videos continue.

The Actor cannot invent captions when none are exposed. Auto-generated and human tracks both count when YouTube provides them.

***

### Why choose this Actor

- **Public captions only** — Clear availability flags; `cuesError` when tracks exist without timed cues
- **Flexible storage** — Keep cues as JSON on the parent row, or expand to flat rows
- **Suite join keys** — Same `videoId` as Video / Search / Related
- **Batch transcript automation** — Built for catalogs, not phone copy-paste

***

### Pricing

**$1.99 per 1,000 results** on Apify. Cue expansion multiplies rows. Free users: first **200** videos per run. See the [Store page](https://apify.com/scrapemamba/youtube-subtitles-scraper).

***

### FAQ

#### How do I get YouTube transcripts in bulk?

Pass many URLs/IDs, set `lang`, keep `expandCues: false` unless you need cue rows, run on Apify, export the Dataset.

#### What if captions are off?

If no track (including auto-generated) exists, the Actor will not invent speech — expect empty availability or an error.

#### What does `cuesError` mean?

Tracks were found, but timed cues were not returned. Inspect `raw`; try another language or retry. Different from “captions fully off.”

#### Auto vs human captions?

Both are returned when available. Quality varies; the Actor does not guarantee a human track.

#### Do Shorts work?

Yes, if you pass Shorts URLs/IDs and captions exist.

#### How many videos can I process in one run?

Free users are limited to the first **200** videos per run; paying users are uncapped.

#### Should I store cues as JSON or rows?

JSON on the `subtitles` row is usually cheaper. Use `expandCues` when your warehouse prefers flat timestamp tables.

***

### Related Actors

| Actor | Use it for |
|---|---|
| [YouTube Video Scraper](https://apify.com/scrapemamba/youtube-video-scraper) | Metadata beside captions |
| [YouTube Search Scraper](https://apify.com/scrapemamba/youtube-search-scraper) | Find videos to caption |
| [YouTube Related Videos Scraper](https://apify.com/scrapemamba/youtube-related-videos-scraper) | Expand a neighborhood before selective captioning |
| [YouTube Channel Videos Scraper](https://apify.com/scrapemamba/youtube-channel-videos-scraper) | Shortlist uploads to caption |

Use only on **public** caption data per YouTube’s terms, copyright/privacy law, and your policies. Do not bypass disabled captions or access private videos.

# Actor input Schema

## `videoIds` (type: `array`):

YouTube video URLs or 11-character video IDs. Free users are limited to 200 videos per run.

## `lang` (type: `string`):

Preferred caption language (e.g. en).

## `expandCues` (type: `boolean`):

If true, also push one dataset row per subtitle cue.

## Actor input object example

```json
{
  "videoIds": [
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  ],
  "lang": "en",
  "expandCues": false
}
```

# Actor output Schema

## `results` (type: `string`):

Default dataset items produced by this Actor.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "videoIds": [
        "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
    ],
    "lang": "en"
};

// Run the Actor and wait for it to finish
const run = await client.actor("scrapemamba/youtube-subtitles-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "videoIds": ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"],
    "lang": "en",
}

# Run the Actor and wait for it to finish
run = client.actor("scrapemamba/youtube-subtitles-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "videoIds": [
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  ],
  "lang": "en"
}' |
apify call scrapemamba/youtube-subtitles-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,scrapemamba/youtube-subtitles-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/KrY6RSnnFfzC308le/builds/eKSgOXh1XNxqA24ft/openapi.json
