Updated on 2023-07-17 GMT+08:00

Creating a Video Moderation Job

  1. This section describes how to create a video moderation job using the video moderation SDK and AK/SK.

    Replace the AK/SK in the sample code with the actual AK/SK. You can use the withUrls method of the RunCreateVideoModerationJobRequest class to configure the URLs of the videos to be reviewed, and then execute the code.

    using System;
    using System.Collections.Generic;
    using HuaweiCloud.SDK.Core;
    using HuaweiCloud.SDK.Core.Auth;
    using HuaweiCloud.SDK.Moderation;
    using HuaweiCloud.SDK.Moderation.V3;
    using HuaweiCloud.SDK.Moderation.V3.Model;
     
    namespace RunCreateVideoModerationJobSolution
    {
        class Program
        {
            static void Main(string[] args)
            {
           //Enter your AK/SK.
                const string ak = "<YOUR AK>";
                const string sk = "<YOUR SK>";
     
                var config = HttpConfig.GetDefaultConfig();
                config.IgnoreSslVerification = true;
                var auth = new BasicCredentials(ak, sk);
     
                var client = ModerationClient.NewBuilder()
                        .WithCredential(auth)
                        .WithRegion(ModerationRegion.ValueOf("xxx"))  //Replace xxx with the region where the service is located.
                        .WithHttpConfig(config)
                        .Build();
     
                var req = new RunCreateVideoModerationJobRequest
                {
                };
                List<VideoCreateRequest.AudioCategoriesEnum> listAudioCategoriesbody = new List<VideoCreateRequest.AudioCategoriesEnum>();
                listAudioCategoriesbody.Add(VideoCreateRequest.AudioCategoriesEnum.FromValue("porn"));
                List<VideoCreateRequest.ImageCategoriesEnum> listImageCategoriesbody = new List<VideoCreateRequest.ImageCategoriesEnum>();
                listImageCategoriesbody.Add(VideoCreateRequest.ImageCategoriesEnum.FromValue("porn"));
                VideoCreateRequestData databody = new VideoCreateRequestData()
                {
                    Url = "http://xxx.xx.xxxx",
                    FrameInterval = 5.5
                };
                req.Body = new VideoCreateRequest()
                {
                    Callback = "http://xxx.xx.xxxx",
                    AudioCategories = listAudioCategoriesbody,
                    ImageCategories = listImageCategoriesbody,
                    EventType = VideoCreateRequest.EventTypeEnum.FromValue("default"),
                    Data = databody
                };
     
                try
                {
                    var resp = client.RunCreateVideoModerationJob(req);
                    var respStatusCode = resp.HttpStatusCode;
                    Console.WriteLine(respStatusCode);
                }
                catch (RequestTimeoutException requestTimeoutException)
                {
                    Console.WriteLine(requestTimeoutException.ErrorMessage);
                }
                catch (ServiceResponseException clientRequestException)
                {
                    Console.WriteLine(clientRequestException.HttpStatusCode);
                    Console.WriteLine(clientRequestException.ErrorCode);
                    Console.WriteLine(clientRequestException.ErrorMsg);
                }
                catch (ConnectionException connectionException)
                {
                    Console.WriteLine(connectionException.ErrorMessage);
                }
            }
        }
    }
  2. The console returns the creation result of the video moderation job.
    200
     {
        "request_id":"dbbcb75d1a174bfa899a38be38fdd107",
        "job_id":"xxx"
    }