All Products
Search
Document Center

Snapshot template

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see init_vod_client.

Add a snapshot template

For more information about the request and response parameters, see AddVodTemplate.

from aliyunsdkvod.request.v20170321 import AddVodTemplateRequest
def add_vod_template(clt):
    request = AddVodTemplateRequest.AddVodTemplateRequest()
    # Sets the template name.
    request.set_Name('Sample Snapshot Template')
    # Sets the template type to Snapshot.
    request.set_TemplateType('Snapshot')

    # Generates the snapshot template configuration.
    snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
                      'FrameType': 'normal'}
    templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'NormalSnapshot'}

    """
    # (Optional) Specifies the sprite snapshot configuration, which must be constructed based on the normal snapshot configuration.
    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())

Modify a snapshot template

For more information about the request and response parameters, see UpdateVodTemplate.

from aliyunsdkvod.request.v20170321 import UpdateVodTemplateRequest
def update_vod_template(clt):
    request = UpdateVodTemplateRequest.UpdateVodTemplateRequest()
    request.set_VodTemplateId('<templateId>')
    # Sets the template name.
    request.set_Name('New Snapshot Template Name')
    # Modifies the snapshot template configuration.
    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())

Delete a snapshot template

For more information about the request and response parameters, see 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())

Query a list of snapshot templates

For more information about the request and response parameters, see ListVodTemplate.

from aliyunsdkvod.request.v20170321 import ListVodTemplateRequest
def list_vod_template(clt):
    request = ListVodTemplateRequest.ListVodTemplateRequest()
    # Sets the template type to 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())

Query a snapshot template

For more information about the request and response parameters, see 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())