Youtube-API:上传二进制字幕文件(ebu-stl) [英] Youtube-API: Upload binary captions file (ebu-stl)

查看:312
本文介绍了Youtube-API:上传二进制字幕文件(ebu-stl)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Youtube支持某些二进制字幕文件格式,例如 -stl.

Youtube supports some binary caption file formats, such as ebu-stl.

我有一个* .stl文件,当我通过Web界面上载该文件时,它可以进行上传和处理.但是,当我尝试通过带有POST请求的API v2上载它时,它似乎无法正确识别文件格式. POST请求看起来像这样:

I've got an *.stl file that uploads and processes just fine when I upload it via the web interface. But when I try to upload it via the API v2 with a POST request, it does not seem to recognize the file format properly. 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文件在网站上的外观.应该有几行带有可读文本.

This is how the *.stl file uploaded via the API looks on the website. There should be several lines with readable text.

当我使用相同的代码上传utf8纯文本字幕文件(例如* .vtt)时,一切正常.此外,如果我通过网络界面和API一次上传了stl文件,则之后通过API检索两个文件,它们都是字节相同的.

Everything works fine when I upload a utf8 plain text subtitle file (eg *.vtt) with the same code. Furthermore, if I upload the stl file once via the web interface and once via the API, and retrieve both files through the API afterwards, they are byte-identical.

对于我来说,似乎是编码问题,YouTube正确接收了该文件,但可能会将整个二进制文件解析为UTF-8.但是,当我忽略 charset = Content-Language 时,youtube会出现4xx错误.

It looks like an encoding issue to me- youtube receives the file correctly, but probably parses the entire binary file as UTF-8. However, youtube responds with a 4xx error when I ommit either charset= or Content-Language.

是否可以上传二进制字幕文件?如果无法确认,我也将不胜感激.

Is it possible to upload binary caption files? I would also appreciate confirmation in case it is not possible.

简约的stl文件,如果您想自己尝试(十六进制转储).读取为(红宝石) :

Minimalistic stl file if you want to try it yourself (hex dump). Read it as (ruby):

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

推荐答案

API v2现在已正式弃用.从4月2日开始,API v3现在正式支持字幕.也支持二进制字幕文件.

API v2 is now officially deprecated. As of April 2, the API v3 now officially support captions. Binary caption files are supported, too.

该文档缺少有关原始HTTP请求的一些详细信息.您可以尝试使用其中一个库.

The documentation is lacking some details as to the raw HTTP requests. You could try using one of their libraries.

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

I used their python script and took a look at the request it made. For reference, here's a minimal working HTTP request for uploading a binary subtitle/captions file.

文档未提及此参数,但设置为uploadType=multipart很重要,否则API会返回错误.

The docs aren't mentioning this parameter, but setting uploadType=multipart is important, the API returns an error otherwise.

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字幕文件.将text/plain用于纯文本字幕(.srt,.vtt,.ass和& c).

application/sla are ebu-stl caption files. Use text/plain for plain text subtitles (.srt, .vtt, .ass, &c.).

正确的授权凭据替换{AUTH_TOKEN}{YOUR_KEY}范围https://www.googleapis.com/auth/youtube.force-ssl; {BINARY_CAPTION_FILE_DATA}以及要上传的文件.

Replace {AUTH_TOKEN} and {YOUR_KEY} with the proper authorization credentials for the scope https://www.googleapis.com/auth/youtube.force-ssl; and {BINARY_CAPTION_FILE_DATA} with the file you wish to upload.

这篇关于Youtube-API:上传二进制字幕文件(ebu-stl)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆