全部产品
云市场

截图模板

更新时间:2018-12-27 16:42:05

初始化客户端

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

添加截图模板

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

  1. from aliyunsdkvod.request.v20170321 import AddVodTemplateRequest
  2. def add_vod_template(clt):
  3. request = AddVodTemplateRequest.AddVodTemplateRequest()
  4. # 模板名称
  5. request.set_Name('Sample Snapshot Template')
  6. # 模板类型,固定值为Snapshot
  7. request.set_TemplateType('Snapshot')
  8. # 截图模板配置数据
  9. snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
  10. 'FrameType': 'normal'}
  11. templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'NormalSnapshot'}
  12. """
  13. # 可选项:雪碧图配置(雪碧图配置必须建立在普通截图配置之上)
  14. spriteSnapshotConfig = {'CellWidth': 120, 'CellHeight': 68, 'Columns': 3, 'Lines': 10, 'Padding': 20,
  15. 'Margin': 50, 'KeepCellPic': 'keep', 'Color': 'tomato'}
  16. snapshotConfig['SpriteSnapshotConfig'] = spriteSnapshotConfig
  17. templateConfig['SnapshotType'] = 'SpriteSnapshot'
  18. """
  19. request.set_TemplateConfig(json.dumps(templateConfig))
  20. request.set_accept_format('JSON')
  21. response = json.loads(clt.do_action_with_exception(request))
  22. return response
  23. try:
  24. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  25. template = add_vod_template(clt)
  26. print(template['VodTemplateId'])
  27. print(json.dumps(template, ensure_ascii=False, indent=4))
  28. except Exception as e:
  29. print(e)
  30. print(traceback.format_exc())

修改截图模板

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

  1. from aliyunsdkvod.request.v20170321 import UpdateVodTemplateRequest
  2. def update_vod_template(clt):
  3. request = UpdateVodTemplateRequest.UpdateVodTemplateRequest()
  4. request.set_VodTemplateId('<templateId>')
  5. # 修改模板名称
  6. request.set_Name('New Snapshot Template Name')
  7. # 修改截图模板配置数据
  8. snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
  9. 'FrameType': 'normal'}
  10. templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'NormalSnapshot'}
  11. request.set_TemplateConfig(json.dumps(templateConfig))
  12. request.set_accept_format('JSON')
  13. response = json.loads(clt.do_action_with_exception(request))
  14. return response
  15. try:
  16. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  17. template = update_vod_template(clt)
  18. print(json.dumps(template, ensure_ascii=False, indent=4))
  19. except Exception as e:
  20. print(e)
  21. print(traceback.format_exc())

删除截图模板

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

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

查询截图模板列表

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

  1. from aliyunsdkvod.request.v20170321 import ListVodTemplateRequest
  2. def list_vod_template(clt):
  3. request = ListVodTemplateRequest.ListVodTemplateRequest()
  4. # 模板类型,固定值为Snapshot
  5. request.set_TemplateType('Snapshot')
  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. templates = list_vod_template(clt)
  12. print(templates['VodTemplateInfoList'])
  13. print(json.dumps(templates, ensure_ascii=False, indent=4))
  14. except Exception as e:
  15. print(e)
  16. print(traceback.format_exc())

查询截图模板

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

  1. from aliyunsdkvod.request.v20170321 import GetVodTemplateRequest
  2. def get_vod_template(clt):
  3. request = GetVodTemplateRequest.GetVodTemplateRequest()
  4. request.set_VodTemplateId('<templateId>')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. template = get_vod_template(clt)
  11. print(template['VodTemplateInfo'])
  12. print(json.dumps(template, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())