screenshotService
1. Add a Screenshot Task at a Specified Time Point
Description
通过视频id、截图等相关参数添加视频指定时间点截图任务
接口地址(仅做说明使用):https://api.polyv.net/v2/video/snapshot/%s/addTask
Call Constraints
The API call has a frequency limit. Click here for details. For common exceptions, click here.
This API is used to add a screenshot task at a specified time point. Each task allows up to 20 screenshots.
Screenshot operations are not allowed for videos that are banned from playback.
If a
callbackUrlis set, for example, http://example.polyv.net/snapshot-callback.do, after the screenshot task is completed, Polyv will call back to this URL with signature information. Developers can use the signature to verify whether the call is a legitimate Polyv call. The specific signature rule is: md5("snapshot" + vid + secretKey).For example, if vid="e6b23c6f51350f106556806a576b1942_e" and secretKey="testKey", then sign="3adb60893894d422d00ed2efae8c41f3" (lowercase md5). The final callback URL is http://example.polyv.net/snapshot-callback.do?sign=3adb60893894d422d00ed2efae8c41f3.
Unit Test
@Test
public void testCreateScreenshotTask() throws IOException, NoSuchAlgorithmException {
VodCreateScreenshotTaskRequest vodCreateScreenshotTaskRequest = new VodCreateScreenshotTaskRequest();
Integer vodCreateScreenshotTaskResponse = null;
try {
vodCreateScreenshotTaskRequest.setUploadTime(new Date())
.setVideoId(super.getTestVideoId())
.setOffsetTimes("8");
vodCreateScreenshotTaskResponse = new VodScreenshotServiceImpl().createScreenshotTask(
vodCreateScreenshotTaskRequest);
Assert.assertNotNull(vodCreateScreenshotTaskResponse);
if (vodCreateScreenshotTaskResponse != null) {
log.debug("测试添加指定时间点截图任务成功,{}", vodCreateScreenshotTaskResponse);
}
} catch (PloyvSdkException e) {
//参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
log.error(e.getMessage(), e);
// 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
throw e;
} catch (Exception e) {
log.error("SDK调用异常", e);
throw e;
}
}
Unit Test Description
If the request is correct, an Integer object is returned, and the B-side processes business logic based on this object.
If the request parameter validation fails, a PloyvSdkException is thrown. The error message can be found in PloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ].
If the server encounters an error during processing, a PloyvSdkException is thrown. The error message can be found in PloyvSdkException.getMessage(), e.g., [ Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]
Request Parameter Description
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| uploadTime | true | Date | Upload time, format: yyyy-MM-dd HH:mm:ss [Corresponds to the ptime field in the API documentation] |
| videoId | true | String | Video ID [Corresponds to the vid field in the API documentation] |
| offsetTimes | true | String | Screenshot time points, multiple time points separated by commas, unit: seconds |
| width | false | Integer | Screenshot width, defaults to the original video width |
| height | false | Integer | Screenshot height, defaults to the original video height |
| callbackUrl | false | String | Callback URL after screenshot completion. After the task is completed, the result information and signature will be POSTed to this URL. If the URL returns an HTTP status code of 200, the callback is considered successful. For example, http://example.polyv.net/snapshot-callback.do |
Return Object Description
Returns the screenshot task ID upon successful addition.
2. Query Screenshot Task Status
Description
通过截图任务id查询截图任务状态
接口地址(仅做说明使用):https://api.polyv.net/v2/video/snapshot/%s/getTaskStatus
Call Constraints
- The API call has a frequency limit. Click here for details. For common exceptions, click here.
Unit Test
@Test
public void testGetScreenshotTaskStatus() throws IOException, NoSuchAlgorithmException {
VodGetScreenshotTaskStatusRequest vodGetScreenshotTaskStatusRequest = new VodGetScreenshotTaskStatusRequest();
VodGetScreenshotTaskStatusResponse vodGetScreenshotTaskStatusResponse = null;
try {
vodGetScreenshotTaskStatusRequest.setTaskId(1146);
vodGetScreenshotTaskStatusResponse = new VodScreenshotServiceImpl().getScreenshotTaskStatus(
vodGetScreenshotTaskStatusRequest);
Assert.assertNotNull(vodGetScreenshotTaskStatusResponse);
if (vodGetScreenshotTaskStatusResponse != null) {
log.debug("测试查询截图任务状态成功,{}", JSON.toJSONString(vodGetScreenshotTaskStatusResponse));
}
} catch (PloyvSdkException e) {
//参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
log.error(e.getMessage(), e);
// 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
throw e;
} catch (Exception e) {
log.error("SDK调用异常", e);
throw e;
}
}
Unit Test Description
If the request is correct, a VodGetScreenshotTaskStatusResponse object is returned, and the B-side processes business logic based on this object.
If the request parameter validation fails, a PloyvSdkException is thrown. The error message can be found in PloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ].
If the server encounters an error during processing, a PloyvSdkException is thrown. The error message can be found in PloyvSdkException.getMessage(), e.g., [ Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]
Request Parameter Description
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| taskId | true | Integer | Task ID |
Return Object Description
| Parameter Name | Type | Description |
|---|---|---|
| taskId | Integer | Task ID |
| vid | String | Video vid |
| status | String | Task status: waiting - waiting for screenshot, processing - screenshot processing, success - task successful, fail - task failed |
| createTime | Date | Task creation time, format: yyyy-MM-dd HH:mm:ss |
| beginProcessTime | Date | Screenshot start time, format: yyyy-MM-dd HH:mm:ss |
| finishProcessTime | Date | Screenshot completion time, format: yyyy-MM-dd HH:mm:ss |
| screenshots | Array | Screenshot information array, empty if failed or not started [Corresponds to the snapshots field in the API documentation] [See Screenshot Parameter Description] |
Screenshot Parameter Description
| Parameter Name | Type | Description |
|---|---|---|
| offsetTime | Integer | Screenshot time point, unit: seconds |
| imageUrl | String | Screenshot access URL |
