全部产品
云市场

媒资管理

更新时间:2019-01-21 11:01:30

初始化客户端

使用前请先初始化客户端,参考 initVodClient 接口。

搜索媒资信息

接口参数和返回字段请参考 SearchMedia

  1. import com.aliyuncs.vod.model.v20170321.SearchMediaRequest;
  2. import com.aliyuncs.vod.model.v20170321.SearchMediaResponse;
  3. /**
  4. * 搜索媒资信息
  5. * @param client 发送请求客户端
  6. * @return SearchMediaResponse 搜索媒资信息响应数据
  7. * @throws Exception
  8. */
  9. public static SearchMediaResponse searchMedia(DefaultAcsClient client) throws Exception {
  10. SearchMediaRequest request = new SearchMediaRequest();
  11. request.setFields("Title,CoverURL,Status");
  12. request.setMatch("Status in ('Normal','Checking') and CreationTime = ('2018-07-01T08:00:00Z','2018-08-01T08:00:00Z')");
  13. request.setPageNo(1);
  14. request.setPageSize(10);
  15. request.setSearchType("video");
  16. request.setSortBy("CreationTime:Desc");
  17. return client.getAcsResponse(request);
  18. }
  19. // 请求示例
  20. public static void main(String[] argv) {
  21. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  22. SearchMediaResponse response = new SearchMediaResponse();
  23. try {
  24. response = searchMedia(client);
  25. if (response.getMediaList() != null && response.getMediaList().size() > 0) {
  26. System.out.print("Total = " + response.getTotal() + "\n");
  27. System.out.print("ScrollToken = " + response.getScrollToken() + "\n");
  28. for (SearchMediaResponse.Media media : response.getMediaList()) {
  29. System.out.print("MediaId = " + media.getMediaId() + "\n");
  30. System.out.print("MediaType = " + media.getMediaType() + "\n");
  31. System.out.print("CreationTime = " + media.getCreationTime() + "\n");
  32. System.out.print("Title = " + media.getVideo().getTitle() + "\n");
  33. System.out.print("CoverURL = " + media.getVideo().getCoverURL() + "\n");
  34. System.out.print("Status = " + media.getVideo().getStatus() + "\n");
  35. }
  36. }
  37. } catch (Exception e) {
  38. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  39. }
  40. System.out.print("RequestId = " + response.getRequestId() + "\n");
  41. }

获取视频信息

接口参数和返回字段请参考 GetVideoInfo

  1. import com.aliyuncs.vod.model.v20170321.GetVideoInfoRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetVideoInfoResponse;
  3. /**
  4. * 获取视频信息
  5. * @param client 发送请求客户端
  6. * @return GetVideoInfoResponse 获取视频信息响应数据
  7. * @throws Exception
  8. */
  9. public static GetVideoInfoResponse getVideoInfo(DefaultAcsClient client) throws Exception {
  10. GetVideoInfoRequest request = new GetVideoInfoRequest();
  11. request.setVideoId("VideoId");
  12. return client.getAcsResponse(request);
  13. }
  14. // 请求示例
  15. public static void main(String[] argv) {
  16. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  17. GetVideoInfoResponse response = new GetVideoInfoResponse();
  18. try {
  19. response = getVideoInfo(client);
  20. System.out.print("Title = " + response.getVideo().getTitle() + "\n");
  21. System.out.print("Description = " + response.getVideo().getDescription() + "\n");
  22. } catch (Exception e) {
  23. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  24. }
  25. System.out.print("RequestId = " + response.getRequestId() + "\n");
  26. }

批量获取视频信息

接口参数和返回字段请参考 GetVideoInfos

  1. import com.aliyuncs.vod.model.v20170321.GetVideoInfosRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetVideoInfosResponse;
  3. /**
  4. * 批量获取视频信息函数
  5. * @param client 发送请求客户端
  6. * @return GetVideoInfosResponse 获取视频信息响应数据
  7. * @throws Exception
  8. */
  9. public static GetVideoInfosResponse getVideoInfos(DefaultAcsClient client) throws Exception {
  10. GetVideoInfosRequest request = new GetVideoInfosRequest();
  11. request.setVideoIds("VideoId1,VideoId2");
  12. return client.getAcsResponse(request);
  13. }
  14. //请求示例
  15. public static void main(String[] argv) {
  16. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  17. GetVideoInfosResponse response = new GetVideoInfosResponse();
  18. try {
  19. response = getVideoInfos(client);
  20. if (response.getVideoList() != null && response.getVideoList().size() > 0) {
  21. System.out.print("===== exist video infos : ===== \n");
  22. for (GetVideoInfosResponse.Video video : response.getVideoList()) {
  23. System.out.print("VideoId = " + video.getVideoId() + "\n");
  24. System.out.print("Title = " + video.getTitle() + "\n");
  25. System.out.print("Description = " + video.getDescription() + "\n");
  26. System.out.print("Tags = " + video.getTags() + "\n");
  27. System.out.print("CreationTime = " + video.getCreationTime() + "\n");
  28. }
  29. }
  30. if (response.getNonExistVideoIds() != null && response.getNonExistVideoIds().size() > 0) {
  31. System.out.print("===== nonexistent videoIds : ===== \n");
  32. for (String videoId : response.getNonExistVideoIds()) {
  33. System.out.print(videoId + "\n");
  34. }
  35. }
  36. } catch (Exception e) {
  37. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  38. }
  39. System.out.print("RequestId = " + response.getRequestId() + "\n");
  40. }

修改视频信息

接口参数和返回字段请参考 UpdateVideoInfo

  1. import com.aliyuncs.vod.model.v20170321.UpdateVideoInfoRequest;
  2. import com.aliyuncs.vod.model.v20170321.UpdateVideoInfoResponse;
  3. /**
  4. * 修改视频信息
  5. * @param client 发送请求客户端
  6. * @return UpdateVideoInfoResponse 修改视频信息响应数据
  7. * @throws Exception
  8. */
  9. public static UpdateVideoInfoResponse updateVideoInfo(DefaultAcsClient client) throws Exception {
  10. UpdateVideoInfoRequest request = new UpdateVideoInfoRequest();
  11. request.setVideoId("VideoId");
  12. request.setTitle("new Title");
  13. request.setDescription("new Description");
  14. request.setTags("new Tag1,new Tag2");
  15. return client.getAcsResponse(request);
  16. }
  17. // 请求示例
  18. public static void main(String[] argv) {
  19. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. UpdateVideoInfoResponse response = new UpdateVideoInfoResponse();
  21. try {
  22. response = updateVideoInfo(client);
  23. } catch (Exception e) {
  24. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  25. }
  26. System.out.print("RequestId = " + response.getRequestId() + "\n");
  27. }

批量修改视频信息

接口参数和返回字段请参考 UpdateVideoInfos

  1. import com.aliyuncs.vod.model.v20170321.UpdateVideoInfosRequest;
  2. import com.aliyuncs.vod.model.v20170321.UpdateVideoInfosResponse;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. /**
  6. * 批量修改视频信息
  7. * @param client 发送请求客户端
  8. * @return UpdateVideoInfosResponse 批量修改视频信息响应数据
  9. * @throws Exception
  10. */
  11. public static UpdateVideoInfosResponse updateVideoInfos(DefaultAcsClient client) throws Exception {
  12. UpdateVideoInfosRequest request = new UpdateVideoInfosRequest();
  13. JSONArray updateContentArray = new JSONArray();
  14. JSONObject updateContent1 = new JSONObject();
  15. updateContent1.put("VideoId", "VideoId1");
  16. // updateContent1.put("Title", "new Title");
  17. // updateContent1.put("Tags", "new Tag1,new Tag2");
  18. updateContentArray.add((updateContent1));
  19. JSONObject updateContent2 = new JSONObject();
  20. updateContent2.put("VideoId", "VideoId2");
  21. // updateContent2.put("Title", "new Title");
  22. // updateContent2.put("Tags", "new Tag1,new Tag2");
  23. updateContentArray.add((updateContent2));
  24. request.setUpdateContent(updateContentArray.toJSONString());
  25. DefaultAcsClient client = init();
  26. return client.getAcsResponse(request);
  27. }
  28. // 请求示例
  29. public static void main(String[] argv) {
  30. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  31. UpdateVideoInfosResponse response = new UpdateVideoInfosResponse();
  32. try {
  33. response = updateVideoInfos(client);
  34. if (response.getNonExistVideoIds() != null && response.getNonExistVideoIds().size() > 0) {
  35. System.out.print("======nonexistent VideoIds : ======\n");
  36. for (String videoId : response.getNonExistVideoIds()) {
  37. System.out.print(videoId + "\n");
  38. }
  39. }
  40. } catch (Exception e) {
  41. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  42. }
  43. System.out.print("RequestId = " + response.getRequestId() + "\n");
  44. }

删除视频

接口参数和返回字段请参考 DeleteVideo

  1. import com.aliyuncs.vod.model.v20170321.DeleteVideoRequest;
  2. import com.aliyuncs.vod.model.v20170321.DeleteVideoResponse;
  3. /**
  4. * 删除视频
  5. * @param client 发送请求客户端
  6. * @return DeleteVideoResponse 删除视频响应数据
  7. * @throws Exception
  8. */
  9. public static DeleteVideoResponse deleteVideo(DefaultAcsClient client) throws Exception {
  10. DeleteVideoRequest request = new DeleteVideoRequest();
  11. //支持传入多个视频ID,多个用逗号分隔
  12. request.setVideoIds("VideoId1,VideoId2");
  13. return client.getAcsResponse(request);
  14. }
  15. /*请求示例*/
  16. public static void main(String[] argv) {
  17. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. DeleteVideoResponse response = new DeleteVideoResponse();
  19. try {
  20. response = deleteVideo(client);
  21. } catch (Exception e) {
  22. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  23. }
  24. System.out.print("RequestId = " + response.getRequestId() + "\n");
  25. }

获取源文件信息(含源片下载地址)

接口参数和返回字段请参考 GetMezzanineInfo

  1. import com.aliyuncs.vod.model.v20170321.GetMezzanineInfoRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetMezzanineInfoResponse;
  3. /**
  4. * 获取源文件信息
  5. * @param client 发送请求客户端
  6. * @return GetMezzanineInfoResponse 获取源文件信息响应数据
  7. * @throws Exception
  8. */
  9. public static GetMezzanineInfoResponse getMezzanineInfo(DefaultAcsClient client) throws Exception {
  10. GetMezzanineInfoRequest request = new GetMezzanineInfoRequest();
  11. request.setVideoId("VideoId");
  12. //源片下载地址过期时间
  13. request.setAuthTimeout(3600L);
  14. return client.getAcsResponse(request);
  15. }
  16. // 请求示例
  17. public static void main(String[] argv) {
  18. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. GetMezzanineInfoResponse response = new GetMezzanineInfoResponse();
  20. try {
  21. response = getMezzanineInfo(client);
  22. System.out.print("Mezzanine.VideoId = " + response.getMezzanine().getVideoId() + "\n");
  23. System.out.print("Mezzanine.FileURL = " + response.getMezzanine().getFileURL() + "\n");
  24. System.out.print("Mezzanine.Width = " + response.getMezzanine().getWidth() + "\n");
  25. System.out.print("Mezzanine.Height = " + response.getMezzanine().getWidth() + "\n");
  26. System.out.print("Mezzanine.Size = " + response.getMezzanine().getSize() + "\n");
  27. } catch (Exception e) {
  28. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  29. }
  30. System.out.print("RequestId = " + response.getRequestId() + "\n");
  31. }

获取视频列表

接口参数和返回字段请参考 GetVideoList

  1. import com.aliyuncs.vod.model.v20170321.GetVideoListRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetVideoListResponse;
  3. import java.text.DateFormat;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. // 根据Date时间生成UTC时间函数
  7. public static String generateUTCTime(Date time) {
  8. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  9. dateFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
  10. dateFormat.setLenient(false);
  11. return dateFormat.format(time);
  12. }
  13. /**
  14. * 获取视频列表
  15. * @param client 发送请求客户端
  16. * @return GetVideoListResponse 获取视频列表响应数据
  17. * @throws Exception
  18. */
  19. public static GetVideoListResponse getVideoList(DefaultAcsClient client) throws Exception {
  20. GetVideoListRequest request = new GetVideoListRequest();
  21. // 分别取一个月前、当前时间的UTC时间作为筛选视频列表的起止时间
  22. String monthAgoUTCTime = generateUTCTime(new Date(System.currentTimeMillis() - 30 * 86400L));
  23. String nowUTCTime = generateUTCTime(new Date(System.currentTimeMillis()));
  24. // 视频创建的起始时间,为UTC格式
  25. request.setStartTime(monthAgoUTCTime);
  26. // 视频创建的结束时间,为UTC格式
  27. request.setEndTime(nowUTCTime);
  28. // 视频状态,默认获取所有状态的视频,多个用逗号分隔
  29. // request.setStatus("Uploading,Normal,Transcoding");
  30. request.setPageNo(1L);
  31. request.setPageSize(20L);
  32. return client.getAcsResponse(request);
  33. }
  34. // 请求示例
  35. public static void main(String[] argv) {
  36. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  37. GetVideoListResponse response = new GetVideoListResponse();
  38. try {
  39. response = getVideoList(client);
  40. // 根据指定筛选条件查询到的视频总数
  41. System.out.print("Total = " + response.getTotal() + "\n");
  42. for (GetVideoListResponse.Video video : response.getVideoList()) {
  43. System.out.print("Title = " + video.getTitle() + "\n");
  44. System.out.print("Description = " + video.getDescription() + "\n");
  45. System.out.print("Tags = " + video.getTags() + "\n");
  46. System.out.print("CreationTime = " + video.getCreationTime() + "\n");
  47. }
  48. } catch (Exception e) {
  49. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  50. }
  51. System.out.print("RequestId = " + response.getRequestId() + "\n");
  52. }

删除媒体流

接口参数和返回字段请参考 DeleteStream

  1. import com.aliyuncs.vod.model.v20170321.DeleteStreamRequest;
  2. import com.aliyuncs.vod.model.v20170321.DeleteStreamResponse;
  3. /**
  4. * 删除媒体流函数
  5. * @param client 发送请求客户端
  6. * @return DeleteMezzaninesResponse 删除媒体流响应数据
  7. * @throws Exception
  8. */
  9. public static DeleteStreamResponse deleteStream(DefaultAcsClient client) throws Exception {
  10. DeleteStreamRequest request = new DeleteStreamRequest();
  11. request.setVideoId("VideoId");
  12. request.setJobIds("JobId1,JobId2");
  13. return client.getAcsResponse(request);
  14. }
  15. //请求示例
  16. public static void main(String[] argv) {
  17. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. DeleteStreamResponse response = new DeleteStreamResponse();
  19. try {
  20. response = deleteStream(client);
  21. } catch (Exception e) {
  22. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  23. }
  24. System.out.print("RequestId = " + response.getRequestId() + "\n");
  25. }

批量删除源文件

接口参数和返回字段请参考 DeleteMezzanines

  1. import com.aliyuncs.vod.model.v20170321.DeleteMezzaninesRequest;
  2. import com.aliyuncs.vod.model.v20170321.DeleteMezzaninesResponse;
  3. /**
  4. * 批量删除源文件函数
  5. * @param client 发送请求客户端
  6. * @return DeleteMezzaninesResponse 批量删除源文件响应数据
  7. * @throws Exception
  8. */
  9. public static DeleteMezzaninesResponse deleteMezzanines(DefaultAcsClient client) throws Exception {
  10. DeleteMezzaninesRequest request = new DeleteMezzaninesRequest();
  11. //支持传入多个视频ID,多个用逗号分隔
  12. request.setVideoIds("VideoId1,VideoId2");
  13. request.setForce(false);
  14. return client.getAcsResponse(request);
  15. }
  16. //请求示例
  17. public static void main(String[] argv) {
  18. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. DeleteMezzaninesResponse response = new DeleteMezzaninesResponse();
  20. try {
  21. response = deleteMezzanines(client);
  22. } catch (Exception e) {
  23. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  24. }
  25. System.out.print("RequestId = " + response.getRequestId() + "\n");
  26. }

批量更新图片信息

接口参数和返回字段请参考 UpdateImageInfos

  1. import com.aliyuncs.vod.model.v20170321.UpdateImageInfosRequest;
  2. import com.aliyuncs.vod.model.v20170321.UpdateImageInfosResponse;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. /**
  6. * 批量更新图片信息函数
  7. * @param client 发送请求客户端
  8. * @return UpdateImageInfosResponse 批量更新图片信息响应数据
  9. * @throws Exception
  10. */
  11. public static UpdateImageInfosResponse updateImageInfos(DefaultAcsClient client) throws Exception{
  12. UpdateImageInfosRequest request = new UpdateImageInfosRequest();
  13. JSONArray updateContentArray = new JSONArray();
  14. JSONObject updateContent1 = new JSONObject();
  15. updateContent1.put("ImageId", "ImageId1");
  16. // updateContent1.put("Title", "new Title");
  17. // updateContent1.put("Tags", "new Tag1,new Tag2");
  18. updateContentArray.add((updateContent1));
  19. JSONObject updateContent2 = new JSONObject();
  20. updateContent2.put("ImageId", "ImageId2");
  21. // updateContent2.put("Title", "new Title");
  22. // updateContent2.put("Tags", "new Tag1,new Tag2");
  23. updateContentArray.add((updateContent2));
  24. request.setUpdateContent(updateContentArray.toJSONString());
  25. return client.getAcsResponse(request);
  26. }
  27. // 请求示例
  28. public static void main(String[] argv) throws Exception {
  29. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  30. UpdateImageInfosResponse response = new UpdateImageInfosResponse();
  31. try {
  32. response = updateImageInfos(client);
  33. if (response.getNonExistImageIds() != null && response.getNonExistImageIds().size() > 0) {
  34. System.out.print("======nonexistent ImageIds : ======\n");
  35. for (String imageId : response.getNonExistImageIds()) {
  36. System.out.print(imageId + "\n");
  37. }
  38. }
  39. } catch (Exception e) {
  40. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  41. }
  42. System.out.print("RequestId = " + response.getRequestId() + "\n");
  43. }

获取图片信息

接口参数和返回字段请参考 GetImageInfo

  1. import com.aliyuncs.vod.model.v20170321.GetImageInfoRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetImageInfoResponse;
  3. /**
  4. * 获取图片信息函数
  5. *
  6. * @param client 发送请求客户端
  7. * @return GetImageInfoResponse 获取图片信息响应数据
  8. * @throws Exception
  9. */
  10. public static GetImageInfoResponse getImageInfo(DefaultAcsClient client) throws Exception {
  11. GetImageInfoRequest request = new GetImageInfoRequest();
  12. request.setImageId("ImageId");
  13. return client.getAcsResponse(request);
  14. }
  15. // 请求示例
  16. public static void main(String[] argv) throws ClientException {
  17. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. GetImageInfoResponse response = new GetImageInfoResponse();
  19. try {
  20. response = getImageInfo(client);
  21. System.out.print("ImageId=" + response.getImageInfo().getImageId());
  22. System.out.print("Title=" + response.getImageInfo().getTitle());
  23. System.out.print("CreationTime=" + response.getImageInfo().getCreationTime());
  24. System.out.print("FileURL=" + response.getImageInfo().getMezzanine().getFileURL());
  25. } catch (Exception e) {
  26. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  27. }
  28. System.out.print("RequestId = " + response.getRequestId() + "\n");
  29. }

删除图片

接口参数和返回字段请参考 DeleteImage

  1. import com.aliyuncs.vod.model.v20170321.DeleteImageRequest;
  2. import com.aliyuncs.vod.model.v20170321.DeleteImageResponse;
  3. /**
  4. * 删除图片函数
  5. *
  6. * @param client 发送请求客户端
  7. * @return DeleteImageResponse 删除图片响应数据
  8. * @throws Exception
  9. */
  10. public static DeleteImageResponse deleteImage(DefaultAcsClient client) throws Exception {
  11. DeleteImageRequest request = new DeleteImageRequest();
  12. //根据ImageURL删除图片文件
  13. request.setDeleteImageType("ImageURL");
  14. String url = "http://sample.aliyun.com/cover.jpg";
  15. String encodeUrl = URLEncoder.encode(url, "UTF-8");
  16. request.setImageURLs(encodeUrl);
  17. //根据ImageId删除图片文件
  18. //request.setDeleteImageType("ImageId");
  19. //request.setImageIds("ImageId1,ImageId2");
  20. //根据VideoId删除指定ImageType的图片文件
  21. //request.setDeleteImageType("VideoId");
  22. //request.setVideoId("VideoId");
  23. //request.setImageType("SpriteSnapshot");
  24. return client.getAcsResponse(request);
  25. }
  26. // 请求示例
  27. public static void main(String[] argv) throws ClientException {
  28. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  29. DeleteImageResponse response = new DeleteImageResponse();
  30. try {
  31. response = deleteImage(client);
  32. } catch (Exception e) {
  33. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  34. }
  35. System.out.print("RequestId = " + response.getRequestId() + "\n");
  36. }