截图模板
本篇文档提供了Python SDK截图模板功能的API调用示例。包含添加截图模板、修改截图模板、删除截图模板、查询截图模板列表。
初始化客户端
使用前请先初始化客户端,请参见初始化。
添加截图模板
调用AddVodTemplate接口,完成添加截图模板功能。
接口参数和返回字段请参见AddVodTemplate。调用示例如下:
from aliyunsdkvod.request.v20170321 import AddVodTemplateRequest
def add_vod_template(clt):
request = AddVodTemplateRequest.AddVodTemplateRequest()
# 模板名称
request.set_Name('Sample Snapshot Template')
# 模板类型,固定值为Snapshot
request.set_TemplateType('Snapshot')
# 截图模板配置数据
snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
'FrameType': 'normal'}
templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'NormalSnapshot'}
"""
# 可选项:雪碧图配置(雪碧图配置必须建立在普通截图配置之上)
spriteSnapshotConfig = {'CellWidth': 120, 'CellHeight': 68, 'Columns': 3, 'Lines': 10, 'Padding': 20,
'Margin': 50, 'KeepCellPic': 'keep', 'Color': 'tomato'}
snapshotConfig['SpriteSnapshotConfig'] = spriteSnapshotConfig
templateConfig['SnapshotType'] = 'SpriteSnapshot'
"""
request.set_TemplateConfig(json.dumps(templateConfig))
request.set_accept_format('JSON')
response = json.loads(clt.do_action_with_exception(request))
return response
try:
clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
template = add_vod_template(clt)
print(template['VodTemplateId'])
print(json.dumps(template, ensure_ascii=False, indent=4))
except Exception as e:
print(e)
print(traceback.format_exc())
修改截图模板
调用UpdateVodTemplate接口,完成修改截图模板功能。
接口参数和返回字段请参见UpdateVodTemplate。调用示例如下:
from aliyunsdkvod.request.v20170321 import UpdateVodTemplateRequest
def update_vod_template(clt):
request = UpdateVodTemplateRequest.UpdateVodTemplateRequest()
request.set_VodTemplateId('<templateId>')
# 修改模板名称
request.set_Name('New Snapshot Template Name')
# 修改截图模板配置数据
snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
'FrameType': 'normal'}
templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'NormalSnapshot'}
request.set_TemplateConfig(json.dumps(templateConfig))
request.set_accept_format('JSON')
response = json.loads(clt.do_action_with_exception(request))
return response
try:
clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
template = update_vod_template(clt)
print(json.dumps(template, ensure_ascii=False, indent=4))
except Exception as e:
print(e)
print(traceback.format_exc())
删除截图模板
调用DeleteVodTemplate接口,完成删除截图模板功能。
接口参数和返回字段请参见DeleteVodTemplate。调用示例如下:
from aliyunsdkvod.request.v20170321 import DeleteVodTemplateRequest
def delete_vod_template(clt):
request = DeleteVodTemplateRequest.DeleteVodTemplateRequest()
request.set_VodTemplateId('<templateId>')
request.set_accept_format('JSON')
response = json.loads(clt.do_action_with_exception(request))
return response
try:
clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
res = delete_vod_template(clt)
print(json.dumps(res, ensure_ascii=False, indent=4))
except Exception as e:
print(e)
print(traceback.format_exc())
查询截图模板列表
调用ListVodTemplate接口,完成查询截图模板列表功能。
接口参数和返回字段请参见ListVodTemplate。调用示例如下:
from aliyunsdkvod.request.v20170321 import ListVodTemplateRequest
def list_vod_template(clt):
request = ListVodTemplateRequest.ListVodTemplateRequest()
# 模板类型,固定值为Snapshot
request.set_TemplateType('Snapshot')
request.set_accept_format('JSON')
response = json.loads(clt.do_action_with_exception(request))
return response
try:
clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
templates = list_vod_template(clt)
print(templates['VodTemplateInfoList'])
print(json.dumps(templates, ensure_ascii=False, indent=4))
except Exception as e:
print(e)
print(traceback.format_exc())
查询截图模板
调用GetVodTemplate接口,完成查询截图模板功能。
接口参数和返回字段请参见GetVodTemplate。调用示例如下:
from aliyunsdkvod.request.v20170321 import GetVodTemplateRequest
def get_vod_template(clt):
request = GetVodTemplateRequest.GetVodTemplateRequest()
request.set_VodTemplateId('<templateId>')
request.set_accept_format('JSON')
response = json.loads(clt.do_action_with_exception(request))
return response
try:
clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
template = get_vod_template(clt)
print(template['VodTemplateInfo'])
print(json.dumps(template, ensure_ascii=False, indent=4))
except Exception as e:
print(e)
print(traceback.format_exc())