文档

媒资审核

更新时间:

通过阅读本文,您可以了解通过服务端SDK调用OpenAPI审核智能媒体服务媒资信息的示例代码。

示例代码

您可以通过阿里云OpenAPI开发者门户在线调试。

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和云产品SDK都需引入Client,此处为创建别名
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:
        # 使用默认凭证初始化Credentials Client        
        cred = CredClient()
        config = Config(credential = cred)
        # 配置云产品服务接入地址(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,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全
    #     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)

    # 读取命令行参数
    @staticmethod
    def main() -> None:
        region = 'cn-shanghai'
        # 初始化客户端
        client = Sample.create_client(region)
        # 创建审核模板
        censor_template_config = '{\"Scene\":[\"porn\",\"terrorism\"],\"Scope\":[\"title\",\"video\",\"audio\",\"cover\"]}'
        create_custom_template_request = ice20201109_models.CreateCustomTemplateRequest(
            name = 'sdk_sample_censor_template',
            type = 7,
            subtype = 1,
            template_config = censor_template_config
        )
        create_custom_template_response = client.create_custom_template(create_custom_template_request)
        print('[LOG]', json.dumps(create_custom_template_response.to_map()))
        template_id = create_custom_template_response.body.custom_template.template_id

        # 提交媒体审核作业
        submit_censor_job_request = ice20201109_models.SubmitMediaCensorJobRequest(
            input = ice20201109_models.SubmitMediaCensorJobRequestInput(
                type = 'Media',
                media = '1b1b9cd148034739af413150fded****'
            ),
            output = "oss://test_bucket/censor/snapshot-{Count}.jpg",
            template_id = template_id
        )
        submit_media_censor_job_response = client.submit_media_censor_job(submit_censor_job_request)
        print('[LOG]', json.dumps(submit_media_censor_job_response.to_map()))
        job_id = submit_media_censor_job_response.body.job_id

        # 查询媒体审核任务作业详情
        query_media_censor_job_request = ice20201109_models.QueryMediaCensorJobDetailRequest(
            job_id = job_id
        )
        get_snapshot_job_response = client.query_media_censor_job_detail(query_media_censor_job_request)
        print('[LOG]', json.dumps(get_snapshot_job_response.to_map()))

        # 查询媒体审核任务作业列表
        query_media_censor_job_list_request = ice20201109_models.QueryMediaCensorJobListRequest(
            job_ids=job_id
        )
        query_media_censor_job_list_response = client.query_media_censor_job_list(query_media_censor_job_list_request)
        print('[LOG]', json.dumps(query_media_censor_job_list_response.to_map()))


if __name__ == '__main__':
    Sample.main()

相关接口