Manage a content library

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.

Usage notes

Media assets can be registered only from files stored in Object Storage Service (OSS).

Sample code

Use the Alibaba Cloud OpenAPI Developer Portal for online debugging.

package main

import (
    "fmt"
    openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
    ice "github.com/alibabacloud-go/ice-20201109/v2/client"
    "github.com/aliyun/credentials-go/credentials"
    "github.com/alibabacloud-go/tea/tea"
)

func main() {

    // An AccessKey of an Alibaba Cloud account has full access permissions on all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform daily O&M.
    // This example shows how to configure an AccessKey ID and an AccessKey secret as environment variables. For more information about the configuration method, see https://help.aliyun.com/document_detail/378661.html.
    credential, _err := credentials.NewCredential(nil)
    if _err != nil {
      panic(_err)
    }
    iceClient, _err := ice.NewClient(&openapi.Config{
      Credential: credential,
      Endpoint: tea.String("ice.cn-shanghai.aliyuncs.com"),
    })

    // If you want to hard-code the AccessKey ID and AccessKey secret, use the following code. We strongly recommend that you do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
    // config := new(openapi.Config)
    // config.SetAccessKeyId("<accessKeyId>").
    //     SetAccessKeySecret("<accessKeySecret>").
    //     SetRegionId("<regionId>").
    //     SetEndpoint("<endpoint>")
    // iceClient, _err := ice.NewClient(config)

    if _err != nil {
      panic(_err)
    }

    // Register a media asset.
    inputUrl := "OSS://***"
    mediaType := "video"
    mediaInfo := ice.RegisterMediaInfoRequest{
        InputURL:  &inputUrl,
        MediaType: &mediaType,
    }

    result, err := iceClient.RegisterMediaInfo(&mediaInfo)
    fmt.Println(result, err)

    // Get the content of a single media asset.
    mediaId := "****94bef6e348c8b6ed59c88cda****"
    getMediaInfoRequest := ice.GetMediaInfoRequest{
        MediaId: &mediaId,
    }
    getMediaInfoResult, err := iceClient.GetMediaInfo(&getMediaInfoRequest)
    fmt.Println(getMediaInfoResult, err)

    // Modify the content.
    coverUrl := "https://****/test.jpg"
    updateMediainfoRequest := ice.UpdateMediaInfoRequest{
        MediaId:  &mediaId,
        CoverURL: &coverUrl,
    }
    updateMediaInfoResult, err := iceClient.UpdateMediaInfo(&updateMediainfoRequest)
    fmt.Println(updateMediaInfoResult, err)

    // Retrieve media asset content.
    maxResults := int32(10)
    listMediaBasicInfosRequest := ice.ListMediaBasicInfosRequest{
        MaxResults: &maxResults,
    }
    listMediaBasicInfosResult, err := iceClient.ListMediaBasicInfos(&listMediaBasicInfosRequest)
    fmt.Println(listMediaBasicInfosResult, err)
}

Related API operations