@pixwel/pixwel-sdk 1.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.
Files changed (65) hide show
  1. package/.babelrc +3 -0
  2. package/.editorconfig +36 -0
  3. package/.vs/slnx.sqlite +0 -0
  4. package/.vscode/launch.json +0 -0
  5. package/coverage/clover.xml +7 -0
  6. package/coverage/coverage-final.json +1 -0
  7. package/coverage/lcov-report/Ass.js.html +651 -0
  8. package/coverage/lcov-report/Asset.js.html +129 -0
  9. package/coverage/lcov-report/Filename.js.html +849 -0
  10. package/coverage/lcov-report/Ingest.js.html +591 -0
  11. package/coverage/lcov-report/IngestFile.js.html +87 -0
  12. package/coverage/lcov-report/IngestFileDrop.js.html +540 -0
  13. package/coverage/lcov-report/Order.js.html +162 -0
  14. package/coverage/lcov-report/Srt.js.html +333 -0
  15. package/coverage/lcov-report/Sub.js.html +177 -0
  16. package/coverage/lcov-report/TimeFormat.js.html +210 -0
  17. package/coverage/lcov-report/base.css +223 -0
  18. package/coverage/lcov-report/block-navigation.js +63 -0
  19. package/coverage/lcov-report/index.html +84 -0
  20. package/coverage/lcov-report/lib/Filename.js.html +720 -0
  21. package/coverage/lcov-report/lib/index.html +97 -0
  22. package/coverage/lcov-report/prettify.css +1 -0
  23. package/coverage/lcov-report/prettify.js +1 -0
  24. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  25. package/coverage/lcov-report/sorter.js +158 -0
  26. package/coverage/lcov-report/test/index.html +97 -0
  27. package/coverage/lcov-report/test/mocks.js.html +423 -0
  28. package/coverage/lcov.info +0 -0
  29. package/dist/index.js +61 -0
  30. package/dist/src/Ass.js +200 -0
  31. package/dist/src/Asset.js +41 -0
  32. package/dist/src/Filename.js +252 -0
  33. package/dist/src/Ingest.js +200 -0
  34. package/dist/src/IngestFile.js +17 -0
  35. package/dist/src/IngestFileDrop.js +178 -0
  36. package/dist/src/Order.js +58 -0
  37. package/dist/src/Srt.js +102 -0
  38. package/dist/src/Sub.js +42 -0
  39. package/dist/src/TimeFormat.js +48 -0
  40. package/index.js +6 -0
  41. package/package.json +26 -0
  42. package/src/Ass.js +195 -0
  43. package/src/Asset.js +20 -0
  44. package/src/Filename.js +260 -0
  45. package/src/Ingest.js +175 -0
  46. package/src/IngestFile.js +6 -0
  47. package/src/IngestFileDrop.js +157 -0
  48. package/src/Order.js +31 -0
  49. package/src/Srt.js +89 -0
  50. package/src/Sub.js +37 -0
  51. package/src/TimeFormat.js +48 -0
  52. package/src/docs.json +1 -0
  53. package/test/Ass.spec.js +150 -0
  54. package/test/Asset.spec.js +24 -0
  55. package/test/Filename.spec.js +728 -0
  56. package/test/Ingest.spec.js +95 -0
  57. package/test/Srt.spec.js +111 -0
  58. package/test/Sub.spec.js +75 -0
  59. package/test/TimeFormat.spec.js +84 -0
  60. package/test/mocks/mediainfo.mock.js +67 -0
  61. package/test/mocks/mediainfo.png.mock.js +22 -0
  62. package/test/mocks/mocks.js +118 -0
  63. package/test/mocks/prores.mock.js +71 -0
  64. package/test/parse.spec.ts +927 -0
  65. package/tsconfig.json +11 -0
@@ -0,0 +1,200 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _lodash = require('lodash');
8
+
9
+ var _lodash2 = _interopRequireDefault(_lodash);
10
+
11
+ var _TimeFormat = require('./TimeFormat');
12
+
13
+ var _TimeFormat2 = _interopRequireDefault(_TimeFormat);
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+
17
+ function trim(str) {
18
+ return str.replace(/^\s+|\s+$/g, '');
19
+ }
20
+
21
+ function searchIndex(lines, pattern, startIndex) {
22
+ var len = lines.length;
23
+ startIndex = startIndex || 0;
24
+
25
+ for (var i = startIndex; i < len; i++) {
26
+ var line = lines[i];
27
+ if (line.match(pattern)) {
28
+ return i;
29
+ }
30
+ }
31
+ return false;
32
+ }
33
+
34
+ function extractStyles(lines) {
35
+ var line,
36
+ styles = {};
37
+
38
+ var currentIndex = searchIndex(lines, /^\[V4\+ Styles\]$/);
39
+
40
+ if (currentIndex === false) {
41
+ return styles;
42
+ }
43
+
44
+ currentIndex = searchIndex(lines, /^Format:/, ++currentIndex);
45
+
46
+ if (currentIndex === false) {
47
+ return styles;
48
+ }
49
+
50
+ line = trim(lines[currentIndex]);
51
+ var fields = line.replace(/^Format:\s+/, '').split(/\s*,\s*/);
52
+ var nameIndex = fields.indexOf('Name');
53
+ var alignmentIndex = fields.indexOf('Alignment');
54
+
55
+ if (nameIndex === -1) {
56
+ return styles;
57
+ }
58
+
59
+ var pattern = new RegExp('^' + new Array(fields.length).join('\s*(.*?)\s*,') + '(.*?)$');
60
+
61
+ currentIndex = searchIndex(lines, /^Style:/, ++currentIndex);
62
+
63
+ while (currentIndex !== false) {
64
+ line = trim(lines[currentIndex]);
65
+
66
+ var parts = line.replace(/^Style:\s+/, '').match(pattern);
67
+ if (!parts) {
68
+ throw new Error('Error, missing fields in a `Style` entry');
69
+ }
70
+ if (parts.length) {
71
+ var style = {};
72
+ if (alignmentIndex !== -1) {
73
+ var alignmentNumber = parts[alignmentIndex + 1];
74
+ style.alignment = alignmentNumber >= 7 ? 'top' : 'bottom';
75
+ }
76
+ styles[parts[nameIndex + 1]] = style;
77
+ }
78
+ currentIndex = searchIndex(lines, /^Style:/, ++currentIndex);
79
+ }
80
+ return styles;
81
+ }
82
+
83
+ exports.default = {
84
+ parse: function parse(lines) {
85
+ var line;
86
+ var currentIndex = 0;
87
+
88
+ function normalizeTime(time) {
89
+ if (time.charAt(1) === ':') {
90
+ time = '0' + time;
91
+ }
92
+ return time.replace('.', ',') + '0';
93
+ }
94
+
95
+ function normalizeText(text) {
96
+ return text.replace(/\\n|\\N/, '\n').replace(/{\\(.*)1}(.*){\\\1[0]}/g, function (match, tag, content) {
97
+ return '<' + tag + '>' + content + '</' + tag + '>';
98
+ });
99
+ }
100
+
101
+ var styles = extractStyles(lines);
102
+
103
+ currentIndex = searchIndex(lines, /^\[Events\]$/);
104
+
105
+ if (currentIndex === false) {
106
+ throw new Error('Error, missing `[Events]` section');
107
+ }
108
+
109
+ currentIndex = searchIndex(lines, /^Format:/, ++currentIndex);
110
+
111
+ if (currentIndex === false) {
112
+ throw new Error('Error, missing `Format` entry');
113
+ }
114
+
115
+ line = trim(lines[currentIndex]);
116
+ var fields = line.replace(/^Format:\s+/, '').split(/\s*,\s*/);
117
+ var startIndex = fields.indexOf('Start');
118
+ var endIndex = fields.indexOf('End');
119
+ var styleIndex = fields.indexOf('Style');
120
+ var textIndex = fields.indexOf('Text');
121
+
122
+ if (startIndex === -1 || endIndex === -1 || textIndex === -1) {
123
+ throw new Error('Error, missing fields in a `Format` entry');
124
+ }
125
+
126
+ var result = [];
127
+ var pattern = new RegExp('^' + new Array(fields.length).join('\s*(.*?)\s*,') + '(.*?)$');
128
+
129
+ currentIndex = searchIndex(lines, /^Dialogue:/, ++currentIndex);
130
+
131
+ while (currentIndex !== false) {
132
+ line = trim(lines[currentIndex]);
133
+ var parts = line.replace(/^Dialogue:\s+/, '').match(pattern);
134
+ if (!parts) {
135
+ throw new Error('Error, missing fields in a `Dialogue` entry');
136
+ }
137
+ if (parts.length) {
138
+ var entry = {
139
+ startTime: normalizeTime(parts[startIndex + 1]),
140
+ stopTime: normalizeTime(parts[endIndex + 1]),
141
+ text: normalizeText(parts[textIndex + 1]),
142
+ alignment: 'bottom'
143
+ };
144
+ if (styleIndex !== -1) {
145
+ var style = styles[parts[styleIndex + 1]];
146
+ if (style && style.alignment) {
147
+ entry.alignment = style.alignment;
148
+ }
149
+ }
150
+ result.push(entry);
151
+ }
152
+ currentIndex = searchIndex(lines, /^Dialogue:/, ++currentIndex);
153
+ }
154
+ return result;
155
+ },
156
+ export: function _export(lines, options) {
157
+ var result = '';
158
+
159
+ options = options || {};
160
+
161
+ var font = options.font || {
162
+ face: 'Arial',
163
+ size: 20
164
+ };
165
+
166
+ result += "[Script Info]\n";
167
+ result += "ScriptType: v4.00+\n\n";
168
+
169
+ result += "[V4+ Styles]\n";
170
+ result += "Format: Name, Fontname, Fontsize, PrimaryColour,Shadow,MarginV,Alignment\n";
171
+ result += "Style: Bottom," + font.face + "," + font.size + ",&H00FFFFFF,1,20,2\n";
172
+ result += "Style: Top," + font.face + "," + font.size + ",&H00FFFFFF,1,20,8\n\n";
173
+
174
+ result += "[Events]\n";
175
+ result += "Format: Layer, Start, End, Style, Text\n";
176
+
177
+ function normalizeTime(time) {
178
+ if (time.charAt(0) === '0') {
179
+ time = time.substr(1);
180
+ }
181
+ return time.replace(',', '.').slice(0, -1);
182
+ }
183
+
184
+ function normalizeText(text) {
185
+ return _lodash2.default.unescape(text.replace(/<div>/g, '\\N').replace(/<\/div>/g, '').replace(/\n/g, '\\N').replace(/<br>/g, '\\N').replace(/<i>/g, '{\\i1}').replace(/<\/i>/g, '{\\i0}').replace(/<b>/g, '{\\b1}').replace(/<\/b>/g, '{\\b0}'));
186
+ }
187
+
188
+ lines.forEach(function (line) {
189
+ if (line.text === undefined) {
190
+ return;
191
+ }
192
+ result += "Dialogue: 0";
193
+ result += "," + normalizeTime(_TimeFormat2.default.startTime(line));
194
+ result += "," + normalizeTime(_TimeFormat2.default.stopTime(line));
195
+ result += line.alignment === 'top' ? ",Top" : ",Bottom";
196
+ result += "," + normalizeText(line.text) + "\n";
197
+ });
198
+ return result;
199
+ }
200
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
+
9
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+
11
+ var Asset = function () {
12
+ function Asset() {
13
+ _classCallCheck(this, Asset);
14
+ }
15
+
16
+ _createClass(Asset, null, [{
17
+ key: "mapFromOrder",
18
+ value: function mapFromOrder(order) {
19
+ if (!order) {
20
+ throw new Error("missing order");
21
+ }
22
+ if (!order.asset) {
23
+ throw new Error("missing order.asset");
24
+ }
25
+ if (!order.project) {
26
+ throw new Error("missing order.project");
27
+ }
28
+ if (!order.project.slug) {
29
+ throw new Error("missing order.project.slug");
30
+ }
31
+ var asset = order.asset;
32
+ asset.project = order.project;
33
+ asset.project.filePrefix = order.project.slug.toUpperCase();
34
+ return asset;
35
+ }
36
+ }]);
37
+
38
+ return Asset;
39
+ }();
40
+
41
+ exports.default = Asset;
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
+
9
+ var _lodash = require("lodash");
10
+
11
+ var _lodash2 = _interopRequireDefault(_lodash);
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
+
17
+ /**
18
+ * The Filename class parses a filename into tokens, and can also take a set of
19
+ * tokens and create a valid Pixwel filename.
20
+ * @type class
21
+ */
22
+ var Filename = function () {
23
+ function Filename() {
24
+ _classCallCheck(this, Filename);
25
+ }
26
+
27
+ _createClass(Filename, null, [{
28
+ key: "render",
29
+
30
+ /**
31
+ * Renders a valid filename given all tags, all types, an asset, and metadata
32
+ * options likely parsed from the file itself.
33
+ * @param {Array} [allTags=[]] Collection of all known tags
34
+ * @param {Array} [allTypes=[]] Collection of all known types
35
+ * @param {Object} [asset={}] A Platform Asset
36
+ * @param {Object} [options={}] options containing metadata about file
37
+ * @param {String} [mediaType=''] Indicates video, audio, image and allows for stricter required fields
38
+ * @return {String} A valid filename
39
+ */
40
+ value: function render() {
41
+ var allTags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
42
+ var allTypes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
43
+ var asset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
44
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
45
+ var mediaType = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
46
+
47
+ if (!asset.project) {
48
+ throw "missing asset.project";
49
+ }
50
+
51
+ if (asset.project && !asset.project.filePrefix) {
52
+ throw "missing asset.project.filePrefix";
53
+ }
54
+
55
+ if (!asset.name) {
56
+ throw "missing asset.name";
57
+ }
58
+
59
+ if (!asset.type) {
60
+ throw "missing asset.type";
61
+ }
62
+
63
+ if (asset.type.match(/^film-clip|^featurette/) && !asset.length) {
64
+ throw "missing asset.length";
65
+ }
66
+
67
+ var defaults = {
68
+ language: null,
69
+ country: null,
70
+ version: null,
71
+ tags: {
72
+ Usage: null,
73
+ Aspect: null,
74
+ SubDub: {
75
+ sub: null,
76
+ dub: null
77
+ },
78
+ Resolution: null,
79
+ "Frame Mode": null,
80
+ Framerate: null,
81
+ Text: null,
82
+ Codec: null,
83
+ Extra: []
84
+ }
85
+ };
86
+ options = _lodash2.default.merge(defaults, options);
87
+
88
+ if (!options.language) {
89
+ throw "missing options.language";
90
+ }
91
+
92
+ if (!options.tags.SubDub.sub && !options.tags.SubDub.dub && !options.tags.Text) {
93
+ throw "missing options.tags.Text or options.tags.SubDub";
94
+ }
95
+
96
+ if (mediaType && mediaType == "video" && !options.tags.Codec) {
97
+ throw "missing options.tags.Codec";
98
+ }
99
+
100
+ if (mediaType && mediaType == "video" && !options.tags.Resolution) {
101
+ throw "missing options.tags.Resolution";
102
+ }
103
+
104
+ if (mediaType && mediaType == "video" && !options.tags.Framerate) {
105
+ throw "missing options.tags.Framerate";
106
+ }
107
+
108
+ if (mediaType == "video" && !options.tags["Frame Mode"]) {
109
+ throw "missing options.tags[Frame Mode]";
110
+ }
111
+
112
+ // currently, slurpee's filename.ts will render this, but we can add this back in later when
113
+ // filename.ts starts to rely on Filename.render
114
+ // if ((options.tags.SubDub.dub || options.tags.SubDub.sub) && options.tags.Text) {
115
+ // throw 'conflicting options supplied: SubDub and Text';
116
+ // }
117
+
118
+ function assetType(asset, types) {
119
+ if (/trailer/.test(asset.type)) {
120
+ return false;
121
+ }
122
+
123
+ var matchingType = _lodash2.default.find(types, { name: asset.type });
124
+ if (!matchingType) {
125
+ throw "Asset type \"" + asset.type + "\" could not be found";
126
+ }
127
+
128
+ return matchingType.file || matchingType.name.replace(".", "-").toUpperCase();
129
+ }
130
+
131
+ function assetTitle(asset) {
132
+ var prefix = "";
133
+ var name = asset.slug.toUpperCase().replace("INT-L", "INTL");
134
+ if (/trailer/.test(asset.type)) {
135
+ switch (asset.type) {
136
+ case "trailer.intl":
137
+ prefix = "ITR-";
138
+ name = name.replace(/INTL-TRAILER-/, "");
139
+ break;
140
+ case "trailer":
141
+ prefix = "TR-";
142
+ name = name.replace(/TRAILER-/, "");
143
+ break;
144
+ case "trailer.us":
145
+ prefix = "DTR-";
146
+ name = name.replace(/DOMESTIC-TRAILER-/, "");
147
+ break;
148
+ }
149
+ }
150
+ return prefix + name;
151
+ }
152
+
153
+ function runningTime(asset) {
154
+ var matches = asset.type.match(/^film-clip|^featurette/);
155
+ if (!matches) {
156
+ return;
157
+ }
158
+
159
+ var minutes = Math.floor(asset.length / 60);
160
+ var seconds = asset.length % 60;
161
+
162
+ var result = "";
163
+
164
+ if (minutes > 0) {
165
+ result += minutes + "min";
166
+ }
167
+
168
+ if (seconds > 0) {
169
+ result += seconds + "sec";
170
+ }
171
+
172
+ return result;
173
+ }
174
+
175
+ function locale(country, language) {
176
+ return [language, country].filter(function (str) {
177
+ return !!str && str !== "WW";
178
+ }).join("-");
179
+ }
180
+
181
+ function textType(subDub, text) {
182
+ if (!subDub || !subDub.sub && !subDub.dub) {
183
+ return text;
184
+ }
185
+
186
+ var result = [];
187
+ if (subDub.sub) {
188
+ result.push("sub");
189
+ }
190
+
191
+ if (subDub.dub) {
192
+ result.push("dub");
193
+ }
194
+
195
+ return result;
196
+ }
197
+
198
+ function matchSet(allTags, tags) {
199
+ var selectedTags = (0, _lodash2.default)(tags).values().flatten().value();
200
+
201
+ var setTag = (0, _lodash2.default)(allTags).filter("set").find(function (setTag) {
202
+ return _lodash2.default.difference(setTag.set, selectedTags).length === 0;
203
+ });
204
+
205
+ if (setTag) {
206
+ return setTag.name;
207
+ }
208
+ }
209
+
210
+ var tags = options.tags,
211
+ parts = [asset.project.filePrefix, assetType(asset, allTypes), assetTitle(asset), runningTime(asset), locale(options.country, options.language), textType(tags.SubDub, tags.Text), tags.Extra.join("_"), options.version, tags.Codec];
212
+
213
+ parts = (0, _lodash2.default)(parts).flatten().filter().map(function (part) {
214
+ return part.toUpperCase();
215
+ });
216
+
217
+ var matchedSet = matchSet(allTags, options.tags);
218
+ var requiredInfo = tags.Resolution && tags["Frame Mode"] && tags.Framerate;
219
+
220
+ if (matchedSet) {
221
+ parts = parts.push(matchedSet);
222
+ } else if (mediaType == "video" && tags.Resolution && !requiredInfo) {
223
+ parts = parts.push(tags.Resolution.replace(/\d+x/, ""));
224
+ } else if (mediaType == "image" && tags.Resolution) {
225
+ parts = parts.push(tags.Resolution);
226
+ }
227
+
228
+ var name = parts.join("_");
229
+
230
+ var hasResInfo = name.match(/\d+(i|p)/i);
231
+ var hasAllInfo = name.match(/\d+(i|p)\d+/i);
232
+
233
+ if (requiredInfo && !hasResInfo && !hasAllInfo) {
234
+ var res = tags.Resolution;
235
+ var encodeTag = [hasResInfo ? "" : res.indexOf("x") ? res.replace(/\d+x/, "") : res, res.match(/i|p/i) && !hasResInfo ? "" : tags["Frame Mode"].toLowerCase().slice(0, 1), tags.Framerate.replace(".", "").toUpperCase()].filter(function (val) {
236
+ return val;
237
+ }).join("");
238
+
239
+ var match = new RegExp(encodeTag, "i");
240
+ name = name.match(match) ? name.replace(match, encodeTag) : name + "_" + encodeTag;
241
+ } else if (hasResInfo && !hasAllInfo && tags.Framerate) {
242
+ name += tags.Framerate.replace(".", "").toUpperCase();
243
+ }
244
+
245
+ return name;
246
+ }
247
+ }]);
248
+
249
+ return Filename;
250
+ }();
251
+
252
+ exports.default = Filename;
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
+
9
+ var _lodash = require("lodash");
10
+
11
+ var _lodash2 = _interopRequireDefault(_lodash);
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
+
17
+ /**
18
+ * [media description]
19
+ * @type {[type]}
20
+ */
21
+ var Ingest = function () {
22
+ function Ingest() {
23
+ _classCallCheck(this, Ingest);
24
+ }
25
+
26
+ _createClass(Ingest, null, [{
27
+ key: "mapMetaToTags",
28
+
29
+ /**
30
+ * [mapMetaToTags description]
31
+ * @param {[type]} info [description]
32
+ * @return {[type]} [description]
33
+ */
34
+ value: function mapMetaToTags(info, mediaType) {
35
+
36
+ var tags = {
37
+ Aspect: "",
38
+ Standard: "",
39
+ Resolution: "",
40
+ Codec: "",
41
+ "Frame Mode": "",
42
+ Text: "",
43
+ Usage: "",
44
+ Extra: [],
45
+ Framerate: "",
46
+ Duration: ""
47
+ };
48
+
49
+ switch (mediaType) {
50
+ case 'video':
51
+ mediaType = 'Video';
52
+ break;
53
+ case 'image':
54
+ mediaType = 'Image';
55
+ break;
56
+ default:
57
+ return tags;
58
+ }
59
+
60
+ if (!info.File) {
61
+ throw "missing info.File";
62
+ }
63
+
64
+ if (!info.File.track) {
65
+ throw "missing info.File.track";
66
+ }
67
+
68
+ var mediainfoDefaults = {
69
+ Display_aspect_ratio: "",
70
+ Format: "",
71
+ Standard: "",
72
+ Height: "",
73
+ Width: "",
74
+ Frame_rate: "",
75
+ Scan_type: ""
76
+ };
77
+
78
+ var media = _lodash2.default.find(info["File"]["track"], {
79
+ _type: mediaType
80
+ });
81
+ media = _lodash2.default.merge({}, mediainfoDefaults, media);
82
+
83
+ var width = parseInt(media["Width"].replace(" ", "").match(/[0-9 ]+/));
84
+ var height = parseInt(media["Height"].replace(" ", "").match(/[0-9 ]+/));
85
+ tags.Resolution = width && height ? width + "x" + height : "";
86
+
87
+ tags.Standard = media["Standard"] ? media["Standard"].toLowerCase() : "";
88
+
89
+ var scan = /Progressive/.test(media["Scan_type"]) ? "p" : "i";
90
+ var dimension = /3D/.test(name) ? "3D" : "2D";
91
+
92
+ var framerate = media["Frame_rate"].split(" ");
93
+ if (framerate.length) {
94
+ var f = framerate[0];
95
+ if (f == "23.976") {
96
+ f = "23.98";
97
+ }
98
+ f = parseFloat(f).toString();
99
+ tags.Framerate = f != "NaN" ? f : "";
100
+ }
101
+
102
+ if (!tags.Standard) {
103
+ switch (tags.Framerate) {
104
+ case "24":
105
+ case "23.98":
106
+ case "29.97":
107
+ case "59.94":
108
+ tags.Standard = "ntsc";
109
+ break;
110
+ case "25":
111
+ case "50":
112
+ tags.Standard = "pal";
113
+ break;
114
+ }
115
+ }
116
+
117
+ tags.Codec = function (codec) {
118
+ switch (codec) {
119
+ case "AVC":
120
+ return "h264";
121
+ case "ProRes":
122
+ return "prores";
123
+ default:
124
+ return "";
125
+ }
126
+ }(media["Format"]);
127
+
128
+ if (tags.Codec == "h264") {
129
+ tags.Usage = "online";
130
+ }
131
+
132
+ if (tags.Codec == "prores") {
133
+ tags.Usage = "broadcast";
134
+ }
135
+
136
+ tags.Aspect = media["Display_aspect_ratio"] || "";
137
+ tags["Frame Mode"] = media["Scan_type"].toLowerCase();
138
+
139
+ return tags;
140
+ }
141
+ }, {
142
+ key: "mapFromKnownData",
143
+ value: function mapFromKnownData(context, order, tags) {
144
+ var watermarks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
145
+
146
+
147
+ if (order.asset) {
148
+ context = {
149
+ asset: order.asset._id,
150
+ project: order.project._id,
151
+ assetType: order.assetType,
152
+ purpose: "download"
153
+ };
154
+ }
155
+
156
+ var previewType = function () {
157
+ if (order.isSub() && order.isDub()) return "both";
158
+ if (order.isDub()) return "dub";
159
+ if (order.isSub()) return "sub";
160
+ }();
161
+
162
+ var isPreviewEnabled = tags.Codec == "prores" && tags.Resolution.split("x")[1] == "1080" && (tags.Framerate == "23.98" || tags.Framerate == "25") && watermarks.length;
163
+
164
+ var watermark = watermarks[0] ? watermarks[0]._id : "";
165
+
166
+ return {
167
+ workRequest: order._id,
168
+ selected: {
169
+ download: {
170
+ enabled: true,
171
+ country: order.country,
172
+ language: order.language,
173
+ tags: tags,
174
+ embargo: {
175
+ enabled: false
176
+ }
177
+ },
178
+ preview: {
179
+ enabled: isPreviewEnabled,
180
+ language: order.language,
181
+ revision: "Final",
182
+ type: previewType,
183
+ watermark: watermark,
184
+ embargo: {
185
+ enabled: false
186
+ }
187
+ },
188
+ thumbnail: {
189
+ enabled: false
190
+ }
191
+ },
192
+ context: context
193
+ };
194
+ }
195
+ }]);
196
+
197
+ return Ingest;
198
+ }();
199
+
200
+ exports.default = Ingest;