內(nèi)容庫(kù)管理
更新時(shí)間:
通過(guò)閱讀本文,您可以了解通過(guò)服務(wù)端SDK調(diào)用OpenAPI管理智能媒體服務(wù)內(nèi)容庫(kù)的示例代碼。
示例代碼
您可以通過(guò)阿里云OpenAPI開發(fā)者門戶在線調(diào)試。
import json
import os
import sys
from typing import List
from alibabacloud_ice20201109.client import Client as ICE20201109Client
# 引入阿里云IMS SDK
from alibabacloud_ice20201109 import models as ice20201109_models
# Credentials和云產(chǎn)品SDK都需引入Client,此處為創(chuàng)建別名
from alibabacloud_credentials.client import Client as CredClient
# 引入阿里云SDK核心包
from alibabacloud_tea_openapi.models import Config
#######需要的依賴#############
#pip install alibabacloud_credentials
#pip install alibabacloud_ice20201109==1.3.11
class Sample:
# 初始化客戶端
@staticmethod
def create_client(region: str) -> ICE20201109Client:
# 使用默認(rèn)憑證初始化Credentials Client
cred = CredClient()
config = Config(credential = cred)
# 配置云產(chǎn)品服務(wù)接入地址(endpoint)
config.endpoint = 'ice.' + region + '.aliyuncs.com'
# 使用Credentials Client初始化ECS Client
return ICE20201109Client(config)
# @staticmethod
# def create_client(
# access_key_id: str,
# access_key_secret: str,
# region: str,
# ) -> ICE20201109Client:
# 如需硬編碼AccessKey ID和AccessKey Secret,代碼如下,但強(qiáng)烈建議不要把AccessKey ID和AccessKey Secret保存到工程代碼里,否則可能導(dǎo)致AccessKey泄露,威脅您賬號(hào)下所有資源的安全
# config = open_api_models.Config(
# # 必填,您的 AccessKey ID,
# access_key_id = access_key_id,
# # 必填,您的 AccessKey Secret,
# access_key_secret = access_key_secret
# )
# # 訪問的域名
# config.endpoint = 'ice.' + region + '.aliyuncs.com'
# return ICE20201109Client(config)
# 讀取命令行參數(shù)
@staticmethod
def main() -> None:
region = 'cn-shanghai'
# 初始化客戶端
client = Sample.create_client(region)
# 注冊(cè)內(nèi)容庫(kù)資源
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)
# 獲取媒資內(nèi)容信息
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_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_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)
# 列出媒資基礎(chǔ)信息
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()
相關(guān)接口
文檔內(nèi)容是否對(duì)您有幫助?