Upload Subtitle File
Updated: 2025-01-14 15:55:11
API Description
1、通过视频id上传视频字幕文件,该接口会自动检测字幕语言
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
API URL
http://api.polyv.net/v2/video/{userid}/srt/upload
Request Method
POST
API Constraints
- The API supports both HTTP and HTTPS. HTTPS is recommended to ensure security. API calls have frequency limits. See details
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| ptime | true | Long | Current time in milliseconds, valid within 3 minutes |
| sign | true | String | Signature, a 40-character uppercase SHA1 value. The secretkey used to generate the signature is critical for communication data security. It must never be used directly on the client side. All APIs must be called through your own server to relay requests to the POLYV server and obtain response data. See signature generation rules |
| vid | true | String | Video ID, e.g., 1b448be3235552e5fafb16489eb01839_1 |
| title | true | String | Subtitle file name |
| file | true | File | Subtitle file, supports UTF-8 encoding |
| asDefault | false | String | Whether to set as default subtitle Y: Yes N: No |
| language | false | String | Language of the subtitle file. Default is auto-detect. Supported languages: Chinese, Traditional Chinese, English, Japanese, Korean, French, German, Russian, Spanish, Arabic, Portuguese, Other |
Example
http://api.polyv.net/v2/video/1b448be323/srt/upload
Form parameters:
vid=1b448be323dec2a7bed6db61bd7d8a77_1&sign=F79D8A307847BD91FCEB3455F107A7246223763E&language=中文&title=测试上传字幕&ptime=1617263564197&asDefault=Y
The subtitle file is uploaded to the server as an HTTP binary stream.
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Response status code. 200 indicates success, non-200 indicates failure. See global error description |
| status | String | Response status text |
| message | String | Response description. When code is 400 or 500, it provides additional error details. |
Error Code List
| Error Code | message | Description |
|---|---|---|
| 400 | sign can not be empty. | Signature is empty |
| 400 | ptime is too old. | Timestamp expired |
| 400 | ptime is illegal. | Invalid timestamp format or exceeds current time by 3 minutes |
| 400 | Could not find user by userId. | User ID does not exist |
| 400 | the sign is not right. | Incorrect signature |
| 400 | vid can't be empty | Video vid is empty |
| 400 | file can't be empty | Video file cannot be empty |
| 400 | title can't be empty | Title is empty |
| 400 | language is not support | Unsupported language |
Java Request Example
HttpUtil.java and VodSignUtil.java base code can be downloaded here or obtained online at Base Code
private static final Logger log = LoggerFactory.getLogger(VodVideoSubtitleTest.class);
/**
* 上传字幕文件
*/
@Test
public void testUploadSubtitle() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userid = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = String.format("http://api.polyv.net/v2/video/%s/srt/upload",userid);
String vid = "1b448be3230fa05b4d2d0003bf5a8ad0_1";
String title = "测试上传字幕";
String filePath = getClass().getResource("/file/").getPath() + "zimufile.srt";
File file = new File(filePath);
String asDefault = "Y";
String language = "英语";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("vid", vid);
Map<String,File> fileMap = new HashMap<>();
fileMap.put("file",file);
requestMap.put("title",title);
requestMap.put("asDefault",asDefault);
requestMap.put("language",language);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.postFile(url, requestMap,fileMap,Constant.UTF8);
log.debug("测试上传字幕,{}", response);
//do somethings
}
Response Example
For global error descriptions, see Global Error Description
Success Example
{
"code": 200,
"status": "success",
"message": "success"
}
Error Example
Timestamp Expired
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
File Name Empty
{
"code": 400,
"status": "error",
"message": "title can't be empty",
"data": ""
}
File Empty
{
"code": 400,
"status": "error",
"message": "file can't be empty",
"data": ""
}
Signature Error
{
"code": 400,
"status": "error",
"message": "the sign is not right.",
"data": ""
}
