保利威文档中心

帮助中心

上传字幕文件

更新时间:2025-01-14 15:55:11

接口描述

1、通过视频id上传视频字幕文件,该接口会自动检测字幕语言
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议

接口URL

http://api.polyv.net/v2/video/{userid}/srt/upload

请求方式

POST

接口约束

1、接口同时支持HTTP 、HTTPS ,建议使用HTTPS 确保接口安全,接口调用有频率限制,详细请查看

请求参数描述

参数名 必选 类型 说明
ptime true Long 当前时间的毫秒级时间戳,3分钟内有效
sign true String 签名,为40位大写的SHA1值,生成签名的secretkey密钥作为通信数据安全的关键信息,严禁保存在客户端直接使用,所有API都必须通过客户自己服务器中转调用POLYV服务器获取响应数据【详见签名生成规则
vid true String 视频id,例如:1b448be3235552e5fafb16489eb01839_1
title true String 字幕文件名称
file true File 字幕文件,支持utf-8编码
asDefault false String 是否作为默认字幕
Y:是
N:否
language false String 说明字幕文件是什么语言,默认自动检测,支持语言:中文、繁体中文 、英语、日语、韩语、法语、德语、俄语、西班牙语、阿拉伯语、葡萄牙语、其他

示例

http://api.polyv.net/v2/video/1b448be323/srt/upload

表单参数:

vid=1b448be323dec2a7bed6db61bd7d8a77_1&sign=F79D8A307847BD91FCEB3455F107A7246223763E&language=中文&title=测试上传字幕&ptime=1617263564197&asDefault=Y

字幕文件随HTTP二进制流上传至服务器端

响应参数描述

参数名 类型 说明
code Integer 响应状态码,200为成功返回,非200为失败【详见全局错误说明
status String 响应状态文本信息
message String 响应描述信息,当code为400或者500的时候,辅助描述错误原因

返回错误代码列表

错误代码 message 说明
400 sign can not be empty. 加密串为空
400 ptime is too old. 时间戳过期
400 ptime is illegal. 时间戳参数格式不对或者超过当前时间3分钟
400 Could not find user by userId. userId不存在
400 the sign is not right. 签名不正确
400 vid can't be empty 视频vid为空
400 file can't be empty 视频文件不能为空
400 title can't be empty 标题为空
400 language is not support 不支持的语言

Java请求示例

HttpUtil.java 和 VodSignUtil.java 基础代码请点击下载本地 或跳转到基础代码在线获取

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

}

响应示例

系统全局错误说明详见全局错误说明

成功示例

{
    "code": 200,
    "status": "success",
    "message": "success"
} 

异常示例

时间戳过期

{
  "code": 400,
  "status": "error",
  "message": "ptime is too old.",
  "data": ""
}

文件名称为空

{
    "code": 400,
    "status": "error",
    "message": "title can't be empty",
    "data": ""
}

文件为空

{
    "code": 400,
    "status": "error",
    "message": "file can't be empty",
    "data": ""
}

签名报错

{
    "code": 400,
    "status": "error",
    "message": "the sign is not right.",
    "data": ""
}
联系客服,在线咨询