# FlashData YouTube Transcript API

Recupere o texto da transcrição YouTube com datas e uma transcrição completa. Legendas automáticas são selecionadas por padrão.

Referência canônica: https://flashdata.dev/pt/docs/sources/youtube_transcript
Revisado: 2026-10-23

Ponto final: POST https://data.flashdata.dev/v1/queries/realtime
Autenticação: X-API-Key: YOUR_API_KEY
Modos: [Realtime](https://flashdata.dev/pt/docs/reference/realtime-and-async/reference.md#realtime) · [Async](https://flashdata.dev/pt/docs/reference/realtime-and-async/reference.md#async) · [Batch](https://flashdata.dev/pt/docs/reference/batch-and-bulk/reference.md#batch) · [Bulk](https://flashdata.dev/pt/docs/reference/bulk-processing/reference.md)

Precisou de permissão de origem: youtube_transcript

Substitua YOUR_API_KEY por uma chave API que tem essa permissão de fonte e créditos disponíveis. Execute pedidos no seu servidor ou host de agente.

[Configurar autenticação](https://flashdata.dev/pt/docs/guides/headers-and-authentication/reference.md)

[Escolha uma língua transcrita e a track](https://flashdata.dev/pt/docs/guides/youtube-data-guide/reference.md#captions)

<a id="quickstart"></a>

## Envie um pedido

### Python

```bash
python3 -m pip install requests
```

```python
import json

import requests

api_key = "YOUR_API_KEY"
payload = {
    "source": "youtube_transcript",
    "video_id": "dQw4w9WgXcQ",
    "params": {
        "language": "en",
        "auto": True,
    },
}

response = requests.post(
    "https://data.flashdata.dev/v1/queries/realtime",
    headers={"X-API-Key": api_key},
    json=payload,
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), ensure_ascii=False, indent=2))
```

### Bash / cURL

```bash
api_key="YOUR_API_KEY"
curl --fail-with-body --max-time 120 --request POST "https://data.flashdata.dev/v1/queries/realtime" \
  --header "Content-Type: application/json" \
  --header "X-API-Key: $api_key" \
  --data-binary @- <<'FLASHDATA_JSON'
{
  "source": "youtube_transcript",
  "video_id": "dQw4w9WgXcQ",
  "params": {
    "language": "en",
    "auto": true
  }
}
FLASHDATA_JSON
```

<a id="parameters"></a>

## Parâmetros

<a id="parameters-group-0"></a>

### Corpo da requisição

| Parâmetro | Tipo | Obrigatório | Padrão | Descrição |
| --- | --- | --- | --- | --- |
| <a id="parameter-source"></a> source | string | Sim | — | Preparar para youtube_transcript.  |
| <a id="parameter-video_id"></a> video_id | string | Sim | Não está pronto | O 11-caracter YouTube vídeo ID, como FUfGcZ092b0. Aceita letras, números, sublinhados e hífens. Comprimento mínimo: 11. Comprimento máximo: 11. Padrão: ^[A-Za-z0-9_-]{11}$ |
| <a id="parameter-params"></a> params | object | Não | {} | Settings para este pedido.  |
| <a id="parameter-callback_url"></a> callback_url | string · nullable | Não | Não está pronto | Async e apenas lote. HTTPS conclusão URL na porta 443, até caracteres 2,048. Sem credenciais de usuário ou fragmento URL. Omit, use null ou uma string vazia para nenhuma notificação. Em um lote, coloque isso em cada consulta, fora dos parâmetros.  |

<a id="parameters-group-1"></a>

### Selecção de legendas

| Parâmetro | Tipo | Obrigatório | Padrão | Descrição |
| --- | --- | --- | --- | --- |
| <a id="parameter-params-language"></a> params.language | string \| array | Não | en-orig → en | Omita para o inglês (en-orig, então en). Com auto=true, cada código tenta sua faixa de origem primeiro, depois o código solicitado. Códigos de origem explícitos e auto=false permanecem exatos. Arrays pedem 1–10 línguas distintas. Omita preferir en-orig e volte para en, devolvendo uma pista. Com auto=true, cada código tenta sua faixa de origem primeiro, depois o código solicitado; códigos de origem explícitos e auto=false permanecem exatos. Arrays de 1–10 Códigos distintos tentam cada idioma solicitado e retornam faixas e erros por idioma em ordem de solicitação. languageCode identifica a faixa selecionada; requestedLanguageCode está incluído quando difere do código solicitado. |
| <a id="parameter-params-auto"></a> params.auto | boolean | Não | true | true seleciona legendas geradas por YouTube; false seleciona legendas fornecidas por uploaders. Isso seleciona a origem da legenda, não a detecção de linguagem ou nova transcrição.  |

<a id="response"></a>

## Leia o resultado

Salve a resposta JSON bem sucedida como response.json. Guarde isso como read-response.py e execute python read-response.py. Ele usa apenas a biblioteca padrão do Python e não faz nenhum novo pedido.

### read-response.py

```python
import json
from pathlib import Path

response = json.loads(Path("response.json").read_text(encoding="utf-8-sig"))
if response.get("status") not in ("done", "completed") or not isinstance(response.get("results"), list):
    raise SystemExit("Expected completed result JSON; inspect the response or job status.")
if not response["results"]:
    print("[]")
    raise SystemExit(0)
result = response["results"][0]

output = {
    "tracks": result.get("tracks", [result]),
    "errors": result.get("errors", []),
}
print(json.dumps(output, ensure_ascii=False, indent=2))
```

## Exemplo de resposta

Exemplo gravado; campos e conta depende da fonte e entrada solicitada.
```json
{
  "source": "youtube_transcript",
  "status": "done",
  "results": [
    {
      "videoId": "dQw4w9WgXcQ",
      "languageCode": "en",
      "languageName": null,
      "isAutoGenerated": true,
      "segments": [
        {
          "start": 0.32,
          "end": 14.58,
          "text": "[Music]"
        },
        {
          "start": 18.8,
          "end": 25.96,
          "text": "We're no strangers to"
        },
        {
          "start": 21.8,
          "end": 29.119,
          "text": "love. You know the rules and so do"
        },
        {
          "start": 25.96,
          "end": 30.279,
          "text": "I. I feel commitments from what I'm"
        },
        {
          "start": 29.119,
          "end": 34.36,
          "text": "thinking"
        },
        {
          "start": 30.279,
          "end": 39.559,
          "text": "of. You wouldn't get this from any other"
        },
        {
          "start": 34.36,
          "end": 43.12,
          "text": "guy. I just want to tell you how I'm"
        },
        {
          "start": 39.559,
          "end": 45.84,
          "text": "feeling. Got to make you understand."
        },
        {
          "start": 43.12,
          "end": 49.2,
          "text": "Never going to give you up. I'm going to"
        },
        {
          "start": 45.84,
          "end": 53.32000000000001,
          "text": "let you down. I'm going to run around"
        },
        {
          "start": 49.2,
          "end": 56.399,
          "text": "and desert you. I'm going to make"
        },
        {
          "start": 53.32,
          "end": 59.879,
          "text": "you say goodbye."
        },
        {
          "start": 56.399,
          "end": 64.04,
          "text": "Tell a lie and hurt"
        },
        {
          "start": 59.879,
          "end": 67.2,
          "text": "you. We've known each other for so"
        },
        {
          "start": 64.04,
          "end": 70.56,
          "text": "long. Your heart's been aching, but"
        },
        {
          "start": 67.2,
          "end": 72.60000000000001,
          "text": "you're too shy to say we don't know"
        },
        {
          "start": 70.56,
          "end": 77.799,
          "text": "what's been going"
        },
        {
          "start": 72.6,
          "end": 81.479,
          "text": "on. We know the game and we're going to"
        },
        {
          "start": 77.799,
          "end": 84.56,
          "text": "play. If you ask me how I'm"
        },
        {
          "start": 81.479,
          "end": 88.32,
          "text": "feeling, don't tell me your truth. to"
        },
        {
          "start": 84.56,
          "end": 88.32000000000001,
          "text": "see. I will give"
        },
        {
          "start": 89.88,
          "end": 94.72,
          "text": "you"
        },
        {
          "start": 91.72,
          "end": 94.72,
          "text": "around"
        },
        {
          "start": 95,
          "end": 99.04,
          "text": "you. I will say"
        },
        {
          "start": 99.56,
          "end": 106.759,
          "text": "goodbye and hurt you. I will give"
        },
        {
          "start": 103.99,
          "end": 108.6,
          "text": "[Music]"
        },
        {
          "start": 106.759,
          "end": 115.92,
          "text": "you"
        },
        {
          "start": 108.6,
          "end": 115.92,
          "text": "around you. I will leave you. I will say"
        },
        {
          "start": 116.439,
          "end": 121.079,
          "text": "goodbye and hurt you."
        },
        {
          "start": 128.319,
          "end": 132.56,
          "text": "Never going to give. Never going to"
        },
        {
          "start": 129.759,
          "end": 134,
          "text": "give."
        },
        {
          "start": 132.56,
          "end": 136.8,
          "text": "Never going to give. Never going to"
        },
        {
          "start": 134,
          "end": 141.04,
          "text": "give."
        },
        {
          "start": 136.8,
          "end": 143.68,
          "text": "We've known each other for so long."
        },
        {
          "start": 141.04,
          "end": 147.51999999999998,
          "text": "Your heart's been aching, but you're too"
        },
        {
          "start": 143.68,
          "end": 148.52,
          "text": "shy to say it. We both know what's been"
        },
        {
          "start": 147.52,
          "end": 152.239,
          "text": "going"
        },
        {
          "start": 148.52,
          "end": 157.8,
          "text": "on. We know the game and we're going to"
        },
        {
          "start": 152.239,
          "end": 161.36,
          "text": "play it. I just want to tell you how I'm"
        },
        {
          "start": 157.8,
          "end": 163.92000000000002,
          "text": "feeling. Got to make you understand."
        },
        {
          "start": 161.36,
          "end": 166.8,
          "text": "Never going to give you up. Never going"
        },
        {
          "start": 163.92,
          "end": 171.28,
          "text": "to let you down. Never going to run"
        },
        {
          "start": 166.8,
          "end": 171.28,
          "text": "around and desert you. Heat."
        },
        {
          "start": 172.33,
          "end": 182.76,
          "text": "[Music]"
        },
        {
          "start": 178.76,
          "end": 182.76,
          "text": "Heat. Heat. Heat."
        },
        {
          "start": 183.39,
          "end": 195.2,
          "text": "[Music]"
        },
        {
          "start": 191.04,
          "end": 197.76,
          "text": "Never going to tell a lie and hurt you."
        },
        {
          "start": 195.2,
          "end": 200.64,
          "text": "Never going to give you up. Never going"
        },
        {
          "start": 197.76,
          "end": 204.239,
          "text": "to let you down. Never going to run"
        },
        {
          "start": 200.64,
          "end": 206.83999999999995,
          "text": "around and desert you. Never going to"
        },
        {
          "start": 204.239,
          "end": 211.879,
          "text": "make you cry. Never going to say"
        },
        {
          "start": 206.84,
          "end": 211.879,
          "text": "goodbye. Never going to say goodbye."
        }
      ],
      "fullText": "[Music] We're no strangers to love. You know the rules and so do I. I feel commitments from what I'm thinking of. You wouldn't get this from any other guy. I just want to tell you how I'm feeling. Got to make you understand. Never going to give you up. I'm going to let you down. I'm going to run around and desert you. I'm going to make you say goodbye. Tell a lie and hurt you. We've known each other for so long. Your heart's been aching, but you're too shy to say we don't know what's been going on. We know the game and we're going to play. If you ask me how I'm feeling, don't tell me your truth. to see. I will give you around you. I will say goodbye and hurt you. I will give [Music] you around you. I will leave you. I will say goodbye and hurt you. Never going to give. Never going to give. Never going to give. Never going to give. We've known each other for so long. Your heart's been aching, but you're too shy to say it. We both know what's been going on. We know the game and we're going to play it. I just want to tell you how I'm feeling. Got to make you understand. Never going to give you up. Never going to let you down. Never going to run around and desert you. Heat. [Music] Heat. Heat. Heat. [Music] Never going to tell a lie and hurt you. Never going to give you up. Never going to let you down. Never going to run around and desert you. Never going to make you cry. Never going to say goodbye. Never going to say goodbye."
    }
  ],
  "usage": {
    "credits": 0.01
  },
  "created_at": "2026-09-16T07:45:44.040Z"
}
```

## Múltiplos idiomas

Envie uma lista de idiomas para receber faixas e erros por idioma. Este exemplo mostra inglês disponível e espanhol indisponível.

```json
{
  "source": "youtube_transcript",
  "video_id": "jNQXAC9IVRw",
  "params": {
    "language": [
      "en",
      "es"
    ],
    "auto": true
  }
}
```

`results[0]`:

```json
{
  "videoId": "jNQXAC9IVRw",
  "isAutoGenerated": true,
  "tracks": [
    {
      "videoId": "jNQXAC9IVRw",
      "languageCode": "en-orig",
      "requestedLanguageCode": "en",
      "languageName": null,
      "isAutoGenerated": true,
      "segments": [
        {
          "start": 0,
          "end": 1.5,
          "text": "Hello world."
        }
      ],
      "fullText": "Hello world."
    }
  ],
  "errors": [
    {
      "languageCode": "es",
      "code": "language_unavailable",
      "message": "Auto-generated subtitles not available for language: es"
    }
  ]
}
```

## Campos de resposta

| Campo | Tipo | Descrição |
| --- | --- | --- |
| source | string | A fonte API solicitada. |
| status | string | Feito quando o pedido em tempo real for bem sucedido. |
| created_at | string | Tempo de criação de resposta no formato ISO 8601. |
| usage.credits | number | Créditos cobrados pelo pedido, baseado no seu plano. |
| results[0].videoId | string | O vídeo solicitado ID. |
| results[0].languageCode | string | Código de faixa de legenda selecionado, como en-orig. |
| results[0].languageName | string · nullable | O nome da linguagem quando disponível. |
| results[0].requestedLanguageCode | string · optional | O código solicitado quando difere do languageCode, por exemplo, quando o en-orig foi selecionado. |
| results[0].isAutoGenerated | boolean | Se as legendas selecionadas foram geradas automaticamente. |
| results[0].segments | array | Segmentos de legenda em ordem cronológica. |
| results[0].segments[].start | number | Segmento começa em segundos. |
| results[0].segments[].end | number | Segmento termina em segundos. |
| results[0].segments[].text | string | Mensagem de legenda. |
| results[0].fullText | string | Todo o texto se juntou a uma transcrição. |
| results[0].tracks | array · optional | Só para as linguagens. Faixas disponíveis em ordem de pedido, cada uma tem os campos de trilha única listados acima. |
| results[0].errors | array · optional | Só para as linguagens. Linguagens falhadas em ordem de pedido. Vazio quando todas as pistas têm sucesso. |
| results[0].errors[].languageCode | string | O idioma solicitado que falhou. |
| results[0].errors[].code | string | language_unavailable quando a faixa selecionada não existe, retrieval_failed quando não pode ser baixado ou analisado. |
| results[0].errors[].message | string | Descrição da falha na linguagem. |

- O API lê legendas já disponíveis no YouTube. Não gera novas transcrições ou se encaixam entre legendas automáticas e fornecidas pelo uploader.
- Uma linguagem de cordas mantém a resposta de uma única faixa. Um array, mesmo ["en"], retorna faixas e erros em vez de languageCode de nível superior, segmentos e fullText. Cada faixa inclui esses campos. Auto se aplica a cada idioma.
- Para listas de idiomas, consulte errors para identificar as faixas que falharam. Se nenhuma faixa for obtida, a solicitação falha e os créditos reservados são devolvidos. Uma falha na extração do vídeo ou o fim do prazo também faz a solicitação falhar.
- Disponível em tempo real, sincronia, lote e massa. Bulk exportações ficar JSONL com um registro por vídeo, incluindo suas faixas e erros. Accept e X-Respond-With se aplicam como de costume.

## Formatos de resposta

Respostas usam JSON por padrão. Escolha outro formato com esses cabeçalhos opcionais.

- Accept: application/json (padrão) ou text/plain. Texto simples apresenta os mesmos campos em um layout legível e indentado.
- X-Respond-With: markdown. Deixe de lado os campos originais. Markdown funciona com qualquer formato de resposta.

Markdown está disponível para consultas em tempo real e resultados completos.

Os campos abaixo descrevem a resposta padrão JSON.

[Requisito e formatação de resposta exemplos](https://flashdata.dev/pt/docs/guides/response-formats/reference.md#headers)

<a id="job-lifecycle"></a>

<a id="async-batch"></a>

## Conceitos básicos da API

O construtor de pedidos e exemplos acima usam os parâmetros desta fonte. Use os exemplos Python e cURL abaixo para submissão compartilhada, status e passos de resultado. Um corpo Batch é um objeto JSON contendo consultas, cada item retorna seu próprio trabalho ID.

- [Async pedido e recibo](https://flashdata.dev/pt/docs/reference/realtime-and-async/reference.md#async)

<a id="job-status"></a>

- [Verifique o status do trabalho](https://flashdata.dev/pt/docs/reference/realtime-and-async/reference.md#status)

<a id="job-results"></a>

- [Recupere resultados completados](https://flashdata.dev/pt/docs/reference/realtime-and-async/reference.md#results)
- [Batch JSON pedidos](https://flashdata.dev/pt/docs/reference/batch-and-bulk/reference.md#batch)
- [API de processamento Bulk](https://flashdata.dev/pt/docs/reference/bulk-processing/reference.md)
- [Construir um fluxo de trabalho Bulk para esta fonte](https://flashdata.dev/pt/docs/reference/bulk-processing/reference.md?source=youtube_transcript#playground)
- [Cliente OpenAPI](https://flashdata.dev/docs/openapi.json)

<a id="webhooks"></a>

<a id="callbacks"></a>

## Notificações de conclusão

- [Receba e verifique os hooks de conclusão](https://flashdata.dev/pt/docs/guides/async-batch/reference.md#webhooks)

<a id="troubleshooting"></a>

## Solução de problemas

- [Erros e códigos de status](https://flashdata.dev/pt/docs/errors/reference.md#status-codes)
- [Quando tentar novamente](https://flashdata.dev/pt/docs/errors/reference.md#retries)

## APIs relacionadas

- [YouTube Captions API](https://flashdata.dev/pt/docs/sources/youtube_captions/reference.md)
- [YouTube Video Metadata API](https://flashdata.dev/pt/docs/sources/youtube_metadata/reference.md)
