YouTube 字幕下载 API 接口

YouTube 字幕下载 API 接口简介

为方便需要批量下载 YouTube 字幕的同学,开放本站使用的 YouTube 字幕下载 API 接口。利用本接口,可以编写脚本下载单个视频字幕,或一次性批量下载某个 YouTube Playlist 内全部视频的字幕。
接口使用可参考 @Shadow get_youtube_subtitle
公开课、字幕组的同学如果没有编码经验且时间上要求不是很高(有时候我可能没空😂),也可联系我根据需求定制下载脚本。
也可以使用 YouTube 字幕下载网站手动下载所需字幕。


Authentication

请发邮件至获取 API-key, 默认每日请求数为 1000 次,需要更多请求数的同学请在邮件中说明,请求次数会在每天 00:00:00 清零。
测试用 API-key:a2d09c7d76fced01f8be4b1f4cce8bec
欢迎打赏支持本服务。

YouTube 字幕下载 API 接口

获取 YouTube 字幕

获取视频支持的字幕列表

URI HTTP Method Authentication
api.zhuwei.me/v1/captions/{video_id}?api-key={your_api_key} GET API key

请求参数

参数 类型 必填 说明
video_id string video_id
api-key string api-key

部分返回参数说明

参数 类型 说明
autogenerated Boolean 是否为自动生成字幕
machinetranslated Boolean 是否为机器翻译字幕
limit_remaining Integer 本日剩余请求次数, 将会在每天 00:00:00 清零

https://www.youtube.com/watch?v=XzK98UbxbjY 为例, 获取 video_idXzK98UbxbjY 的视频支持的字幕列表:
GET https://api.zhuwei.me/v1/captions/XzK98UbxbjY

返回结果:

{
  "meta": {
    "code": 200,
    "msg": "OK",
    "limit_remaining": 654
  },
  "responses": {
    "caption": {
      "video_url": "https://www.youtube.com/watch?v=kbdCg_xtUbA",
      "title": "how to get YouTube captions? Here is the easiest way!",
      "available_captions_count": 2,
      "available_captions": [
        {
          "language": "zh-HK",
          "caption_content_url": "https://api.zhuwei.me/v1/captions/kbdCg_xtUbA/contents/zh-HK",
          "autogenerated": false,
          "machinetranslated": false
        },
        {
          "language": "zh-Hans",
          "caption_content_url": "https://api.zhuwei.me/v1/captions/kbdCg_xtUbA/contents/machinetranslation/zh-Hans",
          "autogenerated": true,
          "machinetranslated": true
        }
      ]
    }
  }
}

获取字幕内容

从上一步返回的支持字幕列表中,选择某语言对应的 caption_content_url

URI HTTP Method Authentication
api.zhuwei.me/v1/captions/{video_id}/contents[/machinetranslations]/{language}?api-key={your_api_key}[&multilanguage=multilanguage] [&notimeline=notimeline] GET API key

请求参数

参数 类型 必填 说明
notimeline string notimeline = notimeline 时,将返回不带时间轴的字幕内容
multilanguage string multilanguage = multilanguage 时,将返回源语言 + 中文双语字幕内容
api-key string api-key

部分返回参数说明

参数 类型 说明
multilanguage Boolean 是否为双语字幕
notimeline Boolean 字幕内容是否不包含时间轴
content string 字幕内容,以\n换行

请求示例:
GET https://api.zhuwei.me/v1/captions/XzK98UbxbjY/contents/en?multilanguage=multilanguage
成功返回结果

{
  "meta": {
    "code": 200,
    "msg": "OK",
    "limit_remaining": 80
  },
  "contents": {
    "language": "zh-HK",
    "multilanguage": false,
    "notimeline": false,
    "content": "1\n00:00:00,000 --> 00:00:03,702\n查看視頻是否包含字幕\n\n2\n00:00:03,702 --> 00:00:06,310\n復制 Youtube 視頻地址\n\n3\n00:00:06,310 --> 00:00:11,573\n訪問 Youtube 字幕網站: https://zhuwei.me/y2b/\n\n4\n00:00:11,573 --> 00:00:17,573\n在輸入框粘貼剛才復制的 YouTube 視頻地址\n\n5\n00:00:17,573 --> 00:00:19,535\n點擊"獲取字幕"\n\n6\n00:00:19,535 --> 00:00:21,535\n點擊所需字幕語言\n\n7\n00:00:21,535 --> 00:00:23,593\n字幕分別為 1.打包的 .SRT 字幕\n\n8\n00:00:23,593 --> 00:00:25,565\n2.SRT 字幕\n\n9\n00:00:25,565 --> 00:00:29,393\n3.不包含時間軸的字幕\n\n10\n00:00:29,393 --> 00:00:55,066\n再演示一次 (ง •_•)ง\n\n11\n00:00:55,066 --> 00:00:57,360\n(●'◡'●)\n\n"
  }
}

获取 YouTube Playlist 内所有视频 ID

URI HTTP Method Authentication
api.zhuwei.me/v1/videos/playlists/{playlist_id}?api-key={your_api_key} GET API key

请求示例:
GET https://api.zhuwei.me/v1/videos/playlists/PLUl4u3cNGP61qDex7XslwNJ-xxxEFzMNV
返回示例

{
    "meta": {
        "code": 200, 
        "msg": "OK", 
        "limit_remaining": 100
    }, 
    "response": {
        "playlist": {
            "videos_count": 215, 
            "videos": [
                "F3N5EkMX_ks", 
                "5ucfHd8FWKw", 
                "Jf2PgGInUEk", 
                "Bq0fDYtbfBA", 
                "pW6tqp1zRrg", 
                "VZm6mxu2xlk", 
                "esHLwySu4XU", 
                "i4u7SZjoAs4", 
                "ErlP_SBcA1s", 
                "kJxsMnRZXqE", 
                "W1lxlbJ0BZU", 
                "otGGuHt36XA", 
                "YdyhDdXaSP4", 
                "jtOxRPQDuJs", 
                "xZn4l1TSvPQ", 
                "qxNJGKrx3EY", 
                "qmCbc9dbwXU", 
                "H7xmTMQ265s", 
                "Q3v_2znHCvg", 
                "oOQmu6ICxg4", 
                "sgymEX-4FxE", 
                "83NmtaE7fEk", 
                "_zl4b5MnPF0", 
                "rqTAICbKHYM", 
                "5zXYEVWSIsg", 
                "PQfYJ2TjpEU", 
                "pb5hUGBjS3A", 
                "ZjGjNsmsNBU", 
                "SjK2lmRFxc4", 
                "yLb_a1EE888", 
                "89SjJv30kGU", 
                "4K539RaRDXU", 
                "QCA3zOe2xdA", 
                "z0xyQKalezI", 
                "NiCMMn12CIs", 
                "_mqFIqnCPak", 
                "gl9c9qJRqcM", 
                "IV9NhNIrrDw", 
                "mLLUgcvQLgY", 
                "RBaBEjzMr4E", 
                "CfBeCHrQj_U", 
                "dHMGV_WOG7w", 
                "rCP_-Wuikwo", 
                "sffRo1-_D8E", 
                "7WDiK3flILc", 
                "63U4_OxohOw", 
                "uhaFP0xEmzM", 
                "l062G7RC8-o", 
                "XeTsZhYHY_E", 
                "ozIdCgo5uI4", 
                "sfH3Jw6LZm8", 
                "aAybYawUPC4", 
                "_r7pI2_FjSg", 
                "dlJtUvRaGdE", 
                "uo86ir31pn0", 
                "S9_Oe51XkVY", 
                "q785KV5ZIN0", 
                "emrHcqEvXpw", 
                "l_NW5pPXhg4", 
                "_0PrwAbgoMA", 
                "prCwfSiWuq0", 
                "lufK0UlJ7aE", 
                "tniGFmPQc0E", 
                "ofgusnhQ07Q", 
                "WLHAaaGHfe8", 
                "gEX7MjWwocE", 
                "bX4liSWB4Gk", 
                "vkWY73HnNYA", 
                "0mGd0JUmgm8", 
                "FNOfxJxceIM", 
                "gWLC3r6EHl0", 
                "GuiIyYbI0HM", 
                "lw9W32ezQhM", 
                "3V5y9uq5au0", 
                "9NS0JcjNdp4", 
                "NBOL5X13UFY", 
                "cadbtBS5qf4", 
                "5QKJG0FZTio", 
                "Veyh-DhI8lE", 
                "vUg50UI1aqs", 
                "30Ww1HsRblM", 
                "JTePtoM_MeM", 
                "flwYlUfw4WU", 
                "n1cXiw3s72k", 
                "1GvCIlHihEA", 
                "xtpW7fw8s34", 
                "bEpq3yjismU", 
                "sxv80X2jQYQ", 
                "Cslq_ZYdYwE", 
                "Vg8t8_IOHDg", 
                "w7z_z-lucyU", 
                "ol1COj0LACs", 
                "-b0dFcebPcs", 
                "e548hRYcXlg", 
                "CFh3gu-z_rc", 
                "QPV-DmpGXeQ", 
                "xxGA-7soXiw", 
                "D2lW7o32fzk", 
                "sN-m5WkbMyI", 
                "L5jhg4q1Xvo", 
                "7TljYDljC5w", 
                "V-fy33vi-64", 
                "YGR5_Hf9dDg", 
                "7Mv5hT1nugQ", 
                "Xsg27_uGVZA", 
                "uua2hbbp7h4", 
                "SLPRYIb7RdI", 
                "UPnqIKBAMaQ", 
                "9VJetX_EQqs", 
                "dvWKCH0ocu8", 
                "7Kq8BINVDiw", 
                "bHocXJ4rv5g", 
                "nWaoEjE8a8M", 
                "0qEIs6ie2q8", 
                "efpiHD_2O8E", 
                "d9ugFckUBcg", 
                "QAdiRwOLl0A", 
                "m8_3VwHy7tE", 
                "TF93gm1_O8M", 
                "FSW9EQNZvxI", 
                "2TZa151GC-0", 
                "CsHQ35j_1kY", 
                "zLGu1dlP0UY", 
                "oQqskrRWGco", 
                "i2_731Gi9bg", 
                "ykwNGB9kuaA", 
                "fLuyZ7ayDog", 
                "0jWwl0bt6aU", 
                "nfawe03nvAY", 
                "OwNr82QgkP8", 
                "ZBlHexE8m6A", 
                "Lpd_TddOSZY", 
                "EX0uHJbIw68", 
                "nCDOa63Jd6M", 
                "ThZH56PUwNc", 
                "0EMIK-6LUE4", 
                "_7JPHNCT1Qo", 
                "t2PkbsWjG80", 
                "z5JfWSocZUQ", 
                "huPKjd3wLyc", 
                "NCCzjtqZ28M", 
                "1UdGbyj8924", 
                "EHCACV8rdig", 
                "DYi8KTt8688", 
                "cwO5KdgBQh0", 
                "MoRip5VVdkI", 
                "YLDRzy8Dcgo", 
                "4ZnijNan49U", 
                "CcJoqITNvh0", 
                "6-7BOpZ2k04", 
                "B6a9FaYI730", 
                "ayIgWaBE0aw", 
                "yA203Lrd39E", 
                "1s6_4qX-u2o", 
                "UE-O9TiKOw0", 
                "-M8swpL-Ij8", 
                "KmGPMec8-iU", 
                "7x62TdS0Nn0", 
                "jAcdLZRhYNU", 
                "Uoukes39gb0", 
                "mjrQHIJj1iI", 
                "oRzzwpZ0ei4", 
                "efH7pq9YVQw", 
                "u_LAfG5uIpY", 
                "ZApVXJZF7pE", 
                "2oK7Eb0YZ9U", 
                "0QF_uCgZW4Y", 
                "1AJbVRQTZlA", 
                "BPnbq6BobdA", 
                "r2Qb0vsxa8Y", 
                "QmCQUBSsKwQ", 
                "cMu0hsvgkGk", 
                "X9K8LT7SCZ0", 
                "9yFkrh7-igc", 
                "jM-JYT2j6Yw", 
                "1BU28txGAFI", 
                "ByTlCmDoEnk", 
                "O_M8asN10oQ", 
                "PKOhhK7kPi4", 
                "reUjl788R9Q", 
                "FlHKTvUjD6g", 
                "uRUAnKCyyig", 
                "2guwjwIHmGg", 
                "IWD-Aue6aIk", 
                "6h3T3qIkxqw", 
                "Idx3VgOpUDk", 
                "WwvDJqtHNBU", 
                "d2POYCmmM8A", 
                "2tSUT6HDeaw", 
                "mHVnpuhfpvI", 
                "rd9d0WBFzt8", 
                "tO6Wh_HhifI", 
                "NbXDgm7UyVM", 
                "DSk8HTcB7x0", 
                "x5WavAj2M8A", 
                "W3TqFzVh_rE", 
                "3JzsqGZ6opI", 
                "c15RtHXBVuQ", 
                "EhgF2OViDDs", 
                "oILq3xz_XtU", 
                "WxkwkGEVu-E", 
                "lkeX42KQjac", 
                "1UD560RQ684", 
                "4r1xgrWbALg", 
                "hxa6jAYA980", 
                "CfTLS6YYPms", 
                "cHKyuSAySyE", 
                "TvdmaZR6m8Q", 
                "RX88J2e4W0M", 
                "ZMa-xKcM2L8", 
                "xh_LCHvzp-Q", 
                "V1I-vrXGl3A", 
                "ThP6wQkf5ec", 
                "jOPA3XY-V3U", 
                "5oLLnCGStUc"
            ]
        }
    }
}

已知问题:

  • 部分有地区、年龄限制的视频和 YouTube Red 无法获取字幕,出于安全考虑放弃了传递 Cookie 的想法。

反馈 bug 或者其他任何问题欢迎随时与我联系。欢迎打赏支持本服务。

YouTube 字幕下载 API 接口