@pixwel/pixwel-sdk 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +2 -1
- package/README.md +60 -0
- package/coverage/clover.xml +581 -430
- package/coverage/coverage-final.json +15 -9
- package/coverage/lcov-report/Ass.js.html +212 -212
- package/coverage/lcov-report/Asset.js.html +27 -27
- package/coverage/lcov-report/AssetType.js.html +98 -0
- package/coverage/lcov-report/Encode.js.html +98 -0
- package/coverage/lcov-report/File.js.html +98 -0
- package/coverage/lcov-report/Filename.js.html +9 -726
- package/coverage/lcov-report/Ingest.js.html +1239 -279
- package/coverage/lcov-report/IngestFile.js.html +5 -5
- package/coverage/lcov-report/Model.js.html +821 -0
- package/coverage/lcov-report/Order.js.html +25 -25
- package/coverage/lcov-report/Srt.js.html +102 -102
- package/coverage/lcov-report/Sub.js.html +43 -43
- package/coverage/lcov-report/Tag.js.html +98 -0
- package/coverage/lcov-report/TimeFormat.js.html +63 -63
- package/coverage/lcov-report/fileType.js.html +188 -0
- package/coverage/lcov-report/index.html +164 -86
- package/coverage/lcov.info +1159 -846
- package/dist/index.js +74 -22
- package/dist/src/Asset.js +10 -5
- package/dist/src/AssetType.js +54 -0
- package/dist/src/Encode.js +54 -0
- package/dist/src/File.js +54 -0
- package/dist/src/Filename.js +7 -228
- package/dist/src/Ingest.js +365 -33
- package/dist/src/IngestFile.js +6 -2
- package/dist/src/Model.js +569 -0
- package/dist/src/Order.js +20 -9
- package/dist/src/Srt.js +5 -1
- package/dist/src/Tag.js +54 -0
- package/dist/src/fileType.js +43 -0
- package/index.js +14 -0
- package/package.json +9 -3
- package/src/AssetType.js +11 -0
- package/src/Encode.js +11 -0
- package/src/File.js +11 -0
- package/src/Filename.js +0 -239
- package/src/Ingest.js +347 -27
- package/src/Model.js +252 -0
- package/src/Tag.js +11 -0
- package/src/fileType.js +41 -0
- package/test/Filename.spec.js +3 -707
- package/test/Ingest.spec.js +1107 -152
- package/test/Model.spec.js +328 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var extname = require("path").extname;
|
|
4
|
+
|
|
5
|
+
var TYPES = {
|
|
6
|
+
document: ["doc", "docx", "xls", "xlsx", "txt", "pdf", "ppt", "pptx"],
|
|
7
|
+
|
|
8
|
+
video: ["mov", "mp4", "m4v", "mpg", "mxf"],
|
|
9
|
+
|
|
10
|
+
audio: ["mp3", "wav", "m4a"],
|
|
11
|
+
|
|
12
|
+
image: ["jpg", "jpeg", "png", "tif", "tiff", "ai", "psd", "eps"],
|
|
13
|
+
|
|
14
|
+
zip: ["zip"]
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function extensionType(extension) {
|
|
18
|
+
for (var type in TYPES) {
|
|
19
|
+
if (TYPES[type].indexOf(extension) > -1) {
|
|
20
|
+
return type;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function extension(path) {
|
|
26
|
+
return extname(path.split("?")[0].toLowerCase()).substring(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function mediaType(path) {
|
|
30
|
+
var type = extensionType(extension(path));
|
|
31
|
+
|
|
32
|
+
if (type) {
|
|
33
|
+
return type;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw new Error("Unknown extension '" + extension + "'");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
extension: extension,
|
|
41
|
+
extensionType: extensionType,
|
|
42
|
+
mediaType: mediaType
|
|
43
|
+
};
|
package/index.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
export let Pixwel = {
|
|
2
|
+
credentials: {
|
|
3
|
+
token: null
|
|
4
|
+
},
|
|
5
|
+
endpoint: 'https://api.pixwel.com/api'
|
|
6
|
+
};
|
|
7
|
+
|
|
1
8
|
export { default as Asset } from './src/Asset';
|
|
9
|
+
export { default as AssetType } from './src/AssetType';
|
|
10
|
+
export { default as Encode } from './src/Encode';
|
|
11
|
+
export { default as File } from './src/File';
|
|
2
12
|
export { default as Filename } from './src/Filename';
|
|
3
13
|
export { default as Ingest } from './src/Ingest';
|
|
4
14
|
export { default as IngestFile } from './src/IngestFile';
|
|
15
|
+
export { default as Model } from './src/Model';
|
|
5
16
|
export { default as Order } from './src/Order';
|
|
17
|
+
export { default as Tag } from './src/Tag';
|
|
18
|
+
|
|
19
|
+
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixwel/pixwel-sdk",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"author": "Pixwel",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "npx babel-cli -d dist index.js src/*.js",
|
|
10
10
|
"watch": "npx babel-cli -w -d dist index.js src/*.js",
|
|
11
|
-
"test": "npx jest --coverage"
|
|
11
|
+
"test": "npx jest --coverage",
|
|
12
|
+
"debug": "node --inspect-brk node_modules/.bin/jest --watch --runInBand"
|
|
12
13
|
},
|
|
13
14
|
"browserify": {
|
|
14
15
|
"transform": [
|
|
@@ -24,10 +25,15 @@
|
|
|
24
25
|
]
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
+
"axios": "^0.19.0",
|
|
29
|
+
"deep-object-diff": "^1.1.0",
|
|
30
|
+
"lodash": "^4.17.15",
|
|
31
|
+
"ramda": "^0.26.1",
|
|
32
|
+
"validate.js": "^0.13.1"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
35
|
"babel-cli": "^6.26.0",
|
|
36
|
+
"babel-plugin-transform-runtime": "^6.23.0",
|
|
31
37
|
"babel-preset-env": "^1.7.0",
|
|
32
38
|
"jest": "^22.4.4"
|
|
33
39
|
}
|
package/src/AssetType.js
ADDED
package/src/Encode.js
ADDED
package/src/File.js
ADDED
package/src/Filename.js
CHANGED
|
@@ -6,243 +6,4 @@ import _ from "lodash";
|
|
|
6
6
|
* @type class
|
|
7
7
|
*/
|
|
8
8
|
export default class Filename {
|
|
9
|
-
/**
|
|
10
|
-
* Renders a valid filename given all tags, all types, an asset, and metadata
|
|
11
|
-
* options likely parsed from the file itself.
|
|
12
|
-
* @param {Array} [allTags=[]] Collection of all known tags
|
|
13
|
-
* @param {Array} [allTypes=[]] Collection of all known types
|
|
14
|
-
* @param {Object} [asset={}] A Platform Asset
|
|
15
|
-
* @param {Object} [options={}] options containing metadata about file
|
|
16
|
-
* @param {String} [mediaType=''] Indicates video, audio, image and allows for stricter required fields
|
|
17
|
-
* @return {String} A valid filename
|
|
18
|
-
*/
|
|
19
|
-
static render(params) {
|
|
20
|
-
|
|
21
|
-
let {
|
|
22
|
-
allTags = [],
|
|
23
|
-
allTypes = [],
|
|
24
|
-
asset = {},
|
|
25
|
-
options = {},
|
|
26
|
-
mediaType = ""
|
|
27
|
-
} = params;
|
|
28
|
-
|
|
29
|
-
if (!asset.project) {
|
|
30
|
-
throw new Error("missing asset.project");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (asset.project && !asset.project.filePrefix) {
|
|
34
|
-
throw new Error("missing asset.project.filePrefix");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!asset.name) {
|
|
38
|
-
throw new Error("missing asset.name");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!asset.type) {
|
|
42
|
-
throw new Error("missing asset.type");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let defaults = {
|
|
46
|
-
language: null,
|
|
47
|
-
country: null,
|
|
48
|
-
version: null,
|
|
49
|
-
tags: {
|
|
50
|
-
Usage: null,
|
|
51
|
-
Aspect: null,
|
|
52
|
-
SubDub: {
|
|
53
|
-
sub: null,
|
|
54
|
-
dub: null
|
|
55
|
-
},
|
|
56
|
-
Resolution: null,
|
|
57
|
-
"Frame Mode": null,
|
|
58
|
-
Framerate: null,
|
|
59
|
-
Text: null,
|
|
60
|
-
Codec: null,
|
|
61
|
-
Extra: []
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
options = _.merge(defaults, options);
|
|
65
|
-
|
|
66
|
-
if (!options.language) {
|
|
67
|
-
throw new Error("missing options.language");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (mediaType && mediaType == "video" && !options.tags.Codec) {
|
|
71
|
-
throw new Error("missing options.tags.Codec");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (mediaType && mediaType == "video" && !options.tags.Resolution) {
|
|
75
|
-
throw new Error("missing options.tags.Resolution");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (mediaType && mediaType == "video" && !options.tags.Framerate) {
|
|
79
|
-
throw new Error("missing options.tags.Framerate");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (mediaType == "video" && !options.tags["Frame Mode"]) {
|
|
83
|
-
throw new Error("missing options.tags[Frame Mode]");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function assetType(asset, types) {
|
|
87
|
-
if (/trailer/.test(asset.type)) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
let matchingType = _.find(types, { name: asset.type });
|
|
92
|
-
if (!matchingType) {
|
|
93
|
-
throw new Error(`Asset type "${asset.type}" could not be found`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
matchingType.file || matchingType.name.replace(".", "-").toUpperCase()
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function assetTitle(asset) {
|
|
102
|
-
let prefix = "";
|
|
103
|
-
let name = asset.slug.toUpperCase().replace("INT-L", "INTL");
|
|
104
|
-
if (/trailer/.test(asset.type)) {
|
|
105
|
-
switch (asset.type) {
|
|
106
|
-
case "trailer.intl":
|
|
107
|
-
prefix = "ITR-";
|
|
108
|
-
name = name.replace(/INTL-TRAILER-/, "");
|
|
109
|
-
break;
|
|
110
|
-
case "trailer":
|
|
111
|
-
prefix = "TR-";
|
|
112
|
-
name = name.replace(/TRAILER-/, "");
|
|
113
|
-
break;
|
|
114
|
-
case "trailer.us":
|
|
115
|
-
prefix = "DTR-";
|
|
116
|
-
name = name.replace(/DOMESTIC-TRAILER-/, "");
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return prefix + name;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function runningTime(asset) {
|
|
124
|
-
let matches = asset.type.match(/^film-clip|^featurette/);
|
|
125
|
-
if (!matches) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let minutes = Math.floor(asset.length / 60);
|
|
130
|
-
let seconds = asset.length % 60;
|
|
131
|
-
|
|
132
|
-
let result = "";
|
|
133
|
-
|
|
134
|
-
if (minutes > 0) {
|
|
135
|
-
result += minutes + "min";
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (seconds > 0) {
|
|
139
|
-
result += seconds + "sec";
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function locale(country, language) {
|
|
146
|
-
if (language.includes("-")) {
|
|
147
|
-
country = "";
|
|
148
|
-
}
|
|
149
|
-
return [language, country]
|
|
150
|
-
.filter(str => {
|
|
151
|
-
return !!str && str !== "WW";
|
|
152
|
-
})
|
|
153
|
-
.join("-");
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function textType(subDub, text) {
|
|
157
|
-
if (!subDub || (!subDub.sub && !subDub.dub)) {
|
|
158
|
-
return text;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
let result = [];
|
|
162
|
-
if (subDub.sub) {
|
|
163
|
-
result.push("sub");
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (subDub.dub) {
|
|
167
|
-
result.push("dub");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function matchSet(allTags, tags) {
|
|
174
|
-
let selectedTags = _(tags)
|
|
175
|
-
.values()
|
|
176
|
-
.flatten()
|
|
177
|
-
.value();
|
|
178
|
-
|
|
179
|
-
let setTag = _(allTags)
|
|
180
|
-
.filter("set")
|
|
181
|
-
.find(setTag => {
|
|
182
|
-
return _.difference(setTag.set, selectedTags).length === 0;
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
if (setTag) {
|
|
186
|
-
return setTag.name;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
let tags = options.tags,
|
|
191
|
-
parts = [
|
|
192
|
-
asset.project.filePrefix,
|
|
193
|
-
assetType(asset, allTypes),
|
|
194
|
-
assetTitle(asset),
|
|
195
|
-
runningTime(asset),
|
|
196
|
-
locale(options.country, options.language),
|
|
197
|
-
textType(tags.SubDub, tags.Text),
|
|
198
|
-
tags.Extra.join("_"),
|
|
199
|
-
options.version,
|
|
200
|
-
tags.Codec
|
|
201
|
-
];
|
|
202
|
-
|
|
203
|
-
parts = _(parts)
|
|
204
|
-
.flatten()
|
|
205
|
-
.filter()
|
|
206
|
-
.map(part => part.toUpperCase());
|
|
207
|
-
|
|
208
|
-
let matchedSet = matchSet(allTags, options.tags);
|
|
209
|
-
let requiredInfo = tags.Resolution && tags["Frame Mode"] && tags.Framerate;
|
|
210
|
-
|
|
211
|
-
if (matchedSet) {
|
|
212
|
-
parts = parts.push(matchedSet);
|
|
213
|
-
} else if (mediaType == "video" && tags.Resolution && !requiredInfo) {
|
|
214
|
-
parts = parts.push(tags.Resolution.replace(/\d+x/, ""));
|
|
215
|
-
} else if (mediaType == "image" && tags.Resolution) {
|
|
216
|
-
parts = parts.push(tags.Resolution);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
let name = parts.join("_");
|
|
220
|
-
|
|
221
|
-
let hasResInfo = name.match(/\d+(i|p)/i);
|
|
222
|
-
let hasAllInfo = name.match(/\d+(i|p)\d+/i);
|
|
223
|
-
|
|
224
|
-
if (requiredInfo && !hasResInfo && !hasAllInfo) {
|
|
225
|
-
let res = tags.Resolution;
|
|
226
|
-
let encodeTag = [
|
|
227
|
-
hasResInfo ? "" : res.indexOf("x") ? res.replace(/\d+x/, "") : res,
|
|
228
|
-
res.match(/i|p/i) && !hasResInfo
|
|
229
|
-
? ""
|
|
230
|
-
: tags["Frame Mode"].toLowerCase().slice(0, 1),
|
|
231
|
-
tags.Framerate.replace(".", "").toUpperCase()
|
|
232
|
-
]
|
|
233
|
-
.filter(val => {
|
|
234
|
-
return val;
|
|
235
|
-
})
|
|
236
|
-
.join("");
|
|
237
|
-
|
|
238
|
-
let match = new RegExp(encodeTag, "i");
|
|
239
|
-
name = name.match(match)
|
|
240
|
-
? name.replace(match, encodeTag)
|
|
241
|
-
: name + "_" + encodeTag;
|
|
242
|
-
} else if (hasResInfo && !hasAllInfo && tags.Framerate) {
|
|
243
|
-
name += tags.Framerate.replace(".", "").toUpperCase();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return name;
|
|
247
|
-
}
|
|
248
9
|
}
|