Youtube-API: Upload binary captions file (ebu-stl)

耗尽温柔 提交于 2019-12-01 23:34:00
blutorange

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

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

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.

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 are ebu-stl caption files. Use text/plain for plain text subtitles (.srt, .vtt, .ass, &c.).

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!