Media asset management
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
-
All examples in this topic use an AccessKey pair to initialize a client instance.
-
For request and response parameter details, visit Alibaba Cloud OpenAPI Explorer and open the API Documentations tab.
-
For SDK examples of other API operations, visit Alibaba Cloud OpenAPI Explorer. On the Parameters tab, specify the parameters and initiate the call. Then select the SDK version and language on the SDK Sample Code tab to view and download the code.
-
The examples in this topic use SDK V1.0. For V2.0 examples, select the correct SDK version in OpenAPI Explorer.
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.
Alibaba Cloud OpenAPI Portal: SearchMedia.
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 API to generate an SDK example for retrieving information about a single audio or video file.
Alibaba Cloud OpenAPI Portal: GetVideoInfo.
You can call the GetVideoInfos API to generate an SDK example for retrieving information about multiple audio or video files in a batch.
Alibaba Cloud OpenAPI Portal: GetVideoInfos.
Modify information about an audio or video file
You can call the UpdateVideoInfo operation to modify information about an audio or video file.
Alibaba Cloud OpenAPI Portal: UpdateVideoInfo.
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.
Alibaba Cloud OpenAPI Portal: UpdateVideoInfos.
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.
Alibaba Cloud OpenAPI Portal: GetMezzanineInfo.
Query audio and video files
You can call the GetVideoList operation to query audio and video files.
Alibaba Cloud OpenAPI Portal: GetVideoList.
Sample code:
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.
Alibaba Cloud OpenAPI Portal: DeleteVideo.
Delete media streams
You can call the DeleteStream operation to delete media streams.
Alibaba Cloud OpenAPI Portal: DeleteStream.
Delete multiple source files
You can call the DeleteMezzanines operation to delete multiple source files at a time.
Alibaba Cloud OpenAPI Portal: DeleteMezzanines.
Modify information about multiple images
You can call the UpdateImageInfos operation to modify information about multiple images at a time.
Alibaba Cloud OpenAPI Portal: UpdateImageInfos.
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.
Alibaba Cloud OpenAPI Portal: GetImageInfo.
Delete images
You can call the DeleteImage operation to delete images.
Alibaba Cloud OpenAPI Portal: DeleteImage.
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())