全部产品

媒资管理

本篇文档提供了Node.js SDK媒资管理模块相关功能的API调用示例。主要包含搜索媒资信息、获取视频信息、修改视频信息、删除视频、获取源文件信息、获取图片信息、删除图片信息等。

初始化客户端

使用前请先初始化客户端,请参见初始化

搜索媒资信息

调用SearchMedia接口,完成搜索媒资信息功能。

接口参数和返回字段请参见SearchMedia。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("SearchMedia", {
    Fields: 'Title,CoverURL,Status',
    Match: "Status in ('Normal','Checking') and CreationTime = ('2018-07-01T08:00:00Z','2018-08-01T08:00:00Z')",
    PageNo: 1,
    PageSize: 10,
    SearchType: 'video',
    SortBy: 'CreationTime:Desc'
}, {}).then(function (response) {
    console.log("Total = " + response.Total);
    console.log("ScrollToken = " + response.ScrollToken);
    if (response.MediaList && response.MediaList && response.MediaList.length > 0){
        for (var i=0; i<response.MediaList.length; i++){
            console.log("MediaId = " + response.MediaList[i].MediaId);
            console.log("MediaType = " + response.MediaList[i].MediaType);
            console.log("CreationTime = " + response.MediaList[i].CreationTime);
            console.log("Title = " + response.MediaList[i].Video.Title);
            console.log("CoverURL = " + response.MediaList[i].Video.CoverURL);
            console.log("Status = " + response.MediaList[i].Video.Status);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

获取视频信息

调用GetVideoInfo接口,完成获取视频信息功能。

接口参数和返回字段请参见GetVideoInfo。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("GetVideoInfo", {
    VideoId: 'VideoId'
}, {}).then(function (response) {
    if (response.Video){
        console.log("Title = " + response.Video.Title);
        console.log("Description = " + response.Video.Description);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

批量获取视频信息

调用GetVideoInfos接口,完成批量获取视频信息功能。

接口参数和返回字段请参见GetVideoInfos。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("GetVideoInfos", {
    VideoIds: 'Video1,Video2'
}, {}).then(function (response) {
    if (response.VideoList && response.VideoList.length > 0){
        console.log("===== exist video infos : =====");
        for (var i=0; i<response.VideoList.length; i++) {
            var video = response.VideoList[i];
            console.log("VideoId = " + video.VideoId);
            console.log("Title = " + video.Title);
            console.log("Description = " + video.Description);
            console.log("Tags = " + video.Tags);
            console.log("CreationTime = " + video.CreationTime);
        }
    }
    if (response.NonExistVideoIds && response.NonExistVideoIds.length > 0){
        console.log("===== nonexistent videoIds : =====");
        for (var i=0; i<response.NonExistVideoIds.length; i++) {
            console.log("VideoId = " + response.NonExistVideoIds[i]);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

修改视频信息

调用UpdateVideoInfo接口,完成修改视频信息功能。

接口参数和返回字段请参见UpdateVideoInfo。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("UpdateVideoInfo", {
    VideoId: 'VideoId',
    Title: 'new Title',
    Description: 'new Description',
    Tags: 'new Tag1,new Tag2'
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

批量修改视频信息

调用UpdateVideoInfos接口,完成批量修改视频信息功能。

接口参数和返回字段请参见UpdateVideoInfos。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

var updateContent = [{
    VideoId: 'VideoId1',
    Title: 'new Title',
    Tags: 'new Tag1,new Tag2'
},{
    VideoId: 'VideoId2',
    Title: 'new Title',
    Tags: 'new Tag1,new Tag2'
}];
client.request("UpdateVideoInfos", {
    UpdateContent: JSON.stringify(updateContent)
}, {}).then(function (response) {
    if (response.NonExistVideoIds && response.NonExistVideoIds.length > 0){
        console.log("===== nonexistent videoIds : =====");
        for (var i=0; i<response.NonExistVideoIds.length; i++) {
            console.log("VideoId = " + response.NonExistVideoIds[i]);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

删除视频

调用DeleteVideo接口,完成删除视频功能。

接口参数和返回字段请参见DeleteVideo。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("DeleteVideo", {
    VideoIds: 'Video1,Video2'
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

获取源文件信息(含源片下载地址)

调用GetMezzanineInfo接口,完成获取源文件信息功能。

接口参数和返回字段请参见GetMezzanineInfo。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("GetMezzanineInfo", {
    VideoId: 'VideoId',
    AuthTimeout: 3600   // 源片下载地址过期时间
}, {}).then(function (response) {
    if (response.Mezzanine){
        console.log('Mezzanine.VideoId = ' + response.Mezzanine.VideoId);
        console.log('Mezzanine.FileURL = ' + response.Mezzanine.FileURL);
        console.log('Mezzanine.Width = ' + response.Mezzanine.Width);
        console.log('Mezzanine.Height = ' + response.Mezzanine.Height);
        console.log('Mezzanine.Size = ' + response.Mezzanine.Size);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

获取视频列表

调用GetVideoList接口,完成获取视频列表功能。

接口参数和返回字段请参见GetVideoList。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("GetVideoList", {
    StartTime: '2018-12-28T06:00:00Z',
    EndTime: '2018-12-28T14:00:00Z',
    PageNo: 1,
    PageSize: 2
}, {}).then(function (response) {
    // 根据指定筛选条件查询到的视频总数
    console.log('Total = ' + response.Total);
    if (response.VideoList && response.VideoList.Video && response.VideoList.Video.length > 0){
        for (var i=0; i<response.VideoList.Video.length; i++){
            var video = response.VideoList.Video[i];
            console.log('Title = ' + video.Title);
            console.log('Description = ' + video.Description);
            console.log('Tags = ' + video.Tags);
            console.log('CreationTime = ' + video.CreationTime);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

删除媒体流

调用DeleteStream接口,完成删除媒体流功能。

接口参数和返回字段请参见DeleteStream。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("DeleteStream", {
    VideoId: 'VideoId',
    JobIds: 'JobId1,JobId2'
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

批量删除源文件

调用DeleteMezzanines接口,完成批量删除源文件功能。

接口参数和返回字段请参见DeleteMezzanines。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("DeleteMezzanines", {
    VideoIds: 'VideoId',
    Force: false
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

批量更新图片信息

调用UpdateImageInfos接口,完成批量更新图片信息功能。

接口参数和返回字段请参见UpdateImageInfos。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

var updateContent = [{
    ImageId: 'ImageId1',
    Title: 'new title',
    Tags: 'new Tag1,new Tag2'
},{
    ImageId: 'ImageId2',
    Title: 'new title',
    Tags: 'new Tag1,new Tag2'
}];
client.request("UpdateImageInfos", {
    UpdateContent: JSON.stringify(updateContent)
}, {}).then(function (response) {
    if (response.NonExistImageIds && response.NonExistImageIds.ImageId && response.NonExistImageIds.ImageId.length > 0) {
        console.log("======nonexistent ImageIds : ======");
        console.log('ImageId = ' + response.NonExistImageIds.ImageId);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

获取图片信息

调用GetImageInfo接口,完成获取图片信息功能。

接口参数和返回字段请参见GetImageInfo。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

client.request("GetImageInfo", {
    ImageId: 'ImageId1'
}, {}).then(function (response) {
    if (response.ImageInfo) {
        console.log('ImageId = ' + response.ImageInfo.ImageId);
        console.log('Title = ' + response.ImageInfo.Title);
        console.log('CreationTime = ' + response.ImageInfo.CreationTime);
        console.log('FileURL = ' + response.ImageInfo.Mezzanine.FileURL);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

删除图片

调用DeleteImage接口,完成删除图片功能。

接口参数和返回字段请参见DeleteImage。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>');

// 根据ImageURL删除图片文件
var paras = {
    DeleteImageType: 'ImageURL',
    ImageURLs: 'http://sample.aliyun.com/cover.jpg'
};
// 根据ImageId删除图片文件
// var paras = {
//     DeleteImageType: 'ImageId',
//     ImageIds: 'ImageId1,ImageId2'
// };
// 根据VideoId删除指定ImageType的图片文件
// var paras = {
//     DeleteImageType: 'VideoId',
//     VideoId: 'http://sample.aliyun.com/cover.jpg',
//     ImageType: 'SpriteSnapshot'
// };
client.request("DeleteImage", paras, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});