字幕提取接口
Note
接口概述
该接口用于提取视频字幕,目前仅支持 YouTube 平台。如需其他平台支持,请联系客服。
🎯 基本信息
| 项目 | 内容 |
|---|---|
| 接口地址 | https://api.meowload.net/openapi/extract/subtitles |
| 请求方式 | POST |
| Content-Type | application/json |
📋 请求参数
请求头 (Headers)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
x-api-key | string | 是 | API 密钥,在 开发者管理中心 获取 |
accept-language | string | - | 错误消息语言,默认 en支持: zh、en、ja、es、de 等 |
请求体 (Body)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 是 | 视频分享链接地址 |
请求示例
curl -X POST https://api.meowload.net/openapi/extract/subtitles \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key-here" \
-H "accept-language: zh" \
-d '{
"url": "https://www.youtube.com/watch?v=bdLEBN6JKPY"
}'🟢 成功响应
HTTP 状态码:
200 OK
响应示例
{
"id": "bdLEBN6JKPY",
"text": "Germán Santillán: A taste of Mexico's ancient chocolate-making tradition | TED",
"description": "Dating back more than 800 years, chocolate is deeply woven into the Indigenous history of Oaxaca, Mexico. TED Fellow Germán Santillán talks about his work reviving the Mixtec technique used to prepare this ancient delicacy by training a new generation of local farmers -- helping create economic opportunity and preserve a delicious legacy at the same time.",
"duration": 363,
"published_at": "2021-09-13T08:00:32-07:00",
"thumbnail_url": "https://i.ytimg.com/vi_webp/bdLEBN6JKPY/maxresdefault.webp",
"subtitles": [
{
"language_name": "Chinese (China)",
"language_tag": "zh-CN",
"urls": [
{
"url": "https://www.youtube.com/api/timedtext?fmt=srt&lang=zh-CN&v=bdLEBN6JKPY",
"format": "srt"
},
{
"url": "https://www.youtube.com/api/timedtext?fmt=vtt&lang=zh-CN&v=bdLEBN6JKPY",
"format": "vtt"
}
]
},
{
"language_name": "English",
"language_tag": "en",
"urls": [
{
"url": "https://www.youtube.com/api/timedtext?fmt=srt&lang=en&v=bdLEBN6JKPY",
"format": "srt"
},
{
"url": "https://www.youtube.com/api/timedtext?fmt=vtt&lang=en&v=bdLEBN6JKPY",
"format": "vtt"
}
]
}
]
}响应字段说明
| 字段 | 类型 | 必返回 | 说明 |
|---|---|---|---|
id | string | - | 视频 ID |
text | string | 是 | 视频标题 |
description | string | - | 视频详细描述 |
duration | number | - | 视频时长(秒) |
published_at | string | - | 视频发布时间 |
thumbnail_url | string | - | 视频封面图地址 |
subtitles | array | 是 | 字幕列表数组 |
subtitles 数组字段
| 字段 | 类型 | 必返回 | 说明 |
|---|---|---|---|
language_name | string | 是 | 语言名称(如 “Chinese (China)“) |
language_tag | string | 是 | 语言标签(如 “zh-CN”) |
urls | array | 是 | 该语言各种格式的字幕下载链接 |
urls 数组字段
| 字段 | 类型 | 必返回 | 说明 |
|---|---|---|---|
format | string | 是 | 字幕格式srt、vtt、ttml、json3、srv1、srv2、srv3 |
url | string | 是 | 字幕文件下载地址 |
🔴 错误响应
HTTP 状态码:非
200(如 400、401、402、422、500)
错误响应示例
{
"message": "链接格式错误"
}HTTP 状态码说明
| 状态码 | 说明 | 常见原因 | 解决方案 |
|---|---|---|---|
200 | 成功 | - | - |
400 | 业务失败 | 解析失败,链接不包含有效媒体 | 检查链接是否正确,是否包含视频/图片等 |
401 | 鉴权失败 | API Key 无效或过期 | 检查 x-api-key 是否正确 |
402 | 次数用尽 | 调用额度已用完 | 前往 管理中心 充值 |
422 | 参数错误 | 链接格式不正确 | 检查 url 参数格式 |
500 | 服务器错误 | 服务器内部异常 | 联系技术支持 |
💻 代码示例
Python
import requests
api_url = "https://api.meowload.net/openapi/extract/subtitles"
api_key = "your-api-key-here"
payload = {
"url": "https://www.youtube.com/watch?v=bdLEBN6JKPY"
}
headers = {
"x-api-key": api_key,
"accept-language": "zh"
}
response = requests.post(api_url, json=payload, headers=headers)
if response.status_code == 200:
data = response.json()
print(f"✅ 提取成功!")
print(f"视频标题: {data['text']}")
print(f"字幕语言数: {len(data['subtitles'])}")
# 下载第一个语言的 SRT 格式字幕
if data['subtitles']:
first_lang = data['subtitles'][0]
print(f"\n下载 {first_lang['language_name']} 字幕...")
# 找到 SRT 格式
srt_url = next(
(u['url'] for u in first_lang['urls'] if u['format'] == 'srt'),
None
)
if srt_url:
subtitle_response = requests.get(srt_url)
with open(f"{first_lang['language_tag']}.srt", 'wb') as f:
f.write(subtitle_response.content)
print(f"✅ 字幕已保存: {first_lang['language_tag']}.srt")
else:
error = response.json()
print(f"❌ 请求失败: {error['message']}")Golang
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
type SubtitlesRequest struct {
URL string `json:"url"`
}
type SubtitleURL struct {
URL string `json:"url"`
Format string `json:"format"`
}
type Subtitle struct {
LanguageName string `json:"language_name"`
LanguageTag string `json:"language_tag"`
URLs []SubtitleURL `json:"urls"`
}
type SubtitlesResponse struct {
ID string `json:"id"`
Text string `json:"text"`
Description string `json:"description"`
Duration int `json:"duration"`
PublishedAt string `json:"published_at"`
ThumbnailURL string `json:"thumbnail_url"`
Subtitles []Subtitle `json:"subtitles"`
}
func main() {
apiURL := "https://api.meowload.net/openapi/extract/subtitles"
apiKey := "your-api-key-here"
requestBody := SubtitlesRequest{
URL: "https://www.youtube.com/watch?v=bdLEBN6JKPY",
}
jsonData, _ := json.Marshal(requestBody)
req, _ := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", apiKey)
req.Header.Set("accept-language", "zh")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("❌ 请求失败: %v\n", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode == 200 {
var result SubtitlesResponse
json.Unmarshal(body, &result)
fmt.Println("✅ 提取成功!")
fmt.Printf("视频标题: %s\n", result.Text)
fmt.Printf("字幕语言数: %d\n", len(result.Subtitles))
// 下载第一个语言的 SRT 格式字幕
if len(result.Subtitles) > 0 {
firstLang := result.Subtitles[0]
fmt.Printf("\n下载 %s 字幕...\n", firstLang.LanguageName)
// 找到 SRT 格式
var srtURL string
for _, urlInfo := range firstLang.URLs {
if urlInfo.Format == "srt" {
srtURL = urlInfo.URL
break
}
}
if srtURL != "" {
subtitleResp, _ := http.Get(srtURL)
defer subtitleResp.Body.Close()
subtitleData, _ := io.ReadAll(subtitleResp.Body)
filename := firstLang.LanguageTag + ".srt"
os.WriteFile(filename, subtitleData, 0644)
fmt.Printf("✅ 字幕已保存: %s\n", filename)
}
}
} else {
fmt.Printf("- 请求失败 (%d)\n", resp.StatusCode)
}
}💡 使用技巧
1. 批量下载所有语言的字幕
def download_all_subtitles(video_url, api_key, format='srt', output_dir='subtitles'):
import os
os.makedirs(output_dir, exist_ok=True)
# 获取字幕信息
response = requests.post(
"https://api.meowload.net/openapi/extract/subtitles",
json={"url": video_url},
headers={"x-api-key": api_key}
)
if response.status_code != 200:
print(f"❌ 获取失败: {response.json()['message']}")
return
data = response.json()
# 下载所有语言的指定格式字幕
for subtitle in data['subtitles']:
lang_tag = subtitle['language_tag']
lang_name = subtitle['language_name']
# 找到指定格式的URL
url_info = next(
(u for u in subtitle['urls'] if u['format'] == format),
None
)
if url_info:
subtitle_resp = requests.get(url_info['url'])
filename = f"{lang_tag}.{format}"
filepath = os.path.join(output_dir, filename)
with open(filepath, 'wb') as f:
f.write(subtitle_resp.content)
print(f"✅ 下载完成: {lang_name} ({filename})")
# 使用示例
download_all_subtitles(
"https://www.youtube.com/watch?v=bdLEBN6JKPY",
"your-api-key-here",
format='srt',
output_dir='my_subtitles'
)2. 检查是否有特定语言的字幕
def has_subtitle_language(subtitles, language_tag):
"""检查是否有特定语言的字幕"""
return any(s['language_tag'] == language_tag for s in subtitles)
# 使用示例
if has_subtitle_language(data['subtitles'], 'zh-CN'):
print("✅ 有中文字幕")
else:
print("❌ 没有中文字幕")3. 字幕格式说明
| 格式 | 全称 | 说明 | 推荐使用场景 |
|---|---|---|---|
srt | SubRip Text | 最常用的字幕格式 | 通用播放器 |
vtt | WebVTT | Web 视频字幕格式 | HTML5 视频播放器 |
ttml | TTML | XML 格式字幕 | 专业视频编辑 |
json3 | YouTube JSON | JSON 格式,包含元数据 | 程序化处理 |
srv1 | YouTube Server Format 1 | YouTube 服务器格式 1 | YouTube 内部使用 |
srv2 | YouTube Server Format 2 | YouTube 服务器格式 2 | YouTube 内部使用 |
srv3 | YouTube Server Format 3 | YouTube 服务器格式 3 | YouTube 内部使用 |
Tip
格式选择建议
- 通用下载:推荐使用
srt格式,兼容性最好 - Web 播放:推荐使用
vtt格式,HTML5 原生支持 - 专业编辑:推荐使用
ttml格式,功能最丰富 - 程序处理:推荐使用
json3格式,解析方便 - srv 系列:仅供特殊场景使用,一般用户无需关注