All Products
Search
Document Center

Intelligent Media Services:Content library management

Last Updated:Nov 28, 2024

This topic describes the sample code that is used to call API operations by using the server SDK to manage content libraries of Intelligent Media Services (IMS).

Sample code

You can use Alibaba Cloud OpenAPI Explorer to perform online debugging.

import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Credential, { Config } from '@alicloud/credentials';
const Client = require('@alicloud/ice20201109').default;

// An AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use an AccessKey pair of a RAM user to call API operations or perform routine O&M. 
// In this example, the AccessKey ID and AccessKey secret are obtained from the environment variables. For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-0-node-js-sdk/?spm=a2c63.p38356.0.0.3b2b3ccarBQ6QC.

const cred = new Credential();
const iceClient = new Client(new $OpenApi.Config({
  credential: cred,
  endpoint: 'ice.cn-shanghai.aliyuncs.com'
}));

// To hard-code your AccessKey ID and AccessKey secret, use the following code. However, we recommend that you do not save the AccessKey ID and the AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of resources within your account may be compromised. 
// const iceClient = new Client(new $OpenApi.Config({
//   accessKeyId: '<yourAccessKeyId>',
//   accessKeySecret: '<yourAccessKeySecret>',
//   endpoint: 'ice.cn-shanghai.aliyuncs.com'
// }));

// Register the content library resources.
iceClient.registerMediaInfo({
    InputURL : 'http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.mp4',
    MediaType : 'video',
    Businesstype : 'video',
    Title : 'default_title'
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// Obtain the media asset information.
iceClient.getMediaInfo({
    MediaId : 'e76bd08-9555-429f-9aca-17ff8983****'
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// Update the content information.
iceClient.updateMediaInfo({
    MediaId : '76bd08-9555-429f-9aca-17ff8983****',
    CoverURL : "http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.jpg"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});


// Delete the media asset information.
iceClient.deleteMediaInfos({
    MediaIds : '****e76bd08-9555-429f-9aca-17ff8983****'
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// List the basic information about the media asset.
iceClient.listMediaBasicInfos({
    MaxResults: 10
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

Related API operations