-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
484 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"author": "[email protected]", | ||
"license": "MIT", | ||
"dependencies": { | ||
"debug": "^2.1.3", | ||
"q": "^1.1.2", | ||
"underscore": "^1.7.0" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
/** | ||
* Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
/*eslint-env node*/ | ||
/*eslint max-params:[0,10]*/ | ||
|
||
var util = require('util'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
|
||
var u = require('underscore'); | ||
var Q = require('q'); | ||
|
||
var H = require('./headers'); | ||
var Auth = require('./auth'); | ||
var HttpClient = require('./http_client'); | ||
var BceBaseClient = require('./bce_base_client'); | ||
var MimeType = require('./mime.types'); | ||
var WMStream = require('./wm_stream'); | ||
|
||
/** | ||
* Media service api. | ||
* @constructor | ||
* @param {Object} config The media client configuration. | ||
* @extends {BceBaseClient} | ||
*/ | ||
function MediaClient(config) { | ||
BceBaseClient.call(this, config, 'media', true); | ||
} | ||
util.inherits(MediaClient, BceBaseClient); | ||
|
||
|
||
// --- B E G I N --- | ||
MediaClient.prototype.createPipeline = function (pipelineName, sourceBucket, targetBucket, | ||
opt_config, opt_description, opt_options) { | ||
|
||
var url = '/v3/pipeline'; | ||
var options = opt_options || {}; | ||
var body = JSON.stringify({ | ||
pipelineName: pipelineName, | ||
sourceBucket: sourceBucket, | ||
targetBucket: targetBucket, | ||
config: opt_config || {capacity: 5}, | ||
description: opt_description || '' | ||
}); | ||
|
||
return this._sendRequest('POST', url, { | ||
body: body, | ||
config: options.config, | ||
}); | ||
}; | ||
|
||
MediaClient.prototype.getPipeline = function (pipelineName, opt_options) { | ||
var url = '/v3/pipeline/' + pipelineName; | ||
var options = opt_options || {}; | ||
|
||
return this._sendRequest('GET', url, {config: options.config}); | ||
}; | ||
|
||
MediaClient.prototype.deletePipeline = function (pipelineName, opt_options) { | ||
var url = '/v3/pipeline/' + pipelineName; | ||
var options = opt_options || {}; | ||
|
||
return this._sendRequest('DELETE', url, {config: options.config}); | ||
}; | ||
|
||
MediaClient.prototype.getAllPipelines = function (opt_options) { | ||
var url = '/v3/pipeline'; | ||
var options = opt_options || {}; | ||
|
||
return this._sendRequest('GET', url, {config: options.config}); | ||
}; | ||
|
||
MediaClient.prototype.createJob = function (pipelineName, source, target, presetName, opt_options) { | ||
var url = '/v3/job'; | ||
var options = opt_options || {}; | ||
var body = JSON.stringify({ | ||
pipelineName: pipelineName, | ||
source: source, | ||
target: target, | ||
presetName: presetName | ||
}); | ||
|
||
return this._sendRequest('POST', url, { | ||
body: body, | ||
config: options.config | ||
}); | ||
}; | ||
|
||
MediaClient.prototype.getAllJobs = function (pipelineName, opt_options) { | ||
var url = '/v3/job'; | ||
var options = opt_options || {}; | ||
var params = {pipelineName: pipelineName}; | ||
|
||
return this._sendRequest('GET', url, { | ||
params: params, | ||
config: options.config | ||
}); | ||
}; | ||
|
||
MediaClient.prototype.getJob = function (jobId, opt_options) { | ||
var url = '/v3/job/' + jobId; | ||
var options = opt_options || {}; | ||
|
||
return this._sendRequest('GET', url, {config: options.config}); | ||
}; | ||
|
||
/** | ||
* 创建模板, 不对外部用户开放,仅服务于Console. | ||
* @param {string} presetName 转码模板名称. | ||
* @param {string} container 音视频文件的容器. | ||
* @param {Object=} clip 是否截取音视频片段. | ||
* @param {Object=} audio 音频输出信息的集合,不填写表示只处理视频部分. | ||
* @param {Object=} video 视频输出信息的集合,不填写表示只处理音频部分. | ||
* @param {Object=} opt_encryption HLS加解密信息的集合. | ||
* @param {boolean=} opt_transmux 是否仅执行容器格式转换. | ||
* @param {string=} opt_description 转码模板描述. | ||
* @param {Object=} opt_options Media Client 的配置. | ||
*/ | ||
MediaClient.prototype.createPreset = function (presetName, container, clip, audio, video, | ||
opt_encryption, opt_transmux, opt_description, opt_options) { | ||
// container: mp4, flv, hls, mp3, m4a | ||
var url = '/v3/preset'; | ||
var options = opt_options || {}; | ||
var body = { | ||
presetName: presetName, | ||
container: container | ||
}; | ||
clip && (body.clip = clip); | ||
audio && (body.audio = audio); | ||
video && (body.video = video); | ||
opt_encryption && (body.encryption = opt_encryption); | ||
opt_transmux != null && (body.transmux = opt_transmux); | ||
opt_description && (body.description = opt_description); | ||
|
||
return this._sendRequest('POST', url, { | ||
body: JSON.stringify(body), | ||
config: options.config | ||
}); | ||
}; | ||
|
||
MediaClient.prototype.getPreset = function (presetName, opt_options) { | ||
var url = '/v3/preset/' + presetName; | ||
var options = opt_options || {}; | ||
|
||
return this._sendRequest('GET', url, { | ||
config: options.config | ||
}); | ||
}; | ||
|
||
MediaClient.prototype.deletePreset = function (presetName, opt_options) { | ||
var url = '/v3/preset/' + presetName; | ||
var options = opt_options || {}; | ||
|
||
return this._sendRequest('DELETE', url, { | ||
config: options.config | ||
}); | ||
}; | ||
|
||
MediaClient.prototype.getMediainfo = function (bucket, key, opt_options) { | ||
var url = '/v3/mediainfo'; | ||
var options = opt_options || {}; | ||
var params = { | ||
bucket: bucket, | ||
key: key | ||
}; | ||
|
||
return this._sendRequest('GET', url, { | ||
params: params, | ||
config: options.config | ||
}); | ||
}; | ||
|
||
MediaClient.prototype.createSignature = function (credentials, httpMethod, path, params, headers) { | ||
var auth = new Auth(credentials.ak, credentials.sk); | ||
// 不能对content-type,content-length,content-md5进行签名 | ||
// 不能对x-bce-request-id进行签名 | ||
var headersToSign = ['host']; | ||
return auth.generateAuthorization(httpMethod, path, params, headers, 0, 0, headersToSign); | ||
}; | ||
// --- E N D --- | ||
|
||
|
||
MediaClient.prototype._sendRequest = function (httpMethod, resource, varArgs) { | ||
var defaultArgs = { | ||
bucketName: null, | ||
key: null, | ||
body: null, | ||
headers: {}, | ||
params: {}, | ||
config: {}, | ||
outputStream: null | ||
}; | ||
var args = u.extend(defaultArgs, varArgs); | ||
|
||
var config = u.extend({}, this.config, args.config); | ||
|
||
var httpClient = new HttpClient(config); | ||
return httpClient.sendRequest(httpMethod, resource, args.body, | ||
args.headers, args.params, u.bind(this.createSignature, this), | ||
args.outputStream | ||
); | ||
}; | ||
|
||
module.exports = MediaClient; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
module.exports = { | ||
credentials: { | ||
ak: '46bd9968a6194b4bbdf0341f2286ccce', | ||
sk: 'ec7f4e0174254f6f9020f9680fb1da9f' | ||
}, | ||
connection_timeout_in_mills: 5000, // 5 seconds | ||
// region: 'bj', | ||
// region: 'nj', | ||
// 有了 endpoint,region 其实就不生效了 | ||
endpoint: 'http://multimedia.bce-testinternal.baidu.com' | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/* vim: set ts=4 sw=4 sts=4 tw=120: */ |
Oops, something went wrong.