-
Notifications
You must be signed in to change notification settings - Fork 2
/
route-encode.js
83 lines (68 loc) · 2.17 KB
/
route-encode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
var conf = require('./conf');
var Encoder = require('media-encoder');
/** /encode */
class RouteEncode{
constructor(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY){
this.encoder = new Encoder(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
conf.awsRegion,
conf.pipelineId,
conf.bucketName,
conf.outputBucketName);
}
handleJobResult(err, jobResult, next){
if (err) {
switch (err) {
case this.encoder.errAccessDenied:
next(new Error('access denied for your user'));
return;
case this.encoder.errAws:
next(new Error('errAws: ' + this.encoder.errAws.message));
return;
}
next(new Error('err: ' + err.message));
return;
}
console.log(JSON.stringify(jobResult));
next(null, jobResult);
// if (jobResult.Status === "Submitted" || jobResult.Status === "Progressing"){
// next(null, jobResult);
// // setTimeout(() => {
// // this.encoder.readJob(jobResult.Id, handleJobResult);
// // }, 1500);
// } else {
// // return dest file path
// next(null, jobResult);
// return;
// }
}
encode(fileBaseName, kbps, next){
var presetId = conf["preset" + kbps];
var outFolder = conf["out" + kbps];
if (!presetId || !outFolder){
next(new Error("kbps is not supported"));
return;
}
// replace extension to mp3
var arrPart = fileBaseName.split('.');
// do not change if no extension
if (arrPart.length > 1){
arrPart[arrPart-1] = 'mp3';
}
var outName = arrPart.join('.');
this.encoder.createJob(conf.outBase + fileBaseName,
outFolder + outName,
presetId,
(err, jobResult) => {
this.handleJobResult(err, jobResult, next);
});
}
readJob(id, next) {
this.encoder.readJob(id, (err, jobResult) => {
this.handleJobResult(err, jobResult, next);
});
}
}
module.exports = RouteEncode;