上傳字幕檔案
更新時間: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": ""
}
