All Products
Search
Document Center

Media asset management

Last Updated: Jul 11, 2019

Initialize a client

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

Search for media asset information

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

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('<AccessKeyId>', '<AccessKeySecret>') 
    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())

Obtain video information

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

from aliyunsdkvod.request.v20170321 import GetVideoInfoRequest
def get_video_info(clt, videoId):
    request = GetVideoInfoRequest.GetVideoInfoRequest()
    request.set_accept_format('JSON')
    request.set_VideoId(videoId)
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>') 
    videoInfo = get_video_info(clt, '<videoId>') 
    print(json.dumps(videoInfo, ensure_ascii=False, indent=4))

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

Obtain the information about multiple videos

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

from aliyunsdkvod.request.v20170321 import GetVideoInfosRequest
def get_video_infos(clt):
    request = GetVideoInfosRequest.GetVideoInfosRequest()
    videoIds = ['videoId1', 'videoId2']
    request.set_VideoIds(','.join(videoIds))

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

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    videos = get_video_infos(clt)
    #print(videos['VideoList'])
    print(videos['NonExistVideoIds'])
    print(json.dumps(videos, ensure_ascii=False, indent=4))

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

Modify video information

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

from aliyunsdkvod.request.v20170321 import UpdateVideoInfoRequest
def update_video_info(clt, videoId):
    request = UpdateVideoInfoRequest.UpdateVideoInfoRequest()
    request.set_VideoId(videoId)
    request.set_Title('New Title') 
    request.set_Description('New Description')
    request.set_CoverURL('http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png')  
    request.set_Tags('tag1,tag2') 
    #request.set_CateId(0) 

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

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>') 
    updateInfo = update_video_info(clt, '<videoId>') 
    print(json.dumps(updateInfo, ensure_ascii=False, indent=4))

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

Modify the information about multiple videos

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

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('<AccessKeyId>', '<AccessKeySecret>') 
    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())

Delete videos

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

from aliyunsdkvod.request.v20170321 import DeleteVideoRequest
def delete_videos(clt):
    request = DeleteVideoRequest.DeleteVideoRequest()
    videoIds = ['videoId1', 'videoId2']
    request.set_VideoIds(','.join(videoIds)) # Specifies one or more IDs of the videos to be deleted. Separate multiple video IDs with a comma (,).

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

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

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

Obtain mezzanine file information (including the mezzanine file download URL)

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

from aliyunsdkvod.request.v20170321 import GetMezzanineInfoRequest
def get_mezzanine_info(clt, videoId):
    request = GetMezzanineInfoRequest.GetMezzanineInfoRequest()
    request.set_VideoId(videoId)
    request.set_AuthTimeout(3600*5)
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>') 
    mezzanine = get_mezzanine_info(clt, '<videoId>') 
    print(json.dumps(mezzanine, ensure_ascii=False, indent=4))

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

Obtain a video list

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

Note: Set the time parameters to UTC time. China Standard Time (UTC+8) is 8 hours ahead of UTC time. For example, a value of 2018-01-01T12:00:00Z indicates 20:00:00 on January 1, 2018, China Standard Time.

from aliyunsdkvod.request.v20170321 import GetVideoListRequest
def get_video_list(clt):
    request = GetVideoListRequest.GetVideoListRequest()
    # Obtains a video list 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) # Sets the start time for video creation, in UTC.
    request.set_EndTime(utcNow) # Sets the end time for video creation, in UTC.
    #request.set_Status('Uploading,Normal,Transcoding') # Sets the video status. By default, videos in all statuses are obtained. Separate multiple video statuses with a comma (,).
    #request.set_CateId(0) # Filters videos 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('<AccessKeyId>', '<AccessKeySecret>')
    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 media streams

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

from aliyunsdkvod.request.v20170321 import DeleteStreamRequest
# Deletes one or more video or audio streams and their storage files. The deleted streams cannot be played if the CDN cache expires, so proceed with caution.
def delete_stream(clt):
    request = DeleteStreamRequest.DeleteStreamRequest()
    request.set_VideoId('<videoId>') 
    # Specifies the IDs of media stream transcoding jobs. Separate multiple job IDs with a comma (,). You can obtain the job ID through the GetPlayInfo operation.
    jobIds = ['jobId1', 'jobId2']
    request.set_JobIds(','.join(jobIds))
    request.set_accept_format('JSON')

    response = json.loads(clt.do_action_with_exception(request))
    return response

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

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

Delete multiple mezzanine files

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

from aliyunsdkvod.request.v20170321 import DeleteMezzaninesRequest
def delete_mezzanines(clt):
    request = DeleteMezzaninesRequest.DeleteMezzaninesRequest()

    videoIds = ['videoId1', 'videoId2']
    request.set_VideoIds(','.join(videoIds))

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

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>') 
    delInfo = delete_mezzanines(clt)
    print(delInfo['NonExistVideoIds'])
    print(json.dumps(delInfo, ensure_ascii=False, indent=4))

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

Update the information about multiple images

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

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('<AccessKeyId>', '<AccessKeySecret>') 
    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())

Obtain image information

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

from aliyunsdkvod.request.v20170321 import GetImageInfoRequest
def get_image_info(clt):
    request = GetImageInfoRequest.GetImageInfoRequest()
    request.set_ImageId('<imageId>')
    request.set_AuthTimeout(3600*24)

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

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>') 
    image = get_image_info(clt)
    print(image['ImageInfo'])
    print(json.dumps(image, ensure_ascii=False, indent=4))

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

Delete images

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

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

    #Deletes image files based on image URLs.
    request.set_DeleteImageType('ImageURL')
    request.set_ImageURLs('http://sample.aliyun.com/cover.jpg')

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

    #Deletes image files of the specified image type based on a video ID.
    #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('<AccessKeyId>', '<AccessKeySecret>') 
    delInfo = delete_image(clt)
    print(json.dumps(delInfo, ensure_ascii=False, indent=4))

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