# YouTube Caption & Chapter Preflight (`bread-kim/youtube-caption-chapter-preflight`) Actor

Validate SRT captions and YouTube chapters before upload. Detect timing errors, overlaps, reading-speed issues, and chapter-rule violations, then export cleaned caption and chapter files plus validation reports. No video scraping or AI caption generation.

- **URL**: https://apify.com/bread-kim/youtube-caption-chapter-preflight.md
- **Developed by:** [bread kim](https://apify.com/bread-kim) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$20.00 / 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 Caption & Chapter Preflight

A private Apify Actor for developer teams and creator agencies that batch-check **creator-owned or otherwise authorized** basic UTF-8 SRT and description chapter text before a manual YouTube upload. It performs no scraping, video/audio download, AI inference, proxying, account access, or YouTube mutation.

The Actor accepts pasted SRT plus trusted `durationSeconds` metadata. It returns exactly one coordinate-only summary in `OUTPUT` and exactly one identical default-dataset item for valid input. Valid artifacts are independently exportable: a chapter failure does not withhold a valid caption export, and a caption failure does not withhold valid chapters. Private KVS subtitle/chapter exports contain customer text; the dataset and reports do not.

### Supported contract

- 1–20 videos; 11-character video IDs are metadata only and are never fetched.
- Basic numbered UTF-8 SRT blocks separated by blank lines, exact `HH:MM:SS,mmm --> HH:MM:SS,mmm`, BOM/CRLF accepted, multiline Unicode text preserved.
- Plain text only. WebVTT, ASS, TTML, cue settings and markup are refused instead of silently transformed.
- Cue timing is never sorted, shifted, repaired, removed, or invented. Export changes only line endings, removes a leading BOM, and reindexes cue IDs.
- Overlap, gaps over five seconds, and reading speed are advisory warnings. Overlap may be legitimate for speakers. Reading speed counts Unicode code points, not grapheme clusters, and is not a YouTube rule.
- Chapter parsing recognizes only nonempty-title lines beginning with `MM:SS` (minutes 00–59) or `H:MM:SS`. Other description lines are ignored; timestamp-looking malformed lines are errors. Normalized chapter exports exclude ordinary description prose.
- Chapter rules checked: at least three timestamps, first at 00:00, strictly ascending, each start before duration, and every span—including the last—at least ten seconds. These implement the documented chapter timing rules but do not claim that YouTube will actually display chapters.

This is not transcript-accuracy review, legal/accessibility certification, ownership proof, automatic upload, or an authorization bypass. Do not submit third-party, confidential, unlawful, or unauthorized content. Credential/private-key patterns are rejected, but the detector is not a secret scanner guarantee.

### Use

See [examples/input.json](examples/input.json). Run `npm ci --ignore-scripts`, then `npm test`, `npm run typecheck`, and `npm run build`. For local Actor-storage integration, set an absolute `CRAWLEE_STORAGE_DIR`; no input produces only an `OUTPUT` record with `INVALID_INPUT` and no dataset row. `AUTOMATON_CONTAINER_SMOKE=1` selects a deterministic no-network startup check.

Outputs include `REPORT.JSON`, `REPORT.MD`, `EXPORTS.JSON`, `MANIFEST.JSON`, and eligible `CAPTIONS_<hash>.SRT` / `CHAPTERS_<hash>.TXT` records. Record keys are derived from the validated video ID; payload hashes and a canonical source-input hash support reproducibility. Deep links are canonical `https://www.youtube.com/watch?v=<validated-id>&t=0s` values and are never requested.

Free alternatives include Subtitle Edit and manual checks in YouTube Studio. The product's value is bounded batch/CI validation, line-level evidence, machine-readable summaries, independent handoff files, and reproducible hashes—not a novel caption algorithm.

# Actor input Schema

## `videos` (type: `array`):

One to twenty creator-owned video preflight jobs.

## `maxCharactersPerSecond` (type: `number`):

Advisory reading-speed threshold using Unicode code points.

## Actor input object example

```json
{
  "videos": [
    {
      "videoId": "OwnedDemo01",
      "durationSeconds": 60,
      "captionsSrt": "1\n00:00:00,000 --> 00:00:03,000\nHello, owned demo.\n",
      "chapterText": "00:00 Opening\n00:20 Details\n00:40 Wrap up"
    }
  ],
  "maxCharactersPerSecond": 20
}
```

# Actor output Schema

## `summary` (type: `string`):

The single authoritative OUTPUT key-value store record.

## `dataset` (type: `string`):

Exactly one copy of the authoritative summary for valid input.

## `report` (type: `string`):

Report without caption text or chapter titles.

## `exports` (type: `string`):

Hashes and record keys for eligible normalized handoff files.

## `manifest` (type: `string`):

Hashes every payload record except the manifest itself.

# 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 = {
    "videos": [
        {
            "videoId": "OwnedDemo01",
            "durationSeconds": 60,
            "captionsSrt": "1\n00:00:00,000 --> 00:00:03,000\nHello, owned demo.\n",
            "chapterText": "00:00 Opening\n00:20 Details\n00:40 Wrap up"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("bread-kim/youtube-caption-chapter-preflight").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 = { "videos": [{
            "videoId": "OwnedDemo01",
            "durationSeconds": 60,
            "captionsSrt": """1
00:00:00,000 --> 00:00:03,000
Hello, owned demo.
""",
            "chapterText": """00:00 Opening
00:20 Details
00:40 Wrap up""",
        }] }

# Run the Actor and wait for it to finish
run = client.actor("bread-kim/youtube-caption-chapter-preflight").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 '{
  "videos": [
    {
      "videoId": "OwnedDemo01",
      "durationSeconds": 60,
      "captionsSrt": "1\\n00:00:00,000 --> 00:00:03,000\\nHello, owned demo.\\n",
      "chapterText": "00:00 Opening\\n00:20 Details\\n00:40 Wrap up"
    }
  ]
}' |
apify call bread-kim/youtube-caption-chapter-preflight --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bread-kim/youtube-caption-chapter-preflight"
        }
    }
}
```

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/hjr9Pc0hzWI52Wcpk/builds/mBcOC6aM7SwKaG7Ti/openapi.json
