Content library management
Updated at:
By reading this article, you can learn the sample code for calling the OpenAPI to manage the intelligent media service content library through the server SDK.
Sample code
Use Alibaba Cloud OpenAPI Explorer to debug API calls online.
import json
import os
import sys
from typing import List
from alibabacloud_ice20201109.client import Client as ICE20201109Client
# Import Alibaba Cloud IMS SDK.
from alibabacloud_ice20201109 import models as ice20201109_models
# Import a client for credentials and SDKs of cloud services and create an alias for the client.
from alibabacloud_credentials.client import Client as CredClient
# Import the core package of Alibaba Cloud SDKs.
from alibabacloud_tea_openapi.models import Config
#######Required dependencies#############
#pip install alibabacloud_credentials
#pip install alibabacloud_ice20201109==1.3.11
class Sample:
# Initialize the client.
@staticmethod
def create_client(region: str) -> ICE20201109Client:
# Use the default credential to initialize the credentials client.
cred = CredClient()
config = Config(credential = cred)
# Specify the endpoint of the cloud service.
config.endpoint = 'ice.' + region + '.aliyuncs.com'
# Use the credentials client to initialize the ECS SDK client.
return ICE20201109Client(config)
# @staticmethod
# def create_client(
# access_key_id: str,
# access_key_secret: str,
# region: str,
# ) -> ICE20201109Client:
# To hard-code your AccessKey ID and AccessKey secret, use the following code. However, we recommend that you do not save the AccessKey ID and the AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of resources within your account may be compromised.
# config = open_api_models.Config(
# # Required. Specify your AccessKey ID.
# access_key_id = access_key_id,
# # Required. Specify your AccessKey secret.
# access_key_secret = access_key_secret
# )
# # Specify the endpoint that you want to access.
# config.endpoint = 'ice.' + region + '.aliyuncs.com'
# return ICE20201109Client(config)
# Read command line parameters.
@staticmethod
def main() -> None:
region = 'cn-shanghai'
# Initialize the client.
client = Sample.create_client(region)
# Register content library resources.
register_mediaInfo_request = ice20201109_models.RegisterMediaInfoRequest()
register_mediaInfo_request.input_url = 'http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.mp4'
register_mediaInfo_request.media_type = 'video'
register_mediaInfo_request.business_type = 'video'
register_mediaInfo_request.title = 'default_title'
register_mediaInfo_response = client.register_media_info(register_mediaInfo_request)
print(register_mediaInfo_response)
print('request id:', register_mediaInfo_response.body.request_id)
print('media info:', register_mediaInfo_response.body.media_id)
# Obtain the media asset information.
get_mediaInfo_request = ice20201109_models.GetMediaInfoRequest()
# get media info by mediaId
get_mediaInfo_request.media_id = '****20b48fb04483915d4f2cd8ac****'
# get media info by inputUrl
# request.input_url = 'http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.mp4'
get_mediaInfo_response = client.get_media_info(get_mediaInfo_request)
print(get_mediaInfo_response)
print('request id:', get_mediaInfo_response.body.request_id)
print('media info:', get_mediaInfo_response.body.media_info)
# Update the media asset information.
update_mediaInfo_request = ice20201109_models.UpdateMediaInfoRequest()
# get media info by mediaId
update_mediaInfo_request.media_id = '****20b48fb04483915d4f2cd8ac****'
# get media info by inputUrl
# request.input_url = 'http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.mp4'
update_mediaInfo_response = client.update_media_info(update_mediaInfo_request)
print(update_mediaInfo_response)
print('request id:', update_mediaInfo_response.body.request_id)
print('media info:', update_mediaInfo_response.body.media_info)
# Delete the media asset information.
delete_mediaInfos_request = ice20201109_models.DeleteMediaInfosRequest()
# delete media info by mediaId
delete_mediaInfos_request.media_ids = '****20b48fb04483915d4f2cd8ac****,****81539d420bb04d8ac4f48f2c****'
# delete media info by inputUrl
# request.input_urls = 'http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.mp4,http://example-bucket.oss-cn-shanghai.aliyuncs.com/example2.mp4'
delete_mediaInfos_response = client.delete_media_infos(delete_mediaInfos_request)
print(delete_mediaInfos_response)
print('request id:', delete_mediaInfos_response.body.request_id)
print('ignored list:', delete_mediaInfos_response.body.ignored_list)
# List the basic information about the media asset.
list_media_basicInfos_request = ice20201109_models.ListMediaBasicInfosRequest()
# set start time (exclusive)
list_media_basicInfos_request.start_time = '2020-12-20T12:00:00Z'
# set end time (inclusive)
list_media_basicInfos_request.end_time = '2020-12-20T13:00:00Z'
# set max return entries
list_media_basicInfos_request.max_results = 5
list_media_basicInfos_response = client.list_media_basic_infos(list_media_basicInfos_request)
print(list_media_basicInfos_response)
print('request id:', list_media_basicInfos_response.body.request_id)
print('media info list:', list_media_basicInfos_response.body.media_infos)
print('next token', list_media_basicInfos_response.body.next_token)
print('max results', list_media_basicInfos_response.body.max_results)
if __name__ == '__main__':
Sample.main()
Related API operations
Is this page helpful?