All Products
Search
Document Center

Media asset category

Last Updated: Jul 11, 2019

Initialize a client

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

Create a category

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

from aliyunsdkvod.request.v20170321 import AddCategoryRequest
def add_category(clt, cateName, parentId=-1):
    request = AddCategoryRequest.AddCategoryRequest()
    request.set_CateName(cateName)
    request.set_ParentId(parentId)
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    addRes = add_category(clt, 'Category Name')
    print(json.dumps(addRes, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Modify a category

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

from aliyunsdkvod.request.v20170321 import UpdateCategoryRequest
def update_category(clt, cateId, cateName):
    request = UpdateCategoryRequest.UpdateCategoryRequest()
    request.set_CateId(cateId)
    request.set_CateName(cateName)
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    updateRes = update_category(clt, '<cateId>', 'New Category Name')
    print(json.dumps(updateRes, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Delete a category

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

from aliyunsdkvod.request.v20170321 import UpdateCategoryRequest
# If you delete a video category, its subcategories are deleted recursively, including level-2 and level-3 categories. Proceed with caution.
def delete_category(clt, cateId):
    request = DeleteCategoryRequest.DeleteCategoryRequest()
    request.set_CateId(cateId)
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    delRes = delete_category(clt, '<cateId>')
    print(json.dumps(delRes, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Query a category and its subcategories

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

from aliyunsdkvod.request.v20170321 import GetCategoriesRequest
def get_categories(clt, cateId=-1, pageNo=1, pageSize=10):
    request = GetCategoriesRequest.GetCategoriesRequest()
    request.set_CateId(cateId)
    request.set_PageNo(pageNo)
    request.set_PageSize(pageSize)
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    getRes = get_categories(clt, '<cateId>')
    print(json.dumps(getRes, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())