본문으로 건너뛰기
KO
API 키 받기

YouTube Data / JavaScript

을 얻다 YouTube 제목과 JavaScript

기존의 캡션 트랙을 검색하고 텍스트를 저장하고 검색, 인용 및 비디오 탐색을위한 타임 스탬프를 유지합니다.

FlashData · 게시됨

Timetamped transcript 세그먼트로 배치 된 비디오 캡션

당신의 환경을 준비

Node.js 22 또는 나중에 사용하십시오. 스크립트 사용 내장 fetch 그리고 파일 APIs, 그래서 패키지가 필요하지 않습니다. API 키, 사용 가능한 크레딧 및 기존 캡션 트랙과 비디오의 ID가 필요합니다.

bash
# Replace YOUR_API_KEY near the top of the code below.
export YOUTUBE_VIDEO_ID='dQw4w9WgXcQ'

비디오 ID는 v YouTube 시계 URL에 있는 가치. 이 엔드포인트의 경우, ID를 통해 전달합니다. video_id.

Fetch 및 캡션 저장

코드 저장 transcript.mjs. 그것은 영어 자동 트랙을 요청, 일반 텍스트를 하나의 파일로 작성하고 다른 전체 성적표를 유지합니다.

javascript
import { writeFile } from "node:fs/promises";

const apiKey = "YOUR_API_KEY";
const videoId = process.env.YOUTUBE_VIDEO_ID;
if (!videoId) {
  throw new Error("Set YOUTUBE_VIDEO_ID first.");
}
const baseUrl = "https://data.flashdata.dev";
const response = await fetch(baseUrl + "/v1/queries/realtime", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": apiKey,
  },
  body: JSON.stringify({
    source: "youtube_transcript",
    video_id: videoId,
    params: { language: "en", auto: true },
  }),
  signal: AbortSignal.timeout(60000),
});

const payload = await response.json();
if (!response.ok || payload.error) {
  throw new Error(payload.message ?? payload.detail ?? "Transcript request failed");
}
const transcript = payload.results?.[0];
if (!Array.isArray(transcript?.segments) || transcript.segments.length === 0) {
  throw new Error("No caption segments were returned for this video and language.");
}

const text = transcript.segments.map(segment => segment.text).join("\n");
await writeFile("transcript.txt", text, "utf8");
await writeFile("transcript.json", JSON.stringify(transcript, null, 2), "utf8");
console.log("Saved transcript.txt and transcript.json (with segment timestamps).");
bash
node transcript.mjs

transcript.txt 독서 또는 더 많은 텍스트 처리에 편리합니다. transcript.json 언어 정보 및 세그먼트 타임스탬프를 유지하십시오.

타임스탬프 유지

Caption 세그먼트에는 start, end 으로 text 검색 인덱스를 구축 할 때, 비디오 ID, 언어 및 타임 스탬프를 모든 펑크로 유지하므로 경기는 비디오로 다시 포인트를 할 수 있습니다.

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"
}

비디오 링크는 포함될 수 있습니다 &t=SECONDSs 세그먼트의 시작을 닫습니다. Timestamps는 인용 및 탐색에 유용합니다. 여러 개의 세그먼트를 하나의 문서로 결합하면.

손잡이 누락된 captions

Caption 가용성은 영상, 언어 및 궤도 유형에 달려 있습니다. 사용 가능한 트랙은 오류 또는 사용 가능한 세그먼트를 생성 할 수 있습니다. 스크립트는 두 개의 케이스를 확인하고 메시지를 중지합니다.

이 엔드포인트는 기존의 캡션을 검색합니다. 그들은 새로운 연설에 텍스트 출력을 생성하지 않습니다. 창조자 보호 트랙의 경우, 확인 캡션 API 그리고 그것의 선택권. 요청된 트랙이 존재하지 않을 때 반복적으로 동일한 요청을 제출하지 마십시오.