全部产品
云市场

媒资管理

更新时间:2018-12-30 17:24:45

初始化客户端

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

搜索媒资信息

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

  1. from aliyunsdkvod.request.v20170321 import SearchMediaRequest
  2. def search_media(clt):
  3. request = SearchMediaRequest.SearchMediaRequest()
  4. request.set_Fields('Title,CoverURL,Status');
  5. request.set_Match('Status in ("Normal","Checking") and CreationTime = ("2018-10-01T08:00:00Z","2018-12-25T08:00:00Z")')
  6. request.set_PageNo(1)
  7. request.set_PageSize(10)
  8. request.set_SearchType('video')
  9. request.set_SortBy('CreationTime:Desc')
  10. request.set_accept_format('JSON')
  11. response = json.loads(clt.do_action_with_exception(request))
  12. return response
  13. try:
  14. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  15. medias = search_media(clt)
  16. print(medias['MediaList'])
  17. print(json.dumps(medias, ensure_ascii=False, indent=4))
  18. except Exception as e:
  19. print(e)
  20. print(traceback.format_exc())

获取视频信息

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

  1. from aliyunsdkvod.request.v20170321 import GetVideoInfoRequest
  2. def get_video_info(clt, videoId):
  3. request = GetVideoInfoRequest.GetVideoInfoRequest()
  4. request.set_accept_format('JSON')
  5. request.set_VideoId(videoId)
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. videoInfo = get_video_info(clt, '<videoId>')
  11. print(json.dumps(videoInfo, ensure_ascii=False, indent=4))
  12. except Exception as e:
  13. print(e)
  14. print(traceback.format_exc())

批量获取视频信息

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

  1. from aliyunsdkvod.request.v20170321 import GetVideoInfosRequest
  2. def get_video_infos(clt):
  3. request = GetVideoInfosRequest.GetVideoInfosRequest()
  4. videoIds = ['videoId1', 'videoId2']
  5. request.set_VideoIds(','.join(videoIds))
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. videos = get_video_infos(clt)
  12. #print(videos['VideoList'])
  13. print(videos['NonExistVideoIds'])
  14. print(json.dumps(videos, ensure_ascii=False, indent=4))
  15. except Exception as e:
  16. print(e)
  17. print(traceback.format_exc())

修改视频信息

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

  1. from aliyunsdkvod.request.v20170321 import UpdateVideoInfoRequest
  2. def update_video_info(clt, videoId):
  3. request = UpdateVideoInfoRequest.UpdateVideoInfoRequest()
  4. request.set_VideoId(videoId)
  5. request.set_Title('New Title')
  6. request.set_Description('New Description')
  7. request.set_CoverURL('http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png')
  8. request.set_Tags('tag1,tag2')
  9. #request.set_CateId(0)
  10. request.set_accept_format('JSON')
  11. response = json.loads(clt.do_action_with_exception(request))
  12. return response
  13. try:
  14. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  15. updateInfo = update_video_info(clt, '<videoId>')
  16. print(json.dumps(updateInfo, ensure_ascii=False, indent=4))
  17. except Exception as e:
  18. print(e)
  19. print(traceback.format_exc())

批量修改视频信息

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

  1. from aliyunsdkvod.request.v20170321 import UpdateVideoInfosRequest
  2. def update_video_infos(clt):
  3. request = UpdateVideoInfosRequest.UpdateVideoInfosRequest()
  4. updateContent = []
  5. updateItem1 = {'VideoId': '<VideoId1>', 'Title': 'New Sample Title1', 'Tags': 'NewTag1,NewTag2'}
  6. updateItem2 = {'VideoId': '<VideoId2>', 'Title': 'New Sample Title2', 'Tags': 'NewTag3,NewTag4'}
  7. updateContent.append(updateItem1)
  8. updateContent.append(updateItem2)
  9. request.set_UpdateContent(json.dumps(updateContent))
  10. request.set_accept_format('JSON')
  11. response = json.loads(clt.do_action_with_exception(request))
  12. return response
  13. try:
  14. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  15. update = update_video_infos(clt)
  16. print(update['NonExistVideoIds'])
  17. print(json.dumps(update, ensure_ascii=False, indent=4))
  18. except Exception as e:
  19. print(e)
  20. print(traceback.format_exc())

删除视频

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

  1. from aliyunsdkvod.request.v20170321 import DeleteVideoRequest
  2. def delete_videos(clt):
  3. request = DeleteVideoRequest.DeleteVideoRequest()
  4. videoIds = ['videoId1', 'videoId2']
  5. request.set_VideoIds(','.join(videoIds)) # 支持批量删除视频,多个用逗号分隔
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. delInfo = delete_videos(clt)
  12. print(json.dumps(delInfo, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

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

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

  1. from aliyunsdkvod.request.v20170321 import GetMezzanineInfoRequest
  2. def get_mezzanine_info(clt, videoId):
  3. request = GetMezzanineInfoRequest.GetMezzanineInfoRequest()
  4. request.set_VideoId(videoId)
  5. request.set_AuthTimeout(3600*5)
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. mezzanine = get_mezzanine_info(clt, '<videoId>')
  12. print(json.dumps(mezzanine, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

获取视频列表

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

注意时间参数要使用UTC时间,北京时间与UTC的时差为+8,也就是UTC+8,例如2018-01-01T12:00:00Z表示北京时间2018年1月1日20点0分0秒

  1. from aliyunsdkvod.request.v20170321 import GetVideoListRequest
  2. def get_video_list(clt):
  3. request = GetVideoListRequest.GetVideoListRequest()
  4. # 以获取最近30天的视频列表为例
  5. utcNow = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
  6. utcMonthAgo = datetime.datetime.utcfromtimestamp(time.time() - 30*86400).strftime("%Y-%m-%dT%H:%M:%SZ")
  7. request.set_StartTime(utcMonthAgo) # 视频创建的起始时间,为UTC格式
  8. request.set_EndTime(utcNow) # 视频创建的结束时间,为UTC格式
  9. #request.set_Status('Uploading,Normal,Transcoding') # 视频状态,默认获取所有状态的视频,多个用逗号分隔
  10. #request.set_CateId(0) # 按分类进行筛选
  11. request.set_PageNo(1)
  12. request.set_PageSize(20)
  13. request.set_accept_format('JSON')
  14. response = json.loads(clt.do_action_with_exception(request))
  15. return response
  16. try:
  17. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  18. videoList = get_video_list(clt)
  19. print(json.dumps(videoList, ensure_ascii=False, indent=4))
  20. except Exception as e:
  21. print(e)
  22. print(traceback.format_exc())

删除媒体流

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

  1. from aliyunsdkvod.request.v20170321 import DeleteStreamRequest
  2. # 可删除视频流或音频流信息及存储文件,并支持批量删除;删除后当CDN缓存过期,该路流会无法播放,请谨慎操作
  3. def delete_stream(clt):
  4. request = DeleteStreamRequest.DeleteStreamRequest()
  5. request.set_VideoId('<videoId>')
  6. # 媒体流转码的作业ID列表,多个用逗号分隔;JobId可通过获取播放地址接口(GetPlayInfo)获取到。
  7. jobIds = ['jobId1', 'jobId2']
  8. request.set_JobIds(','.join(jobIds))
  9. request.set_accept_format('JSON')
  10. response = json.loads(clt.do_action_with_exception(request))
  11. return response
  12. try:
  13. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  14. delStream = delete_stream(clt)
  15. print(json.dumps(delStream, ensure_ascii=False, indent=4))
  16. except Exception as e:
  17. print(e)
  18. print(traceback.format_exc())

批量删除源文件

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

  1. from aliyunsdkvod.request.v20170321 import DeleteMezzaninesRequest
  2. def delete_mezzanines(clt):
  3. request = DeleteMezzaninesRequest.DeleteMezzaninesRequest()
  4. videoIds = ['videoId1', 'videoId2']
  5. request.set_VideoIds(','.join(videoIds))
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. delInfo = delete_mezzanines(clt)
  12. print(delInfo['NonExistVideoIds'])
  13. print(json.dumps(delInfo, ensure_ascii=False, indent=4))
  14. except Exception as e:
  15. print(e)
  16. print(traceback.format_exc())

批量更新图片信息

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

  1. from aliyunsdkvod.request.v20170321 import UpdateImageInfosRequest
  2. def update_image_infos(clt):
  3. request = UpdateImageInfosRequest.UpdateImageInfosRequest()
  4. updateContent = []
  5. updateItem1 = {'ImageId': '<imageId1>', 'Title': 'New Sample Title1', 'Tags': 'NewTag1,NewTag2'}
  6. updateItem2 = {'ImageId': '<imageId2>', 'Title': 'New Sample Title2', 'Tags': 'NewTag3,NewTag4'}
  7. updateContent.append(updateItem1)
  8. updateContent.append(updateItem2)
  9. request.set_UpdateContent(json.dumps(updateContent))
  10. request.set_accept_format('JSON')
  11. response = json.loads(clt.do_action_with_exception(request))
  12. return response
  13. try:
  14. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  15. update = update_image_infos(clt)
  16. print(update['NonExistImageIds']['ImageId'])
  17. print(json.dumps(update, ensure_ascii=False, indent=4))
  18. except Exception as e:
  19. print(e)
  20. print(traceback.format_exc())

获取图片信息

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

  1. from aliyunsdkvod.request.v20170321 import GetImageInfoRequest
  2. def get_image_info(clt):
  3. request = GetImageInfoRequest.GetImageInfoRequest()
  4. request.set_ImageId('<imageId>')
  5. request.set_AuthTimeout(3600*24)
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. image = get_image_info(clt)
  12. print(image['ImageInfo'])
  13. print(json.dumps(image, ensure_ascii=False, indent=4))
  14. except Exception as e:
  15. print(e)
  16. print(traceback.format_exc())

删除图片

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

  1. from aliyunsdkvod.request.v20170321 import DeleteImageRequest
  2. def delete_image(clt):
  3. request = DeleteImageRequest.DeleteImageRequest()
  4. #根据ImageURL删除图片文件
  5. request.set_DeleteImageType('ImageURL')
  6. request.set_ImageURLs('http://sample.aliyun.com/cover.jpg')
  7. #根据ImageId删除图片文件
  8. #request.set_DeleteImageType('ImageId')
  9. #request.set_ImageIds('ImageId1,ImageId2')
  10. #根据VideoId删除指定ImageType的图片文件
  11. #request.set_DeleteImageType('VideoId')
  12. #request.set_VideoId('VideoId')
  13. #request.set_ImageType('SpriteSnapshot')
  14. request.set_accept_format('JSON')
  15. response = json.loads(clt.do_action_with_exception(request))
  16. return response
  17. try:
  18. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  19. delInfo = delete_image(clt)
  20. print(json.dumps(delInfo, ensure_ascii=False, indent=4))
  21. except Exception as e:
  22. print(e)
  23. print(traceback.format_exc())