Manage media information analysis jobs

更新时间:
复制 MD 格式

ApsaraVideo for Media Processing (MPS) SDK for Go V2.0 allows you to submit and query media information analysis jobs. This topic provides sample code for these operations.

Prerequisites

The SDK client is initialized. For more information, see Initialize a client.

Submit a media information analysis job

Call the SubmitMediaInfoJob operation to submit a media information analysis job.

Note
  • When you submit a job by using the SDK for Go, you must URL-encode the file path. Otherwise, the job fails. For more information, see URL encoding.

  • Ensure that the file name is valid. Otherwise, the file cannot be found and the job fails. For more information, see Parameter details.

  • Record the job ID for subsequent operations.

package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  mts20140618  "github.com/alibabacloud-go/mts-20140618/v6/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
// 
// Use your AccessKey ID and AccessKey secret to initialize a client.
// 
// @return Client
// 
// @throws Exception
func CreateClient () (_result *mts20140618.Client, _err error) {

  config := &openapi.Config{
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }

  config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
  _result = &mts20140618.Client{}
  _result, _err = mts20140618.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  submitMediaInfoJobRequest := &mts20140618.SubmitMediaInfoJobRequest{
	// Required. The job input.
    Input: tea.String("{\"Bucket\":\"example-bucket\",\"Location\":\"example-location\",\"Object\":\"example%2Fexample.flv\"}"),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // Write your own code to display the response of the API operation if necessary.
    _, _err = client.SubmitMediaInfoJobWithOptions(submitMediaInfoJobRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.Error())
    }
    // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
    // The error message.
    fmt.Println(tea.StringValue(error.Message))
    // The URL of the corresponding error diagnostics page.
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}

Query a media information analysis job

Call the QueryMediaInfoJobList operation to query a media information analysis job.

package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  mts20140618  "github.com/alibabacloud-go/mts-20140618/v6/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
// 
// Use your AccessKey ID and AccessKey secret to initialize a client.
// 
// @return Client
// 
// @throws Exception
func CreateClient () (_result *mts20140618.Client, _err error) {

  config := &openapi.Config{
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }

  config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
  _result = &mts20140618.Client{}
  _result, _err = mts20140618.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  queryMediaInfoJobListRequest := &mts20140618.QueryMediaInfoJobListRequest{
	// The ID of the media information analysis job.
    MediaInfoJobIds: tea.String("23ca1d184c0e4341e5b665e2a12****"),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // Write your own code to display the response of the API operation if necessary.
    _, _err = client.QueryMediaInfoJobListWithOptions(queryMediaInfoJobListRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.Error())
    }
    // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
    // The error message.
    fmt.Println(tea.StringValue(error.Message))
    // The URL of the corresponding error diagnostics page.
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}