全部产品
云市场

媒资管理

更新时间:2018-12-27 18:17:08

初始化客户端

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

搜索媒资信息

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

  1. **
  2. * 搜索媒资信息
  3. * @param client 发送请求客户端
  4. * @return SearchMediaResponse 搜索媒资信息响应数据
  5. */
  6. function searchMedia($client) {
  7. $request = new vod\SearchMediaRequest();
  8. $request->setFields("Title,CoverURL,Status");
  9. $request->setMatch("Status in ('Normal','Checking') and CreationTime = ('2018-07-01T08:00:00Z','2018-08-01T08:00:00Z')");
  10. $request->setPageNo(1);
  11. $request->setPageSize(10);
  12. $request->setSearchType("video");
  13. $request->setSortBy("CreationTime:Desc");
  14. return $client->getAcsResponse($request);
  15. }
  16. try {
  17. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  18. $result = searchMedia($client);
  19. var_dump($result);
  20. } catch (Exception $e) {
  21. print $e->getMessage()."\n";
  22. }

获取视频信息

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

  1. /**
  2. * 获取视频信息
  3. * @param client 发送请求客户端
  4. * @return GetVideoInfoResponse 获取视频信息响应数据
  5. */
  6. function getVideoInfo($client, $videoId) {
  7. $request = new vod\GetVideoInfoRequest();
  8. $request->setVideoId($videoId);
  9. $request->setAcceptFormat('JSON');
  10. return $client->getAcsResponse($request);
  11. }
  12. try {
  13. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  14. $videoInfo = getVideoInfo($client, '您的videoId');
  15. var_dump($videoInfo);
  16. } catch (Exception $e) {
  17. print $e->getMessage()."\n";
  18. }

批量获取视频信息

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

  1. /**
  2. * 批量获取视频信息函数
  3. * @param client 发送请求客户端
  4. * @return GetVideoInfosResponse 获取视频信息响应数据
  5. */
  6. function getVideoInfos($client) {
  7. $request = new vod\GetVideoInfosRequest();
  8. $request->setVideoIds("e67e761ec04342cd9ca5149c74xxxxxx,b19439abb9a94374b7f4d45f69xxxxxx");
  9. return $client->getAcsResponse($request);
  10. }
  11. try {
  12. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  13. $result = getVideoInfos($client);
  14. var_dump($result);
  15. } catch (Exception $e) {
  16. print $e->getMessage()."\n";
  17. }

修改视频信息

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

  1. /**
  2. * 修改视频信息
  3. * @param client 发送请求客户端
  4. * @return UpdateVideoInfoResponse 修改视频信息响应数据
  5. */
  6. function updateVideoInfo($client, $videoId) {
  7. $request = new vod\UpdateVideoInfoRequest();
  8. $request->setVideoId($videoId);
  9. $request->setTitle('New Title'); // 更改视频标题
  10. $request->setDescription('New Description'); // 更改视频描述
  11. $request->setCoverURL('http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png'); // 更改视频封面
  12. $request->setTags('tag1,tag2'); // 更改视频标签,多个用逗号分隔
  13. $request->setCateId(0); // 更改视频分类(可在点播控制台·全局设置·分类管理里查看分类ID:https://vod.console.aliyun.com/#/vod/settings/category)
  14. $request->setAcceptFormat('JSON');
  15. return $client->getAcsResponse($request);
  16. }
  17. try {
  18. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  19. $videoInfo = updateVideoInfo($client, '您的videoId');
  20. var_dump($videoInfo);
  21. } catch (Exception $e) {
  22. print $e->getMessage()."\n";
  23. }

批量修改视频信息

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

  1. /**
  2. * 批量修改视频信息
  3. * @param client 发送请求客户端
  4. * @return UpdateVideoInfosResponse 批量修改视频信息响应数据
  5. */
  6. function updateVideoInfos($client) {
  7. $request = new vod\UpdateVideoInfosRequest();
  8. $updateContentArray = array();
  9. $updateContent1 = array();
  10. $updateContent1["VideoId"] = "e67e761ec04342cd9ca5149c74xxxxxx";
  11. $updateContent1["Title"] = "new Title1";
  12. $updateContentArray[] = $updateContent1;
  13. $updateContent2 = array();
  14. $updateContent2["VideoId"] = "b19439abb9a94374b7f4d45f69xxxxxx";
  15. $updateContent2["Title"] = "new Title2";
  16. $updateContentArray[] = $updateContent2;
  17. $request->setUpdateContent(json_encode($updateContentArray));
  18. return $client->getAcsResponse($request);
  19. }
  20. try {
  21. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  22. $result = updateVideoInfos($client);
  23. var_dump($result);
  24. } catch (Exception $e) {
  25. print $e->getMessage()."\n";
  26. }

删除视频

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

  1. /**
  2. * 删除视频
  3. * @param client 发送请求客户端
  4. * @return DeleteVideoResponse 删除视频响应数据
  5. */
  6. function deleteVideos($client, $videoIds) {
  7. $request = new vod\DeleteVideoRequest();
  8. $request->setVideoIds($videoIds); // 支持批量删除视频;videoIds为传入的视频ID列表,多个用逗号分隔
  9. $request->setAcceptFormat('JSON');
  10. return $client->getAcsResponse($request);
  11. }
  12. try {
  13. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  14. $delInfo = deleteVideos($client, 'vid1,vid2');
  15. var_dump($delInfo);
  16. } catch (Exception $e) {
  17. print $e->getMessage()."\n";
  18. }

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

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

  1. /**
  2. * 获取源文件信息
  3. * @param client 发送请求客户端
  4. * @return GetMezzanineInfoResponse 获取源文件信息响应数据
  5. */
  6. function getMezzanineInfo($client, $videoId) {
  7. $request = new vod\GetMezzanineInfoRequest();
  8. $request->setVideoId($videoId);
  9. $request->setAuthTimeout(3600*5); // 原片下载地址过期时间,单位:秒,默认为3600秒
  10. $request->setAcceptFormat('JSON');
  11. return $client->getAcsResponse($request);
  12. }
  13. try {
  14. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  15. $mezzanine = getMezzanineInfo($client, '您的videoId');
  16. var_dump($mezzanine);
  17. } catch (Exception $e) {
  18. print $e->getMessage()."\n";
  19. }

获取视频列表

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

  1. /**
  2. * 获取视频列表
  3. * @param client 发送请求客户端
  4. * @return GetVideoListResponse 获取视频列表响应数据
  5. */
  6. function getVideoList($client) {
  7. $request = new vod\GetVideoListRequest();
  8. // 示例:分别取一个月前、当前时间的UTC时间作为筛选视频列表的起止时间
  9. $localTimeZone = date_default_timezone_get();
  10. date_default_timezone_set('UTC');
  11. $utcNow = gmdate('Y-m-d\TH:i:s\Z');
  12. $utcMonthAgo = gmdate('Y-m-d\TH:i:s\Z', time() - 30*86400);
  13. date_default_timezone_set($localTimeZone);
  14. $request->setStartTime($utcMonthAgo); // 视频创建的起始时间,为UTC格式
  15. $request->setEndTime($utcNow); // 视频创建的结束时间,为UTC格式
  16. #$request->setStatus('Uploading,Normal,Transcoding'); // 视频状态,默认获取所有状态的视频,多个用逗号分隔
  17. #$request->setCateId(0); // 按分类进行筛选
  18. $request->setPageNo(1);
  19. $request->setPageSize(20);
  20. $request->setAcceptFormat('JSON');
  21. return $client->getAcsResponse($request);
  22. }
  23. try {
  24. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  25. $videoList = getVideoList($client);
  26. var_dump($videoList);
  27. } catch (Exception $e) {
  28. print $e->getMessage()."\n";
  29. }

删除媒体流

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

  1. /**
  2. * 删除媒体流函数
  3. * @param client 发送请求客户端
  4. * @return DeleteMezzaninesResponse 删除媒体流响应数据
  5. */
  6. function deleteStream($client, $videoId, $jobIds) {
  7. $request = new vod\DeleteStreamRequest();
  8. $request->setVideoId($videoId);
  9. $request->setJobIds($jobIds); // 媒体流转码的作业ID列表,多个用逗号分隔;JobId可通过获取播放地址接口(GetPlayInfo)获取到。
  10. $request->setAcceptFormat('JSON');
  11. return $client->getAcsResponse($request);
  12. }
  13. try {
  14. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  15. $delStream = deleteStream($client, 'videoId', 'jobId1,jobId2');
  16. var_dump($delStream);
  17. } catch (Exception $e) {
  18. print $e->getMessage()."\n";
  19. }

批量删除源文件

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

  1. /**
  2. * 批量删除源文件函数
  3. * @param client 发送请求客户端
  4. * @return DeleteMezzaninesResponse 批量删除源文件响应数据
  5. */
  6. function deleteMezzanines($client) {
  7. $request = new vod\DeleteMezzaninesRequest();
  8. $request->setVideoIds("b19439abb9a94374b7f4d45f6xxxxxx");
  9. $request->setForce(false);
  10. return $client->getAcsResponse($request);
  11. }
  12. try {
  13. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  14. $result = deleteMezzanines($client);
  15. var_dump($result);
  16. } catch (Exception $e) {
  17. print $e->getMessage()."\n";
  18. }

批量更新图片信息

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

  1. /**
  2. * 批量更新图片信息函数
  3. * @param client 发送请求客户端
  4. * @return UpdateImageInfosResponse 批量更新图片信息响应数据
  5. */
  6. function updateImageInfos($client) {
  7. $request = new vod\UpdateImageInfosRequest();
  8. $updateContentArray = array();
  9. $updateContent1 = array();
  10. $updateContent1["ImageId"] = "7e66f99e1cb34199822753981xxxxxx";
  11. $updateContent1["Title"] = "new Title1";
  12. $updateContentArray[] = $updateContent1;
  13. $updateContent2 = array();
  14. $updateContent2["ImageId"] = "d2171a5656454c49a4f11a544cxxxxx";
  15. $updateContent2["Title"] = "new Title2";
  16. $updateContentArray[] = $updateContent2;
  17. $request->setUpdateContent(json_encode($updateContentArray));
  18. return $client->getAcsResponse($request);
  19. }
  20. try {
  21. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  22. $result = updateImageInfos($client);
  23. var_dump($result);
  24. } catch (Exception $e) {
  25. print $e->getMessage()."\n";
  26. }

获取图片信息

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

  1. /**
  2. * 获取图片信息函数
  3. * @param client 发送请求客户端
  4. * @return GetImageInfoResponse 获取图片信息响应数据
  5. */
  6. function getImageInfo($client) {
  7. $request = new vod\GetImageInfoRequest();
  8. $request->setImageId("7e66f99e1cb341998227539812b4f502");
  9. return $client->getAcsResponse($request);
  10. }
  11. try {
  12. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  13. $result = getImageInfo($client);
  14. var_dump($result);
  15. } catch (Exception $e) {
  16. print $e->getMessage()."\n";
  17. }

删除图片

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

  1. /**
  2. * 删除图片函数
  3. * @param client 发送请求客户端
  4. * @return DeleteImageResponse 删除图片响应数据
  5. */
  6. function deleteImage($client) {
  7. $request = new vod\DeleteImageRequest();
  8. //根据ImageURL删除图片文件
  9. $request->setDeleteImageType("ImageURL");
  10. $request->setImageURLs("http://sample.aliyun.com/cover.jpg");
  11. //根据ImageId删除图片文件
  12. //$request->setDeleteImageType("ImageId");
  13. //$request->setImageIds("ImageId1,ImageId2");
  14. //根据VideoId删除指定ImageType的图片文件
  15. //$request->setDeleteImageType("VideoId");
  16. //$request->setVideoId("VideoId");
  17. return $client->getAcsResponse($request);
  18. }
  19. try {
  20. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  21. $result = deleteImage($client);
  22. var_dump($result);
  23. } catch (Exception $e) {
  24. print $e->getMessage()."\n";
  25. }