Search in sources :

Example 21 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method modifyCover.

/**
 * {@inheritDoc}
 */
@Override
public String modifyCover(String fileId, String base64Data) throws CloudSDKException {
    try {
        ModifyMediaInfoRequest req = new ModifyMediaInfoRequest();
        req.setCoverData(base64Data);
        req.setFileId(fileId);
        ModifyMediaInfoResponse resp = vodClient.ModifyMediaInfo(req);
        if (StringUtils.isBlank(resp.getCoverUrl())) {
            throw new CloudSDKException("Modify cover failed, response: " + ModifyMediaInfoResponse.toJsonString(resp));
        }
        return resp.getCoverUrl();
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getErrorCode(), e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ModifyMediaInfoRequest(com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoRequest) ModifyMediaInfoResponse(com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoResponse)

Example 22 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method confirmEvents.

/**
 * {@inheritDoc}
 */
@Override
public void confirmEvents(String[] eventIds) throws CloudSDKException {
    try {
        ConfirmEventsRequest req = new ConfirmEventsRequest();
        req.setEventHandles(eventIds);
        vodClient.ConfirmEvents(req);
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getErrorCode(), e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ConfirmEventsRequest(com.tencentcloudapi.vod.v20180717.models.ConfirmEventsRequest)

Example 23 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method snapshotCover.

/**
 * {@inheritDoc}
 */
@Override
public String snapshotCover(String fileId, long screenshotTmplId, float timePosition) throws CloudSDKException {
    try {
        ProcessMediaRequest req = new ProcessMediaRequest();
        MediaProcessTaskInput mediaProcessTaskInput = new MediaProcessTaskInput();
        CoverBySnapshotTaskInput[] coverBySnapshotTaskInputs = new CoverBySnapshotTaskInput[1];
        CoverBySnapshotTaskInput coverBySnapshotTaskInput = new CoverBySnapshotTaskInput();
        coverBySnapshotTaskInput.setDefinition(screenshotTmplId);
        coverBySnapshotTaskInput.setPositionType("Time");
        coverBySnapshotTaskInput.setPositionValue(timePosition);
        coverBySnapshotTaskInputs[0] = coverBySnapshotTaskInput;
        mediaProcessTaskInput.setCoverBySnapshotTaskSet(coverBySnapshotTaskInputs);
        req.setMediaProcessTask(mediaProcessTaskInput);
        req.setFileId(fileId);
        ProcessMediaResponse resp = vodClient.ProcessMedia(req);
        if (StringUtils.isBlank(resp.getTaskId())) {
            throw new CloudSDKException("Snapshot cover failed, response: " + ProcessMediaResponse.toJsonString(resp));
        }
        return resp.getTaskId();
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getErrorCode(), e.getMessage(), e);
    }
}
Also used : ProcessMediaResponse(com.tencentcloudapi.vod.v20180717.models.ProcessMediaResponse) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ProcessMediaRequest(com.tencentcloudapi.vod.v20180717.models.ProcessMediaRequest) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) MediaProcessTaskInput(com.tencentcloudapi.vod.v20180717.models.MediaProcessTaskInput) CoverBySnapshotTaskInput(com.tencentcloudapi.vod.v20180717.models.CoverBySnapshotTaskInput)

Example 24 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method uploadVideo.

/**
 * {@inheritDoc}
 */
@Override
public String uploadVideo(File mediaFile, File coverFile) throws CloudSDKException {
    MediaTypeEnum mediaType = getMediaType(mediaFile);
    CoverTypeEnum coverType = getCoverType(coverFile);
    COSObjectStorageServiceImpl objectStorageService = null;
    String bucket = null;
    String coverObjectName = null;
    String mediaObjectName = null;
    try {
        ApplyUploadRequest req = new ApplyUploadRequest();
        req.setMediaType(mediaType.getValue());
        req.setCoverType(coverType.getValue());
        ApplyUploadResponse applyResponse = vodClient.ApplyUpload(req);
        COSProfile config = new COSProfile();
        config.setAccessKey(applyResponse.getTempCertificate().getSecretId());
        config.setSecretKey(applyResponse.getTempCertificate().getSecretKey());
        config.setSessionToken(applyResponse.getTempCertificate().getToken());
        config.setRegion(applyResponse.getStorageRegion());
        objectStorageService = new COSObjectStorageServiceImpl();
        objectStorageService.init(config);
        bucket = applyResponse.getStorageBucket();
        objectStorageService.putObject(bucket, applyResponse.getCoverStoragePath(), coverFile);
        coverObjectName = applyResponse.getCoverStoragePath();
        objectStorageService.putObject(bucket, applyResponse.getMediaStoragePath(), mediaFile);
        mediaObjectName = applyResponse.getMediaStoragePath();
        CommitUploadRequest commitRequest = new CommitUploadRequest();
        commitRequest.setVodSessionKey(applyResponse.getVodSessionKey());
        CommitUploadResponse commitResponse = vodClient.CommitUpload(commitRequest);
        // 上传成功后要置为NULL
        coverObjectName = null;
        mediaObjectName = null;
        return commitResponse.getFileId();
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getErrorCode(), e.getMessage(), e);
    } finally {
        cleanUploadFailedFile(bucket, coverObjectName, objectStorageService);
        cleanUploadFailedFile(bucket, mediaObjectName, objectStorageService);
        if (null != objectStorageService) {
            objectStorageService.destory();
        }
    }
}
Also used : CoverTypeEnum(com.mizhousoft.tencent.vod.constants.CoverTypeEnum) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CommitUploadResponse(com.tencentcloudapi.vod.v20180717.models.CommitUploadResponse) ApplyUploadResponse(com.tencentcloudapi.vod.v20180717.models.ApplyUploadResponse) MediaTypeEnum(com.mizhousoft.tencent.vod.constants.MediaTypeEnum) ApplyUploadRequest(com.tencentcloudapi.vod.v20180717.models.ApplyUploadRequest) CommitUploadRequest(com.tencentcloudapi.vod.v20180717.models.CommitUploadRequest) COSProfile(com.mizhousoft.tencent.oss.COSProfile) COSObjectStorageServiceImpl(com.mizhousoft.tencent.oss.COSObjectStorageServiceImpl)

Example 25 with CloudSDKException

use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method getVideoMeta.

/**
 * {@inheritDoc}
 */
@Override
public MediaMeta getVideoMeta(String fileId) throws CloudSDKException {
    try {
        String[] fileIds = { fileId };
        DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
        req.setFileIds(fileIds);
        DescribeMediaInfosResponse resp = vodClient.DescribeMediaInfos(req);
        MediaInfo[] mediaInfos = resp.getMediaInfoSet();
        if (null != mediaInfos && 1 == mediaInfos.length) {
            MediaInfo mediaInfo = mediaInfos[0];
            MediaMeta meta = buildMediaMeta(fileId, mediaInfo.getBasicInfo(), mediaInfo.getMetaData(), mediaInfo.getTranscodeInfo());
            return meta;
        } else {
            return null;
        }
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getErrorCode(), e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) MediaInfo(com.tencentcloudapi.vod.v20180717.models.MediaInfo) MediaMeta(com.mizhousoft.cloudsdk.vod.MediaMeta) DescribeMediaInfosRequest(com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosRequest) DescribeMediaInfosResponse(com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosResponse)

Aggregations

CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)44 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)14 Test (org.junit.Test)13 URL (java.net.URL)8 ObjectMetadata (com.mizhousoft.cloudsdk.oss.ObjectMetadata)6 File (java.io.File)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 RecognitionResult (com.mizhousoft.cloudsdk.nlp.RecognitionResult)3 Date (java.util.Date)3 GeneratePresignedUrlRequest (com.aliyun.oss.model.GeneratePresignedUrlRequest)2 TempCredential (com.mizhousoft.cloudsdk.TempCredential)2 OSSTempCredential (com.mizhousoft.cloudsdk.oss.OSSTempCredential)2 MediaMeta (com.mizhousoft.cloudsdk.vod.MediaMeta)2 CoverTypeEnum (com.mizhousoft.tencent.vod.constants.CoverTypeEnum)2 MediaTypeEnum (com.mizhousoft.tencent.vod.constants.MediaTypeEnum)2 GeneratePresignedUrlRequest (com.qcloud.cos.model.GeneratePresignedUrlRequest)2 VinOCRRequest (com.tencentcloudapi.ocr.v20181119.models.VinOCRRequest)2 VinOCRResponse (com.tencentcloudapi.ocr.v20181119.models.VinOCRResponse)2 CoverBySnapshotTaskInput (com.tencentcloudapi.vod.v20180717.models.CoverBySnapshotTaskInput)2