【问题标题】:Youtube-API: Upload binary captions file (ebu-stl)Youtube-API:上传二进制字幕文件 (ebu-stl)
【发布时间】:2014-10-02 21:30:24
【问题描述】:

Youtube 支持一些二进制字幕文件格式,such as ebu-stl.

我有一个 *.stl 文件,当我通过 Web 界面上传它时,它可以很好地上传和处理。但是,当我尝试使用 POST 请求通过 API v2 上传它时,它似乎无法正确识别文件格式。 The POST request looks like this:

POST /feeds/api/videos/VIDEO_ID/captions HTTP/1.1
Host: gdata.youtube.com
Content-Type: application/vnd.youtube.timedtext; charset=UTF-8
Content-Language: en
Slug: Title of caption track
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=DEVELOPER_KEY

<Caption File Data>

这是通过 API 上传的 *.stl 文件在网站上的外观。应该有几行带有可读文本的行。

当我上传具有相同代码的 utf8 纯文本字幕文件(例如 *.vtt)时,一切正常。此外,如果我通过 Web 界面和 API 上传 stl 文件一次,and retrieve both files through the API afterwards,它们是字节相同的。

在我看来这是一个编码问题 - youtube 正确接收文件,但可能会将整个二进制文件解析为 UTF-8。但是,当我省略 charset= 或 Content-Language 时,youtube 会响应 4xx 错误。

是否可以上传二进制字幕文件?如果不可能,我也将不胜感激。

Minimalistic stl file if you want to try it yourself (hex dump). 读作(红宝石):

stl = hex.chars.each_slice(2).map{|x|x.join.to_i(16)}.pack('C*')

【问题讨论】:

  • API V2 已弃用,请使用 API V3
  • 我知道,如果它支持字幕 apiblog.youtube.com/2014/03/… 除非他们最近添加了对字幕的支持,我会使用它?
  • 你说得对,我没有注意到这一点。

标签: youtube-api binaryfiles closed-captions


【解决方案1】:

API v2 现已正式弃用。截至 4 月 2 日,API v3 现在officially support captions。也支持二进制字幕文件。

文档缺少有关原始 HTTP 请求的一些详细信息。您可以尝试使用one of their libraries。

我使用了他们的 python 脚本并查看了它发出的请求。作为参考,这是上传二进制字幕/字幕文件的最小工作 HTTP 请求。

docs aren't mentioning这个参数,但是设置uploadType=multipart很重要,否则API返回错误。

POST /upload/youtube/v3/captions?uploadType=multipart&part=id,snippet&sync=false HTTP/1.1
Host: www.googleapis.com
Accept: */*
Authorization: Bearer {AUTH_TOKEN}
X-GData-Key: key={YOUR_KEY}
Content-Type: multipart/related; boundary================83250640405719953005==
Content-Length: 7147
Expect: 100-continue

--===============83250640405719953005==
Content-Type: application/json
MIME-Version: 1.0

{"snippet":{"videoId":"Agn_uesF248","language":"en","name":"Subtitle Test 2","isDraft":false}}
--===============83250640405719953005==
MIME-Version: 1.0
Content-Type: application/sla
Content-Transfer-Encoding: binary

{BINARY_CAPTION_FILE_DATA}
--===============83250640405719953005==--

application/sla 是 ebu-stl 字幕文件。对纯文本字幕(.srt、.vtt、.ass 等)使用 text/plain。

将{AUTH_TOKEN} 和{YOUR_KEY} 替换为the proper authorization credentials 用于范围https://www.googleapis.com/auth/youtube.force-ssl;和{BINARY_CAPTION_FILE_DATA} 与您要上传的文件。

【讨论】:

    猜你喜欢
    • 2016-02-21
    • 1970-01-01
    • 2021-12-18
    • 2015-09-24
    • 1970-01-01
    • 2013-05-12
    • 2011-07-21
    • 2021-09-18
    • 1970-01-01
    相关资源
    最近更新 更多