All Products
Search
Document Center

ApsaraVideo VOD:Media asset management

Last Updated:Aug 22, 2023

This topic provides examples on how to use the API operations of the media management module. The API operations are encapsulated in ApsaraVideo VOD SDK for Python. You can call the API operations to query media asset information, modify video information, and query source file information. You can also query and delete videos and images.

Usage notes

  • In this example, an AccessKey pair is used to initialize a client instance.

  • For more information about the request and response parameters of this operation, visit OpenAPI Explorer. You can click API Documentation in the top navigation bar to view information related to the API operation.

  • This topic provides sample code only for some complex API operations. To obtain sample code for other API operations, perform the following operations: Visit Alibaba Cloud OpenAPI Explorer. In the left-side navigation pane, find the API operation whose sample code you want to obtain and specify the required parameters on the Parameters tab. Then, click Initiate Call. On the SDK Sample Code tab, select the language to view and download the sample code.

Initialize a client

Before you use the SDK, initialize a client. For more information, see Initialization.

Query media asset information

You can call the SearchMedia operation to query media asset information.

Click SearchMedia to learn more about this API operation.

Sample code:

from aliyunsdkvod.request.v20170321 import SearchMediaRequest
def search_media(clt):
    request = SearchMediaRequest.SearchMediaRequest()
    request.set_Fields('Title,CoverURL,Status');
    request.set_Match('Status in ("Normal","Checking") and CreationTime = ("2018-10-01T08:00:00Z","2018-12-25T08:00:00Z")')
    request.set_PageNo(1)
    request.set_PageSize(10)
    request.set_SearchType('video')
    request.set_SortBy('CreationTime:Desc')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client()
    medias = search_media(clt)
    print(medias['MediaList'])
    print(json.dumps(medias, ensure_ascii=False, indent=4))

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

Query information about audio or video files

  • You can call the GetVideoInfo operation to query information about an audio or video file.

    Click GetVideoInfo to learn more about this API operation.

  • You can call the GetVideoInfos operation to query information about multiple audio or video files at a time.

    Click GetVideoInfos to learn more about this API operation.

Modify information about an audio or video file

You can call the UpdateVideoInfo operation to modify information about an audio or video file.

Click UpdateVideoInfo to learn more about this API operation.

Modify information about multiple audio or video files

You can call the UpdateVideoInfos operation to modify information about multiple audio or video files at a time.

Click UpdateVideoInfos to learn more about this API operation.

Sample code:

from aliyunsdkvod.request.v20170321 import UpdateVideoInfosRequest
def update_video_infos(clt):
    request = UpdateVideoInfosRequest.UpdateVideoInfosRequest()

    updateContent = []
    updateItem1 = {'VideoId': '<VideoId1>', 'Title': 'New Sample Title1', 'Tags': 'NewTag1,NewTag2'}
    updateItem2 = {'VideoId': '<VideoId2>', 'Title': 'New Sample Title2', 'Tags': 'NewTag3,NewTag4'}
    updateContent.append(updateItem1)
    updateContent.append(updateItem2)
    request.set_UpdateContent(json.dumps(updateContent))

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client()
    update = update_video_infos(clt)
    print(update['NonExistVideoIds'])
    print(json.dumps(update, ensure_ascii=False, indent=4))

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

Query source file information (the download URL included)

You can call the GetMezzanineInfo operation to query source file information.

Click GetMezzanineInfo to learn more about this API operation.

Query audio and video files

You can call the GetVideoList operation to query audio and video files.

Click GetVideoList to learn more about this API operation.

Sample code:

Important

The time must be in UTC. For example, 2018-01-01T12:00:00Z indicates 20:00:00 on January 1, 2018 (UTC+8).

from aliyunsdkvod.request.v20170321 import GetVideoListRequest
def get_video_list(clt):
    request = GetVideoListRequest.GetVideoListRequest()
    # The following sample code provides an example on how to query video files in the last 30 days.
    utcNow = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
    utcMonthAgo = datetime.datetime.utcfromtimestamp(time.time() - 30*86400).strftime("%Y-%m-%dT%H:%M:%SZ")
    request.set_StartTime(utcMonthAgo)   # The beginning of the time range during which the video was created. The time must be in UTC.
    request.set_EndTime(utcNow)          # The end of the time range during which the video was created. The time must be in UTC.
    # request.set_Status('Uploading,Normal,Transcoding')  # The status of the video. Separate multiple video statuses with commas (,). By default, videos in all statuses are queried.
    #request.set_CateId(0)               # Filter by category.
    request.set_PageNo(1)
    request.set_PageSize(20)

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client()
    videoList = get_video_list(clt)
    print(json.dumps(videoList, ensure_ascii=False, indent=4))

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

Delete audio and video files

You can call the DeleteVideo operation to delete audio and video files.

Click DeleteVideo to learn more about this API operation.

Delete media streams

You can call the DeleteStream operation to delete media streams.

Click DeleteStream to learn more about this API operation.

Delete multiple source files

You can call the DeleteMezzanines operation to delete multiple source files at a time.

Click DeleteMezzanines to learn more about this API operation.

Modify information about multiple images

You can call the UpdateImageInfos operation to modify information about multiple images at a time.

Click UpdateImageInfos to learn more about this API operation.

Sample code:

from aliyunsdkvod.request.v20170321 import UpdateImageInfosRequest
def update_image_infos(clt):
    request = UpdateImageInfosRequest.UpdateImageInfosRequest()

    updateContent = []
    updateItem1 = {'ImageId': '<imageId1>', 'Title': 'New Sample Title1', 'Tags': 'NewTag1,NewTag2'}
    updateItem2 = {'ImageId': '<imageId2>', 'Title': 'New Sample Title2', 'Tags': 'NewTag3,NewTag4'}
    updateContent.append(updateItem1)
    updateContent.append(updateItem2)
    request.set_UpdateContent(json.dumps(updateContent))

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client()
    update = update_image_infos(clt)
    print(update['NonExistImageIds']['ImageId'])
    print(json.dumps(update, ensure_ascii=False, indent=4))

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

Query information about an image

You can call the GetImageInfo operation to query information about an image.

Click GetImageInfo to learn more about this API operation.

Delete images

You can call the DeleteImage operation to delete images.

Click DeleteImage to learn more about this API operation.

Sample code:

from aliyunsdkvod.request.v20170321 import DeleteImageRequest
def delete_image(clt):
    request = DeleteImageRequest.DeleteImageRequest()

    # Delete image files based on ImageURL.
    request.set_DeleteImageType('ImageURL')
    request.set_ImageURLs('http://192.168.0.0/16/cover.jpg')

    # Delete image files based on ImageId.
    #request.set_DeleteImageType('ImageId')
    #request.set_ImageIds('ImageId1,ImageId2')

    # Delete image files based on VideoId and ImageType.
    #request.set_DeleteImageType('VideoId')
    #request.set_VideoId('VideoId')
    #request.set_ImageType('SpriteSnapshot')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client()
    delInfo = delete_image(clt)
    print(json.dumps(delInfo, ensure_ascii=False, indent=4))

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